]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpa_supplicant: Allow global scan frequencies configuration
authorBen Greear <greearb@candelatech.com>
Sun, 5 May 2013 08:46:54 +0000 (11:46 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 5 May 2013 08:46:54 +0000 (11:46 +0300)
This allows one to limit the channels that wpa_supplicant will
scan. This is a useful addition to the freq_list configurable
in the network {} section.

Signed-hostap: Ben Greear <greearb@candelatech.com>

wpa_supplicant/config.c
wpa_supplicant/config.h
wpa_supplicant/config_file.c
wpa_supplicant/scan.c
wpa_supplicant/wpa_supplicant.conf

index 2de7845090ccbc6baade87978f5c60f0e1d7b273..aceaa02b182702b97720384d1fc684f036d5839c 100644 (file)
@@ -1826,6 +1826,7 @@ void wpa_config_free(struct wpa_config *config)
        os_free(config->pssid);
        os_free(config->p2p_pref_chan);
        os_free(config->autoscan);
+       os_free(config->freq_list);
        wpabuf_free(config->wps_nfc_dh_pubkey);
        wpabuf_free(config->wps_nfc_dh_privkey);
        wpabuf_free(config->wps_nfc_dev_pw);
@@ -2733,6 +2734,21 @@ static int wpa_global_config_parse_bin(const struct global_parse_data *data,
 }
 
 
+static int wpa_config_process_freq_list(const struct global_parse_data *data,
+                                       struct wpa_config *config, int line,
+                                       const char *value)
+{
+       int *freqs;
+
+       freqs = wpa_config_parse_int_array(value);
+       if (freqs == NULL)
+               return -1;
+       os_free(config->freq_list);
+       config->freq_list = freqs;
+       return 0;
+}
+
+
 static int wpa_config_process_country(const struct global_parse_data *data,
                                      struct wpa_config *config, int line,
                                      const char *pos)
@@ -3088,6 +3104,7 @@ static const struct global_parse_data global_fields[] = {
        { INT(beacon_int), 0 },
        { FUNC(ap_vendor_elements), 0 },
        { INT_RANGE(ignore_old_scan_res, 0, 1), 0 },
+       { FUNC(freq_list), 0 },
 };
 
 #undef FUNC
index 4a175ce9918801b91df40a968f04bbdb159bb322..cdaaa8948ba48e6794b8fdcfff936aa40cefe152 100644 (file)
@@ -644,6 +644,14 @@ struct wpa_config {
         */
        unsigned int max_num_sta;
 
+       /**
+        * freq_list - Array of allowed scan frequencies or %NULL for all
+        *
+        * This is an optional zero-terminated array of frequencies in
+        * megahertz (MHz) to allow for narrowing scanning range.
+        */
+       int *freq_list;
+
        /**
         * changed_parameters - Bitmap of changed parameters since last update
         */
index 8604ae8a41c09baba4b9cdc63dcd0745d63988b2..ed6b3f2b5c616b65461fa15380b1fec02869bbe7 100644 (file)
@@ -1015,6 +1015,16 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
        if (config->ignore_old_scan_res)
                fprintf(f, "ignore_old_scan_res=%d\n",
                        config->ignore_old_scan_res);
+
+       if (config->freq_list && config->freq_list[0]) {
+               int i;
+               fprintf(f, "freq_list=");
+               for (i = 0; config->freq_list[i]; i++) {
+                       fprintf(f, "%s%u", i > 0 ? " " : "",
+                               config->freq_list[i]);
+               }
+               fprintf(f, "\n");
+       }
 }
 
 #endif /* CONFIG_NO_CONFIG_WRITE */
index 6e2bb812e326927e26177d59fce5d7c5b7618386..8d4c7f1a7d7855a7a11bee55c000c725bb8011af 100644 (file)
@@ -749,6 +749,13 @@ ssid_list_set:
                os_free(wpa_s->next_scan_freqs);
        wpa_s->next_scan_freqs = NULL;
 
+       /* See if user specified frequencies. If so, scan only those. */
+       if (wpa_s->conf->freq_list && !params.freqs) {
+               wpa_dbg(wpa_s, MSG_DEBUG,
+                       "Optimize scan based on conf->freq_list");
+               int_array_concat(&params.freqs, wpa_s->conf->freq_list);
+       }
+
        params.filter_ssids = wpa_supplicant_build_filter_ssids(
                wpa_s->conf, &params.num_filter_ssids);
        if (extra_ie) {
index 0935a0624ab53d5d5fe5167d29eb1ba6ae0f6ddb..87dd3970a8118ec7be0a36fa9cc94a65791edca0 100644 (file)
@@ -524,6 +524,9 @@ fast_reauth=1
 # set, scan results that do not match any of the specified frequencies are not
 # considered when selecting a BSS.
 #
+# This can also be set on the outside of the network block. In this case,
+# it limits the frequencies that will be scanned.
+#
 # bgscan: Background scanning
 # wpa_supplicant behavior for background scanning can be specified by
 # configuring a bgscan module. These modules are responsible for requesting
@@ -1231,3 +1234,10 @@ SGVsbG8gV29ybGQhCg==
 network={
        key_mgmt=NONE
 }
+
+
+# Example config file that will only scan on channel 36.
+freq_list=5180
+network={
+       key_mgmt=NONE
+}