Allow IBSS/AP mode networks to be created in ap_scan=1 mode
authorJouni Malinen <jouni.malinen@atheros.com>
Tue, 29 Sep 2009 14:11:36 +0000 (17:11 +0300)
committerJouni Malinen <j@w1.fi>
Tue, 29 Sep 2009 14:11:36 +0000 (17:11 +0300)
If no BSSes/IBSSes matching the enabled networks are found in the scan
results, IBSS/AP mode network (if configured) can be created in
ap_scan=1 mode instead of requiring ap_scan=2 mode to be used whenever
using IBSS or AP mode.

wpa_supplicant/events.c
wpa_supplicant/wpa_supplicant.conf

index 19b7521..f44a0e6 100644 (file)
@@ -697,6 +697,26 @@ static void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
 }
 
 
+static struct wpa_ssid *
+wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
+{
+       int prio;
+       struct wpa_ssid *ssid;
+
+       for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
+               for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
+               {
+                       if (ssid->disabled)
+                               continue;
+                       if (ssid->mode == IEEE80211_MODE_IBSS ||
+                           ssid->mode == IEEE80211_MODE_AP)
+                               return ssid;
+               }
+       }
+       return NULL;
+}
+
+
 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
 {
        struct wpa_scan_res *selected;
@@ -744,7 +764,12 @@ static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
                wpa_supplicant_connect(wpa_s, selected, ssid);
        } else {
                wpa_printf(MSG_DEBUG, "No suitable network found");
-               wpa_supplicant_req_new_scan(wpa_s, 5);
+               ssid = wpa_supplicant_pick_new_network(wpa_s);
+               if (ssid) {
+                       wpa_printf(MSG_DEBUG, "Setup a new network");
+                       wpa_supplicant_associate(wpa_s, NULL, ssid);
+               } else
+                       wpa_supplicant_req_new_scan(wpa_s, 5);
        }
 }
 #endif /* CONFIG_NO_SCAN_PROCESSING */
index 49ed96d..1ee282a 100644 (file)
@@ -89,7 +89,9 @@ eapol_version=1
 # allow the driver to take care of AP scanning and selection and use
 # wpa_supplicant just to process EAPOL frames based on IEEE 802.11 association
 # information from the driver.
-# 1: wpa_supplicant initiates scanning and AP selection
+# 1: wpa_supplicant initiates scanning and AP selection; if no APs matching to
+#    the currently enabled networks are found, a new network (IBSS or AP mode
+#    operation) may be initialized (if configured) (default)
 # 0: driver takes care of scanning, AP selection, and IEEE 802.11 association
 #    parameters (e.g., WPA IE generation); this mode can also be used with
 #    non-WPA drivers when using IEEE 802.1X mode; do not try to associate with
@@ -102,6 +104,10 @@ eapol_version=1
 #    the driver reports successful association; each network block should have
 #    explicit security policy (i.e., only one option in the lists) for
 #    key_mgmt, pairwise, group, proto variables
+# When using IBSS or AP mode, ap_scan=2 mode can force the new network to be
+# created immediately regardless of scan results. ap_scan=1 mode will first try
+# to scan for existing networks and only if no matches with the enabled
+# networks are found, a new IBSS or AP mode network is created.
 ap_scan=1
 
 # EAP fast re-authentication
@@ -244,8 +250,8 @@ fast_reauth=1
 # 1 = IBSS (ad-hoc, peer-to-peer)
 # 2 = AP (access point)
 # Note: IBSS can only be used with key_mgmt NONE (plaintext and static WEP)
-# and key_mgmt=WPA-NONE (fixed group key TKIP/CCMP). In addition, ap_scan has
-# to be set to 2 for IBSS. WPA-None requires following network block options:
+# and key_mgmt=WPA-NONE (fixed group key TKIP/CCMP). WPA-None requires
+# following network block options:
 # proto=WPA, key_mgmt=WPA-NONE, pairwise=NONE, group=TKIP (or CCMP, but not
 # both), and psk must also be set.
 #