2 * darwin backend for libusb 1.0
3 * Copyright © 2008-2019 Nathan Hjelm <hjelmn@users.sourceforge.net>
4 * Copyright © 2019 Google LLC. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #if !defined(LIBUSB_DARWIN_H)
22 #define LIBUSB_DARWIN_H
28 #include <IOKit/IOTypes.h>
29 #include <IOKit/IOCFBundle.h>
30 #include <IOKit/usb/IOUSBLib.h>
31 #include <IOKit/IOCFPlugIn.h>
33 /* IOUSBInterfaceInferface */
35 /* New in OS 10.12.0. */
36 #if defined (kIOUSBInterfaceInterfaceID800) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
38 #define usb_interface_t IOUSBInterfaceInterface800
39 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID800
40 #define InterfaceVersion 800
42 /* New in OS 10.10.0. */
43 #elif defined (kIOUSBInterfaceInterfaceID700) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 101000)
45 #define usb_interface_t IOUSBInterfaceInterface700
46 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID700
47 #define InterfaceVersion 700
49 /* New in OS 10.9.0. */
50 #elif defined (kIOUSBInterfaceInterfaceID650) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
52 #define usb_interface_t IOUSBInterfaceInterface650
53 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID650
54 #define InterfaceVersion 650
56 /* New in OS 10.8.2 but can't test deployment target to that granularity, so round up. */
57 #elif defined (kIOUSBInterfaceInterfaceID550) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
59 #define usb_interface_t IOUSBInterfaceInterface550
60 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID550
61 #define InterfaceVersion 550
63 /* New in OS 10.7.3 but can't test deployment target to that granularity, so round up. */
64 #elif defined (kIOUSBInterfaceInterfaceID500) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
66 #define usb_interface_t IOUSBInterfaceInterface500
67 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID500
68 #define InterfaceVersion 500
70 /* New in OS 10.5.0. */
71 #elif defined (kIOUSBInterfaceInterfaceID300) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
73 #define usb_interface_t IOUSBInterfaceInterface300
74 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID300
75 #define InterfaceVersion 300
77 /* New in OS 10.4.5 (or 10.4.6?) but can't test deployment target to that granularity, so round up. */
78 #elif defined (kIOUSBInterfaceInterfaceID245) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
80 #define usb_interface_t IOUSBInterfaceInterface245
81 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID245
82 #define InterfaceVersion 245
84 /* New in OS 10.4.0. */
85 #elif defined (kIOUSBInterfaceInterfaceID220) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1040)
87 #define usb_interface_t IOUSBInterfaceInterface220
88 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID220
89 #define InterfaceVersion 220
93 #error "IOUSBFamily is too old. Please upgrade your SDK and/or deployment target"
97 /* IOUSBDeviceInterface */
99 /* New in OS 10.9.0. */
100 #if defined (kIOUSBDeviceInterfaceID650) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
102 #define usb_device_t IOUSBDeviceInterface650
103 #define DeviceInterfaceID kIOUSBDeviceInterfaceID650
104 #define DeviceVersion 650
106 /* New in OS 10.7.3 but can't test deployment target to that granularity, so round up. */
107 #elif defined (kIOUSBDeviceInterfaceID500) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
109 #define usb_device_t IOUSBDeviceInterface500
110 #define DeviceInterfaceID kIOUSBDeviceInterfaceID500
111 #define DeviceVersion 500
113 /* New in OS 10.5.4 but can't test deployment target to that granularity, so round up. */
114 #elif defined (kIOUSBDeviceInterfaceID320) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
116 #define usb_device_t IOUSBDeviceInterface320
117 #define DeviceInterfaceID kIOUSBDeviceInterfaceID320
118 #define DeviceVersion 320
120 /* New in OS 10.5.0. */
121 #elif defined (kIOUSBDeviceInterfaceID300) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
123 #define usb_device_t IOUSBDeviceInterface300
124 #define DeviceInterfaceID kIOUSBDeviceInterfaceID300
125 #define DeviceVersion 300
127 /* New in OS 10.4.5 (or 10.4.6?) but can't test deployment target to that granularity, so round up. */
128 #elif defined (kIOUSBDeviceInterfaceID245) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
130 #define usb_device_t IOUSBDeviceInterface245
131 #define DeviceInterfaceID kIOUSBDeviceInterfaceID245
132 #define DeviceVersion 245
134 /* New in OS 10.2.3 but can't test deployment target to that granularity, so round up. */
135 #elif defined (kIOUSBDeviceInterfaceID197) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030)
137 #define usb_device_t IOUSBDeviceInterface197
138 #define DeviceInterfaceID kIOUSBDeviceInterfaceID197
139 #define DeviceVersion 197
143 #error "IOUSBFamily is too old. Please upgrade your SDK and/or deployment target"
147 #if !defined(IO_OBJECT_NULL)
148 #define IO_OBJECT_NULL ((io_object_t) 0)
151 typedef IOCFPlugInInterface *io_cf_plugin_ref_t;
152 typedef IONotificationPortRef io_notification_port_t;
154 /* private structures */
155 struct darwin_cached_device {
156 struct list_head list;
157 IOUSBDeviceDescriptor dev_descriptor;
159 UInt64 parent_session;
161 USBDeviceAddress address;
163 usb_device_t **device;
165 UInt8 first_config, active_config, port;
171 struct darwin_device_priv {
172 struct darwin_cached_device *dev;
175 struct darwin_device_handle_priv {
177 CFRunLoopSourceRef cfSource;
179 struct darwin_interface {
180 usb_interface_t **interface;
181 uint8_t num_endpoints;
182 CFRunLoopSourceRef cfSource;
183 uint64_t frames[256];
184 uint8_t endpoint_addrs[USB_MAXENDPOINTS];
185 } interfaces[USB_MAXINTERFACES];
188 struct darwin_transfer_priv {
190 IOUSBIsocFrame *isoc_framelist;
194 IOUSBDevRequestTO req;
198 /* Completion status */