blob: ba157f1fb8d1974519d4dab1b7ecbc95b221f1f7 [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
25#include "sysdeps.h"
26
27#include <stdio.h>
28
29#define TRACE_TAG TRACE_USB
30#include "adb.h"
31
32#define DBG D
33
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080034static IONotificationPortRef notificationPort = 0;
Al Sutton8e01cc62014-11-21 12:21:12 +000035static io_iterator_t notificationIterator;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080036
37struct usb_handle
38{
39 UInt8 bulkIn;
40 UInt8 bulkOut;
41 IOUSBInterfaceInterface **interface;
42 io_object_t usbNotification;
43 unsigned int zero_mask;
44};
45
46static CFRunLoopRef currentRunLoop = 0;
47static pthread_mutex_t start_lock;
48static pthread_cond_t start_cond;
49
50
Dima Zavin3fd82b82009-05-08 18:25:58 -070051static void AndroidInterfaceAdded(void *refCon, io_iterator_t iterator);
52static void AndroidInterfaceNotify(void *refCon, io_iterator_t iterator,
53 natural_t messageType,
54 void *messageArgument);
55static usb_handle* CheckInterface(IOUSBInterfaceInterface **iface,
56 UInt16 vendor, UInt16 product);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080057
58static int
59InitUSB()
60{
61 CFMutableDictionaryRef matchingDict;
62 CFRunLoopSourceRef runLoopSource;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080063
64 //* To set up asynchronous notifications, create a notification port and
65 //* add its run loop event source to the program's run loop
66 notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
67 runLoopSource = IONotificationPortGetRunLoopSource(notificationPort);
68 CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
69
Al Sutton8e01cc62014-11-21 12:21:12 +000070 //* Create our matching dictionary to find the Android device's
71 //* adb interface
72 //* IOServiceAddMatchingNotification consumes the reference, so we do
73 //* not need to release this
74 matchingDict = IOServiceMatching(kIOUSBInterfaceClassName);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080075
Al Sutton8e01cc62014-11-21 12:21:12 +000076 if (!matchingDict) {
77 DBG("ERR: Couldn't create USB matching dictionary.\n");
78 return -1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080079 }
80
Al Sutton8e01cc62014-11-21 12:21:12 +000081 //* We have to get notifications for all potential candidates and test them
82 //* at connection time because the matching rules don't allow for a
83 //* USB interface class of 0xff for class+subclass+protocol matches
84 //* See https://developer.apple.com/library/mac/qa/qa1076/_index.html
85 IOServiceAddMatchingNotification(
86 notificationPort,
87 kIOFirstMatchNotification,
88 matchingDict,
89 AndroidInterfaceAdded,
90 NULL,
91 &notificationIterator);
92
93 //* Iterate over set of matching interfaces to access already-present
94 //* devices and to arm the notification
95 AndroidInterfaceAdded(NULL, notificationIterator);
96
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080097 return 0;
98}
99
100static void
Dima Zavin3fd82b82009-05-08 18:25:58 -0700101AndroidInterfaceAdded(void *refCon, io_iterator_t iterator)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800102{
103 kern_return_t kr;
104 io_service_t usbDevice;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700105 io_service_t usbInterface;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800106 IOCFPlugInInterface **plugInInterface = NULL;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700107 IOUSBInterfaceInterface220 **iface = NULL;
108 IOUSBDeviceInterface197 **dev = NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800109 HRESULT result;
110 SInt32 score;
Scott Andersone109d262012-04-20 11:21:14 -0700111 UInt32 locationId;
Al Sutton8e01cc62014-11-21 12:21:12 +0000112 UInt8 class, subclass, protocol;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800113 UInt16 vendor;
114 UInt16 product;
115 UInt8 serialIndex;
116 char serial[256];
Scott Andersone109d262012-04-20 11:21:14 -0700117 char devpathBuf[64];
118 char *devpath = NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800119
Dima Zavin3fd82b82009-05-08 18:25:58 -0700120 while ((usbInterface = IOIteratorNext(iterator))) {
121 //* Create an intermediate interface plugin
122 kr = IOCreatePlugInInterfaceForService(usbInterface,
123 kIOUSBInterfaceUserClientTypeID,
124 kIOCFPlugInInterfaceID,
125 &plugInInterface, &score);
126 IOObjectRelease(usbInterface);
127 if ((kIOReturnSuccess != kr) || (!plugInInterface)) {
128 DBG("ERR: Unable to create an interface plug-in (%08x)\n", kr);
129 continue;
130 }
131
132 //* This gets us the interface object
133 result = (*plugInInterface)->QueryInterface(plugInInterface,
134 CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID), (LPVOID)
135 &iface);
136 //* We only needed the plugin to get the interface, so discard it
137 (*plugInInterface)->Release(plugInInterface);
138 if (result || !iface) {
139 DBG("ERR: Couldn't query the interface (%08x)\n", (int) result);
140 continue;
141 }
142
Al Sutton8e01cc62014-11-21 12:21:12 +0000143 kr = (*iface)->GetInterfaceClass(iface, &class);
144 kr = (*iface)->GetInterfaceSubClass(iface, &subclass);
145 kr = (*iface)->GetInterfaceProtocol(iface, &protocol);
146 if(class != ADB_CLASS || subclass != ADB_SUBCLASS || protocol != ADB_PROTOCOL) {
147 // Ignore non-ADB devices.
148 DBG("Ignoring interface with incorrect class/subclass/protocol - %d, %d, %d\n", class, subclass, protocol);
149 (*iface)->Release(iface);
150 continue;
151 }
152
Dima Zavin3fd82b82009-05-08 18:25:58 -0700153 //* this gets us an ioservice, with which we will find the actual
154 //* device; after getting a plugin, and querying the interface, of
155 //* course.
156 //* Gotta love OS X
157 kr = (*iface)->GetDevice(iface, &usbDevice);
158 if (kIOReturnSuccess != kr || !usbDevice) {
159 DBG("ERR: Couldn't grab device from interface (%08x)\n", kr);
160 continue;
161 }
162
163 plugInInterface = NULL;
164 score = 0;
165 //* create an intermediate device plugin
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800166 kr = IOCreatePlugInInterfaceForService(usbDevice,
167 kIOUSBDeviceUserClientTypeID,
168 kIOCFPlugInInterfaceID,
169 &plugInInterface, &score);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700170 //* only needed this to find the plugin
171 (void)IOObjectRelease(usbDevice);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800172 if ((kIOReturnSuccess != kr) || (!plugInInterface)) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700173 DBG("ERR: Unable to create a device plug-in (%08x)\n", kr);
174 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800175 }
176
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800177 result = (*plugInInterface)->QueryInterface(plugInInterface,
178 CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID), (LPVOID) &dev);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700179 //* only needed this to query the plugin
180 (*plugInInterface)->Release(plugInInterface);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800181 if (result || !dev) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700182 DBG("ERR: Couldn't create a device interface (%08x)\n",
183 (int) result);
184 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800185 }
186
Dima Zavin3fd82b82009-05-08 18:25:58 -0700187 //* Now after all that, we actually have a ref to the device and
188 //* the interface that matched our criteria
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800189 kr = (*dev)->GetDeviceVendor(dev, &vendor);
190 kr = (*dev)->GetDeviceProduct(dev, &product);
Scott Andersone109d262012-04-20 11:21:14 -0700191 kr = (*dev)->GetLocationID(dev, &locationId);
192 if (kr == 0) {
Ying Wang42a809b2014-08-14 15:50:13 -0700193 snprintf(devpathBuf, sizeof(devpathBuf), "usb:%" PRIu32 "X",
194 (unsigned int)locationId);
Scott Andersone109d262012-04-20 11:21:14 -0700195 devpath = devpathBuf;
196 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800197 kr = (*dev)->USBGetSerialNumberStringIndex(dev, &serialIndex);
198
Guang Zhu1a1f8182009-08-06 17:21:52 -0700199 if (serialIndex > 0) {
200 IOUSBDevRequest req;
201 UInt16 buffer[256];
202 UInt16 languages[128];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800203
Guang Zhu1a1f8182009-08-06 17:21:52 -0700204 memset(languages, 0, sizeof(languages));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800205
Guang Zhu1a1f8182009-08-06 17:21:52 -0700206 req.bmRequestType =
207 USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
208 req.bRequest = kUSBRqGetDescriptor;
209 req.wValue = (kUSBStringDesc << 8) | 0;
210 req.wIndex = 0;
211 req.pData = languages;
212 req.wLength = sizeof(languages);
213 kr = (*dev)->DeviceRequest(dev, &req);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800214
Guang Zhu1a1f8182009-08-06 17:21:52 -0700215 if (kr == kIOReturnSuccess && req.wLenDone > 0) {
216
217 int langCount = (req.wLenDone - 2) / 2, lang;
218
219 for (lang = 1; lang <= langCount; lang++) {
220
221 memset(buffer, 0, sizeof(buffer));
222 memset(&req, 0, sizeof(req));
223
224 req.bmRequestType =
225 USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
226 req.bRequest = kUSBRqGetDescriptor;
227 req.wValue = (kUSBStringDesc << 8) | serialIndex;
228 req.wIndex = languages[lang];
229 req.pData = buffer;
230 req.wLength = sizeof(buffer);
231 kr = (*dev)->DeviceRequest(dev, &req);
232
233 if (kr == kIOReturnSuccess && req.wLenDone > 0) {
234 int i, count;
235
236 // skip first word, and copy the rest to the serial string,
237 // changing shorts to bytes.
238 count = (req.wLenDone - 1) / 2;
239 for (i = 0; i < count; i++)
240 serial[i] = buffer[i + 1];
241 serial[i] = 0;
242 break;
243 }
244 }
245 }
246 }
Dima Zavin3fd82b82009-05-08 18:25:58 -0700247 (*dev)->Release(dev);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800248
Dima Zavin3fd82b82009-05-08 18:25:58 -0700249 DBG("INFO: Found vid=%04x pid=%04x serial=%s\n", vendor, product,
250 serial);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800251
Dima Zavin3fd82b82009-05-08 18:25:58 -0700252 usb_handle* handle = CheckInterface((IOUSBInterfaceInterface**)iface,
253 vendor, product);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800254 if (handle == NULL) {
255 DBG("ERR: Could not find device interface: %08x\n", kr);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700256 (*iface)->Release(iface);
257 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800258 }
259
260 DBG("AndroidDeviceAdded calling register_usb_transport\n");
Scott Andersone109d262012-04-20 11:21:14 -0700261 register_usb_transport(handle, (serial[0] ? serial : NULL), devpath, 1);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800262
Dima Zavin3fd82b82009-05-08 18:25:58 -0700263 // Register for an interest notification of this device being removed.
264 // Pass the reference to our private data as the refCon for the
265 // notification.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800266 kr = IOServiceAddInterestNotification(notificationPort,
Dima Zavin3fd82b82009-05-08 18:25:58 -0700267 usbInterface,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800268 kIOGeneralInterest,
Dima Zavin3fd82b82009-05-08 18:25:58 -0700269 AndroidInterfaceNotify,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800270 handle,
271 &handle->usbNotification);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700272
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800273 if (kIOReturnSuccess != kr) {
274 DBG("ERR: Unable to create interest notification (%08x)\n", kr);
275 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800276 }
277}
278
279static void
Dima Zavin3fd82b82009-05-08 18:25:58 -0700280AndroidInterfaceNotify(void *refCon, io_service_t service, natural_t messageType, void *messageArgument)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800281{
282 usb_handle *handle = (usb_handle *)refCon;
283
284 if (messageType == kIOMessageServiceIsTerminated) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700285 if (!handle) {
286 DBG("ERR: NULL handle\n");
287 return;
288 }
289 DBG("AndroidInterfaceNotify\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800290 IOObjectRelease(handle->usbNotification);
291 usb_kick(handle);
292 }
293}
294
Dima Zavin3fd82b82009-05-08 18:25:58 -0700295//* TODO: simplify this further since we only register to get ADB interface
296//* subclass+protocol events
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800297static usb_handle*
Dima Zavin3fd82b82009-05-08 18:25:58 -0700298CheckInterface(IOUSBInterfaceInterface **interface, UInt16 vendor, UInt16 product)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800299{
300 usb_handle* handle = NULL;
301 IOReturn kr;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800302 UInt8 interfaceNumEndpoints, interfaceClass, interfaceSubClass, interfaceProtocol;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700303 UInt8 endpoint;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800304
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800305
Dima Zavin3fd82b82009-05-08 18:25:58 -0700306 //* Now open the interface. This will cause the pipes associated with
307 //* the endpoints in the interface descriptor to be instantiated
308 kr = (*interface)->USBInterfaceOpen(interface);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800309 if (kr != kIOReturnSuccess) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700310 DBG("ERR: Could not open interface: (%08x)\n", kr);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800311 return NULL;
312 }
313
Dima Zavin3fd82b82009-05-08 18:25:58 -0700314 //* Get the number of endpoints associated with this interface
315 kr = (*interface)->GetNumEndpoints(interface, &interfaceNumEndpoints);
316 if (kr != kIOReturnSuccess) {
317 DBG("ERR: Unable to get number of endpoints: (%08x)\n", kr);
318 goto err_get_num_ep;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800319 }
320
Dima Zavin3fd82b82009-05-08 18:25:58 -0700321 //* Get interface class, subclass and protocol
322 if ((*interface)->GetInterfaceClass(interface, &interfaceClass) != kIOReturnSuccess ||
323 (*interface)->GetInterfaceSubClass(interface, &interfaceSubClass) != kIOReturnSuccess ||
324 (*interface)->GetInterfaceProtocol(interface, &interfaceProtocol) != kIOReturnSuccess) {
325 DBG("ERR: Unable to get interface class, subclass and protocol\n");
326 goto err_get_interface_class;
327 }
328
329 //* check to make sure interface class, subclass and protocol match ADB
330 //* avoid opening mass storage endpoints
331 if (!is_adb_interface(vendor, product, interfaceClass,
332 interfaceSubClass, interfaceProtocol))
333 goto err_bad_adb_interface;
334
335 handle = calloc(1, sizeof(usb_handle));
336
337 //* Iterate over the endpoints for this interface and find the first
338 //* bulk in/out pipes available. These will be our read/write pipes.
339 for (endpoint = 0; endpoint <= interfaceNumEndpoints; endpoint++) {
340 UInt8 transferType;
341 UInt16 maxPacketSize;
342 UInt8 interval;
343 UInt8 number;
344 UInt8 direction;
345
346 kr = (*interface)->GetPipeProperties(interface, endpoint, &direction,
347 &number, &transferType, &maxPacketSize, &interval);
348
349 if (kIOReturnSuccess == kr) {
350 if (kUSBBulk != transferType)
351 continue;
352
353 if (kUSBIn == direction)
354 handle->bulkIn = endpoint;
355
356 if (kUSBOut == direction)
357 handle->bulkOut = endpoint;
358
359 handle->zero_mask = maxPacketSize - 1;
360 } else {
361 DBG("ERR: FindDeviceInterface - could not get pipe properties\n");
362 goto err_get_pipe_props;
363 }
364 }
365
366 handle->interface = interface;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800367 return handle;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700368
369err_get_pipe_props:
370 free(handle);
371err_bad_adb_interface:
372err_get_interface_class:
373err_get_num_ep:
374 (*interface)->USBInterfaceClose(interface);
375 return NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800376}
377
378
379void* RunLoopThread(void* unused)
380{
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800381 InitUSB();
382
383 currentRunLoop = CFRunLoopGetCurrent();
384
385 // Signal the parent that we are running
386 adb_mutex_lock(&start_lock);
387 adb_cond_signal(&start_cond);
388 adb_mutex_unlock(&start_lock);
389
390 CFRunLoopRun();
391 currentRunLoop = 0;
392
Al Sutton8e01cc62014-11-21 12:21:12 +0000393 IOObjectRelease(notificationIterator);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800394 IONotificationPortDestroy(notificationPort);
395
396 DBG("RunLoopThread done\n");
397 return NULL;
398}
399
400
401static int initialized = 0;
402void usb_init()
403{
404 if (!initialized)
405 {
406 adb_thread_t tid;
407
408 adb_mutex_init(&start_lock, NULL);
409 adb_cond_init(&start_cond, NULL);
410
411 if(adb_thread_create(&tid, RunLoopThread, NULL))
412 fatal_errno("cannot create input thread");
413
414 // Wait for initialization to finish
415 adb_mutex_lock(&start_lock);
416 adb_cond_wait(&start_cond, &start_lock);
417 adb_mutex_unlock(&start_lock);
418
419 adb_mutex_destroy(&start_lock);
420 adb_cond_destroy(&start_cond);
421
422 initialized = 1;
423 }
424}
425
426void usb_cleanup()
427{
428 DBG("usb_cleanup\n");
429 close_usb_devices();
430 if (currentRunLoop)
431 CFRunLoopStop(currentRunLoop);
432}
433
434int usb_write(usb_handle *handle, const void *buf, int len)
435{
436 IOReturn result;
437
438 if (!len)
439 return 0;
440
441 if (!handle)
442 return -1;
443
444 if (NULL == handle->interface) {
445 DBG("ERR: usb_write interface was null\n");
446 return -1;
447 }
448
449 if (0 == handle->bulkOut) {
450 DBG("ERR: bulkOut endpoint not assigned\n");
451 return -1;
452 }
453
454 result =
455 (*handle->interface)->WritePipe(
456 handle->interface, handle->bulkOut, (void *)buf, len);
457
458 if ((result == 0) && (handle->zero_mask)) {
459 /* we need 0-markers and our transfer */
460 if(!(len & handle->zero_mask)) {
461 result =
462 (*handle->interface)->WritePipe(
463 handle->interface, handle->bulkOut, (void *)buf, 0);
464 }
465 }
466
467 if (0 == result)
468 return 0;
469
470 DBG("ERR: usb_write failed with status %d\n", result);
471 return -1;
472}
473
474int usb_read(usb_handle *handle, void *buf, int len)
475{
476 IOReturn result;
477 UInt32 numBytes = len;
478
479 if (!len) {
480 return 0;
481 }
482
483 if (!handle) {
484 return -1;
485 }
486
487 if (NULL == handle->interface) {
488 DBG("ERR: usb_read interface was null\n");
489 return -1;
490 }
491
492 if (0 == handle->bulkIn) {
493 DBG("ERR: bulkIn endpoint not assigned\n");
494 return -1;
495 }
496
Esteban de la Canal9dd83dc2014-09-11 11:02:17 -0700497 result = (*handle->interface)->ReadPipe(handle->interface, handle->bulkIn, buf, &numBytes);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800498
Esteban de la Canal9dd83dc2014-09-11 11:02:17 -0700499 if (kIOUSBPipeStalled == result) {
500 DBG(" Pipe stalled, clearing stall.\n");
501 (*handle->interface)->ClearPipeStall(handle->interface, handle->bulkIn);
502 result = (*handle->interface)->ReadPipe(handle->interface, handle->bulkIn, buf, &numBytes);
503 }
504
505 if (kIOReturnSuccess == result)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800506 return 0;
507 else {
Esteban de la Canal9dd83dc2014-09-11 11:02:17 -0700508 DBG("ERR: usb_read failed with status %x\n", result);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800509 }
510
511 return -1;
512}
513
514int usb_close(usb_handle *handle)
515{
516 return 0;
517}
518
519void usb_kick(usb_handle *handle)
520{
521 /* release the interface */
Dima Zavin3fd82b82009-05-08 18:25:58 -0700522 if (!handle)
523 return;
524
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800525 if (handle->interface)
526 {
527 (*handle->interface)->USBInterfaceClose(handle->interface);
528 (*handle->interface)->Release(handle->interface);
529 handle->interface = 0;
530 }
531}