From 9be8502c31eafd0cad4300da64a0cbdd6f6ee300 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Dutta Date: Tue, 10 Mar 2026 12:26:49 +0530 Subject: [PATCH] For config download, use downloaded filename as import name if it exists in system --- .gitlab-ci.yml | 2 +- src/download.c | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d3e033d..38f0e52 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ variables: - CFLAGS: "-DBBF_VENDOR_PREFIX=\\\"X_IOWRT_EU_\\\"" + CFLAGS: "-DBBF_VENDOR_PREFIX=\\\"X_IOWRT_EU_\\\" -DICWMP_ENABLE_OPCONF_SUPPORT -DICWMP_ENABLE_VENDOR_EXTN -DICWMP_ENABLE_SMM_SUPPORT" #VERBOSE: true SOURCE_FOLDER: "." COMPILATION_FIXUP: "cmake ." diff --git a/src/download.c b/src/download.c index ea29989..a780eae 100644 --- a/src/download.c +++ b/src/download.c @@ -533,7 +533,7 @@ static int cwmp_apply_multiple_firmware(enum download_filetypes filetype, bool a int bank_id = get_available_bank_id(); char buffer[32] = {0}; int keep_opconf = -1, keep_userconf = -1; - char *config_scope = NULL; + const char *config_scope = NULL; if (bank_id <= 0) return -1; @@ -838,20 +838,22 @@ int apply_downloaded_file(struct download *pdownload, char *download_file_name, is_opconf = is_downloaded_file_opconf(file_path); if (is_opconf == false) { // handle normal uci download + char buffer[1024] = {0}; + // First run the macro_engine.sh to resolve the macros in uci (if present) if (file_exists(MACRO_ENGINE) == true) { - char cmd[1024] = {0}; - - snprintf(cmd, sizeof(cmd), "%s %s", MACRO_ENGINE, file_path); - run_cmd(cmd, NULL, 0); + snprintf(buffer, sizeof(buffer), "%s %s", MACRO_ENGINE, file_path); + run_cmd(buffer, NULL, 0); } - if (CWMP_STRSTR(download_file_name, ".uci.conf") != NULL || - CWMP_STRSTR(pdownload->target_file_name, ".uci.conf") != NULL) { - err = import_uci_package(NULL, file_path); - } else { + // If the downloaded filename is one of the uci name, use named import + snprintf(buffer, sizeof(buffer), "/etc/config/%s", download_file_name); + if (file_exists(buffer) == true) { err = import_uci_package(download_file_name, file_path); + } else { + err = import_uci_package(NULL, file_path); } + if (err == CWMP_GEN_ERR) { error = FAULT_CPE_INTERNAL_ERROR; snprintf(err_msg, sizeof(err_msg), "Failed to commit the config file changes"); @@ -864,11 +866,19 @@ int apply_downloaded_file(struct download *pdownload, char *download_file_name, err = cwmp_apply_opconf(file_path, pdownload->filetype); if (err != CWMP_OK) { snprintf(err_msg, sizeof(err_msg), "Failed to apply the opconf file"); + error = FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED; } #endif } remove_file(file_path); + // Trigger reboot/soft-reset only in case of its not operator default opconf file, + // operator will trigger factory reset to apply it latter, triggering factoryreset + // will break the DownloadRPC message flow +#ifdef ICWMP_ENABLE_OPCONF_SUPPORT + if (err == CWMP_OK && pdownload->filetype != DOWNLOAD_FILETYPE_OPERATOR_CONF_FILE) { +#else if (err == CWMP_OK) { +#endif if (is_opconf == true) { CWMP_LOG(INFO, "Trigger Soft Factory Reset to apply the opconf"); cwmp_factory_reset(true); @@ -906,6 +916,9 @@ int apply_downloaded_file(struct download *pdownload, char *download_file_name, if (error == FAULT_CPE_NO_FAULT) { set_rpc_parameter_key(pdownload->command_key); if (pdownload->filetype == DOWNLOAD_FILETYPE_WEB_CONTENT || +#ifdef ICWMP_ENABLE_OPCONF_SUPPORT + pdownload->filetype == DOWNLOAD_FILETYPE_OPERATOR_CONF_FILE || +#endif pdownload->filetype == DOWNLOAD_FILETYPE_STORED_FIRMWARE_IMAGE) { bkp_session_delete_element((ltype == TYPE_DOWNLOAD) ? "download" : "schedule_download", pdownload->id);