HID minidriver, no device

Hello all.

I’ve read about HID minidrivers and want to play with them a bit. But it looks like I don’t understand good enough how it works. I wrote very small skeleton of driver that registers itself using HidRegisterMinidriver. The function returns success, but it doesn’t create any device objects. So the driver gets unloaded immediately after executing DriverEntry.

The question is how to get the driver working without a real device? I expected that Windows asks minidriver about device it serves. The driver returns VID/PID and so on. Windows then loads functional drivers (like mou/kbdhid). The idea was to pretend that virtual device is a keyboard or a mouse.


With Best Regards,
Mikae.

On 30-Jul-2012 14:45, xxxxx@yahoo.com wrote:

The question is how to get the driver working without a real device?

a. Make root enumerated device instance(s)
b. Make a fake bus that creates fake child devices
c. For USB stuff maybe DSF can work for you as well

I expected that Windows asks minidriver about device it serves. The driver returns VID/PID and so on.

Windows is not Linux. No modprobes, module aliases, udev and so on.

– pa

Devcon install your.inf

Will create a root enumerated devnode. Your best starting point is going to be the hidusbfx2 sample

d

debt from my phone


From: Pavel A
Sent: 7/30/2012 7:27 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] HID minidriver, no device

On 30-Jul-2012 14:45, xxxxx@yahoo.com wrote:

The question is how to get the driver working without a real device?

a. Make root enumerated device instance(s)
b. Make a fake bus that creates fake child devices
c. For USB stuff maybe DSF can work for you as well

I expected that Windows asks minidriver about device it serves. The driver returns VID/PID and so on.

Windows is not Linux. No modprobes, module aliases, udev and so on.

– pa


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Well. As I understand, the trick is to say that my upper driver is kbd/mouclass, right? In general the scheme looks like this:

When HID minidriver for kbd or mouse loads, it chains kbd/mouclass drivers. So let’s say kbdhid.sys causes kbdclass ->AddDevice to be called to create kbdclass’s DO and attach it to minidriver’s DO. Then RIT will know that a new device has arrived and will open it for reading.

So, the point of attention is .inf file. I am checking \SystemRoot\inf for kbdhid/mouhid to get example. Please correct me if I am wrong.

You are wrong. Keyboards and mice are enumerated by HIDClass based on what your hid report descriptor says your device is. It is a two level hierarchy. Your hidminiport+hidclas are the parent device, the child stacks are enumerated by hidclass based on the top level collections described in the hid descriptor. Those child stacks are the ones that load mouhid or kbdhid

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Monday, July 30, 2012 11:31 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] HID minidriver, no device

Well. As I understand, the trick is to say that my upper driver is kbd/mouclass, right? In general the scheme looks like this:

When HID minidriver for kbd or mouse loads, it chains kbd/mouclass drivers. So let’s say kbdhid.sys causes kbdclass ->AddDevice to be called to create kbdclass’s DO and attach it to minidriver’s DO. Then RIT will know that a new device has arrived and will open it for reading.

So, the point of attention is .inf file. I am checking \SystemRoot\inf for kbdhid/mouhid to get example. Please correct me if I am wrong.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Doron, Ok, I’ve got it. Don’t get 2 things:

  1. By which means HIDClass calls kbd/mouclass’s AddDevice?
  2. Where to read about enumerators, root enumerator and devnodes? Is this information stored in .inf file?

Thank you.

Answering to myself: here goes some information: http://www.osronline.com/showThread.CFM?link=113416

Hidclass does not call the AddDevice routine of these drivers, just like the root bus or the driver that created your device’s PDO calls your AddDevice routine. All bus drivers is are report the presence or removal of PDO. When reporting a new PDO, the bus PDO also reports a bunch of information about that PDO’s identity (hw IDs, compatible IDs, bus instance ID, device instance ID, etc). that’s it.

Now, the INF comes in to play what it contains a hardware or compatible ID that matches one of the IDs associated with the PDO. A pnp install happens and the function driver (kbdhid or mouhid in your instance below) is loaded on the stack and the pnp manager calls its AddDevice as the stack is being built right after install

