Monday 12 September 2011

Default\Default\What?

Loading USB and HID drivers depends on Registry keys.
The USB driver tries to find the best fitting driver for an attached device.
Typical Registry keys are
[HKEY_LOCAL_MACHINE\Drivers\USB\LoadClients\Default\Default\3\Hid_Class]
"DLL"="USBHID.DLL"
and
[HKEY_LOCAL_MACHINE\Drivers\HID\LoadClients\Default\Default\1_2\Mouse]
"DLL"="MOUHID.DLL"

But what exactly is coded with "Default\Default\3"?
You may guess, it is somehow related to the vendor and the type of the device.

The easy part is to google/bing (can Bing be used as a verb?) the USB Class Codes at USB.org
http://www.usb.org/developers/defined_class
In this example "3" stands for the Interface "HID (Human Interface Device)"
and "1_2" stands for HID Mouse,
see http://www.usb.org/developers/devclass_docs/HID1_11.pdf

The Microsoft online help hides the syntax anywhere in the middle of this article:
http://msdn.microsoft.com/en-us/library/ee484468.aspx
In my own words it stats:
[HKEY_LOCAL_MACHINE\Drivers\USB\LoadClients\\\\]
where
Group1_ID = Default|DeviceVendorID[_DeviceProductID[_DeviceReleaseNumber]]
Group2_ID = Default|DeviceClassCode[_DeviceSubclassCode[_DeviceProtocolCode]]
Group3_ID = Default|InterfaceClassCode[_InterfaceSubclassCode[_InterfaceProtocolCode]]

The following two pieces of the puzzle are missing:
* The syntax is similar for HID devices.
* All numbers are DECIMAL! This includes VendorIDs and DeviceIDs!

Example:
VendorID: 0x045e=1118 Microsoft Corp.
DeviceID: 0x0040=64 Wheel Mouse Optical

[HKEY_LOCAL_MACHINE\Drivers\HID\LoadClients\1118_64\Default\1_2\WheelMouse]
"DLL"="WheelMouse.DLL"

Contrary to this example you should write a general-purpose and Vendor-INdependent driver.

Tschüß Holger

2 comments:

garzanti said...

Hi Holger,

I think is somehow logical what it is going to be loaded. All the operating systems, not only Windows, in order to create this illusion of Plug'n'Play rely on the USB descriptor which is provided by the attached device.

First the OS or the host will look at the Vendor ID, Product ID to identify the proper driver, while the serial number is going to be used for uniqueness.

If based on Vendor ID/Product ID couldn't help to identify the proper driver, the next information used will be class id/sub class id. For example, it will tell me that is a HID - human interaction device. But the HIDs are great variety and it is going to be used also interface and protocol which will tell the OS: "I am an audio, keyboard, mouse, etc". So in this second case it will be loaded a generic driver: audio, keyboard, mouse, etc.

There is no exact default, it may be a generic driver or a manufacturer driver from case to case.

I would recomend for further reading Jan Axelson book: http://www.lvr.com/ - USB Complete Fourth Edition.

Holger Moltrecht said...

Hi Garzanti,
thank you for your great completion.
The issue I tried to explain was more simple:
How to add the correct Registry Settings for a certain device?

Tschüß Holger