Accessing URBs from the Continuous Reader CompletionRoutine

This seems like a stupid question, but I have to ask…

Can I access the URBs for each transfer from the EvtUsbContinuousReaderComplete Callback Function? If such a thing is allowed, how do I go about it?

Nope. Why do you need them? What problem are you trying to solve?

d

debt from my phone

-----Original Message-----
From: xxxxx@razerzone.com
Sent: Thursday, June 09, 2011 6:03 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Accessing URBs from the Continuous Reader CompletionRoutine

This seems like a stupid question, but I have to ask…

Can I access the URBs for each transfer from the EvtUsbContinuousReaderComplete Callback Function? If such a thing is allowed, how do I go about it?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

xxxxx@razerzone.com wrote:

This seems like a stupid question, but I have to ask…

Can I access the URBs for each transfer from the EvtUsbContinuousReaderComplete Callback Function? If such a thing is allowed, how do I go about it?

I believe the framework tries to abstract that away, so they are not
necessarily tied to a one-callback-per-URB limitation. What are you
hoping to learn from the URB?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

When I try to access the buffer for the WdfMemory passed to the evtusbtargetreadercomplete, I get a buffer length of zero. Similarly when I try the copy the wdfmemory to a buffer that too fails for obvious reasons. BUT the numbytestransferred arguement shows that 8 bytes have been transferred. So the question is, where are those bytes?

Post your code. Also, you can break in and run !wdfkd.wdfmemory and get underlying info.

d

debt from my phone

-----Original Message-----
From: xxxxx@razerzone.com
Sent: Thursday, June 09, 2011 7:17 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Accessing URBs from the Continuous Reader CompletionRoutine

When I try to access the buffer for the WdfMemory passed to the evtusbtargetreadercomplete, I get a buffer length of zero. Similarly when I try the copy the wdfmemory to a buffer that too fails for obvious reasons. BUT the numbytestransferred arguement shows that 8 bytes have been transferred. So the question is, where are those bytes?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

