From 0943bf2ecb7abe8ee2ffdaae48efd7ee123fbefa Mon Sep 17 00:00:00 2001 From: doinkythederp Date: Tue, 16 Jul 2024 17:03:47 -0700 Subject: [PATCH 1/2] fix(usb): improve robustness of interface field when using IOKit backend --- src/posix/enumerate.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/posix/enumerate.rs b/src/posix/enumerate.rs index 455a484c..57e67386 100644 --- a/src/posix/enumerate.rs +++ b/src/posix/enumerate.rs @@ -321,8 +321,15 @@ fn port_type(service: io_object_t) -> SerialPortType { // https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_driverkit_transport_usb // https://developer.apple.com/library/archive/documentation/DeviceDrivers/Conceptual/USBBook/USBOverview/USBOverview.html#//apple_ref/doc/uid/TP40002644-BBCEACAJ #[cfg(feature = "usbportinfo-interface")] - interface: get_int_property(usb_device, "bInterfaceNumber", kCFNumberSInt8Type) - .map(|x| x as u8), + interface: get_parent_device_by_type( + service, + b"IOUSBHostInterface\0".as_ptr() as *const c_char, + ) + .and_then(|interface| { + get_int_property(interface, "bInterfaceNumber", kCFNumberSInt8Type) + }) + .or_else(|| get_int_property(usb_device, "bInterfaceNumber", kCFNumberSInt8Type)) + .map(|x| x as u8), }) } else if get_parent_device_by_type(service, bluetooth_device_class_name).is_some() { SerialPortType::BluetoothPort From 889771cbefea6a15367934c561b3d5c1baa7a69b Mon Sep 17 00:00:00 2001 From: doinkythederp Date: Tue, 16 Jul 2024 17:25:27 -0700 Subject: [PATCH 2/2] fix: remove nonexistent IOUSBHostDevice.bInterfaceNumber property access --- src/posix/enumerate.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/posix/enumerate.rs b/src/posix/enumerate.rs index 57e67386..7fc49192 100644 --- a/src/posix/enumerate.rs +++ b/src/posix/enumerate.rs @@ -328,7 +328,6 @@ fn port_type(service: io_object_t) -> SerialPortType { .and_then(|interface| { get_int_property(interface, "bInterfaceNumber", kCFNumberSInt8Type) }) - .or_else(|| get_int_property(usb_device, "bInterfaceNumber", kCFNumberSInt8Type)) .map(|x| x as u8), }) } else if get_parent_device_by_type(service, bluetooth_device_class_name).is_some() {