From 95978bdc41b351b723b0fc8f30df85aed6898da9 Mon Sep 17 00:00:00 2001 From: Thamim Razith Date: Thu, 21 Nov 2024 23:40:08 +0000 Subject: [PATCH] DELIA-66222,DELIA-66509: onAvailableSSIDs event not functioning correctly in the WiFi plugin Reason for change: Added the SsidList & frequency filter logic during WifiStartScan Test Procedure: Verify in custom build Risks: None Signed-off-by: Thamim Razith tabbas651@cable.comcast.com --- LegacyPlugin_WiFiManagerAPIs.cpp | 27 +++++++++++++- NetworkManagerGnomeEvents.cpp | 2 +- NetworkManagerGnomeProxy.cpp | 26 ++++++++++++- NetworkManagerImplementation.cpp | 63 +++++++++++++++++++++++++++++++- NetworkManagerImplementation.h | 8 +++- NetworkManagerJsonRpc.cpp | 43 +++++++++++++++++++++- NetworkManagerRDKProxy.cpp | 29 ++++++++++++--- 7 files changed, 184 insertions(+), 14 deletions(-) diff --git a/LegacyPlugin_WiFiManagerAPIs.cpp b/LegacyPlugin_WiFiManagerAPIs.cpp index 5dada6b2..6b3df3fe 100644 --- a/LegacyPlugin_WiFiManagerAPIs.cpp +++ b/LegacyPlugin_WiFiManagerAPIs.cpp @@ -546,9 +546,31 @@ namespace WPEFramework { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - string frequency = parameters["frequency"].String(); + string frequency{}; Exchange::INetworkManager::IStringIterator* ssids = NULL; + + if (parameters.HasLabel("frequency")) + { + frequency = parameters["frequency"].String(); + NMLOG_INFO("Received frequency string : %s", frequency.c_str()); + } + else + { + NMLOG_INFO("No frequency provided. Proceeding without frequency filtering."); + } + + if (parameters.HasLabel("ssid")) + { + string tmpssid = parameters["ssid"].String(); + NMLOG_INFO("Provided SSID value : %s", tmpssid.c_str()); + ssids = (Core::Service::Create(tmpssid)); + } + else + { + NMLOG_INFO("No SSIDs provided. Proceeding without SSID filtering."); + } + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); if (_nwmgr) { @@ -558,6 +580,9 @@ namespace WPEFramework else rc = Core::ERROR_UNAVAILABLE; + if (ssids) + ssids->Release(); + returnJson(rc); } diff --git a/NetworkManagerGnomeEvents.cpp b/NetworkManagerGnomeEvents.cpp index 56e94be4..4c39ff2b 100644 --- a/NetworkManagerGnomeEvents.cpp +++ b/NetworkManagerGnomeEvents.cpp @@ -634,7 +634,7 @@ namespace WPEFramework if(_nmEventInstance->doScanNotify) { _nmEventInstance->doScanNotify = false; - _instance->ReportAvailableSSIDs(ssidListJson); + _instance->ReportAvailableSSIDs(ssidList); } } diff --git a/NetworkManagerGnomeProxy.cpp b/NetworkManagerGnomeProxy.cpp index bf8b66bd..66fdf674 100644 --- a/NetworkManagerGnomeProxy.cpp +++ b/NetworkManagerGnomeProxy.cpp @@ -650,10 +650,32 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::StartWiFiScan(const string& frequency /* @in */, IStringIterator* const ssids/* @in */) { uint32_t rc = Core::ERROR_RPC_CALL_FAILED; - (void) ssids; + + //Cleared the Existing Store filterred SSID list + scanForSsidslist.clear(); + + if(ssids) + { + string tmpssidlist{}; + while (ssids->Next(tmpssidlist) == true) + { + scanForSsidslist.push_back(tmpssidlist.c_str()); + } + } + + if (frequency.empty()) + { + NMLOG_INFO("No frequency provided. Proceeding without frequency filtering."); + scanForFreq.clear(); + } + else + { + scanForFreq = frequency; + NMLOG_INFO("Frequency set for scanning: %s", scanForFreq.c_str()); + } nmEvent->setwifiScanOptions(true); - if(wifi->wifiScanRequest(frequency)) + if(wifi->wifiScanRequest(scanForFreq)) rc = Core::ERROR_NONE; return rc; } diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index 7da44a9e..ed11c6eb 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -488,6 +488,61 @@ namespace WPEFramework return; } + + void NetworkManagerImplementation::filterScanResults(JsonArray &ssids) + { + JsonArray result; + double inputFreq = 0.0; + std::unordered_set scanForSsidsSet(scanForSsidslist.begin(), scanForSsidslist.end()); + + NMLOG_INFO("User Provided Frequency: %s\n", scanForFreq.c_str()); + + // If neither SSID list nor frequency is provided, exit + if (scanForSsidslist.empty() && scanForFreq.empty()) + { + NMLOG_INFO("Neither SSID nor Frequency is provided. Exiting function."); + return; + } + + // Convert user-provided scanForFreq to double for comparison + if (!scanForFreq.empty()) + { + inputFreq = std::stod(scanForFreq); + NMLOG_INFO("Frequency provided: %lf\n", inputFreq); + } + + NMLOG_INFO(" Frequency: %s\n", scanForFreq.c_str()); + + for (int i = 0; i < ssids.Length(); i++) + { + JsonObject object = ssids[i].Object(); + string ssid = object["ssid"].String(); + string frequency = object["frequency"].String(); + + NMLOG_INFO("Processing SSID: %s, Frequency: %s\n", ssid.c_str(), frequency.c_str()); + + double frequencyValue = std::stod(frequency); + + //Debug to print log + NMLOG_INFO("Processing Frequency after double conversion: %lf\n", frequencyValue); + + bool ssidMatches = scanForSsidsSet.empty() || scanForSsidsSet.find(ssid) != scanForSsidsSet.end(); + bool freqMatches = scanForFreq.empty() || (inputFreq == frequencyValue); + + if (ssidMatches && freqMatches) + { + result.Add(object); + NMLOG_INFO("Match found: SSID = %s, Frequency = %lf\n", ssid.c_str(), frequencyValue); + } + else + { + NMLOG_INFO("No match: SSID = %s, Frequency = %lf\n", ssid.c_str(), frequencyValue); + } + } + ssids = result; + NMLOG_INFO("Filtered %d SSIDs.", ssids.Length()); + } + // WiFi Specific Methods /* @brief Initiate a WIFI Scan; This is Async method and returns the scan results as Event */ uint32_t NetworkManagerImplementation::GetSupportedSecurityModes(ISecurityModeIterator*& securityModes /* @out */) const @@ -570,9 +625,15 @@ namespace WPEFramework _notificationLock.Unlock(); } - void NetworkManagerImplementation::ReportAvailableSSIDs(const string jsonOfWiFiScanResults) + void NetworkManagerImplementation::ReportAvailableSSIDs(JsonArray &arrayofWiFiScanResults) { _notificationLock.Lock(); + + string jsonOfWiFiScanResults; + filterScanResults(arrayofWiFiScanResults); + + arrayofWiFiScanResults.ToString(jsonOfWiFiScanResults); + NMLOG_INFO("Posting onAvailableSSIDs result is, %s", jsonOfWiFiScanResults.c_str()); for (const auto callback : _notificationCallbacks) { callback->onAvailableSSIDs(jsonOfWiFiScanResults); diff --git a/NetworkManagerImplementation.h b/NetworkManagerImplementation.h index d6ae934c..00b1402c 100644 --- a/NetworkManagerImplementation.h +++ b/NetworkManagerImplementation.h @@ -218,7 +218,7 @@ namespace WPEFramework void ReportActiveInterfaceChange(const string prevActiveInterface, const string currentActiveinterface); void ReportIPAddressChange(const string interface, const string ipversion, const string ipaddress, const Exchange::INetworkManager::IPStatus status); void ReportInternetStatusChange(const Exchange::INetworkManager::InternetStatus prevState, const Exchange::INetworkManager::InternetStatus currState); - void ReportAvailableSSIDs(const string jsonOfScanResults); + void ReportAvailableSSIDs(JsonArray &arrayofWiFiScanResults); void ReportWiFiStateChange(const Exchange::INetworkManager::WiFiState state); void ReportWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality); @@ -227,6 +227,7 @@ namespace WPEFramework void retryIarmEventRegistration(); void threadEventRegistration(); void executeExternally(NetworkEvents event, const string commandToExecute, string& response); + void filterScanResults(JsonArray &ssids); private: std::list _notificationCallbacks; @@ -239,7 +240,10 @@ namespace WPEFramework uint16_t m_stunBindTimeout; uint16_t m_stunCacheTimeout; std::thread m_registrationThread; - public: + string scanForFreq; + std::vector scanForSsidslist; + + public: WiFiSignalStrengthMonitor m_wifiSignalMonitor; mutable ConnectivityMonitor connectivityMonitor; }; diff --git a/NetworkManagerJsonRpc.cpp b/NetworkManagerJsonRpc.cpp index 5557e498..047d68f3 100644 --- a/NetworkManagerJsonRpc.cpp +++ b/NetworkManagerJsonRpc.cpp @@ -670,14 +670,53 @@ namespace WPEFramework { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - string frequency = parameters["frequency"].String(); - Exchange::INetworkManager::IStringIterator* ssids = NULL; + string frequency{}; + Exchange::INetworkManager::IStringIterator* ssids = NULL; + + if (parameters.HasLabel("frequency")) + { + frequency = parameters["frequency"].String(); + NMLOG_INFO("Received frequency string : %s", frequency.c_str()); + } + else + { + NMLOG_INFO("No frequency provided. Proceeding without frequency filtering."); + } + + if (parameters.HasLabel("ssids")) + { + JsonArray array = parameters["ssids"].Array(); + std::vector tmpssidslist; + JsonArray::Iterator index(array.Elements()); + + while (index.Next() == true) + { + if (Core::JSON::Variant::type::STRING == index.Current().Content()) + { + tmpssidslist.push_back(index.Current().String().c_str()); + } + else + { + NMLOG_DEBUG("Unexpected variant type in SSID array."); + returnJson(rc); + } + } + ssids = (Core::Service::Create(tmpssidslist)); + } + else + { + NMLOG_INFO("No SSIDs provided. Proceeding without SSID filtering."); + } if (_networkManager) rc = _networkManager->StartWiFiScan(frequency, ssids); else rc = Core::ERROR_UNAVAILABLE; + if (ssids) + ssids->Release(); + + returnJson(rc); } diff --git a/NetworkManagerRDKProxy.cpp b/NetworkManagerRDKProxy.cpp index 8099a3cc..0eca56e8 100644 --- a/NetworkManagerRDKProxy.cpp +++ b/NetworkManagerRDKProxy.cpp @@ -505,10 +505,8 @@ namespace WPEFramework } JsonArray ssids = eventDocument["getAvailableSSIDs"].Array(); - string json; - ssids.ToString(json); - ::_instance->ReportAvailableSSIDs(json); + ::_instance->ReportAvailableSSIDs(ssids); break; } case IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged: @@ -1027,8 +1025,29 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { IARM_Bus_WiFiSrvMgr_SsidList_Param_t param; IARM_Result_t retVal = IARM_RESULT_SUCCESS; - (void)ssids; - (void) frequency; + //Cleared the Existing Store filterred SSID list + scanForSsidslist.clear(); + + if(ssids) + { + string tmpssidlist{}; + while (ssids->Next(tmpssidlist) == true) + { + scanForSsidslist.push_back(tmpssidlist.c_str()); + NMLOG_INFO("SSID added to scanForSsidslist: %s", tmpssidlist.c_str()); + } + } + + if (frequency.empty()) + { + NMLOG_INFO("No frequency provided. Proceeding without frequency filtering."); + scanForFreq.clear(); + } + else + { + scanForFreq = frequency; + NMLOG_INFO("Frequency set for scanning: %s", scanForFreq.c_str()); + } memset(¶m, 0, sizeof(param));