diff --git a/src/connection/usb/xdbd_connection_usb.c b/src/connection/usb/xdbd_connection_usb.c index f034772..3b2b17b 100644 --- a/src/connection/usb/xdbd_connection_usb.c +++ b/src/connection/usb/xdbd_connection_usb.c @@ -3,6 +3,7 @@ #include #include #include +#include #define USB_ADB_PATH "/dev/adb/usb" #define USB_FFS_ADB_PATH "/dev/usb-ffs/adb/" @@ -129,7 +130,7 @@ struct adb_connection { }; static int -adb_init_send(struct adb_connection *conn) +usb_init_send(struct adb_connection *conn) { int retval; @@ -149,7 +150,7 @@ adb_init_send(struct adb_connection *conn) } static int -adb_init_connection(struct adb_connection *conn) +usb_init_connection(struct adb_connection *conn) { int retval; @@ -174,7 +175,7 @@ adb_init_connection(struct adb_connection *conn) } conn->bulk_in = retval; - retval = adb_init_send(conn); + retval = usb_init_send(conn); if (retval) { bfdev_log_err("adbd: init send failed\n"); goto failed; @@ -183,12 +184,33 @@ adb_init_connection(struct adb_connection *conn) return 0; failed: - if (conn->control) + if (conn->control >= 0) close(conn->control); - if (conn->bulk_out) + if (conn->bulk_out >= 0) close(conn->bulk_out); - if (conn->bulk_in) + if (conn->bulk_in >= 0) close(conn->bulk_in); + conn->control = -1; + conn->bulk_out = -1; + conn->bulk_in = -1; + return retval; } + +static int +usb_kick_timer(xdbd_timer_t *timer, void *pdata) +{ + struct adb_connection *conn; + int retval; + + conn = pdata; + retval = usb_init_connection(conn); + if (!retval) + return 0; + + bfdev_log_warn("adbd: usb kick timer retry\n"); + xdbd_add_timer(timer, 1000); + + return 0; +}