• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * darwin backend for libusb 1.0
3  * Copyright © 2008-2015 Nathan Hjelm <hjelmn@users.sourceforge.net>
4  *
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.
9  *
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.
14  *
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
18  */
19 
20 #if !defined(LIBUSB_DARWIN_H)
21 #define LIBUSB_DARWIN_H
22 
23 #include "libusbi.h"
24 
25 #include <IOKit/IOTypes.h>
26 #include <IOKit/IOCFBundle.h>
27 #include <IOKit/usb/IOUSBLib.h>
28 #include <IOKit/IOCFPlugIn.h>
29 
30 /* IOUSBInterfaceInferface */
31 #if defined (kIOUSBInterfaceInterfaceID700) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
32 
33 #define usb_interface_t IOUSBInterfaceInterface700
34 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID700
35 #define InterfaceVersion 700
36 
37 #elif defined (kIOUSBInterfaceInterfaceID550) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
38 
39 #define usb_interface_t IOUSBInterfaceInterface550
40 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID550
41 #define InterfaceVersion 550
42 
43 #elif defined (kIOUSBInterfaceInterfaceID500)
44 
45 #define usb_interface_t IOUSBInterfaceInterface500
46 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID500
47 #define InterfaceVersion 500
48 
49 #elif defined (kIOUSBInterfaceInterfaceID300)
50 
51 #define usb_interface_t IOUSBInterfaceInterface300
52 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID300
53 #define InterfaceVersion 300
54 
55 #elif defined (kIOUSBInterfaceInterfaceID245)
56 
57 #define usb_interface_t IOUSBInterfaceInterface245
58 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID245
59 #define InterfaceVersion 245
60 
61 #elif defined (kIOUSBInterfaceInterfaceID220)
62 
63 #define usb_interface_t IOUSBInterfaceInterface220
64 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID220
65 #define InterfaceVersion 220
66 
67 #else
68 
69 #error "IOUSBFamily is too old. Please upgrade your OS"
70 
71 #endif
72 
73 /* IOUSBDeviceInterface */
74 #if defined (kIOUSBDeviceInterfaceID500) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
75 
76 #define usb_device_t    IOUSBDeviceInterface500
77 #define DeviceInterfaceID kIOUSBDeviceInterfaceID500
78 #define DeviceVersion 500
79 
80 #elif defined (kIOUSBDeviceInterfaceID320)
81 
82 #define usb_device_t    IOUSBDeviceInterface320
83 #define DeviceInterfaceID kIOUSBDeviceInterfaceID320
84 #define DeviceVersion 320
85 
86 #elif defined (kIOUSBDeviceInterfaceID300)
87 
88 #define usb_device_t    IOUSBDeviceInterface300
89 #define DeviceInterfaceID kIOUSBDeviceInterfaceID300
90 #define DeviceVersion 300
91 
92 #elif defined (kIOUSBDeviceInterfaceID245)
93 
94 #define usb_device_t    IOUSBDeviceInterface245
95 #define DeviceInterfaceID kIOUSBDeviceInterfaceID245
96 #define DeviceVersion 245
97 
98 #elif defined (kIOUSBDeviceInterfaceID220)
99 #define usb_device_t    IOUSBDeviceInterface197
100 #define DeviceInterfaceID kIOUSBDeviceInterfaceID197
101 #define DeviceVersion 197
102 
103 #else
104 
105 #error "IOUSBFamily is too old. Please upgrade your OS"
106 
107 #endif
108 
109 #if !defined(IO_OBJECT_NULL)
110 #define IO_OBJECT_NULL ((io_object_t) 0)
111 #endif
112 
113 typedef IOCFPlugInInterface *io_cf_plugin_ref_t;
114 typedef IONotificationPortRef io_notification_port_t;
115 
116 /* private structures */
117 struct darwin_cached_device {
118   struct list_head      list;
119   IOUSBDeviceDescriptor dev_descriptor;
120   UInt32                location;
121   UInt64                parent_session;
122   UInt64                session;
123   UInt16                address;
124   char                  sys_path[21];
125   usb_device_t        **device;
126   int                   open_count;
127   UInt8                 first_config, active_config, port;
128   int                   can_enumerate;
129   int                   refcount;
130 };
131 
132 struct darwin_device_priv {
133   struct darwin_cached_device *dev;
134 };
135 
136 struct darwin_device_handle_priv {
137   int                  is_open;
138   CFRunLoopSourceRef   cfSource;
139 
140   struct darwin_interface {
141     usb_interface_t    **interface;
142     uint8_t              num_endpoints;
143     CFRunLoopSourceRef   cfSource;
144     uint64_t             frames[256];
145     uint8_t              endpoint_addrs[USB_MAXENDPOINTS];
146   } interfaces[USB_MAXINTERFACES];
147 };
148 
149 struct darwin_transfer_priv {
150   /* Isoc */
151   IOUSBIsocFrame *isoc_framelist;
152   int num_iso_packets;
153 
154   /* Control */
155   IOUSBDevRequestTO req;
156 
157   /* Bulk */
158 
159   /* Completion status */
160   IOReturn result;
161   UInt32 size;
162 };
163 
164 #endif
165