| Josh Gao | 1c70e1b | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2016 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 | #pragma once | 
 | 18 |  | 
| Josh Gao | ef3d343 | 2017-05-02 15:01:09 -0700 | [diff] [blame] | 19 | #include <sys/types.h> | 
 | 20 |  | 
| Josh Gao | 1c70e1b | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 21 | // USB host/client interface. | 
 | 22 |  | 
 | 23 | #define ADB_USB_INTERFACE(handle_ref_type)                       \ | 
 | 24 |     void usb_init();                                             \ | 
| Josh Gao | 01b7bc4 | 2017-05-09 13:43:35 -0700 | [diff] [blame] | 25 |     void usb_cleanup();                                          \ | 
| Josh Gao | 1c70e1b | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 26 |     int usb_write(handle_ref_type h, const void* data, int len); \ | 
 | 27 |     int usb_read(handle_ref_type h, void* data, int len);        \ | 
 | 28 |     int usb_close(handle_ref_type h);                            \ | 
| Josh Gao | 3705b34 | 2019-03-28 15:47:44 -0700 | [diff] [blame] | 29 |     void usb_reset(handle_ref_type h);                           \ | 
| Josh Gao | ef3d343 | 2017-05-02 15:01:09 -0700 | [diff] [blame] | 30 |     void usb_kick(handle_ref_type h);                            \ | 
 | 31 |     size_t usb_get_max_packet_size(handle_ref_type) | 
| Josh Gao | 1c70e1b | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 32 |  | 
| Josh Gao | 9425996 | 2017-12-08 13:05:40 -0800 | [diff] [blame] | 33 | #if !ADB_HOST | 
 | 34 | // The daemon has a single implementation. | 
| Josh Gao | 1c70e1b | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 35 |  | 
 | 36 | struct usb_handle; | 
 | 37 | ADB_USB_INTERFACE(usb_handle*); | 
 | 38 |  | 
 | 39 | #else // linux host || darwin | 
 | 40 | // Linux and Darwin clients have native and libusb implementations. | 
 | 41 |  | 
 | 42 | namespace libusb { | 
 | 43 |     struct usb_handle; | 
 | 44 |     ADB_USB_INTERFACE(libusb::usb_handle*); | 
 | 45 | } | 
 | 46 |  | 
 | 47 | namespace native { | 
 | 48 |     struct usb_handle; | 
 | 49 |     ADB_USB_INTERFACE(native::usb_handle*); | 
 | 50 | } | 
 | 51 |  | 
 | 52 | // Empty base that both implementations' opaque handles inherit from. | 
 | 53 | struct usb_handle { | 
 | 54 | }; | 
 | 55 |  | 
 | 56 | ADB_USB_INTERFACE(::usb_handle*); | 
 | 57 |  | 
 | 58 | #endif // linux host || darwin | 
 | 59 |  | 
 | 60 |  | 
 | 61 | // USB device detection. | 
 | 62 | int is_adb_interface(int usb_class, int usb_subclass, int usb_protocol); | 
| Josh Gao | 5d1756c | 2017-02-22 17:07:01 -0800 | [diff] [blame] | 63 |  | 
 | 64 | bool should_use_libusb(); |