Skip to content

Commit

Permalink
getInterfacestate added
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Nov 1, 2024
1 parent afe84da commit 981b1f2
Showing 1 changed file with 60 additions and 31 deletions.
91 changes: 60 additions & 31 deletions NetworkManagerGnomeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ namespace WPEFramework
{
uint32_t rc = Core::ERROR_GENERAL;
static std::vector<Exchange::INetworkManager::InterfaceDetails> interfaceList;
std::string wifiname;
std::string ethname;
std::string wifiname, ethname;
int interfaceCount = 0;

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

if(!nmUtils::GetInterfacesName(wifiname, ethname)) {
NMLOG_FATAL("GetInterface Name Error !");
Expand All @@ -76,11 +81,12 @@ namespace WPEFramework
if(NM_DEVICE_TYPE_WIFI == type) {
interface.m_type = string("WIFI");
interface.m_name = wifiname;
interfaceCount++;
}

if(NM_DEVICE_TYPE_ETHERNET == type) {
interface.m_type = string("ETHERNET");
interface.m_name = ethname;
interfaceCount++;
}
interface.m_mac = nm_device_get_hw_address(device);
deviceState = nm_device_get_state(device);
Expand All @@ -91,6 +97,8 @@ namespace WPEFramework
interface.m_isConnected = false;
interfaceList.push_back(interface);
rc = Core::ERROR_NONE;
if(interfaceCount > 1) // only need 2 interface details
break;
}
}
}
Expand All @@ -116,26 +124,30 @@ 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)
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, 8);
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 @@ -245,32 +257,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, 8);
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(const string& interface /* @in */, const string& ipversion /* @in */, IPAddressInfo& result /* @out */)
Expand Down

0 comments on commit 981b1f2

Please sign in to comment.