blob: 665e958ffcd257091c29c448e04f6c8ec90b9a8c [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
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#define TRACE_TAG TRACE_ADB
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <ctype.h>
22#include <stdarg.h>
23#include <errno.h>
Scott Andersonc7993af2012-05-25 13:55:46 -070024#include <stddef.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080025#include <string.h>
26#include <time.h>
Mike Lockwood1f546e62009-05-25 18:17:55 -040027#include <sys/time.h>
Ray Donnellycbb98912012-11-29 01:36:08 +000028#include <stdint.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080029
30#include "sysdeps.h"
31#include "adb.h"
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070032#include "adb_auth.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080033
Scott Andersone82c2db2012-05-25 14:10:02 -070034#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
35
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080036#if !ADB_HOST
Nick Kralevich893a4a42013-05-23 09:54:13 -070037#include <cutils/properties.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080038#include <private/android_filesystem_config.h>
Nick Kraleviche2864bf2013-02-28 14:12:58 -080039#include <sys/capability.h>
Mike Lockwood5f4b0512009-08-04 20:37:51 -040040#include <linux/prctl.h>
Jeff Sharkey885342a2012-08-14 21:00:22 -070041#include <sys/mount.h>
Nick Kralevichd49aa252014-01-18 09:25:04 -080042#include <getopt.h>
43#include <selinux/selinux.h>
Xavier Ducroheta09fbd12009-05-20 17:33:53 -070044#else
45#include "usb_vendors.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080046#endif
47
JP Abgrall408fa572011-03-16 15:57:42 -070048#if ADB_TRACE
49ADB_MUTEX_DEFINE( D_lock );
50#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080051
52int HOST = 0;
Matt Gumbeld7b33082012-11-14 10:16:17 -080053int gListenAll = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080054
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070055static int auth_enabled = 0;
56
Scott Andersone82c2db2012-05-25 14:10:02 -070057#if !ADB_HOST
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080058static const char *adb_device_banner = "device";
Nick Kralevichd49aa252014-01-18 09:25:04 -080059static const char *root_seclabel = NULL;
Scott Andersone82c2db2012-05-25 14:10:02 -070060#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080061
62void fatal(const char *fmt, ...)
63{
64 va_list ap;
65 va_start(ap, fmt);
66 fprintf(stderr, "error: ");
67 vfprintf(stderr, fmt, ap);
68 fprintf(stderr, "\n");
69 va_end(ap);
70 exit(-1);
71}
72
73void fatal_errno(const char *fmt, ...)
74{
75 va_list ap;
76 va_start(ap, fmt);
77 fprintf(stderr, "error: %s: ", strerror(errno));
78 vfprintf(stderr, fmt, ap);
79 fprintf(stderr, "\n");
80 va_end(ap);
81 exit(-1);
82}
83
84int adb_trace_mask;
85
86/* read a comma/space/colum/semi-column separated list of tags
87 * from the ADB_TRACE environment variable and build the trace
88 * mask from it. note that '1' and 'all' are special cases to
89 * enable all tracing
90 */
91void adb_trace_init(void)
92{
93 const char* p = getenv("ADB_TRACE");
94 const char* q;
95
96 static const struct {
97 const char* tag;
98 int flag;
99 } tags[] = {
100 { "1", 0 },
101 { "all", 0 },
102 { "adb", TRACE_ADB },
103 { "sockets", TRACE_SOCKETS },
104 { "packets", TRACE_PACKETS },
105 { "rwx", TRACE_RWX },
106 { "usb", TRACE_USB },
107 { "sync", TRACE_SYNC },
108 { "sysdeps", TRACE_SYSDEPS },
109 { "transport", TRACE_TRANSPORT },
110 { "jdwp", TRACE_JDWP },
JP Abgrall408fa572011-03-16 15:57:42 -0700111 { "services", TRACE_SERVICES },
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700112 { "auth", TRACE_AUTH },
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800113 { NULL, 0 }
114 };
115
116 if (p == NULL)
117 return;
118
119 /* use a comma/column/semi-colum/space separated list */
120 while (*p) {
121 int len, tagn;
122
123 q = strpbrk(p, " ,:;");
124 if (q == NULL) {
125 q = p + strlen(p);
126 }
127 len = q - p;
128
129 for (tagn = 0; tags[tagn].tag != NULL; tagn++)
130 {
131 int taglen = strlen(tags[tagn].tag);
132
133 if (len == taglen && !memcmp(tags[tagn].tag, p, len) )
134 {
135 int flag = tags[tagn].flag;
136 if (flag == 0) {
137 adb_trace_mask = ~0;
138 return;
139 }
140 adb_trace_mask |= (1 << flag);
141 break;
142 }
143 }
144 p = q;
145 if (*p)
146 p++;
147 }
148}
149
Vladimir Chtchetkine28781b02012-02-27 10:41:53 -0800150#if !ADB_HOST
151/*
152 * Implements ADB tracing inside the emulator.
153 */
154
155#include <stdarg.h>
156
157/*
158 * Redefine open and write for qemu_pipe.h that contains inlined references
159 * to those routines. We will redifine them back after qemu_pipe.h inclusion.
160 */
161
162#undef open
163#undef write
164#define open adb_open
165#define write adb_write
166#include <hardware/qemu_pipe.h>
167#undef open
168#undef write
169#define open ___xxx_open
170#define write ___xxx_write
171
172/* A handle to adb-debug qemud service in the emulator. */
173int adb_debug_qemu = -1;
174
175/* Initializes connection with the adb-debug qemud service in the emulator. */
176static int adb_qemu_trace_init(void)
177{
178 char con_name[32];
179
180 if (adb_debug_qemu >= 0) {
181 return 0;
182 }
183
184 /* adb debugging QEMUD service connection request. */
185 snprintf(con_name, sizeof(con_name), "qemud:adb-debug");
186 adb_debug_qemu = qemu_pipe_open(con_name);
187 return (adb_debug_qemu >= 0) ? 0 : -1;
188}
189
190void adb_qemu_trace(const char* fmt, ...)
191{
192 va_list args;
193 va_start(args, fmt);
194 char msg[1024];
195
196 if (adb_debug_qemu >= 0) {
197 vsnprintf(msg, sizeof(msg), fmt, args);
198 adb_write(adb_debug_qemu, msg, strlen(msg));
199 }
200}
201#endif /* !ADB_HOST */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800202
203apacket *get_apacket(void)
204{
205 apacket *p = malloc(sizeof(apacket));
206 if(p == 0) fatal("failed to allocate an apacket");
207 memset(p, 0, sizeof(apacket) - MAX_PAYLOAD);
208 return p;
209}
210
211void put_apacket(apacket *p)
212{
213 free(p);
214}
215
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700216void handle_online(atransport *t)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800217{
218 D("adb: online\n");
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700219 t->online = 1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800220}
221
222void handle_offline(atransport *t)
223{
224 D("adb: offline\n");
225 //Close the associated usb
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700226 t->online = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800227 run_transport_disconnects(t);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800228}
229
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700230#if DEBUG_PACKETS
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800231#define DUMPMAX 32
232void print_packet(const char *label, apacket *p)
233{
234 char *tag;
235 char *x;
236 unsigned count;
237
238 switch(p->msg.command){
239 case A_SYNC: tag = "SYNC"; break;
240 case A_CNXN: tag = "CNXN" ; break;
241 case A_OPEN: tag = "OPEN"; break;
242 case A_OKAY: tag = "OKAY"; break;
243 case A_CLSE: tag = "CLSE"; break;
244 case A_WRTE: tag = "WRTE"; break;
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700245 case A_AUTH: tag = "AUTH"; break;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800246 default: tag = "????"; break;
247 }
248
249 fprintf(stderr, "%s: %s %08x %08x %04x \"",
250 label, tag, p->msg.arg0, p->msg.arg1, p->msg.data_length);
251 count = p->msg.data_length;
252 x = (char*) p->data;
253 if(count > DUMPMAX) {
254 count = DUMPMAX;
255 tag = "\n";
256 } else {
257 tag = "\"\n";
258 }
259 while(count-- > 0){
260 if((*x >= ' ') && (*x < 127)) {
261 fputc(*x, stderr);
262 } else {
263 fputc('.', stderr);
264 }
265 x++;
266 }
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700267 fputs(tag, stderr);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800268}
269#endif
270
271static void send_ready(unsigned local, unsigned remote, atransport *t)
272{
273 D("Calling send_ready \n");
274 apacket *p = get_apacket();
275 p->msg.command = A_OKAY;
276 p->msg.arg0 = local;
277 p->msg.arg1 = remote;
278 send_packet(p, t);
279}
280
281static void send_close(unsigned local, unsigned remote, atransport *t)
282{
283 D("Calling send_close \n");
284 apacket *p = get_apacket();
285 p->msg.command = A_CLSE;
286 p->msg.arg0 = local;
287 p->msg.arg1 = remote;
288 send_packet(p, t);
289}
290
Scott Andersone82c2db2012-05-25 14:10:02 -0700291static size_t fill_connect_data(char *buf, size_t bufsize)
292{
293#if ADB_HOST
294 return snprintf(buf, bufsize, "host::") + 1;
295#else
296 static const char *cnxn_props[] = {
297 "ro.product.name",
298 "ro.product.model",
299 "ro.product.device",
300 };
301 static const int num_cnxn_props = ARRAY_SIZE(cnxn_props);
302 int i;
303 size_t remaining = bufsize;
304 size_t len;
305
306 len = snprintf(buf, remaining, "%s::", adb_device_banner);
307 remaining -= len;
308 buf += len;
309 for (i = 0; i < num_cnxn_props; i++) {
310 char value[PROPERTY_VALUE_MAX];
311 property_get(cnxn_props[i], value, "");
312 len = snprintf(buf, remaining, "%s=%s;", cnxn_props[i], value);
313 remaining -= len;
314 buf += len;
315 }
316
317 return bufsize - remaining + 1;
318#endif
319}
320
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800321static void send_connect(atransport *t)
322{
323 D("Calling send_connect \n");
324 apacket *cp = get_apacket();
325 cp->msg.command = A_CNXN;
326 cp->msg.arg0 = A_VERSION;
327 cp->msg.arg1 = MAX_PAYLOAD;
Scott Andersone82c2db2012-05-25 14:10:02 -0700328 cp->msg.data_length = fill_connect_data((char *)cp->data,
329 sizeof(cp->data));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800330 send_packet(cp, t);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700331}
332
Benoit Goby045a4a92013-01-15 19:59:14 -0800333void send_auth_request(atransport *t)
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700334{
335 D("Calling send_auth_request\n");
336 apacket *p;
337 int ret;
338
339 ret = adb_auth_generate_token(t->token, sizeof(t->token));
340 if (ret != sizeof(t->token)) {
341 D("Error generating token ret=%d\n", ret);
342 return;
343 }
344
345 p = get_apacket();
346 memcpy(p->data, t->token, ret);
347 p->msg.command = A_AUTH;
348 p->msg.arg0 = ADB_AUTH_TOKEN;
349 p->msg.data_length = ret;
350 send_packet(p, t);
351}
352
353static void send_auth_response(uint8_t *token, size_t token_size, atransport *t)
354{
355 D("Calling send_auth_response\n");
356 apacket *p = get_apacket();
357 int ret;
358
359 ret = adb_auth_sign(t->key, token, token_size, p->data);
360 if (!ret) {
361 D("Error signing the token\n");
362 put_apacket(p);
363 return;
364 }
365
366 p->msg.command = A_AUTH;
367 p->msg.arg0 = ADB_AUTH_SIGNATURE;
368 p->msg.data_length = ret;
369 send_packet(p, t);
370}
371
372static void send_auth_publickey(atransport *t)
373{
374 D("Calling send_auth_publickey\n");
375 apacket *p = get_apacket();
376 int ret;
377
378 ret = adb_auth_get_userkey(p->data, sizeof(p->data));
379 if (!ret) {
380 D("Failed to get user public key\n");
381 put_apacket(p);
382 return;
383 }
384
385 p->msg.command = A_AUTH;
386 p->msg.arg0 = ADB_AUTH_RSAPUBLICKEY;
387 p->msg.data_length = ret;
388 send_packet(p, t);
389}
390
391void adb_auth_verified(atransport *t)
392{
393 handle_online(t);
394 send_connect(t);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800395}
396
397static char *connection_state_name(atransport *t)
398{
399 if (t == NULL) {
400 return "unknown";
401 }
402
403 switch(t->connection_state) {
404 case CS_BOOTLOADER:
405 return "bootloader";
406 case CS_DEVICE:
407 return "device";
trevda5ad5392013-04-17 14:34:23 +0100408 case CS_RECOVERY:
409 return "recovery";
410 case CS_SIDELOAD:
411 return "sideload";
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800412 case CS_OFFLINE:
413 return "offline";
Benoit Goby77e8e582013-01-15 12:36:47 -0800414 case CS_UNAUTHORIZED:
415 return "unauthorized";
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800416 default:
417 return "unknown";
418 }
419}
420
Scott Andersone82c2db2012-05-25 14:10:02 -0700421/* qual_overwrite is used to overwrite a qualifier string. dst is a
422 * pointer to a char pointer. It is assumed that if *dst is non-NULL, it
Scott Anderson2ca3e6b2012-05-30 18:11:27 -0700423 * was malloc'ed and needs to freed. *dst will be set to a dup of src.
Scott Andersone82c2db2012-05-25 14:10:02 -0700424 */
425static void qual_overwrite(char **dst, const char *src)
426{
427 if (!dst)
428 return;
429
430 free(*dst);
431 *dst = NULL;
432
433 if (!src || !*src)
434 return;
435
436 *dst = strdup(src);
437}
438
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800439void parse_banner(char *banner, atransport *t)
440{
Scott Andersone82c2db2012-05-25 14:10:02 -0700441 static const char *prop_seps = ";";
442 static const char key_val_sep = '=';
Scott Anderson2ca3e6b2012-05-30 18:11:27 -0700443 char *cp;
444 char *type;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800445
446 D("parse_banner: %s\n", banner);
447 type = banner;
Scott Andersone82c2db2012-05-25 14:10:02 -0700448 cp = strchr(type, ':');
449 if (cp) {
450 *cp++ = 0;
451 /* Nothing is done with second field. */
452 cp = strchr(cp, ':');
453 if (cp) {
454 char *save;
455 char *key;
Scott Anderson1b7a7e82012-06-05 17:54:27 -0700456 key = adb_strtok_r(cp + 1, prop_seps, &save);
Scott Andersone82c2db2012-05-25 14:10:02 -0700457 while (key) {
458 cp = strchr(key, key_val_sep);
459 if (cp) {
460 *cp++ = '\0';
461 if (!strcmp(key, "ro.product.name"))
462 qual_overwrite(&t->product, cp);
463 else if (!strcmp(key, "ro.product.model"))
464 qual_overwrite(&t->model, cp);
465 else if (!strcmp(key, "ro.product.device"))
466 qual_overwrite(&t->device, cp);
467 }
Scott Anderson1b7a7e82012-06-05 17:54:27 -0700468 key = adb_strtok_r(NULL, prop_seps, &save);
Scott Andersone82c2db2012-05-25 14:10:02 -0700469 }
470 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800471 }
472
473 if(!strcmp(type, "bootloader")){
474 D("setting connection_state to CS_BOOTLOADER\n");
475 t->connection_state = CS_BOOTLOADER;
476 update_transports();
477 return;
478 }
479
480 if(!strcmp(type, "device")) {
481 D("setting connection_state to CS_DEVICE\n");
482 t->connection_state = CS_DEVICE;
483 update_transports();
484 return;
485 }
486
487 if(!strcmp(type, "recovery")) {
488 D("setting connection_state to CS_RECOVERY\n");
489 t->connection_state = CS_RECOVERY;
490 update_transports();
491 return;
492 }
493
Doug Zongker447f0612012-01-09 14:54:53 -0800494 if(!strcmp(type, "sideload")) {
495 D("setting connection_state to CS_SIDELOAD\n");
496 t->connection_state = CS_SIDELOAD;
497 update_transports();
498 return;
499 }
500
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800501 t->connection_state = CS_HOST;
502}
503
504void handle_packet(apacket *p, atransport *t)
505{
506 asocket *s;
507
Viral Mehta899913f2010-06-16 18:41:28 +0530508 D("handle_packet() %c%c%c%c\n", ((char*) (&(p->msg.command)))[0],
509 ((char*) (&(p->msg.command)))[1],
510 ((char*) (&(p->msg.command)))[2],
511 ((char*) (&(p->msg.command)))[3]);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800512 print_packet("recv", p);
513
514 switch(p->msg.command){
515 case A_SYNC:
516 if(p->msg.arg0){
517 send_packet(p, t);
518 if(HOST) send_connect(t);
519 } else {
520 t->connection_state = CS_OFFLINE;
521 handle_offline(t);
522 send_packet(p, t);
523 }
524 return;
525
526 case A_CNXN: /* CONNECT(version, maxdata, "system-id-string") */
527 /* XXX verify version, etc */
528 if(t->connection_state != CS_OFFLINE) {
529 t->connection_state = CS_OFFLINE;
530 handle_offline(t);
531 }
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700532
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800533 parse_banner((char*) p->data, t);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700534
535 if (HOST || !auth_enabled) {
536 handle_online(t);
537 if(!HOST) send_connect(t);
538 } else {
539 send_auth_request(t);
540 }
541 break;
542
543 case A_AUTH:
544 if (p->msg.arg0 == ADB_AUTH_TOKEN) {
Benoit Goby77e8e582013-01-15 12:36:47 -0800545 t->connection_state = CS_UNAUTHORIZED;
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700546 t->key = adb_auth_nextkey(t->key);
547 if (t->key) {
548 send_auth_response(p->data, p->msg.data_length, t);
549 } else {
550 /* No more private keys to try, send the public key */
551 send_auth_publickey(t);
552 }
553 } else if (p->msg.arg0 == ADB_AUTH_SIGNATURE) {
554 if (adb_auth_verify(t->token, p->data, p->msg.data_length)) {
555 adb_auth_verified(t);
556 t->failed_auth_attempts = 0;
557 } else {
558 if (t->failed_auth_attempts++ > 10)
559 adb_sleep_ms(1000);
560 send_auth_request(t);
561 }
562 } else if (p->msg.arg0 == ADB_AUTH_RSAPUBLICKEY) {
563 adb_auth_confirm_key(p->data, p->msg.data_length, t);
564 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800565 break;
566
567 case A_OPEN: /* OPEN(local-id, 0, "destination") */
David 'Digit' Turner818d6412013-12-13 14:09:44 +0100568 if (t->online && p->msg.arg0 != 0 && p->msg.arg1 == 0) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800569 char *name = (char*) p->data;
570 name[p->msg.data_length > 0 ? p->msg.data_length - 1 : 0] = 0;
571 s = create_local_service_socket(name);
572 if(s == 0) {
573 send_close(0, p->msg.arg0, t);
574 } else {
575 s->peer = create_remote_socket(p->msg.arg0, t);
576 s->peer->peer = s;
577 send_ready(s->id, s->peer->id, t);
578 s->ready(s);
579 }
580 }
581 break;
582
583 case A_OKAY: /* READY(local-id, remote-id, "") */
David 'Digit' Turner818d6412013-12-13 14:09:44 +0100584 if (t->online && p->msg.arg0 != 0 && p->msg.arg1 != 0) {
585 if((s = find_local_socket(p->msg.arg1, 0))) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800586 if(s->peer == 0) {
David 'Digit' Turner818d6412013-12-13 14:09:44 +0100587 /* On first READY message, create the connection. */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800588 s->peer = create_remote_socket(p->msg.arg0, t);
589 s->peer->peer = s;
David 'Digit' Turner818d6412013-12-13 14:09:44 +0100590 s->ready(s);
591 } else if (s->peer->id == p->msg.arg0) {
592 /* Other READY messages must use the same local-id */
593 s->ready(s);
594 } else {
595 D("Invalid A_OKAY(%d,%d), expected A_OKAY(%d,%d) on transport %s\n",
596 p->msg.arg0, p->msg.arg1, s->peer->id, p->msg.arg1, t->serial);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800597 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800598 }
599 }
600 break;
601
David 'Digit' Turner818d6412013-12-13 14:09:44 +0100602 case A_CLSE: /* CLOSE(local-id, remote-id, "") or CLOSE(0, remote-id, "") */
603 if (t->online && p->msg.arg1 != 0) {
604 if((s = find_local_socket(p->msg.arg1, p->msg.arg0))) {
605 /* According to protocol.txt, p->msg.arg0 might be 0 to indicate
606 * a failed OPEN only. However, due to a bug in previous ADB
607 * versions, CLOSE(0, remote-id, "") was also used for normal
608 * CLOSE() operations.
609 *
610 * This is bad because it means a compromised adbd could
611 * send packets to close connections between the host and
612 * other devices. To avoid this, only allow this if the local
613 * socket has a peer on the same transport.
614 */
615 if (p->msg.arg0 == 0 && s->peer && s->peer->transport != t) {
616 D("Invalid A_CLSE(0, %u) from transport %s, expected transport %s\n",
617 p->msg.arg1, t->serial, s->peer->transport->serial);
618 } else {
619 s->close(s);
620 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800621 }
622 }
623 break;
624
David 'Digit' Turner818d6412013-12-13 14:09:44 +0100625 case A_WRTE: /* WRITE(local-id, remote-id, <data>) */
626 if (t->online && p->msg.arg0 != 0 && p->msg.arg1 != 0) {
627 if((s = find_local_socket(p->msg.arg1, p->msg.arg0))) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800628 unsigned rid = p->msg.arg0;
629 p->len = p->msg.data_length;
630
631 if(s->enqueue(s, p) == 0) {
632 D("Enqueue the socket\n");
633 send_ready(s->id, rid, t);
634 }
635 return;
636 }
637 }
638 break;
639
640 default:
641 printf("handle_packet: what is %08x?!\n", p->msg.command);
642 }
643
644 put_apacket(p);
645}
646
647alistener listener_list = {
648 .next = &listener_list,
649 .prev = &listener_list,
650};
651
652static void ss_listener_event_func(int _fd, unsigned ev, void *_l)
653{
654 asocket *s;
655
656 if(ev & FDE_READ) {
657 struct sockaddr addr;
658 socklen_t alen;
659 int fd;
660
661 alen = sizeof(addr);
662 fd = adb_socket_accept(_fd, &addr, &alen);
663 if(fd < 0) return;
664
665 adb_socket_setbufsize(fd, CHUNK_SIZE);
666
667 s = create_local_socket(fd);
668 if(s) {
669 connect_to_smartsocket(s);
670 return;
671 }
672
673 adb_close(fd);
674 }
675}
676
677static void listener_event_func(int _fd, unsigned ev, void *_l)
678{
679 alistener *l = _l;
680 asocket *s;
681
682 if(ev & FDE_READ) {
683 struct sockaddr addr;
684 socklen_t alen;
685 int fd;
686
687 alen = sizeof(addr);
688 fd = adb_socket_accept(_fd, &addr, &alen);
689 if(fd < 0) return;
690
691 s = create_local_socket(fd);
692 if(s) {
693 s->transport = l->transport;
694 connect_to_remote(s, l->connect_to);
695 return;
696 }
697
698 adb_close(fd);
699 }
700}
701
702static void free_listener(alistener* l)
703{
704 if (l->next) {
705 l->next->prev = l->prev;
706 l->prev->next = l->next;
707 l->next = l->prev = l;
708 }
709
710 // closes the corresponding fd
711 fdevent_remove(&l->fde);
712
713 if (l->local_name)
714 free((char*)l->local_name);
715
716 if (l->connect_to)
717 free((char*)l->connect_to);
718
719 if (l->transport) {
720 remove_transport_disconnect(l->transport, &l->disconnect);
721 }
722 free(l);
723}
724
725static void listener_disconnect(void* _l, atransport* t)
726{
727 alistener* l = _l;
728
729 free_listener(l);
730}
731
732int local_name_to_fd(const char *name)
733{
734 int port;
735
736 if(!strncmp("tcp:", name, 4)){
737 int ret;
738 port = atoi(name + 4);
Matt Gumbeld7b33082012-11-14 10:16:17 -0800739
740 if (gListenAll > 0) {
741 ret = socket_inaddr_any_server(port, SOCK_STREAM);
742 } else {
743 ret = socket_loopback_server(port, SOCK_STREAM);
744 }
745
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800746 return ret;
747 }
748#ifndef HAVE_WIN32_IPC /* no Unix-domain sockets on Win32 */
749 // It's non-sensical to support the "reserved" space on the adb host side
750 if(!strncmp(name, "local:", 6)) {
751 return socket_local_server(name + 6,
752 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
753 } else if(!strncmp(name, "localabstract:", 14)) {
754 return socket_local_server(name + 14,
755 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
756 } else if(!strncmp(name, "localfilesystem:", 16)) {
757 return socket_local_server(name + 16,
758 ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM);
759 }
760
761#endif
762 printf("unknown local portname '%s'\n", name);
763 return -1;
764}
765
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100766// Write a single line describing a listener to a user-provided buffer.
767// Appends a trailing zero, even in case of truncation, but the function
768// returns the full line length.
769// If |buffer| is NULL, does not write but returns required size.
770static int format_listener(alistener* l, char* buffer, size_t buffer_len) {
771 // Format is simply:
772 //
773 // <device-serial> " " <local-name> " " <remote-name> "\n"
774 //
775 int local_len = strlen(l->local_name);
776 int connect_len = strlen(l->connect_to);
777 int serial_len = strlen(l->transport->serial);
778
779 if (buffer != NULL) {
780 snprintf(buffer, buffer_len, "%s %s %s\n",
781 l->transport->serial, l->local_name, l->connect_to);
782 }
783 // NOTE: snprintf() on Windows returns -1 in case of truncation, so
784 // return the computed line length instead.
785 return local_len + connect_len + serial_len + 3;
786}
787
788// Write the list of current listeners (network redirections) into a
789// user-provided buffer. Appends a trailing zero, even in case of
790// trunctaion, but return the full size in bytes.
791// If |buffer| is NULL, does not write but returns required size.
792static int format_listeners(char* buf, size_t buflen)
793{
794 alistener* l;
795 int result = 0;
796 for (l = listener_list.next; l != &listener_list; l = l->next) {
797 // Ignore special listeners like those for *smartsocket*
798 if (l->connect_to[0] == '*')
799 continue;
800 int len = format_listener(l, buf, buflen);
801 // Ensure there is space for the trailing zero.
802 result += len;
803 if (buf != NULL) {
804 buf += len;
805 buflen -= len;
806 if (buflen <= 0)
807 break;
808 }
809 }
810 return result;
811}
812
813static int remove_listener(const char *local_name, atransport* transport)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800814{
815 alistener *l;
816
817 for (l = listener_list.next; l != &listener_list; l = l->next) {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100818 if (!strcmp(local_name, l->local_name)) {
819 listener_disconnect(l, l->transport);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800820 return 0;
821 }
822 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800823 return -1;
824}
825
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100826static void remove_all_listeners(void)
827{
828 alistener *l, *l_next;
829 for (l = listener_list.next; l != &listener_list; l = l_next) {
830 l_next = l->next;
831 // Never remove smart sockets.
832 if (l->connect_to[0] == '*')
833 continue;
834 listener_disconnect(l, l->transport);
835 }
836}
837
838// error/status codes for install_listener.
839typedef enum {
840 INSTALL_STATUS_OK = 0,
841 INSTALL_STATUS_INTERNAL_ERROR = -1,
842 INSTALL_STATUS_CANNOT_BIND = -2,
843 INSTALL_STATUS_CANNOT_REBIND = -3,
844} install_status_t;
845
846static install_status_t install_listener(const char *local_name,
847 const char *connect_to,
848 atransport* transport,
849 int no_rebind)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800850{
851 alistener *l;
852
853 //printf("install_listener('%s','%s')\n", local_name, connect_to);
854
855 for(l = listener_list.next; l != &listener_list; l = l->next){
856 if(strcmp(local_name, l->local_name) == 0) {
857 char *cto;
858
859 /* can't repurpose a smartsocket */
860 if(l->connect_to[0] == '*') {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100861 return INSTALL_STATUS_INTERNAL_ERROR;
862 }
863
864 /* can't repurpose a listener if 'no_rebind' is true */
865 if (no_rebind) {
866 return INSTALL_STATUS_CANNOT_REBIND;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800867 }
868
869 cto = strdup(connect_to);
870 if(cto == 0) {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100871 return INSTALL_STATUS_INTERNAL_ERROR;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800872 }
873
874 //printf("rebinding '%s' to '%s'\n", local_name, connect_to);
875 free((void*) l->connect_to);
876 l->connect_to = cto;
877 if (l->transport != transport) {
878 remove_transport_disconnect(l->transport, &l->disconnect);
879 l->transport = transport;
880 add_transport_disconnect(l->transport, &l->disconnect);
881 }
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100882 return INSTALL_STATUS_OK;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800883 }
884 }
885
886 if((l = calloc(1, sizeof(alistener))) == 0) goto nomem;
887 if((l->local_name = strdup(local_name)) == 0) goto nomem;
888 if((l->connect_to = strdup(connect_to)) == 0) goto nomem;
889
890
891 l->fd = local_name_to_fd(local_name);
892 if(l->fd < 0) {
893 free((void*) l->local_name);
894 free((void*) l->connect_to);
895 free(l);
896 printf("cannot bind '%s'\n", local_name);
897 return -2;
898 }
899
900 close_on_exec(l->fd);
901 if(!strcmp(l->connect_to, "*smartsocket*")) {
902 fdevent_install(&l->fde, l->fd, ss_listener_event_func, l);
903 } else {
904 fdevent_install(&l->fde, l->fd, listener_event_func, l);
905 }
906 fdevent_set(&l->fde, FDE_READ);
907
908 l->next = &listener_list;
909 l->prev = listener_list.prev;
910 l->next->prev = l;
911 l->prev->next = l;
912 l->transport = transport;
913
914 if (transport) {
915 l->disconnect.opaque = l;
916 l->disconnect.func = listener_disconnect;
917 add_transport_disconnect(transport, &l->disconnect);
918 }
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100919 return INSTALL_STATUS_OK;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800920
921nomem:
922 fatal("cannot allocate listener");
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100923 return INSTALL_STATUS_INTERNAL_ERROR;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800924}
925
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800926#ifdef HAVE_WIN32_PROC
927static BOOL WINAPI ctrlc_handler(DWORD type)
928{
929 exit(STATUS_CONTROL_C_EXIT);
930 return TRUE;
931}
932#endif
933
934static void adb_cleanup(void)
935{
936 usb_cleanup();
937}
938
939void start_logging(void)
940{
941#ifdef HAVE_WIN32_PROC
942 char temp[ MAX_PATH ];
943 FILE* fnul;
944 FILE* flog;
945
946 GetTempPath( sizeof(temp) - 8, temp );
947 strcat( temp, "adb.log" );
948
949 /* Win32 specific redirections */
950 fnul = fopen( "NUL", "rt" );
951 if (fnul != NULL)
952 stdin[0] = fnul[0];
953
954 flog = fopen( temp, "at" );
955 if (flog == NULL)
956 flog = fnul;
957
958 setvbuf( flog, NULL, _IONBF, 0 );
959
960 stdout[0] = flog[0];
961 stderr[0] = flog[0];
962 fprintf(stderr,"--- adb starting (pid %d) ---\n", getpid());
963#else
964 int fd;
965
966 fd = unix_open("/dev/null", O_RDONLY);
967 dup2(fd, 0);
JP Abgrall408fa572011-03-16 15:57:42 -0700968 adb_close(fd);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800969
970 fd = unix_open("/tmp/adb.log", O_WRONLY | O_CREAT | O_APPEND, 0640);
971 if(fd < 0) {
972 fd = unix_open("/dev/null", O_WRONLY);
973 }
974 dup2(fd, 1);
975 dup2(fd, 2);
JP Abgrall408fa572011-03-16 15:57:42 -0700976 adb_close(fd);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800977 fprintf(stderr,"--- adb starting (pid %d) ---\n", getpid());
978#endif
979}
980
981#if !ADB_HOST
982void start_device_log(void)
983{
984 int fd;
Mike Lockwood1f546e62009-05-25 18:17:55 -0400985 char path[PATH_MAX];
986 struct tm now;
987 time_t t;
988 char value[PROPERTY_VALUE_MAX];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800989
Mike Lockwood1f546e62009-05-25 18:17:55 -0400990 // read the trace mask from persistent property persist.adb.trace_mask
991 // give up if the property is not set or cannot be parsed
992 property_get("persist.adb.trace_mask", value, "");
993 if (sscanf(value, "%x", &adb_trace_mask) != 1)
994 return;
995
996 adb_mkdir("/data/adb", 0775);
997 tzset();
998 time(&t);
999 localtime_r(&t, &now);
1000 strftime(path, sizeof(path),
1001 "/data/adb/adb-%Y-%m-%d-%H-%M-%S.txt",
1002 &now);
1003 fd = unix_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0640);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001004 if (fd < 0)
1005 return;
1006
1007 // redirect stdout and stderr to the log file
1008 dup2(fd, 1);
1009 dup2(fd, 2);
1010 fprintf(stderr,"--- adb starting (pid %d) ---\n", getpid());
Benoit Goby95ef8282011-02-01 18:57:41 -08001011 adb_close(fd);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001012
1013 fd = unix_open("/dev/null", O_RDONLY);
1014 dup2(fd, 0);
Benoit Goby95ef8282011-02-01 18:57:41 -08001015 adb_close(fd);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001016}
1017#endif
1018
1019#if ADB_HOST
JP Abgrall571c1362012-12-06 18:18:12 -08001020
1021#ifdef WORKAROUND_BUG6558362
1022#include <sched.h>
1023#define AFFINITY_ENVVAR "ADB_CPU_AFFINITY_BUG6558362"
1024void adb_set_affinity(void)
1025{
1026 cpu_set_t cpu_set;
1027 const char* cpunum_str = getenv(AFFINITY_ENVVAR);
1028 char* strtol_res;
1029 int cpu_num;
1030
1031 if (!cpunum_str || !*cpunum_str)
1032 return;
1033 cpu_num = strtol(cpunum_str, &strtol_res, 0);
1034 if (*strtol_res != '\0')
1035 fatal("bad number (%s) in env var %s. Expecting 0..n.\n", cpunum_str, AFFINITY_ENVVAR);
1036
1037 sched_getaffinity(0, sizeof(cpu_set), &cpu_set);
1038 D("orig cpu_set[0]=0x%08lx\n", cpu_set.__bits[0]);
1039 CPU_ZERO(&cpu_set);
1040 CPU_SET(cpu_num, &cpu_set);
1041 sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
1042 sched_getaffinity(0, sizeof(cpu_set), &cpu_set);
1043 D("new cpu_set[0]=0x%08lx\n", cpu_set.__bits[0]);
1044}
1045#endif
1046
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001047int launch_server(int server_port)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001048{
1049#ifdef HAVE_WIN32_PROC
1050 /* we need to start the server in the background */
1051 /* we create a PIPE that will be used to wait for the server's "OK" */
1052 /* message since the pipe handles must be inheritable, we use a */
1053 /* security attribute */
1054 HANDLE pipe_read, pipe_write;
Ray Donnelly267aa8b2012-11-29 01:18:50 +00001055 HANDLE stdout_handle, stderr_handle;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001056 SECURITY_ATTRIBUTES sa;
1057 STARTUPINFO startup;
1058 PROCESS_INFORMATION pinfo;
1059 char program_path[ MAX_PATH ];
1060 int ret;
1061
1062 sa.nLength = sizeof(sa);
1063 sa.lpSecurityDescriptor = NULL;
1064 sa.bInheritHandle = TRUE;
1065
1066 /* create pipe, and ensure its read handle isn't inheritable */
1067 ret = CreatePipe( &pipe_read, &pipe_write, &sa, 0 );
1068 if (!ret) {
1069 fprintf(stderr, "CreatePipe() failure, error %ld\n", GetLastError() );
1070 return -1;
1071 }
1072
1073 SetHandleInformation( pipe_read, HANDLE_FLAG_INHERIT, 0 );
1074
Ray Donnelly267aa8b2012-11-29 01:18:50 +00001075 /* Some programs want to launch an adb command and collect its output by
1076 * calling CreateProcess with inheritable stdout/stderr handles, then
1077 * using read() to get its output. When this happens, the stdout/stderr
1078 * handles passed to the adb client process will also be inheritable.
1079 * When starting the adb server here, care must be taken to reset them
1080 * to non-inheritable.
1081 * Otherwise, something bad happens: even if the adb command completes,
1082 * the calling process is stuck while read()-ing from the stdout/stderr
1083 * descriptors, because they're connected to corresponding handles in the
1084 * adb server process (even if the latter never uses/writes to them).
1085 */
1086 stdout_handle = GetStdHandle( STD_OUTPUT_HANDLE );
1087 stderr_handle = GetStdHandle( STD_ERROR_HANDLE );
1088 if (stdout_handle != INVALID_HANDLE_VALUE) {
1089 SetHandleInformation( stdout_handle, HANDLE_FLAG_INHERIT, 0 );
1090 }
1091 if (stderr_handle != INVALID_HANDLE_VALUE) {
1092 SetHandleInformation( stderr_handle, HANDLE_FLAG_INHERIT, 0 );
1093 }
1094
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001095 ZeroMemory( &startup, sizeof(startup) );
1096 startup.cb = sizeof(startup);
1097 startup.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
1098 startup.hStdOutput = pipe_write;
1099 startup.hStdError = GetStdHandle( STD_ERROR_HANDLE );
1100 startup.dwFlags = STARTF_USESTDHANDLES;
1101
1102 ZeroMemory( &pinfo, sizeof(pinfo) );
1103
1104 /* get path of current program */
1105 GetModuleFileName( NULL, program_path, sizeof(program_path) );
1106
1107 ret = CreateProcess(
1108 program_path, /* program path */
1109 "adb fork-server server",
1110 /* the fork-server argument will set the
1111 debug = 2 in the child */
1112 NULL, /* process handle is not inheritable */
1113 NULL, /* thread handle is not inheritable */
1114 TRUE, /* yes, inherit some handles */
1115 DETACHED_PROCESS, /* the new process doesn't have a console */
1116 NULL, /* use parent's environment block */
1117 NULL, /* use parent's starting directory */
1118 &startup, /* startup info, i.e. std handles */
1119 &pinfo );
1120
1121 CloseHandle( pipe_write );
1122
1123 if (!ret) {
1124 fprintf(stderr, "CreateProcess failure, error %ld\n", GetLastError() );
1125 CloseHandle( pipe_read );
1126 return -1;
1127 }
1128
1129 CloseHandle( pinfo.hProcess );
1130 CloseHandle( pinfo.hThread );
1131
1132 /* wait for the "OK\n" message */
1133 {
1134 char temp[3];
1135 DWORD count;
1136
1137 ret = ReadFile( pipe_read, temp, 3, &count, NULL );
1138 CloseHandle( pipe_read );
1139 if ( !ret ) {
1140 fprintf(stderr, "could not read ok from ADB Server, error = %ld\n", GetLastError() );
1141 return -1;
1142 }
1143 if (count != 3 || temp[0] != 'O' || temp[1] != 'K' || temp[2] != '\n') {
1144 fprintf(stderr, "ADB server didn't ACK\n" );
1145 return -1;
1146 }
1147 }
1148#elif defined(HAVE_FORKEXEC)
1149 char path[PATH_MAX];
1150 int fd[2];
1151
1152 // set up a pipe so the child can tell us when it is ready.
1153 // fd[0] will be parent's end, and fd[1] will get mapped to stderr in the child.
1154 if (pipe(fd)) {
1155 fprintf(stderr, "pipe failed in launch_server, errno: %d\n", errno);
1156 return -1;
1157 }
Alexey Tarasov31664102009-10-22 02:55:00 +11001158 get_my_path(path, PATH_MAX);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001159 pid_t pid = fork();
1160 if(pid < 0) return -1;
1161
1162 if (pid == 0) {
1163 // child side of the fork
1164
1165 // redirect stderr to the pipe
1166 // we use stderr instead of stdout due to stdout's buffering behavior.
1167 adb_close(fd[0]);
1168 dup2(fd[1], STDERR_FILENO);
1169 adb_close(fd[1]);
1170
Matt Gumbeld7b33082012-11-14 10:16:17 -08001171 char str_port[30];
1172 snprintf(str_port, sizeof(str_port), "%d", server_port);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001173 // child process
Matt Gumbeld7b33082012-11-14 10:16:17 -08001174 int result = execl(path, "adb", "-P", str_port, "fork-server", "server", NULL);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001175 // this should not return
1176 fprintf(stderr, "OOPS! execl returned %d, errno: %d\n", result, errno);
1177 } else {
1178 // parent side of the fork
1179
1180 char temp[3];
1181
1182 temp[0] = 'A'; temp[1] = 'B'; temp[2] = 'C';
1183 // wait for the "OK\n" message
1184 adb_close(fd[1]);
1185 int ret = adb_read(fd[0], temp, 3);
JP Abgrall408fa572011-03-16 15:57:42 -07001186 int saved_errno = errno;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001187 adb_close(fd[0]);
1188 if (ret < 0) {
JP Abgrall408fa572011-03-16 15:57:42 -07001189 fprintf(stderr, "could not read ok from ADB Server, errno = %d\n", saved_errno);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001190 return -1;
1191 }
1192 if (ret != 3 || temp[0] != 'O' || temp[1] != 'K' || temp[2] != '\n') {
1193 fprintf(stderr, "ADB server didn't ACK\n" );
1194 return -1;
1195 }
1196
1197 setsid();
1198 }
1199#else
1200#error "cannot implement background server start on this platform"
1201#endif
1202 return 0;
1203}
1204#endif
1205
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001206/* Constructs a local name of form tcp:port.
1207 * target_str points to the target string, it's content will be overwritten.
1208 * target_size is the capacity of the target string.
1209 * server_port is the port number to use for the local name.
1210 */
1211void build_local_name(char* target_str, size_t target_size, int server_port)
1212{
1213 snprintf(target_str, target_size, "tcp:%d", server_port);
1214}
1215
Nick Kralevichbd9206b2012-01-19 10:18:59 -08001216#if !ADB_HOST
Nick Kralevich080427e2013-02-15 14:39:15 -08001217
1218static void drop_capabilities_bounding_set_if_needed() {
1219#ifdef ALLOW_ADBD_ROOT
1220 char value[PROPERTY_VALUE_MAX];
1221 property_get("ro.debuggable", value, "");
1222 if (strcmp(value, "1") == 0) {
1223 return;
1224 }
1225#endif
1226 int i;
1227 for (i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {
Nick Kralevichca8e66a2013-04-18 12:20:02 -07001228 if (i == CAP_SETUID || i == CAP_SETGID) {
Nick Kralevich080427e2013-02-15 14:39:15 -08001229 // CAP_SETUID CAP_SETGID needed by /system/bin/run-as
1230 continue;
1231 }
1232 int err = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
1233
1234 // Some kernels don't have file capabilities compiled in, and
1235 // prctl(PR_CAPBSET_DROP) returns EINVAL. Don't automatically
1236 // die when we see such misconfigured kernels.
1237 if ((err < 0) && (errno != EINVAL)) {
1238 exit(1);
1239 }
1240 }
1241}
1242
Nick Kralevichbd9206b2012-01-19 10:18:59 -08001243static int should_drop_privileges() {
Nick Kralevich5890fe32012-01-19 13:11:35 -08001244#ifndef ALLOW_ADBD_ROOT
1245 return 1;
1246#else /* ALLOW_ADBD_ROOT */
Nick Kralevichbd9206b2012-01-19 10:18:59 -08001247 int secure = 0;
1248 char value[PROPERTY_VALUE_MAX];
1249
1250 /* run adbd in secure mode if ro.secure is set and
1251 ** we are not in the emulator
1252 */
1253 property_get("ro.kernel.qemu", value, "");
1254 if (strcmp(value, "1") != 0) {
1255 property_get("ro.secure", value, "1");
1256 if (strcmp(value, "1") == 0) {
1257 // don't run as root if ro.secure is set...
1258 secure = 1;
1259
1260 // ... except we allow running as root in userdebug builds if the
1261 // service.adb.root property has been set by the "adb root" command
1262 property_get("ro.debuggable", value, "");
1263 if (strcmp(value, "1") == 0) {
1264 property_get("service.adb.root", value, "");
1265 if (strcmp(value, "1") == 0) {
1266 secure = 0;
1267 }
1268 }
1269 }
1270 }
1271 return secure;
Nick Kralevich5890fe32012-01-19 13:11:35 -08001272#endif /* ALLOW_ADBD_ROOT */
Nick Kralevichbd9206b2012-01-19 10:18:59 -08001273}
1274#endif /* !ADB_HOST */
1275
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001276int adb_main(int is_daemon, int server_port)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001277{
1278#if !ADB_HOST
Mike Lockwood2f38b692009-08-24 15:58:40 -07001279 int port;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001280 char value[PROPERTY_VALUE_MAX];
Nick Kralevicheb68fa82012-04-02 13:00:35 -07001281
1282 umask(000);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001283#endif
1284
1285 atexit(adb_cleanup);
1286#ifdef HAVE_WIN32_PROC
1287 SetConsoleCtrlHandler( ctrlc_handler, TRUE );
1288#elif defined(HAVE_FORKEXEC)
JP Abgrall408fa572011-03-16 15:57:42 -07001289 // No SIGCHLD. Let the service subproc handle its children.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001290 signal(SIGPIPE, SIG_IGN);
1291#endif
1292
1293 init_transport_registration();
1294
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001295#if ADB_HOST
1296 HOST = 1;
JP Abgrall571c1362012-12-06 18:18:12 -08001297
1298#ifdef WORKAROUND_BUG6558362
1299 if(is_daemon) adb_set_affinity();
1300#endif
Xavier Ducroheta09fbd12009-05-20 17:33:53 -07001301 usb_vendors_init();
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001302 usb_init();
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001303 local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -07001304 adb_auth_init();
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001305
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001306 char local_name[30];
1307 build_local_name(local_name, sizeof(local_name), server_port);
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001308 if(install_listener(local_name, "*smartsocket*", NULL, 0)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001309 exit(1);
1310 }
1311#else
Benoit Gobyd5fcafa2012-04-12 12:23:49 -07001312 property_get("ro.adb.secure", value, "0");
1313 auth_enabled = !strcmp(value, "1");
1314 if (auth_enabled)
1315 adb_auth_init();
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001316
Jeff Sharkeyd6d42862012-09-06 13:05:40 -07001317 // Our external storage path may be different than apps, since
1318 // we aren't able to bind mount after dropping root.
1319 const char* adb_external_storage = getenv("ADB_EXTERNAL_STORAGE");
1320 if (NULL != adb_external_storage) {
1321 setenv("EXTERNAL_STORAGE", adb_external_storage, 1);
1322 } else {
1323 D("Warning: ADB_EXTERNAL_STORAGE is not set. Leaving EXTERNAL_STORAGE"
1324 " unchanged.\n");
1325 }
1326
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001327 /* don't listen on a port (default 5037) if running in secure mode */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001328 /* don't run as root if we are running in secure mode */
Nick Kralevichbd9206b2012-01-19 10:18:59 -08001329 if (should_drop_privileges()) {
Nick Kralevich080427e2013-02-15 14:39:15 -08001330 drop_capabilities_bounding_set_if_needed();
1331
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001332 /* add extra groups:
1333 ** AID_ADB to access the USB driver
1334 ** AID_LOG to read system logs (adb logcat)
1335 ** AID_INPUT to diagnose input issues (getevent)
1336 ** AID_INET to diagnose network issues (netcfg, ping)
1337 ** AID_GRAPHICS to access the frame buffer
The Android Open Source Project20155492009-03-11 12:12:01 -07001338 ** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump)
Dianne Hackborn50458cf2012-03-07 12:57:14 -08001339 ** AID_SDCARD_R to allow reading from the SD card
Mike Lockwood6a3075c2009-05-25 13:52:00 -04001340 ** AID_SDCARD_RW to allow writing to the SD card
Mike Lockwoodd969faa2010-02-24 16:07:23 -05001341 ** AID_MOUNT to allow unmounting the SD card before rebooting
JP Abgrall61b90bd2011-11-09 10:30:08 -08001342 ** AID_NET_BW_STATS to read out qtaguid statistics
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001343 */
The Android Open Source Project20155492009-03-11 12:12:01 -07001344 gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_GRAPHICS,
Dianne Hackborn50458cf2012-03-07 12:57:14 -08001345 AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_R, AID_SDCARD_RW,
1346 AID_MOUNT, AID_NET_BW_STATS };
Nick Kralevich44db9902010-08-27 14:35:07 -07001347 if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
1348 exit(1);
1349 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001350
1351 /* then switch user and group to "shell" */
Nick Kralevich44db9902010-08-27 14:35:07 -07001352 if (setgid(AID_SHELL) != 0) {
1353 exit(1);
1354 }
1355 if (setuid(AID_SHELL) != 0) {
1356 exit(1);
1357 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001358
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001359 D("Local port disabled\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001360 } else {
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001361 char local_name[30];
Nick Kralevichd49aa252014-01-18 09:25:04 -08001362 if ((root_seclabel != NULL) && (is_selinux_enabled() > 0)) {
1363 // b/12587913: fix setcon to allow const pointers
1364 if (setcon((char *)root_seclabel) < 0) {
1365 exit(1);
1366 }
1367 }
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001368 build_local_name(local_name, sizeof(local_name), server_port);
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001369 if(install_listener(local_name, "*smartsocket*", NULL, 0)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001370 exit(1);
1371 }
1372 }
1373
Mike J. Chen1dd55c52012-07-20 18:16:21 -07001374 int usb = 0;
1375 if (access(USB_ADB_PATH, F_OK) == 0 || access(USB_FFS_ADB_EP0, F_OK) == 0) {
Mike Lockwoodcef31a02009-08-26 12:50:22 -07001376 // listen on USB
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001377 usb_init();
Mike J. Chen1dd55c52012-07-20 18:16:21 -07001378 usb = 1;
1379 }
1380
1381 // If one of these properties is set, also listen on that port
1382 // If one of the properties isn't set and we couldn't listen on usb,
1383 // listen on the default port.
1384 property_get("service.adb.tcp.port", value, "");
1385 if (!value[0]) {
1386 property_get("persist.adb.tcp.port", value, "");
1387 }
1388 if (sscanf(value, "%d", &port) == 1 && port > 0) {
1389 printf("using port=%d\n", port);
1390 // listen on TCP port specified by service.adb.tcp.port property
1391 local_init(port);
1392 } else if (!usb) {
Mike Lockwoodcef31a02009-08-26 12:50:22 -07001393 // listen on default port
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001394 local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001395 }
Mike J. Chen1dd55c52012-07-20 18:16:21 -07001396
JP Abgrall408fa572011-03-16 15:57:42 -07001397 D("adb_main(): pre init_jdwp()\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001398 init_jdwp();
JP Abgrall408fa572011-03-16 15:57:42 -07001399 D("adb_main(): post init_jdwp()\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001400#endif
1401
1402 if (is_daemon)
1403 {
1404 // inform our parent that we are up and running.
1405#ifdef HAVE_WIN32_PROC
1406 DWORD count;
1407 WriteFile( GetStdHandle( STD_OUTPUT_HANDLE ), "OK\n", 3, &count, NULL );
1408#elif defined(HAVE_FORKEXEC)
1409 fprintf(stderr, "OK\n");
1410#endif
1411 start_logging();
1412 }
JP Abgrall408fa572011-03-16 15:57:42 -07001413 D("Event loop starting\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001414
1415 fdevent_loop();
1416
1417 usb_cleanup();
1418
1419 return 0;
1420}
1421
1422int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s)
1423{
1424 atransport *transport = NULL;
1425 char buf[4096];
1426
1427 if(!strcmp(service, "kill")) {
1428 fprintf(stderr,"adb server killed by remote request\n");
1429 fflush(stdout);
1430 adb_write(reply_fd, "OKAY", 4);
1431 usb_cleanup();
1432 exit(0);
1433 }
1434
1435#if ADB_HOST
1436 // "transport:" is used for switching transport with a specified serial number
1437 // "transport-usb:" is used for switching transport to the only USB transport
1438 // "transport-local:" is used for switching transport to the only local transport
1439 // "transport-any:" is used for switching transport to the only transport
1440 if (!strncmp(service, "transport", strlen("transport"))) {
1441 char* error_string = "unknown failure";
1442 transport_type type = kTransportAny;
1443
1444 if (!strncmp(service, "transport-usb", strlen("transport-usb"))) {
1445 type = kTransportUsb;
1446 } else if (!strncmp(service, "transport-local", strlen("transport-local"))) {
1447 type = kTransportLocal;
1448 } else if (!strncmp(service, "transport-any", strlen("transport-any"))) {
1449 type = kTransportAny;
1450 } else if (!strncmp(service, "transport:", strlen("transport:"))) {
1451 service += strlen("transport:");
Tom Marlin3175c8e2011-07-27 12:56:14 -05001452 serial = service;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001453 }
1454
1455 transport = acquire_one_transport(CS_ANY, type, serial, &error_string);
1456
1457 if (transport) {
1458 s->transport = transport;
1459 adb_write(reply_fd, "OKAY", 4);
1460 } else {
1461 sendfailmsg(reply_fd, error_string);
1462 }
1463 return 1;
1464 }
1465
1466 // return a list of all connected devices
Scott Andersone109d262012-04-20 11:21:14 -07001467 if (!strncmp(service, "devices", 7)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001468 char buffer[4096];
Scott Andersone109d262012-04-20 11:21:14 -07001469 int use_long = !strcmp(service+7, "-l");
1470 if (use_long || service[7] == 0) {
1471 memset(buf, 0, sizeof(buf));
1472 memset(buffer, 0, sizeof(buffer));
1473 D("Getting device list \n");
1474 list_transports(buffer, sizeof(buffer), use_long);
1475 snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer),buffer);
1476 D("Wrote device list \n");
1477 writex(reply_fd, buf, strlen(buf));
1478 return 0;
1479 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001480 }
1481
Mike Lockwood74d7ff82009-10-11 23:04:18 -04001482 // remove TCP transport
1483 if (!strncmp(service, "disconnect:", 11)) {
1484 char buffer[4096];
1485 memset(buffer, 0, sizeof(buffer));
1486 char* serial = service + 11;
Mike Lockwoodcbbe79a2010-05-24 10:44:35 -04001487 if (serial[0] == 0) {
1488 // disconnect from all TCP devices
1489 unregister_all_tcp_transports();
Mike Lockwood74d7ff82009-10-11 23:04:18 -04001490 } else {
Mike Lockwoodcbbe79a2010-05-24 10:44:35 -04001491 char hostbuf[100];
1492 // assume port 5555 if no port is specified
1493 if (!strchr(serial, ':')) {
1494 snprintf(hostbuf, sizeof(hostbuf) - 1, "%s:5555", serial);
1495 serial = hostbuf;
1496 }
1497 atransport *t = find_transport(serial);
1498
1499 if (t) {
1500 unregister_transport(t);
1501 } else {
1502 snprintf(buffer, sizeof(buffer), "No such device %s", serial);
1503 }
Mike Lockwood74d7ff82009-10-11 23:04:18 -04001504 }
1505
1506 snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer), buffer);
Mike Lockwood2f38b692009-08-24 15:58:40 -07001507 writex(reply_fd, buf, strlen(buf));
1508 return 0;
1509 }
1510
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001511 // returns our value for ADB_SERVER_VERSION
1512 if (!strcmp(service, "version")) {
1513 char version[12];
1514 snprintf(version, sizeof version, "%04x", ADB_SERVER_VERSION);
1515 snprintf(buf, sizeof buf, "OKAY%04x%s", (unsigned)strlen(version), version);
1516 writex(reply_fd, buf, strlen(buf));
1517 return 0;
1518 }
1519
1520 if(!strncmp(service,"get-serialno",strlen("get-serialno"))) {
1521 char *out = "unknown";
1522 transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
1523 if (transport && transport->serial) {
1524 out = transport->serial;
1525 }
1526 snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(out),out);
1527 writex(reply_fd, buf, strlen(buf));
1528 return 0;
1529 }
Scott Andersone109d262012-04-20 11:21:14 -07001530 if(!strncmp(service,"get-devpath",strlen("get-devpath"))) {
1531 char *out = "unknown";
1532 transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
1533 if (transport && transport->devpath) {
1534 out = transport->devpath;
1535 }
1536 snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(out),out);
1537 writex(reply_fd, buf, strlen(buf));
1538 return 0;
1539 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001540 // indicates a new emulator instance has started
1541 if (!strncmp(service,"emulator:",9)) {
1542 int port = atoi(service+9);
1543 local_connect(port);
1544 /* we don't even need to send a reply */
1545 return 0;
1546 }
1547#endif // ADB_HOST
1548
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001549 if(!strcmp(service,"list-forward")) {
1550 // Create the list of forward redirections.
1551 char header[9];
1552 int buffer_size = format_listeners(NULL, 0);
1553 // Add one byte for the trailing zero.
1554 char* buffer = malloc(buffer_size+1);
1555 (void) format_listeners(buffer, buffer_size+1);
1556 snprintf(header, sizeof header, "OKAY%04x", buffer_size);
1557 writex(reply_fd, header, 8);
1558 writex(reply_fd, buffer, buffer_size);
1559 free(buffer);
1560 return 0;
1561 }
1562
1563 if (!strcmp(service,"killforward-all")) {
1564 remove_all_listeners();
1565 adb_write(reply_fd, "OKAYOKAY", 8);
1566 return 0;
1567 }
1568
1569 if(!strncmp(service,"forward:",8) ||
1570 !strncmp(service,"killforward:",12)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001571 char *local, *remote, *err;
1572 int r;
1573 atransport *transport;
1574
1575 int createForward = strncmp(service,"kill",4);
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001576 int no_rebind = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001577
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001578 local = strchr(service, ':') + 1;
1579
1580 // Handle forward:norebind:<local>... here
1581 if (createForward && !strncmp(local, "norebind:", 9)) {
1582 no_rebind = 1;
1583 local = strchr(local, ':') + 1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001584 }
1585
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001586 remote = strchr(local,';');
1587
1588 if (createForward) {
1589 // Check forward: parameter format: '<local>;<remote>'
1590 if(remote == 0) {
1591 sendfailmsg(reply_fd, "malformed forward spec");
1592 return 0;
1593 }
1594
1595 *remote++ = 0;
1596 if((local[0] == 0) || (remote[0] == 0) || (remote[0] == '*')){
1597 sendfailmsg(reply_fd, "malformed forward spec");
1598 return 0;
1599 }
1600 } else {
1601 // Check killforward: parameter format: '<local>'
1602 if (local[0] == 0) {
1603 sendfailmsg(reply_fd, "malformed forward spec");
1604 return 0;
1605 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001606 }
1607
1608 transport = acquire_one_transport(CS_ANY, ttype, serial, &err);
1609 if (!transport) {
1610 sendfailmsg(reply_fd, err);
1611 return 0;
1612 }
1613
1614 if (createForward) {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001615 r = install_listener(local, remote, transport, no_rebind);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001616 } else {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001617 r = remove_listener(local, transport);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001618 }
1619 if(r == 0) {
1620 /* 1st OKAY is connect, 2nd OKAY is status */
1621 writex(reply_fd, "OKAYOKAY", 8);
1622 return 0;
1623 }
1624
1625 if (createForward) {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001626 const char* message;
1627 switch (r) {
1628 case INSTALL_STATUS_CANNOT_BIND:
1629 message = "cannot bind to socket";
1630 break;
1631 case INSTALL_STATUS_CANNOT_REBIND:
1632 message = "cannot rebind existing socket";
1633 break;
1634 default:
1635 message = "internal error";
1636 }
1637 sendfailmsg(reply_fd, message);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001638 } else {
1639 sendfailmsg(reply_fd, "cannot remove listener");
1640 }
1641 return 0;
1642 }
1643
1644 if(!strncmp(service,"get-state",strlen("get-state"))) {
1645 transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
1646 char *state = connection_state_name(transport);
1647 snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(state),state);
1648 writex(reply_fd, buf, strlen(buf));
1649 return 0;
1650 }
1651 return -1;
1652}
1653
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001654int main(int argc, char **argv)
1655{
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001656#if ADB_HOST
1657 adb_sysdeps_init();
JP Abgrall408fa572011-03-16 15:57:42 -07001658 adb_trace_init();
1659 D("Handling commandline()\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001660 return adb_commandline(argc - 1, argv + 1);
1661#else
Vladimir Chtchetkine28781b02012-02-27 10:41:53 -08001662 /* If adbd runs inside the emulator this will enable adb tracing via
1663 * adb-debug qemud service in the emulator. */
1664 adb_qemu_trace_init();
Nick Kralevichd49aa252014-01-18 09:25:04 -08001665 while(1) {
1666 int c;
1667 int option_index = 0;
1668 static struct option opts[] = {
1669 {"root_seclabel", required_argument, 0, 's' },
1670 {"device_banner", required_argument, 0, 'b' }
1671 };
1672 c = getopt_long(argc, argv, "", opts, &option_index);
1673 if (c == -1)
1674 break;
1675 switch (c) {
1676 case 's':
1677 root_seclabel = optarg;
1678 break;
1679 case 'b':
1680 adb_device_banner = optarg;
1681 break;
1682 default:
1683 break;
1684 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001685 }
Mike Lockwood1f546e62009-05-25 18:17:55 -04001686
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001687 start_device_log();
JP Abgrall408fa572011-03-16 15:57:42 -07001688 D("Handling main()\n");
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001689 return adb_main(0, DEFAULT_ADB_PORT);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001690#endif
1691}