Getting HID descriptors from windows

Hello,
I’m trying to write a piece of code that make the correlation between the descriptor of a HID device and its data. My problem is to get the descriptor from the device. I’m running my code in user mode.

With the windows hid api (HidP_GetButtonCaps, HidP_GetValueCaps,…) I can get the functions of the device (the information of the descriptors), but I still can’t figure out how I’m supposed to map these functions to their corresponding bits and bytes.

For example, I see my device has 5 buttons each represented by a bit, in a pack, or a wheel, represented by a complete byte.
Now when I read a report, I get some data. How do I now where in this data are located the bits of my buttons and the byte of my wheel?

I also tried to find a way to get the complete descriptor of the device (to parse it manually), but I couldn’t find any way to achieve it.

I would be very grateful if you could indicate me a way to solve my problem.
Thank you.

Erwan Martin.

xxxxx@fzwte.net wrote:

Hello,
I’m trying to write a piece of code that make the correlation between the descriptor of a HID device and its data. My problem is to get the descriptor from the device. I’m running my code in user mode.

With the windows hid api (HidP_GetButtonCaps, HidP_GetValueCaps,…) I can get the functions of the device (the information of the descriptors), but I still can’t figure out how I’m supposed to map these functions to their corresponding bits and bytes.

That’s what the controls, usages, and collections tell you. You should
be able to use HidP_GetUsages.

Do you already have a copy of the USB HID Class Specification? You’re
going to need to understand it. You should also read the DDK docs about
HID devices. There’s lots of good information there, and you will need
to speak the vocabulary to succeed here.
http://msdn.microsoft.com/en-us/library/ms789921.aspx


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

I think that you must feed the raw descriptor BLOB to the HID parser, thus
initializing the parser object.

After this, the parser object will be able to parse the raw HID report to
bit flags (on/off) and values.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
> Hello,
> I’m trying to write a piece of code that make the correlation between the
descriptor of a HID device and its data. My problem is to get the descriptor
from the device. I’m running my code in user mode.
>
> With the windows hid api (HidP_GetButtonCaps, HidP_GetValueCaps,…) I can
get the functions of the device (the information of the descriptors), but I
still can’t figure out how I’m supposed to map these functions to their
corresponding bits and bytes.
>
> For example, I see my device has 5 buttons each represented by a bit, in a
pack, or a wheel, represented by a complete byte.
> Now when I read a report, I get some data. How do I now where in this data
are located the bits of my buttons and the byte of my wheel?
>
> I also tried to find a way to get the complete descriptor of the device (to
parse it manually), but I couldn’t find any way to achieve it.
>
> I would be very grateful if you could indicate me a way to solve my problem.
> Thank you.
>
> Erwan Martin.
>

I don’t want to read reports. I only want to get information about them.
My problem is not about understanding the descriptor, it’s about getting it, whatever the device is.

That way I would know where to look for the data of a specific value or button in the raw data, if I were to find a report.
My code must not be device dependent, if I plug a joystick or anything else, it still should be able to create the correlation table.

I’d also be happy to get a report descriptor like the one at (even in binary):
http://euc.jp/periphs/xbox-pad-report-desc.txt

Maybe it can be done with the MSDN api, but I still can’t figure out how.
I still don’t understand how HidP_GetUsages gives me the location of the bits of a button of value in a raw report.

Erwan Martin.

xxxxx@fzwte.net wrote:

I don’t want to read reports. I only want to get information about them.
My problem is not about understanding the descriptor, it’s about getting it, whatever the device is.

That way I would know where to look for the data of a specific value or button in the raw data, if I were to find a report.
My code must not be device dependent, if I plug a joystick or anything else, it still should be able to create the correlation table.

I’d also be happy to get a report descriptor like the one at (even in binary):
http://euc.jp/periphs/xbox-pad-report-desc.txt

Actually, I believe HIdD_GetPreparsedData and HidP_GetCaps are where you
want to start.

Maybe it can be done with the MSDN api, but I still can’t figure out how.
I still don’t understand how HidP_GetUsages gives me the location of the bits of a button of value in a raw report.

No, I think I gave you bad advice there.

Have you read the USB HID Class Specification? That’s the definitive
document that defines the actual format of the reports, and how to
correlate that information to a usage page.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

I still can’t manage to do what I need.
I’ll take the example of a regular mouse I own (3 buttons and a wheel).
HidP_GetCaps returned me that NumberInputButtonCaps = 1 and NumberInputValueCaps = 3, which seems normal.

When I reverse-engineer the data of the reports, I can manually extract the table I’m trying to create with my code:
Function - Size:

//Byte 1
Button 1 - 1 bit
Button 2 - 1 bit
Button 3 - 1 bit
Unused - 5 bits
//Byte 2
X Axis - 8 bits
//Byte 3
Y Axis - 8 bits
//Byte 4
Wheel - 8 bits

Now here are the information I get from HidP_GetButtonCaps and HidP_GetValueCaps. And again, I don’t understand where the position of the data in the bit field is given. I can only see the size of the items and their usage.

Button Input

