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