• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include <sys/types.h>
20 
21 #include "adb.h"
22 #include "transport.h"
23 
24 // USB host/client interface.
25 
26 struct usb_handle;
27 
28 void usb_init();
29 void usb_cleanup();
30 int usb_write(usb_handle* h, const void* data, int len);
31 int usb_read(usb_handle* h, void* data, int len);
32 int usb_close(usb_handle* h);
33 void usb_reset(usb_handle* h);
34 void usb_kick(usb_handle* h);
35 size_t usb_get_max_packet_size(usb_handle*);
36 
37 // USB device detection.
38 bool is_adb_interface(int usb_class, int usb_subclass, int usb_protocol);
39 
40 bool is_libusb_enabled();
41 
42 struct UsbConnection : public BlockingConnection {
UsbConnectionUsbConnection43     explicit UsbConnection(usb_handle* handle) : handle_(handle) {}
44     ~UsbConnection();
45 
46     bool Read(apacket* packet) override final;
47     bool Write(apacket* packet) override final;
48     bool DoTlsHandshake(RSA* key, std::string* auth_key) override final;
49 
50     void Close() override final;
51     virtual void Reset() override final;
52 
53     usb_handle* handle_;
54 };
55