How do you get raw descriptor data from a USB-HID device in Windows?

How do you get raw descriptor data from a HID device in Windows?

Background:

I need to get the manufacturer name, product name and serial number from a HID device in Windows. I use hid.dll to access devices using the features that are visible here . My question is very similar to this one . I can get the manufacturer string and product line from SOME HID devices, but most of them cannot return this data with HidD_GetManufacturerString returning false. However, I KNOW that these devices have string information in their descriptors, because I can see it using USBTreeView .

Interestingly, even for devices that return the names of manufacturers and products, the values ​​that I get through hid.dll are very different from the values ​​I see using the above tool, which receives raw data from a USB device.

For example, the Xbox 360 controller:

Via USB Tree View: Device Description : Xbox 360 Controller for Windows Language 0x0409 : "©Microsoft Corporation" iProduct : 0x02 Language 0x0409 : "Controller" iSerialNumber : 0x03 Language 0x0409 : "0843806" Via hid.dll using HidD_GetManufacturerString, HidD_GetProductString, and HidD_GetSerialNumberString: Description : HID-compliant game controller Product : Controller (XBOX 360 Controller for Windows) Manufacturer : FAILS Serial Number : FAILS 

WinUSB cannot open these devices at all to retrieve this data because they do not use the winusb.sys driver.

1) I do not understand why the values ​​returned by the HidD functions do not match the values ​​in the USB descriptor. 2) I can not find a way to access the raw USB descriptor data for the HID device, because I can not access them using WinUSB.


Change 1:

Ok, so I learned a little more about HID. It seems that the data I get through hid.dll is the data specified by the driver, and not the data coming from the USB device. HID can also be applied to devices on vehicles other than USB. So good. Ultimately, I really want to know how I can get a USB device when I have a HID device and which API I use for this. Besides WinUSB, which does not work, the only thing I can find is the IOCTL kernel level functions. I don't know if this is suitable for a regular, non-admin application.

+6
source share
1 answer

I finally found a solution. The main problem was simply to connect the HID device to its parent USB device. This is the main process:

Assuming you already have a HID device and SP_DEVINFO_DATA:

  • List all USB devices as shown here .
  • Find all USB child devices with CM_GetChild and CM_GetSibling.
  • Compare the known HID device instance descriptor (SP_DEVINFO_DATA-> DevInst) with each child device instance descriptor returned by the CM functions to determine which USB device is the parent.
  • From there, you can get any USB information you want, including a descriptor.
+2
source

Source: https://habr.com/ru/post/976245/


All Articles