diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a764beb7..1177b2736 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,20 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [1.3.5](https://github.com/rdkcentral/tr69hostif/compare/1.3.4...1.3.5) + +- RDKEMW-14726: Implement Chrony runtime selection for Time Sync [`#385`](https://github.com/rdkcentral/tr69hostif/pull/385) +- Add the datamodel entries in generic [`#384`](https://github.com/rdkcentral/tr69hostif/pull/384) +- RDKEMW-14685 : Implement Product Class Data Model Parameter for RDKE [`#373`](https://github.com/rdkcentral/tr69hostif/pull/373) +- Merge tag '1.3.4' into develop [`600330e`](https://github.com/rdkcentral/tr69hostif/commit/600330e89cfdb20e35a188cd31ef260b76de21c5) + #### [1.3.4](https://github.com/rdkcentral/tr69hostif/compare/1.3.3...1.3.4) +> 3 March 2026 + - RDKEMW-14761 - Add RFC to control wifi-optimizer [`#371`](https://github.com/rdkcentral/tr69hostif/pull/371) - RDK-60924 : Addition of RFC parameter for Stage video devices [`#367`](https://github.com/rdkcentral/tr69hostif/pull/367) +- tr69hostif 1.3.4 release changelog updates [`ab04119`](https://github.com/rdkcentral/tr69hostif/commit/ab04119c9521f7aa4cbed1b40a875e5ccf33c615) - Merge tag '1.3.3' into develop [`d4a740b`](https://github.com/rdkcentral/tr69hostif/commit/d4a740b7b59527c3b744271da7e10fd3864b8ae9) #### [1.3.3](https://github.com/rdkcentral/tr69hostif/compare/1.3.2...1.3.3) diff --git a/src/hostif/handlers/src/hostIf_TimeClient_ReqHandler.cpp b/src/hostif/handlers/src/hostIf_TimeClient_ReqHandler.cpp index 42abb9877..e51a2b6a6 100644 --- a/src/hostif/handlers/src/hostIf_TimeClient_ReqHandler.cpp +++ b/src/hostif/handlers/src/hostIf_TimeClient_ReqHandler.cpp @@ -127,6 +127,37 @@ int TimeClientReqHandler::handleSetMsg(HOSTIF_MsgData_t *stMsgData) { ret = pIface->set_Device_Time_Enable(stMsgData); } + else if (strcasecmp(stMsgData->paramName,"Device.Time.ChronyEnable") == 0) + { + ret = pIface->set_Device_Time_Chrony_Enable(stMsgData); + } + + else if (strcasecmp(stMsgData->paramName,"Device.Time.NTPMinpoll") == 0) + { + ret = pIface->set_Device_Time_NTPMinpoll(stMsgData); + } + else if (strcasecmp(stMsgData->paramName,"Device.Time.NTPMaxpoll") == 0) + { + ret = pIface->set_Device_Time_NTPMaxpoll(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, "Device.Time.NTPServer1Directive") == 0) { + ret = pIface->set_Device_Time_NTPServer1Directive(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, "Device.Time.NTPServer2Directive") == 0) { + ret = pIface->set_Device_Time_NTPServer2Directive(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, "Device.Time.NTPServer3Directive") == 0) { + ret = pIface->set_Device_Time_NTPServer3Directive(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, "Device.Time.NTPServer4Directive") == 0) { + ret = pIface->set_Device_Time_NTPServer4Directive(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, "Device.Time.NTPServer5Directive") == 0) { + ret = pIface->set_Device_Time_NTPServer5Directive(stMsgData); + } + else if (strcasecmp(stMsgData->paramName,"Device.Time.NTPMaxstep") == 0) { + ret = pIface->set_Device_Time_NTPMaxstep(stMsgData); + } else { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s:%d] parameter : \'%s\' Not handled \n", __FUNCTION__, __FILE__, __LINE__, stMsgData->paramName); @@ -230,7 +261,38 @@ int TimeClientReqHandler::handleGetMsg(HOSTIF_MsgData_t *stMsgData) else if (strcasecmp(stMsgData->paramName, "Device.Time.X_RDK_CurrentUTCTime") == 0) { ret = pIface->get_Device_Time_CurrentUTCTime(stMsgData); + } + else if (strcasecmp(stMsgData->paramName,"Device.Time.ChronyEnable") == 0) + { + ret = pIface->get_Device_Time_Chrony_Enable(stMsgData); + } + + else if (strcasecmp(stMsgData->paramName,"Device.Time.NTPMinpoll") == 0) + { + ret = pIface->get_Device_Time_NTPMinpoll(stMsgData); + } + else if (strcasecmp(stMsgData->paramName,"Device.Time.NTPMaxpoll") == 0) + { + ret = pIface->get_Device_Time_NTPMaxpoll(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, "Device.Time.NTPServer1Directive") == 0) { + ret = pIface->get_Device_Time_NTPServer1Directive(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, "Device.Time.NTPServer2Directive") == 0) { + ret = pIface->get_Device_Time_NTPServer2Directive(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, "Device.Time.NTPServer3Directive") == 0) { + ret = pIface->get_Device_Time_NTPServer3Directive(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, "Device.Time.NTPServer4Directive") == 0) { + ret = pIface->get_Device_Time_NTPServer4Directive(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, "Device.Time.NTPServer5Directive") == 0) { + ret = pIface->get_Device_Time_NTPServer5Directive(stMsgData); } + else if (strcasecmp(stMsgData->paramName,"Device.Time.NTPMaxstep") == 0) { + ret = pIface->get_Device_Time_NTPMaxstep(stMsgData); + } else { RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s:%d] parameter : \'%s\' Not handled \n", __FUNCTION__, __FILE__, __LINE__, stMsgData->paramName); diff --git a/src/hostif/handlers/src/hostIf_WiFi_ReqHandler.cpp b/src/hostif/handlers/src/hostIf_WiFi_ReqHandler.cpp index 1b4be8168..e6200bfb3 100644 --- a/src/hostif/handlers/src/hostIf_WiFi_ReqHandler.cpp +++ b/src/hostif/handlers/src/hostIf_WiFi_ReqHandler.cpp @@ -255,9 +255,9 @@ int WiFiReqHandler::handleGetMsg(HOSTIF_MsgData_t *stMsgData) const char *pSetting; const int maxSSID_Instances = 1; int instanceNum = 0; + int radioIndex = 1; #ifdef RDKV_TR69 const int maxRadioInstances = 1; - int radioIndex = 1; if (strcasecmp(stMsgData->paramName,"Device.WiFi.RadioNumberOfEntries") == 0) { stMsgData->instanceNum = maxRadioInstances; @@ -327,6 +327,43 @@ int WiFiReqHandler::handleGetMsg(HOSTIF_MsgData_t *stMsgData) } ret = pIface->get_Device_WiFi_EnableWiFi(stMsgData); } + #ifndef RDKV_TR69 + else if (matchComponent(stMsgData->paramName, "Device.WiFi.Radio", &pSetting, instanceNum)) + { + if (instanceNum != 1) + { + return NOK; + } + + stMsgData->instanceNum = instanceNum; + hostIf_WiFi_Radio *pWifiRadio = hostIf_WiFi_Radio::getInstance(stMsgData->instanceNum); + hostIf_WiFi_Radio_Stats *pWifiRadioStats = hostIf_WiFi_Radio_Stats::getInstance(stMsgData->instanceNum); + + if ((!pWifiRadio) || (!pWifiRadioStats)) + { + return NOK; + } + + if (strcasecmp(pSetting,"OperatingChannelBandwidth") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_OperatingChannelBandwidth(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.PacketsReceived") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_PacketsReceived(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.Noise") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_NoiseFloor(stMsgData,radioIndex); + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%d] Parameter : \'%s\' is Not Supported \n", __FUNCTION__, __LINE__, stMsgData->paramName); + stMsgData->faultCode = fcInvalidParameterName; + ret = NOK; + } + } + #endif #ifdef RDKV_TR69 else if (matchComponent(stMsgData->paramName, "Device.WiFi.Radio", &pSetting, instanceNum)) { diff --git a/src/hostif/parodusClient/waldb/data-model/data-model-generic.xml b/src/hostif/parodusClient/waldb/data-model/data-model-generic.xml index 9b6f54db1..48be368d0 100755 --- a/src/hostif/parodusClient/waldb/data-model/data-model-generic.xml +++ b/src/hostif/parodusClient/waldb/data-model/data-model-generic.xml @@ -63,6 +63,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/hostif/parodusClient/waldb/data-model/data-model-stb.xml b/src/hostif/parodusClient/waldb/data-model/data-model-stb.xml index 5b6255946..083a4b73c 100644 --- a/src/hostif/parodusClient/waldb/data-model/data-model-stb.xml +++ b/src/hostif/parodusClient/waldb/data-model/data-model-stb.xml @@ -415,6 +415,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/hostif/parodusClient/waldb/data-model/data-model-tv.xml b/src/hostif/parodusClient/waldb/data-model/data-model-tv.xml index a4ea79a7c..4206e5adb 100644 --- a/src/hostif/parodusClient/waldb/data-model/data-model-tv.xml +++ b/src/hostif/parodusClient/waldb/data-model/data-model-tv.xml @@ -463,6 +463,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/hostif/profiles/Time/Device_Time.cpp b/src/hostif/profiles/Time/Device_Time.cpp index 22a7af457..e1e5f2cbd 100644 --- a/src/hostif/profiles/Time/Device_Time.cpp +++ b/src/hostif/profiles/Time/Device_Time.cpp @@ -48,8 +48,25 @@ #include #include "Device_Time.h" #include "safec_lib.h" +#include +#include +#include +#include +#include +#include +#include #define TIME_ZONE_LENGTH 8 +#define CHRONY_ENABLE_FILE "/opt/secure/RFC/chrony/chronyd_enabled" +#define NTP_MINPOLL_FILE "/opt/secure/RFC/chrony/ntp_minpoll" +#define NTP_MAXPOLL_FILE "/opt/secure/RFC/chrony/ntp_maxpoll" +#define NTP_SERVER1_DIRECTIVE_FILE "/opt/secure/RFC/chrony/ntp_server1_directive" +#define NTP_SERVER2_DIRECTIVE_FILE "/opt/secure/RFC/chrony/ntp_server2_directive" +#define NTP_SERVER3_DIRECTIVE_FILE "/opt/secure/RFC/chrony/ntp_server3_directive" +#define NTP_SERVER4_DIRECTIVE_FILE "/opt/secure/RFC/chrony/ntp_server4_directive" +#define NTP_SERVER5_DIRECTIVE_FILE "/opt/secure/RFC/chrony/ntp_server5_directive" +#define NTP_MAXSTEP_FILE "/opt/secure/RFC/chrony/ntp_maxstep" +#define NTP_MAXSTEP_DEFAULT "1.0,3" GHashTable* hostIf_Time::ifHash = NULL; GMutex hostIf_Time::m_mutex; @@ -224,6 +241,7 @@ int hostIf_Time::get_Device_Time_NTPServer5(HOSTIF_MsgData_t *, bool *pChanged ) return NOK; } + int hostIf_Time::get_Device_Time_CurrentLocalTime(HOSTIF_MsgData_t *stMsgData, bool *pChanged ) { time_t rawtime; @@ -333,5 +351,385 @@ int hostIf_Time::get_Device_Time_CurrentUTCTime(HOSTIF_MsgData_t *stMsgData, boo return OK; } +int hostIf_Time::set_Device_Time_Chrony_Enable(HOSTIF_MsgData_t *stMsgData, bool *pChanged) +{ + std::string chronyEnableStr = getStringValue(stMsgData); + + // If the value is empty, remove the file + if (chronyEnableStr.empty() || chronyEnableStr == "false" || chronyEnableStr == "0") { + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, + "[%s:%s:%d] Chrony Enable set to false/empty, removing the file %s\n", + __FUNCTION__, __FILE__, __LINE__, + CHRONY_ENABLE_FILE); + + if (std::remove(CHRONY_ENABLE_FILE) != 0) { + if (errno != ENOENT) { // Only log if it's not "file not found" + RDK_LOG(RDK_LOG_WARN, LOG_TR69HOSTIF, + "[%s:%s:%d] Failed to remove %s: %s\n", + __FUNCTION__, __FILE__, __LINE__, + CHRONY_ENABLE_FILE, strerror(errno)); + } + } + if (pChanged) *pChanged = true; + return OK; + } + + // Only allow "true" or "1" to enable + if (chronyEnableStr == "true" || chronyEnableStr == "1") { + const char* chronyDir = "/opt/secure/RFC/chrony"; + if (mkdir(chronyDir, 0755) != 0 && errno != EEXIST) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%s:%d] Failed to create %s: %s\n", + __FUNCTION__, __FILE__, __LINE__, + chronyDir, strerror(errno)); + return NOK; + } + std::ofstream file(CHRONY_ENABLE_FILE); + if (!file.is_open()) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%s:%d] Failed to open %s for writing\n", + __FUNCTION__, __FILE__, __LINE__, CHRONY_ENABLE_FILE); + return NOK; + } + file << "true"; // Always write "true" if enabling + file.close(); + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, + "[%s:%s:%d] Successfully enabled Chrony\n", __FUNCTION__, __FILE__, __LINE__); + if (pChanged) *pChanged = true; + return OK; + } + + // Unrecognized value + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%s:%d] Invalid Chrony Enable value: %s\n", + __FUNCTION__, __FILE__, __LINE__, chronyEnableStr.c_str()); + return NOK; +} + +int hostIf_Time::get_Device_Time_Chrony_Enable(HOSTIF_MsgData_t *stMsgData, bool *pChanged) +{ + stMsgData->paramtype = hostIf_BooleanType; + + if (access(CHRONY_ENABLE_FILE, F_OK) == 0) { + put_boolean(stMsgData->paramValue, true); + } else { + put_boolean(stMsgData->paramValue, false); + } + + stMsgData->paramLen = sizeof(bool); + + if (pChanged) *pChanged = false; + return OK; +} + + +// Get handler for NTPMinpoll +int hostIf_Time::get_Device_Time_NTPMinpoll(HOSTIF_MsgData_t *stMsgData, bool *pChanged) +{ + stMsgData->paramtype = hostIf_UnsignedIntType; + + unsigned int minpoll = 10; // Default value + std::ifstream file(NTP_MINPOLL_FILE); + if (file.is_open()) { + std::string value; + std::getline(file, value); + file.close(); + if (!value.empty()) { + try { + minpoll = static_cast(std::stoul(value)); + } catch (const std::exception&) { + minpoll = 10; + } + } + } + + put_uint(stMsgData->paramValue, minpoll); + stMsgData->paramLen = sizeof(unsigned int); + + if (pChanged) *pChanged = false; + return OK; +} + +// Set handler for NTPMinpoll +int hostIf_Time::set_Device_Time_NTPMinpoll(HOSTIF_MsgData_t *stMsgData, bool *pChanged) +{ + const char* chronyDir = "/opt/secure/RFC/chrony"; + if (mkdir(chronyDir, 0755) != 0 && errno != EEXIST) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%s:%d] Failed to create %s: %s\n", + __FUNCTION__, __FILE__, __LINE__, + chronyDir, strerror(errno)); + return NOK; + } + + std::string minpollStr = getStringValue(stMsgData); + + // Validate that minpollStr is a number in a valid range [4, 17] for NTP + int minpoll = atoi(minpollStr.c_str()); + if (minpoll < 4 || minpoll > 24) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%s:%d] Invalid NTPMinpoll value: %s\n", + __FUNCTION__, __FILE__, __LINE__, minpollStr.c_str()); + return NOK; + } + + std::ofstream file(NTP_MINPOLL_FILE); + if (!file.is_open()) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%s:%d] Failed to open %s for writing\n", + __FUNCTION__, __FILE__, __LINE__, NTP_MINPOLL_FILE); + return NOK; + } + file << minpollStr; + file.close(); + + if (pChanged) *pChanged = true; + return OK; +} + + +// Get handler for NTPMaxpoll +int hostIf_Time::get_Device_Time_NTPMaxpoll(HOSTIF_MsgData_t *stMsgData, bool *pChanged) +{ + stMsgData->paramtype = hostIf_UnsignedIntType; + + unsigned int maxpoll = 12; // Default if file is empty or missing (NTP typical maxpoll default) + + std::ifstream file(NTP_MAXPOLL_FILE); + if (file.is_open()) { + std::string value; + std::getline(file, value); + file.close(); + + if (!value.empty()) { + maxpoll = static_cast(atoi(value.c_str())); + } + } + + put_uint(stMsgData->paramValue, maxpoll); + stMsgData->paramLen = sizeof(unsigned int); + if (pChanged) *pChanged = false; + return OK; +} + +// Set handler for NTPMaxpoll +int hostIf_Time::set_Device_Time_NTPMaxpoll(HOSTIF_MsgData_t *stMsgData, bool *pChanged) +{ + const char* chronyDir = "/opt/secure/RFC/chrony"; + if (mkdir(chronyDir, 0755) != 0 && errno != EEXIST) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%s:%d] Failed to create %s: %s\n", + __FUNCTION__, __FILE__, __LINE__, + chronyDir, strerror(errno)); + return NOK; + } + + std::string maxpollStr = getStringValue(stMsgData); + + // Validate maxpoll in NTP allowed range [4,24] + int maxpoll = atoi(maxpollStr.c_str()); + if (maxpoll < 4 || maxpoll > 24) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%s:%d] Invalid NTPMaxpoll value: %s\n", + __FUNCTION__, __FILE__, __LINE__, maxpollStr.c_str()); + return NOK; + } + + std::ofstream file(NTP_MAXPOLL_FILE); + if (!file.is_open()) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%s:%d] Failed to open %s for writing\n", + __FUNCTION__, __FILE__, __LINE__, NTP_MAXPOLL_FILE); + return NOK; + } + file << maxpollStr; + file.close(); + + if (pChanged) *pChanged = true; + return OK; +} + + +int hostIf_Time::get_Device_Time_NTPServer1Directive(HOSTIF_MsgData_t *stMsgData, bool *pChanged) +{ + stMsgData->paramtype = hostIf_StringType; + std::ifstream file(NTP_SERVER1_DIRECTIVE_FILE); + std::string value; + + if (file.is_open()) { + std::getline(file, value); + file.close(); + } + if (value.empty()) { + value = "server"; + } + strncpy(stMsgData->paramValue, value.c_str(), sizeof(stMsgData->paramValue)-1); + stMsgData->paramValue[sizeof(stMsgData->paramValue)-1] = '\0'; + stMsgData->paramLen = strlen(stMsgData->paramValue); + + if (pChanged) *pChanged = false; + return OK; +} + +int hostIf_Time::set_Device_Time_NTPServer1Directive(HOSTIF_MsgData_t *stMsgData, bool *pChanged) +{ + std::string directive = getStringValue(stMsgData); + std::ofstream file(NTP_SERVER1_DIRECTIVE_FILE); + if (!file.is_open()) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%s:%d] Failed to open %s for writing: %s\n", + __FUNCTION__, __FILE__, __LINE__, + NTP_SERVER1_DIRECTIVE_FILE, strerror(errno)); + return NOK; + } + file << directive; + file.close(); + + if (pChanged) *pChanged = true; + return OK; +} + +int hostIf_Time::get_Device_Time_NTPServer2Directive(HOSTIF_MsgData_t *stMsgData, bool *pChanged) { + stMsgData->paramtype = hostIf_StringType; + std::ifstream file(NTP_SERVER2_DIRECTIVE_FILE); + std::string value; + if (file.is_open()) { + std::getline(file, value); + file.close(); + } + if (value.empty()) value = "server"; + strncpy(stMsgData->paramValue, value.c_str(), sizeof(stMsgData->paramValue)-1); + stMsgData->paramValue[sizeof(stMsgData->paramValue)-1] = '\0'; + stMsgData->paramLen = strlen(stMsgData->paramValue); + if (pChanged) *pChanged = false; + return OK; +} + +int hostIf_Time::set_Device_Time_NTPServer2Directive(HOSTIF_MsgData_t *stMsgData, bool *pChanged) { + std::string directive = getStringValue(stMsgData); + std::ofstream file(NTP_SERVER2_DIRECTIVE_FILE); + if (!file.is_open()) return NOK; + file << directive; + file.close(); + if (pChanged) *pChanged = true; + return OK; +} + +int hostIf_Time::get_Device_Time_NTPServer3Directive(HOSTIF_MsgData_t *stMsgData, bool *pChanged) { + stMsgData->paramtype = hostIf_StringType; + std::ifstream file(NTP_SERVER3_DIRECTIVE_FILE); + std::string value; + if (file.is_open()) { + std::getline(file, value); + file.close(); + } + if (value.empty()) value = "server"; + strncpy(stMsgData->paramValue, value.c_str(), sizeof(stMsgData->paramValue)-1); + stMsgData->paramValue[sizeof(stMsgData->paramValue)-1] = '\0'; + stMsgData->paramLen = strlen(stMsgData->paramValue); + if (pChanged) *pChanged = false; + return OK; +} + +int hostIf_Time::set_Device_Time_NTPServer3Directive(HOSTIF_MsgData_t *stMsgData, bool *pChanged) { + std::string directive = getStringValue(stMsgData); + std::ofstream file(NTP_SERVER3_DIRECTIVE_FILE); + if (!file.is_open()) return NOK; + file << directive; + file.close(); + if (pChanged) *pChanged = true; + return OK; +} + +int hostIf_Time::get_Device_Time_NTPServer4Directive(HOSTIF_MsgData_t *stMsgData, bool *pChanged) { + stMsgData->paramtype = hostIf_StringType; + std::ifstream file(NTP_SERVER4_DIRECTIVE_FILE); + std::string value; + if (file.is_open()) { + std::getline(file, value); + file.close(); + } + if (value.empty()) value = "server"; + strncpy(stMsgData->paramValue, value.c_str(), sizeof(stMsgData->paramValue)-1); + stMsgData->paramValue[sizeof(stMsgData->paramValue)-1] = '\0'; + stMsgData->paramLen = strlen(stMsgData->paramValue); + if (pChanged) *pChanged = false; + return OK; +} + +int hostIf_Time::set_Device_Time_NTPServer4Directive(HOSTIF_MsgData_t *stMsgData, bool *pChanged) { + std::string directive = getStringValue(stMsgData); + std::ofstream file(NTP_SERVER4_DIRECTIVE_FILE); + if (!file.is_open()) return NOK; + file << directive; + file.close(); + if (pChanged) *pChanged = true; + return OK; +} + +int hostIf_Time::get_Device_Time_NTPServer5Directive(HOSTIF_MsgData_t *stMsgData, bool *pChanged) { + stMsgData->paramtype = hostIf_StringType; + std::ifstream file(NTP_SERVER5_DIRECTIVE_FILE); + std::string value; + if (file.is_open()) { + std::getline(file, value); + file.close(); + } + if (value.empty()) value = "server"; + strncpy(stMsgData->paramValue, value.c_str(), sizeof(stMsgData->paramValue)-1); + stMsgData->paramValue[sizeof(stMsgData->paramValue)-1] = '\0'; + stMsgData->paramLen = strlen(stMsgData->paramValue); + if (pChanged) *pChanged = false; + return OK; +} + +int hostIf_Time::set_Device_Time_NTPServer5Directive(HOSTIF_MsgData_t *stMsgData, bool *pChanged) { + std::string directive = getStringValue(stMsgData); + std::ofstream file(NTP_SERVER5_DIRECTIVE_FILE); + if (!file.is_open()) return NOK; + file << directive; + file.close(); + if (pChanged) *pChanged = true; + return OK; +} + +int hostIf_Time::get_Device_Time_NTPMaxstep(HOSTIF_MsgData_t *stMsgData, bool *pChanged) +{ + stMsgData->paramtype = hostIf_StringType; + std::ifstream file(NTP_MAXSTEP_FILE); + std::string value; + if (file.is_open()) { + std::getline(file, value); + file.close(); + } + if (value.empty()) + value = NTP_MAXSTEP_DEFAULT; + strncpy(stMsgData->paramValue, value.c_str(), sizeof(stMsgData->paramValue) - 1); + stMsgData->paramValue[sizeof(stMsgData->paramValue) - 1] = '\0'; + stMsgData->paramLen = strlen(stMsgData->paramValue); + if (pChanged) *pChanged = false; + return OK; +} + +int hostIf_Time::set_Device_Time_NTPMaxstep(HOSTIF_MsgData_t *stMsgData, bool *pChanged) +{ + std::string input = getStringValue(stMsgData); + + //Format - makestep 1.0 3 + size_t comma = input.find(','); + if (comma == std::string::npos) { + stMsgData->faultCode = fcInvalidParameterValue; + return NOK; + } + // Optional: check number formats - left as exercise for stricter validation + + std::ofstream file(NTP_MAXSTEP_FILE, std::ios::trunc); + if (!file.is_open()) + return NOK; + file << input; + file.close(); + if (pChanged) *pChanged = true; + return OK; +} /** @} */ /** @} */ diff --git a/src/hostif/profiles/Time/Device_Time.h b/src/hostif/profiles/Time/Device_Time.h index 7fc5cd481..f03dd4cf3 100644 --- a/src/hostif/profiles/Time/Device_Time.h +++ b/src/hostif/profiles/Time/Device_Time.h @@ -142,6 +142,7 @@ class hostIf_Time { static XBSStore *m_bsStore; int dev_id; + bool bCalledLocalTimeZone; bool bCalledCurrentLocalTime; @@ -276,6 +277,25 @@ class hostIf_Time { */ int get_Device_Time_CurrentLocalTime(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + int get_Device_Time_Chrony_Enable(HOSTIF_MsgData_t *,bool *pChanged = NULL); + + int get_Device_Time_NTPMinpoll(HOSTIF_MsgData_t *,bool *pChanged = NULL); + + int get_Device_Time_NTPMaxpoll(HOSTIF_MsgData_t *,bool *pChanged = NULL); + + int get_Device_Time_NTPServer1Directive(HOSTIF_MsgData_t*, bool* pChanged = NULL); + + int get_Device_Time_NTPServer2Directive(HOSTIF_MsgData_t*, bool* pChanged = NULL); + + int get_Device_Time_NTPServer3Directive(HOSTIF_MsgData_t*, bool* pChanged = NULL); + + int get_Device_Time_NTPServer4Directive(HOSTIF_MsgData_t*, bool* pChanged = NULL); + + int get_Device_Time_NTPServer5Directive(HOSTIF_MsgData_t*, bool* pChanged = NULL); + + int get_Device_Time_NTPMaxstep(HOSTIF_MsgData_t *stMsgData, bool *pChanged = NULL); + /** * @brief Get the local time zone definition. @@ -419,6 +439,24 @@ class hostIf_Time { */ int set_xRDKCentralComBootstrap(HOSTIF_MsgData_t *); + int set_Device_Time_Chrony_Enable(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + int set_Device_Time_NTPMinpoll(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + int set_Device_Time_NTPMaxpoll(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + int set_Device_Time_NTPServer1Directive(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + int set_Device_Time_NTPServer2Directive(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + int set_Device_Time_NTPServer3Directive(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + int set_Device_Time_NTPServer4Directive(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + int set_Device_Time_NTPServer5Directive(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + int set_Device_Time_NTPMaxstep(HOSTIF_MsgData_t *stMsgData, bool *pChanged = NULL); + /** * @brief Get the bootstrap parameters. * @@ -435,6 +473,7 @@ class hostIf_Time { */ int get_Device_Time_CurrentUTCTime(HOSTIF_MsgData_t *, bool *pChanged = NULL); + #if defined(GTEST_ENABLE) FRIEND_TEST(TimeTest, releaseLock); diff --git a/src/hostif/profiles/wifi/Device_WiFi_EndPoint.cpp b/src/hostif/profiles/wifi/Device_WiFi_EndPoint.cpp index 72dfd8c58..628d76742 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_EndPoint.cpp +++ b/src/hostif/profiles/wifi/Device_WiFi_EndPoint.cpp @@ -344,7 +344,7 @@ int hostIf_WiFi_EndPoint::refreshCache() std::string postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetWifiState\"}"; string response = getJsonRPCData(std::move(postData)); - if(response.c_str()) + if(!response.empty()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); cJSON* root = cJSON_Parse(response.c_str()); @@ -355,19 +355,58 @@ int hostIf_WiFi_EndPoint::refreshCache() if (jsonObj) { cJSON *interfaces = cJSON_GetObjectItem(jsonObj, "interfaces"); - cJSON *interface = nullptr, *interfaceType; - for (int i = 0; i < cJSON_GetArraySize(interfaces); i++) { + cJSON *interface = nullptr, *interfaceType = nullptr; + + if (!cJSON_IsArray(interfaces)) + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] WifiState result missing interfaces array\n", __FUNCTION__); + cJSON_Delete(root); + return NOK; + } + + for (int i = 0; i < cJSON_GetArraySize(interfaces); i++) { interface = cJSON_GetArrayItem(interfaces, i); + if (!cJSON_IsObject(interface)) { + interface = nullptr; + continue; + } interfaceType = cJSON_GetObjectItem(interface, "type"); - if (strcmp(interfaceType->valuestring, "WIFI") == 0) + if (cJSON_IsString(interfaceType) && interfaceType->valuestring && (strcmp(interfaceType->valuestring, "WIFI") == 0)) break; + interface = nullptr; } + if (!interface) + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] WIFI interface not found\n", __FUNCTION__); + cJSON_Delete(root); + return NOK; + } + //ASSIGN TO OP HERE cJSON *result = cJSON_GetObjectItem(interface, "enabled"); - Enable = result->type; + if (cJSON_IsBool(result)) + { + Enable = cJSON_IsTrue(result); + } + else if (cJSON_IsNumber(result)) + { + Enable = (0 != result->valueint); + } + else + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] WIFI interface missing valid enabled field\n", __FUNCTION__); + cJSON_Delete(root); + return NOK; + } cJSON *state = cJSON_GetObjectItem(jsonObj, "state"); + if (!cJSON_IsNumber(state)) + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] WifiState result missing numeric state\n", __FUNCTION__); + cJSON_Delete(root); + return NOK; + } int res = state->valueint; switch (res) { case 0: @@ -412,6 +451,9 @@ int hostIf_WiFi_EndPoint::refreshCache() case 13: strncpy(Status, "ERROR", BUFF_LENGTH_64); break; + default: + strncpy(Status, "ERROR", BUFF_LENGTH_64); + break; } } else @@ -430,14 +472,14 @@ int hostIf_WiFi_EndPoint::refreshCache() } else { - RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: curl init failed\n", __FUNCTION__); + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: getJsonRPCData() failed or returned empty response\n", __FUNCTION__); return NOK; } postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetConnectedSSID\"}"; response = getJsonRPCData(postData); - if(response.c_str()) + if(!response.empty()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); cJSON* root = cJSON_Parse(response.c_str()); @@ -448,6 +490,12 @@ int hostIf_WiFi_EndPoint::refreshCache() if (jsonObj) { cJSON *ssid = cJSON_GetObjectItem(jsonObj, "ssid"); + if (!(cJSON_IsString(ssid) && ssid->valuestring)) + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] ConnectedSSID result missing valid ssid\n", __FUNCTION__); + cJSON_Delete(root); + return NOK; + } //ASSIGN TO OP HERE strncpy (SSIDReference, ssid->valuestring, BUFF_LENGTH_256); SSIDReference[BUFF_LENGTH_256 - 1] = '\0'; @@ -468,14 +516,14 @@ int hostIf_WiFi_EndPoint::refreshCache() } else { - RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: curl init failed\n", __FUNCTION__); + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: getJsonRPCData() failed or returned empty response\n", __FUNCTION__); return NOK; } postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetWiFiSignalStrength\"}"; response = getJsonRPCData(std::move(postData)); - if(response.c_str()) + if(!response.empty()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); cJSON* root = cJSON_Parse(response.c_str()); @@ -486,6 +534,12 @@ int hostIf_WiFi_EndPoint::refreshCache() if (jsonObj) { cJSON *sigstr = cJSON_GetObjectItem(jsonObj, "signalStrength"); + if (!cJSON_IsNumber(sigstr)) + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] GetWiFiSignalStrength result missing numeric signalStrength\n", __FUNCTION__); + cJSON_Delete(root); + return NOK; + } //ASSIGN TO OP HERE stats.SignalStrength = sigstr->valueint; } @@ -505,7 +559,7 @@ int hostIf_WiFi_EndPoint::refreshCache() } else { - RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: curl init failed\n", __FUNCTION__); + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: getJsonRPCData() failed or returned empty response\n", __FUNCTION__); return NOK; } diff --git a/src/hostif/profiles/wifi/Device_WiFi_Radio.cpp b/src/hostif/profiles/wifi/Device_WiFi_Radio.cpp index affca9375..0cc888fa3 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_Radio.cpp +++ b/src/hostif/profiles/wifi/Device_WiFi_Radio.cpp @@ -155,9 +155,103 @@ hostIf_WiFi_Radio::hostIf_WiFi_Radio(int dev_id): memset(TransmitPowerSupported, 0, sizeof(TransmitPowerSupported)); memset(RegulatoryDomain, 0, sizeof(RegulatoryDomain)); } -#ifdef RDKV_NM + +static int wifi_getRadioOperatingChannelBandwidth(int radioIndex, char *output_buffer, size_t output_buffer_size) +{ + char resultBuff[64]; + char cmd[64]; + char interfaceName[10] = "wlan0"; + int bandWidth = 0; + FILE *fp = NULL; + int ret = NOK; + bool iw_info_failed = false; + char *bandwidth_string = NULL; + char *bandwidth_token = NULL; + bool bandwidth_found = false; + + if (!output_buffer) + return ret; + + memset(cmd, 0, sizeof(cmd)); + memset(resultBuff, 0, sizeof(resultBuff)); + + snprintf(cmd, sizeof(cmd), "iw dev %s info | grep channel | cut -f 2 -d ','", interfaceName); + + if (NULL != (fp = popen(cmd,"r"))) + { + if ((fgets(resultBuff, sizeof (resultBuff), fp) != NULL) && (resultBuff[0] != '\0')) + { + sscanf(resultBuff,"%*s%d%*s", &bandWidth); /* Expected output :- " width: 80 MHz" */ + if (bandWidth != 0) + { + snprintf(output_buffer, output_buffer_size, "%dMHz", bandWidth); + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "OperatingChannelBandwidth = %s\n", output_buffer); + ret = OK; + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Failure in getting bandwidth \n"); + } + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Unable to read Channel width from iw \n"); + iw_info_failed = true; + } + pclose(fp); + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "popen() failed. failure in getting Channel Bandwidth\n"); + iw_info_failed = true; + } + + if (iw_info_failed) // iw info fallback + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "iw info command failed, fall back to iw link command\n"); + + memset(cmd, 0, sizeof(cmd)); + memset(resultBuff, 0, sizeof(resultBuff)); + + snprintf(cmd, sizeof(cmd), "iw dev %s link | grep tx", interfaceName); + + if (NULL != (fp = popen(cmd,"r"))) + { + if ((fgets(resultBuff, sizeof (resultBuff), fp) != NULL) && (resultBuff[0] != '\0')) + { + char *resultBuff_P = resultBuff; + while ((bandwidth_string = strtok_r(resultBuff_P, " ", &resultBuff_P))) + { + bandwidth_token = strcasestr(bandwidth_string, "MHz"); + if (NULL != bandwidth_token) + { + snprintf(output_buffer, output_buffer_size, "%s", bandwidth_string); + bandwidth_found = true; + break; + } + } + if (!bandwidth_found) + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "MHz information missing in iw link o/p \n"); + snprintf(output_buffer, output_buffer_size, "%s", "20MHz"); // assume 20MHz + } + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "OperatingChannelBandwidth = %s\n", output_buffer); + ret = OK; + } + else + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Failure in getting bandwidth \n"); + + pclose(fp); + } + else + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "popen() failed. failure in getting Channel Bandwidth\n"); + } + return ret; +} + int hostIf_WiFi_Radio::get_Device_WiFi_Radio_Props_Fields(int radioIndex) { +#ifdef RDKV_NM IARM_Result_t retVal = IARM_RESULT_SUCCESS; IARM_BUS_WiFi_DiagsPropParam_t param = {0}; int ret; @@ -208,22 +302,40 @@ int hostIf_WiFi_Radio::get_Device_WiFi_Radio_Props_Fields(int radioIndex) RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s]Error! Unable to connect to wifi instance\n", __FILE__, __FUNCTION__); return NOK; } +#else + hostIf_WiFi_Radio *pDev = hostIf_WiFi_Radio::getInstance(dev_id); + if (pDev) + { +// snprintf(OperatingChannelBandwidth, BUFF_MIN_16, "80MHz"); + wifi_getRadioOperatingChannelBandwidth(0, OperatingChannelBandwidth, sizeof (OperatingChannelBandwidth)); + // TODO: what's this for? + radioFirstExTime = time (NULL); + return OK; + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s]Error! Unable to connect to wifi instance\n", __FILE__, __FUNCTION__); + return NOK; + } +#endif } void hostIf_WiFi_Radio::checkWifiRadioFetch(int radioIndex) { - int retVal=NOK; + int retVal = NOK; time_t currExTime = time (NULL); - if((currExTime - radioFirstExTime ) > QUERY_INTERVAL) + if ((currExTime - radioFirstExTime) > QUERY_INTERVAL) { retVal = get_Device_WiFi_Radio_Props_Fields(radioIndex); - if( OK != retVal) + if (OK != retVal) { RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Failed to fetch : %d.\n", __FILE__, __FUNCTION__, retVal); } } } +#ifdef RDKV_NM + int hostIf_WiFi_Radio::get_Device_WiFi_Radio_Enable(HOSTIF_MsgData_t *stMsgData,int radioIndex ) { @@ -465,6 +577,8 @@ int hostIf_WiFi_Radio::get_Device_WiFi_Radio_ChannelsInUse(HOSTIF_MsgData_t *stM return OK; } +#endif + int hostIf_WiFi_Radio::get_Device_WiFi_Radio_OperatingChannelBandwidth(HOSTIF_MsgData_t *stMsgData,int radioIndex ) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); @@ -476,6 +590,8 @@ int hostIf_WiFi_Radio::get_Device_WiFi_Radio_OperatingChannelBandwidth(HOSTIF_Ms return OK; } +#ifdef RDKV_NM + int hostIf_WiFi_Radio::get_Device_WiFi_Radio_ExtensionChannel(HOSTIF_MsgData_t *stMsgData,int radioIndex ) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); diff --git a/src/hostif/profiles/wifi/Device_WiFi_Radio.h b/src/hostif/profiles/wifi/Device_WiFi_Radio.h index 348bb690b..340a547a8 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_Radio.h +++ b/src/hostif/profiles/wifi/Device_WiFi_Radio.h @@ -118,10 +118,8 @@ class hostIf_WiFi_Radio { static GList* getAllAssociateDevs(); static void closeInstance(hostIf_WiFi_Radio *); static void closeAllInstances(); - #ifdef RDKV_NM int get_Device_WiFi_Radio_Props_Fields(int radioIndex); void checkWifiRadioFetch(int radioIndex); - #endif bool Enable; char Status[BUFF_LENGTH_64]; char Alias[BUFF_LENGTH_64]; diff --git a/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.cpp b/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.cpp index 5fa032b7f..dd9bafcbe 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.cpp +++ b/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.cpp @@ -44,9 +44,7 @@ extern "C" { #endif GHashTable* hostIf_WiFi_Radio_Stats::ifHash = NULL; -#ifdef RDKV_NM static time_t radioFirstExTime = 0; -#endif hostIf_WiFi_Radio_Stats *hostIf_WiFi_Radio_Stats::getInstance(int dev_id) { @@ -119,9 +117,123 @@ hostIf_WiFi_Radio_Stats::hostIf_WiFi_Radio_Stats(int dev_id): } -#ifdef RDKV_NM +static bool getNoise(int &noise_value) +{ + char cmd[50]; + snprintf(cmd, sizeof(cmd), "wpa_cli -i wlan0 signal_poll"); + + FILE *fp = popen(cmd, "r"); + if (NULL == fp) + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Error in popen() : signal_poll failed \n"); + return false; + } + + char line[256]; + char noise[64] = { 0 }; + + while (fgets(line, sizeof(line), fp)) + { + if (strncmp(line, "NOISE=", 6) == 0) + { + strncpy(noise, line + 6, sizeof(noise) - 1); + // Strip trailing newline if present + size_t len = strlen(noise); + if (len > 0 && noise[len - 1] == '\n') + noise[len - 1] = '\0'; + } + } + pclose(fp); + + if (noise[0] == '\0') + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "NOISE not found in signal_poll.\n"); + return false; + } + + noise_value = atoi(noise); + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "\n noise = %d ", noise_value); + + return true; +} + +struct wifi_radioTrafficStats_t +{ + unsigned long bytesSent; + unsigned long bytesReceived; + unsigned long packetsSent; + unsigned long packetsReceived; + unsigned int errorsSent; + unsigned int errorsReceived; + unsigned int discardPacketsSent; + unsigned int discardPacketsReceived; +}; + +static int wifi_getRadioTrafficStats(int radioIndex, wifi_radioTrafficStats_t *output_struct) +{ + FILE *fp = NULL; + char resultBuff[256]; + char cmd[50]; + char interfaceName[10] = "wlan0"; + long long int rx_bytes = 0,rx_packets = 0,rx_err = 0,rx_drop = 0; + long long int tx_bytes = 0,tx_packets = 0,tx_err = 0,tx_drop = 0; + int numParams = 0; + + if (!output_struct) + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "output struct is null"); + return NOK; + } + + memset(resultBuff, 0, sizeof(resultBuff)); + memset(cmd, 0, sizeof(cmd)); + + snprintf(cmd, sizeof(cmd), "cat /proc/net/dev | grep %s", interfaceName); + + if (NULL != (fp = popen(cmd, "r"))) + { + if (fgets(resultBuff, sizeof (resultBuff), fp) != NULL) + { + numParams = sscanf(resultBuff, " %[^:]: %lld %lld %lld %lld %*u %*u %*u %*u %lld %lld %lld %lld %*u %*u %*u %*u", + interfaceName, + &rx_bytes, &rx_packets, &rx_err, &rx_drop, + &tx_bytes, &tx_packets, &tx_err, &tx_drop); + if (numParams != 9) + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Error in parsing Radio Stats params \n"); + + output_struct->packetsSent = tx_packets; + output_struct->packetsReceived = rx_packets; + output_struct->bytesSent = tx_bytes; + output_struct->bytesReceived = rx_bytes; + output_struct->errorsReceived = rx_err; + output_struct->errorsSent = tx_err; + output_struct->discardPacketsSent = tx_drop; + output_struct->discardPacketsReceived = rx_drop; + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, + "[tx_packets = %lld] [rx_packets = %lld] " + "[tx_bytes = %lld] [rx_bytes = %lld] " + "[rx_err = %lld] [tx_err = %lld] " + "[tx_drop = %lld] [rx_drop = %lld] \n", + tx_packets, rx_packets, tx_bytes, rx_bytes, + rx_err, tx_err, tx_drop, rx_drop); + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Error in reading /proc/net/dev file \n"); + } + pclose(fp); + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Error in popen() : Opening /proc/net/dev failed \n"); + } + + return OK; +} + int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_Props_Fields(int radioIndex) { +#ifdef RDKV_NM IARM_Result_t retVal = IARM_RESULT_SUCCESS; IARM_BUS_WiFi_DiagsPropParam_t param = {0}; int ret; @@ -153,6 +265,33 @@ int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_Props_Fields(int radioI RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s]Error! Unable to connect to wifi instance\n", __FILE__, __FUNCTION__); return NOK; } +#else + hostIf_WiFi_Radio_Stats *pDev = hostIf_WiFi_Radio_Stats::getInstance(dev_id); + if (pDev) + { + int noise; + wifi_radioTrafficStats_t stats = {0}; + wifi_getRadioTrafficStats(0, &stats); + + BytesSent = stats.bytesSent; + BytesReceived = stats.bytesReceived; + PacketsSent = stats.packetsSent; + PacketsReceived = stats.packetsReceived; + ErrorsSent = stats.errorsSent; + ErrorsReceived = stats.errorsReceived; + DiscardPacketsSent = stats.discardPacketsSent; + DiscardPacketsReceived = stats.discardPacketsReceived; + NoiseFloor = getNoise(noise) ? noise : 0; + + radioFirstExTime = time (NULL); + return OK; + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s]Error! Unable to connect to wifi instance\n", __FILE__, __FUNCTION__); + return NOK; + } +#endif } @@ -170,6 +309,8 @@ void hostIf_WiFi_Radio_Stats::checkWifiRadioPropsFetch(int radioIndex) } } +#ifdef RDKV_NM + int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_BytesSent(HOSTIF_MsgData_t *stMsgData,int radioIndex ) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); @@ -205,6 +346,8 @@ int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_PacketsSent(HOSTIF_MsgD return OK; } +#endif + int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_PacketsReceived(HOSTIF_MsgData_t *stMsgData,int radioIndex ) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); @@ -216,6 +359,8 @@ int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_PacketsReceived(HOSTIF_ return OK; } +#ifdef RDKV_NM + int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_ErrorsSent(HOSTIF_MsgData_t *stMsgData,int radioIndex ) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); @@ -259,6 +404,9 @@ int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_DiscardPacketsReceived( RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); return OK; } + +#endif + int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_NoiseFloor(HOSTIF_MsgData_t *stMsgData,int radioIndex ) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); @@ -269,6 +417,5 @@ int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_NoiseFloor(HOSTIF_MsgDa RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); return OK; } -#endif #endif /* #ifdef USE_WIFI_PROFILE */ diff --git a/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.h b/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.h index 876286d76..97cdd3c09 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.h +++ b/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.h @@ -76,10 +76,8 @@ class hostIf_WiFi_Radio_Stats { static GList* getAllAssociateDevs(); static void closeInstance(hostIf_WiFi_Radio_Stats *); static void closeAllInstances(); - #ifdef RDKV_NM int get_Device_WiFi_Radio_Stats_Props_Fields(int radioIndex); void checkWifiRadioPropsFetch(int radioIndex); - #endif unsigned long BytesSent; unsigned long BytesReceived; @@ -89,7 +87,7 @@ class hostIf_WiFi_Radio_Stats { unsigned int ErrorsReceived; unsigned int DiscardPacketsSent; unsigned int DiscardPacketsReceived; - unsigned int NoiseFloor; + int NoiseFloor; /** * @ingroup TR69_HOSTIF_WIFI_RADIO_STAT