diff --git a/plugin/NetworkManagerImplementation.cpp b/plugin/NetworkManagerImplementation.cpp index 1ba0509af..8325a9453 100644 --- a/plugin/NetworkManagerImplementation.cpp +++ b/plugin/NetworkManagerImplementation.cpp @@ -1328,7 +1328,7 @@ namespace WPEFramework GetWiFiSignalQuality(ssid, strength, noise, snr, newSignalQuality); if (!ssid.empty()) - m_lastConnectedSSID = ssid; // last connected ssid used in wifiConnect + setLastConnectedSSID(ssid); // last connected ssid used in wifiConnect if (oldSignalQuality != newSignalQuality) { oldSignalQuality = newSignalQuality; @@ -1457,11 +1457,12 @@ namespace WPEFramework { if (m_wlanDisconnectedForSleep.load()) { - if (!m_lastConnectedSSID.empty()) + const std::string lastConnectedSSID = getLastConnectedSSID(); + if (!lastConnectedSSID.empty()) { NMLOG_INFO("OnPowerModePreChange: waking from DeepSleep — reconnecting to '%s'", - m_lastConnectedSSID.c_str()); - uint32_t rcWifiUp = ConnectToKnownSSID(m_lastConnectedSSID); + lastConnectedSSID.c_str()); + uint32_t rcWifiUp = ConnectToKnownSSID(lastConnectedSSID); if (rcWifiUp == Core::ERROR_NONE) { m_wlanDisconnectedForSleep.store(false); diff --git a/plugin/NetworkManagerImplementation.h b/plugin/NetworkManagerImplementation.h index bafe337fc..1b6cb6c51 100644 --- a/plugin/NetworkManagerImplementation.h +++ b/plugin/NetworkManagerImplementation.h @@ -466,9 +466,22 @@ namespace WPEFramework m_defaultInterface = iface; } + void setLastConnectedSSID(const std::string& ssid) + { + std::lock_guard lock(m_lastConnectedSSIDMutex); + m_lastConnectedSSID = ssid; + } + + std::string getLastConnectedSSID() const + { + std::lock_guard lock(m_lastConnectedSSIDMutex); + return m_lastConnectedSSID; + } + private: string m_defaultInterface; mutable std::mutex m_defaultInterfaceMutex; + mutable std::mutex m_lastConnectedSSIDMutex; std::map, IpFamilyCache> m_ipCacheMap; mutable std::mutex m_ipCacheMutex; }; diff --git a/plugin/gnome/NetworkManagerGnomeProxy.cpp b/plugin/gnome/NetworkManagerGnomeProxy.cpp index 65b2fc4ba..057ba1bf6 100644 --- a/plugin/gnome/NetworkManagerGnomeProxy.cpp +++ b/plugin/gnome/NetworkManagerGnomeProxy.cpp @@ -590,8 +590,9 @@ namespace WPEFramework if(enabled && interface == nmUtils::wlanIface() && _instance != NULL) { sleep(1); // wait for 1 sec to change the device state - NMLOG_INFO("Activating connection '%s' ...", _instance->m_lastConnectedSSID.c_str()); - wifi->activateKnownConnection(nmUtils::wlanIface(), _instance->m_lastConnectedSSID); + const string lastConnectedSSID = _instance->getLastConnectedSSID(); + NMLOG_INFO("Activating connection '%s' ...", lastConnectedSSID.c_str()); + wifi->activateKnownConnection(nmUtils::wlanIface(), lastConnectedSSID); } } @@ -814,8 +815,9 @@ namespace WPEFramework if(ssid.ssid.empty()) { - NMLOG_WARNING("ssid is empty activating last connected ssid !"); - if(_instance != NULL && wifi->activateKnownConnection(nmUtils::wlanIface(), _instance->m_lastConnectedSSID)) + const string lastConnectedSSID = _instance->getLastConnectedSSID(); + NMLOG_WARNING("ssid is empty activating last connected ssid (%s) !", lastConnectedSSID.c_str()); + if(_instance != NULL && wifi->activateKnownConnection(nmUtils::wlanIface(), lastConnectedSSID)) { rc = Core::ERROR_NONE; } diff --git a/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp b/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp index 2b44c1096..8c5224406 100644 --- a/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp +++ b/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp @@ -979,8 +979,9 @@ namespace WPEFramework // Wait for 1 sec to change the device state sleep(1); if(interface == GnomeUtils::getWifiIfname() && _instance != nullptr) { - NMLOG_INFO("Activating connection '%s' ...", _instance->m_lastConnectedSSID.c_str()); - activateKnownConnection(GnomeUtils::getWifiIfname(), _instance->m_lastConnectedSSID); + const std::string lastConnectedSSID = _instance->getLastConnectedSSID(); + NMLOG_INFO("Activating connection '%s' ...", lastConnectedSSID.c_str()); + activateKnownConnection(GnomeUtils::getWifiIfname(), lastConnectedSSID); } else if(interface == GnomeUtils::getEthIfname()) { NMLOG_INFO("Activating connection 'Wired connection 1' ..."); diff --git a/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp b/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp index 3cbb977ec..0f8a0ddf9 100644 --- a/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp +++ b/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp @@ -286,8 +286,9 @@ namespace WPEFramework if(ssid.ssid.empty() && _instance != NULL) { - NMLOG_WARNING("ssid is empty activating last connected ssid !"); - if(_nmGdbusClient->activateKnownConnection(GnomeUtils::getWifiIfname(), _instance->m_lastConnectedSSID)) + const string lastConnectedSSID = _instance->getLastConnectedSSID(); + NMLOG_WARNING("ssid is empty activating last connected ssid (%s) !", lastConnectedSSID.c_str()); + if(_nmGdbusClient->activateKnownConnection(GnomeUtils::getWifiIfname(), lastConnectedSSID)) rc = Core::ERROR_NONE; } else if(ssid.ssid.size() <= 32)