From f85092556b9ec9eb67cfe0925f711ff0d5df299f Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Tue, 10 Feb 2026 17:53:34 +0530 Subject: [PATCH 01/23] Initial code change --- interface/INetworkManager.h | 2 + plugin/gnome/NetworkManagerGnomeProxy.cpp | 73 +++++++++++++++++++---- plugin/gnome/NetworkManagerGnomeUtils.cpp | 34 +++++++++++ plugin/gnome/NetworkManagerGnomeUtils.h | 2 + plugin/gnome/NetworkManagerGnomeWIFI.cpp | 22 ++++++- 5 files changed, 118 insertions(+), 15 deletions(-) diff --git a/interface/INetworkManager.h b/interface/INetworkManager.h index a3097d7a..867f5800 100644 --- a/interface/INetworkManager.h +++ b/interface/INetworkManager.h @@ -113,6 +113,8 @@ namespace WPEFramework struct EXTERNAL WiFiConnectTo { string ssid; string passphrase; + string bssid; + string frequency; WIFISecurityMode security; string ca_cert; string client_cert; diff --git a/plugin/gnome/NetworkManagerGnomeProxy.cpp b/plugin/gnome/NetworkManagerGnomeProxy.cpp index 85326d63..7c6951d6 100644 --- a/plugin/gnome/NetworkManagerGnomeProxy.cpp +++ b/plugin/gnome/NetworkManagerGnomeProxy.cpp @@ -922,27 +922,74 @@ namespace WPEFramework { uint32_t rc = Core::ERROR_GENERAL; - // Check the last scanning time and if it exceeds 5 sec do a rescanning - if(!wifi->isWifiScannedRecently()) + if(!ssid.ssid.empty() && ssid.ssid.size() > 32) { - nmEvent->setwifiScanOptions(false); - if(!wifi->wifiScanRequest()) - NMLOG_WARNING("scanning failed but try to connect"); + NMLOG_WARNING("SSID is invalid"); + return Core::ERROR_NONE; } - - if(ssid.ssid.empty() && _instance != NULL) + else if(ssid.ssid.empty()) { - NMLOG_WARNING("ssid is empty activating last connectd ssid !"); - if(wifi->activateKnownConnection(nmUtils::wlanIface(), _instance->m_lastConnectedSSID)) + if(_instance != NULL && !_instance->m_lastConnectedSSID.empty()) + { + NMLOG_WARNING("There is no last connected ssid available"); rc = Core::ERROR_NONE; + } + else + { + NMLOG_WARNING("ssid is empty activating last connectd ssid !"); + if(wifi->activateKnownConnection(nmUtils::wlanIface(), _instance->m_lastConnectedSSID)) + rc = Core::ERROR_NONE; + else + NMLOG_ERROR("activating last connected ssid failed"); + } + + return rc; } - else if(ssid.ssid.size() <= 32) + else if(!ssid.ssid.empty() && (ssid.security == WIFI_SECURITY_NONE) && ssid.passphrase.empty()) { - if(wifi->wifiConnect(ssid)) + NMLOG_INFO("Only SSID: %s, so activating know connection", ssid.ssid.c_str()); + + // TODO: 1 find how to find this is open network request of activate known connection, + // because for open network ssid is only required field, + // so if passphrase is empty and security is none then it is open network request + + // TODO: 2 do we need to persisit same ssid multiple connection + + if(wifi->activateKnownConnection(nmUtils::wlanIface(), ssid.ssid)) rc = Core::ERROR_NONE; + else + NMLOG_ERROR("activating last connected ssid failed"); + + return rc; } - else - NMLOG_WARNING("SSID is invalid"); + + // Gnome will not accept passphrase less than 8 char for WPA/WPA2 security + if(!ssid.passphrase.empty() && ssid.passphrase.size() < 8) + { + NMLOG_ERROR("Passphrase is invalid"); + return Core::ERROR_GENERAL; + } + + if(!nmUtils::isValidBSSID(ssid.bssid)) + { + return Core::ERROR_GENERAL; + } + + if(!nmUtils::isValidFrequency(ssid.frequency)) + { + return Core::ERROR_GENERAL; + } + + // Check the last scanning time and if it exceeds 5 sec do a rescanning + if(!wifi->isWifiScannedRecently()) + { + nmEvent->setwifiScanOptions(false); + if(!wifi->wifiScanRequest()) + NMLOG_WARNING("scanning failed but try to connect"); + } + + if(wifi->wifiConnect(ssid)) + rc = Core::ERROR_NONE; return rc; } diff --git a/plugin/gnome/NetworkManagerGnomeUtils.cpp b/plugin/gnome/NetworkManagerGnomeUtils.cpp index 3910b6c3..e35f25ef 100644 --- a/plugin/gnome/NetworkManagerGnomeUtils.cpp +++ b/plugin/gnome/NetworkManagerGnomeUtils.cpp @@ -180,6 +180,40 @@ namespace WPEFramework return securityStr; } + bool nmUtils::isValidBSSID(const std::string& bssid) + { + if (bssid.empty()) + return true; // BSSID is optional for connection, so empty value is considered valid + + // Regular expression to match valid BSSID formats (e.g., "00:11:22:33:44:55") + const std::regex bssidRegex("^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$"); + if (!std::regex_match(bssid, bssidRegex)) + { + NMLOG_ERROR("Invalid BSSID format: %s. Expected format is XX:XX:XX:XX:XX:XX where X is a hexadecimal digit.", bssid.c_str()); + return false; + } + + return true; + } + + bool nmUtils::isValidFrequency(const std::string& frequency) + { + if (frequency.empty()) + return true; // Frequency is optional for connection, so empty value is considered valid + + // 6 GHz frequency is not supported in current implementation gnom networkmanger + if(frequency == "2.4" || frequency == "5") + { + NMLOG_DEBUG("Valid frequency: %s", frequency.c_str()); + return true; + } + else + { + NMLOG_ERROR("Invalid frequency: %s. Valid values are 2.4, 5 GHz.", frequency.c_str()); + } + return false; + } + std::string nmUtils::wifiFrequencyFromAp(guint32 apFreq) { std::string freq; diff --git a/plugin/gnome/NetworkManagerGnomeUtils.h b/plugin/gnome/NetworkManagerGnomeUtils.h index aab7daf0..0dba08e8 100644 --- a/plugin/gnome/NetworkManagerGnomeUtils.h +++ b/plugin/gnome/NetworkManagerGnomeUtils.h @@ -50,6 +50,8 @@ namespace WPEFramework static bool isInterfaceEnabled(const std::string& interface); static bool writePersistentHostname(const std::string& hostname); static bool readPersistentHostname(std::string& hostname); + static bool isValidFrequency(const std::string& frequency); + static bool isValidBSSID(const std::string& bssid); }; } } diff --git a/plugin/gnome/NetworkManagerGnomeWIFI.cpp b/plugin/gnome/NetworkManagerGnomeWIFI.cpp index c1cbdfcb..fc000d11 100644 --- a/plugin/gnome/NetworkManagerGnomeWIFI.cpp +++ b/plugin/gnome/NetworkManagerGnomeWIFI.cpp @@ -651,8 +651,26 @@ namespace WPEFramework g_object_set(G_OBJECT(sWireless), NM_SETTING_WIRELESS_HIDDEN, true, NULL); // hidden = true if(ssid) g_bytes_unref(ssid); - // 'bssid' parameter is used to restrict the connection only to the BSSID - // g_object_set(s_wifi, NM_SETTING_WIRELESS_BSSID, bssid, NULL); + + if(!ssidinfo.bssid.empty()) + g_object_set(sWireless, NM_SETTING_WIRELESS_BSSID, ssidinfo.bssid, NULL); + + if(!ssidinfo.frequency.empty()) + { + if(ssidinfo.frequency == "2.4") + { + g_object_set(sWireless, NM_SETTING_WIRELESS_BAND, "bg", NULL); + } + else if(ssidinfo.frequency == "5") + { + g_object_set(sWireless, NM_SETTING_WIRELESS_BAND, "a", NULL); + } + else + { + NMLOG_WARNING("invalid frequency value: %s", ssidinfo.frequency.c_str()); + return false; + } + } NMSettingWirelessSecurity *sSecurity = NULL; switch(ssidinfo.security) From 43bc5958f8c91c53cda52b4a09ae017fb09231e2 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Tue, 10 Feb 2026 19:19:10 +0530 Subject: [PATCH 02/23] error fix --- plugin/gnome/NetworkManagerGnomeUtils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/gnome/NetworkManagerGnomeUtils.cpp b/plugin/gnome/NetworkManagerGnomeUtils.cpp index e35f25ef..c303fcac 100644 --- a/plugin/gnome/NetworkManagerGnomeUtils.cpp +++ b/plugin/gnome/NetworkManagerGnomeUtils.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include "Module.h" From 596444990be7932f8b99fe175d7015febc32ba64 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Wed, 11 Feb 2026 13:24:56 +0530 Subject: [PATCH 03/23] jason rpc changes added --- plugin/NetworkManagerJsonRpc.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/NetworkManagerJsonRpc.cpp b/plugin/NetworkManagerJsonRpc.cpp index ff1dd5df..63f3925f 100644 --- a/plugin/NetworkManagerJsonRpc.cpp +++ b/plugin/NetworkManagerJsonRpc.cpp @@ -778,7 +778,12 @@ namespace WPEFramework if (parameters.HasLabel("passphrase")) ssid.passphrase = parameters["passphrase"].String(); - + + if (parameters.HasLabel("bssid")) + ssid.bssid = parameters["bssid"].String(); + if (parameters.HasLabel("frequency")) + ssid.frequency = parameters["frequency"].String(); + if (parameters.HasLabel("security")) ssid.security= static_cast (parameters["security"].Number()); From 74d89f2b0098541bd9a3a295c30d7295e5bf761e Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Wed, 11 Feb 2026 14:52:12 +0530 Subject: [PATCH 04/23] bssid infomation on scanning result --- plugin/gnome/NetworkManagerGnomeEvents.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/gnome/NetworkManagerGnomeEvents.cpp b/plugin/gnome/NetworkManagerGnomeEvents.cpp index dea7c5ef..d0e914df 100644 --- a/plugin/gnome/NetworkManagerGnomeEvents.cpp +++ b/plugin/gnome/NetworkManagerGnomeEvents.cpp @@ -731,7 +731,7 @@ namespace WPEFramework { GBytes *ssid = NULL; int strength = 0; - std::string freq; + std::string freq, bssid; int security; guint32 flags, wpaFlags, rsnFlags, apFreq; if(ap == nullptr) @@ -748,6 +748,7 @@ namespace WPEFramework free(ssidStr); } ssidObj["ssid"] = ssidString; + bssid = nm_access_point_get_bssid(ap); strength = nm_access_point_get_strength(ap); apFreq = nm_access_point_get_frequency(ap); flags = nm_access_point_get_flags(ap); @@ -756,6 +757,7 @@ namespace WPEFramework freq = nmUtils::wifiFrequencyFromAp(apFreq); security = nmUtils::wifiSecurityModeFromAp(ssidString, flags, wpaFlags, rsnFlags, false); + ssidObj["bssid"] = bssid; ssidObj["security"] = security; ssidObj["strength"] = nmUtils::convertPercentageToSignalStrengtStr(strength); ssidObj["frequency"] = freq; From e925d7effecc4e31bf0b55a656875c3e28f47ba4 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Wed, 11 Feb 2026 16:10:21 +0530 Subject: [PATCH 05/23] WIFI CONNECT --- plugin/gnome/NetworkManagerGnomeWIFI.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/gnome/NetworkManagerGnomeWIFI.cpp b/plugin/gnome/NetworkManagerGnomeWIFI.cpp index fc000d11..38ab172c 100644 --- a/plugin/gnome/NetworkManagerGnomeWIFI.cpp +++ b/plugin/gnome/NetworkManagerGnomeWIFI.cpp @@ -653,7 +653,10 @@ namespace WPEFramework g_bytes_unref(ssid); if(!ssidinfo.bssid.empty()) - g_object_set(sWireless, NM_SETTING_WIRELESS_BSSID, ssidinfo.bssid, NULL); + { + NMLOG_INFO("setting bssid: %s", ssidinfo.bssid.c_str()); + g_object_set(sWireless, NM_SETTING_WIRELESS_BSSID, ssidinfo.bssid.c_str(), NULL); + } if(!ssidinfo.frequency.empty()) { @@ -957,7 +960,7 @@ namespace WPEFramework Exchange::INetworkManager::WiFiSSIDInfo apinfo; std::string activeSSID{}; - NMLOG_DEBUG("wifi connect ssid: %s, security %d persist %d", ssidInfoParam.ssid.c_str(), ssidInfoParam.security, ssidInfoParam.persist); + NMLOG_DEBUG("wifi connect ssid: %s, bssid: %s, frequency: %s, security %d, persist %d", ssidInfoParam.ssid.c_str(), ssidInfoParam.bssid.c_str(), ssidInfoParam.frequency.c_str(), ssidInfoParam.security, ssidInfoParam.persist); Exchange::INetworkManager::WiFiConnectTo ssidInfo = ssidInfoParam; m_isSuccess = false; From 0647bb1c318223fbf4e3cf49ea459536a9457a71 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Fri, 13 Feb 2026 15:43:24 +0530 Subject: [PATCH 06/23] updated find matching --- plugin/gnome/NetworkManagerGnomeUtils.cpp | 29 +++++++++ plugin/gnome/NetworkManagerGnomeUtils.h | 1 + plugin/gnome/NetworkManagerGnomeWIFI.cpp | 79 +++++++++++++++++------ 3 files changed, 89 insertions(+), 20 deletions(-) diff --git a/plugin/gnome/NetworkManagerGnomeUtils.cpp b/plugin/gnome/NetworkManagerGnomeUtils.cpp index 3e9f0d25..2dd46e57 100644 --- a/plugin/gnome/NetworkManagerGnomeUtils.cpp +++ b/plugin/gnome/NetworkManagerGnomeUtils.cpp @@ -228,6 +228,35 @@ namespace WPEFramework return false; } + bool nmUtils::isValidWifiFrequencyForBand(std::string& band, guint32 apFreq) + { + if (apFreq != 0) + { + if (band == "a") + { + // frequency range for 5 GHz band is typically 4915 MHz to 5825 MHz + if (apFreq < 4915 || apFreq > 5825) + return false; + else + NMLOG_INFO("Valid 5 GHz frequency: %u MHz", apFreq); // TODO change to debug + } + else if (band == "bg") + { + // frequency range for 2.4 GHz band is typically 2412 MHz to 2484 MHz + if (apFreq < 2412 || apFreq > 2484) + return false; + else + NMLOG_INFO("Valid 2.4 GHz frequency: %u MHz", apFreq); // TODO change to debug + } + else + { + NMLOG_ERROR("Invalid band: %s. Valid values are 'a' for 5 GHz and 'bg' for 2.4 GHz.", band.c_str()); + return false; + } + } + return true; + } + bool nmUtils::caseInsensitiveCompare(const std::string& str1, const std::string& str2) { std::string upperStr1 = str1; diff --git a/plugin/gnome/NetworkManagerGnomeUtils.h b/plugin/gnome/NetworkManagerGnomeUtils.h index c4d4d425..b7d8893d 100644 --- a/plugin/gnome/NetworkManagerGnomeUtils.h +++ b/plugin/gnome/NetworkManagerGnomeUtils.h @@ -52,6 +52,7 @@ namespace WPEFramework static bool readPersistentHostname(std::string& hostname); static bool isValidFrequency(const std::string& frequency); static bool isValidBSSID(const std::string& bssid); + static bool isValidWifiFrequencyForBand(std::string& band, guint32 apFreq); }; } } diff --git a/plugin/gnome/NetworkManagerGnomeWIFI.cpp b/plugin/gnome/NetworkManagerGnomeWIFI.cpp index 6720ded7..d7e26833 100644 --- a/plugin/gnome/NetworkManagerGnomeWIFI.cpp +++ b/plugin/gnome/NetworkManagerGnomeWIFI.cpp @@ -413,37 +413,79 @@ namespace WPEFramework return m_isSuccess; } - static NMAccessPoint* findMatchingSSID(const GPtrArray* ApList, std::string& ssid) + static NMAccessPoint* findMatchingSSID(const GPtrArray* ApList, Exchange::INetworkManager::WiFiConnectTo& ssidInfo) { NMAccessPoint *AccessPoint = nullptr; - if(ssid.empty()) + if(ssidInfo.ssid.empty()) return nullptr; for (guint i = 0; i < ApList->len; i++) { std::string ssidstr{}; + bool ssidMatch = false; NMAccessPoint *ap = static_cast(g_ptr_array_index(ApList, i)); GBytes *ssidGBytes = nm_access_point_get_ssid(ap); - if(ssidGBytes) + if(ssidGBytes == nullptr) { - char* ssidUtf8 = nm_utils_ssid_to_utf8((const guint8*)g_bytes_get_data(ssidGBytes, NULL), g_bytes_get_size(ssidGBytes)); - if(ssidUtf8 != nullptr) + NMLOG_WARNING("hidden ssid found, bssid: %s", nm_access_point_get_bssid(ap)); + // TODO remove log or handle hidden ssid case based on bssid matching if ssidInfo.ssid is empty + continue; + } + + char* ssidUtf8 = nm_utils_ssid_to_utf8((const guint8*)g_bytes_get_data(ssidGBytes, NULL), g_bytes_get_size(ssidGBytes)); + if(ssidUtf8 == nullptr) + { + NMLOG_WARNING("Invalid ssid length Error"); + continue; + } + + ssidstr = ssidUtf8; + free(ssidUtf8); + + if(ssidInfo.ssid == ssidstr) + { + NMLOG_INFO("SSID matched: %s", ssidstr.c_str()); + ssidMatch = true; + } + else + { + NMLOG_WARNING("SSID did not match: expected %s, got %s", ssidInfo.ssid.c_str(), ssidstr.c_str()); + // continue searching other APs in case of multiple APs with same SSID and matching BSSID or frequency + // TODO hidden ssid handling - if ssidInfo.ssid is empty then matching based on bssid ? + continue; + } + + if(!ssidInfo.bssid.empty()) + { + std::string bssidStr = nm_access_point_get_bssid(ap); + if(ssidInfo.bssid == bssidStr) { - ssidstr = ssidUtf8; - if(ssid == ssidstr) - { - AccessPoint = ap; - free(ssidUtf8); - break; - } - // NMLOG_DEBUG("ssid < %s >", ssidstr.c_str()); + NMLOG_INFO("BSSID matched: %s", bssidStr.c_str()); // TODO remove log + ssidMatch = true; } else - NMLOG_WARNING("Invalid ssid length Error"); + { + NMLOG_WARNING("BSSID did not match: expected %s, got %s", ssidInfo.bssid.c_str(), bssidStr.c_str()); + continue; + } + } - if(ssidUtf8 != nullptr) - free(ssidUtf8); + if(!ssidInfo.frequency.empty()) + { + if(nmUtils::isValidWifiFrequencyForBand(ssidInfo.frequency, nm_access_point_get_frequency(ap))) + { + NMLOG_INFO("Frequency matched: %s GHz", ssidInfo.frequency.c_str()); // TODO remove log + ssidMatch = true; + } + else + { + NMLOG_WARNING("Frequency did not match: expected %s GHz, got %s GHz", ssidInfo.frequency.c_str(), ssidInfo.frequency.c_str()); + ssidMatch = false; + } } + + if(ssidMatch) + AccessPoint = ap; } return AccessPoint; @@ -652,10 +694,7 @@ namespace WPEFramework g_bytes_unref(ssid); if(!ssidinfo.bssid.empty()) - { - NMLOG_INFO("setting bssid: %s", ssidinfo.bssid.c_str()); g_object_set(sWireless, NM_SETTING_WIRELESS_BSSID, ssidinfo.bssid.c_str(), NULL); - } if(!ssidinfo.frequency.empty()) { @@ -1000,7 +1039,7 @@ namespace WPEFramework return false; } - AccessPoint = findMatchingSSID(ApList, ssidInfo.ssid); + AccessPoint = findMatchingSSID(ApList, ssidInfo); if(AccessPoint == NULL) { NMLOG_WARNING("SSID '%s' not found !", ssidInfo.ssid.c_str()); From 33792913db952ee88ee867fe928b6e90e12bc7f0 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Fri, 20 Feb 2026 17:02:57 +0530 Subject: [PATCH 07/23] update frequncy to number --- interface/INetworkManager.h | 10 ++++- plugin/NetworkManagerJsonRpc.cpp | 2 +- plugin/gnome/NetworkManagerGnomeProxy.cpp | 8 ++-- plugin/gnome/NetworkManagerGnomeUtils.cpp | 47 ----------------------- plugin/gnome/NetworkManagerGnomeUtils.h | 2 - plugin/gnome/NetworkManagerGnomeWIFI.cpp | 31 +++++---------- 6 files changed, 23 insertions(+), 77 deletions(-) diff --git a/interface/INetworkManager.h b/interface/INetworkManager.h index 16e12ee5..64e815f5 100644 --- a/interface/INetworkManager.h +++ b/interface/INetworkManager.h @@ -103,6 +103,14 @@ namespace WPEFramework WIFI_SECURITY_EAP /* @text: EAP */, }; + enum WIFIFrequency : uint8_t + { + WIFI_FREQUENCY_NONE /* @text: NONE */, + WIFI_FREQUENCY_2_4_GHZ /* @text: 2.4GHz */, + WIFI_FREQUENCY_5_GHZ /* @text: 5GHz */, + WIFI_FREQUENCY_6_GHZ /* @text: 6GHz */, + }; + struct EXTERNAL WiFiScanResults { string ssid; WIFISecurityMode security; @@ -114,7 +122,7 @@ namespace WPEFramework string ssid; string passphrase; string bssid; - string frequency; + WIFIFrequency frequency; WIFISecurityMode security; string ca_cert; string client_cert; diff --git a/plugin/NetworkManagerJsonRpc.cpp b/plugin/NetworkManagerJsonRpc.cpp index 8bc29fb9..c3aa15e9 100644 --- a/plugin/NetworkManagerJsonRpc.cpp +++ b/plugin/NetworkManagerJsonRpc.cpp @@ -782,7 +782,7 @@ namespace WPEFramework if (parameters.HasLabel("bssid")) ssid.bssid = parameters["bssid"].String(); if (parameters.HasLabel("frequency")) - ssid.frequency = parameters["frequency"].String(); + ssid.frequency = static_cast (parameters["frequency"].Number()); if (parameters.HasLabel("security")) ssid.security= static_cast (parameters["security"].Number()); diff --git a/plugin/gnome/NetworkManagerGnomeProxy.cpp b/plugin/gnome/NetworkManagerGnomeProxy.cpp index 7c6951d6..e4c6b1b7 100644 --- a/plugin/gnome/NetworkManagerGnomeProxy.cpp +++ b/plugin/gnome/NetworkManagerGnomeProxy.cpp @@ -638,7 +638,7 @@ namespace WPEFramework deviceState = nm_device_get_state(device); if(deviceState < NM_DEVICE_STATE_DISCONNECTED) { - NMLOG_WARNING("Device state is not a valid state: (%d)", deviceState); + NMLOG_WARNING("%s state is not a valid state: (%d)", interface.c_str(), deviceState); return Core::ERROR_GENERAL; } @@ -975,10 +975,8 @@ namespace WPEFramework return Core::ERROR_GENERAL; } - if(!nmUtils::isValidFrequency(ssid.frequency)) - { - return Core::ERROR_GENERAL; - } + if(ssidinfo.frequency != Exchange::INetworkManager::WIFIFrequency::WIFI_FREQUENCY_NONE) + NMLOG_INFO("Requested frequency is %d GHz", ssidinfo.frequency); // Check the last scanning time and if it exceeds 5 sec do a rescanning if(!wifi->isWifiScannedRecently()) diff --git a/plugin/gnome/NetworkManagerGnomeUtils.cpp b/plugin/gnome/NetworkManagerGnomeUtils.cpp index 2dd46e57..6d9097c5 100644 --- a/plugin/gnome/NetworkManagerGnomeUtils.cpp +++ b/plugin/gnome/NetworkManagerGnomeUtils.cpp @@ -209,53 +209,6 @@ namespace WPEFramework return true; } - - bool nmUtils::isValidFrequency(const std::string& frequency) - { - if (frequency.empty()) - return true; // Frequency is optional for connection, so empty value is considered valid - - // 6 GHz frequency is not supported in current implementation gnom networkmanger - if(frequency == "2.4" || frequency == "5") - { - NMLOG_DEBUG("Valid frequency: %s", frequency.c_str()); - return true; - } - else - { - NMLOG_ERROR("Invalid frequency: %s. Valid values are 2.4, 5 GHz.", frequency.c_str()); - } - return false; - } - - bool nmUtils::isValidWifiFrequencyForBand(std::string& band, guint32 apFreq) - { - if (apFreq != 0) - { - if (band == "a") - { - // frequency range for 5 GHz band is typically 4915 MHz to 5825 MHz - if (apFreq < 4915 || apFreq > 5825) - return false; - else - NMLOG_INFO("Valid 5 GHz frequency: %u MHz", apFreq); // TODO change to debug - } - else if (band == "bg") - { - // frequency range for 2.4 GHz band is typically 2412 MHz to 2484 MHz - if (apFreq < 2412 || apFreq > 2484) - return false; - else - NMLOG_INFO("Valid 2.4 GHz frequency: %u MHz", apFreq); // TODO change to debug - } - else - { - NMLOG_ERROR("Invalid band: %s. Valid values are 'a' for 5 GHz and 'bg' for 2.4 GHz.", band.c_str()); - return false; - } - } - return true; - } bool nmUtils::caseInsensitiveCompare(const std::string& str1, const std::string& str2) { diff --git a/plugin/gnome/NetworkManagerGnomeUtils.h b/plugin/gnome/NetworkManagerGnomeUtils.h index b7d8893d..1264b018 100644 --- a/plugin/gnome/NetworkManagerGnomeUtils.h +++ b/plugin/gnome/NetworkManagerGnomeUtils.h @@ -50,9 +50,7 @@ namespace WPEFramework static bool isInterfaceEnabled(const std::string& interface); static bool writePersistentHostname(const std::string& hostname); static bool readPersistentHostname(std::string& hostname); - static bool isValidFrequency(const std::string& frequency); static bool isValidBSSID(const std::string& bssid); - static bool isValidWifiFrequencyForBand(std::string& band, guint32 apFreq); }; } } diff --git a/plugin/gnome/NetworkManagerGnomeWIFI.cpp b/plugin/gnome/NetworkManagerGnomeWIFI.cpp index d7e26833..f2bcbaa5 100644 --- a/plugin/gnome/NetworkManagerGnomeWIFI.cpp +++ b/plugin/gnome/NetworkManagerGnomeWIFI.cpp @@ -449,7 +449,7 @@ namespace WPEFramework } else { - NMLOG_WARNING("SSID did not match: expected %s, got %s", ssidInfo.ssid.c_str(), ssidstr.c_str()); + NMLOG_DEBUG("SSID did not match: expected %s, got %s", ssidInfo.ssid.c_str(), ssidstr.c_str()); // continue searching other APs in case of multiple APs with same SSID and matching BSSID or frequency // TODO hidden ssid handling - if ssidInfo.ssid is empty then matching based on bssid ? continue; @@ -460,29 +460,19 @@ namespace WPEFramework std::string bssidStr = nm_access_point_get_bssid(ap); if(ssidInfo.bssid == bssidStr) { - NMLOG_INFO("BSSID matched: %s", bssidStr.c_str()); // TODO remove log + NMLOG_DEBUG("BSSID matched: %s", bssidStr.c_str()); ssidMatch = true; } else { - NMLOG_WARNING("BSSID did not match: expected %s, got %s", ssidInfo.bssid.c_str(), bssidStr.c_str()); + ssidMatch = false; + NMLOG_WARNING("SSID matched but BSSID did not match: expected %s, got %s", ssidInfo.bssid.c_str(), bssidStr.c_str()); continue; } } - if(!ssidInfo.frequency.empty()) - { - if(nmUtils::isValidWifiFrequencyForBand(ssidInfo.frequency, nm_access_point_get_frequency(ap))) - { - NMLOG_INFO("Frequency matched: %s GHz", ssidInfo.frequency.c_str()); // TODO remove log - ssidMatch = true; - } - else - { - NMLOG_WARNING("Frequency did not match: expected %s GHz, got %s GHz", ssidInfo.frequency.c_str(), ssidInfo.frequency.c_str()); - ssidMatch = false; - } - } + // TODO frequency matching if ssidInfo.frequency ? + // BSSID matching should be sufficient to identify the AP uniquely even if there are multiple APs with same SSID if(ssidMatch) AccessPoint = ap; @@ -696,19 +686,19 @@ namespace WPEFramework if(!ssidinfo.bssid.empty()) g_object_set(sWireless, NM_SETTING_WIRELESS_BSSID, ssidinfo.bssid.c_str(), NULL); - if(!ssidinfo.frequency.empty()) + if(ssidinfo.frequency != Exchange::INetworkManager::WIFIFrequency::WIFI_FREQUENCY_NONE) { - if(ssidinfo.frequency == "2.4") + if(ssidinfo.frequency == Exchange::INetworkManager::WIFIFrequency::WIFI_FREQUENCY_2_4_GHZ) { g_object_set(sWireless, NM_SETTING_WIRELESS_BAND, "bg", NULL); } - else if(ssidinfo.frequency == "5") + else if(ssidinfo.frequency == Exchange::INetworkManager::WIFIFrequency::WIFI_FREQUENCY_5_GHZ) { g_object_set(sWireless, NM_SETTING_WIRELESS_BAND, "a", NULL); } else { - NMLOG_WARNING("invalid frequency value: %s", ssidinfo.frequency.c_str()); + NMLOG_WARNING("invalid frequency value: %d", ssidinfo.frequency); return false; } } @@ -719,7 +709,6 @@ namespace WPEFramework case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK: case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_SAE: { - sSecurity = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); nm_connection_add_setting(m_connection, NM_SETTING(sSecurity)); if(Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_SAE == ssidinfo.security) From c6b0c1322f1bb2525949ee166b64b65d3566db3d Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Fri, 20 Feb 2026 19:04:57 +0530 Subject: [PATCH 08/23] error fix --- plugin/gnome/NetworkManagerGnomeProxy.cpp | 5 ++--- plugin/gnome/NetworkManagerGnomeWIFI.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/plugin/gnome/NetworkManagerGnomeProxy.cpp b/plugin/gnome/NetworkManagerGnomeProxy.cpp index e4c6b1b7..72d436ef 100644 --- a/plugin/gnome/NetworkManagerGnomeProxy.cpp +++ b/plugin/gnome/NetworkManagerGnomeProxy.cpp @@ -139,7 +139,6 @@ namespace WPEFramework static bool modifyDefaultConnConfig(NMClient *client) { - GError *error = NULL; const GPtrArray *connections = NULL; NMConnection *connection = NULL; std::string hostname{}; @@ -975,8 +974,8 @@ namespace WPEFramework return Core::ERROR_GENERAL; } - if(ssidinfo.frequency != Exchange::INetworkManager::WIFIFrequency::WIFI_FREQUENCY_NONE) - NMLOG_INFO("Requested frequency is %d GHz", ssidinfo.frequency); + if(ssid.frequency != Exchange::INetworkManager::WIFIFrequency::WIFI_FREQUENCY_NONE) + NMLOG_INFO("Requested frequency is %d GHz", ssid.frequency); // Check the last scanning time and if it exceeds 5 sec do a rescanning if(!wifi->isWifiScannedRecently()) diff --git a/plugin/gnome/NetworkManagerGnomeWIFI.cpp b/plugin/gnome/NetworkManagerGnomeWIFI.cpp index f2bcbaa5..8e7a4ec7 100644 --- a/plugin/gnome/NetworkManagerGnomeWIFI.cpp +++ b/plugin/gnome/NetworkManagerGnomeWIFI.cpp @@ -993,7 +993,7 @@ namespace WPEFramework Exchange::INetworkManager::WiFiSSIDInfo apinfo; std::string activeSSID{}; - NMLOG_DEBUG("wifi connect ssid: %s, bssid: %s, frequency: %s, security %d, persist %d", ssidInfoParam.ssid.c_str(), ssidInfoParam.bssid.c_str(), ssidInfoParam.frequency.c_str(), ssidInfoParam.security, ssidInfoParam.persist); + NMLOG_DEBUG("wifi connect ssid: %s, bssid: %s, frequency: %d, security %d, persist %d", ssidInfoParam.ssid.c_str(), ssidInfoParam.bssid.c_str(), ssidInfoParam.frequency, ssidInfoParam.security, ssidInfoParam.persist); Exchange::INetworkManager::WiFiConnectTo ssidInfo = ssidInfoParam; m_isSuccess = false; From 0a9ef192f3ee071da54f27e21fe6e610de327e94 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Mon, 23 Feb 2026 09:26:13 +0530 Subject: [PATCH 09/23] activate know ssid --- interface/INetworkManager.h | 1 + plugin/gnome/NetworkManagerGnomeProxy.cpp | 34 ++++++++++++++--------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/interface/INetworkManager.h b/interface/INetworkManager.h index 64e815f5..136a7bed 100644 --- a/interface/INetworkManager.h +++ b/interface/INetworkManager.h @@ -254,6 +254,7 @@ namespace WPEFramework virtual uint32_t GetKnownSSIDs(IStringIterator*& ssids /* @out */) = 0; virtual uint32_t AddToKnownSSIDs(const WiFiConnectTo& ssid /* @in */) = 0; virtual uint32_t RemoveKnownSSID(const string& ssid /* @in */) = 0; + virtual uint32_t ActivateKnownSSID(const string& ssid /* @in */) = 0; virtual uint32_t WiFiConnect(const WiFiConnectTo& ssid /* @in */) = 0; virtual uint32_t WiFiDisconnect(void) = 0; diff --git a/plugin/gnome/NetworkManagerGnomeProxy.cpp b/plugin/gnome/NetworkManagerGnomeProxy.cpp index 72d436ef..4421360d 100644 --- a/plugin/gnome/NetworkManagerGnomeProxy.cpp +++ b/plugin/gnome/NetworkManagerGnomeProxy.cpp @@ -909,6 +909,14 @@ namespace WPEFramework return rc; } + uint32_t NetworkManagerImplementation::ActivateKnownSSID(const string& ssid /* @in */) + { + uint32_t rc = Core::ERROR_GENERAL; + if(wifi->activateKnownConnection(nmUtils::wlanIface(), ssid)) + rc = Core::ERROR_NONE; + return rc; + } + uint32_t NetworkManagerImplementation::RemoveKnownSSID(const string& ssid /* @in */) { uint32_t rc = Core::ERROR_GENERAL; @@ -944,23 +952,23 @@ namespace WPEFramework return rc; } - else if(!ssid.ssid.empty() && (ssid.security == WIFI_SECURITY_NONE) && ssid.passphrase.empty()) - { - NMLOG_INFO("Only SSID: %s, so activating know connection", ssid.ssid.c_str()); + // else if(!ssid.ssid.empty() && (ssid.security == WIFI_SECURITY_NONE) && ssid.passphrase.empty()) + // { + // NMLOG_INFO("Only SSID: %s, so activating know connection", ssid.ssid.c_str()); - // TODO: 1 find how to find this is open network request of activate known connection, - // because for open network ssid is only required field, - // so if passphrase is empty and security is none then it is open network request + // // TODO: 1 find how to find this is open network request of activate known connection, + // // because for open network ssid is only required field, + // // so if passphrase is empty and security is none then it is open network request - // TODO: 2 do we need to persisit same ssid multiple connection + // // TODO: 2 do we need to persisit same ssid multiple connection - if(wifi->activateKnownConnection(nmUtils::wlanIface(), ssid.ssid)) - rc = Core::ERROR_NONE; - else - NMLOG_ERROR("activating last connected ssid failed"); + // if(wifi->activateKnownConnection(nmUtils::wlanIface(), ssid.ssid)) + // rc = Core::ERROR_NONE; + // else + // NMLOG_ERROR("activating last connected ssid failed"); - return rc; - } + // return rc; + // } // Gnome will not accept passphrase less than 8 char for WPA/WPA2 security if(!ssid.passphrase.empty() && ssid.passphrase.size() < 8) From 515d459ea91b4063cd346b41f47206fffc18eb28 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Mon, 23 Feb 2026 09:40:57 +0530 Subject: [PATCH 10/23] json erro --- plugin/NetworkManagerJsonRpc.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugin/NetworkManagerJsonRpc.cpp b/plugin/NetworkManagerJsonRpc.cpp index c3aa15e9..f1de8e2f 100644 --- a/plugin/NetworkManagerJsonRpc.cpp +++ b/plugin/NetworkManagerJsonRpc.cpp @@ -766,6 +766,23 @@ namespace WPEFramework returnJson(rc); } + uint32_t NetworkManager::ActivateKnownSSID(const JsonObject& parameters, JsonObject& response) + { + LOG_INPARAM(); + uint32_t rc = Core::ERROR_GENERAL; + string ssid{}; + + if (parameters.HasLabel("ssid")) + ssid = parameters["ssid"].String(); + + if (_networkManager) + rc = _networkManager->ActivateKnownSSID(ssid); + else + rc = Core::ERROR_UNAVAILABLE; + + returnJson(rc); + } + uint32_t NetworkManager::WiFiConnect(const JsonObject& parameters, JsonObject& response) { uint32_t rc = Core::ERROR_GENERAL; From 8611393759f718ef06bdd53e2c6759149791a201 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Mon, 23 Feb 2026 09:44:31 +0530 Subject: [PATCH 11/23] known ssid registrationa added --- plugin/NetworkManagerJsonRpc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin/NetworkManagerJsonRpc.cpp b/plugin/NetworkManagerJsonRpc.cpp index f1de8e2f..b03b2cdb 100644 --- a/plugin/NetworkManagerJsonRpc.cpp +++ b/plugin/NetworkManagerJsonRpc.cpp @@ -75,6 +75,7 @@ namespace WPEFramework Register("GetKnownSSIDs", &NetworkManager::GetKnownSSIDs, this); Register("AddToKnownSSIDs", &NetworkManager::AddToKnownSSIDs, this); Register("RemoveKnownSSID", &NetworkManager::RemoveKnownSSID, this); + Register("ActivateKnownSSID", &NetworkManager::ActivateKnownSSID, this); Register("WiFiConnect", &NetworkManager::WiFiConnect, this); Register("WiFiDisconnect", &NetworkManager::WiFiDisconnect, this); Register("GetConnectedSSID", &NetworkManager::GetConnectedSSID, this); @@ -112,6 +113,7 @@ namespace WPEFramework Unregister("GetKnownSSIDs"); Unregister("AddToKnownSSIDs"); Unregister("RemoveKnownSSID"); + Unregister("ActivateKnownSSID"); Unregister("WiFiConnect"); Unregister("WiFiDisconnect"); Unregister("GetConnectedSSID"); From a194b60133badda05b1c772bb36dd73e8ad97b27 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Mon, 23 Feb 2026 10:30:18 +0530 Subject: [PATCH 12/23] Test --- plugin/NetworkManager.h | 1 + plugin/NetworkManagerImplementation.h | 1 + plugin/rdk/NetworkManagerRDKProxy.cpp | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/plugin/NetworkManager.h b/plugin/NetworkManager.h index 319476f9..715ac11e 100644 --- a/plugin/NetworkManager.h +++ b/plugin/NetworkManager.h @@ -247,6 +247,7 @@ namespace WPEFramework uint32_t GetKnownSSIDs(const JsonObject& parameters, JsonObject& response); uint32_t AddToKnownSSIDs(const JsonObject& parameters, JsonObject& response); uint32_t RemoveKnownSSID(const JsonObject& parameters, JsonObject& response); + uint32_t ActivateKnownSSID(const JsonObject& parameters, JsonObject& response); uint32_t WiFiConnect(const JsonObject& parameters, JsonObject& response); uint32_t WiFiDisconnect(const JsonObject& parameters, JsonObject& response); uint32_t GetConnectedSSID(const JsonObject& parameters, JsonObject& response); diff --git a/plugin/NetworkManagerImplementation.h b/plugin/NetworkManagerImplementation.h index 565d7ee9..f20e0231 100644 --- a/plugin/NetworkManagerImplementation.h +++ b/plugin/NetworkManagerImplementation.h @@ -217,6 +217,7 @@ namespace WPEFramework uint32_t GetKnownSSIDs(IStringIterator*& ssids /* @out */) override; uint32_t AddToKnownSSIDs(const WiFiConnectTo& ssid /* @in */) override; uint32_t RemoveKnownSSID(const string& ssid /* @in */) override; + uint32_t ActivateKnownSSID(const string& ssid /* @in */) override; uint32_t WiFiConnect(const WiFiConnectTo& ssid /* @in */) override; uint32_t WiFiDisconnect(void) override; diff --git a/plugin/rdk/NetworkManagerRDKProxy.cpp b/plugin/rdk/NetworkManagerRDKProxy.cpp index f2a1e959..e341d5a2 100644 --- a/plugin/rdk/NetworkManagerRDKProxy.cpp +++ b/plugin/rdk/NetworkManagerRDKProxy.cpp @@ -1070,6 +1070,13 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { return rc; } + uint32_t NetworkManagerImplementation::ActivateKnownSSID(const string& ssid /* @in */) + { + LOG_ENTRY_FUNCTION(); + NMLOG_INFO ("netsrvmgr not support multiple known SSIDs. ActivateKnownSSID not supported !"); + return Core::ERROR_UNAVAILABLE; + } + uint32_t NetworkManagerImplementation::RemoveKnownSSID(const string& ssid /* @in */) { LOG_ENTRY_FUNCTION(); From 92fe873fcbee7a0516694168ae3ce129e325b051 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Mon, 23 Feb 2026 15:04:13 +0530 Subject: [PATCH 13/23] activate know connection --- plugin/gnome/NetworkManagerGnomeProxy.cpp | 2 +- plugin/gnome/NetworkManagerGnomeWIFI.cpp | 80 +++++++++++++++++++++++ plugin/gnome/NetworkManagerGnomeWIFI.h | 1 + 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/plugin/gnome/NetworkManagerGnomeProxy.cpp b/plugin/gnome/NetworkManagerGnomeProxy.cpp index 4421360d..19e57287 100644 --- a/plugin/gnome/NetworkManagerGnomeProxy.cpp +++ b/plugin/gnome/NetworkManagerGnomeProxy.cpp @@ -912,7 +912,7 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::ActivateKnownSSID(const string& ssid /* @in */) { uint32_t rc = Core::ERROR_GENERAL; - if(wifi->activateKnownConnection(nmUtils::wlanIface(), ssid)) + if(wifi->activateKnownSSID(ssid)) rc = Core::ERROR_NONE; return rc; } diff --git a/plugin/gnome/NetworkManagerGnomeWIFI.cpp b/plugin/gnome/NetworkManagerGnomeWIFI.cpp index 8e7a4ec7..db349d45 100644 --- a/plugin/gnome/NetworkManagerGnomeWIFI.cpp +++ b/plugin/gnome/NetworkManagerGnomeWIFI.cpp @@ -839,6 +839,86 @@ namespace WPEFramework return true; } + + bool wifiManager::activateKnownSSID(const std::string& ssid) + { + const GPtrArray *allnmConn = NULL; + const char* specificObjPath = "/"; + NMConnection *knownConnection = NULL; + bool ret = false; + + if(!createClientNewConnection()) + return ret; + + m_wifidevice = getWifiDevice(); + if(m_wifidevice == NULL) + { + deleteClientConnection(); + return false; + } + + allnmConn = nm_client_get_connections(m_client); + if(allnmConn == NULL || allnmConn->len == 0) + { + NMLOG_ERROR("No connections found !"); + deleteClientConnection(); + return ret; + } + + for (guint i = 0; i < allnmConn->len; i++) + { + NMConnection *conn = static_cast(g_ptr_array_index(allnmConn, i)); + if(conn == NULL) + continue; + + const char *connId = nm_connection_get_id(NM_CONNECTION(conn)); + if (connId == NULL) { + NMLOG_WARNING("connection id is NULL"); + continue; + } + + const char *connTyp = nm_connection_get_connection_type(NM_CONNECTION(conn)); + if (connTyp == NULL) { + NMLOG_WARNING("connection type is NULL"); + continue; + } + + std::string connTypStr = connTyp; + if(connTypStr != "802-11-wireless") + { + NMLOG_DEBUG("skipping non wifi connection: %s", connId); + continue; + } + + if(ssid == connId) + { + knownConnection = g_object_ref(conn); + NMLOG_DEBUG("connection '%s' exists !", ssid.c_str()); + break; + } + } + + if(knownConnection != NULL) + { + NMLOG_INFO("activating known wifi '%s' connection", ssid.c_str()); + m_isSuccess = false; + m_createNewConnection = false; // no need to create new connection + nm_client_activate_connection_async(m_client, NM_CONNECTION(knownConnection), m_wifidevice, specificObjPath, m_cancellable, wifiConnectCb, this); + wait(m_loop); + deleteClientConnection(); + g_object_unref(knownConnection); + ret = m_isSuccess; + } + else + { + NMLOG_WARNING("'%s' connection not found", ssid.c_str()); + ret = false; + } + + deleteClientConnection(); + return ret; + } + bool wifiManager::activateKnownConnection(std::string iface, std::string knowConnectionID) { const GPtrArray *devConnections = NULL; diff --git a/plugin/gnome/NetworkManagerGnomeWIFI.h b/plugin/gnome/NetworkManagerGnomeWIFI.h index ca4d1d95..6bd649ea 100644 --- a/plugin/gnome/NetworkManagerGnomeWIFI.h +++ b/plugin/gnome/NetworkManagerGnomeWIFI.h @@ -52,6 +52,7 @@ namespace WPEFramework bool getWifiState(Exchange::INetworkManager::WiFiState& state); bool wifiDisconnect(); bool activateKnownConnection(std::string iface, std::string knowConnectionID=""); + bool activateKnownSSID(const std::string& ssid); bool wifiConnectedSSIDInfo(Exchange::INetworkManager::WiFiSSIDInfo &ssidinfo); bool wifiConnect(const Exchange::INetworkManager::WiFiConnectTo &ssidInfo); bool wifiScanRequest(std::string ssidReq = ""); From cc76b2422cd863f8e282c270ed5b05d13844078d Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Tue, 24 Feb 2026 11:03:12 +0530 Subject: [PATCH 14/23] Testlog --- plugin/gnome/NetworkManagerGnomeEvents.cpp | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/plugin/gnome/NetworkManagerGnomeEvents.cpp b/plugin/gnome/NetworkManagerGnomeEvents.cpp index 5e6e3716..c2618e9c 100644 --- a/plugin/gnome/NetworkManagerGnomeEvents.cpp +++ b/plugin/gnome/NetworkManagerGnomeEvents.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -41,9 +42,19 @@ namespace WPEFramework extern NetworkManagerImplementation* _instance; static GnomeNetworkManagerEvents *_nmEventInstance = nullptr; + static std::atomic g_nmEventTraceCount {0}; + + static inline void nmEventTrace(const int line) + { + const unsigned int count = g_nmEventTraceCount.fetch_add(1, std::memory_order_relaxed) + 1; + NMLOG_INFO("nm_event_thrd line=%d count=%u", line, count); + } + +#define NM_EVENT_TRACE() nmEventTrace(__LINE__) static void primaryConnectionCb(NMClient *client, GParamSpec *param, NMEvents *nmEvents) { + NM_EVENT_TRACE(); NMActiveConnection *primaryConn; const char *activeConnId = NULL; const char *connectionTyp = NULL; @@ -52,6 +63,7 @@ namespace WPEFramework std::string newIface ="unknown"; if (primaryConn) { + NM_EVENT_TRACE(); activeConnId = nm_active_connection_get_id(primaryConn); connectionTyp = nm_active_connection_get_connection_type(primaryConn); NMLOG_INFO("active connection - %s (%s)", activeConnId, connectionTyp); @@ -61,14 +73,17 @@ namespace WPEFramework else if(0 == strncmp("802-11-wireless", connectionTyp, sizeof("802-11-wireless")) && string("wlan0_missing") != nmUtils::wlanIface()) newIface = nmUtils::wlanIface(); else { + NM_EVENT_TRACE(); NMLOG_WARNING("Active connection not valid: Ethernet/WiFi ID: %s", connectionTyp); return; // if not good don't report the evnet } + NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onActiveInterfaceChangeCb(newIface); } else { + NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onActiveInterfaceChangeCb(newIface); NMLOG_WARNING("now there's no active connection"); } @@ -76,17 +91,23 @@ namespace WPEFramework void GnomeNetworkManagerEvents::deviceStateChangeCb(NMDevice *device, GParamSpec *pspec, NMEvents *nmEvents) { + NM_EVENT_TRACE(); static bool isEthDisabled = false; static bool isWlanDisabled = false; if(device == nullptr) + { + NM_EVENT_TRACE(); return; + } NMDeviceState deviceState; deviceState = nm_device_get_state(device); std::string ifname = nm_device_get_iface(device); NMDeviceStateReason reason = nm_device_get_state_reason(device); if(ifname == nmUtils::wlanIface()) { + NM_EVENT_TRACE(); if(!NM_IS_DEVICE_WIFI(device)) { + NM_EVENT_TRACE(); NMLOG_FATAL("not a wifi device !"); return; } @@ -183,6 +204,7 @@ namespace WPEFramework if(isWlanDisabled && deviceState > NM_DEVICE_STATE_UNMANAGED) { + NM_EVENT_TRACE(); isWlanDisabled = false; GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::wlanIface()); } @@ -194,6 +216,7 @@ namespace WPEFramework } else if(ifname == nmUtils::ethIface()) { + NM_EVENT_TRACE(); switch (deviceState) { case NM_DEVICE_STATE_UNKNOWN: @@ -226,6 +249,7 @@ namespace WPEFramework */ if(isEthDisabled && deviceState > NM_DEVICE_STATE_UNMANAGED) { + NM_EVENT_TRACE(); isEthDisabled = false; GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::ethIface()); } @@ -236,50 +260,68 @@ namespace WPEFramework static void ip4ChangedCb(NMIPConfig *ipConfig, GParamSpec *pspec, gpointer userData) { + NM_EVENT_TRACE(); if (!ipConfig) { + NM_EVENT_TRACE(); NMLOG_ERROR("IP config is null"); return; } NMDevice *device = (NMDevice*)userData; if((device == NULL) || (!NM_IS_DEVICE(device))) + { + NM_EVENT_TRACE(); return; + } const char* iface = nm_device_get_iface(device); if(iface == NULL) + { + NM_EVENT_TRACE(); return; + } std::string ifname = iface; GPtrArray *addresses = nm_ip_config_get_addresses(ipConfig); if (!addresses) { + NM_EVENT_TRACE(); NMLOG_ERROR("No addresses found"); return; } else { if(addresses->len == 0) { + NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onAddressChangeCb(ifname, "", false, false); return; } } for (guint i = 0; i < addresses->len; ++i) { + NM_EVENT_TRACE(); NMIPAddress *address = (NMIPAddress *)g_ptr_array_index(addresses, i); if(address == NULL) { + NM_EVENT_TRACE(); NMLOG_WARNING("IPv4 address is null"); continue; } if (nm_ip_address_get_family(address) == AF_INET) { + NM_EVENT_TRACE(); const char *ipAddress = nm_ip_address_get_address(address); if(ipAddress != NULL) + { + NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onAddressChangeCb(iface, ipAddress, true, false); + } } } } static void ip6ChangedCb(NMIPConfig *ipConfig, GParamSpec *pspec, gpointer userData) { + NM_EVENT_TRACE(); if (!ipConfig) { + NM_EVENT_TRACE(); NMLOG_ERROR("ip config is null"); return; } @@ -287,39 +329,51 @@ namespace WPEFramework NMDevice *device = (NMDevice*)userData; if( ((device != NULL) && NM_IS_DEVICE(device)) ) { + NM_EVENT_TRACE(); const char* iface = nm_device_get_iface(device); if(iface == NULL) + { + NM_EVENT_TRACE(); return; + } std::string ifname = iface; GPtrArray *addresses = nm_ip_config_get_addresses(ipConfig); if (!addresses) { + NM_EVENT_TRACE(); NMLOG_ERROR("No addresses found"); return; } else { if(addresses->len == 0) { + NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onAddressChangeCb(ifname, "", false, true); return; } } for (guint i = 0; i < addresses->len; ++i) { + NM_EVENT_TRACE(); NMIPAddress *address = (NMIPAddress *)g_ptr_array_index(addresses, i); if(address == NULL) { + NM_EVENT_TRACE(); NMLOG_WARNING("IPv6 address is null"); continue; } if (nm_ip_address_get_family(address) == AF_INET6) { + NM_EVENT_TRACE(); const char *ipaddr = nm_ip_address_get_address(address); //int prefix = nm_ip_address_get_prefix(address); if(ipaddr != NULL) { + NM_EVENT_TRACE(); std::string ipAddress = ipaddr; if (ipAddress.compare(0, 5, "fe80:") == 0 || ipAddress.compare(0, 6, "fe80::") == 0) { + NM_EVENT_TRACE(); NMLOG_DEBUG("%s It's link-local ip", ipAddress.c_str()); continue; // It's link-local so skiping } + NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onAddressChangeCb(iface, ipAddress, true, true); break; // SLAAC protocol may include multip ipv6 address posting only one Global address } @@ -330,14 +384,18 @@ namespace WPEFramework static void deviceAddedCB(NMClient *client, NMDevice *device, NMEvents *nmEvents) { + NM_EVENT_TRACE(); if( ((device != NULL) && NM_IS_DEVICE(device)) ) { + NM_EVENT_TRACE(); std::string ifname = nm_device_get_iface(device); if(ifname == nmUtils::wlanIface()) { + NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::wlanIface()); NMLOG_INFO("WIFI device added: %s", ifname.c_str()); } else if(ifname == nmUtils::ethIface()) { + NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::ethIface()); NMLOG_INFO("ETHERNET device added: %s", ifname.c_str()); } @@ -345,20 +403,24 @@ namespace WPEFramework /* ip events added only for eth0 and wlan0 */ if(ifname == nmUtils::ethIface() || ifname == nmUtils::wlanIface()) { + NM_EVENT_TRACE(); g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(GnomeNetworkManagerEvents::deviceStateChangeCb), nmEvents); // TODO call notify::" NM_DEVICE_ACTIVE_CONNECTION if needed NMIPConfig *ipv4Config = nm_device_get_ip4_config(device); NMIPConfig *ipv6Config = nm_device_get_ip6_config(device); if (ipv4Config) { + NM_EVENT_TRACE(); g_signal_connect(ipv4Config, "notify::addresses", G_CALLBACK(ip4ChangedCb), device); } if (ipv6Config) { + NM_EVENT_TRACE(); g_signal_connect(ipv6Config, "notify::addresses", G_CALLBACK(ip6ChangedCb), device); } if (NM_IS_DEVICE_WIFI(device)) { + NM_EVENT_TRACE(); // Register signal handler for WiFi scanning events to detect when scan operations complete nmEvents->wifiDevice = NM_DEVICE_WIFI(device); NMLOG_INFO("WIFI device added, adding signal handler for last-scan"); @@ -367,20 +429,27 @@ namespace WPEFramework } } else + { + NM_EVENT_TRACE(); NMLOG_DEBUG("device error null"); + } } static void deviceRemovedCB(NMClient *client, NMDevice *device, NMEvents *nmEvents) { + NM_EVENT_TRACE(); if( ((device != NULL) && NM_IS_DEVICE(device)) ) { + NM_EVENT_TRACE(); std::string ifname = nm_device_get_iface(device); if(ifname == nmUtils::wlanIface()) { + NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::wlanIface()); g_signal_handlers_disconnect_by_func(device, (gpointer)GnomeNetworkManagerEvents::deviceStateChangeCb, nmEvents); NMLOG_INFO("WIFI device removed: %s", ifname.c_str()); } else if(ifname == nmUtils::ethIface()) { + NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::ethIface()); g_signal_handlers_disconnect_by_func(device, (gpointer)GnomeNetworkManagerEvents::deviceStateChangeCb, nmEvents); NMLOG_INFO("ETHERNET device removed: %s", ifname.c_str()); @@ -397,12 +466,15 @@ namespace WPEFramework static void clientStateChangedCb (NMClient *client, GParamSpec *pspec, gpointer user_data) { + NM_EVENT_TRACE(); switch (nm_client_get_state (client)) { case NM_STATE_DISCONNECTED: + NM_EVENT_TRACE(); NMLOG_WARNING("internet connection down"); break; case NM_STATE_CONNECTED_GLOBAL: + NM_EVENT_TRACE(); NMLOG_DEBUG("global internet connection success"); break; default: @@ -412,9 +484,12 @@ namespace WPEFramework static void managerRunningCb (NMClient *client, GParamSpec *pspec, gpointer user_data) { + NM_EVENT_TRACE(); if (nm_client_get_nm_running (client)) { + NM_EVENT_TRACE(); NMLOG_INFO("network manager daemon is running"); } else { + NM_EVENT_TRACE(); NMLOG_FATAL("network manager daemon not running !"); // TODO check need any client reconnection or not ? } @@ -422,43 +497,58 @@ namespace WPEFramework void* GnomeNetworkManagerEvents::networkMangerEventMonitor(void *arg) { + NM_EVENT_TRACE(); if(arg == nullptr) { + NM_EVENT_TRACE(); NMLOG_FATAL("function argument error: nm event monitor failed"); return nullptr; } NMEvents *nmEvents = static_cast(arg); + NM_EVENT_TRACE(); primaryConnectionCb(nmEvents->client, NULL, nmEvents); + NM_EVENT_TRACE(); g_signal_connect (nmEvents->client, "notify::" NM_CLIENT_NM_RUNNING,G_CALLBACK (managerRunningCb), nmEvents); + NM_EVENT_TRACE(); g_signal_connect(nmEvents->client, "notify::" NM_CLIENT_STATE, G_CALLBACK (clientStateChangedCb),nmEvents); + NM_EVENT_TRACE(); g_signal_connect(nmEvents->client, "notify::" NM_CLIENT_PRIMARY_CONNECTION, G_CALLBACK(primaryConnectionCb), nmEvents); const GPtrArray *devices = nullptr; devices = nm_client_get_devices(nmEvents->client); + NM_EVENT_TRACE(); g_signal_connect(nmEvents->client, NM_CLIENT_DEVICE_ADDED, G_CALLBACK(deviceAddedCB), nmEvents); + NM_EVENT_TRACE(); g_signal_connect(nmEvents->client, NM_CLIENT_DEVICE_REMOVED, G_CALLBACK(deviceRemovedCB), nmEvents); + NM_EVENT_TRACE(); for (u_int count = 0; count < devices->len; count++) { + NM_EVENT_TRACE(); NMDevice *device = NM_DEVICE(g_ptr_array_index(devices, count)); if( ((device != NULL) && NM_IS_DEVICE(device)) ) { + NM_EVENT_TRACE(); std::string ifname = nm_device_get_iface(device); if((ifname == nmUtils::ethIface()) || (ifname == nmUtils::wlanIface())) { + NM_EVENT_TRACE(); NMDeviceState devState = nm_device_get_state(device); if(devState > NM_DEVICE_STATE_DISCONNECTED && devState <= NM_DEVICE_STATE_ACTIVATED) { + NM_EVENT_TRACE(); // posting device state change event if interface already connected GnomeNetworkManagerEvents::deviceStateChangeCb(device, nullptr, nullptr); } /* Register device state change event */ + NM_EVENT_TRACE(); g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(GnomeNetworkManagerEvents::deviceStateChangeCb), nmEvents); if(NM_IS_DEVICE_WIFI(device)) { + NM_EVENT_TRACE(); nmEvents->wifiDevice = NM_DEVICE_WIFI(device); g_signal_connect(nmEvents->wifiDevice, "notify::" NM_DEVICE_WIFI_LAST_SCAN, G_CALLBACK(GnomeNetworkManagerEvents::onAvailableSSIDsCb), nmEvents); } @@ -466,74 +556,107 @@ namespace WPEFramework NMIPConfig *ipv4Config = nm_device_get_ip4_config(device); NMIPConfig *ipv6Config = nm_device_get_ip6_config(device); if (ipv4Config) { + NM_EVENT_TRACE(); ip4ChangedCb(ipv4Config, NULL, device); // posting event if interface already connected + NM_EVENT_TRACE(); g_signal_connect(ipv4Config, "notify::addresses", G_CALLBACK(ip4ChangedCb), device); } else + { + NM_EVENT_TRACE(); NMLOG_WARNING("IPv4 config is null for device: %s, No IPv4 monitor", ifname.c_str()); + } if (ipv6Config) { + NM_EVENT_TRACE(); ip6ChangedCb(ipv6Config, NULL, device); + NM_EVENT_TRACE(); g_signal_connect(ipv6Config, "notify::addresses", G_CALLBACK(ip6ChangedCb), device); } else + { + NM_EVENT_TRACE(); NMLOG_WARNING("IPv6 config is null for device: %s, No IPv6 monitor", ifname.c_str()); + } } else + { + NM_EVENT_TRACE(); NMLOG_DEBUG("device type not eth/wifi %s", ifname.c_str()); + } } else + { + NM_EVENT_TRACE(); NMLOG_WARNING("device error null"); + } } + NM_EVENT_TRACE(); NMLOG_INFO("registered all networkmnager dbus events"); + NM_EVENT_TRACE(); g_main_loop_run(nmEvents->loop); + NM_EVENT_TRACE(); // Clean up all signal handlers after thread has stopped if(_nmEventInstance != nullptr) { + NM_EVENT_TRACE(); _nmEventInstance->cleanupSignalHandlers(); } //g_main_loop_unref(nmEvents->loop); + NM_EVENT_TRACE(); return nullptr; } bool GnomeNetworkManagerEvents::startNetworkMangerEventMonitor() { + NM_EVENT_TRACE(); NMLOG_DEBUG("starting gnome event monitor"); if (NULL == nmEvents.client) { + NM_EVENT_TRACE(); NMLOG_ERROR("Client Connection NULL DBUS event Failed!"); return false; } if(!isEventThrdActive) { + NM_EVENT_TRACE(); isEventThrdActive = true; // Create event monitor thread eventThrdID = g_thread_new("nm_event_thrd", GnomeNetworkManagerEvents::networkMangerEventMonitor, &nmEvents); + NM_EVENT_TRACE(); } + NM_EVENT_TRACE(); return true; } void GnomeNetworkManagerEvents::stopNetworkMangerEventMonitor() { + NM_EVENT_TRACE(); // g_signal_handlers_disconnect_by_func(client, G_CALLBACK(primaryConnectionCb), NULL); if (!isEventThrdActive) { + NM_EVENT_TRACE(); return; } if (nmEvents.loop != NULL) { + NM_EVENT_TRACE(); g_main_loop_quit(nmEvents.loop); } if (eventThrdID) { + NM_EVENT_TRACE(); g_thread_join(eventThrdID); // Wait for the thread to finish eventThrdID = NULL; // Reset the thread ID NMLOG_WARNING("gnome event monitor stopped"); } isEventThrdActive = false; + NM_EVENT_TRACE(); } void GnomeNetworkManagerEvents::cleanupSignalHandlers() { + NM_EVENT_TRACE(); if(nmEvents.client == nullptr) { + NM_EVENT_TRACE(); return; // Already cleaned up } @@ -545,18 +668,23 @@ namespace WPEFramework // Clean up device signals const GPtrArray *devices = nm_client_get_devices(nmEvents.client); if (devices) { + NM_EVENT_TRACE(); for (guint i = 0; i < devices->len; i++) { + NM_EVENT_TRACE(); NMDevice *device = NM_DEVICE(g_ptr_array_index(devices, i)); if (device && NM_IS_DEVICE(device)) { + NM_EVENT_TRACE(); g_signal_handlers_disconnect_by_data(device, &nmEvents); // Clean up IP config signals NMIPConfig *ipv4Config = nm_device_get_ip4_config(device); NMIPConfig *ipv6Config = nm_device_get_ip6_config(device); if (ipv4Config) { + NM_EVENT_TRACE(); g_signal_handlers_disconnect_by_func(ipv4Config, (gpointer)ip4ChangedCb, device); } if (ipv6Config) { + NM_EVENT_TRACE(); g_signal_handlers_disconnect_by_func(ipv6Config, (gpointer)ip6ChangedCb, device); } } From 199678df511312e4dc2a6b2e8e766168e9ca4dac Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Wed, 25 Feb 2026 12:18:56 +0530 Subject: [PATCH 15/23] more logs --- plugin/gnome/NetworkManagerGnomeEvents.cpp | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/plugin/gnome/NetworkManagerGnomeEvents.cpp b/plugin/gnome/NetworkManagerGnomeEvents.cpp index c2618e9c..2fe45c11 100644 --- a/plugin/gnome/NetworkManagerGnomeEvents.cpp +++ b/plugin/gnome/NetworkManagerGnomeEvents.cpp @@ -725,6 +725,7 @@ namespace WPEFramework nmEvents.client = nm_client_new(NULL, &error); if(!nmEvents.client || error ) { + NM_EVENT_TRACE(); if (error) { NMLOG_ERROR("Could not connect to NetworkManager: %s", error->message); g_error_free(error); @@ -821,6 +822,7 @@ namespace WPEFramework { if (isIPv6) { + NM_EVENT_TRACE(); if (ipv6Map[iface].find(ipAddress) == std::string::npos) { // same ip comes multiple time so avoding that ipv6Map[iface] = ipAddress; } @@ -829,6 +831,7 @@ namespace WPEFramework } else { + NM_EVENT_TRACE(); ipv4Map[iface] = ipAddress; } } @@ -836,11 +839,13 @@ namespace WPEFramework { if (isIPv6) { + NM_EVENT_TRACE(); ipAddress = ipv6Map[iface]; ipv6Map[iface].clear(); } else { + NM_EVENT_TRACE(); ipAddress = ipv4Map[iface]; ipv4Map[iface].clear(); } @@ -857,10 +862,11 @@ namespace WPEFramework bool GnomeNetworkManagerEvents::apToJsonObject(NMAccessPoint *ap, JsonObject& ssidObj) { + NM_EVENT_TRACE(); GBytes *ssid = NULL; int strength = 0; double freq; - std::string bssid; + std::string bssid{}; int security; guint32 flags, wpaFlags, rsnFlags, apFreq; if(ap == nullptr) @@ -877,7 +883,12 @@ namespace WPEFramework free(ssidStr); } ssidObj["ssid"] = ssidString; - bssid = nm_access_point_get_bssid(ap); + if (nm_access_point_get_bssid(ap) == NULL) + { + NMLOG_WARNING("BSSID is null for ssid: %s", ssidString.c_str()); + } + else + bssid = nm_access_point_get_bssid(ap); strength = nm_access_point_get_strength(ap); apFreq = nm_access_point_get_frequency(ap); flags = nm_access_point_get_flags(ap); @@ -885,11 +896,11 @@ namespace WPEFramework rsnFlags = nm_access_point_get_rsn_flags(ap); freq = nmUtils::wifiFrequencyFromAp(apFreq); security = nmUtils::wifiSecurityModeFromAp(ssidString, flags, wpaFlags, rsnFlags, false); - ssidObj["bssid"] = bssid; ssidObj["security"] = security; ssidObj["strength"] = nmUtils::convertPercentageToSignalStrength(strength); ssidObj["frequency"] = freq; + NM_EVENT_TRACE(); return true; } // else @@ -899,6 +910,7 @@ namespace WPEFramework void GnomeNetworkManagerEvents::onAvailableSSIDsCb(NMDeviceWifi *wifiDevice, GParamSpec *pspec, gpointer userData) { + NM_EVENT_TRACE(); if(!NM_IS_DEVICE_WIFI(wifiDevice)) { NMLOG_ERROR("Not a wifi object "); @@ -909,22 +921,26 @@ namespace WPEFramework const GPtrArray *accessPoints = nm_device_wifi_get_access_points(wifiDevice); for (guint i = 0; i < accessPoints->len; i++) { + NM_EVENT_TRACE(); JsonObject ssidObj; ap = static_cast(accessPoints->pdata[i]); if(GnomeNetworkManagerEvents::apToJsonObject(ap, ssidObj)) ssidList.Add(ssidObj); } - + NM_EVENT_TRACE(); NMLOG_DEBUG("No of AP Available = %d", static_cast(accessPoints->len)); if(_nmEventInstance->doScanNotify) { _nmEventInstance->doScanNotify = false; + NM_EVENT_TRACE(); _instance->ReportAvailableSSIDs(ssidList); + NM_EVENT_TRACE(); } } void GnomeNetworkManagerEvents::setwifiScanOptions(bool doNotify) { + NM_EVENT_TRACE(); doScanNotify.store(doNotify); if(!doScanNotify) { From 59fca2706d798ccd81fb41f3da9aaa8dd3226299 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Wed, 25 Feb 2026 13:04:29 +0530 Subject: [PATCH 16/23] Revert "more logs" This reverts commit 199678df511312e4dc2a6b2e8e766168e9ca4dac. --- plugin/gnome/NetworkManagerGnomeEvents.cpp | 24 ++++------------------ 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/plugin/gnome/NetworkManagerGnomeEvents.cpp b/plugin/gnome/NetworkManagerGnomeEvents.cpp index 2fe45c11..c2618e9c 100644 --- a/plugin/gnome/NetworkManagerGnomeEvents.cpp +++ b/plugin/gnome/NetworkManagerGnomeEvents.cpp @@ -725,7 +725,6 @@ namespace WPEFramework nmEvents.client = nm_client_new(NULL, &error); if(!nmEvents.client || error ) { - NM_EVENT_TRACE(); if (error) { NMLOG_ERROR("Could not connect to NetworkManager: %s", error->message); g_error_free(error); @@ -822,7 +821,6 @@ namespace WPEFramework { if (isIPv6) { - NM_EVENT_TRACE(); if (ipv6Map[iface].find(ipAddress) == std::string::npos) { // same ip comes multiple time so avoding that ipv6Map[iface] = ipAddress; } @@ -831,7 +829,6 @@ namespace WPEFramework } else { - NM_EVENT_TRACE(); ipv4Map[iface] = ipAddress; } } @@ -839,13 +836,11 @@ namespace WPEFramework { if (isIPv6) { - NM_EVENT_TRACE(); ipAddress = ipv6Map[iface]; ipv6Map[iface].clear(); } else { - NM_EVENT_TRACE(); ipAddress = ipv4Map[iface]; ipv4Map[iface].clear(); } @@ -862,11 +857,10 @@ namespace WPEFramework bool GnomeNetworkManagerEvents::apToJsonObject(NMAccessPoint *ap, JsonObject& ssidObj) { - NM_EVENT_TRACE(); GBytes *ssid = NULL; int strength = 0; double freq; - std::string bssid{}; + std::string bssid; int security; guint32 flags, wpaFlags, rsnFlags, apFreq; if(ap == nullptr) @@ -883,12 +877,7 @@ namespace WPEFramework free(ssidStr); } ssidObj["ssid"] = ssidString; - if (nm_access_point_get_bssid(ap) == NULL) - { - NMLOG_WARNING("BSSID is null for ssid: %s", ssidString.c_str()); - } - else - bssid = nm_access_point_get_bssid(ap); + bssid = nm_access_point_get_bssid(ap); strength = nm_access_point_get_strength(ap); apFreq = nm_access_point_get_frequency(ap); flags = nm_access_point_get_flags(ap); @@ -896,11 +885,11 @@ namespace WPEFramework rsnFlags = nm_access_point_get_rsn_flags(ap); freq = nmUtils::wifiFrequencyFromAp(apFreq); security = nmUtils::wifiSecurityModeFromAp(ssidString, flags, wpaFlags, rsnFlags, false); + ssidObj["bssid"] = bssid; ssidObj["security"] = security; ssidObj["strength"] = nmUtils::convertPercentageToSignalStrength(strength); ssidObj["frequency"] = freq; - NM_EVENT_TRACE(); return true; } // else @@ -910,7 +899,6 @@ namespace WPEFramework void GnomeNetworkManagerEvents::onAvailableSSIDsCb(NMDeviceWifi *wifiDevice, GParamSpec *pspec, gpointer userData) { - NM_EVENT_TRACE(); if(!NM_IS_DEVICE_WIFI(wifiDevice)) { NMLOG_ERROR("Not a wifi object "); @@ -921,26 +909,22 @@ namespace WPEFramework const GPtrArray *accessPoints = nm_device_wifi_get_access_points(wifiDevice); for (guint i = 0; i < accessPoints->len; i++) { - NM_EVENT_TRACE(); JsonObject ssidObj; ap = static_cast(accessPoints->pdata[i]); if(GnomeNetworkManagerEvents::apToJsonObject(ap, ssidObj)) ssidList.Add(ssidObj); } - NM_EVENT_TRACE(); + NMLOG_DEBUG("No of AP Available = %d", static_cast(accessPoints->len)); if(_nmEventInstance->doScanNotify) { _nmEventInstance->doScanNotify = false; - NM_EVENT_TRACE(); _instance->ReportAvailableSSIDs(ssidList); - NM_EVENT_TRACE(); } } void GnomeNetworkManagerEvents::setwifiScanOptions(bool doNotify) { - NM_EVENT_TRACE(); doScanNotify.store(doNotify); if(!doScanNotify) { From 41904aa2f685c92b4b37493311b01d873456233e Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Wed, 25 Feb 2026 13:04:41 +0530 Subject: [PATCH 17/23] Revert "Testlog" This reverts commit cc76b2422cd863f8e282c270ed5b05d13844078d. --- plugin/gnome/NetworkManagerGnomeEvents.cpp | 128 --------------------- 1 file changed, 128 deletions(-) diff --git a/plugin/gnome/NetworkManagerGnomeEvents.cpp b/plugin/gnome/NetworkManagerGnomeEvents.cpp index c2618e9c..5e6e3716 100644 --- a/plugin/gnome/NetworkManagerGnomeEvents.cpp +++ b/plugin/gnome/NetworkManagerGnomeEvents.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -42,19 +41,9 @@ namespace WPEFramework extern NetworkManagerImplementation* _instance; static GnomeNetworkManagerEvents *_nmEventInstance = nullptr; - static std::atomic g_nmEventTraceCount {0}; - - static inline void nmEventTrace(const int line) - { - const unsigned int count = g_nmEventTraceCount.fetch_add(1, std::memory_order_relaxed) + 1; - NMLOG_INFO("nm_event_thrd line=%d count=%u", line, count); - } - -#define NM_EVENT_TRACE() nmEventTrace(__LINE__) static void primaryConnectionCb(NMClient *client, GParamSpec *param, NMEvents *nmEvents) { - NM_EVENT_TRACE(); NMActiveConnection *primaryConn; const char *activeConnId = NULL; const char *connectionTyp = NULL; @@ -63,7 +52,6 @@ namespace WPEFramework std::string newIface ="unknown"; if (primaryConn) { - NM_EVENT_TRACE(); activeConnId = nm_active_connection_get_id(primaryConn); connectionTyp = nm_active_connection_get_connection_type(primaryConn); NMLOG_INFO("active connection - %s (%s)", activeConnId, connectionTyp); @@ -73,17 +61,14 @@ namespace WPEFramework else if(0 == strncmp("802-11-wireless", connectionTyp, sizeof("802-11-wireless")) && string("wlan0_missing") != nmUtils::wlanIface()) newIface = nmUtils::wlanIface(); else { - NM_EVENT_TRACE(); NMLOG_WARNING("Active connection not valid: Ethernet/WiFi ID: %s", connectionTyp); return; // if not good don't report the evnet } - NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onActiveInterfaceChangeCb(newIface); } else { - NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onActiveInterfaceChangeCb(newIface); NMLOG_WARNING("now there's no active connection"); } @@ -91,23 +76,17 @@ namespace WPEFramework void GnomeNetworkManagerEvents::deviceStateChangeCb(NMDevice *device, GParamSpec *pspec, NMEvents *nmEvents) { - NM_EVENT_TRACE(); static bool isEthDisabled = false; static bool isWlanDisabled = false; if(device == nullptr) - { - NM_EVENT_TRACE(); return; - } NMDeviceState deviceState; deviceState = nm_device_get_state(device); std::string ifname = nm_device_get_iface(device); NMDeviceStateReason reason = nm_device_get_state_reason(device); if(ifname == nmUtils::wlanIface()) { - NM_EVENT_TRACE(); if(!NM_IS_DEVICE_WIFI(device)) { - NM_EVENT_TRACE(); NMLOG_FATAL("not a wifi device !"); return; } @@ -204,7 +183,6 @@ namespace WPEFramework if(isWlanDisabled && deviceState > NM_DEVICE_STATE_UNMANAGED) { - NM_EVENT_TRACE(); isWlanDisabled = false; GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::wlanIface()); } @@ -216,7 +194,6 @@ namespace WPEFramework } else if(ifname == nmUtils::ethIface()) { - NM_EVENT_TRACE(); switch (deviceState) { case NM_DEVICE_STATE_UNKNOWN: @@ -249,7 +226,6 @@ namespace WPEFramework */ if(isEthDisabled && deviceState > NM_DEVICE_STATE_UNMANAGED) { - NM_EVENT_TRACE(); isEthDisabled = false; GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::ethIface()); } @@ -260,68 +236,50 @@ namespace WPEFramework static void ip4ChangedCb(NMIPConfig *ipConfig, GParamSpec *pspec, gpointer userData) { - NM_EVENT_TRACE(); if (!ipConfig) { - NM_EVENT_TRACE(); NMLOG_ERROR("IP config is null"); return; } NMDevice *device = (NMDevice*)userData; if((device == NULL) || (!NM_IS_DEVICE(device))) - { - NM_EVENT_TRACE(); return; - } const char* iface = nm_device_get_iface(device); if(iface == NULL) - { - NM_EVENT_TRACE(); return; - } std::string ifname = iface; GPtrArray *addresses = nm_ip_config_get_addresses(ipConfig); if (!addresses) { - NM_EVENT_TRACE(); NMLOG_ERROR("No addresses found"); return; } else { if(addresses->len == 0) { - NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onAddressChangeCb(ifname, "", false, false); return; } } for (guint i = 0; i < addresses->len; ++i) { - NM_EVENT_TRACE(); NMIPAddress *address = (NMIPAddress *)g_ptr_array_index(addresses, i); if(address == NULL) { - NM_EVENT_TRACE(); NMLOG_WARNING("IPv4 address is null"); continue; } if (nm_ip_address_get_family(address) == AF_INET) { - NM_EVENT_TRACE(); const char *ipAddress = nm_ip_address_get_address(address); if(ipAddress != NULL) - { - NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onAddressChangeCb(iface, ipAddress, true, false); - } } } } static void ip6ChangedCb(NMIPConfig *ipConfig, GParamSpec *pspec, gpointer userData) { - NM_EVENT_TRACE(); if (!ipConfig) { - NM_EVENT_TRACE(); NMLOG_ERROR("ip config is null"); return; } @@ -329,51 +287,39 @@ namespace WPEFramework NMDevice *device = (NMDevice*)userData; if( ((device != NULL) && NM_IS_DEVICE(device)) ) { - NM_EVENT_TRACE(); const char* iface = nm_device_get_iface(device); if(iface == NULL) - { - NM_EVENT_TRACE(); return; - } std::string ifname = iface; GPtrArray *addresses = nm_ip_config_get_addresses(ipConfig); if (!addresses) { - NM_EVENT_TRACE(); NMLOG_ERROR("No addresses found"); return; } else { if(addresses->len == 0) { - NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onAddressChangeCb(ifname, "", false, true); return; } } for (guint i = 0; i < addresses->len; ++i) { - NM_EVENT_TRACE(); NMIPAddress *address = (NMIPAddress *)g_ptr_array_index(addresses, i); if(address == NULL) { - NM_EVENT_TRACE(); NMLOG_WARNING("IPv6 address is null"); continue; } if (nm_ip_address_get_family(address) == AF_INET6) { - NM_EVENT_TRACE(); const char *ipaddr = nm_ip_address_get_address(address); //int prefix = nm_ip_address_get_prefix(address); if(ipaddr != NULL) { - NM_EVENT_TRACE(); std::string ipAddress = ipaddr; if (ipAddress.compare(0, 5, "fe80:") == 0 || ipAddress.compare(0, 6, "fe80::") == 0) { - NM_EVENT_TRACE(); NMLOG_DEBUG("%s It's link-local ip", ipAddress.c_str()); continue; // It's link-local so skiping } - NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onAddressChangeCb(iface, ipAddress, true, true); break; // SLAAC protocol may include multip ipv6 address posting only one Global address } @@ -384,18 +330,14 @@ namespace WPEFramework static void deviceAddedCB(NMClient *client, NMDevice *device, NMEvents *nmEvents) { - NM_EVENT_TRACE(); if( ((device != NULL) && NM_IS_DEVICE(device)) ) { - NM_EVENT_TRACE(); std::string ifname = nm_device_get_iface(device); if(ifname == nmUtils::wlanIface()) { - NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::wlanIface()); NMLOG_INFO("WIFI device added: %s", ifname.c_str()); } else if(ifname == nmUtils::ethIface()) { - NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::ethIface()); NMLOG_INFO("ETHERNET device added: %s", ifname.c_str()); } @@ -403,24 +345,20 @@ namespace WPEFramework /* ip events added only for eth0 and wlan0 */ if(ifname == nmUtils::ethIface() || ifname == nmUtils::wlanIface()) { - NM_EVENT_TRACE(); g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(GnomeNetworkManagerEvents::deviceStateChangeCb), nmEvents); // TODO call notify::" NM_DEVICE_ACTIVE_CONNECTION if needed NMIPConfig *ipv4Config = nm_device_get_ip4_config(device); NMIPConfig *ipv6Config = nm_device_get_ip6_config(device); if (ipv4Config) { - NM_EVENT_TRACE(); g_signal_connect(ipv4Config, "notify::addresses", G_CALLBACK(ip4ChangedCb), device); } if (ipv6Config) { - NM_EVENT_TRACE(); g_signal_connect(ipv6Config, "notify::addresses", G_CALLBACK(ip6ChangedCb), device); } if (NM_IS_DEVICE_WIFI(device)) { - NM_EVENT_TRACE(); // Register signal handler for WiFi scanning events to detect when scan operations complete nmEvents->wifiDevice = NM_DEVICE_WIFI(device); NMLOG_INFO("WIFI device added, adding signal handler for last-scan"); @@ -429,27 +367,20 @@ namespace WPEFramework } } else - { - NM_EVENT_TRACE(); NMLOG_DEBUG("device error null"); - } } static void deviceRemovedCB(NMClient *client, NMDevice *device, NMEvents *nmEvents) { - NM_EVENT_TRACE(); if( ((device != NULL) && NM_IS_DEVICE(device)) ) { - NM_EVENT_TRACE(); std::string ifname = nm_device_get_iface(device); if(ifname == nmUtils::wlanIface()) { - NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::wlanIface()); g_signal_handlers_disconnect_by_func(device, (gpointer)GnomeNetworkManagerEvents::deviceStateChangeCb, nmEvents); NMLOG_INFO("WIFI device removed: %s", ifname.c_str()); } else if(ifname == nmUtils::ethIface()) { - NM_EVENT_TRACE(); GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::ethIface()); g_signal_handlers_disconnect_by_func(device, (gpointer)GnomeNetworkManagerEvents::deviceStateChangeCb, nmEvents); NMLOG_INFO("ETHERNET device removed: %s", ifname.c_str()); @@ -466,15 +397,12 @@ namespace WPEFramework static void clientStateChangedCb (NMClient *client, GParamSpec *pspec, gpointer user_data) { - NM_EVENT_TRACE(); switch (nm_client_get_state (client)) { case NM_STATE_DISCONNECTED: - NM_EVENT_TRACE(); NMLOG_WARNING("internet connection down"); break; case NM_STATE_CONNECTED_GLOBAL: - NM_EVENT_TRACE(); NMLOG_DEBUG("global internet connection success"); break; default: @@ -484,12 +412,9 @@ namespace WPEFramework static void managerRunningCb (NMClient *client, GParamSpec *pspec, gpointer user_data) { - NM_EVENT_TRACE(); if (nm_client_get_nm_running (client)) { - NM_EVENT_TRACE(); NMLOG_INFO("network manager daemon is running"); } else { - NM_EVENT_TRACE(); NMLOG_FATAL("network manager daemon not running !"); // TODO check need any client reconnection or not ? } @@ -497,58 +422,43 @@ namespace WPEFramework void* GnomeNetworkManagerEvents::networkMangerEventMonitor(void *arg) { - NM_EVENT_TRACE(); if(arg == nullptr) { - NM_EVENT_TRACE(); NMLOG_FATAL("function argument error: nm event monitor failed"); return nullptr; } NMEvents *nmEvents = static_cast(arg); - NM_EVENT_TRACE(); primaryConnectionCb(nmEvents->client, NULL, nmEvents); - NM_EVENT_TRACE(); g_signal_connect (nmEvents->client, "notify::" NM_CLIENT_NM_RUNNING,G_CALLBACK (managerRunningCb), nmEvents); - NM_EVENT_TRACE(); g_signal_connect(nmEvents->client, "notify::" NM_CLIENT_STATE, G_CALLBACK (clientStateChangedCb),nmEvents); - NM_EVENT_TRACE(); g_signal_connect(nmEvents->client, "notify::" NM_CLIENT_PRIMARY_CONNECTION, G_CALLBACK(primaryConnectionCb), nmEvents); const GPtrArray *devices = nullptr; devices = nm_client_get_devices(nmEvents->client); - NM_EVENT_TRACE(); g_signal_connect(nmEvents->client, NM_CLIENT_DEVICE_ADDED, G_CALLBACK(deviceAddedCB), nmEvents); - NM_EVENT_TRACE(); g_signal_connect(nmEvents->client, NM_CLIENT_DEVICE_REMOVED, G_CALLBACK(deviceRemovedCB), nmEvents); - NM_EVENT_TRACE(); for (u_int count = 0; count < devices->len; count++) { - NM_EVENT_TRACE(); NMDevice *device = NM_DEVICE(g_ptr_array_index(devices, count)); if( ((device != NULL) && NM_IS_DEVICE(device)) ) { - NM_EVENT_TRACE(); std::string ifname = nm_device_get_iface(device); if((ifname == nmUtils::ethIface()) || (ifname == nmUtils::wlanIface())) { - NM_EVENT_TRACE(); NMDeviceState devState = nm_device_get_state(device); if(devState > NM_DEVICE_STATE_DISCONNECTED && devState <= NM_DEVICE_STATE_ACTIVATED) { - NM_EVENT_TRACE(); // posting device state change event if interface already connected GnomeNetworkManagerEvents::deviceStateChangeCb(device, nullptr, nullptr); } /* Register device state change event */ - NM_EVENT_TRACE(); g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(GnomeNetworkManagerEvents::deviceStateChangeCb), nmEvents); if(NM_IS_DEVICE_WIFI(device)) { - NM_EVENT_TRACE(); nmEvents->wifiDevice = NM_DEVICE_WIFI(device); g_signal_connect(nmEvents->wifiDevice, "notify::" NM_DEVICE_WIFI_LAST_SCAN, G_CALLBACK(GnomeNetworkManagerEvents::onAvailableSSIDsCb), nmEvents); } @@ -556,107 +466,74 @@ namespace WPEFramework NMIPConfig *ipv4Config = nm_device_get_ip4_config(device); NMIPConfig *ipv6Config = nm_device_get_ip6_config(device); if (ipv4Config) { - NM_EVENT_TRACE(); ip4ChangedCb(ipv4Config, NULL, device); // posting event if interface already connected - NM_EVENT_TRACE(); g_signal_connect(ipv4Config, "notify::addresses", G_CALLBACK(ip4ChangedCb), device); } else - { - NM_EVENT_TRACE(); NMLOG_WARNING("IPv4 config is null for device: %s, No IPv4 monitor", ifname.c_str()); - } if (ipv6Config) { - NM_EVENT_TRACE(); ip6ChangedCb(ipv6Config, NULL, device); - NM_EVENT_TRACE(); g_signal_connect(ipv6Config, "notify::addresses", G_CALLBACK(ip6ChangedCb), device); } else - { - NM_EVENT_TRACE(); NMLOG_WARNING("IPv6 config is null for device: %s, No IPv6 monitor", ifname.c_str()); - } } else - { - NM_EVENT_TRACE(); NMLOG_DEBUG("device type not eth/wifi %s", ifname.c_str()); - } } else - { - NM_EVENT_TRACE(); NMLOG_WARNING("device error null"); - } } - NM_EVENT_TRACE(); NMLOG_INFO("registered all networkmnager dbus events"); - NM_EVENT_TRACE(); g_main_loop_run(nmEvents->loop); - NM_EVENT_TRACE(); // Clean up all signal handlers after thread has stopped if(_nmEventInstance != nullptr) { - NM_EVENT_TRACE(); _nmEventInstance->cleanupSignalHandlers(); } //g_main_loop_unref(nmEvents->loop); - NM_EVENT_TRACE(); return nullptr; } bool GnomeNetworkManagerEvents::startNetworkMangerEventMonitor() { - NM_EVENT_TRACE(); NMLOG_DEBUG("starting gnome event monitor"); if (NULL == nmEvents.client) { - NM_EVENT_TRACE(); NMLOG_ERROR("Client Connection NULL DBUS event Failed!"); return false; } if(!isEventThrdActive) { - NM_EVENT_TRACE(); isEventThrdActive = true; // Create event monitor thread eventThrdID = g_thread_new("nm_event_thrd", GnomeNetworkManagerEvents::networkMangerEventMonitor, &nmEvents); - NM_EVENT_TRACE(); } - NM_EVENT_TRACE(); return true; } void GnomeNetworkManagerEvents::stopNetworkMangerEventMonitor() { - NM_EVENT_TRACE(); // g_signal_handlers_disconnect_by_func(client, G_CALLBACK(primaryConnectionCb), NULL); if (!isEventThrdActive) { - NM_EVENT_TRACE(); return; } if (nmEvents.loop != NULL) { - NM_EVENT_TRACE(); g_main_loop_quit(nmEvents.loop); } if (eventThrdID) { - NM_EVENT_TRACE(); g_thread_join(eventThrdID); // Wait for the thread to finish eventThrdID = NULL; // Reset the thread ID NMLOG_WARNING("gnome event monitor stopped"); } isEventThrdActive = false; - NM_EVENT_TRACE(); } void GnomeNetworkManagerEvents::cleanupSignalHandlers() { - NM_EVENT_TRACE(); if(nmEvents.client == nullptr) { - NM_EVENT_TRACE(); return; // Already cleaned up } @@ -668,23 +545,18 @@ namespace WPEFramework // Clean up device signals const GPtrArray *devices = nm_client_get_devices(nmEvents.client); if (devices) { - NM_EVENT_TRACE(); for (guint i = 0; i < devices->len; i++) { - NM_EVENT_TRACE(); NMDevice *device = NM_DEVICE(g_ptr_array_index(devices, i)); if (device && NM_IS_DEVICE(device)) { - NM_EVENT_TRACE(); g_signal_handlers_disconnect_by_data(device, &nmEvents); // Clean up IP config signals NMIPConfig *ipv4Config = nm_device_get_ip4_config(device); NMIPConfig *ipv6Config = nm_device_get_ip6_config(device); if (ipv4Config) { - NM_EVENT_TRACE(); g_signal_handlers_disconnect_by_func(ipv4Config, (gpointer)ip4ChangedCb, device); } if (ipv6Config) { - NM_EVENT_TRACE(); g_signal_handlers_disconnect_by_func(ipv6Config, (gpointer)ip6ChangedCb, device); } } From 7ae499840a4d395ca68ca872cb034ab6aa9d2c64 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Wed, 25 Feb 2026 13:19:13 +0530 Subject: [PATCH 18/23] add bssid null check --- plugin/gnome/NetworkManagerGnomeEvents.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugin/gnome/NetworkManagerGnomeEvents.cpp b/plugin/gnome/NetworkManagerGnomeEvents.cpp index 5e6e3716..1d2d9850 100644 --- a/plugin/gnome/NetworkManagerGnomeEvents.cpp +++ b/plugin/gnome/NetworkManagerGnomeEvents.cpp @@ -730,9 +730,9 @@ namespace WPEFramework bool GnomeNetworkManagerEvents::apToJsonObject(NMAccessPoint *ap, JsonObject& ssidObj) { GBytes *ssid = NULL; + const char *bssid = NULL; int strength = 0; double freq; - std::string bssid; int security; guint32 flags, wpaFlags, rsnFlags, apFreq; if(ap == nullptr) @@ -750,6 +750,13 @@ namespace WPEFramework } ssidObj["ssid"] = ssidString; bssid = nm_access_point_get_bssid(ap); + if (bssid) { + ssidObj["bssid"] = bssid; + } + else + { + NMLOG_WARNING("BSSID is null for SSID: %s", ssidString.c_str()); + } strength = nm_access_point_get_strength(ap); apFreq = nm_access_point_get_frequency(ap); flags = nm_access_point_get_flags(ap); @@ -758,7 +765,6 @@ namespace WPEFramework freq = nmUtils::wifiFrequencyFromAp(apFreq); security = nmUtils::wifiSecurityModeFromAp(ssidString, flags, wpaFlags, rsnFlags, false); - ssidObj["bssid"] = bssid; ssidObj["security"] = security; ssidObj["strength"] = nmUtils::convertPercentageToSignalStrength(strength); ssidObj["frequency"] = freq; @@ -789,7 +795,7 @@ namespace WPEFramework NMLOG_DEBUG("No of AP Available = %d", static_cast(accessPoints->len)); - if(_nmEventInstance->doScanNotify) { + if(_nmEventInstance->doScanNotify && _instance != nullptr) { _nmEventInstance->doScanNotify = false; _instance->ReportAvailableSSIDs(ssidList); } From 9d008da53bb581b94e3bf55e4cbfd2769df9939a Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Wed, 25 Feb 2026 15:27:20 +0530 Subject: [PATCH 19/23] error fix --- plugin/gnome/NetworkManagerGnomeEvents.cpp | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/plugin/gnome/NetworkManagerGnomeEvents.cpp b/plugin/gnome/NetworkManagerGnomeEvents.cpp index 1d2d9850..7fb32493 100644 --- a/plugin/gnome/NetworkManagerGnomeEvents.cpp +++ b/plugin/gnome/NetworkManagerGnomeEvents.cpp @@ -782,20 +782,32 @@ namespace WPEFramework NMLOG_ERROR("Not a wifi object "); return; } - JsonArray ssidList = JsonArray(); - NMAccessPoint *ap = nullptr; + const GPtrArray *accessPoints = nm_device_wifi_get_access_points(wifiDevice); + + if (accessPoints == nullptr) { + NMLOG_ERROR("scanning result No access points found !"); + return; + } + + NMLOG_DEBUG("No of AP Available = %d", static_cast(accessPoints->len)); + + if(!_nmEventInstance->doScanNotify) + { + NMLOG_DEBUG("wifi scan result received but notify is false, skipping event notify"); + return; + } + + JsonArray ssidList = JsonArray(); for (guint i = 0; i < accessPoints->len; i++) { - JsonObject ssidObj; - ap = static_cast(accessPoints->pdata[i]); + JsonObject ssidObj{}; + NMAccessPoint *ap = static_cast(accessPoints->pdata[i]); if(GnomeNetworkManagerEvents::apToJsonObject(ap, ssidObj)) ssidList.Add(ssidObj); } - NMLOG_DEBUG("No of AP Available = %d", static_cast(accessPoints->len)); - - if(_nmEventInstance->doScanNotify && _instance != nullptr) { + if(_instance != nullptr) { _nmEventInstance->doScanNotify = false; _instance->ReportAvailableSSIDs(ssidList); } From 8752797b685f7b07b4ed6c129736a0ec5cfb8b22 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Thu, 26 Feb 2026 13:09:52 +0530 Subject: [PATCH 20/23] update some coments --- plugin/gnome/NetworkManagerGnomeProxy.cpp | 24 ++--------------------- plugin/gnome/NetworkManagerGnomeUtils.cpp | 3 --- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/plugin/gnome/NetworkManagerGnomeProxy.cpp b/plugin/gnome/NetworkManagerGnomeProxy.cpp index 19e57287..4a608c09 100644 --- a/plugin/gnome/NetworkManagerGnomeProxy.cpp +++ b/plugin/gnome/NetworkManagerGnomeProxy.cpp @@ -943,7 +943,7 @@ namespace WPEFramework } else { - NMLOG_WARNING("ssid is empty activating last connectd ssid !"); + NMLOG_WARNING("ssid is empty activating last connected ssid !"); if(wifi->activateKnownConnection(nmUtils::wlanIface(), _instance->m_lastConnectedSSID)) rc = Core::ERROR_NONE; else @@ -952,23 +952,6 @@ namespace WPEFramework return rc; } - // else if(!ssid.ssid.empty() && (ssid.security == WIFI_SECURITY_NONE) && ssid.passphrase.empty()) - // { - // NMLOG_INFO("Only SSID: %s, so activating know connection", ssid.ssid.c_str()); - - // // TODO: 1 find how to find this is open network request of activate known connection, - // // because for open network ssid is only required field, - // // so if passphrase is empty and security is none then it is open network request - - // // TODO: 2 do we need to persisit same ssid multiple connection - - // if(wifi->activateKnownConnection(nmUtils::wlanIface(), ssid.ssid)) - // rc = Core::ERROR_NONE; - // else - // NMLOG_ERROR("activating last connected ssid failed"); - - // return rc; - // } // Gnome will not accept passphrase less than 8 char for WPA/WPA2 security if(!ssid.passphrase.empty() && ssid.passphrase.size() < 8) @@ -977,14 +960,11 @@ namespace WPEFramework return Core::ERROR_GENERAL; } - if(!nmUtils::isValidBSSID(ssid.bssid)) + if(!ssid.bssid.empty() && !nmUtils::isValidBSSID(ssid.bssid)) { return Core::ERROR_GENERAL; } - if(ssid.frequency != Exchange::INetworkManager::WIFIFrequency::WIFI_FREQUENCY_NONE) - NMLOG_INFO("Requested frequency is %d GHz", ssid.frequency); - // Check the last scanning time and if it exceeds 5 sec do a rescanning if(!wifi->isWifiScannedRecently()) { diff --git a/plugin/gnome/NetworkManagerGnomeUtils.cpp b/plugin/gnome/NetworkManagerGnomeUtils.cpp index 6d9097c5..43b535ea 100644 --- a/plugin/gnome/NetworkManagerGnomeUtils.cpp +++ b/plugin/gnome/NetworkManagerGnomeUtils.cpp @@ -196,9 +196,6 @@ namespace WPEFramework bool nmUtils::isValidBSSID(const std::string& bssid) { - if (bssid.empty()) - return true; // BSSID is optional for connection, so empty value is considered valid - // Regular expression to match valid BSSID formats (e.g., "00:11:22:33:44:55") const std::regex bssidRegex("^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$"); if (!std::regex_match(bssid, bssidRegex)) From b9ad11de4fa34382251476970148f66bed65b70b Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Thu, 26 Feb 2026 13:11:19 +0530 Subject: [PATCH 21/23] Test code --- plugin/NetworkManagerLogger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/NetworkManagerLogger.cpp b/plugin/NetworkManagerLogger.cpp index 7b631d37..eb6b82b0 100644 --- a/plugin/NetworkManagerLogger.cpp +++ b/plugin/NetworkManagerLogger.cpp @@ -34,7 +34,7 @@ #endif namespace NetworkManagerLogger { - static LogLevel gDefaultLogLevel = INFO_LEVEL; + static LogLevel gDefaultLogLevel = DEBUG_LEVEL; #ifdef USE_RDK_LOGGER From 022574c247269244e2624e2ce47b21382610dad4 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Fri, 27 Feb 2026 15:02:53 +0530 Subject: [PATCH 22/23] updated the code --- definition/NetworkManager.json | 53 +++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/definition/NetworkManager.json b/definition/NetworkManager.json index dcc4dc20..ccae842b 100644 --- a/definition/NetworkManager.json +++ b/definition/NetworkManager.json @@ -159,7 +159,7 @@ }, "methods": { "SetLogLevel":{ - "summary": "Set Log level for more information. The possible set log level are as follows. \n* `0`: FATAL \n* `1`: ERROR \n* `2`: WARNING \n* `3`: INFO \n* `4`: DEBUG \n", + "summary": "Set Log level for more information. The possible set log level are as follows. \n* `0`: FATAL \n* `1`: ERROR \n* `2`: WARNING \n* `3`: INFO \n* `4`: DEBUG \n if logllevel is debug, it will also enable Gnome Networkmanager debug logs which can be helpful to debug network related issues.", "params": { "type": "object", "properties": { @@ -262,7 +262,7 @@ } }, "GetPrimaryInterface": { - "summary": "Gets the primary/default network interface for the device. The active network interface is defined as the one that can make requests to the external network. Returns one of the supported interfaces as per `GetAvailableInterfaces`.", + "summary": "Gets the primary/default network interface for the device. The active network interface is defined as the one that can make requests to the external network. Returns one of the supported interfaces as per `GetAvailableInterfaces`. if no active network is available, it returns empty string.", "result": { "type": "object", "properties": { @@ -984,6 +984,36 @@ ] } }, + "ActivateKnownSSID":{ + "summary": "Activate given SSID from saved SSIDs. This method will initiate a connect a specified SSID from the list of saved SSIDs. if given ssid not in the list of saved SSIDs, it will return failure.", + "events":{ + "onWiFiStateChange" : "Triggered when Wifi state changes to CONNECTING, CONNECTED .", + "onAddressChange" : "Triggered when an IP Address is assigned or lost", + "onInternetStatusChange" : "Triggered when internet connection state changed" + }, + "params": { + "type": "object", + "properties": { + "ssid": { + "$ref": "#/definitions/ssid" + } + }, + "required": [ + "ssid" + ] + }, + "result": { + "type": "object", + "properties": { + "success":{ + "$ref": "#/definitions/success" + } + }, + "required": [ + "success" + ] + } + }, "WiFiConnect":{ "summary": "Initiates request to connect to the specified SSID with the given passphrase. Passphrase can be `null` when the network security is `NONE`. The security mode is decided based on the highest security mode provided by the SSID. Also when called with no arguments, this method attempts to connect to the saved SSID and password. See `AddToKnownSSIDs`.", "events":{ @@ -998,6 +1028,19 @@ "passphrase": { "$ref": "#/definitions/passphrase" }, + "security": { + "$ref": "#/definitions/security" + }, + "bssid": { + "summary": "Specify the BSSID to connect. if specified it will not connect to other BSSID even with the same SSID. It is optional parameter and if not specified, it will connect to the best BSSID available for the SSID.", + "type": "string", + "example": "00:11:22:33:44:55" + }, + "frequency": { + "summary": "Specify the frequency band to connect. `1`: 2.4GHz `2`: 5GHz When not specified it will connect to the best frequency available", + "type": "integer", + "example": 2 + }, "ca_cert": { "summary": "The ca_cert to be used for EAP", "type": "string", @@ -1048,11 +1091,7 @@ "type": "boolean", "example": true } - }, - "required": [ - "ssid", - "passphrase" - ] + } }, "result": { "type": "object", From 8d2ff1186ca81151fe067ab4abb54d845858d429 Mon Sep 17 00:00:00 2001 From: Muhammed Rafi C Date: Fri, 27 Feb 2026 15:08:12 +0530 Subject: [PATCH 23/23] md file updated --- docs/NetworkManagerPlugin.md | 63 +++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/docs/NetworkManagerPlugin.md b/docs/NetworkManagerPlugin.md index 5747075c..61fcd088 100644 --- a/docs/NetworkManagerPlugin.md +++ b/docs/NetworkManagerPlugin.md @@ -94,6 +94,7 @@ NetworkManager interface methods: | [GetKnownSSIDs](#method.GetKnownSSIDs) | Gets list of saved SSIDs | | [AddToKnownSSIDs](#method.AddToKnownSSIDs) | Saves the SSID, passphrase, and security mode for upcoming and future sessions | | [RemoveKnownSSID](#method.RemoveKnownSSID) | Remove given SSID from saved SSIDs | +| [ActivateKnownSSID](#method.ActivateKnownSSID) | Activate given SSID from saved SSIDs | | [WiFiConnect](#method.WiFiConnect) | Initiates request to connect to the specified SSID with the given passphrase | | [WiFiDisconnect](#method.WiFiDisconnect) | Disconnects from the currently connected SSID | | [GetConnectedSSID](#method.GetConnectedSSID) | Returns the connected SSID information | @@ -113,7 +114,7 @@ Set Log level for more information. The possible set log level are as follows. * `2`: WARNING * `3`: INFO * `4`: DEBUG -. + if logllevel is debug, it will also enable Gnome Networkmanager debug logs which can be helpful to debug network related issues. ### Parameters @@ -257,7 +258,7 @@ This method takes no parameters. ## *GetPrimaryInterface [method](#head.Methods)* -Gets the primary/default network interface for the device. The active network interface is defined as the one that can make requests to the external network. Returns one of the supported interfaces as per `GetAvailableInterfaces`. +Gets the primary/default network interface for the device. The active network interface is defined as the one that can make requests to the external network. Returns one of the supported interfaces as per `GetAvailableInterfaces`. if no active network is available, it returns empty string. ### Parameters @@ -1238,6 +1239,54 @@ Also see: [onWiFiStateChange](#event.onWiFiStateChange), [onAddressChange](#even } ``` + +## *ActivateKnownSSID [method](#head.Methods)* + +Activate given SSID from saved SSIDs. This method will initiate a connect a specified SSID from the list of saved SSIDs. if given ssid not in the list of saved SSIDs, it will return failure. + +Also see: [onWiFiStateChange](#event.onWiFiStateChange), [onAddressChange](#event.onAddressChange), [onInternetStatusChange](#event.onInternetStatusChange) + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.ssid | string | The WiFi SSID Name | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.ActivateKnownSSID", + "params": { + "ssid": "myHomeSSID" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + ## *WiFiConnect [method](#head.Methods)* @@ -1250,8 +1299,11 @@ Also see: [onWiFiStateChange](#event.onWiFiStateChange) | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.ssid | string | The WiFi SSID Name | -| params.passphrase | string | The access point password | +| params?.ssid | string | *(optional)* The WiFi SSID Name | +| params?.passphrase | string | *(optional)* The access point password | +| params?.security | integer | *(optional)* The security mode. See `GetSupportedSecurityModes` | +| params?.bssid | string | *(optional)* Specify the BSSID to connect. if specified it will not connect to other BSSID even with the same SSID. It is optional parameter and if not specified, it will connect to the best BSSID available for the SSID | +| params?.frequency | integer | *(optional)* Specify the frequency band to connect. `1`: 2.4GHz `2`: 5GHz When not specified it will connect to the best frequency available | | params?.ca_cert | string | *(optional)* The ca_cert to be used for EAP | | params?.client_cert | string | *(optional)* The client_cert to be used for EAP | | params?.private_key | string | *(optional)* The private_key to be used for EAP | @@ -1282,6 +1334,9 @@ Also see: [onWiFiStateChange](#event.onWiFiStateChange) "params": { "ssid": "myHomeSSID", "passphrase": "password", + "security": 2, + "bssid": "00:11:22:33:44:55", + "frequency": 2, "ca_cert": "...", "client_cert": "...", "private_key": "...",