help,problems difficult to solve
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: help,problems difficult to solve

  1. #1
    Join Date
    Mar 2010
    Posts
    1

    help,problems difficult to solve

    I'm coding bulk-usb drivers,i try to send data through bulk-out pipe,but transaction failed,I call IoCancelIrp when timeout,but then usbd do not respond with any of my requests.Does anyone have ideas?


    NTSTATUS CallUSBDI( IN PUSBPS_DEVICE_EXTENSION dx, IN PVOID UrbEtc,
    IN ULONG IoControlCode/*=IOCTL_INTERNAL_USB_SUBMIT_URB*/,
    IN ULONG Arg2/*=0*/)
    {
    IO_STATUS_BLOCK IoStatus;
    KEVENT event;
    // Initialise IRP completion event
    KeInitializeEvent(&event, NotificationEvent, FALSE);
    // Build Internal IOCTL IRP
    PIRP Irp = IoBuildDeviceIoControlRequest(
    IoControlCode, dx->NextStackDevice,
    NULL, 0, // Input buffer
    NULL, 0, // Output buffer
    TRUE, &event, &IoStatus);
    // Get IRP stack location for next driver down (already set up)
    PIO_STACK_LOCATION NextIrpStack = IoGetNextIrpStackLocation(Irp);
    // Store pointer to the URB etc
    NextIrpStack->Parameters.Others.Argument1 = UrbEtc;
    NextIrpStack->Parameters.Others.Argument2 = (PVOID)Arg2;

    IoSetCompletionRoutine(Irp,
    (PIO_COMPLETION_ROUTINE)USBDCompletionRoutine,
    (PVOID)&event,
    TRUE,
    TRUE,
    TRUE);
    // Call the driver and wait for completion if necessary
    //dx -> TimerHandledEvent = &event;
    //IoStartTimer(dx->fdo);
    DebugPrint("Usb Waiting\n");
    LARGE_INTEGER TimeoutInt;
    TimeoutInt.QuadPart = -1000000;
    NTSTATUS status = IoCallDriver( dx->NextStackDevice, Irp);
    DebugPrint("Usb Waiting 1\n");
    if (status == STATUS_PENDING)
    {
    DebugPrint("CallUSBDI: waiting for URB completion");
    DebugPrint("Usb Waiting a\n");
    status = KeWaitForSingleObject( &event, Suspended, KernelMode, FALSE, &TimeoutInt);
    //status = KeWaitForSingleObject( &event, Suspended, KernelMode, FALSE, NULL);
    DebugPrint("Usb Waiting b\n");

    if( status == STATUS_TIMEOUT )
    {
    DebugPrint (" Wait for single object, returned STATUS_TIMEOUT\n");
    // we timed out - cancel the IRP
    status = IoCancelIrp( Irp );
    DebugPrint (" Canceling IRP %x\n",status);
    KeWaitForSingleObject(&event,Suspended,KernelMode,FALSE,NULL);
    }
    else
    {
    status = IoStatus.Status;
    }
    }
    // return IRP completion status
    // DebugPrint("CallUSBDI returned %x",status);
    return status;
    }
    NTSTATUS
    USBDCompletionRoutine(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp,
    IN PVOID Context)
    {
    PKEVENT pEvent = (PKEVENT)Context;
    KeSetEvent(pEvent, 0, FALSE);
    return STATUS_MORE_PROCESSING_REQUIRED;
    }
    NTSTATUS UsbGetData( IN PUSBPS_DEVICE_EXTENSION dx)
    {
    // Allocate memory for URB

    UCHAR retryCount = 0;

    USHORT UrbSize = sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER);
    PURB urb = (PURB)ExAllocatePool(NonPagedPool, UrbSize);
    if( urb==NULL)
    {
    DebugPrint("No URB memory");
    return STATUS_INSUFFICIENT_RESOURCES;
    }

    ULONG sizeBuffer;
    PUCHAR dataBuffer;

    sizeBuffer = 64;
    dataBuffer = (PUCHAR)ExAllocatePool(NonPagedPool, sizeBuffer);

    if( dataBuffer==NULL)
    {
    ExFreePool(urb);
    DebugPrint("No buffer memory");
    return STATUS_INSUFFICIENT_RESOURCES;
    }

    // Build the Get Descriptor URB

    checkSendData:
    UsbBuildInterruptOrBulkTransferRequest(
    urb,
    UrbSize,
    dx->UsbDataInHandle, //Pipe Handler
    dataBuffer, //buffer
    NULL, //MDL
    sizeBuffer, //size
    USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK ,//TransferFlags
    NULL // link
    );
    // Call the USB driver
    NTSTATUS status = CallUSBDI( dx, urb );
    // Check statuses
    if( !USBD_SUCCESS( urb->UrbHeader.Status))
    {
    DebugPrint("status %x URB status %x", status, urb->UrbHeader.Status);
    status = STATUS_UNSUCCESSFUL;
    if ( retryCount < 3 )
    {
    DebugPrint("USB get data failed:retry");
    retryCount ++;
    goto checkSendData;
    }
    }

    ExFreePool(urb);
    ExFreePool(dataBuffer );

    return status;
    }

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,632

    Re: help,problems difficult to solve

    Ok so you manage to find this site but you consider yourself way to important to spend some time reading about the board and how to post code using code tags. Now ask yourself why anybody here should spend his time trying the decipher your code in order to understand your problem enough to help you...
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center