diff --git a/.github/workflows/gnome_unit_test.yml b/.github/workflows/gnome_unit_test.yml index 3d8fd278..23be4d13 100644 --- a/.github/workflows/gnome_unit_test.yml +++ b/.github/workflows/gnome_unit_test.yml @@ -15,20 +15,6 @@ jobs: runs-on: ubuntu-22.04 steps: - - name: Configure cache - if: ${{ !env.ACT }} - id: cache - uses: actions/cache@v3 - with: - path: | - build/Thunder - build/ThunderInterfaces - build/ThunderTools - install - !install/etc/WPEFramework/plugins - !install/usr/lib/wpeframework/plugins - key: ${{ runner.os }}-${{ env.THUNDER_REF }} - - name: Install packages run: | sudo apt update @@ -46,14 +32,12 @@ jobs: cmake-version: '3.16.x' - name: Checkout thunder repositories - if: steps.cache.outputs.cache-hit != 'true' run: | git clone https://github.com/rdkcentral/ThunderTools ThunderTools --branch ${{ env.THUNDER_REF }} git clone https://github.com/rdkcentral/Thunder Thunder --branch ${{ env.THUNDER_REF }} git clone https://github.com/rdkcentral/ThunderInterfaces ThunderInterfaces --branch ${{ env.THUNDER_REF }} - name: Build ThunderTools - if: steps.cache.outputs.cache-hit != 'true' run: > cmake -S "${{github.workspace}}/ThunderTools" -B build/ThunderTools @@ -64,7 +48,6 @@ jobs: cmake --build build/ThunderTools --target install -j8 - name: Build Thunder - if: steps.cache.outputs.cache-hit != 'true' run: > cmake -S "${{github.workspace}}/Thunder" -B build/Thunder @@ -77,7 +60,6 @@ jobs: cmake --build build/Thunder --target install -j8 - name: Build ThunderInterfaces - if: steps.cache.outputs.cache-hit != 'true' run: > cmake -S "${{github.workspace}}/ThunderInterfaces" -B build/ThunderInterfaces diff --git a/INetworkManager.h b/INetworkManager.h index 6b67729f..26d63374 100644 --- a/INetworkManager.h +++ b/INetworkManager.h @@ -237,11 +237,6 @@ namespace WPEFramework /* @brief Get Authentication URL if the device is behind Captive Portal */ virtual uint32_t GetCaptivePortalURI(string &uri/* @out */) const = 0; - /* @brief Start The Internet Connectivity Monitoring */ - virtual uint32_t StartConnectivityMonitoring(const uint32_t interval /* @in */) = 0; - /* @brief Stop The Internet Connectivity Monitoring */ - virtual uint32_t StopConnectivityMonitoring(void) const = 0; - /* @brief Get the Public IP used for external world communication */ virtual uint32_t GetPublicIP (string& interface /* @inout */, string &ipversion /* @inout */, string& ipaddress /* @out */) = 0; diff --git a/LegacyPlugin_NetworkAPIs.cpp b/LegacyPlugin_NetworkAPIs.cpp index 67b82246..8d49452e 100644 --- a/LegacyPlugin_NetworkAPIs.cpp +++ b/LegacyPlugin_NetworkAPIs.cpp @@ -817,19 +817,7 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { uint32_t Network::startConnectivityMonitoring(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); - uint32_t rc = Core::ERROR_GENERAL; - uint32_t interval = parameters["interval"].Number(); - - NMLOG_DEBUG("connectivity interval = %d", interval); - auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); - if (_nwmgr) - rc = _nwmgr->StartConnectivityMonitoring(interval); - else - rc = Core::ERROR_UNAVAILABLE; - - if(_nwmgr) - _nwmgr->Release(); - + uint32_t rc = Core::ERROR_NONE; returnJson(rc); } @@ -857,17 +845,7 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { uint32_t Network::stopConnectivityMonitoring(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); - uint32_t rc = Core::ERROR_GENERAL; - - auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); - if (_nwmgr) - { - rc = _nwmgr->StopConnectivityMonitoring(); - _nwmgr->Release(); - } - else - rc = Core::ERROR_UNAVAILABLE; - + uint32_t rc = Core::ERROR_NONE; returnJson(rc); } diff --git a/NetworkManager.h b/NetworkManager.h index c99b8615..d4830dd0 100644 --- a/NetworkManager.h +++ b/NetworkManager.h @@ -247,8 +247,6 @@ namespace WPEFramework uint32_t SetConnectivityTestEndpoints(const JsonObject& parameters, JsonObject& response); uint32_t IsConnectedToInternet(const JsonObject& parameters, JsonObject& response); uint32_t GetCaptivePortalURI(const JsonObject& parameters, JsonObject& response); - uint32_t StartConnectivityMonitoring(const JsonObject& parameters, JsonObject& response); - uint32_t StopConnectivityMonitoring(const JsonObject& parameters, JsonObject& response); uint32_t GetPublicIP(const JsonObject& parameters, JsonObject& response); uint32_t Ping(const JsonObject& parameters, JsonObject& response); uint32_t Trace(const JsonObject& parameters, JsonObject& response); diff --git a/NetworkManager.json b/NetworkManager.json index 649a044b..ed3e481a 100644 --- a/NetworkManager.json +++ b/NetworkManager.json @@ -108,14 +108,14 @@ "example": "30" }, "ssid":{ - "summary": "The paired SSID", + "summary": "The WiFi SSID Name", "type": "string", - "example": "123412341234" + "example": "myHomeSSID" }, "bssid":{ - "summary": "The paired BSSID", + "summary": "The BSSID of given SSID", "type": "string", - "example": "ff:ff:ff:ff:ff:ff" + "example": "AA:BB:CC:DD:EE:FF" }, "passphrase": { "summary": "The access point password", @@ -128,10 +128,15 @@ "example": 6 }, "strength":{ - "summary": "The RSSI value in dBm", + "summary": "The Signal RSSI value in dBm", "type": "string", "example": "-27.000000" }, + "quality":{ + "summary": "Signal strength Quality", + "type": "string", + "example": "Excellent" + }, "frequency":{ "summary": "The supported frequency for this SSID in GHz", "type": "string", @@ -334,9 +339,7 @@ "type": "object", "properties": { "interface": { - "summary": "Disable the specified interface", - "type": "string", - "example": "wlan0" + "$ref": "#/definitions/interface" } }, "required": [ @@ -552,9 +555,10 @@ "type":"object", "properties": { "endpoints": { - "summary": "", + "summary": "A list of endpoint URLs used", "type": "array", "items": { + "summary": "The endpoint URL", "type": "string", "example": "http://clients3.google.com/generate_204" } @@ -578,6 +582,7 @@ "summary": "A list of endpoints to test", "type": "array", "items": { + "summary": "The endpoint URL", "type": "string", "example": "http://clients3.google.com/generate_204" } @@ -665,49 +670,6 @@ ] } }, - "StartConnectivityMonitoring":{ - "summary": "Enable a continuous monitoring of internet connectivity with heart beat interval thats given. If the monitoring is already happening, it will be restarted with new given interval. When the interval is not passed, it will be 60s by default.", - "events":{ - "onInternetStatusChange" : "Triggered when internet connection state changed." - }, - "params": { - "type":"object", - "properties": { - "interval": { - "summary": "Interval in sec.", - "type": "number", - "example": "30" - } - }, - "required": [ - ] - }, - "result": { - "type": "object", - "properties": { - "success":{ - "$ref": "#/definitions/success" - } - }, - "required": [ - "success" - ] - } - }, - "StopConnectivityMonitoring":{ - "summary": "Stops the connectivity monitoring", - "result": { - "type": "object", - "properties": { - "success":{ - "$ref": "#/definitions/success" - } - }, - "required": [ - "success" - ] - } - }, "GetPublicIP":{ "summary": "Gets the internet/public IP Address of the device.", "params": { @@ -915,6 +877,7 @@ "summary": "The list of SSIDs to be scanned.", "type": "array", "items": { + "summary": "The SSID to scan.", "type": "string", "example": "Xfinity Mobile" } @@ -955,9 +918,10 @@ "type": "object", "properties": { "ssids": { - "summary": "Known SSIDS", + "summary": "A list of known SSIDs", "type": "array", "items": { + "summary": "The WiFi SSID Name", "type": "string", "example": "Xfinity_Guest" } @@ -1263,9 +1227,7 @@ "$ref": "#/definitions/strength" }, "quality":{ - "summary": "Signal strength Quality", - "type": "string", - "example": "Excellent" + "$ref": "#/definitions/quality" }, "success":{ "$ref": "#/definitions/success" @@ -1514,24 +1476,18 @@ "type":"object", "properties": { "ssid":{ - "summary": "ssid", + "summary": "Discovered SSID", "type": "string", "example": "myAP-2.4" }, "security":{ - "summary": "security", - "type": "integer", - "example": 6 + "$ref": "#/definitions/security" }, "strength":{ - "summary": "strength", - "type": "string", - "example": "-27.000000" + "$ref": "#/definitions/strength" }, "frequency":{ - "summary": "frequency", - "type": "string", - "example": "2.442000" + "$ref": "#/definitions/frequency" } }, "required": [ @@ -1573,19 +1529,13 @@ "type": "object", "properties": { "ssid":{ - "summary": "Signal Strength changed SSID", - "type": "string", - "example": "home-new_123" + "$ref": "#/definitions/ssid" }, "strength":{ - "summary": "Signal Strength", - "type": "string", - "example": "-27.000000" + "$ref": "#/definitions/strength" }, "quality":{ - "summary": "Signal quality", - "type": "string", - "example": "Excellent" + "$ref": "#/definitions/quality" } }, "required": [ diff --git a/NetworkManagerConnectivity.cpp b/NetworkManagerConnectivity.cpp index ce38c246..8140b2e9 100644 --- a/NetworkManagerConnectivity.cpp +++ b/NetworkManagerConnectivity.cpp @@ -19,14 +19,17 @@ #include #include -#include +#include #include #include -#include +#include +#include +#include #include "NetworkManagerImplementation.h" #include "NetworkManagerConnectivity.h" #include "NetworkManagerLogger.h" +#include "INetworkManager.h" namespace WPEFramework { @@ -35,27 +38,30 @@ namespace WPEFramework extern NetworkManagerImplementation* _instance; - static const char* getInternetStateString(nsm_internetState state) + constexpr auto INTERNET_NOT_AVAILABLE = Exchange::INetworkManager::InternetStatus::INTERNET_NOT_AVAILABLE; + constexpr auto INTERNET_LIMITED = Exchange::INetworkManager::InternetStatus::INTERNET_LIMITED; + constexpr auto INTERNET_CAPTIVE_PORTAL = Exchange::INetworkManager::InternetStatus::INTERNET_CAPTIVE_PORTAL; + constexpr auto INTERNET_FULLY_CONNECTED = Exchange::INetworkManager::InternetStatus::INTERNET_FULLY_CONNECTED; + constexpr auto INTERNET_UNKNOWN = Exchange::INetworkManager::InternetStatus::INTERNET_UNKNOWN; + + constexpr auto IP_ADDRESS_V4 = Exchange::INetworkManager::IPVersion::IP_ADDRESS_V4; + constexpr auto IP_ADDRESS_V6 = Exchange::INetworkManager::IPVersion::IP_ADDRESS_V6; + + static const char* getInternetStateString(Exchange::INetworkManager::InternetStatus state) { switch(state) { - case NO_INTERNET: return "NO_INTERNET"; - case LIMITED_INTERNET: return "LIMITED_INTERNET"; - case CAPTIVE_PORTAL: return "CAPTIVE_PORTAL"; - case FULLY_CONNECTED: return "FULLY_CONNECTED"; + case INTERNET_NOT_AVAILABLE: return "NO_INTERNET"; + case INTERNET_LIMITED: return "LIMITED_INTERNET"; + case INTERNET_CAPTIVE_PORTAL: return "CAPTIVE_PORTAL"; + case INTERNET_FULLY_CONNECTED: return "FULLY_CONNECTED"; default: return "UNKNOWN"; } } - bool EndpointCache::isEndpointCashFileExist() - { - std::ifstream fileStream(CachefilePath); - return fileStream.is_open(); - } - - void EndpointCache::writeEnpointsToFile(const std::vector& endpoints) + void EndpointManager::writeEndpointsToFile(const std::vector& endpoints) { - std::ofstream outputFile(CachefilePath); + std::ofstream outputFile(m_CachefilePath); if (outputFile.is_open()) { for (const std::string& str : endpoints) @@ -70,10 +76,10 @@ namespace WPEFramework } } - std::vector EndpointCache::readEnpointsFromFile() + std::vector EndpointManager::readEndpointsFromFile() { std::vector readStrings; - std::ifstream inputFile(CachefilePath); + std::ifstream inputFile(m_CachefilePath); if (inputFile.is_open()) { std::string line; @@ -90,9 +96,152 @@ namespace WPEFramework return readStrings; } - TestConnectivity::TestConnectivity(const std::vector& endpoints, long timeout_ms, bool headReq, nsm_ipversion ipversion) + void EndpointManager::setConnectivityMonitorEndpoints(const std::vector& endpoints) + { + const std::lock_guard lock(m_endpointMutex); + if(endpoints.empty()) + { + NMLOG_ERROR("Empty endpoints"); + return; + } + + m_Endpoints.clear(); + for (auto endpoint : endpoints) { + if(!endpoint.empty() && endpoint.size() > 3) + m_Endpoints.push_back(endpoint.c_str()); + else + NMLOG_ERROR("endpoint not vallied = %s", endpoint.c_str()); + } + + // write the endpoints to a file + writeEndpointsToFile(m_Endpoints); + + std::string endpointsStr; + for (const auto& endpoint : m_Endpoints) + endpointsStr.append(endpoint).append(" "); + NMLOG_INFO("Connectivity monitor endpoints updated -: %d :- %s", static_cast(m_Endpoints.size()), endpointsStr.c_str()); + } + + EndpointManager::EndpointManager() + { + m_CachefilePath = NMCONNECTIVITY_MONITOR_CACHE_FILE; + m_Endpoints.clear(); // default value will be loaded from NetworkManagerImplementation configuration + + std::ifstream inputFile(m_CachefilePath); + if (inputFile.is_open()) + { + std::string line; + std::vector endpoints{}; + while (std::getline(inputFile, line)) + { + if(!line.empty() && line.size() > 3) + endpoints.push_back(line); + } + NMLOG_WARNING("cached connectivity endpoints loaded .."); + setConnectivityMonitorEndpoints(endpoints); + inputFile.close(); + } + else + { + NMLOG_ERROR("no endpoint cache file found"); + } + } + + std::vector EndpointManager::getConnectivityMonitorEndpoints() + { + const std::lock_guard lock(m_endpointMutex); + return m_Endpoints; + } + + bool DnsResolver::resolveIP(std::string& uri, Exchange::INetworkManager::IPVersion& ipversion) + { + struct addrinfo sockAddrProps, *resultAddr= NULL; + char ipStr[INET6_ADDRSTRLEN] = {0}; + + if(ipversion == IP_ADDRESS_V4) + sockAddrProps.ai_family = AF_INET; + else if(ipversion == IP_ADDRESS_V6) + sockAddrProps.ai_family = AF_INET6; + else + sockAddrProps.ai_family = AF_UNSPEC; + + sockAddrProps.ai_socktype = SOCK_STREAM; + sockAddrProps.ai_flags = 0; + sockAddrProps.ai_protocol = 0; + + int ret = getaddrinfo(uri.c_str(), NULL, &sockAddrProps, &resultAddr); + if (ret != 0) { + NMLOG_WARNING("Resolved IP Failed getaddrinfo: %s", gai_strerror(ret)); + return false; + } + + NMLOG_DEBUG("Resolved IP addresses for %s", uri.c_str()); + + for (struct addrinfo * resutIP = resultAddr; resutIP != NULL; resutIP = resutIP->ai_next) + { + void *addr= NULL; + if (resutIP->ai_family == AF_INET) { + struct sockaddr_in *ipv4 = (struct sockaddr_in *)resutIP->ai_addr; + addr = &(ipv4->sin_addr); + ipv4Resolved = true; + } else if (resutIP->ai_family == AF_INET6) { + struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)resutIP->ai_addr; + addr = &(ipv6->sin6_addr); + ipv6Resolved = true; + } else { + continue; + } + + inet_ntop(resutIP->ai_family, addr, ipStr, sizeof(ipStr)); + NMLOG_DEBUG("Resolved IP --> %s", ipStr); + } + + freeaddrinfo(resultAddr); + return true; + } + + std::string DnsResolver::convertUrIToDomainName(std::string& url) { - internetSate = UNKNOWN; + size_t domainStart = 0; + size_t protocolEnd = url.find("://"); + if (protocolEnd != std::string::npos) { + domainStart = protocolEnd + 3; + } + + size_t domainEnd = url.find('/', domainStart); + if (domainEnd != std::string::npos) + return url.substr(domainStart, domainEnd - domainStart); + else + return url.substr(domainStart); + } + + DnsResolver::DnsResolver(std::string url, Exchange::INetworkManager::IPVersion ipversion, int curlErrorCode) + { + NMLOG_DEBUG("url %s - ipversion %d - curl error %d ", url.c_str(), ipversion, curlErrorCode); + if(url.empty()) { + NMLOG_ERROR("URI/hostname missing"); + return; + } + switch (curlErrorCode) + { + case CURLE_COULDNT_RESOLVE_HOST: // 6 - Could not resolve host + case CURLE_OPERATION_TIMEDOUT: // 28 - Operation timeout. time-out period + case CURLE_RECV_ERROR: // 56 - Failure with receiving network data + { + m_domain = convertUrIToDomainName(url); + resolveIP(m_domain, ipversion); + break; + } + default: + ipv4Resolved = false; + ipv6Resolved = false; + break; + } + } + + TestConnectivity::TestConnectivity(const std::vector& endpoints, long timeout_ms, bool headReq, Exchange::INetworkManager::IPVersion ipversion) + { + internetSate = INTERNET_UNKNOWN; if(endpoints.size() < 1) { NMLOG_ERROR("Endpoints size error ! curl check not possible"); return; @@ -119,7 +268,7 @@ namespace WPEFramework return size * nmemb; } - nsm_internetState TestConnectivity::checkCurlResponse(const std::vector& endpoints, long timeout_ms, bool headReq, nsm_ipversion ipversion) + Exchange::INetworkManager::InternetStatus TestConnectivity::checkCurlResponse(const std::vector& endpoints, long timeout_ms, bool headReq, Exchange::INetworkManager::IPVersion ipversion) { long deadline = current_time() + timeout_ms, time_now = 0, time_earlier = 0; @@ -127,7 +276,7 @@ namespace WPEFramework if (!curl_multi_handle) { NMLOG_ERROR("curl_multi_init returned NULL"); - return NO_INTERNET; + return INTERNET_NOT_AVAILABLE; } CURLMcode mc; @@ -156,15 +305,17 @@ namespace WPEFramework } curl_easy_setopt(curl_easy_handle, CURLOPT_WRITEFUNCTION, writeFunction); curl_easy_setopt(curl_easy_handle, CURLOPT_TIMEOUT_MS, deadline - current_time()); - if ((ipversion == CURL_IPRESOLVE_V4) || (ipversion == CURL_IPRESOLVE_V6)) - { - NMLOG_DEBUG("curlopt ipversion = %s reqtyp = %s", ipversion == CURL_IPRESOLVE_V4?"IPv4":"IPv6", headReq? "HEAD":"GET"); - curl_easy_setopt(curl_easy_handle, CURLOPT_IPRESOLVE, ipversion); + if (IP_ADDRESS_V4 == ipversion) { + curl_easy_setopt(curl_easy_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + NMLOG_DEBUG("curlopt ipversion = IPv4 reqtyp = %s", headReq? "HEAD":"GET"); + } + else if (IP_ADDRESS_V6 == ipversion) { + curl_easy_setopt(curl_easy_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6); + NMLOG_DEBUG("curlopt ipversion = IPv6 reqtyp = %s", headReq? "HEAD":"GET"); } else - { NMLOG_DEBUG("curlopt ipversion = whatever reqtyp = %s", headReq? "HEAD":"GET"); - } + if(curlVerboseEnabled()) curl_easy_setopt(curl_easy_handle, CURLOPT_VERBOSE, 1L); if (CURLM_OK != (mc = curl_multi_add_handle(curl_multi_handle, curl_easy_handle))) @@ -205,8 +356,10 @@ namespace WPEFramework } } } - else + else { NMLOG_ERROR("endpoint = <%s> curl error = %d (%s)", endpoint, msg->data.result, curl_easy_strerror(msg->data.result)); + curlErrorCode = static_cast(msg->data.result); + } http_responses.push_back(response_code); } time_earlier = time_now; @@ -264,9 +417,9 @@ namespace WPEFramework * Return Internet State: FULLY_CONNECTED - 50 % */ - nsm_internetState TestConnectivity::checkInternetStateFromResponseCode(const std::vector& responses) + Exchange::INetworkManager::InternetStatus TestConnectivity::checkInternetStateFromResponseCode(const std::vector& responses) { - nsm_internetState InternetConnectionState = NO_INTERNET; + Exchange::INetworkManager::InternetStatus InternetConnectionState = INTERNET_NOT_AVAILABLE; nsm_connectivity_httpcode http_response_code = HttpStatus_response_error; int max_count = 0; @@ -289,20 +442,20 @@ namespace WPEFramework switch (http_response_code) { case HttpStatus_204_No_Content: - InternetConnectionState = FULLY_CONNECTED; + InternetConnectionState = INTERNET_FULLY_CONNECTED; NMLOG_INFO("Internet State: FULLY_CONNECTED - %.1f%%", (percentage*100)); break; case HttpStatus_200_OK: - InternetConnectionState = LIMITED_INTERNET; + InternetConnectionState = INTERNET_LIMITED; NMLOG_INFO("Internet State: LIMITED_INTERNET - %.1f%%", (percentage*100)); break; case HttpStatus_511_Authentication_Required: case HttpStatus_302_Found: - InternetConnectionState = CAPTIVE_PORTAL; + InternetConnectionState = INTERNET_CAPTIVE_PORTAL; NMLOG_INFO("Internet State: CAPTIVE_PORTAL - %.1f%%", (percentage*100)); break; default: - InternetConnectionState = NO_INTERNET; + InternetConnectionState = INTERNET_NOT_AVAILABLE; if(http_response_code == -1) NMLOG_ERROR("Internet State: NO_INTERNET (curl error)"); else @@ -315,202 +468,111 @@ namespace WPEFramework ConnectivityMonitor::ConnectivityMonitor() { - if(endpointCache.isEndpointCashFileExist()) - { - std::vector cachedEndPnt = endpointCache.readEnpointsFromFile(); - setConnectivityMonitorEndpoints(cachedEndPnt); - NMLOG_WARNING("cached connectivity endpoints loaded .."); - } - - doContinuousMonitor = false; - doConnectivityMonitor = false; - m_InternetState = nsm_internetState::UNKNOWN; - m_Ipv4InternetState = nsm_internetState::UNKNOWN; - m_Ipv6InternetState = nsm_internetState::UNKNOWN; + NMLOG_WARNING("ConnectivityMonitor"); + m_cmRunning = false; + m_notify = true; + m_InternetState = INTERNET_UNKNOWN; + m_Ipv4InternetState = INTERNET_UNKNOWN; + m_Ipv6InternetState = INTERNET_UNKNOWN; + startConnectivityMonitor(); } ConnectivityMonitor::~ConnectivityMonitor() { NMLOG_WARNING("~ConnectivityMonitor"); - doContinuousMonitor = false; - doConnectivityMonitor = false; - cvConnectivityMonitor.notify_one(); - cvContinuousMonitor.notify_one(); - if (continuousMonitorThrd.joinable()) - continuousMonitorThrd.join(); - if (connectivityMonitorThrd.joinable()) - connectivityMonitorThrd.join(); + stopConnectivityMonitor(); } std::vector ConnectivityMonitor::getConnectivityMonitorEndpoints() { - const std::lock_guard lock(endpointMutex); - std::vector endpoints; - for (auto endpoint : connectivityMonitorEndpt) { - endpoints.push_back(endpoint); - } - return endpoints; + return m_endpoint.getConnectivityMonitorEndpoints(); } void ConnectivityMonitor::setConnectivityMonitorEndpoints(const std::vector &endpoints) { - const std::lock_guard lock(endpointMutex); - connectivityMonitorEndpt.clear(); - for (auto endpoint : endpoints) { - if(!endpoint.empty() && endpoint.size() > 3) - connectivityMonitorEndpt.push_back(endpoint.c_str()); - else - NMLOG_ERROR("endpoint not vallied = %s", endpoint.c_str()); - } - - // write the endpoints to a file - endpointCache.writeEnpointsToFile(connectivityMonitorEndpt); - - std::string endpointsStr; - for (const auto& endpoint : connectivityMonitorEndpt) - endpointsStr.append(endpoint).append(" "); - NMLOG_INFO("Connectivity monitor endpoints -: %d :- %s", static_cast(connectivityMonitorEndpt.size()), endpointsStr.c_str()); - } - - bool ConnectivityMonitor::isConnectedToInternet(nsm_ipversion ipversion) - { - if (nsm_internetState::FULLY_CONNECTED == getInternetState(ipversion)) - { - NMLOG_INFO("isConnectedToInternet %s = true", (ipversion == nsm_ipversion::NSM_IPRESOLVE_WHATEVER)?"":(ipversion == nsm_ipversion::NSM_IPRESOLVE_V4? "IPv4":"IPv6")); - return true; - } - NMLOG_WARNING("isConnectedToInternet %s = false",(ipversion == nsm_ipversion::NSM_IPRESOLVE_WHATEVER)?"":(ipversion == nsm_ipversion::NSM_IPRESOLVE_V4? "IPv4":"IPv6") ); - return false; + m_endpoint.setConnectivityMonitorEndpoints(endpoints); } - nsm_internetState ConnectivityMonitor::getInternetState(nsm_ipversion& ipversion) + Exchange::INetworkManager::InternetStatus ConnectivityMonitor::getInternetState(Exchange::INetworkManager::IPVersion& ipversion, bool ipVersionNotSpecified) { - nsm_internetState internetState = nsm_internetState::UNKNOWN; - // If monitor connectivity is running take the cache value - - if ( doContinuousMonitor && (nsm_ipversion::NSM_IPRESOLVE_V4 == ipversion || nsm_ipversion::NSM_IPRESOLVE_WHATEVER == ipversion) - && m_Ipv4InternetState != nsm_internetState::UNKNOWN ) { - NMLOG_WARNING("Reading Ipv4 internet state cached value %s", getInternetStateString(m_Ipv4InternetState)); - internetState = m_Ipv4InternetState; - ipversion = NSM_IPRESOLVE_V4; - } - else if ( doContinuousMonitor && (nsm_ipversion::NSM_IPRESOLVE_V6 == ipversion || nsm_ipversion::NSM_IPRESOLVE_WHATEVER == ipversion) - && m_Ipv6InternetState != nsm_internetState::UNKNOWN ) { - NMLOG_WARNING("Reading Ipv6 internet state cached value %s", getInternetStateString(m_Ipv6InternetState)); - internetState = m_Ipv6InternetState; - ipversion = NSM_IPRESOLVE_V6; + if(ipVersionNotSpecified) { + ipversion = m_ipversion; + NMLOG_DEBUG("ipversion %s - %s", ipversion == IP_ADDRESS_V4? "IPv4":"IPv6", getInternetStateString(m_InternetState.load())); + return m_InternetState.load(); } + else if(ipversion == IP_ADDRESS_V4) + return m_Ipv4InternetState.load(); + else if(ipversion == IP_ADDRESS_V6) + return m_Ipv6InternetState.load(); else - { - TestConnectivity testInternet(getConnectivityMonitorEndpoints(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, NMCONNECTIVITY_CURL_GET_REQUEST, ipversion); - internetState = testInternet.getInternetState(); - // TODO : Lets not hard code here. - ipversion = NSM_IPRESOLVE_V4; - } - return internetState; + return INTERNET_UNKNOWN; } std::string ConnectivityMonitor::getCaptivePortalURI() { - TestConnectivity testInternet(getConnectivityMonitorEndpoints(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, NMCONNECTIVITY_CURL_GET_REQUEST, NSM_IPRESOLVE_WHATEVER); - if(nsm_internetState::CAPTIVE_PORTAL == testInternet.getInternetState()) + if(m_Ipv4InternetState == INTERNET_CAPTIVE_PORTAL || m_Ipv6InternetState == INTERNET_CAPTIVE_PORTAL) { - NMLOG_WARNING("captive portal URI = %s", testInternet.getCaptivePortal().c_str()); - return testInternet.getCaptivePortal(); + NMLOG_INFO("captive portal URI = %s", m_captiveURI.c_str()); + return m_captiveURI; } + NMLOG_WARNING("No captive portal found !"); return std::string(""); } - bool ConnectivityMonitor::startContinuousConnectivityMonitor(int timeoutInSeconds) + bool ConnectivityMonitor::startConnectivityMonitor() { - if(_instance != nullptr ) - NMLOG_INFO("interface status eth - %s wlan - %s ", _instance->m_ethConnected? "up":"down", _instance->m_wlanConnected? "up":"down"); - continuousMonitorTimeout.store(timeoutInSeconds >= NMCONNECTIVITY_MONITOR_MIN_INTERVAL ? timeoutInSeconds : NMCONNECTIVITY_MONITOR_DEFAULT_INTERVAL); - if (doContinuousMonitor) + if (m_cmRunning) { - if(doConnectivityMonitor) - { - NMLOG_INFO("continuous monitor new timeout updated %d Sec", continuousMonitorTimeout.load()); - } - else - { - NMLOG_INFO("continuous monitor restarted with %d Sec", continuousMonitorTimeout.load()); - cvContinuousMonitor.notify_one(); - } + m_cmCv.notify_one(); + NMLOG_DEBUG("connectivity monitor is already running"); return true; } - if (continuousMonitorThrd.joinable()) { - NMLOG_WARNING("continuous monitor joinable thread running"); - doContinuousMonitor = false; - continuousMonitorThrd.join(); - } + m_cmRunning = true; + m_cmThrdID = std::thread(&ConnectivityMonitor::connectivityMonitorFunction, this); - doContinuousMonitor = true; - continuousMonitorThrd = std::thread(&ConnectivityMonitor::continuousMonitorFunction, this); - NMLOG_INFO("continuous connectivity monitor started with %d Sec", continuousMonitorTimeout.load()); - if(!continuousMonitorThrd.joinable()) { - NMLOG_ERROR("continuous connectivity monitor start Failed"); - return false; + if(_instance != nullptr) { + NMLOG_INFO("connectivity monitor started - eth %s - wlan %s", + _instance->m_ethConnected? "up":"down", _instance->m_wlanConnected? "up":"down"); } + + NMLOG_INFO("connectivity monitor is started"); return true; } - bool ConnectivityMonitor::stopContinuousConnectivityMonitor() + bool ConnectivityMonitor::stopConnectivityMonitor() { - doContinuousMonitor = false; - cvContinuousMonitor.notify_one(); - if (continuousMonitorThrd.joinable()) - continuousMonitorThrd.join(); - NMLOG_INFO("continuous connectivity monitor stopped"); + m_cmRunning = false; + m_cmCv.notify_one(); + if(m_cmThrdID.joinable()) + m_cmThrdID.join(); + m_InternetState = INTERNET_UNKNOWN; + m_Ipv4InternetState = INTERNET_UNKNOWN; + m_Ipv6InternetState = INTERNET_UNKNOWN; + NMLOG_INFO("connectivity monitor stoped !!!"); return true; } - /* - * - * call startConnectivityMonitor function - * --> when IP address accuired - * --> when etherenet/wifi disconnected - */ - bool ConnectivityMonitor::startConnectivityMonitor() + bool ConnectivityMonitor::switchToInitialCheck() { - m_InternetState = nsm_internetState::UNKNOWN; - m_Ipv4InternetState = nsm_internetState::UNKNOWN; - m_Ipv6InternetState = nsm_internetState::UNKNOWN; - if (doConnectivityMonitor) - { - cvConnectivityMonitor.notify_one(); - NMLOG_DEBUG("trigger connectivity monitor thread"); - return true; - } - - if (connectivityMonitorThrd.joinable()) { // cleanup of previous thread - doConnectivityMonitor = false; - connectivityMonitorThrd.join(); - } - - doConnectivityMonitor = true; - connectivityMonitorThrd = std::thread(&ConnectivityMonitor::connectivityMonitorFunction, this); - if(!connectivityMonitorThrd.joinable()) { - NMLOG_ERROR("connectivity monitor start failed"); - return false; - } - + m_switchToInitial = true; + m_notify = true; // m_notify internet state because some network state change may happen + m_cmCv.notify_one(); if(_instance != nullptr) { - NMLOG_INFO("connectivity monitor started %d sec - eth %s - wlan %s", NMCONNECTIVITY_MONITOR_MIN_INTERVAL, - _instance->m_ethConnected? "up":"down", _instance->m_wlanConnected? "up":"down"); + NMLOG_INFO("switching to initial check - eth %s - wlan %s", + _instance->m_ethConnected? "up":"down", _instance->m_wlanConnected? "up":"down"); } return true; } - void ConnectivityMonitor::notifyInternetStatusChangedEvent(nsm_internetState newInternetState) + void ConnectivityMonitor::notifyInternetStatusChangedEvent(Exchange::INetworkManager::InternetStatus newInternetState) { - static Exchange::INetworkManager::InternetStatus oldState = Exchange::INetworkManager::InternetStatus::INTERNET_UNKNOWN; + static Exchange::INetworkManager::InternetStatus oldState = INTERNET_UNKNOWN; if(_instance != nullptr) { - NMLOG_INFO("notify internet state %s", getInternetStateString(newInternetState)); - Exchange::INetworkManager::InternetStatus newState = static_cast(newInternetState); + NMLOG_INFO("notifying internet state %s", getInternetStateString(newInternetState)); + Exchange::INetworkManager::InternetStatus newState = newInternetState; _instance->ReportInternetStatusChange(oldState , newState); m_InternetState = newInternetState; oldState = newState; // 'm_InternetState' not exactly previous state, it may change to unknow when interface changed @@ -519,223 +581,181 @@ namespace WPEFramework NMLOG_FATAL("NetworkManagerImplementation Instance NULL notifyInternetStatusChange failed."); } - void ConnectivityMonitor::continuousMonitorFunction() + void ConnectivityMonitor::connectivityMonitorFunction() { - int TempInterval = continuousMonitorTimeout.load(); - std::mutex connMutex; - nsm_ipversion ipResolveTyp = NSM_IPRESOLVE_WHATEVER; - int notifyPreRetry = 1; - nsm_internetState currentInternetState = nsm_internetState::UNKNOWN; - - do - { - if(_instance != nullptr && (!_instance->m_ethConnected && !_instance->m_wlanConnected)) // no wifi no ethernet connected - { - NMLOG_DEBUG("no interface connected; no ccm check"); - m_Ipv4InternetState = NO_INTERNET; - m_Ipv6InternetState = NO_INTERNET; - std::unique_lock lock(connMutex); - cvContinuousMonitor.wait_for(lock, std::chrono::seconds(continuousMonitorTimeout.load())); - ipResolveTyp = NSM_IPRESOLVE_WHATEVER; - continue; + int timeoutInSec = NMCONNECTIVITY_MONITOR_MIN_INTERVAL; + Exchange::INetworkManager::InternetStatus currentInternetState = INTERNET_NOT_AVAILABLE; + int InitialRetryCount = 0; + int IdealRetryCount = 0; + m_switchToInitial = true; + m_InternetState = INTERNET_UNKNOWN; + m_Ipv4InternetState = INTERNET_UNKNOWN; + m_Ipv6InternetState = INTERNET_UNKNOWN; + m_notify = true; + + while (m_cmRunning) { + // Check if no interfaces are connected + if (_instance != nullptr && !_instance->m_ethConnected && !_instance->m_wlanConnected) { + NMLOG_DEBUG("no interface connected, no ccm check"); + timeoutInSec = NMCONNECTIVITY_MONITOR_MIN_INTERVAL; + m_InternetState = INTERNET_NOT_AVAILABLE; + m_Ipv4InternetState = INTERNET_NOT_AVAILABLE; + m_Ipv6InternetState = INTERNET_NOT_AVAILABLE; + currentInternetState = INTERNET_NOT_AVAILABLE; + if (InitialRetryCount == 0) + m_notify = true; + InitialRetryCount = 1; } - - if(doConnectivityMonitor) - { - NMLOG_DEBUG("connectivity monitor running so skiping ccm check"); - m_Ipv4InternetState = nsm_internetState::UNKNOWN; - m_Ipv6InternetState = nsm_internetState::UNKNOWN; - std::unique_lock lock(connMutex); - cvContinuousMonitor.wait_for(lock, std::chrono::seconds(continuousMonitorTimeout.load())); - ipResolveTyp = NSM_IPRESOLVE_WHATEVER; /* some interface change happense */ - continue; - } - else if (ipResolveTyp == NSM_IPRESOLVE_WHATEVER) + else if (m_switchToInitial) { - nsm_internetState ipV4InternetState = nsm_internetState::UNKNOWN; - nsm_internetState ipV6InternetState = nsm_internetState::UNKNOWN; + NMLOG_INFO("Initial cm check - retry count %d - %s", InitialRetryCount, getInternetStateString(currentInternetState)); + timeoutInSec = NMCONNECTIVITY_MONITOR_MIN_INTERVAL; + + // Lambda functions to check connectivity for IPv4 and IPv6 auto curlCheckThrdIpv4 = [&]() { - TestConnectivity testInternet(getConnectivityMonitorEndpoints(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, - NMCONNECTIVITY_CURL_GET_REQUEST, NSM_IPRESOLVE_V4); - ipV4InternetState = testInternet.getInternetState(); + TestConnectivity testInternet(m_endpoint(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, + NMCONNECTIVITY_CURL_HEAD_REQUEST, IP_ADDRESS_V4); + m_Ipv4InternetState = testInternet.getInternetState(); + if(m_Ipv6InternetState == INTERNET_CAPTIVE_PORTAL) + m_captiveURI = testInternet.getCaptivePortal(); }; auto curlCheckThrdIpv6 = [&]() { - TestConnectivity testInternet(getConnectivityMonitorEndpoints(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, - NMCONNECTIVITY_CURL_GET_REQUEST, NSM_IPRESOLVE_V6); - ipV6InternetState = testInternet.getInternetState(); + TestConnectivity testInternet(m_endpoint(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, + NMCONNECTIVITY_CURL_HEAD_REQUEST, IP_ADDRESS_V6); + m_Ipv6InternetState = testInternet.getInternetState(); + if(m_Ipv6InternetState == INTERNET_CAPTIVE_PORTAL) + m_captiveURI = testInternet.getCaptivePortal(); }; + + // Start threads for IPv4 and IPv6 checks std::thread ipv4thread(curlCheckThrdIpv4); std::thread ipv6thread(curlCheckThrdIpv6); + // Wait for both threads to finish ipv4thread.join(); ipv6thread.join(); - if(ipV4InternetState == FULLY_CONNECTED) { - ipResolveTyp = NSM_IPRESOLVE_V4; - currentInternetState = ipV4InternetState; - NMLOG_INFO("connectivity monitor default ip resolve IPV4"); - } - else if(ipV6InternetState == FULLY_CONNECTED) { - ipResolveTyp = NSM_IPRESOLVE_V6; - currentInternetState = ipV6InternetState; - NMLOG_INFO("connectivity monitor default ip resolve IPV6"); - } - else /* not changing ip resolve type */ - currentInternetState = ipV4InternetState; - } - else /* IPV4 or IPV6 based on default values */ - { - TestConnectivity testInternet(getConnectivityMonitorEndpoints(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, - NMCONNECTIVITY_CURL_HEAD_REQUEST, ipResolveTyp); - currentInternetState = testInternet.getInternetState(); - if(ipResolveTyp == NSM_IPRESOLVE_V4) - m_Ipv4InternetState = currentInternetState; - else if(ipResolveTyp == NSM_IPRESOLVE_V6) - m_Ipv6InternetState = currentInternetState; - } - if (currentInternetState == NO_INTERNET) - { - if(m_InternetState == FULLY_CONNECTED && notifyPreRetry < NMCONNECTIVITY_NO_INTERNET_RETRY_COUNT) - { - /* it will prevent posting notification */ - currentInternetState = m_InternetState; - TempInterval = 5; - NMLOG_INFO("No internet retrying connection check %d ...", notifyPreRetry); - notifyPreRetry++; - /* no internet state retry do it in ipv4 and ipv6 sepratly in two thread */ - ipResolveTyp = NSM_IPRESOLVE_WHATEVER; + // Determine the current internet state based on the results + if (m_Ipv4InternetState == INTERNET_NOT_AVAILABLE && m_Ipv6InternetState == INTERNET_NOT_AVAILABLE) { + currentInternetState = INTERNET_NOT_AVAILABLE; + if (InitialRetryCount == 0) + m_notify = true; + InitialRetryCount = 1; // continue same check for 5 sec + } else { + if (m_Ipv4InternetState == INTERNET_FULLY_CONNECTED || m_Ipv6InternetState == INTERNET_FULLY_CONNECTED) + { + currentInternetState = INTERNET_FULLY_CONNECTED; + m_ipversion = (m_Ipv4InternetState == INTERNET_FULLY_CONNECTED) ? IP_ADDRESS_V4 : IP_ADDRESS_V6; + } + else if (m_Ipv4InternetState == INTERNET_CAPTIVE_PORTAL || m_Ipv6InternetState == INTERNET_CAPTIVE_PORTAL) + { + currentInternetState = INTERNET_CAPTIVE_PORTAL; + m_ipversion = (m_Ipv4InternetState == INTERNET_CAPTIVE_PORTAL) ? IP_ADDRESS_V4 : IP_ADDRESS_V6; + } else if (m_Ipv4InternetState == INTERNET_LIMITED || m_Ipv6InternetState == INTERNET_LIMITED) { + currentInternetState = INTERNET_LIMITED; + m_ipversion = (m_Ipv4InternetState == INTERNET_LIMITED) ? IP_ADDRESS_V4 : IP_ADDRESS_V6; + } else { + currentInternetState = INTERNET_NOT_AVAILABLE; + m_ipversion = IP_ADDRESS_V4; + } + + if (InitialRetryCount == 0) + m_notify = true; + + if (currentInternetState != m_InternetState) { + NMLOG_DEBUG("initial connectivity state change %s", getInternetStateString(m_InternetState)); + m_InternetState = currentInternetState; + InitialRetryCount = 1; // reset retry count to get continuous 3 same state + } + InitialRetryCount++; } - else - { - notifyPreRetry = 1; - TempInterval = continuousMonitorTimeout.load(); + + if (InitialRetryCount > NM_CONNECTIVITY_MONITOR_RETRY_COUNT) { + m_switchToInitial = false; + m_notify = true; + InitialRetryCount = 0; + IdealRetryCount = 0; } } + // Ideal case monitoring else { - notifyPreRetry = 1; - TempInterval = continuousMonitorTimeout.load(); - } - - if(m_InternetState != currentInternetState) - { - /* Notify Internet state change */ - notifyInternetStatusChangedEvent(currentInternetState); - } - - //NMLOG_INFO("icm %d, ccm %d", doConnectivityMonitor.load(), doContinuousMonitor.load()); - if(!doContinuousMonitor) - break; - /* wait for next interval */ - std::unique_lock lock(connMutex); - if (cvContinuousMonitor.wait_for(lock, std::chrono::seconds(TempInterval)) != std::cv_status::timeout) - NMLOG_INFO("continous connectivity monitor recieved signal. skping %d sec interval", TempInterval); + timeoutInSec = NMCONNECTIVITY_MONITOR_RETRY_INTERVAL; + InitialRetryCount = 0; - } while(doContinuousMonitor); - - m_Ipv4InternetState = nsm_internetState::UNKNOWN; - m_Ipv6InternetState = nsm_internetState::UNKNOWN; - NMLOG_DEBUG("continous connectivity monitor exit"); - } + TestConnectivity testInternet(m_endpoint(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, + NMCONNECTIVITY_CURL_HEAD_REQUEST, m_ipversion); + currentInternetState = testInternet.getInternetState(); - void ConnectivityMonitor::connectivityMonitorFunction() - { - int TempInterval = NMCONNECTIVITY_MONITOR_MIN_INTERVAL; - std::mutex connMutex; - bool notifyNow = true; - int notifyPreRetry = 1; - nsm_internetState currentInternetState = nsm_internetState::UNKNOWN; - nsm_internetState tempInternetState = nsm_internetState::UNKNOWN; - - do - { - TestConnectivity testInternet(getConnectivityMonitorEndpoints(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, - NMCONNECTIVITY_CURL_GET_REQUEST, NSM_IPRESOLVE_WHATEVER); - currentInternetState = testInternet.getInternetState(); - if(currentInternetState == CAPTIVE_PORTAL) - { - /* set to every 30 sec interval */ - TempInterval = NMCONNECTIVITY_CONN_MONITOR_RETRY_INTERVAL; - } - else if(currentInternetState == LIMITED_INTERNET) - { - TempInterval = NMCONNECTIVITY_CONN_MONITOR_RETRY_INTERVAL; - } - else // fullyconnect / noInternet - { - if(notifyPreRetry <= NMCONNECTIVITY_CONN_MONITOR_RETRY_COUNT - 1) - { - if(tempInternetState != currentInternetState ) // check for continous same state - { - tempInternetState = currentInternetState; - notifyPreRetry = 1; - NMLOG_INFO("Connectivity check retrying %d ...", notifyPreRetry); - } - else - { - notifyPreRetry++; - NMLOG_INFO("Connectivity check retrying %d ...", notifyPreRetry); - } + if (currentInternetState == INTERNET_CAPTIVE_PORTAL) // if captive portal found copy the URL + m_captiveURI = testInternet.getCaptivePortal(); - if(m_InternetState != nsm_internetState::UNKNOWN) - currentInternetState = m_InternetState; - TempInterval = 5; - } - else if(tempInternetState != currentInternetState) // last state have change + if (currentInternetState != m_InternetState) { - tempInternetState = currentInternetState; - notifyPreRetry = 1; - TempInterval = 5; - NMLOG_INFO("Connectivity check retrying %d ...", notifyPreRetry); - } - else - { - if(currentInternetState == FULLY_CONNECTED) - { - doConnectivityMonitor = false; // self exit - notifyNow = true; // post current state when retry complete - } - else if(_instance != nullptr && (_instance->m_ethConnected | _instance->m_wlanConnected)) + if (currentInternetState == INTERNET_NOT_AVAILABLE && m_InternetState == INTERNET_FULLY_CONNECTED) { - /* 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) + DnsResolver dnsResolver(getConnectivityMonitorEndpoints()[0], m_ipversion, testInternet.getCurlError() ); // only first endpoint with specific ipversion + if (dnsResolver()) { + NMLOG_INFO("DNS resolved, success !!!"); + IdealRetryCount = 0; + currentInternetState = INTERNET_FULLY_CONNECTED; + } + else { - notifyPreRetry++; - notifyNow = true; + NMLOG_WARNING("DNS resolve failed !!!"); + timeoutInSec = NMCONNECTIVITY_MONITOR_MIN_INTERVAL; // retry in 5 sec + IdealRetryCount++; + if (IdealRetryCount >= NM_CONNECTIVITY_MONITOR_RETRY_COUNT) { + IdealRetryCount = 0; + m_InternetState = INTERNET_NOT_AVAILABLE; + m_Ipv4InternetState = INTERNET_NOT_AVAILABLE; + m_Ipv6InternetState = INTERNET_NOT_AVAILABLE; // reset all states to NO_INTERNET + currentInternetState = INTERNET_NOT_AVAILABLE; + m_switchToInitial = true; // switch to initial check after 3 retries + InitialRetryCount = 1; // reset initial retry count it will not post the event + m_notify = true; + NMLOG_DEBUG("No internet retrying completed notifying !!!"); + } else { + NMLOG_INFO("No internet retrying connection check %d ...", IdealRetryCount); + } } + } else { + // a state change happened but it is not fully connected to no internet + // switch to initial check to get the correct state + m_switchToInitial = true; + InitialRetryCount = 0; + IdealRetryCount = 0; + timeoutInSec = NMCONNECTIVITY_MONITOR_MIN_INTERVAL; // retry in 5 sec + + if (m_ipversion == IP_ADDRESS_V4) + m_Ipv4InternetState = currentInternetState; + else if (m_ipversion == IP_ADDRESS_V6) + m_Ipv6InternetState = currentInternetState; + else + m_InternetState = currentInternetState; } - else // no interface connected - { - doConnectivityMonitor = false; - notifyNow = true; - } + } else { // ideal case no change in network state + IdealRetryCount = 0; + m_InternetState = currentInternetState; } } - if(m_InternetState != currentInternetState || notifyNow) - { - notifyNow = false; - notifyInternetStatusChangedEvent(currentInternetState); + if (m_notify) { + m_InternetState = currentInternetState; + notifyInternetStatusChangedEvent(m_InternetState); + m_notify = false; } - if(!doConnectivityMonitor) + if (!m_cmRunning) break; - /* wait for next interval */ - std::unique_lock lock(connMutex); - if (cvConnectivityMonitor.wait_for(lock, std::chrono::seconds(TempInterval)) != std::cv_status::timeout) { - NMLOG_INFO("connectivity monitor recieved signal. skping %d sec interval", TempInterval); - notifyPreRetry = 1; - notifyNow = true; // new signal came should notify in next check - } - - } while(doConnectivityMonitor); - if(!doContinuousMonitor) - m_InternetState = nsm_internetState::UNKNOWN; // no continous monitor running reset to unknow - NMLOG_DEBUG("initial connectivity monitor exit"); + // Wait for next interval + std::unique_lock lock(m_cmMutex); + if (m_cmCv.wait_for(lock, std::chrono::seconds(timeoutInSec)) != std::cv_status::timeout) { + NMLOG_INFO("connectivity monitor received signal. skipping %d sec interval", timeoutInSec); + } + } } } // namespace Plugin diff --git a/NetworkManagerConnectivity.h b/NetworkManagerConnectivity.h index e9840035..38e12ebb 100644 --- a/NetworkManagerConnectivity.h +++ b/NetworkManagerConnectivity.h @@ -19,35 +19,16 @@ #pragma once -#include #include #include #include -#include -#include -#include #include #include #include #include #include -#include -#include -enum nsm_ipversion -{ - NSM_IPRESOLVE_WHATEVER = 0, /* default, resolves addresses to all IP*/ - NSM_IPRESOLVE_V4 = 1, /* resolve to IPv4 addresses */ - NSM_IPRESOLVE_V6 = 2 /* resolve to IPv6 addresses */ -}; - -enum nsm_internetState { - NO_INTERNET, - LIMITED_INTERNET, - CAPTIVE_PORTAL, - FULLY_CONNECTED, - UNKNOWN, -}; +#include "INetworkManager.h" enum nsm_connectivity_httpcode { HttpStatus_response_error = 99, @@ -64,30 +45,50 @@ enum nsm_connectivity_httpcode { #define NMCONNECTIVITY_CURL_HEAD_REQUEST true #define NMCONNECTIVITY_CURL_GET_REQUEST false - -#define NMCONNECTIVITY_MONITOR_DEFAULT_INTERVAL 60 // sec -#define NMCONNECTIVITY_MONITOR_MIN_INTERVAL 5 // sec -#define NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS 5000 // ms -#define NMCONNECTIVITY_NO_INTERNET_RETRY_COUNT 4 // 4 retry -#define NMCONNECTIVITY_CONN_MONITOR_RETRY_COUNT 3 // 3 retry -#define NMCONNECTIVITY_CAPTIVE_MONITOR_INTERVAL 30 // sec -#define NMCONNECTIVITY_CONN_MONITOR_RETRY_INTERVAL 30 // sec +#define NMCONNECTIVITY_MONITOR_CACHE_FILE "/tmp/nm.plugin.endpoints" +#define NMCONNECTIVITY_MONITOR_MIN_INTERVAL 5 // sec +#define NMCONNECTIVITY_MONITOR_RETRY_INTERVAL 30 // sec +#define NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS 5000 // ms +#define NM_CONNECTIVITY_MONITOR_RETRY_COUNT 3 // 3 retry namespace WPEFramework { namespace Plugin { - /* save user specific endponint in to a chache file and load form the file if monitorEndpoints are empty case wpeframework restared */ - class EndpointCache { + + class DnsResolver + { public: - bool isEndpointCashFileExist(); - void writeEnpointsToFile(const std::vector& endpoints); - std::vector readEnpointsFromFile(); + DnsResolver(std::string url, Exchange::INetworkManager::IPVersion ipversion, int curlErrorCode); + ~DnsResolver(){}; + bool operator()() { return (ipv6Resolved || ipv4Resolved);} - EndpointCache() : CachefilePath("/tmp/nm.plugin.endpoints") {} - ~EndpointCache(){} private: - std::string CachefilePath; + std::string m_domain{}; + bool ipv4Resolved = false; + bool ipv6Resolved = false; + std::string convertUrIToDomainName(std::string& url); + bool resolveIP(std::string& uri, Exchange::INetworkManager::IPVersion& ipversion); + }; + + /* + * Save user specific endpoint into a cache file and load from the file + * if endpoints are empty in case plugin is restarted. + */ + class EndpointManager { + public: + EndpointManager(); + ~EndpointManager() {} + void writeEndpointsToFile(const std::vector& endpoints); + std::vector readEndpointsFromFile(); + void setConnectivityMonitorEndpoints(const std::vector& endpoints); + std::vector getConnectivityMonitorEndpoints(); + std::vector operator()() { return getConnectivityMonitorEndpoints(); } + + private: + std::string m_CachefilePath; + std::vector m_Endpoints; + std::mutex m_endpointMutex; }; class TestConnectivity @@ -96,15 +97,17 @@ namespace WPEFramework const TestConnectivity& operator=(const TestConnectivity&) = delete; public: - TestConnectivity(const std::vector& endpoints, long timeout_ms = 2000, bool = true, nsm_ipversion ipversion = NSM_IPRESOLVE_WHATEVER); + TestConnectivity(const std::vector& endpoints, long timeout_ms, bool headReq, Exchange::INetworkManager::IPVersion ipversion); ~TestConnectivity(){} std::string getCaptivePortal() {return captivePortalURI;} - nsm_internetState getInternetState(){return internetSate;} + Exchange::INetworkManager::InternetStatus getInternetState(){return internetSate;} + int getCurlError(){return curlErrorCode;} private: - nsm_internetState checkCurlResponse(const std::vector& endpoints, long timeout_ms, bool headReq, nsm_ipversion ipversion); - nsm_internetState checkInternetStateFromResponseCode(const std::vector& responses); + Exchange::INetworkManager::InternetStatus checkCurlResponse(const std::vector& endpoints, long timeout_ms, bool headReq, Exchange::INetworkManager::IPVersion ipversion); + Exchange::INetworkManager::InternetStatus checkInternetStateFromResponseCode(const std::vector& responses); std::string captivePortalURI; - nsm_internetState internetSate; + Exchange::INetworkManager::InternetStatus internetSate; + int curlErrorCode = 0; }; class ConnectivityMonitor @@ -112,37 +115,33 @@ namespace WPEFramework public: ConnectivityMonitor(); ~ConnectivityMonitor(); - bool startContinuousConnectivityMonitor(int timeoutInSeconds); - bool stopContinuousConnectivityMonitor(); + bool stopConnectivityMonitor(); bool startConnectivityMonitor(); + bool switchToInitialCheck(); void setConnectivityMonitorEndpoints(const std::vector &endpoints); std::vector getConnectivityMonitorEndpoints(); - bool isConnectedToInternet(nsm_ipversion ipversion); - nsm_internetState getInternetState(nsm_ipversion& ipversion); + Exchange::INetworkManager::InternetStatus getInternetState(Exchange::INetworkManager::IPVersion& ipversion, bool ipVersionNotSpecified = false); std::string getCaptivePortalURI(); private: ConnectivityMonitor(const ConnectivityMonitor&) = delete; ConnectivityMonitor& operator=(const ConnectivityMonitor&) = delete; void connectivityMonitorFunction(); - void notifyInternetStatusChangedEvent(nsm_internetState newState); + void notifyInternetStatusChangedEvent(Exchange::INetworkManager::InternetStatus newState); /* connectivity monitor */ - std::thread connectivityMonitorThrd; - std::condition_variable cvConnectivityMonitor; - std::atomic continuousMonitorTimeout; - std::atomic doConnectivityMonitor; - std::vector connectivityMonitorEndpt; - /*continuous connectivity monitor */ - std::atomic doContinuousMonitor; - std::thread continuousMonitorThrd; - std::condition_variable cvContinuousMonitor; - void continuousMonitorFunction(); - - EndpointCache endpointCache; - std::mutex endpointMutex; - std::atomic m_InternetState; - std::atomic m_Ipv4InternetState; - std::atomic m_Ipv6InternetState; + std::thread m_cmThrdID; + std::atomic m_cmRunning; + std::condition_variable m_cmCv; + std::mutex m_cmMutex; + std::atomic m_notify; + std::atomic m_switchToInitial; + std::string m_captiveURI; + std::atomic m_InternetState; // IPv4 or IPv6 + std::atomic m_Ipv4InternetState; // IPv4 + std::atomic m_Ipv6InternetState; // IPv6 + std::atomic m_ipversion; // IPv6 + /* manages endpoints */ + EndpointManager m_endpoint; }; } // namespace Plugin } // namespace WPEFramework diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index 5719c718..ee6b3687 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -53,11 +53,11 @@ namespace WPEFramework NetworkManagerImplementation::~NetworkManagerImplementation() { LOG_ENTRY_FUNCTION(); + if(m_registrationThread.joinable()) { m_registrationThread.join(); } - connectivityMonitor.stopContinuousConnectivityMonitor(); } /** @@ -244,27 +244,20 @@ namespace WPEFramework } /* @brief Get Internet Connectivty Status */ - uint32_t NetworkManagerImplementation::IsConnectedToInternet(string &ipversion /* @in */, InternetStatus &result /* @out */) + uint32_t NetworkManagerImplementation::IsConnectedToInternet(string &ipversion /* @inout */, InternetStatus &result /* @out */) { LOG_ENTRY_FUNCTION(); - nsm_internetState isconnected; - nsm_ipversion tmpVersion = NSM_IPRESOLVE_WHATEVER; + Exchange::INetworkManager::IPVersion curlIPversion = Exchange::INetworkManager::IP_ADDRESS_V4; + bool ipVersionNotSpecified = false; if(0 == strcasecmp("IPv4", ipversion.c_str())) - tmpVersion = NSM_IPRESOLVE_V4; + curlIPversion = Exchange::INetworkManager::IP_ADDRESS_V4; else if(0 == strcasecmp("IPv6", ipversion.c_str())) - tmpVersion = NSM_IPRESOLVE_V6; - - isconnected = connectivityMonitor.getInternetState(tmpVersion); - if (FULLY_CONNECTED == isconnected) - result = INTERNET_FULLY_CONNECTED; - else if (CAPTIVE_PORTAL == isconnected) - result = INTERNET_CAPTIVE_PORTAL; - else if (LIMITED_INTERNET == isconnected) - result = INTERNET_LIMITED; + curlIPversion = Exchange::INetworkManager::IP_ADDRESS_V6; else - result = INTERNET_NOT_AVAILABLE; + ipVersionNotSpecified = true; - if (NSM_IPRESOLVE_V6 == tmpVersion) + result = connectivityMonitor.getInternetState(curlIPversion, ipVersionNotSpecified); + if (Exchange::INetworkManager::IP_ADDRESS_V6 == curlIPversion) ipversion = "IPv6"; else ipversion = "IPv4"; @@ -280,26 +273,6 @@ namespace WPEFramework return Core::ERROR_NONE; } - /* @brief Start The Internet Connectivity Monitoring */ - uint32_t NetworkManagerImplementation::StartConnectivityMonitoring(const uint32_t interval/* @in */) - { - LOG_ENTRY_FUNCTION(); - if (connectivityMonitor.startContinuousConnectivityMonitor(interval)) - return Core::ERROR_NONE; - else - return Core::ERROR_GENERAL; - } - - /* @brief Stop The Internet Connectivity Monitoring */ - uint32_t NetworkManagerImplementation::StopConnectivityMonitoring(void) const - { - LOG_ENTRY_FUNCTION(); - if (connectivityMonitor.stopContinuousConnectivityMonitor()) - return Core::ERROR_NONE; - else - return Core::ERROR_GENERAL; - } - /* @brief Get the Public IP used for external world communication */ uint32_t NetworkManagerImplementation::GetPublicIP (string& interface /* @inout */, string &ipversion /* @inout */, string& ipaddress /* @out */) { @@ -614,8 +587,7 @@ namespace WPEFramework m_ethConnected = false; else if(interface == "wlan0") m_wlanConnected = false; - - connectivityMonitor.startConnectivityMonitor(); + connectivityMonitor.switchToInitialCheck(); } /* Only the Ethernet connection status is changing here. The WiFi status is updated in the WiFi state callback. */ @@ -653,6 +625,7 @@ namespace WPEFramework { LOG_ENTRY_FUNCTION(); if (Exchange::INetworkManager::IP_ACQUIRED == status) { + // Switch the connectivity monitor to initial check // if ipaddress is aquired means there should be interface connected if(interface == "eth0") m_ethConnected = true; @@ -665,9 +638,7 @@ namespace WPEFramework else m_defaultInterface = interface; - // 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(); + connectivityMonitor.switchToInitialCheck(); } _notificationLock.Lock(); diff --git a/NetworkManagerImplementation.h b/NetworkManagerImplementation.h index 0c1d0645..16fd2f79 100644 --- a/NetworkManagerImplementation.h +++ b/NetworkManagerImplementation.h @@ -224,11 +224,6 @@ namespace WPEFramework /* @brief Get Authentication URL if the device is behind Captive Portal */ uint32_t GetCaptivePortalURI(string &endpoints/* @out */) const override; - /* @brief Start The Internet Connectivity Monitoring */ - uint32_t StartConnectivityMonitoring(const uint32_t interval/* @in */) override; - /* @brief Stop The Internet Connectivity Monitoring */ - uint32_t StopConnectivityMonitoring(void) const override; - /* @brief Get the Public IP used for external world communication */ uint32_t GetPublicIP (string& interface /* @inout */, string &ipversion /* @inout */, string& ipaddress /* @out */) override; diff --git a/NetworkManagerJsonRpc.cpp b/NetworkManagerJsonRpc.cpp index f1269af1..55be805b 100644 --- a/NetworkManagerJsonRpc.cpp +++ b/NetworkManagerJsonRpc.cpp @@ -67,8 +67,6 @@ namespace WPEFramework Register("SetConnectivityTestEndpoints", &NetworkManager::SetConnectivityTestEndpoints, this); Register("IsConnectedToInternet", &NetworkManager::IsConnectedToInternet, this); Register("GetCaptivePortalURI", &NetworkManager::GetCaptivePortalURI, this); - Register("StartConnectivityMonitoring", &NetworkManager::StartConnectivityMonitoring, this); - Register("StopConnectivityMonitoring", &NetworkManager::StopConnectivityMonitoring, this); Register("GetPublicIP", &NetworkManager::GetPublicIP, this); Register("Ping", &NetworkManager::Ping, this); Register("Trace", &NetworkManager::Trace, this); @@ -106,8 +104,6 @@ namespace WPEFramework Unregister("SetConnectivityTestEndpoints"); Unregister("IsConnectedToInternet"); Unregister("GetCaptivePortalURI"); - Unregister("StartConnectivityMonitoring"); - Unregister("StopConnectivityMonitoring"); Unregister("GetPublicIP"); Unregister("Ping"); Unregister("Trace"); @@ -503,34 +499,6 @@ namespace WPEFramework returnJson(rc); } - uint32_t NetworkManager::StartConnectivityMonitoring(const JsonObject& parameters, JsonObject& response) - { - LOG_INPARAM(); - uint32_t rc = Core::ERROR_GENERAL; - uint32_t interval = parameters["interval"].Number(); - - NMLOG_DEBUG("connectivity interval = %d", interval); - if (_networkManager) - rc = _networkManager->StartConnectivityMonitoring(interval); - else - rc = Core::ERROR_UNAVAILABLE; - - returnJson(rc); - } - - uint32_t NetworkManager::StopConnectivityMonitoring(const JsonObject& parameters, JsonObject& response) - { - LOG_INPARAM(); - uint32_t rc = Core::ERROR_GENERAL; - - if (_networkManager) - rc = _networkManager->StopConnectivityMonitoring(); - else - rc = Core::ERROR_UNAVAILABLE; - - returnJson(rc); - } - uint32_t NetworkManager::GetPublicIP(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); diff --git a/NetworkManagerRDKProxy.cpp b/NetworkManagerRDKProxy.cpp index 96119348..4b35e51e 100644 --- a/NetworkManagerRDKProxy.cpp +++ b/NetworkManagerRDKProxy.cpp @@ -689,7 +689,6 @@ namespace WPEFramework */ getInitialConnectionState(); } - } uint32_t NetworkManagerImplementation::GetAvailableInterfaces (Exchange::INetworkManager::IInterfaceDetailsIterator*& interfacesItr/* @out */) diff --git a/Tests/unit_test/test_NetworkManagerConnectivity.cpp b/Tests/unit_test/test_NetworkManagerConnectivity.cpp index 1b59920f..2f6cf144 100644 --- a/Tests/unit_test/test_NetworkManagerConnectivity.cpp +++ b/Tests/unit_test/test_NetworkManagerConnectivity.cpp @@ -29,77 +29,11 @@ class ConnectivityMonitorTest : public ::testing::Test { WPEFramework::Plugin::ConnectivityMonitor cm; }; -TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_Success) { - int timeout = 30; - bool result = cm.startContinuousConnectivityMonitor(timeout); - EXPECT_TRUE(result); -} - -TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_FailureNegativeTimeout) { - int timeout = -1; - bool result = cm.startContinuousConnectivityMonitor(timeout); - EXPECT_TRUE(result); -} - -TEST_F(ConnectivityMonitorTest, StartMonitorWithTimeoutLessThanMinimum) { - int timeout = 3; - bool result = cm.startContinuousConnectivityMonitor(timeout); - EXPECT_TRUE(result); -} - -TEST_F(ConnectivityMonitorTest, MonitorFailsToStart) { - int timeout = 0; - bool result = cm.startContinuousConnectivityMonitor(timeout); - EXPECT_TRUE(result); -} - -TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_WhenStarted) { - int timeout = 30; - cm.startContinuousConnectivityMonitor(timeout); - bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); -} - -TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_WhenNotStarted) { - bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); -} - -TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_AfterMultipleStartsAndStops) { - int timeout = 30; - cm.startContinuousConnectivityMonitor(timeout); - bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); - - cm.startContinuousConnectivityMonitor(timeout); - result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); - - cm.startContinuousConnectivityMonitor(timeout); - result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); -} - -TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_LongRunningMonitor) { - int timeout = 1000; - cm.startContinuousConnectivityMonitor(timeout); - std::this_thread::sleep_for(std::chrono::seconds(2)); - - bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); -} - -TEST_F(ConnectivityMonitorTest, StartMonitor_WithInterfaceStatus) { +TEST_F(ConnectivityMonitorTest, StartConnectivityMonitor_Success) { bool result = cm.startConnectivityMonitor(); EXPECT_TRUE(result); -} - -TEST_F(ConnectivityMonitorTest, StartMonitor_NotifyIfAlreadyMonitoring) { - bool result = false; result = cm.startConnectivityMonitor(); EXPECT_TRUE(result); - result = cm.startConnectivityMonitor(); - EXPECT_TRUE(result); } TEST_F(ConnectivityMonitorTest, SetEndpoints_Valid) { @@ -108,12 +42,6 @@ TEST_F(ConnectivityMonitorTest, SetEndpoints_Valid) { EXPECT_EQ(cm.getConnectivityMonitorEndpoints(), endpoints); } -TEST_F(ConnectivityMonitorTest, SetEndpoints_EmptyList) { - std::vector endpoints; - cm.setConnectivityMonitorEndpoints(endpoints); - EXPECT_TRUE(cm.getConnectivityMonitorEndpoints().empty()); -} - TEST_F(ConnectivityMonitorTest, SetEndpoints_InvalidShortEndpoints) { std::vector endpoints = {"ab", "htt", "xyz"}; cm.setConnectivityMonitorEndpoints(endpoints); diff --git a/docs/NetworkManagerPlugin.md b/docs/NetworkManagerPlugin.md index 66203f5f..3af6eff5 100644 --- a/docs/NetworkManagerPlugin.md +++ b/docs/NetworkManagerPlugin.md @@ -87,8 +87,6 @@ NetworkManager interface methods: | [SetConnectivityTestEndpoints](#method.SetConnectivityTestEndpoints) | This method used to set up to 5 endpoints for a connectivity test | | [IsConnectedToInternet](#method.IsConnectedToInternet) | Seeks whether the device has internet connectivity | | [GetCaptivePortalURI](#method.GetCaptivePortalURI) | Gets the captive portal URI if connected to any captive portal network | -| [StartConnectivityMonitoring](#method.StartConnectivityMonitoring) | Enable a continuous monitoring of internet connectivity with heart beat interval thats given | -| [StopConnectivityMonitoring](#method.StopConnectivityMonitoring) | Stops the connectivity monitoring | | [GetPublicIP](#method.GetPublicIP) | Gets the internet/public IP Address of the device | | [Ping](#method.Ping) | Pings the specified endpoint with the specified number of packets | | [Trace](#method.Trace) | Traces the specified endpoint with the specified number of packets using `traceroute` | @@ -404,7 +402,7 @@ Gets the current Status of the specified interface. | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.interface | string | Disable the specified interface | +| params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | ### Result @@ -686,8 +684,8 @@ This method takes no parameters. | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.endpoints | array | | -| result.endpoints[#] | string | | +| result.endpoints | array | A list of endpoint URLs used | +| result.endpoints[#] | string | The endpoint URL | | result.success | boolean | Whether the request succeeded | ### Example @@ -728,7 +726,7 @@ This method used to set up to 5 endpoints for a connectivity test. Successful co | :-------- | :-------- | :-------- | | params | object | | | params.endpoints | array | A list of endpoints to test | -| params.endpoints[#] | string | | +| params.endpoints[#] | string | The endpoint URL | ### Result @@ -862,94 +860,6 @@ This method takes no parameters. } ``` - -## *StartConnectivityMonitoring [method](#head.Methods)* - -Enable a continuous monitoring of internet connectivity with heart beat interval thats given. If the monitoring is already happening, it will be restarted with new given interval. When the interval is not passed, it will be 60s by default. - -Also see: [onInternetStatusChange](#event.onInternetStatusChange) - -### Parameters - -| Name | Type | Description | -| :-------- | :-------- | :-------- | -| params | object | | -| params?.interval | integer | *(optional)* Interval in sec | - -### 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.StartConnectivityMonitoring", - "params": { - "interval": 30 - } -} -``` - -#### Response - -```json -{ - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } -} -``` - - -## *StopConnectivityMonitoring [method](#head.Methods)* - -Stops the connectivity monitoring. - -### Parameters - -This method takes no parameters. - -### 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.StopConnectivityMonitoring" -} -``` - -#### Response - -```json -{ - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } -} -``` - ## *GetPublicIP [method](#head.Methods)* @@ -1150,7 +1060,7 @@ Also see: [onAvailableSSIDs](#event.onAvailableSSIDs) | params | object | | | params?.frequency | string | *(optional)* The frequency to scan. An empty or `null` value scans all frequencies | | params?.ssids | array | *(optional)* The list of SSIDs to be scanned | -| params?.ssids[#] | string | *(optional)* | +| params?.ssids[#] | string | *(optional)* The SSID to scan | ### Result @@ -1243,8 +1153,8 @@ This method takes no parameters. | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.ssids | array | Known SSIDS | -| result.ssids[#] | string | | +| result.ssids | array | A list of known SSIDs | +| result.ssids[#] | string | The WiFi SSID Name | | result.success | boolean | Whether the request succeeded | ### Example @@ -1284,7 +1194,7 @@ Saves the SSID, passphrase, and security mode for upcoming and future sessions. | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.ssid | string | The paired SSID | +| params.ssid | string | The WiFi SSID Name | | params.passphrase | string | The access point password | | params.security | integer | The security mode. See `getSupportedsecurityModes` | @@ -1305,7 +1215,7 @@ Saves the SSID, passphrase, and security mode for upcoming and future sessions. "id": 42, "method": "org.rdk.NetworkManager.1.AddToKnownSSIDs", "params": { - "ssid": "123412341234", + "ssid": "myHomeSSID", "passphrase": "password", "security": 6 } @@ -1336,7 +1246,7 @@ Also see: [onWiFiStateChange](#event.onWiFiStateChange), [onAddressChange](#even | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.ssid | string | The paired SSID | +| params.ssid | string | The WiFi SSID Name | ### Result @@ -1355,7 +1265,7 @@ Also see: [onWiFiStateChange](#event.onWiFiStateChange), [onAddressChange](#even "id": 42, "method": "org.rdk.NetworkManager.1.RemoveKnownSSID", "params": { - "ssid": "123412341234" + "ssid": "myHomeSSID" } } ``` @@ -1384,7 +1294,7 @@ Also see: [onWiFiStateChange](#event.onWiFiStateChange) | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.ssid | string | The paired SSID | +| params.ssid | string | The WiFi SSID Name | | params.passphrase | string | The access point password | | params.security | integer | The security mode. See `getSupportedsecurityModes` | | params?.ca_cert | string | *(optional)* The ca_cert to be used for EAP | @@ -1415,7 +1325,7 @@ Also see: [onWiFiStateChange](#event.onWiFiStateChange) "id": 42, "method": "org.rdk.NetworkManager.1.WiFiConnect", "params": { - "ssid": "123412341234", + "ssid": "myHomeSSID", "passphrase": "password", "security": 6, "ca_cert": "...", @@ -1500,10 +1410,10 @@ This method takes no parameters. | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.ssid | string | The paired SSID | -| result.bssid | string | The paired BSSID | +| result.ssid | string | The WiFi SSID Name | +| result.bssid | string | The BSSID of given SSID | | result.security | string | The security mode. See the `connect` method | -| result.strength | string | The RSSI value in dBm | +| result.strength | string | The Signal RSSI value in dBm | | result.frequency | string | The supported frequency for this SSID in GHz | | result.rate | string | The physical data rate in Mbps | | result.noise | string | The average noise strength in dBm | @@ -1528,8 +1438,8 @@ This method takes no parameters. "jsonrpc": "2.0", "id": 42, "result": { - "ssid": "123412341234", - "bssid": "ff:ff:ff:ff:ff:ff", + "ssid": "myHomeSSID", + "bssid": "AA:BB:CC:DD:EE:FF", "security": "5", "strength": "-27.000000", "frequency": "2.442000", @@ -1658,8 +1568,8 @@ This method takes no parameters. | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.ssid | string | The paired SSID | -| result.strength | string | The RSSI value in dBm | +| result.ssid | string | The WiFi SSID Name | +| result.strength | string | The Signal RSSI value in dBm | | result.quality | string | Signal strength Quality | | result.success | boolean | Whether the request succeeded | @@ -1682,7 +1592,7 @@ This method takes no parameters. "jsonrpc": "2.0", "id": 42, "result": { - "ssid": "123412341234", + "ssid": "myHomeSSID", "strength": "-27.000000", "quality": "Excellent", "success": true @@ -1974,10 +1884,10 @@ Triggered when scan completes or when scan cancelled. | params | object | | | params.ssids | array | On Available SSID's | | params.ssids[#] | object | | -| params.ssids[#].ssid | string | Ssid | -| params.ssids[#].security | integer | Security | -| params.ssids[#].strength | string | Strength | -| params.ssids[#].frequency | string | Frequency | +| params.ssids[#].ssid | string | Discovered SSID | +| params.ssids[#].security | integer | The security mode. See `getSupportedsecurityModes` | +| params.ssids[#].strength | string | The Signal RSSI value in dBm | +| params.ssids[#].frequency | string | The supported frequency for this SSID in GHz | ### Example @@ -2034,9 +1944,9 @@ Triggered when WIFI connection Signal Strength get changed. | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.ssid | string | Signal Strength changed SSID | -| params.strength | string | Signal Strength | -| params.quality | string | Signal quality | +| params.ssid | string | The WiFi SSID Name | +| params.strength | string | The Signal RSSI value in dBm | +| params.quality | string | Signal strength Quality | ### Example @@ -2045,7 +1955,7 @@ Triggered when WIFI connection Signal Strength get changed. "jsonrpc": "2.0", "method": "client.events.1.onWiFiSignalStrengthChange", "params": { - "ssid": "home-new_123", + "ssid": "myHomeSSID", "strength": "-27.000000", "quality": "Excellent" }