blob: 0ccc057647e094a20180ae7498df06d1f27ebbae [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 Gao6b55e752020-03-27 18:09:56 -070021#include "adb.h"
22#include "transport.h"
23
Josh Gaob7366922016-09-28 12:32:45 -070024// USB host/client interface.
25
Josh Gao6b55e752020-03-27 18:09:56 -070026struct usb_handle;
Fabien Sanglard704b4b62023-10-18 17:22:03 -070027
28void usb_init();
29void usb_cleanup();
30int usb_write(usb_handle* h, const void* data, int len);
31int usb_read(usb_handle* h, void* data, int len);
32int usb_close(usb_handle* h);
33void usb_reset(usb_handle* h);
34void usb_kick(usb_handle* h);
35size_t usb_get_max_packet_size(usb_handle*);
Josh Gaob7366922016-09-28 12:32:45 -070036
Josh Gaob7366922016-09-28 12:32:45 -070037// USB device detection.
Nataraj Deshpanded0db47d2023-03-13 11:28:58 -070038bool is_adb_interface(int usb_class, int usb_subclass, int usb_protocol);
Josh Gao210b63f2017-02-22 17:07:01 -080039
40bool should_use_libusb();
Josh Gao6b55e752020-03-27 18:09:56 -070041
Josh Gaof2d6af52021-04-27 20:32:02 -070042namespace libusb {
43void usb_init();
44}
45
Josh Gao6b55e752020-03-27 18:09:56 -070046struct UsbConnection : public BlockingConnection {
47 explicit UsbConnection(usb_handle* handle) : handle_(handle) {}
48 ~UsbConnection();
49
50 bool Read(apacket* packet) override final;
51 bool Write(apacket* packet) override final;
52 bool DoTlsHandshake(RSA* key, std::string* auth_key) override final;
53
54 void Close() override final;
55 virtual void Reset() override final;
56
57 usb_handle* handle_;
58};