Tech Support > Microsoft Windows > Development Resources > SetupDi in Kernel Mode
SetupDi in Kernel Mode
Posted by Eric Minso on July 10th, 2003


Still me, still disturbing you !

I tried to use the SetupDi functions inside a driver, but in order to
use them, you must include the file "setupapi.h"

It seems there is some problems with dependencies, because I can't
compile ; and I don't know which file is missing.

It is very annoying, because there is a lot of useful functions I
can't use.


My final purpose is to get a handle on a HID collection. I would like
to read some reports data from it.

Have you some tips ?

Thanks !

Posted by Doron Holan [MS] on July 11th, 2003


at what point in time are you calling this function relative to the keyboard
and mouse being enumerated? You can call IoRegisterPlugPlayNotifications
and receive a notification callback of when the interfaces arrive. Also,
make sure the GUID you are using is the *interface* guid and not the class
guid. They are different. The class guid is the one you find the in the
INF file (and probably confusing, in the header file as well), the interface
GUID is the one find a header file alone. usually the device interface has
DEVINTERFACE in its name.

d

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Eric Minso" <minso@altern.org> wrote in message
news:7db38e60.0307110533.50731222@posting.google.c om...


Posted by Maxim S. Shatskih on July 15th, 2003


Setup class GUIDs are used only to match the class installer DLL to
your driver (including the Device Manager icon which is taken from
that DLL), in INF file processing and in SetupDixxx APIs.

Interface GUIDs used in IoRegisterDeviceInterface are other thing.

These two are different notions, which - in general - are not the
same, though some device kinds can share the same GUID value for both.

Max



Posted by Doron Holan [MS] on July 16th, 2003


yes, once you get the device name in the callback, you can use
IoGetDeviceObjectPointer or ZwOpenFile to start communicating with the HID
report. Class GUIDs are for installation time and they control which icon
is shown in device manager. The driver usually has no idea or link to the
class guid, the interface guid it uses is completely different. the only
thing they share is that they are the same data structure.

d

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Eric Minso" <minso@altern.org> wrote in message
news:7db38e60.0307150536.2c762239@posting.google.c om...


Posted by Eric Minso on July 16th, 2003


So, is there an easy way, given a class guid (in my case, the HID
class guid), to

* enumerate all hid devices (keyboard, mouse)
* for these devices, enumerate their hid collections
* for these collections, to read or write hid reports

I must do that in kernel mode. I know that it would be easier in user
mode by using the SetupDi functions, but the purpose of my training
course is to find a way to read any hid report from any hid device
inside a driver.

The driver will be located as an upper filter of kbdclass (so that it
can easily add new scancodes to the keyboard buffer), that's why I
can't use INF information.

Thank you very much for any help you can provide !

Posted by Maxim S. Shatskih on July 16th, 2003


Use _interface GUID for this, not _class GUID_.

In kernel mode, IoRegisterPlugPlayNotification is a way to go, just
use the correct GUID.

Max



Posted by Eric Minso on July 16th, 2003


"Doron Holan [MS]" <doronh@online.microsoft.com> wrote in message news:<OpMmSI2SDHA.1912@tk2msftngp13.phx.gbl>...

I did what you explained, but I had some strange results.

When I send a IOCTL_HID_GET_COLLECTION_INFORMATION (with
IoBuildDeviceIoControlRequest), the returned code is successful and my
buffer is full of zeros.

I can open the interface (given the symbolic name) with ZwOpenFile,
but if I try to read something from it with ZwReadFile, the status
code is 0xc0000008 : STATUS_INVALID_HANDLE.

Somtimes, I crash near a call to IoGetDeviceObjectPointer().

I will continue to search :'''(((
If you have any idea, don't hesitate !
Thanks a lot !

Posted by Doron Holan [MS] on July 16th, 2003


make sure in the object attributes you specify OBJ_KERNEL_HANDLE otherwise
you will receive a process relative handle. IoGetDeviceInterfaces is the
exact equivalent of the SetupDiEnumerateDeviceInterface call (albeit it
returns results slightly different).

1) you cannot open the HIDCLASS FDO itself to enumerate all of the
collections, the FDO does not support creates against it
2) the HID device interface GUID through IoRegisterPlugPlayNotificatio
should be enough to find each of the children (this is what the raw input
thread uses so that has to work)

the ability to open a keyboard and mouse and read from it will be quite hard
to attain. even if you successfully do it (you must be in kernel mode), you
will most likely render the keyboard or mouse useless b/c they are exclusive
devices and if the raw input thread can't open the device, no input.

d

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Eric Minso" <minso@altern.org> wrote in message
news:7db38e60.0307160549.12cdbd6f@posting.google.c om...


Posted by Eric Minso on July 16th, 2003


Some others details about what I said in my previous message :
I said that when I send a IOCTL_HID_GET_COLLECTION_INFORMATION with
the function IoBuildDeviceIoControlRequest, I receive a empty buffer.

In the IO_STATUS_BLOCK, the Information field seems to be a pointer
(it has the value 0xf6e02cf4) but if I try to read it, it sometimes
causes a crash or gives me bad values (DescriptorSize = 1769475,
VendorID = 0).

The flags of the device object (obtained with
IoGetDeviceObjectPointer) are 0x2044 (DO_POWER_PAGABLE +
DO_BUFFERED_IO + an unknown one).

Posted by Eric Minso on July 16th, 2003


"Doron Holan [MS]" <doronh@online.microsoft.com> wrote in message
Is it true for any keyboard or mouse's HID collection ?

So, there is no hope that I can open a specific HID collection on the
keyboard (the multimedia keys, the LED, ... ?)

Posted by Doron Holan [MS] on July 17th, 2003


true for all keyboards and mice. like i said before, the multimedia keys
are not a part of the keyboard collection, they are consumer keys. Think of
an "old" 103 key extended AT style keyboard. Any key that is not on that
keyboard shows up on a separate HID collection.

You can get around some of this by installing a filter in each of the HID
stacks and playing some games (firefly (a HID mouse filter) in the DDK shows
how to open the stack a second time).

d

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Eric Minso" <minso@altern.org> wrote in message
news:7db38e60.0307161414.f0b763c@posting.google.co m...


Posted by Eric Minso on July 17th, 2003


"Doron Holan [MS]" <doronh@online.microsoft.com> wrote in message
I don't find this mouse filter in the DDK (maybe because I don't have
the latest version) and I don't find it on the Microsoft website. Can
you send it to me by e-mail ? Thanks a lot !

Eric.

Posted by Eric Minso on July 18th, 2003


"Doron Holan [MS]" <doronh@online.microsoft.com> wrote :
I use the 2002 ddk, and there is no hid mouse example in that ddk. Or
else, it is very well hidden...

So I don't know how to get this source code (should I order a new DDK
just for a source code ?)

Posted by Eric Minso on July 21st, 2003


"Doron Holan [MS]" <doronh@online.microsoft.com> wrote :
I use the 2002 ddk, and there is no hid mouse example in that ddk. Or
else, it is very well hidden...

So I don't know how to get this source code (should I order a new DDK
just for a source code ?)