Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions legacy/LegacyNetworkAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,9 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
}
}
endpointsIter = (Core::Service<RPC::StringIterator>::Create<RPC::IStringIterator>(endpoints));
if (endpointsIter == nullptr) {
returnJson(rc);
}

auto _nwmgr = m_service->QueryInterfaceByCallsign<Exchange::INetworkManager>(NETWORK_MANAGER_CALLSIGN);
if (_nwmgr)
Expand Down
3 changes: 3 additions & 0 deletions legacy/LegacyWiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@ namespace WPEFramework
}

ssids = (Core::Service<RPC::StringIterator>::Create<RPC::IStringIterator>(inputSSIDlist));
if (ssids == nullptr) {
returnJson(rc);
}
}

auto _nwmgr = m_service->QueryInterfaceByCallsign<Exchange::INetworkManager>(NETWORK_MANAGER_CALLSIGN);
Expand Down
120 changes: 64 additions & 56 deletions plugin/NetworkManagerConnectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ namespace WPEFramework
NMCONNECTIVITY_CURL_HEAD_REQUEST, ipversionLocal, interface);

if (interface.empty())
interface = _instance->m_defaultInterface;
interface = _instance->getDefaultInterface();

return testInternet.getInternetState();
}
Expand Down Expand Up @@ -634,7 +634,9 @@ namespace WPEFramework
return false;
}

if(_instance->m_defaultInterface.empty())
string defaultIface = _instance->getDefaultInterface();

if(defaultIface.empty())
{
NMLOG_WARNING("default interface not set");
return false;
Expand All @@ -646,7 +648,7 @@ namespace WPEFramework
m_cmCv.notify_one();

NMLOG_INFO("switching to initial check - eth %s - wlan %s - default interface %s",
_instance->m_ethConnected.load()? "up":"down", _instance->m_wlanConnected.load()? "up":"down", _instance->m_defaultInterface.c_str());
_instance->m_ethConnected.load()? "up":"down", _instance->m_wlanConnected.load()? "up":"down", defaultIface.c_str());

