2009-03-04 11:32:55 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ADB_H
|
|
|
|
#define __ADB_H
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
2014-07-30 03:50:02 +08:00
|
|
|
#include "adb_trace.h"
|
2014-11-25 15:34:35 +08:00
|
|
|
#include "fdevent.h"
|
2011-03-17 06:57:42 +08:00
|
|
|
#include "transport.h" /* readx(), writex() */
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
#define MAX_PAYLOAD 4096
|
|
|
|
|
|
|
|
#define A_SYNC 0x434e5953
|
|
|
|
#define A_CNXN 0x4e584e43
|
|
|
|
#define A_OPEN 0x4e45504f
|
|
|
|
#define A_OKAY 0x59414b4f
|
|
|
|
#define A_CLSE 0x45534c43
|
|
|
|
#define A_WRTE 0x45545257
|
adb: Add public key authentification
Secure adb using a public key authentication, to allow USB debugging
only from authorized hosts.
When a device is connected to an unauthorized host, the adb daemon sends
the user public key to the device. A popup is shown to ask the user to
allow debugging once or permanantly from the host. The public key is
installed on the device in the later case. Other keys may be installed
at build time.
On the host, the user public/private key pair is automatically generated,
if it does not exist, when the adb daemon starts and is stored in
$HOME/.android/adb_key(.pub) or in $ANDROID_SDK_HOME on windows. If needed,
the ADB_KEYS_PATH env variable may be set to a :-separated (; under
Windows) list of private keys, e.g. company-wide or vendor keys.
On the device, vendors public keys are installed at build time in
/adb_keys. User-installed keys are stored in /data/misc/adb/adb_keys.
ADB Protocol change:
If the device needs to authenticate the host, it replies to CNXN
packets with an AUTH packet. The AUTH packet payload is a random token.
The host signs the token with one of its private keys and sends an AUTH(0)
packet. If the signature verification succeeds, the device replies with
a CNXN packet. Otherwise, it sends a new AUTH packet with a new token so
that the host can retry with another private key. Once the host has tried
all its keys, it can send an AUTH(1) packet with a public key as
payload. adbd then sends the public key to the framework (if it has been
started) for confirmation.
Change-Id: I4e84d7621da956f66ff657245901bdaefead8395
2012-04-13 03:23:49 +08:00
|
|
|
#define A_AUTH 0x48545541
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
#define A_VERSION 0x01000000 // ADB protocol version
|
|
|
|
|
|
|
|
#define ADB_VERSION_MAJOR 1 // Used for help/version information
|
|
|
|
#define ADB_VERSION_MINOR 0 // Used for help/version information
|
|
|
|
|
2014-06-27 06:35:36 +08:00
|
|
|
#define ADB_SERVER_VERSION 32 // Increment this when we want to force users to start a new adb server
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
typedef struct amessage amessage;
|
|
|
|
typedef struct apacket apacket;
|
|
|
|
typedef struct asocket asocket;
|
|
|
|
typedef struct alistener alistener;
|
|
|
|
typedef struct aservice aservice;
|
|
|
|
typedef struct atransport atransport;
|
|
|
|
typedef struct adisconnect adisconnect;
|
|
|
|
typedef struct usb_handle usb_handle;
|
|
|
|
|
|
|
|
struct amessage {
|
|
|
|
unsigned command; /* command identifier constant */
|
|
|
|
unsigned arg0; /* first argument */
|
|
|
|
unsigned arg1; /* second argument */
|
|
|
|
unsigned data_length; /* length of payload (0 is allowed) */
|
|
|
|
unsigned data_check; /* checksum of data payload */
|
|
|
|
unsigned magic; /* command ^ 0xffffffff */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct apacket
|
|
|
|
{
|
|
|
|
apacket *next;
|
|
|
|
|
|
|
|
unsigned len;
|
|
|
|
unsigned char *ptr;
|
|
|
|
|
|
|
|
amessage msg;
|
|
|
|
unsigned char data[MAX_PAYLOAD];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* An asocket represents one half of a connection between a local and
|
|
|
|
** remote entity. A local asocket is bound to a file descriptor. A
|
|
|
|
** remote asocket is bound to the protocol engine.
|
|
|
|
*/
|
|
|
|
struct asocket {
|
|
|
|
/* chain pointers for the local/remote list of
|
|
|
|
** asockets that this asocket lives in
|
|
|
|
*/
|
|
|
|
asocket *next;
|
|
|
|
asocket *prev;
|
|
|
|
|
|
|
|
/* the unique identifier for this asocket
|
|
|
|
*/
|
|
|
|
unsigned id;
|
|
|
|
|
|
|
|
/* flag: set when the socket's peer has closed
|
|
|
|
** but packets are still queued for delivery
|
|
|
|
*/
|
|
|
|
int closing;
|
|
|
|
|
2012-03-17 05:50:07 +08:00
|
|
|
/* flag: quit adbd when both ends close the
|
|
|
|
** local service socket
|
|
|
|
*/
|
|
|
|
int exit_on_close;
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
/* the asocket we are connected to
|
|
|
|
*/
|
|
|
|
|
|
|
|
asocket *peer;
|
|
|
|
|
|
|
|
/* For local asockets, the fde is used to bind
|
|
|
|
** us to our fd event system. For remote asockets
|
|
|
|
** these fields are not used.
|
|
|
|
*/
|
|
|
|
fdevent fde;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* queue of apackets waiting to be written
|
|
|
|
*/
|
|
|
|
apacket *pkt_first;
|
|
|
|
apacket *pkt_last;
|
|
|
|
|
|
|
|
/* enqueue is called by our peer when it has data
|
|
|
|
** for us. It should return 0 if we can accept more
|
|
|
|
** data or 1 if not. If we return 1, we must call
|
|
|
|
** peer->ready() when we once again are ready to
|
|
|
|
** receive data.
|
|
|
|
*/
|
|
|
|
int (*enqueue)(asocket *s, apacket *pkt);
|
|
|
|
|
|
|
|
/* ready is called by the peer when it is ready for
|
|
|
|
** us to send data via enqueue again
|
|
|
|
*/
|
|
|
|
void (*ready)(asocket *s);
|
|
|
|
|
2013-12-13 21:09:44 +08:00
|
|
|
/* shutdown is called by the peer before it goes away.
|
|
|
|
** the socket should not do any further calls on its peer.
|
|
|
|
** Always followed by a call to close. Optional, i.e. can be NULL.
|
|
|
|
*/
|
|
|
|
void (*shutdown)(asocket *s);
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
/* close is called by the peer when it has gone away.
|
|
|
|
** we are not allowed to make any further calls on the
|
|
|
|
** peer once our close method is called.
|
|
|
|
*/
|
|
|
|
void (*close)(asocket *s);
|
|
|
|
|
2013-02-21 07:04:53 +08:00
|
|
|
/* A socket is bound to atransport */
|
2009-03-04 11:32:55 +08:00
|
|
|
atransport *transport;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* the adisconnect structure is used to record a callback that
|
|
|
|
** will be called whenever a transport is disconnected (e.g. by the user)
|
|
|
|
** this should be used to cleanup objects that depend on the
|
|
|
|
** transport (e.g. remote sockets, listeners, etc...)
|
|
|
|
*/
|
|
|
|
struct adisconnect
|
|
|
|
{
|
|
|
|
void (*func)(void* opaque, atransport* t);
|
|
|
|
void* opaque;
|
|
|
|
adisconnect* next;
|
|
|
|
adisconnect* prev;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* a transport object models the connection to a remote device or emulator
|
|
|
|
** there is one transport per connected device/emulator. a "local transport"
|
|
|
|
** connects through TCP (for the emulator), while a "usb transport" through
|
|
|
|
** USB (for real devices)
|
|
|
|
**
|
|
|
|
** note that kTransportHost doesn't really correspond to a real transport
|
|
|
|
** object, it's a special value used to indicate that a client wants to
|
|
|
|
** connect to a service implemented within the ADB server itself.
|
|
|
|
*/
|
|
|
|
typedef enum transport_type {
|
|
|
|
kTransportUsb,
|
|
|
|
kTransportLocal,
|
|
|
|
kTransportAny,
|
|
|
|
kTransportHost,
|
|
|
|
} transport_type;
|
|
|
|
|
adb: Add public key authentification
Secure adb using a public key authentication, to allow USB debugging
only from authorized hosts.
When a device is connected to an unauthorized host, the adb daemon sends
the user public key to the device. A popup is shown to ask the user to
allow debugging once or permanantly from the host. The public key is
installed on the device in the later case. Other keys may be installed
at build time.
On the host, the user public/private key pair is automatically generated,
if it does not exist, when the adb daemon starts and is stored in
$HOME/.android/adb_key(.pub) or in $ANDROID_SDK_HOME on windows. If needed,
the ADB_KEYS_PATH env variable may be set to a :-separated (; under
Windows) list of private keys, e.g. company-wide or vendor keys.
On the device, vendors public keys are installed at build time in
/adb_keys. User-installed keys are stored in /data/misc/adb/adb_keys.
ADB Protocol change:
If the device needs to authenticate the host, it replies to CNXN
packets with an AUTH packet. The AUTH packet payload is a random token.
The host signs the token with one of its private keys and sends an AUTH(0)
packet. If the signature verification succeeds, the device replies with
a CNXN packet. Otherwise, it sends a new AUTH packet with a new token so
that the host can retry with another private key. Once the host has tried
all its keys, it can send an AUTH(1) packet with a public key as
payload. adbd then sends the public key to the framework (if it has been
started) for confirmation.
Change-Id: I4e84d7621da956f66ff657245901bdaefead8395
2012-04-13 03:23:49 +08:00
|
|
|
#define TOKEN_SIZE 20
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
struct atransport
|
|
|
|
{
|
|
|
|
atransport *next;
|
|
|
|
atransport *prev;
|
|
|
|
|
|
|
|
int (*read_from_remote)(apacket *p, atransport *t);
|
|
|
|
int (*write_to_remote)(apacket *p, atransport *t);
|
|
|
|
void (*close)(atransport *t);
|
|
|
|
void (*kick)(atransport *t);
|
|
|
|
|
|
|
|
int fd;
|
|
|
|
int transport_socket;
|
|
|
|
fdevent transport_fde;
|
|
|
|
int ref_count;
|
|
|
|
unsigned sync_token;
|
|
|
|
int connection_state;
|
adb: Add public key authentification
Secure adb using a public key authentication, to allow USB debugging
only from authorized hosts.
When a device is connected to an unauthorized host, the adb daemon sends
the user public key to the device. A popup is shown to ask the user to
allow debugging once or permanantly from the host. The public key is
installed on the device in the later case. Other keys may be installed
at build time.
On the host, the user public/private key pair is automatically generated,
if it does not exist, when the adb daemon starts and is stored in
$HOME/.android/adb_key(.pub) or in $ANDROID_SDK_HOME on windows. If needed,
the ADB_KEYS_PATH env variable may be set to a :-separated (; under
Windows) list of private keys, e.g. company-wide or vendor keys.
On the device, vendors public keys are installed at build time in
/adb_keys. User-installed keys are stored in /data/misc/adb/adb_keys.
ADB Protocol change:
If the device needs to authenticate the host, it replies to CNXN
packets with an AUTH packet. The AUTH packet payload is a random token.
The host signs the token with one of its private keys and sends an AUTH(0)
packet. If the signature verification succeeds, the device replies with
a CNXN packet. Otherwise, it sends a new AUTH packet with a new token so
that the host can retry with another private key. Once the host has tried
all its keys, it can send an AUTH(1) packet with a public key as
payload. adbd then sends the public key to the framework (if it has been
started) for confirmation.
Change-Id: I4e84d7621da956f66ff657245901bdaefead8395
2012-04-13 03:23:49 +08:00
|
|
|
int online;
|
2009-03-04 11:32:55 +08:00
|
|
|
transport_type type;
|
|
|
|
|
|
|
|
/* usb handle or socket fd as needed */
|
|
|
|
usb_handle *usb;
|
|
|
|
int sfd;
|
|
|
|
|
|
|
|
/* used to identify transports for clients */
|
|
|
|
char *serial;
|
|
|
|
char *product;
|
2012-05-26 05:10:02 +08:00
|
|
|
char *model;
|
|
|
|
char *device;
|
2012-04-21 02:21:14 +08:00
|
|
|
char *devpath;
|
2010-04-26 17:17:43 +08:00
|
|
|
int adb_port; // Use for emulators (local transport)
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
/* a list of adisconnect callbacks called when the transport is kicked */
|
|
|
|
int kicked;
|
|
|
|
adisconnect disconnects;
|
adb: Add public key authentification
Secure adb using a public key authentication, to allow USB debugging
only from authorized hosts.
When a device is connected to an unauthorized host, the adb daemon sends
the user public key to the device. A popup is shown to ask the user to
allow debugging once or permanantly from the host. The public key is
installed on the device in the later case. Other keys may be installed
at build time.
On the host, the user public/private key pair is automatically generated,
if it does not exist, when the adb daemon starts and is stored in
$HOME/.android/adb_key(.pub) or in $ANDROID_SDK_HOME on windows. If needed,
the ADB_KEYS_PATH env variable may be set to a :-separated (; under
Windows) list of private keys, e.g. company-wide or vendor keys.
On the device, vendors public keys are installed at build time in
/adb_keys. User-installed keys are stored in /data/misc/adb/adb_keys.
ADB Protocol change:
If the device needs to authenticate the host, it replies to CNXN
packets with an AUTH packet. The AUTH packet payload is a random token.
The host signs the token with one of its private keys and sends an AUTH(0)
packet. If the signature verification succeeds, the device replies with
a CNXN packet. Otherwise, it sends a new AUTH packet with a new token so
that the host can retry with another private key. Once the host has tried
all its keys, it can send an AUTH(1) packet with a public key as
payload. adbd then sends the public key to the framework (if it has been
started) for confirmation.
Change-Id: I4e84d7621da956f66ff657245901bdaefead8395
2012-04-13 03:23:49 +08:00
|
|
|
|
|
|
|
void *key;
|
|
|
|
unsigned char token[TOKEN_SIZE];
|
|
|
|
fdevent auth_fde;
|
|
|
|
unsigned failed_auth_attempts;
|
2009-03-04 11:32:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* A listener is an entity which binds to a local port
|
|
|
|
** and, upon receiving a connection on that port, creates
|
|
|
|
** an asocket to connect the new local connection to a
|
|
|
|
** specific remote service.
|
|
|
|
**
|
|
|
|
** TODO: some listeners read from the new connection to
|
|
|
|
** determine what exact service to connect to on the far
|
|
|
|
** side.
|
|
|
|
*/
|
|
|
|
struct alistener
|
|
|
|
{
|
|
|
|
alistener *next;
|
|
|
|
alistener *prev;
|
|
|
|
|
|
|
|
fdevent fde;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
const char *local_name;
|
|
|
|
const char *connect_to;
|
|
|
|
atransport *transport;
|
|
|
|
adisconnect disconnect;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void print_packet(const char *label, apacket *p);
|
|
|
|
|
2013-12-13 21:09:44 +08:00
|
|
|
asocket *find_local_socket(unsigned local_id, unsigned remote_id);
|
2009-03-04 11:32:55 +08:00
|
|
|
void install_local_socket(asocket *s);
|
|
|
|
void remove_socket(asocket *s);
|
|
|
|
void close_all_sockets(atransport *t);
|
|
|
|
|
|
|
|
#define LOCAL_CLIENT_PREFIX "emulator-"
|
|
|
|
|
|
|
|
asocket *create_local_socket(int fd);
|
|
|
|
asocket *create_local_service_socket(const char *destination);
|
|
|
|
|
|
|
|
asocket *create_remote_socket(unsigned id, atransport *t);
|
|
|
|
void connect_to_remote(asocket *s, const char *destination);
|
|
|
|
void connect_to_smartsocket(asocket *s);
|
|
|
|
|
|
|
|
void fatal(const char *fmt, ...);
|
|
|
|
void fatal_errno(const char *fmt, ...);
|
|
|
|
|
|
|
|
void handle_packet(apacket *p, atransport *t);
|
|
|
|
void send_packet(apacket *p, atransport *t);
|
|
|
|
|
2009-10-21 23:55:00 +08:00
|
|
|
void get_my_path(char *s, size_t maxLen);
|
2010-04-19 19:21:12 +08:00
|
|
|
int launch_server(int server_port);
|
|
|
|
int adb_main(int is_daemon, int server_port);
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* transports are ref-counted
|
|
|
|
** get_device_transport does an acquire on your behalf before returning
|
|
|
|
*/
|
|
|
|
void init_transport_registration(void);
|
adb: Generalizing -s to take qualifiers.
Prior to this change, -s could take either a serial number or a
device path (e.g. "-s 01498B1F02015015" or "-s usb:1-4.2"). This
change extends -s to also allow product, model or device names
(e.g. "-s product:mysid"). These new qualifiers will only be
available on devices that are running an adb daemon that provides
properties in the connect message per Change-Id:
I09200decde4facb8fc9b4056fdae910155f2bcb9
The product, model and device are derived from the
ro.product.name, ro.product.model and ro.product.device
properties respectively. They are prefixed with "product:",
"model:" or "device:" as appropriate. In addition, any
non-alphanumerics in the model are changed to underscores.
If the -s parameter matches multiple devices, the result will be
the same as when multiple devices are connected but no -d, -e or
-s option is specified. In general, this means the user will get
"error: more than one device". However for get-state,
get-devpath and get-serialno, they will get "unknown".
The format of "devices -l" was changed to list all of the
qualifiers that are available. The following example output
(with the last digits of the serial numbers replaced with X's) is
with a Galaxy Prime with an older adb daemon and another Galaxy
Prime and Galaxy S both with the enhanced adb daemons:
List of devices attached
016B75D60A0060XX device usb:2-5 product:mysid model:Galaxy_Nexus device:toro
3731B535FAC200XX device usb:1-4.2 product:soju model:Nexus_S device:crespo
01498B1F020150XX device usb:1-4.1
Note that the serial number and state are now column oriented
instead of tab delimited. After the serial number and state, all
qualifiers are listed with each preceded by a space. The output
of the original devices command (without -l) is unchanged.
Change-Id: Iceeb2789874effc25a630d514a375d6f1889dc56
Signed-off-by: Scott Anderson <saa@android.com>
2012-05-31 09:11:27 +08:00
|
|
|
int list_transports(char *buf, size_t bufsize, int long_listing);
|
2009-03-04 11:32:55 +08:00
|
|
|
void update_transports(void);
|
|
|
|
|
|
|
|
asocket* create_device_tracker(void);
|
|
|
|
|
|
|
|
/* Obtain a transport from the available transports.
|
|
|
|
** If state is != CS_ANY, only transports in that state are considered.
|
|
|
|
** If serial is non-NULL then only the device with that serial will be chosen.
|
|
|
|
** If no suitable transport is found, error is set.
|
|
|
|
*/
|
|
|
|
atransport *acquire_one_transport(int state, transport_type ttype, const char* serial, char **error_out);
|
|
|
|
void add_transport_disconnect( atransport* t, adisconnect* dis );
|
|
|
|
void remove_transport_disconnect( atransport* t, adisconnect* dis );
|
|
|
|
void run_transport_disconnects( atransport* t );
|
|
|
|
void kick_transport( atransport* t );
|
|
|
|
|
|
|
|
/* initialize a transport object's func pointers and state */
|
2010-04-26 17:17:43 +08:00
|
|
|
#if ADB_HOST
|
|
|
|
int get_available_local_transport_index();
|
|
|
|
#endif
|
2009-08-25 06:58:40 +08:00
|
|
|
int init_socket_transport(atransport *t, int s, int port, int local);
|
2009-08-09 00:37:44 +08:00
|
|
|
void init_usb_transport(atransport *t, usb_handle *usb, int state);
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
/* for MacOS X cleanup */
|
|
|
|
void close_usb_devices();
|
|
|
|
|
|
|
|
/* cause new transports to be init'd and added to the list */
|
2013-03-30 09:22:36 +08:00
|
|
|
int register_socket_transport(int s, const char *serial, int port, int local);
|
2009-10-12 11:04:18 +08:00
|
|
|
|
2010-05-24 22:44:35 +08:00
|
|
|
/* these should only be used for the "adb disconnect" command */
|
2009-10-12 11:04:18 +08:00
|
|
|
void unregister_transport(atransport *t);
|
2010-05-24 22:44:35 +08:00
|
|
|
void unregister_all_tcp_transports();
|
2009-10-12 11:04:18 +08:00
|
|
|
|
2012-04-21 02:21:14 +08:00
|
|
|
void register_usb_transport(usb_handle *h, const char *serial, const char *devpath, unsigned writeable);
|
2009-08-09 00:37:44 +08:00
|
|
|
|
|
|
|
/* this should only be used for transports with connection_state == CS_NOPERM */
|
|
|
|
void unregister_usb_transport(usb_handle *usb);
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2009-10-12 11:04:18 +08:00
|
|
|
atransport *find_transport(const char *serial);
|
2010-04-26 17:17:43 +08:00
|
|
|
#if ADB_HOST
|
|
|
|
atransport* find_emulator_transport_by_adb_port(int adb_port);
|
|
|
|
#endif
|
2009-10-12 11:04:18 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
int service_to_fd(const char *name);
|
|
|
|
#if ADB_HOST
|
|
|
|
asocket *host_service_to_socket(const char* name, const char *serial);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !ADB_HOST
|
|
|
|
int init_jdwp(void);
|
|
|
|
asocket* create_jdwp_service_socket();
|
|
|
|
asocket* create_jdwp_tracker_service_socket();
|
|
|
|
int create_jdwp_connection_fd(int jdwp_pid);
|
|
|
|
#endif
|
|
|
|
|
2013-03-22 04:07:42 +08:00
|
|
|
int handle_forward_request(const char* service, transport_type ttype, char* serial, int reply_fd);
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
#if !ADB_HOST
|
|
|
|
void framebuffer_service(int fd, void *cookie);
|
2014-12-04 07:31:57 +08:00
|
|
|
// Allow enable-verity to write to system and vendor block devices
|
2015-01-02 21:30:50 +08:00
|
|
|
int make_block_device_writable(const char* dev);
|
2009-03-04 11:32:55 +08:00
|
|
|
void remount_service(int fd, void *cookie);
|
2014-12-04 07:31:57 +08:00
|
|
|
void set_verity_enabled_state_service(int fd, void* cookie);
|
2009-03-04 11:32:55 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* packet allocator */
|
|
|
|
apacket *get_apacket(void);
|
|
|
|
void put_apacket(apacket *p);
|
|
|
|
|
|
|
|
int check_header(apacket *p);
|
|
|
|
int check_data(apacket *p);
|
|
|
|
|
2014-08-16 00:51:27 +08:00
|
|
|
// Define it if you want to dump packets.
|
|
|
|
#define DEBUG_PACKETS 0
|
|
|
|
|
adb: Add public key authentification
Secure adb using a public key authentication, to allow USB debugging
only from authorized hosts.
When a device is connected to an unauthorized host, the adb daemon sends
the user public key to the device. A popup is shown to ask the user to
allow debugging once or permanantly from the host. The public key is
installed on the device in the later case. Other keys may be installed
at build time.
On the host, the user public/private key pair is automatically generated,
if it does not exist, when the adb daemon starts and is stored in
$HOME/.android/adb_key(.pub) or in $ANDROID_SDK_HOME on windows. If needed,
the ADB_KEYS_PATH env variable may be set to a :-separated (; under
Windows) list of private keys, e.g. company-wide or vendor keys.
On the device, vendors public keys are installed at build time in
/adb_keys. User-installed keys are stored in /data/misc/adb/adb_keys.
ADB Protocol change:
If the device needs to authenticate the host, it replies to CNXN
packets with an AUTH packet. The AUTH packet payload is a random token.
The host signs the token with one of its private keys and sends an AUTH(0)
packet. If the signature verification succeeds, the device replies with
a CNXN packet. Otherwise, it sends a new AUTH packet with a new token so
that the host can retry with another private key. Once the host has tried
all its keys, it can send an AUTH(1) packet with a public key as
payload. adbd then sends the public key to the framework (if it has been
started) for confirmation.
Change-Id: I4e84d7621da956f66ff657245901bdaefead8395
2012-04-13 03:23:49 +08:00
|
|
|
#if !DEBUG_PACKETS
|
2009-03-04 11:32:55 +08:00
|
|
|
#define print_packet(tag,p) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
2010-09-24 06:08:34 +08:00
|
|
|
#if ADB_HOST_ON_TARGET
|
|
|
|
/* adb and adbd are coexisting on the target, so use 5038 for adb
|
|
|
|
* to avoid conflicting with adbd's usage of 5037
|
|
|
|
*/
|
|
|
|
# define DEFAULT_ADB_PORT 5038
|
|
|
|
#else
|
|
|
|
# define DEFAULT_ADB_PORT 5037
|
|
|
|
#endif
|
|
|
|
|
2010-04-19 19:21:12 +08:00
|
|
|
#define DEFAULT_ADB_LOCAL_TRANSPORT_PORT 5555
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2009-05-22 08:47:43 +08:00
|
|
|
#define ADB_CLASS 0xff
|
|
|
|
#define ADB_SUBCLASS 0x42
|
|
|
|
#define ADB_PROTOCOL 0x1
|
2009-05-09 09:25:58 +08:00
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2009-08-27 03:50:22 +08:00
|
|
|
void local_init(int port);
|
2009-03-04 11:32:55 +08:00
|
|
|
int local_connect(int port);
|
2010-04-26 17:17:43 +08:00
|
|
|
int local_connect_arbitrary_ports(int console_port, int adb_port);
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
/* usb host/client interface */
|
|
|
|
void usb_init();
|
|
|
|
void usb_cleanup();
|
|
|
|
int usb_write(usb_handle *h, const void *data, int len);
|
|
|
|
int usb_read(usb_handle *h, void *data, int len);
|
|
|
|
int usb_close(usb_handle *h);
|
|
|
|
void usb_kick(usb_handle *h);
|
|
|
|
|
|
|
|
/* used for USB device detection */
|
2009-05-21 08:33:53 +08:00
|
|
|
#if ADB_HOST
|
2009-03-04 11:32:55 +08:00
|
|
|
int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_protocol);
|
2009-05-21 08:33:53 +08:00
|
|
|
#endif
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
int adb_commandline(int argc, char **argv);
|
|
|
|
|
|
|
|
int connection_state(atransport *t);
|
|
|
|
|
|
|
|
#define CS_ANY -1
|
|
|
|
#define CS_OFFLINE 0
|
|
|
|
#define CS_BOOTLOADER 1
|
|
|
|
#define CS_DEVICE 2
|
|
|
|
#define CS_HOST 3
|
|
|
|
#define CS_RECOVERY 4
|
2009-08-09 00:37:44 +08:00
|
|
|
#define CS_NOPERM 5 /* Insufficient permissions to communicate with the device */
|
2012-01-10 06:54:53 +08:00
|
|
|
#define CS_SIDELOAD 6
|
2013-01-16 04:36:47 +08:00
|
|
|
#define CS_UNAUTHORIZED 7
|
2009-03-04 11:32:55 +08:00
|
|
|
|
|
|
|
extern int HOST;
|
2011-03-17 06:57:42 +08:00
|
|
|
extern int SHELL_EXIT_NOTIFY_FD;
|
2009-03-04 11:32:55 +08:00
|
|
|
|
2014-05-27 09:30:43 +08:00
|
|
|
typedef enum {
|
|
|
|
SUBPROC_PTY = 0,
|
|
|
|
SUBPROC_RAW = 1,
|
|
|
|
} subproc_mode;
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
#define CHUNK_SIZE (64*1024)
|
|
|
|
|
2012-01-13 22:13:46 +08:00
|
|
|
#if !ADB_HOST
|
|
|
|
#define USB_ADB_PATH "/dev/android_adb"
|
|
|
|
|
|
|
|
#define USB_FFS_ADB_PATH "/dev/usb-ffs/adb/"
|
|
|
|
#define USB_FFS_ADB_EP(x) USB_FFS_ADB_PATH#x
|
|
|
|
|
|
|
|
#define USB_FFS_ADB_EP0 USB_FFS_ADB_EP(ep0)
|
|
|
|
#define USB_FFS_ADB_OUT USB_FFS_ADB_EP(ep1)
|
|
|
|
#define USB_FFS_ADB_IN USB_FFS_ADB_EP(ep2)
|
|
|
|
#endif
|
|
|
|
|
2009-03-04 11:32:55 +08:00
|
|
|
int sendfailmsg(int fd, const char *reason);
|
|
|
|
int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s);
|
|
|
|
|
|
|
|
#endif
|