Skip to content

Commit

Permalink
RDKEMW-234: [RDKE][GNOME] Not getting values for WIFI interface on Ge…
Browse files Browse the repository at this point in the history
…tAvailableInterfaces method (#31)

* Gnome issue fix for following api
 wifiConnect
 addtoknownssid
 removeknowssid
 getavilablessid
 getwifisiganlstrength

 GetAvailableInterfaces
 GetPrimaryInterface
 GetInterfaceState
 GetIPSettings

* onAddressChange event modified
* Posting event even if interface already connected before plugin start
* Update NetworkManagerGnomeEvents.cpp

Signed-off-by: cmuhammedrafi <[email protected]>
  • Loading branch information
cmuhammedrafi authored Nov 18, 2024
1 parent e01ff54 commit 661d49d
Show file tree
Hide file tree
Showing 9 changed files with 781 additions and 637 deletions.
98 changes: 56 additions & 42 deletions NetworkManagerGnomeEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,27 @@ namespace WPEFramework
const char *connectionTyp = NULL;
primaryConn = nm_client_get_primary_connection(client);
nmEvents->activeConn = primaryConn;
std::string newIface ="unknown";
if (primaryConn)
{
activeConnId = nm_active_connection_get_id(primaryConn);
connectionTyp = nm_active_connection_get_connection_type(primaryConn);
NMLOG_INFO("active connection - %s (%s)", activeConnId, connectionTyp);
std::string newIface ="";

if (0 == strncmp("802-3-ethernet", connectionTyp, sizeof("802-3-ethernet")))
newIface = "eth0";
newIface = nmUtils::ethIface();
else if(0 == strncmp("802-11-wireless", connectionTyp, sizeof("802-11-wireless")))
newIface = "wlan0";
newIface = nmUtils::wlanIface();
else
NMLOG_WARNING("active connection not an ethernet/wifi %s", connectionTyp);

GnomeNetworkManagerEvents::onActiveInterfaceChangeCb(newIface);
}
else
NMLOG_ERROR("now there's no active connection");
{
GnomeNetworkManagerEvents::onActiveInterfaceChangeCb(newIface);
NMLOG_WARNING("now there's no active connection");
}
}

static void deviceStateChangeCb(NMDevice *device, GParamSpec *pspec, NMEvents *nmEvents)
Expand Down Expand Up @@ -134,7 +137,7 @@ namespace WPEFramework
GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_CONNECTING);
break;
case NM_DEVICE_STATE_IP_CHECK:
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ACQUIRING_IP,"wlan0");
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ACQUIRING_IP, nmUtils::wlanIface());
break;
case NM_DEVICE_STATE_ACTIVATED:
wifiState = "WIFI_STATE_CONNECTED";
Expand All @@ -150,10 +153,11 @@ namespace WPEFramework
break;
case NM_DEVICE_STATE_NEED_AUTH:
//GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_CONNECTION_INTERRUPTED);
//wifiState = "WIFI_STATE_CONNECTION_INTERRUPTED";
wifiState = "WIFI_STATE_CONNECTION_INTERRUPTED";
break;
default:
wifiState = "Un handiled";
wifiState = "Un handiled: " ;
wifiState += std::to_string(deviceState);
}
}
}
Expand All @@ -165,23 +169,23 @@ namespace WPEFramework
{
case NM_DEVICE_STATE_UNKNOWN:
case NM_DEVICE_STATE_UNMANAGED:
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_DISABLED, "eth0");
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_DISABLED, nmUtils::ethIface());
break;
case NM_DEVICE_STATE_UNAVAILABLE:
case NM_DEVICE_STATE_DISCONNECTED:
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_LINK_DOWN, "eth0");
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_LINK_DOWN, nmUtils::ethIface());
break;
case NM_DEVICE_STATE_PREPARE:
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_LINK_UP, "eth0");
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_LINK_UP, nmUtils::ethIface());
break;
case NM_DEVICE_STATE_IP_CONFIG:
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ACQUIRING_IP,"eth0");
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ACQUIRING_IP, nmUtils::ethIface());
case NM_DEVICE_STATE_NEED_AUTH:
case NM_DEVICE_STATE_SECONDARIES:
case NM_DEVICE_STATE_ACTIVATED:
case NM_DEVICE_STATE_DEACTIVATING:
default:
NMLOG_WARNING("Unhandiled state change");
NMLOG_WARNING("Unhandiled state change %d", deviceState);
}
}

Expand Down Expand Up @@ -256,10 +260,17 @@ namespace WPEFramework
for (guint i = 0; i < addresses->len; ++i) {
NMIPAddress *address = (NMIPAddress *)g_ptr_array_index(addresses, i);
if (nm_ip_address_get_family(address) == AF_INET6) {
const char *ipAddress = nm_ip_address_get_address(address);
const char *ipaddr = nm_ip_address_get_address(address);
//int prefix = nm_ip_address_get_prefix(address);
if(ipAddress != NULL) {
if(ipaddr != NULL) {
std::string ipAddress = ipaddr;
if (ipAddress.compare(0, 5, "fe80:") == 0 ||
ipAddress.compare(0, 6, "fe80::") == 0) {
NMLOG_DEBUG("%s It's link-local ip", ipAddress.c_str());
continue; // It's link-local so skiping
}
GnomeNetworkManagerEvents::onAddressChangeCb(iface, ipAddress, true, true);
break; // SLAAC protocol may include multip ipv6 address posting only one Global address
}
}
}
Expand All @@ -272,10 +283,10 @@ namespace WPEFramework
{
std::string ifname = nm_device_get_iface(device);
if(ifname == nmEvents->ifnameWlan0) {
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, "wlan0");
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::wlanIface());
}
else if(ifname == nmEvents->ifnameEth0) {
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, "eth0");
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::ethIface());
}

