Skip to content

Commit 8d251c3

Browse files
felix-schwarzjdk
authored andcommitted
Mac: use IORegistryEntryGetRegistryEntryID to resolve paths
Closes signal11#301. Some hubs created long paths that were over 512 bytes (io_string_t length). Rather than using the entire string path, use the ID, and attach to the service.
1 parent a6a622f commit 8d251c3

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

‎mac/hid.c‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
434434
struct hid_device_info *tmp;
435435
io_object_t iokit_dev;
436436
kern_return_t res;
437+
uint64_t entry_id;
437438
io_string_t path;
438439

439440
/* VID/PID match. Create the record. */
@@ -461,6 +462,16 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
461462
else
462463
cur_dev->path = strdup("");
463464

465+
/* Fill in the kernel_entry_id */
466+
res = IORegistryEntryGetRegistryEntryID(iokit_dev, &entry_id);
467+
if (res == KERN_SUCCESS) {
468+
if ((cur_dev->path = calloc(32 + 3 + 1, 1)) != NULL) {
469+
sprintf(cur_dev->path, "id:%llu", entry_id);
470+
}
471+
} else {
472+
cur_dev->path = strdup("");
473+
}
474+
464475
/* Serial Number */
465476
get_serial_number(dev, buf, BUF_LEN);
466477
cur_dev->serial_number = dup_wcs(buf);
@@ -689,10 +700,28 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
689700
if (hid_init() < 0)
690701
return NULL;
691702

692-
/* Get the IORegistry entry for the given path */
693-
entry = IORegistryEntryFromPath(kIOMasterPortDefault, path);
694-
if (entry == MACH_PORT_NULL) {
695-
/* Path wasn't valid (maybe device was removed?) */
703+
/* Check if the path represents IORegistry path or an IORegistryEntry ID */
704+
if (strlen(path) > 3) {
705+
if (strncmp("id:", path, 3) == 0) {
706+
/* Get the IORegistry entry for the given ID */
707+
uint64_t entry_id;
708+
709+
entry_id = strtoull(path+3, NULL, 10);
710+
711+
entry = IOServiceGetMatchingService(kIOMasterPortDefault, IORegistryEntryIDMatching(entry_id));
712+
if (entry == 0) {
713+
/* No service found for ID */
714+
goto return_error;
715+
}
716+
} else {
717+
/* Get the IORegistry entry for the given path */
718+
entry = IORegistryEntryFromPath(kIOMasterPortDefault, path);
719+
if (entry == MACH_PORT_NULL) {
720+
/* Path wasn't valid (maybe device was removed?) */
721+
goto return_error;
722+
}
723+
}
724+
} else {
696725
goto return_error;
697726
}
698727

0 commit comments

Comments
 (0)