Skip to content

Commit

Permalink
RDKERDKE-353 WiFi is connected on bootup even if WiFi option was disa…
Browse files Browse the repository at this point in the history
…bled before reboot
  • Loading branch information
cmuhammedrafi committed Nov 19, 2024
1 parent 1936e82 commit c8fd19d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
12 changes: 6 additions & 6 deletions LegacyPlugin_NetworkAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,10 +1014,10 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
{
JsonObject legacyParams;

legacyParams["oldInterfaceName"] = getInterfaceNameToType(parameters["oldInterfaceName"].String());
legacyParams["newInterfaceName"] = getInterfaceNameToType(parameters["newInterfaceName"].String());
legacyParams["oldInterfaceName"] = getInterfaceNameToType(parameters["prevActiveInterface"].String());
legacyParams["newInterfaceName"] = getInterfaceNameToType(parameters["currentActiveInterface"].String());

m_defaultInterface = parameters["newInterfaceName"].String();
m_defaultInterface = parameters["currentActiveInterface"].String();

string json;
legacyParams.ToString(json);
Expand All @@ -1032,7 +1032,7 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
JsonObject legacyParams;
legacyParams["interface"] = getInterfaceNameToType(parameters["interface"].String());

if (parameters["isIPv6"].Boolean())
if (parameters["ipversion"].String() == "IPv6")
{
legacyParams["ip6Address"] = parameters["ipaddress"];
}
Expand All @@ -1049,8 +1049,8 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {

Notify("onIPAddressStatusChanged", legacyParams);

if ("ACQUIRED" == parameters["status"].String())
m_defaultInterface = parameters["interface"].String();
// if ("ACQUIRED" == parameters["status"].String())
// m_defaultInterface = parameters["interface"].String();

return;
}
Expand Down
10 changes: 5 additions & 5 deletions LegacyPlugin_WiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ namespace WPEFramework
}
}
else
NMLOG_WARNING("Ignoring %s\n", __FUNCTION__);
NMLOG_WARNING("Ignoring %s", __FUNCTION__);

return;
}
Expand All @@ -710,24 +710,24 @@ namespace WPEFramework
if(_gWiFiInstance)
_gWiFiInstance->Notify("onAvailableSSIDs", parameters);
else
NMLOG_WARNING("Ignoring %s\n", __FUNCTION__);
NMLOG_WARNING("Ignoring %s", __FUNCTION__);

return;
}

void WiFiManager::onWiFiSignalStrengthChange(const JsonObject& parameters)
{
JsonObject legacyParams;
legacyParams["signalStrength"] = parameters["signalQuality"];
legacyParams["strength"] = parameters["signalLevel"];
legacyParams["signalStrength"] = parameters["strength"];
legacyParams["strength"] = parameters["quality"];

string json;
legacyParams.ToString(json);
NMLOG_INFO("Posting onWifiSignalThresholdChanged as %s", json.c_str());
if (_gWiFiInstance)
_gWiFiInstance->Notify("onWifiSignalThresholdChanged", legacyParams);
else
NMLOG_WARNING("Ignoring %s\n", __FUNCTION__);
NMLOG_WARNING("Ignoring %s", __FUNCTION__);

return;
}
Expand Down
54 changes: 37 additions & 17 deletions NetworkManagerGnomeEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ namespace WPEFramework

