From bc091d40782ef34748311c4aeb2b6d95bf2ba324 Mon Sep 17 00:00:00 2001 From: bunnam988 Date: Tue, 18 Nov 2025 19:08:54 +0000 Subject: [PATCH 01/39] Revert "Merge pull request #32 from jonathanwu-csv/develop" This reverts commit f99d362aaf8c71380153f10ddd3fbc1ba7497e34, reversing changes made to 8f8f58e7a8b8cc600eea92b5b509ee40f0c4e6d4. --- source/cosa/utilities/bsp_eng/bspeng_branch_co_process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/cosa/utilities/bsp_eng/bspeng_branch_co_process.c b/source/cosa/utilities/bsp_eng/bspeng_branch_co_process.c index cdb2c4660..4708e8103 100644 --- a/source/cosa/utilities/bsp_eng/bspeng_branch_co_process.c +++ b/source/cosa/utilities/bsp_eng/bspeng_branch_co_process.c @@ -678,7 +678,7 @@ BspTemplateBranchLoadBranchData if (!bSucc) return FALSE; - pBrData->type = (BSP_TEMPLATE_BRANCH_TYPE)ucType; + pBrData->type = (BSP_TEMPLATE_OPERATOR)ucType; switch (pBrData->type) { From 2011ddad5a4db92f1a6ab312bf991730aa6b7cfd Mon Sep 17 00:00:00 2001 From: bunnam988 Date: Tue, 18 Nov 2025 19:09:37 +0000 Subject: [PATCH 02/39] Revert "Merge pull request #29 from madhukrishnasmenon-comcast/develop" This reverts commit 85ca445c3315e04c581d81f5e363dda6caf9eed3, reversing changes made to 5b06b95546e057a50a243b67d0fb2dec400eab83. --- .../DslhObjController/dslh_objco_access.c | 4 +++ .../ansc_uint_array_co_process.c | 31 +++++++++++++++---- .../utilities/bsp_eng/bspeng_co_execute.c | 14 +++++++-- source/debug_api/ansc_memory.c | 9 ++++++ .../util_api/ansc/AnscPlatform/ansc_debug.c | 8 +++++ .../util_api/ansc/AnscPlatform/ansc_file_io.c | 23 +++++++++++--- .../util_api/ansc/AnscPlatform/user_file_io.c | 12 ++++--- .../AnscXmlDomParser/ansc_xml_dom_node_base.c | 21 +++++++++++++ .../util_api/ccsp_msg_bus/ccsp_message_bus.c | 25 ++++++++++++--- .../TlsHandShaker/tls_hso_control.c | 18 +++++++++++ 10 files changed, 143 insertions(+), 22 deletions(-) diff --git a/source/ccsp/components/common/DataModel/dml/components/DslhObjController/dslh_objco_access.c b/source/ccsp/components/common/DataModel/dml/components/DslhObjController/dslh_objco_access.c index d7bd89de7..0d03c25cd 100644 --- a/source/ccsp/components/common/DataModel/dml/components/DslhObjController/dslh_objco_access.c +++ b/source/ccsp/components/common/DataModel/dml/components/DslhObjController/dslh_objco_access.c @@ -1028,7 +1028,11 @@ DslhObjcoGetParamValueByName /*AnscTraceVerbose(("DslhObjcoGetParamValueByName -- name %s\n", pName));*/ /* check whether it's a count of table (xxxNumberOfEntries) or not */ +#ifdef _64BIT_ARCH_SUPPORT_ if(pSlapVariable->Syntax == (ULONG)SLAP_VAR_SYNTAX_uint32) +#else + if(pSlapVariable->Syntax == SLAP_VAR_SYNTAX_uint32) +#endif { pFind = _ansc_strstr(pName, TR69_NUMBER_OF_ENTRIES_STRING); diff --git a/source/cosa/utilities/AnscObjectArray/AnscUIntArray/ansc_uint_array_co_process.c b/source/cosa/utilities/AnscObjectArray/AnscUIntArray/ansc_uint_array_co_process.c index 06bc14ca5..427612722 100644 --- a/source/cosa/utilities/AnscObjectArray/AnscUIntArray/ansc_uint_array_co_process.c +++ b/source/cosa/utilities/AnscObjectArray/AnscUIntArray/ansc_uint_array_co_process.c @@ -74,7 +74,6 @@ #include "ansc_uint_array_co_global.h" -#include /********************************************************************** @@ -276,7 +275,11 @@ AnscUIntArrayGetAt pStorage = (PUINT)pUIntArray->hStorage; - return (ANSC_OBJECT_ARRAY_DATA)(uintptr_t)pStorage[ulIndex]; +#ifdef _64BIT_ARCH_SUPPORT_ + return (ANSC_OBJECT_ARRAY_DATA)(ULONG)pStorage[ulIndex]; +#else + return (ANSC_OBJECT_ARRAY_DATA)pStorage[ulIndex]; +#endif } return (ANSC_OBJECT_ARRAY_DATA)NULL; @@ -332,7 +335,11 @@ AnscUIntArraySetAt PUINT pStorage; pStorage = (PUINT)pUIntArray->hStorage; - pStorage[ulIndex] = (uintptr_t)Data; +#ifdef _64BIT_ARCH_SUPPORT_ + pStorage[ulIndex] = (ULONG)Data; +#else + pStorage[ulIndex] = (UINT)Data; +#endif } } @@ -413,7 +420,11 @@ AnscUIntArrayInsertAt for (i = 0; i < ulCount; i ++) { - pStorage[i + ulIndex] = (uintptr_t)Data; +#ifdef _64BIT_ARCH_SUPPORT_ + pStorage[i + ulIndex] = (ULONG)Data; +#else + pStorage[i + ulIndex] = (UINT)Data; +#endif } } } @@ -528,7 +539,11 @@ AnscUIntArrayAdd PUINT pStorage; pStorage = (PUINT)pUIntArray->hStorage; - pStorage[pUIntArray->ulItemCount ++] = (uintptr_t)Data; +#ifdef _64BIT_ARCH_SUPPORT_ + pStorage[pUIntArray->ulItemCount ++] = (ULONG)Data; +#else + pStorage[pUIntArray->ulItemCount ++] = (UINT)Data; +#endif return pUIntArray->ulItemCount; } @@ -661,7 +676,11 @@ AnscUIntArrayFind LONG Count = pUIntArray->ulItemCount; LONG i; PUINT pStorage = (PUINT)pUIntArray->hStorage; - UINT uSample = (uintptr_t)Data; +#ifdef _64BIT_ARCH_SUPPORT_ + UINT uSample = (ULONG)Data; +#else + UINT uSample = (UINT)Data; +#endif for (i = 0; i < Count; i ++) { diff --git a/source/cosa/utilities/bsp_eng/bspeng_co_execute.c b/source/cosa/utilities/bsp_eng/bspeng_co_execute.c index cff8f8da8..900bd7142 100644 --- a/source/cosa/utilities/bsp_eng/bspeng_co_execute.c +++ b/source/cosa/utilities/bsp_eng/bspeng_co_execute.c @@ -72,7 +72,7 @@ **********************************************************************/ -#include + #include "bspeng_co_global.h" #include "safec_lib_common.h" @@ -6198,7 +6198,11 @@ BspTemplateEngGetSlapObjectString if (pString) { - rc = sprintf_s(pString, ulSize, "%.08X", (UINT)(uintptr_t)pSlapVar->Variant.varHandle); +#ifdef _64BIT_ARCH_SUPPORT_ + rc = sprintf_s(pString, ulSize, "%.08X", (UINT)(ULONG)pSlapVar->Variant.varHandle); +#else + rc = sprintf_s(pString, ulSize, "%.08X", (UINT)pSlapVar->Variant.varHandle); +#endif if(rc < EOK) { ERR_CHK(rc); @@ -6417,7 +6421,11 @@ BspTemplateEngGetSlapObjectString pString + AnscSizeOfString(pString), ulSize+1, (i == 0)? "%.08X" : ".%.08X", - (UINT)(uintptr_t)pArray->Array.arrayHandle[i] +#ifdef _64BIT_ARCH_SUPPORT_ + (UINT)(ULONG)pArray->Array.arrayHandle[i] +#else + (UINT)pArray->Array.arrayHandle[i] +#endif ); if(rc < EOK) { diff --git a/source/debug_api/ansc_memory.c b/source/debug_api/ansc_memory.c index ae8230baf..e22b33b5f 100644 --- a/source/debug_api/ansc_memory.c +++ b/source/debug_api/ansc_memory.c @@ -958,8 +958,13 @@ AnscTraceMemoryTable2 sprintf ( pTraceMessage, +#ifdef _64BIT_ARCH_SUPPORT_ " *** mem_block = %p, size = %9d bytes, id = %6d, %s ***", pMemoryAllocItem->MemoryPointer, +#else + " *** mem_block = 0x%8X, size = %9d bytes, id = %6d, %s ***", + (UINT)pMemoryAllocItem->MemoryPointer, +#endif (int)pMemoryAllocItem->MemorySize, (int)pMemoryAllocItem->AllocId, pMemoryAllocItem->OwnerDesp @@ -1444,7 +1449,11 @@ void AnscLiveMemoryInspectRecordDetail pPrevAllocItem = AnscGetPrevMemoryAllocItem(pMemoryBlock); +#ifdef _64BIT_ARCH_SUPPORT_ printf("found %p\n",pPrevAllocItem); +#else + printf("found %x\n",(UINT)pPrevAllocItem); +#endif if ( !pPrevAllocItem ) { diff --git a/source/util_api/ansc/AnscPlatform/ansc_debug.c b/source/util_api/ansc/AnscPlatform/ansc_debug.c index 46284e6d8..e55f68d0b 100644 --- a/source/util_api/ansc/AnscPlatform/ansc_debug.c +++ b/source/util_api/ansc/AnscPlatform/ansc_debug.c @@ -650,7 +650,11 @@ AnscDumpMemory /* * Print the address */ +#ifdef _64BIT_ARCH_SUPPORT_ _ansc_sprintf(PrintBuffer, "%p", pCurr); +#else + _ansc_sprintf(PrintBuffer, "0x%08X", (unsigned int)pCurr); +#endif _ansc_strcat (PrintBuffer, ": "); /* @@ -691,7 +695,11 @@ AnscDumpMemory /* * Print the address */ +#ifdef _64BIT_ARCH_SUPPORT_ _ansc_sprintf(PrintBuffer, "%p", pCurr); +#else + _ansc_sprintf(PrintBuffer, "0x%08X", (unsigned int)pCurr); +#endif _ansc_strcat (PrintBuffer, ": " ); /* diff --git a/source/util_api/ansc/AnscPlatform/ansc_file_io.c b/source/util_api/ansc/AnscPlatform/ansc_file_io.c index a1932276f..6a2e1aa77 100644 --- a/source/util_api/ansc/AnscPlatform/ansc_file_io.c +++ b/source/util_api/ansc/AnscPlatform/ansc_file_io.c @@ -88,7 +88,7 @@ **********************************************************************/ -#include + #include "ansc_platform.h" #include "ansc_external_storage.h" #include "ansc_crypto_interface.h" @@ -245,7 +245,12 @@ AnscReadFile if ( pFileInfo->bZlibCompressed ) { - iReturnsize = _ansc_get_file_size((VOID*)(uintptr_t)pFileInfo->Handle); +#ifdef _64BIT_ARCH_SUPPORT_ + ULONG uHandle = pFileInfo->Handle; + iReturnsize = _ansc_get_file_size((VOID*)uHandle); +#else + iReturnsize = _ansc_get_file_size((VOID*)pFileInfo->Handle); +#endif if ( iReturnsize < 0 ) { return ANSC_STATUS_FAILURE; @@ -482,7 +487,12 @@ AnscGetFileSize { int iReadSize = (int)0; - iReturnSize = _ansc_get_file_size((VOID*)(uintptr_t)pFileInfo->Handle); +#ifdef _64BIT_ARCH_SUPPORT_ + ULONG uHandle = pFileInfo->Handle; + iReturnSize = _ansc_get_file_size((VOID*)uHandle); +#else + iReturnSize = _ansc_get_file_size((VOID*)pFileInfo->Handle); +#endif if ( iReturnSize < 0 ) { return 0; @@ -536,7 +546,12 @@ AnscGetFileSize else { /*CID: 59651 Improper use of negative value*/ - iReturnSize = _ansc_get_file_size((VOID*)(uintptr_t)pFileInfo->Handle); +#ifdef _64BIT_ARCH_SUPPORT_ + ULONG uHandle = pFileInfo->Handle; + iReturnSize = _ansc_get_file_size((VOID*)uHandle); +#else + iReturnSize = _ansc_get_file_size((VOID*)pFileInfo->Handle); +#endif if(iReturnSize < 0) { return 0; diff --git a/source/util_api/ansc/AnscPlatform/user_file_io.c b/source/util_api/ansc/AnscPlatform/user_file_io.c index e7ac18419..f62fcaf16 100644 --- a/source/util_api/ansc/AnscPlatform/user_file_io.c +++ b/source/util_api/ansc/AnscPlatform/user_file_io.c @@ -74,7 +74,6 @@ #include #include -#include #include "ansc_global.h" #include "user_base.h" @@ -309,9 +308,14 @@ inline int user_get_file_size(PVOID h) { int length = 0; - length = lseek((int)(uintptr_t)h, 0, SEEK_END); - lseek((int)(uintptr_t)h, 0, SEEK_SET); - return length; +#ifdef _64BIT_ARCH_SUPPORT_ + length = lseek((int)(ULONG)h, 0, SEEK_END); + lseek((int)(ULONG)h, 0, SEEK_SET); +#else + length = lseek((int)h, 0, SEEK_END); + lseek((int)h, 0, SEEK_SET); +#endif + return length; } /* diff --git a/source/util_api/ansc/AnscXmlDomParser/ansc_xml_dom_node_base.c b/source/util_api/ansc/AnscXmlDomParser/ansc_xml_dom_node_base.c index c504eac73..89c48a843 100644 --- a/source/util_api/ansc/AnscXmlDomParser/ansc_xml_dom_node_base.c +++ b/source/util_api/ansc/AnscXmlDomParser/ansc_xml_dom_node_base.c @@ -253,9 +253,17 @@ AnscXmlDomNodeRemove { AnscXmlWarning ( +#ifdef _64BIT_ARCH_SUPPORT_ "The child node queue of XML node '%s' is corrupted.cookie1= %p\n", +#else + "The child node queue of XML node '%s' is corrupted.cookie1= 0x%.8X\n", +#endif (char *)pXmlNode->ChildNodeQueueLock, +#ifdef _64BIT_ARCH_SUPPORT_ (void*)pNameAttr->StringData +#else + (unsigned int)pNameAttr->StringData +#endif ); } @@ -270,17 +278,30 @@ AnscXmlDomNodeRemove { AnscXmlWarning ( +#ifdef _64BIT_ARCH_SUPPORT_ "The child node queue of XML node is corrupted. cookie2= %p\n", (void*)pXmlNode->AttributesListLock +#else + "The child node queue of XML node is corrupted. cookie2= 0x%.8X\n", + (unsigned int)pXmlNode->AttributesListLock +#endif ); } else { AnscXmlWarning ( +#ifdef _64BIT_ARCH_SUPPORT_ "The child node queue of XML node '%s' is corrupted.cookie2= %p\n", +#else + "The child node queue of XML node '%s' is corrupted.cookie2= 0x%.8X\n", +#endif (char *)pXmlNode->AttributesListLock, +#ifdef _64BIT_ARCH_SUPPORT_ (void*)pNameAttr->StringData +#else + (unsigned int)pNameAttr->StringData +#endif ); } diff --git a/source/util_api/ccsp_msg_bus/ccsp_message_bus.c b/source/util_api/ccsp_msg_bus/ccsp_message_bus.c index d684b2cb2..28e071b0f 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_message_bus.c +++ b/source/util_api/ccsp_msg_bus/ccsp_message_bus.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include "ccsp_base_api.h" @@ -1567,17 +1566,33 @@ void ccsp_handle_rbus_component_reply (void* bus_handle, rbusMessage msg, rbusVa case RBUS_INT64: { rbusMessage_GetInt64(msg, &i64); - n = snprintf(pTmp, 0, "%" PRId64, i64) + 1; +#ifdef _64BIT_ARCH_SUPPORT_ + n = snprintf(pTmp, 0, "%ld", i64) + 1; +#else + n = snprintf(pTmp, 0, "%lld", i64) + 1; +#endif *pStringValue = bus_info->mallocfunc(n); - snprintf(*pStringValue, (unsigned int)n, "%" PRId64, i64); +#ifdef _64BIT_ARCH_SUPPORT_ + snprintf(*pStringValue, (unsigned int)n, "%ld", i64); +#else + snprintf(*pStringValue, (unsigned int)n, "%lld", i64); +#endif break; } case RBUS_UINT64: { rbusMessage_GetInt64(msg, &i64); - n = snprintf(pTmp, 0, "%" PRIu64, (uint64_t)i64) + 1; +#ifdef _64BIT_ARCH_SUPPORT_ + n = snprintf(pTmp, 0, "%lu", (uint64_t)i64) + 1; +#else + n = snprintf(pTmp, 0, "%llu", (uint64_t)i64) + 1; +#endif *pStringValue = bus_info->mallocfunc(n); - snprintf(*pStringValue, (unsigned int)n, "%" PRIu64, (uint64_t)i64); +#ifdef _64BIT_ARCH_SUPPORT_ + snprintf(*pStringValue, (unsigned int)n, "%lu", (uint64_t)i64); +#else + snprintf(*pStringValue, (unsigned int)n, "%llu", (uint64_t)i64); +#endif break; } case RBUS_SINGLE: diff --git a/source/util_api/tls/components/TlsHandShaker/tls_hso_control.c b/source/util_api/tls/components/TlsHandShaker/tls_hso_control.c index 8acf8be41..f5e0952f5 100644 --- a/source/util_api/tls/components/TlsHandShaker/tls_hso_control.c +++ b/source/util_api/tls/components/TlsHandShaker/tls_hso_control.c @@ -475,12 +475,21 @@ TlsHsoCalKeys30 PTLS_RECORD_STATE pRecordStateR = (PTLS_RECORD_STATE )&pMyObject->RecordStateR; PTLS_MEC_INTERFACE pTlsMecIf = (PTLS_MEC_INTERFACE )pMyObject->hTlsMecIf; PTLS_CRYPTO_PROVIDER_OBJECT pTlsCryptoProvider = (PTLS_CRYPTO_PROVIDER_OBJECT)pTlsMecIf->GetTlsCryptoProvider(pTlsMecIf->hOwnerContext); +#ifdef _64BIT_ARCH_SUPPORT_ ANSC_CRYPTO_KEY* pMacSecretC = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->MacSecret : &pRecordStateW->MacSecret; ANSC_CRYPTO_KEY* pMacSecretS = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->MacSecret : &pRecordStateR->MacSecret; ANSC_CRYPTO_KEY* pCipherKeyC = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->CipherKey : &pRecordStateW->CipherKey; ANSC_CRYPTO_KEY* pCipherKeyS = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->CipherKey : &pRecordStateR->CipherKey; ANSC_CRYPTO_IV* pCipherIV_C = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->CipherIV : &pRecordStateW->CipherIV; ANSC_CRYPTO_IV* pCipherIV_S = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->CipherIV : &pRecordStateR->CipherIV; +#else + ANSC_CRYPTO_KEY* pMacSecretC = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->MacSecret : &pRecordStateW->MacSecret; + ANSC_CRYPTO_KEY* pMacSecretS = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->MacSecret : &pRecordStateR->MacSecret; + ANSC_CRYPTO_KEY* pCipherKeyC = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->CipherKey : &pRecordStateW->CipherKey; + ANSC_CRYPTO_KEY* pCipherKeyS = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->CipherKey : &pRecordStateR->CipherKey; + ANSC_CRYPTO_IV* pCipherIV_C = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->CipherIV : &pRecordStateW->CipherIV; + ANSC_CRYPTO_IV* pCipherIV_S = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->CipherIV : &pRecordStateR->CipherIV; +#endif PUCHAR pKeyBlock = (PUCHAR )NULL; ULONG write_key_length = 0; ULONG key_block_offset = 0; @@ -836,12 +845,21 @@ TlsHsoCalKeys31 PTLS_RECORD_STATE pRecordStateR = (PTLS_RECORD_STATE )&pMyObject->RecordStateR; PTLS_MEC_INTERFACE pTlsMecIf = (PTLS_MEC_INTERFACE )pMyObject->hTlsMecIf; PTLS_CRYPTO_PROVIDER_OBJECT pTlsCryptoProvider = (PTLS_CRYPTO_PROVIDER_OBJECT)pTlsMecIf->GetTlsCryptoProvider(pTlsMecIf->hOwnerContext); +#ifdef _64BIT_ARCH_SUPPORT_ ANSC_CRYPTO_KEY* pMacSecretC = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->MacSecret : &pRecordStateW->MacSecret; ANSC_CRYPTO_KEY* pMacSecretS = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->MacSecret : &pRecordStateR->MacSecret; ANSC_CRYPTO_KEY* pCipherKeyC = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->CipherKey : &pRecordStateW->CipherKey; ANSC_CRYPTO_KEY* pCipherKeyS = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->CipherKey : &pRecordStateR->CipherKey; ANSC_CRYPTO_IV* pCipherIV_C = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->CipherIV : &pRecordStateW->CipherIV; ANSC_CRYPTO_IV* pCipherIV_S = (ANSC_CRYPTO_KEY* )(ULONG)(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->CipherIV : &pRecordStateR->CipherIV; +#else + ANSC_CRYPTO_KEY* pMacSecretC = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->MacSecret : &pRecordStateW->MacSecret; + ANSC_CRYPTO_KEY* pMacSecretS = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->MacSecret : &pRecordStateR->MacSecret; + ANSC_CRYPTO_KEY* pCipherKeyC = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->CipherKey : &pRecordStateW->CipherKey; + ANSC_CRYPTO_KEY* pCipherKeyS = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->CipherKey : &pRecordStateR->CipherKey; + ANSC_CRYPTO_IV* pCipherIV_C = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateR->CipherIV : &pRecordStateW->CipherIV; + ANSC_CRYPTO_IV* pCipherIV_S = (ANSC_CRYPTO_KEY* )(pSecurityParams->ConnectionEnd == TLS_CONNECTION_END_server)? &pRecordStateW->CipherIV : &pRecordStateR->CipherIV; +#endif PUCHAR pKeyBlock = (PUCHAR )NULL; ULONG write_key_length = 0; ULONG key_block_offset = 0; From ec4426f78298f8d2564b745f7f9b0e2713015194 Mon Sep 17 00:00:00 2001 From: bunnam988 Date: Tue, 18 Nov 2025 19:11:00 +0000 Subject: [PATCH 03/39] Revert "Merge pull request #19 from ldalek/ow_threads_stack_sizes" This reverts commit 5b06b95546e057a50a243b67d0fb2dec400eab83, reversing changes made to 426881d08a46b17cdcf6ff154bb04b6d3ce3cea6. --- systemd_units/onewifi.service | 1 - 1 file changed, 1 deletion(-) diff --git a/systemd_units/onewifi.service b/systemd_units/onewifi.service index aab09912f..b0b154d66 100644 --- a/systemd_units/onewifi.service +++ b/systemd_units/onewifi.service @@ -23,7 +23,6 @@ After=CcspPandMSsp.service [Service] Type=forking PIDFile=/var/tmp/OneWifi.pid -LimitSTACK=4096K WorkingDirectory=/usr/ccsp/wifi Environment="Subsys=eRT." Environment="LOG4C_RCPATH=/etc" From e0b3fc2aeba3e04d342b2154ff3190706f0e7c6b Mon Sep 17 00:00:00 2001 From: bunnam988 Date: Fri, 5 Dec 2025 16:51:59 +0000 Subject: [PATCH 04/39] Reapply "Merge pull request #19 from ldalek/ow_threads_stack_sizes" This reverts commit ec4426f78298f8d2564b745f7f9b0e2713015194. --- systemd_units/onewifi.service | 1 + 1 file changed, 1 insertion(+) diff --git a/systemd_units/onewifi.service b/systemd_units/onewifi.service index b0b154d66..aab09912f 100644 --- a/systemd_units/onewifi.service +++ b/systemd_units/onewifi.service @@ -23,6 +23,7 @@ After=CcspPandMSsp.service [Service] Type=forking PIDFile=/var/tmp/OneWifi.pid +LimitSTACK=4096K WorkingDirectory=/usr/ccsp/wifi Environment="Subsys=eRT." Environment="LOG4C_RCPATH=/etc" From 40c402a9b7bc8dbf0801d76bca26f88b43cc2ebf Mon Sep 17 00:00:00 2001 From: apattu200 Date: Tue, 18 Nov 2025 08:24:27 +0530 Subject: [PATCH 05/39] Merge pull request #40 from Gowthamik93/XB9-669 XB9-668 : Upstream xb9 specific changes to github repo --- scripts/ccsp_restart.sh | 5 ++++- scripts/cosa_start_arm.sh | 2 ++ scripts/cosa_start_rem.sh | 3 ++- source/debug_api/ansc_debug.c | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/ccsp_restart.sh b/scripts/ccsp_restart.sh index e7e3e6124..dd99355f6 100644 --- a/scripts/ccsp_restart.sh +++ b/scripts/ccsp_restart.sh @@ -72,11 +72,13 @@ exec 3>&1 4>&2 >>$SELFHEALFILE 2>&1 fi killall CcspLMLite killall CcspXdnsSsp +if [ "$VOICE_SUPPORTED" != "false" ]; then if [ -f "/tmp/mta_initialized" ] then rm -rf /tmp/mta_initialized fi killall CcspMtaAgentSsp +fi killall CcspHotspot @@ -174,6 +176,7 @@ ulimit -c unlimited sleep 3 #mta +if [ "$VOICE_SUPPORTED" != "false" ]; then if [ "$MODEL_NUM" = "DPC3939B" ] || [ "$MODEL_NUM" = "DPC3941B" ]; then echo_t "Disabling MTA for BWG " else @@ -185,7 +188,7 @@ ulimit -c unlimited $BINPATH/CcspMtaAgentSsp -subsys $Subsys fi fi - +fi sleep 3 echo "[`getDateTime`] RDKB_SELFHEAL : Resetting process webpa on atom reset" cd /usr/ccsp/webpa diff --git a/scripts/cosa_start_arm.sh b/scripts/cosa_start_arm.sh index 31868c4fe..157ec7ae6 100644 --- a/scripts/cosa_start_arm.sh +++ b/scripts/cosa_start_arm.sh @@ -75,7 +75,9 @@ if [ "x"$1 = "xkill" ] || [ "x"$2 = "xkill" ]; then # killall CcspRmSsp killall CcspCrSsp # killall CcspLmSsp +if [ "$VOICE_SUPPORTED" != "false" ]; then killall CcspMtaAgentSsp +fi killall CcspCMAgentSsp killall CcspLMLite killall CcspXdnsSsp diff --git a/scripts/cosa_start_rem.sh b/scripts/cosa_start_rem.sh index 94f123695..512a62a19 100644 --- a/scripts/cosa_start_rem.sh +++ b/scripts/cosa_start_rem.sh @@ -197,7 +197,7 @@ syscfg set mgmt_wan_sshaccess 1 syscfg commit echo_t "PWD is `pwd`" - +if [ "$VOICE_SUPPORTED" != "false" ]; then if [ "$MODEL_NUM" = "DPC3939B" ] || [ "$MODEL_NUM" = "DPC3941B" ]; then echo_t "Disabling MTA for BWG " else @@ -212,6 +212,7 @@ if [ -e ./mta ]; then cd .. fi fi +fi if [ -e ./moca ]; then cd moca diff --git a/source/debug_api/ansc_debug.c b/source/debug_api/ansc_debug.c index 51faeca9f..24ebbfe2b 100644 --- a/source/debug_api/ansc_debug.c +++ b/source/debug_api/ansc_debug.c @@ -265,7 +265,9 @@ const char *CcspTraceGetRdkLogModule(const char *pComponentName) #if !defined (NO_MOCA_FEATURE_SUPPORT) if (strcmp(pComponentName, "moca") == 0) return "LOG.RDK.MOCA"; #endif +#if !defined (NO_MTA_FEATURE_SUPPORT) if (strcmp(pComponentName, "mta") == 0) return "LOG.RDK.MTA"; +#endif break; case 'n': #if defined (FEATURE_RDKB_NFC_MANAGER) From 852b295cb6e30ab4df213f25e02aae0f734fe6af Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Wed, 1 Apr 2026 07:56:32 +0000 Subject: [PATCH 06/39] Implement PSM APIs using CORD #53 Reason for change: replacing PSM APIs with CORD APIs Test Procedure: build and verify Risks: Low Priority: P1 Signed-off-by: mkorav871 madhukrishnasmenon@comcast.com --- configure.ac | 13 + source/util_api/ccsp_msg_bus/ccsp_base_api.c | 358 ++++++++++++++++++- 2 files changed, 369 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 604352a42..88a202da6 100644 --- a/configure.ac +++ b/configure.ac @@ -40,6 +40,19 @@ AC_ARG_ENABLE([gtestapp], [echo "Gtestapp is disabled"]) AM_CONDITIONAL([WITH_GTEST_SUPPORT], [test x$GTEST_SUPPORT_ENABLED = xtrue]) +AC_ARG_ENABLE([cord], + AS_HELP_STRING([--enable-cord],[enable CORD persistent storage support (default is no)]), + [ + case "${enableval}" in + yes) CORD_ENABLED=true + CFLAGS="$CFLAGS -DCORD_ENABLED";; + no) CORD_ENABLED=false;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-cord]);; + esac + ], + [CORD_ENABLED=false]) +AM_CONDITIONAL([WITH_CORD_SUPPORT], [test x$CORD_ENABLED = xtrue]) + AC_PREFIX_DEFAULT(`pwd`) AC_ENABLE_SHARED AC_DISABLE_STATIC diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 56e414a88..bb98e9b91 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -47,6 +47,12 @@ #endif #include #include "ccsp_trace.h" +#include +#include +#include +#ifdef CORD_ENABLED +#include +#endif /* For AnscEqualString */ #include "ansc_platform.h" @@ -2984,6 +2990,59 @@ int PSM_Set_Record_Value { UNREFERENCED_PARAMETER(ulRecordType); UNREFERENCED_PARAMETER(pSubSystemPrefix); + +#ifdef CORD_ENABLED + UNREFERENCED_PARAMETER(bus_handle); + + if (pRecordName == NULL || pValue == NULL) + return CCSP_CR_ERR_INVALID_PARAM; + + cord_rc_t cord_rc; + + switch (pValue->Syntax) + { + case SLAP_VAR_SYNTAX_int: + cord_rc = cord_set_i32(pRecordName, (int32_t)pValue->Variant.varInt, CORD_FLAG_PERSIST_ASYNC); + break; + case SLAP_VAR_SYNTAX_uint32: + cord_rc = cord_set_u32(pRecordName, (uint32_t)pValue->Variant.varUint32, CORD_FLAG_PERSIST_ASYNC); + break; + case SLAP_VAR_SYNTAX_bool: + cord_rc = cord_set_bool(pRecordName, (pValue->Variant.varBool != 0), CORD_FLAG_PERSIST_ASYNC); + break; + case SLAP_VAR_SYNTAX_string: + if (pValue->Variant.varString == NULL) + return CCSP_CR_ERR_INVALID_PARAM; + cord_rc = cord_set_string(pRecordName, pValue->Variant.varString, CORD_FLAG_PERSIST_ASYNC); + break; + case SLAP_VAR_SYNTAX_TYPE_ucharArray: + { + SLAP_UCHAR_ARRAY* var_uchar_array = pValue->Variant.varUcharArray; + if (var_uchar_array == NULL) + return CCSP_CR_ERR_INVALID_PARAM; + cord_rc = cord_set_blob(pRecordName, + var_uchar_array->Array.arrayUchar, + var_uchar_array->VarCount, + CORD_FLAG_PERSIST_ASYNC); + break; + } + default: + return CCSP_CR_ERR_INVALID_PARAM; + } + + switch (cord_rc) { + case CORD_RC_SUCCESS: return CCSP_SUCCESS; + case CORD_RC_NOT_OPEN: return CCSP_Message_Bus_ERROR; + case CORD_RC_INVALID_NAME: return CCSP_ERR_INVALID_PARAMETER_VALUE; + case CORD_RC_INVALID_FLAG: return CCSP_ERR_INVALID_PARAMETER_VALUE; + case CORD_RC_PERMISSION_DENIED: return CCSP_ERR_REQUEST_REJECTED; + case CORD_RC_PERSIST_FAILED: return CCSP_Message_Bus_OOM; + case CORD_RC_INVALID_ARG: return CCSP_ERR_INVALID_PARAMETER_VALUE; + } + return CCSP_Message_Bus_ERROR; + +#else /* !CORD_ENABLED */ + parameterValStruct_t val[1]; char buf[128]; char* var_string = 0; @@ -3061,6 +3120,8 @@ int PSM_Set_Record_Value if(var_string) bus_info->freefunc(var_string); return ret; + +#endif /* CORD_ENABLED */ } int PSM_Get_Record_Value @@ -3073,11 +3134,86 @@ int PSM_Get_Record_Value ) { UNREFERENCED_PARAMETER(pSubSystemPrefix); + CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; + +#ifdef CORD_ENABLED + + if (pRecordName == NULL || pValue == NULL) + return CCSP_CR_ERR_INVALID_PARAM; + + cord_value_t *pCordValue = NULL; + cord_rc_t cord_rc = cord_get(pRecordName, &pCordValue); + + switch (cord_rc) { + case CORD_RC_SUCCESS: break; + case CORD_RC_NOT_OPEN: return CCSP_Message_Bus_ERROR; + case CORD_RC_INVALID_NAME: return CCSP_ERR_NOT_EXIST; + case CORD_RC_PERMISSION_DENIED: return CCSP_ERR_REQUEST_REJECTED; + case CORD_RC_OUT_OF_MEMORY: return CCSP_ERR_MEMORY_ALLOC_FAIL; + default: return CCSP_Message_Bus_ERROR; + } + + int ret = CCSP_SUCCESS; + + switch (pCordValue->valueType) + { + case CORD_TYPE_I32: + if (ulRecordType) *ulRecordType = ccsp_int; + pValue->Syntax = SLAP_VAR_SYNTAX_int; + pValue->Variant.varInt = (int)pCordValue->i32Value; + break; + case CORD_TYPE_U32: + if (ulRecordType) *ulRecordType = ccsp_unsignedInt; + pValue->Syntax = SLAP_VAR_SYNTAX_uint32; + pValue->Variant.varUint32 = (uint32_t)pCordValue->u32Value; + break; + case CORD_TYPE_BOOL: + if (ulRecordType) *ulRecordType = ccsp_boolean; + pValue->Syntax = SLAP_VAR_SYNTAX_bool; + pValue->Variant.varBool = pCordValue->boolValue ? TRUE : SLAP_FALSE; + break; + case CORD_TYPE_STRING: + { + if (ulRecordType) *ulRecordType = ccsp_string; + pValue->Syntax = SLAP_VAR_SYNTAX_string; + if (pValue->Variant.varString) + bus_info->freefunc(pValue->Variant.varString); + size_t str_len = strlen(pCordValue->stringValue); + pValue->Variant.varString = (char *)bus_info->mallocfunc(str_len + 1); + if (pValue->Variant.varString == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + strcpy(pValue->Variant.varString, pCordValue->stringValue); + break; + } + case CORD_TYPE_BLOB: + { + if (ulRecordType) *ulRecordType = ccsp_byte; + pValue->Syntax = SLAP_VAR_SYNTAX_TYPE_ucharArray; + size_t blob_len = pCordValue->blobValue.length; + SLAP_UCHAR_ARRAY *var_ucharArray = (SLAP_UCHAR_ARRAY *)bus_info->mallocfunc(sizeof(SLAP_UCHAR_ARRAY) + blob_len); + if (var_ucharArray == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + var_ucharArray->Size = sizeof(SLAP_UCHAR_ARRAY) + blob_len; + var_ucharArray->VarCount = (ULONG)blob_len; + var_ucharArray->Syntax = SLAP_VAR_SYNTAX_ucharArray; + memcpy(var_ucharArray->Array.arrayUchar, pCordValue->blobValue.pData, blob_len); + if (pValue->Variant.varUcharArray) + bus_info->freefunc(pValue->Variant.varUcharArray); + pValue->Variant.varUcharArray = var_ucharArray; + break; + } + default: + cord_free_values(pCordValue); + return CCSP_CR_ERR_UNSUPPORTED_DATATYPE; + } + + cord_free_values(pCordValue); + return ret; + +#else /* !CORD_ENABLED */ + char* parameterNames[1]; int size = 0; parameterValStruct_t **val = 0; int ret = -1; - CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; parameterNames[0] = (char *)pRecordName; ret = PSM_Get_Record_Value_rbus(bus_handle, parameterNames, 1, &size, &val); if(ret != CCSP_SUCCESS ) @@ -3168,6 +3304,8 @@ int PSM_Get_Record_Value } free_parameterValStruct_t(bus_handle , size, val); return ret; + +#endif /* CORD_ENABLED */ } #endif @@ -3181,6 +3319,127 @@ int PSM_Set_Record_Value2 ) { UNREFERENCED_PARAMETER(pSubSystemPrefix); + +#ifdef CORD_ENABLED + UNREFERENCED_PARAMETER(bus_handle); + + if (pRecordName == NULL || pVal == NULL) + return CCSP_CR_ERR_INVALID_PARAM; + + cord_rc_t cord_rc; + + char *endptr = NULL; + switch (ulRecordType) + { + case ccsp_int: + { + errno = 0; + long val_l = strtol(pVal, &endptr, 10); + if (errno != 0 || endptr == pVal || *endptr != '\0') + return CCSP_ERR_INVALID_PARAMETER_VALUE; + cord_rc = cord_set_i32(pRecordName, (int32_t)val_l, CORD_FLAG_PERSIST_ASYNC); + break; + } + case ccsp_unsignedInt: + { + errno = 0; + unsigned long val_ul = strtoul(pVal, &endptr, 10); + if (errno != 0 || endptr == pVal || *endptr != '\0') + return CCSP_ERR_INVALID_PARAMETER_VALUE; + cord_rc = cord_set_u32(pRecordName, (uint32_t)val_ul, CORD_FLAG_PERSIST_ASYNC); + break; + } + case ccsp_boolean: + if (strcmp(pVal, PSM_FALSE) && strcmp(pVal, PSM_TRUE)) + return CCSP_CR_ERR_INVALID_PARAM; + cord_rc = cord_set_bool(pRecordName, (strcasecmp(pVal, PSM_TRUE) == 0), CORD_FLAG_PERSIST_ASYNC); + break; + case ccsp_string: + cord_rc = cord_set_string(pRecordName, pVal, CORD_FLAG_PERSIST_ASYNC); + break; + case ccsp_long: + { + errno = 0; + long long val_ll = strtoll(pVal, &endptr, 10); + if (errno != 0 || endptr == pVal || *endptr != '\0') + return CCSP_ERR_INVALID_PARAMETER_VALUE; + cord_rc = cord_set_i64(pRecordName, (int64_t)val_ll, CORD_FLAG_PERSIST_ASYNC); + break; + } + case ccsp_unsignedLong: + { + errno = 0; + unsigned long long val_ull = strtoull(pVal, &endptr, 10); + if (errno != 0 || endptr == pVal || *endptr != '\0') + return CCSP_ERR_INVALID_PARAMETER_VALUE; + cord_rc = cord_set_u64(pRecordName, (uint64_t)val_ull, CORD_FLAG_PERSIST_ASYNC); + break; + } + case ccsp_float: + case ccsp_double: + { + errno = 0; + double val_d = strtod(pVal, &endptr); + if (errno != 0 || endptr == pVal || *endptr != '\0') + return CCSP_ERR_INVALID_PARAMETER_VALUE; + cord_rc = cord_set_double(pRecordName, val_d, CORD_FLAG_PERSIST_ASYNC); + break; + } + case ccsp_byte: + { + errno = 0; + long val_b = strtol(pVal, &endptr, 10); + if (errno != 0 || endptr == pVal || *endptr != '\0') + return CCSP_ERR_INVALID_PARAMETER_VALUE; + cord_rc = cord_set_i32(pRecordName, (int32_t)val_b, CORD_FLAG_PERSIST_ASYNC); + break; + } + case ccsp_dateTime: + { + struct tm tm_val; + memset(&tm_val, 0, sizeof(tm_val)); + time_t time_val; + char *parse_end = strptime(pVal, "%Y-%m-%dT%H:%M:%S", &tm_val); + if (parse_end != NULL) + { + tm_val.tm_isdst = -1; + time_val = mktime(&tm_val); + if (time_val == (time_t)-1) + return CCSP_ERR_INVALID_PARAMETER_VALUE; + } + else + { + errno = 0; + long val_t = strtol(pVal, &endptr, 10); + if (errno != 0 || endptr == pVal || *endptr != '\0') + return CCSP_ERR_INVALID_PARAMETER_VALUE; + time_val = (time_t)val_t; + } + cord_rc = cord_set_datetime(pRecordName, time_val, CORD_FLAG_PERSIST_ASYNC); + break; + } + case ccsp_base64: + cord_rc = cord_set_string(pRecordName, pVal, CORD_FLAG_PERSIST_ASYNC); + break; + case ccsp_none: + return CCSP_CR_ERR_UNSUPPORTED_DATATYPE; + default: + return CCSP_CR_ERR_INVALID_PARAM; + } + + switch (cord_rc) { + case CORD_RC_SUCCESS: return CCSP_SUCCESS; + case CORD_RC_NOT_OPEN: return CCSP_Message_Bus_ERROR; + case CORD_RC_INVALID_NAME: return CCSP_ERR_INVALID_PARAMETER_VALUE; + case CORD_RC_INVALID_FLAG: return CCSP_ERR_INVALID_PARAMETER_VALUE; + case CORD_RC_PERMISSION_DENIED: return CCSP_ERR_REQUEST_REJECTED; + case CORD_RC_PERSIST_FAILED: return CCSP_Message_Bus_OOM; + case CORD_RC_INVALID_ARG: return CCSP_ERR_INVALID_PARAMETER_VALUE; + } + return CCSP_Message_Bus_ERROR; + +#else /* !CORD_ENABLED */ + parameterValStruct_t val[1]; if(ulRecordType == ccsp_boolean) { @@ -3193,6 +3452,8 @@ int PSM_Set_Record_Value2 val[0].type = ulRecordType; val[0].parameterValue = (char *)pVal; return PSM_Set_Record_Value_rbus(bus_handle, 1, val); + +#endif /* CORD_ENABLED */ } int PSM_Get_Record_Value2 @@ -3204,9 +3465,100 @@ int PSM_Get_Record_Value2 char** pValue ) { - int ret = 0; UNREFERENCED_PARAMETER(pSubSystemPrefix); *pValue = NULL; + +#ifdef CORD_ENABLED + + if (pRecordName == NULL || pValue == NULL) + return CCSP_CR_ERR_INVALID_PARAM; + + CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; + cord_value_t *pCordValue = NULL; + cord_rc_t cord_rc = cord_get(pRecordName, &pCordValue); + + switch (cord_rc) { + case CORD_RC_SUCCESS: break; + case CORD_RC_NOT_OPEN: return CCSP_Message_Bus_ERROR; + case CORD_RC_INVALID_NAME: return CCSP_ERR_NOT_EXIST; + case CORD_RC_PERMISSION_DENIED: return CCSP_ERR_REQUEST_REJECTED; + case CORD_RC_OUT_OF_MEMORY: return CCSP_ERR_MEMORY_ALLOC_FAIL; + default: return CCSP_Message_Bus_ERROR; + } + + char buf[64]; + int ret = CCSP_SUCCESS; + + switch (pCordValue->valueType) + { + case CORD_TYPE_I32: + if (ulRecordType) *ulRecordType = ccsp_int; + snprintf(buf, sizeof(buf), "%d", (int)pCordValue->i32Value); + *pValue = bus_info->mallocfunc(strlen(buf) + 1); + if (*pValue == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + strcpy(*pValue, buf); + break; + case CORD_TYPE_U32: + if (ulRecordType) *ulRecordType = ccsp_unsignedInt; + snprintf(buf, sizeof(buf), "%u", (unsigned int)pCordValue->u32Value); + *pValue = bus_info->mallocfunc(strlen(buf) + 1); + if (*pValue == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + strcpy(*pValue, buf); + break; + case CORD_TYPE_BOOL: + { + if (ulRecordType) *ulRecordType = ccsp_boolean; + const char *bstr = pCordValue->boolValue ? PSM_TRUE : PSM_FALSE; + *pValue = bus_info->mallocfunc(strlen(bstr) + 1); + if (*pValue == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + strcpy(*pValue, bstr); + break; + } + case CORD_TYPE_STRING: + if (ulRecordType) *ulRecordType = ccsp_string; + *pValue = bus_info->mallocfunc(strlen(pCordValue->stringValue) + 1); + if (*pValue == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + strcpy(*pValue, pCordValue->stringValue); + break; + case CORD_TYPE_I64: + if (ulRecordType) *ulRecordType = ccsp_long; + snprintf(buf, sizeof(buf), "%" PRId64, (int64_t)pCordValue->i64Value); + *pValue = bus_info->mallocfunc(strlen(buf) + 1); + if (*pValue == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + strcpy(*pValue, buf); + break; + case CORD_TYPE_U64: + if (ulRecordType) *ulRecordType = ccsp_unsignedLong; + snprintf(buf, sizeof(buf), "%" PRIu64, (uint64_t)pCordValue->u64Value); + *pValue = bus_info->mallocfunc(strlen(buf) + 1); + if (*pValue == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + strcpy(*pValue, buf); + break; + case CORD_TYPE_DOUBLE: + if (ulRecordType) *ulRecordType = ccsp_double; + snprintf(buf, sizeof(buf), "%.17g", pCordValue->doubleValue); + *pValue = bus_info->mallocfunc(strlen(buf) + 1); + if (*pValue == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + strcpy(*pValue, buf); + break; + case CORD_TYPE_DATETIME: + if (ulRecordType) *ulRecordType = ccsp_dateTime; + snprintf(buf, sizeof(buf), "%ld", (long)pCordValue->dateTimeValue); + *pValue = bus_info->mallocfunc(strlen(buf) + 1); + if (*pValue == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + strcpy(*pValue, buf); + break; + default: + cord_free_values(pCordValue); + return CCSP_CR_ERR_UNSUPPORTED_DATATYPE; + } + + cord_free_values(pCordValue); + return ret; + +#else /* !CORD_ENABLED */ + + int ret = 0; int n = 0; int size; char* pTmp = NULL; @@ -3233,6 +3585,8 @@ int PSM_Get_Record_Value2 } free_parameterValStruct_t(bus_handle , size, val); return ret; + +#endif /* CORD_ENABLED */ } int PSM_Del_Record From 2c85db5da42f1b9b7d002421b9dadd748053fcea Mon Sep 17 00:00:00 2001 From: Srinivas Mamidi Date: Thu, 2 Apr 2026 22:00:48 +0000 Subject: [PATCH 07/39] Implement PSM APIs using CORD --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 256 ++++++++++++++++++- 1 file changed, 254 insertions(+), 2 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index bb98e9b91..f1b0e3b2a 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3596,6 +3596,45 @@ int PSM_Del_Record char const * const pRecordName ) { +#ifdef CORD_ENABLED + char psmName[512] = ""; + errno_t rc = -1; + cord_rc_t crc = CORD_RC_SUCCESS; + + if (!pRecordName) { + return CCSP_ERR_INVALID_PARAMETER_VALUE; + } + + if (pSubSystemPrefix && pSubSystemPrefix[0] != 0) { + rc = strcpy_s(psmName, sizeof(psmName), pSubSystemPrefix); + ERR_CHK(rc); + } + rc = strcat_s(psmName, sizeof(psmName), CCSP_DBUS_PSM); + ERR_CHK(rc); + rc = strcat_s(psmName, sizeof(psmName), "."); + ERR_CHK(rc); + rc = strcat_s(psmName, sizeof(psmName), pRecordName); + ERR_CHK(rc); + + if ( pRecordName[strlen(pRecordName)-1] == '.' ) { + crc = cord_default_multi(psmName, CORD_FLAG_PERSIST_ASYNC); + } + else { + crc = cord_default(psmName, CORD_FLAG_PERSIST_ASYNC); + } + switch (crc) { + case CORD_RC_SUCCESS: return CCSP_SUCCESS; + case CORD_RC_NOT_OPEN: return CCSP_Message_Bus_ERROR; + case CORD_RC_INVALID_NAME: return CCSP_ERR_INVALID_PARAMETER_VALUE; + case CORD_RC_INVALID_FLAG: return CCSP_ERR_INVALID_PARAMETER_VALUE; + case CORD_RC_PERMISSION_DENIED: return CCSP_ERR_REQUEST_REJECTED; + case CORD_RC_PERSIST_FAILED: return CCSP_Message_Bus_OOM; + case CORD_RC_INVALID_ARG: return CCSP_ERR_INVALID_PARAMETER_VALUE; + } + return CCSP_Message_Bus_ERROR; + +#else /* !CORD_ENABLED */ + parameterAttributeStruct_t attr_val[1]; parameterInfoStruct_t **parameter; char psmName[256]; @@ -3670,6 +3709,8 @@ int PSM_Del_Record 1 ); } +#endif /* CORD_ENABLED */ + } int PsmGroupGet(void *bus_handle, const char *subsys, @@ -3691,6 +3732,41 @@ void PsmFreeRecords(void *bus_handle, parameterValStruct_t **records, int nrec) free_parameterValStruct_t(bus_handle, nrec, records); } +#ifdef CORD_ENABLED +typedef struct cord_list_GetNextLevelInstances_List { + unsigned int* pInstanceArray; + size_t nCount, nCapacity; + bool callbackError; +}GNLInstanceList; +static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, cord_value_type_t valueType, void* pUserData) { + static const size_t kDefaultArraySize = 32; + GNLInstanceList *pList = (GNLInstanceList*)pUserData; + + if (!pList) return; + const size_t len = strlen(pParameterName); + if (valueType != CORD_TYPE_OBJECT_PATH || pParameterName[len - 1] != '.') { + pList->callbackError = true; + return; + } + + // Do we need to alloc or grow the array? + if (pList->nCount == pList->nCapacity) { + const size_t nNewCapacity = pList->nCapacity ? pList->nCapacity * 2 : kDefaultArraySize; + unsigned int* pNewInstanceArray = (unsigned int*)realloc(pList->pInstanceArray, sizeof(unsigned int*) * nNewCapacity); + if (!pNewInstanceArray) { + pList->callbackError = true; + return; + } + pList->pInstanceArray = pNewInstanceArray; + pList->nCapacity = nNewCapacity; + } + // To DO Need to check with LUC + //pListItem->pInstanceArray[pList->nCount] = safe_atou(); + safe_atou(pParameterName[len-1], pList->pInstanceArray[pList->nCount]); + pList->nCount++; +}; +#endif /* CORD_ENABLED */ + int PsmGetNextLevelInstances ( void* bus_handle, @@ -3700,9 +3776,41 @@ int PsmGetNextLevelInstances unsigned int** ppInstanceArray ) { - char psmName[256]; + char psmName[512] = ""; errno_t rc = -1; +#ifdef CORD_ENABLED + *ppInstanceArray = NULL; + *pulNumInstance = 0; + if (pSubSystemPrefix && pSubSystemPrefix[0] != 0) { + rc = strcpy_s(psmName, sizeof(psmName), pSubSystemPrefix); + ERR_CHK(rc); + } + rc = strcat_s(psmName, sizeof(psmName), CCSP_DBUS_PSM); + ERR_CHK(rc); + rc = strcat_s(psmName, sizeof(psmName), "."); + ERR_CHK(rc); + rc = strcat_s(psmName, sizeof(psmName), pParentPath); + ERR_CHK(rc); + + GNLInstanceList list = {0}; + cord_rc_t crc = cord_list(psmName, 1, cord_list_callback_GetNextLevelInstances, (void*)&list); + if (crc != CORD_RC_SUCCESS) { + return CCSP_Message_Bus_ERROR; + } + if (list.callbackError) { + if (list.pInstanceArray) { + free(list.pInstanceArray); + } + return CCSP_Message_Bus_OOM; + } + + *ppInstanceArray = list.pInstanceArray; + *pulNumInstance = list.nCount; + + return CCSP_SUCCESS; + +#else /* !CORD_ENABLED */ if ( pSubSystemPrefix && pSubSystemPrefix[0] != 0 ) { rc = sprintf_s(psmName, sizeof(psmName), "%s%s", pSubSystemPrefix, CCSP_DBUS_PSM); @@ -3726,8 +3834,54 @@ int PsmGetNextLevelInstances pulNumInstance, ppInstanceArray ); +#endif /* !CORD_ENABLED */ + +} +#ifdef CORD_ENABLED +typedef struct cord_list_PsmEnumRecords_ListItem { + char *pParameterName; + cord_value_type_t valueType; + struct cord_list_PsmEnumRecords_ListItem *pNext; +}ERListItem; +typedef struct cord_list_PsmEnumRecords_List { + ERListItem *pHead; + size_t nCount; + bool nextLevel; + bool callbackError; +}ERList; + +static void cord_list_callback_PsmEnumRecords(const char* pParameterName, cord_value_type_t valueType, void* pUserData) { + ERList *pList = (ERList*)pUserData; + + if (!pList) return; + if (pList->nextLevel == false && valueType == CORD_TYPE_OBJECT_PATH) return; // PSM behaviour - only object/instance returned if nextLevel==true + + const size_t lenNameWithNull = strlen(pParameterName) + 1; + + // Append new list item + ERListItem *pListItem = malloc(sizeof(ERListItem) + lenNameWithNull); + if (!pListItem) { + pList->callbackError = true; + return; + } + pListItem->pParameterName = (char*)(pListItem + 1); + memcpy(pListItem->pParameterName, pParameterName, lenNameWithNull); + pListItem->valueType = valueType; + pListItem->pNext = pList->pHead; + pList->pHead = pListItem; + pList->nCount++; } +void FreeList(ERList* pList) +{ + if(!pList->pHead) return; + while (pList->pHead) { + ERListItem *pItem = pList->pHead; + pList->pHead = pItem->pNext; + free(pItem); + } +} +#endif /* CORD_ENABLED */ int PsmEnumRecords ( @@ -3739,9 +3893,82 @@ int PsmEnumRecords PCCSP_BASE_RECORD* ppRecArray ) { - char psmName[256]; + char psmName[512] = ""; errno_t rc = -1; +#ifdef CORD_ENABLED + *ppRecArray = NULL; + *pulNumRec = 0; + + if (pSubSystemPrefix && pSubSystemPrefix[0] != 0) { + rc = strcpy_s(psmName, sizeof(psmName), pSubSystemPrefix); + ERR_CHK(rc); + } + rc = strcat_s(psmName, sizeof(psmName), CCSP_DBUS_PSM); + ERR_CHK(rc); + rc = strcat_s(psmName, sizeof(psmName), "."); + ERR_CHK(rc); + rc = strcat_s(psmName, sizeof(psmName), pParentPath); + ERR_CHK(rc); + + ERList list = {0}; + list.nextLevel = nextLevel; + const size_t depth = nextLevel ? 1 : 0; + cord_rc_t crc = cord_list(psmName, depth, cord_list_callback_PsmEnumRecords, (void*)&list); + if (crc != CORD_RC_SUCCESS) { + return CCSP_Message_Bus_ERROR; + } + if (list.callbackError) { + //free linked list + FreeList(&list); + return CCSP_Message_Bus_OOM; + } + + // Alloc output array + PCCSP_BASE_RECORD pRecArray = (PCCSP_BASE_RECORD)calloc(list.nCount, sizeof(CCSP_BASE_RECORD)); + if (!pRecArray) { + //free linked list + FreeList(&list); + return CCSP_Message_Bus_OOM; + } + size_t idxRecArray = 0; + size_t len = 0; + + // Traverse list, transcode to expected format. + while (list.pHead) { + ERListItem *pItem = list.pHead; + + if (pItem->valueType == CORD_TYPE_OBJECT_PATH) { + //last node name is all integer digits + len = strlen(pItem->pParameterName); + if (pItem->pParameterName[len-1] != '.') { + pRecArray[idxRecArray].RecordType = CCSP_BASE_INSTANCE; + //pRecArray[idxRecArray].InstanceNumber = safe_atou(); + safe_atou(pItem->pParameterName[len-1], &(pRecArray[idxRecArray].Instance.InstanceNumber)); + } + else { + pRecArray[idxRecArray].RecordType = CCSP_BASE_OBJECT; + strncpy(pRecArray[idxRecArray].Instance.Name, pItem->pParameterName, CCSP_BASE_PARAM_LENGTH-1); + } + } + else { + strncpy(pRecArray[idxRecArray].Instance.Name, pItem->pParameterName, CCSP_BASE_PARAM_LENGTH-1); + } + + list.pHead = pItem->pNext; // Unlink this list item from list + free(pItem); + idxRecArray++; + } + + *ppRecArray = pRecArray; + *pulNumRec = list.nCount; + + return CCSP_SUCCESS; + + + +#else /* !CORD_ENABLED */ + if ( pSubSystemPrefix && pSubSystemPrefix[0] != 0 ) { rc = sprintf_s(psmName, sizeof(psmName), "%s%s", pSubSystemPrefix, CCSP_DBUS_PSM); @@ -3766,6 +3993,8 @@ int PsmEnumRecords pulNumRec, ppRecArray ); +#endif /* CORD_ENABLED */ + } int PSM_Reset_UserChangeFlag @@ -3775,11 +4004,34 @@ int PSM_Reset_UserChangeFlag char const * const pathName ) { + +#ifdef CORD_ENABLED + static const char kPrefix[] = "UserChanged."; + static const size_t kPrefixLen = sizeof(kPrefix) - 1; + enum { kBufSize = 256 }; + static const size_t kMaxPathLen = kBufSize - kPrefixLen - 1; + + if (!pathName) { + return CCSP_ERR_INVALID_PARAMETER_VALUE; + } + + const size_t path_len = strnlen(pathName, kMaxPathLen + 1); + if (path_len > kMaxPathLen) { + return CCSP_ERR_INVALID_PARAMETER_VALUE; /* or a better “name too long” error */ + } + char record_name[kBufSize] = "UserChanged."; + memcpy(record_name + kPrefixLen, pathName, path_len); + record_name[kPrefixLen + path_len] = '\0'; + +#else /* !CORD_ENABLED */ + char record_name[256]; snprintf(record_name, sizeof(record_name), "UserChanged.%s", pathName); +#endif /* CORD_ENABLED */ return PSM_Del_Record(bus_handle, pSubSystemPrefix, record_name); + } /* The function is called to register event, if the interface name and data path is NULL. Default is register the base interface*/ From 825bb0b910d829a50ba854d17d13a4fe4e91dc0f Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Wed, 8 Apr 2026 12:33:52 +0000 Subject: [PATCH 08/39] Add definition for safe_atou --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 52 ++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index f1b0e3b2a..e61f1e5cb 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3733,6 +3733,53 @@ void PsmFreeRecords(void *bus_handle, parameterValStruct_t **records, int nrec) } #ifdef CORD_ENABLED +/** + * safe_atou - safely extract and convert the last path segment of pParameterName + * to an unsigned int. Skips any trailing dot before locating the segment. + * Returns 0 on success, -1 on NULL input, empty segment, non-numeric chars, or overflow. + */ +static inline int safe_atou(const char *pParameterName, unsigned int *out) +{ + if (!pParameterName || !out) + return -1; + + const size_t len = strlen(pParameterName); + if (len == 0) + return -1; + + /* Find end of last segment, skipping any trailing dot */ + const char *end = pParameterName + len; + if (*(end - 1) == '.') + end--; + + if (end == pParameterName) + return -1; + + /* Find start of last segment */ + const char *start = end; + while (start > pParameterName && *(start - 1) != '.') + start--; + + /* Copy segment into a local buffer for strtoul */ + size_t segLen = (size_t)(end - start); + if (segLen == 0 || segLen >= 32) + return -1; + + char buf[32]; + memcpy(buf, start, segLen); + buf[segLen] = '\0'; + + char *endptr; + unsigned long val; + errno = 0; + val = strtoul(buf, &endptr, 10); + if (errno != 0 || endptr == buf || *endptr != '\0' || val > UINT_MAX) + return -1; + + *out = (unsigned int)val; + return 0; +} + typedef struct cord_list_GetNextLevelInstances_List { unsigned int* pInstanceArray; size_t nCount, nCapacity; @@ -3760,9 +3807,8 @@ static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, pList->pInstanceArray = pNewInstanceArray; pList->nCapacity = nNewCapacity; } - // To DO Need to check with LUC //pListItem->pInstanceArray[pList->nCount] = safe_atou(); - safe_atou(pParameterName[len-1], pList->pInstanceArray[pList->nCount]); + safe_atou(pParameterName, &pList->pInstanceArray[pList->nCount]); pList->nCount++; }; #endif /* CORD_ENABLED */ @@ -3943,7 +3989,7 @@ int PsmEnumRecords if (pItem->pParameterName[len-1] != '.') { pRecArray[idxRecArray].RecordType = CCSP_BASE_INSTANCE; //pRecArray[idxRecArray].InstanceNumber = safe_atou(); - safe_atou(pItem->pParameterName[len-1], &(pRecArray[idxRecArray].Instance.InstanceNumber)); + safe_atou(pItem->pParameterName, &(pRecArray[idxRecArray].Instance.InstanceNumber)); } else { pRecArray[idxRecArray].RecordType = CCSP_BASE_OBJECT; From b3d875bb68be5229ab8a5abf5fb7657c23a1affe Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Sun, 12 Apr 2026 03:01:25 +0000 Subject: [PATCH 09/39] Adding cord open and close --- source/util_api/ccsp_msg_bus/ccsp_message_bus.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/util_api/ccsp_msg_bus/ccsp_message_bus.c b/source/util_api/ccsp_msg_bus/ccsp_message_bus.c index 28e071b0f..dd12e604c 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_message_bus.c +++ b/source/util_api/ccsp_msg_bus/ccsp_message_bus.c @@ -53,6 +53,9 @@ #include #include +#ifdef CORD_ENABLED +#include +#endif #ifdef _DEBUG // #define _DEBUG_LOCAL_ @@ -1115,6 +1118,9 @@ CCSP_Message_Bus_Init } /*CID: 110434 Resource leak*/ fclose(fp); +#ifdef CORD_ENABLED + cord_open(); +#endif return 0; } @@ -1136,6 +1142,9 @@ CCSP_Message_Bus_Exit CcspTraceError(("<%s>: rbus_close fails with %d\n", __FUNCTION__,rc)); bus_info->freefunc(bus_info); bus_info = NULL; +#ifdef CORD_ENABLED + cord_close(); +#endif } static void From 4c8365aae04c145f7d0233a4b6baf317f5fb250b Mon Sep 17 00:00:00 2001 From: Lucien Kennedy-Lamb <59568759+lucienkennedylamb@users.noreply.github.com> Date: Mon, 20 Apr 2026 21:31:05 +0100 Subject: [PATCH 10/39] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index e61f1e5cb..07fc475be 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3799,7 +3799,7 @@ static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, // Do we need to alloc or grow the array? if (pList->nCount == pList->nCapacity) { const size_t nNewCapacity = pList->nCapacity ? pList->nCapacity * 2 : kDefaultArraySize; - unsigned int* pNewInstanceArray = (unsigned int*)realloc(pList->pInstanceArray, sizeof(unsigned int*) * nNewCapacity); + unsigned int* pNewInstanceArray = (unsigned int*)realloc(pList->pInstanceArray, sizeof(*pList->pInstanceArray) * nNewCapacity); if (!pNewInstanceArray) { pList->callbackError = true; return; From 038d7db484ea4d6c48959bd8edc31c198e477a88 Mon Sep 17 00:00:00 2001 From: Srinivas Mamidi Date: Wed, 22 Apr 2026 18:54:03 +0000 Subject: [PATCH 11/39] Implement PSM APIs using CORD --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 41 +++++++++++++++---- .../util_api/ccsp_msg_bus/ccsp_message_bus.c | 4 +- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 07fc475be..0bb640e8c 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3784,12 +3784,14 @@ typedef struct cord_list_GetNextLevelInstances_List { unsigned int* pInstanceArray; size_t nCount, nCapacity; bool callbackError; + void* bus_handle; }GNLInstanceList; static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, cord_value_type_t valueType, void* pUserData) { static const size_t kDefaultArraySize = 32; GNLInstanceList *pList = (GNLInstanceList*)pUserData; - + if (!pList) return; + CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)pList->bus_handle; const size_t len = strlen(pParameterName); if (valueType != CORD_TYPE_OBJECT_PATH || pParameterName[len - 1] != '.') { pList->callbackError = true; @@ -3799,7 +3801,8 @@ static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, // Do we need to alloc or grow the array? if (pList->nCount == pList->nCapacity) { const size_t nNewCapacity = pList->nCapacity ? pList->nCapacity * 2 : kDefaultArraySize; - unsigned int* pNewInstanceArray = (unsigned int*)realloc(pList->pInstanceArray, sizeof(*pList->pInstanceArray) * nNewCapacity); + unsigned int* pNewInstanceArray = bus_info->mallocfunc(sizeof(*pList->pInstanceArray) * nNewCapacity); + if (!pNewInstanceArray) { pList->callbackError = true; return; @@ -3808,8 +3811,12 @@ static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, pList->nCapacity = nNewCapacity; } //pListItem->pInstanceArray[pList->nCount] = safe_atou(); - safe_atou(pParameterName, &pList->pInstanceArray[pList->nCount]); - pList->nCount++; + if(0 == safe_atou(pParameterName, &pList->pInstanceArray[pList->nCount])) + pList->nCount++; + else { + pList->callbackError = true; + return; + } }; #endif /* CORD_ENABLED */ @@ -3828,6 +3835,7 @@ int PsmGetNextLevelInstances *ppInstanceArray = NULL; *pulNumInstance = 0; + CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; if (pSubSystemPrefix && pSubSystemPrefix[0] != 0) { rc = strcpy_s(psmName, sizeof(psmName), pSubSystemPrefix); ERR_CHK(rc); @@ -3840,13 +3848,14 @@ int PsmGetNextLevelInstances ERR_CHK(rc); GNLInstanceList list = {0}; + list.bus_handle = bus_handle; cord_rc_t crc = cord_list(psmName, 1, cord_list_callback_GetNextLevelInstances, (void*)&list); if (crc != CORD_RC_SUCCESS) { return CCSP_Message_Bus_ERROR; } if (list.callbackError) { if (list.pInstanceArray) { - free(list.pInstanceArray); + bus_info->freefunc(list.pInstanceArray); } return CCSP_Message_Bus_OOM; } @@ -3918,7 +3927,7 @@ static void cord_list_callback_PsmEnumRecords(const char* pParameterName, cord_v pList->nCount++; } -void FreeList(ERList* pList) +static void FreeList(ERList* pList) { if(!pList->pHead) return; while (pList->pHead) { @@ -3970,7 +3979,19 @@ int PsmEnumRecords } // Alloc output array - PCCSP_BASE_RECORD pRecArray = (PCCSP_BASE_RECORD)calloc(list.nCount, sizeof(CCSP_BASE_RECORD)); + CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; + PCCSP_BASE_RECORD pRecArray = NULL; + size_t recArraySize = list.nCount * sizeof(CCSP_BASE_RECORD); + if (bus_info && bus_info->mallocfunc) { + pRecArray = (PCCSP_BASE_RECORD)bus_info->mallocfunc(recArraySize); + if (pRecArray) { + memset(pRecArray, 0, recArraySize); + } + } else { + pRecArray = (PCCSP_BASE_RECORD)calloc(list.nCount, sizeof(CCSP_BASE_RECORD)); + } + + if (!pRecArray) { //free linked list FreeList(&list); @@ -3989,15 +4010,19 @@ int PsmEnumRecords if (pItem->pParameterName[len-1] != '.') { pRecArray[idxRecArray].RecordType = CCSP_BASE_INSTANCE; //pRecArray[idxRecArray].InstanceNumber = safe_atou(); - safe_atou(pItem->pParameterName, &(pRecArray[idxRecArray].Instance.InstanceNumber)); + if(0 != safe_atou(pItem->pParameterName, &(pRecArray[idxRecArray].Instance.InstanceNumber))); + CcspTraceError(("%s error while collecting the items\n", __FUNCTION__)); + } else { pRecArray[idxRecArray].RecordType = CCSP_BASE_OBJECT; strncpy(pRecArray[idxRecArray].Instance.Name, pItem->pParameterName, CCSP_BASE_PARAM_LENGTH-1); + pRecArray[idxRecArray].Instance.Name[CCSP_BASE_PARAM_LENGTH-1] = '\0'; } } else { strncpy(pRecArray[idxRecArray].Instance.Name, pItem->pParameterName, CCSP_BASE_PARAM_LENGTH-1); + pRecArray[idxRecArray].Instance.Name[CCSP_BASE_PARAM_LENGTH-1] = '\0'; } list.pHead = pItem->pNext; // Unlink this list item from list diff --git a/source/util_api/ccsp_msg_bus/ccsp_message_bus.c b/source/util_api/ccsp_msg_bus/ccsp_message_bus.c index dd12e604c..66dec2df5 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_message_bus.c +++ b/source/util_api/ccsp_msg_bus/ccsp_message_bus.c @@ -1119,7 +1119,9 @@ CCSP_Message_Bus_Init /*CID: 110434 Resource leak*/ fclose(fp); #ifdef CORD_ENABLED - cord_open(); + if(CORD_RC_SUCCESS != cord_open()) + CcspTraceError(("<%s>: Cord open failed\n", __FUNCTION__)); + #endif return 0; } From 7098b22eddd308160a4cadb7d2d3315f45b939e2 Mon Sep 17 00:00:00 2001 From: Srinivas Mamidi Date: Tue, 28 Apr 2026 18:01:56 +0000 Subject: [PATCH 12/39] Implement PSM APIs using CORD --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 80 ++++++++++++++++++-- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 0bb640e8c..d5c66670a 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3123,6 +3123,58 @@ int PSM_Set_Record_Value #endif /* CORD_ENABLED */ } +#ifdef CORD_ENABLED +static int8_t b64_table[256]; + +static void init_b64_table(void) { + static int initialized = 0; + if (initialized) return; + initialized = 1; + + for (int i = 0; i < 256; i++) b64_table[i] = -1; + for (int i = 'A'; i <= 'Z'; i++) b64_table[i] = i - 'A'; + for (int i = 'a'; i <= 'z'; i++) b64_table[i] = i - 'a' + 26; + for (int i = '0'; i <= '9'; i++) b64_table[i] = i - '0' + 52; + b64_table[(unsigned char)'+'] = 62; + b64_table[(unsigned char)'/'] = 63; +} + +unsigned char *base64_to_binary(const char *in, size_t in_len, size_t *out_len) { + init_b64_table(); + if (!in || !out_len) return NULL; + if (in_len % 4 != 0) return NULL; + + size_t padding = 0; + if (in_len >= 1 && in[in_len - 1] == '=') padding++; + if (in_len >= 2 && in[in_len - 2] == '=') padding++; + + size_t decoded_len = (in_len / 4) * 3 - padding; + unsigned char *out = (unsigned char *)malloc(decoded_len ? decoded_len : 1); + if (!out) return NULL; + + size_t o = 0; + for (size_t i = 0; i < in_len; i += 4) { + int8_t a = b64_table[(unsigned char)in[i]]; + int8_t b = b64_table[(unsigned char)in[i + 1]]; + int8_t c = (in[i + 2] == '=') ? 0 : b64_table[(unsigned char)in[i + 2]]; + int8_t d = (in[i + 3] == '=') ? 0 : b64_table[(unsigned char)in[i + 3]]; + + if (a < 0 || b < 0 || (in[i + 2] != '=' && c < 0) || (in[i + 3] != '=' && d < 0)) { + free(out); + return NULL; + } + + uint32_t triple = ((uint32_t)a << 18) | ((uint32_t)b << 12) | ((uint32_t)c << 6) | (uint32_t)d; + + if (o < decoded_len) out[o++] = (triple >> 16) & 0xFF; + if (o < decoded_len) out[o++] = (triple >> 8) & 0xFF; + if (o < decoded_len) out[o++] = triple & 0xFF; + } + + *out_len = decoded_len; + return out; +} +#endif /* CORD_ENABLED */ int PSM_Get_Record_Value ( @@ -3321,7 +3373,7 @@ int PSM_Set_Record_Value2 UNREFERENCED_PARAMETER(pSubSystemPrefix); #ifdef CORD_ENABLED - UNREFERENCED_PARAMETER(bus_handle); + CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; if (pRecordName == NULL || pVal == NULL) return CCSP_CR_ERR_INVALID_PARAM; @@ -3376,6 +3428,14 @@ int PSM_Set_Record_Value2 break; } case ccsp_float: + { + errno = 0; + float val_f = strtof(pVal, &endptr); + if (errno != 0 || endptr == pVal || *endptr != '\0') + return CCSP_ERR_INVALID_PARAMETER_VALUE; + cord_rc = cord_set_float(pRecordName, val_f, CORD_FLAG_PERSIST_ASYNC); + break; + } case ccsp_double: { errno = 0; @@ -3419,8 +3479,15 @@ int PSM_Set_Record_Value2 break; } case ccsp_base64: - cord_rc = cord_set_string(pRecordName, pVal, CORD_FLAG_PERSIST_ASYNC); + { + size_t outbuf_len = 0;; + unsigned char *outbuf = base64_to_binary(pVal,strlen(pVal),&outbuf_len); + //Free the pVal, The above fn allocates the buffer for the conversion. + bus_info->freefunc((void*)pVal); + cord_rc = cord_set_blob(pRecordName,outbuf, outbuf_len, CORD_FLAG_PERSIST_ASYNC); + //cord_rc = cord_set_string(pRecordName, pVal, CORD_FLAG_PERSIST_ASYNC); break; + } case ccsp_none: return CCSP_CR_ERR_UNSUPPORTED_DATATYPE; default: @@ -3440,6 +3507,7 @@ int PSM_Set_Record_Value2 #else /* !CORD_ENABLED */ + UNREFERENCED_PARAMETER(bus_handle); parameterValStruct_t val[1]; if(ulRecordType == ccsp_boolean) { @@ -3765,15 +3833,11 @@ static inline int safe_atou(const char *pParameterName, unsigned int *out) if (segLen == 0 || segLen >= 32) return -1; - char buf[32]; - memcpy(buf, start, segLen); - buf[segLen] = '\0'; - char *endptr; unsigned long val; errno = 0; - val = strtoul(buf, &endptr, 10); - if (errno != 0 || endptr == buf || *endptr != '\0' || val > UINT_MAX) + val = strtoul(start, &endptr, 10); + if (errno != 0 || endptr == start || *endptr != '\0' || val > UINT_MAX) return -1; *out = (unsigned int)val; From 834fbd2e389e82a8daf0703e16f97380d634d596 Mon Sep 17 00:00:00 2001 From: Srinivas Mamidi Date: Tue, 28 Apr 2026 18:01:56 +0000 Subject: [PATCH 13/39] Implement PSM APIs using CORD --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 75 ++++++++++++++++++-- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 0bb640e8c..af3cc52b0 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3123,6 +3123,58 @@ int PSM_Set_Record_Value #endif /* CORD_ENABLED */ } +#ifdef CORD_ENABLED +static int8_t b64_table[256]; + +static void init_b64_table(void) { + static int initialized = 0; + if (initialized) return; + initialized = 1; + + for (int i = 0; i < 256; i++) b64_table[i] = -1; + for (int i = 'A'; i <= 'Z'; i++) b64_table[i] = i - 'A'; + for (int i = 'a'; i <= 'z'; i++) b64_table[i] = i - 'a' + 26; + for (int i = '0'; i <= '9'; i++) b64_table[i] = i - '0' + 52; + b64_table[(unsigned char)'+'] = 62; + b64_table[(unsigned char)'/'] = 63; +} + +unsigned char *base64_to_binary(const char *in, size_t in_len, size_t *out_len) { + init_b64_table(); + if (!in || !out_len) return NULL; + if (in_len % 4 != 0) return NULL; + + size_t padding = 0; + if (in_len >= 1 && in[in_len - 1] == '=') padding++; + if (in_len >= 2 && in[in_len - 2] == '=') padding++; + + size_t decoded_len = (in_len / 4) * 3 - padding; + unsigned char *out = (unsigned char *)malloc(decoded_len ? decoded_len : 1); + if (!out) return NULL; + + size_t o = 0; + for (size_t i = 0; i < in_len; i += 4) { + int8_t a = b64_table[(unsigned char)in[i]]; + int8_t b = b64_table[(unsigned char)in[i + 1]]; + int8_t c = (in[i + 2] == '=') ? 0 : b64_table[(unsigned char)in[i + 2]]; + int8_t d = (in[i + 3] == '=') ? 0 : b64_table[(unsigned char)in[i + 3]]; + + if (a < 0 || b < 0 || (in[i + 2] != '=' && c < 0) || (in[i + 3] != '=' && d < 0)) { + free(out); + return NULL; + } + + uint32_t triple = ((uint32_t)a << 18) | ((uint32_t)b << 12) | ((uint32_t)c << 6) | (uint32_t)d; + + if (o < decoded_len) out[o++] = (triple >> 16) & 0xFF; + if (o < decoded_len) out[o++] = (triple >> 8) & 0xFF; + if (o < decoded_len) out[o++] = triple & 0xFF; + } + + *out_len = decoded_len; + return out; +} +#endif /* CORD_ENABLED */ int PSM_Get_Record_Value ( @@ -3376,6 +3428,14 @@ int PSM_Set_Record_Value2 break; } case ccsp_float: + { + errno = 0; + float val_f = strtof(pVal, &endptr); + if (errno != 0 || endptr == pVal || *endptr != '\0') + return CCSP_ERR_INVALID_PARAMETER_VALUE; + cord_rc = cord_set_float(pRecordName, val_f, CORD_FLAG_PERSIST_ASYNC); + break; + } case ccsp_double: { errno = 0; @@ -3419,8 +3479,15 @@ int PSM_Set_Record_Value2 break; } case ccsp_base64: - cord_rc = cord_set_string(pRecordName, pVal, CORD_FLAG_PERSIST_ASYNC); + { + size_t outbuf_len = 0;; + unsigned char *outbuf = base64_to_binary(pVal,strlen(pVal),&outbuf_len); + //Free the pVal, The above fn allocates the buffer for the conversion. + bus_info->freefunc((void*)pVal); + cord_rc = cord_set_blob(pRecordName,outbuf, outbuf_len, CORD_FLAG_PERSIST_ASYNC); + //cord_rc = cord_set_string(pRecordName, pVal, CORD_FLAG_PERSIST_ASYNC); break; + } case ccsp_none: return CCSP_CR_ERR_UNSUPPORTED_DATATYPE; default: @@ -3765,14 +3832,10 @@ static inline int safe_atou(const char *pParameterName, unsigned int *out) if (segLen == 0 || segLen >= 32) return -1; - char buf[32]; - memcpy(buf, start, segLen); - buf[segLen] = '\0'; - char *endptr; unsigned long val; errno = 0; - val = strtoul(buf, &endptr, 10); + val = strtoul(start, &endptr, 10); if (errno != 0 || endptr == buf || *endptr != '\0' || val > UINT_MAX) return -1; From 5afe9ca702b623e4bfcdd1a1a092b6f858428b28 Mon Sep 17 00:00:00 2001 From: Srinivas Mamidi Date: Wed, 29 Apr 2026 21:05:47 +0000 Subject: [PATCH 14/39] Implement PSM APIs using CORD --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 85 ++++++++++++-------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 137d9455a..a43772e95 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3124,53 +3124,65 @@ int PSM_Set_Record_Value #endif /* CORD_ENABLED */ } #ifdef CORD_ENABLED -static int8_t b64_table[256]; - -static void init_b64_table(void) { - static int initialized = 0; - if (initialized) return; - initialized = 1; - - for (int i = 0; i < 256; i++) b64_table[i] = -1; - for (int i = 'A'; i <= 'Z'; i++) b64_table[i] = i - 'A'; - for (int i = 'a'; i <= 'z'; i++) b64_table[i] = i - 'a' + 26; - for (int i = '0'; i <= '9'; i++) b64_table[i] = i - '0' + 52; - b64_table[(unsigned char)'+'] = 62; - b64_table[(unsigned char)'/'] = 63; -} +static const int8_t B64_DEC[256] = { + /* 0x00-0x0F */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /* 0x10-0x1F */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + /* 0x20-0x2F */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, + /* 0x30-0x3F */ 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, + /* 0x40-0x4F */ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, + /* 0x50-0x5F */ 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, + /* 0x60-0x6F */ -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, + /* 0x70-0x7F */ 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, + /* 0x80-0xFF */ + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +}; unsigned char *base64_to_binary(const char *in, size_t in_len, size_t *out_len) { - init_b64_table(); if (!in || !out_len) return NULL; - if (in_len % 4 != 0) return NULL; - + if ((in_len % 4) != 0) return NULL; + size_t padding = 0; if (in_len >= 1 && in[in_len - 1] == '=') padding++; if (in_len >= 2 && in[in_len - 2] == '=') padding++; - + size_t decoded_len = (in_len / 4) * 3 - padding; unsigned char *out = (unsigned char *)malloc(decoded_len ? decoded_len : 1); if (!out) return NULL; - + size_t o = 0; for (size_t i = 0; i < in_len; i += 4) { - int8_t a = b64_table[(unsigned char)in[i]]; - int8_t b = b64_table[(unsigned char)in[i + 1]]; - int8_t c = (in[i + 2] == '=') ? 0 : b64_table[(unsigned char)in[i + 2]]; - int8_t d = (in[i + 3] == '=') ? 0 : b64_table[(unsigned char)in[i + 3]]; - - if (a < 0 || b < 0 || (in[i + 2] != '=' && c < 0) || (in[i + 3] != '=' && d < 0)) { + unsigned char c0 = (unsigned char)in[i]; + unsigned char c1 = (unsigned char)in[i + 1]; + unsigned char c2 = (unsigned char)in[i + 2]; + unsigned char c3 = (unsigned char)in[i + 3]; + + int8_t a = B64_DEC[c0]; + int8_t b = B64_DEC[c1]; + int8_t c = (c2 == '=') ? 0 : B64_DEC[c2]; + int8_t d = (c3 == '=') ? 0 : B64_DEC[c3]; + + if (a < 0 || b < 0 || (c2 != '=' && c < 0) || (c3 != '=' && d < 0)) { free(out); return NULL; } - - uint32_t triple = ((uint32_t)a << 18) | ((uint32_t)b << 12) | ((uint32_t)c << 6) | (uint32_t)d; - - if (o < decoded_len) out[o++] = (triple >> 16) & 0xFF; - if (o < decoded_len) out[o++] = (triple >> 8) & 0xFF; - if (o < decoded_len) out[o++] = triple & 0xFF; + + uint32_t triple = ((uint32_t)a << 18) | + ((uint32_t)b << 12) | + ((uint32_t)c << 6) | + (uint32_t)d; + + if (o < decoded_len) out[o++] = (unsigned char)((triple >> 16) & 0xFF); + if (o < decoded_len) out[o++] = (unsigned char)((triple >> 8) & 0xFF); + if (o < decoded_len) out[o++] = (unsigned char)(triple & 0xFF); } - + *out_len = decoded_len; return out; } @@ -3465,7 +3477,7 @@ int PSM_Set_Record_Value2 tm_val.tm_isdst = -1; time_val = mktime(&tm_val); if (time_val == (time_t)-1) - return CCSP_ERR_INVALID_PARAMETER_VALUE; + return CCSP_ERR_INVALID_PARAMETER_VALUE; } else { @@ -3482,9 +3494,11 @@ int PSM_Set_Record_Value2 { size_t outbuf_len = 0;; unsigned char *outbuf = base64_to_binary(pVal,strlen(pVal),&outbuf_len); - //Free the pVal, The above fn allocates the buffer for the conversion. - bus_info->freefunc((void*)pVal); + if (outbuf == NULL) + return CCSP_ERR_INVALID_PARAMETER_VALUE; cord_rc = cord_set_blob(pRecordName,outbuf, outbuf_len, CORD_FLAG_PERSIST_ASYNC); + //Free the outbuf which is allocated in base64_to_binary fn for the conversion purpose. + free(outbuf); //cord_rc = cord_set_string(pRecordName, pVal, CORD_FLAG_PERSIST_ASYNC); break; } @@ -4086,6 +4100,7 @@ int PsmEnumRecords } } else { + pRecArray[idxRecArray].RecordType = CCSP_BASE_PARAM; strncpy(pRecArray[idxRecArray].Instance.Name, pItem->pParameterName, CCSP_BASE_PARAM_LENGTH-1); pRecArray[idxRecArray].Instance.Name[CCSP_BASE_PARAM_LENGTH-1] = '\0'; } From fa309a59ef891c51c9075611d4eb5d67259d5e99 Mon Sep 17 00:00:00 2001 From: Srinivas Mamidi Date: Tue, 5 May 2026 21:32:03 +0000 Subject: [PATCH 15/39] Implement PsmGroupGet Api --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 137 ++++++++++++++++++- 1 file changed, 135 insertions(+), 2 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index a43772e95..8df5fc08c 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3794,7 +3794,6 @@ int PSM_Del_Record #endif /* CORD_ENABLED */ } - int PsmGroupGet(void *bus_handle, const char *subsys, const char *names[], int nname, parameterValStruct_t ***records, int *nrec) { @@ -3802,13 +3801,147 @@ int PsmGroupGet(void *bus_handle, const char *subsys, if (!bus_handle || !names || !records || !nrec) return CCSP_FAILURE; +#ifdef CORD_ENABLED +//cord_rc_t cord_get_multi(const char* pParameterNames[], size_t nParameterNames, size_t depth, cord_parameter_t** ppParameters, size_t *pnParameters); + cord_parameter_t* params = NULL; + size_t count = 0; + parameterValStruct_t **val = 0; + *nrec = 0; + cord_value_type_t valueType; + + cord_rc_t cord_rc = cord_get_multi((const char **)names, nname, 0, ¶ms,&count); + switch (cord_rc) { + case CORD_RC_SUCCESS: break; + case CORD_RC_NOT_OPEN: return CCSP_Message_Bus_ERROR; + case CORD_RC_INVALID_NAME: return CCSP_ERR_NOT_EXIST; + case CORD_RC_PERMISSION_DENIED: return CCSP_ERR_REQUEST_REJECTED; + case CORD_RC_OUT_OF_MEMORY: return CCSP_ERR_MEMORY_ALLOC_FAIL; + default: return CCSP_Message_Bus_ERROR; + } + + char buf[64]; + int ret = CCSP_SUCCESS; + int i = 0; + size_t len; + CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; + if (bus_info == NULL) { cord_free_parameters(params); return CCSP_Message_Bus_ERROR; } + if(count) + { + *nrec = count; + val = bus_info->mallocfunc(count*sizeof(parameterValStruct_t *)); + if (val == NULL) { cord_free_parameters(params); return CCSP_ERR_MEMORY_ALLOC_FAIL; } + memset(val, 0, count*sizeof(parameterValStruct_t *)); + for (i = 0; i < count; i++) + { + val[i] = bus_info->mallocfunc(sizeof(parameterValStruct_t)); + if(NULL == val[i]){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} + memset(val[i], 0, sizeof(parameterValStruct_t)); + /*Get Name */ + const char* pname = params[i].pName; + if(NULL == pname){ret = CCSP_Message_Bus_ERROR;break;} + len = strlen(pname); + val[i]->parameterName = bus_info->mallocfunc(len + 1); + if(NULL == val[i]->parameterName){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} + memcpy(val[i]->parameterName, params[i].pName, len + 1); + /*Get Type*/ + valueType = params[i].value.valueType; + switch (valueType) + { + case CORD_TYPE_I32: + val[i]->type = ccsp_int; + snprintf(buf, sizeof(buf), "%d", (int)params[i].value.i32Value); + val[i]->parameterValue = bus_info->mallocfunc(strlen(buf) + 1); + if(NULL == val[i]->parameterValue ){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} + memcpy(val[i]->parameterValue, buf,strlen(buf) + 1); + break; + case CORD_TYPE_U32: + val[i]->type = ccsp_unsignedInt; + snprintf(buf, sizeof(buf), "%u", (unsigned int)params[i].value.u32Value); + val[i]->parameterValue = bus_info->mallocfunc(strlen(buf) + 1); + if(NULL == val[i]->parameterValue ){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} + memcpy(val[i]->parameterValue, buf,strlen(buf) + 1); + break; + case CORD_TYPE_BOOL: + val[i]->type = ccsp_boolean; + const char *bstr = params[i].value.boolValue ? true : false; + val[i]->parameterValue = bus_info->mallocfunc(strlen(bstr) + 1); + if(NULL == val[i]->parameterValue ){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} + memcpy(val[i]->parameterValue, buf,strlen(buf) + 1); + break; + + case CORD_TYPE_STRING: + val[i]->type = ccsp_string; + val[i]->parameterValue = bus_info->mallocfunc(strlen(params[i].value.stringValue) + 1); + if(NULL == val[i]->parameterValue ){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} + memcpy(val[i]->parameterValue, params[i].value.stringValue,strlen(params[i].value.stringValue) + 1); + break; + case CORD_TYPE_I64: + val[i]->type = ccsp_long; + snprintf(buf, sizeof(buf), "%" PRId64, (int64_t)params[i].value.i64Value); + val[i]->parameterValue = bus_info->mallocfunc(strlen(buf) + 1); + if(NULL == val[i]->parameterValue ){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} + memcpy(val[i]->parameterValue, buf,strlen(buf) + 1); + break; + case CORD_TYPE_U64: + val[i]->type = ccsp_unsignedLong; + snprintf(buf, sizeof(buf), "%" PRIu64, (uint64_t)params[i].value.u64Value); + val[i]->parameterValue = bus_info->mallocfunc(strlen(buf) + 1); + if(NULL == val[i]->parameterValue ){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} + memcpy(val[i]->parameterValue, buf,strlen(buf) + 1); + break; + case CORD_TYPE_DOUBLE: + val[i]->type = ccsp_double; + snprintf(buf, sizeof(buf), "%.17g", params[i].value.doubleValue); + val[i]->parameterValue = bus_info->mallocfunc(strlen(buf) + 1); + if(NULL == val[i]->parameterValue ){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} + memcpy(val[i]->parameterValue, buf,strlen(buf) + 1); + break; + case CORD_TYPE_DATETIME: + val[i]->type = ccsp_dateTime; + snprintf(buf, sizeof(buf), "%ld", (long)params[i].value.dateTimeValue); + val[i]->parameterValue = bus_info->mallocfunc(strlen(buf) + 1); + if(NULL == val[i]->parameterValue ){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} + memcpy(val[i]->parameterValue, buf,strlen(buf) + 1); + break; + default: + ret = CCSP_CR_ERR_UNSUPPORTED_DATATYPE; + break; + } + if(ret != CCSP_SUCCESS) break; + } + *records = val; + if(ret != CCSP_SUCCESS) + { + if(val) + { + for(int j = 0; j <= i; j++) { + if(val[j]) { + if(val[j]->parameterName) + bus_info->freefunc(val[j]->parameterName); + if(val[j]->parameterValue) + bus_info->freefunc(val[j]->parameterValue); + bus_info->freefunc(val[j]); + } + } + bus_info->freefunc(val); + val = NULL; + } + } + + } + cord_free_parameters(params); + return ret; + +#else /* !CORD_ENABLED */ + snprintf(psmName, sizeof(psmName), "%s%s", (subsys ? subsys : ""), CCSP_DBUS_PSM); return CcspBaseIf_getParameterValues(bus_handle, psmName, CCSP_DBUS_PATH_PSM, (char **)names, nname, nrec, records); -} +#endif /* CORD_ENABLED */ +} void PsmFreeRecords(void *bus_handle, parameterValStruct_t **records, int nrec) { free_parameterValStruct_t(bus_handle, nrec, records); From c53aa1ada125ab411320bf0f2e0462307c430593 Mon Sep 17 00:00:00 2001 From: smamidi2011 Date: Fri, 8 May 2026 14:40:47 -0700 Subject: [PATCH 16/39] Update ccsp_base_api.c --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 8df5fc08c..a56578c91 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3807,6 +3807,7 @@ int PsmGroupGet(void *bus_handle, const char *subsys, size_t count = 0; parameterValStruct_t **val = 0; *nrec = 0; + *records = NULL; cord_value_type_t valueType; cord_rc_t cord_rc = cord_get_multi((const char **)names, nname, 0, ¶ms,&count); @@ -3863,10 +3864,10 @@ int PsmGroupGet(void *bus_handle, const char *subsys, break; case CORD_TYPE_BOOL: val[i]->type = ccsp_boolean; - const char *bstr = params[i].value.boolValue ? true : false; + const char *bstr = params[i].value.boolValue ? "true" : "false"; val[i]->parameterValue = bus_info->mallocfunc(strlen(bstr) + 1); if(NULL == val[i]->parameterValue ){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} - memcpy(val[i]->parameterValue, buf,strlen(buf) + 1); + memcpy(val[i]->parameterValue, bstr,strlen(bstr) + 1); break; case CORD_TYPE_STRING: @@ -3926,8 +3927,9 @@ int PsmGroupGet(void *bus_handle, const char *subsys, bus_info->freefunc(val); val = NULL; } + *records = NULL; + *nrec = 0; } - } cord_free_parameters(params); return ret; From 739c056749fce2fd78d3446195208e906c65ae1f Mon Sep 17 00:00:00 2001 From: smamidi2011 Date: Thu, 21 May 2026 10:00:59 -0700 Subject: [PATCH 17/39] Update ccsp_base_api.c checking nname for valid value(nname > 0) --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index a56578c91..8849a506e 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3809,7 +3809,7 @@ int PsmGroupGet(void *bus_handle, const char *subsys, *nrec = 0; *records = NULL; cord_value_type_t valueType; - + if(0 == nname) return CCSP_FAILURE; cord_rc_t cord_rc = cord_get_multi((const char **)names, nname, 0, ¶ms,&count); switch (cord_rc) { case CORD_RC_SUCCESS: break; From 75c3e55e7d21166bc1c9dc9168d28f23a598b0ff Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Wed, 10 Jun 2026 11:11:06 +0000 Subject: [PATCH 18/39] updating Psm service to run after cord daemon is up --- systemd_units/PsmSsp.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemd_units/PsmSsp.service b/systemd_units/PsmSsp.service index 1ac082833..d95fec1a7 100644 --- a/systemd_units/PsmSsp.service +++ b/systemd_units/PsmSsp.service @@ -19,7 +19,7 @@ [Unit] Description=PsmSsp service -After=CcspCrSsp.service +After=CcspCrSsp.service cordd.service [Service] Type=forking From 79046c1f161a46e363aa780d42e79bcc898fc8b6 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Mon, 15 Jun 2026 10:27:23 +0000 Subject: [PATCH 19/39] fix(psm): handle root PsmEnumRecords path for dumpall output --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 8849a506e..195a0fcae 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -4056,10 +4056,12 @@ int PsmGetNextLevelInstances } rc = strcat_s(psmName, sizeof(psmName), CCSP_DBUS_PSM); ERR_CHK(rc); - rc = strcat_s(psmName, sizeof(psmName), "."); - ERR_CHK(rc); - rc = strcat_s(psmName, sizeof(psmName), pParentPath); - ERR_CHK(rc); + if (pParentPath && pParentPath[0] != '\0') { + rc = strcat_s(psmName, sizeof(psmName), "."); + ERR_CHK(rc); + rc = strcat_s(psmName, sizeof(psmName), pParentPath); + ERR_CHK(rc); + } GNLInstanceList list = {0}; list.bus_handle = bus_handle; @@ -4174,10 +4176,12 @@ int PsmEnumRecords } rc = strcat_s(psmName, sizeof(psmName), CCSP_DBUS_PSM); ERR_CHK(rc); - rc = strcat_s(psmName, sizeof(psmName), "."); - ERR_CHK(rc); - rc = strcat_s(psmName, sizeof(psmName), pParentPath); - ERR_CHK(rc); + if (pParentPath && pParentPath[0] != '\0') { + rc = strcat_s(psmName, sizeof(psmName), "."); + ERR_CHK(rc); + rc = strcat_s(psmName, sizeof(psmName), pParentPath); + ERR_CHK(rc); + } ERList list = {0}; list.nextLevel = nextLevel; From 764881ca1995333874f9c2a8ca9a89b406844137 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Mon, 15 Jun 2026 20:45:50 +0000 Subject: [PATCH 20/39] fix(cord): report PSM health as Green via psm_initialized sentinel In CORD builds, PSM does not initialize rbus/dbus, so it never registers a GetHealth() rbus method handler. Components that poll PSM health (PAM, WEBPA) receive CCSP_ERR_ENTRY_NOT_FOUND (204) on every attempt, causing them to burn their full retry timeouts before proceeding: - PAM: 10 retries x 2s = 20s delay before LAN init (Lan_init_start regressed from ~30s to ~91s) - WEBPA: unbounded retry loop, WEBPA_READY delayed by ~400s+ Fix CcspBaseIf_getHealth_rbus() to check /tmp/psm_initialized when the rbus call fails for a PSM component. PSM already creates this sentinel file after cord_open() + Engage() complete. If the file exists, return health=Green and CCSP_SUCCESS so the caller proceeds immediately without any retry delay. The check is guarded by #ifdef CORD_ENABLED so it has no effect on non-CORD builds. --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 195a0fcae..afcbcdc7f 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -2283,6 +2283,21 @@ int CcspBaseIf_getHealth_rbus( else ret = Rbus2_to_CCSP_error_mapper(ret_val); CcspTraceError(("%s: %s error: %d\n", __FUNCTION__, methodName, ret)); + +#ifdef CORD_ENABLED + /* In CORD builds PSM has no rbus bus interface so GetHealth() always + * returns CCSP_ERR_ENTRY_NOT_FOUND (204). Use /tmp/psm_initialized + * (written by PSM after cord_open + Engage complete) as the readiness + * signal. This avoids every caller (PAM, WEBPA, ...) burning their + * full retry timeout waiting for a handler that will never exist. */ + if(strstr(dst_component_id, "psm") && access("/tmp/psm_initialized", F_OK) == 0) + { + CcspTraceInfo(("%s: %s not reachable via rbus but psm_initialized sentinel found, reporting Green\n", + __FUNCTION__, dst_component_id)); + *health = 3; /* CCSP_COMMON_COMPONENT_HEALTH_Green */ + ret = CCSP_SUCCESS; + } +#endif /* CORD_ENABLED */ } if(outParams) rbusObject_Release(outParams); From a171392bd3d9dfae31d74b69955f36851364d518 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Mon, 15 Jun 2026 21:00:15 +0000 Subject: [PATCH 21/39] cord_list() takes a data namespace path (e.g. "dmsb.", ""), not a rbus component ID. No stored keys have the prefix eRT.com.cisco.spvtg.ccsp.psm, so cord_list either returned an error or an empty result. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix: Pass pParentPath directly to cord_list() — empty string ("") for a full dump (lists everything), or the caller-supplied subtree path for a scoped enumeration. The pSubSystemPrefix + CCSP_DBUS_PSM component-ID construction is a rbus routing concept that has no meaning in the CORD data model. --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index afcbcdc7f..756634092 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -4185,16 +4185,12 @@ int PsmEnumRecords *ppRecArray = NULL; *pulNumRec = 0; - if (pSubSystemPrefix && pSubSystemPrefix[0] != 0) { - rc = strcpy_s(psmName, sizeof(psmName), pSubSystemPrefix); - ERR_CHK(rc); - } - rc = strcat_s(psmName, sizeof(psmName), CCSP_DBUS_PSM); - ERR_CHK(rc); + /* cord_list() operates on the PSM data namespace (e.g. "dmsb."), + * NOT on the rbus component ID ("eRT.com.cisco.spvtg.ccsp.psm"). + * Pass pParentPath directly: empty string lists everything, a + * non-empty path scopes the enumeration to that subtree. */ if (pParentPath && pParentPath[0] != '\0') { - rc = strcat_s(psmName, sizeof(psmName), "."); - ERR_CHK(rc); - rc = strcat_s(psmName, sizeof(psmName), pParentPath); + rc = strcpy_s(psmName, sizeof(psmName), pParentPath); ERR_CHK(rc); } From c09fc4bb13c27186fad783e2b9c0e9bfd859ba37 Mon Sep 17 00:00:00 2001 From: smamidi2011 Date: Thu, 18 Jun 2026 11:43:56 -0700 Subject: [PATCH 22/39] Update ccsp_base_api.c added the logic in CcspBaseIf_getParameterValues to support the psm health with out rbus dependency --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 756634092..cb86d9bf4 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -602,6 +602,37 @@ int CcspBaseIf_getParameterValues_rbus( /*Get call for PSM parameters*/ if(dst_component_id && strstr(dst_component_id, ".psm")) { +#ifdef CORD_ENABLED + /* In CORD builds PSM has no rbus bus interface so GetHealth() always + * returns CCSP_ERR_ENTRY_NOT_FOUND (204). Use /tmp/psm_initialized + * (written by PSM after cord_open + Engage complete) as the readiness + * signal. This avoids every caller (PAM, WEBPA, ...) burning their + * full retry timeout waiting for a handler that will never exist. */ + if (1 == param_size){ + if(strstr(parameterNames[0], "Health") && access("/tmp/psm_initialized", F_OK) == 0) + { + CcspTraceInfo(("%s: %s not reachable via rbus but psm_initialized sentinel found, reporting Green\n", + __FUNCTION__, dst_component_id)); + size = 1; + *val_size = size; + val = bus_info->mallocfunc(size*sizeof(parameterValStruct_t *)); + memset(val, 0, size*sizeof(parameterValStruct_t *)); + for (i = 0; i < size; i++) + { + val[i] = bus_info->mallocfunc(sizeof(parameterValStruct_t)); + memset(val[i], 0, sizeof(parameterValStruct_t)); + /*Get Name */ + val[i]->parameterName = bus_info->mallocfunc(strlen(parameterNames[0])+1); + strcpy(val[i]->parameterName,parameterNames[0]); + val[i]->type = ccsp_string; + val[i]->parameterValue = bus_info->mallocfunc(strlen("Green")+1); + strcpy(val[i]->parameterValue, "Green"); + } + ret = CCSP_SUCCESS; + } + } + +#else ret = PSM_Get_Record_Value_rbus(bus_handle, parameterNames, param_size, &size, &val); if(ret == CCSP_SUCCESS) { @@ -609,6 +640,8 @@ int CcspBaseIf_getParameterValues_rbus( for(i = 0; i < size; i++) RBUS_LOG(" PSM Param [%d] Name = %s, Type = %d, Value = %s\n", i,val[i]->parameterName, val[i]->type, val[i]->parameterValue); } +#endif /* CORD_ENABLED */ + } else { From 71f3ee8ded1b1f63cd566b4936d4802031d371fd Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Tue, 14 Jul 2026 10:34:59 +0000 Subject: [PATCH 23/39] feat(psm): add call-count tracing to PSM CORD APIs Add a lightweight, flag-gated call counter to the 9 PSM APIs (PSM_Set/Get_Record_Value, PSM_Set/Get_Record_Value2, PSM_Del_Record, PsmGroupGet, PsmGetNextLevelInstances, PsmEnumRecords, PSM_Reset_UserChangeFlag) in ccsp_base_api.c. How it works: - Counting is activated only when /nvram/psm_cord_trace exists; zero overhead otherwise (flag re-checked at most once per second). - Each API maintains a per-call-site static counter incremented atomically via __sync_add_and_fetch. - The current cumulative count is written to /tmp/psm_cord_ on every call; a single pthread_mutex guards concurrent file writes. - Counts fire on both CORD_ENABLED and non-CORD code paths, making it easy to compare call rates between build variants. Usage: touch /nvram/psm_cord_trace # enable cat /tmp/psm_cord_PSM_Get_Record_Value2 rm /nvram/psm_cord_trace # disable (takes effect within ~1s) Signed-off-by: madhukrishnasmenon-comcast --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index cb86d9bf4..be2ef601e 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -50,6 +50,8 @@ #include #include #include +#include +#include #ifdef CORD_ENABLED #include #endif @@ -85,6 +87,52 @@ int CcspBaseIf_timeout_getval_seconds = 120; //seconds #define CcspBaseIf_timeout_rbus (CcspBaseIf_timeout_seconds * 1000) // in milliseconds #define CcspBaseIf_timeout_getval_rbus (CcspBaseIf_timeout_getval_seconds * 1000) // in milliseconds +/* --- PSM API call counter ----------------------------------------------- + * Activated only when /nvram/psm_cord_trace exists. + * Counts calls to both CORD_ENABLED and non-CORD PSM API paths. + * Writes the cumulative count to /tmp/psm_cord_. + * Thread-safe: GCC atomic counter + mutex-protected file write. + * ---------------------------------------------------------------------- */ +static pthread_mutex_t g_psm_trace_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void psm_cord_trace_inc(const char *api_name, int *p_count) +{ + static int s_enabled = -1; /* -1=unknown, 0=disabled, 1=enabled */ + static time_t s_last_check = 0; + + time_t now = time(NULL); + if (s_enabled == -1 || (now - s_last_check) >= 1) + { + s_enabled = (access("/nvram/psm_cord_trace", F_OK) == 0) ? 1 : 0; + s_last_check = now; + } + + if (!s_enabled) + return; + + int count = __sync_add_and_fetch(p_count, 1); + + char path[128]; + snprintf(path, sizeof(path), "/tmp/psm_cord_%s", api_name); + + pthread_mutex_lock(&g_psm_trace_mutex); + int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd >= 0) + { + char buf[32]; + int len = snprintf(buf, sizeof(buf), "%d\n", count); + write(fd, buf, (size_t)len); + close(fd); + } + pthread_mutex_unlock(&g_psm_trace_mutex); +} + +#define PSM_CORD_COUNT() \ + do { \ + static int s_count = 0; \ + psm_cord_trace_inc(__func__, &s_count); \ + } while (0) + int CcspBaseIf_freeResources( void* bus_handle, const char* dst_component_id, @@ -3036,6 +3084,7 @@ int PSM_Set_Record_Value PSLAP_VARIABLE pValue ) { + PSM_CORD_COUNT(); UNREFERENCED_PARAMETER(ulRecordType); UNREFERENCED_PARAMETER(pSubSystemPrefix); @@ -3245,6 +3294,7 @@ int PSM_Get_Record_Value PSLAP_VARIABLE pValue ) { + PSM_CORD_COUNT(); UNREFERENCED_PARAMETER(pSubSystemPrefix); CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; @@ -3430,6 +3480,7 @@ int PSM_Set_Record_Value2 char const * const pVal ) { + PSM_CORD_COUNT(); UNREFERENCED_PARAMETER(pSubSystemPrefix); #ifdef CORD_ENABLED @@ -3595,6 +3646,7 @@ int PSM_Get_Record_Value2 char** pValue ) { + PSM_CORD_COUNT(); UNREFERENCED_PARAMETER(pSubSystemPrefix); *pValue = NULL; @@ -3726,6 +3778,7 @@ int PSM_Del_Record char const * const pRecordName ) { + PSM_CORD_COUNT(); #ifdef CORD_ENABLED char psmName[512] = ""; errno_t rc = -1; @@ -3845,6 +3898,7 @@ int PSM_Del_Record int PsmGroupGet(void *bus_handle, const char *subsys, const char *names[], int nname, parameterValStruct_t ***records, int *nrec) { + PSM_CORD_COUNT(); char psmName[256]; if (!bus_handle || !names || !records || !nrec) @@ -4091,6 +4145,7 @@ int PsmGetNextLevelInstances unsigned int** ppInstanceArray ) { + PSM_CORD_COUNT(); char psmName[512] = ""; errno_t rc = -1; #ifdef CORD_ENABLED @@ -4212,6 +4267,7 @@ int PsmEnumRecords PCCSP_BASE_RECORD* ppRecArray ) { + PSM_CORD_COUNT(); char psmName[512] = ""; errno_t rc = -1; #ifdef CORD_ENABLED @@ -4338,6 +4394,7 @@ int PSM_Reset_UserChangeFlag char const * const pathName ) { + PSM_CORD_COUNT(); #ifdef CORD_ENABLED static const char kPrefix[] = "UserChanged."; From a9c7877da3d1b608df28faed382734b38b603712 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Thu, 30 Jul 2026 22:55:13 +0000 Subject: [PATCH 24/39] feat(psm): add ns-resolution timing to PSM API call tracer Extends the existing PSM_CORD_COUNT() mechanism to also record per-call timing using clock_gettime(CLOCK_MONOTONIC). Uses GCC __attribute__((cleanup)) so the end-timestamp is captured on every return path without touching any existing call site. Each trace file (/tmp/psm_cord_) now contains: count=N last_ns=L total_ns=T avg_ns=A min_ns=m max_ns=M No change to the 9 PSM_CORD_COUNT() call sites. Gated by /nvram/psm_cord_trace. --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 76 ++++++++++++++++---- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index be2ef601e..ec32ae5dd 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -87,50 +87,96 @@ int CcspBaseIf_timeout_getval_seconds = 120; //seconds #define CcspBaseIf_timeout_rbus (CcspBaseIf_timeout_seconds * 1000) // in milliseconds #define CcspBaseIf_timeout_getval_rbus (CcspBaseIf_timeout_getval_seconds * 1000) // in milliseconds -/* --- PSM API call counter ----------------------------------------------- +/* --- PSM API call counter + timing -------------------------------------- * Activated only when /nvram/psm_cord_trace exists. - * Counts calls to both CORD_ENABLED and non-CORD PSM API paths. - * Writes the cumulative count to /tmp/psm_cord_. - * Thread-safe: GCC atomic counter + mutex-protected file write. + * Counts calls and records ns-resolution timing for both CORD and non-CORD + * PSM API paths. Writes to /tmp/psm_cord_. + * Thread-safe: GCC atomic counters + mutex-protected file write. * ---------------------------------------------------------------------- */ static pthread_mutex_t g_psm_trace_mutex = PTHREAD_MUTEX_INITIALIZER; -static void psm_cord_trace_inc(const char *api_name, int *p_count) +typedef struct { + const char *api_name; + int *p_count; + long long *p_total_ns; + long long *p_min_ns; + long long *p_max_ns; + struct timespec t_start; + int enabled; +} psm_trace_ctx_t; + +static int psm_cord_trace_is_enabled(void) { - static int s_enabled = -1; /* -1=unknown, 0=disabled, 1=enabled */ + static int s_enabled = -1; static time_t s_last_check = 0; - time_t now = time(NULL); if (s_enabled == -1 || (now - s_last_check) >= 1) { s_enabled = (access("/nvram/psm_cord_trace", F_OK) == 0) ? 1 : 0; s_last_check = now; } + return s_enabled; +} - if (!s_enabled) +/* cleanup handler: fires on any return path via __attribute__((cleanup)) */ +static void psm_cord_trace_end(psm_trace_ctx_t *ctx) +{ + if (!ctx->enabled) return; - int count = __sync_add_and_fetch(p_count, 1); + struct timespec t_end; + clock_gettime(CLOCK_MONOTONIC, &t_end); - char path[128]; - snprintf(path, sizeof(path), "/tmp/psm_cord_%s", api_name); + long long elapsed_ns = ((long long)(t_end.tv_sec - ctx->t_start.tv_sec) * 1000000000LL) + + ((long long)(t_end.tv_nsec - ctx->t_start.tv_nsec)); + + int count = __sync_add_and_fetch(ctx->p_count, 1); pthread_mutex_lock(&g_psm_trace_mutex); + + long long total = *ctx->p_total_ns + elapsed_ns; + *ctx->p_total_ns = total; + + if (*ctx->p_min_ns == 0 || elapsed_ns < *ctx->p_min_ns) + *ctx->p_min_ns = elapsed_ns; + if (elapsed_ns > *ctx->p_max_ns) + *ctx->p_max_ns = elapsed_ns; + + long long avg_ns = total / count; + + char path[128]; + snprintf(path, sizeof(path), "/tmp/psm_cord_%s", ctx->api_name); int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd >= 0) { - char buf[32]; - int len = snprintf(buf, sizeof(buf), "%d\n", count); + char buf[128]; + int len = snprintf(buf, sizeof(buf), + "count=%d last_ns=%lld total_ns=%lld avg_ns=%lld min_ns=%lld max_ns=%lld\n", + count, elapsed_ns, total, avg_ns, + *ctx->p_min_ns, *ctx->p_max_ns); write(fd, buf, (size_t)len); close(fd); } + pthread_mutex_unlock(&g_psm_trace_mutex); } #define PSM_CORD_COUNT() \ do { \ - static int s_count = 0; \ - psm_cord_trace_inc(__func__, &s_count); \ + static int s_count = 0; \ + static long long s_total_ns = 0; \ + static long long s_min_ns = 0; \ + static long long s_max_ns = 0; \ + psm_trace_ctx_t _trace_ctx __attribute__((cleanup(psm_cord_trace_end))) = { \ + .api_name = __func__, \ + .p_count = &s_count, \ + .p_total_ns= &s_total_ns, \ + .p_min_ns = &s_min_ns, \ + .p_max_ns = &s_max_ns, \ + .enabled = psm_cord_trace_is_enabled(), \ + }; \ + if (_trace_ctx.enabled) \ + clock_gettime(CLOCK_MONOTONIC, &_trace_ctx.t_start); \ } while (0) int CcspBaseIf_freeResources( From 66c05d2f960abb2f2e2f3ea83443a34b7b74adc0 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Fri, 31 Jul 2026 09:31:40 +0000 Subject: [PATCH 25/39] =?UTF-8?q?fix(psm):=20fix=20PSM=5FCORD=5FCOUNT=20ti?= =?UTF-8?q?ming=20scope=20=E2=80=94=20do-while=20ended=20cleanup=20too=20e?= =?UTF-8?q?arly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 30 +++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index ec32ae5dd..68e4099c8 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -162,22 +162,20 @@ static void psm_cord_trace_end(psm_trace_ctx_t *ctx) } #define PSM_CORD_COUNT() \ - do { \ - static int s_count = 0; \ - static long long s_total_ns = 0; \ - static long long s_min_ns = 0; \ - static long long s_max_ns = 0; \ - psm_trace_ctx_t _trace_ctx __attribute__((cleanup(psm_cord_trace_end))) = { \ - .api_name = __func__, \ - .p_count = &s_count, \ - .p_total_ns= &s_total_ns, \ - .p_min_ns = &s_min_ns, \ - .p_max_ns = &s_max_ns, \ - .enabled = psm_cord_trace_is_enabled(), \ - }; \ - if (_trace_ctx.enabled) \ - clock_gettime(CLOCK_MONOTONIC, &_trace_ctx.t_start); \ - } while (0) + static int s_count = 0; \ + static long long s_total_ns = 0; \ + static long long s_min_ns = 0; \ + static long long s_max_ns = 0; \ + psm_trace_ctx_t _psm_trace_ctx __attribute__((cleanup(psm_cord_trace_end))) = { \ + .api_name = __func__, \ + .p_count = &s_count, \ + .p_total_ns= &s_total_ns, \ + .p_min_ns = &s_min_ns, \ + .p_max_ns = &s_max_ns, \ + .enabled = psm_cord_trace_is_enabled(), \ + }; \ + if (_psm_trace_ctx.enabled) \ + clock_gettime(CLOCK_MONOTONIC, &_psm_trace_ctx.t_start) int CcspBaseIf_freeResources( void* bus_handle, From 83654a3c6d8bb5f44bf57b171ef48b95ab7b3d98 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Fri, 31 Jul 2026 09:43:37 +0000 Subject: [PATCH 26/39] feat(psm): use per-PID trace files to avoid cross-process overwrite --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 68e4099c8..5eaa82c8c 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -144,8 +144,8 @@ static void psm_cord_trace_end(psm_trace_ctx_t *ctx) long long avg_ns = total / count; - char path[128]; - snprintf(path, sizeof(path), "/tmp/psm_cord_%s", ctx->api_name); + char path[160]; + snprintf(path, sizeof(path), "/tmp/psm_cord_%s_%d", ctx->api_name, (int)getpid()); int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd >= 0) { From b47a26656200da56b51bc6d5f440ae54a4da26b1 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Mon, 10 Aug 2026 10:24:48 +0000 Subject: [PATCH 27/39] feat(psm): print the process name in the per-PID trace files --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 5eaa82c8c..0833fa694 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -56,6 +56,8 @@ #include #endif +#include + /* For AnscEqualString */ #include "ansc_platform.h" @@ -146,13 +148,17 @@ static void psm_cord_trace_end(psm_trace_ctx_t *ctx) char path[160]; snprintf(path, sizeof(path), "/tmp/psm_cord_%s_%d", ctx->api_name, (int)getpid()); + char process_name[16] = {0}; // Limited to 16 bytes by Linux kernel + if (prctl(PR_GET_NAME, process_name, 0, 0, 0) == 0) { + printf("Process Name: %s\n", process_name); + } int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd >= 0) { char buf[128]; int len = snprintf(buf, sizeof(buf), - "count=%d last_ns=%lld total_ns=%lld avg_ns=%lld min_ns=%lld max_ns=%lld\n", - count, elapsed_ns, total, avg_ns, + "process=%s count=%d last_ns=%lld total_ns=%lld avg_ns=%lld min_ns=%lld max_ns=%lld\n", + process_name, count, elapsed_ns, total, avg_ns, *ctx->p_min_ns, *ctx->p_max_ns); write(fd, buf, (size_t)len); close(fd); From 68311591764738a5a7a162b25304388dfb5b910f Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Mon, 10 Aug 2026 14:04:08 +0000 Subject: [PATCH 28/39] feat(psm): print the record name in the per-PID trace files --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 94 ++++++++++++++++---- 1 file changed, 77 insertions(+), 17 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 0833fa694..0eaa6562d 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -92,13 +92,14 @@ int CcspBaseIf_timeout_getval_seconds = 120; //seconds /* --- PSM API call counter + timing -------------------------------------- * Activated only when /nvram/psm_cord_trace exists. * Counts calls and records ns-resolution timing for both CORD and non-CORD - * PSM API paths. Writes to /tmp/psm_cord_. + * PSM API paths. Writes to /tmp/psm_cord__. * Thread-safe: GCC atomic counters + mutex-protected file write. * ---------------------------------------------------------------------- */ static pthread_mutex_t g_psm_trace_mutex = PTHREAD_MUTEX_INITIALIZER; typedef struct { const char *api_name; + char record_name[256]; int *p_count; long long *p_total_ns; long long *p_min_ns; @@ -150,38 +151,97 @@ static void psm_cord_trace_end(psm_trace_ctx_t *ctx) snprintf(path, sizeof(path), "/tmp/psm_cord_%s_%d", ctx->api_name, (int)getpid()); char process_name[16] = {0}; // Limited to 16 bytes by Linux kernel if (prctl(PR_GET_NAME, process_name, 0, 0, 0) == 0) { - printf("Process Name: %s\n", process_name); } - int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + char *existing_records = NULL; + size_t existing_records_len = 0; + + int fd = open(path, O_RDONLY); if (fd >= 0) { - char buf[128]; + off_t old_size = lseek(fd, 0, SEEK_END); + if (old_size > 0 && lseek(fd, 0, SEEK_SET) != (off_t)-1) + { + char *oldbuf = (char *)malloc((size_t)old_size + 1); + if (oldbuf) + { + ssize_t total_read = 0; + while (total_read < old_size) + { + ssize_t r = read(fd, oldbuf + total_read, (size_t)(old_size - total_read)); + if (r <= 0) + break; + total_read += r; + } + + if (total_read > 0) + { + oldbuf[total_read] = '\0'; + char *first_nl = strchr(oldbuf, '\n'); + if (first_nl && *(first_nl + 1) != '\0') + { + existing_records_len = strlen(first_nl + 1); + existing_records = (char *)malloc(existing_records_len + 1); + if (existing_records) + memcpy(existing_records, first_nl + 1, existing_records_len + 1); + else + existing_records_len = 0; + } + } + free(oldbuf); + } + } + close(fd); + } + + fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (fd >= 0) + { + char buf[512]; int len = snprintf(buf, sizeof(buf), "process=%s count=%d last_ns=%lld total_ns=%lld avg_ns=%lld min_ns=%lld max_ns=%lld\n", - process_name, count, elapsed_ns, total, avg_ns, + process_name, + count, elapsed_ns, total, avg_ns, *ctx->p_min_ns, *ctx->p_max_ns); write(fd, buf, (size_t)len); + + if (existing_records && existing_records_len > 0) + write(fd, existing_records, existing_records_len); + + if (ctx->record_name[0] != '\0') + { + int rn_len = snprintf(buf, sizeof(buf), "%s\n", ctx->record_name); + write(fd, buf, (size_t)rn_len); + } + close(fd); } + if (existing_records) + free(existing_records); + pthread_mutex_unlock(&g_psm_trace_mutex); } -#define PSM_CORD_COUNT() \ +#define PSM_CORD_COUNT(record_expr) \ static int s_count = 0; \ static long long s_total_ns = 0; \ static long long s_min_ns = 0; \ static long long s_max_ns = 0; \ psm_trace_ctx_t _psm_trace_ctx __attribute__((cleanup(psm_cord_trace_end))) = { \ .api_name = __func__, \ + .record_name = {0}, \ .p_count = &s_count, \ .p_total_ns= &s_total_ns, \ .p_min_ns = &s_min_ns, \ .p_max_ns = &s_max_ns, \ .enabled = psm_cord_trace_is_enabled(), \ }; \ - if (_psm_trace_ctx.enabled) \ - clock_gettime(CLOCK_MONOTONIC, &_psm_trace_ctx.t_start) + if (_psm_trace_ctx.enabled) { \ + const char *_psm_trace_record = (record_expr); \ + if (_psm_trace_record != NULL) \ + snprintf(_psm_trace_ctx.record_name, sizeof(_psm_trace_ctx.record_name), "%s", _psm_trace_record); \ + clock_gettime(CLOCK_MONOTONIC, &_psm_trace_ctx.t_start); \ + } int CcspBaseIf_freeResources( void* bus_handle, @@ -3134,7 +3194,7 @@ int PSM_Set_Record_Value PSLAP_VARIABLE pValue ) { - PSM_CORD_COUNT(); + PSM_CORD_COUNT(pRecordName); UNREFERENCED_PARAMETER(ulRecordType); UNREFERENCED_PARAMETER(pSubSystemPrefix); @@ -3344,7 +3404,7 @@ int PSM_Get_Record_Value PSLAP_VARIABLE pValue ) { - PSM_CORD_COUNT(); + PSM_CORD_COUNT(pRecordName); UNREFERENCED_PARAMETER(pSubSystemPrefix); CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; @@ -3530,7 +3590,7 @@ int PSM_Set_Record_Value2 char const * const pVal ) { - PSM_CORD_COUNT(); + PSM_CORD_COUNT(pRecordName); UNREFERENCED_PARAMETER(pSubSystemPrefix); #ifdef CORD_ENABLED @@ -3696,7 +3756,7 @@ int PSM_Get_Record_Value2 char** pValue ) { - PSM_CORD_COUNT(); + PSM_CORD_COUNT(pRecordName); UNREFERENCED_PARAMETER(pSubSystemPrefix); *pValue = NULL; @@ -3828,7 +3888,7 @@ int PSM_Del_Record char const * const pRecordName ) { - PSM_CORD_COUNT(); + PSM_CORD_COUNT(pRecordName); #ifdef CORD_ENABLED char psmName[512] = ""; errno_t rc = -1; @@ -3948,7 +4008,7 @@ int PSM_Del_Record int PsmGroupGet(void *bus_handle, const char *subsys, const char *names[], int nname, parameterValStruct_t ***records, int *nrec) { - PSM_CORD_COUNT(); + PSM_CORD_COUNT((names && nname > 0) ? names[0] : NULL); char psmName[256]; if (!bus_handle || !names || !records || !nrec) @@ -4195,7 +4255,7 @@ int PsmGetNextLevelInstances unsigned int** ppInstanceArray ) { - PSM_CORD_COUNT(); + PSM_CORD_COUNT(pParentPath); char psmName[512] = ""; errno_t rc = -1; #ifdef CORD_ENABLED @@ -4317,7 +4377,7 @@ int PsmEnumRecords PCCSP_BASE_RECORD* ppRecArray ) { - PSM_CORD_COUNT(); + PSM_CORD_COUNT(pParentPath); char psmName[512] = ""; errno_t rc = -1; #ifdef CORD_ENABLED @@ -4444,7 +4504,7 @@ int PSM_Reset_UserChangeFlag char const * const pathName ) { - PSM_CORD_COUNT(); + PSM_CORD_COUNT(pathName); #ifdef CORD_ENABLED static const char kPrefix[] = "UserChanged."; From 765bc9473dfd9eccd1be573d8760d9c18510a479 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Sat, 5 Sep 2026 06:32:00 +0000 Subject: [PATCH 29/39] bug(psm): Adding debug prints for PsmGetNextLevelInstances --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 29 +++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 0eaa6562d..1e07de012 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -4169,12 +4169,19 @@ void PsmFreeRecords(void *bus_handle, parameterValStruct_t **records, int nrec) */ static inline int safe_atou(const char *pParameterName, unsigned int *out) { + printf("safe_atou: pParameterName=%s\n", pParameterName); if (!pParameterName || !out) + { + printf("safe_atou: checking input validity\n"); return -1; + } const size_t len = strlen(pParameterName); if (len == 0) + { + printf("safe_atou: empty parameter name\n"); return -1; + } /* Find end of last segment, skipping any trailing dot */ const char *end = pParameterName + len; @@ -4182,7 +4189,10 @@ static inline int safe_atou(const char *pParameterName, unsigned int *out) end--; if (end == pParameterName) + { + printf("safe_atou: last segment is empty\n"); return -1; + } /* Find start of last segment */ const char *start = end; @@ -4192,16 +4202,23 @@ static inline int safe_atou(const char *pParameterName, unsigned int *out) /* Copy segment into a local buffer for strtoul */ size_t segLen = (size_t)(end - start); if (segLen == 0 || segLen >= 32) - return -1; + { + printf("safe_atou: segment length invalid\n"); + return -1; + } char *endptr; unsigned long val; errno = 0; val = strtoul(start, &endptr, 10); if (errno != 0 || endptr == start || *endptr != '\0' || val > UINT_MAX) + { + printf("safe_atou: conversion failed\n"); return -1; + } + printf("safe_atou: conversion succeeded, extracted value=%lu\n", val); *out = (unsigned int)val; return 0; } @@ -4215,7 +4232,7 @@ typedef struct cord_list_GetNextLevelInstances_List { static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, cord_value_type_t valueType, void* pUserData) { static const size_t kDefaultArraySize = 32; GNLInstanceList *pList = (GNLInstanceList*)pUserData; - + printf("cord_list_callback_GetNextLevelInstances: pParameterName=%s, valueType=%d,pList=%p\n", pParameterName, valueType, pList); if (!pList) return; CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)pList->bus_handle; const size_t len = strlen(pParameterName); @@ -4227,19 +4244,23 @@ static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, // Do we need to alloc or grow the array? if (pList->nCount == pList->nCapacity) { const size_t nNewCapacity = pList->nCapacity ? pList->nCapacity * 2 : kDefaultArraySize; + printf("Growing instance array from %zu to %zu\n", pList->nCapacity, nNewCapacity); unsigned int* pNewInstanceArray = bus_info->mallocfunc(sizeof(*pList->pInstanceArray) * nNewCapacity); if (!pNewInstanceArray) { pList->callbackError = true; + printf("Failed to allocate memory for instance array\n"); return; } pList->pInstanceArray = pNewInstanceArray; pList->nCapacity = nNewCapacity; } //pListItem->pInstanceArray[pList->nCount] = safe_atou(); - if(0 == safe_atou(pParameterName, &pList->pInstanceArray[pList->nCount])) + if(0 == safe_atou(pParameterName, &pList->pInstanceArray[pList->nCount])){ pList->nCount++; - else { + printf("Added instance %u to the list, total count now %zu\n", pList->pInstanceArray[pList->nCount - 1], pList->nCount); + } else { + printf("Failed to add instance from parameter name %s\n", pParameterName); pList->callbackError = true; return; } From 33077a7bb0a3ca7aa0c378ede18a80a420a90fc6 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Sat, 5 Sep 2026 12:30:30 +0000 Subject: [PATCH 30/39] bug(psm): passing pParentPath to cord_list --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 1e07de012..1a35ea9ce 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -4282,7 +4282,7 @@ int PsmGetNextLevelInstances #ifdef CORD_ENABLED *ppInstanceArray = NULL; *pulNumInstance = 0; - + CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; if (pSubSystemPrefix && pSubSystemPrefix[0] != 0) { rc = strcpy_s(psmName, sizeof(psmName), pSubSystemPrefix); @@ -4299,7 +4299,8 @@ int PsmGetNextLevelInstances GNLInstanceList list = {0}; list.bus_handle = bus_handle; - cord_rc_t crc = cord_list(psmName, 1, cord_list_callback_GetNextLevelInstances, (void*)&list); + printf("PsmGetNextLevelInstances: calling cord_list with psmName='%s', pParentPath='%s'\n", psmName, pParentPath); + cord_rc_t crc = cord_list(pParentPath, 1, cord_list_callback_GetNextLevelInstances, (void*)&list); if (crc != CORD_RC_SUCCESS) { return CCSP_Message_Bus_ERROR; } From 592d979d5e61d9e3c8dde87197712cc9c387b5e2 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Sat, 5 Sep 2026 16:58:28 +0000 Subject: [PATCH 31/39] bug(psm): fixed safe_atou --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 26 +++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 1a35ea9ce..921705302 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -4183,9 +4183,9 @@ static inline int safe_atou(const char *pParameterName, unsigned int *out) return -1; } - /* Find end of last segment, skipping any trailing dot */ + /* Move to the end of the numeric segment, skipping any trailing dot(s). */ const char *end = pParameterName + len; - if (*(end - 1) == '.') + while (end > pParameterName && end[-1] == '.') end--; if (end == pParameterName) @@ -4194,29 +4194,27 @@ static inline int safe_atou(const char *pParameterName, unsigned int *out) return -1; } - /* Find start of last segment */ + /* Find start of the last segment; for "dmsb.l2net.3." this leaves start at '3'. */ const char *start = end; - while (start > pParameterName && *(start - 1) != '.') + while (start > pParameterName && start[-1] != '.') start--; - /* Copy segment into a local buffer for strtoul */ - size_t segLen = (size_t)(end - start); + const size_t segLen = (size_t)(end - start); if (segLen == 0 || segLen >= 32) - { - printf("safe_atou: segment length invalid\n"); - return -1; - } + { + printf("safe_atou: segment length invalid\n"); + return -1; + } - char *endptr; - unsigned long val; + char *endptr = NULL; + unsigned long val = 0; errno = 0; val = strtoul(start, &endptr, 10); - if (errno != 0 || endptr == start || *endptr != '\0' || val > UINT_MAX) + if (errno != 0 || endptr == start || endptr != end || val > UINT_MAX) { printf("safe_atou: conversion failed\n"); return -1; } - printf("safe_atou: conversion succeeded, extracted value=%lu\n", val); *out = (unsigned int)val; From 2ac374d105e61515dace225a4126486dd493efbf Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Sun, 6 Sep 2026 02:24:07 +0000 Subject: [PATCH 32/39] bug(psm): removing debug prints --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 23 -------------------- 1 file changed, 23 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 921705302..800dab787 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -4169,19 +4169,12 @@ void PsmFreeRecords(void *bus_handle, parameterValStruct_t **records, int nrec) */ static inline int safe_atou(const char *pParameterName, unsigned int *out) { - printf("safe_atou: pParameterName=%s\n", pParameterName); if (!pParameterName || !out) - { - printf("safe_atou: checking input validity\n"); return -1; - } const size_t len = strlen(pParameterName); if (len == 0) - { - printf("safe_atou: empty parameter name\n"); return -1; - } /* Move to the end of the numeric segment, skipping any trailing dot(s). */ const char *end = pParameterName + len; @@ -4189,10 +4182,7 @@ static inline int safe_atou(const char *pParameterName, unsigned int *out) end--; if (end == pParameterName) - { - printf("safe_atou: last segment is empty\n"); return -1; - } /* Find start of the last segment; for "dmsb.l2net.3." this leaves start at '3'. */ const char *start = end; @@ -4201,22 +4191,15 @@ static inline int safe_atou(const char *pParameterName, unsigned int *out) const size_t segLen = (size_t)(end - start); if (segLen == 0 || segLen >= 32) - { - printf("safe_atou: segment length invalid\n"); return -1; - } char *endptr = NULL; unsigned long val = 0; errno = 0; val = strtoul(start, &endptr, 10); if (errno != 0 || endptr == start || endptr != end || val > UINT_MAX) - { - printf("safe_atou: conversion failed\n"); return -1; - } - printf("safe_atou: conversion succeeded, extracted value=%lu\n", val); *out = (unsigned int)val; return 0; } @@ -4230,7 +4213,6 @@ typedef struct cord_list_GetNextLevelInstances_List { static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, cord_value_type_t valueType, void* pUserData) { static const size_t kDefaultArraySize = 32; GNLInstanceList *pList = (GNLInstanceList*)pUserData; - printf("cord_list_callback_GetNextLevelInstances: pParameterName=%s, valueType=%d,pList=%p\n", pParameterName, valueType, pList); if (!pList) return; CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)pList->bus_handle; const size_t len = strlen(pParameterName); @@ -4242,12 +4224,10 @@ static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, // Do we need to alloc or grow the array? if (pList->nCount == pList->nCapacity) { const size_t nNewCapacity = pList->nCapacity ? pList->nCapacity * 2 : kDefaultArraySize; - printf("Growing instance array from %zu to %zu\n", pList->nCapacity, nNewCapacity); unsigned int* pNewInstanceArray = bus_info->mallocfunc(sizeof(*pList->pInstanceArray) * nNewCapacity); if (!pNewInstanceArray) { pList->callbackError = true; - printf("Failed to allocate memory for instance array\n"); return; } pList->pInstanceArray = pNewInstanceArray; @@ -4256,9 +4236,7 @@ static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, //pListItem->pInstanceArray[pList->nCount] = safe_atou(); if(0 == safe_atou(pParameterName, &pList->pInstanceArray[pList->nCount])){ pList->nCount++; - printf("Added instance %u to the list, total count now %zu\n", pList->pInstanceArray[pList->nCount - 1], pList->nCount); } else { - printf("Failed to add instance from parameter name %s\n", pParameterName); pList->callbackError = true; return; } @@ -4297,7 +4275,6 @@ int PsmGetNextLevelInstances GNLInstanceList list = {0}; list.bus_handle = bus_handle; - printf("PsmGetNextLevelInstances: calling cord_list with psmName='%s', pParentPath='%s'\n", psmName, pParentPath); cord_rc_t crc = cord_list(pParentPath, 1, cord_list_callback_GetNextLevelInstances, (void*)&list); if (crc != CORD_RC_SUCCESS) { return CCSP_Message_Bus_ERROR; From e47793f32ad13010f63c86972cafa8dc956a500a Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Sun, 6 Sep 2026 10:58:51 +0000 Subject: [PATCH 33/39] bug(psm): 1. returning callbackerror if any one instance is not CORD_TYPE_OBJECT_PATH hence entire list is omitted. 2. array allocation is made as incremental 3. if convertion of instance number fails callbackerror is set which is not required since that can be omitted --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 38 +++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 800dab787..a2ae7f528 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -4211,35 +4211,49 @@ typedef struct cord_list_GetNextLevelInstances_List { void* bus_handle; }GNLInstanceList; static void cord_list_callback_GetNextLevelInstances(const char* pParameterName, cord_value_type_t valueType, void* pUserData) { - static const size_t kDefaultArraySize = 32; GNLInstanceList *pList = (GNLInstanceList*)pUserData; if (!pList) return; CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)pList->bus_handle; + if (!bus_info || !bus_info->mallocfunc || !bus_info->freefunc) { + pList->callbackError = true; + return; + } + if (!pParameterName) + return; + const size_t len = strlen(pParameterName); + if (len == 0) + return; + if (valueType != CORD_TYPE_OBJECT_PATH || pParameterName[len - 1] != '.') { - pList->callbackError = true; return; } - // Do we need to alloc or grow the array? + unsigned int instance = 0; + if (safe_atou(pParameterName, &instance) != 0) + return; + + /* Grow one-by-one and preserve existing entries. */ if (pList->nCount == pList->nCapacity) { - const size_t nNewCapacity = pList->nCapacity ? pList->nCapacity * 2 : kDefaultArraySize; + const size_t nNewCapacity = pList->nCapacity + 1; unsigned int* pNewInstanceArray = bus_info->mallocfunc(sizeof(*pList->pInstanceArray) * nNewCapacity); if (!pNewInstanceArray) { pList->callbackError = true; return; - } + } + + if (pList->pInstanceArray && pList->nCount > 0) { + memcpy(pNewInstanceArray, pList->pInstanceArray, sizeof(*pList->pInstanceArray) * pList->nCount); + bus_info->freefunc(pList->pInstanceArray); + } + pList->pInstanceArray = pNewInstanceArray; pList->nCapacity = nNewCapacity; - } - //pListItem->pInstanceArray[pList->nCount] = safe_atou(); - if(0 == safe_atou(pParameterName, &pList->pInstanceArray[pList->nCount])){ - pList->nCount++; - } else { - pList->callbackError = true; - return; } + + pList->pInstanceArray[pList->nCount] = instance; + pList->nCount++; }; #endif /* CORD_ENABLED */ From f4f04141664cc5c41624b4905d6a5297fa9d8720 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Wed, 16 Sep 2026 09:41:18 +0000 Subject: [PATCH 34/39] bug(psm): debug prints for PsmEnumRecords --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 29 ++++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index a2ae7f528..85e35290c 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -4347,10 +4347,10 @@ typedef struct cord_list_PsmEnumRecords_List { static void cord_list_callback_PsmEnumRecords(const char* pParameterName, cord_value_type_t valueType, void* pUserData) { ERList *pList = (ERList*)pUserData; - + printf("cord_list_callback_PsmEnumRecords called with pParameterName: %s, valueType: %d\n", pParameterName, valueType); if (!pList) return; if (pList->nextLevel == false && valueType == CORD_TYPE_OBJECT_PATH) return; // PSM behaviour - only object/instance returned if nextLevel==true - + printf("Appending new list item for pParameterName: %s\n", pParameterName); const size_t lenNameWithNull = strlen(pParameterName) + 1; // Append new list item @@ -4365,6 +4365,7 @@ static void cord_list_callback_PsmEnumRecords(const char* pParameterName, cord_v pListItem->pNext = pList->pHead; pList->pHead = pListItem; pList->nCount++; + printf("New list count: %zu\n", pList->nCount); } static void FreeList(ERList* pList) @@ -4408,6 +4409,8 @@ int PsmEnumRecords list.nextLevel = nextLevel; const size_t depth = nextLevel ? 1 : 0; cord_rc_t crc = cord_list(psmName, depth, cord_list_callback_PsmEnumRecords, (void*)&list); + printf("cord_list returned: %d\n", crc); + printf("list.nCount: %zu list.callbackError: %d\n", list.nCount, list.callbackError); if (crc != CORD_RC_SUCCESS) { return CCSP_Message_Bus_ERROR; } @@ -4416,7 +4419,7 @@ int PsmEnumRecords FreeList(&list); return CCSP_Message_Bus_OOM; } - + printf("Finished listing PSM records, preparing to allocate output array\n"); // Alloc output array CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; PCCSP_BASE_RECORD pRecArray = NULL; @@ -4430,10 +4433,11 @@ int PsmEnumRecords pRecArray = (PCCSP_BASE_RECORD)calloc(list.nCount, sizeof(CCSP_BASE_RECORD)); } - + printf("Allocated output array of size: %zu\n", recArraySize); if (!pRecArray) { //free linked list FreeList(&list); + printf("Failed to allocate output array\n"); return CCSP_Message_Bus_OOM; } size_t idxRecArray = 0; @@ -4445,24 +4449,30 @@ int PsmEnumRecords if (pItem->valueType == CORD_TYPE_OBJECT_PATH) { //last node name is all integer digits + printf("Processing object path: %s\n", pItem->pParameterName); len = strlen(pItem->pParameterName); if (pItem->pParameterName[len-1] != '.') { pRecArray[idxRecArray].RecordType = CCSP_BASE_INSTANCE; //pRecArray[idxRecArray].InstanceNumber = safe_atou(); - if(0 != safe_atou(pItem->pParameterName, &(pRecArray[idxRecArray].Instance.InstanceNumber))); - CcspTraceError(("%s error while collecting the items\n", __FUNCTION__)); + if(0 != safe_atou(pItem->pParameterName, &(pRecArray[idxRecArray].Instance.InstanceNumber))) { + printf("Failed to convert object path to instance number: %s\n", pItem->pParameterName); + CcspTraceError(("%s error while collecting the items\n", __FUNCTION__)); + } + printf("Successfully converted object path to instance number: %s -> %u\n", pItem->pParameterName, pRecArray[idxRecArray].Instance.InstanceNumber); } else { pRecArray[idxRecArray].RecordType = CCSP_BASE_OBJECT; strncpy(pRecArray[idxRecArray].Instance.Name, pItem->pParameterName, CCSP_BASE_PARAM_LENGTH-1); - pRecArray[idxRecArray].Instance.Name[CCSP_BASE_PARAM_LENGTH-1] = '\0'; + pRecArray[idxRecArray].Instance.Name[CCSP_BASE_PARAM_LENGTH-1] = '\0'; + printf("Processed object path as object: %s\n", pItem->pParameterName); } } else { - pRecArray[idxRecArray].RecordType = CCSP_BASE_PARAM; + pRecArray[idxRecArray].RecordType = CCSP_BASE_PARAM; strncpy(pRecArray[idxRecArray].Instance.Name, pItem->pParameterName, CCSP_BASE_PARAM_LENGTH-1); - pRecArray[idxRecArray].Instance.Name[CCSP_BASE_PARAM_LENGTH-1] = '\0'; + pRecArray[idxRecArray].Instance.Name[CCSP_BASE_PARAM_LENGTH-1] = '\0'; + printf("Processed parameter: %s\n", pItem->pParameterName); } list.pHead = pItem->pNext; // Unlink this list item from list @@ -4473,6 +4483,7 @@ int PsmEnumRecords *ppRecArray = pRecArray; *pulNumRec = list.nCount; + printf("Total records processed: %zu pulNumRec: %zu\n", idxRecArray, *pulNumRec); return CCSP_SUCCESS; From 3d7e6b2a2fcf97f56e6879b8bbe2953e9a4dc838 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Thu, 17 Sep 2026 09:23:55 +0000 Subject: [PATCH 35/39] bug(psm): remove debug prints --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 85e35290c..937d53e96 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -4347,10 +4347,8 @@ typedef struct cord_list_PsmEnumRecords_List { static void cord_list_callback_PsmEnumRecords(const char* pParameterName, cord_value_type_t valueType, void* pUserData) { ERList *pList = (ERList*)pUserData; - printf("cord_list_callback_PsmEnumRecords called with pParameterName: %s, valueType: %d\n", pParameterName, valueType); if (!pList) return; if (pList->nextLevel == false && valueType == CORD_TYPE_OBJECT_PATH) return; // PSM behaviour - only object/instance returned if nextLevel==true - printf("Appending new list item for pParameterName: %s\n", pParameterName); const size_t lenNameWithNull = strlen(pParameterName) + 1; // Append new list item @@ -4365,7 +4363,6 @@ static void cord_list_callback_PsmEnumRecords(const char* pParameterName, cord_v pListItem->pNext = pList->pHead; pList->pHead = pListItem; pList->nCount++; - printf("New list count: %zu\n", pList->nCount); } static void FreeList(ERList* pList) @@ -4409,8 +4406,6 @@ int PsmEnumRecords list.nextLevel = nextLevel; const size_t depth = nextLevel ? 1 : 0; cord_rc_t crc = cord_list(psmName, depth, cord_list_callback_PsmEnumRecords, (void*)&list); - printf("cord_list returned: %d\n", crc); - printf("list.nCount: %zu list.callbackError: %d\n", list.nCount, list.callbackError); if (crc != CORD_RC_SUCCESS) { return CCSP_Message_Bus_ERROR; } @@ -4419,7 +4414,6 @@ int PsmEnumRecords FreeList(&list); return CCSP_Message_Bus_OOM; } - printf("Finished listing PSM records, preparing to allocate output array\n"); // Alloc output array CCSP_MESSAGE_BUS_INFO *bus_info = (CCSP_MESSAGE_BUS_INFO *)bus_handle; PCCSP_BASE_RECORD pRecArray = NULL; @@ -4433,11 +4427,9 @@ int PsmEnumRecords pRecArray = (PCCSP_BASE_RECORD)calloc(list.nCount, sizeof(CCSP_BASE_RECORD)); } - printf("Allocated output array of size: %zu\n", recArraySize); if (!pRecArray) { //free linked list FreeList(&list); - printf("Failed to allocate output array\n"); return CCSP_Message_Bus_OOM; } size_t idxRecArray = 0; @@ -4449,30 +4441,24 @@ int PsmEnumRecords if (pItem->valueType == CORD_TYPE_OBJECT_PATH) { //last node name is all integer digits - printf("Processing object path: %s\n", pItem->pParameterName); len = strlen(pItem->pParameterName); if (pItem->pParameterName[len-1] != '.') { pRecArray[idxRecArray].RecordType = CCSP_BASE_INSTANCE; //pRecArray[idxRecArray].InstanceNumber = safe_atou(); if(0 != safe_atou(pItem->pParameterName, &(pRecArray[idxRecArray].Instance.InstanceNumber))) { - printf("Failed to convert object path to instance number: %s\n", pItem->pParameterName); CcspTraceError(("%s error while collecting the items\n", __FUNCTION__)); } - printf("Successfully converted object path to instance number: %s -> %u\n", pItem->pParameterName, pRecArray[idxRecArray].Instance.InstanceNumber); - } else { pRecArray[idxRecArray].RecordType = CCSP_BASE_OBJECT; strncpy(pRecArray[idxRecArray].Instance.Name, pItem->pParameterName, CCSP_BASE_PARAM_LENGTH-1); pRecArray[idxRecArray].Instance.Name[CCSP_BASE_PARAM_LENGTH-1] = '\0'; - printf("Processed object path as object: %s\n", pItem->pParameterName); } } else { pRecArray[idxRecArray].RecordType = CCSP_BASE_PARAM; strncpy(pRecArray[idxRecArray].Instance.Name, pItem->pParameterName, CCSP_BASE_PARAM_LENGTH-1); pRecArray[idxRecArray].Instance.Name[CCSP_BASE_PARAM_LENGTH-1] = '\0'; - printf("Processed parameter: %s\n", pItem->pParameterName); } list.pHead = pItem->pNext; // Unlink this list item from list @@ -4483,7 +4469,6 @@ int PsmEnumRecords *ppRecArray = pRecArray; *pulNumRec = list.nCount; - printf("Total records processed: %zu pulNumRec: %zu\n", idxRecArray, *pulNumRec); return CCSP_SUCCESS; From 9c1d2ac5cba55c2fcfb7aa8033abaf4eda7d37c0 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Tue, 20 Oct 2026 20:00:12 +0000 Subject: [PATCH 36/39] bug(psm): fix record delete and bool value case in CORD PSM_Del_Record called cord_default()/cord_default_multi(), which are stubs that return success without deleting anything. It also prefixed the key with the PSM component name, so a real delete would still have missed the stored key. It now calls cord_unset_multi() with the plain record name. A missing key is treated as success, matching non-CORD PSM. CORD bool values are now returned as "TRUE"/"FALSE" from both PSM_Get_Record_Value2() and PsmGroupGet(), replacing the previous PSM_TRUE/PSM_FALSE and lowercase "true"/"false" strings. --- source/util_api/ccsp_msg_bus/ccsp_base_api.c | 31 ++++++-------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/source/util_api/ccsp_msg_bus/ccsp_base_api.c b/source/util_api/ccsp_msg_bus/ccsp_base_api.c index 937d53e96..c896dea1d 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_base_api.c +++ b/source/util_api/ccsp_msg_bus/ccsp_base_api.c @@ -3800,7 +3800,7 @@ int PSM_Get_Record_Value2 case CORD_TYPE_BOOL: { if (ulRecordType) *ulRecordType = ccsp_boolean; - const char *bstr = pCordValue->boolValue ? PSM_TRUE : PSM_FALSE; + const char *bstr = pCordValue->boolValue ? "TRUE" : "FALSE"; *pValue = bus_info->mallocfunc(strlen(bstr) + 1); if (*pValue == NULL) { cord_free_values(pCordValue); return CCSP_ERR_MEMORY_ALLOC_FAIL; } strcpy(*pValue, bstr); @@ -3890,31 +3890,18 @@ int PSM_Del_Record { PSM_CORD_COUNT(pRecordName); #ifdef CORD_ENABLED - char psmName[512] = ""; - errno_t rc = -1; + UNREFERENCED_PARAMETER(bus_handle); + UNREFERENCED_PARAMETER(pSubSystemPrefix); cord_rc_t crc = CORD_RC_SUCCESS; - if (!pRecordName) { + if (!pRecordName || pRecordName[0] == '\0') { return CCSP_ERR_INVALID_PARAMETER_VALUE; } - if (pSubSystemPrefix && pSubSystemPrefix[0] != 0) { - rc = strcpy_s(psmName, sizeof(psmName), pSubSystemPrefix); - ERR_CHK(rc); - } - rc = strcat_s(psmName, sizeof(psmName), CCSP_DBUS_PSM); - ERR_CHK(rc); - rc = strcat_s(psmName, sizeof(psmName), "."); - ERR_CHK(rc); - rc = strcat_s(psmName, sizeof(psmName), pRecordName); - ERR_CHK(rc); - - if ( pRecordName[strlen(pRecordName)-1] == '.' ) { - crc = cord_default_multi(psmName, CORD_FLAG_PERSIST_ASYNC); - } - else { - crc = cord_default(psmName, CORD_FLAG_PERSIST_ASYNC); - } + /* Keys are stored under their plain record name; a trailing '.' deletes the whole subtree. + * cord_unset_multi() treats a missing key as success, matching non-CORD PSM. */ + const char *names[1] = { pRecordName }; + crc = cord_unset_multi(names, 1, CORD_FLAG_PERSIST_ASYNC); switch (crc) { case CORD_RC_SUCCESS: return CCSP_SUCCESS; case CORD_RC_NOT_OPEN: return CCSP_Message_Bus_ERROR; @@ -4076,7 +4063,7 @@ int PsmGroupGet(void *bus_handle, const char *subsys, break; case CORD_TYPE_BOOL: val[i]->type = ccsp_boolean; - const char *bstr = params[i].value.boolValue ? "true" : "false"; + const char *bstr = params[i].value.boolValue ? "TRUE" : "FALSE"; val[i]->parameterValue = bus_info->mallocfunc(strlen(bstr) + 1); if(NULL == val[i]->parameterValue ){ret = CCSP_ERR_MEMORY_ALLOC_FAIL;break;} memcpy(val[i]->parameterValue, bstr,strlen(bstr) + 1); From 32dd454e4eacfccf3af47ccb7cb70adfcabc129a Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Thu, 29 Oct 2026 07:25:32 +0000 Subject: [PATCH 37/39] feat(psm): add PSM API latency benchmark for CORD comparison Add psm_api_speed_test, which times each PSM helper API in libccsp_common and prints the average latency per call. The same source builds for CORD and non-CORD images; CORD_ENABLED selects the mode label. Calls that fail are excluded from the average and reported on stderr. Link -lcord only when WITH_CORD_SUPPORT is set. --- source/Makefile.am | 23 +++ source/psm_api_speed_test.c | 337 ++++++++++++++++++++++++++++++++++++ 2 files changed, 360 insertions(+) create mode 100644 source/psm_api_speed_test.c diff --git a/source/Makefile.am b/source/Makefile.am index ccdec4abb..46a93b770 100644 --- a/source/Makefile.am +++ b/source/Makefile.am @@ -244,3 +244,26 @@ libccsp_common_la_DEPENDENCIES = \ libccsp_common_la_LIBADD = $(libccsp_common_la_DEPENDENCIES) + +# PSM API speed test: run on CORD and non-CORD images to compare per-API latency. +bin_PROGRAMS = psm_api_speed_test +psm_api_speed_test_SOURCES = psm_api_speed_test.c +psm_api_speed_test_CPPFLAGS = \ + -I$(top_srcdir)/source/cosa/include/linux \ + -I$(top_srcdir)/source/debug_api/include \ + -I$(top_srcdir)/source/cosa/include \ + -I$(top_srcdir)/source/cosa/utilities/include \ + -I$(top_srcdir)/source/cosa/custom \ + -I$(top_srcdir)/source/cosa/package/system/include \ + -I$(top_srcdir)/source/cosa/package/slap/include \ + -I$(top_srcdir)/source/cosa/package/slap/services/dslh/include \ + -I$(top_srcdir)/source/ccsp/include \ + -I$(top_srcdir)/source/ccsp/components/include \ + -I$(top_srcdir)/source/ccsp/components/common/MessageBusHelper/include \ + -I$(top_srcdir)/source/ccsp/components/common/PoamIrepFolder \ + -I$(top_srcdir)/source/ccsp/custom \ + -I$(top_srcdir)/source/util_api/ansc/include +psm_api_speed_test_LDADD = libccsp_common.la -ldbus-1 -lrbus -lrbuscore -lrtMessage -lpthread -lrt +if WITH_CORD_SUPPORT +psm_api_speed_test_LDADD += -lcord +endif diff --git a/source/psm_api_speed_test.c b/source/psm_api_speed_test.c new file mode 100644 index 000000000..645d90ee7 --- /dev/null +++ b/source/psm_api_speed_test.c @@ -0,0 +1,337 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2026 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +/* + * psm_api_speed_test [iterations] + * + * Measures the average latency of each PSM helper API in libccsp_common. + * The same source is built for CORD and non-CORD images (CORD_ENABLED is set + * by configure --enable-cord), so results can be compared directly. + * + * Only the API call itself is timed; fixture set-up and freeing of returned + * memory are outside the timed region. Failed calls are counted but excluded + * from the timing statistics. + */ + +#include +#include +#include +#include +#include +#include + +#include "ccsp_message_bus.h" +#include "ccsp_base_api.h" +#include "ccsp_psm_helper.h" +#include "ccsp_custom.h" + +#define DEFAULT_ITERATIONS 1000000ULL +#define COMPONENT_ID "com.cisco.spvtg.ccsp.psm.apispeedtest" +#define SUBSYS "" + +#define PERF_ROOT "dmsb.perftest." +#define KEY_STR PERF_ROOT "StringParam" +#define KEY_INT PERF_ROOT "IntParam" +#define KEY_DEL PERF_ROOT "DelParam" +#define INST_PARENT PERF_ROOT "Inst." +#define NUM_INST 5U +#define STR_VALUE "perftest123" +#define INT_VALUE 12345 + +typedef struct { + uint64_t ok; + uint64_t fails; + uint64_t total_ns; + uint64_t min_ns; + uint64_t max_ns; +} stats_t; + +typedef void (*bench_fn)(uint64_t n, stats_t *st); + +static void *g_bus = NULL; + +static uint64_t now_ns(void) +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint64_t)ts.tv_sec * 1000000000ULL + (uint64_t)ts.tv_nsec; +} + +static void stats_add(stats_t *st, uint64_t ns, int rc) +{ + if (rc != CCSP_SUCCESS) { + st->fails++; + return; + } + if (st->ok == 0 || ns < st->min_ns) st->min_ns = ns; + if (ns > st->max_ns) st->max_ns = ns; + st->ok++; + st->total_ns += ns; +} + +static void bus_free(void *p) +{ + if (p) ((CCSP_MESSAGE_BUS_INFO *)g_bus)->freefunc(p); +} + +static void inst_key(char *buf, size_t len, unsigned int idx) +{ + snprintf(buf, len, INST_PARENT "%u.Name", idx); +} + +static int set_int_record(int value) +{ + SLAP_VARIABLE var; + memset(&var, 0, sizeof(var)); + var.Syntax = SLAP_VAR_SYNTAX_int; + var.Variant.varInt = value; + return PSM_Set_Record_Value(g_bus, SUBSYS, KEY_INT, ccsp_int, &var); +} + +/* ---- benchmarks ------------------------------------------------------- */ + +static void bench_get_next_level_instances(uint64_t n, stats_t *st) +{ + for (uint64_t i = 0; i < n; i++) { + unsigned int num = 0; + unsigned int *arr = NULL; + uint64_t t0 = now_ns(); + int rc = PsmGetNextLevelInstances(g_bus, SUBSYS, INST_PARENT, &num, &arr); + uint64_t t1 = now_ns(); + stats_add(st, t1 - t0, rc); + bus_free(arr); + } +} + +static void bench_enum_records(uint64_t n, stats_t *st) +{ + for (uint64_t i = 0; i < n; i++) { + unsigned int num = 0; + PCCSP_BASE_RECORD arr = NULL; + uint64_t t0 = now_ns(); + int rc = PsmEnumRecords(g_bus, SUBSYS, INST_PARENT, 1, &num, &arr); + uint64_t t1 = now_ns(); + stats_add(st, t1 - t0, rc); + bus_free(arr); + } +} + +static void bench_get_record_value2(uint64_t n, stats_t *st) +{ + for (uint64_t i = 0; i < n; i++) { + char *val = NULL; + unsigned int type = 0; + uint64_t t0 = now_ns(); + int rc = PSM_Get_Record_Value2(g_bus, SUBSYS, KEY_STR, &type, &val); + uint64_t t1 = now_ns(); + stats_add(st, t1 - t0, rc); + bus_free(val); + } +} + +static void bench_group_get(uint64_t n, stats_t *st) +{ + const char *names[2] = { KEY_STR, KEY_INT }; + + for (uint64_t i = 0; i < n; i++) { + parameterValStruct_t **recs = NULL; + int nrec = 0; + uint64_t t0 = now_ns(); + int rc = PsmGroupGet(g_bus, SUBSYS, names, 2, &recs, &nrec); + uint64_t t1 = now_ns(); + stats_add(st, t1 - t0, rc); + if (rc == CCSP_SUCCESS && recs) + PsmFreeRecords(g_bus, recs, nrec); + } +} + +static void bench_del_record(uint64_t n, stats_t *st) +{ + for (uint64_t i = 0; i < n; i++) { + /* Re-create the record so every delete has something to remove. */ + PSM_Set_Record_Value2(g_bus, SUBSYS, KEY_DEL, ccsp_string, STR_VALUE); + uint64_t t0 = now_ns(); + int rc = PSM_Del_Record(g_bus, SUBSYS, KEY_DEL); + uint64_t t1 = now_ns(); + stats_add(st, t1 - t0, rc); + } +} + +static void bench_set_record_value2(uint64_t n, stats_t *st) +{ + for (uint64_t i = 0; i < n; i++) { + uint64_t t0 = now_ns(); + int rc = PSM_Set_Record_Value2(g_bus, SUBSYS, KEY_STR, ccsp_string, STR_VALUE); + uint64_t t1 = now_ns(); + stats_add(st, t1 - t0, rc); + } +} + +static void bench_get_record_value(uint64_t n, stats_t *st) +{ + for (uint64_t i = 0; i < n; i++) { + SLAP_VARIABLE var; + unsigned int type = 0; + memset(&var, 0, sizeof(var)); + uint64_t t0 = now_ns(); + int rc = PSM_Get_Record_Value(g_bus, SUBSYS, KEY_INT, &type, &var); + uint64_t t1 = now_ns(); + stats_add(st, t1 - t0, rc); + } +} + +static void bench_set_record_value(uint64_t n, stats_t *st) +{ + SLAP_VARIABLE var; + memset(&var, 0, sizeof(var)); + var.Syntax = SLAP_VAR_SYNTAX_int; + var.Variant.varInt = INT_VALUE; + + for (uint64_t i = 0; i < n; i++) { + uint64_t t0 = now_ns(); + int rc = PSM_Set_Record_Value(g_bus, SUBSYS, KEY_INT, ccsp_int, &var); + uint64_t t1 = now_ns(); + stats_add(st, t1 - t0, rc); + } +} + +static const struct { + const char *name; + bench_fn fn; +} k_bench[] = { + { "PsmGetNextLevelInstances", bench_get_next_level_instances }, + { "PsmEnumRecords", bench_enum_records }, + { "PSM_Get_Record_Value2", bench_get_record_value2 }, + { "PsmGroupGet", bench_group_get }, + { "PSM_Del_Record", bench_del_record }, + { "PSM_Set_Record_Value2", bench_set_record_value2 }, + { "PSM_Get_Record_Value", bench_get_record_value }, + { "PSM_Set_Record_Value", bench_set_record_value }, +}; + +/* ---- fixture ---------------------------------------------------------- */ + +static int fixture_setup(void) +{ + char key[128]; + int rc; + + rc = PSM_Set_Record_Value2(g_bus, SUBSYS, KEY_STR, ccsp_string, STR_VALUE); + if (rc != CCSP_SUCCESS) return rc; + + rc = set_int_record(INT_VALUE); + if (rc != CCSP_SUCCESS) return rc; + + for (unsigned int i = 1; i <= NUM_INST; i++) { + inst_key(key, sizeof(key), i); + rc = PSM_Set_Record_Value2(g_bus, SUBSYS, key, ccsp_string, STR_VALUE); + if (rc != CCSP_SUCCESS) return rc; + } + return CCSP_SUCCESS; +} + +static void fixture_cleanup(void) +{ + char key[128]; + + PSM_Del_Record(g_bus, SUBSYS, KEY_STR); + PSM_Del_Record(g_bus, SUBSYS, KEY_INT); + PSM_Del_Record(g_bus, SUBSYS, KEY_DEL); + for (unsigned int i = 1; i <= NUM_INST; i++) { + inst_key(key, sizeof(key), i); + PSM_Del_Record(g_bus, SUBSYS, key); + } +} + +/* ---- main ------------------------------------------------------------- */ + +static int parse_iterations(const char *arg, uint64_t *out) +{ + char *end = NULL; + + if (arg[0] < '0' || arg[0] > '9') return -1; + errno = 0; + unsigned long long v = strtoull(arg, &end, 10); + if (errno != 0 || *end != '\0' || v == 0) return -1; + *out = (uint64_t)v; + return 0; +} + +int main(int argc, char *argv[]) +{ + static char component_id[] = COMPONENT_ID; + uint64_t iterations = DEFAULT_ITERATIONS; + int rc; + + if (argc > 2 || (argc == 2 && parse_iterations(argv[1], &iterations) != 0)) { + fprintf(stderr, + "Usage: %s [iterations]\n" + " iterations: positive integer (default %llu)\n", + argv[0], DEFAULT_ITERATIONS); + return 1; + } + + rc = CCSP_Message_Bus_Init(component_id, CCSP_MSG_BUS_CFG, &g_bus, NULL, NULL); + if (rc == -1 || g_bus == NULL) { + fprintf(stderr, "ERROR: CCSP_Message_Bus_Init failed (rc=%d)\n", rc); + return 1; + } + + rc = fixture_setup(); + if (rc != CCSP_SUCCESS) { + fprintf(stderr, "ERROR: fixture set-up failed (rc=%d)\n", rc); + fixture_cleanup(); + CCSP_Message_Bus_Exit(g_bus); + return 1; + } + +#ifdef CORD_ENABLED + printf("Mode : CORD\n"); +#else + printf("Mode : non-CORD\n"); +#endif + printf("Iterations : %llu per API\n\n", (unsigned long long)iterations); + printf("%-26s %14s\n", "API", "Avg (ms)"); + fflush(stdout); + + int failed_any = 0; + for (size_t i = 0; i < sizeof(k_bench) / sizeof(k_bench[0]); i++) { + stats_t st; + memset(&st, 0, sizeof(st)); + k_bench[i].fn(iterations, &st); + + if (st.ok > 0) + printf("%-26s %14.6f\n", k_bench[i].name, + (double)st.total_ns / (double)st.ok / 1e6); + else + printf("%-26s %14s\n", k_bench[i].name, "n/a"); + fflush(stdout); + + if (st.fails > 0) { + fprintf(stderr, "WARNING: %s: %llu of %llu calls failed (excluded from average)\n", + k_bench[i].name, (unsigned long long)st.fails, + (unsigned long long)(st.ok + st.fails)); + failed_any = 1; + } + } + + fixture_cleanup(); + CCSP_Message_Bus_Exit(g_bus); + return failed_any ? 2 : 0; +} From 3a40d2d437e5e43eacf65c5d4330f60034b499d4 Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Thu, 29 Oct 2026 10:17:09 +0000 Subject: [PATCH 38/39] feat(psm): add -f option and delete failure diagnostic to speed test Add -f to psm_api_speed_test to print the failed call count per API. The option may appear before or after the iteration count. Report the first failing PSM_Del_Record return code, with the return code of the preceding PSM_Set_Record_Value2, to stderr. This helps diagnose the delete failures seen in non-CORD builds. --- source/psm_api_speed_test.c | 49 ++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/source/psm_api_speed_test.c b/source/psm_api_speed_test.c index 645d90ee7..7b8c8f3d8 100644 --- a/source/psm_api_speed_test.c +++ b/source/psm_api_speed_test.c @@ -18,7 +18,9 @@ */ /* - * psm_api_speed_test [iterations] + * psm_api_speed_test [-f] [iterations] + * + * -f also prints the failed call count per API. * * Measures the average latency of each PSM helper API in libccsp_common. * The same source is built for CORD and non-CORD images (CORD_ENABLED is set @@ -163,12 +165,19 @@ static void bench_group_get(uint64_t n, stats_t *st) static void bench_del_record(uint64_t n, stats_t *st) { + int reported = 0; + for (uint64_t i = 0; i < n; i++) { /* Re-create the record so every delete has something to remove. */ - PSM_Set_Record_Value2(g_bus, SUBSYS, KEY_DEL, ccsp_string, STR_VALUE); + int set_rc = PSM_Set_Record_Value2(g_bus, SUBSYS, KEY_DEL, ccsp_string, STR_VALUE); uint64_t t0 = now_ns(); int rc = PSM_Del_Record(g_bus, SUBSYS, KEY_DEL); uint64_t t1 = now_ns(); + if (rc != CCSP_SUCCESS && !reported) { + fprintf(stderr, "PSM_Del_Record: first failure rc=%d (preceding set rc=%d)\n", + rc, set_rc); + reported = 1; + } stats_add(st, t1 - t0, rc); } } @@ -277,14 +286,23 @@ int main(int argc, char *argv[]) { static char component_id[] = COMPONENT_ID; uint64_t iterations = DEFAULT_ITERATIONS; + int show_fails = 0; + int have_iters = 0; int rc; - if (argc > 2 || (argc == 2 && parse_iterations(argv[1], &iterations) != 0)) { - fprintf(stderr, - "Usage: %s [iterations]\n" - " iterations: positive integer (default %llu)\n", - argv[0], DEFAULT_ITERATIONS); - return 1; + for (int a = 1; a < argc; a++) { + if (strcmp(argv[a], "-f") == 0) { + show_fails = 1; + } else if (!have_iters && parse_iterations(argv[a], &iterations) == 0) { + have_iters = 1; + } else { + fprintf(stderr, + "Usage: %s [-f] [iterations]\n" + " -f also print the failed call count per API\n" + " iterations: positive integer (default %llu)\n", + argv[0], DEFAULT_ITERATIONS); + return 1; + } } rc = CCSP_Message_Bus_Init(component_id, CCSP_MSG_BUS_CFG, &g_bus, NULL, NULL); @@ -307,20 +325,27 @@ int main(int argc, char *argv[]) printf("Mode : non-CORD\n"); #endif printf("Iterations : %llu per API\n\n", (unsigned long long)iterations); - printf("%-26s %14s\n", "API", "Avg (ms)"); + if (show_fails) + printf("%-26s %14s %10s\n", "API", "Avg (ms)", "Failed"); + else + printf("%-26s %14s\n", "API", "Avg (ms)"); fflush(stdout); int failed_any = 0; for (size_t i = 0; i < sizeof(k_bench) / sizeof(k_bench[0]); i++) { stats_t st; + char avg[32]; memset(&st, 0, sizeof(st)); k_bench[i].fn(iterations, &st); if (st.ok > 0) - printf("%-26s %14.6f\n", k_bench[i].name, - (double)st.total_ns / (double)st.ok / 1e6); + snprintf(avg, sizeof(avg), "%.6f", (double)st.total_ns / (double)st.ok / 1e6); else - printf("%-26s %14s\n", k_bench[i].name, "n/a"); + snprintf(avg, sizeof(avg), "n/a"); + printf("%-26s %14s", k_bench[i].name, avg); + if (show_fails) + printf(" %10llu", (unsigned long long)st.fails); + printf("\n"); fflush(stdout); if (st.fails > 0) { From df059acde7043f1ee2393042dc4de7421330a8fd Mon Sep 17 00:00:00 2001 From: madhukrishnasmenon-comcast Date: Fri, 30 Oct 2026 09:29:18 +0000 Subject: [PATCH 39/39] bug(psm): use psmcli default prefix in speed test The empty subsystem prefix makes PSM_Del_Record fail on the device (rc 102), while the psmcli default "eRT." prefix succeeds. Use "eRT." for all benchmark calls so set, get and delete target the same endpoint. --- source/psm_api_speed_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/psm_api_speed_test.c b/source/psm_api_speed_test.c index 7b8c8f3d8..52f5b4327 100644 --- a/source/psm_api_speed_test.c +++ b/source/psm_api_speed_test.c @@ -45,7 +45,8 @@ #define DEFAULT_ITERATIONS 1000000ULL #define COMPONENT_ID "com.cisco.spvtg.ccsp.psm.apispeedtest" -#define SUBSYS "" +/* Matches psmcli's default prefix; the empty prefix makes PSM_Del_Record fail. */ +#define SUBSYS "eRT." #define PERF_ROOT "dmsb.perftest." #define KEY_STR PERF_ROOT "StringParam"