Export (0) Print
Expand All
Expand Minimize

WdfUsbTargetDeviceFormatRequestForUrb method

[Applies to KMDF only]

The WdfUsbTargetDeviceFormatRequestForUrb method builds an USB request for a specified USB device, using request parameters that are described by a URB, but it does not send the request.

Syntax


NTSTATUS WdfUsbTargetDeviceFormatRequestForUrb(
  [in]            WDFUSBDEVICE UsbDevice,
  [in]            WDFREQUEST Request,
  [in]            WDFMEMORY UrbMemory,
  [in, optional]  PWDFMEMORY_OFFSET UrbMemoryOffset
);

Parameters

UsbDevice [in]

A handle to a USB device object that was obtained from a previous call to WdfUsbTargetDeviceCreateWithParameters.

Request [in]

A handle to a framework request object. For more information, see the following Remarks section.

UrbMemory [in]

A handle to a framework memory object that contains a URB structure or one of the structure's union members. (All of the URB structure's union members contain the _URB_HEADER 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. Otherwise, a bug check occurs.

UrbMemoryOffset [in, optional]

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

WdfUsbTargetDeviceFormatRequestForUrb returns STATUS_SUCCESS if the operation succeeds. Otherwise, this method can return one of the following values:

Return codeDescription
STATUS_INVALID_PARAMETER

An invalid parameter was detected.

STATUS_INSUFFICIENT_RESOURCES

There was insufficient memory.

STATUS_INTEGER_OVERFLOW

The offset that the UsbMemoryOffset parameter specified was invalid.

 

This method also might return other NTSTATUS values.

A bug check occurs if the driver supplies an invalid object handle.

Remarks

Use WdfUsbTargetDeviceFormatRequestForUrb, followed by WdfRequestSend, to send a USB control transfer request either synchronously or asynchronously. Alternatively, use the WdfUsbTargetDeviceSendUrbSynchronously method to send a request synchronously.

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 WdfUsbTargetDeviceFormatRequestForUrb method's Request parameter.

To create a new I/O request, call WdfRequestCreate to preallocate a request object. Supply the request handle for the WdfUsbTargetDeviceFormatRequestForUrb method's Request parameter. You can reuse the request object by calling WdfRequestReuse. Your driver's EvtDriverDeviceAdd callback function can preallocate request objects for a device.

After calling WdfUsbTargetDeviceFormatRequestForUrb to format an I/O request, the driver must call WdfRequestSend to send the request (either synchronously or asynchronously) to an I/O target. Do not use the send and forget option to send the request.

Multiple calls to WdfUsbTargetDeviceFormatRequestForUrb 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 WdfUsbTargetDeviceFormatRequestForUrb), 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 WdfUsbTargetDeviceFormatRequestForUrb 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 WdfUsbTargetDeviceFormatRequestForUrb method and USB I/O targets, see USB I/O Targets.

Examples

The following code example creates a memory object to hold a URB structure, initializes the URB structure, and calls WdfUsbTargetDeviceFormatRequestForUrb to format a request that uses the URB structure's contents. Then, the example registers a CompletionRoutine callback function and sends the request to an I/O target.


WDFMEMORY urbMemory;
URB *urbBuffer;

status = WdfMemoryCreate(
                         WDF_NO_OBJECT_ATTRIBUTES,
                         NonPagedPool,
                         0,
                         sizeof(struct _URB_CONTROL_GET_CONFIGURATION_REQUEST),
                         &urbMemory,
                         NULL
                         );

if (!NT_SUCCESS(status)){
    return status;
}
urbBuffer = (PURB) WdfMemoryGetBuffer(
                                      urbMemory,
                                      NULL
                                      );
urbBuffer->UrbHeader.Function =  URB_FUNCTION_GET_CONFIGURATION;
urbBuffer->UrbHeader.Length = sizeof(struct _URB_CONTROL_GET_CONFIGURATION_REQUEST);
urbBuffer->UrbControlGetConfigurationRequest.TransferBufferLength = 1 ;
urbBuffer->UrbControlGetConfigurationRequest.TransferBufferMDL = NULL;
urbBuffer->UrbControlGetConfigurationRequest.TransferBuffer = outBuffer;
urbBuffer->UrbControlGetConfigurationRequest.UrbLink = NULL;

status = WdfUsbTargetDeviceFormatRequestForUrb(
                                               deviceContext->WdfUsbTargetDevice,
                                               request,
                                               urbMemory,
                                               NULL
                                               );
WdfRequestSetCompletionRoutine(
                              request,
                              MyCompletionRoutine,
                              NULL);

if (WdfRequestSend(
                   request,
                   WdfUsbTargetDeviceGetIoTarget(UsbDevice),
                   NULL
                   ) == FALSE) {
    status = WdfRequestGetStatus(request);
}

Requirements

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, KmdfIrql, KmdfIrql2, RequestFormattedValid, RequestSendAndForgetNoFormatting, RequestSendAndForgetNoFormatting2, UsbKmdfIrql, UsbKmdfIrql2

See also

EvtDriverDeviceAdd
WDFMEMORY_OFFSET
WdfRequestReuse
WdfRequestSend
WdfUsbTargetDeviceCreateWithParameters
WdfUsbTargetDeviceSendUrbSynchronously

 

 

Send comments about this topic to Microsoft

Show:
© 2014 Microsoft