From b55aaa5fdfe3e906bf1c89803f0f15248912861f Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 29 Sep 2009 17:11:36 +0300 Subject: [PATCH] Allow IBSS/AP mode networks to be created in ap_scan=1 mode 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 | 27 ++++++++++++++++++++++++++- wpa_supplicant/wpa_supplicant.conf | 12 +++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 19b75216a..f44a0e616 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -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 */ diff --git a/wpa_supplicant/wpa_supplicant.conf b/wpa_supplicant/wpa_supplicant.conf index 49ed96d21..1ee282a5f 100644 --- a/wpa_supplicant/wpa_supplicant.conf +++ b/wpa_supplicant/wpa_supplicant.conf @@ -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. #