Erweitern Minimieren

WdfUsbTargetDeviceSelectConfig method

[Applies to KMDF and UMDF]

The WdfUsbTargetDeviceSelectConfig method selects a USB configuration for a device, or it deconfigures the device.

Syntax


NTSTATUS WdfUsbTargetDeviceSelectConfig(
  [in]            WDFUSBDEVICE UsbDevice,
  [in, optional]  PWDF_OBJECT_ATTRIBUTES PipeAttributes,
  [in, out]       PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS Params
);

Parameters

UsbDevice [in]

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

PipeAttributes [in, optional]

A pointer to a caller-allocated WDF_OBJECT_ATTRIBUTES structure that contains attributes for new framework USB pipe objects that the framework creates for the device's interfaces. For KMDF drivers, this parameter is optional and can be WDF_NO_OBJECT_ATTRIBUTES. UMDF drivers must set this parameter to NULL.

Params [in, out]

A pointer to a caller-allocated WDF_USB_DEVICE_SELECT_CONFIG_PARAMS structure that the caller and the framework use to specify configuration parameters.

Return value

WdfUsbTargetDeviceSelectConfig returns the I/O target's completion status value 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_INFO_LENGTH_MISMATCH

The Size member of the WDF_USB_DEVICE_SELECT_CONFIG_PARAMS structure that Params points to was incorrect.

STATUS_INSUFFICIENT_RESOURCES

A memory buffer could not be allocated.

STATUS_NOT_SUPPORTED

The framework returns this value if a UMDF driver calls WdfUsbTargetDeviceSelectConfig with Params->Type set to any of the following:

  • WdfUsbTargetDeviceSelectConfigTypeDeconfig
  • WdfUsbTargetDeviceSelectConfigTypeInterfacesDescriptor
  • WdfUsbTargetDeviceSelectConfigTypeUrb

For more info, see WdfUsbTargetDeviceSelectConfigType.

 

This method also might return other NTSTATUS values.

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

Remarks

Your driver can select a device configuration by using a WDF_USB_DEVICE_SELECT_CONFIG_PARAMS structure to specify USB descriptors, a URB, or handles to framework USB interface objects.

The framework creates a framework USB pipe object for each pipe that is associated with each interface in the configuration, after deleting any pipe objects that the framework might have previously created for the configuration. The framework uses alternate setting zero for each interface, unless the driver specifies a different alternate setting.

To obtain information about an interface's pipe objects, the driver can call WdfUsbInterfaceGetNumConfiguredPipes and WdfUsbInterfaceGetConfiguredPipe.

For more information about the WdfUsbTargetDeviceSelectConfig method and USB I/O targets, see USB I/O Targets.

Caution  

You can use WdfUsbTargetDeviceSelectConfig to select only the first USB configuration listed in the descriptor list, but you can select multiple interfaces within this single configuration.

Examples

The following code example selects a configuration with a single, specified interface.


WDF_USB_DEVICE_SELECT_CONFIG_PARAMS  configParams;
NTSTATUS  status;

WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACE(&configParams);

status = WdfUsbTargetDeviceSelectConfig(
                                        UsbDevice,
                                        WDF_NO_OBJECT_ATTRIBUTES,
                                        &configParams
                                        );

The following code example selects a configuration with multiple interfaces, using alternate setting zero on all interfaces. This example applies only to KMDF drivers.


WDF_USB_DEVICE_SELECT_CONFIG_PARAMS  configParams;
PWDF_USB_INTERFACE_SETTING_PAIR settingPairs;
UCHAR numInterfaces;
NTSTATUS  status;

numInterfaces = WdfUsbTargetDeviceGetNumInterfaces(UsbDevice);

settingPairs = ExAllocatePoolWithTag(
    PagedPool,
    sizeof(WDF_USB_INTERFACE_SETTING_PAIR) * numInterfaces,
    MY_DRIVER_TAG
);

if (settingPairs == NULL){
    return STATUS_INSUFFICIENT_RESOURCES;
}

for (interfaceIndex = 0; interfaceIndex < numInterfaces; interfaceIndex++) {
        
    settingPairs[interfaceIndex].UsbInterface = 
                                    WdfUsbTargetDeviceGetInterface(
                                        UsbDevice,
                                        interfaceIndex);

    // Select alternate setting zero on all interfaces.
       
    settingPairs[interfaceIndex].SettingIndex = 0;
}

WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_MULTIPLE_INTERFACES(
    &configParams,
    numInterfaces,
    settingPairs
);

status = WdfUsbTargetDeviceSelectConfig(
    UsbDevice,
    NULL,
    &configParams
);

if (!NT_SUCCESS(status)) {
    ExFreePoolWithTag(
        settingPairs,
        MY_DRIVER_TAG
    );
    return status;
}

Requirements

Minimum KMDF version

1.0

Minimum UMDF version

2.0

Header

Wdfusb.h (include Wdfusb.h)

Library

Wdf01000.sys (KMDF);
WUDFx02000.dll (UMDF)

IRQL

PASSIVE_LEVEL

DDI compliance rules

DriverCreate, KmdfIrql, KmdfIrql2, UsbKmdfIrql, UsbKmdfIrql2

See also

WDF_OBJECT_ATTRIBUTES
WDF_USB_DEVICE_SELECT_CONFIG_PARAMS
WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACE
WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_MULTIPLE_INTERFACES
WdfUsbInterfaceGetConfiguredPipe
WdfUsbInterfaceGetNumConfiguredPipes
WdfUsbTargetDeviceCreateWithParameters

 

 

Send comments about this topic to Microsoft

Anzeigen:
© 2014 Microsoft