Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
a34390c
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 2, 2026
3a4494b
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 4, 2026
a7b6f71
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 5, 2026
0259369
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 6, 2026
cbe0702
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 6, 2026
16d9afa
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 11, 2026
346baef
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 11, 2026
864afa5
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 13, 2026
ed90c87
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 13, 2026
7e73a11
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 13, 2026
0ab138a
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 14, 2026
12da0ab
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 15, 2026
aa04bbb
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 19, 2026
c92eb22
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 21, 2026
5f5afa1
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 21, 2026
16f394b
RDK-61440: Implementation of handling PowerMode Change in NM plugin
anandn654 May 22, 2026
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
3 changes: 2 additions & 1 deletion plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ add_library(${MODULE_IMPL_NAME} SHARED
NetworkManagerConnectivity.cpp
NetworkManagerStunClient.cpp
NetworkManagerLogger.cpp
Module.cpp)
Module.cpp
NetworkManagerPowerClient.cpp)

if(ENABLE_GNOME_NETWORKMANAGER)
if(ENABLE_GNOME_GDBUS)
Expand Down
131 changes: 131 additions & 0 deletions plugin/NetworkManagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace WPEFramework
m_wlanConnected.store(false);
m_ethEnabled.store(false);
m_wlanEnabled.store(false);
m_ethDisconnectedForSleep.store(false);
m_wlanDisconnectedForSleep.store(false);

/* Set NetworkManager Out-Process name to be NWMgrPlugin */
Core::ProcessInfo().Name("NWMgrPlugin");
Expand All @@ -71,6 +73,7 @@ namespace WPEFramework
NetworkManagerImplementation::~NetworkManagerImplementation()
{
NMLOG_INFO("NetworkManager Out-Of-Process Shutdown/Cleanup");
_powerClient.reset();
connectivityMonitor.stopConnectivityMonitor();
_instance = nullptr;
platform_deinit();
Expand Down Expand Up @@ -199,6 +202,7 @@ namespace WPEFramework
NetworkManagerImplementation::platform_init();
/* change gnome networkmanager or netsrvmgr logg level */
NetworkManagerImplementation::platform_logging(static_cast <NetworkManagerLogger::LogLevel>(config.loglevel.Value()));
_powerClient.reset(new NetworkManagerPowerClient(*this));
return(Core::ERROR_NONE);
}

Expand Down Expand Up @@ -1184,5 +1188,132 @@ namespace WPEFramework
}
#endif
}

void NetworkManagerImplementation::OnPowerModePreChange(
const Exchange::IPowerManager::PowerState currentState,
const Exchange::IPowerManager::PowerState newState,
std::function<void()> sendAck)
{
// Called from NetworkManagerPowerClient's power thread.
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)
{
m_wlanDisconnectedForSleep.store(true);
}
else
{
NMLOG_WARNING("OnPowerModePreChange: WiFiDisconnect failed (rc=%u), will not reconnect on wakeup", 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 — deactivating Ethernet");

uint32_t rcEthDown = EthernetDeactivate();
if (rcEthDown == Core::ERROR_NONE)
{
Comment thread
Anand73-n marked this conversation as resolved.
Comment on lines +1224 to +1230
m_ethDisconnectedForSleep.store(true);
}
else
{
NMLOG_WARNING("OnPowerModePreChange: EthernetDeactivate failed (rc=%u), will not activate on wakeup", rcEthDown);
}
}
else
{
NMLOG_WARNING("OnPowerModePreChange: going to DeepSleep — Ethernet not activated, skipping deactivate");
}
}
else if (currentState == PowerState::POWER_STATE_STANDBY_DEEP_SLEEP)
{
if (m_wlanDisconnectedForSleep.load())
{
if (!m_lastConnectedSSID.empty())
{
NMLOG_INFO("OnPowerModePreChange: waking from DeepSleep — reconnecting to '%s'",
m_lastConnectedSSID.c_str());
m_wlanDisconnectedForSleep.store(false);
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");
}
}
else
{
NMLOG_INFO("OnPowerModePreChange: waking from DeepSleep — WiFi was not connected or was already down before sleep, skipping reconnect");
}

if (m_ethDisconnectedForSleep.load())
{
m_ethDisconnectedForSleep.store(false);
NMLOG_INFO("OnPowerModePreChange: waking from DeepSleep — activating Ethernet");
uint32_t rcEthUp = EthernetActivate();
if (rcEthUp != Core::ERROR_NONE)
NMLOG_WARNING("OnPowerModePreChange: EthernetActivate failed (rc=%u)", rcEthUp);
}
else
{
NMLOG_INFO("OnPowerModePreChange: waking from DeepSleep — Ethernet was not activated or was already deactivated before sleep, skipping activate");
}
}
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) {

if (m_wlanEnabled.load() && m_wlanConnected.load())
{
// 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");
if (StartWiFiScan("", nullptr) != Core::ERROR_NONE)
{
NMLOG_WARNING("OnPowerModeChanged: StartWiFiScan failed");
}

NMLOG_INFO("OnPowerModeChanged: waking from DeepSleep, requesting DHCP lease on wlan0");
if (RequestDHCPLease("wlan0") != Core::ERROR_NONE)
{
NMLOG_WARNING("OnPowerModeChanged: RequestDHCPLease(wlan0) failed");
}
}

if (m_ethEnabled.load() && m_ethConnected.load())
{
NMLOG_INFO("OnPowerModeChanged: waking from DeepSleep, requesting DHCP lease on eth0");
if (RequestDHCPLease("eth0") != Core::ERROR_NONE)
{
NMLOG_WARNING("OnPowerModeChanged: RequestDHCPLease(eth0) failed");
}
}
}
}
}
}
15 changes: 15 additions & 0 deletions plugin/NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using namespace std;
#include "NetworkManagerLogger.h"
#include "NetworkManagerConnectivity.h"
#include "NetworkManagerStunClient.h"
#include "NetworkManagerPowerClient.h"

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

uint32_t WiFiConnect(const WiFiConnectTo& ssid /* @in */) override;
uint32_t WiFiDisconnect(void) override;
uint32_t EthernetDeactivate(void);
uint32_t EthernetActivate(void);
uint32_t RequestDHCPLease(const string& iface);
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 +282,13 @@ 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);

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

private:
void platform_init(void);
void platform_deinit(void);
Expand Down Expand Up @@ -314,6 +326,7 @@ namespace WPEFramework
std::atomic<bool> m_stopThread{false};
std::mutex m_condVariableMutex;
std::condition_variable m_condVariable;
std::unique_ptr<NetworkManagerPowerClient> _powerClient;
public:
Comment on lines 326 to 330
IPAddress m_ethIPv4Address;
IPAddress m_wlanIPv4Address;
Expand All @@ -323,6 +336,8 @@ namespace WPEFramework
std::atomic<bool> m_wlanConnected;
std::atomic<bool> m_ethEnabled;
std::atomic<bool> m_wlanEnabled;
std::atomic<bool> m_ethDisconnectedForSleep;
std::atomic<bool> m_wlanDisconnectedForSleep;
std::string m_lastConnectedSSID;
NMClient *m_nmClient{nullptr}; /* proxy NMClient — bound to m_nmContext */
GMainContext *m_nmContext{nullptr}; /* isolated context, not the global default */
Expand Down
Loading
Loading