static void deviceStateChangeCb(NMDevice *device, GParamSpec *pspec, NMEvents *nmEvents)
{
static bool isEthDisabled = false;
static bool isWlanDisabled = false;
NMDeviceState deviceState;
deviceState = nm_device_get_state(device);
std::string ifname = nm_device_get_iface(device);
if(ifname == nmEvents->ifnameWlan0)
if(ifname == nmUtils::wlanIface())
{
if(!NM_IS_DEVICE_WIFI(device)) {
NMLOG_FATAL("not a wifi device !");
Expand Down Expand Up @@ -118,19 +120,24 @@ namespace WPEFramework
case NM_DEVICE_STATE_UNKNOWN:
wifiState = "WIFI_STATE_UNINSTALLED";
GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_UNINSTALLED);
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::wlanIface());
break;
case NM_DEVICE_STATE_UNMANAGED:
wifiState = "WIFI_STATE_DISABLED";
GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_DISABLED);
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::wlanIface());
isEthDisabled = true;
break;
case NM_DEVICE_STATE_UNAVAILABLE:
case NM_DEVICE_STATE_DISCONNECTED:
wifiState = "WIFI_STATE_DISCONNECTED";
GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_DISCONNECTED);
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_LINK_DOWN, nmUtils::wlanIface());
break;
case NM_DEVICE_STATE_PREPARE:
wifiState = "WIFI_STATE_PAIRING";
GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_PAIRING);
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_LINK_UP, nmUtils::wlanIface());
break;
case NM_DEVICE_STATE_CONFIG:
wifiState = "WIFI_STATE_CONNECTING";
Expand Down Expand Up @@ -159,18 +166,27 @@ namespace WPEFramework
wifiState = "Un handiled: " ;
wifiState += std::to_string(deviceState);
}

if(isWlanDisabled & deviceState > NM_DEVICE_STATE_UNMANAGED)
{
isWlanDisabled = false;
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::wlanIface());
}

break;
}
}
NMLOG_DEBUG("wifi state: %s", wifiState.c_str());
}
else if(ifname == nmEvents->ifnameEth0)
else if(ifname == nmUtils::ethIface())
{
switch (deviceState)
{
case NM_DEVICE_STATE_UNKNOWN:
case NM_DEVICE_STATE_UNMANAGED:
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_DISABLED, nmUtils::ethIface());
break;
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::ethIface());
isEthDisabled = true;
break;
case NM_DEVICE_STATE_UNAVAILABLE:
case NM_DEVICE_STATE_DISCONNECTED:
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_LINK_DOWN, nmUtils::ethIface());
Expand All @@ -187,10 +203,15 @@ namespace WPEFramework
default:
NMLOG_WARNING("Unhandiled state change %d", deviceState);
}

if(isEthDisabled & deviceState > NM_DEVICE_STATE_UNMANAGED)
{
isEthDisabled = false;
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::ethIface());
}
}

NMLOG_DEBUG("%s state: (%d)", ifname.c_str(), deviceState);

}

