blob: 45ce4442e5654e2d2a000e06bf06ba54323c370a [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"
Xavier Ducroheta09fbd12009-05-20 17:33:53 -070031#include "usb_vendors.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;
Xavier Ducroheta09fbd12009-05-20 17:33:53 -070036static io_iterator_t* notificationIterators;
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;
Dima Zavin3fd82b82009-05-08 18:25:58 -070064 SInt32 vendor, if_subclass, if_protocol;
65 unsigned i;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080066
67 //* To set up asynchronous notifications, create a notification port and
68 //* add its run loop event source to the program's run loop
69 notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
70 runLoopSource = IONotificationPortGetRunLoopSource(notificationPort);
71 CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
72
73 memset(notificationIterators, 0, sizeof(notificationIterators));
74
Dima Zavin3fd82b82009-05-08 18:25:58 -070075 //* loop through all supported vendors
Xavier Ducroheta09fbd12009-05-20 17:33:53 -070076 for (i = 0; i < vendorIdCount; i++) {
Dima Zavin3fd82b82009-05-08 18:25:58 -070077 //* Create our matching dictionary to find the Android device's
78 //* adb interface
79 //* IOServiceAddMatchingNotification consumes the reference, so we do
80 //* not need to release this
81 matchingDict = IOServiceMatching(kIOUSBInterfaceClassName);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080082
83 if (!matchingDict) {
84 DBG("ERR: Couldn't create USB matching dictionary.\n");
85 return -1;
86 }
87
Dima Zavin3fd82b82009-05-08 18:25:58 -070088 //* Match based on vendor id, interface subclass and protocol
89 vendor = vendorIds[i];
90 if_subclass = ADB_SUBCLASS;
91 if_protocol = ADB_PROTOCOL;
92 CFDictionarySetValue(matchingDict, CFSTR(kUSBVendorID),
93 CFNumberCreate(kCFAllocatorDefault,
94 kCFNumberSInt32Type, &vendor));
95 CFDictionarySetValue(matchingDict, CFSTR(kUSBInterfaceSubClass),
96 CFNumberCreate(kCFAllocatorDefault,
97 kCFNumberSInt32Type, &if_subclass));
98 CFDictionarySetValue(matchingDict, CFSTR(kUSBInterfaceProtocol),
99 CFNumberCreate(kCFAllocatorDefault,
100 kCFNumberSInt32Type, &if_protocol));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800101 IOServiceAddMatchingNotification(
102 notificationPort,
103 kIOFirstMatchNotification,
104 matchingDict,
Dima Zavin3fd82b82009-05-08 18:25:58 -0700105 AndroidInterfaceAdded,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800106 NULL,
107 &notificationIterators[i]);
108
Dima Zavin3fd82b82009-05-08 18:25:58 -0700109 //* Iterate over set of matching interfaces to access already-present
110 //* devices and to arm the notification
111 AndroidInterfaceAdded(NULL, notificationIterators[i]);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800112 }
113
114 return 0;
115}
116
117static void
Dima Zavin3fd82b82009-05-08 18:25:58 -0700118AndroidInterfaceAdded(void *refCon, io_iterator_t iterator)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800119{
120 kern_return_t kr;
121 io_service_t usbDevice;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700122 io_service_t usbInterface;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800123 IOCFPlugInInterface **plugInInterface = NULL;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700124 IOUSBInterfaceInterface220 **iface = NULL;
125 IOUSBDeviceInterface197 **dev = NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800126 HRESULT result;
127 SInt32 score;
Scott Andersone109d262012-04-20 11:21:14 -0700128 UInt32 locationId;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800129 UInt16 vendor;
130 UInt16 product;
131 UInt8 serialIndex;
132 char serial[256];
Scott Andersone109d262012-04-20 11:21:14 -0700133 char devpathBuf[64];
134 char *devpath = NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800135
Dima Zavin3fd82b82009-05-08 18:25:58 -0700136 while ((usbInterface = IOIteratorNext(iterator))) {
137 //* Create an intermediate interface plugin
138 kr = IOCreatePlugInInterfaceForService(usbInterface,
139 kIOUSBInterfaceUserClientTypeID,
140 kIOCFPlugInInterfaceID,
141 &plugInInterface, &score);
142 IOObjectRelease(usbInterface);
143 if ((kIOReturnSuccess != kr) || (!plugInInterface)) {
144 DBG("ERR: Unable to create an interface plug-in (%08x)\n", kr);
145 continue;
146 }
147
148 //* This gets us the interface object
149 result = (*plugInInterface)->QueryInterface(plugInInterface,
150 CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID), (LPVOID)
151 &iface);
152 //* We only needed the plugin to get the interface, so discard it
153 (*plugInInterface)->Release(plugInInterface);
154 if (result || !iface) {
155 DBG("ERR: Couldn't query the interface (%08x)\n", (int) result);
156 continue;
157 }
158
159 //* this gets us an ioservice, with which we will find the actual
160 //* device; after getting a plugin, and querying the interface, of
161 //* course.
162 //* Gotta love OS X
163 kr = (*iface)->GetDevice(iface, &usbDevice);
164 if (kIOReturnSuccess != kr || !usbDevice) {
165 DBG("ERR: Couldn't grab device from interface (%08x)\n", kr);
166 continue;
167 }
168
169 plugInInterface = NULL;
170 score = 0;
171 //* create an intermediate device plugin
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800172 kr = IOCreatePlugInInterfaceForService(usbDevice,
173 kIOUSBDeviceUserClientTypeID,
174 kIOCFPlugInInterfaceID,
175 &plugInInterface, &score);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700176 //* only needed this to find the plugin
177 (void)IOObjectRelease(usbDevice);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800178 if ((kIOReturnSuccess != kr) || (!plugInInterface)) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700179 DBG("ERR: Unable to create a device plug-in (%08x)\n", kr);
180 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800181 }
182
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800183 result = (*plugInInterface)->QueryInterface(plugInInterface,
184 CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID), (LPVOID) &dev);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700185 //* only needed this to query the plugin
186 (*plugInInterface)->Release(plugInInterface);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800187 if (result || !dev) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700188 DBG("ERR: Couldn't create a device interface (%08x)\n",
189 (int) result);
190 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800191 }
192
Dima Zavin3fd82b82009-05-08 18:25:58 -0700193 //* Now after all that, we actually have a ref to the device and
194 //* the interface that matched our criteria
195
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800196 kr = (*dev)->GetDeviceVendor(dev, &vendor);
197 kr = (*dev)->GetDeviceProduct(dev, &product);
Scott Andersone109d262012-04-20 11:21:14 -0700198 kr = (*dev)->GetLocationID(dev, &locationId);
199 if (kr == 0) {
200 snprintf(devpathBuf, sizeof(devpathBuf), "usb:%lX", locationId);
201 devpath = devpathBuf;
202 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800203 kr = (*dev)->USBGetSerialNumberStringIndex(dev, &serialIndex);
204
Guang Zhu1a1f8182009-08-06 17:21:52 -0700205 if (serialIndex > 0) {
206 IOUSBDevRequest req;
207 UInt16 buffer[256];
208 UInt16 languages[128];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800209
Guang Zhu1a1f8182009-08-06 17:21:52 -0700210 memset(languages, 0, sizeof(languages));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800211
Guang Zhu1a1f8182009-08-06 17:21:52 -0700212 req.bmRequestType =
213 USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
214 req.bRequest = kUSBRqGetDescriptor;
215 req.wValue = (kUSBStringDesc << 8) | 0;
216 req.wIndex = 0;
217 req.pData = languages;
218 req.wLength = sizeof(languages);
219 kr = (*dev)->DeviceRequest(dev, &req);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800220
Guang Zhu1a1f8182009-08-06 17:21:52 -0700221 if (kr == kIOReturnSuccess && req.wLenDone > 0) {
222
223 int langCount = (req.wLenDone - 2) / 2, lang;
224
225 for (lang = 1; lang <= langCount; lang++) {
226
227 memset(buffer, 0, sizeof(buffer));
228 memset(&req, 0, sizeof(req));
229
230 req.bmRequestType =
231 USBmakebmRequestType(kUSBIn, kUSBStandard, kUSBDevice);
232 req.bRequest = kUSBRqGetDescriptor;
233 req.wValue = (kUSBStringDesc << 8) | serialIndex;
234 req.wIndex = languages[lang];
235 req.pData = buffer;
236 req.wLength = sizeof(buffer);
237 kr = (*dev)->DeviceRequest(dev, &req);
238
239 if (kr == kIOReturnSuccess && req.wLenDone > 0) {
240 int i, count;
241
242 // skip first word, and copy the rest to the serial string,
243 // changing shorts to bytes.
244 count = (req.wLenDone - 1) / 2;
245 for (i = 0; i < count; i++)
246 serial[i] = buffer[i + 1];
247 serial[i] = 0;
248 break;
249 }
250 }
251 }
252 }
Dima Zavin3fd82b82009-05-08 18:25:58 -0700253 (*dev)->Release(dev);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800254
Dima Zavin3fd82b82009-05-08 18:25:58 -0700255 DBG("INFO: Found vid=%04x pid=%04x serial=%s\n", vendor, product,
256 serial);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800257
Dima Zavin3fd82b82009-05-08 18:25:58 -0700258 usb_handle* handle = CheckInterface((IOUSBInterfaceInterface**)iface,
259 vendor, product);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800260 if (handle == NULL) {
261 DBG("ERR: Could not find device interface: %08x\n", kr);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700262 (*iface)->Release(iface);
263 continue;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800264 }
265
266 DBG("AndroidDeviceAdded calling register_usb_transport\n");
Scott Andersone109d262012-04-20 11:21:14 -0700267 register_usb_transport(handle, (serial[0] ? serial : NULL), devpath, 1);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800268
Dima Zavin3fd82b82009-05-08 18:25:58 -0700269 // Register for an interest notification of this device being removed.
270 // Pass the reference to our private data as the refCon for the
271 // notification.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800272 kr = IOServiceAddInterestNotification(notificationPort,
Dima Zavin3fd82b82009-05-08 18:25:58 -0700273 usbInterface,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800274 kIOGeneralInterest,
Dima Zavin3fd82b82009-05-08 18:25:58 -0700275 AndroidInterfaceNotify,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800276 handle,
277 &handle->usbNotification);
Dima Zavin3fd82b82009-05-08 18:25:58 -0700278
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800279 if (kIOReturnSuccess != kr) {
280 DBG("ERR: Unable to create interest notification (%08x)\n", kr);
281 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800282 }
283}
284
285static void
Dima Zavin3fd82b82009-05-08 18:25:58 -0700286AndroidInterfaceNotify(void *refCon, io_service_t service, natural_t messageType, void *messageArgument)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800287{
288 usb_handle *handle = (usb_handle *)refCon;
289
290 if (messageType == kIOMessageServiceIsTerminated) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700291 if (!handle) {
292 DBG("ERR: NULL handle\n");
293 return;
294 }
295 DBG("AndroidInterfaceNotify\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800296 IOObjectRelease(handle->usbNotification);
297 usb_kick(handle);
298 }
299}
300
Dima Zavin3fd82b82009-05-08 18:25:58 -0700301//* TODO: simplify this further since we only register to get ADB interface
302//* subclass+protocol events
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800303static usb_handle*
Dima Zavin3fd82b82009-05-08 18:25:58 -0700304CheckInterface(IOUSBInterfaceInterface **interface, UInt16 vendor, UInt16 product)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800305{
306 usb_handle* handle = NULL;
307 IOReturn kr;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800308 UInt8 interfaceNumEndpoints, interfaceClass, interfaceSubClass, interfaceProtocol;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700309 UInt8 endpoint;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800310
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800311
Dima Zavin3fd82b82009-05-08 18:25:58 -0700312 //* Now open the interface. This will cause the pipes associated with
313 //* the endpoints in the interface descriptor to be instantiated
314 kr = (*interface)->USBInterfaceOpen(interface);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800315 if (kr != kIOReturnSuccess) {
Dima Zavin3fd82b82009-05-08 18:25:58 -0700316 DBG("ERR: Could not open interface: (%08x)\n", kr);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800317 return NULL;
318 }
319
Dima Zavin3fd82b82009-05-08 18:25:58 -0700320 //* Get the number of endpoints associated with this interface
321 kr = (*interface)->GetNumEndpoints(interface, &interfaceNumEndpoints);
322 if (kr != kIOReturnSuccess) {
323 DBG("ERR: Unable to get number of endpoints: (%08x)\n", kr);
324 goto err_get_num_ep;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800325 }
326
Dima Zavin3fd82b82009-05-08 18:25:58 -0700327 //* Get interface class, subclass and protocol
328 if ((*interface)->GetInterfaceClass(interface, &interfaceClass) != kIOReturnSuccess ||
329 (*interface)->GetInterfaceSubClass(interface, &interfaceSubClass) != kIOReturnSuccess ||
330 (*interface)->GetInterfaceProtocol(interface, &interfaceProtocol) != kIOReturnSuccess) {
331 DBG("ERR: Unable to get interface class, subclass and protocol\n");
332 goto err_get_interface_class;
333 }
334
335 //* check to make sure interface class, subclass and protocol match ADB
336 //* avoid opening mass storage endpoints
337 if (!is_adb_interface(vendor, product, interfaceClass,
338 interfaceSubClass, interfaceProtocol))
339 goto err_bad_adb_interface;
340
341 handle = calloc(1, sizeof(usb_handle));
342
343 //* Iterate over the endpoints for this interface and find the first
344 //* bulk in/out pipes available. These will be our read/write pipes.
345 for (endpoint = 0; endpoint <= interfaceNumEndpoints; endpoint++) {
346 UInt8 transferType;
347 UInt16 maxPacketSize;
348 UInt8 interval;
349 UInt8 number;
350 UInt8 direction;
351
352 kr = (*interface)->GetPipeProperties(interface, endpoint, &direction,
353 &number, &transferType, &maxPacketSize, &interval);
354
355 if (kIOReturnSuccess == kr) {
356 if (kUSBBulk != transferType)
357 continue;
358
359 if (kUSBIn == direction)
360 handle->bulkIn = endpoint;
361
362 if (kUSBOut == direction)
363 handle->bulkOut = endpoint;
364
365 handle->zero_mask = maxPacketSize - 1;
366 } else {
367 DBG("ERR: FindDeviceInterface - could not get pipe properties\n");
368 goto err_get_pipe_props;
369 }
370 }
371
372 handle->interface = interface;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800373 return handle;
Dima Zavin3fd82b82009-05-08 18:25:58 -0700374
375err_get_pipe_props:
376 free(handle);
377err_bad_adb_interface:
378err_get_interface_class:
379err_get_num_ep:
380 (*interface)->USBInterfaceClose(interface);
381 return NULL;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800382}
383
384
385void* RunLoopThread(void* unused)
386{
Dima Zavin3fd82b82009-05-08 18:25:58 -0700387 unsigned i;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800388
389 InitUSB();
390
391 currentRunLoop = CFRunLoopGetCurrent();
392
393 // Signal the parent that we are running
394 adb_mutex_lock(&start_lock);
395 adb_cond_signal(&start_cond);
396 adb_mutex_unlock(&start_lock);
397
398 CFRunLoopRun();
399 currentRunLoop = 0;
400
Xavier Ducroheta09fbd12009-05-20 17:33:53 -0700401 for (i = 0; i < vendorIdCount; i++) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800402 IOObjectRelease(notificationIterators[i]);
403 }
404 IONotificationPortDestroy(notificationPort);
405
406 DBG("RunLoopThread done\n");
407 return NULL;
408}
409
410
411static int initialized = 0;
412void usb_init()
413{
414 if (!initialized)
415 {
416 adb_thread_t tid;
417
Xavier Ducroheta09fbd12009-05-20 17:33:53 -0700418 notificationIterators = (io_iterator_t*)malloc(
419 vendorIdCount * sizeof(io_iterator_t));
420
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800421 adb_mutex_init(&start_lock, NULL);
422 adb_cond_init(&start_cond, NULL);
423
424 if(adb_thread_create(&tid, RunLoopThread, NULL))
425 fatal_errno("cannot create input thread");
426
427 // Wait for initialization to finish
428 adb_mutex_lock(&start_lock);
429 adb_cond_wait(&start_cond, &start_lock);
430 adb_mutex_unlock(&start_lock);
431
432 adb_mutex_destroy(&start_lock);
433 adb_cond_destroy(&start_cond);
434
435 initialized = 1;
436 }
437}
438
439void usb_cleanup()
440{
441 DBG("usb_cleanup\n");
442 close_usb_devices();
443 if (currentRunLoop)
444 CFRunLoopStop(currentRunLoop);
Xavier Ducroheta09fbd12009-05-20 17:33:53 -0700445
446 if (notificationIterators != NULL) {
447 free(notificationIterators);
448 notificationIterators = NULL;
449 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800450}
451
452int usb_write(usb_handle *handle, const void *buf, int len)
453{
454 IOReturn result;
455
456 if (!len)
457 return 0;
458
459 if (!handle)
460 return -1;
461
462 if (NULL == handle->interface) {
463 DBG("ERR: usb_write interface was null\n");
464 return -1;
465 }
466
467 if (0 == handle->bulkOut) {
468 DBG("ERR: bulkOut endpoint not assigned\n");
469 return -1;
470 }
471
472 result =
473 (*handle->interface)->WritePipe(
474 handle->interface, handle->bulkOut, (void *)buf, len);
475
476 if ((result == 0) && (handle->zero_mask)) {
477 /* we need 0-markers and our transfer */
478 if(!(len & handle->zero_mask)) {
479 result =
480 (*handle->interface)->WritePipe(
481 handle->interface, handle->bulkOut, (void *)buf, 0);
482 }
483 }
484
485 if (0 == result)
486 return 0;
487
488 DBG("ERR: usb_write failed with status %d\n", result);
489 return -1;
490}
491
492int usb_read(usb_handle *handle, void *buf, int len)
493{
494 IOReturn result;
495 UInt32 numBytes = len;
496
497 if (!len) {
498 return 0;
499 }
500
501 if (!handle) {
502 return -1;
503 }
504
505 if (NULL == handle->interface) {
506 DBG("ERR: usb_read interface was null\n");
507 return -1;
508 }
509
510 if (0 == handle->bulkIn) {
511 DBG("ERR: bulkIn endpoint not assigned\n");
512 return -1;
513 }
514
515 result =
516 (*handle->interface)->ReadPipe(handle->interface,
517 handle->bulkIn, buf, &numBytes);
518
519 if (0 == result)
520 return 0;
521 else {
522 DBG("ERR: usb_read failed with status %d\n", result);
523 }
524
525 return -1;
526}
527
528int usb_close(usb_handle *handle)
529{
530 return 0;
531}
532
533void usb_kick(usb_handle *handle)
534{
535 /* release the interface */
Dima Zavin3fd82b82009-05-08 18:25:58 -0700536 if (!handle)
537 return;
538
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800539 if (handle->interface)
540 {
541 (*handle->interface)->USBInterfaceClose(handle->interface);
542 (*handle->interface)->Release(handle->interface);
543 handle->interface = 0;
544 }
545}