Commit f3b85252 authored by Johannes Berg's avatar Johannes Berg Committed by John W. Linville

mac80211: fix scan races and rework scanning

There are some places marked
	/* XXX maybe racy? */
and they really are racy because there's no locking.

This patch reworks much of the scan code, and introduces proper
locking for the scan request as well as the internal scanning
(which is necessary for IBSS/managed modes). Helper functions
are added to call the scanning code whenever necessary. The
scan deferring is changed to simply queue the scanning work
instead of trying to start the scan in place, the scanning work
will then take care of the rest.

Also, currently when internal scans are requested for an interface
that is trying to associate, we reject such scans. This was not
intended, the mlme code has provisions to scan twice when it can't
find the BSS to associate with right away; this has never worked
properly. Fix this by not rejecting internal scan requests for an
interface that is associating.
Signed-off-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 2d722890
...@@ -432,15 +432,7 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata) ...@@ -432,15 +432,7 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
"IBSS networks with same SSID (merge)\n", sdata->dev->name); "IBSS networks with same SSID (merge)\n", sdata->dev->name);
/* XXX maybe racy? */ ieee80211_request_internal_scan(sdata, ifibss->ssid, ifibss->ssid_len);
if (sdata->local->scan_req)
return;
memcpy(sdata->local->int_scan_req.ssids[0].ssid,
ifibss->ssid, IEEE80211_MAX_SSID_LEN);
sdata->local->int_scan_req.ssids[0].ssid_len = ifibss->ssid_len;
if (ieee80211_request_scan(sdata, &sdata->local->int_scan_req))
ieee80211_scan_failed(sdata->local);
} }
static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata) static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
...@@ -553,16 +545,8 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata) ...@@ -553,16 +545,8 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
"join\n", sdata->dev->name); "join\n", sdata->dev->name);
/* XXX maybe racy? */ ieee80211_request_internal_scan(sdata, ifibss->ssid,
if (local->scan_req) ifibss->ssid_len);
return;
memcpy(local->int_scan_req.ssids[0].ssid,
ifibss->ssid, IEEE80211_MAX_SSID_LEN);
local->int_scan_req.ssids[0].ssid_len =
ifibss->ssid_len;
if (ieee80211_request_scan(sdata, &local->int_scan_req))
ieee80211_scan_failed(local);
} else if (ifibss->state != IEEE80211_IBSS_MLME_JOINED) { } else if (ifibss->state != IEEE80211_IBSS_MLME_JOINED) {
int interval = IEEE80211_SCAN_INTERVAL; int interval = IEEE80211_SCAN_INTERVAL;
......
...@@ -659,6 +659,7 @@ struct ieee80211_local { ...@@ -659,6 +659,7 @@ struct ieee80211_local {
/* Scanning and BSS list */ /* Scanning and BSS list */
struct mutex scan_mtx;
bool sw_scanning, hw_scanning; bool sw_scanning, hw_scanning;
struct cfg80211_ssid scan_ssid; struct cfg80211_ssid scan_ssid;
struct cfg80211_scan_request int_scan_req; struct cfg80211_scan_request int_scan_req;
...@@ -947,6 +948,8 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata); ...@@ -947,6 +948,8 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata);
/* scan/BSS handling */ /* scan/BSS handling */
void ieee80211_scan_work(struct work_struct *work); void ieee80211_scan_work(struct work_struct *work);
int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
const u8 *ssid, u8 ssid_len);
int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
struct cfg80211_scan_request *req); struct cfg80211_scan_request *req);
int ieee80211_scan_results(struct ieee80211_local *local, int ieee80211_scan_results(struct ieee80211_local *local,
...@@ -960,9 +963,6 @@ int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, ...@@ -960,9 +963,6 @@ int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
const char *ie, size_t len); const char *ie, size_t len);
void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local); void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local);
void ieee80211_scan_failed(struct ieee80211_local *local);
int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata,
struct cfg80211_scan_request *req);
struct ieee80211_bss * struct ieee80211_bss *
ieee80211_bss_info_update(struct ieee80211_local *local, ieee80211_bss_info_update(struct ieee80211_local *local,
struct ieee80211_rx_status *rx_status, struct ieee80211_rx_status *rx_status,
......
...@@ -783,6 +783,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, ...@@ -783,6 +783,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
INIT_LIST_HEAD(&local->interfaces); INIT_LIST_HEAD(&local->interfaces);
mutex_init(&local->iflist_mtx); mutex_init(&local->iflist_mtx);
mutex_init(&local->scan_mtx);
spin_lock_init(&local->key_lock); spin_lock_init(&local->key_lock);
...@@ -1126,6 +1127,7 @@ void ieee80211_free_hw(struct ieee80211_hw *hw) ...@@ -1126,6 +1127,7 @@ void ieee80211_free_hw(struct ieee80211_hw *hw)
struct ieee80211_local *local = hw_to_local(hw); struct ieee80211_local *local = hw_to_local(hw);
mutex_destroy(&local->iflist_mtx); mutex_destroy(&local->iflist_mtx);
mutex_destroy(&local->scan_mtx);
wiphy_free(local->hw.wiphy); wiphy_free(local->hw.wiphy);
} }
......
...@@ -2072,19 +2072,15 @@ static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata) ...@@ -2072,19 +2072,15 @@ static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
return 0; return 0;
} else { } else {
if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) { if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
u8 ssid_len = 0;
if (!(ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL))
ssid_len = ifmgd->ssid_len;
ifmgd->assoc_scan_tries++; ifmgd->assoc_scan_tries++;
/* XXX maybe racy? */
if (local->scan_req)
return -1;
memcpy(local->int_scan_req.ssids[0].ssid,
ifmgd->ssid, IEEE80211_MAX_SSID_LEN);
if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL)
local->int_scan_req.ssids[0].ssid_len = 0;
else
local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
if (ieee80211_start_scan(sdata, &local->int_scan_req)) ieee80211_request_internal_scan(sdata, ifmgd->ssid,
ieee80211_scan_failed(local); ssid_len);
ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE; ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request); set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
...@@ -2122,14 +2118,8 @@ static void ieee80211_sta_work(struct work_struct *work) ...@@ -2122,14 +2118,8 @@ static void ieee80211_sta_work(struct work_struct *work)
ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE && ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE && ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) { test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
/* queue_delayed_work(local->hw.workqueue, &local->scan_work,
* The call to ieee80211_start_scan can fail but ieee80211_request_scan round_jiffies_relative(0));
* (which queued ieee80211_sta_work) did not return an error. Thus, call
* ieee80211_scan_failed here if ieee80211_start_scan fails in order to
* notify the scan requester.
*/
if (ieee80211_start_scan(sdata, local->scan_req))
ieee80211_scan_failed(local);
return; return;
} }
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment