blob: 8be5765676be345b2b0470bb13ac8ed0412a4967 [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>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080028
29#include "sysdeps.h"
30#include "adb.h"
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070031#include "adb_auth.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080032
Scott Andersone82c2db2012-05-25 14:10:02 -070033#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
34
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080035#if !ADB_HOST
36#include <private/android_filesystem_config.h>
Mike Lockwood5f4b0512009-08-04 20:37:51 -040037#include <linux/capability.h>
38#include <linux/prctl.h>
Jeff Sharkey885342a2012-08-14 21:00:22 -070039#include <sys/mount.h>
Xavier Ducroheta09fbd12009-05-20 17:33:53 -070040#else
41#include "usb_vendors.h"
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080042#endif
43
JP Abgrall408fa572011-03-16 15:57:42 -070044#if ADB_TRACE
45ADB_MUTEX_DEFINE( D_lock );
46#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080047
48int HOST = 0;
Matt Gumbeld7b33082012-11-14 10:16:17 -080049int gListenAll = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080050
Benoit Gobyd5fcafa2012-04-12 12:23:49 -070051static int auth_enabled = 0;
52
Scott Andersone82c2db2012-05-25 14:10:02 -070053#if !ADB_HOST
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080054static const char *adb_device_banner = "device";
Scott Andersone82c2db2012-05-25 14:10:02 -070055#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080056
57void fatal(const char *fmt, ...)
58{
59 va_list ap;
60 va_start(ap, fmt);
61 fprintf(stderr, "error: ");
62 vfprintf(stderr, fmt, ap);
63 fprintf(stderr, "\n");
64 va_end(ap);
65 exit(-1);
66}
67
68void fatal_errno(const char *fmt, ...)
69{
70 va_list ap;
71 va_start(ap, fmt);
72 fprintf(stderr, "error: %s: ", strerror(errno));
73 vfprintf(stderr, fmt, ap);
74 fprintf(stderr, "\n");
75 va_end(ap);
76 exit(-1);
77}
78
79int adb_trace_mask;
80
81/* read a comma/space/colum/semi-column separated list of tags
82 * from the ADB_TRACE environment variable and build the trace
83 * mask from it. note that '1' and 'all' are special cases to
84 * enable all tracing
85 */
86void adb_trace_init(void)
87{
88 const char* p = getenv("ADB_TRACE");
89 const char* q;
90
91 static const struct {
92 const char* tag;
93 int flag;
94 } tags[] = {
95 { "1", 0 },
96 { "all", 0 },
97 { "adb", TRACE_ADB },
98 { "sockets", TRACE_SOCKETS },
99 { "packets", TRACE_PACKETS },
100 { "rwx", TRACE_RWX },
101 { "usb", TRACE_USB },
102 { "sync", TRACE_SYNC },
103 { "sysdeps", TRACE_SYSDEPS },
104 { "transport", TRACE_TRANSPORT },
105 { "jdwp", TRACE_JDWP },
JP Abgrall408fa572011-03-16 15:57:42 -0700106 { "services", TRACE_SERVICES },
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700107 { "auth", TRACE_AUTH },
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800108 { NULL, 0 }
109 };
110
111 if (p == NULL)
112 return;
113
114 /* use a comma/column/semi-colum/space separated list */
115 while (*p) {
116 int len, tagn;
117
118 q = strpbrk(p, " ,:;");
119 if (q == NULL) {
120 q = p + strlen(p);
121 }
122 len = q - p;
123
124 for (tagn = 0; tags[tagn].tag != NULL; tagn++)
125 {
126 int taglen = strlen(tags[tagn].tag);
127
128 if (len == taglen && !memcmp(tags[tagn].tag, p, len) )
129 {
130 int flag = tags[tagn].flag;
131 if (flag == 0) {
132 adb_trace_mask = ~0;
133 return;
134 }
135 adb_trace_mask |= (1 << flag);
136 break;
137 }
138 }
139 p = q;
140 if (*p)
141 p++;
142 }
143}
144
Vladimir Chtchetkine28781b02012-02-27 10:41:53 -0800145#if !ADB_HOST
146/*
147 * Implements ADB tracing inside the emulator.
148 */
149
150#include <stdarg.h>
151
152/*
153 * Redefine open and write for qemu_pipe.h that contains inlined references
154 * to those routines. We will redifine them back after qemu_pipe.h inclusion.
155 */
156
157#undef open
158#undef write
159#define open adb_open
160#define write adb_write
161#include <hardware/qemu_pipe.h>
162#undef open
163#undef write
164#define open ___xxx_open
165#define write ___xxx_write
166
167/* A handle to adb-debug qemud service in the emulator. */
168int adb_debug_qemu = -1;
169
170/* Initializes connection with the adb-debug qemud service in the emulator. */
171static int adb_qemu_trace_init(void)
172{
173 char con_name[32];
174
175 if (adb_debug_qemu >= 0) {
176 return 0;
177 }
178
179 /* adb debugging QEMUD service connection request. */
180 snprintf(con_name, sizeof(con_name), "qemud:adb-debug");
181 adb_debug_qemu = qemu_pipe_open(con_name);
182 return (adb_debug_qemu >= 0) ? 0 : -1;
183}
184
185void adb_qemu_trace(const char* fmt, ...)
186{
187 va_list args;
188 va_start(args, fmt);
189 char msg[1024];
190
191 if (adb_debug_qemu >= 0) {
192 vsnprintf(msg, sizeof(msg), fmt, args);
193 adb_write(adb_debug_qemu, msg, strlen(msg));
194 }
195}
196#endif /* !ADB_HOST */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800197
198apacket *get_apacket(void)
199{
200 apacket *p = malloc(sizeof(apacket));
201 if(p == 0) fatal("failed to allocate an apacket");
202 memset(p, 0, sizeof(apacket) - MAX_PAYLOAD);
203 return p;
204}
205
206void put_apacket(apacket *p)
207{
208 free(p);
209}
210
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700211void handle_online(atransport *t)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800212{
213 D("adb: online\n");
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700214 t->online = 1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800215}
216
217void handle_offline(atransport *t)
218{
219 D("adb: offline\n");
220 //Close the associated usb
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700221 t->online = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800222 run_transport_disconnects(t);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800223}
224
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700225#if DEBUG_PACKETS
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800226#define DUMPMAX 32
227void print_packet(const char *label, apacket *p)
228{
229 char *tag;
230 char *x;
231 unsigned count;
232
233 switch(p->msg.command){
234 case A_SYNC: tag = "SYNC"; break;
235 case A_CNXN: tag = "CNXN" ; break;
236 case A_OPEN: tag = "OPEN"; break;
237 case A_OKAY: tag = "OKAY"; break;
238 case A_CLSE: tag = "CLSE"; break;
239 case A_WRTE: tag = "WRTE"; break;
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700240 case A_AUTH: tag = "AUTH"; break;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800241 default: tag = "????"; break;
242 }
243
244 fprintf(stderr, "%s: %s %08x %08x %04x \"",
245 label, tag, p->msg.arg0, p->msg.arg1, p->msg.data_length);
246 count = p->msg.data_length;
247 x = (char*) p->data;
248 if(count > DUMPMAX) {
249 count = DUMPMAX;
250 tag = "\n";
251 } else {
252 tag = "\"\n";
253 }
254 while(count-- > 0){
255 if((*x >= ' ') && (*x < 127)) {
256 fputc(*x, stderr);
257 } else {
258 fputc('.', stderr);
259 }
260 x++;
261 }
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700262 fputs(tag, stderr);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800263}
264#endif
265
266static void send_ready(unsigned local, unsigned remote, atransport *t)
267{
268 D("Calling send_ready \n");
269 apacket *p = get_apacket();
270 p->msg.command = A_OKAY;
271 p->msg.arg0 = local;
272 p->msg.arg1 = remote;
273 send_packet(p, t);
274}
275
276static void send_close(unsigned local, unsigned remote, atransport *t)
277{
278 D("Calling send_close \n");
279 apacket *p = get_apacket();
280 p->msg.command = A_CLSE;
281 p->msg.arg0 = local;
282 p->msg.arg1 = remote;
283 send_packet(p, t);
284}
285
Scott Andersone82c2db2012-05-25 14:10:02 -0700286static size_t fill_connect_data(char *buf, size_t bufsize)
287{
288#if ADB_HOST
289 return snprintf(buf, bufsize, "host::") + 1;
290#else
291 static const char *cnxn_props[] = {
292 "ro.product.name",
293 "ro.product.model",
294 "ro.product.device",
295 };
296 static const int num_cnxn_props = ARRAY_SIZE(cnxn_props);
297 int i;
298 size_t remaining = bufsize;
299 size_t len;
300
301 len = snprintf(buf, remaining, "%s::", adb_device_banner);
302 remaining -= len;
303 buf += len;
304 for (i = 0; i < num_cnxn_props; i++) {
305 char value[PROPERTY_VALUE_MAX];
306 property_get(cnxn_props[i], value, "");
307 len = snprintf(buf, remaining, "%s=%s;", cnxn_props[i], value);
308 remaining -= len;
309 buf += len;
310 }
311
312 return bufsize - remaining + 1;
313#endif
314}
315
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800316static void send_connect(atransport *t)
317{
318 D("Calling send_connect \n");
319 apacket *cp = get_apacket();
320 cp->msg.command = A_CNXN;
321 cp->msg.arg0 = A_VERSION;
322 cp->msg.arg1 = MAX_PAYLOAD;
Scott Andersone82c2db2012-05-25 14:10:02 -0700323 cp->msg.data_length = fill_connect_data((char *)cp->data,
324 sizeof(cp->data));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800325 send_packet(cp, t);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700326}
327
328static void send_auth_request(atransport *t)
329{
330 D("Calling send_auth_request\n");
331 apacket *p;
332 int ret;
333
334 ret = adb_auth_generate_token(t->token, sizeof(t->token));
335 if (ret != sizeof(t->token)) {
336 D("Error generating token ret=%d\n", ret);
337 return;
338 }
339
340 p = get_apacket();
341 memcpy(p->data, t->token, ret);
342 p->msg.command = A_AUTH;
343 p->msg.arg0 = ADB_AUTH_TOKEN;
344 p->msg.data_length = ret;
345 send_packet(p, t);
346}
347
348static void send_auth_response(uint8_t *token, size_t token_size, atransport *t)
349{
350 D("Calling send_auth_response\n");
351 apacket *p = get_apacket();
352 int ret;
353
354 ret = adb_auth_sign(t->key, token, token_size, p->data);
355 if (!ret) {
356 D("Error signing the token\n");
357 put_apacket(p);
358 return;
359 }
360
361 p->msg.command = A_AUTH;
362 p->msg.arg0 = ADB_AUTH_SIGNATURE;
363 p->msg.data_length = ret;
364 send_packet(p, t);
365}
366
367static void send_auth_publickey(atransport *t)
368{
369 D("Calling send_auth_publickey\n");
370 apacket *p = get_apacket();
371 int ret;
372
373 ret = adb_auth_get_userkey(p->data, sizeof(p->data));
374 if (!ret) {
375 D("Failed to get user public key\n");
376 put_apacket(p);
377 return;
378 }
379
380 p->msg.command = A_AUTH;
381 p->msg.arg0 = ADB_AUTH_RSAPUBLICKEY;
382 p->msg.data_length = ret;
383 send_packet(p, t);
384}
385
386void adb_auth_verified(atransport *t)
387{
388 handle_online(t);
389 send_connect(t);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800390}
391
392static char *connection_state_name(atransport *t)
393{
394 if (t == NULL) {
395 return "unknown";
396 }
397
398 switch(t->connection_state) {
399 case CS_BOOTLOADER:
400 return "bootloader";
401 case CS_DEVICE:
402 return "device";
403 case CS_OFFLINE:
404 return "offline";
405 default:
406 return "unknown";
407 }
408}
409
Scott Andersone82c2db2012-05-25 14:10:02 -0700410/* qual_overwrite is used to overwrite a qualifier string. dst is a
411 * pointer to a char pointer. It is assumed that if *dst is non-NULL, it
Scott Anderson2ca3e6b2012-05-30 18:11:27 -0700412 * was malloc'ed and needs to freed. *dst will be set to a dup of src.
Scott Andersone82c2db2012-05-25 14:10:02 -0700413 */
414static void qual_overwrite(char **dst, const char *src)
415{
416 if (!dst)
417 return;
418
419 free(*dst);
420 *dst = NULL;
421
422 if (!src || !*src)
423 return;
424
425 *dst = strdup(src);
426}
427
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800428void parse_banner(char *banner, atransport *t)
429{
Scott Andersone82c2db2012-05-25 14:10:02 -0700430 static const char *prop_seps = ";";
431 static const char key_val_sep = '=';
Scott Anderson2ca3e6b2012-05-30 18:11:27 -0700432 char *cp;
433 char *type;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800434
435 D("parse_banner: %s\n", banner);
436 type = banner;
Scott Andersone82c2db2012-05-25 14:10:02 -0700437 cp = strchr(type, ':');
438 if (cp) {
439 *cp++ = 0;
440 /* Nothing is done with second field. */
441 cp = strchr(cp, ':');
442 if (cp) {
443 char *save;
444 char *key;
Scott Anderson1b7a7e82012-06-05 17:54:27 -0700445 key = adb_strtok_r(cp + 1, prop_seps, &save);
Scott Andersone82c2db2012-05-25 14:10:02 -0700446 while (key) {
447 cp = strchr(key, key_val_sep);
448 if (cp) {
449 *cp++ = '\0';
450 if (!strcmp(key, "ro.product.name"))
451 qual_overwrite(&t->product, cp);
452 else if (!strcmp(key, "ro.product.model"))
453 qual_overwrite(&t->model, cp);
454 else if (!strcmp(key, "ro.product.device"))
455 qual_overwrite(&t->device, cp);
456 }
Scott Anderson1b7a7e82012-06-05 17:54:27 -0700457 key = adb_strtok_r(NULL, prop_seps, &save);
Scott Andersone82c2db2012-05-25 14:10:02 -0700458 }
459 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800460 }
461
462 if(!strcmp(type, "bootloader")){
463 D("setting connection_state to CS_BOOTLOADER\n");
464 t->connection_state = CS_BOOTLOADER;
465 update_transports();
466 return;
467 }
468
469 if(!strcmp(type, "device")) {
470 D("setting connection_state to CS_DEVICE\n");
471 t->connection_state = CS_DEVICE;
472 update_transports();
473 return;
474 }
475
476 if(!strcmp(type, "recovery")) {
477 D("setting connection_state to CS_RECOVERY\n");
478 t->connection_state = CS_RECOVERY;
479 update_transports();
480 return;
481 }
482
Doug Zongker447f0612012-01-09 14:54:53 -0800483 if(!strcmp(type, "sideload")) {
484 D("setting connection_state to CS_SIDELOAD\n");
485 t->connection_state = CS_SIDELOAD;
486 update_transports();
487 return;
488 }
489
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800490 t->connection_state = CS_HOST;
491}
492
493void handle_packet(apacket *p, atransport *t)
494{
495 asocket *s;
496
Viral Mehta899913f2010-06-16 18:41:28 +0530497 D("handle_packet() %c%c%c%c\n", ((char*) (&(p->msg.command)))[0],
498 ((char*) (&(p->msg.command)))[1],
499 ((char*) (&(p->msg.command)))[2],
500 ((char*) (&(p->msg.command)))[3]);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800501 print_packet("recv", p);
502
503 switch(p->msg.command){
504 case A_SYNC:
505 if(p->msg.arg0){
506 send_packet(p, t);
507 if(HOST) send_connect(t);
508 } else {
509 t->connection_state = CS_OFFLINE;
510 handle_offline(t);
511 send_packet(p, t);
512 }
513 return;
514
515 case A_CNXN: /* CONNECT(version, maxdata, "system-id-string") */
516 /* XXX verify version, etc */
517 if(t->connection_state != CS_OFFLINE) {
518 t->connection_state = CS_OFFLINE;
519 handle_offline(t);
520 }
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700521
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800522 parse_banner((char*) p->data, t);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700523
524 if (HOST || !auth_enabled) {
525 handle_online(t);
526 if(!HOST) send_connect(t);
527 } else {
528 send_auth_request(t);
529 }
530 break;
531
532 case A_AUTH:
533 if (p->msg.arg0 == ADB_AUTH_TOKEN) {
534 t->key = adb_auth_nextkey(t->key);
535 if (t->key) {
536 send_auth_response(p->data, p->msg.data_length, t);
537 } else {
538 /* No more private keys to try, send the public key */
539 send_auth_publickey(t);
540 }
541 } else if (p->msg.arg0 == ADB_AUTH_SIGNATURE) {
542 if (adb_auth_verify(t->token, p->data, p->msg.data_length)) {
543 adb_auth_verified(t);
544 t->failed_auth_attempts = 0;
545 } else {
546 if (t->failed_auth_attempts++ > 10)
547 adb_sleep_ms(1000);
548 send_auth_request(t);
549 }
550 } else if (p->msg.arg0 == ADB_AUTH_RSAPUBLICKEY) {
551 adb_auth_confirm_key(p->data, p->msg.data_length, t);
552 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800553 break;
554
555 case A_OPEN: /* OPEN(local-id, 0, "destination") */
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700556 if (t->online) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800557 char *name = (char*) p->data;
558 name[p->msg.data_length > 0 ? p->msg.data_length - 1 : 0] = 0;
559 s = create_local_service_socket(name);
560 if(s == 0) {
561 send_close(0, p->msg.arg0, t);
562 } else {
563 s->peer = create_remote_socket(p->msg.arg0, t);
564 s->peer->peer = s;
565 send_ready(s->id, s->peer->id, t);
566 s->ready(s);
567 }
568 }
569 break;
570
571 case A_OKAY: /* READY(local-id, remote-id, "") */
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700572 if (t->online) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800573 if((s = find_local_socket(p->msg.arg1))) {
574 if(s->peer == 0) {
575 s->peer = create_remote_socket(p->msg.arg0, t);
576 s->peer->peer = s;
577 }
578 s->ready(s);
579 }
580 }
581 break;
582
583 case A_CLSE: /* CLOSE(local-id, remote-id, "") */
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700584 if (t->online) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800585 if((s = find_local_socket(p->msg.arg1))) {
586 s->close(s);
587 }
588 }
589 break;
590
591 case A_WRTE:
Benoit Gobyd5fcafa2012-04-12 12:23:49 -0700592 if (t->online) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800593 if((s = find_local_socket(p->msg.arg1))) {
594 unsigned rid = p->msg.arg0;
595 p->len = p->msg.data_length;
596
597 if(s->enqueue(s, p) == 0) {
598 D("Enqueue the socket\n");
599 send_ready(s->id, rid, t);
600 }
601 return;
602 }
603 }
604 break;
605
606 default:
607 printf("handle_packet: what is %08x?!\n", p->msg.command);
608 }
609
610 put_apacket(p);
611}
612
613alistener listener_list = {
614 .next = &listener_list,
615 .prev = &listener_list,
616};
617
618static void ss_listener_event_func(int _fd, unsigned ev, void *_l)
619{
620 asocket *s;
621
622 if(ev & FDE_READ) {
623 struct sockaddr addr;
624 socklen_t alen;
625 int fd;
626
627 alen = sizeof(addr);
628 fd = adb_socket_accept(_fd, &addr, &alen);
629 if(fd < 0) return;
630
631 adb_socket_setbufsize(fd, CHUNK_SIZE);
632
633 s = create_local_socket(fd);
634 if(s) {
635 connect_to_smartsocket(s);
636 return;
637 }
638
639 adb_close(fd);
640 }
641}
642
643static void listener_event_func(int _fd, unsigned ev, void *_l)
644{
645 alistener *l = _l;
646 asocket *s;
647
648 if(ev & FDE_READ) {
649 struct sockaddr addr;
650 socklen_t alen;
651 int fd;
652
653 alen = sizeof(addr);
654 fd = adb_socket_accept(_fd, &addr, &alen);
655 if(fd < 0) return;
656
657 s = create_local_socket(fd);
658 if(s) {
659 s->transport = l->transport;
660 connect_to_remote(s, l->connect_to);
661 return;
662 }
663
664 adb_close(fd);
665 }
666}
667
668static void free_listener(alistener* l)
669{
670 if (l->next) {
671 l->next->prev = l->prev;
672 l->prev->next = l->next;
673 l->next = l->prev = l;
674 }
675
676 // closes the corresponding fd
677 fdevent_remove(&l->fde);
678
679 if (l->local_name)
680 free((char*)l->local_name);
681
682 if (l->connect_to)
683 free((char*)l->connect_to);
684
685 if (l->transport) {
686 remove_transport_disconnect(l->transport, &l->disconnect);
687 }
688 free(l);
689}
690
691static void listener_disconnect(void* _l, atransport* t)
692{
693 alistener* l = _l;
694
695 free_listener(l);
696}
697
698int local_name_to_fd(const char *name)
699{
700 int port;
701
702 if(!strncmp("tcp:", name, 4)){
703 int ret;
704 port = atoi(name + 4);
Matt Gumbeld7b33082012-11-14 10:16:17 -0800705
706 if (gListenAll > 0) {
707 ret = socket_inaddr_any_server(port, SOCK_STREAM);
708 } else {
709 ret = socket_loopback_server(port, SOCK_STREAM);
710 }
711
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800712 return ret;
713 }
714#ifndef HAVE_WIN32_IPC /* no Unix-domain sockets on Win32 */
715 // It's non-sensical to support the "reserved" space on the adb host side
716 if(!strncmp(name, "local:", 6)) {
717 return socket_local_server(name + 6,
718 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
719 } else if(!strncmp(name, "localabstract:", 14)) {
720 return socket_local_server(name + 14,
721 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
722 } else if(!strncmp(name, "localfilesystem:", 16)) {
723 return socket_local_server(name + 16,
724 ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM);
725 }
726
727#endif
728 printf("unknown local portname '%s'\n", name);
729 return -1;
730}
731
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100732// Write a single line describing a listener to a user-provided buffer.
733// Appends a trailing zero, even in case of truncation, but the function
734// returns the full line length.
735// If |buffer| is NULL, does not write but returns required size.
736static int format_listener(alistener* l, char* buffer, size_t buffer_len) {
737 // Format is simply:
738 //
739 // <device-serial> " " <local-name> " " <remote-name> "\n"
740 //
741 int local_len = strlen(l->local_name);
742 int connect_len = strlen(l->connect_to);
743 int serial_len = strlen(l->transport->serial);
744
745 if (buffer != NULL) {
746 snprintf(buffer, buffer_len, "%s %s %s\n",
747 l->transport->serial, l->local_name, l->connect_to);
748 }
749 // NOTE: snprintf() on Windows returns -1 in case of truncation, so
750 // return the computed line length instead.
751 return local_len + connect_len + serial_len + 3;
752}
753
754// Write the list of current listeners (network redirections) into a
755// user-provided buffer. Appends a trailing zero, even in case of
756// trunctaion, but return the full size in bytes.
757// If |buffer| is NULL, does not write but returns required size.
758static int format_listeners(char* buf, size_t buflen)
759{
760 alistener* l;
761 int result = 0;
762 for (l = listener_list.next; l != &listener_list; l = l->next) {
763 // Ignore special listeners like those for *smartsocket*
764 if (l->connect_to[0] == '*')
765 continue;
766 int len = format_listener(l, buf, buflen);
767 // Ensure there is space for the trailing zero.
768 result += len;
769 if (buf != NULL) {
770 buf += len;
771 buflen -= len;
772 if (buflen <= 0)
773 break;
774 }
775 }
776 return result;
777}
778
779static int remove_listener(const char *local_name, atransport* transport)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800780{
781 alistener *l;
782
783 for (l = listener_list.next; l != &listener_list; l = l->next) {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100784 if (!strcmp(local_name, l->local_name)) {
785 listener_disconnect(l, l->transport);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800786 return 0;
787 }
788 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800789 return -1;
790}
791
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100792static void remove_all_listeners(void)
793{
794 alistener *l, *l_next;
795 for (l = listener_list.next; l != &listener_list; l = l_next) {
796 l_next = l->next;
797 // Never remove smart sockets.
798 if (l->connect_to[0] == '*')
799 continue;
800 listener_disconnect(l, l->transport);
801 }
802}
803
804// error/status codes for install_listener.
805typedef enum {
806 INSTALL_STATUS_OK = 0,
807 INSTALL_STATUS_INTERNAL_ERROR = -1,
808 INSTALL_STATUS_CANNOT_BIND = -2,
809 INSTALL_STATUS_CANNOT_REBIND = -3,
810} install_status_t;
811
812static install_status_t install_listener(const char *local_name,
813 const char *connect_to,
814 atransport* transport,
815 int no_rebind)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800816{
817 alistener *l;
818
819 //printf("install_listener('%s','%s')\n", local_name, connect_to);
820
821 for(l = listener_list.next; l != &listener_list; l = l->next){
822 if(strcmp(local_name, l->local_name) == 0) {
823 char *cto;
824
825 /* can't repurpose a smartsocket */
826 if(l->connect_to[0] == '*') {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100827 return INSTALL_STATUS_INTERNAL_ERROR;
828 }
829
830 /* can't repurpose a listener if 'no_rebind' is true */
831 if (no_rebind) {
832 return INSTALL_STATUS_CANNOT_REBIND;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800833 }
834
835 cto = strdup(connect_to);
836 if(cto == 0) {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100837 return INSTALL_STATUS_INTERNAL_ERROR;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800838 }
839
840 //printf("rebinding '%s' to '%s'\n", local_name, connect_to);
841 free((void*) l->connect_to);
842 l->connect_to = cto;
843 if (l->transport != transport) {
844 remove_transport_disconnect(l->transport, &l->disconnect);
845 l->transport = transport;
846 add_transport_disconnect(l->transport, &l->disconnect);
847 }
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100848 return INSTALL_STATUS_OK;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800849 }
850 }
851
852 if((l = calloc(1, sizeof(alistener))) == 0) goto nomem;
853 if((l->local_name = strdup(local_name)) == 0) goto nomem;
854 if((l->connect_to = strdup(connect_to)) == 0) goto nomem;
855
856
857 l->fd = local_name_to_fd(local_name);
858 if(l->fd < 0) {
859 free((void*) l->local_name);
860 free((void*) l->connect_to);
861 free(l);
862 printf("cannot bind '%s'\n", local_name);
863 return -2;
864 }
865
866 close_on_exec(l->fd);
867 if(!strcmp(l->connect_to, "*smartsocket*")) {
868 fdevent_install(&l->fde, l->fd, ss_listener_event_func, l);
869 } else {
870 fdevent_install(&l->fde, l->fd, listener_event_func, l);
871 }
872 fdevent_set(&l->fde, FDE_READ);
873
874 l->next = &listener_list;
875 l->prev = listener_list.prev;
876 l->next->prev = l;
877 l->prev->next = l;
878 l->transport = transport;
879
880 if (transport) {
881 l->disconnect.opaque = l;
882 l->disconnect.func = listener_disconnect;
883 add_transport_disconnect(transport, &l->disconnect);
884 }
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100885 return INSTALL_STATUS_OK;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800886
887nomem:
888 fatal("cannot allocate listener");
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +0100889 return INSTALL_STATUS_INTERNAL_ERROR;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800890}
891
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800892#ifdef HAVE_WIN32_PROC
893static BOOL WINAPI ctrlc_handler(DWORD type)
894{
895 exit(STATUS_CONTROL_C_EXIT);
896 return TRUE;
897}
898#endif
899
900static void adb_cleanup(void)
901{
902 usb_cleanup();
903}
904
905void start_logging(void)
906{
907#ifdef HAVE_WIN32_PROC
908 char temp[ MAX_PATH ];
909 FILE* fnul;
910 FILE* flog;
911
912 GetTempPath( sizeof(temp) - 8, temp );
913 strcat( temp, "adb.log" );
914
915 /* Win32 specific redirections */
916 fnul = fopen( "NUL", "rt" );
917 if (fnul != NULL)
918 stdin[0] = fnul[0];
919
920 flog = fopen( temp, "at" );
921 if (flog == NULL)
922 flog = fnul;
923
924 setvbuf( flog, NULL, _IONBF, 0 );
925
926 stdout[0] = flog[0];
927 stderr[0] = flog[0];
928 fprintf(stderr,"--- adb starting (pid %d) ---\n", getpid());
929#else
930 int fd;
931
932 fd = unix_open("/dev/null", O_RDONLY);
933 dup2(fd, 0);
JP Abgrall408fa572011-03-16 15:57:42 -0700934 adb_close(fd);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800935
936 fd = unix_open("/tmp/adb.log", O_WRONLY | O_CREAT | O_APPEND, 0640);
937 if(fd < 0) {
938 fd = unix_open("/dev/null", O_WRONLY);
939 }
940 dup2(fd, 1);
941 dup2(fd, 2);
JP Abgrall408fa572011-03-16 15:57:42 -0700942 adb_close(fd);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800943 fprintf(stderr,"--- adb starting (pid %d) ---\n", getpid());
944#endif
945}
946
947#if !ADB_HOST
948void start_device_log(void)
949{
950 int fd;
Mike Lockwood1f546e62009-05-25 18:17:55 -0400951 char path[PATH_MAX];
952 struct tm now;
953 time_t t;
954 char value[PROPERTY_VALUE_MAX];
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800955
Mike Lockwood1f546e62009-05-25 18:17:55 -0400956 // read the trace mask from persistent property persist.adb.trace_mask
957 // give up if the property is not set or cannot be parsed
958 property_get("persist.adb.trace_mask", value, "");
959 if (sscanf(value, "%x", &adb_trace_mask) != 1)
960 return;
961
962 adb_mkdir("/data/adb", 0775);
963 tzset();
964 time(&t);
965 localtime_r(&t, &now);
966 strftime(path, sizeof(path),
967 "/data/adb/adb-%Y-%m-%d-%H-%M-%S.txt",
968 &now);
969 fd = unix_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0640);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800970 if (fd < 0)
971 return;
972
973 // redirect stdout and stderr to the log file
974 dup2(fd, 1);
975 dup2(fd, 2);
976 fprintf(stderr,"--- adb starting (pid %d) ---\n", getpid());
Benoit Goby95ef8282011-02-01 18:57:41 -0800977 adb_close(fd);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800978
979 fd = unix_open("/dev/null", O_RDONLY);
980 dup2(fd, 0);
Benoit Goby95ef8282011-02-01 18:57:41 -0800981 adb_close(fd);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800982}
983#endif
984
985#if ADB_HOST
JP Abgrall571c1362012-12-06 18:18:12 -0800986
987#ifdef WORKAROUND_BUG6558362
988#include <sched.h>
989#define AFFINITY_ENVVAR "ADB_CPU_AFFINITY_BUG6558362"
990void adb_set_affinity(void)
991{
992 cpu_set_t cpu_set;
993 const char* cpunum_str = getenv(AFFINITY_ENVVAR);
994 char* strtol_res;
995 int cpu_num;
996
997 if (!cpunum_str || !*cpunum_str)
998 return;
999 cpu_num = strtol(cpunum_str, &strtol_res, 0);
1000 if (*strtol_res != '\0')
1001 fatal("bad number (%s) in env var %s. Expecting 0..n.\n", cpunum_str, AFFINITY_ENVVAR);
1002
1003 sched_getaffinity(0, sizeof(cpu_set), &cpu_set);
1004 D("orig cpu_set[0]=0x%08lx\n", cpu_set.__bits[0]);
1005 CPU_ZERO(&cpu_set);
1006 CPU_SET(cpu_num, &cpu_set);
1007 sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
1008 sched_getaffinity(0, sizeof(cpu_set), &cpu_set);
1009 D("new cpu_set[0]=0x%08lx\n", cpu_set.__bits[0]);
1010}
1011#endif
1012
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001013int launch_server(int server_port)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001014{
1015#ifdef HAVE_WIN32_PROC
1016 /* we need to start the server in the background */
1017 /* we create a PIPE that will be used to wait for the server's "OK" */
1018 /* message since the pipe handles must be inheritable, we use a */
1019 /* security attribute */
1020 HANDLE pipe_read, pipe_write;
1021 SECURITY_ATTRIBUTES sa;
1022 STARTUPINFO startup;
1023 PROCESS_INFORMATION pinfo;
1024 char program_path[ MAX_PATH ];
1025 int ret;
1026
1027 sa.nLength = sizeof(sa);
1028 sa.lpSecurityDescriptor = NULL;
1029 sa.bInheritHandle = TRUE;
1030
1031 /* create pipe, and ensure its read handle isn't inheritable */
1032 ret = CreatePipe( &pipe_read, &pipe_write, &sa, 0 );
1033 if (!ret) {
1034 fprintf(stderr, "CreatePipe() failure, error %ld\n", GetLastError() );
1035 return -1;
1036 }
1037
1038 SetHandleInformation( pipe_read, HANDLE_FLAG_INHERIT, 0 );
1039
1040 ZeroMemory( &startup, sizeof(startup) );
1041 startup.cb = sizeof(startup);
1042 startup.hStdInput = GetStdHandle( STD_INPUT_HANDLE );
1043 startup.hStdOutput = pipe_write;
1044 startup.hStdError = GetStdHandle( STD_ERROR_HANDLE );
1045 startup.dwFlags = STARTF_USESTDHANDLES;
1046
1047 ZeroMemory( &pinfo, sizeof(pinfo) );
1048
1049 /* get path of current program */
1050 GetModuleFileName( NULL, program_path, sizeof(program_path) );
1051
1052 ret = CreateProcess(
1053 program_path, /* program path */
1054 "adb fork-server server",
1055 /* the fork-server argument will set the
1056 debug = 2 in the child */
1057 NULL, /* process handle is not inheritable */
1058 NULL, /* thread handle is not inheritable */
1059 TRUE, /* yes, inherit some handles */
1060 DETACHED_PROCESS, /* the new process doesn't have a console */
1061 NULL, /* use parent's environment block */
1062 NULL, /* use parent's starting directory */
1063 &startup, /* startup info, i.e. std handles */
1064 &pinfo );
1065
1066 CloseHandle( pipe_write );
1067
1068 if (!ret) {
1069 fprintf(stderr, "CreateProcess failure, error %ld\n", GetLastError() );
1070 CloseHandle( pipe_read );
1071 return -1;
1072 }
1073
1074 CloseHandle( pinfo.hProcess );
1075 CloseHandle( pinfo.hThread );
1076
1077 /* wait for the "OK\n" message */
1078 {
1079 char temp[3];
1080 DWORD count;
1081
1082 ret = ReadFile( pipe_read, temp, 3, &count, NULL );
1083 CloseHandle( pipe_read );
1084 if ( !ret ) {
1085 fprintf(stderr, "could not read ok from ADB Server, error = %ld\n", GetLastError() );
1086 return -1;
1087 }
1088 if (count != 3 || temp[0] != 'O' || temp[1] != 'K' || temp[2] != '\n') {
1089 fprintf(stderr, "ADB server didn't ACK\n" );
1090 return -1;
1091 }
1092 }
1093#elif defined(HAVE_FORKEXEC)
1094 char path[PATH_MAX];
1095 int fd[2];
1096
1097 // set up a pipe so the child can tell us when it is ready.
1098 // fd[0] will be parent's end, and fd[1] will get mapped to stderr in the child.
1099 if (pipe(fd)) {
1100 fprintf(stderr, "pipe failed in launch_server, errno: %d\n", errno);
1101 return -1;
1102 }
Alexey Tarasov31664102009-10-22 02:55:00 +11001103 get_my_path(path, PATH_MAX);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001104 pid_t pid = fork();
1105 if(pid < 0) return -1;
1106
1107 if (pid == 0) {
1108 // child side of the fork
1109
1110 // redirect stderr to the pipe
1111 // we use stderr instead of stdout due to stdout's buffering behavior.
1112 adb_close(fd[0]);
1113 dup2(fd[1], STDERR_FILENO);
1114 adb_close(fd[1]);
1115
Matt Gumbeld7b33082012-11-14 10:16:17 -08001116 char str_port[30];
1117 snprintf(str_port, sizeof(str_port), "%d", server_port);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001118 // child process
Matt Gumbeld7b33082012-11-14 10:16:17 -08001119 int result = execl(path, "adb", "-P", str_port, "fork-server", "server", NULL);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001120 // this should not return
1121 fprintf(stderr, "OOPS! execl returned %d, errno: %d\n", result, errno);
1122 } else {
1123 // parent side of the fork
1124
1125 char temp[3];
1126
1127 temp[0] = 'A'; temp[1] = 'B'; temp[2] = 'C';
1128 // wait for the "OK\n" message
1129 adb_close(fd[1]);
1130 int ret = adb_read(fd[0], temp, 3);
JP Abgrall408fa572011-03-16 15:57:42 -07001131 int saved_errno = errno;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001132 adb_close(fd[0]);
1133 if (ret < 0) {
JP Abgrall408fa572011-03-16 15:57:42 -07001134 fprintf(stderr, "could not read ok from ADB Server, errno = %d\n", saved_errno);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001135 return -1;
1136 }
1137 if (ret != 3 || temp[0] != 'O' || temp[1] != 'K' || temp[2] != '\n') {
1138 fprintf(stderr, "ADB server didn't ACK\n" );
1139 return -1;
1140 }
1141
1142 setsid();
1143 }
1144#else
1145#error "cannot implement background server start on this platform"
1146#endif
1147 return 0;
1148}
1149#endif
1150
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001151/* Constructs a local name of form tcp:port.
1152 * target_str points to the target string, it's content will be overwritten.
1153 * target_size is the capacity of the target string.
1154 * server_port is the port number to use for the local name.
1155 */
1156void build_local_name(char* target_str, size_t target_size, int server_port)
1157{
1158 snprintf(target_str, target_size, "tcp:%d", server_port);
1159}
1160
Nick Kralevichbd9206b2012-01-19 10:18:59 -08001161#if !ADB_HOST
1162static int should_drop_privileges() {
Nick Kralevich5890fe32012-01-19 13:11:35 -08001163#ifndef ALLOW_ADBD_ROOT
1164 return 1;
1165#else /* ALLOW_ADBD_ROOT */
Nick Kralevichbd9206b2012-01-19 10:18:59 -08001166 int secure = 0;
1167 char value[PROPERTY_VALUE_MAX];
1168
1169 /* run adbd in secure mode if ro.secure is set and
1170 ** we are not in the emulator
1171 */
1172 property_get("ro.kernel.qemu", value, "");
1173 if (strcmp(value, "1") != 0) {
1174 property_get("ro.secure", value, "1");
1175 if (strcmp(value, "1") == 0) {
1176 // don't run as root if ro.secure is set...
1177 secure = 1;
1178
1179 // ... except we allow running as root in userdebug builds if the
1180 // service.adb.root property has been set by the "adb root" command
1181 property_get("ro.debuggable", value, "");
1182 if (strcmp(value, "1") == 0) {
1183 property_get("service.adb.root", value, "");
1184 if (strcmp(value, "1") == 0) {
1185 secure = 0;
1186 }
1187 }
1188 }
1189 }
1190 return secure;
Nick Kralevich5890fe32012-01-19 13:11:35 -08001191#endif /* ALLOW_ADBD_ROOT */
Nick Kralevichbd9206b2012-01-19 10:18:59 -08001192}
1193#endif /* !ADB_HOST */
1194
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001195int adb_main(int is_daemon, int server_port)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001196{
1197#if !ADB_HOST
Mike Lockwood2f38b692009-08-24 15:58:40 -07001198 int port;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001199 char value[PROPERTY_VALUE_MAX];
Nick Kralevicheb68fa82012-04-02 13:00:35 -07001200
1201 umask(000);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001202#endif
1203
1204 atexit(adb_cleanup);
1205#ifdef HAVE_WIN32_PROC
1206 SetConsoleCtrlHandler( ctrlc_handler, TRUE );
1207#elif defined(HAVE_FORKEXEC)
JP Abgrall408fa572011-03-16 15:57:42 -07001208 // No SIGCHLD. Let the service subproc handle its children.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001209 signal(SIGPIPE, SIG_IGN);
1210#endif
1211
1212 init_transport_registration();
1213
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001214#if ADB_HOST
1215 HOST = 1;
JP Abgrall571c1362012-12-06 18:18:12 -08001216
1217#ifdef WORKAROUND_BUG6558362
1218 if(is_daemon) adb_set_affinity();
1219#endif
Xavier Ducroheta09fbd12009-05-20 17:33:53 -07001220 usb_vendors_init();
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001221 usb_init();
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001222 local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
Benoit Gobyd5fcafa2012-04-12 12:23:49 -07001223 adb_auth_init();
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001224
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001225 char local_name[30];
1226 build_local_name(local_name, sizeof(local_name), server_port);
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001227 if(install_listener(local_name, "*smartsocket*", NULL, 0)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001228 exit(1);
1229 }
1230#else
Benoit Gobyd5fcafa2012-04-12 12:23:49 -07001231 property_get("ro.adb.secure", value, "0");
1232 auth_enabled = !strcmp(value, "1");
1233 if (auth_enabled)
1234 adb_auth_init();
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001235
Jeff Sharkeyd6d42862012-09-06 13:05:40 -07001236 // Our external storage path may be different than apps, since
1237 // we aren't able to bind mount after dropping root.
1238 const char* adb_external_storage = getenv("ADB_EXTERNAL_STORAGE");
1239 if (NULL != adb_external_storage) {
1240 setenv("EXTERNAL_STORAGE", adb_external_storage, 1);
1241 } else {
1242 D("Warning: ADB_EXTERNAL_STORAGE is not set. Leaving EXTERNAL_STORAGE"
1243 " unchanged.\n");
1244 }
1245
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001246 /* don't listen on a port (default 5037) if running in secure mode */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001247 /* don't run as root if we are running in secure mode */
Nick Kralevichbd9206b2012-01-19 10:18:59 -08001248 if (should_drop_privileges()) {
Mike Lockwood5f4b0512009-08-04 20:37:51 -04001249 struct __user_cap_header_struct header;
1250 struct __user_cap_data_struct cap;
1251
Nick Kralevich44db9902010-08-27 14:35:07 -07001252 if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) {
1253 exit(1);
1254 }
Mike Lockwood5f4b0512009-08-04 20:37:51 -04001255
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001256 /* add extra groups:
1257 ** AID_ADB to access the USB driver
1258 ** AID_LOG to read system logs (adb logcat)
1259 ** AID_INPUT to diagnose input issues (getevent)
1260 ** AID_INET to diagnose network issues (netcfg, ping)
1261 ** AID_GRAPHICS to access the frame buffer
The Android Open Source Project20155492009-03-11 12:12:01 -07001262 ** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump)
Dianne Hackborn50458cf2012-03-07 12:57:14 -08001263 ** AID_SDCARD_R to allow reading from the SD card
Mike Lockwood6a3075c2009-05-25 13:52:00 -04001264 ** AID_SDCARD_RW to allow writing to the SD card
Mike Lockwoodd969faa2010-02-24 16:07:23 -05001265 ** AID_MOUNT to allow unmounting the SD card before rebooting
JP Abgrall61b90bd2011-11-09 10:30:08 -08001266 ** AID_NET_BW_STATS to read out qtaguid statistics
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001267 */
The Android Open Source Project20155492009-03-11 12:12:01 -07001268 gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_GRAPHICS,
Dianne Hackborn50458cf2012-03-07 12:57:14 -08001269 AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_R, AID_SDCARD_RW,
1270 AID_MOUNT, AID_NET_BW_STATS };
Nick Kralevich44db9902010-08-27 14:35:07 -07001271 if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
1272 exit(1);
1273 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001274
1275 /* then switch user and group to "shell" */
Nick Kralevich44db9902010-08-27 14:35:07 -07001276 if (setgid(AID_SHELL) != 0) {
1277 exit(1);
1278 }
1279 if (setuid(AID_SHELL) != 0) {
1280 exit(1);
1281 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001282
Mike Lockwood5f4b0512009-08-04 20:37:51 -04001283 /* set CAP_SYS_BOOT capability, so "adb reboot" will succeed */
1284 header.version = _LINUX_CAPABILITY_VERSION;
1285 header.pid = 0;
1286 cap.effective = cap.permitted = (1 << CAP_SYS_BOOT);
1287 cap.inheritable = 0;
1288 capset(&header, &cap);
1289
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001290 D("Local port disabled\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001291 } else {
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001292 char local_name[30];
1293 build_local_name(local_name, sizeof(local_name), server_port);
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001294 if(install_listener(local_name, "*smartsocket*", NULL, 0)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001295 exit(1);
1296 }
1297 }
1298
Mike J. Chen1dd55c52012-07-20 18:16:21 -07001299 int usb = 0;
1300 if (access(USB_ADB_PATH, F_OK) == 0 || access(USB_FFS_ADB_EP0, F_OK) == 0) {
Mike Lockwoodcef31a02009-08-26 12:50:22 -07001301 // listen on USB
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001302 usb_init();
Mike J. Chen1dd55c52012-07-20 18:16:21 -07001303 usb = 1;
1304 }
1305
1306 // If one of these properties is set, also listen on that port
1307 // If one of the properties isn't set and we couldn't listen on usb,
1308 // listen on the default port.
1309 property_get("service.adb.tcp.port", value, "");
1310 if (!value[0]) {
1311 property_get("persist.adb.tcp.port", value, "");
1312 }
1313 if (sscanf(value, "%d", &port) == 1 && port > 0) {
1314 printf("using port=%d\n", port);
1315 // listen on TCP port specified by service.adb.tcp.port property
1316 local_init(port);
1317 } else if (!usb) {
Mike Lockwoodcef31a02009-08-26 12:50:22 -07001318 // listen on default port
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001319 local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001320 }
Mike J. Chen1dd55c52012-07-20 18:16:21 -07001321
JP Abgrall408fa572011-03-16 15:57:42 -07001322 D("adb_main(): pre init_jdwp()\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001323 init_jdwp();
JP Abgrall408fa572011-03-16 15:57:42 -07001324 D("adb_main(): post init_jdwp()\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001325#endif
1326
1327 if (is_daemon)
1328 {
1329 // inform our parent that we are up and running.
1330#ifdef HAVE_WIN32_PROC
1331 DWORD count;
1332 WriteFile( GetStdHandle( STD_OUTPUT_HANDLE ), "OK\n", 3, &count, NULL );
1333#elif defined(HAVE_FORKEXEC)
1334 fprintf(stderr, "OK\n");
1335#endif
1336 start_logging();
1337 }
JP Abgrall408fa572011-03-16 15:57:42 -07001338 D("Event loop starting\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001339
1340 fdevent_loop();
1341
1342 usb_cleanup();
1343
1344 return 0;
1345}
1346
Stefan Hilzingerd9d1ca42010-04-26 10:17:43 +01001347#if ADB_HOST
1348void connect_device(char* host, char* buffer, int buffer_size)
1349{
1350 int port, fd;
1351 char* portstr = strchr(host, ':');
Mike Lockwoodcbbe79a2010-05-24 10:44:35 -04001352 char hostbuf[100];
1353 char serial[100];
Stefan Hilzingerd9d1ca42010-04-26 10:17:43 +01001354
Mike Lockwoodcbbe79a2010-05-24 10:44:35 -04001355 strncpy(hostbuf, host, sizeof(hostbuf) - 1);
1356 if (portstr) {
Scott Andersonc7993af2012-05-25 13:55:46 -07001357 if (portstr - host >= (ptrdiff_t)sizeof(hostbuf)) {
Mike Lockwoodcbbe79a2010-05-24 10:44:35 -04001358 snprintf(buffer, buffer_size, "bad host name %s", host);
1359 return;
1360 }
1361 // zero terminate the host at the point we found the colon
1362 hostbuf[portstr - host] = 0;
1363 if (sscanf(portstr + 1, "%d", &port) == 0) {
1364 snprintf(buffer, buffer_size, "bad port number %s", portstr);
1365 return;
1366 }
1367 } else {
1368 port = DEFAULT_ADB_LOCAL_TRANSPORT_PORT;
Stefan Hilzingerd9d1ca42010-04-26 10:17:43 +01001369 }
Mike Lockwoodcbbe79a2010-05-24 10:44:35 -04001370
1371 snprintf(serial, sizeof(serial), "%s:%d", hostbuf, port);
1372 if (find_transport(serial)) {
1373 snprintf(buffer, buffer_size, "already connected to %s", serial);
Stefan Hilzingerd9d1ca42010-04-26 10:17:43 +01001374 return;
1375 }
1376
Mike Lockwoodcbbe79a2010-05-24 10:44:35 -04001377 fd = socket_network_client(hostbuf, port, SOCK_STREAM);
Stefan Hilzingerd9d1ca42010-04-26 10:17:43 +01001378 if (fd < 0) {
1379 snprintf(buffer, buffer_size, "unable to connect to %s:%d", host, port);
1380 return;
1381 }
1382
1383 D("client: connected on remote on fd %d\n", fd);
1384 close_on_exec(fd);
1385 disable_tcp_nagle(fd);
Mike Lockwoodcbbe79a2010-05-24 10:44:35 -04001386 register_socket_transport(fd, serial, port, 0);
1387 snprintf(buffer, buffer_size, "connected to %s", serial);
Stefan Hilzingerd9d1ca42010-04-26 10:17:43 +01001388}
1389
1390void connect_emulator(char* port_spec, char* buffer, int buffer_size)
1391{
1392 char* port_separator = strchr(port_spec, ',');
1393 if (!port_separator) {
1394 snprintf(buffer, buffer_size,
1395 "unable to parse '%s' as <console port>,<adb port>",
1396 port_spec);
1397 return;
1398 }
1399
1400 // Zero-terminate console port and make port_separator point to 2nd port.
1401 *port_separator++ = 0;
1402 int console_port = strtol(port_spec, NULL, 0);
1403 int adb_port = strtol(port_separator, NULL, 0);
1404 if (!(console_port > 0 && adb_port > 0)) {
1405 *(port_separator - 1) = ',';
1406 snprintf(buffer, buffer_size,
1407 "Invalid port numbers: Expected positive numbers, got '%s'",
1408 port_spec);
1409 return;
1410 }
1411
1412 /* Check if the emulator is already known.
1413 * Note: There's a small but harmless race condition here: An emulator not
1414 * present just yet could be registered by another invocation right
1415 * after doing this check here. However, local_connect protects
1416 * against double-registration too. From here, a better error message
1417 * can be produced. In the case of the race condition, the very specific
1418 * error message won't be shown, but the data doesn't get corrupted. */
1419 atransport* known_emulator = find_emulator_transport_by_adb_port(adb_port);
1420 if (known_emulator != NULL) {
1421 snprintf(buffer, buffer_size,
1422 "Emulator on port %d already registered.", adb_port);
1423 return;
1424 }
1425
1426 /* Check if more emulators can be registered. Similar unproblematic
1427 * race condition as above. */
1428 int candidate_slot = get_available_local_transport_index();
1429 if (candidate_slot < 0) {
1430 snprintf(buffer, buffer_size, "Cannot accept more emulators.");
1431 return;
1432 }
1433
1434 /* Preconditions met, try to connect to the emulator. */
1435 if (!local_connect_arbitrary_ports(console_port, adb_port)) {
1436 snprintf(buffer, buffer_size,
1437 "Connected to emulator on ports %d,%d", console_port, adb_port);
1438 } else {
1439 snprintf(buffer, buffer_size,
1440 "Could not connect to emulator on ports %d,%d",
1441 console_port, adb_port);
1442 }
1443}
1444#endif
1445
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001446int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s)
1447{
1448 atransport *transport = NULL;
1449 char buf[4096];
1450
1451 if(!strcmp(service, "kill")) {
1452 fprintf(stderr,"adb server killed by remote request\n");
1453 fflush(stdout);
1454 adb_write(reply_fd, "OKAY", 4);
1455 usb_cleanup();
1456 exit(0);
1457 }
1458
1459#if ADB_HOST
1460 // "transport:" is used for switching transport with a specified serial number
1461 // "transport-usb:" is used for switching transport to the only USB transport
1462 // "transport-local:" is used for switching transport to the only local transport
1463 // "transport-any:" is used for switching transport to the only transport
1464 if (!strncmp(service, "transport", strlen("transport"))) {
1465 char* error_string = "unknown failure";
1466 transport_type type = kTransportAny;
1467
1468 if (!strncmp(service, "transport-usb", strlen("transport-usb"))) {
1469 type = kTransportUsb;
1470 } else if (!strncmp(service, "transport-local", strlen("transport-local"))) {
1471 type = kTransportLocal;
1472 } else if (!strncmp(service, "transport-any", strlen("transport-any"))) {
1473 type = kTransportAny;
1474 } else if (!strncmp(service, "transport:", strlen("transport:"))) {
1475 service += strlen("transport:");
Tom Marlin3175c8e2011-07-27 12:56:14 -05001476 serial = service;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001477 }
1478
1479 transport = acquire_one_transport(CS_ANY, type, serial, &error_string);
1480
1481 if (transport) {
1482 s->transport = transport;
1483 adb_write(reply_fd, "OKAY", 4);
1484 } else {
1485 sendfailmsg(reply_fd, error_string);
1486 }
1487 return 1;
1488 }
1489
1490 // return a list of all connected devices
Scott Andersone109d262012-04-20 11:21:14 -07001491 if (!strncmp(service, "devices", 7)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001492 char buffer[4096];
Scott Andersone109d262012-04-20 11:21:14 -07001493 int use_long = !strcmp(service+7, "-l");
1494 if (use_long || service[7] == 0) {
1495 memset(buf, 0, sizeof(buf));
1496 memset(buffer, 0, sizeof(buffer));
1497 D("Getting device list \n");
1498 list_transports(buffer, sizeof(buffer), use_long);
1499 snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer),buffer);
1500 D("Wrote device list \n");
1501 writex(reply_fd, buf, strlen(buf));
1502 return 0;
1503 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001504 }
1505
Stefan Hilzingerd9d1ca42010-04-26 10:17:43 +01001506 // add a new TCP transport, device or emulator
Mike Lockwood2f38b692009-08-24 15:58:40 -07001507 if (!strncmp(service, "connect:", 8)) {
1508 char buffer[4096];
Mike Lockwood2f38b692009-08-24 15:58:40 -07001509 char* host = service + 8;
Stefan Hilzingerd9d1ca42010-04-26 10:17:43 +01001510 if (!strncmp(host, "emu:", 4)) {
1511 connect_emulator(host + 4, buffer, sizeof(buffer));
1512 } else {
1513 connect_device(host, buffer, sizeof(buffer));
Mike Lockwood2f38b692009-08-24 15:58:40 -07001514 }
Stefan Hilzingerd9d1ca42010-04-26 10:17:43 +01001515 // Send response for emulator and device
Mike Lockwood74d7ff82009-10-11 23:04:18 -04001516 snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer), buffer);
1517 writex(reply_fd, buf, strlen(buf));
1518 return 0;
1519 }
1520
1521 // remove TCP transport
1522 if (!strncmp(service, "disconnect:", 11)) {
1523 char buffer[4096];
1524 memset(buffer, 0, sizeof(buffer));
1525 char* serial = service + 11;
Mike Lockwoodcbbe79a2010-05-24 10:44:35 -04001526 if (serial[0] == 0) {
1527 // disconnect from all TCP devices
1528 unregister_all_tcp_transports();
Mike Lockwood74d7ff82009-10-11 23:04:18 -04001529 } else {
Mike Lockwoodcbbe79a2010-05-24 10:44:35 -04001530 char hostbuf[100];
1531 // assume port 5555 if no port is specified
1532 if (!strchr(serial, ':')) {
1533 snprintf(hostbuf, sizeof(hostbuf) - 1, "%s:5555", serial);
1534 serial = hostbuf;
1535 }
1536 atransport *t = find_transport(serial);
1537
1538 if (t) {
1539 unregister_transport(t);
1540 } else {
1541 snprintf(buffer, sizeof(buffer), "No such device %s", serial);
1542 }
Mike Lockwood74d7ff82009-10-11 23:04:18 -04001543 }
1544
1545 snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer), buffer);
Mike Lockwood2f38b692009-08-24 15:58:40 -07001546 writex(reply_fd, buf, strlen(buf));
1547 return 0;
1548 }
1549
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001550 // returns our value for ADB_SERVER_VERSION
1551 if (!strcmp(service, "version")) {
1552 char version[12];
1553 snprintf(version, sizeof version, "%04x", ADB_SERVER_VERSION);
1554 snprintf(buf, sizeof buf, "OKAY%04x%s", (unsigned)strlen(version), version);
1555 writex(reply_fd, buf, strlen(buf));
1556 return 0;
1557 }
1558
1559 if(!strncmp(service,"get-serialno",strlen("get-serialno"))) {
1560 char *out = "unknown";
1561 transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
1562 if (transport && transport->serial) {
1563 out = transport->serial;
1564 }
1565 snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(out),out);
1566 writex(reply_fd, buf, strlen(buf));
1567 return 0;
1568 }
Scott Andersone109d262012-04-20 11:21:14 -07001569 if(!strncmp(service,"get-devpath",strlen("get-devpath"))) {
1570 char *out = "unknown";
1571 transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
1572 if (transport && transport->devpath) {
1573 out = transport->devpath;
1574 }
1575 snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(out),out);
1576 writex(reply_fd, buf, strlen(buf));
1577 return 0;
1578 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001579 // indicates a new emulator instance has started
1580 if (!strncmp(service,"emulator:",9)) {
1581 int port = atoi(service+9);
1582 local_connect(port);
1583 /* we don't even need to send a reply */
1584 return 0;
1585 }
1586#endif // ADB_HOST
1587
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001588 if(!strcmp(service,"list-forward")) {
1589 // Create the list of forward redirections.
1590 char header[9];
1591 int buffer_size = format_listeners(NULL, 0);
1592 // Add one byte for the trailing zero.
1593 char* buffer = malloc(buffer_size+1);
1594 (void) format_listeners(buffer, buffer_size+1);
1595 snprintf(header, sizeof header, "OKAY%04x", buffer_size);
1596 writex(reply_fd, header, 8);
1597 writex(reply_fd, buffer, buffer_size);
1598 free(buffer);
1599 return 0;
1600 }
1601
1602 if (!strcmp(service,"killforward-all")) {
1603 remove_all_listeners();
1604 adb_write(reply_fd, "OKAYOKAY", 8);
1605 return 0;
1606 }
1607
1608 if(!strncmp(service,"forward:",8) ||
1609 !strncmp(service,"killforward:",12)) {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001610 char *local, *remote, *err;
1611 int r;
1612 atransport *transport;
1613
1614 int createForward = strncmp(service,"kill",4);
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001615 int no_rebind = 0;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001616
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001617 local = strchr(service, ':') + 1;
1618
1619 // Handle forward:norebind:<local>... here
1620 if (createForward && !strncmp(local, "norebind:", 9)) {
1621 no_rebind = 1;
1622 local = strchr(local, ':') + 1;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001623 }
1624
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001625 remote = strchr(local,';');
1626
1627 if (createForward) {
1628 // Check forward: parameter format: '<local>;<remote>'
1629 if(remote == 0) {
1630 sendfailmsg(reply_fd, "malformed forward spec");
1631 return 0;
1632 }
1633
1634 *remote++ = 0;
1635 if((local[0] == 0) || (remote[0] == 0) || (remote[0] == '*')){
1636 sendfailmsg(reply_fd, "malformed forward spec");
1637 return 0;
1638 }
1639 } else {
1640 // Check killforward: parameter format: '<local>'
1641 if (local[0] == 0) {
1642 sendfailmsg(reply_fd, "malformed forward spec");
1643 return 0;
1644 }
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001645 }
1646
1647 transport = acquire_one_transport(CS_ANY, ttype, serial, &err);
1648 if (!transport) {
1649 sendfailmsg(reply_fd, err);
1650 return 0;
1651 }
1652
1653 if (createForward) {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001654 r = install_listener(local, remote, transport, no_rebind);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001655 } else {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001656 r = remove_listener(local, transport);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001657 }
1658 if(r == 0) {
1659 /* 1st OKAY is connect, 2nd OKAY is status */
1660 writex(reply_fd, "OKAYOKAY", 8);
1661 return 0;
1662 }
1663
1664 if (createForward) {
David 'Digit' Turner0d82fbf2012-11-14 15:01:55 +01001665 const char* message;
1666 switch (r) {
1667 case INSTALL_STATUS_CANNOT_BIND:
1668 message = "cannot bind to socket";
1669 break;
1670 case INSTALL_STATUS_CANNOT_REBIND:
1671 message = "cannot rebind existing socket";
1672 break;
1673 default:
1674 message = "internal error";
1675 }
1676 sendfailmsg(reply_fd, message);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001677 } else {
1678 sendfailmsg(reply_fd, "cannot remove listener");
1679 }
1680 return 0;
1681 }
1682
1683 if(!strncmp(service,"get-state",strlen("get-state"))) {
1684 transport = acquire_one_transport(CS_ANY, ttype, serial, NULL);
1685 char *state = connection_state_name(transport);
1686 snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(state),state);
1687 writex(reply_fd, buf, strlen(buf));
1688 return 0;
1689 }
1690 return -1;
1691}
1692
1693#if !ADB_HOST
1694int recovery_mode = 0;
1695#endif
1696
1697int main(int argc, char **argv)
1698{
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001699#if ADB_HOST
1700 adb_sysdeps_init();
JP Abgrall408fa572011-03-16 15:57:42 -07001701 adb_trace_init();
1702 D("Handling commandline()\n");
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001703 return adb_commandline(argc - 1, argv + 1);
1704#else
Vladimir Chtchetkine28781b02012-02-27 10:41:53 -08001705 /* If adbd runs inside the emulator this will enable adb tracing via
1706 * adb-debug qemud service in the emulator. */
1707 adb_qemu_trace_init();
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001708 if((argc > 1) && (!strcmp(argv[1],"recovery"))) {
1709 adb_device_banner = "recovery";
1710 recovery_mode = 1;
1711 }
Mike Lockwood1f546e62009-05-25 18:17:55 -04001712
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001713 start_device_log();
JP Abgrall408fa572011-03-16 15:57:42 -07001714 D("Handling main()\n");
Stefan Hilzingera84a42e2010-04-19 12:21:12 +01001715 return adb_main(0, DEFAULT_ADB_PORT);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001716#endif
1717}