@@ -52,6 +52,30 @@ fn usb_service_iter(service: *const ::std::os::raw::c_char) -> Result<IoServiceI
52
52
}
53
53
}
54
54
55
+ fn usb_controller_service_iter (
56
+ controller_type : UsbControllerType ,
57
+ ) -> Result < IoServiceIterator , Error > {
58
+ unsafe {
59
+ let dictionary = match controller_type {
60
+ UsbControllerType :: XHCI => IOServiceMatching ( kAppleUSBXHCI) ,
61
+ UsbControllerType :: EHCI => IOServiceMatching ( kAppleUSBEHCI) ,
62
+ UsbControllerType :: OHCI | UsbControllerType :: UHCI => IOServiceMatching ( kAppleUSBOHCI) ,
63
+ UsbControllerType :: VHCI => IOServiceMatching ( kAppleUSBVHCI) ,
64
+ } ;
65
+ if dictionary. is_null ( ) {
66
+ return Err ( Error :: new ( ErrorKind :: Other , "IOServiceMatching failed" ) ) ;
67
+ }
68
+
69
+ let mut iterator = 0 ;
70
+ let r = IOServiceGetMatchingServices ( kIOMasterPortDefault, dictionary, & mut iterator) ;
71
+ if r != kIOReturnSuccess {
72
+ return Err ( Error :: from_raw_os_error ( r) ) ;
73
+ }
74
+
75
+ Ok ( IoServiceIterator :: new ( iterator) )
76
+ }
77
+ }
78
+
55
79
pub fn list_devices ( ) -> Result < impl Iterator < Item = DeviceInfo > , Error > {
56
80
Ok ( usb_service_iter ( kIOUSBDeviceClassName) ?. filter_map ( probe_device) )
57
81
}
@@ -60,10 +84,22 @@ pub fn list_buses() -> Result<impl Iterator<Item = BusInfo>, Error> {
60
84
// Chain all the HCI types into one iterator
61
85
// A bit of a hack, could maybe probe IOPCIDevice and filter on children with IOClass.starts_with("AppleUSB")
62
86
Ok ( [
63
- ( usb_service_iter ( kAppleUSBXHCI) ?, UsbControllerType :: XHCI ) ,
64
- ( usb_service_iter ( kAppleUSBEHCI) ?, UsbControllerType :: EHCI ) ,
65
- ( usb_service_iter ( kAppleUSBOHCI) ?, UsbControllerType :: OHCI ) ,
66
- ( usb_service_iter ( kAppleUSBVHCI) ?, UsbControllerType :: VHCI ) ,
87
+ (
88
+ usb_controller_service_iter ( UsbControllerType :: XHCI ) ?,
89
+ UsbControllerType :: XHCI ,
90
+ ) ,
91
+ (
92
+ usb_controller_service_iter ( UsbControllerType :: EHCI ) ?,
93
+ UsbControllerType :: EHCI ,
94
+ ) ,
95
+ (
96
+ usb_controller_service_iter ( UsbControllerType :: OHCI ) ?,
97
+ UsbControllerType :: OHCI ,
98
+ ) ,
99
+ (
100
+ usb_controller_service_iter ( UsbControllerType :: VHCI ) ?,
101
+ UsbControllerType :: VHCI ,
102
+ ) ,
67
103
]
68
104
. into_iter ( )
69
105
. map ( |( iter, hci_type) | iter. zip ( std:: iter:: repeat ( hci_type) ) )
0 commit comments