2010-07-08 14:50:06 +00:00
|
|
|
/*
|
|
|
|
* This file is part of wl1271
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009-2010 Nokia Corporation
|
|
|
|
*
|
|
|
|
* Contact: Luciano Coelho <luciano.coelho@nokia.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/ieee80211.h>
|
|
|
|
|
2010-11-08 11:20:10 +00:00
|
|
|
#include "wl12xx.h"
|
|
|
|
#include "cmd.h"
|
|
|
|
#include "scan.h"
|
|
|
|
#include "acx.h"
|
2011-03-01 10:27:26 +00:00
|
|
|
#include "ps.h"
|
2010-07-08 14:50:06 +00:00
|
|
|
|
2010-08-24 03:28:03 +00:00
|
|
|
void wl1271_scan_complete_work(struct work_struct *work)
|
|
|
|
{
|
2010-09-21 04:23:32 +00:00
|
|
|
struct delayed_work *dwork;
|
|
|
|
struct wl1271 *wl;
|
|
|
|
|
|
|
|
dwork = container_of(work, struct delayed_work, work);
|
|
|
|
wl = container_of(dwork, struct wl1271, scan_complete_work);
|
2010-08-24 03:28:03 +00:00
|
|
|
|
|
|
|
wl1271_debug(DEBUG_SCAN, "Scanning complete");
|
|
|
|
|
|
|
|
mutex_lock(&wl->mutex);
|
2010-09-21 04:23:30 +00:00
|
|
|
|
2011-03-01 10:27:26 +00:00
|
|
|
if (wl->state == WL1271_STATE_OFF)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
|
|
|
|
goto out;
|
2010-09-21 04:23:30 +00:00
|
|
|
|
2010-08-24 03:28:03 +00:00
|
|
|
wl->scan.state = WL1271_SCAN_STATE_IDLE;
|
|
|
|
kfree(wl->scan.scanned_ch);
|
|
|
|
wl->scan.scanned_ch = NULL;
|
2010-10-26 11:24:38 +00:00
|
|
|
wl->scan.req = NULL;
|
2010-08-24 03:28:03 +00:00
|
|
|
ieee80211_scan_completed(wl->hw, false);
|
2010-09-21 04:23:32 +00:00
|
|
|
|
2010-11-24 06:16:57 +00:00
|
|
|
/* restore hardware connection monitoring template */
|
2011-03-01 10:27:26 +00:00
|
|
|
if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
|
|
|
|
if (wl1271_ps_elp_wakeup(wl) == 0) {
|
|
|
|
wl1271_cmd_build_ap_probe_req(wl, wl->probereq);
|
|
|
|
wl1271_ps_elp_sleep(wl);
|
|
|
|
}
|
|
|
|
}
|
2010-11-24 06:16:57 +00:00
|
|
|
|
2010-09-21 04:23:32 +00:00
|
|
|
if (wl->scan.failed) {
|
|
|
|
wl1271_info("Scan completed due to error.");
|
|
|
|
ieee80211_queue_work(wl->hw, &wl->recovery_work);
|
|
|
|
}
|
2011-03-01 10:27:26 +00:00
|
|
|
|
|
|
|
out:
|
2010-10-26 11:24:38 +00:00
|
|
|
mutex_unlock(&wl->mutex);
|
|
|
|
|
2010-08-24 03:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
static int wl1271_get_scan_channels(struct wl1271 *wl,
|
|
|
|
struct cfg80211_scan_request *req,
|
|
|
|
struct basic_scan_channel_params *channels,
|
|
|
|
enum ieee80211_band band, bool passive)
|
2010-07-08 14:50:06 +00:00
|
|
|
{
|
2010-09-21 06:14:31 +00:00
|
|
|
struct conf_scan_settings *c = &wl->conf.scan;
|
2010-07-08 14:50:07 +00:00
|
|
|
int i, j;
|
|
|
|
u32 flags;
|
2010-07-08 14:50:06 +00:00
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
for (i = 0, j = 0;
|
|
|
|
i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS;
|
|
|
|
i++) {
|
2010-07-08 14:50:06 +00:00
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
flags = req->channels[i]->flags;
|
2010-07-08 14:50:06 +00:00
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
if (!wl->scan.scanned_ch[i] &&
|
|
|
|
!(flags & IEEE80211_CHAN_DISABLED) &&
|
|
|
|
((!!(flags & IEEE80211_CHAN_PASSIVE_SCAN)) == passive) &&
|
|
|
|
(req->channels[i]->band == band)) {
|
2010-07-08 14:50:06 +00:00
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
|
|
|
|
req->channels[i]->band,
|
|
|
|
req->channels[i]->center_freq);
|
|
|
|
wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
|
|
|
|
req->channels[i]->hw_value,
|
|
|
|
req->channels[i]->flags);
|
|
|
|
wl1271_debug(DEBUG_SCAN,
|
|
|
|
"max_antenna_gain %d, max_power %d",
|
|
|
|
req->channels[i]->max_antenna_gain,
|
|
|
|
req->channels[i]->max_power);
|
|
|
|
wl1271_debug(DEBUG_SCAN, "beacon_found %d",
|
|
|
|
req->channels[i]->beacon_found);
|
2010-07-08 14:50:06 +00:00
|
|
|
|
2010-09-21 06:14:31 +00:00
|
|
|
if (!passive) {
|
|
|
|
channels[j].min_duration =
|
|
|
|
cpu_to_le32(c->min_dwell_time_active);
|
|
|
|
channels[j].max_duration =
|
|
|
|
cpu_to_le32(c->max_dwell_time_active);
|
|
|
|
} else {
|
|
|
|
channels[j].min_duration =
|
|
|
|
cpu_to_le32(c->min_dwell_time_passive);
|
|
|
|
channels[j].max_duration =
|
|
|
|
cpu_to_le32(c->max_dwell_time_passive);
|
|
|
|
}
|
2010-07-08 14:50:07 +00:00
|
|
|
channels[j].early_termination = 0;
|
2010-07-08 14:50:08 +00:00
|
|
|
channels[j].tx_power_att = req->channels[i]->max_power;
|
2010-07-08 14:50:07 +00:00
|
|
|
channels[j].channel = req->channels[i]->hw_value;
|
|
|
|
|
|
|
|
memset(&channels[j].bssid_lsb, 0xff, 4);
|
|
|
|
memset(&channels[j].bssid_msb, 0xff, 2);
|
|
|
|
|
|
|
|
/* Mark the channels we already used */
|
|
|
|
wl->scan.scanned_ch[i] = true;
|
|
|
|
|
2010-07-08 14:50:06 +00:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
return j;
|
|
|
|
}
|
2010-07-08 14:50:06 +00:00
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
#define WL1271_NOTHING_TO_SCAN 1
|
|
|
|
|
|
|
|
static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
|
|
|
|
bool passive, u32 basic_rate)
|
|
|
|
{
|
|
|
|
struct wl1271_cmd_scan *cmd;
|
|
|
|
struct wl1271_cmd_trigger_scan_to *trigger;
|
|
|
|
int ret;
|
|
|
|
u16 scan_options = 0;
|
|
|
|
|
|
|
|
cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
|
|
|
|
trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
|
|
|
|
if (!cmd || !trigger) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
2010-07-08 14:50:06 +00:00
|
|
|
}
|
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
/* We always use high priority scans */
|
|
|
|
scan_options = WL1271_SCAN_OPT_PRIORITY_HIGH;
|
2010-08-04 01:36:32 +00:00
|
|
|
|
|
|
|
/* No SSIDs means that we have a forced passive scan */
|
|
|
|
if (passive || wl->scan.req->n_ssids == 0)
|
2010-07-08 14:50:07 +00:00
|
|
|
scan_options |= WL1271_SCAN_OPT_PASSIVE;
|
2010-08-04 01:36:32 +00:00
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
cmd->params.scan_options = cpu_to_le16(scan_options);
|
|
|
|
|
|
|
|
cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
|
|
|
|
cmd->channels,
|
|
|
|
band, passive);
|
|
|
|
if (cmd->params.n_ch == 0) {
|
|
|
|
ret = WL1271_NOTHING_TO_SCAN;
|
2010-07-08 14:50:06 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
cmd->params.tx_rate = cpu_to_le32(basic_rate);
|
|
|
|
cmd->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
|
|
|
|
cmd->params.rx_filter_options =
|
|
|
|
cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
|
|
|
|
|
2010-09-21 06:14:31 +00:00
|
|
|
cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs;
|
2010-07-08 14:50:07 +00:00
|
|
|
cmd->params.tx_rate = cpu_to_le32(basic_rate);
|
|
|
|
cmd->params.tid_trigger = 0;
|
|
|
|
cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
|
|
|
|
|
|
|
|
if (band == IEEE80211_BAND_2GHZ)
|
|
|
|
cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ;
|
|
|
|
else
|
|
|
|
cmd->params.band = WL1271_SCAN_BAND_5_GHZ;
|
|
|
|
|
|
|
|
if (wl->scan.ssid_len && wl->scan.ssid) {
|
|
|
|
cmd->params.ssid_len = wl->scan.ssid_len;
|
|
|
|
memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len,
|
|
|
|
wl->scan.req->ie, wl->scan.req->ie_len,
|
|
|
|
band);
|
|
|
|
if (ret < 0) {
|
|
|
|
wl1271_error("PROBE request template failed");
|
2010-07-08 14:50:06 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* disable the timeout */
|
|
|
|
trigger->timeout = 0;
|
|
|
|
ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
|
|
|
|
sizeof(*trigger), 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
wl1271_error("trigger scan to failed for hw scan");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
|
2010-07-08 14:50:06 +00:00
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
|
2010-07-08 14:50:06 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
wl1271_error("SCAN failed");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2010-07-08 14:50:07 +00:00
|
|
|
kfree(cmd);
|
2010-07-08 14:50:06 +00:00
|
|
|
kfree(trigger);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
void wl1271_scan_stm(struct wl1271 *wl)
|
2010-07-08 14:50:06 +00:00
|
|
|
{
|
2010-09-21 04:23:32 +00:00
|
|
|
int ret = 0;
|
2010-07-08 14:50:07 +00:00
|
|
|
|
|
|
|
switch (wl->scan.state) {
|
|
|
|
case WL1271_SCAN_STATE_IDLE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WL1271_SCAN_STATE_2GHZ_ACTIVE:
|
|
|
|
ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, false,
|
|
|
|
wl->conf.tx.basic_rate);
|
|
|
|
if (ret == WL1271_NOTHING_TO_SCAN) {
|
|
|
|
wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
|
|
|
|
wl1271_scan_stm(wl);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WL1271_SCAN_STATE_2GHZ_PASSIVE:
|
|
|
|
ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, true,
|
|
|
|
wl->conf.tx.basic_rate);
|
|
|
|
if (ret == WL1271_NOTHING_TO_SCAN) {
|
2010-08-19 02:41:15 +00:00
|
|
|
if (wl->enable_11a)
|
2010-07-08 14:50:07 +00:00
|
|
|
wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
|
|
|
|
else
|
|
|
|
wl->scan.state = WL1271_SCAN_STATE_DONE;
|
|
|
|
wl1271_scan_stm(wl);
|
2010-07-08 14:50:06 +00:00
|
|
|
}
|
2010-07-08 14:50:07 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WL1271_SCAN_STATE_5GHZ_ACTIVE:
|
|
|
|
ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, false,
|
|
|
|
wl->conf.tx.basic_rate_5);
|
|
|
|
if (ret == WL1271_NOTHING_TO_SCAN) {
|
|
|
|
wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
|
|
|
|
wl1271_scan_stm(wl);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WL1271_SCAN_STATE_5GHZ_PASSIVE:
|
|
|
|
ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, true,
|
|
|
|
wl->conf.tx.basic_rate_5);
|
|
|
|
if (ret == WL1271_NOTHING_TO_SCAN) {
|
|
|
|
wl->scan.state = WL1271_SCAN_STATE_DONE;
|
|
|
|
wl1271_scan_stm(wl);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WL1271_SCAN_STATE_DONE:
|
2010-09-21 04:23:32 +00:00
|
|
|
wl->scan.failed = false;
|
|
|
|
cancel_delayed_work(&wl->scan_complete_work);
|
|
|
|
ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
|
|
|
|
msecs_to_jiffies(0));
|
2010-07-08 14:50:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wl1271_error("invalid scan state");
|
|
|
|
break;
|
2010-07-08 14:50:06 +00:00
|
|
|
}
|
2010-09-21 04:23:32 +00:00
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
cancel_delayed_work(&wl->scan_complete_work);
|
|
|
|
ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
|
|
|
|
msecs_to_jiffies(0));
|
|
|
|
}
|
2010-07-08 14:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
|
|
|
|
struct cfg80211_scan_request *req)
|
|
|
|
{
|
|
|
|
if (wl->scan.state != WL1271_SCAN_STATE_IDLE)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE;
|
|
|
|
|
|
|
|
if (ssid_len && ssid) {
|
|
|
|
wl->scan.ssid_len = ssid_len;
|
|
|
|
memcpy(wl->scan.ssid, ssid, ssid_len);
|
|
|
|
} else {
|
|
|
|
wl->scan.ssid_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl->scan.req = req;
|
|
|
|
|
2010-08-11 07:02:48 +00:00
|
|
|
wl->scan.scanned_ch = kcalloc(req->n_channels,
|
2010-07-08 14:50:07 +00:00
|
|
|
sizeof(*wl->scan.scanned_ch),
|
|
|
|
GFP_KERNEL);
|
2010-09-21 04:23:32 +00:00
|
|
|
/* we assume failure so that timeout scenarios are handled correctly */
|
|
|
|
wl->scan.failed = true;
|
|
|
|
ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
|
|
|
|
msecs_to_jiffies(WL1271_SCAN_TIMEOUT));
|
|
|
|
|
2010-07-08 14:50:07 +00:00
|
|
|
wl1271_scan_stm(wl);
|
|
|
|
|
2010-07-08 14:50:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|