Josh Gao | b736692 | 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 | 3734cf0 | 2017-05-02 15:01:09 -0700 | [diff] [blame] | 19 | #include <sys/types.h> |
| 20 | |
Josh Gao | 6b55e75 | 2020-03-27 18:09:56 -0700 | [diff] [blame] | 21 | #include "adb.h" |
| 22 | #include "transport.h" |
| 23 | |
Josh Gao | b736692 | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 24 | // USB host/client interface. |
| 25 | |
| 26 | #define ADB_USB_INTERFACE(handle_ref_type) \ |
| 27 | void usb_init(); \ |
Josh Gao | 165460f | 2017-05-09 13:43:35 -0700 | [diff] [blame] | 28 | void usb_cleanup(); \ |
Josh Gao | b736692 | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 29 | int usb_write(handle_ref_type h, const void* data, int len); \ |
| 30 | int usb_read(handle_ref_type h, void* data, int len); \ |
| 31 | int usb_close(handle_ref_type h); \ |
Josh Gao | 3a2172b | 2019-03-28 15:47:44 -0700 | [diff] [blame] | 32 | void usb_reset(handle_ref_type h); \ |
Josh Gao | 3734cf0 | 2017-05-02 15:01:09 -0700 | [diff] [blame] | 33 | void usb_kick(handle_ref_type h); \ |
| 34 | size_t usb_get_max_packet_size(handle_ref_type) |
Josh Gao | b736692 | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 35 | |
Josh Gao | 6b55e75 | 2020-03-27 18:09:56 -0700 | [diff] [blame] | 36 | struct usb_handle; |
Josh Gao | f2d6af5 | 2021-04-27 20:32:02 -0700 | [diff] [blame] | 37 | ADB_USB_INTERFACE(usb_handle*); |
Josh Gao | b736692 | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 38 | |
Josh Gao | b736692 | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 39 | // USB device detection. |
| 40 | int is_adb_interface(int usb_class, int usb_subclass, int usb_protocol); |
Josh Gao | 210b63f | 2017-02-22 17:07:01 -0800 | [diff] [blame] | 41 | |
| 42 | bool should_use_libusb(); |
Josh Gao | 6b55e75 | 2020-03-27 18:09:56 -0700 | [diff] [blame] | 43 | |
Josh Gao | f2d6af5 | 2021-04-27 20:32:02 -0700 | [diff] [blame] | 44 | namespace libusb { |
| 45 | void usb_init(); |
| 46 | } |
| 47 | |
Josh Gao | 6b55e75 | 2020-03-27 18:09:56 -0700 | [diff] [blame] | 48 | struct UsbConnection : public BlockingConnection { |
| 49 | explicit UsbConnection(usb_handle* handle) : handle_(handle) {} |
| 50 | ~UsbConnection(); |
| 51 | |
| 52 | bool Read(apacket* packet) override final; |
| 53 | bool Write(apacket* packet) override final; |
| 54 | bool DoTlsHandshake(RSA* key, std::string* auth_key) override final; |
| 55 | |
| 56 | void Close() override final; |
| 57 | virtual void Reset() override final; |
| 58 | |
| 59 | usb_handle* handle_; |
| 60 | }; |