Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f3b9be1
fix: git status/git status --ignore normalization check problem
dengwenqi123 Oct 30, 2023
d6b1a7d
microADB: using timer to check usb hotplug event
Donny9 Nov 1, 2023
d096f23
microADB: setup timer when adbd run with usb plugout
Donny9 Nov 14, 2023
3fde409
microadb: fix used after free issue about handle close
Donny9 Nov 29, 2023
31f0b07
microADB: fix memory leaks when adbd exit
Donny9 Nov 30, 2023
e2fcaa6
microADB: using inotify to check usb hotplug event
Donny9 Dec 5, 2023
d021ceb
microADB: call service_close to send CLSE frame when child task exit
Donny9 Dec 14, 2023
cf9049b
microADB: avoid kick when read/write pipe had beed close
Donny9 Dec 14, 2023
a34e817
Send response before adb_reboot_impl()
JianyuWang0623 Jan 5, 2024
1f0a87c
hal_uv_client_usb.c: Call uv_write with one buffer instead two
xiaoxiang781216 Jan 5, 2024
9771f27
hal/hal_uv.c: Remove g_adbd_context global variable
xiaoxiang781216 Jan 6, 2024
6f95403
adb_client.c: Merge the handle of A_CNXN and A_AUTH to switch block
xiaoxiang781216 Jan 7, 2024
35c683a
Add on_ prefix to close_cb like other callback in adb_tcp_socket_s
xiaoxiang781216 Jan 7, 2024
bf816e1
Remove ID_QUIT handler from state_wait_cmd_data
xiaoxiang781216 Jan 7, 2024
c38ec55
Remove SYNC_TEMP_BUFF_SIZE check from state_process_send_sym and stat…
xiaoxiang781216 Jan 7, 2024
b23add5
Always report ID_DONE and ID_FAIL through syncmsg::status
xiaoxiang781216 Jan 7, 2024
a998092
Remove the assignment of client->socket.data
xiaoxiang781216 Jan 7, 2024
1d28038
Revert "hal_uv_client_usb.c: Call uv_write with one buffer instead two"
Donny9 Jan 9, 2024
861e8cb
Check whether client has services before close
JianyuWang0623 Jan 10, 2024
bc1fad4
microadb: using dents message to responde request "LIST"
Donny9 Jan 14, 2024
b62e148
adb/microadb: Copy packet to svc to prevent the current packet from b…
Donny9 Jan 15, 2024
86ec8aa
adb:do not send sigkill when shell close
guohao15 Mar 6, 2024
7f51157
microADB: Implement ADB function through qemu pipe (3/3)
Apr 23, 2024
19345e8
adb/microadb: Skip environment variables when exec logcat
JianyuWang0623 Apr 9, 2024
f4db1dd
adb: send close packet in on_child_exit method
yangsong8-a1 Jul 24, 2024
6a319a0
Revert "adb: send close packet in on_child_exit method"
yangsong8-a1 Jul 30, 2024
6888289
adb: only send close packet in on_child_exit method
yangsong8-a1 Jul 24, 2024
bb979b0
adb: check svc exiting flag in shell_write function
yangsong8-a1 Sep 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use another build folder with CMake, it doesn't have to be in the source folder.

@xiaoxiang781216 xiaoxiang781216 Oct 13, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spiriou I think this change is for Makefile only since NuttX Makefile based build system doesn't support the out of tree.

hal/*.o
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ project (adbd)

find_package(uv REQUIRED)

option(ADBD_USB_HOTPLUG_BYTIMER "adb usb hotplug check by timer" OFF)
option(ADBD_USB_HOTPLUG_BYNOTIFY "adb usb hotplug check by notify" OFF)

option(ADBD_AUTHENTICATION "adb authentication" OFF)
option(ADBD_AUTH_PUBKEY "adb auth public key" OFF)
option(ADBD_FILE_SERVICE "adb file sync service" ON)
Expand Down
4 changes: 3 additions & 1 deletion adb.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ void adb_send_okay_frame_with_data(adb_client_t *client, apacket *p,
unsigned local, unsigned remote);
void adb_send_open_frame(adb_client_t *client, apacket *p,
unsigned local, unsigned remote, int size);
void adb_send_close_frame(adb_client_t *client, apacket *p,
unsigned local, unsigned remote);
void adb_send_data_frame(adb_client_t *client, apacket *p);

int adb_check_frame_data(apacket *p);
Expand Down Expand Up @@ -215,7 +217,7 @@ int adb_hal_socket_connect(struct adb_client_s *client, adb_tcp_socket_t *socket
void (*on_connect_cb)(adb_tcp_socket_t*, int));

void adb_hal_socket_close(adb_tcp_socket_t *socket,
void (*close_cb)(adb_tcp_socket_t*));
void (*on_close_cb)(adb_tcp_socket_t*));

int adb_hal_socket_write(adb_tcp_socket_t *socket, struct apacket_s *p,
void (*cb)(struct adb_client_s*, adb_tcp_socket_t*, struct apacket_s*, bool fail));
Expand Down
67 changes: 28 additions & 39 deletions adb_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
#include "tcp_service.h"
#endif

#define REBOOT_SERVICE ((adb_service_t *)(~0ul))

/****************************************************************************
* Private Function Prototypes
****************************************************************************/