/* ip events added only for eth0 and wlan0 */
Expand Down Expand Up @@ -304,11 +315,11 @@ namespace WPEFramework
{
std::string ifname = nm_device_get_iface(device);
if(ifname == nmEvents->ifnameWlan0) {
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED,"wlan0");
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::wlanIface());
g_signal_handlers_disconnect_by_func(device, (gpointer)deviceStateChangeCb, nmEvents);
}
else if(ifname == nmEvents->ifnameEth0) {
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, "eth0");
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::ethIface());
g_signal_handlers_disconnect_by_func(device, (gpointer)deviceStateChangeCb, nmEvents);
}
}
Expand Down Expand Up @@ -380,10 +391,12 @@ namespace WPEFramework
NMIPConfig *ipv4Config = nm_device_get_ip4_config(device);
NMIPConfig *ipv6Config = nm_device_get_ip6_config(device);
if (ipv4Config) {
ip4ChangedCb(ipv4Config, NULL, device); // posting event if interface already connected
g_signal_connect(ipv4Config, "notify::addresses", G_CALLBACK(ip4ChangedCb), device);
}

if (ipv6Config) {
ip6ChangedCb(ipv6Config, NULL, device);
g_signal_connect(ipv6Config, "notify::addresses", G_CALLBACK(ip6ChangedCb), device);
}

Expand All @@ -393,7 +406,7 @@ namespace WPEFramework
}
}
else
NMLOG_DEBUG("device type not eth/wifi");
NMLOG_DEBUG("device type not eth/wifi %s", ifname.c_str());
}
}

Expand Down Expand Up @@ -453,12 +466,6 @@ namespace WPEFramework
GnomeNetworkManagerEvents::GnomeNetworkManagerEvents()
{
NMLOG_DEBUG("GnomeNetworkManagerEvents");
std::string wifiInterface = "wlan0", ethernetInterface = "eth0";
if(!nmUtils::GetInterfacesName(wifiInterface, ethernetInterface))
{
NMLOG_FATAL("GetInterfacesName failed");
return;
}
GError *error = NULL;
nmEvents.client = nm_client_new(NULL, &error);
if(!nmEvents.client || error )
Expand All @@ -478,8 +485,8 @@ namespace WPEFramework
return;
}
_nmEventInstance = this;
nmEvents.ifnameEth0 = ethernetInterface;
nmEvents.ifnameWlan0 = wifiInterface;
nmEvents.ifnameEth0 = nmUtils::ethIface();
nmEvents.ifnameWlan0 = nmUtils::wlanIface();
}

/* Gnome networkmanger new events */
Expand Down Expand Up @@ -539,28 +546,35 @@ namespace WPEFramework
static std::map<std::string, std::string> ipv6Map;
static std::map<std::string, std::string> ipv4Map;

if (isIPv6)
if(acquired)
{
if (ipAddress.empty()) {
ipAddress = ipv6Map[iface];
ipv6Map[iface].clear();
}
else {
if (isIPv6)
{
if (ipv6Map[iface].find(ipAddress) == std::string::npos) { // same ip comes multiple time so avoding that
if (!ipv6Map[iface].empty())
ipv6Map[iface] += " ";
ipv6Map[iface] += ipAddress; // SLAAC protocol may include multip ipv6 address
ipv6Map[iface] = ipAddress;
}
else
return; // skip same ip event posting
else // same ip not posting
return;
}
else
{
ipv4Map[iface] = ipAddress;
}
}
else
{
if (ipAddress.empty())
ipAddress = ipv4Map[iface];
if (isIPv6)
{
ipAddress = ipv6Map[iface];
ipv6Map[iface].clear();
}
else
ipv4Map[iface] = ipAddress;
{
ipAddress = ipv4Map[iface];
ipv4Map[iface].clear();
}
if(ipAddress.empty())
return; // empty ip address not posting event
}

Exchange::INetworkManager::IPStatus ipStatus{};
Expand All @@ -569,7 +583,7 @@ namespace WPEFramework

if(_instance != nullptr)
_instance->ReportIPAddressChange(iface, isIPv6?"IPv6":"IPv4", ipAddress, ipStatus);
NMLOG_INFO("iface:%s - ipaddress:%s - %s - isIPv6:%s", iface.c_str(), ipAddress.c_str(), acquired?"acquired":"lost", isIPv6?"true":"false");
NMLOG_INFO("iface:%s - ipaddress:%s - %s - %s", iface.c_str(), ipAddress.c_str(), acquired?"acquired":"lost", isIPv6?"isIPv6":"isIPv4");
}

void GnomeNetworkManagerEvents::onAvailableSSIDsCb(NMDeviceWifi *wifiDevice, GParamSpec *pspec, gpointer userData)
Expand Down
Loading

0 comments on commit 661d49d

Please sign in to comment.