2 * darwin backend for libusb 1.0
3 * Copyright © 2008-2015 Nathan Hjelm <hjelmn@users.sourceforge.net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #if !defined(LIBUSB_DARWIN_H)
21 #define LIBUSB_DARWIN_H
25 #include <IOKit/IOTypes.h>
26 #include <IOKit/IOCFBundle.h>
27 #include <IOKit/usb/IOUSBLib.h>
28 #include <IOKit/IOCFPlugIn.h>
30 /* IOUSBInterfaceInferface */
32 /* New in OS 10.12.0. */
33 #if defined (kIOUSBInterfaceInterfaceID800) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
35 #define usb_interface_t IOUSBInterfaceInterface800
36 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID800
37 #define InterfaceVersion 800
39 /* New in OS 10.10.0. */
40 #elif defined (kIOUSBInterfaceInterfaceID700) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 101000)
42 #define usb_interface_t IOUSBInterfaceInterface700
43 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID700
44 #define InterfaceVersion 700
46 /* New in OS 10.9.0. */
47 #elif defined (kIOUSBInterfaceInterfaceID650) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
49 #define usb_interface_t IOUSBInterfaceInterface650
50 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID650
51 #define InterfaceVersion 650
53 /* New in OS 10.8.2 but can't test deployment target to that granularity, so round up. */
54 #elif defined (kIOUSBInterfaceInterfaceID550) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
56 #define usb_interface_t IOUSBInterfaceInterface550
57 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID550
58 #define InterfaceVersion 550
60 /* New in OS 10.7.3 but can't test deployment target to that granularity, so round up. */
61 #elif defined (kIOUSBInterfaceInterfaceID500) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
63 #define usb_interface_t IOUSBInterfaceInterface500
64 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID500
65 #define InterfaceVersion 500
67 /* New in OS 10.5.0. */
68 #elif defined (kIOUSBInterfaceInterfaceID300) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
70 #define usb_interface_t IOUSBInterfaceInterface300
71 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID300
72 #define InterfaceVersion 300
74 /* New in OS 10.4.5 (or 10.4.6?) but can't test deployment target to that granularity, so round up. */
75 #elif defined (kIOUSBInterfaceInterfaceID245) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
77 #define usb_interface_t IOUSBInterfaceInterface245
78 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID245
79 #define InterfaceVersion 245
81 /* New in OS 10.4.0. */
82 #elif defined (kIOUSBInterfaceInterfaceID220) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1040)
84 #define usb_interface_t IOUSBInterfaceInterface220
85 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID220
86 #define InterfaceVersion 220
90 #error "IOUSBFamily is too old. Please upgrade your SDK and/or deployment target"
94 /* IOUSBDeviceInterface */
96 /* New in OS 10.9.0. */
97 #if defined (kIOUSBDeviceInterfaceID650) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
99 #define usb_device_t IOUSBDeviceInterface650
100 #define DeviceInterfaceID kIOUSBDeviceInterfaceID650
101 #define DeviceVersion 650
103 /* New in OS 10.7.3 but can't test deployment target to that granularity, so round up. */
104 #elif defined (kIOUSBDeviceInterfaceID500) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
106 #define usb_device_t IOUSBDeviceInterface500
107 #define DeviceInterfaceID kIOUSBDeviceInterfaceID500
108 #define DeviceVersion 500
110 /* New in OS 10.5.4 but can't test deployment target to that granularity, so round up. */
111 #elif defined (kIOUSBDeviceInterfaceID320) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
113 #define usb_device_t IOUSBDeviceInterface320
114 #define DeviceInterfaceID kIOUSBDeviceInterfaceID320
115 #define DeviceVersion 320
117 /* New in OS 10.5.0. */
118 #elif defined (kIOUSBDeviceInterfaceID300) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
120 #define usb_device_t IOUSBDeviceInterface300
121 #define DeviceInterfaceID kIOUSBDeviceInterfaceID300
122 #define DeviceVersion 300
124 /* New in OS 10.4.5 (or 10.4.6?) but can't test deployment target to that granularity, so round up. */
125 #elif defined (kIOUSBDeviceInterfaceID245) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
127 #define usb_device_t IOUSBDeviceInterface245
128 #define DeviceInterfaceID kIOUSBDeviceInterfaceID245
129 #define DeviceVersion 245
131 /* New in OS 10.2.3 but can't test deployment target to that granularity, so round up. */
132 #elif defined (kIOUSBDeviceInterfaceID197) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030)
134 #define usb_device_t IOUSBDeviceInterface197
135 #define DeviceInterfaceID kIOUSBDeviceInterfaceID197
136 #define DeviceVersion 197
140 #error "IOUSBFamily is too old. Please upgrade your SDK and/or deployment target"
144 #if !defined(IO_OBJECT_NULL)
145 #define IO_OBJECT_NULL ((io_object_t) 0)
148 typedef IOCFPlugInInterface *io_cf_plugin_ref_t;
149 typedef IONotificationPortRef io_notification_port_t;
151 /* private structures */
152 struct darwin_cached_device {
153 struct list_head list;
154 IOUSBDeviceDescriptor dev_descriptor;
156 UInt64 parent_session;
160 usb_device_t **device;
162 UInt8 first_config, active_config, port;
167 struct darwin_device_priv {
168 struct darwin_cached_device *dev;
171 struct darwin_device_handle_priv {
173 CFRunLoopSourceRef cfSource;
175 struct darwin_interface {
176 usb_interface_t **interface;
177 uint8_t num_endpoints;
178 CFRunLoopSourceRef cfSource;
179 uint64_t frames[256];
180 uint8_t endpoint_addrs[USB_MAXENDPOINTS];
181 } interfaces[USB_MAXINTERFACES];
184 struct darwin_transfer_priv {
186 IOUSBIsocFrame *isoc_framelist;
190 IOUSBDevRequestTO req;
194 /* Completion status */