Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a417f70
Add files via upload
jincysam87 Feb 5, 2025
74478f7
Update CMakeLists.txt
jincysam87 Feb 5, 2025
2a305bb
Update CMakeLists.txt
jincysam87 Feb 6, 2025
f64bfe0
Update UpnpDiscoveryManager.h
jincysam87 Feb 6, 2025
30768fb
Update UpnpDiscoveryManager.cpp
jincysam87 Feb 6, 2025
f650d7e
Update NetworkManagerImplementation.h
jincysam87 Feb 6, 2025
fd64c40
Update NetworkManagerImplementation.cpp
jincysam87 Feb 6, 2025
9da5851
Update NetworkManagerImplementation.cpp
jincysam87 Feb 6, 2025
3d8fb4f
Update UpnpDiscoveryManager.cpp
jincysam87 Feb 6, 2025
ade9bfd
Update NetworkManagerImplementation.h
jincysam87 Feb 6, 2025
000b146
Update NetworkManagerRDKProxy.cpp
jincysam87 Feb 6, 2025
79f15d3
Update NetworkManagerImplementation.cpp
jincysam87 Feb 6, 2025
102a38f
Update NetworkManagerImplementation.cpp
jincysam87 Feb 6, 2025
a921d2e
Update NetworkManagerImplementation.cpp
jincysam87 Feb 7, 2025
8ddd764
Update UpnpDiscoveryManager.cpp
jincysam87 Feb 10, 2025
e0ac875
Update UpnpDiscoveryManager.h
jincysam87 Feb 10, 2025
02d3309
Update NetworkManagerImplementation.cpp
jincysam87 Feb 10, 2025
dd42797
Update CMakeLists.txt
jincysam87 Feb 11, 2025
f3a3c34
Update UpnpDiscoveryManager.cpp
jincysam87 Feb 11, 2025
6cecee2
Update UpnpDiscoveryManager.h
jincysam87 Feb 11, 2025
d8f44a5
Update NetworkManagerImplementation.cpp
jincysam87 Feb 11, 2025
7ffd840
Update NetworkManagerImplementation.cpp
jincysam87 Feb 12, 2025
c9f63db
Update UpnpDiscoveryManager.cpp
jincysam87 Feb 14, 2025
dcb8250
Update UpnpDiscoveryManager.h
jincysam87 Feb 14, 2025
eaa34b3
Update CMakeLists.txt
jincysam87 Feb 14, 2025
e179cef
Create Findtelemetry_msgsender.cmake
jincysam87 Feb 14, 2025
2d1f085
Update Findtelemetry_msgsender.cmake
jincysam87 Feb 14, 2025
d30766d
Update NetworkManagerImplementation.cpp
jincysam87 Feb 14, 2025
c906683
Update UpnpDiscoveryManager.cpp
jincysam87 Feb 14, 2025
8278082
Update UpnpDiscoveryManager.cpp
jincysam87 Feb 14, 2025
1e01a37
Update UpnpDiscoveryManager.cpp
jincysam87 Feb 17, 2025
d8b8287
Update UpnpDiscoveryManager.cpp
jincysam87 Feb 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" ON )

string(TOLOWER ${NAMESPACE} STORAGE_DIRECTORY)
get_directory_property(SEVICES_DEFINES COMPILE_DEFINITIONS)
Expand All @@ -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(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)
endif ()

Expand Down Expand Up @@ -96,6 +100,12 @@ 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
Expand All @@ -107,7 +117,10 @@ add_library(${MODULE_NAME} SHARED
NetworkManagerStunClient.cpp
WiFiSignalStrengthMonitor.cpp
Module.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
Expand All @@ -118,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)
Expand Down Expand Up @@ -206,4 +222,3 @@ write_config(PLUGINS LegacyPlugin_WiFiManagerAPIs CLASSNAME WiFiManager LOCATOR
if(ENABLE_UNIT_TESTING)
include(Tests/unit_test/unit_tests.cmake)
endif(ENABLE_UNIT_TESTING)

9 changes: 9 additions & 0 deletions NetworkManagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -627,6 +633,9 @@ namespace WPEFramework
m_defaultInterface = interface;

connectivityMonitor.switchToInitialCheck();

NMLOG_ERROR("MYTEST Calling NotifyIpAcquiredEvent");
m_upnpDiscoveryManager.NotifyIpAcquiredEvent(interface);
}