static void send_frame(adb_client_t *s, apacket *p);
static void send_close_frame(adb_client_t *s, apacket *p,
unsigned local, unsigned remote);
static void send_cnxn_frame(adb_client_t *s, apacket *p);

#ifdef CONFIG_ADBD_AUTHENTICATION
Expand Down Expand Up @@ -69,7 +69,7 @@ static void send_frame(adb_client_t *client, apacket *p)
p->msg.magic = p->msg.command ^ 0xffffffff;

count = p->msg.data_length;
x = (unsigned char *) p->data;
x = (unsigned char *)p->data;
sum = 0;
while(count-- > 0){
sum += *x++;
Expand All @@ -85,17 +85,6 @@ static void send_frame(adb_client_t *client, apacket *p)
}
}

static void send_close_frame(adb_client_t *client, apacket *p,
unsigned local, unsigned remote)
{
p->msg.command = A_CLSE;
p->msg.arg0 = local;
p->msg.arg1 = remote;
p->msg.data_length = 0;
p->write_len = 0;
send_frame(client, p);
}

static void send_cnxn_frame(adb_client_t *client, apacket *p)
{
p->msg.command = A_CNXN;
Expand Down Expand Up @@ -133,7 +122,7 @@ static void send_auth_request(adb_client_t *client, apacket *p)

static void handle_open_frame(adb_client_t *client, apacket *p) {
adb_service_t *svc;
char *name = (char*) p->data;
char *name = (char*)p->data;

/* OPEN(local-id, 0, "destination") */
if (p->msg.arg0 == 0 || p->msg.arg1 != 0) {
Expand All @@ -150,9 +139,9 @@ static void handle_open_frame(adb_client_t *client, apacket *p) {
p->msg.arg0);
}
else {
send_close_frame(client, p, 0, p->msg.arg0);
adb_send_close_frame(client, p, 0, p->msg.arg0);
}
} else {
} else if (svc != REBOOT_SERVICE) {
if (p->write_len == APACKET_SERVICE_INIT_ASYNC) {
/* Service init is asynchronous. Release apacket. */
adb_hal_apacket_release(client, p);
Expand Down Expand Up @@ -181,7 +170,7 @@ static void handle_write_frame(adb_client_t *client, apacket *p) {
svc = adb_client_find_service(client, p->msg.arg1, p->msg.arg0);
if (svc == NULL) {
/* Ensure service is closed on peer side */
send_close_frame(client, p, p->msg.arg1, p->msg.arg0);
adb_send_close_frame(client, p, p->msg.arg1, p->msg.arg0);
return;
}

Expand All @@ -207,7 +196,7 @@ static void handle_okay_frame(adb_client_t *client, apacket *p) {
adb_service_t *svc;
svc = adb_client_find_service(client, p->msg.arg1, 0);
if (!svc) {
send_close_frame(client, p, p->msg.arg1, p->msg.arg0);
adb_hal_apacket_release(client, p);
return;
}

Expand Down Expand Up @@ -324,6 +313,17 @@ void adb_send_open_frame(adb_client_t *client, apacket *p,
send_frame(client, p);
}

void adb_send_close_frame(adb_client_t *client, apacket *p,
unsigned local, unsigned remote)
{
p->msg.command = A_CLSE;
p->msg.arg0 = local;
p->msg.arg1 = remote;
p->msg.data_length = 0;
p->write_len = 0;
send_frame(client, p);
}

void adb_send_data_frame(adb_client_t *client, apacket *p)
{
p->msg.command = A_WRTE;
Expand All @@ -343,8 +343,6 @@ static adb_service_t *adb_service_open(adb_client_t *client, const char *name, a
{
adb_service_t *svc = NULL;

UNUSED(p);

if (client->next_service_id == 0) {
/* service id overflow, exit */
fatal("service_id overflow");
Expand All @@ -371,7 +369,7 @@ static adb_service_t *adb_service_open(adb_client_t *client, const char *name, a
/* Search for logcat */
char *ptr = strstr(name, "exec logcat");
if (ptr) {
svc = logcat_service(client, name);
svc = logcat_service(client, ptr);
break;
}
#endif /* CONFIG_ADBD_LOGCAT_SERVICE */
Expand All @@ -383,10 +381,9 @@ static adb_service_t *adb_service_open(adb_client_t *client, const char *name, a
#endif

if (!strncmp(name, "reboot:", 7)) {
adb_send_okay_frame(client, p, client->next_service_id++, p->msg.arg0);
adb_reboot_impl(&name[7]);

/* One shot service, skip service register */
return NULL;
return REBOOT_SERVICE;
}
} while (0);

Expand All @@ -408,7 +405,7 @@ void adb_service_close(adb_client_t *client, adb_service_t *svc, apacket *p) {
goto exit_free_service;
}

while (cur_svc->next) {
while (cur_svc != NULL && cur_svc->next != NULL) {
if (cur_svc->next == svc) {
cur_svc->next = svc->next;
goto exit_free_service;
Expand All @@ -421,7 +418,7 @@ void adb_service_close(adb_client_t *client, adb_service_t *svc, apacket *p) {

exit_free_service:
if (p) {
send_close_frame(client, p, svc->id, svc->peer_id);
adb_send_close_frame(client, p, svc->id, svc->peer_id);
}
svc->ops->on_close(svc);
}
Expand Down Expand Up @@ -484,7 +481,8 @@ void adb_process_packet(adb_client_t *client, apacket *p)
{
p->write_len = 0;

if (p->msg.command == A_CNXN) {
switch(p->msg.command) {
case A_CNXN:
/* CONNECT(version, maxdata, "system-id-string") */
#ifdef CONFIG_ADBD_AUTHENTICATION
if (!client->is_connected) {
Expand All @@ -495,22 +493,16 @@ void adb_process_packet(adb_client_t *client, apacket *p)
send_cnxn_frame(client, p);
client->is_connected = 1;
return;
}

#ifdef CONFIG_ADBD_AUTHENTICATION
if (p->msg.command == A_AUTH) {
case A_AUTH:
if (!client->is_connected) {
handle_auth_frame(client, p);
return;
}

goto invalid_frame;
}
break;
#endif /* CONFIG_ADBD_AUTHENTICATION */

/* Client is connected */

switch(p->msg.command) {
case A_OPEN:
handle_open_frame(client, p);
return;
Expand All @@ -531,9 +523,6 @@ void adb_process_packet(adb_client_t *client, apacket *p)
break;
}

#ifdef CONFIG_ADBD_AUTHENTICATION
invalid_frame:
#endif
adb_log("handle_packet: what is %08x?!\n", p->msg.command);
adb_hal_apacket_release(client, p);
client->ops->close(client);
Expand Down
64 changes: 39 additions & 25 deletions file_sync_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#define ID_FAIL MKID('F','A','I','L')
#define ID_QUIT MKID('Q','U','I','T')

#define min(a,b) ((a) < (b) ? (a):(b))
#define min(a,b) ((a) < (b) ? (a) : (b))

#define SYNC_TEMP_BUFF_SIZE PATH_MAX

Expand Down Expand Up @@ -99,6 +99,7 @@ enum {
typedef struct afs_service_s {
adb_service_t service;
uint8_t *packet_ptr;
uint8_t *payload;

uint8_t state;
unsigned cmd;
Expand All @@ -125,7 +126,7 @@ typedef struct afs_service_s {
};

unsigned size;
char buff[SYNC_TEMP_BUFF_SIZE];
char buff[SYNC_TEMP_BUFF_SIZE + 1];
} afs_service_t;

/****************************************************************************
Expand Down Expand Up @@ -188,13 +189,13 @@ static void prepare_fail_message(afs_service_t *svc, apacket *p, const char *rea
adb_err("sync: failure: %s\n", reason);

len = min(strlen(reason),
CONFIG_ADBD_PAYLOAD_SIZE - sizeof(msg->data) - p->write_len);
memcpy((char*)(&msg->data+1), reason, len);
CONFIG_ADBD_PAYLOAD_SIZE - sizeof(msg->status) - p->write_len);
memcpy((char*)(&msg->status+1), reason, len);

msg->data.id = ID_FAIL;
msg->data.size = htoll(len);
msg->status.id = ID_FAIL;
msg->status.msglen = htoll(len);

p->write_len += sizeof(msg->data) + len;
p->write_len += sizeof(msg->status) + len;
}

static void prepare_fail_errno(afs_service_t *svc, apacket *p)
Expand Down Expand Up @@ -262,6 +263,23 @@ static int create_path_directories(char *name)
return 0;
}

static uint8_t *get_payload(afs_service_t *svc, apacket *p)
{
if (svc->size > 0) {
if (svc->payload == NULL) {
svc->payload = malloc(CONFIG_ADBD_PAYLOAD_SIZE);
if (svc->payload == NULL) {
return NULL;
}
}

memcpy(svc->payload, p->data, p->msg.data_length);
return svc->payload;
}

return p->data;
}

static void state_reset(afs_service_t *svc)
{
switch (svc->state) {
Expand Down Expand Up @@ -582,11 +600,6 @@ static int state_process_send_sym(afs_service_t *svc, apacket *p) {
return 0;
}

if (svc->namelen >= SYNC_TEMP_BUFF_SIZE) {
prepare_fail_message(svc, p, "symlink target too long");
return 0;
}

svc->buff[svc->namelen] = 0;
ret = symlink(svc->buff, svc->send_link.path);

Expand Down Expand Up @@ -694,10 +707,6 @@ static int state_wait_cmd_data(afs_service_t *svc, apacket *p)
return -1;
}

if (svc->namelen >= SYNC_TEMP_BUFF_SIZE) {
return -1;
}

svc->buff[svc->namelen] = 0;

switch(svc->cmd) {
Expand All @@ -714,11 +723,6 @@ static int state_wait_cmd_data(afs_service_t *svc, apacket *p)
ret = state_init_recv(svc, p);
break;

case ID_QUIT:
// adb_log("got QUIT command\n");
ret = 0;
break;

default:
adb_err("Unexpected command 0x%x\n", svc->cmd);
ret = -1;
Expand All @@ -730,7 +734,7 @@ static int state_wait_cmd_data(afs_service_t *svc, apacket *p)
static int file_sync_on_write(adb_service_t *service, apacket *p) {
int ret = 0;
afs_service_t *svc = container_of(service, afs_service_t, service);
svc->packet_ptr = p->data;
svc->packet_ptr = get_payload(svc, p);

/* Process all packet data */

Expand Down Expand Up @@ -779,7 +783,7 @@ static int file_sync_on_write(adb_service_t *service, apacket *p) {
static int file_sync_on_ack(adb_service_t *service, apacket *p) {
int ret;
afs_service_t *svc = container_of(service, afs_service_t, service);
svc->packet_ptr = p->data;
svc->packet_ptr = get_payload(svc, p);

/* No data in notify packet */
switch (svc->state) {
Expand All @@ -791,11 +795,19 @@ static int file_sync_on_ack(adb_service_t *service, apacket *p) {
ret = state_process_list(svc, p);
break;

case AFS_STATE_PROCESS_SEND_FILE_DATA:
case AFS_STATE_PROCESS_SEND_FILE_HDR:
case AFS_STATE_PROCESS_SEND_SYM_HDR:
case AFS_STATE_WAIT_CMD_DATA:
case AFS_STATE_WAIT_CMD:
/* Nothing to do */
ret = 0;
/* Since the WRITE frame can contain multiple incomplete
* combinations of ID_SEND and ID_DONE, when the pc replies to ID_DONE,
* the OKAY frame sent can be at any time in the state machine.
* At this time, we should not reset the state machine and continue
* to process the next frame status.
*/

ret = 1;
break;

default:
Expand All @@ -817,6 +829,7 @@ static int file_sync_on_ack(adb_service_t *service, apacket *p) {
static void file_sync_on_close(struct adb_service_s *service) {
afs_service_t *svc = container_of(service, afs_service_t, service);
state_reset(svc);
free(svc->payload);
free(svc);
}

Expand All @@ -842,6 +855,7 @@ adb_service_t* file_sync_service(const char *params)
}

service->size = 0;
service->payload = NULL;
service->state = AFS_STATE_WAIT_CMD;
service->service.ops = &file_sync_ops;

Expand Down
Loading