UsagePage: Button ($0009)
ReportID: 0
IsAlias: False
BitField: 2
LinkCollection: 1
LinkUsage: Pointing Device ($0001)
LinkUsagePage: Generic Desktop ($0001)
IsRange: True
IsStringRange: False
IsDesignatorRange: False
IsAbsolute: True
UsageMin: 1 UsageMax: 3
StringMin: 0 StringMax: 0
DesignatorMin: 0 DesignatorMax: 0
DataIndexMin: 0 DataIndexMax: 2

Value Input

UsagePage: Generic Desktop ($0001)
ReportID: 0
IsAlias: False
BitField: 6
LinkCollection: 1
LinkUsage: Pointing Device ($0001)
LinkUsagePage: Generic Desktop ($0001)
IsRange: False
IsStringRange: False
IsDesignatorRange: False
IsAbsolute: False
HasNull: False
BitSize: 8
ReportCount: 1
UnitsExp: 0
Units: 0
LogicalMin: -127
LogicalMax: 127
PhysicalMin: 0
PhysicalMax: 0
Usage: Wheel ($0038)
StringIndex: 0
DesignatorIndex: 0
DataIndex: 3

UsagePage: Generic Desktop ($0001)
ReportID: 0
IsAlias: False
BitField: 6
LinkCollection: 1
LinkUsage: Pointing Device ($0001)
LinkUsagePage: Generic Desktop ($0001)
IsRange: False
IsStringRange: False
IsDesignatorRange: False
IsAbsolute: False
HasNull: False
BitSize: 8
ReportCount: 1
UnitsExp: 0
Units: 0
LogicalMin: -127
LogicalMax: 127
PhysicalMin: 0
PhysicalMax: 0
Usage: Y Axis ($0031)
StringIndex: 0
DesignatorIndex: 0
DataIndex: 4

UsagePage: Generic Desktop ($0001)
ReportID: 0
IsAlias: False
BitField: 6
LinkCollection: 1
LinkUsage: Pointing Device ($0001)
LinkUsagePage: Generic Desktop ($0001)
IsRange: False
IsStringRange: False
IsDesignatorRange: False
IsAbsolute: False
HasNull: False
BitSize: 8
ReportCount: 1
UnitsExp: 0
Units: 0
LogicalMin: -127
LogicalMax: 127
PhysicalMin: 0
PhysicalMax: 0
Usage: X Axis ($0030)
StringIndex: 0
DesignatorIndex: 0
DataIndex: 5

I continue to feel that the answer is right in front of my eyes, but I still don’t see it.

Still no answers?

xxxxx@fzwte.net wrote:

Still no answers?

Well, what did you try? In the last message, I pointed you to
HidD_GetPreparsedData, HidP_GetCaps, and the USB HID class
specification. What did all of that get you?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

This is what I understand: HidD_GetPreparsedData gets me a PHIDP_PREPARSED_DATA variable, which I can use in HidP_GetCaps, to get a PHIDP_CAPS.
This structure contains information like the size of the reports, and the number of buttons and values.
Knowing the number of buttons and values, I can then call HidP_GetButtonCaps and HidP_GetValueCaps, which will give me a list of all the HID Controls.
But my problem is still the same: Even if I have the list of the element of a report, I still don’t know how to order them, and more importantly how to locate them in the data.

For example, I see that my mouse has a value “Wheel”, which takes 8 bits. My input report is 4 bytes long, and I still didn’t find anything that tells me the location of the bits of my wheel. This is my problem.

You would call HidP_GetScaledUsageValue (http://msdn.microsoft.com/en-us/library/ms790930.aspx) or HidP_GetUsageValue (http://msdn.microsoft.com/en-us/library/ms790945.aspx) depending on your needs. Even though the docs say these are KM, they are also exported from hid.dll in UM (via hidpi.h, although you may have to manually define some types like NTSTATUS)

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@fzwte.net
Sent: Monday, June 09, 2008 1:53 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Getting HID descriptors from windows

This is what I understand: HidD_GetPreparsedData gets me a PHIDP_PREPARSED_DATA variable, which I can use in HidP_GetCaps, to get a PHIDP_CAPS.
This structure contains information like the size of the reports, and the number of buttons and values.
Knowing the number of buttons and values, I can then call HidP_GetButtonCaps and HidP_GetValueCaps, which will give me a list of all the HID Controls.
But my problem is still the same: Even if I have the list of the element of a report, I still don’t know how to order them, and more importantly how to locate them in the data.

For example, I see that my mouse has a value “Wheel”, which takes 8 bits. My input report is 4 bytes long, and I still didn’t find anything that tells me the location of the bits of my wheel. This is my problem.


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 don’t think HidP_GetScaledUsageValue is what I need.

My problem is not to get the content of the values and buttons (ie ±1 for my wheel), but to determine the location of their bits in a raw report.

My report is 4 bytes long. I need my code to tell me: the data of this value (or button) is represented by the 8 bits starting at bit number 24.

I feel like I don’t make myself clear. Actually, English is not my native language, so I’m sorry if what I say doesn’t make sense.

To sum up what I need: I need the coordinate of the different bits of a value.
I still don’t know where is the information which tell me where the data of a value or button is.