As for where to read about enumerators, it is not in an INF file. All an INF file does is say "for this given hardware ID, install this software.‘’ Read about bus drivers and enumerators in the wdk docs

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Monday, July 30, 2012 12:18 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] HID minidriver, no device

Doron, Ok, I’ve got it. Don’t get 2 things:

  1. By which means HIDClass calls kbd/mouclass’s AddDevice?
  2. Where to read about enumerators, root enumerator and devnodes? Is this information stored in .inf file?

Thank you.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

My English looks not good enough. I didn’t mean that HIDclass calls AddDevice directly, just would like to know what is the reason that makes PnP manager (or whatever entity) to call AddDevice.

Ah, QUERY_RELATIONS returns information including different IDs and so on. Probably I have to reread this chapter again.

Anyway, thank you for explanations.

QUERY_RELATIONS/bus relations returns a list of device objecs. QUERY_IDS returns a list of ids

d

debt from my phone


From: xxxxx@yahoo.com
Sent: 7/30/2012 1:19 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] HID minidriver, no device

My English looks not good enough. I didn’t mean that HIDclass calls AddDevice directly, just would like to know what is the reason that makes PnP manager (or whatever entity) to call AddDevice.

Ah, QUERY_RELATIONS returns information including different IDs and so on. Probably I have to reread this chapter again.

Anyway, thank you for explanations.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

I’ve read about device IDs and other useful stuff. Before actually starting writing code, I would lke to summarize what I am going to do:

  1. Create bus driver. The driver creates PDO for the stack, reports presence of PDO in QUERY_RELATIONS and handles QUERY_ID in such a way that HID minidriver will be loaded. As I understand it is enough to use generic ID (like *PNP1234). The driver must be installed with devcon install (or my own installer that makes root enumerated devnode).

  2. Create functional driver (HID minidriver). The driver handles class’s IoCTLs. The driver is installed with .inf file (that claims that the driver serves *PNP1234 device).

Please correct my if I am wrong. Thank you.

You don’t need a root enumerated bus driver just to enumerate a hid stack. Just root enumerate the hid stack without the indirection. Also use specific unique ids, dont copy eisa ids like PNP1234

d

debt from my phone


From: xxxxx@yahoo.com
Sent: 8/4/2012 4:13 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] HID minidriver, no device

I’ve read about device IDs and other useful stuff. Before actually starting writing code, I would lke to summarize what I am going to do:

  1. Create bus driver. The driver creates PDO for the stack, reports presence of PDO in QUERY_RELATIONS and handles QUERY_ID in such a way that HID minidriver will be loaded. As I understand it is enough to use generic ID (like *PNP1234). The driver must be installed with devcon install (or my own installer that makes root enumerated devnode).

  2. Create functional driver (HID minidriver). The driver handles class’s IoCTLs. The driver is installed with .inf file (that claims that the driver serves *PNP1234 device).

Please correct my if I am wrong. Thank you.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Ok, I’ve changed the HardwareID to FAKEHID000. The driver starts with the OS. But I see that AddDevice callback called 8 times! This is something I didn’t expect. Why 8? What are these devices that want to join my stack?..

Thank you.

Did you accidentally install 8 root stacks?

d

debt from my phone


From: xxxxx@yahoo.com
Sent: 8/4/2012 4:11 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] HID minidriver, no device

Ok, I’ve changed the HardwareID to FAKEHID000. The driver starts with the OS. But I see that AddDevice callback called 8 times! This is something I didn’t expect. Why 8? What are these devices that want to join my stack?..

Thank you.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Ah, I think I know it happens. When trying to install the driver, I created incorrect .inf file. So devcon wrote something like ‘Creating devnode – success, devcon failed’. I ran it multiple times while fixing the .inf file. Then Checkinf helped to identify the problem. Probably there are multiple devnodes in the OS. Will check it with DeviceTree.