Working with USB Devices in UMDF 1.x Drivers

[This topic applies to UMDF 1.x.]

The framework represents each USB device as a framework USB device object. A UMDF driver must create a framework USB device object before the driver can access the framework's support for USB I/O targets. UMDF provides USB device object methods that enable a UMDF driver to:

Creating a UMDF-USB Device Object

To use the framework's USB I/O target capabilities, a UMDF driver must first obtain a pointer to the IWDFUsbTargetFactory interface. To obtain the pointer, the driver must call the QueryInterface method of the device's IWDFDevice interface. The following code example shows how to call QueryInterface to obtain the pointer:


hr = pdevice->QueryInterface(IID_IWDFUsbTargetFactory, (LPVOID*)&ppUsbTargetFactory);

The driver must next call the IWDFUsbTargetFactory::CreateUsbTargetDevice method to create a USB I/O target object for the device. After the driver creates the USB I/O target, the driver can send requests to the I/O target. Typically, drivers call IWDFUsbTargetFactory::CreateUsbTargetDevice from within an IPnpCallbackHardware::OnPrepareHardware callback function.

After the driver calls IWDFUsbTargetFactory::CreateUsbTargetDevice, the driver can obtain USB device information (for example, USB descriptors for the device, USB interfaces, and interface endpoints). The USB descriptors are described in the USB specification.

Obtaining UMDF-USB Device Information

After a UMDF driver calls the IWDFUsbTargetFactory::CreateUsbTargetDevice method to create a UMDF-USB target device object, the driver can call the following methods that the USB target device object defines for obtaining information about a USB device:

IWDFUsbTargetDevice::RetrieveDescriptor

Obtains a device's USB device descriptor.

IWDFUsbTargetDevice::GetNumInterfaces

Obtains the number of USB interfaces that the device supports.

IWDFUsbTargetDevice::RetrieveUsbInterface

Obtains a pointer to a IWDFUsbInterface interface that exposes one of the USB interfaces that the device supports.

IWDFUsbTargetDevice::RetrieveDeviceInformation

Retrieves capability information that is associated with a USB device.

IWDFUsbTargetDevice::RetrievePowerPolicy

Retrieves a WinUsb power policy.

IWDFUsbTargetDevice::GetWinUsbHandle

Obtains the WinUsb interface handle that is associated with the I/O target device object.

Sending a Control Transfer to a UMDF-USB Device Object

A UMDF driver can call the IWDFUsbTargetDevice::FormatRequestForControlTransfer method to format an I/O request that describes a standard, device-class-specific, or vendor-specific USB control transfer. The driver can then call the IWDFIoRequest::Send method to send the request synchronously or asynchronously.

Setting Power Policy for a UMDF-USB Device

A UMDF driver can call the IWDFUsbTargetDevice::SetPowerPolicy method to set the power policy that is used by WinUsb for a USB device. The power policy for a USB device effects changes to power management states for the device.

 

 

Send comments about this topic to Microsoft

Show:
© 2014 Microsoft