123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- #ifndef __ADB_H
- #define __ADB_H
- #include <limits.h>
- #include <stdint.h>
- #include <sys/types.h>
- #include <string>
- #include <android-base/macros.h>
- #include "adb_trace.h"
- #include "fdevent.h"
- #include "socket.h"
- #include "types.h"
- #include "usb.h"
- constexpr size_t MAX_PAYLOAD_V1 = 4 * 1024;
- constexpr size_t MAX_PAYLOAD = 1024 * 1024;
- constexpr size_t MAX_FRAMEWORK_PAYLOAD = 64 * 1024;
- constexpr size_t LINUX_MAX_SOCKET_SIZE = 4194304;
- #define A_SYNC 0x434e5953
- #define A_CNXN 0x4e584e43
- #define A_OPEN 0x4e45504f
- #define A_OKAY 0x59414b4f
- #define A_CLSE 0x45534c43
- #define A_WRTE 0x45545257
- #define A_AUTH 0x48545541
- #define A_VERSION_MIN 0x01000000
- #define A_VERSION_SKIP_CHECKSUM 0x01000001
- #define A_VERSION 0x01000001
- #define ADB_VERSION_MAJOR 1
- #define ADB_VERSION_MINOR 0
- std::string adb_version();
- #define ADB_SERVER_VERSION 41
- using TransportId = uint64_t;
- class atransport;
- uint32_t calculate_apacket_checksum(const apacket* packet);
- struct adisconnect {
- void (*func)(void* opaque, atransport* t);
- void* opaque;
- };
- enum TransportType {
- kTransportUsb,
- kTransportLocal,
- kTransportAny,
- kTransportHost,
- };
- #define TOKEN_SIZE 20
- enum ConnectionState {
- kCsAny = -1,
- kCsConnecting = 0,
- kCsAuthorizing,
- kCsUnauthorized,
- kCsNoPerm,
- kCsOffline,
- kCsBootloader,
- kCsDevice,
- kCsHost,
- kCsRecovery,
- kCsSideload,
- kCsRescue,
- };
- inline bool ConnectionStateIsOnline(ConnectionState state) {
- switch (state) {
- case kCsBootloader:
- case kCsDevice:
- case kCsHost:
- case kCsRecovery:
- case kCsSideload:
- case kCsRescue:
- return true;
- default:
- return false;
- }
- }
- void print_packet(const char* label, apacket* p);
- void handle_packet(apacket* p, atransport* t);
- int launch_server(const std::string& socket_spec);
- int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply_fd);
- int init_socket_transport(atransport* t, unique_fd s, int port, int local);
- void init_usb_transport(atransport* t, usb_handle* usb);
- std::string getEmulatorSerialString(int console_port);
- #if ADB_HOST
- atransport* find_emulator_transport_by_adb_port(int adb_port);
- atransport* find_emulator_transport_by_console_port(int console_port);
- #endif
- unique_fd service_to_fd(std::string_view name, atransport* transport);
- #if !ADB_HOST
- unique_fd daemon_service_to_fd(std::string_view name, atransport* transport);
- #endif
- #if ADB_HOST
- asocket* host_service_to_socket(std::string_view name, std::string_view serial,
- TransportId transport_id);
- #endif
- #if !ADB_HOST
- asocket* daemon_service_to_socket(std::string_view name);
- #endif
- #if !ADB_HOST
- unique_fd execute_abb_command(std::string_view command);
- #endif
- #if !ADB_HOST
- int init_jdwp(void);
- asocket* create_jdwp_service_socket();
- asocket* create_jdwp_tracker_service_socket();
- unique_fd create_jdwp_connection_fd(int jdwp_pid);
- #endif
- bool handle_forward_request(const char* service, atransport* transport, int reply_fd);
- bool handle_forward_request(const char* service,
- std::function<atransport*(std::string* error)> transport_acquirer,
- int reply_fd);
- apacket* get_apacket(void);
- void put_apacket(apacket* p);
- #define DEBUG_PACKETS 0
- #if !DEBUG_PACKETS
- #define print_packet(tag, p) \
- do { \
- } while (0)
- #endif
- #if ADB_HOST_ON_TARGET
- #define DEFAULT_ADB_PORT 5038
- #else
- #define DEFAULT_ADB_PORT 5037
- #endif
- #define DEFAULT_ADB_LOCAL_TRANSPORT_PORT 5555
- #define ADB_CLASS 0xff
- #define ADB_SUBCLASS 0x42
- #define ADB_PROTOCOL 0x1
- void local_init(int port);
- bool local_connect(int port);
- int local_connect_arbitrary_ports(int console_port, int adb_port, std::string* error);
- ConnectionState connection_state(atransport* t);
- extern const char* adb_device_banner;
- #define CHUNK_SIZE (64 * 1024)
- #define ABB_ARG_DELIMETER ('\0')
- #if !ADB_HOST
- #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 (access("/.cell", F_OK) == 0?"/adb/ep0":"/dev/usb-ffs/adb/ep0")
- #define USB_FFS_ADB_OUT (access("/.cell", F_OK) == 0?"/adb/ep1":"/dev/usb-ffs/adb/ep1")
- #define USB_FFS_ADB_IN (access("/.cell", F_OK) == 0?"/adb/ep2":"/dev/usb-ffs/adb/ep2")
- #endif
- enum class HostRequestResult {
- Handled,
- SwitchedTransport,
- Unhandled,
- };
- HostRequestResult handle_host_request(std::string_view service, TransportType type,
- const char* serial, TransportId transport_id, int reply_fd,
- asocket* s);
- void handle_online(atransport* t);
- void handle_offline(atransport* t);
- void send_connect(atransport* t);
- void parse_banner(const std::string&, atransport* t);
- void adb_notify_device_scan_complete();
- void update_transport_status();
- void adb_wait_for_device_initialization();
- #endif
|