From 0b5ab39dbf14b4d3d34c4a37b10fa084d0fb272a Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 24 May 2011 12:37:55 -0500 Subject: [PATCH] wifi: always fix up Ad-Hoc frequency when connecting (rh #699203) This used to only happen for user-created APs, but the supplicant always wants a frequency no matter what, and the kernel drivers will normally merge with any other IBSS with the same SSID no matter what frequency is used, so we might as well just pass something since it doesn't really matter in the end anyway. As a bonus we get to remove the user_created stuff since it doesn't really matter much anymore. --- src/nm-device-wifi.c | 33 +++++++++++++-------------------- src/nm-wifi-ap.c | 28 ---------------------------- src/nm-wifi-ap.h | 3 --- 3 files changed, 13 insertions(+), 51 deletions(-) diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c index 9142137abf..7a6e7528b8 100644 --- a/src/nm-device-wifi.c +++ b/src/nm-device-wifi.c @@ -2871,7 +2871,7 @@ remove_supplicant_timeouts (NMDeviceWifi *self) } static guint32 -find_supported_frequency (NMDeviceWifi *self, guint32 *freqs) +find_supported_frequency (NMDeviceWifi *self, const guint32 *freqs) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); int i; @@ -2907,25 +2907,25 @@ build_supplicant_config (NMDeviceWifi *self, if (!config) return NULL; - /* Figure out the Ad-Hoc frequency to use if creating an adhoc network; if - * nothing was specified then pick something usable. + /* Supplicant requires an initial frequency for Ad-Hoc networks; if the user + * didn't specify one and we didn't find an AP that matched the connection, + * just pick a frequency the device supports. */ - if ((nm_ap_get_mode (ap) == NM_802_11_MODE_ADHOC) && nm_ap_get_user_created (ap)) { + if (nm_ap_get_mode (ap) == NM_802_11_MODE_ADHOC) { const char *band = nm_setting_wireless_get_band (s_wireless); + const guint32 a_freqs[] = { 5180, 5200, 5220, 5745, 5765, 5785, 5805, 0 }; + const guint32 bg_freqs[] = { 2412, 2437, 2462, 2472, 0 }; adhoc_freq = nm_ap_get_freq (ap); if (!adhoc_freq) { - if (band && !strcmp (band, "a")) { - guint32 a_freqs[] = {5180, 5200, 5220, 5745, 5765, 5785, 5805, 0}; + if (g_strcmp0 (band, "a") == 0) adhoc_freq = find_supported_frequency (self, a_freqs); - } else { - guint32 bg_freqs[] = {2412, 2437, 2462, 2472, 0}; + else adhoc_freq = find_supported_frequency (self, bg_freqs); - } } if (!adhoc_freq) { - if (band && !strcmp (band, "a")) + if (g_strcmp0 (band, "a") == 0) adhoc_freq = 5180; else adhoc_freq = 2462; @@ -3118,15 +3118,8 @@ real_act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) ap = nm_ap_new_fake_from_connection (connection); g_return_val_if_fail (ap != NULL, NM_ACT_STAGE_RETURN_FAILURE); - switch (nm_ap_get_mode (ap)) { - case NM_802_11_MODE_ADHOC: - nm_ap_set_user_created (ap, TRUE); - break; - case NM_802_11_MODE_INFRA: - default: - nm_ap_set_broadcast (ap, FALSE); - break; - } + if (nm_ap_get_mode (ap) == NM_802_11_MODE_INFRA) + nm_ap_set_broadcast (ap, FALSE); priv->ap_list = g_slist_prepend (priv->ap_list, ap); nm_ap_export_to_dbus (ap); @@ -3419,7 +3412,7 @@ activation_success_handler (NMDevice *dev) nm_ap_set_address (ap, &bssid); if (!nm_ap_get_freq (ap)) nm_ap_set_freq (ap, nm_device_wifi_get_frequency (self)); - if (!nm_ap_get_max_bitrate (ap) && nm_ap_get_user_created (ap)) + if (!nm_ap_get_max_bitrate (ap)) nm_ap_set_max_bitrate (ap, nm_device_wifi_get_bitrate (self)); tmp_ap = get_active_ap (self, ap, TRUE); diff --git a/src/nm-wifi-ap.c b/src/nm-wifi-ap.c index c5f4509f43..f9c664738a 100644 --- a/src/nm-wifi-ap.c +++ b/src/nm-wifi-ap.c @@ -58,12 +58,6 @@ typedef struct /* Non-scanned attributes */ gboolean fake; /* Whether or not the AP is from a scan */ gboolean broadcast; /* Whether or not the AP is broadcasting (hidden) */ - gboolean user_created; /* Whether or not the AP was created - * by the user with "Create network..." - * A subset of Ad-Hoc mode. user_created - * implies Ad-Hoc, but not necessarily - * the other way around. - */ glong last_seen; /* Last time the AP was seen in a scan in seconds */ /* Things from user prefs/NetworkManagerInfo */ @@ -1158,28 +1152,6 @@ void nm_ap_set_last_seen (NMAccessPoint *ap, const glong last_seen) } -/* - * Get/Set functions to indicate that an access point is - * user-created, ie whether or not its a network filled with - * information from the user and intended to create a new Ad-Hoc - * wireless network. - * - */ -gboolean nm_ap_get_user_created (const NMAccessPoint *ap) -{ - g_return_val_if_fail (NM_IS_AP (ap), FALSE); - - return NM_AP_GET_PRIVATE (ap)->user_created; -} - -void nm_ap_set_user_created (NMAccessPoint *ap, gboolean user_created) -{ - g_return_if_fail (NM_IS_AP (ap)); - - NM_AP_GET_PRIVATE (ap)->user_created = user_created; -} - - /* * Get/Set functions for user address list * diff --git a/src/nm-wifi-ap.h b/src/nm-wifi-ap.h index 4c98f248d3..95514ba6cc 100644 --- a/src/nm-wifi-ap.h +++ b/src/nm-wifi-ap.h @@ -104,9 +104,6 @@ void nm_ap_set_broadcast (NMAccessPoint *ap, gboolean broadcast); glong nm_ap_get_last_seen (const NMAccessPoint *ap); void nm_ap_set_last_seen (NMAccessPoint *ap, const glong last_seen); -gboolean nm_ap_get_user_created (const NMAccessPoint *ap); -void nm_ap_set_user_created (NMAccessPoint *ap, gboolean user_created); - GSList * nm_ap_get_user_addresses (const NMAccessPoint *ap); void nm_ap_set_user_addresses (NMAccessPoint *ap, GSList *list);