2 * This file is part of wl1271
4 * Copyright (C) 2009-2010 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <linux/ieee80211.h>
34 void wl1271_scan_complete_work(struct work_struct *work)
36 struct delayed_work *dwork;
38 struct wl12xx_vif *wlvif;
41 dwork = container_of(work, struct delayed_work, work);
42 wl = container_of(dwork, struct wl1271, scan_complete_work);
44 wl1271_debug(DEBUG_SCAN, "Scanning complete");
46 mutex_lock(&wl->mutex);
48 if (unlikely(wl->state != WLCORE_STATE_ON))
51 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
54 wlvif = wl->scan_wlvif;
57 * Rearm the tx watchdog just before idling scan. This
58 * prevents just-finished scans from triggering the watchdog
60 wl12xx_rearm_tx_watchdog_locked(wl);
62 wl->scan.state = WL1271_SCAN_STATE_IDLE;
63 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
65 wl->scan_wlvif = NULL;
67 ret = wl1271_ps_elp_wakeup(wl);
71 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
72 /* restore hardware connection monitoring template */
73 wl1271_cmd_build_ap_probe_req(wl, wlvif, wlvif->probereq);
76 wl1271_ps_elp_sleep(wl);
78 if (wl->scan.failed) {
79 wl1271_info("Scan completed due to error.");
80 wl12xx_queue_recovery_work(wl);
83 ieee80211_scan_completed(wl->hw, false);
86 mutex_unlock(&wl->mutex);
91 wlcore_scan_get_channels(struct wl1271 *wl,
92 struct ieee80211_channel *req_channels[],
95 struct conn_scan_ch_params *channels,
96 u32 band, bool radar, bool passive,
97 int start, int max_channels,
100 struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
103 bool force_passive = !n_ssids;
104 u32 min_dwell_time_active, max_dwell_time_active, delta_per_probe;
105 u32 dwell_time_passive, dwell_time_dfs;
107 if (band == IEEE80211_BAND_5GHZ)
108 delta_per_probe = c->dwell_time_delta_per_probe_5;
110 delta_per_probe = c->dwell_time_delta_per_probe;
112 min_dwell_time_active = c->base_dwell_time +
113 n_ssids * c->num_probe_reqs * delta_per_probe;
115 max_dwell_time_active = min_dwell_time_active + c->max_dwell_time_delta;
117 min_dwell_time_active = DIV_ROUND_UP(min_dwell_time_active, 1000);
118 max_dwell_time_active = DIV_ROUND_UP(max_dwell_time_active, 1000);
119 dwell_time_passive = DIV_ROUND_UP(c->dwell_time_passive, 1000);
120 dwell_time_dfs = DIV_ROUND_UP(c->dwell_time_dfs, 1000);
122 for (i = 0, j = start;
123 i < n_channels && j < max_channels;
125 flags = req_channels[i]->flags;
128 flags |= IEEE80211_CHAN_PASSIVE_SCAN;
130 if ((req_channels[i]->band == band) &&
131 !(flags & IEEE80211_CHAN_DISABLED) &&
132 (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
133 /* if radar is set, we ignore the passive flag */
135 !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
136 wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
137 req_channels[i]->band,
138 req_channels[i]->center_freq);
139 wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
140 req_channels[i]->hw_value,
141 req_channels[i]->flags);
142 wl1271_debug(DEBUG_SCAN, "max_power %d",
143 req_channels[i]->max_power);
144 wl1271_debug(DEBUG_SCAN, "min_dwell_time %d max dwell time %d",
145 min_dwell_time_active,
146 max_dwell_time_active);
148 if (flags & IEEE80211_CHAN_RADAR) {
149 channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS;
151 channels[j].passive_duration =
152 cpu_to_le16(dwell_time_dfs);
154 channels[j].passive_duration =
155 cpu_to_le16(dwell_time_passive);
158 channels[j].min_duration =
159 cpu_to_le16(min_dwell_time_active);
160 channels[j].max_duration =
161 cpu_to_le16(max_dwell_time_active);
163 channels[j].tx_power_att = req_channels[i]->max_power;
164 channels[j].channel = req_channels[i]->hw_value;
167 (band == IEEE80211_BAND_2GHZ) &&
168 (channels[j].channel >= 12) &&
169 (channels[j].channel <= 14) &&
170 (flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
172 /* pactive channels treated as DFS */
173 channels[j].flags = SCAN_CHANNEL_FLAGS_DFS;
176 * n_pactive_ch is counted down from the end of
177 * the passive channel list
180 wl1271_debug(DEBUG_SCAN, "n_pactive_ch = %d",
192 wlcore_set_scan_chan_params(struct wl1271 *wl,
193 struct wlcore_scan_channels *cfg,
194 struct ieee80211_channel *channels[],
201 wlcore_scan_get_channels(wl,
211 wlcore_scan_get_channels(wl,
222 wlcore_scan_get_channels(wl,
232 wlcore_scan_get_channels(wl,
243 wlcore_scan_get_channels(wl,
250 cfg->passive[1] + cfg->dfs,
254 /* 802.11j channels are not supported yet */
258 cfg->passive_active = n_pactive_ch;
260 wl1271_debug(DEBUG_SCAN, " 2.4GHz: active %d passive %d",
261 cfg->active[0], cfg->passive[0]);
262 wl1271_debug(DEBUG_SCAN, " 5GHz: active %d passive %d",
263 cfg->active[1], cfg->passive[1]);
264 wl1271_debug(DEBUG_SCAN, " DFS: %d", cfg->dfs);
266 return cfg->passive[0] || cfg->active[0] ||
267 cfg->passive[1] || cfg->active[1] || cfg->dfs ||
268 cfg->passive[2] || cfg->active[2];
270 EXPORT_SYMBOL_GPL(wlcore_set_scan_chan_params);
272 int wlcore_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
273 const u8 *ssid, size_t ssid_len,
274 struct cfg80211_scan_request *req)
276 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
279 * cfg80211 should guarantee that we don't get more channels
280 * than what we have registered.
282 BUG_ON(req->n_channels > WL1271_MAX_CHANNELS);
284 if (wl->scan.state != WL1271_SCAN_STATE_IDLE)
287 wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE;
289 if (ssid_len && ssid) {
290 wl->scan.ssid_len = ssid_len;
291 memcpy(wl->scan.ssid, ssid, ssid_len);
293 wl->scan.ssid_len = 0;
296 wl->scan_wlvif = wlvif;
298 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
300 /* we assume failure so that timeout scenarios are handled correctly */
301 wl->scan.failed = true;
302 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
303 msecs_to_jiffies(WL1271_SCAN_TIMEOUT));
305 wl->ops->scan_start(wl, wlvif, req);
309 /* Returns the scan type to be used or a negative value on error */
311 wlcore_scan_sched_scan_ssid_list(struct wl1271 *wl,
312 struct wl12xx_vif *wlvif,
313 struct cfg80211_sched_scan_request *req)
315 struct wl1271_cmd_sched_scan_ssid_list *cmd = NULL;
316 struct cfg80211_match_set *sets = req->match_sets;
317 struct cfg80211_ssid *ssids = req->ssids;
318 int ret = 0, type, i, j, n_match_ssids = 0;
320 wl1271_debug(DEBUG_CMD, "cmd sched scan ssid list");
322 /* count the match sets that contain SSIDs */
323 for (i = 0; i < req->n_match_sets; i++)
324 if (sets[i].ssid.ssid_len > 0)
327 /* No filter, no ssids or only bcast ssid */
328 if (!n_match_ssids &&
330 (req->n_ssids == 1 && req->ssids[0].ssid_len == 0))) {
331 type = SCAN_SSID_FILTER_ANY;
335 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
341 cmd->role_id = wlvif->role_id;
342 if (!n_match_ssids) {
343 /* No filter, with ssids */
344 type = SCAN_SSID_FILTER_DISABLED;
346 for (i = 0; i < req->n_ssids; i++) {
347 cmd->ssids[cmd->n_ssids].type = (ssids[i].ssid_len) ?
348 SCAN_SSID_TYPE_HIDDEN : SCAN_SSID_TYPE_PUBLIC;
349 cmd->ssids[cmd->n_ssids].len = ssids[i].ssid_len;
350 memcpy(cmd->ssids[cmd->n_ssids].ssid, ssids[i].ssid,
355 type = SCAN_SSID_FILTER_LIST;
357 /* Add all SSIDs from the filters */
358 for (i = 0; i < req->n_match_sets; i++) {
359 /* ignore sets without SSIDs */
360 if (!sets[i].ssid.ssid_len)
363 cmd->ssids[cmd->n_ssids].type = SCAN_SSID_TYPE_PUBLIC;
364 cmd->ssids[cmd->n_ssids].len = sets[i].ssid.ssid_len;
365 memcpy(cmd->ssids[cmd->n_ssids].ssid,
366 sets[i].ssid.ssid, sets[i].ssid.ssid_len);
369 if ((req->n_ssids > 1) ||
370 (req->n_ssids == 1 && req->ssids[0].ssid_len > 0)) {
372 * Mark all the SSIDs passed in the SSID list as HIDDEN,
373 * so they're used in probe requests.
375 for (i = 0; i < req->n_ssids; i++) {
376 if (!req->ssids[i].ssid_len)
379 for (j = 0; j < cmd->n_ssids; j++)
380 if ((req->ssids[i].ssid_len ==
381 cmd->ssids[j].len) &&
382 !memcmp(req->ssids[i].ssid,
384 req->ssids[i].ssid_len)) {
386 SCAN_SSID_TYPE_HIDDEN;
389 /* Fail if SSID isn't present in the filters */
390 if (j == cmd->n_ssids) {
398 wl1271_dump(DEBUG_SCAN, "SSID_LIST: ", cmd, sizeof(*cmd));
400 ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_SSID_CFG, cmd,
403 wl1271_error("cmd sched scan ssid list failed");
414 EXPORT_SYMBOL_GPL(wlcore_scan_sched_scan_ssid_list);
416 void wl1271_scan_sched_scan_results(struct wl1271 *wl)
418 wl1271_debug(DEBUG_SCAN, "got periodic scan results");
420 ieee80211_sched_scan_results(wl->hw);