Skip to content

Commit

Permalink
feat framewwork: add xdbd framwork support
Browse files Browse the repository at this point in the history
  • Loading branch information
ffashion committed Feb 29, 2024
1 parent 3ba6458 commit 1746e6d
Show file tree
Hide file tree
Showing 18 changed files with 966 additions and 54 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ set(SRCS
${PROJECT_SOURCE_DIR}/src/xdbd.c
${PROJECT_SOURCE_DIR}/src/adb/adb.c
${PROJECT_SOURCE_DIR}/src/adb/xdbd_adb.c
${PROJECT_SOURCE_DIR}/src/adb/xdbd_adb_request.c
${PROJECT_SOURCE_DIR}/src/adb/command.c
${PROJECT_SOURCE_DIR}/src/adb/packet.c
${PROJECT_SOURCE_DIR}/src/connection/connection.c
${PROJECT_SOURCE_DIR}/src/event/xdbd_event.c
${PROJECT_SOURCE_DIR}/src/event/select/xdbd_select.c
${PROJECT_SOURCE_DIR}/src/core/xdbd_pool.c
${PROJECT_SOURCE_DIR}/src/core/xdbd_buf.c
)

set(
Expand Down
5 changes: 2 additions & 3 deletions include/xdbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@

#define xdbd_msec_t unsigned

typedef struct adb_command_s adb_command_t;
typedef struct adb_packet_s adb_packet_t;
typedef struct xdbd_connection_s xdbd_connection_t;
typedef struct xdbd_listening_s xdbd_listening_t;
typedef struct xdbd_event_s xdbd_event_t;
typedef struct adb_pcmd_s adb_pcmd_t;
typedef struct xdbd_buf_s xdbd_buf_t;

typedef struct xdbd_s xdbd_t;

Expand All @@ -49,6 +47,7 @@ struct xdbd_s {
#define xdbd_memcpy(dst, src, n) (void) memcpy(dst, src, n)
#define xdbd_cpymem(dst, src, n) (((u_char *) memcpy(dst, src, n)) + (n))

#define xdbd_cpymem(dst, src, n) (((u_char *) memcpy(dst, src, n)) + (n))

/*socket*/
#define xdbd_socket socket
Expand Down
17 changes: 17 additions & 0 deletions src/adb/adb.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@
#include <stdbool.h>
#include <xdbd.h>

typedef struct adb_command_s adb_command_t;
typedef struct adb_pcmd_s adb_pcmd_t;
typedef struct xdbd_adb_header_s xdbd_adb_header_t;
typedef struct xdbd_adb_packet_s xdbd_adb_packet_t;
typedef struct xdbd_adb_request_s xdbd_adb_request_t;
// https://android.googlesource.com/platform/packages/modules/adb/+/master/protocol.txt

/* AUTH packets first argument */
/* Request */
#define ADB_AUTH_TOKEN 1
/* Response */
#define ADB_AUTH_SIGNATURE 2
#define ADB_AUTH_RSAPUBLICKEY 3

#define ADB_VERSION_MIN 0x01000000
#define ADB_VERSION_SKIP_CHECKSUM 0x01000001
#define ADB_VERSION 0x01000001


enum TransportType {
kTransportUsb,
kTransportLocal,
Expand Down
65 changes: 61 additions & 4 deletions src/adb/command.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,67 @@
#include <adb.h>
#include <bfdev/macro.h>
#include <string.h>
#include <xdbd.h>
#include <command.h>
#include <stdlib.h>
#include <packet.h>
#include <xdbd_buf.h>
#include <xdbd_adb.h>
#include <xdbd_string.h>

adb_command_t adb_cmds[] = {
int xdbd_process_shell_cmd(xdbd_adb_request_t *r, xdbd_adb_packet_t *p, const adb_command_t *cmd);

static adb_command_t adb_cmds[] = {
{
.cmd = "shell",
.handler = NULL,
.cmd = xdbd_string("shell"),
.handler = xdbd_process_shell_cmd,
},
};

int xdbd_process_shell_cmd(xdbd_adb_request_t *r, xdbd_adb_packet_t *p, const adb_command_t *cmd) {
xdbd_adb_packet_t *out;

out = xdbd_palloc(r->pool, sizeof(xdbd_adb_packet_t));
if (out == NULL) {
return XDBD_ERR;
}

out->payload = xdbd_create_buf(r->pool, ADB_MAX_PACKET_SIZE);
if (out->payload == NULL) {
return XDBD_ERR;
}

bfdev_log_info("shell_cmd: send okay packet\n");
xdbd_okey_packet(r, out);

xdbd_buf_append_mem(r->out, r->pool, &out->header, sizeof(xdbd_adb_header_t));
xdbd_buf_append_buf(r->out, r->pool, out->payload);

return XDBD_OK;
}

int xddb_process_cmd(xdbd_adb_request_t *r, xdbd_adb_packet_t *p) {
size_t i;
const xdbd_adb_header_t *h;
const adb_command_t *cmd;
const xdbd_buf_t *paylod;

h = &p->header;
paylod = p->payload;
for (i = 0; i < BFDEV_ARRAY_SIZE(adb_cmds); i++) {
cmd = &adb_cmds[i];

/*FIME: parse the payload to cmd and argv*/
/*
if (cmd->cmd.size != h->dlen) {
continue;
}
if (strncmp((const char *)cmd->cmd.data, (const char *)paylod->pos, h->dlen) != 0) {
continue;
}
*/
return cmd->handler(r, p, cmd);
}

return XDBD_ERR;
}
6 changes: 4 additions & 2 deletions src/adb/command.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#ifndef __COMMAND__H__
#define __COMMAND__H__

#include <xdbd_string.h>
#include <adb.h>

typedef int (*adb_cmd_pt)(const char *cmd);
typedef int (*adb_cmd_pt)(xdbd_adb_request_t *r, xdbd_adb_packet_t *p, const adb_command_t *cmd);


struct adb_command_s {
const char *cmd;
xdbd_str_t cmd;
adb_cmd_pt handler;
};

int xddb_process_cmd(xdbd_adb_request_t *r, xdbd_adb_packet_t *p);

#endif /*__COMMAND__H__*/
Loading

0 comments on commit 1746e6d

Please sign in to comment.