25
25
#include <IOKit/hid/IOHIDManager.h>
26
26
#include <IOKit/hid/IOHIDKeys.h>
27
27
#include <IOKit/IOKitLib.h>
28
+ #include <IOKit/usb/USBSpec.h>
28
29
#include <CoreFoundation/CoreFoundation.h>
29
30
#include <wchar.h>
30
31
#include <locale.h>
@@ -432,6 +433,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
432
433
if ((vendor_id == 0x0 || vendor_id == dev_vid ) &&
433
434
(product_id == 0x0 || product_id == dev_pid )) {
434
435
struct hid_device_info * tmp ;
436
+ bool is_usb_hid ; /* Is this an actual HID usb device */
435
437
io_object_t iokit_dev ;
436
438
kern_return_t res ;
437
439
io_string_t path ;
@@ -446,6 +448,8 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
446
448
}
447
449
cur_dev = tmp ;
448
450
451
+ is_usb_hid = get_int_property (dev , CFSTR (kUSBInterfaceClass )) == kUSBHIDClass ;
452
+
449
453
/* Get the Usage Page and Usage for this device. */
450
454
cur_dev -> usage_page = get_int_property (dev , CFSTR (kIOHIDPrimaryUsagePageKey ));
451
455
cur_dev -> usage = get_int_property (dev , CFSTR (kIOHIDPrimaryUsageKey ));
@@ -478,8 +482,15 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
478
482
/* Release Number */
479
483
cur_dev -> release_number = get_int_property (dev , CFSTR (kIOHIDVersionNumberKey ));
480
484
481
- /* Interface Number (Unsupported on Mac)*/
482
- cur_dev -> interface_number = -1 ;
485
+ /* We can only retrieve the interface number for USB HID devices.
486
+ * IOKit always seems to return 0 when querying a standard USB device
487
+ * for its interface. */
488
+ if (is_usb_hid ) {
489
+ /* Get the interface number */
490
+ cur_dev -> interface_number = get_int_property (dev , CFSTR (kUSBInterfaceNumber ));
491
+ } else {
492
+ cur_dev -> interface_number = -1 ;
493
+ }
483
494
}
484
495
}
485
496
0 commit comments