static void ip4ChangedCb(NMIPConfig *ipConfig, GParamSpec *pspec, gpointer userData)
Expand Down Expand Up @@ -282,15 +303,15 @@ namespace WPEFramework
if( ((device != NULL) && NM_IS_DEVICE(device)) )
{
std::string ifname = nm_device_get_iface(device);
if(ifname == nmEvents->ifnameWlan0) {
if(ifname == nmUtils::wlanIface()) {
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::wlanIface());
}
else if(ifname == nmEvents->ifnameEth0) {
else if(ifname == nmUtils::ethIface()) {
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::ethIface());
}

/* ip events added only for eth0 and wlan0 */
if((ifname == nmEvents->ifnameEth0) || (ifname == nmEvents->ifnameWlan0))
if(ifname == nmUtils::ethIface() || ifname == nmUtils::wlanIface())
{
g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(deviceStateChangeCb), nmEvents);
// TODO call notify::" NM_DEVICE_ACTIVE_CONNECTION if needed
Expand All @@ -314,11 +335,11 @@ namespace WPEFramework
if( ((device != NULL) && NM_IS_DEVICE(device)) )
{
std::string ifname = nm_device_get_iface(device);
if(ifname == nmEvents->ifnameWlan0) {
if(ifname == nmUtils::wlanIface()) {
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::wlanIface());
g_signal_handlers_disconnect_by_func(device, (gpointer)deviceStateChangeCb, nmEvents);
}
else if(ifname == nmEvents->ifnameEth0) {
else if(ifname == nmUtils::ethIface()) {
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::ethIface());
g_signal_handlers_disconnect_by_func(device, (gpointer)deviceStateChangeCb, nmEvents);
}
Expand Down Expand Up @@ -383,11 +404,11 @@ namespace WPEFramework
NMDevice *device = NM_DEVICE(g_ptr_array_index(devices, count));
if( ((device != NULL) && NM_IS_DEVICE(device)) )
{
g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(deviceStateChangeCb), nmEvents);
//g_signal_connect(device, "notify::" NM_DEVICE_ACTIVE_CONNECTION, G_CALLBACK(deviceActiveConnChangeCb), NULL);
std::string ifname = nm_device_get_iface(device);
if((ifname == nmEvents->ifnameEth0) || (ifname == nmEvents->ifnameWlan0)) /* ip events added only for eth0 and wlan0 */
if((ifname == nmUtils::ethIface()) || (ifname == nmUtils::wlanIface()))
{
deviceStateChangeCb(device, nullptr, nullptr); //posting event if interface already connected
g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(deviceStateChangeCb), nmEvents);
NMIPConfig *ipv4Config = nm_device_get_ip4_config(device);
NMIPConfig *ipv6Config = nm_device_get_ip6_config(device);
if (ipv4Config) {
Expand Down Expand Up @@ -485,8 +506,6 @@ namespace WPEFramework
return;
}
_nmEventInstance = this;
nmEvents.ifnameEth0 = nmUtils::ethIface();
nmEvents.ifnameWlan0 = nmUtils::wlanIface();
}

/* Gnome networkmanger new events */
Expand All @@ -506,7 +525,7 @@ namespace WPEFramework

void GnomeNetworkManagerEvents::onInterfaceStateChangeCb(uint8_t newState, std::string iface)
{
std::string state = "";
std::string state {};
switch (newState)
{
case Exchange::INetworkManager::INTERFACE_ADDED:
Expand All @@ -530,8 +549,9 @@ namespace WPEFramework
default:
state = "Unknown";
}

NMLOG_DEBUG("%s interface state changed - %s", iface.c_str(), state.c_str());
if(_instance != nullptr && (iface == _nmEventInstance->nmEvents.ifnameWlan0 || iface == _nmEventInstance->nmEvents.ifnameEth0))
if(_instance != nullptr && (iface == nmUtils::wlanIface() || iface == nmUtils::ethIface()))
_instance->ReportInterfaceStateChange(static_cast<Exchange::INetworkManager::InterfaceState>(newState), iface);
}

Expand Down
7 changes: 3 additions & 4 deletions WiFiSignalStrengthMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ namespace WPEFramework
ssid = retrieveValues(ssid_command, "ssid", buff, sizeof (buff));
if (ssid.empty())
{
NMLOG_ERROR("ssid is empty");
quality = Exchange::INetworkManager::WIFI_SIGNAL_DISCONNECTED;
strengthOut = "0.00";
return;
}

Expand All @@ -71,6 +71,7 @@ namespace WPEFramework
if (signalStrengthOut == 0.0f)
{
quality = Exchange::INetworkManager::WIFI_SIGNAL_DISCONNECTED;
strengthOut = "0.00";
}
else if (signalStrengthOut >= signalStrengthThresholdExcellent && signalStrengthOut < 0)
{
Expand Down Expand Up @@ -100,14 +101,12 @@ namespace WPEFramework
isRunning = true;
monitorThread = std::thread(&WiFiSignalStrengthMonitor::monitorThreadFunction, this, interval);
monitorThread.detach();
std::thread::id threadId = monitorThread.get_id();
NMLOG_INFO("Thread started with interval: %d seconds", interval);
}

void WiFiSignalStrengthMonitor::monitorThreadFunction(int interval)
{
static Exchange::INetworkManager::WiFiSignalQuality oldSignalQuality = Exchange::INetworkManager::WIFI_SIGNAL_DISCONNECTED;
NMLOG_INFO("WiFiSignalStrengthMonitor thread started !");
NMLOG_INFO("WiFiSignalStrengthMonitor thread started ! (%d)", interval);
while (!stopThread)
{
string ssid = "";
Expand Down

0 comments on commit c8fd19d

Please sign in to comment.