CODE:
VOID
EvtUsbTargetPipeReadComplete (
IN WDFUSBPIPE arg_objPipe,
IN WDFMEMORY arg_objBuffer,
IN size_t arg_dNumBytesTransferred,
IN WDFCONTEXT arg_objContext
)
{
NTSTATUS status;
WDF_IO_QUEUE_STATE queue_state;
PDEVICE_CONTEXT pDeviceContext;
WDFREQUEST objRequest;
WDFMEMORY objDataBuffer;
WDF_REQUEST_PARAMETERS objRequestParameters;
PURB pUrbBuffer = NULL;
ULONG dNumRequests = 0;
ULONG dBytesRead = 0;

BOOLEAN bCompleteRequest = FALSE;

BYTE * pDataPtr = NULL;
BYTE * pBufPtr = NULL;
size_t buf_len = 0;

pDeviceContext = (PDEVICE_CONTEXT)(arg_objContext);

WdfSpinLockAcquire ( pDeviceContext->objSpinLock );
status = WdfIoQueueRetrieveNextRequest (
pDeviceContext->objManualQueue,
&objRequest
);
if ( NT_SUCCESS(status) )
{
WDF_REQUEST_PARAMETERS_INIT(&objRequestParameters);
WdfRequestGetParameters ( objRequest, &objRequestParameters );

pUrbBuffer = objRequestParameters.Parameters.Others.Arg1;

pBufPtr = pUrbBuffer->UrbBulkOrInterruptTransfer.TransferBuffer;
buf_len = pUrbBuffer->UrbBulkOrInterruptTransfer.TransferBufferLength;

if ( pBufPtr )
{
status = WdfMemoryCopyToBuffer (
arg_objBuffer,
0,
pBufPtr,
buf_len
);
if (NT_SUCCESS(status))
{
WdfRequestComplete ( objRequest, status );
}
}
}
More…
END CODE

The WdfMemoryCopyToBuffer fails with STATUS_BUFFER_TOO_SMALL. also the !wdfmemory for arg_objBuffer is as follows:

WDFMEMORY 0x0000057ff7fc2178: Buffer 0xfffffa800803de80, Length 0x0 (0) bytes
allocated from WDFLOOKASIDE 0xfffffffffffffff8

Also the transfer type is a BulkOrInterruptTransfer (Interrupt Transfer).

Are you a lower filter below a USB fdo client driver? Why do you have a queue of requests that have urbs in them? Should the length to copy be dNumBytesTransferred, not buf_len? What size buffer did you configure the cont reader buffer with?

d

debt from my phone

-----Original Message-----
From: xxxxx@razerzone.com
Sent: Thursday, June 09, 2011 8:02 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Accessing URBs from the Continuous Reader CompletionRoutine

CODE:
VOID
EvtUsbTargetPipeReadComplete (
IN WDFUSBPIPE arg_objPipe,
IN WDFMEMORY arg_objBuffer,
IN size_t arg_dNumBytesTransferred,
IN WDFCONTEXT arg_objContext
)
{
NTSTATUS status;
WDF_IO_QUEUE_STATE queue_state;
PDEVICE_CONTEXT pDeviceContext;
WDFREQUEST objRequest;
WDFMEMORY objDataBuffer;
WDF_REQUEST_PARAMETERS objRequestParameters;
PURB pUrbBuffer = NULL;
ULONG dNumRequests = 0;
ULONG dBytesRead = 0;

BOOLEAN bCompleteRequest = FALSE;

BYTE * pDataPtr = NULL;
BYTE * pBufPtr = NULL;
size_t buf_len = 0;

pDeviceContext = (PDEVICE_CONTEXT)(arg_objContext);

WdfSpinLockAcquire ( pDeviceContext->objSpinLock );
status = WdfIoQueueRetrieveNextRequest (
pDeviceContext->objManualQueue,
&objRequest
);
if ( NT_SUCCESS(status) )
{
WDF_REQUEST_PARAMETERS_INIT(&objRequestParameters);
WdfRequestGetParameters ( objRequest, &objRequestParameters );

pUrbBuffer = objRequestParameters.Parameters.Others.Arg1;

pBufPtr = pUrbBuffer->UrbBulkOrInterruptTransfer.TransferBuffer;
buf_len = pUrbBuffer->UrbBulkOrInterruptTransfer.TransferBufferLength;

if ( pBufPtr )
{
status = WdfMemoryCopyToBuffer (
arg_objBuffer,
0,
pBufPtr,
buf_len
);
if (NT_SUCCESS(status))
{
WdfRequestComplete ( objRequest, status );
}
}
}
More…
END CODE

The WdfMemoryCopyToBuffer fails with STATUS_BUFFER_TOO_SMALL. also the !wdfmemory for arg_objBuffer is as follows:

WDFMEMORY 0x0000057ff7fc2178: Buffer 0xfffffa800803de80, Length 0x0 (0) bytes
allocated from WDFLOOKASIDE 0xfffffffffffffff8


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

Yes

Its a manual queue, also the MemoryCopy fails for other WdfMemory objects all the same.

Yes it should be, however technically they should be equal.

If you are refering to the Transferlength I think I initialized it with the MaximumPacketLength in the USBpipeInfo. If I initialize it to the single packet legth (8 bytes), the ConfigContinuousReader fails with INVALID_BUFFER_SIZE status

> If you are refering to the Transferlength I think I initialized it with the MaximumPacketLength in the USBpipeInfo. If I initialize it to the single packet legth (8 bytes), the ConfigContinuousReader fails with INVALID_BUFFER_SIZE status

This field is ignored starting with XP. It is probably zero and probably the reason why you are seeing zero sized buffers (also probably a minor bug that KMDF allows you specify a length of zero). If you are sending reads of single packet length, you are communicating with the device very inefficiently. Packet length is just a piece of wire protocol information that the HC uses to talk to the device, it should not be the size of the buffer of each transfer from the host.

With that said, this assumption
Yes it should be, however technically they should be equal.

Is incorrect and would probably not be equal. pUrbBuffer->UrbBulkOrInterruptTransfer.TransferBufferLength (buf_len) is the maximum size of the buffer to read in. since the short transfer OK flag is set, the resulting number of bytes returned can be smaller than the size of the buffer itself

The size of the buffer you specify in the cont reader configuration should be the max buffer size that the over the wire protocol can send, not the max packet size

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@razerzone.com
Sent: Thursday, June 09, 2011 9:07 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Accessing URBs from the Continuous Reader CompletionRoutine

Yes

Its a manual queue, also the MemoryCopy fails for other WdfMemory objects all the same.

Yes it should be, however technically they should be equal.

If you are refering to the Transferlength I think I initialized it with the MaximumPacketLength in the USBpipeInfo. If I initialize it to the single packet legth (8 bytes), the ConfigContinuousReader fails with INVALID_BUFFER_SIZE status


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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