From c7d1bf18c45cb72c2b0cae42f763f98a7d04e4e9 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 11 Apr 2011 11:42:12 -0500 Subject: [PATCH] wifi: fix connection completion when no wifi setting is sent In NMDeviceWifi's real_complete_connection() the wifi setting was looked up at the start of the function, but if no wifi setting was sent by the caller, it would be NULL. The wifi setting would later get added by nm_ap_utils_complete_connection(), but after calling that the new wifi setting would not be looked up again. Make that clearer by moving the wifi setting add code to the wifi device's real_complete_connection() and not burying it in some other function. This is more like what other device types do. --- src/nm-device-wifi.c | 18 +++++++++++++----- src/nm-wifi-ap-utils.c | 12 ++++-------- src/tests/test-wifi-ap-utils.c | 8 ++++++++ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c index 626c2c0dba..9258f77c27 100644 --- a/src/nm-device-wifi.c +++ b/src/nm-device-wifi.c @@ -1390,9 +1390,9 @@ real_complete_connection (NMDevice *device, const GByteArray *ssid = NULL; GSList *iter; - s_wifi = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS); - s_wsec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); - s_8021x = (NMSetting8021x *) nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X); + s_wifi = nm_connection_get_setting_wireless (connection); + s_wsec = nm_connection_get_setting_wireless_security (connection); + s_8021x = nm_connection_get_setting_802_1x (connection); if (!specific_object) { /* If not given a specific object, we need at minimum an SSID */ @@ -1430,8 +1430,10 @@ real_complete_connection (NMDevice *device, gboolean valid; settings = g_slist_prepend (settings, s_wifi); - settings = g_slist_prepend (settings, s_wsec); - settings = g_slist_prepend (settings, s_8021x); + if (s_wsec) + settings = g_slist_prepend (settings, s_wsec); + if (s_8021x) + settings = g_slist_prepend (settings, s_8021x); valid = nm_setting_verify (NM_SETTING (s_wifi), settings, error); g_slist_free (settings); if (!valid) @@ -1449,6 +1451,12 @@ real_complete_connection (NMDevice *device, } } + /* Add a wifi setting if one doesn't exist yet */ + if (!s_wifi) { + s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); + nm_connection_add_setting (connection, NM_SETTING (s_wifi)); + } + if (ap) { ssid = nm_ap_get_ssid (ap); diff --git a/src/nm-wifi-ap-utils.c b/src/nm-wifi-ap-utils.c index 1efcc9d8cd..215c4935c9 100644 --- a/src/nm-wifi-ap-utils.c +++ b/src/nm-wifi-ap-utils.c @@ -481,14 +481,10 @@ nm_ap_utils_complete_connection (const GByteArray *ap_ssid, const char *mode, *key_mgmt, *auth_alg, *leap_username; gboolean adhoc = FALSE; - s_wifi = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS); - s_wsec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); - s_8021x = (NMSetting8021x *) nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X); - - if (!s_wifi) { - s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - nm_connection_add_setting (connection, NM_SETTING (s_wifi)); - } + s_wifi = nm_connection_get_setting_wireless (connection); + g_assert (s_wifi); + s_wsec = nm_connection_get_setting_wireless_security (connection); + s_8021x = nm_connection_get_setting_802_1x (connection); /* Fill in missing SSID */ ssid = nm_setting_wireless_get_ssid (s_wifi); diff --git a/src/tests/test-wifi-ap-utils.c b/src/tests/test-wifi-ap-utils.c index deb31f3f5d..93bd325a5a 100644 --- a/src/tests/test-wifi-ap-utils.c +++ b/src/tests/test-wifi-ap-utils.c @@ -77,6 +77,14 @@ complete_connection (const char *ssid, { GByteArray *tmp; gboolean success; + NMSettingWireless *s_wifi; + + /* Add a wifi setting if one doesn't exist */ + s_wifi = nm_connection_get_setting_wireless (src); + if (!s_wifi) { + s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); + nm_connection_add_setting (src, NM_SETTING (s_wifi)); + } tmp = g_byte_array_sized_new (strlen (ssid)); g_byte_array_append (tmp, (const guint8 *) ssid, strlen (ssid));