return true;
}
Expand All @@ -658,7 +660,8 @@ namespace WPEFramework
{
NMLOG_INFO("notifying internet state %s", getInternetStateString(newInternetState));
Exchange::INetworkManager::InternetStatus newState = newInternetState;
_instance->ReportInternetStatusChange(oldState , newState, _instance->m_defaultInterface);
string defaultIface = _instance->getDefaultInterface();
_instance->ReportInternetStatusChange(oldState, newState, defaultIface);
m_InternetState = newInternetState;
oldState = newState; // 'm_InternetState' not exactly previous state, it may change to unknow when interface changed
}
Expand Down Expand Up @@ -694,68 +697,73 @@ namespace WPEFramework
m_notify = true;
InitialRetryCount = 1;
}
else if(_instance->m_defaultInterface.empty())
{
NMLOG_WARNING("default interface not set");
if (InitialRetryCount == 0)
m_notify = true;
InitialRetryCount = 1;
}
else if (m_switchToInitial)
else
{
if (InitialRetryCount == 0)
m_notify = true;
NMLOG_INFO("Initial connectivity check - index:%d, current state:%s, interface:%s", InitialRetryCount, getInternetStateString(currentInternetState), _instance->m_defaultInterface.c_str());
timeoutInSec = NMCONNECTIVITY_MONITOR_MIN_INTERVAL;
TestConnectivity testInternet(m_endpoint(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS,
NMCONNECTIVITY_CURL_HEAD_REQUEST, 2, _instance->m_defaultInterface);
currentInternetState = testInternet.getInternetState();
string defaultIface = _instance->getDefaultInterface();

if (currentInternetState == INTERNET_NOT_AVAILABLE) {
NMLOG_DEBUG("interface connected but no internet");
InitialRetryCount = 1; // continue same check for 5 sec
}
else {
if(currentInternetState == INTERNET_CAPTIVE_PORTAL)
m_captiveURI = testInternet.getCaptivePortal();

if (currentInternetState != m_InternetState) {
NMLOG_DEBUG("initial connectivity state change from %s to %s", getInternetStateString(m_InternetState), getInternetStateString(currentInternetState));
m_InternetState = currentInternetState;
InitialRetryCount = 1; // reset retry count to get continuous 3 same state
if(defaultIface.empty())
{
NMLOG_WARNING("default interface not set");
if (InitialRetryCount == 0)
m_notify = true;
}
InitialRetryCount++;
InitialRetryCount = 1;
}

if (InitialRetryCount > NM_CONNECTIVITY_MONITOR_RETRY_COUNT) {
m_switchToInitial = false;
m_notify = true;
NMLOG_INFO("switching to ideal ccm check interface: %s", _instance->m_defaultInterface.c_str());
}
}
else
{
// ideal case check every 30 sec happenses when captive portal or limited internet
timeoutInSec = NMCONNECTIVITY_MONITOR_RETRY_INTERVAL;
InitialRetryCount = 0;

if(m_InternetState != INTERNET_FULLY_CONNECTED)
else if (m_switchToInitial)
{
if (InitialRetryCount == 0)
m_notify = true;
NMLOG_INFO("Initial connectivity check - index:%d, current state:%s, interface:%s", InitialRetryCount, getInternetStateString(currentInternetState), defaultIface.c_str());
timeoutInSec = NMCONNECTIVITY_MONITOR_MIN_INTERVAL;
TestConnectivity testInternet(m_endpoint(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS,
NMCONNECTIVITY_CURL_HEAD_REQUEST, 2, _instance->m_defaultInterface); // check both IP versions
NMCONNECTIVITY_CURL_HEAD_REQUEST, 2, defaultIface);
currentInternetState = testInternet.getInternetState();

if (currentInternetState == INTERNET_CAPTIVE_PORTAL) // if captive portal found copy the URL
m_captiveURI = testInternet.getCaptivePortal();
if (currentInternetState == INTERNET_NOT_AVAILABLE) {
NMLOG_DEBUG("interface connected but no internet");
InitialRetryCount = 1; // continue same check for 5 sec
}
else {
if(currentInternetState == INTERNET_CAPTIVE_PORTAL)
m_captiveURI = testInternet.getCaptivePortal();

if (currentInternetState != m_InternetState) {
NMLOG_DEBUG("initial connectivity state change from %s to %s", getInternetStateString(m_InternetState), getInternetStateString(currentInternetState));
m_InternetState = currentInternetState;
InitialRetryCount = 1; // reset retry count to get continuous 3 same state
m_notify = true;
}
InitialRetryCount++;
}

if (currentInternetState != m_InternetState)
{
NMLOG_INFO("ideal connectivity state change from %s to %s", getInternetStateString(m_InternetState), getInternetStateString(currentInternetState));
m_switchToInitial = true;
if (InitialRetryCount > NM_CONNECTIVITY_MONITOR_RETRY_COUNT) {
m_switchToInitial = false;
m_notify = true;
InitialRetryCount = 1;
timeoutInSec = NMCONNECTIVITY_MONITOR_MIN_INTERVAL; // retry in 5 sec
NMLOG_INFO("switching to ideal ccm check interface: %s", defaultIface.c_str());
}
}
else
{
// ideal case check every 30 sec happenses when captive portal or limited internet
timeoutInSec = NMCONNECTIVITY_MONITOR_RETRY_INTERVAL;
InitialRetryCount = 0;

if(m_InternetState != INTERNET_FULLY_CONNECTED)
{
TestConnectivity testInternet(m_endpoint(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS,
NMCONNECTIVITY_CURL_HEAD_REQUEST, 2, defaultIface); // check both IP versions
currentInternetState = testInternet.getInternetState();

if (currentInternetState == INTERNET_CAPTIVE_PORTAL) // if captive portal found copy the URL
m_captiveURI = testInternet.getCaptivePortal();

if (currentInternetState != m_InternetState)
{
NMLOG_INFO("ideal connectivity state change from %s to %s", getInternetStateString(m_InternetState), getInternetStateString(currentInternetState));
m_switchToInitial = true;
m_notify = true;
InitialRetryCount = 1;
timeoutInSec = NMCONNECTIVITY_MONITOR_MIN_INTERVAL; // retry in 5 sec
}
}
}
}
Expand Down
31 changes: 20 additions & 11 deletions plugin/NetworkManagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace WPEFramework
NMLOG_INFO("NetworkManager Out-Of-Process Shutdown/Cleanup");
connectivityMonitor.stopConnectivityMonitor();
_instance = nullptr;
platform_deinit();
if(m_registrationThread.joinable())
{
m_registrationThread.join();
Expand Down Expand Up @@ -250,6 +251,9 @@ namespace WPEFramework
LOG_ENTRY_FUNCTION();
std::vector<std::string> tmpEndpoints = connectivityMonitor.getConnectivityMonitorEndpoints();
endpoints = (Core::Service<RPC::StringIterator>::Create<RPC::IStringIterator>(tmpEndpoints));
if(endpoints == nullptr) {
return Core::ERROR_GENERAL;
}

return Core::ERROR_NONE;
}
Expand Down Expand Up @@ -311,7 +315,7 @@ namespace WPEFramework
ipversion = "IPv4";

if(interface.empty())
interface = m_defaultInterface;
interface = getDefaultInterface();

return Core::ERROR_NONE;
}
Expand All @@ -337,7 +341,7 @@ namespace WPEFramework
NMLOG_DEBUG("Primary interface: %s, eth0: [enabled=%d, connected=%d], wlan0: [enabled=%d, connected=%d]",
interface.c_str(), m_ethEnabled.load(), m_ethConnected.load(), m_wlanEnabled.load(), m_wlanConnected.load());

m_defaultInterface = interface;
setDefaultInterface(interface);
return Core::ERROR_NONE;
}

Expand All @@ -364,7 +368,7 @@ namespace WPEFramework
ipversion = "IPv4";

if (interface.empty())
interface = m_defaultInterface;
interface = getDefaultInterface();

ipaddress = result.public_ip;
#if USE_TELEMETRY
Expand Down Expand Up @@ -637,7 +641,9 @@ namespace WPEFramework

using Implementation = RPC::IteratorType<Exchange::INetworkManager::ISecurityModeIterator>;
security = Core::Service<Implementation>::Create<Exchange::INetworkManager::ISecurityModeIterator>(modeInfo);

if (security == nullptr) {
return Core::ERROR_GENERAL;
}
return Core::ERROR_NONE;
}

Expand All @@ -651,7 +657,7 @@ namespace WPEFramework
m_ethIPv4Address = {};
m_ethIPv6Address = {};
m_ethConnected.store(false);
m_defaultInterface = "wlan0"; // If WiFi is connected, make it the default interface
setDefaultInterface("wlan0"); // If WiFi is connected, make it the default interface
// As default interface is changed to wlan0, switch connectivity monitor to initial check
connectivityMonitor.switchToInitialCheck();
}
Expand All @@ -660,10 +666,11 @@ namespace WPEFramework
m_wlanIPv4Address = {};
m_wlanIPv6Address = {};
m_wlanConnected.store(false);
bool triggerConnectivityCheck;
if(m_ethConnected.load())
m_defaultInterface = "eth0"; // If Ethernet is connected, make it the default interface

