From 7e5c8436311d78aa69aed263dbfcce575fa43f8b Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Tue, 6 Jan 2026 16:42:20 +0530 Subject: [PATCH 01/11] Update cosa_device_info_apis.c --- .../cosa_device_info_apis.c | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/source/TR-181/integration_src.shared/cosa_device_info_apis.c b/source/TR-181/integration_src.shared/cosa_device_info_apis.c index a32336a..43c9104 100644 --- a/source/TR-181/integration_src.shared/cosa_device_info_apis.c +++ b/source/TR-181/integration_src.shared/cosa_device_info_apis.c @@ -380,6 +380,107 @@ ANSC_STATUS CosaDmlDIGetRfSignalStatus(BOOLEAN *pRfSignalStatus) { #endif +int can_proceed_fw_download(void) +{ + char url[1024] = {0}; + char fname[256] = {0}; + char buf[64] = {0}; + char line[256] = {0}; + + uint64_t fw_kb = 0; + uint64_t avail_kb = 0; + uint64_t rsrv_mb = 0, rsrv_kb = 0; + int imgp_pct = 0; + + /* 1) Fetch URL and filename */ + if (cm_hal_Get_HTTP_Download_Url(url, fname) != 0 || url[0] == '\0') { + CcspTraceError(("[FWCHK] Failed to get download URL/filename\n")); + return 0; + } + CcspTraceInfo(("[FWCHK] URL: %s\n", url)); + + /* 2) Fetch Content-Length using curl CLI via popen (NO libcurl needed) */ + { + char cmd[1500]; + snprintf(cmd, sizeof(cmd), + "curl -sI '%s' | grep -i Content-Length | awk '{print $2}'", + url); + + FILE *fp = popen(cmd, "r"); + if (!fp) { + CcspTraceError(("[FWCHK] popen() failed for curl\n")); + return 0; + } + + if (fgets(line, sizeof(line), fp) == NULL) { + CcspTraceError(("[FWCHK] Content-Length not found\n")); + pclose(fp); + return 0; + } + pclose(fp); + + uint64_t bytes = strtoull(line, NULL, 10); + if (bytes == 0) { + CcspTraceError(("[FWCHK] Invalid Content-Length\n")); + return 0; + } + + fw_kb = (bytes + 1023ULL) / 1024ULL; + CcspTraceInfo(("[FWCHK] Firmware size: %" PRIu64 " kB\n", fw_kb)); + } + + /* 3) Read MemAvailable (kB) */ + { + FILE *fp = fopen("/proc/meminfo", "r"); + if (!fp) { + CcspTraceError(("[FWCHK] Cannot read /proc/meminfo\n")); + return 0; + } + + while (fgets(line, sizeof(line), fp)) { + if (strncmp(line, "MemAvailable:", 13) == 0) { + char *p = line + 13; + while (*p && !isdigit((unsigned char)*p)) ++p; + avail_kb = strtoull(p, NULL, 10); + break; + } + } + fclose(fp); + + if (avail_kb == 0) { + CcspTraceError(("[FWCHK] MemAvailable not found\n")); + return 0; + } + CcspTraceInfo(("[FWCHK] MemAvailable: %" PRIu64 " kB\n", avail_kb)); + } + + /* 4) syscfg variables EXACTLY as you wanted */ + syscfg_get(NULL, "FwDwld_AvlMem_RsrvThreshold", buf, sizeof(buf)); + rsrv_mb = atoi(buf); + rsrv_kb = rsrv_mb * 1024ULL; + CcspTraceInfo(("[FWCHK] ReserveThreshold: %llu MB\n", (unsigned long long)rsrv_mb)); + + syscfg_get(NULL, "FwDwld_ImageProcMemPercent", buf, sizeof(buf)); + imgp_pct = atoi(buf); + if (imgp_pct < 0) imgp_pct = 0; + CcspTraceInfo(("[FWCHK] ImageProcPercent: %d %%\n", imgp_pct)); + + /* 5) Required Memory calculation */ + uint64_t img_proc_kb = (fw_kb * imgp_pct + 99ULL) / 100ULL; + uint64_t required_kb = fw_kb + rsrv_kb + img_proc_kb; + + CcspTraceInfo(("[FWCHK] Required Memory: %" PRIu64 " kB\n", required_kb)); + + /* 6) Verdict */ + if (avail_kb >= required_kb) { + CcspTraceError(("[FWCHK] Verdict: PROCEED\n")); + return 1; + } + + CcspTraceInfo(("[FWCHK] Verdict: BLOCK\n")); + return 0; +} + ANSC_STATUS CosaDmlDIDownloadNow(ANSC_HANDLE hContext) { PCOSA_DATAMODEL_DEVICEINFO pMyObject = (PCOSA_DATAMODEL_DEVICEINFO)hContext; @@ -491,6 +592,12 @@ ANSC_STATUS CosaDmlDIDownloadNow(ANSC_HANDLE hContext) } } */ + + if(can_proceed_fw_download() == 0){ + CcspTraceError(("CosaDmlDIDownloadNow : Not enough memory to proceed firmware download\n")); + return ANSC_STATUS_FAILURE; + } + pthread_t FWDL_Thread; res = pthread_create(&FWDL_Thread, NULL, FWDL_ThreadFunc, "FWDL_ThreadFunc"); if(res != 0) From a86f9685b656bd97899e62249bbafcf7926cb849 Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Tue, 6 Jan 2026 17:04:30 +0530 Subject: [PATCH 02/11] Update cosa_device_info_apis.c --- source/TR-181/integration_src.shared/cosa_device_info_apis.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/TR-181/integration_src.shared/cosa_device_info_apis.c b/source/TR-181/integration_src.shared/cosa_device_info_apis.c index 43c9104..26bf887 100644 --- a/source/TR-181/integration_src.shared/cosa_device_info_apis.c +++ b/source/TR-181/integration_src.shared/cosa_device_info_apis.c @@ -71,6 +71,7 @@ #define _GNU_SOURCE #include #include +#include #include "cosa_device_info_apis.h" #include "cm_hal.h" #include "cosa_device_info_internal.h" From f6505dddd70719be3757fc449d529714d80496d5 Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Wed, 7 Jan 2026 15:42:57 +0530 Subject: [PATCH 03/11] Update cosa_device_info_apis.c --- source/TR-181/integration_src.shared/cosa_device_info_apis.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/TR-181/integration_src.shared/cosa_device_info_apis.c b/source/TR-181/integration_src.shared/cosa_device_info_apis.c index 26bf887..207ae39 100644 --- a/source/TR-181/integration_src.shared/cosa_device_info_apis.c +++ b/source/TR-181/integration_src.shared/cosa_device_info_apis.c @@ -72,6 +72,7 @@ #include #include #include +#include #include "cosa_device_info_apis.h" #include "cm_hal.h" #include "cosa_device_info_internal.h" @@ -434,7 +435,7 @@ int can_proceed_fw_download(void) { FILE *fp = fopen("/proc/meminfo", "r"); if (!fp) { - CcspTraceError(("[FWCHK] Cannot read /proc/meminfo\n")); + CcspTraceError(("[FWCHK] fopen(/proc/meminfo) failed: errno=%d (%s)\n",errno, strerror(errno))); return 0; } From abca33e8cd8bcd371994cd16393dc436215f4e20 Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Wed, 21 Jan 2026 09:48:21 +0000 Subject: [PATCH 04/11] removed function from here --- .../TR-181/integration_src.shared/Makefile.am | 2 +- .../cosa_device_info_apis.c | 103 +----------------- 2 files changed, 2 insertions(+), 103 deletions(-) diff --git a/source/TR-181/integration_src.shared/Makefile.am b/source/TR-181/integration_src.shared/Makefile.am index 944ab48..acd49bb 100644 --- a/source/TR-181/integration_src.shared/Makefile.am +++ b/source/TR-181/integration_src.shared/Makefile.am @@ -29,7 +29,7 @@ libCcspCMAgent_integration_src_shared_la_CPPFLAGS = \ -I$(top_srcdir)/source/Custom libCcspCMAgent_integration_src_shared_la_SOURCES = cosa_x_cisco_com_cablemodem_apis.c cosa_device_info_apis.c cosa_x_rdkcentral_com_cablemodem_apis.c -libCcspCMAgent_integration_src_shared_la_LDFLAGS = -lccsp_common -lcm_mgnt -lsysevent -lsecure_wrapper +libCcspCMAgent_integration_src_shared_la_LDFLAGS = -lccsp_common -lcm_mgnt -lsysevent -lsecure_wrapper -lfw_download_chk if CORE_NET_LIB_FEATURE_SUPPORT libCcspCMAgent_integration_src_shared_la_LDFLAGS += -lnet endif diff --git a/source/TR-181/integration_src.shared/cosa_device_info_apis.c b/source/TR-181/integration_src.shared/cosa_device_info_apis.c index 207ae39..673c0e4 100644 --- a/source/TR-181/integration_src.shared/cosa_device_info_apis.c +++ b/source/TR-181/integration_src.shared/cosa_device_info_apis.c @@ -79,6 +79,7 @@ #include "safec_lib_common.h" #include #include "secure_wrapper.h" +#include "fw_download_check.h" #define CM_HTTPURL_LEN 512 #define VALID_fW_LEN 128 @@ -381,108 +382,6 @@ ANSC_STATUS CosaDmlDIGetRfSignalStatus(BOOLEAN *pRfSignalStatus) { } #endif - -int can_proceed_fw_download(void) -{ - char url[1024] = {0}; - char fname[256] = {0}; - char buf[64] = {0}; - char line[256] = {0}; - - uint64_t fw_kb = 0; - uint64_t avail_kb = 0; - uint64_t rsrv_mb = 0, rsrv_kb = 0; - int imgp_pct = 0; - - /* 1) Fetch URL and filename */ - if (cm_hal_Get_HTTP_Download_Url(url, fname) != 0 || url[0] == '\0') { - CcspTraceError(("[FWCHK] Failed to get download URL/filename\n")); - return 0; - } - CcspTraceInfo(("[FWCHK] URL: %s\n", url)); - - /* 2) Fetch Content-Length using curl CLI via popen (NO libcurl needed) */ - { - char cmd[1500]; - snprintf(cmd, sizeof(cmd), - "curl -sI '%s' | grep -i Content-Length | awk '{print $2}'", - url); - - FILE *fp = popen(cmd, "r"); - if (!fp) { - CcspTraceError(("[FWCHK] popen() failed for curl\n")); - return 0; - } - - if (fgets(line, sizeof(line), fp) == NULL) { - CcspTraceError(("[FWCHK] Content-Length not found\n")); - pclose(fp); - return 0; - } - pclose(fp); - - uint64_t bytes = strtoull(line, NULL, 10); - if (bytes == 0) { - CcspTraceError(("[FWCHK] Invalid Content-Length\n")); - return 0; - } - - fw_kb = (bytes + 1023ULL) / 1024ULL; - CcspTraceInfo(("[FWCHK] Firmware size: %" PRIu64 " kB\n", fw_kb)); - } - - /* 3) Read MemAvailable (kB) */ - { - FILE *fp = fopen("/proc/meminfo", "r"); - if (!fp) { - CcspTraceError(("[FWCHK] fopen(/proc/meminfo) failed: errno=%d (%s)\n",errno, strerror(errno))); - return 0; - } - - while (fgets(line, sizeof(line), fp)) { - if (strncmp(line, "MemAvailable:", 13) == 0) { - char *p = line + 13; - while (*p && !isdigit((unsigned char)*p)) ++p; - avail_kb = strtoull(p, NULL, 10); - break; - } - } - fclose(fp); - - if (avail_kb == 0) { - CcspTraceError(("[FWCHK] MemAvailable not found\n")); - return 0; - } - CcspTraceInfo(("[FWCHK] MemAvailable: %" PRIu64 " kB\n", avail_kb)); - } - - /* 4) syscfg variables EXACTLY as you wanted */ - syscfg_get(NULL, "FwDwld_AvlMem_RsrvThreshold", buf, sizeof(buf)); - rsrv_mb = atoi(buf); - rsrv_kb = rsrv_mb * 1024ULL; - CcspTraceInfo(("[FWCHK] ReserveThreshold: %llu MB\n", (unsigned long long)rsrv_mb)); - - syscfg_get(NULL, "FwDwld_ImageProcMemPercent", buf, sizeof(buf)); - imgp_pct = atoi(buf); - if (imgp_pct < 0) imgp_pct = 0; - CcspTraceInfo(("[FWCHK] ImageProcPercent: %d %%\n", imgp_pct)); - - /* 5) Required Memory calculation */ - uint64_t img_proc_kb = (fw_kb * imgp_pct + 99ULL) / 100ULL; - uint64_t required_kb = fw_kb + rsrv_kb + img_proc_kb; - - CcspTraceInfo(("[FWCHK] Required Memory: %" PRIu64 " kB\n", required_kb)); - - /* 6) Verdict */ - if (avail_kb >= required_kb) { - CcspTraceError(("[FWCHK] Verdict: PROCEED\n")); - return 1; - } - - CcspTraceInfo(("[FWCHK] Verdict: BLOCK\n")); - return 0; -} - ANSC_STATUS CosaDmlDIDownloadNow(ANSC_HANDLE hContext) { PCOSA_DATAMODEL_DEVICEINFO pMyObject = (PCOSA_DATAMODEL_DEVICEINFO)hContext; From bb2a7d4842b76ba796c5237faa51f614bf823e40 Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Wed, 21 Jan 2026 09:50:17 +0000 Subject: [PATCH 05/11] removed unnecessary headers --- source/TR-181/integration_src.shared/cosa_device_info_apis.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/TR-181/integration_src.shared/cosa_device_info_apis.c b/source/TR-181/integration_src.shared/cosa_device_info_apis.c index 673c0e4..f40e939 100644 --- a/source/TR-181/integration_src.shared/cosa_device_info_apis.c +++ b/source/TR-181/integration_src.shared/cosa_device_info_apis.c @@ -71,8 +71,6 @@ #define _GNU_SOURCE #include #include -#include -#include #include "cosa_device_info_apis.h" #include "cm_hal.h" #include "cosa_device_info_internal.h" From 3a15aafeb04d6eeeaef7b39306551a9d5d59770a Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Wed, 21 Jan 2026 17:15:00 +0530 Subject: [PATCH 06/11] Update Makefile.am --- source/TR-181/integration_src.shared/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/TR-181/integration_src.shared/Makefile.am b/source/TR-181/integration_src.shared/Makefile.am index acd49bb..6cfcfbe 100644 --- a/source/TR-181/integration_src.shared/Makefile.am +++ b/source/TR-181/integration_src.shared/Makefile.am @@ -26,7 +26,8 @@ libCcspCMAgent_integration_src_shared_la_CPPFLAGS = \ -I$(top_srcdir)/source/TR-181/board_sbapi \ -I$(top_srcdir)/source/TR-181/middle_layer_src \ -I$(top_srcdir)/source/TR-181/include \ - -I$(top_srcdir)/source/Custom + -I$(top_srcdir)/source/Custom \ + -I${includedir}/ccsp libCcspCMAgent_integration_src_shared_la_SOURCES = cosa_x_cisco_com_cablemodem_apis.c cosa_device_info_apis.c cosa_x_rdkcentral_com_cablemodem_apis.c libCcspCMAgent_integration_src_shared_la_LDFLAGS = -lccsp_common -lcm_mgnt -lsysevent -lsecure_wrapper -lfw_download_chk From 7c4e0b960038f7889b844dea9007c89d947c0d9a Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Wed, 21 Jan 2026 18:38:22 +0530 Subject: [PATCH 07/11] Update Makefile.am --- source/TR-181/integration_src.shared/Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/TR-181/integration_src.shared/Makefile.am b/source/TR-181/integration_src.shared/Makefile.am index 6cfcfbe..acd49bb 100644 --- a/source/TR-181/integration_src.shared/Makefile.am +++ b/source/TR-181/integration_src.shared/Makefile.am @@ -26,8 +26,7 @@ libCcspCMAgent_integration_src_shared_la_CPPFLAGS = \ -I$(top_srcdir)/source/TR-181/board_sbapi \ -I$(top_srcdir)/source/TR-181/middle_layer_src \ -I$(top_srcdir)/source/TR-181/include \ - -I$(top_srcdir)/source/Custom \ - -I${includedir}/ccsp + -I$(top_srcdir)/source/Custom libCcspCMAgent_integration_src_shared_la_SOURCES = cosa_x_cisco_com_cablemodem_apis.c cosa_device_info_apis.c cosa_x_rdkcentral_com_cablemodem_apis.c libCcspCMAgent_integration_src_shared_la_LDFLAGS = -lccsp_common -lcm_mgnt -lsysevent -lsecure_wrapper -lfw_download_chk From 85113dc5372b9cbfa6ff0866176ee7b347d084e7 Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Wed, 21 Jan 2026 18:39:18 +0530 Subject: [PATCH 08/11] Update cosa_device_info_apis.c --- source/TR-181/integration_src.shared/cosa_device_info_apis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/TR-181/integration_src.shared/cosa_device_info_apis.c b/source/TR-181/integration_src.shared/cosa_device_info_apis.c index f40e939..b53a672 100644 --- a/source/TR-181/integration_src.shared/cosa_device_info_apis.c +++ b/source/TR-181/integration_src.shared/cosa_device_info_apis.c @@ -77,7 +77,7 @@ #include "safec_lib_common.h" #include #include "secure_wrapper.h" -#include "fw_download_check.h" +#include #define CM_HTTPURL_LEN 512 #define VALID_fW_LEN 128 From d8b4d953b99a7de7c971537f5c514d5174accaf9 Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Wed, 21 Jan 2026 19:27:19 +0530 Subject: [PATCH 09/11] Update cosa_device_info_apis.c --- source/TR-181/integration_src.shared/cosa_device_info_apis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/TR-181/integration_src.shared/cosa_device_info_apis.c b/source/TR-181/integration_src.shared/cosa_device_info_apis.c index b53a672..f40e939 100644 --- a/source/TR-181/integration_src.shared/cosa_device_info_apis.c +++ b/source/TR-181/integration_src.shared/cosa_device_info_apis.c @@ -77,7 +77,7 @@ #include "safec_lib_common.h" #include #include "secure_wrapper.h" -#include +#include "fw_download_check.h" #define CM_HTTPURL_LEN 512 #define VALID_fW_LEN 128 From 3d92313078c06c0178fa332e5c8b72ed1a8c449f Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Tue, 27 Jan 2026 18:07:40 +0530 Subject: [PATCH 10/11] Update ssp_main.c Adding t2 init --- source/CMAgentSsp/ssp_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/CMAgentSsp/ssp_main.c b/source/CMAgentSsp/ssp_main.c index d9c9ed6..118e583 100644 --- a/source/CMAgentSsp/ssp_main.c +++ b/source/CMAgentSsp/ssp_main.c @@ -51,6 +51,7 @@ //#include #include "safec_lib_common.h" #include "syscfg/syscfg.h" +#include "telemetry_busmessage_sender.h" #include #define DEBUG_INI_NAME "/etc/debug.ini" @@ -960,6 +961,7 @@ int main(int argc, char *argv[]) CcspTraceInfo(("pthread create docsis registration\n")); pthread_create(&docsisclbk_tid, NULL, GWP_docsisregistration_threadfunc, NULL); #endif + t2_init("CcspCMAgent"); cmd_dispatch('e'); // printf("Calling Docsis\n"); From df7dba2c312965381ebe8eac8af2f7a00cea3eca Mon Sep 17 00:00:00 2001 From: bunnam988 <107185904+bunnam988@users.noreply.github.com> Date: Mon, 2 Feb 2026 23:39:27 +0530 Subject: [PATCH 11/11] Update cosa_device_info_apis.c --- source/TR-181/integration_src.shared/cosa_device_info_apis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/TR-181/integration_src.shared/cosa_device_info_apis.c b/source/TR-181/integration_src.shared/cosa_device_info_apis.c index f40e939..bf65b80 100644 --- a/source/TR-181/integration_src.shared/cosa_device_info_apis.c +++ b/source/TR-181/integration_src.shared/cosa_device_info_apis.c @@ -492,7 +492,7 @@ ANSC_STATUS CosaDmlDIDownloadNow(ANSC_HANDLE hContext) } */ - if(can_proceed_fw_download() == 0){ + if(can_proceed_fw_download() == FW_DWNLD_MEMCHK_NOT_ENOUGH_MEM){ CcspTraceError(("CosaDmlDIDownloadNow : Not enough memory to proceed firmware download\n")); return ANSC_STATUS_FAILURE; }