diff --git a/NetworkManagerConnectivity.cpp b/NetworkManagerConnectivity.cpp index f71144ba..c3a57c51 100644 --- a/NetworkManagerConnectivity.cpp +++ b/NetworkManagerConnectivity.cpp @@ -327,8 +327,6 @@ namespace WPEFramework gInternetState = nsm_internetState::UNKNOWN; gIpv4InternetState = nsm_internetState::UNKNOWN; gIpv6InternetState = nsm_internetState::UNKNOWN; - gEthStatus = false; - gWifiStatus = false; } ConnectivityMonitor::~ConnectivityMonitor() @@ -473,14 +471,8 @@ namespace WPEFramework * --> when IP address accuired * --> when etherenet/wifi disconnected */ - bool ConnectivityMonitor::startConnectivityMonitor(std::string iface, bool interfaceStatus) + bool ConnectivityMonitor::startConnectivityMonitor() { - /* interface status connected/disconnected */ - if(iface == "eth0") - gEthStatus = interfaceStatus; - else if(iface == "wlan0") - gWifiStatus = interfaceStatus; - gInternetState = UNKNOWN; gIpv4InternetState = UNKNOWN; gIpv6InternetState = UNKNOWN; @@ -503,7 +495,8 @@ namespace WPEFramework return false; } - NMLOG_INFO("connectivity monitor started %d sec - %s - %s", NMCONNECTIVITY_MONITOR_MIN_INTERVAL, iface.c_str(), interfaceStatus? "up":"down"); + NMLOG_INFO("connectivity monitor started %d sec - eth %s - wlan %s", + NMCONNECTIVITY_MONITOR_MIN_INTERVAL, _instance->isEthConnected? "up":"down", _instance->isWlanConnected? "up":"down"); return true; } @@ -532,7 +525,7 @@ namespace WPEFramework do { - if(!gEthStatus && !gWifiStatus) // no wifi no ethernet connected + if(!_instance->isEthConnected && !_instance->isWlanConnected) // no wifi no ethernet connected { NMLOG_DEBUG("no interface connected; no ccm check"); gIpv4InternetState = NO_INTERNET; @@ -699,8 +692,9 @@ namespace WPEFramework doConnectivityMonitor = false; // self exit notifyNow = true; // post current state when retry complete } - else if(gEthStatus | gWifiStatus) // interface is active and still no internet, continue check every 30 sec + else if(_instance->isEthConnected | _instance->isWlanConnected) { + /* interface is connected and still no internet, continue check every 30 sec */ TempInterval = NMCONNECTIVITY_CONN_MONITOR_RETRY_INTERVAL; /* notify if retry completed and state stil no internet state */ if(notifyPreRetry == NMCONNECTIVITY_CONN_MONITOR_RETRY_COUNT) diff --git a/NetworkManagerConnectivity.h b/NetworkManagerConnectivity.h index 39946d08..02d885aa 100644 --- a/NetworkManagerConnectivity.h +++ b/NetworkManagerConnectivity.h @@ -114,7 +114,7 @@ namespace WPEFramework ~ConnectivityMonitor(); bool startContinuousConnectivityMonitor(int timeoutInSeconds); bool stopContinuousConnectivityMonitor(); - bool startConnectivityMonitor(std::string iface, bool interfaceStatus); + bool startConnectivityMonitor(); void setConnectivityMonitorEndpoints(const std::vector &endpoints); std::vector getConnectivityMonitorEndpoints(); bool isConnectedToInternet(nsm_ipversion ipversion); @@ -140,8 +140,6 @@ namespace WPEFramework EndpointCache endpointCache; std::mutex endpointMutex; - std::atomic gEthStatus; - std::atomic gWifiStatus; std::atomic gInternetState; std::atomic gIpv4InternetState; std::atomic gIpv6InternetState; diff --git a/NetworkManagerGnomeProxy.cpp b/NetworkManagerGnomeProxy.cpp index bf8b66bd..aad101a8 100644 --- a/NetworkManagerGnomeProxy.cpp +++ b/NetworkManagerGnomeProxy.cpp @@ -84,23 +84,25 @@ namespace WPEFramework { NMDeviceState deviceState = NM_DEVICE_STATE_UNKNOWN; Exchange::INetworkManager::InterfaceDetails interface; + interface.mac = nm_device_get_hw_address(device); + deviceState = nm_device_get_state(device); + interface.enabled = (deviceState >= NM_DEVICE_STATE_UNAVAILABLE)? true : false; + if(deviceState > NM_DEVICE_STATE_DISCONNECTED && deviceState < NM_DEVICE_STATE_DEACTIVATING) + interface.connected = true; + else + interface.connected = false; + if(ifaceStr == wifiname) { interface.type = INTERFACE_TYPE_WIFI; interface.name = wifiname; + isWlanConnected = interface.connected; } if(ifaceStr == ethname) { interface.type = INTERFACE_TYPE_ETHERNET; interface.name = ethname; + isEthConnected = interface.connected; } - interface.mac = nm_device_get_hw_address(device); - deviceState = nm_device_get_state(device); - interface.enabled = (deviceState >= NM_DEVICE_STATE_UNAVAILABLE) ? true : false; - if(deviceState > NM_DEVICE_STATE_DISCONNECTED && deviceState < NM_DEVICE_STATE_DEACTIVATING){ - interface.connected = true; - m_defaultInterface = interface.name; - } - else - interface.connected = false; + interfaceList.push_back(interface); rc = Core::ERROR_NONE; } diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index f83ed53b..53f610f4 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -50,6 +50,8 @@ namespace WPEFramework m_stunCacheTimeout = 0; m_defaultInterface = ""; m_publicIP = ""; + isEthConnected = false; + isWlanConnected = false; } NetworkManagerImplementation::~NetworkManagerImplementation() @@ -523,9 +525,17 @@ namespace WPEFramework if(Exchange::INetworkManager::INTERFACE_LINK_DOWN == state || Exchange::INetworkManager::INTERFACE_REMOVED == state) { // Start the connectivity monitor with 'false' to indicate the interface is down. // The monitor will automatically exit after the retry attempts are completed, posting a 'noInternet' event. - connectivityMonitor.startConnectivityMonitor(interface, false); + if(interface == "eth0") + isEthConnected = false; + else + isWlanConnected = false; + connectivityMonitor.startConnectivityMonitor(); } + /* Only the Ethernet connection status is changing here. The WiFi status is updated in the WiFi state callback. */ + if(Exchange::INetworkManager::INTERFACE_LINK_UP == state && interface == "eth0") + isEthConnected = true; + _notificationLock.Lock(); NMLOG_INFO("Posting onInterfaceChange %s - %u", interface.c_str(), (unsigned)state); for (const auto callback : _notificationCallbacks) { @@ -550,7 +560,7 @@ namespace WPEFramework if (Exchange::INetworkManager::IP_ACQUIRED == status) { // Start the connectivity monitor with 'true' to indicate the interface is up. // The monitor will conntinoue even after no internet retry completed, Exit when fully connectd. - connectivityMonitor.startConnectivityMonitor(interface, true); + connectivityMonitor.startConnectivityMonitor(); } _notificationLock.Lock(); @@ -585,7 +595,12 @@ namespace WPEFramework { /* start signal strength monitor when wifi connected */ if(INetworkManager::WiFiState::WIFI_STATE_CONNECTED == state) + { + isWlanConnected = true; m_wifiSignalMonitor.startWiFiSignalStrengthMonitor(DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC); + } + else + isWlanConnected = false; /* Any other state is considered as WiFi not connected. */ _notificationLock.Lock(); NMLOG_INFO("Posting onWiFiStateChange (%d)", state); diff --git a/NetworkManagerImplementation.h b/NetworkManagerImplementation.h index 213957d5..6e6dea8c 100644 --- a/NetworkManagerImplementation.h +++ b/NetworkManagerImplementation.h @@ -25,6 +25,7 @@ #include #include #include +#include using namespace std; @@ -222,6 +223,10 @@ namespace WPEFramework void ReportWiFiStateChange(const Exchange::INetworkManager::WiFiState state); void ReportWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality); + public: + std::atomic isEthConnected; + std::atomic isWlanConnected; + private: void platform_init(); void retryIarmEventRegistration(); diff --git a/NetworkManagerRDKProxy.cpp b/NetworkManagerRDKProxy.cpp index c045fe99..c8f48e46 100644 --- a/NetworkManagerRDKProxy.cpp +++ b/NetworkManagerRDKProxy.cpp @@ -697,15 +697,19 @@ namespace WPEFramework { InterfaceDetails tmp; /* Update the interface as per RDK NetSrvMgr */ - if ("eth0" == interfaceName) - tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_ETHERNET; - else if ("wlan0" == interfaceName) - tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_WIFI; - tmp.name = interfaceName; tmp.mac = string(list.interfaces[i].mac); tmp.enabled = ((list.interfaces[i].flags & IFF_UP) != 0); tmp.connected = ((list.interfaces[i].flags & IFF_RUNNING) != 0); + if ("eth0" == interfaceName) { + tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_ETHERNET; + isEthConnected = tmp.connected; + } + else if ("wlan0" == interfaceName) { + tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_WIFI; + isWlanConnected = tmp.connected; + } + interfaceList.push_back(tmp); } }