阅读:2860回复:2
WDF的USB驱动,为何异步IO请求不进入完成回调函数?
在测试USB驱动的时候发现,WdfReqeustSend请求写设备时,前几次是成功的,之后就不会调用请求完成回调函数,
VOID EvtDeviceIoWrite( IN WDFQUEUE Queue, IN WDFREQUEST Request, IN size_t Length ) { size_t totalLength = Length; NTSTATUS status = STATUS_SUCCESS; PDEVICE_CONTEXT devCtx = NULL; WDFMEMORY requestMem; UCHAR * lpBuf; KdPrint((__DRIVER_NAME "EvtDeviceIoWrite - begin\n")); devCtx = GetDeviceContext(WdfIoQueueGetDevice(Queue)); KdPrint((__DRIVER_NAME "Received a write request of %d bytes\n", Length)); if (totalLength > devCtx->MaximumTransferSize) { KdPrint((__DRIVER_NAME "Transfer length > MaximunTransferSize(%d)\n", devCtx->MaximumTransferSize)); status = STATUS_INVALID_PARAMETER; goto Exit; } // Get the input memory for write status = WdfRequestRetrieveInputMemory(Request, &requestMem); if(!NT_SUCCESS(status)) { KdPrint((__DRIVER_NAME "WdfRequestRetrieveInputMemory failed with status 0x%08x\n", status)); goto Exit; } if (totalLength > MAX_TRANSFER_SIZE) { status = STATUS_CANCELLED; KdPrint((__DRIVER_NAME "Length>MaxTransferSize.this is bad request!!!!!!!failed with status 0x%08x\n", status)); goto Exit; } status = WdfUsbTargetPipeFormatRequestForWrite( devCtx->UsbBulkOutPipe, Request, requestMem, NULL); if(!NT_SUCCESS(status)) { KdPrint((__DRIVER_NAME "WdfUsbTargetPipeFormatRequestForWrite failed with status 0x%08x\n", status)); goto Exit; } WdfRequestSetCompletionRoutine(Request, EvtIoWriteComplete, devCtx->UsbBulkOutPipe); //设置请求完成回调函数 if(FALSE == WdfRequestSend(Request, /*WdfUsbTargetPipeGetIoTarget(devCtx->UsbBulkOutPipe)*/WdfDeviceGetIoTarget(WdfIoQueueGetDevice(Queue)), /*WDF_NO_SEND_OPTIONS*/ &options)) //发送请求,前两次能够完成,正常进入请求完成回调函数,之后不进入,直接进入EXIT,应用程序阻塞在WriteFile { status = WdfRequestGetStatus(Request); KdPrint((__DRIVER_NAME "WdfRequestSend failed with status 0x%08x\n", status)); } else { status = WdfRequestGetStatus(Request); KdPrint((__DRIVER_NAME "WdfRequestSend finished with status 0x%08x\n",status)); } Exit: if (!NT_SUCCESS(status)) { WdfRequestCompleteWithInformation(Request, status, 0); } KdPrint((__DRIVER_NAME "EvtDeviceIoWrite - ends with status 0x%08x\n",status)); } VOID EvtIoWriteComplete( IN WDFREQUEST Request, IN WDFIOTARGET Target, IN PWDF_REQUEST_COMPLETION_PARAMS Params, IN WDFCONTEXT Context) { PWDF_USB_REQUEST_COMPLETION_PARAMS usbCompletionParams; NTSTATUS status; ULONG_PTR ulLen; LONG * lpBuf; UNREFERENCED_PARAMETER(Context); UNREFERENCED_PARAMETER(Target); usbCompletionParams = Params->Parameters.Usb.Completion; status = Params->IoStatus.Status; ulLen = usbCompletionParams->Parameters.PipeWrite.Length; if(NT_SUCCESS(status)) { KdPrint((__DRIVER_NAME "Completed the write request with %d bytes\n", usbCompletionParams->Parameters.PipeWrite.Length)); } else { KdPrint((__DRIVER_NAME "Failed the write request with status 0x%08x\n", Params->IoStatus.Status)); } WdfRequestCompleteWithInformation(Request, Params->IoStatus.Status, ulLen); } 请教大家,这是怎么回事呢?谢谢。 |
|
沙发#
发布于:2010-12-02 09:09
自顶,没人遇到过这种情况吗?
|
|
板凳#
发布于:2010-12-03 09:30
根你顶下,我看了下你的程序,既然驱动都能够运行到WdfRequestCompleteWithInformation你的应用程序因该能正常退出阿,还有WdfDeviceGetIoTarget这个恐怕有点问题哦!USB要用USB专用的WDF函数吧
|
|