Skip to content

Commit

Permalink
fix: fix get hid device interface is always 0 on macos 13.3
Browse files Browse the repository at this point in the history
  • Loading branch information
pengxianheng-nreal committed Apr 13, 2023
1 parent 9f185ec commit 9c10af7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,36 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
cur_dev->interface_number = -1;
}

if (cur_dev->interface_number == -1 || cur_dev->interface_number == 0) {
int old_interface_number = cur_dev->interface_number;
//try to Fallback to older interface number find rules
io_string_t temp_dev_path_str;
char* temp_dev_path = NULL;
/* Fill in the path (IOService plane) */
if (iokit_dev != MACH_PORT_NULL) {
res = IORegistryEntryGetPath(iokit_dev, kIOServicePlane, temp_dev_path_str);
if (res == KERN_SUCCESS)
temp_dev_path = strdup(temp_dev_path_str);
else
temp_dev_path = strdup("");
}

if (temp_dev_path) {
const char* match_prefix_string = "Interface@";
char* interface_component = strstr(temp_dev_path, match_prefix_string);
if (interface_component) {
char* decimal_str = interface_component + strlen(match_prefix_string);
char* endptr = NULL;
cur_dev->interface_number = strtol(decimal_str, &endptr, 10);
if (endptr == decimal_str) {
/* The parsing failed. Set interface_number to old_interface_number. */
cur_dev->interface_number = old_interface_number;
}
}
free(temp_dev_path);
}
}

/* Bus Type */
transport_prop = IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDTransportKey));

Expand Down

0 comments on commit 9c10af7

Please sign in to comment.