blob: aa7e1ea0ad511629f83500d2b789b783b9f01cf6 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <CoreFoundation/CoreFoundation.h>
18
19#include <IOKit/IOKitLib.h>
20#include <IOKit/IOCFPlugIn.h>
21#include <IOKit/usb/IOUSBLib.h>
22#include <IOKit/IOMessage.h>
23#include <mach/mach_port.h>
24
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080025#include <stdio.h>
26
Dan Albertdc0f8ec2015-02-25 10:26:17 -080027#include "sysdeps.h"
28
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080029#define TRACE_TAG TRACE_USB
30#include "adb.h"
Dan Albertdc0f8ec2015-02-25 10:26:17 -080031#include "transport.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080032
33#define DBG D
34
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080035static IONotificationPortRef notificationPort = 0;
Al Sutton8e01cc62014-11-21 12:21:12 +000036static io_iterator_t notificationIterator;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080037
38struct usb_handle
39{
40 UInt8 bulkIn;
41 UInt8 bulkOut;
42 IOUSBInterfaceInterface **interface;
43 io_object_t usbNotification;
44 unsigned int zero_mask;
45};
46
47static CFRunLoopRef currentRunLoop = 0;
48static pthread_mutex_t start_lock;
49static pthread_cond_t start_cond;
50
51
Dima Zavin3fd82b82009-05-08 18:25:58 -070052static void AndroidInterfaceAdded(void *refCon, io_iterator_t iterator);
53static void AndroidInterfaceNotify(void *refCon, io_iterator_t iterator,
54 natural_t messageType,
55 void *messageArgument);
56static usb_handle* CheckInterface(IOUSBInterfaceInterface **iface,
57 UInt16 vendor, UInt16 product);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080058
59static int
60InitUSB()
61{
62 CFMutableDictionaryRef matchingDict;
63 CFRunLoopSourceRef runLoopSource;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080064
65 //* To set up asynchronous notifications, create a notification port and
66 //* add its run loop event source to the program's run loop
67 notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
68 runLoopSource = IONotificationPortGetRunLoopSource(notificationPort);
69 CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
70
Al Sutton8e01cc62014-11-21 12:21:12 +000071 //* Create our matching dictionary to find the Android device's
72 //* adb interface
73 //* IOServiceAddMatchingNotification consumes the reference, so we do
74 //* not need to release this
75 matchingDict = IOServiceMatching(kIOUSBInterfaceClassName);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080076
Al Sutton8e01cc62014-11-21 12:21:12 +000077 if (!matchingDict) {
78 DBG("ERR: Couldn't create USB matching dictionary.\n");
79 return -1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080080 }
81
Al Sutton8e01cc62014-11-21 12:21:12 +000082 //* We have to get notifications for all potential candidates and test them
83 //* at connection time because the matching rules don't allow for a
84 //* USB interface class of 0xff for class+subclass+protocol matches
85 //* See https://developer.apple.com/library/mac/qa/qa1076/_index.html
86 IOServiceAddMatchingNotification(
87 notificationPort,
88 kIOFirstMatchNotification,
89 matchingDict,
90 AndroidInterfaceAdded,
91 NULL,
92 &notificationIterator);
93
94 //* Iterate over set of matching interfaces to access already-present
95 //* devices and to arm the notification
96 AndroidInterfaceAdded(NULL, notificationIterator);
97
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080098 return 0;
99}
100
101static void
Dima Zavin3fd82b82009-05-08 18:25:58 -0700102AndroidInterfaceAdded(void *refCon, io_iterator_t iterator)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800103{
104 kern_return_t kr;
105 io_service_t usbDevice;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700106 io_service_t usbInterface;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800107 IOCFPlugInInterface **plugInInterface = NULL;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700108 IOUSBInterfaceInterface220 **iface = NULL;
109 IOUSBDeviceInterface197 **dev = NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800110 HRESULT result;
111 SInt32 score;
Scott Andersone109d262012-04-20 11:21:14 -0700112 UInt32 locationId;
Al Sutton8e01cc62014-11-21 12:21:12 +0000113 UInt8 class, subclass, protocol;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800114 UInt16 vendor;
115 UInt16 product;
116 UInt8 serialIndex;
117 char serial[256];
Scott Andersone109d262012-04-20 11:21:14 -0700118 char devpathBuf[64];
119 char *devpath = NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800120
Dima Zavin3fd82b82009-05-08 18:25:58 -0700121 while ((usbInterface = IOIteratorNext(iterator))) {
122 //* Create an intermediate interface plugin
123 kr = IOCreatePlugInInterfaceForService(usbInterface,
124 kIOUSBInterfaceUserClientTypeID,
125 kIOCFPlugInInterfaceID,
126 &plugInInterface, &score);
127 IOObjectRelease(usbInterface);
128 if ((kIOReturnSuccess != kr) || (!plugInInterface)) {
129 DBG("ERR: Unable to create an interface plug-in (%08x)\n", kr);
130 continue;
131 }
132
133 //* This gets us the interface object
134 result = (*plugInInterface)->QueryInterface(plugInInterface,
135 CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID), (LPVOID)
136 &iface);
137 //* We only needed the plugin to get the interface, so discard it
138 (*plugInInterface)->Release(plugInInterface);
139 if (result || !iface) {
140 DBG("ERR: Couldn't query the interface (%08x)\n", (int) result);
141 continue;
142 }
143
Al Sutton8e01cc62014-11-21 12:21:12 +0000144 kr = (*iface)->GetInterfaceClass(iface, &class);
145 kr = (*iface)->GetInterfaceSubClass(iface, &subclass);
146 kr = (*iface)->GetInterfaceProtocol(iface, &protocol);
147 if(class != ADB_CLASS || subclass != ADB_SUBCLASS || protocol != ADB_PROTOCOL) {
148 // Ignore non-ADB devices.
149 DBG("Ignoring interface with incorrect class/subclass/protocol - %d, %d, %d\n", class, subclass, protocol);
150 (*iface)->Release(iface);
151 continue;
152 }
153
Dima Zavin3fd82b82009-05-08 18:25:58 -0700154 //* this gets us an ioservice, with which we will find the actual
155 //* device; after getting a plugin, and querying the interface, of
156 //* course.
157 //* Gotta love OS X
158 kr = (*iface)->GetDevice(iface, &usbDevice);
159 if (kIOReturnSuccess != kr || !usbDevice) {
160 DBG("ERR: Couldn't grab device from interface (%08x)\n", kr);
161 continue;
162 }
163
164 plugInInterface = NULL;
165 score = 0;
166 //* create an intermediate device plugin
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800167 kr = IOCreatePlugInInterfaceForService(usbDevice,
168 kIOUSBDeviceUserClientTypeID,
169 kIOCFPlugInInterfaceID,
170 &plugInInterface, &score);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700171 //* only needed this to find the plugin
172 (void)IOObjectRelease(usbDevice);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800173 if ((kIOReturnSuccess != kr) || (!plugInInterface)) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700174 DBG("ERR: Unable to create a device plug-in (%08x)\n", kr);
175 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800176 }
177
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800178 result = (*plugInInterface)->QueryInterface(plugInInterface,
179 CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID), (LPVOID) &dev);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700180 //* only needed this to query the plugin
181 (*plugInInterface)->Release(plugInInterface);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800182 if (result || !dev) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700183 DBG("ERR: Couldn't create a device interface (%08x)\n",
184 (int) result);
185 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800186 }
187
Dima Zavin3fd82b82009-05-08 18:25:58 -0700188 //* Now after all that, we actually have a ref to the device and
189 //* the interface that matched our criteria
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800190 kr = (*dev)->GetDeviceVendor(dev, &vendor);
191 kr = (*dev)->GetDeviceProduct(dev, &product);
Scott Andersone109d262012-04-20 11:21:14 -0700192 kr = (*dev)->GetLocationID(dev, &locationId);
193 if (kr == 0) {
Ying Wang42a809b2014-08-14 15:50:13 -0700194 snprintf(devpathBuf, sizeof(devpathBuf), "usb:%" PRIu32 "X",
195 (unsigned int)locationId);
Scott Andersone109d262012-04-20 11:21:14 -0700196 devpath = devpathBuf;
197 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800198 kr = (*dev)->USBGetSerialNumberStringIndex(dev, &serialIndex);
199
Guang Zhu1a1f8182009-08-06 17:21:52 -0700200 if (serialIndex > 0) {
201 IOUSBDevRequest req;
202 UInt16 buffer[256];
203 UInt16 languages[128];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800204
Guang Zhu1a1f8182009-08-06 17:21:52 -0700205 memset(languages, 0, sizeof(languages));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800206
Guang Zhu1a1f8182009-08-06 17:21:52 -0700207 req.bmRequestType =
208 USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
209 req.bRequest = kUSBRqGetDescriptor;
210 req.wValue = (kUSBStringDesc << 8) | 0;
211 req.wIndex = 0;
212 req.pData = languages;
213 req.wLength = sizeof(languages);
214 kr = (*dev)->DeviceRequest(dev, &req);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800215
Guang Zhu1a1f8182009-08-06 17:21:52 -0700216 if (kr == kIOReturnSuccess && req.wLenDone > 0) {
217
218 int langCount = (req.wLenDone - 2) / 2, lang;
219
220 for (lang = 1; lang <= langCount; lang++) {
221
222 memset(buffer, 0, sizeof(buffer));
223 memset(&req, 0, sizeof(req));
224
225 req.bmRequestType =
226 USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
227 req.bRequest = kUSBRqGetDescriptor;
228 req.wValue = (kUSBStringDesc << 8) | serialIndex;
229 req.wIndex = languages[lang];
230 req.pData = buffer;
231 req.wLength = sizeof(buffer);
232 kr = (*dev)->DeviceRequest(dev, &req);
233
234 if (kr == kIOReturnSuccess && req.wLenDone > 0) {
235 int i, count;
236
237 // skip first word, and copy the rest to the serial string,
238 // changing shorts to bytes.
239 count = (req.wLenDone - 1) / 2;
240 for (i = 0; i < count; i++)
241 serial[i] = buffer[i + 1];
242 serial[i] = 0;
243 break;
244 }
245 }
246 }
247 }
Dima Zavin3fd82b82009-05-08 18:25:58 -0700248 (*dev)->Release(dev);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800249
Dima Zavin3fd82b82009-05-08 18:25:58 -0700250 DBG("INFO: Found vid=%04x pid=%04x serial=%s\n", vendor, product,
251 serial);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800252
Dima Zavin3fd82b82009-05-08 18:25:58 -0700253 usb_handle* handle = CheckInterface((IOUSBInterfaceInterface**)iface,
254 vendor, product);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800255 if (handle == NULL) {
256 DBG("ERR: Could not find device interface: %08x\n", kr);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700257 (*iface)->Release(iface);
258 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800259 }
260
261 DBG("AndroidDeviceAdded calling register_usb_transport\n");
Scott Andersone109d262012-04-20 11:21:14 -0700262 register_usb_transport(handle, (serial[0] ? serial : NULL), devpath, 1);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800263
Dima Zavin3fd82b82009-05-08 18:25:58 -0700264 // Register for an interest notification of this device being removed.
265 // Pass the reference to our private data as the refCon for the
266 // notification.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800267 kr = IOServiceAddInterestNotification(notificationPort,
Dima Zavin3fd82b82009-05-08 18:25:58 -0700268 usbInterface,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800269 kIOGeneralInterest,
Dima Zavin3fd82b82009-05-08 18:25:58 -0700270 AndroidInterfaceNotify,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800271 handle,
272 &handle->usbNotification);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700273
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800274 if (kIOReturnSuccess != kr) {
275 DBG("ERR: Unable to create interest notification (%08x)\n", kr);
276 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800277 }
278}
279
280static void
Dima Zavin3fd82b82009-05-08 18:25:58 -0700281AndroidInterfaceNotify(void *refCon, io_service_t service, natural_t messageType, void *messageArgument)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800282{
283 usb_handle *handle = (usb_handle *)refCon;
284
285 if (messageType == kIOMessageServiceIsTerminated) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700286 if (!handle) {
287 DBG("ERR: NULL handle\n");
288 return;
289 }
290 DBG("AndroidInterfaceNotify\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800291 IOObjectRelease(handle->usbNotification);
292 usb_kick(handle);
293 }
294}
295
Dima Zavin3fd82b82009-05-08 18:25:58 -0700296//* TODO: simplify this further since we only register to get ADB interface
297//* subclass+protocol events
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800298static usb_handle*
Dima Zavin3fd82b82009-05-08 18:25:58 -0700299CheckInterface(IOUSBInterfaceInterface **interface, UInt16 vendor, UInt16 product)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800300{
301 usb_handle* handle = NULL;
302 IOReturn kr;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800303 UInt8 interfaceNumEndpoints, interfaceClass, interfaceSubClass, interfaceProtocol;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700304 UInt8 endpoint;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800305
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800306
Dima Zavin3fd82b82009-05-08 18:25:58 -0700307 //* Now open the interface. This will cause the pipes associated with
308 //* the endpoints in the interface descriptor to be instantiated
309 kr = (*interface)->USBInterfaceOpen(interface);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800310 if (kr != kIOReturnSuccess) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700311 DBG("ERR: Could not open interface: (%08x)\n", kr);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800312 return NULL;
313 }
314
Dima Zavin3fd82b82009-05-08 18:25:58 -0700315 //* Get the number of endpoints associated with this interface
316 kr = (*interface)->GetNumEndpoints(interface, &interfaceNumEndpoints);
317 if (kr != kIOReturnSuccess) {
318 DBG("ERR: Unable to get number of endpoints: (%08x)\n", kr);
319 goto err_get_num_ep;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800320 }
321
Dima Zavin3fd82b82009-05-08 18:25:58 -0700322 //* Get interface class, subclass and protocol
323 if ((*interface)->GetInterfaceClass(interface, &interfaceClass) != kIOReturnSuccess ||
324 (*interface)->GetInterfaceSubClass(interface, &interfaceSubClass) != kIOReturnSuccess ||
325 (*interface)->GetInterfaceProtocol(interface, &interfaceProtocol) != kIOReturnSuccess) {
326 DBG("ERR: Unable to get interface class, subclass and protocol\n");
327 goto err_get_interface_class;
328 }
329
330 //* check to make sure interface class, subclass and protocol match ADB
331 //* avoid opening mass storage endpoints
332 if (!is_adb_interface(vendor, product, interfaceClass,
333 interfaceSubClass, interfaceProtocol))
334 goto err_bad_adb_interface;
335
336 handle = calloc(1, sizeof(usb_handle));
337
338 //* Iterate over the endpoints for this interface and find the first
339 //* bulk in/out pipes available. These will be our read/write pipes.
340 for (endpoint = 0; endpoint <= interfaceNumEndpoints; endpoint++) {
341 UInt8 transferType;
342 UInt16 maxPacketSize;
343 UInt8 interval;
344 UInt8 number;
345 UInt8 direction;
346
347 kr = (*interface)->GetPipeProperties(interface, endpoint, &direction,
348 &number, &transferType, &maxPacketSize, &interval);
349
350 if (kIOReturnSuccess == kr) {
351 if (kUSBBulk != transferType)
352 continue;
353
354 if (kUSBIn == direction)
355 handle->bulkIn = endpoint;
356
357 if (kUSBOut == direction)
358 handle->bulkOut = endpoint;
359
360 handle->zero_mask = maxPacketSize - 1;
361 } else {
362 DBG("ERR: FindDeviceInterface - could not get pipe properties\n");
363 goto err_get_pipe_props;
364 }
365 }
366
367 handle->interface = interface;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800368 return handle;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700369
370err_get_pipe_props:
371 free(handle);
372err_bad_adb_interface:
373err_get_interface_class:
374err_get_num_ep:
375 (*interface)->USBInterfaceClose(interface);
376 return NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800377}
378
379
380void* RunLoopThread(void* unused)
381{
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800382 InitUSB();
383
384 currentRunLoop = CFRunLoopGetCurrent();
385
386 // Signal the parent that we are running
387 adb_mutex_lock(&start_lock);
388 adb_cond_signal(&start_cond);
389 adb_mutex_unlock(&start_lock);
390
391 CFRunLoopRun();
392 currentRunLoop = 0;
393
Al Sutton8e01cc62014-11-21 12:21:12 +0000394 IOObjectRelease(notificationIterator);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800395 IONotificationPortDestroy(notificationPort);
396
397 DBG("RunLoopThread done\n");
398 return NULL;
399}
400
401
402static int initialized = 0;
403void usb_init()
404{
405 if (!initialized)
406 {
407 adb_thread_t tid;
408
409 adb_mutex_init(&start_lock, NULL);
410 adb_cond_init(&start_cond, NULL);
411
412 if(adb_thread_create(&tid, RunLoopThread, NULL))
413 fatal_errno("cannot create input thread");
414
415 // Wait for initialization to finish
416 adb_mutex_lock(&start_lock);
417 adb_cond_wait(&start_cond, &start_lock);
418 adb_mutex_unlock(&start_lock);
419
420 adb_mutex_destroy(&start_lock);
421 adb_cond_destroy(&start_cond);
422
423 initialized = 1;
424 }
425}
426
427void usb_cleanup()
428{
429 DBG("usb_cleanup\n");
430 close_usb_devices();
431 if (currentRunLoop)
432 CFRunLoopStop(currentRunLoop);
433}
434
435int usb_write(usb_handle *handle, const void *buf, int len)
436{
437 IOReturn result;
438
439 if (!len)
440 return 0;
441
442 if (!handle)
443 return -1;
444
445 if (NULL == handle->interface) {
446 DBG("ERR: usb_write interface was null\n");
447 return -1;
448 }
449
450 if (0 == handle->bulkOut) {
451 DBG("ERR: bulkOut endpoint not assigned\n");
452 return -1;
453 }
454
455 result =
456 (*handle->interface)->WritePipe(
457 handle->interface, handle->bulkOut, (void *)buf, len);
458
459 if ((result == 0) && (handle->zero_mask)) {
460 /* we need 0-markers and our transfer */
461 if(!(len & handle->zero_mask)) {
462 result =
463 (*handle->interface)->WritePipe(
464 handle->interface, handle->bulkOut, (void *)buf, 0);
465 }
466 }
467
468 if (0 == result)
469 return 0;
470
471 DBG("ERR: usb_write failed with status %d\n", result);
472 return -1;
473}
474
475int usb_read(usb_handle *handle, void *buf, int len)
476{
477 IOReturn result;
478 UInt32 numBytes = len;
479
480 if (!len) {
481 return 0;
482 }
483
484 if (!handle) {
485 return -1;
486 }
487
488 if (NULL == handle->interface) {
489 DBG("ERR: usb_read interface was null\n");
490 return -1;
491 }
492
493 if (0 == handle->bulkIn) {
494 DBG("ERR: bulkIn endpoint not assigned\n");
495 return -1;
496 }
497
Esteban de la Canal9dd83dc2014-09-11 11:02:17 -0700498 result = (*handle->interface)->ReadPipe(handle->interface, handle->bulkIn, buf, &numBytes);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800499
Esteban de la Canal9dd83dc2014-09-11 11:02:17 -0700500 if (kIOUSBPipeStalled == result) {
501 DBG(" Pipe stalled, clearing stall.\n");
502 (*handle->interface)->ClearPipeStall(handle->interface, handle->bulkIn);
503 result = (*handle->interface)->ReadPipe(handle->interface, handle->bulkIn, buf, &numBytes);
504 }
505
506 if (kIOReturnSuccess == result)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800507 return 0;
508 else {
Esteban de la Canal9dd83dc2014-09-11 11:02:17 -0700509 DBG("ERR: usb_read failed with status %x\n", result);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800510 }
511
512 return -1;
513}
514
515int usb_close(usb_handle *handle)
516{
517 return 0;
518}
519
520void usb_kick(usb_handle *handle)
521{
522 /* release the interface */
Dima Zavin3fd82b82009-05-08 18:25:58 -0700523 if (!handle)
524 return;
525
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800526 if (handle->interface)
527 {
528 (*handle->interface)->USBInterfaceClose(handle->interface);
529 (*handle->interface)->Release(handle->interface);
530 handle->interface = 0;
531 }
532}