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;
}
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...