blob: e867ec8a34810765402ec16935c02aa30433bb41 [file] [log] [blame]
Josh Gaob7366922016-09-28 12:32:45 -07001/*
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 Gao3734cf02017-05-02 15:01:09 -070019#include <sys/types.h>
20
Josh Gaob7366922016-09-28 12:32:45 -070021// USB host/client interface.
22
23#define ADB_USB_INTERFACE(handle_ref_type) \
24 void usb_init(); \
25 int usb_write(handle_ref_type h, const void* data, int len); \
26 int usb_read(handle_ref_type h, void* data, int len); \
27 int usb_close(handle_ref_type h); \
Josh Gao3734cf02017-05-02 15:01:09 -070028 void usb_kick(handle_ref_type h); \
29 size_t usb_get_max_packet_size(handle_ref_type)
Josh Gaob7366922016-09-28 12:32:45 -070030
31#if defined(_WIN32) || !ADB_HOST
32// Windows and the daemon have a single implementation.
33
34struct usb_handle;
35ADB_USB_INTERFACE(usb_handle*);
36
37#else // linux host || darwin
38// Linux and Darwin clients have native and libusb implementations.
39
40namespace libusb {
41 struct usb_handle;
42 ADB_USB_INTERFACE(libusb::usb_handle*);
43}
44
45namespace native {
46 struct usb_handle;
47 ADB_USB_INTERFACE(native::usb_handle*);
48}
49
50// Empty base that both implementations' opaque handles inherit from.
51struct usb_handle {
52};
53
54ADB_USB_INTERFACE(::usb_handle*);
55
56#endif // linux host || darwin
57
58
59// USB device detection.
60int is_adb_interface(int usb_class, int usb_subclass, int usb_protocol);
Josh Gao210b63f2017-02-22 17:07:01 -080061
62bool should_use_libusb();