diff --git a/adb/adb.c b/adb/adb.c index 949e5ea42..530a4c8df 100644 --- a/adb/adb.c +++ b/adb/adb.c @@ -326,7 +326,7 @@ static void send_connect(atransport *t) send_packet(cp, t); } -static void send_auth_request(atransport *t) +void send_auth_request(atransport *t) { D("Calling send_auth_request\n"); apacket *p; diff --git a/adb/adb_auth.h b/adb/adb_auth.h index 96f637b9e..b24c67413 100644 --- a/adb/adb_auth.h +++ b/adb/adb_auth.h @@ -20,6 +20,8 @@ void adb_auth_init(void); void adb_auth_verified(atransport *t); +void send_auth_request(atransport *t); + /* AUTH packets first argument */ /* Request */ #define ADB_AUTH_TOKEN 1 diff --git a/adb/adb_auth_client.c b/adb/adb_auth_client.c index a4ad18fd9..efc49ebb5 100644 --- a/adb/adb_auth_client.c +++ b/adb/adb_auth_client.c @@ -43,6 +43,10 @@ static char *key_paths[] = { static fdevent listener_fde; static int framework_fd = -1; +static void usb_disconnected(void* unused, atransport* t); +static struct adisconnect usb_disconnect = { usb_disconnected, 0, 0, 0 }; +static atransport* usb_transport; +static bool needs_retry = false; static void read_keys(const char *file, struct listnode *list) { @@ -155,21 +159,30 @@ int adb_auth_verify(void *token, void *sig, int siglen) return ret; } +static void usb_disconnected(void* unused, atransport* t) +{ + D("USB disconnect"); + remove_transport_disconnect(usb_transport, &usb_disconnect); + usb_transport = NULL; + needs_retry = false; +} + static void adb_auth_event(int fd, unsigned events, void *data) { - atransport *t = data; char response[2]; int ret; if (events & FDE_READ) { ret = unix_read(fd, response, sizeof(response)); if (ret < 0) { - D("Disconnect"); - fdevent_remove(&t->auth_fde); + D("Framework disconnect"); + if (usb_transport) + fdevent_remove(&usb_transport->auth_fde); framework_fd = -1; } else if (ret == 2 && response[0] == 'O' && response[1] == 'K') { - adb_auth_verified(t); + if (usb_transport) + adb_auth_verified(usb_transport); } } } @@ -179,8 +192,12 @@ void adb_auth_confirm_key(unsigned char *key, size_t len, atransport *t) char msg[MAX_PAYLOAD]; int ret; + usb_transport = t; + add_transport_disconnect(t, &usb_disconnect); + if (framework_fd < 0) { D("Client not connected\n"); + needs_retry = true; return; } @@ -221,6 +238,11 @@ static void adb_auth_listener(int fd, unsigned events, void *data) } framework_fd = s; + + if (needs_retry) { + needs_retry = false; + send_auth_request(usb_transport); + } } void adb_auth_init(void)