WDM Device Interfaces



Help, I am trying to use WDM Device Interfaces and I am more than a little confused.


WDM Device Interfaces

Win32 Driver Model introduces the concept of device interfaces. A device interface is an object that provides a defined set of IRP-based services, and is instantiated in a particular device object. The abstract functionality of a device interface is referred to as an interface class. For example, suppose an application needs the services of a Toaster, but doesn't know the name of a particular device that provides the standard services that all Toaster devices support. On WDM systems, the application can query the operating system for the names (actually, symbolic links) of all devices that have registered instances of the Toaster interface class. In order to query for the devices that provide a particular interface class, the application must know the GUID that identifies the class. Once an application has obtained a symbolic link to a device that supports the interface class, it can then use CreateFile to gain access to the device.

At the driver level, there are new system services that enable drivers to declare that an interface class is manifested in a particular device. When a WDM driver creates a device, it registers a device interface for each interface class that the device provides. To register a device interface, the driver calls IoRegisterDeviceInterface, passing the physical device object and the GUID that identifies the interface class. This service creates and returns a symbolic link that uniquely identifies the device interface. The system composes the symbolic link from the class GUID and a serial number which it maintains in the registry and increments each time a new interface of that class is registered.

The device object to which the symbolic link refers is the physical device object (PDO), not the functional device object (FDO) created by the driver that calls IoRegisterDeviceInterface. In order to receive IRPs sent by an application that opens the symbolic link, the driver must attach the FDO to the PDO, as is normal. Prior to WDM, drivers were responsible for naming the symbolic links of each device they created. In the WDM environment, the symbolic link is to the underlying PDO, and its name is determined by the system, based on the GUID of the interface class.

When a device is activated (i.e., it receives IRP_MJ_PNP with minor function IRP_MN_START_DEVICE), it enables its interfaces by calling IoSetDeviceInterfaceState, passing TRUE to indicate enabling. Similarly, when the device is stopped or removed, it must call that service again, passing FALSE.

In DriverWorks™ (version 2.0 and later), device interfaces are treated similarly to symbolic links. There is a constructor for class KPnpDevice that accepts a class GUID as a parameter and registers the corresponding device interface. There are also new member functions to support registration of additional interfaces, as well as support for automatically enabling and disabling interfaces as the device state changes. For more information on this subject, go to article number 1312.

Old KB# 11303
Comment List
Related Discussions