BytesRead in WdfUsbTargetPipeReadSynchronously

Hi All,

I’m using WDF v1.5 from WinDDK 6000, compiling on a WinXP machine, running on a Win2K machine, and I’m having trouble with the BytesRead variable returned by WdfUsbTargetPipeReadSynchronously. I believe it is similar to the problem mentioned in the thread from Oct 6, 2006 titled “BytesWritten in WdfUsbTargetPipeWriteSynchronously”.

BytesRead gets set to 4, but I’m only expecting 1 byte. However, I do see the expected 1 when I check the PipeRead.Length value in the WDF_USB_REQUEST_COMPLETION_PARAMS. Shouldn’t these two parameters give me the same value?

Following Doron’s advice, I set the debugger to break when BytesRead is written. The break point triggers twice when I execute WdfUsbTargetPipeReadSynchronously. The first break clearly initializes BytesRead to 0 and the second fills it with [ebp-44h]. Is this correct or could my setup somehow contain corrupted or mismatched versions?

I’ve included below part of the code from the EvtIoDeviceControl function that handles this request. Can anyone see something I’ve
done wrong? Is there anything else I should be trying or checking?

Thanks, Wendy Tucker / Symmetric Research

WDFUSBPIPE PipeEp6In;
WDFMEMORY Memory;
WDF_MEMORY_DESCRIPTOR MemoryDesc;
WDF_REQUEST_SEND_OPTIONS RequestSendOptions;
WDF_REQUEST_COMPLETION_PARAMS CompletionParams;
WDF_USB_REQUEST_COMPLETION_PARAMS *UsbCompletionParams;
size_t BytesRead, CpBytesRead;

Status = WdfRequestRetrieveOutputMemory( Request, &Memory );
WDF_MEMORY_DESCRIPTOR_INIT_HANDLE( &MemoryDesc, Memory, NULL );
WDF_REQUEST_SEND_OPTIONS_INIT( &RequestSendOptions, 0 );

Status = WdfUsbTargetPipeReadSynchronously( PipeEp6In,
Request,
&RequestSendOptions,
&MemoryDesc,
&BytesRead
);

WDF_REQUEST_COMPLETION_PARAMS_INIT( &CompletionParams );
WdfRequestGetCompletionParams( Request, &CompletionParams );
UsbCompletionParams = CompletionParams.Parameters.Usb.Completion;
CpBytesRead = UsbCompletionParams->Parameters.PipeRead.Length;

WdfUsbTargetPipeWriteSynchronously shares the same implementation as
WdfUsbTargetPipeReadSynchronously, so yes the same bug applies. There
are 2 workarounds

  1. if you want to use your own request, use the Format call and then
    WdfRequestSend with the synchronous flag
  2. pass NULL for the request to WdfUsbTargetPipeReadSynchronously

HTH
d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@symres.com
Sent: Thursday, June 28, 2007 1:16 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] BytesRead in WdfUsbTargetPipeReadSynchronously

Hi All,

I’m using WDF v1.5 from WinDDK 6000, compiling on a WinXP machine,
running on a Win2K machine, and I’m having trouble with the BytesRead
variable returned by WdfUsbTargetPipeReadSynchronously. I believe it is
similar to the problem mentioned in the thread from Oct 6, 2006 titled
“BytesWritten in WdfUsbTargetPipeWriteSynchronously”.

BytesRead gets set to 4, but I’m only expecting 1 byte. However, I do
see the expected 1 when I check the PipeRead.Length value in the
WDF_USB_REQUEST_COMPLETION_PARAMS. Shouldn’t these two parameters give
me the same value?

Following Doron’s advice, I set the debugger to break when BytesRead is
written. The break point triggers twice when I execute
WdfUsbTargetPipeReadSynchronously. The first break clearly initializes
BytesRead to 0 and the second fills it with [ebp-44h]. Is this correct
or could my setup somehow contain corrupted or mismatched versions?

I’ve included below part of the code from the EvtIoDeviceControl
function that handles this request. Can anyone see something I’ve
done wrong? Is there anything else I should be trying or checking?

Thanks, Wendy Tucker / Symmetric Research

WDFUSBPIPE PipeEp6In;
WDFMEMORY Memory;
WDF_MEMORY_DESCRIPTOR MemoryDesc;
WDF_REQUEST_SEND_OPTIONS RequestSendOptions;
WDF_REQUEST_COMPLETION_PARAMS CompletionParams;
WDF_USB_REQUEST_COMPLETION_PARAMS *UsbCompletionParams;
size_t BytesRead, CpBytesRead;

Status = WdfRequestRetrieveOutputMemory( Request, &Memory );
WDF_MEMORY_DESCRIPTOR_INIT_HANDLE( &MemoryDesc, Memory, NULL );
WDF_REQUEST_SEND_OPTIONS_INIT( &RequestSendOptions, 0 );

Status = WdfUsbTargetPipeReadSynchronously( PipeEp6In,
Request,
&RequestSendOptions,
&MemoryDesc,
&BytesRead
);

WDF_REQUEST_COMPLETION_PARAMS_INIT( &CompletionParams );
WdfRequestGetCompletionParams( Request, &CompletionParams );
UsbCompletionParams = CompletionParams.Parameters.Usb.Completion;
CpBytesRead = UsbCompletionParams->Parameters.PipeRead.Length;


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Workaround #1 took care of the problem for me.
Thanks for your help, Wendy