Skip to content

Commit

Permalink
Gnome issue fix for following api
Browse files Browse the repository at this point in the history
    wifiConnect
    addtoknownssid
    removeknowssid
    getavilablessid

Signed-off-by: cmuhammedrafi <[email protected]>
  • Loading branch information
cmuhammedrafi committed Nov 4, 2024
1 parent bbd92e7 commit f31c75e
Show file tree
Hide file tree
Showing 5 changed files with 469 additions and 432 deletions.
61 changes: 39 additions & 22 deletions NetworkManagerGnomeEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ namespace WPEFramework
const char *connectionTyp = NULL;
primaryConn = nm_client_get_primary_connection(client);
nmEvents->activeConn = primaryConn;
std::string newIface ="unknow";
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";
Expand All @@ -64,7 +64,10 @@ namespace WPEFramework
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 @@ -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 Down Expand Up @@ -181,7 +185,7 @@ namespace WPEFramework
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 Down Expand Up @@ -393,7 +404,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 @@ -539,28 +550,34 @@ 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();
}

}

Exchange::INetworkManager::IPStatus ipStatus{};
Expand Down
161 changes: 98 additions & 63 deletions NetworkManagerGnomeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,47 +47,59 @@ namespace WPEFramework

uint32_t NetworkManagerImplementation::GetAvailableInterfaces (Exchange::INetworkManager::IInterfaceDetailsIterator*& interfacesItr/* @out */)
{
uint32_t rc = Core::ERROR_RPC_CALL_FAILED;
NMDeviceType type;
NMDeviceState state;
NMDevice *device = NULL;
static std::vector<Exchange::INetworkManager::InterfaceDetails> interfaceList;
uint32_t rc = Core::ERROR_GENERAL;
std::vector<Exchange::INetworkManager::InterfaceDetails> interfaceList;
std::string wifiname, ethname;

if(client == nullptr) {
NMLOG_WARNING("client connection null:");
return Core::ERROR_GENERAL;
}

if(!nmUtils::GetInterfacesName(wifiname, ethname)) {
NMLOG_FATAL("GetInterface Name Error !");
return Core::ERROR_GENERAL;
}

GPtrArray *devices = const_cast<GPtrArray *>(nm_client_get_devices(client));
if (devices == NULL) {
NMLOG_ERROR("Failed to get device list.");
return Core::ERROR_GENERAL;
}

if(interfaceList.empty())
for (guint j = 0; j < devices->len; j++)
{
std::string interfaces[2];
if(!nmUtils::GetInterfacesName(interfaces[0], interfaces[1]))
NMDevice *device = NM_DEVICE(devices->pdata[j]);
if(device != NULL)
{
NMLOG_WARNING("GetInterface Name Error !");
return Core::ERROR_GENERAL;
}
for (size_t i = 0; i < 2; i++)
{
if(!interfaces[i].empty())
NMDeviceType type = nm_device_get_device_type(device);
if(NM_DEVICE_TYPE_WIFI == type || NM_DEVICE_TYPE_ETHERNET== type ) // only wifi and ethenet taking
{
Exchange::INetworkManager::InterfaceDetails tmp;
device = nm_client_get_device_by_iface(client, interfaces[i].c_str());
if (device)
{
if(i == 0)
tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_WIFI;
else
tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_ETHERNET;
tmp.name = interfaces[i].c_str();
tmp.mac = nm_device_get_hw_address(device);
state = nm_device_get_state(device);
tmp.enabled = (state > NM_DEVICE_STATE_UNAVAILABLE) ? true : false;
tmp.connected = (state > NM_DEVICE_STATE_DISCONNECTED) ? true : false;
interfaceList.push_back(tmp);
//g_clear_object(&device);
NMDeviceState deviceState = NM_DEVICE_STATE_UNKNOWN;
Exchange::INetworkManager::InterfaceDetails interface;
if(NM_DEVICE_TYPE_WIFI == type) {
interface.type = INTERFACE_TYPE_WIFI;
interface.name = wifiname;
}
if(NM_DEVICE_TYPE_ETHERNET == type) {
interface.type = INTERFACE_TYPE_ETHERNET;
interface.name = ethname;
}
interface.mac = nm_device_get_hw_address(device);
deviceState = nm_device_get_state(device);
interface.enabled = (deviceState > NM_DEVICE_STATE_UNAVAILABLE) ? true : false;
if(deviceState > NM_DEVICE_STATE_DISCONNECTED && deviceState < NM_DEVICE_STATE_DEACTIVATING)
interface.connected = true;
else
interface.connected = false;
interfaceList.push_back(interface);
rc = Core::ERROR_NONE;
}
}
}

using Implementation = RPC::IteratorType<Exchange::INetworkManager::IInterfaceDetailsIterator>;
interfacesItr = Core::Service<Implementation>::Create<Exchange::INetworkManager::IInterfaceDetailsIterator>(interfaceList);
rc = Core::ERROR_NONE;
return rc;
}

Expand All @@ -107,25 +119,28 @@ namespace WPEFramework
activeConn = nm_client_get_primary_connection(client);
if (activeConn == NULL) {
NMLOG_ERROR("No active activeConn Interface found");
return Core::ERROR_GENERAL;
interface.clear();
return Core::ERROR_NONE;
}
remoteConn = nm_active_connection_get_connection(activeConn);
if(remoteConn == NULL)
{
NMLOG_WARNING("remote connection error");
return Core::ERROR_GENERAL;
}
interface.clear();
const char *ifacePtr = nm_connection_get_interface_name(NM_CONNECTION(remoteConn));
if(ifacePtr == NULL)
{
NMLOG_ERROR("nm_connection_get_interface_name is failed");
return Core::ERROR_GENERAL;
}
interface = ifacePtr;
if(interface != "eth0" && interface != "wlan0")

interface.assign(ifacePtr);
std::string wifiname, ethname;
nmUtils::GetInterfacesName(wifiname, ethname);
if(interface != wifiname && interface != ethname)
{
NMLOG_DEBUG("interface name is unknow");
NMLOG_ERROR("primary interface is not eth/wlan");
interface.clear();
}
else
Expand Down Expand Up @@ -235,32 +250,49 @@ namespace WPEFramework

uint32_t NetworkManagerImplementation::GetInterfaceState(const string& interface/* @in */, bool& isEnabled /* @out */)
{
uint32_t rc = Core::ERROR_NONE;
#if 0 //FIXME
const GPtrArray *devices = nm_client_get_devices(client);
NMDevice *device = NULL;

for (guint i = 0; i < devices->len; ++i) {
device = NM_DEVICE(g_ptr_array_index(devices, i));

// Get the device details
const char *name = nm_device_get_iface(device);
isEnabled = false;
bool isIfaceFound = false;
if(client == nullptr)
{
NMLOG_WARNING("client connection null:");
return Core::ERROR_GENERAL;
}

// Check if the device name matches
if (g_strcmp0(name, interface.c_str()) == 0) {
nm_device_set_managed(device, false);
GPtrArray *devices = const_cast<GPtrArray *>(nm_client_get_devices(client));
if (devices == NULL) {
NMLOG_ERROR("Failed to get device list.");
return Core::ERROR_GENERAL;
}

NMLOG_DEBUG("Interface %s status set to disabled",
interface.c_str());
for (guint j = 0; j < devices->len; j++)
{
NMDevice *device = NM_DEVICE(devices->pdata[j]);
if(device != NULL)
{
const char* iface = nm_device_get_iface(device);
if(iface != NULL)
{
std::string ifaceStr;
ifaceStr.assign(iface);
NMDeviceState deviceState = NM_DEVICE_STATE_UNKNOWN;
if(ifaceStr == interface)
{
isIfaceFound = true;
deviceState = nm_device_get_state(device);
isEnabled = (deviceState > NM_DEVICE_STATE_UNAVAILABLE) ? true : false;
NMLOG_INFO("%s : %s", ifaceStr.c_str(), isEnabled?"enabled":"disabled");
break;
}
}
}
}
// Cleanup
if(device)
g_clear_object(&device);
#endif
return rc;
}

if(isIfaceFound)
return Core::ERROR_NONE;
else
NMLOG_ERROR("%s : not found", interface.c_str());
return Core::ERROR_GENERAL;
}

/* @brief Get IP Address Of the Interface */
uint32_t NetworkManagerImplementation::GetIPSettings(string& interface /* @inout */, const string &ipversion /* @in */, IPAddress& result /* @out */)
Expand All @@ -284,7 +316,7 @@ namespace WPEFramework
return Core::ERROR_RPC_CALL_FAILED;
}

std::string iface = "eth0";
std::string iface = "wlan0";
std::string ethIface, wifiIface;
if(!nmUtils::GetInterfacesName(wifiIface, ethIface))
{
Expand All @@ -303,6 +335,8 @@ namespace WPEFramework
NMLOG_WARNING("interface is not specified and default interface get failed");
return Core::ERROR_GENERAL;
}
else
iface = wifiIface;
}

