The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | #ifndef __ADB_H |
| 18 | #define __ADB_H |
| 19 | |
| 20 | #include <limits.h> |
Dan Albert | b302d12 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 21 | #include <sys/types.h> |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 22 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 23 | #include <base/macros.h> |
| 24 | |
Elliott Hughes | 43df109 | 2015-07-23 17:12:58 -0700 | [diff] [blame] | 25 | #include <string> |
| 26 | |
leozwang | f25a6a4 | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 27 | #include "adb_trace.h" |
Dan Albert | bbbbea6 | 2014-11-24 23:34:35 -0800 | [diff] [blame] | 28 | #include "fdevent.h" |
JP Abgrall | 2e5dd6e | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 29 | |
Tamas Berghammer | a1c60c0 | 2015-07-13 19:12:28 +0100 | [diff] [blame] | 30 | constexpr size_t MAX_PAYLOAD_V1 = 4 * 1024; |
| 31 | constexpr size_t MAX_PAYLOAD_V2 = 256 * 1024; |
| 32 | constexpr size_t MAX_PAYLOAD = MAX_PAYLOAD_V2; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 33 | |
| 34 | #define A_SYNC 0x434e5953 |
| 35 | #define A_CNXN 0x4e584e43 |
| 36 | #define A_OPEN 0x4e45504f |
| 37 | #define A_OKAY 0x59414b4f |
| 38 | #define A_CLSE 0x45534c43 |
| 39 | #define A_WRTE 0x45545257 |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 40 | #define A_AUTH 0x48545541 |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 41 | |
Dan Albert | b302d12 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 42 | // ADB protocol version. |
| 43 | #define A_VERSION 0x01000000 |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 44 | |
Dan Albert | b302d12 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 45 | // Used for help/version information. |
| 46 | #define ADB_VERSION_MAJOR 1 |
| 47 | #define ADB_VERSION_MINOR 0 |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 48 | |
Dan Albert | b302d12 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 49 | // Increment this when we want to force users to start a new adb server. |
| 50 | #define ADB_SERVER_VERSION 32 |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 51 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 52 | class atransport; |
Elliott Hughes | fe7ff81 | 2015-04-17 09:47:42 -0700 | [diff] [blame] | 53 | struct usb_handle; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 54 | |
| 55 | struct amessage { |
| 56 | unsigned command; /* command identifier constant */ |
| 57 | unsigned arg0; /* first argument */ |
| 58 | unsigned arg1; /* second argument */ |
| 59 | unsigned data_length; /* length of payload (0 is allowed) */ |
| 60 | unsigned data_check; /* checksum of data payload */ |
| 61 | unsigned magic; /* command ^ 0xffffffff */ |
| 62 | }; |
| 63 | |
| 64 | struct apacket |
| 65 | { |
| 66 | apacket *next; |
| 67 | |
| 68 | unsigned len; |
| 69 | unsigned char *ptr; |
| 70 | |
| 71 | amessage msg; |
| 72 | unsigned char data[MAX_PAYLOAD]; |
| 73 | }; |
| 74 | |
| 75 | /* An asocket represents one half of a connection between a local and |
| 76 | ** remote entity. A local asocket is bound to a file descriptor. A |
| 77 | ** remote asocket is bound to the protocol engine. |
| 78 | */ |
| 79 | struct asocket { |
| 80 | /* chain pointers for the local/remote list of |
| 81 | ** asockets that this asocket lives in |
| 82 | */ |
| 83 | asocket *next; |
| 84 | asocket *prev; |
| 85 | |
| 86 | /* the unique identifier for this asocket |
| 87 | */ |
| 88 | unsigned id; |
| 89 | |
| 90 | /* flag: set when the socket's peer has closed |
| 91 | ** but packets are still queued for delivery |
| 92 | */ |
| 93 | int closing; |
| 94 | |
Benoit Goby | 88468f3 | 2012-03-16 14:50:07 -0700 | [diff] [blame] | 95 | /* flag: quit adbd when both ends close the |
| 96 | ** local service socket |
| 97 | */ |
| 98 | int exit_on_close; |
| 99 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 100 | /* the asocket we are connected to |
| 101 | */ |
| 102 | |
| 103 | asocket *peer; |
| 104 | |
| 105 | /* For local asockets, the fde is used to bind |
| 106 | ** us to our fd event system. For remote asockets |
| 107 | ** these fields are not used. |
| 108 | */ |
| 109 | fdevent fde; |
| 110 | int fd; |
| 111 | |
| 112 | /* queue of apackets waiting to be written |
| 113 | */ |
| 114 | apacket *pkt_first; |
| 115 | apacket *pkt_last; |
| 116 | |
| 117 | /* enqueue is called by our peer when it has data |
| 118 | ** for us. It should return 0 if we can accept more |
| 119 | ** data or 1 if not. If we return 1, we must call |
| 120 | ** peer->ready() when we once again are ready to |
| 121 | ** receive data. |
| 122 | */ |
| 123 | int (*enqueue)(asocket *s, apacket *pkt); |
| 124 | |
| 125 | /* ready is called by the peer when it is ready for |
| 126 | ** us to send data via enqueue again |
| 127 | */ |
| 128 | void (*ready)(asocket *s); |
| 129 | |
David 'Digit' Turner | e92344d | 2013-12-13 14:09:44 +0100 | [diff] [blame] | 130 | /* shutdown is called by the peer before it goes away. |
| 131 | ** the socket should not do any further calls on its peer. |
| 132 | ** Always followed by a call to close. Optional, i.e. can be NULL. |
| 133 | */ |
| 134 | void (*shutdown)(asocket *s); |
| 135 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 136 | /* close is called by the peer when it has gone away. |
| 137 | ** we are not allowed to make any further calls on the |
| 138 | ** peer once our close method is called. |
| 139 | */ |
| 140 | void (*close)(asocket *s); |
| 141 | |
Benoit Goby | 12dc369 | 2013-02-20 15:04:53 -0800 | [diff] [blame] | 142 | /* A socket is bound to atransport */ |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 143 | atransport *transport; |
Tamas Berghammer | a1c60c0 | 2015-07-13 19:12:28 +0100 | [diff] [blame] | 144 | |
| 145 | size_t get_max_payload() const; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | |
| 149 | /* the adisconnect structure is used to record a callback that |
| 150 | ** will be called whenever a transport is disconnected (e.g. by the user) |
| 151 | ** this should be used to cleanup objects that depend on the |
| 152 | ** transport (e.g. remote sockets, listeners, etc...) |
| 153 | */ |
| 154 | struct adisconnect |
| 155 | { |
| 156 | void (*func)(void* opaque, atransport* t); |
| 157 | void* opaque; |
| 158 | adisconnect* next; |
| 159 | adisconnect* prev; |
| 160 | }; |
| 161 | |
| 162 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 163 | // A transport object models the connection to a remote device or emulator there |
| 164 | // is one transport per connected device/emulator. A "local transport" connects |
| 165 | // through TCP (for the emulator), while a "usb transport" through USB (for real |
| 166 | // devices). |
| 167 | // |
| 168 | // Note that kTransportHost doesn't really correspond to a real transport |
| 169 | // object, it's a special value used to indicate that a client wants to connect |
| 170 | // to a service implemented within the ADB server itself. |
Elliott Hughes | 3aec2ba | 2015-05-05 13:10:43 -0700 | [diff] [blame] | 171 | enum TransportType { |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 172 | kTransportUsb, |
| 173 | kTransportLocal, |
| 174 | kTransportAny, |
| 175 | kTransportHost, |
Elliott Hughes | fe7ff81 | 2015-04-17 09:47:42 -0700 | [diff] [blame] | 176 | }; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 177 | |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 178 | #define TOKEN_SIZE 20 |
| 179 | |
Dan Albert | 9a50f4c | 2015-05-18 16:43:57 -0700 | [diff] [blame] | 180 | enum ConnectionState { |
| 181 | kCsAny = -1, |
| 182 | kCsOffline = 0, |
| 183 | kCsBootloader, |
| 184 | kCsDevice, |
| 185 | kCsHost, |
| 186 | kCsRecovery, |
| 187 | kCsNoPerm, // Insufficient permissions to communicate with the device. |
| 188 | kCsSideload, |
| 189 | kCsUnauthorized, |
| 190 | }; |
| 191 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 192 | class atransport { |
| 193 | public: |
| 194 | // TODO(danalbert): We expose waaaaaaay too much stuff because this was |
| 195 | // historically just a struct, but making the whole thing a more idiomatic |
| 196 | // class in one go is a very large change. Given how bad our testing is, |
| 197 | // it's better to do this piece by piece. |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 198 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 199 | atransport() { |
| 200 | auth_fde = {}; |
| 201 | transport_fde = {}; |
Tamas Berghammer | a1c60c0 | 2015-07-13 19:12:28 +0100 | [diff] [blame] | 202 | protocol_version = A_VERSION; |
| 203 | max_payload = MAX_PAYLOAD; |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 204 | } |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 205 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 206 | virtual ~atransport() {} |
| 207 | |
| 208 | int (*read_from_remote)(apacket* p, atransport* t) = nullptr; |
| 209 | int (*write_to_remote)(apacket* p, atransport* t) = nullptr; |
| 210 | void (*close)(atransport* t) = nullptr; |
| 211 | void (*kick)(atransport* t) = nullptr; |
| 212 | |
| 213 | int fd = -1; |
| 214 | int transport_socket = -1; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 215 | fdevent transport_fde; |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 216 | int ref_count = 0; |
| 217 | uint32_t sync_token = 0; |
| 218 | ConnectionState connection_state = kCsOffline; |
| 219 | bool online = false; |
| 220 | TransportType type = kTransportAny; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 221 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 222 | // USB handle or socket fd as needed. |
| 223 | usb_handle* usb = nullptr; |
| 224 | int sfd = -1; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 225 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 226 | // Used to identify transports for clients. |
| 227 | char* serial = nullptr; |
| 228 | char* product = nullptr; |
| 229 | char* model = nullptr; |
| 230 | char* device = nullptr; |
| 231 | char* devpath = nullptr; |
| 232 | int adb_port = -1; // Use for emulators (local transport) |
| 233 | bool kicked = false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 234 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 235 | // A list of adisconnect callbacks called when the transport is kicked. |
| 236 | adisconnect disconnects = {}; |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 237 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 238 | void* key = nullptr; |
| 239 | unsigned char token[TOKEN_SIZE] = {}; |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 240 | fdevent auth_fde; |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 241 | size_t failed_auth_attempts = 0; |
Elliott Hughes | 88b4c85 | 2015-04-30 17:32:03 -0700 | [diff] [blame] | 242 | |
| 243 | const char* connection_state_name() const; |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 244 | |
Tamas Berghammer | a1c60c0 | 2015-07-13 19:12:28 +0100 | [diff] [blame] | 245 | void update_version(int version, size_t payload); |
| 246 | int get_protocol_version() const; |
| 247 | size_t get_max_payload() const; |
| 248 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 249 | private: |
Tamas Berghammer | a1c60c0 | 2015-07-13 19:12:28 +0100 | [diff] [blame] | 250 | int protocol_version; |
| 251 | size_t max_payload; |
| 252 | |
Dan Albert | ecce503 | 2015-05-18 16:46:31 -0700 | [diff] [blame] | 253 | DISALLOW_COPY_AND_ASSIGN(atransport); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 254 | }; |
| 255 | |
| 256 | |
| 257 | /* A listener is an entity which binds to a local port |
| 258 | ** and, upon receiving a connection on that port, creates |
| 259 | ** an asocket to connect the new local connection to a |
| 260 | ** specific remote service. |
| 261 | ** |
| 262 | ** TODO: some listeners read from the new connection to |
| 263 | ** determine what exact service to connect to on the far |
| 264 | ** side. |
| 265 | */ |
| 266 | struct alistener |
| 267 | { |
| 268 | alistener *next; |
| 269 | alistener *prev; |
| 270 | |
| 271 | fdevent fde; |
| 272 | int fd; |
| 273 | |
Dan Albert | f30d73c | 2015-02-25 17:51:28 -0800 | [diff] [blame] | 274 | char *local_name; |
| 275 | char *connect_to; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 276 | atransport *transport; |
| 277 | adisconnect disconnect; |
| 278 | }; |
| 279 | |
| 280 | |
| 281 | void print_packet(const char *label, apacket *p); |
| 282 | |
David 'Digit' Turner | e92344d | 2013-12-13 14:09:44 +0100 | [diff] [blame] | 283 | asocket *find_local_socket(unsigned local_id, unsigned remote_id); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 284 | void install_local_socket(asocket *s); |
| 285 | void remove_socket(asocket *s); |
| 286 | void close_all_sockets(atransport *t); |
| 287 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 288 | asocket *create_local_socket(int fd); |
| 289 | asocket *create_local_service_socket(const char *destination); |
| 290 | |
| 291 | asocket *create_remote_socket(unsigned id, atransport *t); |
| 292 | void connect_to_remote(asocket *s, const char *destination); |
| 293 | void connect_to_smartsocket(asocket *s); |
| 294 | |
Dan Albert | 3d978e6 | 2015-07-09 20:35:09 +0000 | [diff] [blame] | 295 | void fatal(const char *fmt, ...); |
| 296 | void fatal_errno(const char *fmt, ...); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 297 | |
| 298 | void handle_packet(apacket *p, atransport *t); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 299 | |
Alexey Tarasov | 857f17a | 2009-10-22 02:55:00 +1100 | [diff] [blame] | 300 | void get_my_path(char *s, size_t maxLen); |
Stefan Hilzinger | 92ca4fa | 2010-04-19 12:21:12 +0100 | [diff] [blame] | 301 | int launch_server(int server_port); |
Siva Velusamy | a55dbd8 | 2015-08-07 10:10:29 -0700 | [diff] [blame^] | 302 | int adb_main(int is_daemon, int server_port, int ack_reply_fd); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 303 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 304 | /* initialize a transport object's func pointers and state */ |
Stefan Hilzinger | 1ec0342 | 2010-04-26 10:17:43 +0100 | [diff] [blame] | 305 | #if ADB_HOST |
| 306 | int get_available_local_transport_index(); |
| 307 | #endif |
Mike Lockwood | b51ae57 | 2009-08-24 15:58:40 -0700 | [diff] [blame] | 308 | int init_socket_transport(atransport *t, int s, int port, int local); |
Dan Albert | 9a50f4c | 2015-05-18 16:43:57 -0700 | [diff] [blame] | 309 | void init_usb_transport(atransport *t, usb_handle *usb, ConnectionState state); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 310 | |
Stefan Hilzinger | 1ec0342 | 2010-04-26 10:17:43 +0100 | [diff] [blame] | 311 | #if ADB_HOST |
| 312 | atransport* find_emulator_transport_by_adb_port(int adb_port); |
| 313 | #endif |
Mike Lockwood | 5f2c4a1 | 2009-10-11 23:04:18 -0400 | [diff] [blame] | 314 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 315 | int service_to_fd(const char *name); |
| 316 | #if ADB_HOST |
| 317 | asocket *host_service_to_socket(const char* name, const char *serial); |
| 318 | #endif |
| 319 | |
| 320 | #if !ADB_HOST |
| 321 | int init_jdwp(void); |
| 322 | asocket* create_jdwp_service_socket(); |
| 323 | asocket* create_jdwp_tracker_service_socket(); |
| 324 | int create_jdwp_connection_fd(int jdwp_pid); |
| 325 | #endif |
| 326 | |
Elliott Hughes | 9d07fee | 2015-05-07 21:38:41 -0700 | [diff] [blame] | 327 | int handle_forward_request(const char* service, TransportType type, const char* serial, int reply_fd); |
David 'Digit' Turner | 963a449 | 2013-03-21 21:07:42 +0100 | [diff] [blame] | 328 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 329 | #if !ADB_HOST |
| 330 | void framebuffer_service(int fd, void *cookie); |
Paul Lawrence | 8ba2b02 | 2014-12-03 15:31:57 -0800 | [diff] [blame] | 331 | void set_verity_enabled_state_service(int fd, void* cookie); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 332 | #endif |
| 333 | |
| 334 | /* packet allocator */ |
| 335 | apacket *get_apacket(void); |
| 336 | void put_apacket(apacket *p); |
| 337 | |
leozwang | 1be5462 | 2014-08-15 09:51:27 -0700 | [diff] [blame] | 338 | // Define it if you want to dump packets. |
| 339 | #define DEBUG_PACKETS 0 |
| 340 | |
Benoit Goby | 2cc19e4 | 2012-04-12 12:23:49 -0700 | [diff] [blame] | 341 | #if !DEBUG_PACKETS |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 342 | #define print_packet(tag,p) do {} while (0) |
| 343 | #endif |
| 344 | |
John Michelau | 8733752 | 2010-09-23 17:08:34 -0500 | [diff] [blame] | 345 | #if ADB_HOST_ON_TARGET |
| 346 | /* adb and adbd are coexisting on the target, so use 5038 for adb |
| 347 | * to avoid conflicting with adbd's usage of 5037 |
| 348 | */ |
| 349 | # define DEFAULT_ADB_PORT 5038 |
| 350 | #else |
| 351 | # define DEFAULT_ADB_PORT 5037 |
| 352 | #endif |
| 353 | |
Stefan Hilzinger | 92ca4fa | 2010-04-19 12:21:12 +0100 | [diff] [blame] | 354 | #define DEFAULT_ADB_LOCAL_TRANSPORT_PORT 5555 |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 355 | |
Xavier Ducrohet | 30a4033 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 356 | #define ADB_CLASS 0xff |
| 357 | #define ADB_SUBCLASS 0x42 |
| 358 | #define ADB_PROTOCOL 0x1 |
Dima Zavin | 3e82491 | 2009-05-08 18:25:58 -0700 | [diff] [blame] | 359 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 360 | |
Mike Lockwood | a8b3875 | 2009-08-26 12:50:22 -0700 | [diff] [blame] | 361 | void local_init(int port); |
Elliott Hughes | 43df109 | 2015-07-23 17:12:58 -0700 | [diff] [blame] | 362 | void local_connect(int port); |
| 363 | int local_connect_arbitrary_ports(int console_port, int adb_port, std::string* error); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 364 | |
| 365 | /* usb host/client interface */ |
| 366 | void usb_init(); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 367 | int usb_write(usb_handle *h, const void *data, int len); |
| 368 | int usb_read(usb_handle *h, void *data, int len); |
| 369 | int usb_close(usb_handle *h); |
| 370 | void usb_kick(usb_handle *h); |
| 371 | |
| 372 | /* used for USB device detection */ |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 373 | #if ADB_HOST |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 374 | int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol); |
Xavier Ducrohet | 2ef5fc2 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 375 | #endif |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 376 | |
Dan Albert | f30d73c | 2015-02-25 17:51:28 -0800 | [diff] [blame] | 377 | int adb_commandline(int argc, const char **argv); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 378 | |
Dan Albert | 9a50f4c | 2015-05-18 16:43:57 -0700 | [diff] [blame] | 379 | ConnectionState connection_state(atransport *t); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 380 | |
Dan Albert | 432ffe2 | 2015-02-18 18:22:45 -0800 | [diff] [blame] | 381 | extern const char *adb_device_banner; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 382 | extern int HOST; |
Alex Vallée | 436fa6b | 2015-07-17 15:30:59 -0400 | [diff] [blame] | 383 | #if !ADB_HOST |
JP Abgrall | 2e5dd6e | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 384 | extern int SHELL_EXIT_NOTIFY_FD; |
Alex Vallée | 436fa6b | 2015-07-17 15:30:59 -0400 | [diff] [blame] | 385 | #endif // !ADB_HOST |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 386 | |
| 387 | #define CHUNK_SIZE (64*1024) |
| 388 | |
Andrzej Pietrasiewicz | d7270f2 | 2012-01-13 15:13:46 +0100 | [diff] [blame] | 389 | #if !ADB_HOST |
| 390 | #define USB_ADB_PATH "/dev/android_adb" |
| 391 | |
| 392 | #define USB_FFS_ADB_PATH "/dev/usb-ffs/adb/" |
| 393 | #define USB_FFS_ADB_EP(x) USB_FFS_ADB_PATH#x |
| 394 | |
| 395 | #define USB_FFS_ADB_EP0 USB_FFS_ADB_EP(ep0) |
| 396 | #define USB_FFS_ADB_OUT USB_FFS_ADB_EP(ep1) |
| 397 | #define USB_FFS_ADB_IN USB_FFS_ADB_EP(ep2) |
| 398 | #endif |
| 399 | |
Elliott Hughes | 9d07fee | 2015-05-07 21:38:41 -0700 | [diff] [blame] | 400 | int handle_host_request(const char* service, TransportType type, const char* serial, int reply_fd, asocket *s); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 401 | |
Dan Albert | 056ad0e | 2015-02-18 17:47:33 -0800 | [diff] [blame] | 402 | void handle_online(atransport *t); |
| 403 | void handle_offline(atransport *t); |
| 404 | |
| 405 | void send_connect(atransport *t); |
| 406 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 407 | #endif |