From 774d10286fdec794b88830ca2755fceddb2537d8 Mon Sep 17 00:00:00 2001 From: Richard Acayan Date: Thu, 5 Jan 2023 22:40:17 -0500 Subject: [PATCH] fastrpc: move fastrpc reverse tunnel to its own file The rpcd.c file is bloating a bit. Move the reverse tunnel into its own file so the RPC handlers won't be cluttered in this single file. --- fastrpc/listener.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ fastrpc/rpcd.c | 45 +++------------------------- 2 files changed, 78 insertions(+), 41 deletions(-) create mode 100644 fastrpc/listener.c diff --git a/fastrpc/listener.c b/fastrpc/listener.c new file mode 100644 index 0000000..d790ffe --- /dev/null +++ b/fastrpc/listener.c @@ -0,0 +1,74 @@ +/* + * FastRPC reverse tunnel + * + * Copyright (C) 2023 Richard Acayan + * + * This file is part of sensh. + * + * Sensh is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "fastrpc.h" +#include "fastrpc_adsp_listener.h" + +static int adsp_listener_init2(int fd) +{ + return fastrpc2(&adsp_listener_init2_def, fd, ADSP_LISTENER_HANDLE); +} + +static int adsp_listener_next2(int fd, + uint32_t ret_rctx, + uint32_t ret_res, + uint32_t ret_outbuf_len, void *ret_outbuf, + uint32_t *rctx, + uint32_t *handle, + uint32_t *sc, + uint32_t *inbufs_len, + uint32_t inbufs_size, void *inbufs) +{ + return fastrpc2(&adsp_listener_next2_def, fd, ADSP_LISTENER_HANDLE, + ret_rctx, + ret_res, + ret_outbuf_len, ret_outbuf, + rctx, + handle, + sc, + inbufs_len, + inbufs_size, inbufs); +} + +int run_fastrpc_listener(int fd) +{ + uint32_t handle; + uint32_t rctx; + uint32_t sc; + uint32_t inbufs_len; + char inbufs[256]; + char outbuf[256]; + int ret; + + ret = adsp_listener_init2(fd); + if (ret) { + fprintf(stderr, "Could not initialize the listener: %u\n", ret); + return ret; + } + + sc = 0xffffffff; + + while (!ret) { + ret = adsp_listener_next2(fd, rctx, AEE_EUNSUPPORTED, 0, outbuf, &rctx, &handle, &sc, &inbufs_len, 256, inbufs); + } + + return ret; +} diff --git a/fastrpc/rpcd.c b/fastrpc/rpcd.c index 8e6e750..bb1ae44 100644 --- a/fastrpc/rpcd.c +++ b/fastrpc/rpcd.c @@ -30,10 +30,11 @@ #include "aee_error.h" #include "fastrpc.h" #include "fastrpc_adsp_default_listener.h" -#include "fastrpc_adsp_listener.h" #include "fastrpc_chre_slpi.h" #include "fastrpc_remotectl.h" +int run_fastrpc_listener(int fd); + static int remotectl_open(int fd, char *name, struct fastrpc_context **ctx, void (*err_cb)(const char *err)) { uint32_t handle; @@ -94,32 +95,6 @@ static int adsp_default_listener_register(struct fastrpc_context *ctx) return fastrpc(&adsp_default_listener_register_def, ctx); } -static int adsp_listener_init2(int fd) -{ - return fastrpc2(&adsp_listener_init2_def, fd, ADSP_LISTENER_HANDLE); -} - -static int adsp_listener_next2(int fd, - uint32_t ret_rctx, - uint32_t ret_res, - uint32_t ret_outbuf_len, void *ret_outbuf, - uint32_t *rctx, - uint32_t *handle, - uint32_t *sc, - uint32_t *inbufs_len, - uint32_t inbufs_size, void *inbufs) -{ - return fastrpc2(&adsp_listener_next2_def, fd, ADSP_LISTENER_HANDLE, - ret_rctx, - ret_res, - ret_outbuf_len, ret_outbuf, - rctx, - handle, - sc, - inbufs_len, - inbufs_size, inbufs); -} - static int chre_slpi_start_thread(struct fastrpc_context *ctx) { return fastrpc(&chre_slpi_start_thread_def, ctx); @@ -153,10 +128,6 @@ err: int main() { struct fastrpc_init_create_static create; - uint32_t rctx, handle, sc; - uint32_t inbufs_len; - char inbufs[256]; - char outbuf[256]; int fd; int ret; @@ -185,17 +156,9 @@ int main() if (ret) goto err_close_dev; - ret = adsp_listener_init2(fd); - if (ret) { - fprintf(stderr, "Could not initialize the listener: %u\n", ret); + ret = run_fastrpc_listener(fd); + if (ret) goto err_close_dev; - } - - sc = 0xffffffff; - - while (!ret) { - ret = adsp_listener_next2(fd, rctx, AEE_EUNSUPPORTED, 0, outbuf, &rctx, &handle, &sc, &inbufs_len, 256, inbufs); - } close(fd);