if(m_defaultInterface == interface)
setDefaultInterface("eth0"); // If Ethernet is connected, make it the default interface
triggerConnectivityCheck = (getDefaultInterface() == interface);
if(triggerConnectivityCheck)
{
// When WiFi is disconnected while Ethernet is connected, we don't need to trigger connectivity monitor.
// For WiFi-only state and WiFi disconnected, we should trigger connectivity monitor.
Expand Down Expand Up @@ -752,12 +759,14 @@ namespace WPEFramework
}

// FIXME : Availability of ip address for a given interface does not mean that its the default interface. This hardcoding will work for RDKProxy but not for Gnome.
bool isDefaultIface;
if (m_ethConnected.load() && m_wlanConnected.load())
m_defaultInterface = "eth0";
setDefaultInterface("eth0");
else
m_defaultInterface = interface;
setDefaultInterface(interface);
isDefaultIface = (getDefaultInterface() == interface);

if(m_defaultInterface == interface) {
if(isDefaultIface) {
// As default interface is connected, switch connectivity monitor to initial check any way
connectivityMonitor.switchToInitialCheck();
}
Expand Down
25 changes: 24 additions & 1 deletion plugin/NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <arpa/inet.h>
#include <linux/rtnetlink.h>
#include <atomic>
#include <mutex>

using namespace std;

Expand All @@ -34,6 +35,10 @@ using namespace std;
#include "NetworkManagerConnectivity.h"
#include "NetworkManagerStunClient.h"

/* Forward declarations to avoid pulling GLib/libnm headers into this header */
typedef struct _NMClient NMClient;
typedef struct _GMainContext GMainContext;

/*
* Receiver thermal noise + BW factor + assumed noise figure (NF) (dB)
* for a 20MHz channel,
Expand Down Expand Up @@ -274,6 +279,7 @@ namespace WPEFramework

private:
void platform_init(void);
void platform_deinit(void);
void platform_logging(const NetworkManagerLogger::LogLevel& level);
void getInitialConnectionState(void);
void executeExternally(NetworkEvents event, const string commandToExecute, string& response);
Expand Down Expand Up @@ -317,9 +323,26 @@ namespace WPEFramework
std::atomic<bool> m_wlanConnected;
std::atomic<bool> m_ethEnabled;
std::atomic<bool> m_wlanEnabled;
string m_defaultInterface;
std::string m_lastConnectedSSID;
NMClient *m_nmClient{nullptr}; /* proxy NMClient — bound to m_nmContext */
GMainContext *m_nmContext{nullptr}; /* isolated context, not the global default */
mutable ConnectivityMonitor connectivityMonitor;

string getDefaultInterface() const
{
std::lock_guard<std::mutex> lock(m_defaultInterfaceMutex);
return m_defaultInterface;
}

void setDefaultInterface(const string& iface)
{
std::lock_guard<std::mutex> lock(m_defaultInterfaceMutex);
m_defaultInterface = iface;
}

private:
string m_defaultInterface;
mutable std::mutex m_defaultInterfaceMutex;
};
}
}
6 changes: 6 additions & 0 deletions plugin/NetworkManagerJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ namespace WPEFramework
}
}
endpointsIter = (Core::Service<RPC::StringIterator>::Create<RPC::IStringIterator>(endpoints));
if(endpointsIter == nullptr){
returnJson(rc);
}

if (_networkManager)
rc = _networkManager->SetConnectivityTestEndpoints(endpointsIter);
Expand Down Expand Up @@ -664,6 +667,9 @@ namespace WPEFramework
}
}
ssids = (Core::Service<RPC::StringIterator>::Create<RPC::IStringIterator>(ssidslist));
if(ssids == nullptr){
returnJson(rc);
}
}

if (_networkManager)
Expand Down
Loading
Loading