-
Notifications
You must be signed in to change notification settings - Fork 431
fix: fix get hid device interface number is always 0 on macos 13.3 #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation of the entire block is wrong. The commit indents with 4 spaces while the rest of the file indents with tabs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, the width of tabs on different system is different , but the width of spaces is the same. so use spaces can croass-platform ,show consistency There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you explain like this ,I got it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything in the taken branch is actually dependent on
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The With this in mind the only conditional you need to evaluate is
|
||
/* 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(""); | ||
pengxianheng-nreal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (temp_dev_path) { | ||
const char* match_prefix_string = "Interface@"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no documentation guarantees that the interface number is going to be a part of the Path There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #527. The author of this discussion is my workmate. Now we have no other good solution to solve this problem except this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
let me investigate this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A string literal would do just fine here. |
||
char* interface_component = strstr(temp_dev_path, match_prefix_string); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (interface_component) { | ||
char* decimal_str = interface_component + strlen(match_prefix_string); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A string literal instead of a Of course a string literal would have to be typed out twice, once for Because at this point I think I've written enough comment spam I'll just post an alternative to the whole code block, with a couple of additional minor tweaks in addition to the ones I've mentioned. Haven't compiled, no guarantees that it actually works. It just might.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for suggestion |
||
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)); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cur_dev->interface_number == 0
is a valid interface numberit doesn't look right to consider it for a fallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cause this problem: my device interface number is not 0. but the old code return 0 on macos 13.3. on macos13.2,the old code works fine(not 0) . so 0 may not be valid!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it is not vaid in your case, but generally the
0
is a valid interface numbermaybe we need to change the
get_int_property(dev, CFSTR(kUSBInterfaceNumber));
part to return-1
in case of failure