Skip to content
Fredrik Orderud edited this page Mar 6, 2024 · 53 revisions

This project demonstrates how to develop a filter driver with a WMI provider to expose HW diagnostics data to user-space.

Pages:

Why develop drivers?

Some benefits:

  • Bus drivers discover connected devices and expose them to the operating system and user-space applications. They also transparently forward communication over the bus.
  • Drivers implement power management and ensure that that devices are powered on and off in the correct order. They also save and restore context state for the HW when transitioning between device power states, so that user-space applications can continue as if nothing happened.
  • Drivers can provide HW abstraction so that user-space applications don't need to deal with HW internal details (e.g. Direct3D/DXGI, Win32_Battery interface and similar).
  • Drivers are used to automatically upload new firmware to devices.
  • Drivers can expose HW diagnostics and self-test capabilities through WMI interfaces.
  • Drivers can work around HW bugs and limitations so that user-space applications don't need to deal with them (e.g. thermal throttling of CPU/GPU).

Windows includes generic drivers for many system-defined device classes, like USB controllers, batteries, mouse/keyboard, disk, network adapters, monitors and more. Vendors often don't need to develop drivers for HW devices compatible with one of the system-defined device classes.

Vendors still need to develop custom drivers for custom HW devices that doesn't fit into the system-defined device classes, or if they want to expose additional functionality. Windows Update is typically used to distribute these drivers to end-users, but they can also be installed manually.

Common challenges with custom HW

Problem Suggested solution Example
Device does not show up in "Device Manager" Write a bus driver for discovery of the device. This will also ensure that the device gets a unique identifier that can be used for diagnostics. Toaster Sample Driver
Device does not expose sufficient diagnostics parameters Either extend the existing driver or write a new filter driver to expose the diagnostics parameters through WMI. This repo
Device need to be reinitialized when computer resumes from sleep Write a power-managment driver that stores HW state in EvtDeviceD0Entry and restores it in EvtDeviceD0Exit.
Device firmware needs to be updated Add firmware update logic to EvtDevicePrepareHardware or EvtDeviceD0Entry, depending if the firmware is persistent or not.
Device is not inherently safe and can be damaged or cause harm if exposed to deliberate SW attacks Write a driver to intercept and filter device communication to prevent harmful command from reaching the device This repo
Unable to test without HW connected Develop a "mock" UDE driver for emulating the custom HW device, so that a subset of the functionality can be tested without HW connected. This repo
Clone this wiki locally