Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Parse the interface number out of the path on Windows where possible.

Although the Windows API doesn't provide direct access to interface number,
on child devices representing the interfaces of a composite device, it is
parsable from the device path. An excerpt of a path for interface 1 of a
Razer Hydra device is as follows:
\?\hid#vid_1532&pid_0300&mi_01

See table 4 and related text here:
  http://msdn.microsoft.com/en-us/windows/hardware/gg487473

This patch, if a path is available, and further, if &mi_ is found, parses
what it can for a hex value into the interface_number field. If there is
any problem, the invalid value (-1) is used instead.

Patch from Ryan Pavlik <abiryan@ryand.net> with modifications by Alan Ott.
  • Loading branch information...
commit 36c309f5216307ff50dc299240d2a91e45efeff3 1 parent abd82e6
@rpavlik authored signal11 committed
Showing with 20 additions and 2 deletions.
  1. +3 −1 hidapi/hidapi.h
  2. +17 −1 windows/hid.cpp
View
4 hidapi/hidapi.h
@@ -69,7 +69,9 @@ extern "C" {
(Windows/Mac only).*/
unsigned short usage;
/** The USB interface which this logical device
- represents (Linux/libusb implementation only). */
+ represents. Valid on the Linux/libusb implementation
+ in all cases, and valid on the Windows implementation
+ only if the device contains more than one interface. */
int interface_number;
/** Pointer to the next device */
View
18 windows/hid.cpp
@@ -367,8 +367,24 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
/* Release Number */
cur_dev->release_number = attrib.VersionNumber;
- /* Interface Number (Unsupported on Windows)*/
+ /* Interface Number. It can sometimes be parsed out of the path
+ on Windows if a device has multiple interfaces. See
+ http://msdn.microsoft.com/en-us/windows/hardware/gg487473 or
+ search for "Hardware IDs for HID Devices" at MSDN. If it's not
+ in the path, it's set to -1. */
cur_dev->interface_number = -1;
+ if (cur_dev->path) {
+ char *interface_component = strstr(cur_dev->path, "&mi_");
+ if (interface_component) {
+ char *hex_str = interface_component + 4;
+ char *endptr = NULL;
+ cur_dev->interface_number = strtol(hex_str, &endptr, 16);
+ if (endptr == hex_str) {
+ /* The parsing failed. Set interface_number to -1. */
+ cur_dev->interface_number = -1;
+ }
+ }
+ }
}
cont_close:
Please sign in to comment.
Something went wrong with that request. Please try again.