Obtaining Plug and Play hardware IDs in VxD and WDM Drivers

0 Likes

Problem:

How do I get my hardware PnP ID ?

Resolution:

In a Plug and Play environment, the operating system detects the presence of a device and notifies the driver responsible for controlling it. For Win32 Driver Model (WDM) drivers, the operating system notifies the driver by calling the driver's AddDevice entry point. For VxDs in Windows 95 and Windows 98, notification is in the form of a control message, namely PNP_NEWDEVNODE.

If a driver supports more than one device, and it does not handle all devices in the same way, then it needs to determine which of the physical devices under its control corresponds to a notification sent by the operating system. Since the operating system assigns a unique Hardware ID to each device, one way for the driver to identify a device is by its Hardware ID.

WDM

A WDM driver can obtain the Hardware ID of a device using the Physical Device Object (PDO) pointer that the system passes as a parameter to AddDevice. A WDM driver calls the system service IoGetDeviceProperty as follows:

NTSTATUS status;

ULONG ReqLen;

USHORT HardwareID[MAX_ID_SIZE];

status =IoGetDeviceProperty(

PDO,

DevicePropertyHardwareID,

sizeof(HardwareID),

HardwareID,

&ReqLen

);

IoGetDeviceProperty writes the device's hardware IDs into the provided buffer. Compatible ID strings are delimited by commas. If the provided buffer is too small, the service returns STATUS_BUFFER_OVERFLOW. Since the buffer may have to be quite large, it is a good idea to allocate it temporarily from the paged pool, and release it when no longer needed.

A WDM driver built with DriverWorks can just call member GetHardwareID of class KPnpLowerDevice.

VxD

A VxD makes an analogous call to the Configuration Manager, passing the DevNode rather than a PDO (assuming VtoolsD™):

CONFIGRET status;

ULONG ReqLen;

USHORT HardwareID[MAX_ID_SIZE];

status =CONFIGMG_Get_Device_ID(

DevNode,

HardwareID,

sizeof(HardwareID),

0

);

Old KB# 11873
Comment List
Anonymous
Related Discussions
Recommended