Re: [PATCH 2/2] wifi: stop doing periodic scanning when supplicant bgscan is used



On Thu, 2013-08-08 at 13:20 +0200, Stanislaw Gruszka wrote:
NM schedule scan on intervals between 20 and 120 seconds. Don't do this
when wpa_supplicant background scanning is used.

One issue here is that bgscan only scans the current SSID and associated
channel, so you'll gradually get all the other APs drop out of the scan
list since the driver hasn't bothered to look on other channels, plus
since it's only probe-scanning one SSID it won't find any other APs on
the same channel.

I'd really like to defer the scanning to the supplicant, since it's got
a lot of logic for optimizing it.

But the longer-term fix here is to just defer scanning to clients almost
entirely:

1) UI applets can trigger a scan broadcast when they want to, like when
the menu is dropped down

2) location-services (like WiFi positioning) can request quicker scans
when they are actively positioning the system

3) other clients that really want to know what APs are around can
request that directly when they need it

NM already has a RequestScan method so these are already all possible,
but the UI clients need to be updated as described here.  Obviously when
disconnected NM would be responsible for doing periodic broadcast scans
to find APs to autoconnect to.

Dan

---
 src/devices/nm-device-wifi.c                          | 14 ++++++++++++--
 src/supplicant-manager/nm-supplicant-config.c         |  5 ++++-
 src/supplicant-manager/nm-supplicant-config.h         |  3 ++-
 src/supplicant-manager/tests/test-supplicant-config.c |  8 ++++++--
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/devices/nm-device-wifi.c b/src/devices/nm-device-wifi.c
index 2935e27..d92a75b 100644
--- a/src/devices/nm-device-wifi.c
+++ b/src/devices/nm-device-wifi.c
@@ -146,6 +146,7 @@ struct _NMDeviceWifiPrivate {
      Supplicant        supplicant;
      WifiData *        wifi_data;
      gboolean          ssid_found;
+     gboolean          bgscan_enabled;
      NM80211Mode       mode;
 
      guint32           failed_link_count;
@@ -1739,8 +1740,14 @@ schedule_scan (NMDeviceWifi *self, gboolean backoff)
              guint factor = 2, next_scan = priv->scan_interval;
 
              if (    nm_device_is_activating (NM_DEVICE (self))
-                 || (nm_device_get_state (NM_DEVICE (self)) == NM_DEVICE_STATE_ACTIVATED))
+                 || (nm_device_get_state (NM_DEVICE (self)) == NM_DEVICE_STATE_ACTIVATED)) {
                      factor = 1;
+                     if (priv->bgscan_enabled) {
+                             nm_log_dbg (LOGD_WIFI_SCAN, "(%s): do not schedule scan as scanning in 
background is enabled",
+                                         nm_device_get_iface (NM_DEVICE (self)));
+                             return;
+                     }
+             }
 
              priv->pending_scan_id = g_timeout_add_seconds (next_scan,
                                                             request_wireless_scan,
@@ -2742,6 +2749,8 @@ build_supplicant_config (NMDeviceWifi *self,
              goto error;
      }
 
+     priv->bgscan_enabled = FALSE;
+
      s_wireless_sec = nm_connection_get_setting_wireless_security (connection);
      if (s_wireless_sec) {
              NMSetting8021x *s_8021x;
@@ -2752,7 +2761,8 @@ build_supplicant_config (NMDeviceWifi *self,
              if (!nm_supplicant_config_add_setting_wireless_security (config,
                                                                       s_wireless_sec,
                                                                       s_8021x,
-                                                                      con_uuid)) {
+                                                                      con_uuid,
+                                                                      &priv->bgscan_enabled)) {
                      nm_log_err (LOGD_WIFI, "Couldn't add 802-11-wireless-security setting to "
                                  "supplicant config.");
                      goto error;
diff --git a/src/supplicant-manager/nm-supplicant-config.c b/src/supplicant-manager/nm-supplicant-config.c
index 446dc21..6305f1b 100644
--- a/src/supplicant-manager/nm-supplicant-config.c
+++ b/src/supplicant-manager/nm-supplicant-config.c
@@ -573,7 +573,8 @@ gboolean
 nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self,
                                                     NMSettingWirelessSecurity *setting,
                                                     NMSetting8021x *setting_8021x,
-                                                    const char *con_uuid)
+                                                    const char *con_uuid,
+                                                    gboolean *bgscan)
 {
      char *value;
      gboolean success;
@@ -692,6 +693,8 @@ nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self,
                       */
                      if (!nm_supplicant_config_add_option (self, "bgscan", "simple:30:-65:300", -1, FALSE))
                              nm_log_warn (LOGD_SUPPLICANT, "Error enabling background scanning for ESS 
roaming");
+                     else
+                             *bgscan = TRUE;
 
                      /* When using WPA-Enterprise, we want to use Proactive Key Caching (also
                       * called Opportunistic Key Caching) to avoid full EAP exchanges when
diff --git a/src/supplicant-manager/nm-supplicant-config.h b/src/supplicant-manager/nm-supplicant-config.h
index a8d3047..19a6dc1 100644
--- a/src/supplicant-manager/nm-supplicant-config.h
+++ b/src/supplicant-manager/nm-supplicant-config.h
@@ -72,7 +72,8 @@ gboolean nm_supplicant_config_add_setting_wireless (NMSupplicantConfig *self,
 gboolean nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig *self,
                                                              NMSettingWirelessSecurity *setting,
                                                              NMSetting8021x *setting_8021x,
-                                                             const char *con_uuid);
+                                                             const char *con_uuid,
+                                                             gboolean *bgscan);
 
 gboolean nm_supplicant_config_add_no_security (NMSupplicantConfig *self);
 
diff --git a/src/supplicant-manager/tests/test-supplicant-config.c 
b/src/supplicant-manager/tests/test-supplicant-config.c
index 5c6795c..3990043 100644
--- a/src/supplicant-manager/tests/test-supplicant-config.c
+++ b/src/supplicant-manager/tests/test-supplicant-config.c
@@ -215,6 +215,7 @@ test_wifi_wep_key (const char *detail,
      GByteArray *bssid;
      const unsigned char bssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
      const char *bssid_str = "11:22:33:44:55:66";
+     gboolean dummy;
 
      connection = nm_connection_new ();
 
@@ -280,7 +281,8 @@ test_wifi_wep_key (const char *detail,
      success = nm_supplicant_config_add_setting_wireless_security (config,
                                                                    s_wsec,
                                                                    NULL,
-                                                                   "376aced7-b28c-46be-9a62-fcdf072571da");
+                                                                   "376aced7-b28c-46be-9a62-fcdf072571da",
+                                                                   &dummy);
      ASSERT (success == TRUE,
              detail, "failed to add wireless security to supplicant config.");
 
@@ -343,6 +345,7 @@ test_wifi_wpa_psk (const char *detail,
      GByteArray *bssid;
      const unsigned char bssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
      const char *bssid_str = "11:22:33:44:55:66";
+     gboolean dummy;
 
      connection = nm_connection_new ();
 
@@ -414,7 +417,8 @@ test_wifi_wpa_psk (const char *detail,
      success = nm_supplicant_config_add_setting_wireless_security (config,
                                                                    s_wsec,
                                                                    NULL,
-                                                                   "376aced7-b28c-46be-9a62-fcdf072571da");
+                                                                   "376aced7-b28c-46be-9a62-fcdf072571da",
+                                                                   &dummy);
      ASSERT (success == TRUE,
              detail, "failed to add wireless security to supplicant config.");
 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]