_notificationLock.Lock();
Expand Down
2 changes: 2 additions & 0 deletions NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using namespace std;
#include "WiFiSignalStrengthMonitor.h"
#include "NetworkManagerConnectivity.h"
#include "NetworkManagerStunClient.h"
#include "UpnpDiscoveryManager.h"

namespace WPEFramework
{
Expand Down Expand Up @@ -276,6 +277,7 @@ namespace WPEFramework
std::atomic<bool> m_ethConnected;
std::atomic<bool> m_wlanConnected;
WiFiSignalStrengthMonitor m_wifiSignalMonitor;
UpnpDiscoveryManager m_upnpDiscoveryManager;
mutable ConnectivityMonitor connectivityMonitor;
};
}
Expand Down
4 changes: 2 additions & 2 deletions NetworkManagerRDKProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
210 changes: 210 additions & 0 deletions UpnpDiscoveryManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/**
* 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 <fstream>
#include <sstream>
#include <thread>
#include "UpnpDiscoveryManager.h"

std::string const UpnpDiscoveryManager::m_deviceInternetGateway = "urn:schemas-upnp-org:device:InternetGatewayDevice:1";

UpnpDiscoveryManager::UpnpDiscoveryManager()
{
m_context = NULL;
m_controlPoint = NULL;
m_mainLoop = NULL;

m_mainLoop = g_main_loop_new(NULL, FALSE);

#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);

m_threadUpnp = g_thread_new("thread_upnp", UpnpDiscoveryManager::runUpnp, this);
m_threadGmain = 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::NotifyInterfaceStateChangeEvent()
{
// Clear the upnp running status if there is any interface state change
std::lock_guard<std::mutex> lock(m_upnpStatusMutex);
m_upnpRunStatus = false;
}

void UpnpDiscoveryManager::NotifyIpAcquiredEvent(const std::string& interface)
{
std::lock_guard<std::mutex> 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<UpnpDiscoveryManager*>(arg);
while(true)
{
std::unique_lock<std::mutex> lock(manager->m_upnpCvMutex);
manager->m_upnpCv.wait(lock);
if (true == manager->m_upnpRunStatus)
{
manager->findGatewayDevice(manager->m_interface);
}
}
}

gboolean UpnpDiscoveryManager::initialiseUpnp(const std::string& interface)
{
GError *error = NULL;
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)
{
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)
{
// 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<std::mutex> lock(((UpnpDiscoveryManager *)arg)->m_apMutex);
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);
}
#endif
return true;
}

void UpnpDiscoveryManager::findGatewayDevice(const std::string& interface)
{
//Clear previous gupnp contexts if any
clearUpnpExistingRequests();

//Initialise gupnp context
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_ERR("Failed in initialising upnp");
}
}

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;
}
}

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(','));
// Stop discovery to find InternetGatewayDevice
stopSearchGatewayDevice();
std::lock_guard<std::mutex> lock(m_apMutex);
m_gatewayDetails.str("");
m_gatewayDetails.clear();
m_gatewayDetails << m_apMake << "," << m_apModelName << "," << m_apModelNumber;
LOG_INFO("Received gateway details: %s", m_gatewayDetails.str().c_str());
}

void UpnpDiscoveryManager::stopSearchGatewayDevice()
{
if (TRUE == gssdp_resource_browser_get_active(GSSDP_RESOURCE_BROWSER(m_controlPoint)))
{
gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(m_controlPoint), FALSE);
}
}
Loading