diff --git a/adb/adb.cpp b/adb/adb.cpp index 6b30be884..0e3889762 100644 --- a/adb/adb.cpp +++ b/adb/adb.cpp @@ -240,7 +240,10 @@ void send_connect(atransport* t) { D("Calling send_connect"); apacket* cp = get_apacket(); cp->msg.command = A_CNXN; - cp->msg.arg0 = t->get_protocol_version(); + // Send the max supported version, but because the transport is + // initialized to A_VERSION_MIN, this will be compatible with every + // device. + cp->msg.arg0 = A_VERSION; cp->msg.arg1 = t->get_max_payload(); std::string connection_str = get_connection_string(); diff --git a/adb/adb.h b/adb/adb.h index 3651413e1..21e5d4b02 100644 --- a/adb/adb.h +++ b/adb/adb.h @@ -44,7 +44,12 @@ constexpr size_t LINUX_MAX_SOCKET_SIZE = 4194304; #define A_AUTH 0x48545541 // ADB protocol version. -#define A_VERSION 0x01000000 +// Version revision: +// 0x01000000: original +// 0x01000001: skip checksum (Dec 2017) +#define A_VERSION_MIN 0x01000000 +#define A_VERSION_SKIP_CHECKSUM 0x01000001 +#define A_VERSION 0x01000001 // Used for help/version information. #define ADB_VERSION_MAJOR 1 @@ -53,7 +58,7 @@ constexpr size_t LINUX_MAX_SOCKET_SIZE = 4194304; std::string adb_version(); // Increment this when we want to force users to start a new adb server. -#define ADB_SERVER_VERSION 39 +#define ADB_SERVER_VERSION 40 using TransportId = uint64_t; class atransport; diff --git a/adb/transport.cpp b/adb/transport.cpp index 089a1ecf4..5cf2450a6 100644 --- a/adb/transport.cpp +++ b/adb/transport.cpp @@ -163,7 +163,12 @@ static void transport_socket_events(int fd, unsigned events, void* _t) { void send_packet(apacket* p, atransport* t) { p->msg.magic = p->msg.command ^ 0xffffffff; - p->msg.data_check = calculate_apacket_checksum(p); + // compute a checksum for connection/auth packets for compatibility reasons + if (t->get_protocol_version() >= A_VERSION_SKIP_CHECKSUM) { + p->msg.data_check = 0; + } else { + p->msg.data_check = calculate_apacket_checksum(p); + } print_packet("send", p); @@ -1089,10 +1094,6 @@ bool check_header(apacket* p, atransport* t) { return true; } -bool check_data(apacket* p) { - return calculate_apacket_checksum(p) == p->msg.data_check; -} - #if ADB_HOST std::shared_ptr atransport::NextKey() { if (keys_.empty()) keys_ = adb_auth_get_private_keys(); diff --git a/adb/transport.h b/adb/transport.h index 8c101fdc5..86cd9928c 100644 --- a/adb/transport.h +++ b/adb/transport.h @@ -66,7 +66,9 @@ class atransport { atransport(ConnectionState state = kCsOffline) : id(NextTransportId()), connection_state_(state) { transport_fde = {}; - protocol_version = A_VERSION; + // Initialize protocol to min version for compatibility with older versions. + // Version will be updated post-connect. + protocol_version = A_VERSION_MIN; max_payload = MAX_PAYLOAD; } virtual ~atransport() {} @@ -223,7 +225,6 @@ int register_socket_transport(int s, const char* serial, int port, int local); void unregister_usb_transport(usb_handle* usb); bool check_header(apacket* p, atransport* t); -bool check_data(apacket* p); void close_usb_devices(); void close_usb_devices(std::function predicate); diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp index 9cd378cad..d6c84dac5 100644 --- a/adb/transport_local.cpp +++ b/adb/transport_local.cpp @@ -77,11 +77,6 @@ static int remote_read(apacket *p, atransport *t) return -1; } - if (!check_data(p)) { - D("bad data: terminated (data)"); - return -1; - } - return 0; } diff --git a/adb/transport_usb.cpp b/adb/transport_usb.cpp index c3ac34479..347482016 100644 --- a/adb/transport_usb.cpp +++ b/adb/transport_usb.cpp @@ -109,10 +109,6 @@ static int remote_read(apacket* p, atransport* t) { goto err_msg; } } - if (!check_data(p)) { - D("remote usb: check_data failed, skip it"); - goto err_msg; - } return 0; err_msg: @@ -143,11 +139,6 @@ static int remote_read(apacket *p, atransport *t) } } - if (!check_data(p)) { - LOG(ERROR) << "remote usb: check_data failed"; - return -1; - } - return 0; } #endif