The Android Open Source Project | dd7bc33 | 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> |
| 21 | |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 22 | #include "transport.h" /* readx(), writex() */ |
| 23 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 24 | #define MAX_PAYLOAD 4096 |
| 25 | |
| 26 | #define A_SYNC 0x434e5953 |
| 27 | #define A_CNXN 0x4e584e43 |
| 28 | #define A_OPEN 0x4e45504f |
| 29 | #define A_OKAY 0x59414b4f |
| 30 | #define A_CLSE 0x45534c43 |
| 31 | #define A_WRTE 0x45545257 |
| 32 | |
| 33 | #define A_VERSION 0x01000000 // ADB protocol version |
| 34 | |
| 35 | #define ADB_VERSION_MAJOR 1 // Used for help/version information |
| 36 | #define ADB_VERSION_MINOR 0 // Used for help/version information |
| 37 | |
Benoit Goby | 3fc95a9 | 2012-08-20 23:04:11 -0700 | [diff] [blame] | 38 | #define ADB_SERVER_VERSION 29 // Increment this when we want to force users to start a new adb server |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 39 | |
| 40 | typedef struct amessage amessage; |
| 41 | typedef struct apacket apacket; |
| 42 | typedef struct asocket asocket; |
| 43 | typedef struct alistener alistener; |
| 44 | typedef struct aservice aservice; |
| 45 | typedef struct atransport atransport; |
| 46 | typedef struct adisconnect adisconnect; |
| 47 | typedef struct usb_handle usb_handle; |
| 48 | |
| 49 | struct amessage { |
| 50 | unsigned command; /* command identifier constant */ |
| 51 | unsigned arg0; /* first argument */ |
| 52 | unsigned arg1; /* second argument */ |
| 53 | unsigned data_length; /* length of payload (0 is allowed) */ |
| 54 | unsigned data_check; /* checksum of data payload */ |
| 55 | unsigned magic; /* command ^ 0xffffffff */ |
| 56 | }; |
| 57 | |
| 58 | struct apacket |
| 59 | { |
| 60 | apacket *next; |
| 61 | |
| 62 | unsigned len; |
| 63 | unsigned char *ptr; |
| 64 | |
| 65 | amessage msg; |
| 66 | unsigned char data[MAX_PAYLOAD]; |
| 67 | }; |
| 68 | |
| 69 | /* An asocket represents one half of a connection between a local and |
| 70 | ** remote entity. A local asocket is bound to a file descriptor. A |
| 71 | ** remote asocket is bound to the protocol engine. |
| 72 | */ |
| 73 | struct asocket { |
| 74 | /* chain pointers for the local/remote list of |
| 75 | ** asockets that this asocket lives in |
| 76 | */ |
| 77 | asocket *next; |
| 78 | asocket *prev; |
| 79 | |
| 80 | /* the unique identifier for this asocket |
| 81 | */ |
| 82 | unsigned id; |
| 83 | |
| 84 | /* flag: set when the socket's peer has closed |
| 85 | ** but packets are still queued for delivery |
| 86 | */ |
| 87 | int closing; |
| 88 | |
Benoit Goby | f366b36 | 2012-03-16 14:50:07 -0700 | [diff] [blame] | 89 | /* flag: quit adbd when both ends close the |
| 90 | ** local service socket |
| 91 | */ |
| 92 | int exit_on_close; |
| 93 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 94 | /* the asocket we are connected to |
| 95 | */ |
| 96 | |
| 97 | asocket *peer; |
| 98 | |
| 99 | /* For local asockets, the fde is used to bind |
| 100 | ** us to our fd event system. For remote asockets |
| 101 | ** these fields are not used. |
| 102 | */ |
| 103 | fdevent fde; |
| 104 | int fd; |
| 105 | |
| 106 | /* queue of apackets waiting to be written |
| 107 | */ |
| 108 | apacket *pkt_first; |
| 109 | apacket *pkt_last; |
| 110 | |
| 111 | /* enqueue is called by our peer when it has data |
| 112 | ** for us. It should return 0 if we can accept more |
| 113 | ** data or 1 if not. If we return 1, we must call |
| 114 | ** peer->ready() when we once again are ready to |
| 115 | ** receive data. |
| 116 | */ |
| 117 | int (*enqueue)(asocket *s, apacket *pkt); |
| 118 | |
| 119 | /* ready is called by the peer when it is ready for |
| 120 | ** us to send data via enqueue again |
| 121 | */ |
| 122 | void (*ready)(asocket *s); |
| 123 | |
| 124 | /* close is called by the peer when it has gone away. |
| 125 | ** we are not allowed to make any further calls on the |
| 126 | ** peer once our close method is called. |
| 127 | */ |
| 128 | void (*close)(asocket *s); |
| 129 | |
| 130 | /* socket-type-specific extradata */ |
| 131 | void *extra; |
| 132 | |
JP Abgrall | 0e7c427 | 2011-02-23 18:44:39 -0800 | [diff] [blame] | 133 | /* A socket is bound to atransport */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 134 | atransport *transport; |
| 135 | }; |
| 136 | |
| 137 | |
| 138 | /* the adisconnect structure is used to record a callback that |
| 139 | ** will be called whenever a transport is disconnected (e.g. by the user) |
| 140 | ** this should be used to cleanup objects that depend on the |
| 141 | ** transport (e.g. remote sockets, listeners, etc...) |
| 142 | */ |
| 143 | struct adisconnect |
| 144 | { |
| 145 | void (*func)(void* opaque, atransport* t); |
| 146 | void* opaque; |
| 147 | adisconnect* next; |
| 148 | adisconnect* prev; |
| 149 | }; |
| 150 | |
| 151 | |
| 152 | /* a transport object models the connection to a remote device or emulator |
| 153 | ** there is one transport per connected device/emulator. a "local transport" |
| 154 | ** connects through TCP (for the emulator), while a "usb transport" through |
| 155 | ** USB (for real devices) |
| 156 | ** |
| 157 | ** note that kTransportHost doesn't really correspond to a real transport |
| 158 | ** object, it's a special value used to indicate that a client wants to |
| 159 | ** connect to a service implemented within the ADB server itself. |
| 160 | */ |
| 161 | typedef enum transport_type { |
| 162 | kTransportUsb, |
| 163 | kTransportLocal, |
| 164 | kTransportAny, |
| 165 | kTransportHost, |
| 166 | } transport_type; |
| 167 | |
| 168 | struct atransport |
| 169 | { |
| 170 | atransport *next; |
| 171 | atransport *prev; |
| 172 | |
| 173 | int (*read_from_remote)(apacket *p, atransport *t); |
| 174 | int (*write_to_remote)(apacket *p, atransport *t); |
| 175 | void (*close)(atransport *t); |
| 176 | void (*kick)(atransport *t); |
| 177 | |
| 178 | int fd; |
| 179 | int transport_socket; |
| 180 | fdevent transport_fde; |
| 181 | int ref_count; |
| 182 | unsigned sync_token; |
| 183 | int connection_state; |
| 184 | transport_type type; |
| 185 | |
| 186 | /* usb handle or socket fd as needed */ |
| 187 | usb_handle *usb; |
| 188 | int sfd; |
| 189 | |
| 190 | /* used to identify transports for clients */ |
| 191 | char *serial; |
| 192 | char *product; |
Scott Anderson | e82c2db | 2012-05-25 14:10:02 -0700 | [diff] [blame] | 193 | char *model; |
| 194 | char *device; |
Scott Anderson | e109d26 | 2012-04-20 11:21:14 -0700 | [diff] [blame] | 195 | char *devpath; |
Stefan Hilzinger | d9d1ca4 | 2010-04-26 10:17:43 +0100 | [diff] [blame] | 196 | int adb_port; // Use for emulators (local transport) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 197 | |
| 198 | /* a list of adisconnect callbacks called when the transport is kicked */ |
| 199 | int kicked; |
| 200 | adisconnect disconnects; |
| 201 | }; |
| 202 | |
| 203 | |
| 204 | /* A listener is an entity which binds to a local port |
| 205 | ** and, upon receiving a connection on that port, creates |
| 206 | ** an asocket to connect the new local connection to a |
| 207 | ** specific remote service. |
| 208 | ** |
| 209 | ** TODO: some listeners read from the new connection to |
| 210 | ** determine what exact service to connect to on the far |
| 211 | ** side. |
| 212 | */ |
| 213 | struct alistener |
| 214 | { |
| 215 | alistener *next; |
| 216 | alistener *prev; |
| 217 | |
| 218 | fdevent fde; |
| 219 | int fd; |
| 220 | |
| 221 | const char *local_name; |
| 222 | const char *connect_to; |
| 223 | atransport *transport; |
| 224 | adisconnect disconnect; |
| 225 | }; |
| 226 | |
| 227 | |
| 228 | void print_packet(const char *label, apacket *p); |
| 229 | |
| 230 | asocket *find_local_socket(unsigned id); |
| 231 | void install_local_socket(asocket *s); |
| 232 | void remove_socket(asocket *s); |
| 233 | void close_all_sockets(atransport *t); |
| 234 | |
| 235 | #define LOCAL_CLIENT_PREFIX "emulator-" |
| 236 | |
| 237 | asocket *create_local_socket(int fd); |
| 238 | asocket *create_local_service_socket(const char *destination); |
| 239 | |
| 240 | asocket *create_remote_socket(unsigned id, atransport *t); |
| 241 | void connect_to_remote(asocket *s, const char *destination); |
| 242 | void connect_to_smartsocket(asocket *s); |
| 243 | |
| 244 | void fatal(const char *fmt, ...); |
| 245 | void fatal_errno(const char *fmt, ...); |
| 246 | |
| 247 | void handle_packet(apacket *p, atransport *t); |
| 248 | void send_packet(apacket *p, atransport *t); |
| 249 | |
Alexey Tarasov | 3166410 | 2009-10-22 02:55:00 +1100 | [diff] [blame] | 250 | void get_my_path(char *s, size_t maxLen); |
Stefan Hilzinger | a84a42e | 2010-04-19 12:21:12 +0100 | [diff] [blame] | 251 | int launch_server(int server_port); |
| 252 | int adb_main(int is_daemon, int server_port); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 253 | |
| 254 | |
| 255 | /* transports are ref-counted |
| 256 | ** get_device_transport does an acquire on your behalf before returning |
| 257 | */ |
| 258 | void init_transport_registration(void); |
Scott Anderson | 2ca3e6b | 2012-05-30 18:11:27 -0700 | [diff] [blame] | 259 | int list_transports(char *buf, size_t bufsize, int long_listing); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 260 | void update_transports(void); |
| 261 | |
| 262 | asocket* create_device_tracker(void); |
| 263 | |
| 264 | /* Obtain a transport from the available transports. |
| 265 | ** If state is != CS_ANY, only transports in that state are considered. |
| 266 | ** If serial is non-NULL then only the device with that serial will be chosen. |
| 267 | ** If no suitable transport is found, error is set. |
| 268 | */ |
| 269 | atransport *acquire_one_transport(int state, transport_type ttype, const char* serial, char **error_out); |
| 270 | void add_transport_disconnect( atransport* t, adisconnect* dis ); |
| 271 | void remove_transport_disconnect( atransport* t, adisconnect* dis ); |
| 272 | void run_transport_disconnects( atransport* t ); |
| 273 | void kick_transport( atransport* t ); |
| 274 | |
| 275 | /* initialize a transport object's func pointers and state */ |
Stefan Hilzinger | d9d1ca4 | 2010-04-26 10:17:43 +0100 | [diff] [blame] | 276 | #if ADB_HOST |
| 277 | int get_available_local_transport_index(); |
| 278 | #endif |
Mike Lockwood | 2f38b69 | 2009-08-24 15:58:40 -0700 | [diff] [blame] | 279 | int init_socket_transport(atransport *t, int s, int port, int local); |
Mike Lockwood | 95b837d | 2009-08-08 12:37:44 -0400 | [diff] [blame] | 280 | void init_usb_transport(atransport *t, usb_handle *usb, int state); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 281 | |
| 282 | /* for MacOS X cleanup */ |
| 283 | void close_usb_devices(); |
| 284 | |
| 285 | /* cause new transports to be init'd and added to the list */ |
Mike Lockwood | 2f38b69 | 2009-08-24 15:58:40 -0700 | [diff] [blame] | 286 | void register_socket_transport(int s, const char *serial, int port, int local); |
Mike Lockwood | 74d7ff8 | 2009-10-11 23:04:18 -0400 | [diff] [blame] | 287 | |
Mike Lockwood | cbbe79a | 2010-05-24 10:44:35 -0400 | [diff] [blame] | 288 | /* these should only be used for the "adb disconnect" command */ |
Mike Lockwood | 74d7ff8 | 2009-10-11 23:04:18 -0400 | [diff] [blame] | 289 | void unregister_transport(atransport *t); |
Mike Lockwood | cbbe79a | 2010-05-24 10:44:35 -0400 | [diff] [blame] | 290 | void unregister_all_tcp_transports(); |
Mike Lockwood | 74d7ff8 | 2009-10-11 23:04:18 -0400 | [diff] [blame] | 291 | |
Scott Anderson | e109d26 | 2012-04-20 11:21:14 -0700 | [diff] [blame] | 292 | void register_usb_transport(usb_handle *h, const char *serial, const char *devpath, unsigned writeable); |
Mike Lockwood | 95b837d | 2009-08-08 12:37:44 -0400 | [diff] [blame] | 293 | |
| 294 | /* this should only be used for transports with connection_state == CS_NOPERM */ |
| 295 | void unregister_usb_transport(usb_handle *usb); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 296 | |
Mike Lockwood | 74d7ff8 | 2009-10-11 23:04:18 -0400 | [diff] [blame] | 297 | atransport *find_transport(const char *serial); |
Stefan Hilzinger | d9d1ca4 | 2010-04-26 10:17:43 +0100 | [diff] [blame] | 298 | #if ADB_HOST |
| 299 | atransport* find_emulator_transport_by_adb_port(int adb_port); |
| 300 | #endif |
Mike Lockwood | 74d7ff8 | 2009-10-11 23:04:18 -0400 | [diff] [blame] | 301 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 302 | int service_to_fd(const char *name); |
| 303 | #if ADB_HOST |
| 304 | asocket *host_service_to_socket(const char* name, const char *serial); |
| 305 | #endif |
| 306 | |
| 307 | #if !ADB_HOST |
| 308 | int init_jdwp(void); |
| 309 | asocket* create_jdwp_service_socket(); |
| 310 | asocket* create_jdwp_tracker_service_socket(); |
| 311 | int create_jdwp_connection_fd(int jdwp_pid); |
| 312 | #endif |
| 313 | |
| 314 | #if !ADB_HOST |
Christopher Tate | 702967a | 2011-05-17 15:52:54 -0700 | [diff] [blame] | 315 | typedef enum { |
| 316 | BACKUP, |
| 317 | RESTORE |
| 318 | } BackupOperation; |
| 319 | int backup_service(BackupOperation operation, char* args); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 320 | void framebuffer_service(int fd, void *cookie); |
| 321 | void log_service(int fd, void *cookie); |
| 322 | void remount_service(int fd, void *cookie); |
| 323 | char * get_log_file_path(const char * log_name); |
| 324 | #endif |
| 325 | |
| 326 | /* packet allocator */ |
| 327 | apacket *get_apacket(void); |
| 328 | void put_apacket(apacket *p); |
| 329 | |
| 330 | int check_header(apacket *p); |
| 331 | int check_data(apacket *p); |
| 332 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 333 | /* define ADB_TRACE to 1 to enable tracing support, or 0 to disable it */ |
| 334 | |
| 335 | #define ADB_TRACE 1 |
| 336 | |
| 337 | /* IMPORTANT: if you change the following list, don't |
| 338 | * forget to update the corresponding 'tags' table in |
| 339 | * the adb_trace_init() function implemented in adb.c |
| 340 | */ |
| 341 | typedef enum { |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 342 | TRACE_ADB = 0, /* 0x001 */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 343 | TRACE_SOCKETS, |
| 344 | TRACE_PACKETS, |
| 345 | TRACE_TRANSPORT, |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 346 | TRACE_RWX, /* 0x010 */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 347 | TRACE_USB, |
| 348 | TRACE_SYNC, |
| 349 | TRACE_SYSDEPS, |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 350 | TRACE_JDWP, /* 0x100 */ |
| 351 | TRACE_SERVICES, |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 352 | } AdbTrace; |
| 353 | |
| 354 | #if ADB_TRACE |
| 355 | |
Vladimir Chtchetkine | 28781b0 | 2012-02-27 10:41:53 -0800 | [diff] [blame] | 356 | #if !ADB_HOST |
| 357 | /* |
| 358 | * When running inside the emulator, guest's adbd can connect to 'adb-debug' |
| 359 | * qemud service that can display adb trace messages (on condition that emulator |
| 360 | * has been started with '-debug adb' option). |
| 361 | */ |
| 362 | |
| 363 | /* Delivers a trace message to the emulator via QEMU pipe. */ |
| 364 | void adb_qemu_trace(const char* fmt, ...); |
| 365 | /* Macro to use to send ADB trace messages to the emulator. */ |
| 366 | #define DQ(...) adb_qemu_trace(__VA_ARGS__) |
| 367 | #else |
| 368 | #define DQ(...) ((void)0) |
| 369 | #endif /* !ADB_HOST */ |
| 370 | |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 371 | extern int adb_trace_mask; |
| 372 | extern unsigned char adb_trace_output_count; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 373 | void adb_trace_init(void); |
| 374 | |
| 375 | # define ADB_TRACING ((adb_trace_mask & (1 << TRACE_TAG)) != 0) |
| 376 | |
| 377 | /* you must define TRACE_TAG before using this macro */ |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 378 | # define D(...) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 379 | do { \ |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 380 | if (ADB_TRACING) { \ |
| 381 | int save_errno = errno; \ |
| 382 | adb_mutex_lock(&D_lock); \ |
| 383 | fprintf(stderr, "%s::%s():", \ |
| 384 | __FILE__, __FUNCTION__); \ |
| 385 | errno = save_errno; \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 386 | fprintf(stderr, __VA_ARGS__ ); \ |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 387 | fflush(stderr); \ |
| 388 | adb_mutex_unlock(&D_lock); \ |
| 389 | errno = save_errno; \ |
| 390 | } \ |
| 391 | } while (0) |
| 392 | # define DR(...) \ |
| 393 | do { \ |
| 394 | if (ADB_TRACING) { \ |
| 395 | int save_errno = errno; \ |
| 396 | adb_mutex_lock(&D_lock); \ |
| 397 | errno = save_errno; \ |
| 398 | fprintf(stderr, __VA_ARGS__ ); \ |
| 399 | fflush(stderr); \ |
| 400 | adb_mutex_unlock(&D_lock); \ |
| 401 | errno = save_errno; \ |
| 402 | } \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 403 | } while (0) |
| 404 | #else |
| 405 | # define D(...) ((void)0) |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 406 | # define DR(...) ((void)0) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 407 | # define ADB_TRACING 0 |
| 408 | #endif |
| 409 | |
| 410 | |
Benoit Goby | 3fc95a9 | 2012-08-20 23:04:11 -0700 | [diff] [blame] | 411 | #if !TRACE_PACKETS |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 412 | #define print_packet(tag,p) do {} while (0) |
| 413 | #endif |
| 414 | |
John Michelau | c318833 | 2010-09-23 17:08:34 -0500 | [diff] [blame] | 415 | #if ADB_HOST_ON_TARGET |
| 416 | /* adb and adbd are coexisting on the target, so use 5038 for adb |
| 417 | * to avoid conflicting with adbd's usage of 5037 |
| 418 | */ |
| 419 | # define DEFAULT_ADB_PORT 5038 |
| 420 | #else |
| 421 | # define DEFAULT_ADB_PORT 5037 |
| 422 | #endif |
| 423 | |
Stefan Hilzinger | a84a42e | 2010-04-19 12:21:12 +0100 | [diff] [blame] | 424 | #define DEFAULT_ADB_LOCAL_TRANSPORT_PORT 5555 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 425 | |
Xavier Ducrohet | a481d09 | 2009-05-21 17:47:43 -0700 | [diff] [blame] | 426 | #define ADB_CLASS 0xff |
| 427 | #define ADB_SUBCLASS 0x42 |
| 428 | #define ADB_PROTOCOL 0x1 |
Dima Zavin | 3fd82b8 | 2009-05-08 18:25:58 -0700 | [diff] [blame] | 429 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 430 | |
Mike Lockwood | cef31a0 | 2009-08-26 12:50:22 -0700 | [diff] [blame] | 431 | void local_init(int port); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 432 | int local_connect(int port); |
Stefan Hilzinger | d9d1ca4 | 2010-04-26 10:17:43 +0100 | [diff] [blame] | 433 | int local_connect_arbitrary_ports(int console_port, int adb_port); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 434 | |
| 435 | /* usb host/client interface */ |
| 436 | void usb_init(); |
| 437 | void usb_cleanup(); |
| 438 | int usb_write(usb_handle *h, const void *data, int len); |
| 439 | int usb_read(usb_handle *h, void *data, int len); |
| 440 | int usb_close(usb_handle *h); |
| 441 | void usb_kick(usb_handle *h); |
| 442 | |
| 443 | /* used for USB device detection */ |
Xavier Ducrohet | a09fbd1 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 444 | #if ADB_HOST |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 445 | int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol); |
Xavier Ducrohet | a09fbd1 | 2009-05-20 17:33:53 -0700 | [diff] [blame] | 446 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 447 | |
| 448 | unsigned host_to_le32(unsigned n); |
| 449 | int adb_commandline(int argc, char **argv); |
| 450 | |
| 451 | int connection_state(atransport *t); |
| 452 | |
| 453 | #define CS_ANY -1 |
| 454 | #define CS_OFFLINE 0 |
| 455 | #define CS_BOOTLOADER 1 |
| 456 | #define CS_DEVICE 2 |
| 457 | #define CS_HOST 3 |
| 458 | #define CS_RECOVERY 4 |
Mike Lockwood | 95b837d | 2009-08-08 12:37:44 -0400 | [diff] [blame] | 459 | #define CS_NOPERM 5 /* Insufficient permissions to communicate with the device */ |
Doug Zongker | 447f061 | 2012-01-09 14:54:53 -0800 | [diff] [blame] | 460 | #define CS_SIDELOAD 6 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 461 | |
| 462 | extern int HOST; |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 463 | extern int SHELL_EXIT_NOTIFY_FD; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 464 | |
| 465 | #define CHUNK_SIZE (64*1024) |
| 466 | |
Andrzej Pietrasiewicz | fd96db1 | 2012-01-13 15:13:46 +0100 | [diff] [blame] | 467 | #if !ADB_HOST |
| 468 | #define USB_ADB_PATH "/dev/android_adb" |
| 469 | |
| 470 | #define USB_FFS_ADB_PATH "/dev/usb-ffs/adb/" |
| 471 | #define USB_FFS_ADB_EP(x) USB_FFS_ADB_PATH#x |
| 472 | |
| 473 | #define USB_FFS_ADB_EP0 USB_FFS_ADB_EP(ep0) |
| 474 | #define USB_FFS_ADB_OUT USB_FFS_ADB_EP(ep1) |
| 475 | #define USB_FFS_ADB_IN USB_FFS_ADB_EP(ep2) |
| 476 | #endif |
| 477 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 478 | int sendfailmsg(int fd, const char *reason); |
| 479 | int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s); |
| 480 | |
| 481 | #endif |