From 86b503bd95304a559f94c605e0f098b8514546b0 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:15:06 +0530 Subject: [PATCH 1/9] Update rrdInterface.h --- src/rrdInterface.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/rrdInterface.h b/src/rrdInterface.h index 01624329..d1be78bb 100644 --- a/src/rrdInterface.h +++ b/src/rrdInterface.h @@ -29,6 +29,7 @@ extern "C" #include "rrdCommon.h" #if !defined(GTEST_ENABLE) #include "rbus.h" +#include #ifdef IARMBUS_SUPPORT #include "libIARM.h" #include "libIBus.h" @@ -45,6 +46,11 @@ extern "C" #define RRD_PROCESS_NAME "remotedebugger" #define RRD_RBUS_TIMEOUT 60 +// RDK Remote Debugger profile data parameter definitions +#define RRD_SET_PROFILE_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.setProfileData" +#define RRD_GET_PROFILE_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.getProfileData" +#define RRD_PROFILE_CATEGORY_FILE "/tmp/rrd_profile_category" + /*Enum for IARM Events*/ typedef enum _RemoteDebugger_EventId_t { IARM_BUS_RDK_REMOTE_DEBUGGER_ISSUETYPE = 0, @@ -57,6 +63,8 @@ typedef enum _RemoteDebugger_EventId_t { void _remoteDebuggerEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription); void _remoteDebuggerWebCfgDataEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription); void _rdmDownloadEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription); +rbusError_t rrd_SetHandler(rbusHandle_t handle, rbusProperty_t property, rbusSetHandlerOptions_t* opts); +rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHandlerOptions_t* opts); #endif #if defined(IARMBUS_SUPPORT) || defined(GTEST_ENABLE) int RRD_IARM_subscribe(void); From c9587f0c9cc2fd2c9a75db7d0156fd8e9bfc424e Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:15:38 +0530 Subject: [PATCH 2/9] Update rrdInterface.h --- src/rrdInterface.h | 688 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 632 insertions(+), 56 deletions(-) diff --git a/src/rrdInterface.h b/src/rrdInterface.h index d1be78bb..d0e9193e 100644 --- a/src/rrdInterface.h +++ b/src/rrdInterface.h @@ -1,5 +1,6 @@ /* - * If not stated otherwise in this file or this component's LICENSE file the + * + * If not stated otherwise in this file or this component's Licenses.txt file the * following copyright and licenses apply: * * Copyright 2018 RDK Management @@ -15,75 +16,650 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. -*/ + */ -#ifndef _RRDIARM_H_ -#define _RRDIARM_H_ +#include "rrdInterface.h" +#include "rrdRbus.h" +#include "rrdRunCmdThread.h" +#if !defined(GTEST_ENABLE) +#include "webconfig_framework.h" -#ifdef __cplusplus -extern "C" -{ +extern int msqid; +#else +int msqid = 0; +key_t key = 1234; #endif +#define RRD_TMP_DIR "/tmp/" +uint32_t gWebCfgBloBVersion = 0; +rbusHandle_t rrdRbusHandle; + +// Global storage for profile category +char RRDProfileCategory[256] = "all"; + +// Helper functions for profile category file-based storage +int load_profile_category(void) { + FILE *fp = fopen(RRD_PROFILE_CATEGORY_FILE, "r"); + if (fp) { + if (fgets(RRDProfileCategory, sizeof(RRDProfileCategory), fp)) { + // Remove trailing newline + char *newline = strchr(RRDProfileCategory, '\n'); + if (newline) *newline = '\0'; + fclose(fp); + return 0; + } + fclose(fp); + } + // Default to "all" if file doesn't exist or read fails + strncpy(RRDProfileCategory, "all", sizeof(RRDProfileCategory) - 1); + RRDProfileCategory[sizeof(RRDProfileCategory) - 1] = '\0'; + return -1; +} + +int save_profile_category(void) { + FILE *fp = fopen(RRD_PROFILE_CATEGORY_FILE, "w"); + if (fp) { + fprintf(fp, "%s\n", RRDProfileCategory); + fclose(fp); + return 0; + } + return -1; +} + +#define DATA_HANDLER_SET_MACRO \ + { \ + NULL, \ + rrd_SetHandler, \ + NULL, \ + NULL, \ + NULL, \ + NULL \ + } + +#define DATA_HANDLER_GET_MACRO \ + { \ + rrd_GetHandler, \ + NULL, \ + NULL, \ + NULL, \ + NULL, \ + NULL \ + } + +// Data elements for profile data RBUS provider +rbusDataElement_t profileDataElements[2] = { + { + RRD_SET_PROFILE_EVENT, + RBUS_ELEMENT_TYPE_PROPERTY, + DATA_HANDLER_SET_MACRO + }, + { + RRD_GET_PROFILE_EVENT, + RBUS_ELEMENT_TYPE_PROPERTY, + DATA_HANDLER_GET_MACRO + } +}; -#include -#include "rrdCommon.h" +/*Function: RRD_subscribe + *Details: This helps to perform Bus init/connect and event handler registration for receiving + *events from the TR181 parameter. + *Input: NULL + *Output: 0 for success and non 0 for failure + */ + +int RRD_subscribe() +{ + int ret = 0; + + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering... \n", __FUNCTION__, __LINE__); +#ifdef IARMBUS_SUPPORT + ret = RRD_IARM_subscribe(); + if (ret != 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: IARM Subscribe!!! \n ", __FUNCTION__, __LINE__); + return ret; + } +#endif + //RBUS Event Subscribe for RRD + ret = rbus_open(&rrdRbusHandle, REMOTE_DEBUGGER_RBUS_HANDLE_NAME); + if (ret != 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS Open Failed!!! \n ", __FUNCTION__, __LINE__); + return ret; + } + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS Open! \n", __FUNCTION__, __LINE__); #if !defined(GTEST_ENABLE) -#include "rbus.h" -#include + subscriptions[0].eventName = RRD_SET_ISSUE_EVENT; + subscriptions[0].filter = NULL; + subscriptions[0].duration = 0; + subscriptions[0].handler = _remoteDebuggerEventHandler; + subscriptions[0].userData = NULL; + + subscriptions[1].eventName = RRD_WEBCFG_ISSUE_EVENT; + subscriptions[1].filter = NULL; + subscriptions[1].duration = 0; + subscriptions[1].handler = _remoteDebuggerWebCfgDataEventHandler; + subscriptions[1].userData = NULL; + #ifdef IARMBUS_SUPPORT -#include "libIARM.h" -#include "libIBus.h" -#include "libIARMCore.h" +#ifdef USE_L2_SUPPORT + subscriptions[2].eventName = RDM_DOWNLOAD_EVENT; + subscriptions[2].filter = NULL; + subscriptions[2].duration = 0; + subscriptions[2].handler = _rdmDownloadEventHandler; + subscriptions[2].userData = NULL; + ret = rbusEvent_SubscribeEx(rrdRbusHandle, subscriptions, 3, 60); +#else + ret = rbusEvent_SubscribeEx(rrdRbusHandle, subscriptions, 2, 60); +#endif +#else + subscriptions[2].eventName = RDM_DOWNLOAD_EVENT; + subscriptions[2].filter = NULL; + subscriptions[2].duration = 0; + subscriptions[2].handler = _rdmDownloadEventHandler; + subscriptions[2].userData = NULL; + ret = rbusEvent_SubscribeEx(rrdRbusHandle, subscriptions, 3, 60); #endif #endif + if(ret != 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS Event Subscribe for RRD return value is : %s \n ", __FUNCTION__, __LINE__, rbusError_ToString((rbusError_t)ret)); + } + else + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS Event Subscribe for RRD done! \n", __FUNCTION__, __LINE__); + } + + // Load profile category from file + if (load_profile_category() == 0) { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Loaded profile category: %s\n", __FUNCTION__, __LINE__, RRDProfileCategory); + } else { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: No stored profile category, defaulting to 'all'\n", __FUNCTION__, __LINE__); + } + + // Register RBUS data elements for profile data provider + ret = rbus_regDataElements(rrdRbusHandle, 2, profileDataElements); + if (ret != RBUS_ERROR_SUCCESS) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS regDataElements failed with error: %d\n", __FUNCTION__, __LINE__, ret); + } else { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS profile data elements registered\n", __FUNCTION__, __LINE__); + } + + webconfigFrameworkInit(); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting.. \n", __FUNCTION__, __LINE__); + return ret; +} + +bool checkAppendRequest(char *issueRequest) +{ + size_t issuestr_len = strlen(issueRequest); + size_t suffixstr_len = strlen(APPEND_SUFFIX); + char *suffixptr = NULL; + + suffixptr = issueRequest + issuestr_len - suffixstr_len; + + if (issuestr_len >= suffixstr_len) + { + if (strcmp(suffixptr, APPEND_SUFFIX) == 0) + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]:Remove suffix from the issuetype to process the request \n", __FUNCTION__, __LINE__); + issueRequest[issuestr_len - suffixstr_len] = '\0'; + return true; + } + } + return false; +} + +void webconfigFrameworkInit() +{ + char *sub_doc = "remotedebugger"; + + blobRegInfo *blobData; + blobData = (blobRegInfo*) malloc( sizeof(blobRegInfo)); + memset(blobData, 0, sizeof(blobRegInfo)); + strncpy( blobData->subdoc_name, sub_doc, strlen(sub_doc) + 1); + + register_sub_docs(blobData, 1 /*SubDoc Count*/, NULL, NULL); +} + +uint32_t getBlobVersion(char* subdoc) +{ + return gWebCfgBloBVersion; +} + +/* API to update the subdoc version */ +int setBlobVersion(char* subdoc,uint32_t version) +{ + gWebCfgBloBVersion = version; + return 0; +} + +void RRDMsgDeliver(int msgqid, data_buf *sbuf) +{ + msgRRDHdr msgHdr; + size_t msgLen = -1; + msgHdr.type = RRD_EVENT_MSG_REQUEST; + msgHdr.mbody = (void *)sbuf; + msgLen = sizeof(msgHdr.mbody); + + if (msgsnd(msgqid, (void *)&msgHdr, msgLen, 0) < 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Message Sending failed with ID=%d MSG=%s Size=%d Type=%u MbufSize=%d !!! \n", __FUNCTION__, __LINE__, msgqid, sbuf->mdata, sizeof(sbuf->mdata), sbuf->mtype, msgLen); + exit(1); + } +} + +/*Function: RRD_data_buff_init + * *Details: Initialize the data buffer for MSG Queue + * *Input: Pointer to Data Buffer and Event Id + * *Output: NULL + * */ +void RRD_data_buff_init(data_buf *sbuf, message_type_et sndtype, deepsleep_event_et deepSleepEvent) +{ + sbuf->mtype = sndtype; + sbuf->mdata = NULL; + sbuf->jsonPath = NULL; + sbuf->inDynamic = false; + sbuf->appendMode = false; + sbuf->dsEvent = deepSleepEvent; +} + +/*Function: RRD_data_buff_deAlloc + * *Details: De Aollocate Data Buffer + * *Input: Pointer to Data Buffer + * *Output:void + * */ +void RRD_data_buff_deAlloc(data_buf *sbuf) +{ + if (sbuf) + { + if (sbuf->mdata) + { + free(sbuf->mdata); + } -#define RDK_REMOTE_DEBUGGER_NAME "REMOTE_DEBUGGER" -#define REMOTE_DEBUGGER_RBUS_HANDLE_NAME "rdkRrdRbus" -#define RRD_WEBCFG_FORCE_SYNC "Device.X_RDK_WebConfig.ForceSync" -#define RRD_SET_ISSUE_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.IssueType" -#define RRD_WEBCFG_ISSUE_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.WebCfgData" -#define RDM_DOWNLOAD_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RDKDownloadManager.DownloadStatus" -#define RRD_PROCESS_NAME "remotedebugger" -#define RRD_RBUS_TIMEOUT 60 - -// RDK Remote Debugger profile data parameter definitions -#define RRD_SET_PROFILE_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.setProfileData" -#define RRD_GET_PROFILE_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.getProfileData" -#define RRD_PROFILE_CATEGORY_FILE "/tmp/rrd_profile_category" - -/*Enum for IARM Events*/ -typedef enum _RemoteDebugger_EventId_t { - IARM_BUS_RDK_REMOTE_DEBUGGER_ISSUETYPE = 0, - IARM_BUS_RDK_REMOTE_DEBUGGER_WEBCFGDATA, - IARM_BUS_RDK_REMOTE_DEBUGGER_MAX_EVENT -} IARM_Bus_RemoteDebugger_EventId_t; - -/*Event Handler Function*/ + if (sbuf->jsonPath) + { + free(sbuf->jsonPath); + } + free(sbuf); + } +} + +/* + * @function _remoteDebuggerEventHandler + * @brief Receives the RBUS event and sends the value as a message in the message-queue to the thread function. + * @param rbusHandle_t handle - RBUS handle. + * @param rbusEvent_t const* event - RBUS event object. + * @param rbusEventSubscription_t* subscription - RBUS event subscription object. + * @return void + */ #if !defined(GTEST_ENABLE) -void _remoteDebuggerEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription); -void _remoteDebuggerWebCfgDataEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription); -void _rdmDownloadEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription); -rbusError_t rrd_SetHandler(rbusHandle_t handle, rbusProperty_t property, rbusSetHandlerOptions_t* opts); -rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHandlerOptions_t* opts); +void _rdmDownloadEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription) +{ + data_buf *sendbuf; + int recPkglen = 0, rrdjsonlen = 0, recPkgNamelen = 0; + cacheData *cache = NULL; + + rbusError_t retCode = RBUS_ERROR_BUS_ERROR; + rbusValue_t value = NULL; + rbusValue_Init(&value); + char const* issue = NULL; + retCode = rbus_get(rrdRbusHandle, RRD_SET_ISSUE_EVENT, &value); + if(retCode != RBUS_ERROR_SUCCESS || value == NULL) + { + RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: RBUS get failed for the event [%s]\n", __FUNCTION__, __LINE__, RRD_SET_ISSUE_EVENT); + return; + } + RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: issue type_value: = [%s]\n", __FUNCTION__, __LINE__, rbusValue_GetString(value, NULL)); + issue =rbusValue_GetString(value, NULL); + char *dot_position = strchr(issue, '.'); // Find the first occurrence of '.' + if (dot_position != NULL) + { + *dot_position = '\0'; // Replace '.' with null terminator + } + size_t len = strlen(RDM_PKG_PREFIX) + strlen(issue) + 1; + + char *pkg_name = (char *)malloc(len); + if(pkg_name == NULL) + { + return; + } + strncpy(pkg_name, RDM_PKG_PREFIX, strlen(RDM_PKG_PREFIX) + 1); + strncat(pkg_name, issue, len - strlen(RDM_PKG_PREFIX) - 1); + RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: pkg_name : [%s]\n", __FUNCTION__, __LINE__, pkg_name); + + char *pkg_inst_path = (char *)malloc(strlen(RRD_TMP_DIR) + strlen(pkg_name) + 1); + if( pkg_inst_path == NULL) + { + return; + } + snprintf(pkg_inst_path, strlen(RRD_TMP_DIR) + strlen(pkg_name) + 1, "%s%s", RRD_TMP_DIR, pkg_name); + RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: pkg_inst_path : [%s]\n", __FUNCTION__, __LINE__, pkg_inst_path); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering... \n", __FUNCTION__, __LINE__); + + (void)(handle); + (void)(subscription); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Received event for RDM_DOWNLOAD_EVENT %s \n", __FUNCTION__, __LINE__, RDM_DOWNLOAD_EVENT); + cache = findPresentInCache(pkg_name); + if (cache != NULL) + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Package found in Cache...%s \n", __FUNCTION__, __LINE__, cache->issueString); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Package Details jsonPath: %s \n", __FUNCTION__, __LINE__, pkg_inst_path); + rrdjsonlen = strlen(RRD_JSON_FILE); + recPkglen = strlen(pkg_inst_path) + 1; + recPkgNamelen = strlen(cache->issueString) + 1; + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]:recPkgNamelen=%d recPkglen=%d rrdjsonlen=%d \n", __FUNCTION__, __LINE__, recPkgNamelen, recPkglen, rrdjsonlen); + sendbuf = (data_buf *)malloc(sizeof(data_buf)); + RRD_data_buff_init(sendbuf, EVENT_MSG, RRD_DEEPSLEEP_RDM_PKG_INSTALL_COMPLETE); + sendbuf->mdata = (char *) calloc(recPkgNamelen, sizeof(char)); + if(!sendbuf->mdata) + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed for the rdm download event \n", __FUNCTION__, __LINE__); + RRD_data_buff_deAlloc(sendbuf); + return; + } + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]:JSON_PATH_LEN=%d \n", __FUNCTION__, __LINE__, recPkglen + rrdjsonlen); + sendbuf->jsonPath = (char *)calloc(recPkglen + rrdjsonlen, sizeof(char)); + if (!sendbuf->jsonPath) + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed for the rdm download event \n", __FUNCTION__, __LINE__); + RRD_data_buff_deAlloc(sendbuf); + return; + } + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Cache.issueString=%s Cache.issueString.Len=%d\n", __FUNCTION__, __LINE__, cache->issueString, strlen(cache->issueString)); + strncpy((char *)sendbuf->mdata, cache->issueString, recPkgNamelen); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: IssueType: %s...\n", __FUNCTION__, __LINE__, (char *)sendbuf->mdata); + snprintf(sendbuf->jsonPath, strlen(pkg_inst_path) + rrdjsonlen + 1, "%s%s", pkg_inst_path, RRD_JSON_FILE); + sendbuf->inDynamic = true; + if (checkAppendRequest(sendbuf->mdata)) + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]:Received command apppend request for the issue \n", __FUNCTION__, __LINE__); + sendbuf->inDynamic = false; + sendbuf->appendMode = true; + } + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: IssueType: %s... jsonPath: %s... \n", __FUNCTION__, __LINE__, (char *)sendbuf->mdata, sendbuf->jsonPath); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Copying Message Received to the queue.. \n", __FUNCTION__, __LINE__); + RRDMsgDeliver(msqid, sendbuf); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: SUCCESS: Message sending Done, ID=%d MSG=%s Size=%d Type=%u AppendMode=%d! \n", __FUNCTION__, __LINE__, msqid, sendbuf->mdata, strlen(sendbuf->mdata), sendbuf->mtype, sendbuf->appendMode); + /* coverity[leaked_storage] */ + remove_item(cache); + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Package not requested... %s \n", __FUNCTION__, __LINE__, pkg_name); + } + free(pkg_name); + free(pkg_inst_path); +} +void _remoteDebuggerEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription) +{ + char *dataMsg = NULL; + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering... \n", __FUNCTION__, __LINE__); + + (void)(handle); + (void)(subscription); + + rbusValue_t value = rbusObject_GetValue(event->data, "value"); + + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Received event for RRD_SET_ISSUE_EVENT %s \n", __FUNCTION__, __LINE__, RRD_SET_ISSUE_EVENT); + if(!value) + { + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: event->data value is NULL \n", __FUNCTION__, __LINE__); + return; + } + + int len = strlen(rbusValue_GetString(value, NULL))+1; + dataMsg = (char *) calloc(1, len); + if(!dataMsg) + { + RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: Memory Allocation Failed for %s \n", __FUNCTION__, __LINE__, rbusValue_ToString(value, NULL, 0)); + return; + } + strncpy(dataMsg, rbusValue_GetString(value, NULL), len-1); + dataMsg[len-1]='\0'; + if (dataMsg[0] == '\0' || len <= 0 ) + { + RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: Message Received is empty, Exit Processing!!! \n", __FUNCTION__, __LINE__); + free(dataMsg); + } + else + { + pushIssueTypesToMsgQueue(dataMsg, EVENT_MSG); + /* coverity[leaked_storage] */ + } + + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__); +} + +void _remoteDebuggerWebCfgDataEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription) +{ + char *inString = NULL; + + (void)(handle); + (void)(subscription); + + rbusValue_t value = rbusObject_GetValue(event->data, "value"); + + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering... \n", __FUNCTION__, __LINE__); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Received event for RRD_WEBCFG_ISSUE_EVENT %s \n", __FUNCTION__, __LINE__, RRD_WEBCFG_ISSUE_EVENT); + if (value) + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Data from TR69 Parameter for REMOTE_DEBUGGER_WEBCFGDATA %s \n", __FUNCTION__, __LINE__, + rbusValue_ToString(value, NULL, 0)); + int len = strlen(rbusValue_GetString(value, NULL)); + inString = (char *)calloc(1, len); + if(inString) + { + strncpy(inString, rbusValue_GetString(value, NULL), len); + pushIssueTypesToMsgQueue(inString, EVENT_WEBCFG_MSG); + } + } + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exit... \n", __FUNCTION__, __LINE__); +} #endif +void pushIssueTypesToMsgQueue(char *issueTypeList, message_type_et sndtype) +{ + data_buf *sbuf = NULL; + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Copying Message Received to the queue.. \n", __FUNCTION__, __LINE__); + sbuf = (data_buf *)malloc(sizeof(data_buf)); + if (!sbuf) + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed\n", __FUNCTION__, __LINE__); + } + else + { + RRD_data_buff_init(sbuf, sndtype, RRD_DEEPSLEEP_INVALID_DEFAULT); + sbuf->mdata = issueTypeList; + if (checkAppendRequest(sbuf->mdata)) + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]:Received command apppend request for the issue \n", __FUNCTION__, __LINE__); + sbuf->appendMode = true; + } + RRDMsgDeliver(msqid, sbuf); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: SUCCESS: Message sending Done, ID=%d MSG=%s Size=%d Type=%u AppendMode=%d! \n", __FUNCTION__, __LINE__, msqid, sbuf->mdata, strlen(sbuf->mdata), sbuf->mtype, sbuf->appendMode); + /* coverity[leaked_storage] */ + } +} + +/*Function: RRD_unsubscribe + *Details: This helps to perform Bus disconnect/terminate and unregister event handler. + *Input: NULL + *Output: 0 for success and non-zero for failure + */ + +int RRD_unsubscribe() +{ + int ret = 0; + + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering... \n", __FUNCTION__, __LINE__); #if defined(IARMBUS_SUPPORT) || defined(GTEST_ENABLE) -int RRD_IARM_subscribe(void); -int RRD_IARM_unsubscribe(void); -void _rdmManagerEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len); -#if defined(PWRMGR_PLUGIN) -void _pwrManagerEventHandler(const PowerController_PowerState_t currentState, - const PowerController_PowerState_t newState, void* userdata); -#else -void _pwrManagerEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len); + ret = RRD_IARM_unsubscribe(); + if (ret != 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: IARM Unsubscribe failed!!! \n ", __FUNCTION__, __LINE__); + return ret; + } + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: IARM_Bus Unsubscribe done!\n", __FUNCTION__, __LINE__); #endif +#if !defined(GTEST_ENABLE) + ret = rbusEvent_UnsubscribeEx(rrdRbusHandle, subscriptions, 3); + if (ret != 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS Unsubscribe EventHandler for RRD failed!!! \n", __FUNCTION__, __LINE__); + return ret; + } + + // Unregister RBUS data elements for profile data provider + ret = rbus_unregDataElements(rrdRbusHandle, 2, profileDataElements); + if (ret != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS unregDataElements failed with error: %d\n", __FUNCTION__, __LINE__, ret); + } else { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS profile data elements unregistered\n", __FUNCTION__, __LINE__); + } + + ret = rbus_close(rrdRbusHandle); + if (ret != 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS Termination failed!!! \n ", __FUNCTION__, __LINE__); + return ret; + } + else + { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS Termination done!\n", __FUNCTION__, __LINE__); + } + + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__); #endif -void RRD_data_buff_deAlloc(data_buf *sbuf); -void RRDMsgDeliver(int msgqid, data_buf *sbuf); -int RRD_subscribe(void); -int RRD_unsubscribe(void); + return ret; +} +/** + * @brief Set handler for RDK Remote Debugger profile category selection + */ +rbusError_t rrd_SetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusSetHandlerOptions_t* opts) +{ + (void)handle; + (void)opts; + + char const* propertyName = rbusProperty_GetName(prop); + rbusValue_t value = rbusProperty_GetValue(prop); + rbusValueType_t type = rbusValue_GetType(value); + + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Set handler called for [%s]\\n", __FUNCTION__, __LINE__, propertyName); + + if(strcmp(propertyName, RRD_SET_PROFILE_EVENT) == 0) { + if (type == RBUS_STRING) { + const char* str = rbusValue_GetString(value, NULL); + if(strlen(str) > 255) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: String too long for setProfileData\\n", __FUNCTION__, __LINE__); + return RBUS_ERROR_INVALID_INPUT; + } + + strncpy(RRDProfileCategory, str, sizeof(RRDProfileCategory)-1); + RRDProfileCategory[sizeof(RRDProfileCategory)-1] = '\\0'; + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: setProfileData value: %s\\n", __FUNCTION__, __LINE__, RRDProfileCategory); -#ifdef __cplusplus + // Store the category selection to file + if(save_profile_category() != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to store profile category\\n", __FUNCTION__, __LINE__); + return RBUS_ERROR_BUS_ERROR; + } + + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Successfully set profile category to: %s\\n", __FUNCTION__, __LINE__, RRDProfileCategory); + return RBUS_ERROR_SUCCESS; + } else { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Invalid type for setProfileData\\n", __FUNCTION__, __LINE__); + return RBUS_ERROR_INVALID_INPUT; + } + } + + return RBUS_ERROR_INVALID_INPUT; } -#endif -#endif +/** + * @brief Get handler for RDK Remote Debugger profile data retrieval + */ +rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHandlerOptions_t* opts) +{ + (void)handle; + (void)opts; + + char const* propertyName = rbusProperty_GetName(prop); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Get handler called for [%s]\\n", __FUNCTION__, __LINE__, propertyName); + + if(strcmp(propertyName, RRD_GET_PROFILE_EVENT) == 0) { + const char *filename = "/etc/rrd/remote_debugger.json"; + + FILE *fp = fopen(filename, "rb"); + if (fp) { + fseek(fp, 0L, SEEK_END); + long fileSz = ftell(fp); + rewind(fp); + + if (fileSz > 0 && fileSz < 32768) { + char *jsonBuffer = malloc(fileSz + 1); + if (jsonBuffer) { + size_t bytesRead = fread(jsonBuffer, 1U, (size_t)fileSz, fp); + jsonBuffer[bytesRead] = '\\0'; + + cJSON *json = cJSON_Parse(jsonBuffer); + if (json) { + char *result_str = NULL; + + if (strlen(RRDProfileCategory) == 0 || strcmp(RRDProfileCategory, "all") == 0) { + // Return category names as array + cJSON *categories = cJSON_CreateArray(); + cJSON *item = json->child; + while (item) { + cJSON_AddItemToArray(categories, cJSON_CreateString(item->string)); + item = item->next; + } + result_str = cJSON_Print(categories); + cJSON_Delete(categories); + } else { + // Return specific category issue types + cJSON *category = cJSON_GetObjectItem(json, RRDProfileCategory); + if (category) { + cJSON *issueTypes = cJSON_CreateArray(); + cJSON *issue = category->child; + while (issue) { + cJSON_AddItemToArray(issueTypes, cJSON_CreateString(issue->string)); + issue = issue->next; + } + cJSON *result = cJSON_CreateObject(); + cJSON_AddItemToObject(result, RRDProfileCategory, issueTypes); + result_str = cJSON_Print(result); + cJSON_Delete(result); + } else { + result_str = cJSON_Print(cJSON_CreateArray()); + } + } + + if (result_str) { + rbusValue_t rbusValue; + rbusValue_Init(&rbusValue); + rbusValue_SetString(rbusValue, result_str); + rbusProperty_SetValue(prop, rbusValue); + rbusValue_Release(rbusValue); + free(result_str); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Successfully returned profile data\\n", __FUNCTION__, __LINE__); + } + + cJSON_Delete(json); + } else { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to parse JSON from %s\\n", __FUNCTION__, __LINE__, filename); + } + + free(jsonBuffer); + } + } + fclose(fp); + } else { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Unable to read profile file from %s\\n", __FUNCTION__, __LINE__, filename); + return RBUS_ERROR_BUS_ERROR; + } + + return RBUS_ERROR_SUCCESS; + } + + return RBUS_ERROR_INVALID_INPUT; +} From 8b712e954e4ce3571f0a5301361d9af5dad6ee49 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:17:54 +0530 Subject: [PATCH 3/9] Update rrdInterface.c --- src/rrdInterface.c | 220 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) diff --git a/src/rrdInterface.c b/src/rrdInterface.c index eb25b91d..d0e9193e 100644 --- a/src/rrdInterface.c +++ b/src/rrdInterface.c @@ -33,6 +33,72 @@ key_t key = 1234; uint32_t gWebCfgBloBVersion = 0; rbusHandle_t rrdRbusHandle; +// Global storage for profile category +char RRDProfileCategory[256] = "all"; + +// Helper functions for profile category file-based storage +int load_profile_category(void) { + FILE *fp = fopen(RRD_PROFILE_CATEGORY_FILE, "r"); + if (fp) { + if (fgets(RRDProfileCategory, sizeof(RRDProfileCategory), fp)) { + // Remove trailing newline + char *newline = strchr(RRDProfileCategory, '\n'); + if (newline) *newline = '\0'; + fclose(fp); + return 0; + } + fclose(fp); + } + // Default to "all" if file doesn't exist or read fails + strncpy(RRDProfileCategory, "all", sizeof(RRDProfileCategory) - 1); + RRDProfileCategory[sizeof(RRDProfileCategory) - 1] = '\0'; + return -1; +} + +int save_profile_category(void) { + FILE *fp = fopen(RRD_PROFILE_CATEGORY_FILE, "w"); + if (fp) { + fprintf(fp, "%s\n", RRDProfileCategory); + fclose(fp); + return 0; + } + return -1; +} + +#define DATA_HANDLER_SET_MACRO \ + { \ + NULL, \ + rrd_SetHandler, \ + NULL, \ + NULL, \ + NULL, \ + NULL \ + } + +#define DATA_HANDLER_GET_MACRO \ + { \ + rrd_GetHandler, \ + NULL, \ + NULL, \ + NULL, \ + NULL, \ + NULL \ + } + +// Data elements for profile data RBUS provider +rbusDataElement_t profileDataElements[2] = { + { + RRD_SET_PROFILE_EVENT, + RBUS_ELEMENT_TYPE_PROPERTY, + DATA_HANDLER_SET_MACRO + }, + { + RRD_GET_PROFILE_EVENT, + RBUS_ELEMENT_TYPE_PROPERTY, + DATA_HANDLER_GET_MACRO + } +}; + /*Function: RRD_subscribe *Details: This helps to perform Bus init/connect and event handler registration for receiving *events from the TR181 parameter. @@ -103,6 +169,21 @@ int RRD_subscribe() RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS Event Subscribe for RRD done! \n", __FUNCTION__, __LINE__); } + // Load profile category from file + if (load_profile_category() == 0) { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Loaded profile category: %s\n", __FUNCTION__, __LINE__, RRDProfileCategory); + } else { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: No stored profile category, defaulting to 'all'\n", __FUNCTION__, __LINE__); + } + + // Register RBUS data elements for profile data provider + ret = rbus_regDataElements(rrdRbusHandle, 2, profileDataElements); + if (ret != RBUS_ERROR_SUCCESS) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS regDataElements failed with error: %d\n", __FUNCTION__, __LINE__, ret); + } else { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS profile data elements registered\n", __FUNCTION__, __LINE__); + } + webconfigFrameworkInit(); RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting.. \n", __FUNCTION__, __LINE__); return ret; @@ -428,6 +509,14 @@ int RRD_unsubscribe() return ret; } + // Unregister RBUS data elements for profile data provider + ret = rbus_unregDataElements(rrdRbusHandle, 2, profileDataElements); + if (ret != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS unregDataElements failed with error: %d\n", __FUNCTION__, __LINE__, ret); + } else { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS profile data elements unregistered\n", __FUNCTION__, __LINE__); + } + ret = rbus_close(rrdRbusHandle); if (ret != 0) { @@ -443,3 +532,134 @@ int RRD_unsubscribe() #endif return ret; } +/** + * @brief Set handler for RDK Remote Debugger profile category selection + */ +rbusError_t rrd_SetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusSetHandlerOptions_t* opts) +{ + (void)handle; + (void)opts; + + char const* propertyName = rbusProperty_GetName(prop); + rbusValue_t value = rbusProperty_GetValue(prop); + rbusValueType_t type = rbusValue_GetType(value); + + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Set handler called for [%s]\\n", __FUNCTION__, __LINE__, propertyName); + + if(strcmp(propertyName, RRD_SET_PROFILE_EVENT) == 0) { + if (type == RBUS_STRING) { + const char* str = rbusValue_GetString(value, NULL); + if(strlen(str) > 255) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: String too long for setProfileData\\n", __FUNCTION__, __LINE__); + return RBUS_ERROR_INVALID_INPUT; + } + + strncpy(RRDProfileCategory, str, sizeof(RRDProfileCategory)-1); + RRDProfileCategory[sizeof(RRDProfileCategory)-1] = '\\0'; + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: setProfileData value: %s\\n", __FUNCTION__, __LINE__, RRDProfileCategory); + + // Store the category selection to file + if(save_profile_category() != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to store profile category\\n", __FUNCTION__, __LINE__); + return RBUS_ERROR_BUS_ERROR; + } + + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Successfully set profile category to: %s\\n", __FUNCTION__, __LINE__, RRDProfileCategory); + return RBUS_ERROR_SUCCESS; + } else { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Invalid type for setProfileData\\n", __FUNCTION__, __LINE__); + return RBUS_ERROR_INVALID_INPUT; + } + } + + return RBUS_ERROR_INVALID_INPUT; +} + +/** + * @brief Get handler for RDK Remote Debugger profile data retrieval + */ +rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHandlerOptions_t* opts) +{ + (void)handle; + (void)opts; + + char const* propertyName = rbusProperty_GetName(prop); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Get handler called for [%s]\\n", __FUNCTION__, __LINE__, propertyName); + + if(strcmp(propertyName, RRD_GET_PROFILE_EVENT) == 0) { + const char *filename = "/etc/rrd/remote_debugger.json"; + + FILE *fp = fopen(filename, "rb"); + if (fp) { + fseek(fp, 0L, SEEK_END); + long fileSz = ftell(fp); + rewind(fp); + + if (fileSz > 0 && fileSz < 32768) { + char *jsonBuffer = malloc(fileSz + 1); + if (jsonBuffer) { + size_t bytesRead = fread(jsonBuffer, 1U, (size_t)fileSz, fp); + jsonBuffer[bytesRead] = '\\0'; + + cJSON *json = cJSON_Parse(jsonBuffer); + if (json) { + char *result_str = NULL; + + if (strlen(RRDProfileCategory) == 0 || strcmp(RRDProfileCategory, "all") == 0) { + // Return category names as array + cJSON *categories = cJSON_CreateArray(); + cJSON *item = json->child; + while (item) { + cJSON_AddItemToArray(categories, cJSON_CreateString(item->string)); + item = item->next; + } + result_str = cJSON_Print(categories); + cJSON_Delete(categories); + } else { + // Return specific category issue types + cJSON *category = cJSON_GetObjectItem(json, RRDProfileCategory); + if (category) { + cJSON *issueTypes = cJSON_CreateArray(); + cJSON *issue = category->child; + while (issue) { + cJSON_AddItemToArray(issueTypes, cJSON_CreateString(issue->string)); + issue = issue->next; + } + cJSON *result = cJSON_CreateObject(); + cJSON_AddItemToObject(result, RRDProfileCategory, issueTypes); + result_str = cJSON_Print(result); + cJSON_Delete(result); + } else { + result_str = cJSON_Print(cJSON_CreateArray()); + } + } + + if (result_str) { + rbusValue_t rbusValue; + rbusValue_Init(&rbusValue); + rbusValue_SetString(rbusValue, result_str); + rbusProperty_SetValue(prop, rbusValue); + rbusValue_Release(rbusValue); + free(result_str); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Successfully returned profile data\\n", __FUNCTION__, __LINE__); + } + + cJSON_Delete(json); + } else { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to parse JSON from %s\\n", __FUNCTION__, __LINE__, filename); + } + + free(jsonBuffer); + } + } + fclose(fp); + } else { + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Unable to read profile file from %s\\n", __FUNCTION__, __LINE__, filename); + return RBUS_ERROR_BUS_ERROR; + } + + return RBUS_ERROR_SUCCESS; + } + + return RBUS_ERROR_INVALID_INPUT; +} From 28ba654cc67a19a904a6e5e91a237834d39e4820 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:18:29 +0530 Subject: [PATCH 4/9] Update rrdInterface.h --- src/rrdInterface.h | 688 ++++----------------------------------------- 1 file changed, 56 insertions(+), 632 deletions(-) diff --git a/src/rrdInterface.h b/src/rrdInterface.h index d0e9193e..d1be78bb 100644 --- a/src/rrdInterface.h +++ b/src/rrdInterface.h @@ -1,6 +1,5 @@ /* - * - * If not stated otherwise in this file or this component's Licenses.txt file the + * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * * Copyright 2018 RDK Management @@ -16,650 +15,75 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#include "rrdInterface.h" -#include "rrdRbus.h" -#include "rrdRunCmdThread.h" -#if !defined(GTEST_ENABLE) -#include "webconfig_framework.h" - -extern int msqid; -#else -int msqid = 0; -key_t key = 1234; -#endif -#define RRD_TMP_DIR "/tmp/" -uint32_t gWebCfgBloBVersion = 0; -rbusHandle_t rrdRbusHandle; - -// Global storage for profile category -char RRDProfileCategory[256] = "all"; - -// Helper functions for profile category file-based storage -int load_profile_category(void) { - FILE *fp = fopen(RRD_PROFILE_CATEGORY_FILE, "r"); - if (fp) { - if (fgets(RRDProfileCategory, sizeof(RRDProfileCategory), fp)) { - // Remove trailing newline - char *newline = strchr(RRDProfileCategory, '\n'); - if (newline) *newline = '\0'; - fclose(fp); - return 0; - } - fclose(fp); - } - // Default to "all" if file doesn't exist or read fails - strncpy(RRDProfileCategory, "all", sizeof(RRDProfileCategory) - 1); - RRDProfileCategory[sizeof(RRDProfileCategory) - 1] = '\0'; - return -1; -} - -int save_profile_category(void) { - FILE *fp = fopen(RRD_PROFILE_CATEGORY_FILE, "w"); - if (fp) { - fprintf(fp, "%s\n", RRDProfileCategory); - fclose(fp); - return 0; - } - return -1; -} - -#define DATA_HANDLER_SET_MACRO \ - { \ - NULL, \ - rrd_SetHandler, \ - NULL, \ - NULL, \ - NULL, \ - NULL \ - } +*/ -#define DATA_HANDLER_GET_MACRO \ - { \ - rrd_GetHandler, \ - NULL, \ - NULL, \ - NULL, \ - NULL, \ - NULL \ - } +#ifndef _RRDIARM_H_ +#define _RRDIARM_H_ -// Data elements for profile data RBUS provider -rbusDataElement_t profileDataElements[2] = { - { - RRD_SET_PROFILE_EVENT, - RBUS_ELEMENT_TYPE_PROPERTY, - DATA_HANDLER_SET_MACRO - }, - { - RRD_GET_PROFILE_EVENT, - RBUS_ELEMENT_TYPE_PROPERTY, - DATA_HANDLER_GET_MACRO - } -}; - -/*Function: RRD_subscribe - *Details: This helps to perform Bus init/connect and event handler registration for receiving - *events from the TR181 parameter. - *Input: NULL - *Output: 0 for success and non 0 for failure - */ - -int RRD_subscribe() +#ifdef __cplusplus +extern "C" { - int ret = 0; - - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering... \n", __FUNCTION__, __LINE__); -#ifdef IARMBUS_SUPPORT - ret = RRD_IARM_subscribe(); - if (ret != 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: IARM Subscribe!!! \n ", __FUNCTION__, __LINE__); - return ret; - } #endif - //RBUS Event Subscribe for RRD - ret = rbus_open(&rrdRbusHandle, REMOTE_DEBUGGER_RBUS_HANDLE_NAME); - if (ret != 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS Open Failed!!! \n ", __FUNCTION__, __LINE__); - return ret; - } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS Open! \n", __FUNCTION__, __LINE__); -#if !defined(GTEST_ENABLE) - subscriptions[0].eventName = RRD_SET_ISSUE_EVENT; - subscriptions[0].filter = NULL; - subscriptions[0].duration = 0; - subscriptions[0].handler = _remoteDebuggerEventHandler; - subscriptions[0].userData = NULL; - - subscriptions[1].eventName = RRD_WEBCFG_ISSUE_EVENT; - subscriptions[1].filter = NULL; - subscriptions[1].duration = 0; - subscriptions[1].handler = _remoteDebuggerWebCfgDataEventHandler; - subscriptions[1].userData = NULL; +#include +#include "rrdCommon.h" +#if !defined(GTEST_ENABLE) +#include "rbus.h" +#include #ifdef IARMBUS_SUPPORT -#ifdef USE_L2_SUPPORT - subscriptions[2].eventName = RDM_DOWNLOAD_EVENT; - subscriptions[2].filter = NULL; - subscriptions[2].duration = 0; - subscriptions[2].handler = _rdmDownloadEventHandler; - subscriptions[2].userData = NULL; - ret = rbusEvent_SubscribeEx(rrdRbusHandle, subscriptions, 3, 60); -#else - ret = rbusEvent_SubscribeEx(rrdRbusHandle, subscriptions, 2, 60); -#endif -#else - subscriptions[2].eventName = RDM_DOWNLOAD_EVENT; - subscriptions[2].filter = NULL; - subscriptions[2].duration = 0; - subscriptions[2].handler = _rdmDownloadEventHandler; - subscriptions[2].userData = NULL; - ret = rbusEvent_SubscribeEx(rrdRbusHandle, subscriptions, 3, 60); +#include "libIARM.h" +#include "libIBus.h" +#include "libIARMCore.h" #endif #endif - if(ret != 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS Event Subscribe for RRD return value is : %s \n ", __FUNCTION__, __LINE__, rbusError_ToString((rbusError_t)ret)); - } - else - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS Event Subscribe for RRD done! \n", __FUNCTION__, __LINE__); - } - - // Load profile category from file - if (load_profile_category() == 0) { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Loaded profile category: %s\n", __FUNCTION__, __LINE__, RRDProfileCategory); - } else { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: No stored profile category, defaulting to 'all'\n", __FUNCTION__, __LINE__); - } - - // Register RBUS data elements for profile data provider - ret = rbus_regDataElements(rrdRbusHandle, 2, profileDataElements); - if (ret != RBUS_ERROR_SUCCESS) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS regDataElements failed with error: %d\n", __FUNCTION__, __LINE__, ret); - } else { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS profile data elements registered\n", __FUNCTION__, __LINE__); - } - - webconfigFrameworkInit(); - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting.. \n", __FUNCTION__, __LINE__); - return ret; -} - -bool checkAppendRequest(char *issueRequest) -{ - size_t issuestr_len = strlen(issueRequest); - size_t suffixstr_len = strlen(APPEND_SUFFIX); - char *suffixptr = NULL; - - suffixptr = issueRequest + issuestr_len - suffixstr_len; - - if (issuestr_len >= suffixstr_len) - { - if (strcmp(suffixptr, APPEND_SUFFIX) == 0) - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]:Remove suffix from the issuetype to process the request \n", __FUNCTION__, __LINE__); - issueRequest[issuestr_len - suffixstr_len] = '\0'; - return true; - } - } - return false; -} - -void webconfigFrameworkInit() -{ - char *sub_doc = "remotedebugger"; - - blobRegInfo *blobData; - blobData = (blobRegInfo*) malloc( sizeof(blobRegInfo)); - memset(blobData, 0, sizeof(blobRegInfo)); - strncpy( blobData->subdoc_name, sub_doc, strlen(sub_doc) + 1); - - register_sub_docs(blobData, 1 /*SubDoc Count*/, NULL, NULL); -} - -uint32_t getBlobVersion(char* subdoc) -{ - return gWebCfgBloBVersion; -} - -/* API to update the subdoc version */ -int setBlobVersion(char* subdoc,uint32_t version) -{ - gWebCfgBloBVersion = version; - return 0; -} - -void RRDMsgDeliver(int msgqid, data_buf *sbuf) -{ - msgRRDHdr msgHdr; - size_t msgLen = -1; - msgHdr.type = RRD_EVENT_MSG_REQUEST; - msgHdr.mbody = (void *)sbuf; - msgLen = sizeof(msgHdr.mbody); - - if (msgsnd(msgqid, (void *)&msgHdr, msgLen, 0) < 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Message Sending failed with ID=%d MSG=%s Size=%d Type=%u MbufSize=%d !!! \n", __FUNCTION__, __LINE__, msgqid, sbuf->mdata, sizeof(sbuf->mdata), sbuf->mtype, msgLen); - exit(1); - } -} - -/*Function: RRD_data_buff_init - * *Details: Initialize the data buffer for MSG Queue - * *Input: Pointer to Data Buffer and Event Id - * *Output: NULL - * */ -void RRD_data_buff_init(data_buf *sbuf, message_type_et sndtype, deepsleep_event_et deepSleepEvent) -{ - sbuf->mtype = sndtype; - sbuf->mdata = NULL; - sbuf->jsonPath = NULL; - sbuf->inDynamic = false; - sbuf->appendMode = false; - sbuf->dsEvent = deepSleepEvent; -} - -/*Function: RRD_data_buff_deAlloc - * *Details: De Aollocate Data Buffer - * *Input: Pointer to Data Buffer - * *Output:void - * */ -void RRD_data_buff_deAlloc(data_buf *sbuf) -{ - if (sbuf) - { - if (sbuf->mdata) - { - free(sbuf->mdata); - } - if (sbuf->jsonPath) - { - free(sbuf->jsonPath); - } - free(sbuf); - } -} - -/* - * @function _remoteDebuggerEventHandler - * @brief Receives the RBUS event and sends the value as a message in the message-queue to the thread function. - * @param rbusHandle_t handle - RBUS handle. - * @param rbusEvent_t const* event - RBUS event object. - * @param rbusEventSubscription_t* subscription - RBUS event subscription object. - * @return void - */ +#define RDK_REMOTE_DEBUGGER_NAME "REMOTE_DEBUGGER" +#define REMOTE_DEBUGGER_RBUS_HANDLE_NAME "rdkRrdRbus" +#define RRD_WEBCFG_FORCE_SYNC "Device.X_RDK_WebConfig.ForceSync" +#define RRD_SET_ISSUE_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.IssueType" +#define RRD_WEBCFG_ISSUE_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.WebCfgData" +#define RDM_DOWNLOAD_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RDKDownloadManager.DownloadStatus" +#define RRD_PROCESS_NAME "remotedebugger" +#define RRD_RBUS_TIMEOUT 60 + +// RDK Remote Debugger profile data parameter definitions +#define RRD_SET_PROFILE_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.setProfileData" +#define RRD_GET_PROFILE_EVENT "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.getProfileData" +#define RRD_PROFILE_CATEGORY_FILE "/tmp/rrd_profile_category" + +/*Enum for IARM Events*/ +typedef enum _RemoteDebugger_EventId_t { + IARM_BUS_RDK_REMOTE_DEBUGGER_ISSUETYPE = 0, + IARM_BUS_RDK_REMOTE_DEBUGGER_WEBCFGDATA, + IARM_BUS_RDK_REMOTE_DEBUGGER_MAX_EVENT +} IARM_Bus_RemoteDebugger_EventId_t; + +/*Event Handler Function*/ #if !defined(GTEST_ENABLE) -void _rdmDownloadEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription) -{ - data_buf *sendbuf; - int recPkglen = 0, rrdjsonlen = 0, recPkgNamelen = 0; - cacheData *cache = NULL; - - rbusError_t retCode = RBUS_ERROR_BUS_ERROR; - rbusValue_t value = NULL; - rbusValue_Init(&value); - char const* issue = NULL; - retCode = rbus_get(rrdRbusHandle, RRD_SET_ISSUE_EVENT, &value); - if(retCode != RBUS_ERROR_SUCCESS || value == NULL) - { - RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: RBUS get failed for the event [%s]\n", __FUNCTION__, __LINE__, RRD_SET_ISSUE_EVENT); - return; - } - RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: issue type_value: = [%s]\n", __FUNCTION__, __LINE__, rbusValue_GetString(value, NULL)); - issue =rbusValue_GetString(value, NULL); - char *dot_position = strchr(issue, '.'); // Find the first occurrence of '.' - if (dot_position != NULL) - { - *dot_position = '\0'; // Replace '.' with null terminator - } - size_t len = strlen(RDM_PKG_PREFIX) + strlen(issue) + 1; - - char *pkg_name = (char *)malloc(len); - if(pkg_name == NULL) - { - return; - } - strncpy(pkg_name, RDM_PKG_PREFIX, strlen(RDM_PKG_PREFIX) + 1); - strncat(pkg_name, issue, len - strlen(RDM_PKG_PREFIX) - 1); - RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: pkg_name : [%s]\n", __FUNCTION__, __LINE__, pkg_name); - - char *pkg_inst_path = (char *)malloc(strlen(RRD_TMP_DIR) + strlen(pkg_name) + 1); - if( pkg_inst_path == NULL) - { - return; - } - snprintf(pkg_inst_path, strlen(RRD_TMP_DIR) + strlen(pkg_name) + 1, "%s%s", RRD_TMP_DIR, pkg_name); - RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: pkg_inst_path : [%s]\n", __FUNCTION__, __LINE__, pkg_inst_path); - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering... \n", __FUNCTION__, __LINE__); - - (void)(handle); - (void)(subscription); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Received event for RDM_DOWNLOAD_EVENT %s \n", __FUNCTION__, __LINE__, RDM_DOWNLOAD_EVENT); - cache = findPresentInCache(pkg_name); - if (cache != NULL) - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Package found in Cache...%s \n", __FUNCTION__, __LINE__, cache->issueString); - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Package Details jsonPath: %s \n", __FUNCTION__, __LINE__, pkg_inst_path); - rrdjsonlen = strlen(RRD_JSON_FILE); - recPkglen = strlen(pkg_inst_path) + 1; - recPkgNamelen = strlen(cache->issueString) + 1; - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]:recPkgNamelen=%d recPkglen=%d rrdjsonlen=%d \n", __FUNCTION__, __LINE__, recPkgNamelen, recPkglen, rrdjsonlen); - sendbuf = (data_buf *)malloc(sizeof(data_buf)); - RRD_data_buff_init(sendbuf, EVENT_MSG, RRD_DEEPSLEEP_RDM_PKG_INSTALL_COMPLETE); - sendbuf->mdata = (char *) calloc(recPkgNamelen, sizeof(char)); - if(!sendbuf->mdata) - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed for the rdm download event \n", __FUNCTION__, __LINE__); - RRD_data_buff_deAlloc(sendbuf); - return; - } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]:JSON_PATH_LEN=%d \n", __FUNCTION__, __LINE__, recPkglen + rrdjsonlen); - sendbuf->jsonPath = (char *)calloc(recPkglen + rrdjsonlen, sizeof(char)); - if (!sendbuf->jsonPath) - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed for the rdm download event \n", __FUNCTION__, __LINE__); - RRD_data_buff_deAlloc(sendbuf); - return; - } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Cache.issueString=%s Cache.issueString.Len=%d\n", __FUNCTION__, __LINE__, cache->issueString, strlen(cache->issueString)); - strncpy((char *)sendbuf->mdata, cache->issueString, recPkgNamelen); - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: IssueType: %s...\n", __FUNCTION__, __LINE__, (char *)sendbuf->mdata); - snprintf(sendbuf->jsonPath, strlen(pkg_inst_path) + rrdjsonlen + 1, "%s%s", pkg_inst_path, RRD_JSON_FILE); - sendbuf->inDynamic = true; - if (checkAppendRequest(sendbuf->mdata)) - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]:Received command apppend request for the issue \n", __FUNCTION__, __LINE__); - sendbuf->inDynamic = false; - sendbuf->appendMode = true; - } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: IssueType: %s... jsonPath: %s... \n", __FUNCTION__, __LINE__, (char *)sendbuf->mdata, sendbuf->jsonPath); - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Copying Message Received to the queue.. \n", __FUNCTION__, __LINE__); - RRDMsgDeliver(msqid, sendbuf); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: SUCCESS: Message sending Done, ID=%d MSG=%s Size=%d Type=%u AppendMode=%d! \n", __FUNCTION__, __LINE__, msqid, sendbuf->mdata, strlen(sendbuf->mdata), sendbuf->mtype, sendbuf->appendMode); - /* coverity[leaked_storage] */ - remove_item(cache); - } - else - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Package not requested... %s \n", __FUNCTION__, __LINE__, pkg_name); - } - free(pkg_name); - free(pkg_inst_path); -} -void _remoteDebuggerEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription) -{ - char *dataMsg = NULL; - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering... \n", __FUNCTION__, __LINE__); - - (void)(handle); - (void)(subscription); - - rbusValue_t value = rbusObject_GetValue(event->data, "value"); - - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Received event for RRD_SET_ISSUE_EVENT %s \n", __FUNCTION__, __LINE__, RRD_SET_ISSUE_EVENT); - if(!value) - { - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: event->data value is NULL \n", __FUNCTION__, __LINE__); - return; - } - - int len = strlen(rbusValue_GetString(value, NULL))+1; - dataMsg = (char *) calloc(1, len); - if(!dataMsg) - { - RDK_LOG(RDK_LOG_ERROR,LOG_REMDEBUG,"[%s:%d]: Memory Allocation Failed for %s \n", __FUNCTION__, __LINE__, rbusValue_ToString(value, NULL, 0)); - return; - } - strncpy(dataMsg, rbusValue_GetString(value, NULL), len-1); - dataMsg[len-1]='\0'; - if (dataMsg[0] == '\0' || len <= 0 ) - { - RDK_LOG(RDK_LOG_DEBUG,LOG_REMDEBUG,"[%s:%d]: Message Received is empty, Exit Processing!!! \n", __FUNCTION__, __LINE__); - free(dataMsg); - } - else - { - pushIssueTypesToMsgQueue(dataMsg, EVENT_MSG); - /* coverity[leaked_storage] */ - } - - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__); -} - -void _remoteDebuggerWebCfgDataEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription) -{ - char *inString = NULL; - - (void)(handle); - (void)(subscription); - - rbusValue_t value = rbusObject_GetValue(event->data, "value"); - - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering... \n", __FUNCTION__, __LINE__); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Received event for RRD_WEBCFG_ISSUE_EVENT %s \n", __FUNCTION__, __LINE__, RRD_WEBCFG_ISSUE_EVENT); - if (value) - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Data from TR69 Parameter for REMOTE_DEBUGGER_WEBCFGDATA %s \n", __FUNCTION__, __LINE__, - rbusValue_ToString(value, NULL, 0)); - int len = strlen(rbusValue_GetString(value, NULL)); - inString = (char *)calloc(1, len); - if(inString) - { - strncpy(inString, rbusValue_GetString(value, NULL), len); - pushIssueTypesToMsgQueue(inString, EVENT_WEBCFG_MSG); - } - } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exit... \n", __FUNCTION__, __LINE__); -} +void _remoteDebuggerEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription); +void _remoteDebuggerWebCfgDataEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription); +void _rdmDownloadEventHandler(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription); +rbusError_t rrd_SetHandler(rbusHandle_t handle, rbusProperty_t property, rbusSetHandlerOptions_t* opts); +rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHandlerOptions_t* opts); #endif -void pushIssueTypesToMsgQueue(char *issueTypeList, message_type_et sndtype) -{ - data_buf *sbuf = NULL; - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Copying Message Received to the queue.. \n", __FUNCTION__, __LINE__); - sbuf = (data_buf *)malloc(sizeof(data_buf)); - if (!sbuf) - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Memory Allocation Failed\n", __FUNCTION__, __LINE__); - } - else - { - RRD_data_buff_init(sbuf, sndtype, RRD_DEEPSLEEP_INVALID_DEFAULT); - sbuf->mdata = issueTypeList; - if (checkAppendRequest(sbuf->mdata)) - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]:Received command apppend request for the issue \n", __FUNCTION__, __LINE__); - sbuf->appendMode = true; - } - RRDMsgDeliver(msqid, sbuf); - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: SUCCESS: Message sending Done, ID=%d MSG=%s Size=%d Type=%u AppendMode=%d! \n", __FUNCTION__, __LINE__, msqid, sbuf->mdata, strlen(sbuf->mdata), sbuf->mtype, sbuf->appendMode); - /* coverity[leaked_storage] */ - } -} - -/*Function: RRD_unsubscribe - *Details: This helps to perform Bus disconnect/terminate and unregister event handler. - *Input: NULL - *Output: 0 for success and non-zero for failure - */ - -int RRD_unsubscribe() -{ - int ret = 0; - - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Entering... \n", __FUNCTION__, __LINE__); #if defined(IARMBUS_SUPPORT) || defined(GTEST_ENABLE) - ret = RRD_IARM_unsubscribe(); - if (ret != 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: IARM Unsubscribe failed!!! \n ", __FUNCTION__, __LINE__); - return ret; - } - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: IARM_Bus Unsubscribe done!\n", __FUNCTION__, __LINE__); +int RRD_IARM_subscribe(void); +int RRD_IARM_unsubscribe(void); +void _rdmManagerEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len); +#if defined(PWRMGR_PLUGIN) +void _pwrManagerEventHandler(const PowerController_PowerState_t currentState, + const PowerController_PowerState_t newState, void* userdata); +#else +void _pwrManagerEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len); #endif -#if !defined(GTEST_ENABLE) - ret = rbusEvent_UnsubscribeEx(rrdRbusHandle, subscriptions, 3); - if (ret != 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS Unsubscribe EventHandler for RRD failed!!! \n", __FUNCTION__, __LINE__); - return ret; - } - - // Unregister RBUS data elements for profile data provider - ret = rbus_unregDataElements(rrdRbusHandle, 2, profileDataElements); - if (ret != 0) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS unregDataElements failed with error: %d\n", __FUNCTION__, __LINE__, ret); - } else { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS profile data elements unregistered\n", __FUNCTION__, __LINE__); - } - - ret = rbus_close(rrdRbusHandle); - if (ret != 0) - { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS Termination failed!!! \n ", __FUNCTION__, __LINE__); - return ret; - } - else - { - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS Termination done!\n", __FUNCTION__, __LINE__); - } - - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: ...Exiting...\n", __FUNCTION__, __LINE__); #endif - return ret; -} -/** - * @brief Set handler for RDK Remote Debugger profile category selection - */ -rbusError_t rrd_SetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusSetHandlerOptions_t* opts) -{ - (void)handle; - (void)opts; - - char const* propertyName = rbusProperty_GetName(prop); - rbusValue_t value = rbusProperty_GetValue(prop); - rbusValueType_t type = rbusValue_GetType(value); - - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Set handler called for [%s]\\n", __FUNCTION__, __LINE__, propertyName); - - if(strcmp(propertyName, RRD_SET_PROFILE_EVENT) == 0) { - if (type == RBUS_STRING) { - const char* str = rbusValue_GetString(value, NULL); - if(strlen(str) > 255) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: String too long for setProfileData\\n", __FUNCTION__, __LINE__); - return RBUS_ERROR_INVALID_INPUT; - } - - strncpy(RRDProfileCategory, str, sizeof(RRDProfileCategory)-1); - RRDProfileCategory[sizeof(RRDProfileCategory)-1] = '\\0'; - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: setProfileData value: %s\\n", __FUNCTION__, __LINE__, RRDProfileCategory); +void RRD_data_buff_deAlloc(data_buf *sbuf); +void RRDMsgDeliver(int msgqid, data_buf *sbuf); +int RRD_subscribe(void); +int RRD_unsubscribe(void); - // Store the category selection to file - if(save_profile_category() != 0) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to store profile category\\n", __FUNCTION__, __LINE__); - return RBUS_ERROR_BUS_ERROR; - } - - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Successfully set profile category to: %s\\n", __FUNCTION__, __LINE__, RRDProfileCategory); - return RBUS_ERROR_SUCCESS; - } else { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Invalid type for setProfileData\\n", __FUNCTION__, __LINE__); - return RBUS_ERROR_INVALID_INPUT; - } - } - - return RBUS_ERROR_INVALID_INPUT; +#ifdef __cplusplus } +#endif -/** - * @brief Get handler for RDK Remote Debugger profile data retrieval - */ -rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHandlerOptions_t* opts) -{ - (void)handle; - (void)opts; - - char const* propertyName = rbusProperty_GetName(prop); - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Get handler called for [%s]\\n", __FUNCTION__, __LINE__, propertyName); - - if(strcmp(propertyName, RRD_GET_PROFILE_EVENT) == 0) { - const char *filename = "/etc/rrd/remote_debugger.json"; - - FILE *fp = fopen(filename, "rb"); - if (fp) { - fseek(fp, 0L, SEEK_END); - long fileSz = ftell(fp); - rewind(fp); - - if (fileSz > 0 && fileSz < 32768) { - char *jsonBuffer = malloc(fileSz + 1); - if (jsonBuffer) { - size_t bytesRead = fread(jsonBuffer, 1U, (size_t)fileSz, fp); - jsonBuffer[bytesRead] = '\\0'; - - cJSON *json = cJSON_Parse(jsonBuffer); - if (json) { - char *result_str = NULL; - - if (strlen(RRDProfileCategory) == 0 || strcmp(RRDProfileCategory, "all") == 0) { - // Return category names as array - cJSON *categories = cJSON_CreateArray(); - cJSON *item = json->child; - while (item) { - cJSON_AddItemToArray(categories, cJSON_CreateString(item->string)); - item = item->next; - } - result_str = cJSON_Print(categories); - cJSON_Delete(categories); - } else { - // Return specific category issue types - cJSON *category = cJSON_GetObjectItem(json, RRDProfileCategory); - if (category) { - cJSON *issueTypes = cJSON_CreateArray(); - cJSON *issue = category->child; - while (issue) { - cJSON_AddItemToArray(issueTypes, cJSON_CreateString(issue->string)); - issue = issue->next; - } - cJSON *result = cJSON_CreateObject(); - cJSON_AddItemToObject(result, RRDProfileCategory, issueTypes); - result_str = cJSON_Print(result); - cJSON_Delete(result); - } else { - result_str = cJSON_Print(cJSON_CreateArray()); - } - } - - if (result_str) { - rbusValue_t rbusValue; - rbusValue_Init(&rbusValue); - rbusValue_SetString(rbusValue, result_str); - rbusProperty_SetValue(prop, rbusValue); - rbusValue_Release(rbusValue); - free(result_str); - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Successfully returned profile data\\n", __FUNCTION__, __LINE__); - } - - cJSON_Delete(json); - } else { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to parse JSON from %s\\n", __FUNCTION__, __LINE__, filename); - } - - free(jsonBuffer); - } - } - fclose(fp); - } else { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Unable to read profile file from %s\\n", __FUNCTION__, __LINE__, filename); - return RBUS_ERROR_BUS_ERROR; - } - - return RBUS_ERROR_SUCCESS; - } - - return RBUS_ERROR_INVALID_INPUT; -} +#endif From 2a7dcba99dba50cc4f2f59067f834b8fe3f7cacc Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:35:11 +0530 Subject: [PATCH 5/9] Update rrdInterface.c --- src/rrdInterface.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rrdInterface.c b/src/rrdInterface.c index d0e9193e..e6d5a543 100644 --- a/src/rrdInterface.c +++ b/src/rrdInterface.c @@ -555,7 +555,7 @@ rbusError_t rrd_SetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusSetHand } strncpy(RRDProfileCategory, str, sizeof(RRDProfileCategory)-1); - RRDProfileCategory[sizeof(RRDProfileCategory)-1] = '\\0'; + RRDProfileCategory[sizeof(RRDProfileCategory)-1] = '\0'; RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: setProfileData value: %s\\n", __FUNCTION__, __LINE__, RRDProfileCategory); // Store the category selection to file @@ -599,7 +599,7 @@ rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHand char *jsonBuffer = malloc(fileSz + 1); if (jsonBuffer) { size_t bytesRead = fread(jsonBuffer, 1U, (size_t)fileSz, fp); - jsonBuffer[bytesRead] = '\\0'; + jsonBuffer[bytesRead] = '\0'; cJSON *json = cJSON_Parse(jsonBuffer); if (json) { From 81cc5018e5575ad4072c089f304199308263d5c1 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:39:25 +0530 Subject: [PATCH 6/9] Update rrdInterface.c --- src/rrdInterface.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/rrdInterface.c b/src/rrdInterface.c index e6d5a543..06e7f6f3 100644 --- a/src/rrdInterface.c +++ b/src/rrdInterface.c @@ -544,30 +544,30 @@ rbusError_t rrd_SetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusSetHand rbusValue_t value = rbusProperty_GetValue(prop); rbusValueType_t type = rbusValue_GetType(value); - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Set handler called for [%s]\\n", __FUNCTION__, __LINE__, propertyName); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Set handler called for [%s]\n", __FUNCTION__, __LINE__, propertyName); if(strcmp(propertyName, RRD_SET_PROFILE_EVENT) == 0) { if (type == RBUS_STRING) { const char* str = rbusValue_GetString(value, NULL); if(strlen(str) > 255) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: String too long for setProfileData\\n", __FUNCTION__, __LINE__); + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: String too long for setProfileData\n", __FUNCTION__, __LINE__); return RBUS_ERROR_INVALID_INPUT; } strncpy(RRDProfileCategory, str, sizeof(RRDProfileCategory)-1); RRDProfileCategory[sizeof(RRDProfileCategory)-1] = '\0'; - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: setProfileData value: %s\\n", __FUNCTION__, __LINE__, RRDProfileCategory); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: setProfileData value: %s\n", __FUNCTION__, __LINE__, RRDProfileCategory); // Store the category selection to file if(save_profile_category() != 0) { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to store profile category\\n", __FUNCTION__, __LINE__); + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to store profile category\n", __FUNCTION__, __LINE__); return RBUS_ERROR_BUS_ERROR; } - RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Successfully set profile category to: %s\\n", __FUNCTION__, __LINE__, RRDProfileCategory); + RDK_LOG(RDK_LOG_INFO, LOG_REMDEBUG, "[%s:%d]: Successfully set profile category to: %s\n", __FUNCTION__, __LINE__, RRDProfileCategory); return RBUS_ERROR_SUCCESS; } else { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Invalid type for setProfileData\\n", __FUNCTION__, __LINE__); + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Invalid type for setProfileData\n", __FUNCTION__, __LINE__); return RBUS_ERROR_INVALID_INPUT; } } @@ -584,7 +584,7 @@ rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHand (void)opts; char const* propertyName = rbusProperty_GetName(prop); - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Get handler called for [%s]\\n", __FUNCTION__, __LINE__, propertyName); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Get handler called for [%s]\n", __FUNCTION__, __LINE__, propertyName); if(strcmp(propertyName, RRD_GET_PROFILE_EVENT) == 0) { const char *filename = "/etc/rrd/remote_debugger.json"; @@ -641,12 +641,12 @@ rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHand rbusProperty_SetValue(prop, rbusValue); rbusValue_Release(rbusValue); free(result_str); - RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Successfully returned profile data\\n", __FUNCTION__, __LINE__); + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Successfully returned profile data\n", __FUNCTION__, __LINE__); } cJSON_Delete(json); } else { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to parse JSON from %s\\n", __FUNCTION__, __LINE__, filename); + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Failed to parse JSON from %s\n", __FUNCTION__, __LINE__, filename); } free(jsonBuffer); @@ -654,7 +654,7 @@ rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHand } fclose(fp); } else { - RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Unable to read profile file from %s\\n", __FUNCTION__, __LINE__, filename); + RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: Unable to read profile file from %s\n", __FUNCTION__, __LINE__, filename); return RBUS_ERROR_BUS_ERROR; } From bb266ac0278a7af30a5f75c8d4fc85db9b74a9f8 Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 8 Apr 2026 14:20:40 +0530 Subject: [PATCH 7/9] Update rrdInterface.c --- src/rrdInterface.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/rrdInterface.c b/src/rrdInterface.c index 06e7f6f3..e2f26b74 100644 --- a/src/rrdInterface.c +++ b/src/rrdInterface.c @@ -606,29 +606,37 @@ rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHand char *result_str = NULL; if (strlen(RRDProfileCategory) == 0 || strcmp(RRDProfileCategory, "all") == 0) { - // Return category names as array - cJSON *categories = cJSON_CreateArray(); - cJSON *item = json->child; - while (item) { - cJSON_AddItemToArray(categories, cJSON_CreateString(item->string)); - item = item->next; + // Return all issue types from all categories (only arrays, not nested objects) + cJSON *allIssueTypes = cJSON_CreateArray(); + cJSON *category = json->child; + while (category) { + if (cJSON_IsArray(category)) { + int arraySize = cJSON_GetArraySize(category); + for (int i = 0; i < arraySize; i++) { + cJSON *issueType = cJSON_GetArrayItem(category, i); + if (cJSON_IsString(issueType)) { + cJSON_AddItemToArray(allIssueTypes, cJSON_CreateString(cJSON_GetStringValue(issueType))); + } + } + } + category = category->next; } - result_str = cJSON_Print(categories); - cJSON_Delete(categories); + result_str = cJSON_Print(allIssueTypes); + cJSON_Delete(allIssueTypes); } else { - // Return specific category issue types + // Return specific category issue types (only if it's an array structure) cJSON *category = cJSON_GetObjectItem(json, RRDProfileCategory); - if (category) { + if (category && cJSON_IsArray(category)) { cJSON *issueTypes = cJSON_CreateArray(); - cJSON *issue = category->child; - while (issue) { - cJSON_AddItemToArray(issueTypes, cJSON_CreateString(issue->string)); - issue = issue->next; + int arraySize = cJSON_GetArraySize(category); + for (int i = 0; i < arraySize; i++) { + cJSON *issueType = cJSON_GetArrayItem(category, i); + if (cJSON_IsString(issueType)) { + cJSON_AddItemToArray(issueTypes, cJSON_CreateString(cJSON_GetStringValue(issueType))); + } } - cJSON *result = cJSON_CreateObject(); - cJSON_AddItemToObject(result, RRDProfileCategory, issueTypes); - result_str = cJSON_Print(result); - cJSON_Delete(result); + result_str = cJSON_Print(issueTypes); + cJSON_Delete(issueTypes); } else { result_str = cJSON_Print(cJSON_CreateArray()); } From 48f1a709fad4b471af6e9ec2241d609781c1ceff Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:05:09 +0530 Subject: [PATCH 8/9] Update rrdInterface.c --- src/rrdInterface.c | 77 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 20 deletions(-) diff --git a/src/rrdInterface.c b/src/rrdInterface.c index e2f26b74..062bad4d 100644 --- a/src/rrdInterface.c +++ b/src/rrdInterface.c @@ -604,40 +604,77 @@ rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHand cJSON *json = cJSON_Parse(jsonBuffer); if (json) { char *result_str = NULL; + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: JSON parsed successfully, processing categories\n", __FUNCTION__, __LINE__); if (strlen(RRDProfileCategory) == 0 || strcmp(RRDProfileCategory, "all") == 0) { - // Return all issue types from all categories (only arrays, not nested objects) + // Return all issue types from all categories (exclude nested structures like DeepSleep) cJSON *allIssueTypes = cJSON_CreateArray(); - cJSON *category = json->child; - while (category) { - if (cJSON_IsArray(category)) { - int arraySize = cJSON_GetArraySize(category); - for (int i = 0; i < arraySize; i++) { - cJSON *issueType = cJSON_GetArrayItem(category, i); - if (cJSON_IsString(issueType)) { - cJSON_AddItemToArray(allIssueTypes, cJSON_CreateString(cJSON_GetStringValue(issueType))); + + cJSON *category = NULL; + cJSON_ArrayForEach(category, json) { + if (cJSON_IsObject(category) && category->string) { + // Skip categories with nested subcategories (no direct Commands/Timeout) + bool hasDirectCommands = false; + cJSON *item = NULL; + cJSON_ArrayForEach(item, category) { + if (cJSON_IsObject(item)) { + cJSON *commands = cJSON_GetObjectItem(item, "Commands"); + if (commands && cJSON_IsString(commands)) { + hasDirectCommands = true; + break; + } + } + } + + if (hasDirectCommands) { + // Extract issue type names (object keys) + cJSON *issueType = NULL; + cJSON_ArrayForEach(issueType, category) { + if (cJSON_IsObject(issueType) && issueType->string) { + cJSON_AddItemToArray(allIssueTypes, cJSON_CreateString(issueType->string)); + } } } } - category = category->next; } + result_str = cJSON_Print(allIssueTypes); cJSON_Delete(allIssueTypes); } else { - // Return specific category issue types (only if it's an array structure) + // Return specific category issue types cJSON *category = cJSON_GetObjectItem(json, RRDProfileCategory); - if (category && cJSON_IsArray(category)) { - cJSON *issueTypes = cJSON_CreateArray(); - int arraySize = cJSON_GetArraySize(category); - for (int i = 0; i < arraySize; i++) { - cJSON *issueType = cJSON_GetArrayItem(category, i); - if (cJSON_IsString(issueType)) { - cJSON_AddItemToArray(issueTypes, cJSON_CreateString(cJSON_GetStringValue(issueType))); + if (category && cJSON_IsObject(category)) { + // Check if this category has direct commands (not nested like DeepSleep) + bool hasDirectCommands = false; + cJSON *item = NULL; + cJSON_ArrayForEach(item, category) { + if (cJSON_IsObject(item)) { + cJSON *commands = cJSON_GetObjectItem(item, "Commands"); + if (commands && cJSON_IsString(commands)) { + hasDirectCommands = true; + break; + } + } + } + + if (hasDirectCommands) { + cJSON *issueTypes = cJSON_CreateArray(); + cJSON *issueType = NULL; + cJSON_ArrayForEach(issueType, category) { + if (cJSON_IsObject(issueType) && issueType->string) { + cJSON_AddItemToArray(issueTypes, cJSON_CreateString(issueType->string)); + } } + result_str = cJSON_Print(issueTypes); + cJSON_Delete(issueTypes); + } else { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Category %s has nested structure, returning empty\n", + __FUNCTION__, __LINE__, RRDProfileCategory); + result_str = cJSON_Print(cJSON_CreateArray()); } - result_str = cJSON_Print(issueTypes); - cJSON_Delete(issueTypes); } else { + RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Category %s not found\n", + __FUNCTION__, __LINE__, RRDProfileCategory); result_str = cJSON_Print(cJSON_CreateArray()); } } From 588db7a7574960fea09eb3792ababb8fe6ceab4c Mon Sep 17 00:00:00 2001 From: Abhinavpv28 <162570454+Abhinavpv28@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:35:36 +0530 Subject: [PATCH 9/9] Update rrdInterface.c --- src/rrdInterface.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/rrdInterface.c b/src/rrdInterface.c index 062bad4d..7ebb96d6 100644 --- a/src/rrdInterface.c +++ b/src/rrdInterface.c @@ -607,8 +607,8 @@ rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHand RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: JSON parsed successfully, processing categories\n", __FUNCTION__, __LINE__); if (strlen(RRDProfileCategory) == 0 || strcmp(RRDProfileCategory, "all") == 0) { - // Return all issue types from all categories (exclude nested structures like DeepSleep) - cJSON *allIssueTypes = cJSON_CreateArray(); + // Return all issue types grouped by categories (exclude nested structures like DeepSleep) + cJSON *response = cJSON_CreateObject(); cJSON *category = NULL; cJSON_ArrayForEach(category, json) { @@ -627,19 +627,27 @@ rbusError_t rrd_GetHandler(rbusHandle_t handle, rbusProperty_t prop, rbusGetHand } if (hasDirectCommands) { - // Extract issue type names (object keys) + // Create array for this category's issue types + cJSON *issueTypesArray = cJSON_CreateArray(); cJSON *issueType = NULL; cJSON_ArrayForEach(issueType, category) { if (cJSON_IsObject(issueType) && issueType->string) { - cJSON_AddItemToArray(allIssueTypes, cJSON_CreateString(issueType->string)); + cJSON_AddItemToArray(issueTypesArray, cJSON_CreateString(issueType->string)); } } + + // Add this category and its issue types to response + if (cJSON_GetArraySize(issueTypesArray) > 0) { + cJSON_AddItemToObject(response, category->string, issueTypesArray); + } else { + cJSON_Delete(issueTypesArray); + } } } } - result_str = cJSON_Print(allIssueTypes); - cJSON_Delete(allIssueTypes); + result_str = cJSON_Print(response); + cJSON_Delete(response); } else { // Return specific category issue types cJSON *category = cJSON_GetObjectItem(json, RRDProfileCategory);