Remove rpc-sys dependencies

This commit is contained in:
Suvendhu Hansa 2026-01-06 16:59:31 +05:30
parent 090e3f6e67
commit f5064dadcf
7 changed files with 72 additions and 59 deletions

View file

@ -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"

View file

@ -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 #");
}

View file

@ -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);

12
test/dummy/sysupgrade Normal file
View file

@ -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

View file

@ -1,3 +0,0 @@
{
"code": 0
}

View file

@ -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"
}

View file

@ -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