From 5ea8e5bcae952afd82201f76f6df6ca3332f1293 Mon Sep 17 00:00:00 2001 From: Karunakaran A <48997923+karuna2git@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:53:12 -0500 Subject: [PATCH 1/4] DELIA-67124 : Handle the JSON Subscribe Event (#65) DELIA-67124 : Handle the JSON Subscribe Event Reason for change: The subscription request reached the NetworkManager and responded but due to the boot-up time no-cpu scenario, the success is NOT sent to consumer. So the consumer subscribes for the 2nd time, it returns already_exist error. It should be handled cleanly. Test Procedure: As per DELIA-67124 Risks: Low Signed-off-by: Karunakaran A --- NetworkManager.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NetworkManager.h b/NetworkManager.h index a2543be..353c34f 100644 --- a/NetworkManager.h +++ b/NetworkManager.h @@ -132,6 +132,14 @@ namespace WPEFramework void Deinitialize(PluginHost::IShell *service) override; string Information() const override; + //override Subscribe from IDispatcher + uint32_t Subscribe(const uint32_t channel, const string& event, const string& designator) override + { + NMLOG_DEBUG("Subscription received for %s event from channelID (%u) with designator as %s", event.c_str(), channel, designator.c_str()); + JSONRPC::Subscribe(channel, event, designator); + return Core::ERROR_NONE; + } + // Do not allow copy/move constructors NetworkManager(const NetworkManager &) = delete; NetworkManager &operator=(const NetworkManager &) = delete; From 304d653fc85003e0758466f69a12d08c25e4480e Mon Sep 17 00:00:00 2001 From: Karunakaran A <48997923+karuna2git@users.noreply.github.com> Date: Sun, 22 Dec 2024 00:22:16 -0500 Subject: [PATCH 2/4] RDKEMW-892 : Replace Printf with NMLOG (#66) Reason for change: Replace Printf with NMLOG Test Procedure: Test `"org.rdk.NetworkManager.GetPublicIP"` Risks: Low Signed-off-by: kamirt573_comcast --- INetworkManager.h | 2 +- NetworkManagerImplementation.cpp | 7 +++- NetworkManagerImplementation.h | 2 +- NetworkManagerJsonRpc.cpp | 2 +- NetworkManagerStunClient.cpp | 66 +++++++++++--------------------- NetworkManagerStunClient.h | 6 +-- 6 files changed, 32 insertions(+), 53 deletions(-) diff --git a/INetworkManager.h b/INetworkManager.h index 254eb06..c1920bb 100644 --- a/INetworkManager.h +++ b/INetworkManager.h @@ -243,7 +243,7 @@ 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 (string &ipversion /* @inout */, 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 count /* @in */, const uint16_t timeout /* @in */, const string guid /* @in */, string& response /* @out */) = 0; diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index 997eaf2..311967f 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -280,7 +280,7 @@ 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 (string &ipversion /* @inout */, string& ipaddress /* @out */) { LOG_ENTRY_FUNCTION(); stun::bind_result result; @@ -289,6 +289,11 @@ namespace WPEFramework 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)) { + if (isIPv6) + ipversion = "IPv6"; + else + ipversion = "IPv4"; + ipaddress = result.public_ip; return Core::ERROR_NONE; } diff --git a/NetworkManagerImplementation.h b/NetworkManagerImplementation.h index 64767f9..8897b7d 100644 --- a/NetworkManagerImplementation.h +++ b/NetworkManagerImplementation.h @@ -197,7 +197,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 (string &ipversion /* @inout */, 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; diff --git a/NetworkManagerJsonRpc.cpp b/NetworkManagerJsonRpc.cpp index 1079443..6628628 100644 --- a/NetworkManagerJsonRpc.cpp +++ b/NetworkManagerJsonRpc.cpp @@ -567,7 +567,6 @@ namespace WPEFramework void NetworkManager::PublishToThunderAboutInternet() { - NMLOG_DEBUG("No public IP persisted yet; Update the data"); if (m_publicIPAddress.empty()) { JsonObject input, output; @@ -576,6 +575,7 @@ namespace WPEFramework if (!m_publicIPAddress.empty()) { + NMLOG_DEBUG("No public IP persisted yet; Update the data"); PluginHost::ISubSystem* subSystem = _service->SubSystems(); if (subSystem != nullptr) diff --git a/NetworkManagerStunClient.cpp b/NetworkManagerStunClient.cpp index 999f14e..1960f0f 100644 --- a/NetworkManagerStunClient.cpp +++ b/NetworkManagerStunClient.cpp @@ -51,7 +51,7 @@ namespace details { int m_fd; }; - #ifdef _STUN_DEBUG +#ifdef _STUN_DEBUG void dump_buffer(char const * prefix, buffer const & buff) { if (prefix) @@ -61,14 +61,7 @@ namespace details { printf("\n"); return; } - #endif - - #ifdef _STUN_DEBUG - #define STUN_TRACE(format, ...) printf("STUN:" format __VA_OPT__(,) __VA_ARGS__) - #else - #define STUN_TRACE(format, ...) - #endif - +#endif void throw_error(char const * format, ...) { @@ -126,7 +119,7 @@ namespace details { details::throw_error("failed to find ip for interface:%s", iface.c_str()); return iface_info; } - STUN_TRACE("local_addr:%s\n", sockaddr_to_string(iface_info).c_str()); + NMLOG_DEBUG("local_addr:%s", sockaddr_to_string(iface_info).c_str()); return iface_info; } @@ -290,7 +283,6 @@ client::client() , m_cache_timeout(30) , m_last_cache_time() , m_last_result() - , m_verbose(true) , m_fd(-1) { } @@ -350,7 +342,7 @@ bool client::bind( dirty = true; } - verbose("client::bind enter: server=%s port=%u iface=%s ipv6=%u timeout=%u cache_timeout=%u dirty=%u\n", + NMLOG_DEBUG("client::bind enter: server=%s port=%u iface=%s ipv6=%u timeout=%u cache_timeout=%u dirty=%u", hostname.c_str(), port, interface.c_str(), proto == stun::protocol::af_inet6, bind_timeout, cache_timeout, dirty); if(m_cache_timeout > 0 /*asking if caching is enabled*/ @@ -360,18 +352,18 @@ bool client::bind( auto time_in_cache = std::chrono::duration_cast( std::chrono::steady_clock::now() - m_last_cache_time); - verbose("client::bind cache time=%lld\n", time_in_cache.count()); + NMLOG_DEBUG("client::bind cache time=%ld", time_in_cache.count()); if(time_in_cache.count() < m_cache_timeout) { result = m_last_result; - verbose("client::bind returning cached result: %s\n", result.public_ip.c_str()); + NMLOG_DEBUG("client::bind returning cached result: %s", result.public_ip.c_str()); return true; } else { - verbose("client::client::bind cached result expired\n"); + NMLOG_DEBUG("client::client::bind cached result expired"); } } @@ -387,7 +379,7 @@ bool client::bind( std::chrono::milliseconds wait_time(interval_wait_time); for (int i = 0; i < num_attempts && total_time < m_bind_timeout; ++i) { - verbose("client::bind sending bind request\n"); + NMLOG_DEBUG("client::bind sending bind request"); std::unique_ptr binding_response = send_binding_request(wait_time); @@ -415,25 +407,25 @@ bool client::bind( m_last_cache_time = std::chrono::steady_clock::now(); - verbose("client::bind success: public_ip=%s\n", result.public_ip.c_str()); + NMLOG_DEBUG("client::bind success: public_ip=%s", result.public_ip.c_str()); ret_ok = true; } else { - verbose("client::bind failed: ip missing from binding response\n"); + NMLOG_DEBUG("client::bind failed: ip missing from binding response"); } } else { - verbose("client::bind failed: no response received from server\n"); + NMLOG_INFO("client::bind failed: no response received from server"); } } } #ifdef __cpp_exceptions catch (std::exception const & err) { - verbose("client::bind failed: %s\n", err.what()); + NMLOG_WARNING("client::bind failed: %s", err.what()); } #endif @@ -454,13 +446,13 @@ void client::create_udp_socket(int inet_family) if (inet_family != AF_INET && inet_family != AF_INET6) details::throw_error("invalid inet family:%d", inet_family); - verbose("creating udp/%s socket\n", details::family_to_string(inet_family)); + NMLOG_DEBUG("creating udp/%s socket", details::family_to_string(inet_family)); int soc = socket(inet_family, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (soc < 0) details::throw_error("error creating socket. %s", strerror(errno)); - #ifdef _SUN_USE_MSGHDR + #ifdef _STUN_USE_MSGHDR int optval = 1; setsockopt(soc, IPPROTO_IP, IP_PKTINFO, &optval, sizeof(int)); #endif @@ -468,7 +460,7 @@ void client::create_udp_socket(int inet_family) if (!m_interface.empty()) { sockaddr_storage local_addr = details::get_interface_address(m_interface, inet_family); - verbose("binding to local interface %s/%s\n", m_interface.c_str(), + NMLOG_DEBUG("binding to local interface %s/%s", m_interface.c_str(), sockaddr_to_string(local_addr).c_str()); int ret = ::bind(soc, reinterpret_cast(&local_addr), details::socket_length(local_addr)); @@ -479,18 +471,16 @@ void client::create_udp_socket(int inet_family) sockaddr_to_string(local_addr).c_str(), strerror(err)); } else { - if (m_verbose) { sockaddr_storage local_endpoint; socklen_t socklen = sizeof(sockaddr_storage); int ret = getsockname(soc, reinterpret_cast(&local_endpoint), &socklen); if (ret == 0) - verbose("local endpoint %s/%d\n", sockaddr_to_string(local_endpoint).c_str(), + NMLOG_DEBUG("local endpoint %s/%d", sockaddr_to_string(local_endpoint).c_str(), details::sockaddr_get_port(local_endpoint)); - } } } else - verbose("no local interface supplied to bind to\n"); + NMLOG_DEBUG("no local interface supplied to bind to"); if (m_fd != -1) close(m_fd); @@ -506,13 +496,13 @@ message * client::send_message(sockaddr_storage const & remote_addr, message con buffer bytes = req.encode(); - STUN_TRACE("remote_addr:%s\n", sockaddr_to_string(remote_addr).c_str()); + NMLOG_DEBUG("remote_addr:%s", sockaddr_to_string(remote_addr).c_str()); #ifdef _STUN_DEBUG details::dump_buffer("STUN >>> ", bytes); #endif - verbose("sending messsage\n"); + NMLOG_DEBUG("sending messsage"); ssize_t n = sendto(m_fd, &bytes[0], bytes.size(), 0, (sockaddr *) &remote_addr, details::socket_length(remote_addr)); if (n < 0) @@ -537,10 +527,10 @@ message * client::send_message(sockaddr_storage const & remote_addr, message con timeout.tv_sec = (timeout.tv_usec / kMicrosecondsPerSecond); timeout.tv_usec -= (timeout.tv_sec * kMicrosecondsPerSecond); } - verbose("waiting for response, timeout set to %lus - %luus\n", timeout.tv_sec, timeout.tv_usec); + NMLOG_DEBUG("waiting for response, timeout set to %lus - %luus", timeout.tv_sec, timeout.tv_usec); int ret = select(m_fd + 1, &rfds, nullptr, nullptr, &timeout); if (ret == 0) { - STUN_TRACE("select timeout out\n"); + NMLOG_DEBUG("select timeout out"); return nullptr; } @@ -608,18 +598,6 @@ message * client::send_message(sockaddr_storage const & remote_addr, message con return decoder::decode_message(bytes, nullptr); } -void client::verbose(char const * format, ...) -{ - if (!m_verbose) - return; - va_list ap; - va_start(ap, format); - printf("STUN:"); - vprintf(format, ap); - va_end(ap); - return; -} - network_access_type client::discover_network_access_type(server const & srv) { std::chrono::milliseconds wait_time(250); @@ -672,7 +650,7 @@ std::unique_ptr client::send_binding_request(std::chrono::milliseconds std::unique_ptr client::send_binding_request(sockaddr_storage const & addr, std::chrono::milliseconds wait_time) { - this->verbose("sending binding request with wait time:%lld ms\n", wait_time.count()); + NMLOG_DEBUG("sending binding request with wait time:%ld ms", wait_time.count()); this->create_udp_socket(addr.ss_family); std::unique_ptr binding_request(message_factory::create_binding_request()); std::unique_ptr binding_response(this->send_message(addr, *binding_request, wait_time)); diff --git a/NetworkManagerStunClient.h b/NetworkManagerStunClient.h index c2f6929..09f093a 100644 --- a/NetworkManagerStunClient.h +++ b/NetworkManagerStunClient.h @@ -8,6 +8,7 @@ #include #include #include +#include "NetworkManagerLogger.h" namespace stun { @@ -157,11 +158,7 @@ class client { network_access_type discover_network_access_type(server const & srv); - inline void set_verbose(bool b) { - m_verbose = b; - } private: - void verbose(char const * format, ...) __attribute__((format(printf, 2, 3))); void create_udp_socket(int inet_family); std::unique_ptr send_binding_request(std::chrono::milliseconds wait_time); @@ -180,7 +177,6 @@ class client { uint16_t m_cache_timeout; std::chrono::time_point m_last_cache_time; bind_result m_last_result; - bool m_verbose; int m_fd; }; From 5d21b7158911346e28634af89d537a3652eaf0fd Mon Sep 17 00:00:00 2001 From: Karunakaran A <48997923+karuna2git@users.noreply.github.com> Date: Mon, 30 Dec 2024 21:25:17 -0500 Subject: [PATCH 3/4] Code Enhancements to the NetworkManager Plugin (#68) Reason for change: Code Enhancements to the NetworkManager Plugin Test Procedure: Sanity Testing Risks: Medium Signed-off-by: Karunakaran A --- CMakeLists.txt | 6 +- INetworkManager.h | 10 +- LegacyPlugin_NetworkAPIs.cpp | 25 +- LegacyPlugin_NetworkAPIs.h | 3 +- LegacyPlugin_WiFiManagerAPIs.cpp | 6 + NetworkManager.cpp | 19 +- NetworkManager.json | 2 +- NetworkManagerImplementation.cpp | 223 +++++++++-------- NetworkManagerImplementation.h | 410 +++++++++++++++++-------------- NetworkManagerJsonRpc.cpp | 14 +- NetworkManagerRDKProxy.cpp | 7 +- 11 files changed, 393 insertions(+), 332 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3670fe9..82961a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,9 +32,9 @@ find_package(${NAMESPACE}Core REQUIRED) find_package(${NAMESPACE}Plugins REQUIRED) find_package(CURL) -set(PLUGIN_NETWORKMANAGER_STARTUPORDER "55" CACHE STRING "To configure startup order of Unified NetworkManager plugin") -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_NETWORKMANAGER_STARTUPORDER "25" CACHE STRING "To configure startup order of Unified NetworkManager plugin") +set(PLUGIN_LEGACY_NW_STARTUPORDER "35" CACHE STRING "To configure startup order of Legacy Network plugin") +set(PLUGIN_LEGACY_WIFI_STARTUPORDER "35" 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}) diff --git a/INetworkManager.h b/INetworkManager.h index c1920bb..90c1076 100644 --- a/INetworkManager.h +++ b/INetworkManager.h @@ -85,7 +85,7 @@ namespace WPEFramework INTERNET_LIMITED /* @text: LIMITED_INTERNET */, INTERNET_CAPTIVE_PORTAL /* @text: CAPTIVE_PORTAL */, INTERNET_FULLY_CONNECTED /* @text: FULLY_CONNECTED */, - INTERNET_UNKNOWN /* @text: NO_INTERNET */, + INTERNET_UNKNOWN /* @text: UNKNOWN */, }; enum WiFiWPS : uint8_t @@ -237,9 +237,9 @@ namespace WPEFramework /* @brief Get Authentication URL if the device is behind Captive Portal */ virtual uint32_t GetCaptivePortalURI(string &uri/* @out */) const = 0; - /* @brief Start The Internet Connectivity Monitoring */ + /* @brief Start The Internet Connectivity Monitoring */ virtual uint32_t StartConnectivityMonitoring(const uint32_t interval /* @in */) = 0; - /* @brief Stop The Internet Connectivity Monitoring */ + /* @brief Stop The Internet Connectivity Monitoring */ virtual uint32_t StopConnectivityMonitoring(void) const = 0; /* @brief Get the Public IP used for external world communication */ @@ -275,8 +275,8 @@ namespace WPEFramework 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 */) = 0; + /* @brief Configure the Network Manager plugin */ + virtual uint32_t Configure(PluginHost::IShell* service /* @in */) = 0; /* @event */ struct EXTERNAL INotification : virtual public Core::IUnknown diff --git a/LegacyPlugin_NetworkAPIs.cpp b/LegacyPlugin_NetworkAPIs.cpp index 1919c3b..9f0068a 100644 --- a/LegacyPlugin_NetworkAPIs.cpp +++ b/LegacyPlugin_NetworkAPIs.cpp @@ -20,7 +20,6 @@ #include "NetworkManagerLogger.h" #include "NetworkManagerJsonEnum.h" - using namespace std; using namespace WPEFramework::Plugin; #define API_VERSION_NUMBER_MAJOR 2 @@ -84,7 +83,6 @@ namespace WPEFramework , m_subsInternetChange(false) { _gNWInstance = this; - m_defaultInterface = "wlan0"; m_timer.connect(std::bind(&Network::subscribeToEvents, this)); registerLegacyMethods(); } @@ -167,7 +165,13 @@ namespace WPEFramework void Network::Deinitialize(PluginHost::IShell* /* service */) { + m_timer.stop(); unregisterLegacyMethods(); + + if (m_networkmanager) + m_networkmanager.reset(); + + m_networkmanager = NULL; m_service->Release(); m_service = nullptr; _gNWInstance = nullptr; @@ -204,7 +208,7 @@ namespace WPEFramework Register("getInternetConnectionState", &Network::getInternetConnectionState, this); Register("ping", &Network::doPing, this); Register("isConnectedToInternet", &Network::isConnectedToInternet, this); - Register("setStunEndPoint", &Network::setStunEndPoint, this); + Register("setStunEndPoint", &Network::setStunEndpoint, this); Register("trace", &Network::doTrace, this); Register("setConnectivityTestEndpoints", &Network::setConnectivityTestEndpoints, this); Register("startConnectivityMonitoring", &Network::startConnectivityMonitoring, this); @@ -219,6 +223,8 @@ namespace WPEFramework */ void Network::unregisterLegacyMethods(void) { + Unregister("getStbIp"); + Unregister("getSTBIPFamily"); Unregister("getInterfaces"); Unregister("isInterfaceEnabled"); Unregister("getPublicIP"); @@ -230,6 +236,8 @@ namespace WPEFramework Unregister("getInternetConnectionState"); Unregister("ping"); Unregister("isConnectedToInternet"); + Unregister("setStunEndPoint"); + Unregister("trace"); Unregister("setConnectivityTestEndpoints"); Unregister("startConnectivityMonitoring"); Unregister("getCaptivePortalURI"); @@ -319,11 +327,11 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { returnJson(rc); } - uint32_t Network::setStunEndPoint(const JsonObject& parameters, JsonObject& response) + uint32_t Network::setStunEndpoint(const JsonObject& parameters, JsonObject& response) { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - string endPoint = parameters["server"].String(); + string endpoint = parameters["server"].String(); uint32_t port = parameters["port"].Number(); uint32_t bindTimeout = parameters["timeout"].Number(); uint32_t cacheTimeout = parameters["cache_timeout"].Number(); @@ -331,7 +339,7 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { auto _nwmgr = m_service->QueryInterfaceByCallsign(NETWORK_MANAGER_CALLSIGN); if (_nwmgr) { - rc = _nwmgr->SetStunEndpoint(endPoint, port, bindTimeout, cacheTimeout); + rc = _nwmgr->SetStunEndpoint(endpoint, port, bindTimeout, cacheTimeout); _nwmgr->Release(); } else @@ -1017,8 +1025,6 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { legacyParams["oldInterfaceName"] = getInterfaceNameToType(parameters["prevActiveInterface"].String()); legacyParams["newInterfaceName"] = getInterfaceNameToType(parameters["currentActiveInterface"].String()); - m_defaultInterface = parameters["currentActiveInterface"].String(); - string json; legacyParams.ToString(json); @@ -1049,9 +1055,6 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { Notify("onIPAddressStatusChanged", legacyParams); - // if ("ACQUIRED" == parameters["status"].String()) - // m_defaultInterface = parameters["interface"].String(); - return; } diff --git a/LegacyPlugin_NetworkAPIs.h b/LegacyPlugin_NetworkAPIs.h index df3019e..d61c045 100644 --- a/LegacyPlugin_NetworkAPIs.h +++ b/LegacyPlugin_NetworkAPIs.h @@ -55,7 +55,7 @@ namespace WPEFramework { uint32_t getCaptivePortalURI(const JsonObject& parameters, JsonObject& response); uint32_t stopConnectivityMonitoring(const JsonObject& parameters, JsonObject& response); uint32_t getPublicIP(const JsonObject& parameters, JsonObject& response); - uint32_t setStunEndPoint(const JsonObject& parameters, JsonObject& response); + uint32_t setStunEndpoint(const JsonObject& parameters, JsonObject& response); uint32_t getStbIp(const JsonObject& parameters, JsonObject& response); uint32_t getSTBIPFamily(const JsonObject& parameters, JsonObject& response); @@ -88,7 +88,6 @@ namespace WPEFramework { PluginHost::IShell* m_service; std::shared_ptr> m_networkmanager; //WPEFramework::Exchange::INetworkManager* m_nwmgr; - string m_defaultInterface; NetworkManagerTimer m_timer; bool m_subsIfaceStateChange; diff --git a/LegacyPlugin_WiFiManagerAPIs.cpp b/LegacyPlugin_WiFiManagerAPIs.cpp index 3369132..0cf50ca 100644 --- a/LegacyPlugin_WiFiManagerAPIs.cpp +++ b/LegacyPlugin_WiFiManagerAPIs.cpp @@ -165,7 +165,13 @@ namespace WPEFramework void WiFiManager::Deinitialize(PluginHost::IShell* /* service */) { + m_timer.stop(); unregisterLegacyMethods(); + + if (m_networkmanager) + m_networkmanager.reset(); + + m_networkmanager = NULL; m_service->Release(); m_service = nullptr; _gWiFiInstance = nullptr; diff --git a/NetworkManager.cpp b/NetworkManager.cpp index c7f3be0..f068565 100644 --- a/NetworkManager.cpp +++ b/NetworkManager.cpp @@ -59,6 +59,7 @@ namespace WPEFramework */ const string NetworkManager::Initialize(PluginHost::IShell *service) { + string message{}; // Make sure everything is null as we expect ASSERT(_service == nullptr); ASSERT(_networkManager == nullptr); @@ -84,20 +85,24 @@ namespace WPEFramework // Still running inside the main WPEFramework process - the child process will have now been spawned and registered if necessary if (_networkManager != nullptr) { - // set the plugin configuration - Exchange::INetworkManager::Logging _loglevel; - _networkManager->Configure(_service->ConfigLine()); + if (_networkManager->Configure(service) != Core::ERROR_NONE) + { + SYSLOG(Logging::Startup, (_T("Configuring NetworkManager"))); + message = _T("NetworkManager failed to configure"); + } - // configure loglevel in libWPEFrameworkNetworkManager.so + // Set the plugin log level + Exchange::INetworkManager::Logging _loglevel; _networkManager->GetLogLevel(_loglevel); NetworkManagerLogger::SetLevel(static_cast (_loglevel)); - + // Register Notifications _networkManager->Register(&_notification); // Register all custom JSON-RPC methods RegisterAllMethods(); + // Get IPlugin interface for this plugin _networkManagerImpl = _networkManager->QueryInterface(); } @@ -109,11 +114,11 @@ namespace WPEFramework _service = nullptr; // Returning a string signals that we failed to initialize - WPEFramework will print this as an error message - return "Failed to initialize NetworkManager"; + message = _T("Failed to initialize NetworkManager"); } // Success - return ""; + return message; } /** diff --git a/NetworkManager.json b/NetworkManager.json index 7636a55..fb9f5c3 100644 --- a/NetworkManager.json +++ b/NetworkManager.json @@ -1242,7 +1242,7 @@ } }, "GetWiFiSignalStrength":{ - "summary": "Get WiFiSignalStrength of connected SSID. The signal quality is identifed based on the signal strength. The possible states are \n* 'Excellent' \n* 'Good' \n* 'Fair' \n* 'Weak' \n* 'Disconnected' \n", + "summary": "Get WiFiSignalStrength of connected SSID. The signal quality is identifed based on the signal strength. The possible states are\n* 'Excellent'\n* 'Good'\n* 'Fair'\n* 'Weak'\n* 'Disconnected'\n", "events":{ "onWiFiSignalStrengthChange" : "Triggered when Wifi signal strength switches between Excellent, Good, Fair, Weak." }, diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index 311967f..81c1749 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -18,7 +18,6 @@ **/ #include "NetworkManagerImplementation.h" -#include "NetworkManagerConnectivity.h" #include "WiFiSignalStrengthMonitor.h" using namespace WPEFramework; @@ -36,15 +35,8 @@ namespace WPEFramework NetworkManagerImplementation::NetworkManagerImplementation() : _notificationCallbacks({}) { - /* Initialize Network Manager */ - NetworkManagerLogger::Init(); - - LOG_ENTRY_FUNCTION(); - /* Name says it all */ - platform_init(); - /* Initialize STUN Endpoints */ - m_stunEndPoint = "stun.l.google.com"; + m_stunEndpoint = "stun.l.google.com"; m_stunPort = 19302; m_stunBindTimeout = 30; m_stunCacheTimeout = 0; @@ -52,6 +44,10 @@ namespace WPEFramework m_publicIP = ""; m_ethConnected = false; m_wlanConnected = false; + + /* Initialize Network Manager */ + NetworkManagerLogger::Init(); + LOG_ENTRY_FUNCTION(); } NetworkManagerImplementation::~NetworkManagerImplementation() @@ -61,6 +57,7 @@ namespace WPEFramework { m_registrationThread.join(); } + connectivityMonitor.stopContinuousConnectivityMonitor(); } /** @@ -102,79 +99,93 @@ namespace WPEFramework return Core::ERROR_NONE; } - uint32_t NetworkManagerImplementation::Configure(const string& configLine /* @in */) + uint32_t NetworkManagerImplementation::Configure(PluginHost::IShell* service) { - if(configLine.empty()) - { - NMLOG_FATAL("config line : is empty !"); - return(Core::ERROR_GENERAL); - } - - NMLOG_DEBUG("config line : %s", configLine.c_str()); + LOG_ENTRY_FUNCTION(); + Configuration config; - Config config; - if(config.FromString(configLine)) + if (service) { - /* stun configuration copy */ - m_stunEndPoint = config.stun.stunEndpoint.Value(); - m_stunPort = config.stun.port.Value(); - m_stunBindTimeout = config.stun.interval.Value(); - - NMLOG_DEBUG("config : stun endpoint %s", m_stunEndPoint.c_str()); - NMLOG_DEBUG("config : stun port %d", m_stunPort); - NMLOG_DEBUG("config : stun interval %d", m_stunBindTimeout); - - NMLOG_DEBUG("config : loglevel %d", config.loglevel.Value()); - NetworkManagerLogger::SetLevel(static_cast (config.loglevel.Value())); - - /* load connectivity monitor endpoints */ - std::vector connectEndpts; - if(!config.connectivityConf.endpoint_1.Value().empty()) { - NMLOG_DEBUG("config : connectivity enpt 1 %s", config.connectivityConf.endpoint_1.Value().c_str()); - connectEndpts.push_back(config.connectivityConf.endpoint_1.Value().c_str()); - } - if(!config.connectivityConf.endpoint_2.Value().empty()) { - NMLOG_DEBUG("config : connectivity enpt 2 %s", config.connectivityConf.endpoint_2.Value().c_str()); - connectEndpts.push_back(config.connectivityConf.endpoint_2.Value().c_str()); - } - if(!config.connectivityConf.endpoint_3.Value().empty()) { - NMLOG_DEBUG("config : connectivity enpt 3 %s", config.connectivityConf.endpoint_3.Value().c_str()); - connectEndpts.push_back(config.connectivityConf.endpoint_3.Value().c_str()); - } - if(!config.connectivityConf.endpoint_4.Value().empty()) { - NMLOG_DEBUG("config : connectivity enpt 4 %s", config.connectivityConf.endpoint_4.Value().c_str()); - connectEndpts.push_back(config.connectivityConf.endpoint_4.Value().c_str()); - } - if(!config.connectivityConf.endpoint_5.Value().empty()) { - NMLOG_DEBUG("config : connectivity enpt 5 %s", config.connectivityConf.endpoint_5.Value().c_str()); - connectEndpts.push_back(config.connectivityConf.endpoint_5.Value().c_str()); - } - - /* check whether the endpoint is already loaded from Cache; if Yes, do not use the one from configuration */ - if (connectivityMonitor.getConnectivityMonitorEndpoints().size() < 1) + string configLine = service->ConfigLine(); + if(configLine.empty()) { - NMLOG_INFO("config : Use the connectivity endpoint from config"); - connectivityMonitor.setConnectivityMonitorEndpoints(connectEndpts); + NMLOG_FATAL("config line : is empty !"); + return Core::ERROR_GENERAL; } - else if (connectEndpts.size() < 1) + else { - 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); + NMLOG_INFO("Loading the incoming configuration : %s", configLine.c_str()); + config.FromString(configLine); } } else - NMLOG_ERROR("Plugin configuration read error !"); + { + NMLOG_FATAL("Service is NULL!"); + return Core::ERROR_GENERAL; + + } + + NetworkManagerLogger::SetLevel(static_cast (config.loglevel.Value())); + NMLOG_DEBUG("loglevel %d", config.loglevel.Value()); + + /* STUN configuration copy */ + m_stunEndpoint = config.stun.stunEndpoint.Value(); + m_stunPort = config.stun.port.Value(); + m_stunBindTimeout = config.stun.interval.Value(); + + NMLOG_INFO("stun endpoint %s", m_stunEndpoint.c_str()); + NMLOG_DEBUG("stun port %d", m_stunPort); + NMLOG_DEBUG("stun interval %d", m_stunBindTimeout); + + /* Connectivity monitor endpoints configuration */ + std::vector connectEndpts; + if(!config.connectivityConf.endpoint_1.Value().empty()) { + NMLOG_INFO("connectivity endpoint 1 %s", config.connectivityConf.endpoint_1.Value().c_str()); + connectEndpts.push_back(config.connectivityConf.endpoint_1.Value().c_str()); + } + if(!config.connectivityConf.endpoint_2.Value().empty()) { + NMLOG_DEBUG("connectivity endpoint 2 %s", config.connectivityConf.endpoint_2.Value().c_str()); + connectEndpts.push_back(config.connectivityConf.endpoint_2.Value().c_str()); + } + if(!config.connectivityConf.endpoint_3.Value().empty()) { + NMLOG_DEBUG("connectivity endpoint 3 %s", config.connectivityConf.endpoint_3.Value().c_str()); + connectEndpts.push_back(config.connectivityConf.endpoint_3.Value().c_str()); + } + if(!config.connectivityConf.endpoint_4.Value().empty()) { + NMLOG_DEBUG("connectivity endpoint 4 %s", config.connectivityConf.endpoint_4.Value().c_str()); + connectEndpts.push_back(config.connectivityConf.endpoint_4.Value().c_str()); + } + if(!config.connectivityConf.endpoint_5.Value().empty()) { + NMLOG_DEBUG("connectivity endpoint 5 %s", config.connectivityConf.endpoint_5.Value().c_str()); + connectEndpts.push_back(config.connectivityConf.endpoint_5.Value().c_str()); + } + + /* 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("Use the connectivity endpoint from config"); + connectivityMonitor.setConnectivityMonitorEndpoints(connectEndpts); + } + else if (connectEndpts.size() < 1) + { + std::vector backup; + NMLOG_INFO("Connectivity endpoints are empty in config; use the default"); + backup.push_back("http://clients3.google.com/generate_204"); + connectivityMonitor.setConnectivityMonitorEndpoints(backup); + } + + /* As all the configuration is set, lets instantiate platform */ + std::thread platformThread = std::thread(&NetworkManagerImplementation::platform_init, this); + platformThread.join(); return(Core::ERROR_NONE); } /* @brief Get STUN Endpoint to be used for identifying Public IP */ - uint32_t NetworkManagerImplementation::GetStunEndpoint (string &endPoint /* @out */, uint32_t& port /* @out */, uint32_t& bindTimeout /* @out */, uint32_t& cacheTimeout /* @out */) const + uint32_t NetworkManagerImplementation::GetStunEndpoint (string &endpoint /* @out */, uint32_t& port /* @out */, uint32_t& bindTimeout /* @out */, uint32_t& cacheTimeout /* @out */) const { LOG_ENTRY_FUNCTION(); - endPoint = m_stunEndPoint; + endpoint = m_stunEndpoint; port = m_stunPort; bindTimeout = m_stunBindTimeout; cacheTimeout = m_stunCacheTimeout; @@ -182,42 +193,52 @@ namespace WPEFramework } /* @brief Set STUN Endpoint to be used to identify Public IP */ - uint32_t NetworkManagerImplementation::SetStunEndpoint (string const endPoint /* @in */, const uint32_t port /* @in */, const uint32_t bindTimeout /* @in */, const uint32_t cacheTimeout /* @in */) + uint32_t NetworkManagerImplementation::SetStunEndpoint (string const endpoint /* @in */, const uint32_t port /* @in */, const uint32_t bindTimeout /* @in */, const uint32_t cacheTimeout /* @in */) { LOG_ENTRY_FUNCTION(); - if (!endPoint.empty()) - m_stunEndPoint = endPoint; - if (port != 0) + if (!endpoint.empty()) + m_stunEndpoint = endpoint; + + if (0 != port) m_stunPort = port; - m_stunBindTimeout = bindTimeout; - m_stunCacheTimeout = cacheTimeout; + if (0 != bindTimeout) + m_stunBindTimeout = bindTimeout; + + if (0 != cacheTimeout) + m_stunCacheTimeout = cacheTimeout; + return Core::ERROR_NONE; } /* @brief Get ConnectivityTest Endpoints */ - uint32_t NetworkManagerImplementation::GetConnectivityTestEndpoints(IStringIterator*& endPoints/* @out */) const + uint32_t NetworkManagerImplementation::GetConnectivityTestEndpoints(IStringIterator*& endpoints/* @out */) const { LOG_ENTRY_FUNCTION(); - std::vector tmpEndPoints = connectivityMonitor.getConnectivityMonitorEndpoints(); - endPoints = (Core::Service::Create(tmpEndPoints)); + std::vector tmpEndpoints = connectivityMonitor.getConnectivityMonitorEndpoints(); + endpoints = (Core::Service::Create(tmpEndpoints)); return Core::ERROR_NONE; } /* @brief Set ConnectivityTest Endpoints */ - uint32_t NetworkManagerImplementation::SetConnectivityTestEndpoints(IStringIterator* const endPoints /* @in */) + uint32_t NetworkManagerImplementation::SetConnectivityTestEndpoints(IStringIterator* const endpoints /* @in */) { LOG_ENTRY_FUNCTION(); - std::vector tmpEndPoints; - if(endPoints) + std::vector tmpEndpoints; + + if(endpoints && (endpoints->Count() >= 1)) { - string endPoint{}; - while (endPoints->Next(endPoint) == true) + string endpoint{}; + while(endpoints->Next(endpoint)) { - tmpEndPoints.push_back(endPoint); + /* The url must be atleast 7 letters to be a valid `http://` url */ + if(!endpoint.empty() && endpoint.size() > 7) + { + tmpEndpoints.push_back(endpoint); + } } - connectivityMonitor.setConnectivityMonitorEndpoints(tmpEndPoints); + connectivityMonitor.setConnectivityMonitorEndpoints(tmpEndpoints); } return Core::ERROR_NONE; } @@ -252,14 +273,14 @@ namespace WPEFramework } /* @brief Get Authentication URL if the device is behind Captive Portal */ - uint32_t NetworkManagerImplementation::GetCaptivePortalURI(string &endPoints/* @out */) const + uint32_t NetworkManagerImplementation::GetCaptivePortalURI(string &uri /* @out */) const { LOG_ENTRY_FUNCTION(); - endPoints = connectivityMonitor.getCaptivePortalURI(); + uri = connectivityMonitor.getCaptivePortalURI(); return Core::ERROR_NONE; } - /* @brief Start The Internet Connectivity Monitoring */ + /* @brief Start The Internet Connectivity Monitoring */ uint32_t NetworkManagerImplementation::StartConnectivityMonitoring(const uint32_t interval/* @in */) { LOG_ENTRY_FUNCTION(); @@ -269,7 +290,7 @@ namespace WPEFramework return Core::ERROR_GENERAL; } - /* @brief Stop The Internet Connectivity Monitoring */ + /* @brief Stop The Internet Connectivity Monitoring */ uint32_t NetworkManagerImplementation::StopConnectivityMonitoring(void) const { LOG_ENTRY_FUNCTION(); @@ -287,7 +308,7 @@ namespace WPEFramework 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)) + if(stunClient.bind(m_stunEndpoint, m_stunPort, m_defaultInterface, proto, m_stunBindTimeout, m_stunCacheTimeout, result)) { if (isIPv6) ipversion = "IPv6"; @@ -577,13 +598,13 @@ namespace WPEFramework void NetworkManagerImplementation::ReportInterfaceStateChange(const Exchange::INetworkManager::InterfaceState state, const string interface) { LOG_ENTRY_FUNCTION(); - if(Exchange::INetworkManager::INTERFACE_LINK_DOWN == state || Exchange::INetworkManager::INTERFACE_REMOVED == state) { - // Start the connectivity monitor with 'false' to indicate the interface is down. - // The monitor will automatically exit after the retry attempts are completed, posting a 'noInternet' event. + if(Exchange::INetworkManager::INTERFACE_LINK_DOWN == state || Exchange::INetworkManager::INTERFACE_REMOVED == state) + { if(interface == "eth0") m_ethConnected = false; - else + else if(interface == "wlan0") m_wlanConnected = false; + connectivityMonitor.startConnectivityMonitor(); } @@ -619,14 +640,15 @@ namespace WPEFramework { LOG_ENTRY_FUNCTION(); 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(); // if ipaddress is aquired means there should be interface connected if(interface == "eth0") m_ethConnected = true; - else if (interface == "wlan0") + else if(interface == "wlan0") m_wlanConnected = true; + + // 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(); } _notificationLock.Lock(); @@ -647,20 +669,21 @@ namespace WPEFramework _notificationLock.Unlock(); } - void NetworkManagerImplementation::ReportAvailableSSIDs(JsonArray &arrayofWiFiScanResults) + void NetworkManagerImplementation::ReportAvailableSSIDs(const JsonArray &arrayofWiFiScanResults) { _notificationLock.Lock(); string jsonOfWiFiScanResults; string jsonOfFilterScanResults; + JsonArray filterResult = arrayofWiFiScanResults; arrayofWiFiScanResults.ToString(jsonOfWiFiScanResults); - NMLOG_DEBUG("Posting onAvailableSSIDs result before Filtering is, %s", jsonOfWiFiScanResults.c_str()); + NMLOG_DEBUG("onAvailableSSIDs Filtering is, %s", jsonOfWiFiScanResults.c_str()); - filterScanResults(arrayofWiFiScanResults); + filterScanResults(filterResult); - arrayofWiFiScanResults.ToString(jsonOfFilterScanResults); + filterResult.ToString(jsonOfFilterScanResults); - NMLOG_INFO("Posting onAvailableSSIDs result is, %s", jsonOfFilterScanResults.c_str()); + NMLOG_INFO("Posting onAvailableSSIDs event as, %s", jsonOfFilterScanResults.c_str()); for (const auto callback : _notificationCallbacks) { callback->onAvailableSSIDs(jsonOfFilterScanResults); } diff --git a/NetworkManagerImplementation.h b/NetworkManagerImplementation.h index 8897b7d..5c9c74e 100644 --- a/NetworkManagerImplementation.h +++ b/NetworkManagerImplementation.h @@ -29,7 +29,6 @@ using namespace std; -//#include #include "INetworkManager.h" #include "NetworkManagerLogger.h" #include "WiFiSignalStrengthMonitor.h" @@ -42,216 +41,247 @@ namespace WPEFramework { class NetworkManagerImplementation : public Exchange::INetworkManager { - enum NetworkEvents { + enum NetworkEvents + { NETMGR_PING, NETMGR_TRACE, }; - class Config : public Core::JSON::Container { - private: - Config(const Config&); - Config& operator=(const Config&); - - public: class ConnectivityConf : public Core::JSON::Container { - public: - ConnectivityConf& operator=(const ConnectivityConf&) = delete; + public: + ConnectivityConf& operator=(const ConnectivityConf&) = delete; - ConnectivityConf() - : Core::JSON::Container() - , endpoint_1(_T("http://clients3.google.com/generate_204")) - , endpoint_2(_T("")) - , endpoint_3(_T("")) - , endpoint_4(_T("")) - , endpoint_5(_T("")) - , ConnectivityCheckInterval(6) - { - Add(_T("endpoint_1"), &endpoint_1); - Add(_T("endpoint_2"), &endpoint_2); - Add(_T("endpoint_3"), &endpoint_3); - Add(_T("endpoint_4"), &endpoint_4); - Add(_T("endpoint_5"), &endpoint_5); - Add(_T("interval"), &ConnectivityCheckInterval); - } - ~ConnectivityConf() override = default; + ConnectivityConf() + : Core::JSON::Container() + , endpoint_1(_T("http://clients3.google.com/generate_204")) + , endpoint_2(_T("")) + , endpoint_3(_T("")) + , endpoint_4(_T("")) + , endpoint_5(_T("")) + , ConnectivityCheckInterval(6) + { + Add(_T("endpoint_1"), &endpoint_1); + Add(_T("endpoint_2"), &endpoint_2); + Add(_T("endpoint_3"), &endpoint_3); + Add(_T("endpoint_4"), &endpoint_4); + Add(_T("endpoint_5"), &endpoint_5); + Add(_T("interval"), &ConnectivityCheckInterval); + } + ~ConnectivityConf() override = default; - public: - /* connectivity configuration */ - Core::JSON::String endpoint_1; - Core::JSON::String endpoint_2; - Core::JSON::String endpoint_3; - Core::JSON::String endpoint_4; - Core::JSON::String endpoint_5; - Core::JSON::DecUInt32 ConnectivityCheckInterval; + public: + /* connectivity configuration */ + Core::JSON::String endpoint_1; + Core::JSON::String endpoint_2; + Core::JSON::String endpoint_3; + Core::JSON::String endpoint_4; + Core::JSON::String endpoint_5; + Core::JSON::DecUInt32 ConnectivityCheckInterval; }; class Stun : public Core::JSON::Container { + public: + Stun& operator=(const Stun&) = delete; + + Stun() + : Core::JSON::Container() + , stunEndpoint(_T("stun.l.google.com")) + , port(19302) + , interval(30) + { + Add(_T("endpoint"), &stunEndpoint); + Add(_T("port"), &port); + Add(_T("interval"), &interval); + } + ~Stun() override = default; + + public: + /* stun configuration */ + Core::JSON::String stunEndpoint; + Core::JSON::DecUInt32 port; + Core::JSON::DecUInt32 interval; + }; + + class WiFiConfig : public Core::JSON::Container + { public: - Stun& operator=(const Stun&) = delete; + Core::JSON::String ssid; + Core::JSON::String password; + Core::JSON::DecUInt8 security; - Stun() - : Core::JSON::Container() - , stunEndpoint(_T("stun.l.google.com")) - , port(19302) - , interval(30) + WiFiConfig() : Core::JSON::Container() { - Add(_T("endpoint"), &stunEndpoint); - Add(_T("port"), &port); - Add(_T("interval"), &interval); + Add(_T("ssid"), &ssid); + Add(_T("password"), &password); + Add(_T("security"), &security); } - ~Stun() override = default; - public: - /* stun configuration */ - Core::JSON::String stunEndpoint; - Core::JSON::DecUInt32 port; - Core::JSON::DecUInt32 interval; + ~WiFiConfig() override = default; + WiFiConfig& operator=(const WiFiConfig&) = delete; + }; + + class Configuration : public Core::JSON::Container { + private: + Configuration(const Configuration&); + Configuration& operator=(const Configuration&); + + public: + Configuration() + : Core::JSON::Container() + { + Add(_T("connectivity"), &connectivityConf); + Add(_T("stun"), &stun); + Add(_T("loglevel"), &loglevel); + } + ~Configuration() override = default; + + public: + ConnectivityConf connectivityConf; + Stun stun; + Core::JSON::DecUInt32 loglevel; }; - public: - Config() - : Core::JSON::Container() + + class Job : public Core::IDispatch { + public: + Job(function work) + : _work(work) { - Add(_T("connectivity"), &connectivityConf); - Add(_T("stun"), &stun); - Add(_T("loglevel"), &loglevel); } - ~Config() override = default; + void Dispatch() override + { + _work(); + } - public: - ConnectivityConf connectivityConf; - Stun stun; - Core::JSON::DecUInt32 loglevel; - }; + private: + function _work; + }; + + public: + NetworkManagerImplementation(); + ~NetworkManagerImplementation() override; + + // Do not allow copy/move constructors + NetworkManagerImplementation(const NetworkManagerImplementation &) = delete; + NetworkManagerImplementation &operator=(const NetworkManagerImplementation &) = delete; + + BEGIN_INTERFACE_MAP(NetworkManagerImplementation) + INTERFACE_ENTRY(Exchange::INetworkManager) + END_INTERFACE_MAP - public: - NetworkManagerImplementation(); - ~NetworkManagerImplementation() override; - - // Do not allow copy/move constructors - NetworkManagerImplementation(const NetworkManagerImplementation &) = delete; - NetworkManagerImplementation &operator=(const NetworkManagerImplementation &) = delete; - - BEGIN_INTERFACE_MAP(NetworkManagerImplementation) - INTERFACE_ENTRY(Exchange::INetworkManager) - END_INTERFACE_MAP - - // Handle Notification registration/removal - uint32_t Register(INetworkManager::INotification *notification) override; - uint32_t Unregister(INetworkManager::INotification *notification) override; - - public: - // Below Control APIs will work with RDK or GNome NW. - /* @brief Get all the Available Interfaces */ - uint32_t GetAvailableInterfaces (IInterfaceDetailsIterator*& interfaces/* @out */) override; - - /* @brief Get the active Interface used for external world communication */ - uint32_t GetPrimaryInterface (string& interface /* @out */) override; - /* @brief Set the active Interface used for external world communication */ - 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; - /* @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(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 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 string& frequency /* @in */, IStringIterator* const ssids/* @in */) override; - uint32_t StopWiFiScan(void) override; - - uint32_t GetKnownSSIDs(IStringIterator*& ssids /* @out */) override; - uint32_t AddToKnownSSIDs(const WiFiConnectTo& ssid /* @in */) override; - uint32_t RemoveKnownSSID(const string& ssid /* @in */) override; - - uint32_t WiFiConnect(const WiFiConnectTo& ssid /* @in */) override; - uint32_t WiFiDisconnect(void) override; - uint32_t GetConnectedSSID(WiFiSSIDInfo& ssidInfo /* @out */) override; - - uint32_t StartWPS(const WiFiWPS& method /* @in */, const string& wps_pin /* @in */) override; - uint32_t StopWPS(void) override; - uint32_t GetWifiState(WiFiState &state) override; - uint32_t GetWiFiSignalStrength(string& ssid /* @out */, string& signalStrength /* @out */, WiFiSignalQuality& quality /* @out */) override; - - uint32_t SetStunEndpoint (string const endPoint /* @in */, const uint32_t port /* @in */, const uint32_t bindTimeout /* @in */, const uint32_t cacheTimeout /* @in */) override; - uint32_t GetStunEndpoint (string &endPoint /* @out */, uint32_t& port /* @out */, uint32_t& bindTimeout /* @out */, uint32_t& cacheTimeout /* @out */) const override; - - /* @brief Get ConnectivityTest Endpoints */ - uint32_t GetConnectivityTestEndpoints(IStringIterator*& endPoints/* @out */) const override; - /* @brief Set ConnectivityTest Endpoints */ - uint32_t SetConnectivityTestEndpoints(IStringIterator* const endPoints /* @in */) override; - - /* @brief Get Internet Connectivty Status */ - 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; - - /* @brief Start The Internet Connectivity Monitoring */ - uint32_t StartConnectivityMonitoring(const uint32_t interval/* @in */) override; - /* @brief Stop The Internet Connectivity Monitoring */ - uint32_t StopConnectivityMonitoring(void) const override; - - /* @brief Get the Public IP used for external world communication */ - uint32_t GetPublicIP (string &ipversion /* @inout */, 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; - - /* @brief Request for trace get the response in as event. The GUID used in the request will be returned in the event. */ - uint32_t Trace (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t noOfRequest /* @in */, const string guid /* @in */, string& response /* @out */) override; - - uint32_t GetSupportedSecurityModes(ISecurityModeIterator*& securityModes /* @out */) const override; - - /* @brief Set the network manager plugin log level */ - 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 */) override; - - /* Events */ - 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(JsonArray &arrayofWiFiScanResults); - void ReportWiFiStateChange(const Exchange::INetworkManager::WiFiState state); - void ReportWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality); - - public: - std::atomic m_ethConnected; - std::atomic m_wlanConnected; - - private: - void platform_init(); - void retryIarmEventRegistration(); - void getInitialConnectionState(); - void threadEventRegistration(); - void executeExternally(NetworkEvents event, const string commandToExecute, string& response); - void filterScanResults(JsonArray &ssids); - - private: - std::list _notificationCallbacks; - Core::CriticalSection _notificationLock; - string m_defaultInterface; - string m_publicIP; - stun::client stunClient; - string m_stunEndPoint; - uint16_t m_stunPort; - uint16_t m_stunBindTimeout; - uint16_t m_stunCacheTimeout; - std::thread m_registrationThread; - string m_filterfrequency; - std::vector m_filterSsidslist; - - public: - WiFiSignalStrengthMonitor m_wifiSignalMonitor; - mutable ConnectivityMonitor connectivityMonitor; + // Handle Notification registration/removal + uint32_t Register(INetworkManager::INotification *notification) override; + uint32_t Unregister(INetworkManager::INotification *notification) override; + + public: + // Below Control APIs will work with RDK or GNome NW. + /* @brief Get all the Available Interfaces */ + uint32_t GetAvailableInterfaces (IInterfaceDetailsIterator*& interfaces/* @out */) override; + + /* @brief Get the active Interface used for external world communication */ + uint32_t GetPrimaryInterface (string& interface /* @out */) override; + /* @brief Set the active Interface used for external world communication */ + 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; + /* @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(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 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 string& frequency /* @in */, IStringIterator* const ssids/* @in */) override; + uint32_t StopWiFiScan(void) override; + + uint32_t GetKnownSSIDs(IStringIterator*& ssids /* @out */) override; + uint32_t AddToKnownSSIDs(const WiFiConnectTo& ssid /* @in */) override; + uint32_t RemoveKnownSSID(const string& ssid /* @in */) override; + + uint32_t WiFiConnect(const WiFiConnectTo& ssid /* @in */) override; + uint32_t WiFiDisconnect(void) override; + uint32_t GetConnectedSSID(WiFiSSIDInfo& ssidInfo /* @out */) override; + + uint32_t StartWPS(const WiFiWPS& method /* @in */, const string& wps_pin /* @in */) override; + uint32_t StopWPS(void) override; + uint32_t GetWifiState(WiFiState &state) override; + uint32_t GetWiFiSignalStrength(string& ssid /* @out */, string& signalStrength /* @out */, WiFiSignalQuality& quality /* @out */) override; + + uint32_t SetStunEndpoint (string const endpoint /* @in */, const uint32_t port /* @in */, const uint32_t bindTimeout /* @in */, const uint32_t cacheTimeout /* @in */) override; + uint32_t GetStunEndpoint (string &endpoint /* @out */, uint32_t& port /* @out */, uint32_t& bindTimeout /* @out */, uint32_t& cacheTimeout /* @out */) const override; + + /* @brief Get ConnectivityTest Endpoints */ + uint32_t GetConnectivityTestEndpoints(IStringIterator*& endpoints/* @out */) const override; + /* @brief Set ConnectivityTest Endpoints */ + uint32_t SetConnectivityTestEndpoints(IStringIterator* const endpoints /* @in */) override; + + /* @brief Get Internet Connectivty Status */ + 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; + + /* @brief Start The Internet Connectivity Monitoring */ + uint32_t StartConnectivityMonitoring(const uint32_t interval/* @in */) override; + /* @brief Stop The Internet Connectivity Monitoring */ + uint32_t StopConnectivityMonitoring(void) const override; + + /* @brief Get the Public IP used for external world communication */ + uint32_t GetPublicIP (string &ipversion /* @inout */, 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; + + /* @brief Request for trace get the response in as event. The GUID used in the request will be returned in the event. */ + uint32_t Trace (const string ipversion /* @in */, const string endpoint /* @in */, const uint32_t noOfRequest /* @in */, const string guid /* @in */, string& response /* @out */) override; + + uint32_t GetSupportedSecurityModes(ISecurityModeIterator*& securityModes /* @out */) const override; + + /* @brief Set the network manager plugin log level */ + uint32_t SetLogLevel(const Logging& level /* @in */) override; + uint32_t GetLogLevel(Logging& level /* @out */) override; + + /* @brief configure network manager plugin */ + uint32_t Configure(PluginHost::IShell* service) override; + + /* Events */ + 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 JsonArray &arrayofWiFiScanResults); + void ReportWiFiStateChange(const Exchange::INetworkManager::WiFiState state); + void ReportWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality); + + private: + void platform_init(void); + void getInitialConnectionState(void); + void executeExternally(NetworkEvents event, const string commandToExecute, string& response); + void threadEventRegistration(void); + void filterScanResults(JsonArray &ssids); + + private: + std::list _notificationCallbacks; + Core::CriticalSection _notificationLock; + string m_defaultInterface; + string m_publicIP; + stun::client stunClient; + string m_stunEndpoint; + uint16_t m_stunPort; + uint16_t m_stunBindTimeout; + uint16_t m_stunCacheTimeout; + std::thread m_registrationThread; + string m_filterfrequency; + std::vector m_filterSsidslist; + + public: + std::atomic m_ethConnected; + std::atomic m_wlanConnected; + WiFiSignalStrengthMonitor m_wifiSignalMonitor; + mutable ConnectivityMonitor connectivityMonitor; }; } } diff --git a/NetworkManagerJsonRpc.cpp b/NetworkManagerJsonRpc.cpp index 6628628..6942302 100644 --- a/NetworkManagerJsonRpc.cpp +++ b/NetworkManagerJsonRpc.cpp @@ -360,19 +360,19 @@ namespace WPEFramework { LOG_INPARAM(); uint32_t rc = Core::ERROR_GENERAL; - string endPoint; + string endpoint; uint32_t port; uint32_t timeout; uint32_t cacheLifetime; if (_networkManager) - rc = _networkManager->GetStunEndpoint(endPoint, port, timeout, cacheLifetime); + 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["timeout"] = timeout; response["cacheLifetime"] = cacheLifetime; @@ -384,13 +384,13 @@ namespace WPEFramework { 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["timeout"].Number(); uint32_t cacheTimeout = parameters["cacheLifetime"].Number(); if (_networkManager) - rc = _networkManager->SetStunEndpoint(endPoint, port, bindTimeout, cacheTimeout); + rc = _networkManager->SetStunEndpoint(endpoint, port, bindTimeout, cacheTimeout); else rc = Core::ERROR_UNAVAILABLE; @@ -583,8 +583,8 @@ namespace WPEFramework const PluginHost::ISubSystem::IInternet* internet(subSystem->Get()); if (nullptr == internet) { + NMLOG_INFO("Setting INTERNET ISubSystem"); subSystem->Set(PluginHost::ISubSystem::INTERNET, this); - NMLOG_INFO("Set INTERNET ISubSystem"); } subSystem->Release(); @@ -632,7 +632,7 @@ namespace WPEFramework reply.FromString(result); response = reply; } - returnJson(rc); + return rc; } uint32_t NetworkManager::Trace(const JsonObject& parameters, JsonObject& response) diff --git a/NetworkManagerRDKProxy.cpp b/NetworkManagerRDKProxy.cpp index 4578571..69955ae 100644 --- a/NetworkManagerRDKProxy.cpp +++ b/NetworkManagerRDKProxy.cpp @@ -537,11 +537,6 @@ namespace WPEFramework NMLOG_WARNING("WARNING - cannot handle IARM events without a Network plugin instance!"); } - void NetworkManagerImplementation::retryIarmEventRegistration() - { - m_registrationThread = thread(&NetworkManagerImplementation::threadEventRegistration, this); - - } void NetworkManagerImplementation::threadEventRegistration() { IARM_Result_t res = IARM_RESULT_SUCCESS; @@ -658,7 +653,7 @@ namespace WPEFramework { string msg = "NetSrvMgr is not available"; NMLOG_INFO("NETWORK_NOT_READY: The NetSrvMgr Component is not available.Retrying in separate thread ::%s::", msg.c_str()); - retryIarmEventRegistration(); + m_registrationThread = thread(&NetworkManagerImplementation::threadEventRegistration, this); } else { IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS, NetworkManagerInternalEventHandler); From a1964151d76c7b2913942d695e076e9b7c349928 Mon Sep 17 00:00:00 2001 From: Karunakaran A Date: Mon, 30 Dec 2024 21:35:47 -0500 Subject: [PATCH 4/4] Release of v0.7.0 Signed-off-by: Karunakaran A --- CHANGELOG.md | 10 ++++++++++ CMakeLists.txt | 2 +- NetworkManager.json | 2 +- docs/NetworkManagerPlugin.md | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ffd188..018968f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,16 @@ All notable changes to this RDK Service will be documented in this file. * Changes in CHANGELOG should be updated when commits are added to the main or release branches. There should be one CHANGELOG entry per JIRA Ticket. This is not enforced on sprint branches since there could be multiple changes for the same JIRA ticket during development. +## [0.7.0] - 2024-12-30 +### Added +- Gnome WPS custom design implemented +- Handle interface status based on IPAddress change event +- Cleanup STUN client codebase +- Handle JSON Event Subscription +- Handle Platform Init and Configure functions of out-of-process +- Handle the startup order +- Added L1 test cases for the plugins + ## [0.6.0] - 2024-12-10 ### Added - Added specific SSID/frequency scanning diff --git a/CMakeLists.txt b/CMakeLists.txt index 82961a4..363463c 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 6) +set(VERSION_MINOR 7) set(VERSION_PATCH 0) add_compile_definitions(NETWORKMANAGER_MAJOR_VERSION=${VERSION_MAJOR}) diff --git a/NetworkManager.json b/NetworkManager.json index fb9f5c3..028586d 100644 --- a/NetworkManager.json +++ b/NetworkManager.json @@ -9,7 +9,7 @@ "status": "development", "description": "A Unified `NetworkManager` plugin that allows you to manage Ethernet and Wifi interfaces on the device.", "sourcelocation": "https://github.com/rdkcentral/networkmanager/blob/main/NetworkManager.json", - "version": "0.6.0" + "version": "0.7.0" }, "definitions": { "success": { diff --git a/docs/NetworkManagerPlugin.md b/docs/NetworkManagerPlugin.md index 8c6b3f3..61b3ea5 100644 --- a/docs/NetworkManagerPlugin.md +++ b/docs/NetworkManagerPlugin.md @@ -2,7 +2,7 @@ # NetworkManager Plugin -**Version: 0.6.0** +**Version: 0.7.0** **Status: :white_circle::white_circle::white_circle:** @@ -23,7 +23,7 @@ org.rdk.NetworkManager interface for Thunder framework. ## Scope -This document describes purpose and functionality of the org.rdk.NetworkManager interface (version 0.6.0). It includes detailed specification about its methods provided and notifications sent. +This document describes purpose and functionality of the org.rdk.NetworkManager interface (version 0.7.0). It includes detailed specification about its methods provided and notifications sent. ## Case Sensitivity