blob: 94c8cfe7e74f47861088f72f92dffc82649053bc [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
Dan Albert33134262015-03-19 15:21:08 -070017#define TRACE_TAG TRACE_USB
18
19#include "sysdeps.h"
20
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080021#include <CoreFoundation/CoreFoundation.h>
22
23#include <IOKit/IOKitLib.h>
24#include <IOKit/IOCFPlugIn.h>
25#include <IOKit/usb/IOUSBLib.h>
26#include <IOKit/IOMessage.h>
27#include <mach/mach_port.h>
28
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080029#include <stdio.h>
30
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080031#include "adb.h"
Dan Albertdc0f8ec2015-02-25 10:26:17 -080032#include "transport.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080033
34#define DBG D
35
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080036static IONotificationPortRef notificationPort = 0;
Al Sutton8e01cc62014-11-21 12:21:12 +000037static io_iterator_t notificationIterator;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080038
39struct usb_handle
40{
41 UInt8 bulkIn;
42 UInt8 bulkOut;
43 IOUSBInterfaceInterface **interface;
44 io_object_t usbNotification;
45 unsigned int zero_mask;
46};
47
48static CFRunLoopRef currentRunLoop = 0;
49static pthread_mutex_t start_lock;
50static pthread_cond_t start_cond;
51
52
Dima Zavin3fd82b82009-05-08 18:25:58 -070053static void AndroidInterfaceAdded(void *refCon, io_iterator_t iterator);
54static void AndroidInterfaceNotify(void *refCon, io_iterator_t iterator,
55 natural_t messageType,
56 void *messageArgument);
57static usb_handle* CheckInterface(IOUSBInterfaceInterface **iface,
58 UInt16 vendor, UInt16 product);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080059
60static int
61InitUSB()
62{
63 CFMutableDictionaryRef matchingDict;
64 CFRunLoopSourceRef runLoopSource;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080065
66 //* To set up asynchronous notifications, create a notification port and
67 //* add its run loop event source to the program's run loop
68 notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
69 runLoopSource = IONotificationPortGetRunLoopSource(notificationPort);
70 CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
71
Al Sutton8e01cc62014-11-21 12:21:12 +000072 //* Create our matching dictionary to find the Android device's
73 //* adb interface
74 //* IOServiceAddMatchingNotification consumes the reference, so we do
75 //* not need to release this
76 matchingDict = IOServiceMatching(kIOUSBInterfaceClassName);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080077
Al Sutton8e01cc62014-11-21 12:21:12 +000078 if (!matchingDict) {
79 DBG("ERR: Couldn't create USB matching dictionary.\n");
80 return -1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080081 }
82
Al Sutton8e01cc62014-11-21 12:21:12 +000083 //* We have to get notifications for all potential candidates and test them
84 //* at connection time because the matching rules don't allow for a
85 //* USB interface class of 0xff for class+subclass+protocol matches
86 //* See https://developer.apple.com/library/mac/qa/qa1076/_index.html
87 IOServiceAddMatchingNotification(
88 notificationPort,
89 kIOFirstMatchNotification,
90 matchingDict,
91 AndroidInterfaceAdded,
92 NULL,
93 &notificationIterator);
94
95 //* Iterate over set of matching interfaces to access already-present
96 //* devices and to arm the notification
97 AndroidInterfaceAdded(NULL, notificationIterator);
98
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080099 return 0;
100}
101
102static void
Dima Zavin3fd82b82009-05-08 18:25:58 -0700103AndroidInterfaceAdded(void *refCon, io_iterator_t iterator)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800104{
105 kern_return_t kr;
106 io_service_t usbDevice;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700107 io_service_t usbInterface;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800108 IOCFPlugInInterface **plugInInterface = NULL;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700109 IOUSBInterfaceInterface220 **iface = NULL;
110 IOUSBDeviceInterface197 **dev = NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800111 HRESULT result;
112 SInt32 score;
Scott Andersone109d262012-04-20 11:21:14 -0700113 UInt32 locationId;
Al Sutton8e01cc62014-11-21 12:21:12 +0000114 UInt8 class, subclass, protocol;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800115 UInt16 vendor;
116 UInt16 product;
117 UInt8 serialIndex;
118 char serial[256];
Scott Andersone109d262012-04-20 11:21:14 -0700119 char devpathBuf[64];
120 char *devpath = NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800121
Dima Zavin3fd82b82009-05-08 18:25:58 -0700122 while ((usbInterface = IOIteratorNext(iterator))) {
123 //* Create an intermediate interface plugin
124 kr = IOCreatePlugInInterfaceForService(usbInterface,
125 kIOUSBInterfaceUserClientTypeID,
126 kIOCFPlugInInterfaceID,
127 &plugInInterface, &score);
128 IOObjectRelease(usbInterface);
129 if ((kIOReturnSuccess != kr) || (!plugInInterface)) {
130 DBG("ERR: Unable to create an interface plug-in (%08x)\n", kr);
131 continue;
132 }
133
134 //* This gets us the interface object
135 result = (*plugInInterface)->QueryInterface(plugInInterface,
136 CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID), (LPVOID)
137 &iface);
138 //* We only needed the plugin to get the interface, so discard it
139 (*plugInInterface)->Release(plugInInterface);
140 if (result || !iface) {
141 DBG("ERR: Couldn't query the interface (%08x)\n", (int) result);
142 continue;
143 }
144
Al Sutton8e01cc62014-11-21 12:21:12 +0000145 kr = (*iface)->GetInterfaceClass(iface, &class);
146 kr = (*iface)->GetInterfaceSubClass(iface, &subclass);
147 kr = (*iface)->GetInterfaceProtocol(iface, &protocol);
148 if(class != ADB_CLASS || subclass != ADB_SUBCLASS || protocol != ADB_PROTOCOL) {
149 // Ignore non-ADB devices.
150 DBG("Ignoring interface with incorrect class/subclass/protocol - %d, %d, %d\n", class, subclass, protocol);
151 (*iface)->Release(iface);
152 continue;
153 }
154
Dima Zavin3fd82b82009-05-08 18:25:58 -0700155 //* this gets us an ioservice, with which we will find the actual
156 //* device; after getting a plugin, and querying the interface, of
157 //* course.
158 //* Gotta love OS X
159 kr = (*iface)->GetDevice(iface, &usbDevice);
160 if (kIOReturnSuccess != kr || !usbDevice) {
161 DBG("ERR: Couldn't grab device from interface (%08x)\n", kr);
162 continue;
163 }
164
165 plugInInterface = NULL;
166 score = 0;
167 //* create an intermediate device plugin
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800168 kr = IOCreatePlugInInterfaceForService(usbDevice,
169 kIOUSBDeviceUserClientTypeID,
170 kIOCFPlugInInterfaceID,
171 &plugInInterface, &score);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700172 //* only needed this to find the plugin
173 (void)IOObjectRelease(usbDevice);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800174 if ((kIOReturnSuccess != kr) || (!plugInInterface)) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700175 DBG("ERR: Unable to create a device plug-in (%08x)\n", kr);
176 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800177 }
178
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800179 result = (*plugInInterface)->QueryInterface(plugInInterface,
180 CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID), (LPVOID) &dev);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700181 //* only needed this to query the plugin
182 (*plugInInterface)->Release(plugInInterface);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800183 if (result || !dev) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700184 DBG("ERR: Couldn't create a device interface (%08x)\n",
185 (int) result);
186 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800187 }
188
Dima Zavin3fd82b82009-05-08 18:25:58 -0700189 //* Now after all that, we actually have a ref to the device and
190 //* the interface that matched our criteria
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800191 kr = (*dev)->GetDeviceVendor(dev, &vendor);
192 kr = (*dev)->GetDeviceProduct(dev, &product);
Scott Andersone109d262012-04-20 11:21:14 -0700193 kr = (*dev)->GetLocationID(dev, &locationId);
194 if (kr == 0) {
Ying Wang42a809b2014-08-14 15:50:13 -0700195 snprintf(devpathBuf, sizeof(devpathBuf), "usb:%" PRIu32 "X",
196 (unsigned int)locationId);
Scott Andersone109d262012-04-20 11:21:14 -0700197 devpath = devpathBuf;
198 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800199 kr = (*dev)->USBGetSerialNumberStringIndex(dev, &serialIndex);
200
Guang Zhu1a1f8182009-08-06 17:21:52 -0700201 if (serialIndex > 0) {
202 IOUSBDevRequest req;
203 UInt16 buffer[256];
204 UInt16 languages[128];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800205
Guang Zhu1a1f8182009-08-06 17:21:52 -0700206 memset(languages, 0, sizeof(languages));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800207
Guang Zhu1a1f8182009-08-06 17:21:52 -0700208 req.bmRequestType =
209 USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
210 req.bRequest = kUSBRqGetDescriptor;
211 req.wValue = (kUSBStringDesc << 8) | 0;
212 req.wIndex = 0;
213 req.pData = languages;
214 req.wLength = sizeof(languages);
215 kr = (*dev)->DeviceRequest(dev, &req);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800216
Guang Zhu1a1f8182009-08-06 17:21:52 -0700217 if (kr == kIOReturnSuccess && req.wLenDone > 0) {
218
219 int langCount = (req.wLenDone - 2) / 2, lang;
220
221 for (lang = 1; lang <= langCount; lang++) {
222
223 memset(buffer, 0, sizeof(buffer));
224 memset(&req, 0, sizeof(req));
225
226 req.bmRequestType =
227 USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
228 req.bRequest = kUSBRqGetDescriptor;
229 req.wValue = (kUSBStringDesc << 8) | serialIndex;
230 req.wIndex = languages[lang];
231 req.pData = buffer;
232 req.wLength = sizeof(buffer);
233 kr = (*dev)->DeviceRequest(dev, &req);
234
235 if (kr == kIOReturnSuccess && req.wLenDone > 0) {
236 int i, count;
237
238 // skip first word, and copy the rest to the serial string,
239 // changing shorts to bytes.
240 count = (req.wLenDone - 1) / 2;
241 for (i = 0; i < count; i++)
242 serial[i] = buffer[i + 1];
243 serial[i] = 0;
244 break;
245 }
246 }
247 }
248 }
Dima Zavin3fd82b82009-05-08 18:25:58 -0700249 (*dev)->Release(dev);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800250
Dima Zavin3fd82b82009-05-08 18:25:58 -0700251 DBG("INFO: Found vid=%04x pid=%04x serial=%s\n", vendor, product,
252 serial);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800253
Dima Zavin3fd82b82009-05-08 18:25:58 -0700254 usb_handle* handle = CheckInterface((IOUSBInterfaceInterface**)iface,
255 vendor, product);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800256 if (handle == NULL) {
257 DBG("ERR: Could not find device interface: %08x\n", kr);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700258 (*iface)->Release(iface);
259 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800260 }
261
262 DBG("AndroidDeviceAdded calling register_usb_transport\n");
Scott Andersone109d262012-04-20 11:21:14 -0700263 register_usb_transport(handle, (serial[0] ? serial : NULL), devpath, 1);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800264
Dima Zavin3fd82b82009-05-08 18:25:58 -0700265 // Register for an interest notification of this device being removed.
266 // Pass the reference to our private data as the refCon for the
267 // notification.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800268 kr = IOServiceAddInterestNotification(notificationPort,
Dima Zavin3fd82b82009-05-08 18:25:58 -0700269 usbInterface,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800270 kIOGeneralInterest,
Dima Zavin3fd82b82009-05-08 18:25:58 -0700271 AndroidInterfaceNotify,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800272 handle,
273 &handle->usbNotification);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700274
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800275 if (kIOReturnSuccess != kr) {
276 DBG("ERR: Unable to create interest notification (%08x)\n", kr);
277 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800278 }
279}
280
281static void
Dima Zavin3fd82b82009-05-08 18:25:58 -0700282AndroidInterfaceNotify(void *refCon, io_service_t service, natural_t messageType, void *messageArgument)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800283{
284 usb_handle *handle = (usb_handle *)refCon;
285
286 if (messageType == kIOMessageServiceIsTerminated) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700287 if (!handle) {
288 DBG("ERR: NULL handle\n");
289 return;
290 }
291 DBG("AndroidInterfaceNotify\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800292 IOObjectRelease(handle->usbNotification);
293 usb_kick(handle);
294 }
295}
296
Dima Zavin3fd82b82009-05-08 18:25:58 -0700297//* TODO: simplify this further since we only register to get ADB interface
298//* subclass+protocol events
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800299static usb_handle*
Dima Zavin3fd82b82009-05-08 18:25:58 -0700300CheckInterface(IOUSBInterfaceInterface **interface, UInt16 vendor, UInt16 product)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800301{
302 usb_handle* handle = NULL;
303 IOReturn kr;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800304 UInt8 interfaceNumEndpoints, interfaceClass, interfaceSubClass, interfaceProtocol;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700305 UInt8 endpoint;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800306
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800307
Dima Zavin3fd82b82009-05-08 18:25:58 -0700308 //* Now open the interface. This will cause the pipes associated with
309 //* the endpoints in the interface descriptor to be instantiated
310 kr = (*interface)->USBInterfaceOpen(interface);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800311 if (kr != kIOReturnSuccess) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700312 DBG("ERR: Could not open interface: (%08x)\n", kr);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800313 return NULL;
314 }
315
Dima Zavin3fd82b82009-05-08 18:25:58 -0700316 //* Get the number of endpoints associated with this interface
317 kr = (*interface)->GetNumEndpoints(interface, &interfaceNumEndpoints);
318 if (kr != kIOReturnSuccess) {
319 DBG("ERR: Unable to get number of endpoints: (%08x)\n", kr);
320 goto err_get_num_ep;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800321 }
322
Dima Zavin3fd82b82009-05-08 18:25:58 -0700323 //* Get interface class, subclass and protocol
324 if ((*interface)->GetInterfaceClass(interface, &interfaceClass) != kIOReturnSuccess ||
325 (*interface)->GetInterfaceSubClass(interface, &interfaceSubClass) != kIOReturnSuccess ||
326 (*interface)->GetInterfaceProtocol(interface, &interfaceProtocol) != kIOReturnSuccess) {
327 DBG("ERR: Unable to get interface class, subclass and protocol\n");
328 goto err_get_interface_class;
329 }
330
331 //* check to make sure interface class, subclass and protocol match ADB
332 //* avoid opening mass storage endpoints
333 if (!is_adb_interface(vendor, product, interfaceClass,
334 interfaceSubClass, interfaceProtocol))
335 goto err_bad_adb_interface;
336
337 handle = calloc(1, sizeof(usb_handle));
338
339 //* Iterate over the endpoints for this interface and find the first
340 //* bulk in/out pipes available. These will be our read/write pipes.
341 for (endpoint = 0; endpoint <= interfaceNumEndpoints; endpoint++) {
342 UInt8 transferType;
343 UInt16 maxPacketSize;
344 UInt8 interval;
345 UInt8 number;
346 UInt8 direction;
347
348 kr = (*interface)->GetPipeProperties(interface, endpoint, &direction,
349 &number, &transferType, &maxPacketSize, &interval);
350
351 if (kIOReturnSuccess == kr) {
352 if (kUSBBulk != transferType)
353 continue;
354
355 if (kUSBIn == direction)
356 handle->bulkIn = endpoint;
357
358 if (kUSBOut == direction)
359 handle->bulkOut = endpoint;
360
361 handle->zero_mask = maxPacketSize - 1;
362 } else {
363 DBG("ERR: FindDeviceInterface - could not get pipe properties\n");
364 goto err_get_pipe_props;
365 }
366 }
367
368 handle->interface = interface;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800369 return handle;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700370
371err_get_pipe_props:
372 free(handle);
373err_bad_adb_interface:
374err_get_interface_class:
375err_get_num_ep:
376 (*interface)->USBInterfaceClose(interface);
377 return NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800378}
379
380
381void* RunLoopThread(void* unused)
382{
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800383 InitUSB();
384
385 currentRunLoop = CFRunLoopGetCurrent();
386
387 // Signal the parent that we are running
388 adb_mutex_lock(&start_lock);
389 adb_cond_signal(&start_cond);
390 adb_mutex_unlock(&start_lock);
391
392 CFRunLoopRun();
393 currentRunLoop = 0;
394
Al Sutton8e01cc62014-11-21 12:21:12 +0000395 IOObjectRelease(notificationIterator);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800396 IONotificationPortDestroy(notificationPort);
397
398 DBG("RunLoopThread done\n");
399 return NULL;
400}
401
402
403static int initialized = 0;
404void usb_init()
405{
406 if (!initialized)
407 {
408 adb_thread_t tid;
409
410 adb_mutex_init(&start_lock, NULL);
411 adb_cond_init(&start_cond, NULL);
412
413 if(adb_thread_create(&tid, RunLoopThread, NULL))
414 fatal_errno("cannot create input thread");
415
416 // Wait for initialization to finish
417 adb_mutex_lock(&start_lock);
418 adb_cond_wait(&start_cond, &start_lock);
419 adb_mutex_unlock(&start_lock);
420
421 adb_mutex_destroy(&start_lock);
422 adb_cond_destroy(&start_cond);
423
424 initialized = 1;
425 }
426}
427
428void usb_cleanup()
429{
430 DBG("usb_cleanup\n");
431 close_usb_devices();
432 if (currentRunLoop)
433 CFRunLoopStop(currentRunLoop);
434}
435
436int usb_write(usb_handle *handle, const void *buf, int len)
437{
438 IOReturn result;
439
440 if (!len)
441 return 0;
442
443 if (!handle)
444 return -1;
445
446 if (NULL == handle->interface) {
447 DBG("ERR: usb_write interface was null\n");
448 return -1;
449 }
450
451 if (0 == handle->bulkOut) {
452 DBG("ERR: bulkOut endpoint not assigned\n");
453 return -1;
454 }
455
456 result =
457 (*handle->interface)->WritePipe(
458 handle->interface, handle->bulkOut, (void *)buf, len);
459
460 if ((result == 0) && (handle->zero_mask)) {
461 /* we need 0-markers and our transfer */
462 if(!(len & handle->zero_mask)) {
463 result =
464 (*handle->interface)->WritePipe(
465 handle->interface, handle->bulkOut, (void *)buf, 0);
466 }
467 }
468
469 if (0 == result)
470 return 0;
471
472 DBG("ERR: usb_write failed with status %d\n", result);
473 return -1;
474}
475
476int usb_read(usb_handle *handle, void *buf, int len)
477{
478 IOReturn result;
479 UInt32 numBytes = len;
480
481 if (!len) {
482 return 0;
483 }
484
485 if (!handle) {
486 return -1;
487 }
488
489 if (NULL == handle->interface) {
490 DBG("ERR: usb_read interface was null\n");
491 return -1;
492 }
493
494 if (0 == handle->bulkIn) {
495 DBG("ERR: bulkIn endpoint not assigned\n");
496 return -1;
497 }
498
Esteban de la Canal9dd83dc2014-09-11 11:02:17 -0700499 result = (*handle->interface)->ReadPipe(handle->interface, handle->bulkIn, buf, &numBytes);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800500
Esteban de la Canal9dd83dc2014-09-11 11:02:17 -0700501 if (kIOUSBPipeStalled == result) {
502 DBG(" Pipe stalled, clearing stall.\n");
503 (*handle->interface)->ClearPipeStall(handle->interface, handle->bulkIn);
504 result = (*handle->interface)->ReadPipe(handle->interface, handle->bulkIn, buf, &numBytes);
505 }
506
507 if (kIOReturnSuccess == result)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800508 return 0;
509 else {
Esteban de la Canal9dd83dc2014-09-11 11:02:17 -0700510 DBG("ERR: usb_read failed with status %x\n", result);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800511 }
512
513 return -1;
514}
515
516int usb_close(usb_handle *handle)
517{
518 return 0;
519}
520
521void usb_kick(usb_handle *handle)
522{
523 /* release the interface */
Dima Zavin3fd82b82009-05-08 18:25:58 -0700524 if (!handle)
525 return;
526
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800527 if (handle->interface)
528 {
529 (*handle->interface)->USBInterfaceClose(handle->interface);
530 (*handle->interface)->Release(handle->interface);
531 handle->interface = 0;
532 }
533}