Skip to content
Open
12 changes: 12 additions & 0 deletions plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ find_package(${NAMESPACE}Core REQUIRED)
find_package(${NAMESPACE}Plugins REQUIRED)
find_package(CURL)

option(ENABLE_POWERMANAGER "Enable PowerManager COMRPC integration for DeepSleep WiFi management" ON)
if(ENABLE_POWERMANAGER)
find_package(${NAMESPACE}Definitions REQUIRED)
add_definitions(-DENABLE_POWERMANAGER)
message("NetworkManager: PowerManager integration enabled")
endif()
Comment on lines +29 to +34

if (USE_RDK_LOGGER)
find_package(rdklogger REQUIRED)
add_definitions(-DUSE_RDK_LOGGER)
Expand Down Expand Up @@ -83,6 +90,11 @@ add_library(${MODULE_IMPL_NAME} SHARED
NetworkManagerLogger.cpp
Module.cpp)

if(ENABLE_POWERMANAGER)
target_sources(${MODULE_IMPL_NAME} PRIVATE NetworkManagerPowerClient.cpp)
target_link_libraries(${MODULE_IMPL_NAME} PRIVATE ${NAMESPACE}Definitions::${NAMESPACE}Definitions)
endif()

if(ENABLE_GNOME_NETWORKMANAGER)
if(ENABLE_GNOME_GDBUS)
message("networkmanager building with gdbus")
Expand Down
78 changes: 78 additions & 0 deletions plugin/NetworkManagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <thread>
#include <chrono>
#include "NetworkManagerImplementation.h"
#ifdef ENABLE_POWERMANAGER
#include "NetworkManagerPowerClient.h"
#endif

#if USE_TELEMETRY
#include "NetworkManagerJsonEnum.h"
Expand Down Expand Up @@ -71,6 +74,9 @@ namespace WPEFramework
NetworkManagerImplementation::~NetworkManagerImplementation()
{
NMLOG_INFO("NetworkManager Out-Of-Process Shutdown/Cleanup");
#ifdef ENABLE_POWERMANAGER
_powerClient.reset();
#endif
connectivityMonitor.stopConnectivityMonitor();
_instance = nullptr;
platform_deinit();
Expand Down Expand Up @@ -199,6 +205,9 @@ namespace WPEFramework
NetworkManagerImplementation::platform_init();
/* change gnome networkmanager or netsrvmgr logg level */
NetworkManagerImplementation::platform_logging(static_cast <NetworkManagerLogger::LogLevel>(config.loglevel.Value()));
#ifdef ENABLE_POWERMANAGER
_powerClient.reset(new NetworkManagerPowerClient(*this));
#endif
return(Core::ERROR_NONE);
}

Expand Down Expand Up @@ -1184,5 +1193,74 @@ namespace WPEFramework
}
#endif
}

#ifdef ENABLE_POWERMANAGER
void NetworkManagerImplementation::OnPowerModePreChange(
const Exchange::IPowerManager::PowerState currentState,
const Exchange::IPowerManager::PowerState newState,
std::function<void()> sendAck)
{
// Called from NetworkManagerPowerClient's power thread.
// Policy (standbyMode check, DeepSleep filter) has already been
// applied by the power thread before calling here.
NMLOG_INFO("OnPowerModePreChange: current=%d new=%d",
static_cast<int>(currentState), static_cast<int>(newState));

using PowerState = Exchange::IPowerManager::PowerState;

if (newState == PowerState::POWER_STATE_STANDBY_DEEP_SLEEP) {
if (m_wlanEnabled.load() && m_wlanConnected.load()) {
NMLOG_INFO("OnPowerModePreChange: going to DeepSleep — disconnecting WiFi");
uint32_t rcWifiDown = WiFiDisconnect();
if (rcWifiDown != Core::ERROR_NONE)
NMLOG_WARNING("OnPowerModePreChange: WiFiDisconnect failed (rc=%u)", rcWifiDown);
}
else
{
NMLOG_WARNING("OnPowerModePreChange: going to DeepSleep — WiFi not connected, skipping disconnect");
}
if (m_ethEnabled.load() && m_ethConnected.load()) {
NMLOG_INFO("OnPowerModePreChange: going to DeepSleep — disconnecting Ethernet");
uint32_t rcEthDown = EthernetDisconnect();
if (rcEthDown != Core::ERROR_NONE)
NMLOG_WARNING("OnPowerModePreChange: EthernetDisconnect failed (rc=%u)", rcEthDown);
} else {
NMLOG_WARNING("OnPowerModePreChange: going to DeepSleep — Ethernet not connected, skipping disconnect");
}
} else if (currentState == PowerState::POWER_STATE_STANDBY_DEEP_SLEEP) {
if (m_wlanEnabled.load() && !m_lastConnectedSSID.empty()) {
NMLOG_INFO("OnPowerModePreChange: waking from DeepSleep — reconnecting to '%s'",
m_lastConnectedSSID.c_str());
uint32_t rcWifiUp = ConnectToKnownSSID(m_lastConnectedSSID);
if (rcWifiUp != Core::ERROR_NONE)
NMLOG_WARNING("OnPowerModePreChange: ConnectToKnownSSID failed (rc=%u)", rcWifiUp);
} else {
NMLOG_WARNING("OnPowerModePreChange: waking from DeepSleep — no last SSID, skipping reconnect");
}
if (m_ethEnabled.load()) {
NMLOG_INFO("OnPowerModePreChange: waking from DeepSleep — reconnecting Ethernet");
uint32_t rcEthUp = EthernetConnect();
if (rcEthUp != Core::ERROR_NONE)
NMLOG_WARNING("OnPowerModePreChange: EthernetConnect failed (rc=%u)", rcEthUp);
}
}
sendAck();
}

