From e34f87f1b2a8783d4c7b0b5a6e09935cb1bfb9c7 Mon Sep 17 00:00:00 2001 From: Karunakaran A <48997923+karuna2git@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:06:05 -0400 Subject: [PATCH] DELIA-66644 : Implement ComRPC in Network and WiFi Plugin to communicate with NetworkManager (#21) Reason for change: Use ComRPC in Network and WiFi Plugin to communicate with NetworkManager Test Procedure: Perform all the Network and Wifi JSONRPC requests n confirm Risks: High Signed-off-by: Karunakaran A --- CMakeLists.txt | 9 +- INetworkManager.h | 191 ++-- LegacyPlugin_NetworkAPIs.cpp | 815 +++++++++------- LegacyPlugin_NetworkAPIs.h | 6 +- LegacyPlugin_WiFiManagerAPIs.cpp | 437 +++++---- Module.cpp | 2 +- NetworkManager.cpp | 11 +- NetworkManager.h | 151 +-- NetworkManager.json | 720 ++++++++------ NetworkManagerConnectivity.cpp | 14 +- NetworkManagerConnectivity.h | 2 +- NetworkManagerGnomeEvents.cpp | 18 +- NetworkManagerGnomeEvents.h | 10 +- NetworkManagerGnomeProxy.cpp | 78 +- NetworkManagerGnomeWIFI.cpp | 85 +- NetworkManagerGnomeWIFI.h | 2 +- NetworkManagerImplementation.cpp | 104 +- NetworkManagerImplementation.h | 33 +- NetworkManagerJsonEnum.h | 99 ++ NetworkManagerJsonRpc.cpp | 737 +++++++------- NetworkManagerLogger.cpp | 25 +- NetworkManagerLogger.h | 7 + NetworkManagerPlugin.json | 15 - NetworkManagerRDKProxy.cpp | 170 ++-- WiFiSignalStrengthMonitor.cpp | 2 +- docs/NetworkManagerPlugin.md | 1558 ++++++++++++++---------------- 26 files changed, 2737 insertions(+), 2564 deletions(-) create mode 100644 NetworkManagerJsonEnum.h delete mode 100644 NetworkManagerPlugin.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c390399..7bfac119 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ find_package(WPEFramework) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") set(VERSION_MAJOR 0) -set(VERSION_MINOR 4) +set(VERSION_MINOR 5) set(VERSION_PATCH 0) add_compile_definitions(NETWORKMANAGER_MAJOR_VERSION=${VERSION_MAJOR}) @@ -34,6 +34,9 @@ set(PLUGIN_NETWORKMANAGER_STARTUPORDER "55" CACHE STRING "To configure startup o set(PLUGIN_LEGACY_NW_STARTUPORDER "56" CACHE STRING "To configure startup order of Legacy Network plugin") set(PLUGIN_LEGACY_WIFI_STARTUPORDER "56" CACHE STRING "To configure startup order of Legacy WiFi plugin") +set(PLUGIN_BUILD_REFERENCE ${PROJECT_VERSION} CACHE STRING "To Set the Hash for the plugin") +add_definitions(-DPLUGIN_BUILD_REFERENCE=${PLUGIN_BUILD_REFERENCE}) + if(ENABLE_GNOME_NETWORKMANAGER) pkg_check_modules(GLIB REQUIRED glib-2.0) pkg_check_modules(LIBNM REQUIRED libnm) @@ -45,6 +48,7 @@ endif () message("Setup ProxyStub for INetworkManager.h") find_package(CompileSettingsDebug CONFIG REQUIRED) find_package(ProxyStubGenerator REQUIRED) +find_package(JsonGenerator REQUIRED) set(ProxyStubGenerator_DIR ${CMAKE_SYSROOT}${CMAKE_INSTALL_PREFIX}/tools/cmake ${ProxyStubGenerator_DIR}) @@ -55,6 +59,9 @@ endif() message("The Search path is, ${GENERATOR_SEARCH_PATH}") ProxyStubGenerator(INPUT "${CMAKE_CURRENT_SOURCE_DIR}" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated" INCLUDE_PATH ${GENERATOR_SEARCH_PATH}) +set(JSON_FILE "${CMAKE_CURRENT_SOURCE_DIR}/NetworkManager.json") +JsonGenerator(CODE INPUT ${JSON_FILE} OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/generated" INCLUDE_PATH ${GENERATOR_SEARCH_PATH} CPPIFDIR "${CMAKE_CURRENT_SOURCE_DIR}" DOCS) + file(GLOB PROXY_STUB_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/generated/ProxyStubs*.cpp") message("Setup ${PROJECT_NAME} v${PROJECT_VERSION}") diff --git a/INetworkManager.h b/INetworkManager.h index f50c6296..254eb063 100644 --- a/INetworkManager.h +++ b/INetworkManager.h @@ -26,77 +26,73 @@ namespace WPEFramework { namespace Exchange { - enum myNetwork_ids { + enum myIDs { ID_NETWORKMANAGER = 0x800004E0, ID_NETWORKMANAGER_NOTIFICATION = ID_NETWORKMANAGER + 1, ID_NETWORKMANAGER_INTERFACE_DETAILS_ITERATOR = ID_NETWORKMANAGER + 2, ID_NETWORKMANAGER_WIFI_SECURITY_MODE_ITERATOR = ID_NETWORKMANAGER + 3 }; - /* @json */ + /* @json @text:keep */ struct EXTERNAL INetworkManager: virtual public Core::IUnknown { // All interfaces require a unique ID, defined in Ids.h enum { ID = ID_NETWORKMANAGER }; // Define the RPC methods - enum InterfaceType : uint8_t - { - INTERFACE_TYPE_ETHERNET, - INTERFACE_TYPE_WIFI, - INTERFACE_TYPE_P2P, + enum InterfaceType : uint8_t { + INTERFACE_TYPE_ETHERNET /* @text: ETHERNET */, + INTERFACE_TYPE_WIFI /* @text: WIFI */, + INTERFACE_TYPE_P2P /* @text: P2P */, }; struct EXTERNAL InterfaceDetails { - string m_type; - string m_name; - string m_mac; - bool m_isEnabled; - bool m_isConnected; + InterfaceType type; + string name; + string mac; + bool enabled; + bool connected; }; - enum IPAddressType : uint8_t + enum IPVersion : uint8_t { - IP_ADDRESS_V4, - IP_ADDRESS_V6, - IP_ADDRESS_BOTH + IP_ADDRESS_V4 /* @text: IPv4 */, + IP_ADDRESS_V6 /* @text: IPv6 */, }; - struct EXTERNAL IPAddressInfo { - string m_ipAddrType; - bool m_autoConfig; - string m_dhcpServer; - string m_v6LinkLocal; - string m_ipAddress; - uint32_t m_prefix; - string m_gateway; - string m_primaryDns; - string m_secondaryDns; + enum IPStatus : uint8_t + { + IP_LOST /* @text: LOST */, + IP_ACQUIRED /* @text: ACQUIRED */, }; - // Define the RPC methods - enum InternetStatus : uint8_t - { - INTERNET_NOT_AVAILABLE, - INTERNET_LIMITED, - INTERNET_CAPTIVE_PORTAL, - INTERNET_FULLY_CONNECTED, - INTERNET_UNKNOWN, + struct EXTERNAL IPAddress { + string ipversion /* @text: ipversion */; + bool autoconfig /* @text: autoconfig */; + string dhcpserver /* @text: dhcpserver */; + string ula /* @text: ula */; + string ipaddress /* @text: ipaddress */; + uint32_t prefix /* @text: prefix */; + string gateway /* @text: gateway */; + string primarydns /* @text: primarydns */; + string secondarydns /* @text: secondarydns */; }; - enum WiFiFrequency : uint8_t + // Define the RPC methods + enum InternetStatus : uint8_t { - WIFI_FREQUENCY_WHATEVER, - WIFI_FREQUENCY_2_4_GHZ, - WIFI_FREQUENCY_5_GHZ, - WIFI_FREQUENCY_6_GHZ + INTERNET_NOT_AVAILABLE /* @text: NO_INTERNET */, + INTERNET_LIMITED /* @text: LIMITED_INTERNET */, + INTERNET_CAPTIVE_PORTAL /* @text: CAPTIVE_PORTAL */, + INTERNET_FULLY_CONNECTED /* @text: FULLY_CONNECTED */, + INTERNET_UNKNOWN /* @text: NO_INTERNET */, }; enum WiFiWPS : uint8_t { - WIFI_WPS_PBC, - WIFI_WPS_PIN, - WIFI_WPS_SERIALIZED_PIN + WIFI_WPS_PBC /* @text: PBC */, + WIFI_WPS_PIN /* @text: PIN */, + WIFI_WPS_SERIALIZED_PIN /* @text: SERIALIZED_PIN */, }; enum WIFISecurityMode : uint8_t @@ -119,49 +115,53 @@ namespace WPEFramework }; struct EXTERNAL WiFiScanResults { - string m_ssid; - WIFISecurityMode m_securityMode; - string m_signalStrength; - double m_frequency; + string ssid; + WIFISecurityMode security; + string strength; + string frequency; }; struct EXTERNAL WiFiConnectTo { - string m_ssid; - string m_passphrase; - WIFISecurityMode m_securityMode; - string m_identity; - string m_caCert; - string m_clientCert; - string m_privateKey; - string m_privateKeyPasswd; - bool m_persistSSIDInfo; + string ssid; + string passphrase; + WIFISecurityMode security; + string ca_cert; + string client_cert; + string private_key; + string private_key_passwd; + string eap; + string eap_identity; + string eap_password; + string eap_phase1; + string eap_phase2; + bool persist; }; struct EXTERNAL WiFiSSIDInfo { - string m_ssid; - string m_bssid; - WIFISecurityMode m_securityMode; - string m_signalStrength; - double m_frequency; - string m_rate; - string m_noise; + string ssid; + string bssid; + WIFISecurityMode security; + string strength; + string frequency; + string rate; + string noise; }; struct EXTERNAL WIFISecurityModeInfo { - WIFISecurityMode m_securityMode; - string m_securityModeText; + WIFISecurityMode security; + string securityName; }; enum WiFiSignalQuality : uint8_t { - WIFI_SIGNAL_DISCONNECTED, - WIFI_SIGNAL_WEAK, - WIFI_SIGNAL_FAIR, - WIFI_SIGNAL_GOOD, - WIFI_SIGNAL_EXCELLENT + WIFI_SIGNAL_DISCONNECTED /* @text: Disconnected */, + WIFI_SIGNAL_WEAK /* @text: Weak */, + WIFI_SIGNAL_FAIR /* @text: Fair */, + WIFI_SIGNAL_GOOD /* @text: Good */, + WIFI_SIGNAL_EXCELLENT /* @text: Excellent */ }; - enum NMLogging : uint8_t + enum Logging : uint8_t { LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, @@ -213,29 +213,29 @@ namespace WPEFramework virtual uint32_t SetPrimaryInterface (const string& interface/* @in */) = 0; /* @brief Enable/Disable the given interface */ - virtual uint32_t SetInterfaceState (const string& interface /* @in */, const bool& enabled /* @in */) = 0; + virtual uint32_t SetInterfaceState (const string& interface /* @in */, const bool enabled /* @in */) = 0; /* @brief Get the state of given interface */ - virtual uint32_t GetInterfaceState (const string& interface /* @in */, bool& isEnabled /* @out */) = 0; + virtual uint32_t GetInterfaceState (const string& interface /* @in */, bool& enabled /* @out */) = 0; /* @brief Get IP Address Of the Interface */ - virtual uint32_t GetIPSettings(const string& interface /* @in */, const string &ipversion /* @in */, IPAddressInfo& result /* @out */) = 0; + virtual uint32_t GetIPSettings(string& interface /* @inout */, const string& ipversion /* @in */, IPAddress& address /* @out */) = 0; /* @brief Set IP Address Of the Interface */ - virtual uint32_t SetIPSettings(const string& interface /* @in */, const string &ipversion /* @in */, const IPAddressInfo& address /* @in */) = 0; + virtual uint32_t SetIPSettings(const string& interface /* @in */, const IPAddress& address /* @in */) = 0; /* @brief Get STUN Endpoint to be used for identifying Public IP */ - virtual uint32_t GetStunEndpoint (string &endPoint /* @out */, uint32_t &port /* @out */, uint32_t &bindTimeout /* @out */, uint32_t &cacheTimeout /* @out */) const = 0; + virtual uint32_t GetStunEndpoint (string &endpoint /* @out */, uint32_t &port /* @out */, uint32_t &timeout /* @out */, uint32_t &cacheLifetime/* @out */) const = 0; /* @brief Set STUN Endpoint to be used to identify Public IP */ - virtual uint32_t SetStunEndpoint (string const endPoint /* @in */, const uint32_t port /* @in */, const uint32_t bindTimeout /* @in */, const uint32_t cacheTimeout /* @in */) = 0; + virtual uint32_t SetStunEndpoint (string const endpoint /* @in */, const uint32_t port /* @in */, const uint32_t timeout /* @in */, const uint32_t cacheLifetime /* @in */) = 0; /* @brief Get ConnectivityTest Endpoints */ - virtual uint32_t GetConnectivityTestEndpoints(IStringIterator*& endPoints/* @out */) const = 0; + virtual uint32_t GetConnectivityTestEndpoints(IStringIterator*& endpoints/* @out */) const = 0; /* @brief Set ConnectivityTest Endpoints */ - virtual uint32_t SetConnectivityTestEndpoints(IStringIterator* const endPoints /* @in */) = 0; + virtual uint32_t SetConnectivityTestEndpoints(IStringIterator* const endpoints /* @in */) = 0; /* @brief Get Internet Connectivty Status */ - virtual uint32_t IsConnectedToInternet(const string &ipversion /* @in */, InternetStatus &result /* @out */) = 0; + virtual uint32_t IsConnectedToInternet(string &ipversion /* @inout */, InternetStatus& status /* @out */) = 0; /* @brief Get Authentication URL if the device is behind Captive Portal */ - virtual uint32_t GetCaptivePortalURI(string &endPoints/* @out */) const = 0; + 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; @@ -243,18 +243,18 @@ namespace WPEFramework virtual uint32_t StopConnectivityMonitoring(void) const = 0; /* @brief Get the Public IP used for external world communication */ - virtual uint32_t GetPublicIP (const string &ipversion /* @in */, string& ipAddress /* @out */) = 0; + virtual uint32_t GetPublicIP (const string &ipversion /* @in */, string& ipaddress /* @out */) = 0; /* @brief Request for ping and get the response in as event. The GUID used in the request will be returned in the event. */ - virtual uint32_t Ping (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t noOfRequest /* @in */, const uint16_t timeOutInSeconds /* @in */, const string guid /* @in */, string& response /* @out */) = 0; + virtual uint32_t Ping (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t count /* @in */, const uint16_t timeout /* @in */, const string guid /* @in */, string& response /* @out */) = 0; /* @brief Request for trace get the response in as event. The GUID used in the request will be returned in the event. */ - virtual uint32_t Trace (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t noOfRequest /* @in */, const string guid /* @in */, string& response /* @out */) = 0; + virtual uint32_t Trace (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t nqueries /* @in */, const string guid /* @in */, string& response /* @out */) = 0; // WiFi Specific Methods /* @brief Initiate a WIFI Scan; This is Async method and returns the scan results as Event */ - virtual uint32_t StartWiFiScan(const WiFiFrequency frequency /* @in */) = 0; + virtual uint32_t StartWiFiScan(const string& frequency /* @in */, IStringIterator* const ssids/* @in */) = 0; virtual uint32_t StopWiFiScan(void) = 0; virtual uint32_t GetKnownSSIDs(IStringIterator*& ssids /* @out */) = 0; @@ -265,17 +265,18 @@ namespace WPEFramework virtual uint32_t WiFiDisconnect(void) = 0; virtual uint32_t GetConnectedSSID(WiFiSSIDInfo& ssidInfo /* @out */) = 0; - virtual uint32_t StartWPS(const WiFiWPS& method /* @in */, const string& wps_pin /* @in */) = 0; + virtual uint32_t StartWPS(const WiFiWPS& method /* @in */, const string& pin /* @in */) = 0; virtual uint32_t StopWPS(void) = 0; virtual uint32_t GetWifiState(WiFiState &state /* @out */) = 0; - virtual uint32_t GetWiFiSignalStrength(string& ssid /* @out */, string& signalStrength /* @out */, WiFiSignalQuality& quality /* @out */) = 0; - virtual uint32_t GetSupportedSecurityModes(ISecurityModeIterator*& securityModes /* @out */) const = 0; + virtual uint32_t GetWiFiSignalStrength(string& ssid /* @out */, string& strength /* @out */, WiFiSignalQuality& quality /* @out */) = 0; + virtual uint32_t GetSupportedSecurityModes(ISecurityModeIterator*& modes/* @out */) const = 0; /* @brief Set the network manager plugin log level */ - virtual uint32_t SetLogLevel(const NMLogging& logLevel /* @in */) = 0; + virtual uint32_t SetLogLevel(const Logging& level /* @in */) = 0; + virtual uint32_t GetLogLevel(Logging& level /* @out */) = 0; /* @brief configure network manager plugin */ - virtual uint32_t Configure(const string& configLine /* @in */, NMLogging& logLevel /* @out */) = 0; + virtual uint32_t Configure(const string& configLine /* @in */) = 0; /* @event */ struct EXTERNAL INotification : virtual public Core::IUnknown @@ -283,15 +284,15 @@ namespace WPEFramework enum { ID = ID_NETWORKMANAGER_NOTIFICATION }; // Network Notifications that other processes can subscribe to - virtual void onInterfaceStateChange(const InterfaceState event /* @in */, const string interface /* @in */) = 0; - virtual void onActiveInterfaceChange(const string prevActiveInterface /* @in */, const string currentActiveinterface /* @in */) = 0; - virtual void onIPAddressChange(const string interface /* @in */, const bool isAcquired /* @in */, const bool isIPv6 /* @in */, const string ipAddress /* @in */) = 0; - virtual void onInternetStatusChange(const InternetStatus oldState /* @in */, const InternetStatus newstate /* @in */) = 0; + virtual void onInterfaceStateChange(const InterfaceState state /* @in */, const string interface /* @in */) = 0; + virtual void onActiveInterfaceChange(const string prevActiveInterface /* @in */, const string currentActiveInterface /* @in */) = 0; + virtual void onIPAddressChange(const string interface /* @in */, const string ipversion /* @in */, const string ipaddress /* @in */, const IPStatus status /* @in */) = 0; + virtual void onInternetStatusChange(const InternetStatus prevState /* @in */, const InternetStatus currState /* @in */) = 0; // WiFi Notifications that other processes can subscribe to - virtual void onAvailableSSIDs(const string jsonOfWiFiScanResults /* @in */) = 0; + virtual void onAvailableSSIDs(const string jsonOfScanResults /* @in */) = 0; virtual void onWiFiStateChange(const WiFiState state /* @in */) = 0; - virtual void onWiFiSignalStrengthChange(const string ssid /* @in */, const string signalLevel /* @in */, const WiFiSignalQuality signalQuality /* @in */) = 0; + virtual void onWiFiSignalStrengthChange(const string ssid /* @in */, const string strength /* @in */, const WiFiSignalQuality quality /* @in */) = 0; }; // Allow other processes to register/unregister from our notifications diff --git a/LegacyPlugin_NetworkAPIs.cpp b/LegacyPlugin_NetworkAPIs.cpp index d380f4e0..6a86dc49 100644 --- a/LegacyPlugin_NetworkAPIs.cpp +++ b/LegacyPlugin_NetworkAPIs.cpp @@ -18,6 +18,7 @@ **/ #include "LegacyPlugin_NetworkAPIs.h" #include "NetworkManagerLogger.h" +#include "NetworkManagerJsonEnum.h" using namespace std; @@ -29,8 +30,18 @@ using namespace WPEFramework::Plugin; #define SUBSCRIPTION_TIMEOUT_IN_MILLISECONDS 500 #define DEFAULT_PING_PACKETS 15 -#define LOG_INPARAM() { string json; parameters.ToString(json); NMLOG_INFO("%s : params=%s", __FUNCTION__, json.c_str() ); } -#define LOG_OUTPARAM() { string json; response.ToString(json); NMLOG_INFO("%s : response=%s", __FUNCTION__, json.c_str() ); } +#define LOG_INPARAM() { string json; parameters.ToString(json); NMLOG_INFO("params=%s", json.c_str() ); } +#define LOG_OUTPARAM() { string json; response.ToString(json); NMLOG_INFO("response=%s", json.c_str() ); } + +#define returnJson(rc) \ + { \ + if (Core::ERROR_NONE == rc) \ + response["success"] = true; \ + else \ + response["success"] = false; \ + LOG_OUTPARAM(); \ + return Core::ERROR_NONE; \ + } namespace WPEFramework { @@ -118,18 +129,14 @@ namespace WPEFramework auto security = m_service->QueryInterfaceByCallsign("SecurityAgent"); if (security != nullptr) { string payload = "http://localhost"; - if (security->CreateToken( - static_cast(payload.length()), - reinterpret_cast(payload.c_str()), - token) - == Core::ERROR_NONE) { + if (security->CreateToken(static_cast(payload.length()), reinterpret_cast(payload.c_str()), token) == Core::ERROR_NONE) { NMLOG_DEBUG("Network plugin got security token"); } else { NMLOG_WARNING("Network plugin failed to get security token"); } security->Release(); } else { - NMLOG_INFO("Network plugin: No security agent"); + NMLOG_DEBUG("Network plugin: No security agent"); } string query = "token=" + token; @@ -138,14 +145,13 @@ namespace WPEFramework if (interface != nullptr) { PluginHost::IShell::state state = interface->State(); - NMLOG_INFO("Current status of the %s plugin is %d", callsign.c_str(), state); - if((PluginHost::IShell::state::ACTIVATED == state) || (PluginHost::IShell::state::ACTIVATION == state)) { NMLOG_INFO("Dependency Plugin '%s' Ready", callsign.c_str()); } else { + NMLOG_INFO("Lets attempt to activate the Plugin '%s'", callsign.c_str()); activatePrimaryPlugin(); } interface->Release(); @@ -155,6 +161,7 @@ namespace WPEFramework m_networkmanager = make_shared >(_T(NETWORK_MANAGER_CALLSIGN), _T("org.rdk.Network"), query); subscribeToEvents(); + return string(); } @@ -230,7 +237,8 @@ namespace WPEFramework } #define CIDR_NETMASK_IP_LEN 32 -const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { +const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { + "0.0.0.0", "128.0.0.0", "192.0.0.0", "224.0.0.0", @@ -275,451 +283,520 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { uint32_t Network::getInterfaces (const JsonObject& parameters, JsonObject& response) { uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpResponse; - JsonArray array; - LOG_INPARAM(); - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetAvailableInterfaces"), parameters, tmpResponse); - else - rc = Core::ERROR_UNAVAILABLE; - - if ((rc == Core::ERROR_NONE) && (tmpResponse["success"].Boolean())) + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) { - const JsonArray& tmpArray = tmpResponse["interfaces"].Array(); - for (int i=0; iGetAvailableInterfaces(_interfaces); + if (Core::ERROR_NONE == rc) { - JsonObject each; - const JsonObject& arrayEntry = tmpArray[i].Object(); - each[_T("interface")] = arrayEntry["type"]; - each[_T("macAddress")] = arrayEntry["mac"]; - each[_T("enabled")] = arrayEntry["isEnabled"]; - each[_T("connected")] = arrayEntry["isConnected"]; - - array.Add(JsonValue(each)); + if (_interfaces != nullptr) + { + JsonArray array; + Exchange::INetworkManager::InterfaceDetails entry{}; + while (_interfaces->Next(entry) == true) + { + JsonObject each; + Core::JSON::EnumType type{entry.type}; + each["interface"] = type.Data(); + each["macAddress"] = entry.mac; + each["enabled"] = entry.enabled; + each["connected"] = entry.connected; + + array.Add(JsonValue(each)); + } + + _interfaces->Release(); + response["interfaces"] = array; + } } - - response["interfaces"] = array; - response["success"] = tmpResponse["success"]; + _nwmgr->Release(); } - LOG_OUTPARAM(); - return rc; + + returnJson(rc); } uint32_t Network::setStunEndPoint(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpParameters; - tmpParameters["endPoint"] = parameters["server"]; - tmpParameters["port"] = parameters["port"]; - tmpParameters["bindTimeout"] = parameters["timeout"]; - tmpParameters["cacheTimeout"] = parameters["cache_timeout"]; + string endPoint = parameters["server"].String(); + uint32_t port = parameters["port"].Number(); + uint32_t bindTimeout = parameters["timeout"].Number(); + uint32_t cacheTimeout = parameters["cache_timeout"].Number(); - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("SetStunEndpoint"), tmpParameters, response); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->SetStunEndpoint(endPoint, port, bindTimeout, cacheTimeout); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t Network::setInterfaceEnabled (const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - string interface; - JsonObject tmpParameters; - LOG_INPARAM(); - if(caseInsensitiveCompare(parameters["interface"].String(),"WIFI")) - interface = "wlan0"; - else if(caseInsensitiveCompare(parameters["interface"].String(), "ETHERNET")) - interface = "eth0"; - - tmpParameters["interface"] = interface; - tmpParameters["enabled"] = parameters["enabled"]; - - if (m_networkmanager) + uint32_t rc = Core::ERROR_GENERAL; + if (parameters.HasLabel("interface") && parameters.HasLabel("enabled")) { - rc = m_networkmanager->Invoke(5000, _T("SetInterfaceState"), tmpParameters, response); + const string givenInterface = parameters["interface"].String(); + const bool enabled = parameters["enabled"].Boolean(); + const string interface = getInterfaceTypeToName(givenInterface); + + if ("wlan0" != interface && "eth0" != interface) + rc = Core::ERROR_BAD_REQUEST; + else + { + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->SetInterfaceState(interface, enabled); + _nwmgr->Release(); + } + else + rc = Core::ERROR_UNAVAILABLE; + } } else - rc = Core::ERROR_UNAVAILABLE; + rc = Core::ERROR_BAD_REQUEST; - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t Network::getDefaultInterface (const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpResponse; - LOG_INPARAM(); + uint32_t rc = Core::ERROR_GENERAL; + string interface; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetPrimaryInterface"), parameters, tmpResponse); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->GetPrimaryInterface(interface); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; if (Core::ERROR_NONE == rc) { - if ("wlan0" == tmpResponse["interface"].String()) - response["interface"] = "WIFI"; - else if("eth0" == tmpResponse["interface"].String()) - response["interface"] = "ETHERNET"; - response["success"] = tmpResponse["success"]; + string mappedInterface = getInterfaceNameToType(interface); + response["interface"] = mappedInterface; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t Network::setDefaultInterface(const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpParameters; - string interface; LOG_INPARAM(); - if(caseInsensitiveCompare(parameters["interface"].String(), "WIFI")) - tmpParameters["interface"] = "wlan0"; - else if(caseInsensitiveCompare(parameters["interface"].String(), "ETHERNET")) - tmpParameters["interface"] = "eth0"; - - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("SetPrimaryInterface"), tmpParameters, response); + uint32_t rc = Core::ERROR_GENERAL; + string givenInterface = parameters["interface"].String(); + const string interface = getInterfaceTypeToName(givenInterface); + + if ("wlan0" != interface && "eth0" != interface) + { + rc = Core::ERROR_BAD_REQUEST; + return rc; + } + + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->SetPrimaryInterface(interface); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - - return rc; + returnJson(rc); } uint32_t Network::setIPSettings(const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpResponse; - JsonObject tmpParameters; LOG_INPARAM(); - - if(caseInsensitiveCompare(parameters["interface"].String(), "WIFI")) - tmpParameters["interface"] = "wlan0"; - else if(caseInsensitiveCompare(parameters["interface"].String(), "ETHERNET")) - tmpParameters["interface"] = "eth0"; - - tmpParameters["ipversion"] = parameters["ipversion"]; - tmpParameters["autoconfig"] = parameters["autoconfig"]; - tmpParameters["ipaddress"] = parameters["ipaddr"]; - auto it = find(begin(CIDR_PREFIXES), end(CIDR_PREFIXES), parameters["netmask"].String()); - if (it == end(CIDR_PREFIXES)) - return rc; - else - tmpParameters["prefix"] = distance(begin(CIDR_PREFIXES), it); - tmpParameters["gateway"] = parameters["gateway"]; - tmpParameters["primarydns"] = parameters["primarydns"]; - tmpParameters["secondarydns"] = parameters["secondarydns"]; + uint32_t rc = Core::ERROR_GENERAL; + Exchange::INetworkManager::IPAddress address{}; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("SetIPSettings"), tmpParameters, tmpResponse); - else - rc = Core::ERROR_UNAVAILABLE; + string givenInterface = ""; + string interface = ""; + string ipversion = ""; - if (Core::ERROR_NONE == rc) + if (parameters.HasLabel("interface")) { - response["supported"] = true; - response["success"] = tmpResponse["success"]; + givenInterface = parameters["interface"].String(); + interface = getInterfaceTypeToName(givenInterface); + + if ("wlan0" != interface && "eth0" != interface) + { + return Core::ERROR_BAD_REQUEST; + } + } + else + { + return Core::ERROR_BAD_REQUEST; } - LOG_OUTPARAM(); - return rc; - } - uint32_t Network::getIPSettings (const JsonObject& parameters, JsonObject& response) - { - uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpResponse; + address.autoconfig = parameters["autoconfig"].Boolean(); + if (!address.autoconfig) + { + address.ipaddress = parameters["ipaddr"].String(); + address.ipversion = parameters["ipversion"].String(); + address.gateway = parameters["gateway"].String(); + address.primarydns = parameters["primarydns"].String(); + address.secondarydns = parameters["secondarydns"].String(); + + auto it = find(begin(CIDR_PREFIXES), end(CIDR_PREFIXES), parameters["netmask"].String()); + if (it == end(CIDR_PREFIXES)) + return Core::ERROR_BAD_REQUEST; + else + address.prefix = distance(begin(CIDR_PREFIXES), it); - LOG_INPARAM(); - rc = getIPSettings2(parameters, tmpResponse); + } - if (tmpResponse.HasLabel("ipaddr")) - response = tmpResponse; - else + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) { - NMLOG_INFO("IP Address not assigned to the given interface yet"); - response["success"] = false; + rc = _nwmgr->SetIPSettings(interface, address); + _nwmgr->Release(); } + else + rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + returnJson(rc); } - uint32_t Network::getIPSettings2 (const JsonObject& parameters, JsonObject& response) + uint32_t Network::internalGetIPSettings(const JsonObject& parameters, JsonObject& response) { uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpResponse; - JsonObject tmpParameters; - size_t index; + string interface{}; + string givenInterface{}; + string ipversion{}; - LOG_INPARAM(); - - if (parameters.HasLabel("ipversion")) - tmpParameters["ipversion"] = parameters["ipversion"]; if (parameters.HasLabel("interface")) { - if (caseInsensitiveCompare(parameters["interface"].String(), "WIFI")) - tmpParameters["interface"] = "wlan0"; - else if(caseInsensitiveCompare(parameters["interface"].String(), "ETHERNET")) - tmpParameters["interface"] = "eth0"; + givenInterface = parameters["interface"].String(); + interface = getInterfaceTypeToName(givenInterface); + + if (!interface.empty() && "wlan0" != interface && "eth0" != interface) + { + return Core::ERROR_BAD_REQUEST; + } } - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetIPSettings"), tmpParameters, tmpResponse); - else - rc = Core::ERROR_UNAVAILABLE; + if (parameters.HasLabel("ipversion")) + ipversion = parameters["ipversion"].String(); - if (Core::ERROR_NONE == rc) + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) { - string ipversion = tmpResponse["ipversion"].String(); + Exchange::INetworkManager::IPAddress address{}; + rc = _nwmgr->GetIPSettings(interface, ipversion, address); + _nwmgr->Release(); - if (parameters.HasLabel("interface")) - { - response["interface"] = parameters["interface"]; - } - else + if (Core::ERROR_NONE == rc) { - if ("wlan0" == m_defaultInterface) - response["interface"] = "WIFI"; - else if("eth0" == m_defaultInterface) - response["interface"] = "ETHERNET"; - } + givenInterface = getInterfaceNameToType(interface); - response["autoconfig"] = tmpResponse["autoconfig"]; - if(!tmpResponse["ipaddress"].String().empty()) - { - response["ipversion"] = tmpResponse["ipversion"]; - response["ipaddr"] = tmpResponse["ipaddress"]; - if (caseInsensitiveCompare(ipversion, "IPV4")) - { - index = tmpResponse["prefix"].Number(); - if(CIDR_NETMASK_IP_LEN <= index) - return Core::ERROR_GENERAL; - response["netmask"] = CIDR_PREFIXES[index]; - } - else if (caseInsensitiveCompare(ipversion, "IPV6")) + response["interface"] = givenInterface; + response["ipversion"] = address.ipversion; + response["autoconfig"] = address.autoconfig; + if (!address.ipaddress.empty()) { - response["netmask"] = tmpResponse["prefix"]; + response["ipaddr"] = address.ipaddress; + if ("IPv4" == address.ipversion) + { + if(address.prefix > CIDR_NETMASK_IP_LEN) + { + rc = Core::ERROR_GENERAL; + return rc; + } + response["netmask"] = CIDR_PREFIXES[address.prefix]; + } + else + response["netmask"] = address.prefix; + + response["dhcpserver"] = address.dhcpserver; + response["gateway"] = address.gateway; + response["primarydns"] = address.primarydns; + response["secondarydns"] = address.secondarydns; } - response["gateway"] = tmpResponse["gateway"]; - response["dhcpserver"] = tmpResponse["dhcpserver"]; - response["primarydns"] = tmpResponse["primarydns"]; - response["secondarydns"] = tmpResponse["secondarydns"]; } - response["success"] = tmpResponse["success"]; } - LOG_OUTPARAM(); return rc; } - uint32_t Network::isConnectedToInternet(const JsonObject& parameters, JsonObject& response) + uint32_t Network::getIPSettings (const JsonObject& parameters, JsonObject& response) { uint32_t rc = Core::ERROR_GENERAL; JsonObject tmpResponse; LOG_INPARAM(); - string ipversion = parameters["ipversion"].String(); + rc = internalGetIPSettings(parameters, tmpResponse); - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("IsConnectedToInternet"), parameters, tmpResponse); + if (tmpResponse.HasLabel("ipaddr") && (!tmpResponse["ipaddr"].String().empty())) + response = tmpResponse; else - rc = Core::ERROR_UNAVAILABLE; - - if (Core::ERROR_NONE == rc) { - response["connectedToInternet"] = tmpResponse["isConnectedToInternet"]; - if(caseInsensitiveCompare(ipversion, "IPV4") || caseInsensitiveCompare(ipversion, "IPV6")) - response["ipversion"] = ipversion.c_str(); - response["success"] = true; + NMLOG_INFO("IP Address not assigned to the given interface yet"); + rc = Core::ERROR_GENERAL; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } - uint32_t Network::getInternetConnectionState(const JsonObject& parameters, JsonObject& response) + + uint32_t Network::getIPSettings2 (const JsonObject& parameters, JsonObject& response) { + LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - uint32_t rc1 = Core::ERROR_GENERAL; - string endPoint; - JsonObject tmpResponse; - JsonObject captivePortalResponse; - JsonObject tmpParameters; - string status; + rc = internalGetIPSettings(parameters, response); + + returnJson(rc); + } + + uint32_t Network::isConnectedToInternet(const JsonObject& parameters, JsonObject& response) + { + uint32_t rc = Core::ERROR_GENERAL; LOG_INPARAM(); - string ipversion = parameters["ipversion"].String(); + string ipversion{}; + Exchange::INetworkManager::InternetStatus status{}; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("IsConnectedToInternet"), parameters, tmpResponse); - else - rc = Core::ERROR_UNAVAILABLE; + if (parameters.HasLabel("ipversion")) + ipversion = parameters["ipversion"].String(); - if (Core::ERROR_NONE == rc) + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr != nullptr) { - status = tmpResponse["status"].String(); - NMLOG_DEBUG("status = %s", status.c_str() ); - NMLOG_DEBUG("tmpResponse[status].String() = %s", tmpResponse["status"].String().c_str() ); - if(status == "LIMITED_INTERNET") - response["state"] = static_cast(2); - else if(status == "CAPTIVE_PORTAL") + rc = _nwmgr->IsConnectedToInternet(ipversion, status); + _nwmgr->Release(); + + if (Core::ERROR_NONE == rc) { - response["state"] = static_cast(1); - rc1 = getCaptivePortalURI(tmpParameters, captivePortalResponse); - if (Core::ERROR_NONE == rc1) - response["uri"] = captivePortalResponse["uri"]; + response["ipversion"] = ipversion; + response["connectedToInternet"] = (Exchange::INetworkManager::InternetStatus::INTERNET_FULLY_CONNECTED == status); } - else if(status == "FULLY_CONNECTED") - response["state"] = static_cast(3); - else - response["state"] = static_cast(0); + } + + returnJson(rc); + } + + uint32_t Network::getInternetConnectionState(const JsonObject& parameters, JsonObject& response) + { + uint32_t rc = Core::ERROR_GENERAL; + LOG_INPARAM(); + string ipversion{}; + Exchange::INetworkManager::InternetStatus status{}; - if(caseInsensitiveCompare(ipversion, "IPV4") || caseInsensitiveCompare(ipversion, "IPV6")) - response["ipversion"] = ipversion.c_str(); - response["success"] = true; + if (parameters.HasLabel("ipversion")) + ipversion = parameters["ipversion"].String(); + + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr != nullptr) + { + rc = _nwmgr->IsConnectedToInternet(ipversion, status); + + if (Core::ERROR_NONE == rc) + { + response["ipversion"] = ipversion; + response["state"] = JsonValue(status); + if (Exchange::INetworkManager::InternetStatus::INTERNET_CAPTIVE_PORTAL == status) + { + string uri{}; + _nwmgr->GetCaptivePortalURI(uri); + response["URI"] = uri; + } + } + _nwmgr->Release(); } - LOG_OUTPARAM(); - return rc; + + returnJson(rc); } + uint32_t Network::doPing(const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - struct in_addr ipv4address; - struct in6_addr ipv6address; - JsonObject tmpParameters; - JsonObject tmpResponse; + LOG_INPARAM(); + string result{}; string endpoint{}; - + uint32_t rc = Core::ERROR_GENERAL; LOG_INPARAM(); + if (parameters.HasLabel("endpoint")) + { + string guid{}; + string ipversion{"IPv4"}; + uint32_t noOfRequest = 3; + uint16_t timeOutInSeconds = 5; - endpoint = parameters["endpoint"].String(); + endpoint = parameters["endpoint"].String(); - if (inet_pton(AF_INET, endpoint.c_str(), &ipv4address) > 0) - tmpParameters["ipversion"] = "IPv4"; - else if (inet_pton(AF_INET6, endpoint.c_str(), &ipv6address) > 0) - tmpParameters["ipversion"] = "IPv6"; + if (parameters.HasLabel("ipversion")) + ipversion = parameters["ipversion"].String(); - if (parameters.HasLabel("packets")) - tmpParameters["noOfRequest"] = parameters["packets"]; - else - tmpParameters["noOfRequest"] = DEFAULT_PING_PACKETS; - tmpParameters["endpoint"] = parameters["endpoint"]; - tmpParameters["timeout"] = 5; - tmpParameters["guid"] = parameters["guid"]; + if (parameters.HasLabel("packets")) + noOfRequest = parameters["packets"].Number(); - if (m_networkmanager) - rc = m_networkmanager->Invoke(15000, _T("Ping"), tmpParameters, response); - else - rc = Core::ERROR_UNAVAILABLE; + if (parameters.HasLabel("guid")) + guid = parameters["guid"].String(); + + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->Ping(ipversion, endpoint, noOfRequest, timeOutInSeconds, guid, result); + _nwmgr->Release(); + } + else + rc = Core::ERROR_UNAVAILABLE; + } if (Core::ERROR_NONE == rc) { - response["target"] = parameters["endpoint"]; - response["guid"] = parameters["guid"]; + JsonObject reply; + reply.FromString(result); + response = reply; + response["target"] = endpoint; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t Network::doTrace(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpParameters; - tmpParameters["endpoint"] = parameters["endpoint"].String(); - tmpParameters["packets"] = parameters["packets"].Number(); - tmpParameters["guid"] = ""; + if (parameters.HasLabel("endpoint")) + { + string result{}; + string ipversion{"IPv4"}; + const string endpoint = parameters["endpoint"].String(); + const uint32_t noOfRequest = parameters["packets"].Number(); + const string guid = parameters["guid"].String(); - if(m_networkmanager) - rc = m_networkmanager->Invoke(20000, _T("Trace"), tmpParameters, response); - else - rc = Core::ERROR_UNAVAILABLE; + if (parameters.HasLabel("ipversion")) + ipversion = parameters["ipversion"].String(); - LOG_OUTPARAM(); - return rc; + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->Trace(ipversion, endpoint, noOfRequest, guid, result); + _nwmgr->Release(); + } + else + rc = Core::ERROR_UNAVAILABLE; + + if (Core::ERROR_NONE == rc) + { + JsonObject reply; + reply.FromString(result); + response = reply; + response["target"] = endpoint; + } + } + returnJson(rc); } uint32_t Network::getPublicIP(const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - string interface; - string ipversion{"IPv4"}; - JsonObject tmpParameters; - JsonObject tmpResponse; - LOG_INPARAM(); - if(caseInsensitiveCompare(parameters["iface"].String(), "WIFI")) - interface = "wlan0"; - else if(caseInsensitiveCompare(parameters["iface"].String(), "ETHERNET")) - interface = "eth0"; - - if(parameters["ipv6"].Boolean()) - ipversion = "IPv6"; - else - ipversion = "IPv4"; - - tmpParameters["interface"] = interface; - tmpParameters["ipversion"] = ipversion; + uint32_t rc = Core::ERROR_GENERAL; + string ipAddress{}; + string ipversion = "IPv4"; + if (parameters.HasLabel("ipversion")) + ipversion = parameters["ipversion"].String(); - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetPublicIP"), tmpParameters, tmpResponse); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->GetPublicIP(ipversion, ipAddress); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; if (Core::ERROR_NONE == rc) { - response["public_ip"] = tmpResponse["publicIP"]; - response["success"] = tmpResponse["success"]; + response["public_ip"] = ipAddress; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t Network::isInterfaceEnabled (const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpParameters; - LOG_INPARAM(); - string interface = parameters["interface"].String(); - string newInterface = ""; + uint32_t rc = Core::ERROR_GENERAL; - if(caseInsensitiveCompare(interface, "WIFI")) - newInterface = "wlan0"; - else if(caseInsensitiveCompare(interface, "ETHERNET")) - newInterface = "eth0"; + if (parameters.HasLabel("interface")) + { + bool enabled; + const string givenInterface = parameters["interface"].String(); + const string interface = getInterfaceTypeToName(givenInterface); - tmpParameters["interface"] = newInterface; + if ("wlan0" != interface && "eth0" != interface) + return Core::ERROR_BAD_REQUEST; + + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->GetInterfaceState(interface, enabled); + _nwmgr->Release(); + } + else + rc = Core::ERROR_UNAVAILABLE; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetInterfaceState"), tmpParameters, response); + if (Core::ERROR_NONE == rc) + response["enabled"] = enabled; + } else - rc = Core::ERROR_UNAVAILABLE; - - LOG_OUTPARAM(); + rc = Core::ERROR_BAD_REQUEST; - return rc; + returnJson(rc); } uint32_t Network::setConnectivityTestEndpoints(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("SetConnectivityTestEndpoints"), parameters, response); + ::WPEFramework::RPC::IIteratorType* endpointsIter{}; + JsonArray array = parameters["endpoints"].Array(); + + if (0 == array.Length() || 5 < array.Length()) + { + NMLOG_DEBUG("minimum of 1 to maximum of 5 Urls are allowed"); + returnJson(rc); + } + + std::vector endpoints; + JsonArray::Iterator index(array.Elements()); + while (index.Next() == true) + { + if (Core::JSON::Variant::type::STRING == index.Current().Content()) + { + endpoints.push_back(index.Current().String().c_str()); + } + else + { + NMLOG_DEBUG("Unexpected variant type"); + returnJson(rc); + } + } + endpointsIter = (Core::Service::Create(endpoints)); + + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + rc = _nwmgr->SetConnectivityTestEndpoints(endpointsIter); else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + if(_nwmgr) + _nwmgr->Release(); + + if (endpointsIter) + endpointsIter->Release(); + + returnJson(rc); } uint32_t Network::startConnectivityMonitoring(const JsonObject& parameters, JsonObject& response) @@ -729,28 +806,37 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { uint32_t interval = parameters["interval"].Number(); NMLOG_DEBUG("connectivity interval = %d", interval); - - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("StartConnectivityMonitoring"), parameters, response); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + rc = _nwmgr->StartConnectivityMonitoring(interval); else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + if(_nwmgr) + _nwmgr->Release(); + + returnJson(rc); } uint32_t Network::getCaptivePortalURI(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - string endPoint; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetCaptivePortalURI"), parameters, response); + string uri; + + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->GetCaptivePortalURI(uri); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + if (Core::ERROR_NONE == rc) + response["uri"] = uri; + + returnJson(rc); } uint32_t Network::stopConnectivityMonitoring(const JsonObject& parameters, JsonObject& response) @@ -758,13 +844,16 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("StopConnectivityMonitoring"), parameters, response); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->StopConnectivityMonitoring(); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t Network::getStbIp(const JsonObject& parameters, JsonObject& response) @@ -773,18 +862,16 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { LOG_INPARAM(); JsonObject tmpResponse; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetIPSettings"), parameters, tmpResponse); - else - rc = Core::ERROR_UNAVAILABLE; + rc = internalGetIPSettings(parameters, tmpResponse); - if (Core::ERROR_NONE == rc) + if ((Core::ERROR_NONE == rc) && tmpResponse.HasLabel("ipaddr")) { - response["ip"] = tmpResponse["ipaddress"]; - response["success"] = true; + response["ip"] = tmpResponse["ipaddr"]; } - LOG_OUTPARAM(); - return rc; + else + rc = Core::ERROR_UNAVAILABLE; + + returnJson(rc); } uint32_t Network::getSTBIPFamily(const JsonObject& parameters, JsonObject& response) @@ -796,18 +883,16 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { tmpParameters["ipversion"] = parameters["family"]; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetIPSettings"), tmpParameters, tmpResponse); - else - rc = Core::ERROR_UNAVAILABLE; + rc = internalGetIPSettings(tmpParameters, tmpResponse); - if (Core::ERROR_NONE == rc) + if ((Core::ERROR_NONE == rc) && tmpResponse.HasLabel("ipaddr")) { - response["ip"] = tmpResponse["ipaddress"]; - response["success"] = true; + response["ip"] = tmpResponse["ipaddr"]; } - LOG_OUTPARAM(); - return rc; + else + rc = Core::ERROR_UNAVAILABLE; + + returnJson(rc); } /** Private */ @@ -864,33 +949,41 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { if (m_subsIfaceStateChange && m_subsActIfaceChange && m_subsIPAddrChange && m_subsInternetChange) { m_timer.stop(); - NMLOG_INFO("subscriber timer stoped"); + NMLOG_INFO("All the required events are subscribed; Retry timer stoped"); } else { m_timer.start(SUBSCRIPTION_TIMEOUT_IN_MILLISECONDS); - NMLOG_INFO("subscriber timer started"); + NMLOG_INFO("Few required events are yet to be subscribed; Retry timer started"); } } - string Network::getInterfaceMapping(const string & interface) + string Network::getInterfaceNameToType(const string & interface) { if(interface == "wlan0") return string("WIFI"); else if(interface == "eth0") return string("ETHERNET"); - return string(" "); + return string(""); + } + + string Network::getInterfaceTypeToName(const string & interface) + { + if(interface == "WIFI") + return string("wlan0"); + else if(interface == "ETHERNET") + return string("eth0"); + return string(""); } /** Event Handling and Publishing */ void Network::ReportonInterfaceStateChange(const JsonObject& parameters) { - LOG_INPARAM(); JsonObject legacyParams; string json; - string state = parameters["state"].String(); + string state = parameters["status"].String(); - legacyParams["interface"] = getInterfaceMapping(parameters["interface"].String()); + legacyParams["interface"] = getInterfaceNameToType(parameters["interface"].String()); /* State check */ if(state == "INTERFACE_ADDED") @@ -902,14 +995,15 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { else if(state == "INTERFACE_LINK_DOWN") legacyParams["status"] = "DISCONNECTED"; + legacyParams.ToString(json); if((state == "INTERFACE_ADDED") || (state == "INTERFACE_REMOVED")) { - NMLOG_INFO("Posting onInterfaceStatusChanged"); + NMLOG_INFO("Posting onInterfaceStatusChanged as %s", json.c_str()); Notify("onInterfaceStatusChanged", legacyParams); } else if((state == "INTERFACE_LINK_UP") || (state == "INTERFACE_LINK_DOWN")) { - NMLOG_INFO("Posting onConnectionStatusChanged"); + NMLOG_INFO("Posting onConnectionStatusChanged as %s", json.c_str()); Notify("onConnectionStatusChanged", legacyParams); } @@ -918,23 +1012,25 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { void Network::ReportonActiveInterfaceChange(const JsonObject& parameters) { - LOG_INPARAM(); JsonObject legacyParams; - legacyParams["oldInterfaceName"] = getInterfaceMapping(parameters["oldInterfaceName"].String()); - legacyParams["newInterfaceName"] = getInterfaceMapping(parameters["newInterfaceName"].String()); + legacyParams["oldInterfaceName"] = getInterfaceNameToType(parameters["oldInterfaceName"].String()); + legacyParams["newInterfaceName"] = getInterfaceNameToType(parameters["newInterfaceName"].String()); m_defaultInterface = parameters["newInterfaceName"].String(); - NMLOG_INFO("Posting onDefaultInterfaceChanged"); + + string json; + legacyParams.ToString(json); + + NMLOG_INFO("Posting onDefaultInterfaceChanged as %s", json.c_str()); Notify("onDefaultInterfaceChanged", legacyParams); return; } void Network::ReportonIPAddressChange(const JsonObject& parameters) { - LOG_INPARAM(); JsonObject legacyParams; - legacyParams["interface"] = getInterfaceMapping(parameters["interface"].String()); + legacyParams["interface"] = getInterfaceNameToType(parameters["interface"].String()); if (parameters["isIPv6"].Boolean()) { @@ -946,7 +1042,11 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { } legacyParams["status"] = parameters["status"]; - NMLOG_INFO("Posting onIPAddressStatusChanged"); + + string json; + legacyParams.ToString(json); + NMLOG_INFO("Posting onIPAddressStatusChanged as %s", json.c_str()); + Notify("onIPAddressStatusChanged", legacyParams); if ("ACQUIRED" == parameters["status"].String()) @@ -957,14 +1057,20 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { void Network::ReportonInternetStatusChange(const JsonObject& parameters) { - NMLOG_INFO("Posting onInternetStatusChange"); - Notify("onInternetStatusChange", parameters); + JsonObject legacyParams; + string json; + + legacyParams["state"] = parameters["state"]; + legacyParams["status"] = parameters["status"]; + legacyParams.ToString(json); + + NMLOG_INFO("Posting onInternetStatusChanged as, %s", json.c_str()); + Notify("onInternetStatusChange", legacyParams); return; } void Network::onInterfaceStateChange(const JsonObject& parameters) { - LOG_INPARAM(); if(_gNWInstance) _gNWInstance->ReportonInterfaceStateChange(parameters); @@ -973,7 +1079,6 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { void Network::onActiveInterfaceChange(const JsonObject& parameters) { - LOG_INPARAM(); if(_gNWInstance) _gNWInstance->ReportonActiveInterfaceChange(parameters); return; @@ -981,7 +1086,6 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { void Network::onIPAddressChange(const JsonObject& parameters) { - LOG_INPARAM(); if(_gNWInstance) _gNWInstance->ReportonIPAddressChange(parameters); return; @@ -989,7 +1093,6 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { void Network::onInternetStatusChange(const JsonObject& parameters) { - LOG_INPARAM(); if(_gNWInstance) _gNWInstance->ReportonInternetStatusChange(parameters); } diff --git a/LegacyPlugin_NetworkAPIs.h b/LegacyPlugin_NetworkAPIs.h index 037b91b0..df3019e1 100644 --- a/LegacyPlugin_NetworkAPIs.h +++ b/LegacyPlugin_NetworkAPIs.h @@ -6,6 +6,7 @@ #include "Module.h" #include "core/Link.h" #include "NetworkManagerTimer.h" +#include "INetworkManager.h" namespace WPEFramework { namespace Plugin { @@ -31,8 +32,10 @@ namespace WPEFramework { void registerLegacyMethods(void); void unregisterLegacyMethods(void); void subscribeToEvents(void); - static std::string getInterfaceMapping(const std::string &interface); void activatePrimaryPlugin(); + uint32_t internalGetIPSettings(const JsonObject& parameters, JsonObject& response); + string getInterfaceNameToType(const string & interface); + string getInterfaceTypeToName(const string & interface); /* Methods */ uint32_t getInterfaces(const JsonObject& parameters, JsonObject& response); @@ -84,6 +87,7 @@ namespace WPEFramework { private: PluginHost::IShell* m_service; std::shared_ptr> m_networkmanager; + //WPEFramework::Exchange::INetworkManager* m_nwmgr; string m_defaultInterface; NetworkManagerTimer m_timer; diff --git a/LegacyPlugin_WiFiManagerAPIs.cpp b/LegacyPlugin_WiFiManagerAPIs.cpp index ac287243..ba0c6427 100644 --- a/LegacyPlugin_WiFiManagerAPIs.cpp +++ b/LegacyPlugin_WiFiManagerAPIs.cpp @@ -18,7 +18,7 @@ **/ #include "LegacyPlugin_WiFiManagerAPIs.h" #include "NetworkManagerLogger.h" -#include "INetworkManager.h" +#include "NetworkManagerJsonEnum.h" using namespace std; using namespace WPEFramework::Plugin; @@ -28,8 +28,18 @@ using namespace WPEFramework::Plugin; #define NETWORK_MANAGER_CALLSIGN "org.rdk.NetworkManager.1" #define SUBSCRIPTION_TIMEOUT_IN_MILLISECONDS 500 -#define LOG_INPARAM() { string json; parameters.ToString(json); NMLOG_INFO("%s : params=%s", __FUNCTION__, json.c_str() ); } -#define LOG_OUTPARAM() { string json; response.ToString(json); NMLOG_INFO("%s : response=%s", __FUNCTION__, json.c_str() ); } +#define LOG_INPARAM() { string json; parameters.ToString(json); NMLOG_INFO("params=%s", json.c_str() ); } +#define LOG_OUTPARAM() { string json; response.ToString(json); NMLOG_INFO("response=%s", json.c_str() ); } + +#define returnJson(rc) \ + { \ + if (Core::ERROR_NONE == rc) \ + response["success"] = true; \ + else \ + response["success"] = false; \ + LOG_OUTPARAM(); \ + return rc; \ + } namespace WPEFramework { @@ -134,14 +144,13 @@ namespace WPEFramework if (interface != nullptr) { PluginHost::IShell::state state = interface->State(); - NMLOG_INFO("Current status of the %s plugin is %d", callsign.c_str(), state); - if((PluginHost::IShell::state::ACTIVATED == state) || (PluginHost::IShell::state::ACTIVATION == state)) { NMLOG_INFO("Dependency Plugin '%s' Ready", callsign.c_str()); } else { + NMLOG_INFO("Lets attempt to activate the Plugin '%s'", callsign.c_str()); activatePrimaryPlugin(); } interface->Release(); @@ -219,156 +228,218 @@ namespace WPEFramework uint32_t WiFiManager::cancelWPSPairing (const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - LOG_INPARAM(); + uint32_t rc = Core::ERROR_GENERAL; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("StopWPS"), parameters, response); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->StopWPS(); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; if (Core::ERROR_NONE == rc) - { response["result"] = string(); - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t WiFiManager::clearSSID (const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpParameters; - tmpParameters["ssid"] = "ssid"; // The input ssid name does not matter at this point in time as there is only one ssid persisted at any given point in time. - LOG_INPARAM(); + uint32_t rc = Core::ERROR_GENERAL; + string ssid{}; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("RemoveKnownSSID"), tmpParameters, response); + ssid = parameters["ssid"].String(); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->RemoveKnownSSID(ssid); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; if (Core::ERROR_NONE == rc) - { response["result"] = 0; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t WiFiManager::connect(const JsonObject& parameters, JsonObject& response) { - LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; + Exchange::INetworkManager::WiFiConnectTo ssid{}; + NMLOG_INFO("Entry to %s\n", __FUNCTION__); - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("WiFiConnect"), parameters, response); + if (parameters.HasLabel("ssid")) + ssid.ssid = parameters["ssid"].String(); else - rc = Core::ERROR_UNAVAILABLE; + returnJson(rc); - if (Core::ERROR_NONE == rc) + if (parameters.HasLabel("passphrase")) + ssid.passphrase = parameters["passphrase"].String(); + + if (parameters.HasLabel("securityMode")) + ssid.security= static_cast (parameters["securityMode"].Number()); + + ssid.persist = true; + + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) { - response["success"] = true; + rc = _nwmgr->WiFiConnect(ssid); + _nwmgr->Release(); } - LOG_OUTPARAM(); - return rc; + else + rc = Core::ERROR_UNAVAILABLE; + + returnJson(rc); } uint32_t WiFiManager::getConnectedSSID (const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpResponse; - LOG_INPARAM(); + uint32_t rc = Core::ERROR_GENERAL; + Exchange::INetworkManager::WiFiSSIDInfo ssidInfo{}; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetConnectedSSID"), parameters, tmpResponse); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->GetConnectedSSID(ssidInfo); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; if (Core::ERROR_NONE == rc) { - response["ssid"] = tmpResponse["ssid"]; - response["bssid"] = tmpResponse["bssid"]; - response["rate"] = tmpResponse["rate"]; - response["noise"] = tmpResponse["noise"]; - response["security"] = tmpResponse["securityMode"]; - response["signalStrength"] = tmpResponse["signalStrength"]; - response["frequency"] = tmpResponse["frequency"]; - response["success"] = tmpResponse["success"]; + response["ssid"] = ssidInfo.ssid; + response["bssid"] = ssidInfo.bssid; + response["rate"] = ssidInfo.rate; + response["noise"] = ssidInfo.noise; + response["security"] = JsonValue(ssidInfo.security); + response["signalStrength"] = ssidInfo.strength; + response["frequency"] = ssidInfo.frequency; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t WiFiManager::getCurrentState(const JsonObject& parameters, JsonObject& response) { + Exchange::INetworkManager::WiFiState state; uint32_t rc = Core::ERROR_GENERAL; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetWifiState"), parameters, response); + LOG_INPARAM(); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->GetWifiState(state); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + if (Core::ERROR_NONE == rc) + { + /* Legacy Enums Mapping */ + if (state >= Exchange::INetworkManager::WiFiState::WIFI_STATE_ERROR) + response["state"] = 6; // 6: FAILED - The device has encountered an unrecoverable error with the Wifi adapter. + else if (state > Exchange::INetworkManager::WiFiState::WIFI_STATE_CONNECTED) + response["state"] = 2; // 2: DISCONNECTED - The device is installed and enabled, but not yet connected to a network + else + response["state"] = JsonValue(state); + } + + returnJson(rc); } uint32_t WiFiManager::getPairedSSID(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpResponse; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetKnownSSIDs"), parameters, tmpResponse); - else - rc = Core::ERROR_UNAVAILABLE; + ::WPEFramework::RPC::IIteratorType* _ssids{}; - JsonArray array = tmpResponse["ssids"].Array(); - if (0 == array.Length()) + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) { - response["ssid"] = ""; /* Assigning empty string when paired SSID is not available */ + rc = _nwmgr->GetKnownSSIDs(_ssids); + _nwmgr->Release(); } else + rc = Core::ERROR_UNAVAILABLE; + + if (Core::ERROR_NONE == rc) { - response["ssid"] = array[0]; + if (_ssids != nullptr) + { + string _resultItem_{}; + while (_ssids->Next(_resultItem_) == true) { + response["ssid"] = _resultItem_; + /* Just take one Entry : 1st Entry */ + break; + } + _ssids->Release(); + } } - response["success"] = tmpResponse["success"]; - - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t WiFiManager::getPairedSSIDInfo(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; + Exchange::INetworkManager::WiFiSSIDInfo ssidInfo{}; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetConnectedSSID"), parameters, response); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->GetConnectedSSID(ssidInfo); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + if (Core::ERROR_NONE == rc) + { + response["ssid"] = ssidInfo.ssid; + response["bssid"] = ssidInfo.bssid; + } + returnJson(rc); } uint32_t WiFiManager::getSupportedSecurityModes(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; + Exchange::INetworkManager::ISecurityModeIterator* securityModes{}; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("GetSupportedSecurityModes"), parameters, response); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->GetSupportedSecurityModes(securityModes); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + if (Core::ERROR_NONE == rc) + { + if (securityModes != nullptr) + { + JsonObject modes{}; + Exchange::INetworkManager::WIFISecurityModeInfo _resultItem_{}; + while (securityModes->Next(_resultItem_) == true) + { + response.Set(_resultItem_.securityName.c_str(), JsonValue(_resultItem_.security)); + } + securityModes->Release(); + } + } + returnJson(rc); } uint32_t WiFiManager::isPaired (const JsonObject& parameters, JsonObject& response) @@ -381,112 +452,113 @@ namespace WPEFramework if (Core::ERROR_NONE == rc) { - JsonArray array = tmpResponse["ssids"].Array(); - if (0 == array.Length()) - { + if (tmpResponse.HasLabel("ssid")) response["result"] = 1; - } else - { response["result"] = 0; - } - response["success"] = true; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t WiFiManager::saveSSID (const JsonObject& parameters, JsonObject& response) { uint32_t rc = Core::ERROR_GENERAL; + Exchange::INetworkManager::WiFiConnectTo ssid{}; + NMLOG_INFO("Entry to %s\n", __FUNCTION__); - LOG_INPARAM(); + if (parameters.HasLabel("ssid") && parameters.HasLabel("passphrase")) + { + ssid.ssid = parameters["ssid"].String(); + ssid.passphrase = parameters["passphrase"].String(); + ssid.security = static_cast (parameters["security"].Number()); - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("AddToKnownSSIDs"), parameters, response); - else - rc = Core::ERROR_UNAVAILABLE; + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->AddToKnownSSIDs(ssid); + _nwmgr->Release(); + } + else + rc = Core::ERROR_UNAVAILABLE; + } if (Core::ERROR_NONE == rc) - { response["result"] = 0; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t WiFiManager::disconnect (const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - LOG_INPARAM(); + uint32_t rc = Core::ERROR_GENERAL; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("WiFiDisconnect"), parameters, response); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->WiFiDisconnect(); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; if (Core::ERROR_NONE == rc) - { response["result"] = 0; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t WiFiManager::initiateWPSPairing (const JsonObject& parameters, JsonObject& response) { - uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpParameters; LOG_INPARAM(); + uint32_t rc = Core::ERROR_GENERAL; + string wps_pin{}; + Core::JSON::EnumType method; + if (parameters.HasLabel("method")) { - string method = parameters["method"].String(); - if (method == "PBC") - { - tmpParameters["method"] = 0; - } - else if (method == "PIN") - { - tmpParameters["method"] = 1; - tmpParameters["wps_pin"] = parameters.HasLabel("wps_pin"); - } - else if (method == "SERIALIZED_PIN") + if (parameters["method"].Content() == WPEFramework::Core::JSON::Variant::type::STRING) + method.FromString(parameters["method"].String()); + else if (parameters["method"].Content() == WPEFramework::Core::JSON::Variant::type::NUMBER) + method = static_cast (parameters["method"].Number()); + + if ((Exchange::INetworkManager::WIFI_WPS_PIN == method) && parameters.HasLabel("pin")) { - tmpParameters["method"] = 2; + wps_pin = parameters["pin"].String(); } } - else - tmpParameters["method"] = 0; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("StartWPS"), tmpParameters, response); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->StartWPS(method, wps_pin); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; if (Core::ERROR_NONE == rc) - { - response["result"] = string(); - } - LOG_OUTPARAM(); - return rc; + response["result"] = 0; + returnJson(rc); } uint32_t WiFiManager::startScan(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - JsonObject tmpParameters; + string frequency = parameters["frequency"].String(); + Exchange::INetworkManager::IStringIterator* ssids = NULL; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("StartWiFiScan"), tmpParameters, response); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->StartWiFiScan(frequency, ssids); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t WiFiManager::stopScan(const JsonObject& parameters, JsonObject& response) @@ -494,13 +566,16 @@ namespace WPEFramework LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - if (m_networkmanager) - rc = m_networkmanager->Invoke(5000, _T("StopWiFiScan"), parameters, response); + auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); + if (_nwmgr) + { + rc = _nwmgr->StopWiFiScan(); + _nwmgr->Release(); + } else rc = Core::ERROR_UNAVAILABLE; - LOG_OUTPARAM(); - return rc; + returnJson(rc); } /** Private */ @@ -542,58 +617,58 @@ namespace WPEFramework if (m_subsWiFiStateChange && m_subsAvailableSSIDs && m_subsWiFiStrengthChange) { m_timer.stop(); - NMLOG_INFO("subscriber timer stoped"); + NMLOG_INFO("All the required events are subscribed; Retry timer stoped"); } else { m_timer.start(SUBSCRIPTION_TIMEOUT_IN_MILLISECONDS); - NMLOG_INFO("subscriber timer started"); + NMLOG_INFO("Few required events are yet to be subscribed; Retry timer started"); } } - bool WiFiManager::ErrorCodeMapping(const uint32_t ipvalue, uint32_t &opvalue) - { - bool ret = true; - - switch (ipvalue) - { - case Exchange::INetworkManager::WIFI_STATE_SSID_CHANGED: - opvalue = WIFI_SSID_CHANGED; - break; - case Exchange::INetworkManager::WIFI_STATE_CONNECTION_LOST: - opvalue = WIFI_CONNECTION_LOST; - break; - case Exchange::INetworkManager::WIFI_STATE_CONNECTION_FAILED: - opvalue = WIFI_CONNECTION_FAILED; - break; - case Exchange::INetworkManager::WIFI_STATE_CONNECTION_INTERRUPTED: - opvalue = WIFI_CONNECTION_INTERRUPTED; - break; - case Exchange::INetworkManager::WIFI_STATE_INVALID_CREDENTIALS: - opvalue = WIFI_INVALID_CREDENTIALS; - break; - case Exchange::INetworkManager::WIFI_STATE_SSID_NOT_FOUND: - opvalue = WIFI_NO_SSID; - break; - case Exchange::INetworkManager::WIFI_STATE_ERROR: - opvalue = WIFI_UNKNOWN; - break; - case Exchange::INetworkManager::WIFI_STATE_AUTHENTICATION_FAILED: - opvalue = WIFI_AUTH_FAILED; - break; - default: - ret = false; - break; - } - return ret; + bool WiFiManager::ErrorCodeMapping(const uint32_t ipvalue, uint32_t &opvalue) + { + bool ret = true; + + switch (ipvalue) + { + case Exchange::INetworkManager::WIFI_STATE_SSID_CHANGED: + opvalue = WIFI_SSID_CHANGED; + break; + case Exchange::INetworkManager::WIFI_STATE_CONNECTION_LOST: + opvalue = WIFI_CONNECTION_LOST; + break; + case Exchange::INetworkManager::WIFI_STATE_CONNECTION_FAILED: + opvalue = WIFI_CONNECTION_FAILED; + break; + case Exchange::INetworkManager::WIFI_STATE_CONNECTION_INTERRUPTED: + opvalue = WIFI_CONNECTION_INTERRUPTED; + break; + case Exchange::INetworkManager::WIFI_STATE_INVALID_CREDENTIALS: + opvalue = WIFI_INVALID_CREDENTIALS; + break; + case Exchange::INetworkManager::WIFI_STATE_SSID_NOT_FOUND: + opvalue = WIFI_NO_SSID; + break; + case Exchange::INetworkManager::WIFI_STATE_ERROR: + opvalue = WIFI_UNKNOWN; + break; + case Exchange::INetworkManager::WIFI_STATE_AUTHENTICATION_FAILED: + opvalue = WIFI_AUTH_FAILED; + break; + default: + ret = false; + break; + } + return ret; } /** Event Handling and Publishing */ void WiFiManager::onWiFiStateChange(const JsonObject& parameters) { - LOG_INPARAM(); JsonObject legacyResult; JsonObject legacyErrorResult; + string json; uint32_t errorCode; uint32_t state = parameters["state"].Number(); @@ -606,39 +681,53 @@ namespace WPEFramework { legacyErrorResult["code"] = errorCode; NMLOG_INFO("onError with errorcode as, %u", errorCode); - NMLOG_INFO("Posting onError"); + + legacyErrorResult.ToString(json); + NMLOG_INFO("Posting onError as %s", json.c_str()); + _gWiFiInstance->Notify("onError", legacyErrorResult); } else { NMLOG_INFO("onWiFiStateChange with state as: %u", state); - NMLOG_INFO("Posting onWIFIStateChanged"); + + legacyResult.ToString(json); + NMLOG_INFO("Posting onWIFIStateChanged as %s", json.c_str()); _gWiFiInstance->Notify("onWIFIStateChanged", legacyResult); } } + else + NMLOG_WARNING("Ignoring %s\n", __FUNCTION__); + return; } void WiFiManager::onAvailableSSIDs(const JsonObject& parameters) { - LOG_INPARAM(); - - NMLOG_INFO("Posting onAvailableSSIDs"); + string json; + parameters.ToString(json); + NMLOG_INFO("Posting onAvailableSSIDs Event as %s", json.c_str()); if(_gWiFiInstance) _gWiFiInstance->Notify("onAvailableSSIDs", parameters); + else + NMLOG_WARNING("Ignoring %s\n", __FUNCTION__); return; } void WiFiManager::onWiFiSignalStrengthChange(const JsonObject& parameters) { - LOG_INPARAM(); JsonObject legacyParams; legacyParams["signalStrength"] = parameters["signalQuality"]; legacyParams["strength"] = parameters["signalLevel"]; - NMLOG_INFO("Posting onWifiSignalThresholdChanged"); + + string json; + legacyParams.ToString(json); + NMLOG_INFO("Posting onWifiSignalThresholdChanged as %s", json.c_str()); if (_gWiFiInstance) _gWiFiInstance->Notify("onWifiSignalThresholdChanged", legacyParams); + else + NMLOG_WARNING("Ignoring %s\n", __FUNCTION__); return; } diff --git a/Module.cpp b/Module.cpp index a574f23d..d402f440 100644 --- a/Module.cpp +++ b/Module.cpp @@ -18,4 +18,4 @@ **/ #include "Module.h" -MODULE_NAME_DECLARATION(BUILD_REFERENCE) +MODULE_NAME_DECLARATION(PLUGIN_BUILD_REFERENCE) diff --git a/NetworkManager.cpp b/NetworkManager.cpp index baa8d482..c7f3be03 100644 --- a/NetworkManager.cpp +++ b/NetworkManager.cpp @@ -18,7 +18,6 @@ **/ #include "NetworkManager.h" - #include namespace WPEFramework @@ -43,8 +42,6 @@ namespace WPEFramework _networkManager(nullptr), _notification(this) { - // Don't do any work in the constructor - all set up should be done in Initialize - m_primaryInterfaceCache = "wlan0"; } NetworkManager::~NetworkManager() @@ -88,10 +85,14 @@ namespace WPEFramework if (_networkManager != nullptr) { // set the plugin configuration - Exchange::INetworkManager::NMLogging _loglevel; - _networkManager->Configure(_service->ConfigLine(), _loglevel); + Exchange::INetworkManager::Logging _loglevel; + _networkManager->Configure(_service->ConfigLine()); + // configure loglevel in libWPEFrameworkNetworkManager.so + _networkManager->GetLogLevel(_loglevel); NetworkManagerLogger::SetLevel(static_cast (_loglevel)); + + _networkManager->Register(&_notification); // Register all custom JSON-RPC methods diff --git a/NetworkManager.h b/NetworkManager.h index 1838c545..a2543bed 100644 --- a/NetworkManager.h +++ b/NetworkManager.h @@ -21,8 +21,6 @@ #include "Module.h" -// Include the interface we created -//#include #include "INetworkManager.h" #include "NetworkManagerLogger.h" @@ -53,59 +51,6 @@ namespace WPEFramework Notification() = delete; Notification(const Notification &) = delete; Notification &operator=(const Notification &) = delete; - string InterfaceStateToString(Exchange::INetworkManager::InterfaceState event) - { - switch (event) - { - case Exchange::INetworkManager::INTERFACE_ADDED: - return "INTERFACE_ADDED"; - case Exchange::INetworkManager::INTERFACE_LINK_UP: - return "INTERFACE_LINK_UP"; - case Exchange::INetworkManager::INTERFACE_LINK_DOWN: - return "INTERFACE_LINK_DOWN"; - case Exchange::INetworkManager::INTERFACE_ACQUIRING_IP: - return "INTERFACE_ACQUIRING_IP"; - case Exchange::INetworkManager::INTERFACE_REMOVED: - return "INTERFACE_REMOVED"; - case Exchange::INetworkManager::INTERFACE_DISABLED: - return "INTERFACE_DISABLED"; - } - return ""; - } - - string WiFiSignalQualityToString(Exchange::INetworkManager::WiFiSignalQuality quality) - { - switch (quality) - { - case Exchange::INetworkManager::WiFiSignalQuality::WIFI_SIGNAL_DISCONNECTED: - return "Disconnected"; - case Exchange::INetworkManager::WiFiSignalQuality::WIFI_SIGNAL_WEAK: - return "Weak"; - case Exchange::INetworkManager::WiFiSignalQuality::WIFI_SIGNAL_FAIR: - return "Fair"; - case Exchange::INetworkManager::WiFiSignalQuality::WIFI_SIGNAL_GOOD: - return "Good"; - case Exchange::INetworkManager::WiFiSignalQuality::WIFI_SIGNAL_EXCELLENT: - return "Excellent"; - } - return ""; - } - - string InternetStatusToString(const Exchange::INetworkManager::InternetStatus internetStatus) - { - switch (internetStatus) - { - case Exchange::INetworkManager::InternetStatus::INTERNET_LIMITED: - return "LIMITED_INTERNET"; - case Exchange::INetworkManager::InternetStatus::INTERNET_CAPTIVE_PORTAL: - return "CAPTIVE_PORTAL"; - case Exchange::INetworkManager::InternetStatus::INTERNET_FULLY_CONNECTED: - return "FULLY_CONNECTED"; - default: - return "NO_INTERNET"; - } - return ""; - } public: explicit Notification(NetworkManager *parent) @@ -118,93 +63,40 @@ namespace WPEFramework } public: - void onInterfaceStateChange(const Exchange::INetworkManager::InterfaceState event, const string interface) override - { - NMLOG_INFO("%s", __FUNCTION__); - JsonObject params; - params["interface"] = interface; - params["state"] = InterfaceStateToString(event); - if(interface == "wlan0") - _parent.m_wifiStateCache.reset(); - _parent.Notify("onInterfaceStateChange", params); - _parent.m_primaryInterfaceCache.reset(); - _parent.m_ipv6AddressCache.reset(); - _parent.m_ipv4AddressCache.reset(); - } - void onIPAddressChange(const string interface, const bool isAcquired, const bool isIPv6, const string ipAddress) override + void onInterfaceStateChange(const Exchange::INetworkManager::InterfaceState state, const string interface) override { - NMLOG_INFO("%s", __FUNCTION__); - JsonObject params; - params["status"] = string (isAcquired ? "ACQUIRED" : "LOST"); - params["interface"] = interface; - params["ipAddress"] = ipAddress; - params["isIPv6"] = isIPv6; - if(isIPv6) - _parent.m_ipv6AddressCache.reset(); - else - _parent.m_ipv4AddressCache.reset(); - _parent.Notify("onIPAddressChange", params); + _parent.onInterfaceStateChange(state, interface); } void onActiveInterfaceChange(const string prevActiveInterface, const string currentActiveinterface) override { - NMLOG_INFO("%s", __FUNCTION__); - JsonObject params; - params["oldInterfaceName"] = prevActiveInterface; - params["newInterfaceName"] = currentActiveinterface; - _parent.Notify("onActiveInterfaceChange", params); - _parent.m_primaryInterfaceCache.reset(); + _parent.onActiveInterfaceChange(prevActiveInterface, currentActiveinterface); } - void onInternetStatusChange(const Exchange::INetworkManager::InternetStatus oldState, const Exchange::INetworkManager::InternetStatus newstate) override + void onIPAddressChange(const string interface, const string ipversion, const string ipaddress, const Exchange::INetworkManager::IPStatus status) override { - NMLOG_INFO("%s", __FUNCTION__); - JsonObject params; - - params["state"] = static_cast (newstate);; - params["status"] = InternetStatusToString(newstate); - params["prevState"] = static_cast (oldState); - params["prevStatus"] = InternetStatusToString(oldState); - - _parent.Notify("onInternetStatusChange", params); - - if (Exchange::INetworkManager::InternetStatus::INTERNET_FULLY_CONNECTED == newstate) - { - NMLOG_INFO("Notify Thunder ISubsystem internet"); - _parent.PublishToThunderAboutInternet(); - } + _parent.onIPAddressChange(interface, ipversion, ipaddress, status); } - // WiFi Notifications that other processes can subscribe to - void onAvailableSSIDs(const string jsonOfWiFiScanResults) override + void onInternetStatusChange(const Exchange::INetworkManager::InternetStatus prevState, const Exchange::INetworkManager::InternetStatus currState) override { - NMLOG_INFO("%s", __FUNCTION__); - JsonArray scanResults; - JsonObject result; - scanResults.FromString(jsonOfWiFiScanResults); - result["ssids"] = scanResults; - _parent.Notify("onAvailableSSIDs", result); + _parent.onInternetStatusChange(prevState, currState); + } + void onAvailableSSIDs(const string jsonOfScanResults) override + { + _parent.onAvailableSSIDs(jsonOfScanResults); } void onWiFiStateChange(const Exchange::INetworkManager::WiFiState state) override { - NMLOG_INFO("%s", __FUNCTION__); - JsonObject result; - result["state"] = static_cast (state); - _parent.Notify("onWiFiStateChange", result); - _parent.m_wifiStateCache = state; + _parent.onWiFiStateChange(state); } - void onWiFiSignalStrengthChange(const string ssid, const string signalLevel, const Exchange::INetworkManager::WiFiSignalQuality signalQuality) override + void onWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality) override { - NMLOG_INFO("%s", __FUNCTION__); - JsonObject result; - result["ssid"] = ssid; - result["signalQuality"] = WiFiSignalQualityToString(signalQuality); - result["signalLevel"] = signalLevel; - _parent.Notify("onWiFiSignalStrengthChange", result); + _parent.onWiFiSignalStrengthChange(ssid, strength, quality); } // The activated/deactived methods are part of the RPC::IRemoteConnection::INotification @@ -320,10 +212,8 @@ namespace WPEFramework }; // cached varibales - Cache m_wifiStateCache; - Cache m_ipv4AddressCache; - Cache m_ipv6AddressCache; - Cache m_primaryInterfaceCache; + Cache m_ipv4AddressCache; + Cache m_ipv6AddressCache; private: // Notification/event handlers // Clean up when we're told to deactivate @@ -335,6 +225,7 @@ namespace WPEFramework // JSON-RPC methods (take JSON in, spit JSON back out) uint32_t SetLogLevel (const JsonObject& parameters, JsonObject& response); + uint32_t GetLogLevel (const JsonObject& parameters, JsonObject& response); uint32_t GetAvailableInterfaces (const JsonObject& parameters, JsonObject& response); uint32_t GetPrimaryInterface (const JsonObject& parameters, JsonObject& response); uint32_t SetPrimaryInterface (const JsonObject& parameters, JsonObject& response); @@ -367,6 +258,14 @@ namespace WPEFramework uint32_t GetWiFiSignalStrength(const JsonObject& parameters, JsonObject& response); uint32_t GetSupportedSecurityModes(const JsonObject& parameters, JsonObject& response); + void onInterfaceStateChange(const Exchange::INetworkManager::InterfaceState state, const string interface); + void onActiveInterfaceChange(const string prevActiveInterface, const string currentActiveinterface); + void onIPAddressChange(const string interface, const string ipversion, const string ipaddress, const Exchange::INetworkManager::IPStatus status); + void onInternetStatusChange(const Exchange::INetworkManager::InternetStatus prevState, const Exchange::INetworkManager::InternetStatus currState); + void onAvailableSSIDs(const string jsonOfScanResults); + void onWiFiStateChange(const Exchange::INetworkManager::WiFiState state); + void onWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality); + private: uint32_t _connectionId; PluginHost::IShell *_service; diff --git a/NetworkManager.json b/NetworkManager.json index 0096bdda..06842f8c 100644 --- a/NetworkManager.json +++ b/NetworkManager.json @@ -1,19 +1,22 @@ { - "$schema": "https://raw.githubusercontent.com/rdkcentral/rdkservices/main/Tools/json_generator/schemas/interface.schema.json", + "$schema": "interface.schema.json", "jsonrpc": "2.0", "info": { "title": "NetworkManager Plugin", "class": "NetworkManager", "callsign": "org.rdk.NetworkManager", "locator": "libWPEFrameworkNetworkManager.so", - "status": "production", + "status": "development", "description": "A Unified `NetworkManager` plugin that allows you to manage Ethernet and Wifi interfaces on the device.", - "version": "0.4.0" - }, - "common": { - "$ref": "../../common/common.json" + "sourcelocation": "https://github.com/rdkcentral/networkmanager/blob/main/NetworkManager.json", + "version": "0.5.0" }, "definitions": { + "success": { + "summary": "Whether the request succeeded", + "type": "boolean", + "example": "true" + }, "interface": { "summary": "An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface", "type": "string", @@ -44,10 +47,10 @@ "type": "integer", "example": 24 }, - "v6LinkLocal": { - "summary": "The v6LinkLocal", + "ula": { + "summary": "The IPv6 Unified Local Address", "type": "string", - "example": "192.168.1.1" + "example": "d00:410:2016::" }, "gateway": { "summary": "The gateway address", @@ -69,28 +72,18 @@ "type": "integer", "example": "3478" }, - "endPoint":{ - "summary": "STUN server endPoint", - "type": "string", - "example": "stun.l.google.com" - }, "endpoint":{ "summary": "The host name or IP address", "type": "string", "example": "45.57.221.20" }, - "bindTimeout":{ - "summary": "STUN server bind timeout", - "type": "integer", - "example": "30" - }, - "cacheTimeout":{ + "cacheLifetime":{ "summary": "STUN server cache timeout", "type": "integer", "example": "0" }, "state": { - "summary": "The internet state", + "summary": "The given State", "type": "integer", "example": 4 }, @@ -99,8 +92,13 @@ "type": "string", "example": "" }, - "noOfRequest": { - "summary": "The number of packets to send. Default is 15.", + "count": { + "summary": "The number of requests to send. Default is 3.", + "type": "integer", + "example": 10 + }, + "packets": { + "summary": "The number of packets to send. Default is 5.", "type": "integer", "example": 10 }, @@ -124,12 +122,12 @@ "type": "string", "example": "password" }, - "securityMode": { - "summary": "The security mode. See `getSupportedSecurityModes`.", + "security": { + "summary": "The security mode. See `getSupportedsecurityModes`.", "type": "integer", "example": 6 }, - "signalStrength":{ + "strength":{ "summary": "The RSSI value in dBm", "type": "string", "example": "-27.000000" @@ -143,14 +141,56 @@ "summary": "Error string of scan failure", "type": "string", "example": "" - }, - "empty_string": { - "summary": "Not supported", - "type": "string", - "example": "" } }, "methods": { + "SetLogLevel":{ + "summary": "Set Log level for more information. The possible set log level are as follows. \n* `0`: FATAL \n* `1`: ERROR \n* `2`: WARNING \n* `3`: INFO \n* `4`: DEBUG \n", + "params": { + "type": "object", + "properties": { + "level": { + "summary": "Set Log level to get more information", + "type": "integer", + "example": 1 + } + }, + "required": [ + "level" + ] + }, + "result": { + "type": "object", + "properties": { + "success": { + "$ref": "#/definitions/success" + } + }, + "required": [ + "success" + ] + } + }, + "GetLogLevel":{ + "summary": "Get Log level that is currently used.", + "result": { + "type": "object", + "properties": { + "level": { + "summary": "Get Log level to get more information", + "type": "integer", + "example": 1 + }, + "success": { + "$ref": "#/definitions/success" + } + }, + "required": [ + "level", + "success" + ] + } + }, "GetAvailableInterfaces":{ "summary": "Get device supported list of available interface including their state.", "result": { @@ -177,12 +217,12 @@ "type": "string", "example": "AA:AA:AA:AA:AA:AA" }, - "isEnabled":{ + "enabled":{ "summary": "Whether the interface is currently enabled", "type": "boolean", "example": true }, - "isConnected":{ + "connected":{ "summary": "Whether the interface is currently connected", "type": "boolean", "example": true @@ -192,13 +232,13 @@ "type", "name", "mac", - "isEnabled", - "isConnected" + "enabled", + "connected" ] } }, "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -208,7 +248,7 @@ } }, "GetPrimaryInterface": { - "summary": "Gets the primary/default network interface for the device. The active network interface is defined as the one that can make requests to the external network. Returns one of the supported interfaces as per `GetAvailableInterfaces`, or an empty value which indicates that there is no default network interface.", + "summary": "Gets the primary/default network interface for the device. The active network interface is defined as the one that can make requests to the external network. Returns one of the supported interfaces as per `GetAvailableInterfaces`.", "result": { "type": "object", "properties": { @@ -241,7 +281,84 @@ ] }, "result": { - "$ref": "#/common/result" + "type": "object", + "properties": { + "success": { + "$ref": "#/definitions/success" + } + }, + "required": [ + "success" + ] + } + }, + "SetInterfaceState":{ + "summary": "Enable or disable the specified interface", + "events":{ + "onInterfaceStateChange" : "Triggered when interface’s status changes to enabled." + }, + "params": { + "type": "object", + "properties": { + "interface": { + "summary": "Enable the specified interface", + "type": "string", + "example": "wlan0" + }, + "enabled":{ + "summary": "Whether the interface must be enabled or disabled", + "type": "boolean", + "example": true + } + }, + "required": [ + "interface", + "enabled" + ] + }, + "result": { + "type": "object", + "properties": { + "success": { + "$ref": "#/definitions/success" + } + }, + "required": [ + "success" + ] + } + }, + "GetInterfaceState":{ + "summary": "Gets the current Status of the specified interface", + "params": { + "type": "object", + "properties": { + "interface": { + "summary": "Disable the specified interface", + "type": "string", + "example": "wlan0" + } + }, + "required": [ + "interface" + ] + }, + "result": { + "type": "object", + "properties": { + "enabled":{ + "summary": "Whether the interface is enabled or disabled", + "type": "boolean", + "example": true + }, + "success": { + "$ref": "#/definitions/success" + } + }, + "required": [ + "enabled", + "success" + ] } }, "GetIPSettings":{ @@ -255,10 +372,7 @@ "ipversion": { "$ref": "#/definitions/ipversion" } - }, - "required": [ - "interface" - ] + } }, "result": { "type": "object", @@ -284,8 +398,8 @@ "gateway": { "$ref": "#/definitions/gateway" }, - "v6LinkLocal": { - "$ref": "#/definitions/v6LinkLocal" + "ula": { + "$ref": "#/definitions/ula" }, "primarydns": { "$ref": "#/definitions/primarydns" @@ -294,7 +408,7 @@ "$ref": "#/definitions/secondarydns" }, "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -303,7 +417,7 @@ "autoconfig", "ipaddress", "prefix", - "v6LinkLocal", + "ula", "gateway", "primarydns", "secondarydns", @@ -360,7 +474,7 @@ "type": "object", "properties": { "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -369,55 +483,55 @@ } }, "GetStunEndpoint": { - "summary": "Get the STUN Endpoint that is used to identify public IP of the device.", + "summary": "Get the STUN endpoint that is used to identify public IP of the device.", "result": { "type": "object", "properties": { - "endPoint": { - "$ref": "#/definitions/endPoint" + "endpoint": { + "$ref": "#/definitions/endpoint" }, "port": { "$ref": "#/definitions/port" }, - "bindTimeout": { - "$ref": "#/definitions/bindTimeout" + "timeout": { + "$ref": "#/definitions/timeout" }, - "cacheTimeout": { - "$ref": "#/definitions/cacheTimeout" + "cacheLifetime": { + "$ref": "#/definitions/cacheLifetime" }, "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ - "endPoint", + "endpoint", "port", - "bindTimeout", - "cacheTimeout", + "timeout", + "cacheLifetime", "success" ] } }, "SetStunEndpoint":{ - "summary": "Set the STUN Endpoint to be used to identify public IP of the device.", + "summary": "Set the STUN endpoint to be used to identify public IP of the device.", "params": { "type":"object", "properties": { - "endPoint": { - "$ref": "#/definitions/endPoint" + "endpoint": { + "$ref": "#/definitions/endpoint" }, "port": { "$ref": "#/definitions/port" }, - "bindTimeout": { - "$ref": "#/definitions/bindTimeout" + "timeout": { + "$ref": "#/definitions/timeout" }, - "cacheTimeout": { - "$ref": "#/definitions/cacheTimeout" + "cacheLifetime": { + "$ref": "#/definitions/cacheLifetime" } }, "required": [ - "endPoint", + "endpoint", "port" ] }, @@ -425,13 +539,9 @@ "type": "object", "properties": { "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } - }, - "required": [ - "public_ip", - "success" - ] + } } }, "GetConnectivityTestEndpoints":{ @@ -448,7 +558,7 @@ } }, "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -476,37 +586,59 @@ ] }, "result": { - "$ref": "#/common/result" + "type": "object", + "properties": { + "success": { + "$ref": "#/definitions/success" + } + }, + "required": [ + "success" + ] } }, "IsConnectedToInternet":{ - "summary": "Seeks Whether the device has internet connectivity. This API might take up to 3s to validate internet connectivity.", + "summary": "Seeks whether the device has internet connectivity. This API might take up to 3s to validate internet connectivity.", "params": { "type":"object", "properties": { "ipversion": { "$ref": "#/definitions/ipversion" } - } + }, + "required": [ + ] }, "result": { "type": "object", "properties": { - "isConnectedToInternet": { + "ipversion": { + "$ref": "#/definitions/ipversion" + }, + "connected": { "summary": "`true` if internet connectivity is detected, otherwise `false`", "type": "boolean", "example": true }, - "internetState": { - "$ref": "#/definitions/state" + "state": { + "summary": "Internet state", + "type": "integer", + "example": 3 + }, + "status": { + "summary": "Internet status", + "type": "string", + "example": "FULLY_CONNECTED" }, "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ - "isConnectedToInternet", - "internetState", + "ipversion", + "connected", + "state", + "status", "success" ] } @@ -522,7 +654,7 @@ "example": "http://10.0.0.1/captiveportal.jst" }, "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -532,7 +664,7 @@ } }, "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.", + "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." }, @@ -546,14 +678,13 @@ } }, "required": [ - "interval" ] }, "result": { "type": "object", "properties": { "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -567,7 +698,7 @@ "type": "object", "properties": { "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -575,7 +706,7 @@ ] } }, - "GetPublicIP":{ + "GetPublicIP":{ "summary": "Gets the internet/public IP Address of the device.", "params": { "type":"object", @@ -586,23 +717,24 @@ } }, "required": [ - "ipversion" ] }, "result": { "type": "object", "properties": { - "publicIP":{ - "summary": "Returns an public ip of the device", - "type":"string", - "example": "69.136.49.95" + "ipaddress": { + "$ref": "#/definitions/ipaddress" + }, + "ipversion": { + "$ref": "#/definitions/ipversion" }, "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ - "publicIP", + "ipaddress", + "ipversion", "success" ] } @@ -618,8 +750,8 @@ "ipversion": { "$ref": "#/definitions/ipversion" }, - "noOfRequest": { - "$ref": "#/definitions/noOfRequest" + "count": { + "$ref": "#/definitions/count" }, "timeout": { "$ref": "#/definitions/timeout" @@ -630,19 +762,14 @@ }, "required": [ "endpoint", - "ipversion", - "noOfRequest", - "timeout", - "guid" + "ipversion" ] }, "result": { "type": "object", "properties": { - "target": { - "summary": "The target IP address", - "type": "string", - "example": "45.57.221.20" + "endpoint":{ + "$ref": "#/definitions/endpoint" }, "packetsTransmitted": { "summary": "The number of packets sent", @@ -690,11 +817,11 @@ "example": "..." }, "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ - "target", + "endpoint", "packetsTransmitted", "packetsReceived", "packetLoss", @@ -722,8 +849,8 @@ "ipversion": { "$ref": "#/definitions/ipversion" }, - "noOfRequest": { - "$ref": "#/definitions/noOfRequest" + "packets": { + "$ref": "#/definitions/packets" }, "guid": { "$ref": "#/definitions/guid" @@ -731,85 +858,39 @@ }, "required": [ "endpoint", - "ipversion", - "noOfRequest", - "guid" + "ipversion" ] }, "result": { "type": "object", "properties": { - "target": { - "summary": "The target IP address", - "type": "string", - "example": "45.57.221.20" - }, - "packetsTransmitted": { - "summary": "The number of packets sent", - "type": "integer", - "example": 10 - }, - "packetsReceived": { - "summary": "The number of packets received", - "type": "integer", - "example": 10 - }, - "packetLoss": { - "summary": "The number of packets lost", - "type": "string", - "example": "0.0" - }, - "tripMin": { - "summary": "The minimum amount of time to receive the packets", - "type": "string", - "example": "61.264" - }, - "tripAvg": { - "summary": "The average time to receive the packets", - "type": "string", - "example": "130.397" - }, - "tripMax": { - "summary": "The maximum amount of time to receive the packets", - "type": "string", - "example": "230.832" - }, - "tripStdDev": { - "summary": "The standard deviation for the trip", - "type": "string", - "example": "80.919" + "endpoint":{ + "$ref": "#/definitions/endpoint" }, - "error": { - "summary": "An error message", + "results": { + "summary": "The response of traceroute", "type": "string", "example": "..." - }, + }, "guid": { "summary": "The globally unique identifier", "type": "string", "example": "..." }, "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ - "target", - "packetsTransmitted", - "packetsReceived", - "packetLoss", - "tripMin", - "tripAvg", - "tripMax", - "tripStdDev", - "error", + "endpoint", + "results", "guid", "success" ] } }, "StartWiFiScan":{ - "summary": "Initiates WiFi scaning. This method supports scanning for specific range of frequency like 2.4GHz only or 5GHz only or 6GHz only or ALL. When no input passed about the frequency to be scanned, it scans for all. It publishes 'onAvailableSSIDs' event upon completion.", + "summary": "Initiates WiFi scaning. This method supports scanning for specific range of frequency like 2.4GHz only or 5GHz only or 6GHz only or ALL. When no input passed about the frequency to be scanned, it scans for all. When list of SSIDs to be scanned specifically, it can be passed as input. It publishes 'onAvailableSSIDs' event upon completion.", "events": { "onAvailableSSIDs" : "Triggered when list of SSIDs is available after the scan completes." }, @@ -817,20 +898,25 @@ "type": "object", "properties": { "frequency": { - "summary": "The frequency to scan. An empty or `null` value scans all frequencies. If a frequency is specified (2.4 or 5.0), then the results are only returned for matching frequencies.", + "summary": "The frequency to scan. An empty or `null` value scans all frequencies.", "type": "string", - "example": "" + "example": "5" + }, + "ssids": { + "summary": "The list of SSIDs to be scanned.", + "type": "array", + "items": { + "type": "string", + "example": "Xfinity Mobile" + } } - }, - "required": [ - "frequency" - ] + } }, "result": { "type": "object", "properties": { "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -841,7 +927,15 @@ "StopWiFiScan":{ "summary": "Stops WiFi scanning. Any discovered SSIDs from the call to the `StartWiFiScan` method up to the point where this method is called are still returned as event.", "result": { - "$ref": "#/common/result" + "type": "object", + "properties": { + "success": { + "$ref": "#/definitions/success" + } + }, + "required": [ + "success" + ] } }, "GetKnownSSIDs":{ @@ -858,7 +952,7 @@ } }, "success": { - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -878,21 +972,21 @@ "passphrase": { "$ref": "#/definitions/passphrase" }, - "securityMode": { - "$ref": "#/definitions/securityMode" + "security": { + "$ref": "#/definitions/security" } }, "required": [ "ssid", "passphrase", - "securityMode" + "security" ] }, "result": { "type": "object", "properties": { "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -901,7 +995,7 @@ } }, "RemoveKnownSSID":{ - "summary": "Remove given SSID from saved SSIDs. This method just removes from the list and of the list is having only one entry thats being removed, it will initiate a disconnect.", + "summary": "Remove given SSID from saved SSIDs. This method just removes an entry from the list and of the list is having only one entry thats being removed, it will initiate a disconnect.", "events":{ "onWiFiStateChange" : "Triggered when Wifi state changes to DISCONNECTED", "onAddressChange" : "Triggered when an IP Address is assigned or lost", @@ -922,7 +1016,7 @@ "type": "object", "properties": { "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -944,18 +1038,76 @@ "passphrase": { "$ref": "#/definitions/passphrase" }, - "securityMode": { - "$ref": "#/definitions/securityMode" + "security": { + "$ref": "#/definitions/security" + }, + "ca_cert": { + "summary": "The ca_cert to be used for EAP", + "type": "string", + "example": "..." + }, + "client_cert": { + "summary": "The client_cert to be used for EAP", + "type": "string", + "example": "..." + }, + "private_key": { + "summary": "The private_key to be used for EAP", + "type": "string", + "example": "..." + }, + "private_key_passwd": { + "summary": "The private_key_passwd to be used for EAP", + "type": "string", + "example": "..." + }, + "eap": { + "summary": "The EAP type to be used", + "type": "string", + "example": "TLS" + }, + "eap_identity": { + "summary": "The identity to be used for EAP", + "type": "string", + "example": "..." + }, + "eap_password": { + "summary": "The eap_password to be used for EAP", + "type": "string", + "example": "..." + }, + "eap_phase1": { + "summary": "The eap_phase1 to be used for EAP", + "type": "string", + "example": "..." + }, + "eap_phase2": { + "summary": "The eap_phase2 to be used for EAP", + "type": "string", + "example": "..." + }, + "persist": { + "summary": " To persist the SSID across reboots; similar to auto connect", + "type": "boolean", + "example": true } }, "required": [ "ssid", "passphrase", - "securityMode" + "security" ] }, "result": { - "$ref": "#/common/result" + "type": "object", + "properties": { + "success": { + "$ref": "#/definitions/success" + } + }, + "required": [ + "success" + ] } }, "WiFiDisconnect":{ @@ -969,7 +1121,7 @@ "type": "object", "properties": { "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -988,13 +1140,13 @@ "bssid": { "$ref": "#/definitions/bssid" }, - "securityMode":{ + "security":{ "summary": "The security mode. See the `connect` method", "type": "string", "example": "5" }, - "signalStrength": { - "$ref": "#/definitions/signalStrength" + "strength": { + "$ref": "#/definitions/strength" }, "frequency": { "$ref": "#/definitions/frequency" @@ -1010,7 +1162,7 @@ "example": "-121.000000" }, "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -1018,8 +1170,8 @@ "bssid", "rate", "noise", - "securityMode", - "signalStrength", + "security", + "strength", "frequency", "success" ] @@ -1037,18 +1189,17 @@ "properties": { "method": { "summary": "The method used to obtain the pin (must be one of the following: PBC=0, PIN=1, SERIALIZED_PIN=2)", - "type": "integer", - "example": 1 + "type": "string", + "example": "PIN" }, - "wps_pin": { + "pin": { "summary": "A valid 8 digit WPS pin number. Use this parameter when the `method` parameter is set to `PIN`.", "type": "string", "example": "88888888" } }, "required": [ - "method", - "wps_pin" + "method" ] }, "result": { @@ -1060,7 +1211,7 @@ "example": "88888888" }, "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -1078,7 +1229,7 @@ "type": "object", "properties": { "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -1097,8 +1248,8 @@ "ssid": { "$ref": "#/definitions/ssid" }, - "signalStrength": { - "$ref": "#/definitions/signalStrength" + "strength": { + "$ref": "#/definitions/strength" }, "quality":{ "summary": "Signal strength Quality", @@ -1106,18 +1257,18 @@ "example": 123 }, "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ "ssid", - "signalStrength", + "strength", "quality", "success" ] } }, - "GetSupportedSecurityModes":{ + "GetSupportedsecurityModes":{ "summary": "Returns the Wifi security modes that the device supports.", "result": { "type": "object", @@ -1190,7 +1341,7 @@ "required": [] }, "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ @@ -1199,107 +1350,26 @@ ] } }, - "SetLogLevel":{ - "summary": "Set Log level for more information. The possible set log level are as follows. \n* `0`: FATAL \n* `1`: ERROR \n* `2`: WARNING \n* `3`: INFO \n* `4`: VERBOSE \n* `5`: TRACE \n", - "params": { - "type": "object", - "properties": { - "loglevel": { - "summary": "Set Log level to get more information", - "type": "integer", - "example": 1 - } - }, - "required": [ - "loglevel" - ] - }, - "result": { - "type": "object", - "properties": { - "success": { - "$ref": "#/common/success" - } - }, - "required": [ - "success" - ] - } - }, - "EnableInterface":{ - "summary": "Enable the specified interface", - "events":{ - "onInterfaceStateChange" : "Triggered when interface’s status changes to enabled." - }, - "params": { - "type": "object", - "properties": { - "interface": { - "summary": "Enable the specified interface", - "type": "string", - "example": "wlan0" - } - }, - "required": [ - "interface" - ] - }, - "result": { - "type": "object", - "properties": { - "success": { - "$ref": "#/common/success" - } - }, - "required": [ - "success" - ] - } - }, - "DisableInterface":{ - "summary": "Disable the specified interface", - "events":{ - "onInterfaceStateChange" : "Triggered when interface’s status changes to disabled." - }, - "params": { - "type": "object", - "properties": { - "interface": { - "summary": "Disable the specified interface", - "type": "string", - "example": "wlan0" - } - }, - "required": [ - "interface" - ] - }, - "result": { - "type": "object", - "properties": { - "success": { - "$ref": "#/common/success" - } - }, - "required": [ - "success" - ] - } - }, "GetWifiState": { - "summary": "Returns the current Wifi State. The possible Wifi states are as follows. \n**Wifi States** \n* `0`: UNINSTALLED - The device was in an installed state and was uninstalled; or, the device does not have a Wifi radio installed \n* `1`: DISABLED - The device is installed but not yet enabled \n* `2`: DISCONNECTED - The device is installed and enabled, but not yet connected to a network \n* `3`: PAIRING - The device is in the process of pairing, but not yet connected to a network \n* `4`: CONNECTING - The device is attempting to connect to a network \n* `5`: CONNECTED - The device is successfully connected to a network \n* `6`: SSID_NOT_FOUND - The requested SSID to connect is not found \n* `7`: SSID_CHANGED - The device connected SSID is changed \n* `8`: CONNECTION_LOST - The device network connection is lost \n* `9`: CONNECTION_FAILED - The device connection got failed \n* `10`: CONNECTION_INTERRUPTED - The device connection is interrupted \n* `11`: INVALID_CREDENTIALS - The credentials provided to connect is not valid \n* `12`: AUTHENTICATION_FAILED - Authentication process as a whole could not be successfully completed \n* `13`: ERROR - The device has encountered an unrecoverable error with the Wifi adapter.", + "summary": "Returns the current Wifi State. The possible Wifi states are as follows. \n**Wifi States** \n* `0`: WIFI_STATE_UNINSTALLED - The device was in an installed state and was uninstalled; or, the device does not have a Wifi radio installed \n* `1`: WIFI_STATE_DISABLED - The device is installed but not yet enabled \n* `2`: WIFI_STATE_DISCONNECTED - The device is installed and enabled, but not yet connected to a network \n* `3`: WIFI_STATE_PAIRING - The device is in the process of pairing, but not yet connected to a network \n* `4`: WIFI_STATE_CONNECTING - The device is attempting to connect to a network \n* `5`: WIFI_STATE_CONNECTED - The device is successfully connected to a network \n* `6`: WIFI_STATE_SSID_NOT_FOUND - The requested SSID to connect is not found \n* `7`: WIFI_STATE_SSID_CHANGED - The device connected SSID is changed \n* `8`: WIFI_STATE_CONNECTION_LOST - The device network connection is lost \n* `9`: WIFI_STATE_CONNECTION_FAILED - The device connection got failed \n* `10`: WIFI_STATE_CONNECTION_INTERRUPTED - The device connection is interrupted \n* `11`: WIFI_STATE_INVALID_CREDENTIALS - The credentials provided to connect is not valid \n* `12`: WIFI_STATE_AUTHENTICATION_FAILED - Authentication process as a whole could not be successfully completed \n* `13`: WIFI_STATE_ERROR - The device has encountered an unrecoverable error with the Wifi adapter.", "result": { "type": "object", "properties": { "state": { "$ref": "#/definitions/state" }, + "status": { + "summary": "WiFi status", + "type": "string", + "example": "WIFI_STATE_CONNECTED" + }, "success":{ - "$ref": "#/common/success" + "$ref": "#/definitions/success" } }, "required": [ "state", + "status", "success" ] } @@ -1317,13 +1387,19 @@ }, "state":{ "summary": "Current state of the interface", + "type": "integer", + "example": 1 + }, + "status":{ + "summary": "Current status of the interface", "type": "string", - "example": "INTERFACE_ADDED" + "example": "INTERFACE_LINK_UP" } }, "required": [ "interface", - "state" + "state", + "status" ] } }, @@ -1335,15 +1411,11 @@ "interface":{ "$ref": "#/definitions/interface" }, - "isIPv6":{ - "summary": "It will be true if the IP address is IPv6", - "type": "boolean", - "example": false + "ipaddress": { + "$ref": "#/definitions/ipaddress" }, - "ipAddress":{ - "summary": "The IPv6 or IPv4 address for the interface", - "type": "string", - "example": "192.168.1.100" + "ipversion": { + "$ref": "#/definitions/ipversion" }, "status":{ "summary": "Whether IP address was acquired or lost (must be one of the following: 'ACQUIRED', 'LOST')", @@ -1357,8 +1429,8 @@ }, "required": [ "interface", - "isIPv6", - "ipAddress", + "ipaddress", + "ipversion", "status" ] } @@ -1368,20 +1440,20 @@ "params": { "type": "object", "properties": { - "oldInterfaceName":{ + "prevActiveInterface":{ "summary": "The previous interface that was changed", "type": "string", "example": "wlan0" }, - "newInterfaceName":{ + "activeInterface":{ "summary": "The current interface", "type": "string", "example": "eth0" } }, "required": [ - "oldInterfaceName", - "newInterfaceName" + "prevActiveInterface", + "activeInterface" ] } }, @@ -1390,12 +1462,12 @@ "params": { "type": "object", "properties": { - "PrevState":{ + "prevState":{ "summary": "The privious internet connection state", "type": "integer", "example": 1 }, - "PrevStatus":{ + "prevStatus":{ "summary": "The previous internet connection status", "type": "string", "example": "NO_INTERNET" @@ -1412,8 +1484,8 @@ } }, "required": [ - "PrevState", - "PrevStatus", + "prevState", + "prevStatus", "state", "status" ] @@ -1440,8 +1512,8 @@ "type": "integer", "example": 6 }, - "signalStrength":{ - "summary": "signalStrength", + "strength":{ + "summary": "strength", "type": "string", "example": "-27.000000" }, @@ -1454,7 +1526,7 @@ "required": [ "ssid", "security", - "signalStrength", + "strength", "frequency" ] } @@ -1463,18 +1535,24 @@ } }, "onWiFiStateChange":{ - "summary": "Triggered when WIFI connection state get changed. The possible states are, \n * '0' - 'WIFI_STATE_UNINSTALLED' \n * '1' - 'WIFI_STATE_DISABLED' \n * '2' - 'WIFI_STATE_DISCONNECTED' \n * '3' - 'WIFI_STATE_PAIRING' \n * '4' - 'WIFI_STATE_CONNECTING' \n * '5' - 'WIFI_STATE_CONNECTED' \n * '6' - 'WIFI_STATE_SSID_NOT_FOUND' \n * '7' - 'WIFI_STATE_SSID_CHANGED' \n * '8' - 'WIFI_STATE_CONNECTION_LOST' \n * '9' - 'WIFI_STATE_CONNECTION_FAILED' \n * '10'- 'WIFI_STATE_CONNECTION_INTERRUPTED' \n * '11' - 'WIFI_STATE_INVALID_CREDENTIALS' \n * '12' - 'WIFI_STATE_AUTHENTICATION_FAILED' \n * '13' - 'WIFI_STATE_ERROR' \n", + "summary": "Triggered when WIFI connection state get changed. The possible states are defined in `GetWifiState()`", "params": { "type": "object", "properties": { "state":{ - "summary": "onWiFiStateChange", + "summary": "WiFi State", "type": "integer", "example": "5" + }, + "status": { + "summary": "WiFi status", + "type": "string", + "example": "WIFI_STATE_CONNECTED" } }, "required": [ - "state" + "state", + "status" ] } }, @@ -1488,7 +1566,7 @@ "type": "string", "example": "home-new_123" }, - "signalStrength":{ + "strength":{ "summary": "Signal Strength", "type": "string", "example": "-27.000000" @@ -1501,7 +1579,7 @@ }, "required": [ "ssid", - "signalStrength", + "strength", "quality" ] } diff --git a/NetworkManagerConnectivity.cpp b/NetworkManagerConnectivity.cpp index e9cacd97..f76c8b4b 100644 --- a/NetworkManagerConnectivity.cpp +++ b/NetworkManagerConnectivity.cpp @@ -158,12 +158,12 @@ namespace WPEFramework curl_easy_setopt(curl_easy_handle, CURLOPT_TIMEOUT_MS, deadline - current_time()); if ((ipversion == CURL_IPRESOLVE_V4) || (ipversion == CURL_IPRESOLVE_V6)) { - NMLOG_INFO("curlopt ipversion = %s reqtyp = %s", ipversion == CURL_IPRESOLVE_V4?"ipv4 only":"ipv6 only", headReq? "HEAD":"GET"); + NMLOG_DEBUG("curlopt ipversion = %s reqtyp = %s", ipversion == CURL_IPRESOLVE_V4?"ipv4 only":"ipv6 only", headReq? "HEAD":"GET"); curl_easy_setopt(curl_easy_handle, CURLOPT_IPRESOLVE, ipversion); } else { - NMLOG_INFO("curlopt ipversion = whatever reqtyp = %s", headReq? "HEAD":"GET"); + NMLOG_DEBUG("curlopt ipversion = whatever reqtyp = %s", headReq? "HEAD":"GET"); } if(curlVerboseEnabled()) curl_easy_setopt(curl_easy_handle, CURLOPT_VERBOSE, 1L); @@ -321,8 +321,6 @@ namespace WPEFramework setConnectivityMonitorEndpoints(cachedEndPnt); NMLOG_WARNING("cached connectivity endpoints loaded .."); } - else - connectivityMonitorEndpt.push_back("http://clients3.google.com/generate_204"); doContinuousMonitor = false; doConnectivityMonitor = false; @@ -386,7 +384,7 @@ namespace WPEFramework return false; } - nsm_internetState ConnectivityMonitor::getInternetState(nsm_ipversion ipversion) + nsm_internetState ConnectivityMonitor::getInternetState(nsm_ipversion& ipversion) { nsm_internetState internetState = nsm_internetState::UNKNOWN; // If monitor connectivity is running take the cache value @@ -395,16 +393,20 @@ namespace WPEFramework && gIpv4InternetState != nsm_internetState::UNKNOWN ) { NMLOG_WARNING("Reading Ipv4 internet state cached value %s", getInternetStateString(gIpv4InternetState)); internetState = gIpv4InternetState; + ipversion = NSM_IPRESOLVE_V4; } else if ( doContinuousMonitor && (nsm_ipversion::NSM_IPRESOLVE_V6 == ipversion || nsm_ipversion::NSM_IPRESOLVE_WHATEVER == ipversion) && gIpv6InternetState != nsm_internetState::UNKNOWN ) { NMLOG_WARNING("Reading Ipv6 internet state cached value %s", getInternetStateString(gIpv6InternetState)); internetState = gIpv6InternetState; + ipversion = NSM_IPRESOLVE_V6; } 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; } @@ -505,7 +507,7 @@ namespace WPEFramework { Exchange::INetworkManager::InternetStatus oldState = static_cast(gInternetState.load()); Exchange::INetworkManager::InternetStatus newState = static_cast(newInternetState); - _instance->ReportInternetStatusChangedEvent(oldState , newState); + _instance->ReportInternetStatusChange(oldState , newState); gInternetState = newInternetState; } else diff --git a/NetworkManagerConnectivity.h b/NetworkManagerConnectivity.h index 2a39ce23..26f256fa 100644 --- a/NetworkManagerConnectivity.h +++ b/NetworkManagerConnectivity.h @@ -118,7 +118,7 @@ namespace WPEFramework void setConnectivityMonitorEndpoints(const std::vector &endpoints); std::vector getConnectivityMonitorEndpoints(); bool isConnectedToInternet(nsm_ipversion ipversion); - nsm_internetState getInternetState(nsm_ipversion ipversion); + nsm_internetState getInternetState(nsm_ipversion& ipversion); std::string getCaptivePortalURI(); private: diff --git a/NetworkManagerGnomeEvents.cpp b/NetworkManagerGnomeEvents.cpp index b7f17062..bd12c341 100644 --- a/NetworkManagerGnomeEvents.cpp +++ b/NetworkManagerGnomeEvents.cpp @@ -491,7 +491,7 @@ namespace WPEFramework if(oldIface != newIface) { if(_instance != nullptr) - _instance->ReportActiveInterfaceChangedEvent(oldIface, newIface); + _instance->ReportActiveInterfaceChange(oldIface, newIface); NMLOG_INFO("old interface - %s new interface - %s", oldIface.c_str(), newIface.c_str()); oldIface = newIface; } @@ -525,16 +525,16 @@ namespace WPEFramework } NMLOG_DEBUG("%s interface state changed - %s", iface.c_str(), state.c_str()); if(_instance != nullptr && (iface == _nmEventInstance->nmEvents.ifnameWlan0 || iface == _nmEventInstance->nmEvents.ifnameEth0)) - _instance->ReportInterfaceStateChangedEvent(static_cast(newState), iface); + _instance->ReportInterfaceStateChange(static_cast(newState), iface); } void GnomeNetworkManagerEvents::onWIFIStateChanged(uint8_t state) { if(_instance != nullptr) - _instance->ReportWiFiStateChangedEvent(static_cast(state)); + _instance->ReportWiFiStateChange(static_cast(state)); } - void GnomeNetworkManagerEvents::onAddressChangeCb(std::string iface, std::string ipAddress, bool acqired, bool isIPv6) + void GnomeNetworkManagerEvents::onAddressChangeCb(std::string iface, std::string ipAddress, bool acquired, bool isIPv6) { static std::map ipv6Map; static std::map ipv4Map; @@ -563,9 +563,13 @@ namespace WPEFramework ipv4Map[iface] = ipAddress; } + Exchange::INetworkManager::IPStatus ipStatus{}; + if (acquired) + ipStatus = Exchange::INetworkManager::IP_ACQUIRED; + if(_instance != nullptr) - _instance->ReportIPAddressChangedEvent(iface, acqired, true, ipAddress); - NMLOG_INFO("iface:%s - ipaddress:%s - %s - isIPv6:%s", iface.c_str(), ipAddress.c_str(), acqired?"acquired":"lost", isIPv6?"true":"false"); + _instance->ReportIPAddressChange(iface, isIPv6?"IPv6":"IPv4", ipAddress, ipStatus); + NMLOG_INFO("iface:%s - ipaddress:%s - %s - isIPv6:%s", iface.c_str(), ipAddress.c_str(), acquired?"acquired":"lost", isIPv6?"true":"false"); } void GnomeNetworkManagerEvents::onAvailableSSIDsCb(NMDeviceWifi *wifiDevice, GParamSpec *pspec, gpointer userData) @@ -597,7 +601,7 @@ namespace WPEFramework if(_nmEventInstance->doScanNotify) { _nmEventInstance->doScanNotify = false; - _instance->ReportAvailableSSIDsEvent(ssidListJson); + _instance->ReportAvailableSSIDs(ssidListJson); } } diff --git a/NetworkManagerGnomeEvents.h b/NetworkManagerGnomeEvents.h index d65354d8..d775aee9 100644 --- a/NetworkManagerGnomeEvents.h +++ b/NetworkManagerGnomeEvents.h @@ -43,11 +43,11 @@ namespace WPEFramework { public: - static void onInterfaceStateChangeCb(uint8_t newState, std::string iface); // ReportInterfaceStateChangedEvent - static void onAddressChangeCb(std::string iface, std::string ipAddress, bool acqired, bool isIPv6); // ReportIPAddressChangedEvent - static void onActiveInterfaceChangeCb(std::string newInterface); // ReportActiveInterfaceChangedEvent - static void onAvailableSSIDsCb(NMDeviceWifi *wifiDevice, GParamSpec *pspec, gpointer userData); // ReportAvailableSSIDsEvent - static void onWIFIStateChanged(uint8_t state); // ReportWiFiStateChangedEvent + static void onInterfaceStateChangeCb(uint8_t newState, std::string iface); // ReportInterfaceStateChange + static void onAddressChangeCb(std::string iface, std::string ipAddress, bool acqired, bool isIPv6); // ReportIPAddressChange + static void onActiveInterfaceChangeCb(std::string newInterface); // ReportActiveInterfaceChange + static void onAvailableSSIDsCb(NMDeviceWifi *wifiDevice, GParamSpec *pspec, gpointer userData); // ReportAvailableSSIDs + static void onWIFIStateChanged(uint8_t state); // ReportWiFiStateChange public: static GnomeNetworkManagerEvents* getInstance(); diff --git a/NetworkManagerGnomeProxy.cpp b/NetworkManagerGnomeProxy.cpp index f069bc94..6b1fbd31 100644 --- a/NetworkManagerGnomeProxy.cpp +++ b/NetworkManagerGnomeProxy.cpp @@ -70,14 +70,14 @@ namespace WPEFramework if (device) { if(i == 0) - tmp.m_type = string("WIFI"); + tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_WIFI; else - tmp.m_type = string("ETHERNET"); - tmp.m_name = interfaces[i].c_str(); - tmp.m_mac = nm_device_get_hw_address(device); + tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_ETHERNET; + tmp.name = interfaces[i].c_str(); + tmp.mac = nm_device_get_hw_address(device); state = nm_device_get_state(device); - tmp.m_isEnabled = (state > NM_DEVICE_STATE_UNAVAILABLE) ? true : false; - tmp.m_isConnected = (state > NM_DEVICE_STATE_DISCONNECTED) ? true : false; + tmp.enabled = (state > NM_DEVICE_STATE_UNAVAILABLE) ? true : false; + tmp.connected = (state > NM_DEVICE_STATE_DISCONNECTED) ? true : false; interfaceList.push_back(tmp); //g_clear_object(&device); } @@ -194,7 +194,7 @@ namespace WPEFramework return rc; } - uint32_t NetworkManagerImplementation::SetInterfaceState(const string& interface/* @in */, const bool& enabled /* @in */) + uint32_t NetworkManagerImplementation::SetInterfaceState(const string& interface/* @in */, const bool enabled /* @in */) { uint32_t rc = Core::ERROR_NONE; if(client == nullptr) @@ -263,7 +263,7 @@ namespace WPEFramework } /* @brief Get IP Address Of the Interface */ - uint32_t NetworkManagerImplementation::GetIPSettings(const string& interface /* @in */, const string& ipversion /* @in */, IPAddressInfo& result /* @out */) + uint32_t NetworkManagerImplementation::GetIPSettings(string& interface /* @inout */, const string &ipversion /* @in */, IPAddress& result /* @out */) { uint32_t rc = Core::ERROR_RPC_CALL_FAILED; NMActiveConnection *conn = NULL; @@ -361,19 +361,19 @@ namespace WPEFramework dhcpserver = nm_dhcp_config_get_one_option (dhcp4_config, "dhcp_server_identifier"); if(!ipversion.empty()) - result.m_ipAddrType = ipversion.c_str(); + result.ipversion = ipversion.c_str(); else - result.m_ipAddrType = "IPv4"; + result.ipversion = "IPv4"; if(dhcpserver) - result.m_dhcpServer = dhcpserver; - result.m_v6LinkLocal = ""; - result.m_ipAddress = nm_ip_address_get_address(address); - result.m_prefix = nm_ip_address_get_prefix(address); - result.m_gateway = gateway; + result.dhcpserver = dhcpserver; + result.ula = ""; + result.ipaddress = nm_ip_address_get_address(address); + result.prefix = nm_ip_address_get_prefix(address); + result.gateway = gateway; if((*(&dns_arr[0]))!=NULL) - result.m_primaryDns = *(&dns_arr[0]); + result.primarydns = *(&dns_arr[0]); if((*(&dns_arr[1]))!=NULL ) - result.m_secondaryDns = *(&dns_arr[1]); + result.secondarydns = *(&dns_arr[1]); rc = Core::ERROR_NONE; } @@ -387,7 +387,7 @@ namespace WPEFramework p = nm_ip_config_get_addresses(ip6_config); for (i = 0; i < p->len; i++) { a = static_cast(p->pdata[i]); - result.m_ipAddress = nm_ip_address_get_address(a); + result.ipaddress = nm_ip_address_get_address(a); NMLOG_DEBUG("\tinet6 %s/%d\n", nm_ip_address_get_address(a), nm_ip_address_get_prefix(a)); } gateway = nm_ip_config_get_gateway(ip6_config); @@ -397,16 +397,16 @@ namespace WPEFramework dhcp6_config = nm_active_connection_get_dhcp6_config(conn); dhcpserver = nm_dhcp_config_get_one_option (dhcp6_config, "dhcp_server_identifier"); - result.m_ipAddrType = ipversion.c_str(); + result.ipversion = ipversion.c_str(); if(dhcpserver) - result.m_dhcpServer = dhcpserver; - result.m_v6LinkLocal = ""; - result.m_prefix = 0; - result.m_gateway = gateway; + result.dhcpserver = dhcpserver; + result.ula = ""; + result.prefix = 0; + result.gateway = gateway; if((*(&dns_arr[0]))!=NULL) - result.m_primaryDns = *(&dns_arr[0]); + result.primarydns = *(&dns_arr[0]); if((*(&dns_arr[1]))!=NULL ) - result.m_secondaryDns = *(&dns_arr[1]); + result.secondarydns = *(&dns_arr[1]); } rc = Core::ERROR_NONE; } @@ -445,7 +445,7 @@ namespace WPEFramework /* @brief Set IP Address Of the Interface */ - uint32_t NetworkManagerImplementation::SetIPSettings(const string& interface /* @in */, const string &ipversion /* @in */, const IPAddressInfo& address /* @in */) + uint32_t NetworkManagerImplementation::SetIPSettings(const string& interface /* @in */, const IPAddress& address /* @in */) { GMainLoop *g_loop; g_loop = g_main_loop_new(NULL, FALSE); @@ -476,9 +476,9 @@ namespace WPEFramework break; } } - if (!address.m_autoConfig) + if (!address.autoconfig) { - if (nmUtils::caseInsensitiveCompare("IPv4", ipversion)) + if (nmUtils::caseInsensitiveCompare("IPv4", address.ipversion)) { NMSettingIPConfig *ip4_config = nm_connection_get_setting_ip4_config(conn); if (ip4_config == NULL) @@ -487,15 +487,15 @@ namespace WPEFramework } NMIPAddress *ipAddress; setting = nm_connection_get_setting_by_name(conn, "ipv4"); - ipAddress = nm_ip_address_new(AF_INET, address.m_ipAddress.c_str(), address.m_prefix, NULL); + ipAddress = nm_ip_address_new(AF_INET, address.ipaddress.c_str(), address.prefix, NULL); nm_setting_ip_config_clear_addresses(ip4_config); nm_setting_ip_config_add_address(NM_SETTING_IP_CONFIG(setting), ipAddress); nm_setting_ip_config_clear_dns(ip4_config); - nm_setting_ip_config_add_dns(ip4_config, address.m_primaryDns.c_str()); - nm_setting_ip_config_add_dns(ip4_config, address.m_secondaryDns.c_str()); + nm_setting_ip_config_add_dns(ip4_config, address.primarydns.c_str()); + nm_setting_ip_config_add_dns(ip4_config, address.secondarydns.c_str()); g_object_set(G_OBJECT(ip4_config), - NM_SETTING_IP_CONFIG_GATEWAY, address.m_gateway.c_str(), + NM_SETTING_IP_CONFIG_GATEWAY, address.gateway.c_str(), NM_SETTING_IP_CONFIG_NEVER_DEFAULT, FALSE, NULL); @@ -509,7 +509,7 @@ namespace WPEFramework } else { - if (nmUtils::caseInsensitiveCompare("IPv4", ipversion)) + if (nmUtils::caseInsensitiveCompare("IPv4", address.ipversion)) { s_ip4 = (NMSettingIP4Config *)nm_setting_ip4_config_new(); g_object_set(G_OBJECT(s_ip4), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); @@ -547,9 +547,11 @@ namespace WPEFramework return rc; } - uint32_t NetworkManagerImplementation::StartWiFiScan(const WiFiFrequency frequency /* @in */) + uint32_t NetworkManagerImplementation::StartWiFiScan(const string& frequency /* @in */, IStringIterator* const ssids/* @in */) { uint32_t rc = Core::ERROR_RPC_CALL_FAILED; + (void) ssids; + nmEvent->setwifiScanOptions(true, true); if(wifi->wifiScanRequest(frequency)) rc = Core::ERROR_NONE; @@ -606,7 +608,7 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::WiFiConnect(const WiFiConnectTo& ssid /* @in */) { uint32_t rc = Core::ERROR_GENERAL; - if(ssid.m_ssid.empty() || ssid.m_ssid.size() > 32) + if(ssid.ssid.empty() || ssid.ssid.size() > 32) { NMLOG_WARNING("ssid is invalied"); return rc; @@ -615,7 +617,7 @@ namespace WPEFramework if(!wifi->isWifiScannedRecently()) { nmEvent->setwifiScanOptions(false, true); // not notify scan result but print logs - if(!wifi->wifiScanRequest(Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_WHATEVER, ssid.m_ssid)) + if(!wifi->wifiScanRequest("", ssid.ssid)) { NMLOG_WARNING("scanning failed but try to connect"); } @@ -648,8 +650,8 @@ namespace WPEFramework WiFiSSIDInfo ssidInfo; if(wifi->wifiConnectedSSIDInfo(ssidInfo)) { - ssid = ssidInfo.m_ssid; - signalStrength = ssidInfo.m_signalStrength; + ssid = ssidInfo.ssid; + signalStrength = ssidInfo.strength; float signalStrengthFloat = 0.0f; if(!signalStrength.empty()) diff --git a/NetworkManagerGnomeWIFI.cpp b/NetworkManagerGnomeWIFI.cpp index 497f567c..12d8e49a 100644 --- a/NetworkManagerGnomeWIFI.cpp +++ b/NetworkManagerGnomeWIFI.cpp @@ -191,48 +191,31 @@ namespace WPEFramework if(size<=32) { std::string ssidTmp(reinterpret_cast(ssidData), size); - wifiInfo.m_ssid = ssidTmp; - NMLOG_INFO("ssid: %s", wifiInfo.m_ssid.c_str()); + wifiInfo.ssid = ssidTmp; + NMLOG_INFO("ssid: %s", wifiInfo.ssid.c_str()); } else { NMLOG_ERROR("Invallied ssid length Error"); - wifiInfo.m_ssid.clear(); + wifiInfo.ssid.clear(); return; } } else { - wifiInfo.m_ssid = "-----"; - NMLOG_DEBUG("ssid: %s", wifiInfo.m_ssid.c_str()); + wifiInfo.ssid = "-----"; + NMLOG_DEBUG("ssid: %s", wifiInfo.ssid.c_str()); } - wifiInfo.m_bssid = (hwaddr != nullptr) ? hwaddr : "-----"; - NMLOG_DEBUG("bssid: %s", wifiInfo.m_bssid.c_str()); - - if (freq >= 2400 && freq < 5000) { - wifiInfo.m_frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_2_4_GHZ; - NMLOG_DEBUG("freq: WIFI_FREQUENCY_2_4_GHZ"); - } - else if (freq >= 5000 && freq < 6000) { - wifiInfo.m_frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_5_GHZ; - NMLOG_DEBUG("freq: WIFI_FREQUENCY_5_GHZ"); - } - else if (freq >= 6000) { - wifiInfo.m_frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_6_GHZ; - NMLOG_DEBUG("freq: WIFI_FREQUENCY_6_GHZ"); - } - else { - wifiInfo.m_frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_WHATEVER; - NMLOG_DEBUG("freq: No available !"); - } - - wifiInfo.m_rate = std::to_string(bitrate); - NMLOG_DEBUG("bitrate : %s kbit/s", wifiInfo.m_rate.c_str()); + wifiInfo.bssid = (hwaddr != nullptr) ? hwaddr : "-----"; + NMLOG_DEBUG("bssid: %s", wifiInfo.bssid.c_str()); + wifiInfo.frequency = std::to_string((double)freq/1000); + wifiInfo.rate = std::to_string(bitrate); + NMLOG_DEBUG("bitrate : %s kbit/s", wifiInfo.rate.c_str()); //TODO signal strenght to dBm - wifiInfo.m_signalStrength = std::to_string(static_cast(strength)); - NMLOG_DEBUG("sterngth: %s %%", wifiInfo.m_signalStrength.c_str()); - wifiInfo.m_securityMode = static_cast(nmUtils::wifiSecurityModeFromAp(flags, wpaFlags, rsnFlags)); + wifiInfo.strength = std::to_string(static_cast(strength)); + NMLOG_DEBUG("sterngth: %s %%", wifiInfo.strength.c_str()); + wifiInfo.security = static_cast(nmUtils::wifiSecurityModeFromAp(flags, wpaFlags, rsnFlags)); NMLOG_DEBUG("security %s", nmUtils::getSecurityModeString(flags, wpaFlags, rsnFlags).c_str()); NMLOG_DEBUG("Mode: %s", mode == NM_802_11_MODE_ADHOC ? "Ad-Hoc": mode == NM_802_11_MODE_INFRA ? "Infrastructure": "Unknown"); } @@ -401,8 +384,8 @@ namespace WPEFramework bool wifiManager::wifiConnect(Exchange::INetworkManager::WiFiConnectTo wifiData) { - const char *ssid_in = wifiData.m_ssid.c_str(); - const char* password_in = wifiData.m_passphrase.c_str(); + const char *ssid_in = wifiData.ssid.c_str(); + const char* password_in = wifiData.passphrase.c_str(); NMAccessPoint *AccessPoint = NULL; GPtrArray *allaps = NULL; const char *conName = ssid_in; @@ -542,19 +525,19 @@ namespace WPEFramework GError *error = NULL; NMLOG_INFO("Ap securtity mode is 802.1X"); - NMLOG_DEBUG("802.1x Identity : %s", wifiData.m_identity.c_str()); - NMLOG_DEBUG("802.1x CA cert path : %s", wifiData.m_caCert.c_str()); - NMLOG_DEBUG("802.1x Client cert path : %s", wifiData.m_clientCert.c_str()); - NMLOG_DEBUG("802.1x Private key path : %s", wifiData.m_privateKey.c_str()); - NMLOG_DEBUG("802.1x Private key psswd : %s", wifiData.m_privateKeyPasswd.c_str()); + NMLOG_DEBUG("802.1x Identity : %s", wifiData.eap_identity.c_str()); + NMLOG_DEBUG("802.1x CA cert path : %s", wifiData.ca_cert.c_str()); + NMLOG_DEBUG("802.1x Client cert path : %s", wifiData.client_cert.c_str()); + NMLOG_DEBUG("802.1x Private key path : %s", wifiData.private_key.c_str()); + NMLOG_DEBUG("802.1x Private key psswd : %s", wifiData.private_key_passwd.c_str()); s8021X = (NMSetting8021x *) nm_setting_802_1x_new(); nm_connection_add_setting(connection, NM_SETTING(s8021X)); - g_object_set(s8021X, NM_SETTING_802_1X_IDENTITY, wifiData.m_identity.c_str(), NULL); + g_object_set(s8021X, NM_SETTING_802_1X_IDENTITY, wifiData.eap_identity.c_str(), NULL); nm_setting_802_1x_add_eap_method(s8021X, "tls"); - if(!wifiData.m_caCert.empty() && !nm_setting_802_1x_set_ca_cert(s8021X, - wifiData.m_caCert.c_str(), + if(!wifiData.ca_cert.empty() && !nm_setting_802_1x_set_ca_cert(s8021X, + wifiData.ca_cert.c_str(), NM_SETTING_802_1X_CK_SCHEME_PATH, NULL, &error)) @@ -564,8 +547,8 @@ namespace WPEFramework return false; } - if(!wifiData.m_clientCert.empty() && !nm_setting_802_1x_set_client_cert(s8021X, - wifiData.m_clientCert.c_str(), + if(!wifiData.client_cert.empty() && !nm_setting_802_1x_set_client_cert(s8021X, + wifiData.client_cert.c_str(), NM_SETTING_802_1X_CK_SCHEME_PATH, NULL, &error)) @@ -575,9 +558,9 @@ namespace WPEFramework return false; } - if(!wifiData.m_privateKey.empty() && !nm_setting_802_1x_set_private_key(s8021X, - wifiData.m_privateKey.c_str(), - wifiData.m_privateKeyPasswd.c_str(), + if(!wifiData.private_key.empty() && !nm_setting_802_1x_set_private_key(s8021X, + wifiData.private_key.c_str(), + wifiData.private_key_passwd.c_str(), NM_SETTING_802_1X_CK_SCHEME_PATH, NULL, &error)) @@ -687,20 +670,20 @@ namespace WPEFramework NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_ID, - ssidinfo.m_ssid.c_str(), + ssidinfo.ssid.c_str(), NM_SETTING_CONNECTION_TYPE, "802-11-wireless", NULL); NMConnection *connection = nm_simple_connection_new(); nm_connection_add_setting(connection, NM_SETTING(nmConnSec)); nmSettingsWifi = (NMSettingWireless *)nm_setting_wireless_new(); - GString *ssidStr = g_string_new(ssidinfo.m_ssid.c_str()); + GString *ssidStr = g_string_new(ssidinfo.ssid.c_str()); g_object_set(G_OBJECT(nmSettingsWifi), NM_SETTING_WIRELESS_SSID, ssidStr, NULL); nm_connection_add_setting(connection, NM_SETTING(nmSettingsWifi)); nmSettingsWifiSec = (NMSettingWirelessSecurity *)nm_setting_wireless_security_new(); // TODO chek different securtity mode and portocol and add settings - switch(ssidinfo.m_securityMode) + switch(ssidinfo.security) { case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK_AES: case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_WPA2_PSK: @@ -710,8 +693,8 @@ namespace WPEFramework case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_SAE: { g_object_set(G_OBJECT(nmSettingsWifiSec), NM_SETTING_WIRELESS_SECURITY_KEY_MGMT,"wpa-psk", NULL); - if(!ssidinfo.m_passphrase.empty()) - g_object_set(G_OBJECT(nmSettingsWifiSec), NM_SETTING_WIRELESS_SECURITY_PSK, ssidinfo.m_passphrase.c_str(), NULL); + if(!ssidinfo.passphrase.empty()) + g_object_set(G_OBJECT(nmSettingsWifiSec), NM_SETTING_WIRELESS_SECURITY_PSK, ssidinfo.passphrase.c_str(), NULL); break; } case Exchange::INetworkManager::WIFI_SECURITY_NONE: @@ -858,7 +841,7 @@ namespace WPEFramework g_main_loop_quit(_wifiManager->loop); } - bool wifiManager::wifiScanRequest(const Exchange::INetworkManager::WiFiFrequency frequency, std::string ssidReq) + bool wifiManager::wifiScanRequest(std::string frequency, std::string ssidReq) { if(!createClientNewConnection()) return false; diff --git a/NetworkManagerGnomeWIFI.h b/NetworkManagerGnomeWIFI.h index ec17b475..8762f409 100644 --- a/NetworkManagerGnomeWIFI.h +++ b/NetworkManagerGnomeWIFI.h @@ -46,7 +46,7 @@ namespace WPEFramework bool wifiDisconnect(); bool wifiConnectedSSIDInfo(Exchange::INetworkManager::WiFiSSIDInfo &ssidinfo); bool wifiConnect(Exchange::INetworkManager::WiFiConnectTo wifiData); - bool wifiScanRequest(const Exchange::INetworkManager::WiFiFrequency frequency, std::string ssidReq = ""); + bool wifiScanRequest(std::string frequency, std::string ssidReq = ""); bool isWifiScannedRecently(int timelimitInSec = 10); // default 10 sec as shotest scanning interval bool getKnownSSIDs(std::list& ssids); bool addToKnownSSIDs(const Exchange::INetworkManager::WiFiConnectTo ssidinfo); diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index 7315ca0f..7da44a9e 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -100,7 +100,7 @@ namespace WPEFramework return Core::ERROR_NONE; } - uint32_t NetworkManagerImplementation::Configure(const string& configLine /* @in */, NMLogging& logLevel /* @out */) + uint32_t NetworkManagerImplementation::Configure(const string& configLine /* @in */) { if(configLine.empty()) { @@ -123,9 +123,7 @@ namespace WPEFramework NMLOG_DEBUG("config : stun interval %d", m_stunBindTimeout); NMLOG_DEBUG("config : loglevel %d", config.loglevel.Value()); - logLevel = static_cast (config.loglevel.Value()); - // configure loglevel in libWPEFrameworkNetworkManagerImplementation.so - NetworkManagerLogger::SetLevel(static_cast (logLevel)); + NetworkManagerLogger::SetLevel(static_cast (config.loglevel.Value())); /* load connectivity monitor endpoints */ std::vector connectEndpts; @@ -150,7 +148,19 @@ namespace WPEFramework connectEndpts.push_back(config.connectivityConf.endpoint_5.Value().c_str()); } - connectivityMonitor.setConnectivityMonitorEndpoints(connectEndpts); + /* check whether the endpoint is already loaded from Cache; if Yes, do not use the one from configuration */ + if (connectivityMonitor.getConnectivityMonitorEndpoints().size() < 1) + { + NMLOG_INFO("config : Use the connectivity endpoint from config"); + connectivityMonitor.setConnectivityMonitorEndpoints(connectEndpts); + } + else if (connectEndpts.size() < 1) + { + std::vector backup; + NMLOG_INFO("config : Connectivity endpoints are empty in config; use the default"); + backup.push_back("http://clients3.google.com/generate_204"); + connectivityMonitor.setConnectivityMonitorEndpoints(backup); + } } else NMLOG_ERROR("Plugin configuration read error !"); @@ -211,7 +221,7 @@ namespace WPEFramework } /* @brief Get Internet Connectivty Status */ - uint32_t NetworkManagerImplementation::IsConnectedToInternet(const string &ipversion /* @in */, InternetStatus &result /* @out */) + uint32_t NetworkManagerImplementation::IsConnectedToInternet(string &ipversion /* @in */, InternetStatus &result /* @out */) { LOG_ENTRY_FUNCTION(); nsm_internetState isconnected; @@ -231,6 +241,11 @@ namespace WPEFramework else result = INTERNET_NOT_AVAILABLE; + if (NSM_IPRESOLVE_V6 == tmpVersion) + ipversion = "IPv6"; + else + ipversion = "IPv4"; + return Core::ERROR_NONE; } @@ -263,15 +278,16 @@ namespace WPEFramework } /* @brief Get the Public IP used for external world communication */ - uint32_t NetworkManagerImplementation::GetPublicIP (const string &ipversion /* @in */, string& ipAddress /* @out */) + uint32_t NetworkManagerImplementation::GetPublicIP (const string &ipversion /* @in */, string& ipaddress /* @out */) { LOG_ENTRY_FUNCTION(); stun::bind_result result; - bool isIPv6 = (0 == strcasecmp("IPv6", ipversion.c_str())); + bool isIPv6 = (ipversion == "IPv6"); + stun::protocol proto (isIPv6 ? stun::protocol::af_inet6 : stun::protocol::af_inet); if(stunClient.bind(m_stunEndPoint, m_stunPort, m_defaultInterface, proto, m_stunBindTimeout, m_stunCacheTimeout, result)) { - ipAddress = result.public_ip; + ipaddress = result.public_ip; return Core::ERROR_NONE; } else @@ -281,9 +297,19 @@ namespace WPEFramework } /* @brief Set the network manager plugin log level */ - uint32_t NetworkManagerImplementation::SetLogLevel(const NMLogging& logLevel /* @in */) + uint32_t NetworkManagerImplementation::SetLogLevel(const Logging& level /* @in */) + { + NetworkManagerLogger::SetLevel((LogLevel)level); + return Core::ERROR_NONE; + } + + /* @brief Get the network manager plugin log level */ + uint32_t NetworkManagerImplementation::GetLogLevel(Logging& level /* @out */) { - NetworkManagerLogger::SetLevel((LogLevel)logLevel); + LogLevel inLevel; + NetworkManagerLogger::GetLevel(inLevel); + + level = static_cast(inLevel); return Core::ERROR_NONE; } @@ -291,6 +317,7 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::Ping (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t noOfRequest /* @in */, const uint16_t timeOutInSeconds /* @in */, const string guid /* @in */, string& response /* @out */) { char cmd[100] = ""; + string tempResult = ""; if(0 == strcasecmp("IPv6", ipversion.c_str())) { snprintf(cmd, sizeof(cmd), "ping6 -c %d -W %d '%s' 2>&1", noOfRequest, timeOutInSeconds, endpoint.c_str()); @@ -302,7 +329,12 @@ namespace WPEFramework NMLOG_DEBUG ("The Command is %s", cmd); string commandToExecute(cmd); - executeExternally(NETMGR_PING, commandToExecute, response); + executeExternally(NETMGR_PING, commandToExecute, tempResult); + + JsonObject temp; + temp.FromString(tempResult); + temp["endpoint"] = endpoint; + temp.ToString(response); return Core::ERROR_NONE; } @@ -326,7 +358,7 @@ namespace WPEFramework executeExternally(NETMGR_TRACE, commandToExecute, tempResult); JsonObject temp; - temp["target"] = endpoint; + temp["endpoint"] = endpoint; temp["results"] = tempResult; temp.ToString(response); @@ -485,7 +517,7 @@ namespace WPEFramework return Core::ERROR_NONE; } - void NetworkManagerImplementation::ReportInterfaceStateChangedEvent(INetworkManager::InterfaceState state, string interface) + void NetworkManagerImplementation::ReportInterfaceStateChange(const Exchange::INetworkManager::InterfaceState state, const string interface) { LOG_ENTRY_FUNCTION(); if(Exchange::INetworkManager::INTERFACE_LINK_DOWN == state) { @@ -494,7 +526,6 @@ namespace WPEFramework connectivityMonitor.startConnectivityMonitor(false); } - NMLOG_INFO("Posting onInterfaceStateChange %s", interface.c_str()); _notificationLock.Lock(); for (const auto callback : _notificationCallbacks) { callback->onInterfaceStateChange(state, interface); @@ -502,48 +533,45 @@ namespace WPEFramework _notificationLock.Unlock(); } - void NetworkManagerImplementation::ReportIPAddressChangedEvent(const string& interface, bool isAcquired, bool isIPv6, const string& ipAddress) + void NetworkManagerImplementation::ReportActiveInterfaceChange(const string prevActiveInterface, const string currentActiveinterface) { - LOG_ENTRY_FUNCTION(); - if (isAcquired) { - // 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(true); - } - - NMLOG_INFO("Posting onIPAddressChange %s", ipAddress.c_str()); + NMLOG_INFO("Posting onActiveInterfaceChange %s", currentActiveinterface.c_str()); _notificationLock.Lock(); for (const auto callback : _notificationCallbacks) { - callback->onIPAddressChange(interface, isAcquired, isIPv6, ipAddress); + callback->onActiveInterfaceChange(prevActiveInterface, currentActiveinterface); } _notificationLock.Unlock(); } - void NetworkManagerImplementation::ReportActiveInterfaceChangedEvent(const string prevActiveInterface, const string currentActiveinterface) + void NetworkManagerImplementation::ReportIPAddressChange(const string interface, const string ipversion, const string ipaddress, const Exchange::INetworkManager::IPStatus status) { LOG_ENTRY_FUNCTION(); - NMLOG_INFO("Posting onActiveInterfaceChange %s", currentActiveinterface.c_str()); + 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(true); + } + + NMLOG_INFO("Posting onIPAddressChange %s", ipaddress.c_str()); _notificationLock.Lock(); for (const auto callback : _notificationCallbacks) { - callback->onActiveInterfaceChange(prevActiveInterface, currentActiveinterface); + callback->onIPAddressChange(interface, ipversion, ipaddress, status); } _notificationLock.Unlock(); } - void NetworkManagerImplementation::ReportInternetStatusChangedEvent(const InternetStatus oldState, const InternetStatus newstate) + void NetworkManagerImplementation::ReportInternetStatusChange(const Exchange::INetworkManager::InternetStatus prevState, const Exchange::INetworkManager::InternetStatus currState) { - LOG_ENTRY_FUNCTION(); - NMLOG_INFO("Posting onInternetStatusChange"); + NMLOG_INFO("Posting onInternetStatusChange with current state as %u", (unsigned)currState); _notificationLock.Lock(); for (const auto callback : _notificationCallbacks) { - callback->onInternetStatusChange(oldState, newstate); + callback->onInternetStatusChange(prevState, currState); } _notificationLock.Unlock(); } - void NetworkManagerImplementation::ReportAvailableSSIDsEvent(const string jsonOfWiFiScanResults) + void NetworkManagerImplementation::ReportAvailableSSIDs(const string jsonOfWiFiScanResults) { - LOG_ENTRY_FUNCTION(); _notificationLock.Lock(); NMLOG_INFO("Posting onAvailableSSIDs result is, %s", jsonOfWiFiScanResults.c_str()); for (const auto callback : _notificationCallbacks) { @@ -552,9 +580,8 @@ namespace WPEFramework _notificationLock.Unlock(); } - void NetworkManagerImplementation::ReportWiFiStateChangedEvent(const INetworkManager::WiFiState state) + void NetworkManagerImplementation::ReportWiFiStateChange(const Exchange::INetworkManager::WiFiState state) { - LOG_ENTRY_FUNCTION(); /* start signal strength monitor when wifi connected */ if(INetworkManager::WiFiState::WIFI_STATE_CONNECTED == state) m_wifiSignalMonitor.startWiFiSignalStrengthMonitor(DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC); @@ -567,13 +594,12 @@ namespace WPEFramework _notificationLock.Unlock(); } - void NetworkManagerImplementation::ReportWiFiSignalStrengthChangedEvent(const string ssid, const string signalLevel, const WiFiSignalQuality signalQuality) + void NetworkManagerImplementation::ReportWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality) { - LOG_ENTRY_FUNCTION(); NMLOG_INFO("Posting onWiFiSignalStrengthChange"); _notificationLock.Lock(); for (const auto callback : _notificationCallbacks) { - callback->onWiFiSignalStrengthChange(ssid, signalLevel, signalQuality); + callback->onWiFiSignalStrengthChange(ssid, strength, quality); } _notificationLock.Unlock(); diff --git a/NetworkManagerImplementation.h b/NetworkManagerImplementation.h index 8c983908..d6ae934c 100644 --- a/NetworkManagerImplementation.h +++ b/NetworkManagerImplementation.h @@ -35,8 +35,6 @@ using namespace std; #include "NetworkManagerConnectivity.h" #include "NetworkManagerStunClient.h" -#define LOG_ENTRY_FUNCTION() { NMLOG_DEBUG("Entering=%s", __FUNCTION__ ); } - namespace WPEFramework { namespace Plugin @@ -152,18 +150,18 @@ namespace WPEFramework uint32_t SetPrimaryInterface (const string& interface/* @in */) override; /* @brief Enable/Disable the given interface */ - uint32_t SetInterfaceState(const string& interface/* @in */, const bool& isEnabled/* @in */) override; + uint32_t SetInterfaceState(const string& interface/* @in */, const bool isEnabled/* @in */) override; /* @brief Get the state of given interface */ uint32_t GetInterfaceState(const string& interface/* @in */, bool& isEnabled/* @out */) override; /* @brief Get IP Address Of the Interface */ - uint32_t GetIPSettings(const string& interface /* @in */, const string &ipversion /* @in */, IPAddressInfo& result /* @out */) override; + uint32_t GetIPSettings(string& interface /* @inout */, const string& ipversion /* @in */, IPAddress& address /* @out */) override; /* @brief Set IP Address Of the Interface */ - uint32_t SetIPSettings(const string& interface /* @in */, const string &ipversion /* @in */, const IPAddressInfo& address /* @in */) override; + uint32_t SetIPSettings(const string& interface /* @in */, const IPAddress& address /* @in */) override; // WiFi Specific Methods /* @brief Initiate a WIFI Scan; This is Async method and returns the scan results as Event */ - uint32_t StartWiFiScan(const WiFiFrequency frequency /* @in */); + uint32_t StartWiFiScan(const string& frequency /* @in */, IStringIterator* const ssids/* @in */) override; uint32_t StopWiFiScan(void) override; uint32_t GetKnownSSIDs(IStringIterator*& ssids /* @out */) override; @@ -188,7 +186,7 @@ namespace WPEFramework uint32_t SetConnectivityTestEndpoints(IStringIterator* const endPoints /* @in */) override; /* @brief Get Internet Connectivty Status */ - uint32_t IsConnectedToInternet(const string &ipversion /* @in */, InternetStatus &result /* @out */) override; + uint32_t IsConnectedToInternet(string &ipversion /* @inout */, InternetStatus &result /* @out */) override; /* @brief Get Authentication URL if the device is behind Captive Portal */ uint32_t GetCaptivePortalURI(string &endPoints/* @out */) const override; @@ -198,7 +196,7 @@ namespace WPEFramework uint32_t StopConnectivityMonitoring(void) const override; /* @brief Get the Public IP used for external world communication */ - uint32_t GetPublicIP (const string &ipversion /* @in */, string& ipAddress /* @out */) override; + uint32_t GetPublicIP (const string &ipversion /* @in */, string& ipaddress /* @out */) override; /* @brief Request for ping and get the response in as event. The GUID used in the request will be returned in the event. */ uint32_t Ping (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t noOfRequest /* @in */, const uint16_t timeOutInSeconds /* @in */, const string guid /* @in */, string& response /* @out */) override; @@ -209,19 +207,20 @@ namespace WPEFramework uint32_t GetSupportedSecurityModes(ISecurityModeIterator*& securityModes /* @out */) const override; /* @brief Set the network manager plugin log level */ - uint32_t SetLogLevel(const NMLogging& logLevel /* @in */) override; + uint32_t SetLogLevel(const Logging& level /* @in */) override; + uint32_t GetLogLevel(Logging& level /* @out */) override; /* @brief configure network manager plugin */ - uint32_t Configure(const string& configLine /* @in */, NMLogging& logLevel /* @out */) override; + uint32_t Configure(const string& configLine /* @in */) override; /* Events */ - void ReportInterfaceStateChangedEvent(INetworkManager::InterfaceState state, string interface); - void ReportIPAddressChangedEvent(const string& interface, bool isAcquired, bool isIPv6, const string& ipAddress); - void ReportActiveInterfaceChangedEvent(const string prevActiveInterface, const string currentActiveinterface); - void ReportInternetStatusChangedEvent(const InternetStatus oldState, const InternetStatus newstate); - void ReportAvailableSSIDsEvent(const string jsonOfWiFiScanResults); - void ReportWiFiStateChangedEvent(const INetworkManager::WiFiState state); - void ReportWiFiSignalStrengthChangedEvent(const string ssid , const string signalLevel , const WiFiSignalQuality signalQuality); + void ReportInterfaceStateChange(const Exchange::INetworkManager::InterfaceState state, const string interface); + void ReportActiveInterfaceChange(const string prevActiveInterface, const string currentActiveinterface); + void ReportIPAddressChange(const string interface, const string ipversion, const string ipaddress, const Exchange::INetworkManager::IPStatus status); + void ReportInternetStatusChange(const Exchange::INetworkManager::InternetStatus prevState, const Exchange::INetworkManager::InternetStatus currState); + void ReportAvailableSSIDs(const string jsonOfScanResults); + void ReportWiFiStateChange(const Exchange::INetworkManager::WiFiState state); + void ReportWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality); private: void platform_init(); diff --git a/NetworkManagerJsonEnum.h b/NetworkManagerJsonEnum.h new file mode 100644 index 00000000..54725b0b --- /dev/null +++ b/NetworkManagerJsonEnum.h @@ -0,0 +1,99 @@ +#pragma once + +#include +#include "INetworkManager.h" + +namespace WPEFramework { + +ENUM_CONVERSION_BEGIN(Exchange::INetworkManager::InterfaceType) + { Exchange::INetworkManager::InterfaceType::INTERFACE_TYPE_ETHERNET, _TXT("ETHERNET") }, + { Exchange::INetworkManager::InterfaceType::INTERFACE_TYPE_WIFI, _TXT("WIFI") }, + { Exchange::INetworkManager::InterfaceType::INTERFACE_TYPE_P2P, _TXT("P2P") }, +ENUM_CONVERSION_END(Exchange::INetworkManager::InterfaceType) + +ENUM_CONVERSION_BEGIN(Exchange::INetworkManager::IPVersion) + { Exchange::INetworkManager::IPVersion::IP_ADDRESS_V4, _TXT("IPv4") }, + { Exchange::INetworkManager::IPVersion::IP_ADDRESS_V6, _TXT("IPv6") }, +ENUM_CONVERSION_END(Exchange::INetworkManager::IPVersion) + +ENUM_CONVERSION_BEGIN(Exchange::INetworkManager::InternetStatus) + { Exchange::INetworkManager::InternetStatus::INTERNET_NOT_AVAILABLE, _TXT("NO_INTERNET") }, + { Exchange::INetworkManager::InternetStatus::INTERNET_LIMITED, _TXT("LIMITED_INTERNET") }, + { Exchange::INetworkManager::InternetStatus::INTERNET_CAPTIVE_PORTAL, _TXT("CAPTIVE_PORTAL") }, + { Exchange::INetworkManager::InternetStatus::INTERNET_FULLY_CONNECTED, _TXT("FULLY_CONNECTED") }, + { Exchange::INetworkManager::InternetStatus::INTERNET_UNKNOWN, _TXT("UNKNOWN") }, +ENUM_CONVERSION_END(Exchange::INetworkManager::InternetStatus) + +ENUM_CONVERSION_BEGIN(Exchange::INetworkManager::WIFISecurityMode) + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_NONE, _TXT("0") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WEP_64, _TXT("1") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WEP_128, _TXT("2") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK_TKIP, _TXT("3") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK_AES, _TXT("4") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA2_PSK_TKIP, _TXT("5") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA2_PSK_AES, _TXT("6") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_ENTERPRISE_TKIP, _TXT("7") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_ENTERPRISE_AES, _TXT("8") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA2_ENTERPRISE_TKIP, _TXT("9") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA2_ENTERPRISE_AES, _TXT("10") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_WPA2_PSK, _TXT("11") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_WPA2_ENTERPRISE, _TXT("12") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_PSK_AES, _TXT("13") }, + { Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_SAE, _TXT("14") }, +ENUM_CONVERSION_END(Exchange::INetworkManager::WIFISecurityMode) + +ENUM_CONVERSION_BEGIN(Exchange::INetworkManager::WiFiWPS) + { Exchange::INetworkManager::WiFiWPS::WIFI_WPS_PBC, _TXT("PBC") }, + { Exchange::INetworkManager::WiFiWPS::WIFI_WPS_PIN, _TXT("PIN") }, + { Exchange::INetworkManager::WiFiWPS::WIFI_WPS_SERIALIZED_PIN, _TXT("SERIALIZED_PIN") }, +ENUM_CONVERSION_END(Exchange::INetworkManager::WiFiWPS) + +ENUM_CONVERSION_BEGIN(Exchange::INetworkManager::WiFiState) + { Exchange::INetworkManager::WiFiState::WIFI_STATE_UNINSTALLED, _TXT("WIFI_STATE_UNINSTALLED") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_DISABLED, _TXT("WIFI_STATE_DISABLED") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_DISCONNECTED, _TXT("WIFI_STATE_DISCONNECTED") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_PAIRING, _TXT("WIFI_STATE_PAIRING") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_CONNECTING, _TXT("WIFI_STATE_CONNECTING") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_CONNECTED, _TXT("WIFI_STATE_CONNECTED") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_SSID_NOT_FOUND, _TXT("WIFI_STATE_SSID_NOT_FOUND") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_SSID_CHANGED, _TXT("WIFI_STATE_SSID_CHANGED") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_CONNECTION_LOST, _TXT("WIFI_STATE_CONNECTION_LOST") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_CONNECTION_FAILED, _TXT("WIFI_STATE_CONNECTION_FAILED") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_CONNECTION_INTERRUPTED, _TXT("WIFI_STATE_CONNECTION_INTERRUPTED") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_INVALID_CREDENTIALS, _TXT("WIFI_STATE_INVALID_CREDENTIALS") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_AUTHENTICATION_FAILED, _TXT("WIFI_STATE_AUTHENTICATION_FAILED") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_ERROR, _TXT("WIFI_STATE_ERROR") }, + { Exchange::INetworkManager::WiFiState::WIFI_STATE_INVALID, _TXT("WIFI_STATE_INVALID") }, +ENUM_CONVERSION_END(Exchange::INetworkManager::WiFiState) + +ENUM_CONVERSION_BEGIN(Exchange::INetworkManager::WiFiSignalQuality) + { Exchange::INetworkManager::WiFiSignalQuality::WIFI_SIGNAL_DISCONNECTED, _TXT("Disconnected") }, + { Exchange::INetworkManager::WiFiSignalQuality::WIFI_SIGNAL_WEAK, _TXT("Weak") }, + { Exchange::INetworkManager::WiFiSignalQuality::WIFI_SIGNAL_FAIR, _TXT("Fair") }, + { Exchange::INetworkManager::WiFiSignalQuality::WIFI_SIGNAL_GOOD, _TXT("Good") }, + { Exchange::INetworkManager::WiFiSignalQuality::WIFI_SIGNAL_EXCELLENT, _TXT("Excellent") }, +ENUM_CONVERSION_END(Exchange::INetworkManager::WiFiSignalQuality) + +ENUM_CONVERSION_BEGIN(Exchange::INetworkManager::Logging) + { Exchange::INetworkManager::Logging::LOG_LEVEL_FATAL, _TXT("LOG_LEVEL_FATAL") }, + { Exchange::INetworkManager::Logging::LOG_LEVEL_ERROR, _TXT("LOG_LEVEL_ERROR") }, + { Exchange::INetworkManager::Logging::LOG_LEVEL_WARNING, _TXT("LOG_LEVEL_WARNING") }, + { Exchange::INetworkManager::Logging::LOG_LEVEL_INFO, _TXT("LOG_LEVEL_INFO") }, + { Exchange::INetworkManager::Logging::LOG_LEVEL_DEBUG, _TXT("LOG_LEVEL_DEBUG") }, +ENUM_CONVERSION_END(Exchange::INetworkManager::Logging) + +ENUM_CONVERSION_BEGIN(Exchange::INetworkManager::InterfaceState) + { Exchange::INetworkManager::InterfaceState::INTERFACE_ADDED, _TXT("INTERFACE_ADDED") }, + { Exchange::INetworkManager::InterfaceState::INTERFACE_LINK_UP, _TXT("INTERFACE_LINK_UP") }, + { Exchange::INetworkManager::InterfaceState::INTERFACE_LINK_DOWN, _TXT("INTERFACE_LINK_DOWN") }, + { Exchange::INetworkManager::InterfaceState::INTERFACE_ACQUIRING_IP, _TXT("INTERFACE_ACQUIRING_IP") }, + { Exchange::INetworkManager::InterfaceState::INTERFACE_REMOVED, _TXT("INTERFACE_REMOVED") }, + { Exchange::INetworkManager::InterfaceState::INTERFACE_DISABLED, _TXT("INTERFACE_DISABLED") }, +ENUM_CONVERSION_END(Exchange::INetworkManager::InterfaceState) + +ENUM_CONVERSION_BEGIN(Exchange::INetworkManager::IPStatus) + { Exchange::INetworkManager::IPStatus::IP_LOST, _TXT("LOST") }, + { Exchange::INetworkManager::IPStatus::IP_ACQUIRED, _TXT("ACQUIRED") }, +ENUM_CONVERSION_END(Exchange::INetworkManager::IPStatus) + +} diff --git a/NetworkManagerJsonRpc.cpp b/NetworkManagerJsonRpc.cpp index 06da7b6f..3c35db25 100644 --- a/NetworkManagerJsonRpc.cpp +++ b/NetworkManagerJsonRpc.cpp @@ -18,9 +18,22 @@ **/ #include "NetworkManager.h" +#include "INetworkManager.h" +#include "NetworkManagerJsonEnum.h" + +#define LOG_INPARAM() { string json; parameters.ToString(json); NMLOG_INFO("params=%s", json.c_str() ); } +#define LOG_OUTPARAM() { string json; response.ToString(json); NMLOG_INFO("response=%s", json.c_str() ); } + +#define returnJson(rc) \ + { \ + if (Core::ERROR_NONE == rc) \ + response["success"] = true; \ + else \ + response["success"] = false; \ + LOG_OUTPARAM(); \ + return Core::ERROR_NONE; \ + } -#define LOG_INPARAM() { string json; parameters.ToString(json); NMLOG_DEBUG("%s : params=%s", __FUNCTION__, json.c_str() ); } -#define LOG_OUTPARAM() { string json; response.ToString(json); NMLOG_INFO("%s : response=%s", __FUNCTION__, json.c_str() ); } using namespace NetworkManagerLogger; @@ -39,6 +52,7 @@ namespace WPEFramework */ void NetworkManager::RegisterAllMethods() { + Register("GetLogLevel", &NetworkManager::GetLogLevel, this); Register("SetLogLevel", &NetworkManager::SetLogLevel, this); Register("GetAvailableInterfaces", &NetworkManager::GetAvailableInterfaces, this); Register("GetPrimaryInterface", &NetworkManager::GetPrimaryInterface, this); @@ -118,60 +132,70 @@ namespace WPEFramework uint32_t rc = Core::ERROR_GENERAL; LogLevel level = INFO_LEVEL; - if (parameters.HasLabel("logLevel")) + if (parameters.HasLabel("level")) { - level = static_cast (parameters["logLevel"].Number()); + level = static_cast (parameters["level"].Number()); NetworkManagerLogger::SetLevel(level); - const Exchange::INetworkManager::NMLogging log = static_cast (level); + const Exchange::INetworkManager::Logging log = static_cast (level); if (_networkManager) rc = _networkManager->SetLogLevel(log); else rc = Core::ERROR_UNAVAILABLE; } - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } - uint32_t NetworkManager::GetAvailableInterfaces (const JsonObject& parameters, JsonObject& response) + uint32_t NetworkManager::GetLogLevel (const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); + uint32_t rc = Core::ERROR_NONE; + LogLevel level = INFO_LEVEL; + NetworkManagerLogger::GetLevel(level); + response["level"] = static_cast (level); + + returnJson(rc); + } + + uint32_t NetworkManager::GetAvailableInterfaces (const JsonObject& parameters, JsonObject& response) + { + LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - Exchange::INetworkManager::IInterfaceDetailsIterator* interfaces = NULL; + + Exchange::INetworkManager::IInterfaceDetailsIterator* _interfaces{}; + if (_networkManager) - rc = _networkManager->GetAvailableInterfaces(interfaces); + rc = _networkManager->GetAvailableInterfaces(_interfaces); else rc = Core::ERROR_UNAVAILABLE; - if (interfaces) + if (Core::ERROR_NONE == rc) { - NMLOG_DEBUG("received response"); - JsonArray array; - Exchange::INetworkManager::InterfaceDetails entry{}; - while (interfaces->Next(entry) == true) { - JsonObject each; - each[_T("type")] = entry.m_type; - each[_T("name")] = entry.m_name; - each[_T("mac")] = entry.m_mac; - each[_T("isEnabled")] = entry.m_isEnabled; - each[_T("isConnected")] = entry.m_isConnected; - - array.Add(JsonValue(each)); - } + if (_interfaces != nullptr) + { + JsonArray array; + Exchange::INetworkManager::InterfaceDetails entry{}; + while (_interfaces->Next(entry) == true) + { + JsonObject each; + Core::JSON::EnumType type{entry.type}; + each["type"] = type.Data(); + each["name"] = entry.name; + each["mac"] = entry.mac; + each["enabled"] = entry.enabled; + each["connected"] = entry.connected; + + array.Add(JsonValue(each)); + } - interfaces->Release(); - NMLOG_DEBUG("Sending Success"); - response["interfaces"] = array; - response["success"] = true; + _interfaces->Release(); + response["interfaces"] = array; + } } - LOG_OUTPARAM(); - return rc; + + returnJson(rc); } uint32_t NetworkManager::GetPrimaryInterface (const JsonObject& parameters, JsonObject& response) @@ -179,13 +203,8 @@ namespace WPEFramework LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; string interface; - if(m_primaryInterfaceCache.isSet()) - { - NMLOG_INFO("reading interface cached values"); - interface = m_primaryInterfaceCache.getValue(); - rc = Core::ERROR_NONE; - } - else if (_networkManager) + + if (_networkManager) rc = _networkManager->GetPrimaryInterface(interface); else rc = Core::ERROR_UNAVAILABLE; @@ -193,11 +212,8 @@ namespace WPEFramework if (Core::ERROR_NONE == rc) { response["interface"] = interface; - m_primaryInterfaceCache = interface; - response["success"] = true; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::SetPrimaryInterface (const JsonObject& parameters, JsonObject& response) @@ -217,196 +233,121 @@ namespace WPEFramework else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::SetInterfaceState(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - string interface = parameters["interface"].String(); - bool enabled = parameters["enabled"].Boolean(); - - if ("wlan0" != interface && "eth0" != interface) + if (parameters.HasLabel("interface") && parameters.HasLabel("enabled")) { - rc = Core::ERROR_BAD_REQUEST; - return rc; - } + const string interface = parameters["interface"].String(); + const bool enabled = parameters["enabled"].Boolean(); - if (_networkManager) - rc = _networkManager->SetInterfaceState(interface, enabled); + if ("wlan0" != interface && "eth0" != interface) + rc = Core::ERROR_BAD_REQUEST; + else if (_networkManager) + rc = _networkManager->SetInterfaceState(interface, enabled); + else + rc = Core::ERROR_UNAVAILABLE; + } else - rc = Core::ERROR_UNAVAILABLE; + rc = Core::ERROR_BAD_REQUEST; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::GetInterfaceState(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - bool isEnabled = false; - string interface = parameters["interface"].String(); - if ("wlan0" != interface && "eth0" != interface) + if (parameters.HasLabel("interface")) { - rc = Core::ERROR_BAD_REQUEST; - return rc; - } + const string interface = parameters["interface"].String(); + bool enabled; - if (_networkManager) - rc = _networkManager->GetInterfaceState(interface, isEnabled); - else - rc = Core::ERROR_UNAVAILABLE; + if ("wlan0" != interface && "eth0" != interface) + rc = Core::ERROR_BAD_REQUEST; + else if (_networkManager) + rc = _networkManager->SetInterfaceState(interface, enabled); + else + rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["enabled"] = isEnabled; - response["success"] = true; + if (Core::ERROR_NONE == rc) + response["enabled"] = enabled; } - LOG_OUTPARAM(); - return rc; + else + rc = Core::ERROR_BAD_REQUEST; + + returnJson(rc); } uint32_t NetworkManager::GetIPSettings (const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - string interface = ""; - string ipversion = ""; - bool isCacheLoaded = false; - Exchange::INetworkManager::IPAddressInfo result{}; - - if (parameters.HasLabel("interface")) - interface = parameters["interface"].String(); - if (parameters.HasLabel("ipversion")) - ipversion = parameters["ipversion"].String(); - - if (interface.empty() || ("wlan0" != interface && "eth0" != interface)) - { - if(!interface.empty()) { - NMLOG_WARNING("interface is neither wlan0 nor eth0: %s", interface.c_str()); - return Core::ERROR_BAD_REQUEST; - } + Exchange::INetworkManager::IPAddress address{}; - interface = m_primaryInterfaceCache.getValue(); - } - - if(m_primaryInterfaceCache.isSet() && (interface == m_primaryInterfaceCache.getValue())) - { - /* If ipversion is empty, IPv4 will be taken as the default version */ - if(m_ipv4AddressCache.isSet() && (ipversion.empty() || strcasecmp(ipversion.c_str(), "IPv4") == 0)) - { - NMLOG_INFO("reading ipv4 settings cached values"); - result = m_ipv4AddressCache.getValue(); - rc = Core::ERROR_NONE; - isCacheLoaded = true; - } - else if(m_ipv6AddressCache.isSet() && (ipversion.empty() || strcasecmp(ipversion.c_str(), "IPv6") == 0)) - { - NMLOG_INFO("reading ipv6 settings cached values"); - result = m_ipv6AddressCache.getValue(); - rc = Core::ERROR_NONE; - isCacheLoaded = true; - } - } + string interface = parameters["interface"].String(); + string ipversion = parameters["ipversion"].String(); - if (!isCacheLoaded) - { - if (_networkManager) - { - rc = _networkManager->GetIPSettings(interface, ipversion, result); - /* The value will be cached only for the primary interface IP address. */ - if(Core::ERROR_NONE == rc && m_primaryInterfaceCache.isSet() && (interface == m_primaryInterfaceCache.getValue())) - { - NMLOG_DEBUG("caching the ip address values"); - if (strcasecmp(result.m_ipAddrType.c_str(), "IPv4") == 0) - m_ipv4AddressCache = result; - else if (strcasecmp(result.m_ipAddrType.c_str(), "IPv6") == 0) - m_ipv6AddressCache = result; - } - } - else - { - NMLOG_ERROR("_networkManager == null"); - rc = Core::ERROR_UNAVAILABLE; - } - } + if (_networkManager) + rc = _networkManager->GetIPSettings(interface, ipversion, address); + else + rc = Core::ERROR_UNAVAILABLE; if (Core::ERROR_NONE == rc) { - response["interface"] = interface; - - if (strcasecmp (result.m_ipAddrType.c_str(), "IPv4") == 0) - result.m_ipAddrType = "IPv4"; - else if (strcasecmp (result.m_ipAddrType.c_str(), "IPv6") == 0) - result.m_ipAddrType = "IPv6"; - response["ipversion"] = result.m_ipAddrType; - response["autoconfig"] = result.m_autoConfig; - response["ipaddress"] = result.m_ipAddress; - response["prefix"] = result.m_prefix; - response["gateway"] = result.m_gateway; - response["dhcpserver"] = result.m_dhcpServer; - if(!result.m_v6LinkLocal.empty()) - response["v6LinkLocal"] = result.m_v6LinkLocal; - response["primarydns"] = result.m_primaryDns; - response["secondarydns"] = result.m_secondaryDns; - response["success"] = true; + response["interface"] = interface; + response["ipversion"] = address.ipversion; + response["autoconfig"] = address.autoconfig; + response["ipaddress"] = address.ipaddress; + response["prefix"] = address.prefix; + response["ula"] = address.ula; + response["dhcpserver"] = address.dhcpserver; + response["gateway"] = address.gateway; + response["primarydns"] = address.primarydns; + response["secondarydns"] = address.secondarydns; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::SetIPSettings(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - Exchange::INetworkManager::IPAddressInfo result{}; + Exchange::INetworkManager::IPAddress address{}; + string interface = ""; string ipversion = ""; if (parameters.HasLabel("interface")) interface = parameters["interface"].String(); - if (parameters.HasLabel("ipversion")) - ipversion = parameters["ipversion"].String(); - - if ("wlan0" != interface && "eth0" != interface) + else { rc = Core::ERROR_BAD_REQUEST; return rc; } - result.m_autoConfig = parameters["autoconfig"].Boolean(); - if (!result.m_autoConfig) + address.autoconfig = parameters["autoconfig"].Boolean(); + if (!address.autoconfig) { - result.m_ipAddress = parameters["ipaddress"]; - result.m_prefix = parameters["prefix"].Number(); - result.m_gateway = parameters["gateway"]; - result.m_primaryDns = parameters["primarydns"]; - result.m_secondaryDns = parameters["secondarydns"]; + address.ipaddress = parameters["ipaddress"].String(); + address.ipversion = parameters["ipversion"].String(); + address.prefix = parameters["prefix"].Number(); + address.gateway = parameters["gateway"].String(); + address.primarydns = parameters["primarydns"].String(); + address.secondarydns = parameters["secondarydns"].String(); } if (_networkManager) - rc = _networkManager->SetIPSettings(interface, ipversion, result); + rc = _networkManager->SetIPSettings(interface, address); else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::GetStunEndpoint(const JsonObject& parameters, JsonObject& response) @@ -415,46 +356,39 @@ namespace WPEFramework uint32_t rc = Core::ERROR_GENERAL; string endPoint; uint32_t port; - uint32_t bindTimeout; - uint32_t cacheTimeout; + uint32_t timeout; + uint32_t cacheLifetime; if (_networkManager) - rc = _networkManager->GetStunEndpoint(endPoint, port, bindTimeout, cacheTimeout); + rc = _networkManager->GetStunEndpoint(endPoint, port, timeout, cacheLifetime); else rc = Core::ERROR_UNAVAILABLE; if (Core::ERROR_NONE == rc) { - response["endPoint"] = endPoint; + response["endpoint"] = endPoint; response["port"] = port; - response["bindTimeout"] = bindTimeout; - response["cacheTimeout"] = cacheTimeout; - response["success"] = true; + response["timeout"] = timeout; + response["cacheLifetime"] = cacheLifetime; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::SetStunEndpoint(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - string endPoint = parameters["endPoint"].String(); + string endPoint = parameters["endpoint"].String(); uint32_t port = parameters["port"].Number(); - uint32_t bindTimeout = parameters["bindTimeout"].Number(); - uint32_t cacheTimeout = parameters["cacheTimeout"].Number(); + uint32_t bindTimeout = parameters["timeout"].Number(); + uint32_t cacheTimeout = parameters["cacheLifetime"].Number(); if (_networkManager) rc = _networkManager->SetStunEndpoint(endPoint, port, bindTimeout, cacheTimeout); else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::GetConnectivityTestEndpoints(const JsonObject& parameters, JsonObject& response) @@ -462,7 +396,6 @@ namespace WPEFramework LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; Exchange::INetworkManager::IStringIterator* endpoints = NULL; - if (_networkManager) rc = _networkManager->GetConnectivityTestEndpoints(endpoints); @@ -474,18 +407,14 @@ namespace WPEFramework if (endpoints) { JsonArray array; - string endPoint{}; - while (endpoints->Next(endPoint) == true) - { - array.Add(endPoint); - } + string entry{}; + while (endpoints->Next(entry) == true) { array.Add(entry); } + endpoints->Release(); response["endpoints"] = array; - response["success"] = true; } } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::SetConnectivityTestEndpoints(const JsonObject& parameters, JsonObject& response) @@ -498,7 +427,7 @@ namespace WPEFramework if (0 == array.Length() || 5 < array.Length()) { NMLOG_DEBUG("minimum of 1 to maximum of 5 Urls are allowed"); - return rc; + returnJson(rc); } std::vector endpoints; @@ -512,7 +441,7 @@ namespace WPEFramework else { NMLOG_DEBUG("Unexpected variant type"); - return rc; + returnJson(rc); } } endpointsIter = (Core::Service::Create(endpoints)); @@ -522,16 +451,10 @@ namespace WPEFramework else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - if (endpointsIter) endpointsIter->Release(); - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::IsConnectedToInternet(const JsonObject& parameters, JsonObject& response) @@ -549,49 +472,29 @@ namespace WPEFramework if (Core::ERROR_NONE == rc) { - response["isConnectedToInternet"] = (Exchange::INetworkManager::InternetStatus::INTERNET_FULLY_CONNECTED == result); - response["internetState"] = static_cast (result); - switch (result) - { - case Exchange::INetworkManager::InternetStatus::INTERNET_LIMITED: - response["status"] = string("LIMITED_INTERNET"); - break; - case Exchange::INetworkManager::InternetStatus::INTERNET_CAPTIVE_PORTAL: - response["status"] = string("CAPTIVE_PORTAL"); - break; - case Exchange::INetworkManager::InternetStatus::INTERNET_FULLY_CONNECTED: - response["status"] = string("FULLY_CONNECTED"); - // when fully connected to internet set Network subsystem - //setInternetSubsystem(); - break; - default: - response["status"] = string("NO_INTERNET"); - break; - } - - response["success"] = true; + Core::JSON::EnumType status(result); + response["ipversion"] = ipversion; + response["connected"] = (Exchange::INetworkManager::InternetStatus::INTERNET_FULLY_CONNECTED == result); + response["state"] = JsonValue(status); + response["status"] = status.Data(); } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::GetCaptivePortalURI(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - string endPoint; + string uri; if (_networkManager) - rc = _networkManager->GetCaptivePortalURI(endPoint); + rc = _networkManager->GetCaptivePortalURI(uri); else rc = Core::ERROR_UNAVAILABLE; if (Core::ERROR_NONE == rc) - { - response["uri"] = endPoint; - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + response["uri"] = uri; + + returnJson(rc); } uint32_t NetworkManager::StartConnectivityMonitoring(const JsonObject& parameters, JsonObject& response) @@ -606,12 +509,7 @@ namespace WPEFramework else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::StopConnectivityMonitoring(const JsonObject& parameters, JsonObject& response) @@ -624,12 +522,7 @@ namespace WPEFramework else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::GetPublicIP(const JsonObject& parameters, JsonObject& response) @@ -656,16 +549,14 @@ namespace WPEFramework if (Core::ERROR_NONE == rc) { - response["publicIP"] = ipAddress; + response["ipaddress"] = ipAddress; response["ipversion"] = ipversion; - response["success"] = true; m_publicIPAddress = ipAddress; m_publicIPAddressType = ipversion; PublishToThunderAboutInternet(); } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } void NetworkManager::PublishToThunderAboutInternet() @@ -699,11 +590,11 @@ namespace WPEFramework { LOG_INPARAM(); string result{}; + string endpoint{}; uint32_t rc = Core::ERROR_GENERAL; LOG_INPARAM(); if (parameters.HasLabel("endpoint")) { - string endpoint{}; string guid{}; string ipversion{"IPv4"}; uint32_t noOfRequest = 3; @@ -714,8 +605,8 @@ namespace WPEFramework if (parameters.HasLabel("ipversion")) ipversion = parameters["ipversion"].String(); - if (parameters.HasLabel("noOfRequest")) - noOfRequest = parameters["noOfRequest"].Number(); + if (parameters.HasLabel("count")) + noOfRequest = parameters["count"].Number(); if (parameters.HasLabel("timeout")) timeOutInSeconds = parameters["timeout"].Number(); @@ -735,8 +626,7 @@ namespace WPEFramework reply.FromString(result); response = reply; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::Trace(const JsonObject& parameters, JsonObject& response) @@ -744,44 +634,42 @@ namespace WPEFramework LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; string result{}; - const string ipversion = parameters["ipversion"].String(); - const string endpoint = parameters["endpoint"].String(); - const uint32_t noOfRequest = parameters["packets"].Number(); - const string guid = parameters["guid"].String(); + + if (parameters.HasLabel("endpoint")) + { + const string ipversion = parameters["ipversion"].String(); + const string endpoint = parameters["endpoint"].String(); + const uint32_t noOfRequest = parameters["packets"].Number(); + const string guid = parameters["guid"].String(); - if (_networkManager) - rc = _networkManager->Trace(ipversion, endpoint, noOfRequest, guid, result); - else - rc = Core::ERROR_UNAVAILABLE; + if (_networkManager) + rc = _networkManager->Trace(ipversion, endpoint, noOfRequest, guid, result); + else + rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - JsonObject reply; - reply.FromString(result); - reply["success"] = true; - response = reply; + if (Core::ERROR_NONE == rc) + { + JsonObject reply; + reply.FromString(result); + response = reply; + } } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::StartWiFiScan(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - const Exchange::INetworkManager::WiFiFrequency frequency = static_cast (parameters["frequency"].Number()); + string frequency = parameters["frequency"].String(); + Exchange::INetworkManager::IStringIterator* ssids = NULL; if (_networkManager) - rc = _networkManager->StartWiFiScan(frequency); + rc = _networkManager->StartWiFiScan(frequency, ssids); else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::StopWiFiScan(const JsonObject& parameters, JsonObject& response) @@ -794,12 +682,7 @@ namespace WPEFramework else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::GetKnownSSIDs(const JsonObject& parameters, JsonObject& response) @@ -807,7 +690,6 @@ namespace WPEFramework LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - JsonArray ssids; ::WPEFramework::RPC::IIteratorType* _ssids{}; if (_networkManager) @@ -815,35 +697,30 @@ namespace WPEFramework if (Core::ERROR_NONE == rc) { - ASSERT(_ssids != nullptr); - if (_ssids != nullptr) { + JsonArray ssids; string _resultItem_{}; - while (_ssids->Next(_resultItem_) == true) - { - ssids.Add() = _resultItem_; - } + while (_ssids->Next(_resultItem_) == true) { ssids.Add() = _resultItem_; } _ssids->Release(); + + response["ssids"] = ssids; } - response["ssids"] = ssids; - response["success"] = true; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::AddToKnownSSIDs(const JsonObject& parameters, JsonObject& response) { - LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; Exchange::INetworkManager::WiFiConnectTo ssid{}; + NMLOG_INFO("Entry to %s\n", __FUNCTION__); if (parameters.HasLabel("ssid") && parameters.HasLabel("passphrase")) { - ssid.m_ssid = parameters["ssid"].String(); - ssid.m_passphrase = parameters["passphrase"].String(); - ssid.m_securityMode = static_cast (parameters["securityMode"].Number()); + ssid.ssid = parameters["ssid"].String(); + ssid.passphrase = parameters["passphrase"].String(); + ssid.security = static_cast (parameters["security"].Number()); if (_networkManager) rc = _networkManager->AddToKnownSSIDs(ssid); @@ -851,12 +728,7 @@ namespace WPEFramework rc = Core::ERROR_UNAVAILABLE; } - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::RemoveKnownSSID(const JsonObject& parameters, JsonObject& response) @@ -873,53 +745,53 @@ namespace WPEFramework else rc = Core::ERROR_UNAVAILABLE; } + else + rc = Core::ERROR_BAD_REQUEST; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::WiFiConnect(const JsonObject& parameters, JsonObject& response) { - LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; Exchange::INetworkManager::WiFiConnectTo ssid{}; + NMLOG_INFO("Entry to %s\n", __FUNCTION__); if (parameters.HasLabel("ssid")) - ssid.m_ssid = parameters["ssid"].String(); + ssid.ssid = parameters["ssid"].String(); + else + returnJson(rc); + if (parameters.HasLabel("passphrase")) - ssid.m_passphrase = parameters["passphrase"].String(); - if (parameters.HasLabel("securityMode")) - ssid.m_securityMode = static_cast (parameters["securityMode"].Number()); - //TODO Check Security modes - if (parameters.HasLabel("identity")) - ssid.m_identity = parameters["identity"].String(); - if (parameters.HasLabel("caCert")) - ssid.m_caCert = parameters["caCert"].String(); - if (parameters.HasLabel("clientCert")) - ssid.m_clientCert = parameters["clientCert"].String(); - if (parameters.HasLabel("privateKey")) - ssid.m_privateKey = parameters["privateKey"].String(); - if (parameters.HasLabel("privateKeyPasswd")) - ssid.m_privateKeyPasswd = parameters["privateKeyPasswd"].String(); - if (parameters.HasLabel("persistSSIDInfo")) - ssid.m_persistSSIDInfo = parameters["persistSSIDInfo"].Boolean(); + ssid.passphrase = parameters["passphrase"].String(); + + if (parameters.HasLabel("security")) + ssid.security= static_cast (parameters["security"].Number()); + + // Check Security modes + if (parameters.HasLabel("eap")) + ssid.eap = parameters["eap"].String(); + if (parameters.HasLabel("eap_identity")) + ssid.eap_identity = parameters["eap_identity"].String(); + if (parameters.HasLabel("ca_cert")) + ssid.ca_cert = parameters["ca_cert"].String(); + if (parameters.HasLabel("client_cert")) + ssid.client_cert = parameters["client_cert"].String(); + if (parameters.HasLabel("private_key")) + ssid.private_key = parameters["private_key"].String(); + if (parameters.HasLabel("private_key_passwd")) + ssid.private_key_passwd = parameters["private_key_passwd"].String(); + if (parameters.HasLabel("persist")) + ssid.persist = parameters["persist"].Boolean(); else - ssid.m_persistSSIDInfo = true; + ssid.persist = true; + if (_networkManager) rc = _networkManager->WiFiConnect(ssid); else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::WiFiDisconnect(const JsonObject& parameters, JsonObject& response) @@ -932,12 +804,7 @@ namespace WPEFramework else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::GetConnectedSSID(const JsonObject& parameters, JsonObject& response) @@ -953,17 +820,15 @@ namespace WPEFramework if (Core::ERROR_NONE == rc) { - response["ssid"] = ssidInfo.m_ssid; - response["bssid"] = ssidInfo.m_bssid; - response["securityMode"] = static_cast (ssidInfo.m_securityMode); - response["signalStrength"] = ssidInfo.m_signalStrength; - response["frequency"] = ssidInfo.m_frequency; - response["rate"] = ssidInfo.m_rate; - response["noise"] = ssidInfo.m_noise; - response["success"] = true; + response["ssid"] = ssidInfo.ssid; + response["bssid"] = ssidInfo.bssid; + response["security"] = JsonValue(ssidInfo.security); + response["strength"] = ssidInfo.strength; + response["frequency"] = ssidInfo.frequency; + response["rate"] = ssidInfo.rate; + response["noise"] = ssidInfo.noise; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::StartWPS(const JsonObject& parameters, JsonObject& response) @@ -971,18 +836,19 @@ namespace WPEFramework LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; string wps_pin{}; - Exchange::INetworkManager::WiFiWPS method; + Core::JSON::EnumType method; if (parameters.HasLabel("method")) { - method = static_cast (parameters["method"].Number()); - } - else - method = Exchange::INetworkManager::WIFI_WPS_PBC; + if (parameters["method"].Content() == WPEFramework::Core::JSON::Variant::type::STRING) + method.FromString(parameters["method"].String()); + else if (parameters["method"].Content() == WPEFramework::Core::JSON::Variant::type::NUMBER) + method = static_cast (parameters["method"].Number()); - if ((Exchange::INetworkManager::WIFI_WPS_PIN == method) && parameters.HasLabel("wps_pin")) - { - wps_pin = parameters["wps_pin"].String(); + if ((Exchange::INetworkManager::WIFI_WPS_PIN == method) && parameters.HasLabel("pin")) + { + wps_pin = parameters["pin"].String(); + } } if (_networkManager) @@ -990,12 +856,7 @@ namespace WPEFramework else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::StopWPS(const JsonObject& parameters, JsonObject& response) @@ -1008,12 +869,7 @@ namespace WPEFramework else rc = Core::ERROR_UNAVAILABLE; - if (Core::ERROR_NONE == rc) - { - response["success"] = true; - } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::GetWifiState(const JsonObject& parameters, JsonObject& response) @@ -1026,14 +882,15 @@ namespace WPEFramework rc = _networkManager->GetWifiState(state); else rc = Core::ERROR_UNAVAILABLE; + if (Core::ERROR_NONE == rc) { - response["state"] = static_cast (state); - m_wifiStateCache = state; - response["success"] = true; + Core::JSON::EnumType iState{state}; + response["state"] = JsonValue(state); + response["status"] = iState.Data(); } - LOG_OUTPARAM(); - return rc; + + returnJson(rc); } uint32_t NetworkManager::GetWiFiSignalStrength(const JsonObject& parameters, JsonObject& response) @@ -1042,7 +899,7 @@ namespace WPEFramework uint32_t rc = Core::ERROR_GENERAL; string ssid{}; string signalStrength{}; - Exchange::INetworkManager::WiFiSignalQuality quality; + Exchange::INetworkManager::WiFiSignalQuality quality{}; if (_networkManager) rc = _networkManager->GetWiFiSignalStrength(ssid, signalStrength, quality); @@ -1051,13 +908,12 @@ namespace WPEFramework if (Core::ERROR_NONE == rc) { + Core::JSON::EnumType iquality(quality); response["ssid"] = ssid; - response["signalStrength"] = signalStrength; - response["quality"] = static_cast (quality); - response["success"] = true; + response["strength"] = signalStrength; + response["quality"] = iquality.Data(); } - LOG_OUTPARAM(); - return rc; + returnJson(rc); } uint32_t NetworkManager::GetSupportedSecurityModes(const JsonObject& parameters, JsonObject& response) @@ -1079,14 +935,95 @@ namespace WPEFramework Exchange::INetworkManager::WIFISecurityModeInfo _resultItem_{}; while (securityModes->Next(_resultItem_) == true) { - response.Set(_resultItem_.m_securityModeText.c_str(), JsonValue(_resultItem_.m_securityMode)); + response.Set(_resultItem_.securityName.c_str(), JsonValue(_resultItem_.security)); } securityModes->Release(); } - response["success"] = true; } - LOG_OUTPARAM(); - return rc; + returnJson(rc); + } + + void NetworkManager::onInterfaceStateChange(const Exchange::INetworkManager::InterfaceState state, const string interface) + { + Core::JSON::EnumType iState{state}; + JsonObject parameters; + parameters["state"] = JsonValue(state); + parameters["status"] = iState.Data(); + parameters["interface"] = interface; + + LOG_INPARAM(); + Notify(_T("onInterfaceStateChange"), parameters); + } + + void NetworkManager::onActiveInterfaceChange(const string prevActiveInterface, const string currentActiveinterface) + { + JsonObject parameters; + parameters["prevActiveInterface"] = prevActiveInterface; + parameters["currentActiveInterface"] = currentActiveinterface; + + LOG_INPARAM(); + Notify(_T("onActiveInterfaceChange"), parameters); + } + + void NetworkManager::onIPAddressChange(const string interface, const string ipversion, const string ipaddress, const Exchange::INetworkManager::IPStatus status) + { + Core::JSON::EnumType iStatus{status}; + JsonObject parameters; + parameters["interface"] = interface; + parameters["ipversion"] = ipversion; + parameters["ipaddress"] = ipaddress; + parameters["status"] = iStatus.Data(); + + LOG_INPARAM(); + Notify(_T("onIPAddressChange"), parameters); + } + + void NetworkManager::onInternetStatusChange(const Exchange::INetworkManager::InternetStatus prevState, const Exchange::INetworkManager::InternetStatus currState) + { + JsonObject parameters; + Core::JSON::EnumType prevStatus(prevState); + Core::JSON::EnumType currStatus(currState); + parameters["prevState"] = JsonValue(prevState); + parameters["prevStatus"] = prevStatus.Data(); + parameters["state"] = JsonValue(currState); + parameters["status"] = currStatus.Data(); + + LOG_INPARAM(); + Notify(_T("onInternetStatusChange"), parameters); + } + + void NetworkManager::onAvailableSSIDs(const string jsonOfScanResults) + { + JsonObject parameters; + JsonArray scanResults; + scanResults.FromString(jsonOfScanResults); + parameters["ssids"] = scanResults; + + LOG_INPARAM(); + Notify(_T("onAvailableSSIDs"), parameters); + } + + void NetworkManager::onWiFiStateChange(const Exchange::INetworkManager::WiFiState state) + { + JsonObject parameters; + Core::JSON::EnumType iState{state}; + parameters["state"] = JsonValue(state); + parameters["status"] = iState.Data(); + + LOG_INPARAM(); + Notify(_T("onWiFiStateChange"), parameters); + } + + void NetworkManager::onWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality) + { + Core::JSON::EnumType iquality(quality); + JsonObject parameters; + parameters["ssid"] = ssid; + parameters["strength"] = strength; + parameters["quality"] = iquality.Data(); + + LOG_INPARAM(); + Notify(_T("onWiFiSignalStrengthChange"), parameters); } } } diff --git a/NetworkManagerLogger.cpp b/NetworkManagerLogger.cpp index faeab4bf..313fdcbc 100644 --- a/NetworkManagerLogger.cpp +++ b/NetworkManagerLogger.cpp @@ -63,6 +63,18 @@ namespace NetworkManagerLogger { } #endif + const char* trimPath(const char* s) + { + if (!s) + return s; + + const char* t = strrchr(s, (int) '/'); + if (t) t++; + if (!t) t = s; + + return t; + } + const char* methodName(const std::string& prettyFunction) { size_t colons = prettyFunction.find("::"); @@ -104,6 +116,7 @@ namespace NetworkManagerLogger { const char* levelMap[] = {"Fatal", "Error", "Warn", "Info", "Debug"}; struct timeval tv; struct tm* lt; + const char* fileName = trimPath(file); if (gDefaultLogLevel < level) return; @@ -111,7 +124,7 @@ namespace NetworkManagerLogger { gettimeofday(&tv, NULL); lt = localtime(&tv.tv_sec); - printf("%.2d:%.2d:%.2d.%.6lld [%-5s] [PID=%d] [TID=%d] %s : %s\n", lt->tm_hour, lt->tm_min, lt->tm_sec, (long long int)tv.tv_usec, levelMap[level], getpid(), gettid(), func, formattedLog); + printf("%.2d:%.2d:%.2d.%.6lld [%-5s] [PID=%d] [TID=%d] [%s +%d] %s : %s\n", lt->tm_hour, lt->tm_min, lt->tm_sec, (long long int)tv.tv_usec, levelMap[level], getpid(), gettid(), fileName, line, func, formattedLog); fflush(stdout); #endif } @@ -124,4 +137,14 @@ namespace NetworkManagerLogger { // TODO : Inform RDKLogger to change the log level #endif } + + void GetLevel(LogLevel& level) + { + level = gDefaultLogLevel; + NMLOG_INFO("NetworkManager logLevel:%d", level); +#ifdef USE_RDK_LOGGER + // TODO : Inform RDKLogger to change the log level +#endif + } + } // namespace NetworkManagerLogger diff --git a/NetworkManagerLogger.h b/NetworkManagerLogger.h index 65014d72..e7bc5e0b 100644 --- a/NetworkManagerLogger.h +++ b/NetworkManagerLogger.h @@ -47,6 +47,11 @@ void Init(); */ void SetLevel(LogLevel level); +/** + * @brief To set log level while runtime + */ +void GetLevel(LogLevel& level); + /** * @brief Log a message * The function is defined by logging backend. @@ -61,6 +66,8 @@ void logPrint(LogLevel level, const char* file, const char* func, int line, cons #define NMLOG_ERROR(FMT, ...) logPrint(NetworkManagerLogger::ERROR_LEVEL, __FILE__, __func__, __LINE__, FMT, ##__VA_ARGS__) #define NMLOG_FATAL(FMT, ...) logPrint(NetworkManagerLogger::FATAL_LEVEL, __FILE__,__func__, __LINE__, FMT, ##__VA_ARGS__) +#define LOG_ENTRY_FUNCTION() { NMLOG_DEBUG("Entering"); } + } // namespace NetworkManagerLogger #endif // NM_LOGGER_H diff --git a/NetworkManagerPlugin.json b/NetworkManagerPlugin.json deleted file mode 100644 index 388367f4..00000000 --- a/NetworkManagerPlugin.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/rdkcentral/rdkservices/main/Tools/json_generator/schemas/plugin.schema.json", - "info": { - "title": "NetworkManager Plugin", - "class": "NetworkManager", - "callsign": "org.rdk.NetworkManager", - "locator": "libWPEFrameworkNetworkManager.so", - "status": "production", - "description": "A Unified `NetworkManager` plugin that allows you to manage Ethernet and Wifi interfaces on the device.", - "version": "0.1.0" - }, - "interface": { - "$ref": "NetworkManager.json#" - } -} diff --git a/NetworkManagerRDKProxy.cpp b/NetworkManagerRDKProxy.cpp index 67052cdc..77588a87 100644 --- a/NetworkManagerRDKProxy.cpp +++ b/NetworkManagerRDKProxy.cpp @@ -353,7 +353,6 @@ typedef struct _IARM_Bus_WiFiSrvMgr_SsidList_Param_t { #define IARM_BUS_WIFI_MGR_API_disconnectSSID "disconnectSSID" /**< Disconnect from current SSID */ #define IARM_BUS_WIFI_MGR_API_getCurrentState "getCurrentState" /**< Retrieve current state */ - namespace WPEFramework { namespace Plugin @@ -435,9 +434,9 @@ namespace WPEFramework if(interface == "eth0" || interface == "wlan0") { if (e->status) - ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_ADDED, interface); + ::_instance->ReportInterfaceStateChange(Exchange::INetworkManager::INTERFACE_ADDED, interface); else - ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_REMOVED, interface); + ::_instance->ReportInterfaceStateChange(Exchange::INetworkManager::INTERFACE_REMOVED, interface); } break; } @@ -448,9 +447,9 @@ namespace WPEFramework NMLOG_INFO ("IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS :: %s", interface.c_str()); if(interface == "eth0" || interface == "wlan0") { if (e->status) - ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_LINK_UP, interface); + ::_instance->ReportInterfaceStateChange(Exchange::INetworkManager::INTERFACE_LINK_UP, interface); else - ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_LINK_DOWN, interface); + ::_instance->ReportInterfaceStateChange(Exchange::INetworkManager::INTERFACE_LINK_DOWN, interface); } break; } @@ -461,7 +460,15 @@ namespace WPEFramework NMLOG_INFO ("IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS :: %s -- %s", interface.c_str(), e->ip_address); if(interface == "eth0" || interface == "wlan0") { - ::_instance->ReportIPAddressChangedEvent(interface, e->acquired, e->is_ipv6, string(e->ip_address)); + string ipversion("IPv4"); + Exchange::INetworkManager::IPStatus status; + + if (e->is_ipv6) + ipversion = "IPv6"; + if (e->acquired) + status = Exchange::INetworkManager::IP_ACQUIRED; + + ::_instance->ReportIPAddressChange(interface, ipversion, string(e->ip_address), status); } break; } @@ -478,7 +485,7 @@ namespace WPEFramework if(newInterface != "eth0" || newInterface != "wlan0") newInterface == ""; /* assigning "null" if the interface is not eth0 or wlan0 */ - ::_instance->ReportActiveInterfaceChangedEvent(oldInterface, newInterface); + ::_instance->ReportActiveInterfaceChange(oldInterface, newInterface); break; } case IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDs: @@ -501,7 +508,8 @@ namespace WPEFramework string json; ssids.ToString(json); - ::_instance->ReportAvailableSSIDsEvent(json); + ::_instance->ReportAvailableSSIDs(json); + break; } case IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged: { @@ -509,7 +517,7 @@ namespace WPEFramework Exchange::INetworkManager::WiFiState state = Exchange::INetworkManager::WIFI_STATE_DISCONNECTED; NMLOG_INFO("Event IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged received; state=%d", e->data.wifiStateChange.state); state = to_wifi_state(e->data.wifiStateChange.state); - ::_instance->ReportWiFiStateChangedEvent(state); + ::_instance->ReportWiFiStateChange(state); break; } case IARM_BUS_WIFI_MGR_EVENT_onError: @@ -517,7 +525,7 @@ namespace WPEFramework IARM_BUS_WiFiSrvMgr_EventData_t* e = (IARM_BUS_WiFiSrvMgr_EventData_t *) data; Exchange::INetworkManager::WiFiState state = errorcode_to_wifi_state(e->data.wifiError.code); NMLOG_INFO("Event IARM_BUS_WIFI_MGR_EVENT_onError received; code=%d", e->data.wifiError.code); - ::_instance->ReportWiFiStateChangedEvent(state); + ::_instance->ReportWiFiStateChange(state); break; } default: @@ -636,14 +644,14 @@ namespace WPEFramework InterfaceDetails tmp; /* Update the interface as per RDK NetSrvMgr */ if ("eth0" == interfaceName) - tmp.m_type = string("ETHERNET"); + tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_ETHERNET; else if ("wlan0" == interfaceName) - tmp.m_type = string("WIFI"); + tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_WIFI; - tmp.m_name = interfaceName; - tmp.m_mac = string(list.interfaces[i].mac); - tmp.m_isEnabled = ((list.interfaces[i].flags & IFF_UP) != 0); - tmp.m_isConnected = ((list.interfaces[i].flags & IFF_RUNNING) != 0); + 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); interfaceList.push_back(tmp); } } @@ -711,7 +719,7 @@ namespace WPEFramework return rc; } - uint32_t NetworkManagerImplementation::SetInterfaceState(const string& interface/* @in */, const bool& enable /* @in */) + uint32_t NetworkManagerImplementation::SetInterfaceState(const string& interface/* @in */, const bool enable /* @in */) { LOG_ENTRY_FUNCTION(); uint32_t rc = Core::ERROR_RPC_CALL_FAILED; @@ -804,7 +812,7 @@ namespace WPEFramework /* @brief Get IP Address Of the Interface */ - uint32_t NetworkManagerImplementation::GetIPSettings(const string& interface /* @in */, const string& ipversion /* @in */, IPAddressInfo& result /* @out */) + uint32_t NetworkManagerImplementation::GetIPSettings(string& interface /* @inout */, const string &ipversion /* @in */, IPAddress& address /* @out */) { LOG_ENTRY_FUNCTION(); uint32_t rc = Core::ERROR_RPC_CALL_FAILED; @@ -815,24 +823,39 @@ namespace WPEFramework strncpy(iarmData.interface, "WIFI", INTERFACE_SIZE); else if ("eth0" == interface) strncpy(iarmData.interface, "ETHERNET", INTERFACE_SIZE); + else if (!interface.empty()) + { + NMLOG_ERROR("Given interface (%s) is NOT supported\n", interface.c_str()); + return Core::ERROR_NOT_SUPPORTED; + } + + if (("IPv4" == ipversion) || ("IPv6" == ipversion)) + sprintf(iarmData.ipversion,"%s", ipversion.c_str()); - strncpy(iarmData.ipversion, ipversion.c_str(), 16); iarmData.isSupported = true; if (IARM_RESULT_SUCCESS == IARM_Bus_Call (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_getIPSettings, (void *)&iarmData, sizeof(iarmData))) { - result.m_ipAddrType = string(iarmData.ipversion); - result.m_autoConfig = iarmData.autoconfig; - result.m_dhcpServer = string(iarmData.dhcpserver,MAX_IP_ADDRESS_LEN - 1); - result.m_v6LinkLocal = ""; - result.m_ipAddress = string(iarmData.ipaddress,MAX_IP_ADDRESS_LEN - 1); + address.autoconfig = iarmData.autoconfig; + address.dhcpserver = string(iarmData.dhcpserver,MAX_IP_ADDRESS_LEN - 1); + address.ula = string(""); + address.ipaddress = string(iarmData.ipaddress,MAX_IP_ADDRESS_LEN - 1); + address.gateway = string(iarmData.gateway,MAX_IP_ADDRESS_LEN - 1); + address.primarydns = string(iarmData.primarydns,MAX_IP_ADDRESS_LEN - 1); + address.secondarydns = string(iarmData.secondarydns,MAX_IP_ADDRESS_LEN - 1); if (0 == strcasecmp("ipv4", iarmData.ipversion)) - result.m_prefix = NetmaskToPrefix(iarmData.netmask); + { + address.ipversion = string ("IPv4"); + address.prefix = NetmaskToPrefix(iarmData.netmask); + } else if (0 == strcasecmp("ipv6", iarmData.ipversion)) - result.m_prefix = std::atoi(iarmData.netmask); - result.m_gateway = string(iarmData.gateway,MAX_IP_ADDRESS_LEN - 1); - result.m_primaryDns = string(iarmData.primarydns,MAX_IP_ADDRESS_LEN - 1); - result.m_secondaryDns = string(iarmData.secondarydns,MAX_IP_ADDRESS_LEN - 1); + { + address.ipversion = string ("IPv6"); + address.prefix = std::atoi(iarmData.netmask); + } + + /* Return the default interface information */ + interface = string(interface); rc = Core::ERROR_NONE; } else @@ -843,8 +866,8 @@ namespace WPEFramework return rc; } -#define CIDR_NETMASK_IP_LEN 32 -const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { +const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { + "0.0.0.0", "128.0.0.0", "192.0.0.0", "224.0.0.0", @@ -880,10 +903,10 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { }; /* @brief Set IP Address Of the Interface */ - uint32_t NetworkManagerImplementation::SetIPSettings(const string& interface /* @in */, const string &ipversion /* @in */, const IPAddressInfo& address /* @in */) + uint32_t NetworkManagerImplementation::SetIPSettings(const string& interface /* @in */, const IPAddress& address /* @in */) { uint32_t rc = Core::ERROR_NONE; - if (0 == strcasecmp("ipv4", ipversion.c_str())) + if ("IPv4" == address.ipversion) { IARM_BUS_NetSrvMgr_Iface_Settings_t iarmData = {0}; /* Netsrvmgr returns eth0 & wlan0 as primary interface but when we want to set., we must set ETHERNET or WIFI*/ @@ -897,27 +920,28 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { rc = Core::ERROR_BAD_REQUEST; return rc; } + /* IP version */ - strncpy(iarmData.ipversion, ipversion.c_str(), 16); + sprintf(iarmData.ipversion, "IPv4"); - if (!address.m_autoConfig) + if (!address.autoconfig) { //Lets validate the prefix Address - if (address.m_prefix >= 32) + if (address.prefix > CIDR_NETMASK_IP_LEN) { rc = Core::ERROR_BAD_REQUEST; } else { - string netmask = CIDR_PREFIXES[address.m_prefix]; + string netmask = CIDR_PREFIXES[address.prefix]; //Lets validate the IP Address struct in_addr tmpIPAddress, tmpGWAddress, tmpNetmask; struct in_addr bcastAddr1, bcastAddr2; - if (inet_pton(AF_INET, address.m_ipAddress.c_str(), &tmpIPAddress) == 1 && + if (inet_pton(AF_INET, address.ipaddress.c_str(), &tmpIPAddress) == 1 && inet_pton(AF_INET, netmask.c_str(), &tmpNetmask) == 1 && - inet_pton(AF_INET, address.m_gateway.c_str(), &tmpGWAddress) == 1) + inet_pton(AF_INET, address.gateway.c_str(), &tmpGWAddress) == 1) { bcastAddr1.s_addr = tmpIPAddress.s_addr | ~tmpNetmask.s_addr; bcastAddr2.s_addr = tmpGWAddress.s_addr | ~tmpNetmask.s_addr; @@ -951,17 +975,17 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { if (Core::ERROR_NONE == rc) { - strncpy(iarmData.ipaddress, address.m_ipAddress.c_str(), 16); + strncpy(iarmData.ipaddress, address.ipaddress.c_str(), 16); strncpy(iarmData.netmask, netmask.c_str(), 16); - strncpy(iarmData.gateway, address.m_gateway.c_str(), 16); - strncpy(iarmData.primarydns, address.m_primaryDns.c_str(), 16); - strncpy(iarmData.secondarydns, address.m_secondaryDns.c_str(), 16); + strncpy(iarmData.gateway, address.gateway.c_str(), 16); + strncpy(iarmData.primarydns, address.primarydns.c_str(), 16); + strncpy(iarmData.secondarydns, address.secondarydns.c_str(), 16); } } } else { - iarmData.autoconfig = address.m_autoConfig; + iarmData.autoconfig = address.autoconfig; } if (Core::ERROR_NONE == rc) { @@ -986,16 +1010,18 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { return rc; } - uint32_t NetworkManagerImplementation::StartWiFiScan(const WiFiFrequency frequency /* @in */) + uint32_t NetworkManagerImplementation::StartWiFiScan(const string& frequency /* @in */, IStringIterator* const ssids/* @in */) { LOG_ENTRY_FUNCTION(); uint32_t rc = Core::ERROR_RPC_CALL_FAILED; IARM_Bus_WiFiSrvMgr_SsidList_Param_t param; IARM_Result_t retVal = IARM_RESULT_SUCCESS; - memset(¶m, 0, sizeof(param)); + (void)ssids; (void) frequency; + memset(¶m, 0, sizeof(param)); + retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsync, (void *)¶m, sizeof(IARM_Bus_WiFiSrvMgr_SsidList_Param_t)); if(retVal == IARM_RESULT_SUCCESS) { @@ -1064,9 +1090,9 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { IARM_Bus_WiFiSrvMgr_Param_t param; memset(¶m, 0, sizeof(param)); - strncpy(param.data.connect.ssid, ssid.m_ssid.c_str(), SSID_SIZE - 1); - strncpy(param.data.connect.passphrase, ssid.m_passphrase.c_str(), PASSPHRASE_BUFF - 1); - param.data.connect.security_mode = (SsidSecurity) ssid.m_securityMode; + strncpy(param.data.connect.ssid, ssid.ssid.c_str(), SSID_SIZE - 1); + strncpy(param.data.connect.passphrase, ssid.passphrase.c_str(), PASSPHRASE_BUFF - 1); + param.data.connect.security_mode = (SsidSecurity) ssid.security; IARM_Result_t retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_saveSSID, (void *)¶m, sizeof(param)); if((retVal == IARM_RESULT_SUCCESS) && param.status) @@ -1114,20 +1140,20 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { IARM_Bus_WiFiSrvMgr_Param_t param; memset(¶m, 0, sizeof(param)); - if(ssid.m_ssid.length() || ssid.m_passphrase.length()) + if(ssid.ssid.length() || ssid.passphrase.length()) { - ssid.m_ssid.copy(param.data.connect.ssid, sizeof(param.data.connect.ssid) - 1); - ssid.m_passphrase.copy(param.data.connect.passphrase, sizeof(param.data.connect.passphrase) - 1); - param.data.connect.security_mode = (SsidSecurity)ssid.m_securityMode; - if(!ssid.m_identity.empty()) - ssid.m_identity.copy(param.data.connect.eapIdentity, sizeof(param.data.connect.eapIdentity) - 1); - if(!ssid.m_caCert.empty()) - ssid.m_caCert.copy(param.data.connect.carootcert, sizeof(param.data.connect.carootcert) - 1); - if(!ssid.m_clientCert.empty()) - ssid.m_clientCert.copy(param.data.connect.clientcert, sizeof(param.data.connect.clientcert) - 1); - if(!ssid.m_privateKey.empty()) - ssid.m_privateKey.copy(param.data.connect.privatekey, sizeof(param.data.connect.privatekey) - 1); - param.data.connect.persistSSIDInfo = ssid.m_persistSSIDInfo; + ssid.ssid.copy(param.data.connect.ssid, sizeof(param.data.connect.ssid) - 1); + ssid.passphrase.copy(param.data.connect.passphrase, sizeof(param.data.connect.passphrase) - 1); + param.data.connect.security_mode = (SsidSecurity)ssid.security; + if(!ssid.eap_identity.empty()) + ssid.eap_identity.copy(param.data.connect.eapIdentity, sizeof(param.data.connect.eapIdentity) - 1); + if(!ssid.ca_cert.empty()) + ssid.ca_cert.copy(param.data.connect.carootcert, sizeof(param.data.connect.carootcert) - 1); + if(!ssid.client_cert.empty()) + ssid.client_cert.copy(param.data.connect.clientcert, sizeof(param.data.connect.clientcert) - 1); + if(!ssid.private_key.empty()) + ssid.private_key.copy(param.data.connect.privatekey, sizeof(param.data.connect.privatekey) - 1); + param.data.connect.persistSSIDInfo = ssid.persist; } retVal = IARM_Bus_Call( IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_connect, (void *)¶m, sizeof(param)); @@ -1181,13 +1207,13 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { { auto &connectedSsid = param.data.getConnectedSSID; - ssidInfo.m_ssid = string(connectedSsid.ssid); - ssidInfo.m_bssid = string(connectedSsid.bssid); - ssidInfo.m_securityMode = (WIFISecurityMode) connectedSsid.securityMode; - ssidInfo.m_signalStrength = to_string(connectedSsid.signalStrength); - ssidInfo.m_frequency = static_cast(connectedSsid.frequency)/1000.0; - ssidInfo.m_rate = to_string(connectedSsid.rate); - ssidInfo.m_noise = to_string(connectedSsid.noise); + ssidInfo.ssid = string(connectedSsid.ssid); + ssidInfo.bssid = string(connectedSsid.bssid); + ssidInfo.security = (WIFISecurityMode) connectedSsid.securityMode; + ssidInfo.strength = to_string(connectedSsid.signalStrength); + ssidInfo.rate = to_string(connectedSsid.rate); + ssidInfo.noise = to_string(connectedSsid.noise); + ssidInfo.frequency = to_string((double)connectedSsid.frequency/1000); NMLOG_INFO ("GetConnectedSSID Success"); rc = Core::ERROR_NONE; @@ -1208,13 +1234,13 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { if (Core::ERROR_NONE == GetConnectedSSID(ssidInfo)) { - ssid = ssidInfo.m_ssid; - signalStrength = ssidInfo.m_signalStrength; + ssid = ssidInfo.ssid; + signalStrength = ssidInfo.strength; if (!signalStrength.empty()) { signalStrengthOut = std::stof(signalStrength.c_str()); - NMLOG_INFO ("WiFiSignalStrength in dB = %s",signalStrengthOut); + NMLOG_INFO ("WiFiSignalStrength in dB = %f",signalStrengthOut); } if (signalStrengthOut == 0) diff --git a/WiFiSignalStrengthMonitor.cpp b/WiFiSignalStrengthMonitor.cpp index 60165f93..839de661 100644 --- a/WiFiSignalStrengthMonitor.cpp +++ b/WiFiSignalStrengthMonitor.cpp @@ -120,7 +120,7 @@ namespace WPEFramework { NMLOG_INFO("Notifying WiFiSignalStrengthChangedEvent %s", signalStrength.c_str()); oldSignalQuality = newSignalQuality; - _instance->ReportWiFiSignalStrengthChangedEvent(ssid, signalStrength, newSignalQuality); + _instance->ReportWiFiSignalStrengthChange(ssid, signalStrength, newSignalQuality); } if(newSignalQuality == Exchange::INetworkManager::WIFI_SIGNAL_DISCONNECTED) diff --git a/docs/NetworkManagerPlugin.md b/docs/NetworkManagerPlugin.md index 41f18666..53529aeb 100644 --- a/docs/NetworkManagerPlugin.md +++ b/docs/NetworkManagerPlugin.md @@ -2,71 +2,90 @@ # NetworkManager Plugin -**Version: [0.4.0]()** +**Version: 0.5.0** -A NetworkManager plugin for Thunder framework. +**Status: :white_circle::white_circle::white_circle:** + +org.rdk.NetworkManager interface for Thunder framework. + +(Defined by [NetworkManager.json](https://github.com/rdkcentral/networkmanager/blob/main/NetworkManager.json)) ### Table of Contents -- [Abbreviation, Acronyms and Terms](#head.Abbreviation,_Acronyms_and_Terms) +- [Introduction](#head.Introduction) - [Description](#head.Description) -- [Configuration](#head.Configuration) -- [Interfaces](#head.Interfaces) - [Methods](#head.Methods) - [Notifications](#head.Notifications) - -# Abbreviation, Acronyms and Terms + +# Introduction -[[Refer to this link](userguide/aat.md)] + +## Scope - -# Description +This document describes purpose and functionality of the org.rdk.NetworkManager interface (version 0.5.0). It includes detailed specification about its methods provided and notifications sent. -A Unified `NetworkManager` plugin that allows you to manage Ethernet and Wifi interfaces on the device. + +## Case Sensitivity - The plugin is designed to be an out-of-process service to be handled by Thunder framework. For more information about the framework refer to [[Thunder](#ref.Thunder)]. +All identifiers of the interfaces described in this document are case-sensitive. Thus, unless stated otherwise, all keywords, entities, properties, relations and actions should be treated as such. - -# Configuration + +## Acronyms, Abbreviations and Terms -The table below lists configuration options of the plugin. +The table below provides and overview of acronyms used in this document and their definitions. -| Name | Type | Description | -| :-------- | :-------- | :-------- | -| callsign | string | Plugin instance name (default: *org.rdk.NetworkManager*) | -| classname | string | Class name: *NetworkManager* | -| locator | string | Library name: *libWPEFrameworkNetworkManager.so* | -| autostart | boolean | Determines if the plugin shall be started automatically along with the framework | +| Acronym | Description | +| :-------- | :-------- | +| API | Application Programming Interface | +| HTTP | Hypertext Transfer Protocol | +| JSON | JavaScript Object Notation; a data interchange format | +| JSON-RPC | A remote procedure call protocol encoded in JSON | - -# Interfaces +The table below provides and overview of terms and abbreviations used in this document and their definitions. -This plugin implements the following interfaces: +| Term | Description | +| :-------- | :-------- | +| callsign | The name given to an instance of a plugin. One plugin can be instantiated multiple times, but each instance the instance name, callsign, must be unique. | + + +## References + +| Ref ID | Description | +| :-------- | :-------- | +| [HTTP](http://www.w3.org/Protocols) | HTTP specification | +| [JSON-RPC](https://www.jsonrpc.org/specification) | JSON-RPC 2.0 specification | +| [JSON](http://www.json.org/) | JSON specification | +| [Thunder](https://github.com/WebPlatformForEmbedded/Thunder/blob/master/doc/WPE%20-%20API%20-%20WPEFramework.docx) | Thunder API Reference | -- [NetworkManager.json](https://github.com/rdkcentral/ThunderInterfaces/blob/master/interfaces/NetworkManager.json) + +# Description + +A Unified `NetworkManager` plugin that allows you to manage Ethernet and Wifi interfaces on the device. # Methods -The following methods are provided by the org.rdk.NetworkManager plugin: +The following methods are provided by the org.rdk.NetworkManager interface: NetworkManager interface methods: | Method | Description | | :-------- | :-------- | +| [SetLogLevel](#method.SetLogLevel) | Set Log level for more information | +| [GetLogLevel](#method.GetLogLevel) | Get Log level that is currently used | | [GetAvailableInterfaces](#method.GetAvailableInterfaces) | Get device supported list of available interface including their state | | [GetPrimaryInterface](#method.GetPrimaryInterface) | Gets the primary/default network interface for the device | | [SetPrimaryInterface](#method.SetPrimaryInterface) | Sets the primary/default interface for the device | -| [SetInterfaceState](#method.SetInterfaceState) | Enable the interface | -| [GetInterfaceState](#method.GetInterfaceState) | Disable the interface | +| [SetInterfaceState](#method.SetInterfaceState) | Enable or disable the specified interface | +| [GetInterfaceState](#method.GetInterfaceState) | Gets the current Status of the specified interface | | [GetIPSettings](#method.GetIPSettings) | Gets the IP setting for the given interface | | [SetIPSettings](#method.SetIPSettings) | Sets the IP settings for the given interface | -| [GetStunEndpoint](#method.GetStunEndpoint) | Get the STUN Endpoint that is used to identify public IP of the device | -| [SetStunEndpoint](#method.SetStunEndpoint) | Set the STUN Endpoint to be used to identify public IP of the device | +| [GetStunEndpoint](#method.GetStunEndpoint) | Get the STUN endpoint that is used to identify public IP of the device | +| [SetStunEndpoint](#method.SetStunEndpoint) | Set the STUN endpoint to be used to identify public IP of the device | | [GetConnectivityTestEndpoints](#method.GetConnectivityTestEndpoints) | Gets currently used test endpoints | | [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 | +| [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 | @@ -84,21 +103,108 @@ NetworkManager interface methods: | [StartWPS](#method.StartWPS) | Initiates a connection using Wifi Protected Setup (WPS) | | [StopWPS](#method.StopWPS) | Cancels the in-progress WPS pairing operation | | [GetWiFiSignalStrength](#method.GetWiFiSignalStrength) | Get WiFiSignalStrength of connected SSID | -| [GetSupportedSecurityModes](#method.GetSupportedSecurityModes) | Returns the Wifi security modes that the device supports | -| [SetLogLevel](#method.SetLogLevel) | Set Log level for more information | -| [GetLogLevel](#method.GetLogLevel) | Gets the Log level thats used | +| [GetSupportedsecurityModes](#method.GetSupportedsecurityModes) | Returns the Wifi security modes that the device supports | | [GetWifiState](#method.GetWifiState) | Returns the current Wifi State | + +## *SetLogLevel [method](#head.Methods)* + +Set Log level for more information. The possible set log level are as follows. +* `0`: FATAL +* `1`: ERROR +* `2`: WARNING +* `3`: INFO +* `4`: DEBUG +. + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.level | integer | Set Log level to get more information | + +### 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.SetLogLevel", + "params": { + "level": 1 + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } +} +``` + + +## *GetLogLevel [method](#head.Methods)* + +Get Log level that is currently used. + +### Parameters + +This method takes no parameters. + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.level | integer | Get Log level to get more information | +| result.success | boolean | Whether the request succeeded | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetLogLevel" +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "level": 1, + "success": true + } +} +``` ## *GetAvailableInterfaces [method](#head.Methods)* Get device supported list of available interface including their state. -### Events - -No Events - ### Parameters This method takes no parameters. @@ -123,9 +229,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetAvailableInterfaces" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetAvailableInterfaces" } ``` @@ -133,31 +239,27 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "interfaces": [ - { - "type": "ETHERNET", - "name": "eth0", - "mac": "AA:AA:AA:AA:AA:AA", - "enabled": true, - "connected": true - } - ], - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "Interfaces": [ + { + "type": "ETHERNET", + "name": "eth0", + "mac": "AA:AA:AA:AA:AA:AA", + "enabled": true, + "connected": true + } + ], + "success": true + } } ``` ## *GetPrimaryInterface [method](#head.Methods)* -Gets the primary/default network interface for the device. The active network interface is defined as the one that can make requests to the external network. Returns one of the supported interfaces as per `GetAvailableInterfaces`, or an empty value which indicates that there is no default network interface. - -### Events - -No Events +Gets the primary/default network interface for the device. The active network interface is defined as the one that can make requests to the external network. Returns one of the supported interfaces as per `GetAvailableInterfaces`. ### Parameters @@ -176,9 +278,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetPrimaryInterface" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetPrimaryInterface" } ``` @@ -186,11 +288,11 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "interface": "wlan0" - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "interface": "wlan0" + } } ``` @@ -199,14 +301,8 @@ This method takes no parameters. Sets the primary/default interface for the device. This call fails if the interface is not enabled. -### Events +Also see: [onActiveInterfaceChange](#event.onActiveInterfaceChange), [onInterfaceStateChange](#event.onInterfaceStateChange), [onAddressChange](#event.onAddressChange), [onInternetStatusChange](#event.onInternetStatusChange) -| Event | Description | -| :-------- | :-------- | -| [onActiveInterfaceChange](#event.onActiveInterfaceChange) | Triggered when device’s default interface changed. | -| [onInterfaceStateChange](#event.onInterfaceStateChange) | Triggered when interface’s state changed | -| [onAddressChange](#event.onAddressChange) | Triggered when the device connects to router. | -| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when each IP address is lost or acquired. | ### Parameters | Name | Type | Description | @@ -227,12 +323,12 @@ Sets the primary/default interface for the device. This call fails if the interf ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.SetPrimaryInterface", - "params": { - "interface": "wlan0" - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.SetPrimaryInterface", + "params": { + "interface": "wlan0" + } } ``` @@ -240,32 +336,28 @@ Sets the primary/default interface for the device. This call fails if the interf ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` ## *SetInterfaceState [method](#head.Methods)* -Enable or Disable the specified interface. - -### Events +Enable or disable the specified interface. -| Event | Description | -| :-------- | :-------- | -| [onInterfaceStateChange](#event.onInterfaceStateChange) | Triggered when interface’s status changes to enabled or disabled. | +Also see: [onInterfaceStateChange](#event.onInterfaceStateChange) ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface in `GetAvailableInterfaces` | -| params.enabled | boolean | Set the state of the interface to be Enabled or Disabled | +| params.interface | string | Enable the specified interface | +| params.enabled | boolean | Whether the interface must be enabled or disabled | ### Result @@ -280,13 +372,13 @@ Enable or Disable the specified interface. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.SetInterfaceState", - "params": { - "interface": "wlan0", - "enabled": true - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.SetInterfaceState", + "params": { + "interface": "wlan0", + "enabled": true + } } ``` @@ -294,36 +386,32 @@ Enable or Disable the specified interface. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` ## *GetInterfaceState [method](#head.Methods)* -Disable the specified interface. - -### Events - -No Events +Gets the current Status of the specified interface. ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface in `GetAvailableInterfaces` | +| params.interface | string | Disable the specified interface | ### Result | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.enabled | boolean | Whether the Interface is enabled or disabled | +| result.enabled | boolean | Whether the interface is enabled or disabled | | result.success | boolean | Whether the request succeeded | ### Example @@ -332,12 +420,12 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetInterfaceState", - "params": { - "interface": "wlan0" - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetInterfaceState", + "params": { + "interface": "wlan0" + } } ``` @@ -345,12 +433,12 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "enabled": true, - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "enabled": true, + "success": true + } } ``` @@ -359,17 +447,13 @@ No Events Gets the IP setting for the given interface. -### Events - -No Events - ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.interface | string | *(optional)* An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface. If this is empty, default interface will be returned | -| params?.ipversion | string | *(optional)* either IPv4 or IPv6 | +| params?.interface | string | *(optional)* An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | +| params?.ipversion | string | *(optional)* Either IPv4 or IPv6 | ### Result @@ -377,13 +461,13 @@ No Events | :-------- | :-------- | :-------- | | result | object | | | result.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | -| result.ipversion | string | either IPv4 or IPv6 | +| result.ipversion | string | Either IPv4 or IPv6 | | result.autoconfig | boolean | `true` if DHCP is used, `false` if IP is configured manually | | result?.dhcpserver | string | *(optional)* The DHCP Server address | | result.ipaddress | string | The IP address | | result.prefix | integer | The prefix number | | result.gateway | string | The gateway address | -| result.ula | string | The IPv6 Unified Local Address; Empty when IPv4 is requested | +| result.ula | string | The IPv6 Unified Local Address | | result.primarydns | string | The primary DNS address | | result.secondarydns | string | The secondary DNS address | | result.success | boolean | Whether the request succeeded | @@ -394,13 +478,13 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetIPSettings", - "params": { - "interface": "wlan0", - "ipversion": "IPv4" - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetIPSettings", + "params": { + "interface": "wlan0", + "ipversion": "IPv4" + } } ``` @@ -408,21 +492,21 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "interface": "wlan0", - "ipversion": "IPv4", - "autoconfig": true, - "dhcpserver": "192.168.1.1", - "ipaddress": "192.168.1.101", - "prefix": 24, - "gateway": "192.168.1.1", - "ula": "...", - "primarydns": "192.168.1.1", - "secondarydns": "192.168.1.2", - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "interface": "wlan0", + "ipversion": "IPv4", + "autoconfig": true, + "dhcpserver": "192.168.1.1", + "ipaddress": "192.168.1.101", + "prefix": 24, + "gateway": "192.168.1.1", + "ula": "d00:410:2016::", + "primarydns": "192.168.1.1", + "secondarydns": "192.168.1.2", + "success": true + } } ``` @@ -431,19 +515,15 @@ No Events Sets the IP settings for the given interface. -### Events +Also see: [onAddressChange](#event.onAddressChange), [onInternetStatusChange](#event.onInternetStatusChange) -| Event | Description | -| :-------- | :-------- | -| [onAddressChange](#event.onAddressChange) | Triggered when the device connects to router. | -| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when each IP address is lost or acquired. | ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | | params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | -| params.ipversion | string | either IPv4 or IPv6 | +| params.ipversion | string | Either IPv4 or IPv6 | | params.autoconfig | boolean | `true` if DHCP is used, `false` if IP is configured manually | | params.ipaddress | string | The IP address | | params.prefix | integer | The prefix number | @@ -464,19 +544,19 @@ Sets the IP settings for the given interface. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.SetIPSettings", - "params": { - "interface": "wlan0", - "ipversion": "IPv4", - "autoconfig": true, - "ipaddress": "192.168.1.101", - "prefix": 24, - "gateway": "192.168.1.1", - "primarydns": "192.168.1.1", - "secondarydns": "192.168.1.2" - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.SetIPSettings", + "params": { + "interface": "wlan0", + "ipversion": "IPv4", + "autoconfig": true, + "ipaddress": "192.168.1.101", + "prefix": 24, + "gateway": "192.168.1.1", + "primarydns": "192.168.1.1", + "secondarydns": "192.168.1.2" + } } ``` @@ -484,22 +564,18 @@ Sets the IP settings for the given interface. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` ## *GetStunEndpoint [method](#head.Methods)* -Get the STUN Endpoint that is used to identify public IP of the device. - -### Events - -No Events +Get the STUN endpoint that is used to identify public IP of the device. ### Parameters @@ -510,10 +586,10 @@ This method takes no parameters. | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.endpoint | string | STUN server endpoint | +| result.endpoint | string | The host name or IP address | | result.port | integer | STUN server port | -| result.timeout | integer | STUN server bind timeout | -| result.cacheLifetime | integer | STUN server cache Lifetime | +| result.timeout | integer | Timeout | +| result.cacheLifetime | integer | STUN server cache timeout | | result.success | boolean | Whether the request succeeded | ### Example @@ -522,9 +598,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetStunEndpoint" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetStunEndpoint" } ``` @@ -532,36 +608,32 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "endpoint": "stun.l.google.com", - "port": 3478, - "timeout": 30, - "cacheLifetime": 0, - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "endpoint": "45.57.221.20", + "port": 3478, + "timeout": 30, + "cacheLifetime": 0, + "success": true + } } ``` ## *SetStunEndpoint [method](#head.Methods)* -Set the STUN Endpoint to be used to identify public IP of the device. - -### Events - -No Events +Set the STUN endpoint to be used to identify public IP of the device. ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.endpoint | string | STUN server endpoint | +| params.endpoint | string | The host name or IP address | | params.port | integer | STUN server port | -| params?.timeout | integer | *(optional)* STUN server bind timeout | -| params?.cacheLifetime | integer | *(optional)* STUN server cache lifetime | +| params?.timeout | integer | *(optional)* Timeout | +| params?.cacheLifetime | integer | *(optional)* STUN server cache timeout | ### Result @@ -576,15 +648,15 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.SetStunEndpoint", - "params": { - "endpoint": "stun.l.google.com", - "port": 3478, - "timeout": 30, - "cacheLifetime": 0 - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.SetStunEndpoint", + "params": { + "endpoint": "45.57.221.20", + "port": 3478, + "timeout": 30, + "cacheLifetime": 0 + } } ``` @@ -592,11 +664,11 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` @@ -605,10 +677,6 @@ No Events Gets currently used test endpoints. on success list out the connectivity test points connections. -### Events - -No Events - ### Parameters This method takes no parameters. @@ -628,9 +696,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetConnectivityTestEndpoints" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetConnectivityTestEndpoints" } ``` @@ -638,14 +706,14 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "endpoints": [ - "http://clients3.google.com/generate_204" - ], - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "endpoints": [ + "http://clients3.google.com/generate_204" + ], + "success": true + } } ``` @@ -654,10 +722,6 @@ This method takes no parameters. This method used to set up to 5 endpoints for a connectivity test. Successful connections are verified with HTTP Status code 204 (No Content). -### Events - -No Events - ### Parameters | Name | Type | Description | @@ -679,14 +743,14 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.SetConnectivityTestEndpoints", - "params": { - "endpoints": [ - "http://clients3.google.com/generate_204" - ] - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.SetConnectivityTestEndpoints", + "params": { + "endpoints": [ + "http://clients3.google.com/generate_204" + ] + } } ``` @@ -694,39 +758,35 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` ## *IsConnectedToInternet [method](#head.Methods)* -Seeks Whether the device has internet connectivity. This API might take up to 3s to validate internet connectivity. - -### Events - -No Events +Seeks whether the device has internet connectivity. This API might take up to 3s to validate internet connectivity. ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.ipversion | string | either IPv4 or IPv6 | +| params?.ipversion | string | *(optional)* Either IPv4 or IPv6 | ### Result | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.ipversion | string | either IPv4 or IPv6 | +| result.ipversion | string | Either IPv4 or IPv6 | | result.connected | boolean | `true` if internet connectivity is detected, otherwise `false` | -| result.state | integer | The internet state | -| result.status | integer | The internet status; could be `LIMITED_INTERNET`, `CAPTIVE_PORTAL`, `NO_INTERNET`, `FULLY_CONNECTED` | +| result.state | integer | Internet state | +| result.status | string | Internet status | | result.success | boolean | Whether the request succeeded | ### Example @@ -735,12 +795,12 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.IsConnectedToInternet", - "params": { - "ipversion": "IPv4" - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.IsConnectedToInternet", + "params": { + "ipversion": "IPv4" + } } ``` @@ -748,15 +808,15 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "ipversion": "IPv4" - "connected": true, - "state": 3, - "status": "FULLY_CONNECTED", - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "ipversion": "IPv4", + "connected": true, + "state": 3, + "status": "FULLY_CONNECTED", + "success": true + } } ``` @@ -765,10 +825,6 @@ No Events Gets the captive portal URI if connected to any captive portal network. -### Events - -No Events - ### Parameters This method takes no parameters. @@ -787,9 +843,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetCaptivePortalURI" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetCaptivePortalURI" } ``` @@ -797,31 +853,28 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "uri": "http://10.0.0.1/captiveportal.jst", - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "uri": "http://10.0.0.1/captiveportal.jst", + "success": true + } } ``` ## *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. +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 +Also see: [onInternetStatusChange](#event.onInternetStatusChange) -| Event | Description | -| :-------- | :-------- | -| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when internet connection state changed. | ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.interval | number | Interval in sec | +| params?.interval | integer | *(optional)* Interval in sec | ### Result @@ -836,12 +889,12 @@ Enable a continuous monitoring of internet connectivity with heart beat interval ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.StartConnectivityMonitoring", - "params": { - "interval": 30 - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.StartConnectivityMonitoring", + "params": { + "interval": 30 + } } ``` @@ -849,11 +902,11 @@ Enable a continuous monitoring of internet connectivity with heart beat interval ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` @@ -862,10 +915,6 @@ Enable a continuous monitoring of internet connectivity with heart beat interval Stops the connectivity monitoring. -### Events - -No Events - ### Parameters This method takes no parameters. @@ -883,9 +932,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.StopConnectivityMonitoring" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.StopConnectivityMonitoring" } ``` @@ -893,11 +942,11 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` @@ -906,24 +955,20 @@ This method takes no parameters. Gets the internet/public IP Address of the device. -### Events - -No Events - ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | -| params | object | it allows empty parameter too | -| params.ipversion | string | *(optional)* Either IPv4 or IPv6 | +| params | object | It allows empty parameter too | +| params?.ipversion | string | *(optional)* Either IPv4 or IPv6 | ### Result | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.ipaddress | string | Returns an public ip of the device | -| result.ipversion | string | Returns an ip version of the public ip | +| result.ipaddress | string | The IP address | +| result.ipversion | string | Either IPv4 or IPv6 | | result.success | boolean | Whether the request succeeded | ### Example @@ -932,12 +977,12 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetPublicIP", - "params": { - "ipversion": "IPv4" - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetPublicIP", + "params": { + "ipversion": "IPv4" + } } ``` @@ -945,13 +990,13 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "ipaddress": "69.136.49.95", - "ipversion": "IPv4" - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "ipaddress": "192.168.1.101", + "ipversion": "IPv4", + "success": true + } } ``` @@ -960,27 +1005,23 @@ No Events Pings the specified endpoint with the specified number of packets. -### Events - -No Events - ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | | params.endpoint | string | The host name or IP address | -| params.ipversion | string | either IPv4 or IPv6 | -| params.count | integer | *(optional)* The number of packets to send. Default is 3 | -| params.timeout | integer | Timeout | -| params.guid | string | The globally unique identifier | +| params.ipversion | string | Either IPv4 or IPv6 | +| params?.count | integer | *(optional)* The number of requests to send. Default is 3 | +| params?.timeout | integer | *(optional)* Timeout | +| params?.guid | string | *(optional)* The globally unique identifier | ### Result | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.target | string | The target IP address | +| result.endpoint | string | The host name or IP address | | result.packetsTransmitted | integer | The number of packets sent | | result.packetsReceived | integer | The number of packets received | | result.packetLoss | string | The number of packets lost | @@ -998,16 +1039,16 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.Ping", - "params": { - "endpoint": "45.57.221.20", - "ipversion": "IPv4", - "count": 5, - "timeout": 30, - "guid": "..." - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.Ping", + "params": { + "endpoint": "45.57.221.20", + "ipversion": "IPv4", + "count": 10, + "timeout": 30, + "guid": "..." + } } ``` @@ -1015,21 +1056,21 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "target": "45.57.221.20", - "packetsTransmitted": 5, - "packetsReceived": 5, - "packetLoss": "0.0", - "tripMin": "61.264", - "tripAvg": "130.397", - "tripMax": "230.832", - "tripStdDev": "80.919", - "error": "...", - "guid": "...", - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "endpoint": "45.57.221.20", + "packetsTransmitted": 10, + "packetsReceived": 10, + "packetLoss": "0.0", + "tripMin": "61.264", + "tripAvg": "130.397", + "tripMax": "230.832", + "tripStdDev": "80.919", + "error": "...", + "guid": "...", + "success": true + } } ``` @@ -1038,27 +1079,24 @@ No Events Traces the specified endpoint with the specified number of packets using `traceroute`. -### Events - -No Events - ### Parameters -| Name | Type | Description | -| :-------- | :-------- | :-------- | +| Name | Type | Description | +| :-------- | :-------- | :-------- | | params | object | | -| params.ipversion| string | *(optional)* The host name or IP address | -| params.endpoint | string | The host name or IP address | -| params.packets | integer | *(optional)* The number of packets to send. Default is 5 | -| params.guid | string | *(optional)* The globally unique identifier | +| params.endpoint | string | The host name or IP address | +| params.ipversion | string | Either IPv4 or IPv6 | +| params?.packets | integer | *(optional)* The number of packets to send. Default is 5 | +| params?.guid | string | *(optional)* The globally unique identifier | ### Result | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.target | string | The target IP address | -| result.results | string | The results from `traceroute` | +| result.endpoint | string | The host name or IP address | +| result.results | string | The response of traceroute | +| result.guid | string | The globally unique identifier | | result.success | boolean | Whether the request succeeded | ### Example @@ -1067,13 +1105,15 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.Trace", - "params": { - "endpoint": "45.57.221.20", - "packets": 5 - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.Trace", + "params": { + "endpoint": "45.57.221.20", + "ipversion": "IPv4", + "packets": 10, + "guid": "..." + } } ``` @@ -1081,34 +1121,32 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "target": "45.57.221.20", - "success": true, - "results": "<<>>" - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "endpoint": "45.57.221.20", + "results": "...", + "guid": "...", + "success": true + } } ``` ## *StartWiFiScan [method](#head.Methods)* -Initiates WiFi scaning. This method supports scanning for specific range of frequency like 2.4GHz only or 5GHz only or 6GHz only or ALL. When no input passed about the frequency to be scanned, it scans for all. It publishes 'onAvailableSSIDs' event upon completion. +Initiates WiFi scaning. This method supports scanning for specific range of frequency like 2.4GHz only or 5GHz only or 6GHz only or ALL. When no input passed about the frequency to be scanned, it scans for all. When list of SSIDs to be scanned specifically, it can be passed as input. It publishes 'onAvailableSSIDs' event upon completion. -### Events +Also see: [onAvailableSSIDs](#event.onAvailableSSIDs) -| Event | Description | -| :-------- | :-------- | -| [onAvailableSSIDs](#event.onAvailableSSIDs) | Triggered when list of SSIDs is available after the scan completes. | ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.frequency | string | *(optional)* The frequency to scan. | -| params.ssids | array | *(optional)* The list of SSIDs to scan. | -| params.ssids[#] | string | | +| 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)* | ### Result @@ -1123,9 +1161,15 @@ Initiates WiFi scaning. This method supports scanning for specific range of freq ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.StartWiFiScan" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.StartWiFiScan", + "params": { + "frequency": "5", + "ssids": [ + "Xfinity Mobile" + ] + } } ``` @@ -1133,11 +1177,11 @@ Initiates WiFi scaning. This method supports scanning for specific range of freq ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` @@ -1146,10 +1190,6 @@ Initiates WiFi scaning. This method supports scanning for specific range of freq Stops WiFi scanning. Any discovered SSIDs from the call to the `StartWiFiScan` method up to the point where this method is called are still returned as event. -### Events - -No Events - ### Parameters This method takes no parameters. @@ -1167,9 +1207,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.StopWiFiScan" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.StopWiFiScan" } ``` @@ -1177,11 +1217,11 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` @@ -1190,10 +1230,6 @@ This method takes no parameters. Gets list of saved SSIDs. This method returns all the SSIDs that are saved as array. -### Events - -No Events - ### Parameters This method takes no parameters. @@ -1213,9 +1249,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetKnownSSIDs" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetKnownSSIDs" } ``` @@ -1223,14 +1259,14 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "ssids": [ - "Xfinity_Guest" - ], - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "ssids": [ + "Xfinity_Guest" + ], + "success": true + } } ``` @@ -1239,10 +1275,6 @@ This method takes no parameters. Saves the SSID, passphrase, and security mode for upcoming and future sessions. This method only adds to the persistent memory; does not disconnect from currently connected SSID. -### Events - -No Events - ### Parameters | Name | Type | Description | @@ -1250,7 +1282,7 @@ No Events | params | object | | | params.ssid | string | The paired SSID | | params.passphrase | string | The access point password | -| params.security | integer | The security mode. See `getSupportedSecurityModes` | +| params.security | integer | The security mode. See `getSupportedsecurityModes` | ### Result @@ -1265,14 +1297,14 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.AddToKnownSSIDs", - "params": { - "ssid": "123412341234", - "passphrase": "password", - "security": 6 - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.AddToKnownSSIDs", + "params": { + "ssid": "123412341234", + "passphrase": "password", + "security": 6 + } } ``` @@ -1280,26 +1312,21 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` ## *RemoveKnownSSID [method](#head.Methods)* -Remove given SSID from saved SSIDs. This method just removes from the list and of the list is having only one entry thats being removed, it will initiate a disconnect. +Remove given SSID from saved SSIDs. This method just removes an entry from the list and of the list is having only one entry thats being removed, it will initiate a disconnect. -### Events +Also see: [onWiFiStateChange](#event.onWiFiStateChange), [onAddressChange](#event.onAddressChange), [onInternetStatusChange](#event.onInternetStatusChange) -| Event | Description | -| :-------- | :-------- | -| [onWiFiStateChange](#event.onWiFiStateChange) | Triggered when Wifi state changes to DISCONNECTED | -| [onAddressChange](#event.onAddressChange) | Triggered when an IP Address is assigned or lost | -| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when internet connection state changed | ### Parameters | Name | Type | Description | @@ -1320,12 +1347,12 @@ Remove given SSID from saved SSIDs. This method just removes from the list and o ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.RemoveKnownSSID", - "params": { - "ssid": "123412341234" - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.RemoveKnownSSID", + "params": { + "ssid": "123412341234" + } } ``` @@ -1333,11 +1360,11 @@ Remove given SSID from saved SSIDs. This method just removes from the list and o ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` @@ -1346,11 +1373,8 @@ Remove given SSID from saved SSIDs. This method just removes from the list and o Initiates request to connect to the specified SSID with the given passphrase. Passphrase can be `null` when the network security is `NONE`. When called with no arguments, this method attempts to connect to the saved SSID and password. See `AddToKnownSSIDs`. -### Events +Also see: [onWiFiStateChange](#event.onWiFiStateChange) -| Event | Description | -| :-------- | :-------- | -| [onWiFiStateChange](#event.onWiFiStateChange) | Triggered when Wifi state changes to CONNECTING, CONNECTED . | ### Parameters | Name | Type | Description | @@ -1358,8 +1382,17 @@ Initiates request to connect to the specified SSID with the given passphrase. Pa | params | object | | | params.ssid | string | The paired SSID | | params.passphrase | string | The access point password | -| params.security | integer | The security mode. See `getSupportedSecurityModes` | -| params?.persist | boolean | *(optional)* Option to connect to SSID without persisting AccessPoint details (default: *true*; always persist) | +| params.security | integer | The security mode. See `getSupportedsecurityModes` | +| params?.ca_cert | string | *(optional)* The ca_cert to be used for EAP | +| params?.client_cert | string | *(optional)* The client_cert to be used for EAP | +| params?.private_key | string | *(optional)* The private_key to be used for EAP | +| params?.private_key_passwd | string | *(optional)* The private_key_passwd to be used for EAP | +| params?.eap | string | *(optional)* The EAP type to be used | +| params?.eap_identity | string | *(optional)* The identity to be used for EAP | +| params?.eap_password | string | *(optional)* The eap_password to be used for EAP | +| params?.eap_phase1 | string | *(optional)* The eap_phase1 to be used for EAP | +| params?.eap_phase2 | string | *(optional)* The eap_phase2 to be used for EAP | +| params?.persist | boolean | *(optional)* To persist the SSID across reboots; similar to auto connect | ### Result @@ -1374,15 +1407,24 @@ Initiates request to connect to the specified SSID with the given passphrase. Pa ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.WiFiConnect", - "params": { - "ssid": "123412341234", - "passphrase": "password", - "security": 6, - "persist": true - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.WiFiConnect", + "params": { + "ssid": "123412341234", + "passphrase": "password", + "security": 6, + "ca_cert": "...", + "client_cert": "...", + "private_key": "...", + "private_key_passwd": "...", + "eap": "TLS", + "eap_identity": "...", + "eap_password": "...", + "eap_phase1": "...", + "eap_phase2": "...", + "persist": true + } } ``` @@ -1390,11 +1432,11 @@ Initiates request to connect to the specified SSID with the given passphrase. Pa ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` @@ -1403,13 +1445,8 @@ Initiates request to connect to the specified SSID with the given passphrase. Pa Disconnects from the currently connected SSID. A event will be posted upon completion. -### Events +Also see: [onWIFIStateChange](#event.onWIFIStateChange), [onAddressChange](#event.onAddressChange), [onInternetStatusChange](#event.onInternetStatusChange) -| Event | Description | -| :-------- | :-------- | -| [onWIFIStateChange](#event.onWIFIStateChange) | Triggered when Wifi state changes to DISCONNECTED (only if currently connected). | -| [onAddressChange](#event.onAddressChange) | Triggered when an IP Address is assigned or lost | -| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when internet connection state changed | ### Parameters This method takes no parameters. @@ -1427,9 +1464,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.WiFiDisconnect" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.WiFiDisconnect" } ``` @@ -1437,11 +1474,11 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` @@ -1450,10 +1487,6 @@ This method takes no parameters. Returns the connected SSID information. -### Events - -No Events - ### Parameters This method takes no parameters. @@ -1478,9 +1511,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetConnectedSSID" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetConnectedSSID" } ``` @@ -1488,18 +1521,18 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "ssid": "123412341234", - "bssid": "ff:ff:ff:ff:ff:ff", - "security": "5", - "strength": "-27.000000", - "frequency": "2.442000", - "rate": "144.000000", - "noise": "-121.000000", - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "ssid": "123412341234", + "bssid": "ff:ff:ff:ff:ff:ff", + "security": "5", + "strength": "-27.000000", + "frequency": "2.442000", + "rate": "144.000000", + "noise": "-121.000000", + "success": true + } } ``` @@ -1510,20 +1543,15 @@ Initiates a connection using Wifi Protected Setup (WPS). An existing connection If the `method` parameter is set to `SERIALIZED_PIN`, then RDK retrieves the serialized pin using the Manufacturer (MFR) API. If the `method` parameter is set to `PIN`, then RDK use the pin supplied as part of the request. If the `method` parameter is set to `PBC`, then RDK uses Push Button Configuration (PBC) to obtain the pin. -### Events +Also see: [onWIFIStateChange](#event.onWIFIStateChange), [onAddressChange](#event.onAddressChange), [onInternetStatusChange](#event.onInternetStatusChange) -| Event | Description | -| :-------- | :-------- | -| [onWIFIStateChange](#event.onWIFIStateChange) | Triggered when Wifi state changes to DISCONNECTED (only if currently connected), CONNECTING, CONNECTED. | -| [onAddressChange](#event.onAddressChange) | Triggered when an IP Address is assigned or lost | -| [onInternetStatusChange](#event.onInternetStatusChange) | Triggered when internet connection state changed | ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.method | integer | The method used to obtain the pin (must be one of the following: PBC=0, PIN=1, SERIALIZED_PIN=2) | -| params.pin | string | A valid 8 digit WPS pin number. Use this parameter when the `method` parameter is set to `PIN` | +| params.method | string | The method used to obtain the pin (must be one of the following: PBC=0, PIN=1, SERIALIZED_PIN=2) | +| params?.pin | string | *(optional)* A valid 8 digit WPS pin number. Use this parameter when the `method` parameter is set to `PIN` | ### Result @@ -1539,13 +1567,13 @@ If the `method` parameter is set to `SERIALIZED_PIN`, then RDK retrieves the ser ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.StartWPS", - "params": { - "method": 1, - "pin": "88888888" - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.StartWPS", + "params": { + "method": "PIN", + "pin": "88888888" + } } ``` @@ -1553,12 +1581,12 @@ If the `method` parameter is set to `SERIALIZED_PIN`, then RDK retrieves the ser ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "pin": "88888888", - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "pin": "88888888", + "success": true + } } ``` @@ -1567,11 +1595,8 @@ If the `method` parameter is set to `SERIALIZED_PIN`, then RDK retrieves the ser Cancels the in-progress WPS pairing operation. The operation forcefully stops the in-progress pairing attempt and aborts the current scan. WPS pairing must be in-progress for the operation to succeed. -### Events +Also see: [onWIFIStateChange](#event.onWIFIStateChange) -| Event | Description | -| :-------- | :-------- | -| [onWIFIStateChange](#event.onWIFIStateChange) | Triggered when Wifi state changes to DISCONNECTED. | ### Parameters This method takes no parameters. @@ -1589,9 +1614,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.StopWPS" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.StopWPS" } ``` @@ -1599,11 +1624,11 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "success": true + } } ``` @@ -1612,11 +1637,8 @@ This method takes no parameters. Get WiFiSignalStrength of connected SSID. -### Events +Also see: [onWiFiSignalStrengthChange](#event.onWiFiSignalStrengthChange) -| Event | Description | -| :-------- | :-------- | -| [onWiFiSignalStrengthChange](#event.onWiFiSignalStrengthChange) | Triggered when Wifi signal strength switches between Excellent, Good, Fair, Weak. | ### Parameters This method takes no parameters. @@ -1628,7 +1650,7 @@ This method takes no parameters. | result | object | | | result.ssid | string | The paired SSID | | result.strength | string | The RSSI value in dBm | -| result.quality | string | Signal strength Quality | +| result.quality | integer | Signal strength Quality | | result.success | boolean | Whether the request succeeded | ### Example @@ -1637,9 +1659,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetWiFiSignalStrength" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetWiFiSignalStrength" } ``` @@ -1647,26 +1669,22 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "ssid": "123412341234", - "strength": "-27.000000", - "quality": "Excellent", - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "ssid": "123412341234", + "strength": "-27.000000", + "quality": 123, + "success": true + } } ``` - -## *GetSupportedSecurityModes [method](#head.Methods)* + +## *GetSupportedsecurityModes [method](#head.Methods)* Returns the Wifi security modes that the device supports. -### Events - -No Events - ### Parameters This method takes no parameters. @@ -1700,82 +1718,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetSupportedSecurityModes" -} -``` - -#### Response - -```json -{ - "jsonrpc": "2.0", - "id": 42, - "result": { - "security_modes": { - "NET_WIFI_SECURITY_NONE": 0, - "NET_WIFI_SECURITY_WEP_64": 1, - "NET_WIFI_SECURITY_WEP_128": 2, - "NET_WIFI_SECURITY_WPA_PSK_TKIP": 3, - "NET_WIFI_SECURITY_WPA_PSK_AES": 4, - "NET_WIFI_SECURITY_WPA2_PSK_TKIP": 5, - "NET_WIFI_SECURITY_WPA2_PSK_AES": 6, - "NET_WIFI_SECURITY_WPA_ENTERPRISE_TKIP": 7, - "NET_WIFI_SECURITY_WPA_ENTERPRISE_AES": 8, - "NET_WIFI_SECURITY_WPA2_ENTERPRISE_TKIP": 9, - "NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES": 10, - "NET_WIFI_SECURITY_WPA_WPA2_PSK": 11, - "NET_WIFI_SECURITY_WPA_WPA2_ENTERPRISE": 12, - "NET_WIFI_SECURITY_WPA3_PSK_AES": 13, - "NET_WIFI_SECURITY_WPA3_SAE": 14 - }, - "success": true - } -} -``` - - -## *SetLogLevel [method](#head.Methods)* - -Set Log level for more information. The possible set log level are as follows. -* `0`: FATAL -* `1`: ERROR -* `2`: WARN -* `3`: INFO -* `4`: DEBUG -. - -### Events - -No Events - -### Parameters - -| Name | Type | Description | -| :-------- | :-------- | :-------- | -| params | object | | -| params.level | integer | Set Log level to get more information | - -### 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.SetLogLevel", - "params": { - "level": 1 - } + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetSupportedsecurityModes" } ``` @@ -1783,87 +1728,50 @@ No Events ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "success": true - } -} -``` - - -## *GetLogLevel [method](#head.Methods)* - -Gets the log level. It could be either of the below -* `0`: FATAL -* `1`: ERROR -* `2`: WARN -* `3`: INFO -* `4`: DEBUG - -### Events - -No Events - -### Parameters - -This method takes no parameters. - -### Result - -| Name | Type | Description | -| :-------- | :-------- | :-------- | -| result | object | | -| result.level | integer | The Log level | -| result.success | boolean | Whether the request succeeded | - -### Example - -#### Request - -```json -{ - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetLogLevel", -} -``` - -#### Response - -```json -{ - "jsonrpc": "2.0", - "id": 42, - "result": { - "level": 3 - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "security_modes": { + "NET_WIFI_SECURITY_NONE": 0, + "NET_WIFI_SECURITY_WEP_64": 1, + "NET_WIFI_SECURITY_WEP_128": 2, + "NET_WIFI_SECURITY_WPA_PSK_TKIP": 3, + "NET_WIFI_SECURITY_WPA_PSK_AES": 4, + "NET_WIFI_SECURITY_WPA2_PSK_TKIP": 5, + "NET_WIFI_SECURITY_WPA2_PSK_AES": 6, + "NET_WIFI_SECURITY_WPA_ENTERPRISE_TKIP": 7, + "NET_WIFI_SECURITY_WPA_ENTERPRISE_AES": 8, + "NET_WIFI_SECURITY_WPA2_ENTERPRISE_TKIP": 9, + "NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES": 10, + "NET_WIFI_SECURITY_WPA_WPA2_PSK": 11, + "NET_WIFI_SECURITY_WPA_WPA2_ENTERPRISE": 12, + "NET_WIFI_SECURITY_WPA3_PSK_AES": 13, + "NET_WIFI_SECURITY_WPA3_SAE": 14 + }, + "success": true + } } ``` ## *GetWifiState [method](#head.Methods)* -Returns the current Wifi State. The possible Wifi states are as follows. -* `0`: UNINSTALLED - The device was in an installed state and was uninstalled; or, the device does not have a Wifi radio installed -* `1`: DISABLED - The device is installed but not yet enabled -* `2`: DISCONNECTED - The device is installed and enabled, but not yet connected to a network -* `3`: PAIRING - The device is in the process of pairing, but not yet connected to a network -* `4`: CONNECTING - The device is attempting to connect to a network -* `5`: CONNECTED - The device is successfully connected to a network -* `6`: SSID_NOT_FOUND - The requested SSID to connect is not found -* `7`: SSID_CHANGED - The device connected SSID is changed -* `8`: CONNECTION_LOST - The device network connection is lost -* `9`: CONNECTION_FAILED - The device network connection got failed -* `10`: CONNECTION_INTERRUPTED - The device connection is interrupted -* `11`: INVALID_CREDENTIALS - The credentials provided to connect is not valid -* `12`: AUTHENTICATION_FAILED - Authentication process as a whole could not be successfully completed -* `13`: ERROR - The device has encountered an unrecoverable error with the Wifi adapter - -### Events - -No Events +Returns the current Wifi State. The possible Wifi states are as follows. +**Wifi States** +* `0`: WIFI_STATE_UNINSTALLED - The device was in an installed state and was uninstalled; or, the device does not have a Wifi radio installed +* `1`: WIFI_STATE_DISABLED - The device is installed but not yet enabled +* `2`: WIFI_STATE_DISCONNECTED - The device is installed and enabled, but not yet connected to a network +* `3`: WIFI_STATE_PAIRING - The device is in the process of pairing, but not yet connected to a network +* `4`: WIFI_STATE_CONNECTING - The device is attempting to connect to a network +* `5`: WIFI_STATE_CONNECTED - The device is successfully connected to a network +* `6`: WIFI_STATE_SSID_NOT_FOUND - The requested SSID to connect is not found +* `7`: WIFI_STATE_SSID_CHANGED - The device connected SSID is changed +* `8`: WIFI_STATE_CONNECTION_LOST - The device network connection is lost +* `9`: WIFI_STATE_CONNECTION_FAILED - The device connection got failed +* `10`: WIFI_STATE_CONNECTION_INTERRUPTED - The device connection is interrupted +* `11`: WIFI_STATE_INVALID_CREDENTIALS - The credentials provided to connect is not valid +* `12`: WIFI_STATE_AUTHENTICATION_FAILED - Authentication process as a whole could not be successfully completed +* `13`: WIFI_STATE_ERROR - The device has encountered an unrecoverable error with the Wifi adapter. ### Parameters @@ -1874,7 +1782,8 @@ This method takes no parameters. | Name | Type | Description | | :-------- | :-------- | :-------- | | result | object | | -| result.state | integer | The Wifi operational state | +| result.state | integer | The given State | +| result.status | string | WiFi status | | result.success | boolean | Whether the request succeeded | ### Example @@ -1883,9 +1792,9 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "method": "org.rdk.NetworkManager.GetWifiState" + "jsonrpc": "2.0", + "id": 42, + "method": "org.rdk.NetworkManager.1.GetWifiState" } ``` @@ -1893,21 +1802,22 @@ This method takes no parameters. ```json { - "jsonrpc": "2.0", - "id": 42, - "result": { - "state": 2, - "success": true - } + "jsonrpc": "2.0", + "id": 42, + "result": { + "state": 4, + "status": "WIFI_STATE_CONNECTED", + "success": true + } } ``` # Notifications -Notifications are autonomous events, triggered by the internals of the implementation, and broadcasted via JSON-RPC to all registered observers. Refer to [[Thunder](#ref.Thunder)] for information on how to register for a notification. +Notifications are autonomous events triggered by the internals of the implementation and broadcasted via JSON-RPC to all registered observers. Refer to [[Thunder](#ref.Thunder)] for information on how to register for a notification. -The following events are provided by the org.rdk.NetworkManager plugin: +The following events are provided by the org.rdk.NetworkManager interface: NetworkManager interface events: @@ -1921,7 +1831,6 @@ NetworkManager interface events: | [onWiFiStateChange](#event.onWiFiStateChange) | Triggered when WIFI connection state get changed | | [onWiFiSignalStrengthChange](#event.onWiFiSignalStrengthChange) | Triggered when WIFI connection Signal Strength get changed | - ## *onInterfaceStateChange [event](#head.Notifications)* @@ -1940,18 +1849,20 @@ Triggered when an interface state is changed. The possible states are | :-------- | :-------- | :-------- | | params | object | | | params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | -| params.state | string | Current state of the interface | +| params.state | integer | Current state of the interface | +| params.status | string | Current status of the interface | ### Example ```json { - "jsonrpc": "2.0", - "method": "client.events.onInterfaceStateChange", - "params": { - "interface": "wlan0", - "state": "INTERFACE_ADDED" - } + "jsonrpc": "2.0", + "method": "client.events.1.onInterfaceStateChange", + "params": { + "interface": "wlan0", + "state": 1, + "status": "INTERFACE_LINK_UP" + } } ``` @@ -1966,22 +1877,22 @@ Triggered when an IP Address is assigned or lost. | :-------- | :-------- | :-------- | | params | object | | | params.interface | string | An interface, such as `eth0` or `wlan0`, depending upon availability of the given interface | -| params.ipversion | string | It will be IPv4 or IPv6 | -| params.ipaddress | string | The IPv6 or IPv4 address for the interface | -| params.status | string | Whether IP address was acquired or lost (must be one of the following: 'ACQUIRED', 'LOST') (must be one of the following: *`ACQUIRED`*, *`LOST`*) | +| params.ipaddress | string | The IP address | +| params.ipversion | string | Either IPv4 or IPv6 | +| params.status | string | Whether IP address was acquired or lost (must be one of the following: 'ACQUIRED', 'LOST') | ### Example ```json { - "jsonrpc": "2.0", - "method": "client.events.onAddressChange", - "params": { - "interface": "wlan0", - "ipversion": "IPv4", - "ipaddress": "192.168.1.100", - "status": "ACQUIRED" - } + "jsonrpc": "2.0", + "method": "client.events.1.onAddressChange", + "params": { + "interface": "wlan0", + "ipaddress": "192.168.1.101", + "ipversion": "IPv4", + "status": "ACQUIRED" + } } ``` @@ -2002,12 +1913,12 @@ Triggered when the primary/active interface changes, regardless if it's from a s ```json { - "jsonrpc": "2.0", - "method": "client.events.onActiveInterfaceChange", - "params": { - "prevActiveInterface": "wlan0", - "activeInterface": "eth0" - } + "jsonrpc": "2.0", + "method": "client.events.1.onActiveInterfaceChange", + "params": { + "prevActiveInterface": "wlan0", + "activeInterface": "eth0" + } } ``` @@ -2030,14 +1941,14 @@ Triggered when internet connection state changed.The possible internet connectio ```json { - "jsonrpc": "2.0", - "method": "client.events.onInternetStatusChange", - "params": { - "prevState": 0, - "prevStatus": "NO_INTERNET", - "state": 3, - "status": "FULLY_CONNECTED" - } + "jsonrpc": "2.0", + "method": "client.events.1.onInternetStatusChange", + "params": { + "prevState": 1, + "prevStatus": "NO_INTERNET", + "state": 4, + "status": "FULLY_CONNECTED" + } } ``` @@ -2053,66 +1964,53 @@ 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 | signalStrength | -| params.ssids[#].frequency | string | frequency | +| params.ssids[#].ssid | string | Ssid | +| params.ssids[#].security | integer | Security | +| params.ssids[#].strength | string | Strength | +| params.ssids[#].frequency | string | Frequency | ### Example ```json { - "jsonrpc": "2.0", - "method": "client.events.onAvailableSSIDs", - "params": { - "ssids": [ - { - "ssid": "myAP-2.4", - "security": 6, - "strength": "-27.000000", - "frequency": "2.442000" - } - ] - } + "jsonrpc": "2.0", + "method": "client.events.1.onAvailableSSIDs", + "params": { + "ssids": [ + { + "ssid": "myAP-2.4", + "security": 6, + "strength": "-27.000000", + "frequency": "2.442000" + } + ] + } } ``` ## *onWiFiStateChange [event](#head.Notifications)* -Triggered when WIFI connection state get changed. The possible states are, - * '0' - 'WIFI_STATE_UNINSTALLED' - * '1' - 'WIFI_STATE_DISABLED' - * '2' - 'WIFI_STATE_DISCONNECTED' - * '3' - 'WIFI_STATE_PAIRING' - * '4' - 'WIFI_STATE_CONNECTING' - * '5' - 'WIFI_STATE_CONNECTED' - * '6' - 'WIFI_STATE_SSID_NOT_FOUND' - * '7' - 'WIFI_STATE_SSID_CHANGED' - * '8' - 'WIFI_STATE_CONNECTION_LOST' - * '9' - 'WIFI_STATE_CONNECTION_FAILED' - * '10'- 'WIFI_STATE_CONNECTION_INTERRUPTED' - * '11' - 'WIFI_STATE_INVALID_CREDENTIALS' - * '12' - 'WIFI_STATE_AUTHENTICATION_FAILED' - * '13' - 'WIFI_STATE_ERROR' -. +Triggered when WIFI connection state get changed. The possible states are defined in `GetWifiState()`. ### Parameters | Name | Type | Description | | :-------- | :-------- | :-------- | | params | object | | -| params.state | integer | onWiFiStateChange | +| params.state | integer | WiFi State | +| params.status | string | WiFi status | ### Example ```json { - "jsonrpc": "2.0", - "method": "client.events.onWiFiStateChange", - "params": { - "state": 5 - } + "jsonrpc": "2.0", + "method": "client.events.1.onWiFiStateChange", + "params": { + "state": 5, + "status": "WIFI_STATE_CONNECTED" + } } ``` @@ -2127,20 +2025,20 @@ Triggered when WIFI connection Signal Strength get changed. | :-------- | :-------- | :-------- | | params | object | | | params.ssid | string | Signal Strength changed SSID | -| params.signalLevel | string | Signal Strength | -| params.signalQuality | string | Signal quality | +| params.strength | string | Signal Strength | +| params.quality | string | Signal quality | ### Example ```json { - "jsonrpc": "2.0", - "method": "client.events.onWiFiSignalStrengthChange", - "params": { - "ssid": "home-new_123", - "strength": "-27.000000", - "quality": "Excellent" - } + "jsonrpc": "2.0", + "method": "client.events.1.onWiFiSignalStrengthChange", + "params": { + "ssid": "home-new_123", + "strength": "-27.000000", + "quality": "Excellent" + } } ```