From a417f70f9f81956b772131688a0fc0e3b17081e7 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:51:48 -0500 Subject: [PATCH 01/32] Add files via upload --- UpnpDiscoveryManager.cpp | 146 +++++++++++++++++++++++++++++++++++++++ UpnpDiscoveryManager.h | 66 ++++++++++++++++++ 2 files changed, 212 insertions(+) create mode 100644 UpnpDiscoveryManager.cpp create mode 100644 UpnpDiscoveryManager.h diff --git a/UpnpDiscoveryManager.cpp b/UpnpDiscoveryManager.cpp new file mode 100644 index 00000000..7967bfa0 --- /dev/null +++ b/UpnpDiscoveryManager.cpp @@ -0,0 +1,146 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 RDK Management +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +#include +#include +#include +#include "UpnpDiscoveryManager.h" + +std::string const UpnpDiscoveryManager::m_deviceInternetGateway = "urn:schemas-upnp-org:device:InternetGatewayDevice:1"; + +UpnpDiscoveryManager::UpnpDiscoveryManager() +{ + m_mainLoop = g_main_loop_new(NULL, FALSE); + + //Create timeout threads to handle telemetry logging + g_timeout_add_seconds (LOGGING_PERIOD_IN_SEC, GSourceFunc(&UpnpDiscoveryManager::logTelemetry), this); + + // pthread_mutex_init(&mutex, NULL); + m_thread_upnp = g_thread_new("thread_gmain", UpnpDiscoveryManager::runMainLoop, this); +} + +UpnpDiscoveryManager::~UpnpDiscoveryManager() +{ + if (m_controlPoint) + g_object_unref(m_controlPoint); + if (m_context) + g_object_unref(m_context); + if (m_mainLoop) + { + g_main_loop_quit(m_mainLoop); + g_main_loop_unref(m_mainLoop); + } +} + +void UpnpDiscoveryManager::initialiseUpnp(const std::string& interface) +{ + GError *error = NULL; + // Create a gupnp context + m_context = gupnp_context_new(interface.c_str(), 0, &error); + if (!m_context) { + LOG_ERR("Error creating Upnp context: %s", error->message); + g_clear_error(&error); + } + + // Create a control point for InternetGatewayDevice + m_controlPoint = gupnp_control_point_new(m_context, m_deviceInternetGateway.c_str()); + if (!m_controlPoint) { + LOG_ERR("Error creating control point"); + } + + // Connects a callback function to a signal for InternetGatewayDevice + g_signal_connect(m_controlPoint, "device-proxy-available", + G_CALLBACK(&UpnpDiscoveryManager::deviceProxyAvailableCallback), this); +} + +void* UpnpDiscoveryManager::runMainLoop(void *arg) +{ + g_main_loop_run(((UpnpDiscoveryManager *)arg)->m_mainLoop); +} + +gboolean UpnpDiscoveryManager::logTelemetry(void *arg) +{ + std::lock_guard lock(((UpnpDiscoveryManager *)arg)->m_apMutex); + //T2 telemtery logging + LOG_INFO("TELEMETRY_UPNP_GATEWAY_DETAILS: %s", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str()); + return TRUE; +} + +void UpnpDiscoveryManager::findGatewayDevice(const std::string& interface) +{ + clearUpnpExistingRequests(); + + //Initialise gupnp context + initialiseUpnp(interface); + + // Start discovery to find InternetGatewayDevice + if (TRUE != gssdp_resource_browser_get_active(GSSDP_RESOURCE_BROWSER(m_controlPoint))) + { + LOG_INFO("Searching for InternetGatewayDevice"); + gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(m_controlPoint), TRUE); + } +} + +void UpnpDiscoveryManager::clearUpnpExistingRequests() +{ + if (m_controlPoint) + { + stopSearchGatewayDevice(); + g_object_unref(m_controlPoint); + } + if (m_context) + g_object_unref(m_context); +} + +void UpnpDiscoveryManager::on_device_proxy_available(GUPnPControlPoint *controlPoint, GUPnPDeviceProxy *proxy) +{ + m_apMake = gupnp_device_info_get_manufacturer(GUPNP_DEVICE_INFO(proxy)); + m_apModelName = gupnp_device_info_get_model_name(GUPNP_DEVICE_INFO(proxy)); + m_apModelNumber = gupnp_device_info_get_model_number(GUPNP_DEVICE_INFO(proxy)); + m_apMake = m_apMake.substr(0, m_apMake.find(',')); + LOG_INFO("Connected to Gateway: %s, %s, %s", m_apMake.c_str(), m_apModelName.c_str(), m_apModelNumber.c_str()); + // Stop discovery to find InternetGatewayDevice + stopSearchGatewayDevice(); + std::lock_guard lock(m_apMutex); + m_gatewayDetails.str(""); + m_gatewayDetails.clear(); + m_gatewayDetails << "make=" << m_apMake << ",model_name=" << m_apModelName << ",model_number=" << m_apModelNumber; +} + +void UpnpDiscoveryManager::stopSearchGatewayDevice() +{ + LOG_INFO("Stop searching for InternetGatewayDevice"); + if (TRUE == gssdp_resource_browser_get_active(GSSDP_RESOURCE_BROWSER(m_controlPoint))) + { + gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(m_controlPoint), FALSE); + } +} + +int main() +{ + UpnpDiscoveryManager* obj = UpnpDiscoveryManager::getInstance(); + //Fetch the gateway details + obj->findGatewayDevice("en0"); + LOG_INFO("AM HERE"); + while(true) + { + sleep(10); + } +} + diff --git a/UpnpDiscoveryManager.h b/UpnpDiscoveryManager.h new file mode 100644 index 00000000..7855a6de --- /dev/null +++ b/UpnpDiscoveryManager.h @@ -0,0 +1,66 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 RDK Management +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ +#ifndef __UPNP_H__ +#define __UPNP_H__ + +#include +#include +#include + +#define LOG_ERR(msg, ...) g_printerr("[%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__) +#define LOG_INFO(msg, ...) g_printerr("[%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__) + +class UpnpDiscoveryManager +{ +public: + static UpnpDiscoveryManager* getInstance() + { + static UpnpDiscoveryManager instance; + return &instance; + } + void findGatewayDevice(const std::string& interface); + UpnpDiscoveryManager(const UpnpDiscoveryManager&) = delete; + void operator=(const UpnpDiscoveryManager&) = delete; + +private: + UpnpDiscoveryManager(); + ~UpnpDiscoveryManager(); + void initialiseUpnp(const std::string& interface); + void clearUpnpExistingRequests(); + static void* runMainLoop(void *arg); + static gboolean logTelemetry(void* arg); + void stopSearchGatewayDevice(); + void on_device_proxy_available(GUPnPControlPoint *control_point, GUPnPDeviceProxy *proxy); + static void deviceProxyAvailableCallback(GUPnPControlPoint *control_point, GUPnPDeviceProxy *proxy, gpointer user_data) { + auto *self = static_cast(user_data); + self->on_device_proxy_available(control_point, proxy); + } + GUPnPContext* m_context; + GUPnPControlPoint* m_controlPoint; + GMainLoop* m_mainLoop; + GThread * m_thread_upnp; + std::string m_apMake; + std::string m_apModelName; + std::string m_apModelNumber; + std::ostringstream m_gatewayDetails; + std::mutex m_apMutex; + static std::string const m_deviceInternetGateway; + static const int LOGGING_PERIOD_IN_SEC = 2; //15min * 60 +}; +#endif From 74478f70e5b8f10b36bcba9ce3639e217c364843 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:53:49 -0500 Subject: [PATCH 02/32] Update CMakeLists.txt --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f777c83..3bbe5f91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,10 @@ pkg_check_modules(GLIB REQUIRED glib-2.0) pkg_check_modules(LIBNM REQUIRED libnm) pkg_check_modules(GLIB REQUIRED gio-2.0) else() +pkg_check_modules(GLIB REQUIRED glib-2.0) +pkg_check_modules(LIBSOUP REQUIRED libsoup-2.4) +pkg_check_modules(GUPNP REQUIRED gupnp-1.0) +pkg_check_modules(GSSDP REQUIRED gssdp-1.2) find_package(IARMBus REQUIRED) endif () @@ -107,6 +111,7 @@ add_library(${MODULE_NAME} SHARED NetworkManagerStunClient.cpp WiFiSignalStrengthMonitor.cpp Module.cpp + UpnpDiscoveryManager.cpp ${PROXY_STUB_SOURCES}) target_link_libraries(${MODULE_NAME} PRIVATE From 2a305bb32fa946238272c1b3764bfcdd0897501a Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:09:17 -0500 Subject: [PATCH 03/32] Update CMakeLists.txt --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bbe5f91..b55797e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,8 +62,8 @@ pkg_check_modules(GLIB REQUIRED glib-2.0) pkg_check_modules(LIBNM REQUIRED libnm) pkg_check_modules(GLIB REQUIRED gio-2.0) else() -pkg_check_modules(GLIB REQUIRED glib-2.0) pkg_check_modules(LIBSOUP REQUIRED libsoup-2.4) +pkg_check_modules(GLIB REQUIRED glib-2.0) pkg_check_modules(GUPNP REQUIRED gupnp-1.0) pkg_check_modules(GSSDP REQUIRED gssdp-1.2) find_package(IARMBus REQUIRED) @@ -111,8 +111,10 @@ add_library(${MODULE_NAME} SHARED NetworkManagerStunClient.cpp WiFiSignalStrengthMonitor.cpp Module.cpp - UpnpDiscoveryManager.cpp + UpnpDiscoveryManager.cpp ${PROXY_STUB_SOURCES}) + target_include_directories(${MODULE_NAME} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBSOUP_INCLUDE_DIRS} ${GUPNP_INCLUDE_DIRS} ${GSSDP_INCLUDE_DIRS}) + target_link_libraries(${MODULE_NAME} PRIVATE ${GLIB_LIBRARIES} ${LIBSOUP_LIBRARIES} ${GUPNP_LIBRARIES} ${GSSDP_LIBRARIES}) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Core::${NAMESPACE}Core From f64bfe0259cbff8700ea3c241180c82b59740862 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:10:35 -0500 Subject: [PATCH 04/32] Update UpnpDiscoveryManager.h --- UpnpDiscoveryManager.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/UpnpDiscoveryManager.h b/UpnpDiscoveryManager.h index 7855a6de..af1d2948 100644 --- a/UpnpDiscoveryManager.h +++ b/UpnpDiscoveryManager.h @@ -20,6 +20,7 @@ #define __UPNP_H__ #include +#include #include #include @@ -29,18 +30,11 @@ class UpnpDiscoveryManager { public: - static UpnpDiscoveryManager* getInstance() - { - static UpnpDiscoveryManager instance; - return &instance; - } void findGatewayDevice(const std::string& interface); - UpnpDiscoveryManager(const UpnpDiscoveryManager&) = delete; - void operator=(const UpnpDiscoveryManager&) = delete; + UpnpDiscoveryManager(); + ~UpnpDiscoveryManager(); private: - UpnpDiscoveryManager(); - ~UpnpDiscoveryManager(); void initialiseUpnp(const std::string& interface); void clearUpnpExistingRequests(); static void* runMainLoop(void *arg); From 30768fb8729a930023b59805169186af4b3ba6c7 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:11:12 -0500 Subject: [PATCH 05/32] Update UpnpDiscoveryManager.cpp --- UpnpDiscoveryManager.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/UpnpDiscoveryManager.cpp b/UpnpDiscoveryManager.cpp index 7967bfa0..1ec6689a 100644 --- a/UpnpDiscoveryManager.cpp +++ b/UpnpDiscoveryManager.cpp @@ -131,16 +131,3 @@ void UpnpDiscoveryManager::stopSearchGatewayDevice() gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(m_controlPoint), FALSE); } } - -int main() -{ - UpnpDiscoveryManager* obj = UpnpDiscoveryManager::getInstance(); - //Fetch the gateway details - obj->findGatewayDevice("en0"); - LOG_INFO("AM HERE"); - while(true) - { - sleep(10); - } -} - From f650d7e60765c2674c8a41ff1f9b96dd281ea8f8 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:12:15 -0500 Subject: [PATCH 06/32] Update NetworkManagerImplementation.h --- NetworkManagerImplementation.h | 1 + 1 file changed, 1 insertion(+) diff --git a/NetworkManagerImplementation.h b/NetworkManagerImplementation.h index 16fd2f79..a76eda88 100644 --- a/NetworkManagerImplementation.h +++ b/NetworkManagerImplementation.h @@ -276,6 +276,7 @@ namespace WPEFramework std::atomic m_ethConnected; std::atomic m_wlanConnected; WiFiSignalStrengthMonitor m_wifiSignalMonitor; + UpnpDiscoveryManager m_upnpDiscoveryManager; mutable ConnectivityMonitor connectivityMonitor; }; } From fd64c40fd3f179b80101af9d0e10a35db1a6d526 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:13:07 -0500 Subject: [PATCH 07/32] Update NetworkManagerImplementation.cpp --- NetworkManagerImplementation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index fc1bfda8..ebd7e2cf 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -675,6 +675,7 @@ namespace WPEFramework { m_wlanConnected = true; m_wifiSignalMonitor.startWiFiSignalStrengthMonitor(DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC); + m_upnpDiscoveryManager.findGatewayDevice("wlan0"); } else m_wlanConnected = false; /* Any other state is considered as WiFi not connected. */ From 9da5851d30cec9eb29ca7eed5c9e22d22e464487 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:14:19 -0500 Subject: [PATCH 08/32] Update NetworkManagerImplementation.cpp --- NetworkManagerImplementation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index ebd7e2cf..9a5c3c93 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -675,6 +675,7 @@ namespace WPEFramework { m_wlanConnected = true; m_wifiSignalMonitor.startWiFiSignalStrengthMonitor(DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC); + NMLOG_ERROR("MYTEST: Calling findGatewayDevice"); m_upnpDiscoveryManager.findGatewayDevice("wlan0"); } else From 3d8fb4f2704f51c3954bd9be53bbe2de29976cd3 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:05:19 -0500 Subject: [PATCH 09/32] Update UpnpDiscoveryManager.cpp --- UpnpDiscoveryManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UpnpDiscoveryManager.cpp b/UpnpDiscoveryManager.cpp index 1ec6689a..29a55e6a 100644 --- a/UpnpDiscoveryManager.cpp +++ b/UpnpDiscoveryManager.cpp @@ -52,7 +52,7 @@ void UpnpDiscoveryManager::initialiseUpnp(const std::string& interface) { GError *error = NULL; // Create a gupnp context - m_context = gupnp_context_new(interface.c_str(), 0, &error); + m_context = gupnp_context_new(NULL, interface.c_str(), 0, &error); if (!m_context) { LOG_ERR("Error creating Upnp context: %s", error->message); g_clear_error(&error); From ade9bfdf03a15f56733c515660ea24af11c7a89d Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:34:20 -0500 Subject: [PATCH 10/32] Update NetworkManagerImplementation.h --- NetworkManagerImplementation.h | 1 + 1 file changed, 1 insertion(+) diff --git a/NetworkManagerImplementation.h b/NetworkManagerImplementation.h index a76eda88..dccbb612 100644 --- a/NetworkManagerImplementation.h +++ b/NetworkManagerImplementation.h @@ -34,6 +34,7 @@ using namespace std; #include "WiFiSignalStrengthMonitor.h" #include "NetworkManagerConnectivity.h" #include "NetworkManagerStunClient.h" +#include "UpnpDiscoveryManager.h" namespace WPEFramework { From 000b14665627a137c696f38a5e1dcc46ccb60c2b Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:54:52 -0500 Subject: [PATCH 11/32] Update NetworkManagerRDKProxy.cpp --- NetworkManagerRDKProxy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NetworkManagerRDKProxy.cpp b/NetworkManagerRDKProxy.cpp index 890d8543..631354bc 100644 --- a/NetworkManagerRDKProxy.cpp +++ b/NetworkManagerRDKProxy.cpp @@ -545,9 +545,9 @@ namespace WPEFramework oldInterface = e->oldInterface; newInterface = e->newInterface; NMLOG_INFO ("IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE %s :: %s..", oldInterface.c_str(), newInterface.c_str()); - if(oldInterface != "eth0" || oldInterface != "wlan0") + if(oldInterface != "eth0" && oldInterface != "wlan0") oldInterface = ""; /* assigning "null" if the interface is not eth0 or wlan0 */ - if(newInterface != "eth0" || newInterface != "wlan0") + if(newInterface != "eth0" && newInterface != "wlan0") newInterface = ""; /* assigning "null" if the interface is not eth0 or wlan0 */ ::_instance->ReportActiveInterfaceChange(oldInterface, newInterface); From 79f15d3226a7a4384d898dea0055d2f85b8b8c2a Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:58:18 -0500 Subject: [PATCH 12/32] Update NetworkManagerImplementation.cpp --- NetworkManagerImplementation.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index 9a5c3c93..0fc0995a 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -599,6 +599,9 @@ namespace WPEFramework m_ethConnected = true; else if (currentActiveinterface == "wlan0") m_wlanConnected = true; + + NMLOG_ERROR("MYTEST: Calling findGatewayDevice"); + m_upnpDiscoveryManager.findGatewayDevice(currentActiveinterface); // FIXME : This could be the place to define `m_defaultInterface` to incoming `currentActiveinterface`. // m_defaultInterface = currentActiveinterface; @@ -675,8 +678,6 @@ namespace WPEFramework { m_wlanConnected = true; m_wifiSignalMonitor.startWiFiSignalStrengthMonitor(DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC); - NMLOG_ERROR("MYTEST: Calling findGatewayDevice"); - m_upnpDiscoveryManager.findGatewayDevice("wlan0"); } else m_wlanConnected = false; /* Any other state is considered as WiFi not connected. */ From 102a38f522294aa56c6b0763427f0a648fd0ad99 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:09:01 -0500 Subject: [PATCH 13/32] Update NetworkManagerImplementation.cpp --- NetworkManagerImplementation.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index 0fc0995a..eb6133cb 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -596,12 +596,13 @@ namespace WPEFramework NMLOG_INFO("Posting onActiveInterfaceChange %s", currentActiveinterface.c_str()); if(currentActiveinterface == "eth0") + { m_ethConnected = true; + NMLOG_ERROR("MYTEST: Calling findGatewayDevice for eth0"); + m_upnpDiscoveryManager.findGatewayDevice("eth0"); + } else if (currentActiveinterface == "wlan0") m_wlanConnected = true; - - NMLOG_ERROR("MYTEST: Calling findGatewayDevice"); - m_upnpDiscoveryManager.findGatewayDevice(currentActiveinterface); // FIXME : This could be the place to define `m_defaultInterface` to incoming `currentActiveinterface`. // m_defaultInterface = currentActiveinterface; @@ -678,6 +679,8 @@ namespace WPEFramework { m_wlanConnected = true; m_wifiSignalMonitor.startWiFiSignalStrengthMonitor(DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC); + NMLOG_ERROR("MYTEST: Calling findGatewayDevice for wlan0"); + m_upnpDiscoveryManager.findGatewayDevice("wlan0"); } else m_wlanConnected = false; /* Any other state is considered as WiFi not connected. */ From a921d2e81b5a47db6fbfa54f20aae664cb73d0b3 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Fri, 7 Feb 2025 12:02:19 -0500 Subject: [PATCH 14/32] Update NetworkManagerImplementation.cpp --- NetworkManagerImplementation.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index eb6133cb..3686629e 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -596,11 +596,7 @@ namespace WPEFramework NMLOG_INFO("Posting onActiveInterfaceChange %s", currentActiveinterface.c_str()); if(currentActiveinterface == "eth0") - { m_ethConnected = true; - NMLOG_ERROR("MYTEST: Calling findGatewayDevice for eth0"); - m_upnpDiscoveryManager.findGatewayDevice("eth0"); - } else if (currentActiveinterface == "wlan0") m_wlanConnected = true; @@ -631,6 +627,8 @@ namespace WPEFramework m_defaultInterface = interface; connectivityMonitor.switchToInitialCheck(); + NMLOG_ERROR("MYTEST: Calling findGatewayDevice for %s", interface.c_str()); + m_upnpDiscoveryManager.findGatewayDevice("interface"); } _notificationLock.Lock(); From 8ddd76449f2a6f76593de176ccacc8a391d7fbc1 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Mon, 10 Feb 2025 13:29:51 -0500 Subject: [PATCH 15/32] Update UpnpDiscoveryManager.cpp --- UpnpDiscoveryManager.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/UpnpDiscoveryManager.cpp b/UpnpDiscoveryManager.cpp index 29a55e6a..3785dbef 100644 --- a/UpnpDiscoveryManager.cpp +++ b/UpnpDiscoveryManager.cpp @@ -31,8 +31,8 @@ UpnpDiscoveryManager::UpnpDiscoveryManager() //Create timeout threads to handle telemetry logging g_timeout_add_seconds (LOGGING_PERIOD_IN_SEC, GSourceFunc(&UpnpDiscoveryManager::logTelemetry), this); - // pthread_mutex_init(&mutex, NULL); - m_thread_upnp = g_thread_new("thread_gmain", UpnpDiscoveryManager::runMainLoop, this); + m_threadUpnp = g_thread_new("thread_upnp", UpnpDiscoveryManager::runUpnp, this); + m_threadGmain = g_thread_new("thread_gmain", UpnpDiscoveryManager::runMainLoop, this); } UpnpDiscoveryManager::~UpnpDiscoveryManager() @@ -48,6 +48,32 @@ UpnpDiscoveryManager::~UpnpDiscoveryManager() } } +void UpnpDiscoveryManager::startUpnpDiscovery(const std::string& interface) +{ + std::lock_guard lock(m_upnpCvMutex); + m_interface = interface; + m_upnpReady = true; + m_upnpCv.notify_one(); +} + +void* UpnpDiscoveryManager::runUpnp(void *arg) +{ + UpnpDiscoveryManager* manager = static_cast(arg); + int timeoutInMin = 30; + while(true) + { + std::unique_lock lock(manager->m_upnpCvMutex); + if (manager->m_upnpCv.wait_for(lock, std::chrono::minutes(timeoutInMin)) == std::cv_status::timeout) { + LOG_INFO("upnp run thread timeout"); + } + if (manager->m_upnpReady) + { + manager->findGatewayDevice(manager->m_interface); + manager->m_upnpReady = false; + } + } +} + void UpnpDiscoveryManager::initialiseUpnp(const std::string& interface) { GError *error = NULL; @@ -69,6 +95,7 @@ void UpnpDiscoveryManager::initialiseUpnp(const std::string& interface) G_CALLBACK(&UpnpDiscoveryManager::deviceProxyAvailableCallback), this); } + void* UpnpDiscoveryManager::runMainLoop(void *arg) { g_main_loop_run(((UpnpDiscoveryManager *)arg)->m_mainLoop); @@ -84,6 +111,7 @@ gboolean UpnpDiscoveryManager::logTelemetry(void *arg) void UpnpDiscoveryManager::findGatewayDevice(const std::string& interface) { + //Clear previous gupnp contexts if any clearUpnpExistingRequests(); //Initialise gupnp context @@ -105,7 +133,9 @@ void UpnpDiscoveryManager::clearUpnpExistingRequests() g_object_unref(m_controlPoint); } if (m_context) + { g_object_unref(m_context); + } } void UpnpDiscoveryManager::on_device_proxy_available(GUPnPControlPoint *controlPoint, GUPnPDeviceProxy *proxy) @@ -130,4 +160,5 @@ void UpnpDiscoveryManager::stopSearchGatewayDevice() { gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(m_controlPoint), FALSE); } + LOG_INFO("Stopped searching for InternetGatewayDevice"); } From e0ac87581afd1a5a1683c09b6153b3ccbc5b192f Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Mon, 10 Feb 2025 13:30:15 -0500 Subject: [PATCH 16/32] Update UpnpDiscoveryManager.h --- UpnpDiscoveryManager.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/UpnpDiscoveryManager.h b/UpnpDiscoveryManager.h index af1d2948..caf5256c 100644 --- a/UpnpDiscoveryManager.h +++ b/UpnpDiscoveryManager.h @@ -23,6 +23,8 @@ #include #include #include +#include +#include #define LOG_ERR(msg, ...) g_printerr("[%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__) #define LOG_INFO(msg, ...) g_printerr("[%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__) @@ -30,15 +32,17 @@ class UpnpDiscoveryManager { public: - void findGatewayDevice(const std::string& interface); - UpnpDiscoveryManager(); + void startUpnpDiscovery(const std::string& interface); + UpnpDiscoveryManager(); ~UpnpDiscoveryManager(); private: void initialiseUpnp(const std::string& interface); void clearUpnpExistingRequests(); static void* runMainLoop(void *arg); + static void* runUpnp(void *arg); static gboolean logTelemetry(void* arg); + void findGatewayDevice(const std::string& interface); void stopSearchGatewayDevice(); void on_device_proxy_available(GUPnPControlPoint *control_point, GUPnPDeviceProxy *proxy); static void deviceProxyAvailableCallback(GUPnPControlPoint *control_point, GUPnPDeviceProxy *proxy, gpointer user_data) { @@ -48,13 +52,18 @@ class UpnpDiscoveryManager GUPnPContext* m_context; GUPnPControlPoint* m_controlPoint; GMainLoop* m_mainLoop; - GThread * m_thread_upnp; + GThread * m_threadGmain; + GThread * m_threadUpnp; std::string m_apMake; std::string m_apModelName; std::string m_apModelNumber; std::ostringstream m_gatewayDetails; std::mutex m_apMutex; + std::condition_variable m_upnpCv; + std::mutex m_upnpCvMutex; + std::string m_interface; static std::string const m_deviceInternetGateway; static const int LOGGING_PERIOD_IN_SEC = 2; //15min * 60 + bool m_upnpReady; }; #endif From 02d3309cdd8ffd46c0a011f038c4038c494314aa Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Mon, 10 Feb 2025 13:32:02 -0500 Subject: [PATCH 17/32] Update NetworkManagerImplementation.cpp --- NetworkManagerImplementation.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index 3686629e..b54dbdd9 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -627,8 +627,11 @@ namespace WPEFramework m_defaultInterface = interface; connectivityMonitor.switchToInitialCheck(); - NMLOG_ERROR("MYTEST: Calling findGatewayDevice for %s", interface.c_str()); - m_upnpDiscoveryManager.findGatewayDevice("interface"); + if (ipversion == "IPv4") + { + NMLOG_ERROR("MYTEST: Calling findGatewayDevice for %s", interface.c_str()); + m_upnpDiscoveryManager.startUpnpDiscovery(interface); + } } _notificationLock.Lock(); From dd427978da68a2069ddeab5bac96115e6c40ce67 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Tue, 11 Feb 2025 18:43:30 -0500 Subject: [PATCH 18/32] Update CMakeLists.txt --- CMakeLists.txt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b55797e3..1ec5d2bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ include(CmakeHelperFunctions) option(USE_RDK_LOGGER "Enable RDK Logger for logging" OFF ) option(ENABLE_UNIT_TESTING "Enable unit tests" OFF) - +option(USE_TELEMETRY "Enable telemetry" OFF ) string(TOLOWER ${NAMESPACE} STORAGE_DIRECTORY) get_directory_property(SEVICES_DEFINES COMPILE_DEFINITIONS) @@ -100,6 +100,13 @@ if (USE_RDK_LOGGER) include_directories(${RDKLOGGER_INCLUDE_DIRS}) endif (USE_RDK_LOGGER) +if (USE_TELEMETRY) + find_package(telemetry_msgsender REQUIRED) + add_definitions(-DUSE_TELEMETRY) + + include_directories(${TELEMETRY_INCLUDE_DIRS}) +endif (USE_TELEMETRY) + include_directories(${PROJECT_SOURCE_DIR}) # Build the main plugin that runs inside the WPEFramework daemon add_library(${MODULE_NAME} SHARED @@ -111,10 +118,13 @@ add_library(${MODULE_NAME} SHARED NetworkManagerStunClient.cpp WiFiSignalStrengthMonitor.cpp Module.cpp - UpnpDiscoveryManager.cpp + UpnpDiscoveryManager.cpp ${PROXY_STUB_SOURCES}) target_include_directories(${MODULE_NAME} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBSOUP_INCLUDE_DIRS} ${GUPNP_INCLUDE_DIRS} ${GSSDP_INCLUDE_DIRS}) target_link_libraries(${MODULE_NAME} PRIVATE ${GLIB_LIBRARIES} ${LIBSOUP_LIBRARIES} ${GUPNP_LIBRARIES} ${GSSDP_LIBRARIES}) +if (USE_TELEMETRY) + target_link_libraries(${MODULE_NAME} PRIVATE ${TELEMETRY_LIBRARIES}) +endif (USE_TELEMETRY) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Core::${NAMESPACE}Core @@ -213,4 +223,3 @@ write_config(PLUGINS LegacyPlugin_WiFiManagerAPIs CLASSNAME WiFiManager LOCATOR if(ENABLE_UNIT_TESTING) include(Tests/unit_test/unit_tests.cmake) endif(ENABLE_UNIT_TESTING) - From f3a3c349b328bdeeccbbc8886afb7dc87c010c93 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Tue, 11 Feb 2025 18:44:54 -0500 Subject: [PATCH 19/32] Update UpnpDiscoveryManager.cpp --- UpnpDiscoveryManager.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/UpnpDiscoveryManager.cpp b/UpnpDiscoveryManager.cpp index 3785dbef..7d9eb87d 100644 --- a/UpnpDiscoveryManager.cpp +++ b/UpnpDiscoveryManager.cpp @@ -26,9 +26,11 @@ std::string const UpnpDiscoveryManager::m_deviceInternetGateway = "urn:schemas-u UpnpDiscoveryManager::UpnpDiscoveryManager() { - m_mainLoop = g_main_loop_new(NULL, FALSE); + m_mainLoop = g_main_loop_new(NULL, FALSE); - //Create timeout threads to handle telemetry logging + // Initialize Telemtry + t2_init("NetworkManager-Plugin"); + //Timer thread to handle telemetry logging g_timeout_add_seconds (LOGGING_PERIOD_IN_SEC, GSourceFunc(&UpnpDiscoveryManager::logTelemetry), this); m_threadUpnp = g_thread_new("thread_upnp", UpnpDiscoveryManager::runUpnp, this); @@ -50,7 +52,6 @@ UpnpDiscoveryManager::~UpnpDiscoveryManager() void UpnpDiscoveryManager::startUpnpDiscovery(const std::string& interface) { - std::lock_guard lock(m_upnpCvMutex); m_interface = interface; m_upnpReady = true; m_upnpCv.notify_one(); @@ -68,13 +69,14 @@ void* UpnpDiscoveryManager::runUpnp(void *arg) } if (manager->m_upnpReady) { + sleep(3); manager->findGatewayDevice(manager->m_interface); manager->m_upnpReady = false; } } } -void UpnpDiscoveryManager::initialiseUpnp(const std::string& interface) +bool UpnpDiscoveryManager::initialiseUpnp(const std::string& interface) { GError *error = NULL; // Create a gupnp context @@ -82,20 +84,22 @@ void UpnpDiscoveryManager::initialiseUpnp(const std::string& interface) if (!m_context) { LOG_ERR("Error creating Upnp context: %s", error->message); g_clear_error(&error); + return false; } // Create a control point for InternetGatewayDevice m_controlPoint = gupnp_control_point_new(m_context, m_deviceInternetGateway.c_str()); if (!m_controlPoint) { LOG_ERR("Error creating control point"); + return false; } // Connects a callback function to a signal for InternetGatewayDevice g_signal_connect(m_controlPoint, "device-proxy-available", G_CALLBACK(&UpnpDiscoveryManager::deviceProxyAvailableCallback), this); + return true; } - void* UpnpDiscoveryManager::runMainLoop(void *arg) { g_main_loop_run(((UpnpDiscoveryManager *)arg)->m_mainLoop); @@ -104,8 +108,11 @@ void* UpnpDiscoveryManager::runMainLoop(void *arg) gboolean UpnpDiscoveryManager::logTelemetry(void *arg) { std::lock_guard lock(((UpnpDiscoveryManager *)arg)->m_apMutex); + LOG_INFO("TELEMETRY-UPNP: %s", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str()); //T2 telemtery logging - LOG_INFO("TELEMETRY_UPNP_GATEWAY_DETAILS: %s", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str()); + T2ERROR t2error = t2_event_s("gateway_details_split", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str()); + if (t2error != T2ERROR_SUCCESS) + LOG_ERR("t2_event_s(\"%s\", \"%s\") returned error code %d", "gateway_details_split", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str(), t2error); return TRUE; } @@ -115,13 +122,18 @@ void UpnpDiscoveryManager::findGatewayDevice(const std::string& interface) clearUpnpExistingRequests(); //Initialise gupnp context - initialiseUpnp(interface); - - // Start discovery to find InternetGatewayDevice - if (TRUE != gssdp_resource_browser_get_active(GSSDP_RESOURCE_BROWSER(m_controlPoint))) + if (true == initialiseUpnp(interface)) + { + // Start discovery to find InternetGatewayDevice + if (TRUE != gssdp_resource_browser_get_active(GSSDP_RESOURCE_BROWSER(m_controlPoint))) + { + LOG_INFO("Searching for InternetGatewayDevice"); + gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(m_controlPoint), TRUE); + } + } + else { - LOG_INFO("Searching for InternetGatewayDevice"); - gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(m_controlPoint), TRUE); + LOG_INFO("Failed in initialising upnp"); } } From 6cecee21df4654c705b4992d0c96de08daa5fc80 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Tue, 11 Feb 2025 18:45:29 -0500 Subject: [PATCH 20/32] Update UpnpDiscoveryManager.h --- UpnpDiscoveryManager.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/UpnpDiscoveryManager.h b/UpnpDiscoveryManager.h index caf5256c..01fc8a1f 100644 --- a/UpnpDiscoveryManager.h +++ b/UpnpDiscoveryManager.h @@ -25,6 +25,7 @@ #include #include #include +#include #define LOG_ERR(msg, ...) g_printerr("[%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__) #define LOG_INFO(msg, ...) g_printerr("[%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__) @@ -37,7 +38,7 @@ class UpnpDiscoveryManager ~UpnpDiscoveryManager(); private: - void initialiseUpnp(const std::string& interface); + bool initialiseUpnp(const std::string& interface); void clearUpnpExistingRequests(); static void* runMainLoop(void *arg); static void* runUpnp(void *arg); @@ -63,7 +64,7 @@ class UpnpDiscoveryManager std::mutex m_upnpCvMutex; std::string m_interface; static std::string const m_deviceInternetGateway; - static const int LOGGING_PERIOD_IN_SEC = 2; //15min * 60 + static const int LOGGING_PERIOD_IN_SEC = 30; //15min * 60 bool m_upnpReady; }; #endif From d8f44a5815dcda1e32cb0d8c54918c919d362ec3 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Tue, 11 Feb 2025 18:47:14 -0500 Subject: [PATCH 21/32] Update NetworkManagerImplementation.cpp --- NetworkManagerImplementation.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index b54dbdd9..bfad056e 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -627,11 +627,8 @@ namespace WPEFramework m_defaultInterface = interface; connectivityMonitor.switchToInitialCheck(); - if (ipversion == "IPv4") - { - NMLOG_ERROR("MYTEST: Calling findGatewayDevice for %s", interface.c_str()); - m_upnpDiscoveryManager.startUpnpDiscovery(interface); - } + NMLOG_ERROR("MYTEST: Calling findGatewayDevice for %s", interface.c_str()); + m_upnpDiscoveryManager.startUpnpDiscovery(interface); } _notificationLock.Lock(); From 7ffd840ec5f15d42d8a6de38cadd5a6b4094629f Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Tue, 11 Feb 2025 19:33:35 -0500 Subject: [PATCH 22/32] Update NetworkManagerImplementation.cpp --- NetworkManagerImplementation.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index bfad056e..f086b11a 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -627,7 +627,7 @@ namespace WPEFramework m_defaultInterface = interface; connectivityMonitor.switchToInitialCheck(); - NMLOG_ERROR("MYTEST: Calling findGatewayDevice for %s", interface.c_str()); + NMLOG_ERROR("MYTEST: Calling startUpnpDiscovery for %s", interface.c_str()); m_upnpDiscoveryManager.startUpnpDiscovery(interface); } @@ -677,8 +677,6 @@ namespace WPEFramework { m_wlanConnected = true; m_wifiSignalMonitor.startWiFiSignalStrengthMonitor(DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC); - NMLOG_ERROR("MYTEST: Calling findGatewayDevice for wlan0"); - m_upnpDiscoveryManager.findGatewayDevice("wlan0"); } else m_wlanConnected = false; /* Any other state is considered as WiFi not connected. */ From c9f63db61cfa6fbecb0df0062b6fb7196dec6386 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:15:25 -0500 Subject: [PATCH 23/32] Update UpnpDiscoveryManager.cpp --- UpnpDiscoveryManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UpnpDiscoveryManager.cpp b/UpnpDiscoveryManager.cpp index 7d9eb87d..ac94b6f2 100644 --- a/UpnpDiscoveryManager.cpp +++ b/UpnpDiscoveryManager.cpp @@ -29,7 +29,7 @@ UpnpDiscoveryManager::UpnpDiscoveryManager() m_mainLoop = g_main_loop_new(NULL, FALSE); // Initialize Telemtry - t2_init("NetworkManager-Plugin"); + t2_init("networkmanager-Plugin"); //Timer thread to handle telemetry logging g_timeout_add_seconds (LOGGING_PERIOD_IN_SEC, GSourceFunc(&UpnpDiscoveryManager::logTelemetry), this); From dcb82508288fcf169bc2953cfdada01c91d5a95d Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:15:48 -0500 Subject: [PATCH 24/32] Update UpnpDiscoveryManager.h --- UpnpDiscoveryManager.h | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/UpnpDiscoveryManager.h b/UpnpDiscoveryManager.h index 01fc8a1f..d227648c 100644 --- a/UpnpDiscoveryManager.h +++ b/UpnpDiscoveryManager.h @@ -25,46 +25,53 @@ #include #include #include +#if USE_TELEMETRY #include +#endif #define LOG_ERR(msg, ...) g_printerr("[%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__) #define LOG_INFO(msg, ...) g_printerr("[%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__) +#define MAX_CONTEXT_FAIL 3 + class UpnpDiscoveryManager { public: - void startUpnpDiscovery(const std::string& interface); + void NotifyInterfaceStateChangeEvent(); + void NotifyIpAcquiredEvent(const std::string& interface); UpnpDiscoveryManager(); ~UpnpDiscoveryManager(); private: - bool initialiseUpnp(const std::string& interface); - void clearUpnpExistingRequests(); static void* runMainLoop(void *arg); static void* runUpnp(void *arg); static gboolean logTelemetry(void* arg); + gboolean initialiseUpnp(const std::string& interface); + void clearUpnpExistingRequests(); void findGatewayDevice(const std::string& interface); void stopSearchGatewayDevice(); void on_device_proxy_available(GUPnPControlPoint *control_point, GUPnPDeviceProxy *proxy); - static void deviceProxyAvailableCallback(GUPnPControlPoint *control_point, GUPnPDeviceProxy *proxy, gpointer user_data) { + static void deviceProxyAvailableCallback(GUPnPControlPoint *control_point, GUPnPDeviceProxy *proxy, gpointer user_data) + { auto *self = static_cast(user_data); self->on_device_proxy_available(control_point, proxy); } GUPnPContext* m_context; GUPnPControlPoint* m_controlPoint; GMainLoop* m_mainLoop; - GThread * m_threadGmain; - GThread * m_threadUpnp; + GThread* m_threadGmain; + GThread* m_threadUpnp; std::string m_apMake; std::string m_apModelName; std::string m_apModelNumber; - std::ostringstream m_gatewayDetails; + std::string m_interface; std::mutex m_apMutex; - std::condition_variable m_upnpCv; + std::mutex m_upnpStatusMutex; std::mutex m_upnpCvMutex; - std::string m_interface; + std::condition_variable m_upnpCv; + std::ostringstream m_gatewayDetails; static std::string const m_deviceInternetGateway; static const int LOGGING_PERIOD_IN_SEC = 30; //15min * 60 - bool m_upnpReady; + bool m_upnpRunStatus; }; #endif From eaa34b37d9e86ff062635ffb5b0b43b0623935ef Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:19:49 -0500 Subject: [PATCH 25/32] Update CMakeLists.txt --- CMakeLists.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ec5d2bc..b6d09fde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ include(CmakeHelperFunctions) option(USE_RDK_LOGGER "Enable RDK Logger for logging" OFF ) option(ENABLE_UNIT_TESTING "Enable unit tests" OFF) -option(USE_TELEMETRY "Enable telemetry" OFF ) +option(USE_TELEMETRY "Enable telemetry" ON ) string(TOLOWER ${NAMESPACE} STORAGE_DIRECTORY) get_directory_property(SEVICES_DEFINES COMPILE_DEFINITIONS) @@ -103,7 +103,6 @@ endif (USE_RDK_LOGGER) if (USE_TELEMETRY) find_package(telemetry_msgsender REQUIRED) add_definitions(-DUSE_TELEMETRY) - include_directories(${TELEMETRY_INCLUDE_DIRS}) endif (USE_TELEMETRY) @@ -122,9 +121,6 @@ add_library(${MODULE_NAME} SHARED ${PROXY_STUB_SOURCES}) target_include_directories(${MODULE_NAME} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBSOUP_INCLUDE_DIRS} ${GUPNP_INCLUDE_DIRS} ${GSSDP_INCLUDE_DIRS}) target_link_libraries(${MODULE_NAME} PRIVATE ${GLIB_LIBRARIES} ${LIBSOUP_LIBRARIES} ${GUPNP_LIBRARIES} ${GSSDP_LIBRARIES}) -if (USE_TELEMETRY) - target_link_libraries(${MODULE_NAME} PRIVATE ${TELEMETRY_LIBRARIES}) -endif (USE_TELEMETRY) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Core::${NAMESPACE}Core @@ -135,7 +131,10 @@ set_target_properties(${MODULE_NAME} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES FRAMEWORK FALSE) - + +if (USE_TELEMETRY) + target_link_libraries(${MODULE_NAME} PRIVATE ${TELEMETRY_LIBRARIES}) +endif (USE_TELEMETRY) if(ENABLE_GNOME_NETWORKMANAGER) if(ENABLE_GNOME_GDBUS) From e179cefddf0655f79bb289b9d980fecd883337cd Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:20:44 -0500 Subject: [PATCH 26/32] Create Findtelemetry_msgsender.cmake --- cmake/Findtelemetry_msgsender.cmake | 1 + 1 file changed, 1 insertion(+) create mode 100644 cmake/Findtelemetry_msgsender.cmake diff --git a/cmake/Findtelemetry_msgsender.cmake b/cmake/Findtelemetry_msgsender.cmake new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cmake/Findtelemetry_msgsender.cmake @@ -0,0 +1 @@ + From 2d1f085663c03ccad716a532448f9d3db80deef6 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:21:09 -0500 Subject: [PATCH 27/32] Update Findtelemetry_msgsender.cmake --- cmake/Findtelemetry_msgsender.cmake | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cmake/Findtelemetry_msgsender.cmake b/cmake/Findtelemetry_msgsender.cmake index 8b137891..64ef7f51 100644 --- a/cmake/Findtelemetry_msgsender.cmake +++ b/cmake/Findtelemetry_msgsender.cmake @@ -1 +1,37 @@ +############################################################################# +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################# +find_package(PkgConfig) + +find_library(TELEMETRY_LIBRARIES NAMES telemetry_msgsender) +find_path(TELEMETRY_INCLUDE_DIRS NAMES telemetry_busmessage_sender.h) + +set(TELEMETRY_LIBRARIES ${TELEMETRY_LIBRARIES} CACHE PATH "Path to telemetry library") +set(TELEMETRY_INCLUDE_DIRS ${TELEMETRY_INCLUDE_DIRS} ) +set(TELEMETRY_INCLUDE_DIRS ${TELEMETRY_INCLUDE_DIRS} CACHE PATH "Path to telemetry include") + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(TELEMETRY DEFAULT_MSG TELEMETRY_INCLUDE_DIRS TELEMETRY_LIBRARIES) + +mark_as_advanced( + TELEMETRY_FOUND + TELEMETRY_INCLUDE_DIRS + TELEMETRY_LIBRARIES + TELEMETRY_LIBRARY_DIRS + TELEMETRY_FLAGS) From d30766df0b34ccd17ed2f5504e544a12b6f7bd9d Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:23:11 -0500 Subject: [PATCH 28/32] Update NetworkManagerImplementation.cpp --- NetworkManagerImplementation.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index f086b11a..412e4314 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -582,6 +582,12 @@ namespace WPEFramework if(Exchange::INetworkManager::INTERFACE_LINK_UP == state && interface == "eth0") m_ethConnected = true; + if ((interface == "eth0") || (interface == "wlan0")) + { + NMLOG_ERROR("MYTEST Calling NotifyInterfaceStateChangeEvent"); + m_upnpDiscoveryManager.NotifyInterfaceStateChangeEvent(); + } + _notificationLock.Lock(); NMLOG_INFO("Posting onInterfaceChange %s - %u", interface.c_str(), (unsigned)state); for (const auto callback : _notificationCallbacks) { @@ -627,8 +633,9 @@ namespace WPEFramework m_defaultInterface = interface; connectivityMonitor.switchToInitialCheck(); - NMLOG_ERROR("MYTEST: Calling startUpnpDiscovery for %s", interface.c_str()); - m_upnpDiscoveryManager.startUpnpDiscovery(interface); + + NMLOG_ERROR("MYTEST Calling NotifyIpAcquiredEvent"); + m_upnpDiscoveryManager.NotifyIpAcquiredEvent(interface); } _notificationLock.Lock(); From c90668342a466e89ed7b70d3a819e600fd0ed721 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Fri, 14 Feb 2025 14:29:00 -0500 Subject: [PATCH 29/32] Update UpnpDiscoveryManager.cpp --- UpnpDiscoveryManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UpnpDiscoveryManager.cpp b/UpnpDiscoveryManager.cpp index ac94b6f2..2d31deb9 100644 --- a/UpnpDiscoveryManager.cpp +++ b/UpnpDiscoveryManager.cpp @@ -29,7 +29,7 @@ UpnpDiscoveryManager::UpnpDiscoveryManager() m_mainLoop = g_main_loop_new(NULL, FALSE); // Initialize Telemtry - t2_init("networkmanager-Plugin"); + t2_init("networkmanager-plugin"); //Timer thread to handle telemetry logging g_timeout_add_seconds (LOGGING_PERIOD_IN_SEC, GSourceFunc(&UpnpDiscoveryManager::logTelemetry), this); From 8278082b9d5a0c31237eb84ee778f26bfe50a1f4 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Fri, 14 Feb 2025 14:30:46 -0500 Subject: [PATCH 30/32] Update UpnpDiscoveryManager.cpp --- UpnpDiscoveryManager.cpp | 107 ++++++++++++++++++++++++++++----------- 1 file changed, 77 insertions(+), 30 deletions(-) diff --git a/UpnpDiscoveryManager.cpp b/UpnpDiscoveryManager.cpp index 2d31deb9..ef6cafa1 100644 --- a/UpnpDiscoveryManager.cpp +++ b/UpnpDiscoveryManager.cpp @@ -26,10 +26,17 @@ std::string const UpnpDiscoveryManager::m_deviceInternetGateway = "urn:schemas-u UpnpDiscoveryManager::UpnpDiscoveryManager() { + m_context = NULL; + m_controlPoint = NULL; + m_mainLoop = NULL; + m_mainLoop = g_main_loop_new(NULL, FALSE); - // Initialize Telemtry +#if USE_TELEMETRY + // Initialize Telemtry t2_init("networkmanager-plugin"); +#endif + //Timer thread to handle telemetry logging g_timeout_add_seconds (LOGGING_PERIOD_IN_SEC, GSourceFunc(&UpnpDiscoveryManager::logTelemetry), this); @@ -50,48 +57,68 @@ UpnpDiscoveryManager::~UpnpDiscoveryManager() } } -void UpnpDiscoveryManager::startUpnpDiscovery(const std::string& interface) +void UpnpDiscoveryManager::NotifyInterfaceStateChangeEvent() +{ + // Clear the upnp running status if there is any interface state change + std::lock_guard lock(m_upnpStatusMutex); + m_upnpRunStatus = false; +} + +void UpnpDiscoveryManager::NotifyIpAcquiredEvent(const std::string& interface) { - m_interface = interface; - m_upnpReady = true; - m_upnpCv.notify_one(); + std::lock_guard lock(m_upnpStatusMutex); + // Once IP is acquired, notify upnp thread to start discovery + if (m_upnpRunStatus == false) + { + m_upnpRunStatus = true; + m_interface = interface; + m_upnpCv.notify_one(); + } } void* UpnpDiscoveryManager::runUpnp(void *arg) { UpnpDiscoveryManager* manager = static_cast(arg); - int timeoutInMin = 30; while(true) { std::unique_lock lock(manager->m_upnpCvMutex); - if (manager->m_upnpCv.wait_for(lock, std::chrono::minutes(timeoutInMin)) == std::cv_status::timeout) { - LOG_INFO("upnp run thread timeout"); - } - if (manager->m_upnpReady) + manager->m_upnpCv.wait(lock); + if (true == manager->m_upnpRunStatus) { - sleep(3); manager->findGatewayDevice(manager->m_interface); - manager->m_upnpReady = false; } } } -bool UpnpDiscoveryManager::initialiseUpnp(const std::string& interface) +gboolean UpnpDiscoveryManager::initialiseUpnp(const std::string& interface) { GError *error = NULL; - // Create a gupnp context - m_context = gupnp_context_new(NULL, interface.c_str(), 0, &error); - if (!m_context) { - LOG_ERR("Error creating Upnp context: %s", error->message); - g_clear_error(&error); - return false; + uint8_t count = 0; + + do + { + // Create a gupnp context + m_context = gupnp_context_new(NULL, interface.c_str(), 0, &error); + if (!m_context) + { + LOG_ERR("Error creating Upnp context: %s", error->message); + g_clear_error(&error); + count++; + sleep(1); + } + } while ((m_context == NULL) && (count < MAX_CONTEXT_FAIL)); + if (count == MAX_CONTEXT_FAIL) + { + LOG_ERR("Context creation failed"); + return false; } - + // Create a control point for InternetGatewayDevice m_controlPoint = gupnp_control_point_new(m_context, m_deviceInternetGateway.c_str()); - if (!m_controlPoint) { + if (!m_controlPoint) + { LOG_ERR("Error creating control point"); - return false; + return false; } // Connects a callback function to a signal for InternetGatewayDevice @@ -102,18 +129,24 @@ bool UpnpDiscoveryManager::initialiseUpnp(const std::string& interface) void* UpnpDiscoveryManager::runMainLoop(void *arg) { - g_main_loop_run(((UpnpDiscoveryManager *)arg)->m_mainLoop); + // gmain loop need to be running for upnp discovery and telemetry logging + g_main_loop_run(((UpnpDiscoveryManager *)arg)->m_mainLoop); } gboolean UpnpDiscoveryManager::logTelemetry(void *arg) { std::lock_guard lock(((UpnpDiscoveryManager *)arg)->m_apMutex); - LOG_INFO("TELEMETRY-UPNP: %s", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str()); + LOG_INFO("Connected to Gateway: %s", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str()); +#if USE_TELEMETRY + LOG_INFO("Telemetry logging"); //T2 telemtery logging T2ERROR t2error = t2_event_s("gateway_details_split", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str()); if (t2error != T2ERROR_SUCCESS) + { LOG_ERR("t2_event_s(\"%s\", \"%s\") returned error code %d", "gateway_details_split", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str(), t2error); - return TRUE; + } +#endif + return true; } void UpnpDiscoveryManager::findGatewayDevice(const std::string& interface) @@ -133,7 +166,7 @@ void UpnpDiscoveryManager::findGatewayDevice(const std::string& interface) } else { - LOG_INFO("Failed in initialising upnp"); + LOG_ERR("Failed in initialising upnp"); } } @@ -141,12 +174,15 @@ void UpnpDiscoveryManager::clearUpnpExistingRequests() { if (m_controlPoint) { + g_object_ref_sink(m_controlPoint); stopSearchGatewayDevice(); g_object_unref(m_controlPoint); + m_controlPoint = NULL; } if (m_context) { g_object_unref(m_context); + m_context = NULL; } } @@ -156,21 +192,32 @@ void UpnpDiscoveryManager::on_device_proxy_available(GUPnPControlPoint *controlP m_apModelName = gupnp_device_info_get_model_name(GUPNP_DEVICE_INFO(proxy)); m_apModelNumber = gupnp_device_info_get_model_number(GUPNP_DEVICE_INFO(proxy)); m_apMake = m_apMake.substr(0, m_apMake.find(',')); - LOG_INFO("Connected to Gateway: %s, %s, %s", m_apMake.c_str(), m_apModelName.c_str(), m_apModelNumber.c_str()); // Stop discovery to find InternetGatewayDevice stopSearchGatewayDevice(); std::lock_guard lock(m_apMutex); m_gatewayDetails.str(""); m_gatewayDetails.clear(); - m_gatewayDetails << "make=" << m_apMake << ",model_name=" << m_apModelName << ",model_number=" << m_apModelNumber; + m_gatewayDetails << m_apMake << "," << m_apModelName << "," << m_apModelNumber; + LOG_INFO("Received gateway details: %s", m_gatewayDetails.str().c_str()); } void UpnpDiscoveryManager::stopSearchGatewayDevice() { - LOG_INFO("Stop searching for InternetGatewayDevice"); if (TRUE == gssdp_resource_browser_get_active(GSSDP_RESOURCE_BROWSER(m_controlPoint))) { gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(m_controlPoint), FALSE); } - LOG_INFO("Stopped searching for InternetGatewayDevice"); +} + +int main() +{ + UpnpDiscoveryManager obj; + + while(true) + { + obj.HandleInterfaceStateChangeEvent(2); + obj.HandleIpAcquiredEvent("en0"); + sleep(10); + } + return 1; } From 1e01a37b73ae5dd50da4b6a92db37cc802bfda84 Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Mon, 17 Feb 2025 09:44:22 -0500 Subject: [PATCH 31/32] Update UpnpDiscoveryManager.cpp --- UpnpDiscoveryManager.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/UpnpDiscoveryManager.cpp b/UpnpDiscoveryManager.cpp index ef6cafa1..5633377a 100644 --- a/UpnpDiscoveryManager.cpp +++ b/UpnpDiscoveryManager.cpp @@ -208,16 +208,3 @@ void UpnpDiscoveryManager::stopSearchGatewayDevice() gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(m_controlPoint), FALSE); } } - -int main() -{ - UpnpDiscoveryManager obj; - - while(true) - { - obj.HandleInterfaceStateChangeEvent(2); - obj.HandleIpAcquiredEvent("en0"); - sleep(10); - } - return 1; -} From d8b8287cfa16e195e824920b7af5bff50befe33d Mon Sep 17 00:00:00 2001 From: jincysam87 <167995204+jincysam87@users.noreply.github.com> Date: Mon, 17 Feb 2025 13:40:04 -0500 Subject: [PATCH 32/32] Update UpnpDiscoveryManager.cpp --- UpnpDiscoveryManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UpnpDiscoveryManager.cpp b/UpnpDiscoveryManager.cpp index 5633377a..1ce7438f 100644 --- a/UpnpDiscoveryManager.cpp +++ b/UpnpDiscoveryManager.cpp @@ -136,7 +136,7 @@ void* UpnpDiscoveryManager::runMainLoop(void *arg) gboolean UpnpDiscoveryManager::logTelemetry(void *arg) { std::lock_guard lock(((UpnpDiscoveryManager *)arg)->m_apMutex); - LOG_INFO("Connected to Gateway: %s", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str()); + LOG_INFO("Connected_to_Gateway: %s", ((UpnpDiscoveryManager *)arg)->m_gatewayDetails.str().c_str()); #if USE_TELEMETRY LOG_INFO("Telemetry logging"); //T2 telemtery logging