Commit 7d3be3cc authored by Helmut Schaa's avatar Helmut Schaa Committed by John W. Linville

mac80211: refactor the scan code

Move the processing of each scan state into its own functions for better
readability. This patch does not introduce functional changes.
Signed-off-by: default avatarHelmut Schaa <helmut.schaa@googlemail.com>
Acked-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 4ef70841
......@@ -474,51 +474,17 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
return rc;
}
void ieee80211_scan_work(struct work_struct *work)
static int ieee80211_scan_state_set_channel(struct ieee80211_local *local,
unsigned long *next_delay)
{
struct ieee80211_local *local =
container_of(work, struct ieee80211_local, scan_work.work);
struct ieee80211_sub_if_data *sdata = local->scan_sdata;
int skip;
struct ieee80211_channel *chan;
int skip, i;
unsigned long next_delay = 0;
mutex_lock(&local->scan_mtx);
if (!sdata || !local->scan_req) {
mutex_unlock(&local->scan_mtx);
return;
}
if (local->scan_req && !(local->sw_scanning || local->hw_scanning)) {
struct cfg80211_scan_request *req = local->scan_req;
int rc;
local->scan_req = NULL;
rc = __ieee80211_start_scan(sdata, req);
mutex_unlock(&local->scan_mtx);
if (rc)
ieee80211_scan_completed(&local->hw, true);
return;
}
mutex_unlock(&local->scan_mtx);
/*
* Avoid re-scheduling when the sdata is going away.
*/
if (!netif_running(sdata->dev)) {
ieee80211_scan_completed(&local->hw, true);
return;
}
struct ieee80211_sub_if_data *sdata = local->scan_sdata;
switch (local->scan_state) {
case SCAN_SET_CHANNEL:
/* if no more bands/channels left, complete scan */
if (local->scan_channel_idx >= local->scan_req->n_channels) {
ieee80211_scan_completed(&local->hw, false);
return;
return 1;
}
skip = 0;
chan = local->scan_req->channels[local->scan_channel_idx];
......@@ -539,7 +505,7 @@ void ieee80211_scan_work(struct work_struct *work)
local->scan_channel_idx++;
if (skip)
break;
return 0;
/*
* Probe delay is used to update the NAV, cf. 11.1.3.2.2
......@@ -553,14 +519,22 @@ void ieee80211_scan_work(struct work_struct *work)
*/
if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
!local->scan_req->n_ssids) {
next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
break;
*next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
return 0;
}
next_delay = IEEE80211_PROBE_DELAY;
*next_delay = IEEE80211_PROBE_DELAY;
local->scan_state = SCAN_SEND_PROBE;
break;
case SCAN_SEND_PROBE:
return 0;
}
static void ieee80211_scan_state_send_probe(struct ieee80211_local *local,
unsigned long *next_delay)
{
int i;
struct ieee80211_sub_if_data *sdata = local->scan_sdata;
for (i = 0; i < local->scan_req->n_ssids; i++)
ieee80211_send_probe_req(
sdata, NULL,
......@@ -572,8 +546,54 @@ void ieee80211_scan_work(struct work_struct *work)
* After sending probe requests, wait for probe responses
* on the channel.
*/
next_delay = IEEE80211_CHANNEL_TIME;
*next_delay = IEEE80211_CHANNEL_TIME;
local->scan_state = SCAN_SET_CHANNEL;
}
void ieee80211_scan_work(struct work_struct *work)
{
struct ieee80211_local *local =
container_of(work, struct ieee80211_local, scan_work.work);
struct ieee80211_sub_if_data *sdata = local->scan_sdata;
unsigned long next_delay = 0;
mutex_lock(&local->scan_mtx);
if (!sdata || !local->scan_req) {
mutex_unlock(&local->scan_mtx);
return;
}
if (local->scan_req && !(local->sw_scanning || local->hw_scanning)) {
struct cfg80211_scan_request *req = local->scan_req;
int rc;
local->scan_req = NULL;
rc = __ieee80211_start_scan(sdata, req);
mutex_unlock(&local->scan_mtx);
if (rc)
ieee80211_scan_completed(&local->hw, true);
return;
}
mutex_unlock(&local->scan_mtx);
/*
* Avoid re-scheduling when the sdata is going away.
*/
if (!netif_running(sdata->dev)) {
ieee80211_scan_completed(&local->hw, true);
return;
}
switch (local->scan_state) {
case SCAN_SET_CHANNEL:
if (ieee80211_scan_state_set_channel(local, &next_delay))
return;
break;
case SCAN_SEND_PROBE:
ieee80211_scan_state_send_probe(local, &next_delay);
break;
}
......
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