Beginner advice for USB HID filter driver

Antonio Ceccato 6 Reputation points
2022-01-13T22:11:29.507+00:00

Hello everybody,

I have this issue: a USB mouse I recently bought has a total of 6 buttons, but the 6th button isn't recognized unless I install vendor software and bind it to extremely limited functions.

I inspected the raw USB HID report descriptor that the device reports, and two things are clear:

  1. the Button usage page reports only 5 bits (so only 5 buttons) and declares 3 constant bits for padding to a full byte
  2. when clicking the 6th button, the input report shows that bit 6 in the Button usage page is set (which is the first of the 3 declared as padding above)

Therefore, the device is hiding the 6th button by not declaring it in the Input Report.
I feel like the easiest workaround would be to intercept the USB HID report descriptor response and modify it on the fly to set 6 bits for buttons and 2 for padding instead of 5+3.

And here is where my knowledge stops: I have very little experience with Win32 / kernel low-level programming, my daily job involves mainly C# .NET and web environments.
I have found and read the official documentation about WDF, KMDF, UMDF, Virtual HID Framework, but I still don't have a clear enough picture to make an informed decision on where my code should be targeted. I understand I might have to write a "filter" driver, but I could also directly access HID reports from userspace (if that allows me to modify the descriptor, which I don't think so).

What advice can you give me on where to start with this driver? Or do you have a better idea with regards to solving my issue?

Thanks in advance

Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,541 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Doron Holan 1,801 Reputation points
    2022-01-14T00:51:23.537+00:00

    You want a filter driver that is below hidusb.sys. You want to be able to modify the raw hid descriptor before hidclass (via hidusb) processes it. This also allows you to modify the incoming hid data as you want. This gets you far enough to properly report the 6th button and hidparse can find and extract it.....

    BUT, you have another problem now. The mouse driver (mouhid.sys) does not know about the 6th button, so the higher-level driver will not query for the 6th button data. Mouhid.sys exclusively owns the mouse and is the only reader so there is no way for you to read the 6th button data in user mode nor does the 6th button get plumbed through the mouse input pipeline. So, you need another way to expose the 6th button data. Since the 6th button is not plumbed through the mouse input pipeline there is no generic solution to expose it to all applications, all consumption will be custom.

    You can use the proposed (in the first paragraph) lower hidusb filter to expose the 6th button (and anything else) by exposing a raw PDO and routing the 6th button data through it. Your user mode application can then open the raw PDO through a device interface and read it. The moufiltr example shows how to create a raw PDO, you would have to go through the sample and extract the relevant code.

    If you want to forgo modifying the raw hid descriptor and just want to get at the 6th button, there is another possible solution.

    1 person found this answer helpful.