device = nm_client_get_device_by_iface(client, iface.c_str());
Expand All @@ -313,9 +347,9 @@ namespace WPEFramework

NMDeviceState deviceState = NM_DEVICE_STATE_UNKNOWN;
deviceState = nm_device_get_state(device);
if(deviceState != NM_DEVICE_STATE_ACTIVATED)
if(deviceState < NM_DEVICE_STATE_DISCONNECTED)
{
NMLOG_WARNING("device state is not activated state: (%d)", deviceState);
NMLOG_WARNING("Device state is not a valid state: (%d)", deviceState);
return Core::ERROR_GENERAL;
}

Expand Down Expand Up @@ -343,7 +377,7 @@ namespace WPEFramework
return Core::ERROR_GENERAL;
}

if(ipversion.empty()||nmUtils::caseInsensitiveCompare(ipversion,"IPV4"))
if(ipversion.empty() || nmUtils::caseInsensitiveCompare(ipversion,"IPV4"))
{
ip4_config = nm_active_connection_get_ip4_config(conn);
if (ip4_config != NULL) {
Expand Down Expand Up @@ -613,11 +647,12 @@ namespace WPEFramework
NMLOG_WARNING("ssid is invalied");
return rc;
}
// Check the last scanning time and if it exceeds 10 sec do a rescanning

// Check the last scanning time and if it exceeds 10 sec do a rescanning
if(!wifi->isWifiScannedRecently())
{
nmEvent->setwifiScanOptions(false, true); // not notify scan result but print logs
if(!wifi->wifiScanRequest("", ssid.ssid))
if(!wifi->wifiScanRequest())
{
NMLOG_WARNING("scanning failed but try to connect");
}
Expand Down
Loading

0 comments on commit f31c75e

Please sign in to comment.