- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / libusb / src / libusb / os / darwin_usb.h
1 /*
2  * darwin backend for libusbx 1.0
3  * Copyright © 2008-2013 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 (kIOUSBInterfaceInterfaceID550)
32
33 #define usb_interface_t IOUSBInterfaceInterface550
34 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID550
35 #define InterfaceVersion 550
36
37 #elif defined (kIOUSBInterfaceInterfaceID500)
38
39 #define usb_interface_t IOUSBInterfaceInterface500
40 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID500
41 #define InterfaceVersion 500
42
43 #elif defined (kIOUSBInterfaceInterfaceID300)
44
45 #define usb_interface_t IOUSBInterfaceInterface300
46 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID300
47 #define InterfaceVersion 300
48
49 #elif defined (kIOUSBInterfaceInterfaceID245)
50
51 #define usb_interface_t IOUSBInterfaceInterface245
52 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID245
53 #define InterfaceVersion 245
54
55 #elif defined (kIOUSBInterfaceInterfaceID220)
56
57 #define usb_interface_t IOUSBInterfaceInterface220
58 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID220
59 #define InterfaceVersion 220
60
61 #else
62
63 #error "IOUSBFamily is too old. Please upgrade your OS"
64
65 #endif
66
67 /* IOUSBDeviceInterface */
68 #if defined (kIOUSBDeviceInterfaceID500)
69
70 #define usb_device_t    IOUSBDeviceInterface500
71 #define DeviceInterfaceID kIOUSBDeviceInterfaceID500
72 #define DeviceVersion 500
73
74 #elif defined (kIOUSBDeviceInterfaceID320)
75
76 #define usb_device_t    IOUSBDeviceInterface320
77 #define DeviceInterfaceID kIOUSBDeviceInterfaceID320
78 #define DeviceVersion 320
79
80 #elif defined (kIOUSBDeviceInterfaceID300)
81
82 #define usb_device_t    IOUSBDeviceInterface300
83 #define DeviceInterfaceID kIOUSBDeviceInterfaceID300
84 #define DeviceVersion 300
85
86 #elif defined (kIOUSBDeviceInterfaceID245)
87
88 #define usb_device_t    IOUSBDeviceInterface245
89 #define DeviceInterfaceID kIOUSBDeviceInterfaceID245
90 #define DeviceVersion 245
91
92 #elif defined (kIOUSBDeviceInterfaceID220)
93 #define usb_device_t    IOUSBDeviceInterface197
94 #define DeviceInterfaceID kIOUSBDeviceInterfaceID197
95 #define DeviceVersion 197
96
97 #else
98
99 #error "IOUSBFamily is too old. Please upgrade your OS"
100
101 #endif
102
103 #if !defined(IO_OBJECT_NULL)
104 #define IO_OBJECT_NULL ((io_object_t) 0)
105 #endif
106
107 typedef IOCFPlugInInterface *io_cf_plugin_ref_t;
108 typedef IONotificationPortRef io_notification_port_t;
109
110 /* private structures */
111 struct darwin_cached_device {
112   struct list_head      list;
113   IOUSBDeviceDescriptor dev_descriptor;
114   UInt32                location;
115   UInt64                parent_session;
116   UInt64                session;
117   UInt16                address;
118   char                  sys_path[21];
119   usb_device_t        **device;
120   int                   open_count;
121   UInt8                 first_config, active_config, port;  
122   int                   can_enumerate;
123   int                   refcount;
124 };
125
126 struct darwin_device_priv {
127   struct darwin_cached_device *dev;
128 };
129
130 struct darwin_device_handle_priv {
131   int                  is_open;
132   CFRunLoopSourceRef   cfSource;
133   int                  fds[2];
134
135   struct darwin_interface {
136     usb_interface_t    **interface;
137     uint8_t              num_endpoints;
138     CFRunLoopSourceRef   cfSource;
139     uint64_t             frames[256];
140     uint8_t            endpoint_addrs[USB_MAXENDPOINTS];
141   } interfaces[USB_MAXINTERFACES];
142 };
143
144 struct darwin_transfer_priv {
145   /* Isoc */
146   IOUSBIsocFrame *isoc_framelist;
147   int num_iso_packets;
148
149   /* Control */
150   IOUSBDevRequestTO req;
151
152   /* Bulk */
153 };
154
155 /* structure for signaling io completion */
156 struct darwin_msg_async_io_complete {
157   struct usbi_transfer *itransfer;
158   IOReturn result;
159   UInt32 size;
160 };
161
162 #endif