I am having a stringe problem for my Windows 2000 Usb driver. When i am
reading data from the usb device, sometimes the Iocalldriver never sets
the event i am waiting for. Notice that this only happens sometimes,
and only on one specific computer. Windows XP on that computer does not
have this issue.
The code is:
--START CODE--
UsbBuildInterruptOrBulkTransferRequest(
¤t->dUrb,
sizeof(_URB_BULK_OR_INTERRUPT_TRANSFER),
pdx->myPipe,
&buffer->data,
NULL,
pdx->bufferChunkSize,
USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK,
NULL
);
KeInitializeEvent(¤t->dEvent, NotificationEvent, FALSE);
current->dIrp = IoBuildDeviceIoControlRequest(
IOCTL_INTERNAL_USB_SUBMIT_URB,
pdx->LowerDeviceObject,
NULL,
0,
InputBufferLength
NULL,
OutputBuffer
0,
OutputBufferLength
TRUE,
InternalDeviceIoControl
¤t->dEvent,
¤t->dIostatus
);
if (!current->dIrp)
{
KdPrint((DRIVERNAME " - IN Pollingthread: Unable to allocate IRP for
sending URB\n"));
goto endThread;
}
stack = IoGetNextIrpStackLocation(current->dIrp);
stack->Parameters.Others.Argument1 = (PVOID) (PURB) ¤t->dUrb;
status = IoCallDriver(pdx->LowerDeviceObject, current->dIrp);
if (!NT_SUCCESS(status))
{
KdPrint((DRIVERNAME " - IN Pollingthread: IoCallDriver 1 failed with
error code: %8.8X\n",status));
InterlockedExchange(&pdx->error, status);
KeSetEvent(&pdx->errorEvent, 0, FALSE);
goto endThread;
}
if(status != STATUS_PENDING)
{
KdPrint((DRIVERNAME " - IN Pollingthread: IoCallDriver did not return
STATUS_PENDING, instead it returned: %8.8X\n",status));
goto endThread;
}
status = KeWaitForMultipleObjects(
2,
current->dCompleteEvents,
WaitAny,
Executive,
KernelMode,
WaitMode
FALSE,
NULL,
NULL
);
--END CODE--
So, sometimes the KeWaitForMultipleObjects does not get released until
i manually unplugg the device and the error event is set. Can anyone
see anything in the code that might cause this to work sometimes and
sometimes not?
Regards
Wilhelm