Skip to content

Commit

Permalink
SetIPsettings stuck in Gmailoop (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi authored and karuna2git committed Dec 11, 2024
1 parent 3c2a140 commit ca90b6c
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 169 deletions.
4 changes: 2 additions & 2 deletions NetworkManagerGnomeEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@ namespace WPEFramework
{
JsonObject ssidObj;
ap = static_cast<NMAccessPoint*>(accessPoints->pdata[i]);
ssidObj = nmUtils::apToJsonObject(ap);
ssidList.Add(ssidObj);
if(nmUtils::apToJsonObject(ap, ssidObj))
ssidList.Add(ssidObj);
}

ssidList.ToString(ssidListJson);
Expand Down
130 changes: 3 additions & 127 deletions NetworkManagerGnomeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,136 +514,12 @@ namespace WPEFramework
return rc;
}

// Callback for nm_client_deactivate_connection_async
static void on_deactivate_complete(GObject *source_object, GAsyncResult *res, gpointer user_data) {
GError *error = NULL;

// Check if the operation was successful
if (!nm_client_deactivate_connection_finish(NM_CLIENT(source_object), res, &error)) {
NMLOG_DEBUG("Deactivating connection failed: %s", error->message);
g_error_free(error);
} else {
NMLOG_DEBUG("Deactivating connection successful");
}
g_main_loop_quit((GMainLoop*)user_data);
}

// Callback for nm_client_activate_connection_async
static void on_activate_complete(GObject *source_object, GAsyncResult *res, gpointer user_data) {
GError *error = NULL;

// Check if the operation was successful
if (!nm_client_activate_connection_finish(NM_CLIENT(source_object), res, &error)) {
NMLOG_DEBUG("Activating connection failed: %s", error->message);
g_error_free(error);
} else {
NMLOG_DEBUG("Activating connection successful");
}

g_main_loop_quit((GMainLoop*)user_data);
}


/* @brief Set IP Address Of the Interface */
uint32_t NetworkManagerImplementation::SetIPSettings(const string& interface /* @in */, const IPAddress& address /* @in */)
{
GMainLoop *g_loop;
g_loop = g_main_loop_new(NULL, FALSE);
uint32_t rc = Core::ERROR_NONE;
if(client == nullptr)
{
NMLOG_WARNING("client connection null");
return Core::ERROR_GENERAL;
}
const GPtrArray *connections = nm_client_get_connections(client);
NMSettingIP4Config *s_ip4;
NMSettingIP6Config *s_ip6;
NMConnection *conn = NULL;
NMSettingConnection *settings;
NMRemoteConnection *remote_connection;
NMSetting *setting;
const char *uuid;
NMDevice *device = NULL;
const char *spec_object;

for (guint i = 0; i < connections->len; i++) {
NMConnection *connection = NM_CONNECTION(connections->pdata[i]);
settings = nm_connection_get_setting_connection(connection);

/* Check if the interface name matches */
if (g_strcmp0(nm_setting_connection_get_interface_name(settings), interface.c_str()) == 0) {
conn = connection;
break;
}
}
if (!address.autoconfig)
{
if (nmUtils::caseInsensitiveCompare("IPv4", address.ipversion))
{
NMSettingIPConfig *ip4_config = nm_connection_get_setting_ip4_config(conn);
if (ip4_config == NULL)
{
ip4_config = (NMSettingIPConfig *)nm_setting_ip4_config_new();
}
NMIPAddress *ipAddress;
setting = nm_connection_get_setting_by_name(conn, "ipv4");
ipAddress = nm_ip_address_new(AF_INET, address.ipaddress.c_str(), address.prefix, NULL);
nm_setting_ip_config_clear_addresses(ip4_config);
nm_setting_ip_config_add_address(NM_SETTING_IP_CONFIG(setting), ipAddress);
nm_setting_ip_config_clear_dns(ip4_config);
nm_setting_ip_config_add_dns(ip4_config, address.primarydns.c_str());
nm_setting_ip_config_add_dns(ip4_config, address.secondarydns.c_str());

g_object_set(G_OBJECT(ip4_config),
NM_SETTING_IP_CONFIG_GATEWAY, address.gateway.c_str(),
NM_SETTING_IP_CONFIG_NEVER_DEFAULT,
FALSE,
NULL);
}
else
{
//FIXME : Add IPv6 support here
NMLOG_WARNING("Setting IPv6 is not supported at this point in time. This is just a place holder");
rc = Core::ERROR_NOT_SUPPORTED;
}
}
else
{
if (nmUtils::caseInsensitiveCompare("IPv4", address.ipversion))
{
s_ip4 = (NMSettingIP4Config *)nm_setting_ip4_config_new();
g_object_set(G_OBJECT(s_ip4), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting(conn, NM_SETTING(s_ip4));
}
else
{
s_ip6 = (NMSettingIP6Config *)nm_setting_ip6_config_new();
g_object_set(G_OBJECT(s_ip6), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL);
nm_connection_add_setting(conn, NM_SETTING(s_ip6));
}
}
device = nm_client_get_device_by_iface(client, interface.c_str());
uuid = nm_connection_get_uuid(conn);
remote_connection = nm_client_get_connection_by_uuid(client, uuid);
NMActiveConnection *active_connection = NULL;

const GPtrArray *acv_connections = nm_client_get_active_connections(client);
for (guint i = 0; i < acv_connections->len; i++) {
NMActiveConnection *connection1 = NM_ACTIVE_CONNECTION(acv_connections->pdata[i]);
settings = nm_connection_get_setting_connection(NM_CONNECTION(nm_active_connection_get_connection(connection1)));

/* Check if the interface name matches */
if (g_strcmp0(nm_setting_connection_get_interface_name(settings), interface.c_str()) == 0) {
active_connection = connection1;
break;
}
}

spec_object = nm_object_get_path(NM_OBJECT(active_connection));
nm_remote_connection_commit_changes(remote_connection, false, NULL, NULL);
nm_client_deactivate_connection_async(client, active_connection, NULL, on_deactivate_complete, NULL);
nm_client_activate_connection_async(client, conn, device, spec_object, NULL, on_activate_complete, g_loop);
g_main_loop_run(g_loop);
uint32_t rc = Core::ERROR_GENERAL;
if(wifi->setIpSettings(interface, address))
rc = Core::ERROR_NONE;
return rc;
}

Expand Down
14 changes: 6 additions & 8 deletions NetworkManagerGnomeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,15 @@ namespace WPEFramework
return freq;
}

