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:
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.
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:
Obtains a device's USB device descriptor.
Obtains the number of USB interfaces that the device supports.
Obtains a pointer to a IWDFUsbInterface interface that exposes one of the USB interfaces that the device supports.
Retrieves capability information that is associated with a USB device.
Retrieves a WinUsb power policy.
Obtains the WinUsb interface handle that is associated with the I/O target 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.
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.