From f5064dadcf1511c1002330ca712e37a9e2712472 Mon Sep 17 00:00:00 2001 From: Suvendhu Hansa Date: Tue, 6 Jan 2026 16:59:31 +0530 Subject: [PATCH] Remove rpc-sys dependencies --- gitlab-ci/setup.sh | 2 ++ src/common.c | 51 ++++++++++++++++++++--------- src/download.c | 33 ++++++++++++------- test/dummy/sysupgrade | 12 +++++++ test/files/tmp/rpc_sys.data | 3 -- test/files/tmp/rpc_sys_fail.data | 4 --- test/files/usr/libexec/rpcd/rpc-sys | 26 --------------- 7 files changed, 72 insertions(+), 59 deletions(-) create mode 100644 test/dummy/sysupgrade delete mode 100644 test/files/tmp/rpc_sys.data delete mode 100644 test/files/tmp/rpc_sys_fail.data delete mode 100755 test/files/usr/libexec/rpcd/rpc-sys diff --git a/gitlab-ci/setup.sh b/gitlab-ci/setup.sh index 8b1d817..3ead39e 100755 --- a/gitlab-ci/setup.sh +++ b/gitlab-ci/setup.sh @@ -6,6 +6,8 @@ pwd [ -d "/opt/dev/bbfdm" ] && cd /opt/dev/bbfdm && ./gitlab-ci/setup.sh && cp -f ./gitlab-ci/bbfdm_services.conf /etc/supervisor/conf.d/ && cd - cp -rf ./test/files/* / +cp ./test/dummy/sysupgrade /sbin/ +chmod 777 /sbin/sysupgrade echo "set ACS url in cwmp uci" url="http://acs:7547" diff --git a/src/common.c b/src/common.c index 6401d93..64b045e 100755 --- a/src/common.c +++ b/src/common.c @@ -448,21 +448,38 @@ void set_rpc_parameter_key(const char *param_key) */ void cwmp_reboot(const char *command_key) { + int code = 3; + set_rpc_parameter_key(command_key); // Set last_reboot_cause to 'RemoteReboot' because the upcoming reboot will be initiated by CWMP Reboot RPC set_uci_path_value(NULL, "sysmngr.reboots.last_reboot_cause", "RemoteReboot"); - struct blob_buf b = { 0 }; - CWMP_MEMSET(&b, 0, sizeof(struct blob_buf)); - blob_buf_init(&b, 0); + // Flawfinder: ignore + FILE *pp = popen("reboot", "r"); + if (pp) { + int status = pclose(pp); + code = WEXITSTATUS(status); + } - icwmp_ubus_invoke("rpc-sys", "reboot", b.head, NULL, NULL); + if (code == 0) { + // Wait before exit to avoid getting restarted by procd + sleep(60); + } - blob_buf_free(&b); + code = 3; - // Wait before exit to avoid getting restarted by procd - sleep(300); + // Flawfinder: ignore + pp = popen("reboot -f", "r"); + if (pp) { + int status = pclose(pp); + code = WEXITSTATUS(status); + } + + if (code == 0) { + // Wait before exit to avoid getting restarted by procd + sleep(120); + } // Set last_reboot_cause to empty because there is a problem in the system reboot set_uci_path_value(NULL, "sysmngr.reboots.last_reboot_cause", ""); @@ -473,18 +490,22 @@ void cwmp_reboot(const char *command_key) /* * FactoryReset */ -void cwmp_factory_reset() //use the ubus rpc-sys factory +void cwmp_factory_reset() { - struct blob_buf b = { 0 }; - CWMP_MEMSET(&b, 0, sizeof(struct blob_buf)); - blob_buf_init(&b, 0); + int code = 3; - icwmp_ubus_invoke("rpc-sys", "factory", b.head, NULL, NULL); + // Flawfinder: ignore + FILE *pp = popen("defaultreset", "r"); + if (pp) { + int status = pclose(pp); + code = WEXITSTATUS(status); + } - blob_buf_free(&b); + if (code == 0) { + // Wait before exit to avoid getting restarted by procd + sleep(300); + } - // Wait before exit to avoid getting restarted by procd - sleep(300); CWMP_LOG(ERROR, "# Problem in system factory reset #"); } diff --git a/src/download.c b/src/download.c index f2b43f7..9e8b2b1 100644 --- a/src/download.c +++ b/src/download.c @@ -187,20 +187,31 @@ void ubus_check_image_callback(struct ubus_request *req, int type __attribute__( *code = tb[0] ? blobmsg_get_u32(tb[0]) : 4; } -int cwmp_check_image() +int cwmp_check_image(const char *fw_path) { - int code = 0, e; - struct blob_buf b = { 0 }; - - blob_buf_init(&b, 0); + int code = 3; + char cmd[128] = {0}; CWMP_LOG(INFO, "Check downloaded image ..."); - e = icwmp_ubus_invoke("rpc-sys", "upgrade_test", b.head, ubus_check_image_callback, &code); - if (e != 0) { - CWMP_LOG(INFO, "rpc-sys upgrade_test ubus method failed: Ubus err code: %d", e); - code = 5; + + if (CWMP_STRLEN(fw_path) == 0) { + CWMP_LOG(INFO, "Firmware path is empty"); + return code; } - blob_buf_free(&b); + + snprintf(cmd, sizeof(cmd), "sysupgrade -T %s", fw_path); + + // Flawfinder: ignore + FILE *pp = popen(cmd, "r"); + if (pp) { + int status = pclose(pp); + code = WEXITSTATUS(status); + } + + if (code != 0) { + CWMP_LOG(INFO, "Firware verification failed with err: %d", code); + } + return code; } @@ -540,7 +551,7 @@ int cwmp_launch_download(struct download *pdownload, char *download_file_name, e } if (CWMP_STRCMP(pdownload->file_type, FIRMWARE_UPGRADE_IMAGE_FILE_TYPE) == 0 || CWMP_STRCMP(pdownload->file_type, STORED_FIRMWARE_IMAGE_FILE_TYPE) == 0) { rename(ICWMP_DOWNLOAD_FILE, FIRMWARE_UPGRADE_IMAGE); - int ret = cwmp_check_image(); + int ret = cwmp_check_image(FIRMWARE_UPGRADE_IMAGE); if (ret == 0) { unsigned int file_size = get_file_size(FIRMWARE_UPGRADE_IMAGE); diff --git a/test/dummy/sysupgrade b/test/dummy/sysupgrade new file mode 100644 index 0000000..571ff5a --- /dev/null +++ b/test/dummy/sysupgrade @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ -z "${2}" ]; then + exit 1 +fi + +invalid="$(cat ${2})" +if [ "${invalid}" = "Invalid" ]; then + exit 1 +fi + +exit 0 diff --git a/test/files/tmp/rpc_sys.data b/test/files/tmp/rpc_sys.data deleted file mode 100644 index 4c85eb3..0000000 --- a/test/files/tmp/rpc_sys.data +++ /dev/null @@ -1,3 +0,0 @@ -{ - "code": 0 -} \ No newline at end of file diff --git a/test/files/tmp/rpc_sys_fail.data b/test/files/tmp/rpc_sys_fail.data deleted file mode 100644 index 69eed36..0000000 --- a/test/files/tmp/rpc_sys_fail.data +++ /dev/null @@ -1,4 +0,0 @@ -{ - "code": 1, - "stderr": "FATAL ERROR: could not read header from: /tmp/firmware.bin\nNot an IOPSYS image\nImage check failed.\n" -} \ No newline at end of file diff --git a/test/files/usr/libexec/rpcd/rpc-sys b/test/files/usr/libexec/rpcd/rpc-sys deleted file mode 100755 index 34b61ce..0000000 --- a/test/files/usr/libexec/rpcd/rpc-sys +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -. /usr/share/libubox/jshn.sh - -case "$1" in - list) - echo '{ "upgrade_test" : {}, "upgrade_start" : {} }' - ;; - call) - case "$2" in - upgrade_test) - invalid=`cat /tmp/firmware.bin` - if [ $invalid = "Invalid" ]; then - cat /tmp/rpc_sys_fail.data 2>/dev/null - else - cat /tmp/rpc_sys.data 2>/dev/null - fi - ;; - upgrade_start) - cat /tmp/rpc_sys.data 2>/dev/null - sleep 7 - supervisorctl stop icwmpd >> ./funl-test-debug.log - ;; - esac - ;; -esac