blob: 54a4e75a37fe8de1f41bee557506c9cf76080ddf [file] [log] [blame]
Luciano Coelho34dd2aa2010-07-08 17:50:06 +03001/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009-2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
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.
11 *
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.
16 *
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
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/ieee80211.h>
25
Shahar Levi00d20102010-11-08 11:20:10 +000026#include "wl12xx.h"
27#include "cmd.h"
28#include "scan.h"
29#include "acx.h"
Arik Nemtsov24225b32011-03-01 12:27:26 +020030#include "ps.h"
Luciano Coelho34dd2aa2010-07-08 17:50:06 +030031
Juuso Oikarinenc454f1d2010-08-24 06:28:03 +030032void wl1271_scan_complete_work(struct work_struct *work)
33{
Juuso Oikarinen78abd322010-09-21 06:23:32 +020034 struct delayed_work *dwork;
35 struct wl1271 *wl;
36
37 dwork = container_of(work, struct delayed_work, work);
38 wl = container_of(dwork, struct wl1271, scan_complete_work);
Juuso Oikarinenc454f1d2010-08-24 06:28:03 +030039
40 wl1271_debug(DEBUG_SCAN, "Scanning complete");
41
42 mutex_lock(&wl->mutex);
Juuso Oikarinen52a2a372010-09-21 06:23:30 +020043
Arik Nemtsov24225b32011-03-01 12:27:26 +020044 if (wl->state == WL1271_STATE_OFF)
45 goto out;
46
47 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
48 goto out;
Juuso Oikarinen52a2a372010-09-21 06:23:30 +020049
Juuso Oikarinenc454f1d2010-08-24 06:28:03 +030050 wl->scan.state = WL1271_SCAN_STATE_IDLE;
Luciano Coelho4a31c112011-03-21 23:16:14 +020051 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Juuso Oikarinenb739a422010-10-26 13:24:38 +020052 wl->scan.req = NULL;
Juuso Oikarinenc454f1d2010-08-24 06:28:03 +030053 ieee80211_scan_completed(wl->hw, false);
Juuso Oikarinen78abd322010-09-21 06:23:32 +020054
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +020055 /* restore hardware connection monitoring template */
Arik Nemtsov24225b32011-03-01 12:27:26 +020056 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
57 if (wl1271_ps_elp_wakeup(wl) == 0) {
58 wl1271_cmd_build_ap_probe_req(wl, wl->probereq);
59 wl1271_ps_elp_sleep(wl);
60 }
61 }
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +020062
Juuso Oikarinen78abd322010-09-21 06:23:32 +020063 if (wl->scan.failed) {
64 wl1271_info("Scan completed due to error.");
Ido Yarivbaacb9a2011-06-06 14:57:05 +030065 wl12xx_queue_recovery_work(wl);
Juuso Oikarinen78abd322010-09-21 06:23:32 +020066 }
Arik Nemtsov24225b32011-03-01 12:27:26 +020067
68out:
Juuso Oikarinenb739a422010-10-26 13:24:38 +020069 mutex_unlock(&wl->mutex);
70
Juuso Oikarinenc454f1d2010-08-24 06:28:03 +030071}
72
73
Luciano Coelho08688d62010-07-08 17:50:07 +030074static int wl1271_get_scan_channels(struct wl1271 *wl,
75 struct cfg80211_scan_request *req,
76 struct basic_scan_channel_params *channels,
77 enum ieee80211_band band, bool passive)
Luciano Coelho34dd2aa2010-07-08 17:50:06 +030078{
Juuso Oikarinenbea39d62010-09-21 08:14:31 +020079 struct conf_scan_settings *c = &wl->conf.scan;
Luciano Coelho08688d62010-07-08 17:50:07 +030080 int i, j;
81 u32 flags;
Luciano Coelho34dd2aa2010-07-08 17:50:06 +030082
Luciano Coelho08688d62010-07-08 17:50:07 +030083 for (i = 0, j = 0;
84 i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS;
85 i++) {
Luciano Coelho34dd2aa2010-07-08 17:50:06 +030086
Luciano Coelho08688d62010-07-08 17:50:07 +030087 flags = req->channels[i]->flags;
Luciano Coelho34dd2aa2010-07-08 17:50:06 +030088
Luciano Coelho4a31c112011-03-21 23:16:14 +020089 if (!test_bit(i, wl->scan.scanned_ch) &&
Luciano Coelho08688d62010-07-08 17:50:07 +030090 !(flags & IEEE80211_CHAN_DISABLED) &&
91 ((!!(flags & IEEE80211_CHAN_PASSIVE_SCAN)) == passive) &&
92 (req->channels[i]->band == band)) {
Luciano Coelho34dd2aa2010-07-08 17:50:06 +030093
Luciano Coelho08688d62010-07-08 17:50:07 +030094 wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
95 req->channels[i]->band,
96 req->channels[i]->center_freq);
97 wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
98 req->channels[i]->hw_value,
99 req->channels[i]->flags);
100 wl1271_debug(DEBUG_SCAN,
101 "max_antenna_gain %d, max_power %d",
102 req->channels[i]->max_antenna_gain,
103 req->channels[i]->max_power);
104 wl1271_debug(DEBUG_SCAN, "beacon_found %d",
105 req->channels[i]->beacon_found);
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300106
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200107 if (!passive) {
108 channels[j].min_duration =
109 cpu_to_le32(c->min_dwell_time_active);
110 channels[j].max_duration =
111 cpu_to_le32(c->max_dwell_time_active);
112 } else {
113 channels[j].min_duration =
114 cpu_to_le32(c->min_dwell_time_passive);
115 channels[j].max_duration =
116 cpu_to_le32(c->max_dwell_time_passive);
117 }
Luciano Coelho08688d62010-07-08 17:50:07 +0300118 channels[j].early_termination = 0;
Luciano Coelho3cc7b542010-07-08 17:50:08 +0300119 channels[j].tx_power_att = req->channels[i]->max_power;
Luciano Coelho08688d62010-07-08 17:50:07 +0300120 channels[j].channel = req->channels[i]->hw_value;
121
122 memset(&channels[j].bssid_lsb, 0xff, 4);
123 memset(&channels[j].bssid_msb, 0xff, 2);
124
125 /* Mark the channels we already used */
Luciano Coelho4a31c112011-03-21 23:16:14 +0200126 set_bit(i, wl->scan.scanned_ch);
Luciano Coelho08688d62010-07-08 17:50:07 +0300127
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300128 j++;
129 }
130 }
131
Luciano Coelho08688d62010-07-08 17:50:07 +0300132 return j;
133}
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300134
Luciano Coelho08688d62010-07-08 17:50:07 +0300135#define WL1271_NOTHING_TO_SCAN 1
136
137static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
138 bool passive, u32 basic_rate)
139{
140 struct wl1271_cmd_scan *cmd;
141 struct wl1271_cmd_trigger_scan_to *trigger;
142 int ret;
143 u16 scan_options = 0;
144
145 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
146 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
147 if (!cmd || !trigger) {
148 ret = -ENOMEM;
149 goto out;
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300150 }
151
Luciano Coelho08688d62010-07-08 17:50:07 +0300152 /* We always use high priority scans */
153 scan_options = WL1271_SCAN_OPT_PRIORITY_HIGH;
Luciano Coelho4f35c022010-08-04 04:36:32 +0300154
155 /* No SSIDs means that we have a forced passive scan */
156 if (passive || wl->scan.req->n_ssids == 0)
Luciano Coelho08688d62010-07-08 17:50:07 +0300157 scan_options |= WL1271_SCAN_OPT_PASSIVE;
Luciano Coelho4f35c022010-08-04 04:36:32 +0300158
Eliad Pellera4e02f32011-08-14 13:17:10 +0300159 if (WARN_ON(wl->role_id == WL12XX_INVALID_ROLE_ID)) {
160 ret = -EINVAL;
161 goto out;
162 }
163 cmd->params.role_id = wl->role_id;
Luciano Coelho08688d62010-07-08 17:50:07 +0300164 cmd->params.scan_options = cpu_to_le16(scan_options);
165
166 cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
167 cmd->channels,
168 band, passive);
169 if (cmd->params.n_ch == 0) {
170 ret = WL1271_NOTHING_TO_SCAN;
171 goto out;
172 }
173
174 cmd->params.tx_rate = cpu_to_le32(basic_rate);
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200175 cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs;
Luciano Coelho08688d62010-07-08 17:50:07 +0300176 cmd->params.tx_rate = cpu_to_le32(basic_rate);
177 cmd->params.tid_trigger = 0;
178 cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
179
180 if (band == IEEE80211_BAND_2GHZ)
181 cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ;
182 else
183 cmd->params.band = WL1271_SCAN_BAND_5_GHZ;
184
185 if (wl->scan.ssid_len && wl->scan.ssid) {
186 cmd->params.ssid_len = wl->scan.ssid_len;
187 memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
188 }
189
Eliad Pellera4e02f32011-08-14 13:17:10 +0300190 memcpy(cmd->addr, wl->mac_addr, ETH_ALEN);
191
Luciano Coelho08688d62010-07-08 17:50:07 +0300192 ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len,
193 wl->scan.req->ie, wl->scan.req->ie_len,
194 band);
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300195 if (ret < 0) {
196 wl1271_error("PROBE request template failed");
197 goto out;
198 }
199
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300200 /* disable the timeout */
201 trigger->timeout = 0;
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300202 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
203 sizeof(*trigger), 0);
204 if (ret < 0) {
205 wl1271_error("trigger scan to failed for hw scan");
206 goto out;
207 }
208
Luciano Coelho08688d62010-07-08 17:50:07 +0300209 wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300210
Luciano Coelho08688d62010-07-08 17:50:07 +0300211 ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300212 if (ret < 0) {
213 wl1271_error("SCAN failed");
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300214 goto out;
215 }
216
217out:
Luciano Coelho08688d62010-07-08 17:50:07 +0300218 kfree(cmd);
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300219 kfree(trigger);
220 return ret;
221}
222
Luciano Coelho08688d62010-07-08 17:50:07 +0300223void wl1271_scan_stm(struct wl1271 *wl)
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300224{
Juuso Oikarinen78abd322010-09-21 06:23:32 +0200225 int ret = 0;
Luciano Coelho08688d62010-07-08 17:50:07 +0300226
227 switch (wl->scan.state) {
228 case WL1271_SCAN_STATE_IDLE:
229 break;
230
231 case WL1271_SCAN_STATE_2GHZ_ACTIVE:
232 ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, false,
233 wl->conf.tx.basic_rate);
234 if (ret == WL1271_NOTHING_TO_SCAN) {
235 wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
236 wl1271_scan_stm(wl);
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300237 }
Luciano Coelho08688d62010-07-08 17:50:07 +0300238
239 break;
240
241 case WL1271_SCAN_STATE_2GHZ_PASSIVE:
242 ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, true,
243 wl->conf.tx.basic_rate);
244 if (ret == WL1271_NOTHING_TO_SCAN) {
Juuso Oikarinen02fabb02010-08-19 04:41:15 +0200245 if (wl->enable_11a)
Luciano Coelho08688d62010-07-08 17:50:07 +0300246 wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
247 else
248 wl->scan.state = WL1271_SCAN_STATE_DONE;
249 wl1271_scan_stm(wl);
250 }
251
252 break;
253
254 case WL1271_SCAN_STATE_5GHZ_ACTIVE:
255 ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, false,
256 wl->conf.tx.basic_rate_5);
257 if (ret == WL1271_NOTHING_TO_SCAN) {
258 wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
259 wl1271_scan_stm(wl);
260 }
261
262 break;
263
264 case WL1271_SCAN_STATE_5GHZ_PASSIVE:
265 ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, true,
266 wl->conf.tx.basic_rate_5);
267 if (ret == WL1271_NOTHING_TO_SCAN) {
268 wl->scan.state = WL1271_SCAN_STATE_DONE;
269 wl1271_scan_stm(wl);
270 }
271
272 break;
273
274 case WL1271_SCAN_STATE_DONE:
Juuso Oikarinen78abd322010-09-21 06:23:32 +0200275 wl->scan.failed = false;
276 cancel_delayed_work(&wl->scan_complete_work);
277 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
278 msecs_to_jiffies(0));
Luciano Coelho08688d62010-07-08 17:50:07 +0300279 break;
280
281 default:
282 wl1271_error("invalid scan state");
283 break;
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300284 }
Juuso Oikarinen78abd322010-09-21 06:23:32 +0200285
286 if (ret < 0) {
287 cancel_delayed_work(&wl->scan_complete_work);
288 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
289 msecs_to_jiffies(0));
290 }
Luciano Coelho08688d62010-07-08 17:50:07 +0300291}
292
293int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
294 struct cfg80211_scan_request *req)
295{
Luciano Coelho4a31c112011-03-21 23:16:14 +0200296 /*
297 * cfg80211 should guarantee that we don't get more channels
298 * than what we have registered.
299 */
300 BUG_ON(req->n_channels > WL1271_MAX_CHANNELS);
301
Luciano Coelho08688d62010-07-08 17:50:07 +0300302 if (wl->scan.state != WL1271_SCAN_STATE_IDLE)
303 return -EBUSY;
304
305 wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE;
306
307 if (ssid_len && ssid) {
308 wl->scan.ssid_len = ssid_len;
309 memcpy(wl->scan.ssid, ssid, ssid_len);
310 } else {
311 wl->scan.ssid_len = 0;
312 }
313
314 wl->scan.req = req;
Luciano Coelho4a31c112011-03-21 23:16:14 +0200315 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Luciano Coelho08688d62010-07-08 17:50:07 +0300316
Juuso Oikarinen78abd322010-09-21 06:23:32 +0200317 /* we assume failure so that timeout scenarios are handled correctly */
318 wl->scan.failed = true;
319 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
320 msecs_to_jiffies(WL1271_SCAN_TIMEOUT));
321
Luciano Coelho08688d62010-07-08 17:50:07 +0300322 wl1271_scan_stm(wl);
323
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300324 return 0;
325}
Luciano Coelho95feadc2011-05-10 14:38:59 +0300326
Eliad Peller2aa01592011-06-27 13:06:44 +0300327int wl1271_scan_stop(struct wl1271 *wl)
328{
329 struct wl1271_cmd_header *cmd = NULL;
330 int ret = 0;
331
332 if (WARN_ON(wl->scan.state == WL1271_SCAN_STATE_IDLE))
333 return -EINVAL;
334
335 wl1271_debug(DEBUG_CMD, "cmd scan stop");
336
337 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
338 if (!cmd) {
339 ret = -ENOMEM;
340 goto out;
341 }
342
343 ret = wl1271_cmd_send(wl, CMD_STOP_SCAN, cmd,
344 sizeof(*cmd), 0);
345 if (ret < 0) {
346 wl1271_error("cmd stop_scan failed");
347 goto out;
348 }
349out:
350 kfree(cmd);
351 return ret;
352}
353
Luciano Coelho95feadc2011-05-10 14:38:59 +0300354static int
355wl1271_scan_get_sched_scan_channels(struct wl1271 *wl,
356 struct cfg80211_sched_scan_request *req,
357 struct conn_scan_ch_params *channels,
358 u32 band, bool radar, bool passive,
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300359 int start, int max_channels)
Luciano Coelho95feadc2011-05-10 14:38:59 +0300360{
361 struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
362 int i, j;
363 u32 flags;
Luciano Coelho66870b12011-05-27 15:34:48 +0300364 bool force_passive = !req->n_ssids;
Luciano Coelho95feadc2011-05-10 14:38:59 +0300365
366 for (i = 0, j = start;
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300367 i < req->n_channels && j < max_channels;
Luciano Coelho95feadc2011-05-10 14:38:59 +0300368 i++) {
369 flags = req->channels[i]->flags;
370
Luciano Coelho66870b12011-05-27 15:34:48 +0300371 if (force_passive)
372 flags |= IEEE80211_CHAN_PASSIVE_SCAN;
373
Luciano Coelho2497a242011-05-27 15:34:46 +0300374 if ((req->channels[i]->band == band) &&
375 !(flags & IEEE80211_CHAN_DISABLED) &&
Luciano Coelhodd086822011-05-27 15:34:45 +0300376 (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
Luciano Coelho2497a242011-05-27 15:34:46 +0300377 /* if radar is set, we ignore the passive flag */
378 (radar ||
379 !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
Luciano Coelho95feadc2011-05-10 14:38:59 +0300380 wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
381 req->channels[i]->band,
382 req->channels[i]->center_freq);
383 wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
384 req->channels[i]->hw_value,
385 req->channels[i]->flags);
386 wl1271_debug(DEBUG_SCAN, "max_power %d",
387 req->channels[i]->max_power);
388
Luciano Coelho50a66d72011-05-27 15:34:47 +0300389 if (flags & IEEE80211_CHAN_RADAR) {
Luciano Coelho2497a242011-05-27 15:34:46 +0300390 channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS;
Luciano Coelho50a66d72011-05-27 15:34:47 +0300391 channels[j].passive_duration =
392 cpu_to_le16(c->dwell_time_dfs);
393 }
394 else if (flags & IEEE80211_CHAN_PASSIVE_SCAN) {
Luciano Coelho95feadc2011-05-10 14:38:59 +0300395 channels[j].passive_duration =
396 cpu_to_le16(c->dwell_time_passive);
397 } else {
398 channels[j].min_duration =
399 cpu_to_le16(c->min_dwell_time_active);
400 channels[j].max_duration =
401 cpu_to_le16(c->max_dwell_time_active);
402 }
Luciano Coelho2497a242011-05-27 15:34:46 +0300403 channels[j].tx_power_att = req->channels[i]->max_power;
Luciano Coelho95feadc2011-05-10 14:38:59 +0300404 channels[j].channel = req->channels[i]->hw_value;
405
406 j++;
407 }
408 }
409
410 return j - start;
411}
412
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300413static bool
Luciano Coelho95feadc2011-05-10 14:38:59 +0300414wl1271_scan_sched_scan_channels(struct wl1271 *wl,
415 struct cfg80211_sched_scan_request *req,
416 struct wl1271_cmd_sched_scan_config *cfg)
417{
Luciano Coelho95feadc2011-05-10 14:38:59 +0300418 cfg->passive[0] =
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300419 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
Luciano Coelho95feadc2011-05-10 14:38:59 +0300420 IEEE80211_BAND_2GHZ,
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300421 false, true, 0,
422 MAX_CHANNELS_2GHZ);
Luciano Coelho95feadc2011-05-10 14:38:59 +0300423 cfg->active[0] =
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300424 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
Luciano Coelho95feadc2011-05-10 14:38:59 +0300425 IEEE80211_BAND_2GHZ,
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300426 false, false,
427 cfg->passive[0],
428 MAX_CHANNELS_2GHZ);
Luciano Coelho95feadc2011-05-10 14:38:59 +0300429 cfg->passive[1] =
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300430 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
Luciano Coelho95feadc2011-05-10 14:38:59 +0300431 IEEE80211_BAND_5GHZ,
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300432 false, true, 0,
433 MAX_CHANNELS_5GHZ);
Luciano Coelho95feadc2011-05-10 14:38:59 +0300434 cfg->dfs =
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300435 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
Luciano Coelho95feadc2011-05-10 14:38:59 +0300436 IEEE80211_BAND_5GHZ,
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300437 true, true,
438 cfg->passive[1],
439 MAX_CHANNELS_5GHZ);
Luciano Coelho2497a242011-05-27 15:34:46 +0300440 cfg->active[1] =
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300441 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
Luciano Coelho2497a242011-05-27 15:34:46 +0300442 IEEE80211_BAND_5GHZ,
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300443 false, false,
444 cfg->passive[1] + cfg->dfs,
445 MAX_CHANNELS_5GHZ);
446 /* 802.11j channels are not supported yet */
447 cfg->passive[2] = 0;
448 cfg->active[2] = 0;
Luciano Coelho2497a242011-05-27 15:34:46 +0300449
Luciano Coelho95feadc2011-05-10 14:38:59 +0300450 wl1271_debug(DEBUG_SCAN, " 2.4GHz: active %d passive %d",
451 cfg->active[0], cfg->passive[0]);
452 wl1271_debug(DEBUG_SCAN, " 5GHz: active %d passive %d",
453 cfg->active[1], cfg->passive[1]);
Luciano Coelho2497a242011-05-27 15:34:46 +0300454 wl1271_debug(DEBUG_SCAN, " DFS: %d", cfg->dfs);
Luciano Coelho95feadc2011-05-10 14:38:59 +0300455
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300456 return cfg->passive[0] || cfg->active[0] ||
457 cfg->passive[1] || cfg->active[1] || cfg->dfs ||
458 cfg->passive[2] || cfg->active[2];
Luciano Coelho95feadc2011-05-10 14:38:59 +0300459}
460
461int wl1271_scan_sched_scan_config(struct wl1271 *wl,
462 struct cfg80211_sched_scan_request *req,
463 struct ieee80211_sched_scan_ies *ies)
464{
465 struct wl1271_cmd_sched_scan_config *cfg = NULL;
466 struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300467 int i, ret;
Luciano Coelho66870b12011-05-27 15:34:48 +0300468 bool force_passive = !req->n_ssids;
Luciano Coelho95feadc2011-05-10 14:38:59 +0300469
470 wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config");
471
472 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
473 if (!cfg)
474 return -ENOMEM;
475
476 cfg->rssi_threshold = c->rssi_threshold;
477 cfg->snr_threshold = c->snr_threshold;
478 cfg->n_probe_reqs = c->num_probe_reqs;
479 /* cycles set to 0 it means infinite (until manually stopped) */
480 cfg->cycles = 0;
481 /* report APs when at least 1 is found */
482 cfg->report_after = 1;
483 /* don't stop scanning automatically when something is found */
484 cfg->terminate = 0;
485 cfg->tag = WL1271_SCAN_DEFAULT_TAG;
486 /* don't filter on BSS type */
487 cfg->bss_type = SCAN_BSS_TYPE_ANY;
488 /* currently NL80211 supports only a single interval */
489 for (i = 0; i < SCAN_MAX_CYCLE_INTERVALS; i++)
490 cfg->intervals[i] = cpu_to_le32(req->interval);
491
Luciano Coelho66870b12011-05-27 15:34:48 +0300492 if (!force_passive && req->ssids[0].ssid_len && req->ssids[0].ssid) {
Luciano Coelho95feadc2011-05-10 14:38:59 +0300493 cfg->filter_type = SCAN_SSID_FILTER_SPECIFIC;
494 cfg->ssid_len = req->ssids[0].ssid_len;
495 memcpy(cfg->ssid, req->ssids[0].ssid,
496 req->ssids[0].ssid_len);
497 } else {
498 cfg->filter_type = SCAN_SSID_FILTER_ANY;
499 cfg->ssid_len = 0;
500 }
501
Luciano Coelhod2c2bb92011-05-31 16:38:56 +0300502 if (!wl1271_scan_sched_scan_channels(wl, req, cfg)) {
Luciano Coelho95feadc2011-05-10 14:38:59 +0300503 wl1271_error("scan channel list is empty");
504 ret = -EINVAL;
505 goto out;
506 }
507
Luciano Coelho66870b12011-05-27 15:34:48 +0300508 if (!force_passive && cfg->active[0]) {
Luciano Coelho95feadc2011-05-10 14:38:59 +0300509 ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid,
510 req->ssids[0].ssid_len,
511 ies->ie[IEEE80211_BAND_2GHZ],
512 ies->len[IEEE80211_BAND_2GHZ],
513 IEEE80211_BAND_2GHZ);
514 if (ret < 0) {
515 wl1271_error("2.4GHz PROBE request template failed");
516 goto out;
517 }
518 }
519
Luciano Coelho66870b12011-05-27 15:34:48 +0300520 if (!force_passive && cfg->active[1]) {
Luciano Coelho95feadc2011-05-10 14:38:59 +0300521 ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid,
522 req->ssids[0].ssid_len,
523 ies->ie[IEEE80211_BAND_5GHZ],
524 ies->len[IEEE80211_BAND_5GHZ],
525 IEEE80211_BAND_5GHZ);
526 if (ret < 0) {
527 wl1271_error("5GHz PROBE request template failed");
528 goto out;
529 }
530 }
531
532 wl1271_dump(DEBUG_SCAN, "SCAN_CFG: ", cfg, sizeof(*cfg));
533
534 ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_CFG, cfg,
535 sizeof(*cfg), 0);
536 if (ret < 0) {
537 wl1271_error("SCAN configuration failed");
538 goto out;
539 }
540out:
541 kfree(cfg);
542 return ret;
543}
544
545int wl1271_scan_sched_scan_start(struct wl1271 *wl)
546{
547 struct wl1271_cmd_sched_scan_start *start;
548 int ret = 0;
549
550 wl1271_debug(DEBUG_CMD, "cmd periodic scan start");
551
Luciano Coelho683c0022011-05-12 17:07:55 +0300552 if (wl->bss_type != BSS_TYPE_STA_BSS)
553 return -EOPNOTSUPP;
554
555 if (!test_bit(WL1271_FLAG_IDLE, &wl->flags))
556 return -EBUSY;
557
Luciano Coelho95feadc2011-05-10 14:38:59 +0300558 start = kzalloc(sizeof(*start), GFP_KERNEL);
559 if (!start)
560 return -ENOMEM;
561
562 start->tag = WL1271_SCAN_DEFAULT_TAG;
563
564 ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start,
565 sizeof(*start), 0);
566 if (ret < 0) {
567 wl1271_error("failed to send scan start command");
568 goto out_free;
569 }
570
571out_free:
572 kfree(start);
573 return ret;
574}
575
576void wl1271_scan_sched_scan_results(struct wl1271 *wl)
577{
578 wl1271_debug(DEBUG_SCAN, "got periodic scan results");
579
580 ieee80211_sched_scan_results(wl->hw);
581}
582
583void wl1271_scan_sched_scan_stop(struct wl1271 *wl)
584{
585 struct wl1271_cmd_sched_scan_stop *stop;
586 int ret = 0;
587
588 wl1271_debug(DEBUG_CMD, "cmd periodic scan stop");
589
590 /* FIXME: what to do if alloc'ing to stop fails? */
591 stop = kzalloc(sizeof(*stop), GFP_KERNEL);
592 if (!stop) {
593 wl1271_error("failed to alloc memory to send sched scan stop");
594 return;
595 }
596
597 stop->tag = WL1271_SCAN_DEFAULT_TAG;
598
599 ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop,
600 sizeof(*stop), 0);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300601 if (ret < 0) {
Luciano Coelho95feadc2011-05-10 14:38:59 +0300602 wl1271_error("failed to send sched scan stop command");
Luciano Coelho33c2c062011-05-10 14:46:02 +0300603 goto out_free;
604 }
605 wl->sched_scanning = false;
Luciano Coelho95feadc2011-05-10 14:38:59 +0300606
Luciano Coelho33c2c062011-05-10 14:46:02 +0300607out_free:
Luciano Coelho95feadc2011-05-10 14:38:59 +0300608 kfree(stop);
609}