From 717e84b79717ef59442c2cc4c9d54343a223526f Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 9 Mar 2026 12:06:59 +0530 Subject: [PATCH 01/55] Update device_api.c Introduce isSecureDbgSrvUnlocked API and replace the condition checks of buildType and deviceType with this API --- src/deviceutils/device_api.c | 55 ++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index 747f92ae..b2ed6cf9 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -40,6 +40,56 @@ #define MAC_ADDRESS_LEN 17 +/* function isSecureDbgSrvUnlocked - checks the buildtype, deviceType from RFC and enables secure debug services accordingly + Usage: bool isSecureDbgSrvUnlocked + + RETURN - True (Enables Debug Services) if buildtype is dev or buildtype is labsigned and deviceType is test +*/ +bool isSecureDbgSrvUnlocked(void) { + bool dbgServices = isDebugServicesEnabled(); + const char* deviceType = getDeviceTypeRFC(); + BUILDTYPE eBuildType; + bool isDebugServicesUnlocked = false; + FILE *fp; + const char* key = "LABSIGNED_ENABLED="; + char buf[URL_MAX_LEN] = {0}; + char buildBuf[URL_MAX_LEN] = {0}; + + GetBuildType(buildBuf, sizeof(buildBuf), &eBuildType); + + if (eBuildType == eDEV) { + isDebugServicesUnlocked = true; + } + else if (eBuildType == ePROD) { + fp = fopen(DEVICE_PROPERTIES_FILE, "r"); + if (!fp) { + COMMONUTILITIES_ERROR("isSecureDbgSrvUnlocked: can't open properties file\n"); + return isDebugServicesUnlocked; + } + while (fgets(buf, sizeof(buf), fp)) { + if (strncmp(buf, key, strlen(key)) == 0) { + char *eVal = buf + strlen(key); + char pBuf[URL_MAX_LEN] = {0}; + snprintf(pBuf, sizeof(pBuf), "%s", eVal); + stripinvalidchar(pBuf, strlen(pBuf)); + if (strcasecmp(pBuf, "true") == 0) { + if ((strcmp(deviceType, "test") == 0) && dbgServices) { + SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); + SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, pBuf); + isDebugServicesUnlocked = true; + } else { + SWLOG_INFO("isSecureDbgSrvUnlocked: unable to enable debug services...\n"); + SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, pBuf); + } + } + break; + } + } + fclose(fp); + } + return isDebugServicesUnlocked; +} + /* function GetServerUrlFile - scans a file for a URL. Usage: size_t GetServerUrlFile @@ -891,7 +941,6 @@ size_t GetServURL( char *pServURL, size_t szBufSize ) BUILDTYPE eBuildType; char buf[URL_MAX_LEN]; bool skip = false; - bool dbgServices = isDebugServicesEnabled(); //check debug services enabled if( pServURL != NULL ) { @@ -899,7 +948,7 @@ size_t GetServURL( char *pServURL, size_t szBufSize ) GetBuildType( buf, sizeof(buf), &eBuildType ); if( isInStateRed() ) { - if(( eBuildType != ePROD ) || ( dbgServices == true )) + if(isSecureDbgSrvUnlocked()) { len = GetServerUrlFile( pServURL, szBufSize, STATE_RED_CONF ); } @@ -910,7 +959,7 @@ size_t GetServURL( char *pServURL, size_t szBufSize ) } else { - if(( eBuildType != ePROD ) || ( dbgServices == true )) + if(isSecureDbgSrvUnlocked()) { if( (filePresentCheck( SWUPDATE_CONF ) == RDK_API_SUCCESS) ) // if the file exists { From d753b4ec80570472e82aaef72b2bbc83651abe2c Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 9 Mar 2026 12:15:45 +0530 Subject: [PATCH 02/55] Update device_api.h --- src/deviceutils/device_api.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/deviceutils/device_api.h b/src/deviceutils/device_api.h index 7318f715..7543a9bf 100644 --- a/src/deviceutils/device_api.h +++ b/src/deviceutils/device_api.h @@ -301,4 +301,14 @@ size_t GetTR181Url(TR181URL eURL, char *pUrlOut, size_t szBufSize); */ size_t GetServURL(char *pServURL, size_t szBufSize); +/* function isSecureDbgSrvUnlocked - checks for DbgService RFC, DeviceType RFC, build type and + LABSIGNED_ENABLED property + value from /etc/device.properties + + Usage: bool isSecureDbgSrvUnlocked() + + RETURN - returns true if build type is dev or "build type is Prod, DbgServices RFC enabled and + DeviceType is Test and LABSIGNED_ENABLED is set to true. Else, false. +*/ +bool isSecureDbgSrvUnlocked(void); #endif From 307da0f5ea06c2bd4c8638b06bf4295c2f2d4148 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 9 Mar 2026 12:38:54 +0530 Subject: [PATCH 03/55] Update rfcinterface.c --- src/rfcInterface/rfcinterface.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/rfcInterface/rfcinterface.c b/src/rfcInterface/rfcinterface.c index f1ccd551..0a58a78b 100644 --- a/src/rfcInterface/rfcinterface.c +++ b/src/rfcInterface/rfcinterface.c @@ -287,3 +287,30 @@ bool isDebugServicesEnabled(void) } return status; } + + +/* Description: Checking device type rfc value + * @param type : void + * @return test, if deviceType RFC is set to test, prod if deviceType is set to prod, else unknown + * */ +const char* getDeviceTypeRFC(void) { + static char deviceType[16] = "unknown"; // default + char rfc_data[RFC_VALUE_BUF_SIZE] = {0}; + int ret = read_RFCProperty("LABSGND", RFC_DEVICETYPE, rfc_data, sizeof(rfc_data)); + + if (ret == -1) { + SWLOG_ERROR("%s: Failed to read device type\n", __FUNCTION__); + return deviceType; + } + + SWLOG_INFO("%s: RFC device type = %s\n", __FUNCTION__, rfc_data); + + if (strncasecmp(rfc_data, "prod", 4) == 0) { + strncpy(deviceType, "prod", sizeof(deviceType) - 1); + } else if (strncasecmp(rfc_data, "test", 4) == 0) { + strncpy(deviceType, "test", sizeof(deviceType) - 1); + } + + deviceType[sizeof(deviceType) - 1] = '\0'; // to ensure null termination + return deviceType; +} From f8dd2b594b6375994f0f7e2bd4294778aff13148 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 9 Mar 2026 12:39:42 +0530 Subject: [PATCH 04/55] Update rfcinterface.h --- src/include/rfcinterface.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/include/rfcinterface.h b/src/include/rfcinterface.h index 24fcf37b..43dd7414 100644 --- a/src/include/rfcinterface.h +++ b/src/include/rfcinterface.h @@ -86,6 +86,7 @@ typedef struct rfcdetails { #define RFC_FW_REBOOT_NOTIFY "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.RebootPendingNotification" #define RFC_FW_AUTO_EXCLUDE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.AutoExcluded.Enable" #define RFC_DEBUGSRV "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Identity.DbgServices.Enable" +#define RFC_DEVICETYPE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Identity.DeviceType" #define RFC_XCONF_CHECK_NOW "Device.X_COMCAST-COM_Xcalibur.Client.xconfCheckNow" @@ -98,5 +99,6 @@ int isMtlsEnabled(const char *); int isIncremetalCDLEnable(const char *file_name); bool isMmgbleNotifyEnabled(void); bool isDebugServicesEnabled(void); +const char* getDeviceTypeRFC(void); #endif /* VIDEO_RFCINTERFACE_RFCINTERFACE_H_ */ From a8625d1861d6fdbb2322913e5a58c0d303e27acf Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 9 Mar 2026 20:59:57 +0530 Subject: [PATCH 05/55] Update device_api.c --- src/deviceutils/device_api.c | 61 ++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index b2ed6cf9..78b47b0e 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -45,48 +45,49 @@ RETURN - True (Enables Debug Services) if buildtype is dev or buildtype is labsigned and deviceType is test */ -bool isSecureDbgSrvUnlocked(void) { +bool isSecureDbgSrvUnlocked(void) +{ bool dbgServices = isDebugServicesEnabled(); const char* deviceType = getDeviceTypeRFC(); BUILDTYPE eBuildType; bool isDebugServicesUnlocked = false; - FILE *fp; - const char* key = "LABSIGNED_ENABLED="; - char buf[URL_MAX_LEN] = {0}; - char buildBuf[URL_MAX_LEN] = {0}; + char labsigned[8]; + char buildBuf[URL_MAX_LEN] = {0}; + int ret = -1; GetBuildType(buildBuf, sizeof(buildBuf), &eBuildType); if (eBuildType == eDEV) { isDebugServicesUnlocked = true; } - else if (eBuildType == ePROD) { - fp = fopen(DEVICE_PROPERTIES_FILE, "r"); - if (!fp) { - COMMONUTILITIES_ERROR("isSecureDbgSrvUnlocked: can't open properties file\n"); - return isDebugServicesUnlocked; + else if (eBuildType == ePROD) + { + labsigned[0] = 0; + ret = getDevicePropertyData("LABSIGNED_ENABLED", labsigned, sizeof(labsigned)); + if (ret == UTILS_SUCCESS) + { + SWLOG_INFO("labsigned_enabled is = %s\n", labsigned); + } + else + { + SWLOG_ERROR("%s: getDevicePropertyData() for labsigned_enabled fail\n", __FUNCTION__); } - while (fgets(buf, sizeof(buf), fp)) { - if (strncmp(buf, key, strlen(key)) == 0) { - char *eVal = buf + strlen(key); - char pBuf[URL_MAX_LEN] = {0}; - snprintf(pBuf, sizeof(pBuf), "%s", eVal); - stripinvalidchar(pBuf, strlen(pBuf)); - if (strcasecmp(pBuf, "true") == 0) { - if ((strcmp(deviceType, "test") == 0) && dbgServices) { - SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); - SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, pBuf); - isDebugServicesUnlocked = true; - } else { - SWLOG_INFO("isSecureDbgSrvUnlocked: unable to enable debug services...\n"); - SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, pBuf); - } - } - break; + + if ((0 == (strncmp(labsigned, "true", 4)))) + { + if ((strcmp(deviceType, "test") == 0) && dbgServices) + { + SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); + SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); + isDebugServicesUnlocked = true; + } + else + { + SWLOG_INFO("isSecureDbgSrvUnlocked: unable to enable debug services...\n"); + SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); } - } - fclose(fp); - } + } + } return isDebugServicesUnlocked; } From b873efdc07e3bcb675232d92d63cbef5252dda2c Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 9 Mar 2026 21:14:59 +0530 Subject: [PATCH 06/55] Update rfcinterface.c --- src/rfcInterface/rfcinterface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rfcInterface/rfcinterface.c b/src/rfcInterface/rfcinterface.c index 0a58a78b..2ff00997 100644 --- a/src/rfcInterface/rfcinterface.c +++ b/src/rfcInterface/rfcinterface.c @@ -294,7 +294,7 @@ bool isDebugServicesEnabled(void) * @return test, if deviceType RFC is set to test, prod if deviceType is set to prod, else unknown * */ const char* getDeviceTypeRFC(void) { - static char deviceType[16] = "unknown"; // default + char deviceType[16] = "unknown"; // default char rfc_data[RFC_VALUE_BUF_SIZE] = {0}; int ret = read_RFCProperty("LABSGND", RFC_DEVICETYPE, rfc_data, sizeof(rfc_data)); From d93cf446a56a8612baa814cb5ee7e434338b1a5e Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 9 Mar 2026 21:15:41 +0530 Subject: [PATCH 07/55] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/deviceutils/device_api.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/deviceutils/device_api.h b/src/deviceutils/device_api.h index 7543a9bf..b04b4566 100644 --- a/src/deviceutils/device_api.h +++ b/src/deviceutils/device_api.h @@ -301,14 +301,21 @@ size_t GetTR181Url(TR181URL eURL, char *pUrlOut, size_t szBufSize); */ size_t GetServURL(char *pServURL, size_t szBufSize); -/* function isSecureDbgSrvUnlocked - checks for DbgService RFC, DeviceType RFC, build type and - LABSIGNED_ENABLED property - value from /etc/device.properties - - Usage: bool isSecureDbgSrvUnlocked() - - RETURN - returns true if build type is dev or "build type is Prod, DbgServices RFC enabled and - DeviceType is Test and LABSIGNED_ENABLED is set to true. Else, false. -*/ +/* function isSecureDbgSrvUnlocked - determines whether the secure debug service may be unlocked. + * + * The decision is based on: + * - DbgServices RFC + * - DeviceType RFC + * - build type (Dev or Prod) + * - LABSIGNED_ENABLED property value from /etc/device.properties + * + * Usage: bool isSecureDbgSrvUnlocked(void) + * + * RETURN - true if: + * - the build type is Dev; or + * - the build type is Prod, DbgServices RFC is enabled, + * DeviceType is "Test", and LABSIGNED_ENABLED is set to true; + * false otherwise. + */ bool isSecureDbgSrvUnlocked(void); #endif From 6892b697fcfacdf918db230757481ae176b57dbb Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 10 Mar 2026 13:59:50 +0530 Subject: [PATCH 08/55] Update rfcinterface.h --- src/include/rfcinterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/rfcinterface.h b/src/include/rfcinterface.h index 43dd7414..149e6c62 100644 --- a/src/include/rfcinterface.h +++ b/src/include/rfcinterface.h @@ -99,6 +99,6 @@ int isMtlsEnabled(const char *); int isIncremetalCDLEnable(const char *file_name); bool isMmgbleNotifyEnabled(void); bool isDebugServicesEnabled(void); -const char* getDeviceTypeRFC(void); +void getDeviceType(char *deviceType, size_t size); #endif /* VIDEO_RFCINTERFACE_RFCINTERFACE_H_ */ From e6630e9e22982dd732f01ffebc7253a610e792ed Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 10 Mar 2026 14:15:30 +0530 Subject: [PATCH 09/55] Update rfcinterface.c --- src/rfcInterface/rfcinterface.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/rfcInterface/rfcinterface.c b/src/rfcInterface/rfcinterface.c index 2ff00997..9ae0a2e0 100644 --- a/src/rfcInterface/rfcinterface.c +++ b/src/rfcInterface/rfcinterface.c @@ -293,24 +293,34 @@ bool isDebugServicesEnabled(void) * @param type : void * @return test, if deviceType RFC is set to test, prod if deviceType is set to prod, else unknown * */ -const char* getDeviceTypeRFC(void) { - char deviceType[16] = "unknown"; // default +void getDeviceType(char *deviceType, size_t size ){ + + if (deviceType == NULL || size == 0){ + SWLOG_ERROR("%s: Invalid Arguments Passed...\n", __FUNCTION__); + return; + } + char rfc_data[RFC_VALUE_BUF_SIZE] = {0}; int ret = read_RFCProperty("LABSGND", RFC_DEVICETYPE, rfc_data, sizeof(rfc_data)); if (ret == -1) { SWLOG_ERROR("%s: Failed to read device type\n", __FUNCTION__); - return deviceType; + strncpy(deviceType,"unknown", size - 1); + deviceType[size - 1] = '\0'; + return; + //return deviceType; } SWLOG_INFO("%s: RFC device type = %s\n", __FUNCTION__, rfc_data); if (strncasecmp(rfc_data, "prod", 4) == 0) { - strncpy(deviceType, "prod", sizeof(deviceType) - 1); + strncpy(deviceType, "prod", size - 1); } else if (strncasecmp(rfc_data, "test", 4) == 0) { - strncpy(deviceType, "test", sizeof(deviceType) - 1); + strncpy(deviceType, "test", size - 1); + } else { + strncpy(deviceType, "unknown", size - 1); } - deviceType[sizeof(deviceType) - 1] = '\0'; // to ensure null termination - return deviceType; + deviceType[size - 1] = '\0'; // to ensure null termination + return; } From e5a0d8ca6159d982e95c2ed3ac460f3d788a0fd9 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 10 Mar 2026 14:20:20 +0530 Subject: [PATCH 10/55] Update rfcinterface.c --- src/rfcInterface/rfcinterface.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/rfcInterface/rfcinterface.c b/src/rfcInterface/rfcinterface.c index 9ae0a2e0..218eb914 100644 --- a/src/rfcInterface/rfcinterface.c +++ b/src/rfcInterface/rfcinterface.c @@ -299,28 +299,23 @@ void getDeviceType(char *deviceType, size_t size ){ SWLOG_ERROR("%s: Invalid Arguments Passed...\n", __FUNCTION__); return; } - + + const char* type = "unknown"; char rfc_data[RFC_VALUE_BUF_SIZE] = {0}; int ret = read_RFCProperty("LABSGND", RFC_DEVICETYPE, rfc_data, sizeof(rfc_data)); if (ret == -1) { SWLOG_ERROR("%s: Failed to read device type\n", __FUNCTION__); - strncpy(deviceType,"unknown", size - 1); - deviceType[size - 1] = '\0'; - return; - //return deviceType; - } + } SWLOG_INFO("%s: RFC device type = %s\n", __FUNCTION__, rfc_data); if (strncasecmp(rfc_data, "prod", 4) == 0) { - strncpy(deviceType, "prod", size - 1); + type = "prod"; } else if (strncasecmp(rfc_data, "test", 4) == 0) { - strncpy(deviceType, "test", size - 1); - } else { - strncpy(deviceType, "unknown", size - 1); - } + type = "test"; + } - deviceType[size - 1] = '\0'; // to ensure null termination - return; + strncpy(deviceType, type, size - 1); + deviceType[size - 1] = '\0'; } From 28afa5ca74de9a3a5f60c17ebf27445d9c0bf340 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 10 Mar 2026 14:32:33 +0530 Subject: [PATCH 11/55] Update device_api.c --- src/deviceutils/device_api.c | 38 ++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index 78b47b0e..ed7d2ec9 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -47,11 +47,10 @@ */ bool isSecureDbgSrvUnlocked(void) { - bool dbgServices = isDebugServicesEnabled(); - const char* deviceType = getDeviceTypeRFC(); + char* deviceType[16] = {0}; BUILDTYPE eBuildType; bool isDebugServicesUnlocked = false; - char labsigned[8]; + char labsigned[8] = {0}; char buildBuf[URL_MAX_LEN] = {0}; int ret = -1; @@ -62,31 +61,28 @@ bool isSecureDbgSrvUnlocked(void) } else if (eBuildType == ePROD) { - labsigned[0] = 0; - ret = getDevicePropertyData("LABSIGNED_ENABLED", labsigned, sizeof(labsigned)); - if (ret == UTILS_SUCCESS) + bool dbgServices = isDebugServicesEnabled(); + getDeviceTypeRFC(deviceType, sizeof(deviceType)); + ret = getDevicePropertyData("LABSIGNED_ENABLED", labsigned, sizeof(labsigned)); + if (ret == UTILS_SUCCESS && (0 == (strncmp(labsigned, "true", 4)))) { SWLOG_INFO("labsigned_enabled is = %s\n", labsigned); - } - else - { - SWLOG_ERROR("%s: getDevicePropertyData() for labsigned_enabled fail\n", __FUNCTION__); - } - - if ((0 == (strncmp(labsigned, "true", 4)))) - { if ((strcmp(deviceType, "test") == 0) && dbgServices) - { - SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); - SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); + { + SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); + SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); isDebugServicesUnlocked = true; } else - { - SWLOG_INFO("isSecureDbgSrvUnlocked: unable to enable debug services...\n"); - SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); + { + SWLOG_INFO("isSecureDbgSrvUnlocked: unable to enable debug services...\n"); + SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); } - } + } + else + { + SWLOG_ERROR("%s: getDevicePropertyData() for labsigned_enabled fail\n", __FUNCTION__); + } } return isDebugServicesUnlocked; } From fd792c2aae07fc3289bf9349c77b4b68a7cbce8d Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 10 Mar 2026 14:48:05 +0530 Subject: [PATCH 12/55] Update rfcinterface.c --- src/rfcInterface/rfcinterface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rfcInterface/rfcinterface.c b/src/rfcInterface/rfcinterface.c index 218eb914..7d95b1d6 100644 --- a/src/rfcInterface/rfcinterface.c +++ b/src/rfcInterface/rfcinterface.c @@ -293,7 +293,7 @@ bool isDebugServicesEnabled(void) * @param type : void * @return test, if deviceType RFC is set to test, prod if deviceType is set to prod, else unknown * */ -void getDeviceType(char *deviceType, size_t size ){ +void getDeviceTypeRFC(char *deviceType, size_t size ){ if (deviceType == NULL || size == 0){ SWLOG_ERROR("%s: Invalid Arguments Passed...\n", __FUNCTION__); From b55ea06a27ae542bdebf6893131542a839cd4e1b Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 10 Mar 2026 14:48:24 +0530 Subject: [PATCH 13/55] Update rfcinterface.h --- src/include/rfcinterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/rfcinterface.h b/src/include/rfcinterface.h index 149e6c62..c7994a7e 100644 --- a/src/include/rfcinterface.h +++ b/src/include/rfcinterface.h @@ -99,6 +99,6 @@ int isMtlsEnabled(const char *); int isIncremetalCDLEnable(const char *file_name); bool isMmgbleNotifyEnabled(void); bool isDebugServicesEnabled(void); -void getDeviceType(char *deviceType, size_t size); +void getDeviceTypeRFC(char *deviceType, size_t size); #endif /* VIDEO_RFCINTERFACE_RFCINTERFACE_H_ */ From 693261cbf72ff1a4ef9fab324d064e11985dd216 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 10 Mar 2026 14:51:01 +0530 Subject: [PATCH 14/55] Update device_api.c --- src/deviceutils/device_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index ed7d2ec9..b746ae21 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -47,7 +47,7 @@ */ bool isSecureDbgSrvUnlocked(void) { - char* deviceType[16] = {0}; + char deviceType[16] = {0}; BUILDTYPE eBuildType; bool isDebugServicesUnlocked = false; char labsigned[8] = {0}; From 7d12e537bf294d231503375b60234ce9a7a01aa8 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Wed, 11 Mar 2026 11:45:28 +0530 Subject: [PATCH 15/55] Update Makefile.am For unit tests to be successful, adding ../src/rfcInterface/rfcinterface.c as a Source, for referencing getDeviceTypeRFC API code access --- unittest/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/Makefile.am b/unittest/Makefile.am index 3ed1b171..4d0f21eb 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -39,7 +39,7 @@ COMMON_CXXFLAGS = -frtti -fprofile-arcs -ftest-coverage -fpermissive # Define the source files rdkfw_device_status_gtest_SOURCES = device_status_helper_gtest.cpp ./mocks/device_status_helper_mock.cpp ../src/device_status_helper.c ../src/download_status_helper.c -rdkfw_deviceutils_gtest_SOURCES = deviceutils/device_api_gtest.cpp deviceutils/deviceutils_gtest.cpp deviceutils/json_parse.c ./mocks/deviceutils_mock.cpp ../src/deviceutils/device_api.c ../src/deviceutils/deviceutils.c +rdkfw_deviceutils_gtest_SOURCES = deviceutils/device_api_gtest.cpp deviceutils/deviceutils_gtest.cpp deviceutils/json_parse.c ./mocks/deviceutils_mock.cpp ../src/deviceutils/device_api.c ../src/deviceutils/deviceutils.c ../src/rfcInterface/rfcinterface.c # rdkfw_main_gtest: Tests core firmware upgrade logic (rdkv_main.c and rdkv_upgrade.c) # REFACTORED: Uses mocks instead of real helper implementations to avoid multiple definition errors From dbab68f7ff7d7e6861c013247f90393debb991fd Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Wed, 11 Mar 2026 12:14:41 +0530 Subject: [PATCH 16/55] Update Makefile.am --- unittest/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/Makefile.am b/unittest/Makefile.am index 4d0f21eb..b44e415e 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -39,7 +39,7 @@ COMMON_CXXFLAGS = -frtti -fprofile-arcs -ftest-coverage -fpermissive # Define the source files rdkfw_device_status_gtest_SOURCES = device_status_helper_gtest.cpp ./mocks/device_status_helper_mock.cpp ../src/device_status_helper.c ../src/download_status_helper.c -rdkfw_deviceutils_gtest_SOURCES = deviceutils/device_api_gtest.cpp deviceutils/deviceutils_gtest.cpp deviceutils/json_parse.c ./mocks/deviceutils_mock.cpp ../src/deviceutils/device_api.c ../src/deviceutils/deviceutils.c ../src/rfcInterface/rfcinterface.c +rdkfw_deviceutils_gtest_SOURCES = deviceutils/device_api_gtest.cpp deviceutils/deviceutils_gtest.cpp deviceutils/json_parse.c ./mocks/deviceutils_mock.cpp ../src/deviceutils/device_api.c ../src/deviceutils/deviceutils.c ../src/rfcInterface/rfcinterface.c ./mocks/interface_mock.cpp # rdkfw_main_gtest: Tests core firmware upgrade logic (rdkv_main.c and rdkv_upgrade.c) # REFACTORED: Uses mocks instead of real helper implementations to avoid multiple definition errors From dc1aa2a855bbfaacaa2a384b5a30a649cdd2088c Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Wed, 11 Mar 2026 12:32:17 +0530 Subject: [PATCH 17/55] Update Makefile.am --- unittest/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/Makefile.am b/unittest/Makefile.am index b44e415e..c9e31278 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -39,7 +39,7 @@ COMMON_CXXFLAGS = -frtti -fprofile-arcs -ftest-coverage -fpermissive # Define the source files rdkfw_device_status_gtest_SOURCES = device_status_helper_gtest.cpp ./mocks/device_status_helper_mock.cpp ../src/device_status_helper.c ../src/download_status_helper.c -rdkfw_deviceutils_gtest_SOURCES = deviceutils/device_api_gtest.cpp deviceutils/deviceutils_gtest.cpp deviceutils/json_parse.c ./mocks/deviceutils_mock.cpp ../src/deviceutils/device_api.c ../src/deviceutils/deviceutils.c ../src/rfcInterface/rfcinterface.c ./mocks/interface_mock.cpp +rdkfw_deviceutils_gtest_SOURCES = deviceutils/device_api_gtest.cpp deviceutils/deviceutils_gtest.cpp deviceutils/json_parse.c ./mocks/deviceutils_mock.cpp ../src/deviceutils/device_api.c ../src/deviceutils/deviceutils.c ../src/rfcInterface/rfcinterface.c ./mocks/interface_mock.cpp fwdl_interface_gtest.cpp # rdkfw_main_gtest: Tests core firmware upgrade logic (rdkv_main.c and rdkv_upgrade.c) # REFACTORED: Uses mocks instead of real helper implementations to avoid multiple definition errors From 5880fbd61f26a8d903a772ecd8f4f4c04ebf379c Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Wed, 11 Mar 2026 15:30:40 +0530 Subject: [PATCH 18/55] Update Makefile.am --- unittest/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/Makefile.am b/unittest/Makefile.am index c13b9ed2..fe4d21c1 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -39,7 +39,7 @@ COMMON_CXXFLAGS = -frtti -fprofile-arcs -ftest-coverage -fpermissive # Define the source files rdkfw_device_status_gtest_SOURCES = device_status_helper_gtest.cpp ./mocks/device_status_helper_mock.cpp ../src/device_status_helper.c ../src/download_status_helper.c -rdkfw_deviceutils_gtest_SOURCES = deviceutils/device_api_gtest.cpp deviceutils/deviceutils_gtest.cpp deviceutils/json_parse.c ./mocks/deviceutils_mock.cpp ../src/deviceutils/device_api.c ../src/deviceutils/deviceutils.c ../src/rfcInterface/rfcinterface.c ./mocks/interface_mock.cpp fwdl_interface_gtest.cpp +rdkfw_deviceutils_gtest_SOURCES = deviceutils/device_api_gtest.cpp deviceutils/deviceutils_gtest.cpp deviceutils/json_parse.c ./mocks/deviceutils_mock.cpp ../src/deviceutils/device_api.c ../src/deviceutils/deviceutils.c # rdkfw_main_gtest: Tests core firmware upgrade logic (rdkv_main.c and rdkv_upgrade.c) # REFACTORED: Uses mocks instead of real helper implementations to avoid multiple definition errors From 35b7bad0fa05d19bb601773a85141f52c5a92b9f Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Thu, 12 Mar 2026 13:30:44 +0530 Subject: [PATCH 19/55] Update rfcinterface.h --- src/include/rfcinterface.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/include/rfcinterface.h b/src/include/rfcinterface.h index c7994a7e..27194510 100644 --- a/src/include/rfcinterface.h +++ b/src/include/rfcinterface.h @@ -15,6 +15,9 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#ifdef __cplusplus +extern "C" { +#endif #ifndef VIDEO_RFCINTERFACE_RFCINTERFACE_H_ #define VIDEO_RFCINTERFACE_RFCINTERFACE_H_ @@ -102,3 +105,7 @@ bool isDebugServicesEnabled(void); void getDeviceTypeRFC(char *deviceType, size_t size); #endif /* VIDEO_RFCINTERFACE_RFCINTERFACE_H_ */ + +#ifdef __cplusplus +} +#endif From ac064ff61d86fb9d71a3e4f96a98b39608ca9949 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Thu, 12 Mar 2026 13:35:04 +0530 Subject: [PATCH 20/55] Update deviceutils_mock.cpp --- unittest/mocks/deviceutils_mock.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/unittest/mocks/deviceutils_mock.cpp b/unittest/mocks/deviceutils_mock.cpp index d7cdb51c..de2cc186 100644 --- a/unittest/mocks/deviceutils_mock.cpp +++ b/unittest/mocks/deviceutils_mock.cpp @@ -56,6 +56,12 @@ extern "C" FILE* v_secure_popen(const char *mode, ...) return g_DeviceUtilsMock->v_secure_popen(mode, cmd); }*/ +extern "C" void getDeviceTypeRFC(char *deviceType, size_t size) +{ + if (g_DeviceUtilsMock) + g_DeviceUtilsMock->getDeviceTypeRFC(deviceType, size); +} + extern "C" int v_secure_pclose(FILE *fp) { if (!g_DeviceUtilsMock) From 371e13a275dba612a8ab169f5e6921d2aff01da8 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Thu, 12 Mar 2026 13:35:51 +0530 Subject: [PATCH 21/55] Update deviceutils_mock.h --- unittest/mocks/deviceutils_mock.h | 1 + 1 file changed, 1 insertion(+) diff --git a/unittest/mocks/deviceutils_mock.h b/unittest/mocks/deviceutils_mock.h index 8d3c9d48..9235ed53 100644 --- a/unittest/mocks/deviceutils_mock.h +++ b/unittest/mocks/deviceutils_mock.h @@ -63,6 +63,7 @@ class DeviceUtilsMock: public DeviceUtilsInterface MOCK_METHOD(int, getFileSize, (const char *filename ), ()); MOCK_METHOD(bool, isInStateRed, (), ()); MOCK_METHOD(bool, isDebugServicesEnabled, (), ()); + MOCK_METHOD(void, getDeviceTypeRFC, (char*, size_t)); MOCK_METHOD(size_t, GetHwMacAddress, (char *iface, char *pMac, size_t szBufSize), ()); MOCK_METHOD(size_t, GetModelNum, ( char *pModelNum, size_t szBufSize ), ()); MOCK_METHOD(void, t2CountNotify, (char *marker), ()); From a03d1977a60ee660dd36cd43b164278d0f147bc2 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:33:03 +0530 Subject: [PATCH 22/55] Update rfcinterface.h --- src/include/rfcinterface.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/include/rfcinterface.h b/src/include/rfcinterface.h index 27194510..20e55b0b 100644 --- a/src/include/rfcinterface.h +++ b/src/include/rfcinterface.h @@ -15,9 +15,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifdef __cplusplus -extern "C" { -#endif + #ifndef VIDEO_RFCINTERFACE_RFCINTERFACE_H_ #define VIDEO_RFCINTERFACE_RFCINTERFACE_H_ From 3a8ea33800fe64296512a8215f8f4db143ca1c9d Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:33:17 +0530 Subject: [PATCH 23/55] Update rfcinterface.h --- src/include/rfcinterface.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/include/rfcinterface.h b/src/include/rfcinterface.h index 20e55b0b..e0bb3863 100644 --- a/src/include/rfcinterface.h +++ b/src/include/rfcinterface.h @@ -16,7 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 */ - #ifndef VIDEO_RFCINTERFACE_RFCINTERFACE_H_ #define VIDEO_RFCINTERFACE_RFCINTERFACE_H_ From 8f9c8d97705aa38b9244b971599802610e24becd Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:33:37 +0530 Subject: [PATCH 24/55] Update rfcinterface.h --- src/include/rfcinterface.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/include/rfcinterface.h b/src/include/rfcinterface.h index e0bb3863..c7994a7e 100644 --- a/src/include/rfcinterface.h +++ b/src/include/rfcinterface.h @@ -102,7 +102,3 @@ bool isDebugServicesEnabled(void); void getDeviceTypeRFC(char *deviceType, size_t size); #endif /* VIDEO_RFCINTERFACE_RFCINTERFACE_H_ */ - -#ifdef __cplusplus -} -#endif From ae1143b62ff183dc1afbb63cfebb0f9ce6033eec Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 18:57:24 +0530 Subject: [PATCH 25/55] Update device_api.c --- src/deviceutils/device_api.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index b746ae21..e658588e 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -41,21 +41,18 @@ #define MAC_ADDRESS_LEN 17 /* function isSecureDbgSrvUnlocked - checks the buildtype, deviceType from RFC and enables secure debug services accordingly - Usage: bool isSecureDbgSrvUnlocked + Usage: bool isSecureDbgSrvUnlocked RETURN - True (Enables Debug Services) if buildtype is dev or buildtype is labsigned and deviceType is test */ -bool isSecureDbgSrvUnlocked(void) +bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) { char deviceType[16] = {0}; - BUILDTYPE eBuildType; bool isDebugServicesUnlocked = false; char labsigned[8] = {0}; char buildBuf[URL_MAX_LEN] = {0}; int ret = -1; - GetBuildType(buildBuf, sizeof(buildBuf), &eBuildType); - if (eBuildType == eDEV) { isDebugServicesUnlocked = true; } @@ -945,7 +942,7 @@ size_t GetServURL( char *pServURL, size_t szBufSize ) GetBuildType( buf, sizeof(buf), &eBuildType ); if( isInStateRed() ) { - if(isSecureDbgSrvUnlocked()) + if(isSecureDbgSrvUnlocked(eBuildType)) { len = GetServerUrlFile( pServURL, szBufSize, STATE_RED_CONF ); } @@ -956,7 +953,7 @@ size_t GetServURL( char *pServURL, size_t szBufSize ) } else { - if(isSecureDbgSrvUnlocked()) + if(isSecureDbgSrvUnlocked(eBuildType)) { if( (filePresentCheck( SWUPDATE_CONF ) == RDK_API_SUCCESS) ) // if the file exists { From ed81ff407f0996df5d8c5016abc8909e6463c43d Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 18:58:22 +0530 Subject: [PATCH 26/55] Update device_api.h --- src/deviceutils/device_api.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/deviceutils/device_api.h b/src/deviceutils/device_api.h index b04b4566..c4d481b3 100644 --- a/src/deviceutils/device_api.h +++ b/src/deviceutils/device_api.h @@ -309,7 +309,7 @@ size_t GetServURL(char *pServURL, size_t szBufSize); * - build type (Dev or Prod) * - LABSIGNED_ENABLED property value from /etc/device.properties * - * Usage: bool isSecureDbgSrvUnlocked(void) + * Usage: bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) * * RETURN - true if: * - the build type is Dev; or @@ -317,5 +317,5 @@ size_t GetServURL(char *pServURL, size_t szBufSize); * DeviceType is "Test", and LABSIGNED_ENABLED is set to true; * false otherwise. */ -bool isSecureDbgSrvUnlocked(void); +bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType); #endif From e2dfbcc88ced69e9a903feeffbb1d79ce2f97d4a Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 19:00:03 +0530 Subject: [PATCH 27/55] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- unittest/mocks/deviceutils_mock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/mocks/deviceutils_mock.h b/unittest/mocks/deviceutils_mock.h index 9235ed53..4a1a89ba 100644 --- a/unittest/mocks/deviceutils_mock.h +++ b/unittest/mocks/deviceutils_mock.h @@ -63,7 +63,7 @@ class DeviceUtilsMock: public DeviceUtilsInterface MOCK_METHOD(int, getFileSize, (const char *filename ), ()); MOCK_METHOD(bool, isInStateRed, (), ()); MOCK_METHOD(bool, isDebugServicesEnabled, (), ()); - MOCK_METHOD(void, getDeviceTypeRFC, (char*, size_t)); + MOCK_METHOD(void, getDeviceTypeRFC, (char*, size_t), ()); MOCK_METHOD(size_t, GetHwMacAddress, (char *iface, char *pMac, size_t szBufSize), ()); MOCK_METHOD(size_t, GetModelNum, ( char *pModelNum, size_t szBufSize ), ()); MOCK_METHOD(void, t2CountNotify, (char *marker), ()); From 032a20cb6ce783ba3f23ace8aea86352b4434271 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 19:03:21 +0530 Subject: [PATCH 28/55] Update device_api.c --- src/deviceutils/device_api.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index e658588e..f72768ed 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -50,7 +50,6 @@ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) char deviceType[16] = {0}; bool isDebugServicesUnlocked = false; char labsigned[8] = {0}; - char buildBuf[URL_MAX_LEN] = {0}; int ret = -1; if (eBuildType == eDEV) { From 89eda9943df0c3484add35231230577c15ccf855 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 21:21:56 +0530 Subject: [PATCH 29/55] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rfcInterface/rfcinterface.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rfcInterface/rfcinterface.c b/src/rfcInterface/rfcinterface.c index 7d95b1d6..40a634d6 100644 --- a/src/rfcInterface/rfcinterface.c +++ b/src/rfcInterface/rfcinterface.c @@ -289,10 +289,11 @@ bool isDebugServicesEnabled(void) } -/* Description: Checking device type rfc value - * @param type : void - * @return test, if deviceType RFC is set to test, prod if deviceType is set to prod, else unknown - * */ +/* Description: Reads the device type RFC value and copies it into the provided buffer. + * @param deviceType Output buffer that receives the device type string ("test", "prod", or "unknown"). + * @param size Size of the deviceType buffer in bytes; must be greater than 0. The string is always NUL-terminated. + * @return void. On error or unrecognized RFC value, "unknown" is written to deviceType (if size > 0). + */ void getDeviceTypeRFC(char *deviceType, size_t size ){ if (deviceType == NULL || size == 0){ From 806f9d9961628849b178b798b2b735018cf5b6ff Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 22:02:59 +0530 Subject: [PATCH 30/55] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- unittest/mocks/deviceutils_mock.h | 1 + 1 file changed, 1 insertion(+) diff --git a/unittest/mocks/deviceutils_mock.h b/unittest/mocks/deviceutils_mock.h index 4a1a89ba..9af9c09a 100644 --- a/unittest/mocks/deviceutils_mock.h +++ b/unittest/mocks/deviceutils_mock.h @@ -37,6 +37,7 @@ class DeviceUtilsInterface virtual int getJsonRpcData(void *Curl_req, FileDwnl_t *req_data, char token_header, int httpCode ) = 0; virtual int getDevicePropertyData(const char *model, char *data, int size) = 0; virtual int read_RFCProperty(char* type, const char* key, char *out_value, size_t datasize) = 0; + virtual void getDeviceTypeRFC(char* type, size_t datasize) = 0; virtual int filePresentCheck(const char *filename) = 0; virtual int getFileSize(const char *filename) = 0; virtual bool isInStateRed() = 0; From 5762dc14a0dd857843dbc35fdcae6383620931c8 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 22:11:39 +0530 Subject: [PATCH 31/55] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/rfcInterface/rfcinterface.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rfcInterface/rfcinterface.c b/src/rfcInterface/rfcinterface.c index 40a634d6..e50fe797 100644 --- a/src/rfcInterface/rfcinterface.c +++ b/src/rfcInterface/rfcinterface.c @@ -23,6 +23,7 @@ #include "rdk_fwdl_utils.h" #include "system_utils.h" #endif +#include /* * Description: Get RFC data and store inside structure. @@ -303,7 +304,7 @@ void getDeviceTypeRFC(char *deviceType, size_t size ){ const char* type = "unknown"; char rfc_data[RFC_VALUE_BUF_SIZE] = {0}; - int ret = read_RFCProperty("LABSGND", RFC_DEVICETYPE, rfc_data, sizeof(rfc_data)); + int ret = read_RFCProperty("DEVICETYPE", RFC_DEVICETYPE, rfc_data, sizeof(rfc_data)); if (ret == -1) { SWLOG_ERROR("%s: Failed to read device type\n", __FUNCTION__); From 53eda894f8379093a347719b5c4eb6102e2361b2 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 22:12:36 +0530 Subject: [PATCH 32/55] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/deviceutils/device_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deviceutils/device_api.h b/src/deviceutils/device_api.h index c4d481b3..6e7f9fc9 100644 --- a/src/deviceutils/device_api.h +++ b/src/deviceutils/device_api.h @@ -314,7 +314,7 @@ size_t GetServURL(char *pServURL, size_t szBufSize); * RETURN - true if: * - the build type is Dev; or * - the build type is Prod, DbgServices RFC is enabled, - * DeviceType is "Test", and LABSIGNED_ENABLED is set to true; + * DeviceType is "test", and LABSIGNED_ENABLED is set to true; * false otherwise. */ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType); From 84e22d203a039a218b8c93259cce13d563865f93 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Mon, 16 Mar 2026 22:13:28 +0530 Subject: [PATCH 33/55] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- unittest/mocks/deviceutils_mock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/mocks/deviceutils_mock.h b/unittest/mocks/deviceutils_mock.h index 9af9c09a..dccad764 100644 --- a/unittest/mocks/deviceutils_mock.h +++ b/unittest/mocks/deviceutils_mock.h @@ -37,7 +37,7 @@ class DeviceUtilsInterface virtual int getJsonRpcData(void *Curl_req, FileDwnl_t *req_data, char token_header, int httpCode ) = 0; virtual int getDevicePropertyData(const char *model, char *data, int size) = 0; virtual int read_RFCProperty(char* type, const char* key, char *out_value, size_t datasize) = 0; - virtual void getDeviceTypeRFC(char* type, size_t datasize) = 0; + virtual void getDeviceTypeRFC(char* deviceType, size_t datasize) = 0; virtual int filePresentCheck(const char *filename) = 0; virtual int getFileSize(const char *filename) = 0; virtual bool isInStateRed() = 0; From 7fd8c672bb8ba2fd8261378fb8a361ddaa4e9ffc Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 10:31:19 +0530 Subject: [PATCH 34/55] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/deviceutils/device_api.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index f72768ed..d023baea 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -60,24 +60,31 @@ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) bool dbgServices = isDebugServicesEnabled(); getDeviceTypeRFC(deviceType, sizeof(deviceType)); ret = getDevicePropertyData("LABSIGNED_ENABLED", labsigned, sizeof(labsigned)); - if (ret == UTILS_SUCCESS && (0 == (strncmp(labsigned, "true", 4)))) + if (ret == UTILS_SUCCESS) { - SWLOG_INFO("labsigned_enabled is = %s\n", labsigned); - if ((strcmp(deviceType, "test") == 0) && dbgServices) + if (0 == strncmp(labsigned, "true", 4)) { - SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); - SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); - isDebugServicesUnlocked = true; - } - else - { - SWLOG_INFO("isSecureDbgSrvUnlocked: unable to enable debug services...\n"); - SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); + SWLOG_INFO("labsigned_enabled is = %s\n", labsigned); + if ((strcmp(deviceType, "test") == 0) && dbgServices) + { + SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); + SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); + isDebugServicesUnlocked = true; + } + else + { + SWLOG_INFO("isSecureDbgSrvUnlocked: unable to enable debug services...\n"); + SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); + } + } + else + { + SWLOG_INFO("LABSIGNED_ENABLED not enabled (value: %s); debug services remain locked\n", labsigned); } } else { - SWLOG_ERROR("%s: getDevicePropertyData() for labsigned_enabled fail\n", __FUNCTION__); + SWLOG_ERROR("%s: getDevicePropertyData() for LABSIGNED_ENABLED failed\n", __FUNCTION__); } } return isDebugServicesUnlocked; From 1ae5164d48d23f73b288862759e01685bdeb8c80 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 10:43:27 +0530 Subject: [PATCH 35/55] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/deviceutils/device_api.c | 21 ++++++++++++++------- unittest/mocks/deviceutils_mock.cpp | 10 ++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index d023baea..3b719c57 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -40,11 +40,18 @@ #define MAC_ADDRESS_LEN 17 -/* function isSecureDbgSrvUnlocked - checks the buildtype, deviceType from RFC and enables secure debug services accordingly - Usage: bool isSecureDbgSrvUnlocked - - RETURN - True (Enables Debug Services) if buildtype is dev or buildtype is labsigned and deviceType is test -*/ +/* function isSecureDbgSrvUnlocked - determines whether secure debug services may be enabled for the given build type. + * Usage: bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) + * + * For eDEV builds, debug services are always unlocked. + * + * For ePROD builds, debug services are unlocked only when all of the following are true: + * - debug services are enabled via isDebugServicesEnabled() (RFC-controlled), + * - the LABSIGNED_ENABLED device property indicates a labsigned image, and + * - the deviceType value from RFC allows test devices (for example "test"). + * + * RETURN - true if secure debug services are allowed to run for the given build type; false otherwise. + */ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) { char deviceType[16] = {0}; @@ -68,14 +75,14 @@ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) if ((strcmp(deviceType, "test") == 0) && dbgServices) { SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); - SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); isDebugServicesUnlocked = true; } else { SWLOG_INFO("isSecureDbgSrvUnlocked: unable to enable debug services...\n"); - SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n",dbgServices ? "true" : "false", deviceType, labsigned); } + SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n", + dbgServices ? "true" : "false", deviceType, labsigned); } else { diff --git a/unittest/mocks/deviceutils_mock.cpp b/unittest/mocks/deviceutils_mock.cpp index de2cc186..4a03d534 100644 --- a/unittest/mocks/deviceutils_mock.cpp +++ b/unittest/mocks/deviceutils_mock.cpp @@ -59,7 +59,17 @@ extern "C" FILE* v_secure_popen(const char *mode, ...) extern "C" void getDeviceTypeRFC(char *deviceType, size_t size) { if (g_DeviceUtilsMock) + { g_DeviceUtilsMock->getDeviceTypeRFC(deviceType, size); + } + else + { + cout << "getDeviceTypeRFC g_DeviceUtilsMock object is NULL" << endl; + if (deviceType != nullptr && size > 0) + { + deviceType[0] = '\0'; + } + } } extern "C" int v_secure_pclose(FILE *fp) From cf280e9db932dd2caa157870644ada358f1c4456 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 12:10:43 +0530 Subject: [PATCH 36/55] Update device_api.h --- src/deviceutils/device_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deviceutils/device_api.h b/src/deviceutils/device_api.h index 6e7f9fc9..19a36969 100644 --- a/src/deviceutils/device_api.h +++ b/src/deviceutils/device_api.h @@ -26,7 +26,7 @@ #ifndef GTEST_ENABLE #include "rdk_fwdl_utils.h" #include "common_device_api.h" -//#include "rdkv_cdl_log_wrapper.h" +#include "rdkv_cdl_log_wrapper.h" extern char* strcasestr(const char* s1, const char* s2); #endif From e4700bd040f87dad099f5ef4ace0e1867fb01a2e Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 12:26:19 +0530 Subject: [PATCH 37/55] Update device_api.c --- src/deviceutils/device_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index 3b719c57..2b1a7e32 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -43,7 +43,7 @@ /* function isSecureDbgSrvUnlocked - determines whether secure debug services may be enabled for the given build type. * Usage: bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) * - * For eDEV builds, debug services are always unlocked. + * For non-prod builds, debug services are always unlocked. * * For ePROD builds, debug services are unlocked only when all of the following are true: * - debug services are enabled via isDebugServicesEnabled() (RFC-controlled), @@ -59,7 +59,7 @@ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) char labsigned[8] = {0}; int ret = -1; - if (eBuildType == eDEV) { + if (eBuildType != ePROD) { isDebugServicesUnlocked = true; } else if (eBuildType == ePROD) From eda7376593acf5fa093f3de5a8506eb0053634c7 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 12:40:05 +0530 Subject: [PATCH 38/55] Update device_api.h --- src/deviceutils/device_api.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/deviceutils/device_api.h b/src/deviceutils/device_api.h index 19a36969..d7e8421b 100644 --- a/src/deviceutils/device_api.h +++ b/src/deviceutils/device_api.h @@ -23,10 +23,14 @@ #define GETRDMMANIFESTVERSION_IN_SCRIPT #endif +#ifdef GTEST_ENABLE +#include "rdkv_cdl_log_wrapper.h" +#endif + #ifndef GTEST_ENABLE #include "rdk_fwdl_utils.h" #include "common_device_api.h" -#include "rdkv_cdl_log_wrapper.h" +//#include "rdkv_cdl_log_wrapper.h" extern char* strcasestr(const char* s1, const char* s2); #endif From 276ad3fd228a77cae6ee448a79588dcf8fe2ed33 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 13:17:15 +0530 Subject: [PATCH 39/55] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/deviceutils/device_api.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/deviceutils/device_api.h b/src/deviceutils/device_api.h index d7e8421b..ca57592d 100644 --- a/src/deviceutils/device_api.h +++ b/src/deviceutils/device_api.h @@ -310,13 +310,13 @@ size_t GetServURL(char *pServURL, size_t szBufSize); * The decision is based on: * - DbgServices RFC * - DeviceType RFC - * - build type (Dev or Prod) + * - build type (Prod vs non-Prod, for example ePROD vs non-ePROD) * - LABSIGNED_ENABLED property value from /etc/device.properties * * Usage: bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) * * RETURN - true if: - * - the build type is Dev; or + * - the build type is non-Prod (for example, any non-ePROD build type); or * - the build type is Prod, DbgServices RFC is enabled, * DeviceType is "test", and LABSIGNED_ENABLED is set to true; * false otherwise. From 30842358690c52d751408c7b114238b465f3cdc1 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 13:54:15 +0530 Subject: [PATCH 40/55] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- unittest/mocks/deviceutils_mock.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/unittest/mocks/deviceutils_mock.cpp b/unittest/mocks/deviceutils_mock.cpp index 4a03d534..c2ba73bf 100644 --- a/unittest/mocks/deviceutils_mock.cpp +++ b/unittest/mocks/deviceutils_mock.cpp @@ -67,7 +67,15 @@ extern "C" void getDeviceTypeRFC(char *deviceType, size_t size) cout << "getDeviceTypeRFC g_DeviceUtilsMock object is NULL" << endl; if (deviceType != nullptr && size > 0) { - deviceType[0] = '\0'; + const char *defaultType = "unknown"; + size_t i = 0; + /* Copy up to size - 1 characters from defaultType, then NUL-terminate */ + while (i + 1 < size && defaultType[i] != '\0') + { + deviceType[i] = defaultType[i]; + ++i; + } + deviceType[i] = '\0'; } } } From 512e78f68764dc9eb7a30cbdd912539e85f17787 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:19:21 +0530 Subject: [PATCH 41/55] Update device_api_gtest.cpp --- unittest/deviceutils/device_api_gtest.cpp | 168 ++++++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/unittest/deviceutils/device_api_gtest.cpp b/unittest/deviceutils/device_api_gtest.cpp index f7918bbd..2e71f514 100644 --- a/unittest/deviceutils/device_api_gtest.cpp +++ b/unittest/deviceutils/device_api_gtest.cpp @@ -35,6 +35,8 @@ using namespace testing; using namespace std; using ::testing::Return; using ::testing::StrEq; +using ::testing::Invoke; +using ::testing::DoAll; //DeviceUtilsMock *g_DeviceApiMock = NULL; @@ -496,6 +498,133 @@ TEST_F(DeviceApiTestFixture, TestName_GetFileContents_Fail) } */ +/* isSecureDbgSrvUnlocked tests: verify the new ePROD gating logic that requires + * isDebugServicesEnabled (RFC), deviceType == "test" (RFC), and LABSIGNED_ENABLED == "true" + * to all be true before unlocking debug services on production builds. + */ + +/* Non-PROD build type: debug services are always unlocked regardless of other conditions */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_NonProd_AlwaysUnlocked) +{ + EXPECT_TRUE(isSecureDbgSrvUnlocked(eVBN)); +} + +/* ePROD + labsigned=true + deviceType=test + dbgServices=true → unlocked */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_Labsigned_DeviceTypeTest_DbgEnabled) +{ + EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "test", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Invoke([](const char* /*model*/, char* data, int size) { + strncpy(data, "true", size - 1); + data[size - 1] = '\0'; + return 0; + })); + EXPECT_TRUE(isSecureDbgSrvUnlocked(ePROD)); +} + +/* ePROD + labsigned=true + deviceType=prod (not "test") → locked */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_Labsigned_DeviceTypeProd_Locked) +{ + EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "prod", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Invoke([](const char* /*model*/, char* data, int size) { + strncpy(data, "true", size - 1); + data[size - 1] = '\0'; + return 0; + })); + EXPECT_FALSE(isSecureDbgSrvUnlocked(ePROD)); +} + +/* ePROD + labsigned=true + deviceType=unknown → locked */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_Labsigned_DeviceTypeUnknown_Locked) +{ + EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "unknown", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Invoke([](const char* /*model*/, char* data, int size) { + strncpy(data, "true", size - 1); + data[size - 1] = '\0'; + return 0; + })); + EXPECT_FALSE(isSecureDbgSrvUnlocked(ePROD)); +} + +/* ePROD + labsigned=false → locked regardless of deviceType or dbgServices */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_LabsignedFalse_Locked) +{ + EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "test", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Invoke([](const char* /*model*/, char* data, int size) { + strncpy(data, "false", size - 1); + data[size - 1] = '\0'; + return 0; + })); + EXPECT_FALSE(isSecureDbgSrvUnlocked(ePROD)); +} + +/* ePROD + labsigned=true + deviceType=test + dbgServices=false → locked */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_Labsigned_DeviceTypeTest_DbgDisabled_Locked) +{ + EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(false)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "test", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Invoke([](const char* /*model*/, char* data, int size) { + strncpy(data, "true", size - 1); + data[size - 1] = '\0'; + return 0; + })); + EXPECT_FALSE(isSecureDbgSrvUnlocked(ePROD)); +} + +/* ePROD + getDevicePropertyData fails → locked */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_LabsignedPropertyFails_Locked) +{ + EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "test", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Return(-1)); + EXPECT_FALSE(isSecureDbgSrvUnlocked(ePROD)); +} + TEST_F(DeviceApiTestFixture, TestName_GetServURL_Nullcheck) { EXPECT_EQ(GetServURL(NULL, 0), 0); @@ -548,6 +677,19 @@ TEST_F(DeviceApiTestFixture, TestName_GetServURL_SuccessStatered_Prod_DebugServi ret = system("echo \"BUILD_TYPE=PROD\" > /tmp/device_gtest.prop"); //EXPECT_CALL(*g_DeviceUtilsMock, filePresentCheck(_)).Times(1).WillOnce(Return(1)); EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "test", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Invoke([](const char* /*model*/, char* data, int size) { + strncpy(data, "true", size - 1); + data[size - 1] = '\0'; + return 0; + })); ret = system("echo \"https://www.statered.com\" > /tmp/stateredrecovry.conf"); ret = GetServURL(output, sizeof(output)); EXPECT_EQ(strncmp(output,servUrl,strlen(servUrl)),0); @@ -567,6 +709,19 @@ TEST_F(DeviceApiTestFixture, TestName_GetServURL_SuccessStatered_Prod_DebugServi ret = system("echo \"BUILD_TYPE=PROD\" > /tmp/device_gtest.prop"); //EXPECT_CALL(*g_DeviceUtilsMock, filePresentCheck(_)).Times(1).WillOnce(Return(1)); EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(false)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "test", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Invoke([](const char* /*model*/, char* data, int size) { + strncpy(data, "true", size - 1); + data[size - 1] = '\0'; + return 0; + })); ret = system("echo \"https://www.statered.com\" > /tmp/stateredrecovry.conf"); ret = system("echo \"https://www.autotool.com\" > /tmp/swupdate.conf"); EXPECT_CALL(*g_DeviceUtilsMock, read_RFCProperty(_, _, _, _)) @@ -634,6 +789,19 @@ TEST_F(DeviceApiTestFixture, TestName_GetServURL_SuccessSwupdate_Prod_DebugServi EXPECT_CALL(*g_DeviceUtilsMock, filePresentCheck(_)).Times(1).WillOnce(Return(0)); ret = system("echo \"BUILD_TYPE=PROD\" > /tmp/device_gtest.prop"); EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "test", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Invoke([](const char* /*model*/, char* data, int size) { + strncpy(data, "true", size - 1); + data[size - 1] = '\0'; + return 0; + })); ret = system("echo \"https://www.rdkautotool.com\" > /tmp/swupdate.conf"); ret=GetServURL(output , sizeof(output)); EXPECT_EQ(strncmp(output , servUrl , strlen(servUrl)),0); From 6b3ad1541285e9d4836ff31ab7891054bb72b69c Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 14:20:20 +0530 Subject: [PATCH 42/55] Update fwdl_interface_gtest.cpp --- unittest/fwdl_interface_gtest.cpp | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/unittest/fwdl_interface_gtest.cpp b/unittest/fwdl_interface_gtest.cpp index 01ef3c80..855db210 100644 --- a/unittest/fwdl_interface_gtest.cpp +++ b/unittest/fwdl_interface_gtest.cpp @@ -171,6 +171,63 @@ TEST_F(InterfaceTestFixture, TestName_isDebugServicesEnableSuccess) EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)).Times(1).WillOnce(Return(1)); EXPECT_EQ(isDebugServicesEnabled(), true); } +TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCNullArgs) +{ + /* NULL buffer and zero size must not crash and must not call getRFCParameter */ + char buf[16]; + memset(buf, 'X', sizeof(buf)); + getDeviceTypeRFC(NULL, sizeof(buf)); + getDeviceTypeRFC(buf, 0); + /* buf[0] must remain 'X' because size == 0 means nothing should be written */ + EXPECT_EQ(buf[0], 'X'); +} +TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCReadFailure) +{ + /* When RFC read fails, result must be "unknown" */ + char deviceType[32] = {0}; + EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)).Times(1).WillOnce(Return(0)); + getDeviceTypeRFC(deviceType, sizeof(deviceType)); + EXPECT_STREQ(deviceType, "unknown"); +} +TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCProd) +{ + /* When RFC value is "prod", result must be "prod" */ + char deviceType[32] = {0}; + EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)) + .Times(1) + .WillOnce(Invoke([](char* /*type*/, const char* /*key*/, RFC_ParamData_t *param) { + snprintf(param->value, sizeof(param->value), "%s", "prod"); + return WDMP_SUCCESS; + })); + getDeviceTypeRFC(deviceType, sizeof(deviceType)); + EXPECT_STREQ(deviceType, "prod"); +} +TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCTest) +{ + /* When RFC value is "test", result must be "test" */ + char deviceType[32] = {0}; + EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)) + .Times(1) + .WillOnce(Invoke([](char* /*type*/, const char* /*key*/, RFC_ParamData_t *param) { + snprintf(param->value, sizeof(param->value), "%s", "test"); + return WDMP_SUCCESS; + })); + getDeviceTypeRFC(deviceType, sizeof(deviceType)); + EXPECT_STREQ(deviceType, "test"); +} +TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCUnknown) +{ + /* When RFC value is unrecognized, result must be "unknown" */ + char deviceType[32] = {0}; + EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)) + .Times(1) + .WillOnce(Invoke([](char* /*type*/, const char* /*key*/, RFC_ParamData_t *param) { + snprintf(param->value, sizeof(param->value), "%s", "staging"); + return WDMP_SUCCESS; + })); + getDeviceTypeRFC(deviceType, sizeof(deviceType)); + EXPECT_STREQ(deviceType, "unknown"); +} TEST_F(InterfaceTestFixture, TestName_isIncremetalCDLEnableSuccess) { EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)).Times(1).WillOnce(Return(1)); From ef9c8446fb774d715539d242d583b2e9b128ad78 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 18:54:32 +0530 Subject: [PATCH 43/55] Update device_api.c --- src/deviceutils/device_api.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index 2b1a7e32..9cb09e11 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -59,9 +59,10 @@ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) char labsigned[8] = {0}; int ret = -1; - if (eBuildType != ePROD) { + if ((eBuildType != ePROD) && (eBuildType != eUNKNOWN)) { isDebugServicesUnlocked = true; } + else if (eBuildType == ePROD) { bool dbgServices = isDebugServicesEnabled(); @@ -71,18 +72,14 @@ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) { if (0 == strncmp(labsigned, "true", 4)) { - SWLOG_INFO("labsigned_enabled is = %s\n", labsigned); if ((strcmp(deviceType, "test") == 0) && dbgServices) { - SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); isDebugServicesUnlocked = true; } else { SWLOG_INFO("isSecureDbgSrvUnlocked: unable to enable debug services...\n"); } - SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n", - dbgServices ? "true" : "false", deviceType, labsigned); } else { @@ -92,7 +89,12 @@ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) else { SWLOG_ERROR("%s: getDevicePropertyData() for LABSIGNED_ENABLED failed\n", __FUNCTION__); - } + } + SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n", dbgServices ? "true" : "false", deviceType, labsigned); + if(isDebugServicesUnlocked){ + SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); + t2CountNotify("SYST_INFO_FW_DbgSrv", 1); + } } return isDebugServicesUnlocked; } From 0d99df79d6b481145d3de2c6f0c0d0278b2a55d4 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 20:51:56 +0530 Subject: [PATCH 44/55] Update dbus_handlers_gmock.cpp --- unittest/mocks/dbus_handlers_gmock.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unittest/mocks/dbus_handlers_gmock.cpp b/unittest/mocks/dbus_handlers_gmock.cpp index 595bc578..ceec0ef4 100644 --- a/unittest/mocks/dbus_handlers_gmock.cpp +++ b/unittest/mocks/dbus_handlers_gmock.cpp @@ -607,6 +607,9 @@ bool isDebugServicesEnabled(void) { return false; // Debug services not enabled by default } +void getDeviceTypeRFC(char *deviceType, size_t size) { + return NULL; // Stub +} int isInStateRed(void) { return 0; // Not in RED state by default } From 23d210ffd42d0c5085661924f2a2879b4dce8ede Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 21:28:18 +0530 Subject: [PATCH 45/55] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- unittest/deviceutils/device_api_gtest.cpp | 1 - unittest/mocks/dbus_handlers_gmock.cpp | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/unittest/deviceutils/device_api_gtest.cpp b/unittest/deviceutils/device_api_gtest.cpp index 2e71f514..209726cc 100644 --- a/unittest/deviceutils/device_api_gtest.cpp +++ b/unittest/deviceutils/device_api_gtest.cpp @@ -36,7 +36,6 @@ using namespace std; using ::testing::Return; using ::testing::StrEq; using ::testing::Invoke; -using ::testing::DoAll; //DeviceUtilsMock *g_DeviceApiMock = NULL; diff --git a/unittest/mocks/dbus_handlers_gmock.cpp b/unittest/mocks/dbus_handlers_gmock.cpp index ceec0ef4..99145687 100644 --- a/unittest/mocks/dbus_handlers_gmock.cpp +++ b/unittest/mocks/dbus_handlers_gmock.cpp @@ -608,7 +608,12 @@ bool isDebugServicesEnabled(void) { } void getDeviceTypeRFC(char *deviceType, size_t size) { - return NULL; // Stub + if (deviceType && size > 0) { + const char defaultType[] = "unknown"; + strncpy(deviceType, defaultType, size - 1); + deviceType[size - 1] = '\0'; + } + return; } int isInStateRed(void) { return 0; // Not in RED state by default From 32a739824b3dae2ae9a4d349dab01479d3b07066 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 21:40:03 +0530 Subject: [PATCH 46/55] Update device_api.c --- src/deviceutils/device_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index 9cb09e11..239d08ff 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -93,7 +93,7 @@ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n", dbgServices ? "true" : "false", deviceType, labsigned); if(isDebugServicesUnlocked){ SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); - t2CountNotify("SYST_INFO_FW_DbgSrv", 1); + t2ValNotify("SYST_INFO_FW_DbgSrv", "true"); } } return isDebugServicesUnlocked; From be1e282f1304cb5655ca44ed0f6b748e372832a4 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 21:42:27 +0530 Subject: [PATCH 47/55] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/deviceutils/device_api.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/deviceutils/device_api.h b/src/deviceutils/device_api.h index ca57592d..a4d15da7 100644 --- a/src/deviceutils/device_api.h +++ b/src/deviceutils/device_api.h @@ -310,16 +310,17 @@ size_t GetServURL(char *pServURL, size_t szBufSize); * The decision is based on: * - DbgServices RFC * - DeviceType RFC - * - build type (Prod vs non-Prod, for example ePROD vs non-ePROD) + * - build type (Prod vs non-Prod; e.g. ePROD vs known non-ePROD types; eUNKNOWN is + * treated as locked/Prod-like) * - LABSIGNED_ENABLED property value from /etc/device.properties * * Usage: bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) * * RETURN - true if: - * - the build type is non-Prod (for example, any non-ePROD build type); or + * - the build type is non-Prod (i.e. not ePROD and not eUNKNOWN); or * - the build type is Prod, DbgServices RFC is enabled, * DeviceType is "test", and LABSIGNED_ENABLED is set to true; - * false otherwise. + * false otherwise (including when the build type is eUNKNOWN). */ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType); #endif From d2922632bff495654bdbc9316b7f7cee0f0fd307 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 21:42:55 +0530 Subject: [PATCH 48/55] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- unittest/mocks/dbus_handlers_gmock.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unittest/mocks/dbus_handlers_gmock.cpp b/unittest/mocks/dbus_handlers_gmock.cpp index 99145687..c39968d4 100644 --- a/unittest/mocks/dbus_handlers_gmock.cpp +++ b/unittest/mocks/dbus_handlers_gmock.cpp @@ -607,6 +607,7 @@ bool isDebugServicesEnabled(void) { return false; // Debug services not enabled by default } +extern "C" { void getDeviceTypeRFC(char *deviceType, size_t size) { if (deviceType && size > 0) { const char defaultType[] = "unknown"; @@ -615,6 +616,7 @@ void getDeviceTypeRFC(char *deviceType, size_t size) { } return; } +} int isInStateRed(void) { return 0; // Not in RED state by default } From a0ef8bd92de1ce8946ca031e7f4757a74cd4ed67 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 21:53:06 +0530 Subject: [PATCH 49/55] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- unittest/deviceutils/device_api_gtest.cpp | 3 +++ unittest/fwdl_interface_gtest.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/unittest/deviceutils/device_api_gtest.cpp b/unittest/deviceutils/device_api_gtest.cpp index 209726cc..bc196a5a 100644 --- a/unittest/deviceutils/device_api_gtest.cpp +++ b/unittest/deviceutils/device_api_gtest.cpp @@ -689,6 +689,9 @@ TEST_F(DeviceApiTestFixture, TestName_GetServURL_SuccessStatered_Prod_DebugServi data[size - 1] = '\0'; return 0; })); + EXPECT_CALL(*g_DeviceUtilsMock, + t2ValNotify(StrEq("SYST_INFO_FW_DbgSrv"), StrEq("true"))) + .Times(1); ret = system("echo \"https://www.statered.com\" > /tmp/stateredrecovry.conf"); ret = GetServURL(output, sizeof(output)); EXPECT_EQ(strncmp(output,servUrl,strlen(servUrl)),0); diff --git a/unittest/fwdl_interface_gtest.cpp b/unittest/fwdl_interface_gtest.cpp index 855db210..07b9ec36 100644 --- a/unittest/fwdl_interface_gtest.cpp +++ b/unittest/fwdl_interface_gtest.cpp @@ -174,6 +174,7 @@ TEST_F(InterfaceTestFixture, TestName_isDebugServicesEnableSuccess) TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCNullArgs) { /* NULL buffer and zero size must not crash and must not call getRFCParameter */ + EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)).Times(0); char buf[16]; memset(buf, 'X', sizeof(buf)); getDeviceTypeRFC(NULL, sizeof(buf)); From 8f455605610657b0c92bad89459ccf00272e03f1 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Tue, 17 Mar 2026 21:54:07 +0530 Subject: [PATCH 50/55] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- unittest/deviceutils/device_api_gtest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unittest/deviceutils/device_api_gtest.cpp b/unittest/deviceutils/device_api_gtest.cpp index bc196a5a..bc7a1c8d 100644 --- a/unittest/deviceutils/device_api_gtest.cpp +++ b/unittest/deviceutils/device_api_gtest.cpp @@ -525,6 +525,8 @@ TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_Labsigned_Devi data[size - 1] = '\0'; return 0; })); + EXPECT_CALL(*g_DeviceUtilsMock, + t2ValNotify(StrEq("SYST_INFO_FW_DbgSrv"), StrEq("true"))); EXPECT_TRUE(isSecureDbgSrvUnlocked(ePROD)); } From 668dab353b8479d4386cc30fdb2996876e344e06 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Wed, 18 Mar 2026 10:15:01 +0530 Subject: [PATCH 51/55] Update device_api_gtest.cpp --- unittest/deviceutils/device_api_gtest.cpp | 55 +++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/unittest/deviceutils/device_api_gtest.cpp b/unittest/deviceutils/device_api_gtest.cpp index bc7a1c8d..96188e3f 100644 --- a/unittest/deviceutils/device_api_gtest.cpp +++ b/unittest/deviceutils/device_api_gtest.cpp @@ -625,7 +625,62 @@ TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_LabsignedPrope .WillOnce(Return(-1)); EXPECT_FALSE(isSecureDbgSrvUnlocked(ePROD)); } +/* eUNKNOWN build type → false (neither non-prod nor ePROD path triggers unlock) */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Unknown_Locked) +{ + EXPECT_FALSE(isSecureDbgSrvUnlocked(eUNKNOWN)); +} + +/* eDEV build type → true (non-prod, always unlocked) */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Dev_Unlocked) +{ + EXPECT_TRUE(isSecureDbgSrvUnlocked(eDEV)); +} +/* eQA build type → true (non-prod, always unlocked) */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_QA_Unlocked) +{ + EXPECT_TRUE(isSecureDbgSrvUnlocked(eQA)); +} + +/* ePROD + labsigned=true + deviceType=prod + dbgServices=false → locked ("unable to enable debug services") */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_Labsigned_DeviceTypeProd_Locked) +{ + EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(false)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "prod", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Invoke([](const char* /*model*/, char* data, int size) { + strncpy(data, "true", size - 1); + data[size - 1] = '\0'; + return 0; + })); + EXPECT_FALSE(isSecureDbgSrvUnlocked(ePROD)); +} + +/* ePROD + labsigned empty string → locked ("LABSIGNED_ENABLED not enabled" log path) */ +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_LabsignedEmpty_Locked) +{ + EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) + .Times(1) + .WillOnce(Invoke([](char* deviceType, size_t size) { + strncpy(deviceType, "test", size - 1); + deviceType[size - 1] = '\0'; + })); + EXPECT_CALL(*g_DeviceUtilsMock, getDevicePropertyData(StrEq("LABSIGNED_ENABLED"), _, _)) + .Times(1) + .WillOnce(Invoke([](const char* /*model*/, char* data, int /*size*/) { + data[0] = '\0'; + return 0; + })); + EXPECT_FALSE(isSecureDbgSrvUnlocked(ePROD)); +} TEST_F(DeviceApiTestFixture, TestName_GetServURL_Nullcheck) { EXPECT_EQ(GetServURL(NULL, 0), 0); From e831411eb61b15a2123fc254cb3cf4fee49cf350 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Wed, 18 Mar 2026 10:22:38 +0530 Subject: [PATCH 52/55] Update fwdl_interface_gtest.cpp --- unittest/fwdl_interface_gtest.cpp | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/unittest/fwdl_interface_gtest.cpp b/unittest/fwdl_interface_gtest.cpp index 07b9ec36..d405a56c 100644 --- a/unittest/fwdl_interface_gtest.cpp +++ b/unittest/fwdl_interface_gtest.cpp @@ -229,6 +229,71 @@ TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCUnknown) getDeviceTypeRFC(deviceType, sizeof(deviceType)); EXPECT_STREQ(deviceType, "unknown"); } +/* Case-insensitive match: "PROD" (uppercase) → "prod" */ +TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCProdUpperCase) +{ + char deviceType[32] = {0}; + EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)) + .Times(1) + .WillOnce(Invoke([](char* /*type*/, const char* /*key*/, RFC_ParamData_t *param) { + snprintf(param->value, sizeof(param->value), "%s", "PROD"); + return WDMP_SUCCESS; + })); + getDeviceTypeRFC(deviceType, sizeof(deviceType)); + EXPECT_STREQ(deviceType, "prod"); +} +/* Case-insensitive match: "TEST" (uppercase) → "test" */ +TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCTestUpperCase) +{ + char deviceType[32] = {0}; + EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)) + .Times(1) + .WillOnce(Invoke([](char* /*type*/, const char* /*key*/, RFC_ParamData_t *param) { + snprintf(param->value, sizeof(param->value), "%s", "TEST"); + return WDMP_SUCCESS; + })); + getDeviceTypeRFC(deviceType, sizeof(deviceType)); + EXPECT_STREQ(deviceType, "test"); +} +/* Case-insensitive match: "Prod" (mixed case) → "prod" */ +TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCProdMixedCase) +{ + char deviceType[32] = {0}; + EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)) + .Times(1) + .WillOnce(Invoke([](char* /*type*/, const char* /*key*/, RFC_ParamData_t *param) { + snprintf(param->value, sizeof(param->value), "%s", "Prod"); + return WDMP_SUCCESS; + })); + getDeviceTypeRFC(deviceType, sizeof(deviceType)); + EXPECT_STREQ(deviceType, "prod"); +} +/* Buffer size = 1 → empty NUL-terminated string (truncation edge case) */ +TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCBufferSizeOne) +{ + char deviceType[1] = {'X'}; + EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)) + .Times(1) + .WillOnce(Invoke([](char* /*type*/, const char* /*key*/, RFC_ParamData_t *param) { + snprintf(param->value, sizeof(param->value), "%s", "prod"); + return WDMP_SUCCESS; + })); + getDeviceTypeRFC(deviceType, 1); + EXPECT_EQ(deviceType[0], '\0'); +} +/* Empty string from RFC → "unknown" */ +TEST_F(InterfaceTestFixture, TestName_getDeviceTypeRFCEmptyString) +{ + char deviceType[32] = {0}; + EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)) + .Times(1) + .WillOnce(Invoke([](char* /*type*/, const char* /*key*/, RFC_ParamData_t *param) { + snprintf(param->value, sizeof(param->value), "%s", ""); + return WDMP_SUCCESS; + })); + getDeviceTypeRFC(deviceType, sizeof(deviceType)); + EXPECT_STREQ(deviceType, "unknown"); +} TEST_F(InterfaceTestFixture, TestName_isIncremetalCDLEnableSuccess) { EXPECT_CALL(*g_InterfaceMock, getRFCParameter(_, _, _)).Times(1).WillOnce(Return(1)); From e31c31362f37ec5c4e87d1b949710d6ab57d7f19 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Wed, 18 Mar 2026 10:45:19 +0530 Subject: [PATCH 53/55] Update device_api_gtest.cpp --- unittest/deviceutils/device_api_gtest.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/unittest/deviceutils/device_api_gtest.cpp b/unittest/deviceutils/device_api_gtest.cpp index 96188e3f..e935ae57 100644 --- a/unittest/deviceutils/device_api_gtest.cpp +++ b/unittest/deviceutils/device_api_gtest.cpp @@ -694,7 +694,6 @@ TEST_F(DeviceApiTestFixture, TestName_GetServURL_SuccessStatered_DebugServices_E //EXPECT_CALL(*g_DeviceUtilsMock, read_RFCProperty(_, _, _, _)).Times(1).WillOnce(Return(1)); ret = system("echo \"BUILD_TYPE=vbn\" > /tmp/device_gtest.prop"); //EXPECT_CALL(*g_DeviceUtilsMock, filePresentCheck(_)).Times(1).WillOnce(Return(1)); - EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(true)); ret = system("echo \"https://www.statered.com\" > /tmp/stateredrecovry.conf"); ret = GetServURL(output, sizeof(output)); EXPECT_EQ(strncmp(output,servUrl,strlen(servUrl)),0); @@ -713,7 +712,6 @@ TEST_F(DeviceApiTestFixture, TestName_GetServURL_SuccessStatered_DebugServices_D //EXPECT_CALL(*g_DeviceUtilsMock, read_RFCProperty(_, _, _, _)).Times(1).WillOnce(Return(1)); ret = system("echo \"BUILD_TYPE=vbn\" > /tmp/device_gtest.prop"); //EXPECT_CALL(*g_DeviceUtilsMock, filePresentCheck(_)).Times(1).WillOnce(Return(1)); - EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(false)); ret = system("echo \"https://www.statered.com\" > /tmp/stateredrecovry.conf"); ret = GetServURL(output, sizeof(output)); EXPECT_EQ(strncmp(output,servUrl,strlen(servUrl)),0); @@ -808,7 +806,6 @@ TEST_F(DeviceApiTestFixture, TestName_GetServURL_SuccessSwupdate_DebugServices_E EXPECT_CALL(*g_DeviceUtilsMock, filePresentCheck(_)).Times(1).WillOnce(Return(0)); //EXPECT_CALL(*g_DeviceUtilsMock, read_RFCProperty(_, _, _, _)).Times(1).WillOnce(Return(1)); ret = system("echo \"BUILD_TYPE=vbn\" > /tmp/device_gtest.prop"); - EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(true)); ret = system("echo \"https://www.rdkautotool.com\" > /tmp/swupdate.conf"); ret=GetServURL(output , sizeof(output)); EXPECT_EQ(strncmp(output , servUrl , strlen(servUrl)),0); @@ -828,7 +825,6 @@ TEST_F(DeviceApiTestFixture, TestName_GetServURL_SuccessSwupdate_DebugServices_D EXPECT_CALL(*g_DeviceUtilsMock, filePresentCheck(_)).Times(1).WillOnce(Return(0)); //EXPECT_CALL(*g_DeviceUtilsMock, read_RFCProperty(_, _, _, _)).Times(1).WillOnce(Return(1)); ret = system("echo \"BUILD_TYPE=vbn\" > /tmp/device_gtest.prop"); - EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(false)); ret = system("echo \"https://www.rdkautotool.com\" > /tmp/swupdate.conf"); ret=GetServURL(output , sizeof(output)); EXPECT_EQ(strncmp(output , servUrl , strlen(servUrl)),0); From 38bbb2fe14626a4dfc21401ec3740e5e9183390d Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Wed, 18 Mar 2026 11:19:38 +0530 Subject: [PATCH 54/55] Update device_api_gtest.cpp --- unittest/deviceutils/device_api_gtest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/deviceutils/device_api_gtest.cpp b/unittest/deviceutils/device_api_gtest.cpp index e935ae57..23e62bee 100644 --- a/unittest/deviceutils/device_api_gtest.cpp +++ b/unittest/deviceutils/device_api_gtest.cpp @@ -644,7 +644,7 @@ TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_QA_Unlocked) } /* ePROD + labsigned=true + deviceType=prod + dbgServices=false → locked ("unable to enable debug services") */ -TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_Labsigned_DeviceTypeProd_Locked) +TEST_F(DeviceApiTestFixture, TestName_isSecureDbgSrvUnlocked_Prod_Labsigned_DeviceTypeProd_DbgDisabled_Locked) { EXPECT_CALL(*g_DeviceUtilsMock, isDebugServicesEnabled()).Times(1).WillOnce(Return(false)); EXPECT_CALL(*g_DeviceUtilsMock, getDeviceTypeRFC(_, _)) From 984b7e837dceb908f898742e01e03a39ffd48c53 Mon Sep 17 00:00:00 2001 From: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com> Date: Wed, 18 Mar 2026 16:03:15 +0530 Subject: [PATCH 55/55] Update device_api.c --- src/deviceutils/device_api.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/deviceutils/device_api.c b/src/deviceutils/device_api.c index 239d08ff..cc092a44 100644 --- a/src/deviceutils/device_api.c +++ b/src/deviceutils/device_api.c @@ -91,10 +91,10 @@ bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) SWLOG_ERROR("%s: getDevicePropertyData() for LABSIGNED_ENABLED failed\n", __FUNCTION__); } SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n", dbgServices ? "true" : "false", deviceType, labsigned); - if(isDebugServicesUnlocked){ - SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); - t2ValNotify("SYST_INFO_FW_DbgSrv", "true"); - } + } + if(isDebugServicesUnlocked){ + SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n"); + t2ValNotify("SYST_INFO_FW_DbgSrv", "true"); } return isDebugServicesUnlocked; }