JsonObject nmUtils::apToJsonObject(NMAccessPoint *ap)
bool nmUtils::apToJsonObject(NMAccessPoint *ap, JsonObject& ssidObj)
{
GError *error = NULL;
GBytes *ssid = NULL;
int strength = 0;
std::string freq;
int security;
guint32 flags, wpaFlags, rsnFlags, apFreq;
JsonObject ssidObj;
if(ap == nullptr)
return ssidObj;
return false;
ssid = nm_access_point_get_ssid(ap);
if (ssid)
{
Expand All @@ -227,11 +225,11 @@ namespace WPEFramework
ssidObj["security"] = security;
ssidObj["strength"] = nmUtils::convertPercentageToSignalStrengtStr(strength);
ssidObj["frequency"] = freq;
return true;
}
else
NMLOG_DEBUG("hidden ssid found, bssid: %s", nm_access_point_get_bssid(ap));

return ssidObj;
// else
// NMLOG_DEBUG("hidden ssid found, bssid: %s", nm_access_point_get_bssid(ap));
return false;
}

void nmUtils::printActiveSSIDsOnly(NMDeviceWifi *wifiDevice)
Expand Down
2 changes: 1 addition & 1 deletion NetworkManagerGnomeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace WPEFramework
static uint8_t wifiSecurityModeFromAp(guint32 flags, guint32 wpaFlags, guint32 rsnFlags);
static std::string wifiFrequencyFromAp(guint32 apFreq);
static std::string getSecurityModeString(guint32 flags, guint32 wpaFlags, guint32 rsnFlags);
static JsonObject apToJsonObject(NMAccessPoint *ap);
static bool apToJsonObject(NMAccessPoint *ap, JsonObject& ssidObj);
static void printActiveSSIDsOnly(NMDeviceWifi *wifiDevice);
static NMDeviceState ifaceState(NMClient *client, const char* interface);
};
Expand Down
Loading

0 comments on commit ca90b6c

Please sign in to comment.