Skip to content

Commit

Permalink
Mac: use IORegistryEntryGetRegistryEntryID to resolve paths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
felix-schwarz authored and jdk committed Feb 11, 2018
1 parent a6a622f commit 8d251c3
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
struct hid_device_info *tmp;
io_object_t iokit_dev;
kern_return_t res;
uint64_t entry_id;
io_string_t path;

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

/* Fill in the kernel_entry_id */
res = IORegistryEntryGetRegistryEntryID(iokit_dev, &entry_id);
if (res == KERN_SUCCESS) {
if ((cur_dev->path = calloc(32 + 3 + 1, 1)) != NULL) {
sprintf(cur_dev->path, "id:%llu", entry_id);
}
} else {
cur_dev->path = strdup("");
}

/* Serial Number */
get_serial_number(dev, buf, BUF_LEN);
cur_dev->serial_number = dup_wcs(buf);
Expand Down Expand Up @@ -689,10 +700,28 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
if (hid_init() < 0)
return NULL;

/* Get the IORegistry entry for the given path */
entry = IORegistryEntryFromPath(kIOMasterPortDefault, path);
if (entry == MACH_PORT_NULL) {
/* Path wasn't valid (maybe device was removed?) */
/* Check if the path represents IORegistry path or an IORegistryEntry ID */
if (strlen(path) > 3) {
if (strncmp("id:", path, 3) == 0) {
/* Get the IORegistry entry for the given ID */
uint64_t entry_id;

entry_id = strtoull(path+3, NULL, 10);

entry = IOServiceGetMatchingService(kIOMasterPortDefault, IORegistryEntryIDMatching(entry_id));
if (entry == 0) {
/* No service found for ID */
goto return_error;
}
} else {
/* Get the IORegistry entry for the given path */
entry = IORegistryEntryFromPath(kIOMasterPortDefault, path);
if (entry == MACH_PORT_NULL) {
/* Path wasn't valid (maybe device was removed?) */
goto return_error;
}
}
} else {
goto return_error;
}

Expand Down

0 comments on commit 8d251c3

Please sign in to comment.