I am a newbie learning how to write WDM device drivers for USB devices and found that the materials available are all too hard to comprehend (the DDK online doc is one of the mo
Use Device Simulation Framework (DSF).
http://msdn.microsoft.com/en-us/library/windows/hardware/gg454516.aspx
Windows uses a Plug and Play Architecture. When you insert a USB device, It sends low level USB request to the device and then based on the response from a device decides what driver to load. Matching is done by comparing vendor id, product id and etc to inf files sections. Drivers come in the form of a compiled xxx.sys with xxx.inf file and is loaded to kernel space. Windows decides which xxx.sys to load based on the *.inf file that comes with the device's driver.
These files have sections like this:
[Manufacturer]
%Manufacturer% = DeviceInstall
[DeviceInstall]
"some usb dev"=OTHER_SECTION_DEV, USB\Vid_XXXX&Pid_yyyy
# This is where windows learns to match this information
# to your device, using the product id (Pid) and the
# vendor id (Vid) that Windows gets back during the
# low level USB DeviceDescriptor request
[OTHER_SECTION_DEV]
CopyFiles = xxx.sys, 10,system32\drivers
(a more detailed description on what's in inf
files can be found over on https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-manufacturer-section)
A detailed look at the USB enumeration process (Use USB Logger):
For any connected USB device you can see these strings using the Device Manager:
For example, I have a USB storage device with Device Id = usb\class_08&subclass_06&prot_50
hooked up, and this string can be matched to an .inf
file that was added to the list of known devices after first enumeration. This file has a string Service = USBSTOR
, and so we know that usbstor.sys
is used to interface with this USB Mass Storage Device.
Let's continue with matching process.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB
For disk on key, you can see something like:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\Vid_0781&Pid_5406\0775555ACA54ADE3]
"Service"="USBSTOR"
For writing drivers my advice is:
Wouldn't it make more sense to provide your own bus type and enumerator?
You can use the USB/IP project to emulate any device that you want. In my blog I demonstrated how to emulate USB Mouse device in python using the USB/IP project: http://breaking-the-system.blogspot.com/2014/08/emulating-usb-devices-in-python-with-no.html
It wont help you to understand how to create the virtual USB device (the process is done in the USB/IP driver, you could read the code), but it will create the virtual USB HID device and you could play with the HID arguments sent to the USB driver.