Author Topic: Getting USB descriptor and location info from a USB HID device  (Read 18051 times)

Augie

  • Member
  • ***
  • Posts: 3
Getting USB descriptor and location info from a USB HID device
« on: October 12, 2014, 03:25:30 am »
Hi,

I've been trying for a week to come up with a way to get the parent USB device only having a HID device (assuming USB). I want to get information from its descriptor since it seems the information returned at the HID level is different. I would also like to be able to identify the USB hub and port number the device is attached to so I can sort my HID devices by USB port (even if this isn't meaningful to the user, at least the order will be consistent from reboot to reboot as long as devices are attached to the same location).

Example of different info returned by HID vs USB:
Code: [Select]
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

So far, I've been able to get some useful information from the HID device, but the information I imagine that I'd need to make the connection between a HID device and the parent USB device seems to be missing. I'm thinking I might be able to get the USB device from the PDO, but I can't find a way to do that.

Useful information obtained through hid.dll:
Vendor id
Product id
Version

Useful information obtained through setupapi.dll (SetupDiGetDeviceRegistryProperty):
Device Path
Description
Instance id
Hardware id
Manufacturer
PDO

These return blank or nonsense information:
Address
Bus Number
Location Info (I was hoping this would give me the info I need for port sorting, but it is always blank)
Friendly Name

Viewing the devices in USBView, I'm able to see that the HID device is actually a 2nd tier child of the USB device itself.

Device ID's in the hierarchy:
USB device: USB\VID_045E&PID_028E\0843806  <-- This is the USB device I want
Child Device 1: USB\VID_045E&PID_028E&IG_00\6&33D4AC&0&00
(sub) Child Device 1: HID\VID_045E&PID_028E&IG_00\7&2C1CE38F&0&0000  <-- This is the HID device I have access to

I realize I'm probably making a bunch of incorrect assumptions because I'm very new to this area. However, I hope I was able to get across what I'm trying to achieve.

By the way, these devices do not work with WinUSB.
« Last Edit: October 12, 2014, 03:34:18 am by Augie »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Getting USB descriptor and location info from a USB HID device
« Reply #1 on: October 12, 2014, 11:57:45 am »
Source code for USBView is here:

https://code.msdn.microsoft.com/windowshardware/USBView-sample-application-e3241039/view/SourceCode#content

When you are able to "sort my HID devices by USB port," how will you use this information? Maybe there is a better way to do it (one that doesn't depend on the devices being attached to the same location).

Augie

  • Member
  • ***
  • Posts: 3
Re: Getting USB descriptor and location info from a USB HID device
« Reply #2 on: October 12, 2014, 01:59:50 pm »
Source code for USBView is here:

https://code.msdn.microsoft.com/windowshardware/USBView-sample-application-e3241039/view/SourceCode#content

When you are able to "sort my HID devices by USB port," how will you use this information? Maybe there is a better way to do it (one that doesn't depend on the devices being attached to the same location).

Thanks so much for the reply! I really appreciate the help.

On device sorting, the idea is to sort USB joysticks by some fixed reference point so that when the computer restarts, the joysticks come up in a predictable order. The primary use of this being an arcade system that has multiple possibly identical devices attached. I want the ids of the devices to be predictable so there's no question which device is player 1 or player 2 as long as the hardware is the same. At present, sorting the device in the order reported by SetupDiEnumDeviceInfo is inconsistent. On OSX, I was able to easily get a location id integer through Hid Manager and sort by that as all the USB information was easily available, but Windows completely separates the HID information from the USB information (understandable since not all HID devices are USB).

Anyway, thank you for the source code link. I'll dig through that and hopefully find what I need. I imagine I will probably have to enumerate all the USB devices searching for my child device's device id.

Augie

  • Member
  • ***
  • Posts: 3
Re: Getting USB descriptor and location info from a USB HID device
« Reply #3 on: October 13, 2014, 05:46:16 am »
Mission accomplished. Unfortunately, the source to USBView didn't tell me what I needed to know to associate the HID device with its USB parent device.

The solution was to use DevInst from SP_DEVINFO_DATA which is the device instance handle to the HID device, enumerate all the USB devices, then search all child devices using CM_Get_Child and CM_Get_Sibling to find their instance handles, and determine which parent USB device contained the child HID device that matched the instance handle.

The sorting seems to work fine on initial tests. Thanks for helping!

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Getting USB descriptor and location info from a USB HID device
« Reply #4 on: October 13, 2014, 02:31:49 pm »
Glad you got it working. Thanks for letting us know what worked.