qwerty_sz
驱动牛犊
驱动牛犊
  • 注册日期2009-04-20
  • 最后登录2012-06-28
  • 粉丝0
  • 关注0
  • 积分16分
  • 威望121点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:2860回复:2

WDF的USB驱动,为何异步IO请求不进入完成回调函数?

楼主#
更多 发布于:2010-12-01 15:59
在测试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);
}

请教大家,这是怎么回事呢?谢谢。
qwerty_sz
驱动牛犊
驱动牛犊
  • 注册日期2009-04-20
  • 最后登录2012-06-28
  • 粉丝0
  • 关注0
  • 积分16分
  • 威望121点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2010-12-02 09:09
自顶,没人遇到过这种情况吗?
lmingyi
驱动牛犊
驱动牛犊
  • 注册日期2010-10-25
  • 最后登录2011-04-13
  • 粉丝0
  • 关注0
  • 积分12分
  • 威望101点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2010-12-03 09:30
根你顶下,我看了下你的程序,既然驱动都能够运行到WdfRequestCompleteWithInformation你的应用程序因该能正常退出阿,还有WdfDeviceGetIoTarget这个恐怕有点问题哦!USB要用USB专用的WDF函数吧
游客

返回顶部