void NetworkManagerImplementation::OnPowerModeChanged(
const Exchange::IPowerManager::PowerState currentState,
const Exchange::IPowerManager::PowerState newState)
{
NMLOG_INFO("OnPowerModeChanged: current=%d new=%d",
static_cast<int>(currentState), static_cast<int>(newState));
if (currentState == Exchange::IPowerManager::POWER_STATE_STANDBY_DEEP_SLEEP) {
// Waking from DeepSleep with Network Standby ON: the AP may have
// changed channel while the device slept (802.11 CSA). Trigger an
// active scan so the driver discovers the AP on its new channel.
NMLOG_INFO("OnPowerModeChanged: waking from DeepSleep, triggering active WiFi scan");
StartWiFiScan("", nullptr);
}
}
#endif // ENABLE_POWERMANAGER
}
}
20 changes: 20 additions & 0 deletions plugin/NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ using namespace std;
#include "NetworkManagerLogger.h"
#include "NetworkManagerConnectivity.h"
#include "NetworkManagerStunClient.h"
#ifdef ENABLE_POWERMANAGER
#include "NetworkManagerPowerClient.h"
#endif

/* Forward declarations to avoid pulling GLib/libnm headers into this header */
typedef struct _NMClient NMClient;
Expand Down Expand Up @@ -63,6 +66,9 @@ namespace WPEFramework
namespace Plugin
{
class NetworkManagerImplementation : public Exchange::INetworkManager
#ifdef ENABLE_POWERMANAGER
, public INetworkPowerCallback
#endif
{
enum NetworkEvents
{
Expand Down Expand Up @@ -226,6 +232,8 @@ namespace WPEFramework

uint32_t WiFiConnect(const WiFiConnectTo& ssid /* @in */) override;
uint32_t WiFiDisconnect(void) override;
uint32_t EthernetDisconnect(void);
uint32_t EthernetConnect(void);
uint32_t GetConnectedSSID(WiFiSSIDInfo& ssidInfo /* @out */) override;

uint32_t StartWPS(const WiFiWPS& method /* @in */, const string& wps_pin /* @in */) override;
Expand Down Expand Up @@ -277,6 +285,15 @@ namespace WPEFramework
void ReportWiFiSignalQualityChange(const string ssid, const int strength, const int noise, const int snr, const Exchange::INetworkManager::WiFiSignalQuality quality);
void logTelemetry(const std::string& eventName, const std::string& message);

#ifdef ENABLE_POWERMANAGER
// INetworkPowerCallback overrides
void OnPowerModePreChange(const Exchange::IPowerManager::PowerState currentState,
const Exchange::IPowerManager::PowerState newState,
std::function<void()> sendAck) override;
void OnPowerModeChanged(const Exchange::IPowerManager::PowerState currentState,
const Exchange::IPowerManager::PowerState newState) override;
#endif

private:
void platform_init(void);
void platform_deinit(void);
Expand Down Expand Up @@ -314,6 +331,9 @@ namespace WPEFramework
std::atomic<bool> m_stopThread{false};
std::mutex m_condVariableMutex;
std::condition_variable m_condVariable;
#ifdef ENABLE_POWERMANAGER
std::unique_ptr<NetworkManagerPowerClient> _powerClient;
#endif
public:
IPAddress m_ethIPv4Address;
IPAddress m_wlanIPv4Address;
Expand Down
Loading
Loading