Skip to content

Commit

Permalink
feat usb: added kick timer
Browse files Browse the repository at this point in the history
Signed-off-by: John Sanpe <[email protected]>
  • Loading branch information
sanpeqf committed Jun 9, 2024
1 parent e30a97b commit ae0714e
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/connection/usb/xdbd_connection_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <sys/fcntl.h>
#include <xdbd_connection_usb.h>
#include <linux/usb/ch9.h>
#include <xdbd_timer.h>

#define USB_ADB_PATH "/dev/adb/usb"
#define USB_FFS_ADB_PATH "/dev/usb-ffs/adb/"
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
}

0 comments on commit ae0714e

Please sign in to comment.