WdfUsbTargetPipeFormatRequestForUrb function (wdfusb.h)
[Applies to KMDF only]
The WdfUsbTargetPipeFormatRequestForUrb method builds an USB request for a specified USB pipe, using request parameters that a specified URB describes, but it does not send the request.
Syntax
NTSTATUS WdfUsbTargetPipeFormatRequestForUrb(
WDFUSBPIPE PIPE,
[in] WDFREQUEST Request,
[in] WDFMEMORY UrbMemory,
[in, optional] PWDFMEMORY_OFFSET UrbMemoryOffset
);
Parameters
PIPE
A handle to a framework pipe object that was obtained by calling WdfUsbInterfaceGetConfiguredPipe.
[in] Request
A handle to a framework request object. For more information, see the following Remarks section.
[in] UrbMemory
A handle to a framework memory object that contains a URB structure.
If the driver previously called WdfUsbTargetDeviceCreateWithParameters to create UsbDevice, the driver must use WdfUsbTargetDeviceCreateUrb or WdfUsbTargetDeviceCreateIsochUrb to create the URB contained in this memory object.
[in, optional] UrbMemoryOffset
A pointer to a caller-allocated WDFMEMORY_OFFSET structure that supplies optional byte offset and length values. The framework uses these values to determine the beginning address of the URB within the memory that UrbMemory specifies. If this pointer is NULL, the URB is located at the beginning of the UrbMemory memory.
Return value
WdfUsbTargetPipeFormatRequestForUrb returns the I/O target's completion status value if the operation succeeds. Otherwise, this method can return one of the following values:
Return code | Description |
---|---|
|
An invalid parameter was detected. |
|
Insufficient memory was available. |
|
The offset that the UsbMemoryOffset parameter specified was invalid. |
|
The I/O request packet (IRP) that the Request parameter represents does not provide enough IO_STACK_LOCATION structures to allow the driver to forward the request. |
This method also might return other NTSTATUS values.
A bug check occurs if the driver supplies an invalid object handle.
Remarks
Use WdfUsbTargetPipeFormatRequestForUrb, followed by WdfRequestSend, to send a USB request either synchronously or asynchronously. Alternatively, use the WdfUsbTargetPipeSendUrbSynchronously method to send a request synchronously.
The framework does not examine the USB request. If the request changes the state of the USB pipe, the framework will not be aware of the change.
You can forward an I/O request that your driver received in an I/O queue, or you can create and send a new request.
To forward an I/O request that your driver received in an I/O queue, specify the received request's handle for the WdfUsbTargetPipeFormatRequestForUrb method's Request parameter.
To create a new I/O request, call WdfRequestCreate to preallocate a request object. Supply the request handle for the WdfUsbTargetPipeFormatRequestForUrb method's Request parameter. You can reuse the request object by calling WdfRequestReuse, so your driver's EvtDriverDeviceAdd callback function can preallocate request objects for a device.
After calling WdfUsbTargetPipeFormatRequestForUrb to format an I/O request, the driver must call WdfRequestSend to send the request (either synchronously or asynchronously) to an I/O target.
Multiple calls to WdfUsbTargetPipeFormatRequestForUrb that use the same request do not cause additional resource allocations. Therefore, to reduce the chance that WdfRequestCreate will return STATUS_INSUFFICIENT_RESOURCES, your driver's EvtDriverDeviceAdd callback function can call WdfRequestCreate to preallocate one or more request objects for a device. The driver can subsequently reuse (call WdfRequestReuse), reformat (call WdfUsbTargetPipeFormatRequestForUrb), and resend (call WdfRequestSend) each request object without risking a STATUS_INSUFFICIENT_RESOURCES return value from a later call to WdfRequestCreate. All subsequent calls to WdfUsbTargetPipeFormatRequestForUrb for the reused request object will return STATUS_SUCCESS, if parameter values do not change. (If the driver does not call the same request-formatting method each time, additional resources might be allocated.)
For information about obtaining status information after an I/O request completes, see Obtaining Completion Information.
For more information about the WdfUsbTargetPipeFormatRequestForUrb method and USB I/O targets, see USB I/O Targets.
Examples
The following code example creates a memory object that represents a URB. Then, the example initializes the URB, formats a USB request that contains the URB, registers a CompletionRoutine callback function, and sends the request.
URB urb;
PURB pUrb = NULL;
WDFMEMORY urbMemory
NTSTATUS status;
status = WdfMemoryCreate(
WDF_NO_OBJECT_ATTRIBUTES,
NonPagedPool,
0,
sizeof(struct _URB_GET_CURRENT_FRAME_NUMBER),
&urbMemory,
NULL
);
if (!NT_SUCCESS(status)){
return status;
}
pUrb = WdfMemoryGetBuffer(
urbMemory,
NULL
);
pUrb->UrbHeader.Length = (USHORT) sizeof(struct _URB_GET_CURRENT_FRAME_NUMBER);
pUrb->UrbHeader.Function = URB_FUNCTION_GET_CURRENT_FRAME_NUMBER;
pUrb->UrbGetCurrentFrameNumber.FrameNumber = 0;
status = WdfUsbTargetPipeFormatRequestForUrb(
pipe,
Request,
urbMemory,
NULL
);
if (!NT_SUCCESS(status)) {
goto Exit;
}
WdfRequestSetCompletionRoutine(
Request,
UrbCompletionRoutine,
pipe
);
if (WdfRequestSend(
Request,
WdfUsbTargetPipeGetIoTarget(pipe),
WDF_NO_SEND_OPTIONS
) == FALSE) {
status = WdfRequestGetStatus(Request);
goto Exit;
}
Exit:
if (!NT_SUCCESS(status)) {
WdfRequestCompleteWithInformation(
Request,
status,
0
);
}
return;
Requirements
Requirement | Value |
---|---|
Target Platform | Universal |
Minimum KMDF version | 1.0 |
Header | wdfusb.h (include Wdfusb.h) |
Library | Wdf01000.sys (see Framework Library Versioning.) |
IRQL | <=DISPATCH_LEVEL |
DDI compliance rules | DriverCreate(kmdf), KmdfIrql(kmdf), KmdfIrql2(kmdf), KmdfIrqlExplicit(kmdf), RequestFormattedValid(kmdf), RequestSendAndForgetNoFormatting(kmdf), RequestSendAndForgetNoFormatting2(kmdf), UsbKmdfIrql(kmdf), UsbKmdfIrql2(kmdf), UsbKmdfIrqlExplicit(kmdf) |
See also
WdfRequestCompleteWithInformation