cfg80211: add more flexible BSS lookup
[deliverable/linux.git] / net / mac80211 / scan.c
CommitLineData
0a51b27e 1/*
5484e237
JB
2 * Scanning implementation
3 *
0a51b27e
JB
4 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
5484e237 15/* TODO:
2a519311 16 * figure out how to avoid that the "current BSS" expires
99cf5f5f 17 * use cfg80211's BSS handling
5484e237
JB
18 */
19
0a51b27e
JB
20#include <linux/wireless.h>
21#include <linux/if_arp.h>
078e1e60 22#include <linux/rtnetlink.h>
0a51b27e
JB
23#include <net/mac80211.h>
24#include <net/iw_handler.h>
25
26#include "ieee80211_i.h"
5484e237 27#include "mesh.h"
0a51b27e
JB
28
29#define IEEE80211_PROBE_DELAY (HZ / 33)
30#define IEEE80211_CHANNEL_TIME (HZ / 33)
31#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
32
5484e237
JB
33void ieee80211_rx_bss_list_init(struct ieee80211_local *local)
34{
c2b13452
JB
35 spin_lock_init(&local->bss_lock);
36 INIT_LIST_HEAD(&local->bss_list);
5484e237
JB
37}
38
39void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local)
40{
c2b13452 41 struct ieee80211_bss *bss, *tmp;
5484e237 42
c2b13452 43 list_for_each_entry_safe(bss, tmp, &local->bss_list, list)
5484e237
JB
44 ieee80211_rx_bss_put(local, bss);
45}
46
c2b13452 47struct ieee80211_bss *
5484e237
JB
48ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
49 u8 *ssid, u8 ssid_len)
50{
c2b13452 51 struct ieee80211_bss *bss;
5484e237 52
c2b13452
JB
53 spin_lock_bh(&local->bss_lock);
54 bss = local->bss_hash[STA_HASH(bssid)];
5484e237
JB
55 while (bss) {
56 if (!bss_mesh_cfg(bss) &&
57 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
58 bss->freq == freq &&
59 bss->ssid_len == ssid_len &&
60 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
61 atomic_inc(&bss->users);
62 break;
63 }
64 bss = bss->hnext;
65 }
c2b13452 66 spin_unlock_bh(&local->bss_lock);
5484e237
JB
67 return bss;
68}
69
c2b13452 70/* Caller must hold local->bss_lock */
5484e237 71static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local,
c2b13452 72 struct ieee80211_bss *bss)
5484e237
JB
73{
74 u8 hash_idx;
75
76 if (bss_mesh_cfg(bss))
77 hash_idx = mesh_id_hash(bss_mesh_id(bss),
78 bss_mesh_id_len(bss));
79 else
80 hash_idx = STA_HASH(bss->bssid);
81
c2b13452
JB
82 bss->hnext = local->bss_hash[hash_idx];
83 local->bss_hash[hash_idx] = bss;
5484e237
JB
84}
85
c2b13452 86/* Caller must hold local->bss_lock */
5484e237 87static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local,
c2b13452 88 struct ieee80211_bss *bss)
5484e237 89{
c2b13452
JB
90 struct ieee80211_bss *b, *prev = NULL;
91 b = local->bss_hash[STA_HASH(bss->bssid)];
5484e237
JB
92 while (b) {
93 if (b == bss) {
94 if (!prev)
c2b13452 95 local->bss_hash[STA_HASH(bss->bssid)] =
5484e237
JB
96 bss->hnext;
97 else
98 prev->hnext = bss->hnext;
99 break;
100 }
101 prev = b;
102 b = b->hnext;
103 }
104}
105
99cf5f5f 106static struct ieee80211_bss *
5484e237
JB
107ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq,
108 u8 *ssid, u8 ssid_len)
109{
c2b13452 110 struct ieee80211_bss *bss;
5484e237
JB
111
112 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
113 if (!bss)
114 return NULL;
115 atomic_set(&bss->users, 2);
116 memcpy(bss->bssid, bssid, ETH_ALEN);
117 bss->freq = freq;
118 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
119 memcpy(bss->ssid, ssid, ssid_len);
120 bss->ssid_len = ssid_len;
121 }
122
c2b13452 123 spin_lock_bh(&local->bss_lock);
5484e237 124 /* TODO: order by RSSI? */
c2b13452 125 list_add_tail(&bss->list, &local->bss_list);
5484e237 126 __ieee80211_rx_bss_hash_add(local, bss);
c2b13452 127 spin_unlock_bh(&local->bss_lock);
5484e237
JB
128 return bss;
129}
130
131#ifdef CONFIG_MAC80211_MESH
c2b13452 132static struct ieee80211_bss *
5484e237
JB
133ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len,
134 u8 *mesh_cfg, int freq)
135{
c2b13452 136 struct ieee80211_bss *bss;
5484e237 137
c2b13452
JB
138 spin_lock_bh(&local->bss_lock);
139 bss = local->bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
5484e237
JB
140 while (bss) {
141 if (bss_mesh_cfg(bss) &&
142 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
143 bss->freq == freq &&
144 mesh_id_len == bss->mesh_id_len &&
145 (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
146 mesh_id_len))) {
147 atomic_inc(&bss->users);
148 break;
149 }
150 bss = bss->hnext;
151 }
c2b13452 152 spin_unlock_bh(&local->bss_lock);
5484e237
JB
153 return bss;
154}
155
c2b13452 156static struct ieee80211_bss *
5484e237
JB
157ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len,
158 u8 *mesh_cfg, int mesh_config_len, int freq)
159{
c2b13452 160 struct ieee80211_bss *bss;
5484e237 161
1239cd58 162 if (mesh_config_len != IEEE80211_MESH_CONFIG_LEN)
5484e237
JB
163 return NULL;
164
165 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
166 if (!bss)
167 return NULL;
168
169 bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
170 if (!bss->mesh_cfg) {
171 kfree(bss);
172 return NULL;
173 }
174
175 if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
176 bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
177 if (!bss->mesh_id) {
178 kfree(bss->mesh_cfg);
179 kfree(bss);
180 return NULL;
181 }
182 memcpy(bss->mesh_id, mesh_id, mesh_id_len);
183 }
184
185 atomic_set(&bss->users, 2);
186 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
187 bss->mesh_id_len = mesh_id_len;
188 bss->freq = freq;
c2b13452 189 spin_lock_bh(&local->bss_lock);
5484e237 190 /* TODO: order by RSSI? */
c2b13452 191 list_add_tail(&bss->list, &local->bss_list);
5484e237 192 __ieee80211_rx_bss_hash_add(local, bss);
c2b13452 193 spin_unlock_bh(&local->bss_lock);
5484e237
JB
194 return bss;
195}
196#endif
197
c2b13452 198static void ieee80211_rx_bss_free(struct ieee80211_bss *bss)
5484e237
JB
199{
200 kfree(bss->ies);
201 kfree(bss_mesh_id(bss));
202 kfree(bss_mesh_cfg(bss));
203 kfree(bss);
204}
205
206void ieee80211_rx_bss_put(struct ieee80211_local *local,
c2b13452 207 struct ieee80211_bss *bss)
5484e237
JB
208{
209 local_bh_disable();
c2b13452 210 if (!atomic_dec_and_lock(&bss->users, &local->bss_lock)) {
5484e237
JB
211 local_bh_enable();
212 return;
213 }
214
215 __ieee80211_rx_bss_hash_del(local, bss);
216 list_del(&bss->list);
c2b13452 217 spin_unlock_bh(&local->bss_lock);
5484e237
JB
218 ieee80211_rx_bss_free(bss);
219}
220
c2b13452 221struct ieee80211_bss *
5484e237
JB
222ieee80211_bss_info_update(struct ieee80211_local *local,
223 struct ieee80211_rx_status *rx_status,
224 struct ieee80211_mgmt *mgmt,
225 size_t len,
226 struct ieee802_11_elems *elems,
2a519311
JB
227 struct ieee80211_channel *channel,
228 bool beacon)
5484e237 229{
c2b13452 230 struct ieee80211_bss *bss;
2a519311
JB
231 int clen, freq = channel->center_freq;
232 enum cfg80211_signal_type sigtype = CFG80211_SIGNAL_TYPE_NONE;
233 s32 signal = 0;
234
235 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
236 sigtype = CFG80211_SIGNAL_TYPE_MBM;
237 signal = rx_status->signal * 100;
238 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
239 sigtype = CFG80211_SIGNAL_TYPE_UNSPEC;
240 signal = (rx_status->signal * 100) / local->hw.max_signal;
241 }
242
243 cfg80211_put_bss(
244 cfg80211_inform_bss_frame(local->hw.wiphy, channel,
245 mgmt, len, signal, sigtype,
246 GFP_ATOMIC));
5484e237
JB
247
248#ifdef CONFIG_MAC80211_MESH
249 if (elems->mesh_config)
250 bss = ieee80211_rx_mesh_bss_get(local, elems->mesh_id,
251 elems->mesh_id_len, elems->mesh_config, freq);
252 else
253#endif
254 bss = ieee80211_rx_bss_get(local, mgmt->bssid, freq,
255 elems->ssid, elems->ssid_len);
256 if (!bss) {
257#ifdef CONFIG_MAC80211_MESH
258 if (elems->mesh_config)
259 bss = ieee80211_rx_mesh_bss_add(local, elems->mesh_id,
260 elems->mesh_id_len, elems->mesh_config,
261 elems->mesh_config_len, freq);
262 else
263#endif
264 bss = ieee80211_rx_bss_add(local, mgmt->bssid, freq,
265 elems->ssid, elems->ssid_len);
266 if (!bss)
267 return NULL;
268 } else {
269#if 0
270 /* TODO: order by RSSI? */
c2b13452
JB
271 spin_lock_bh(&local->bss_lock);
272 list_move_tail(&bss->list, &local->bss_list);
273 spin_unlock_bh(&local->bss_lock);
5484e237
JB
274#endif
275 }
276
277 /* save the ERP value so that it is available at association time */
278 if (elems->erp_info && elems->erp_info_len >= 1) {
279 bss->erp_value = elems->erp_info[0];
280 bss->has_erp_value = 1;
281 }
282
283 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
284 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
285
286 if (elems->tim) {
287 struct ieee80211_tim_ie *tim_ie =
288 (struct ieee80211_tim_ie *)elems->tim;
289 bss->dtim_period = tim_ie->dtim_period;
290 }
291
292 /* set default value for buggy APs */
293 if (!elems->tim || bss->dtim_period == 0)
294 bss->dtim_period = 1;
295
296 bss->supp_rates_len = 0;
297 if (elems->supp_rates) {
298 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
299 if (clen > elems->supp_rates_len)
300 clen = elems->supp_rates_len;
301 memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates,
302 clen);
303 bss->supp_rates_len += clen;
304 }
305 if (elems->ext_supp_rates) {
306 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
307 if (clen > elems->ext_supp_rates_len)
308 clen = elems->ext_supp_rates_len;
309 memcpy(&bss->supp_rates[bss->supp_rates_len],
310 elems->ext_supp_rates, clen);
311 bss->supp_rates_len += clen;
312 }
313
314 bss->band = rx_status->band;
315
316 bss->timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
317 bss->last_update = jiffies;
318 bss->signal = rx_status->signal;
319 bss->noise = rx_status->noise;
320 bss->qual = rx_status->qual;
321 bss->wmm_used = elems->wmm_param || elems->wmm_info;
322
323 if (!beacon)
324 bss->last_probe_resp = jiffies;
325
326 /*
327 * For probe responses, or if we don't have any information yet,
328 * use the IEs from the beacon.
329 */
330 if (!bss->ies || !beacon) {
331 if (bss->ies == NULL || bss->ies_len < elems->total_len) {
332 kfree(bss->ies);
333 bss->ies = kmalloc(elems->total_len, GFP_ATOMIC);
334 }
335 if (bss->ies) {
336 memcpy(bss->ies, elems->ie_start, elems->total_len);
337 bss->ies_len = elems->total_len;
338 } else
339 bss->ies_len = 0;
340 }
341
342 return bss;
343}
0a51b27e 344
7a947080
VT
345void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid,
346 int freq, u8 *ssid, u8 ssid_len)
347{
348 struct ieee80211_bss *bss;
349 struct ieee80211_local *local = sdata->local;
350
351 bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len);
352 if (bss) {
353 atomic_dec(&bss->users);
354 ieee80211_rx_bss_put(local, bss);
355 }
356}
357
98c8fccf 358ieee80211_rx_result
c2b13452
JB
359ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
360 struct ieee80211_rx_status *rx_status)
98c8fccf
JB
361{
362 struct ieee80211_mgmt *mgmt;
c2b13452 363 struct ieee80211_bss *bss;
98c8fccf
JB
364 u8 *elements;
365 struct ieee80211_channel *channel;
366 size_t baselen;
367 int freq;
368 __le16 fc;
369 bool presp, beacon = false;
370 struct ieee802_11_elems elems;
371
372 if (skb->len < 2)
373 return RX_DROP_UNUSABLE;
374
375 mgmt = (struct ieee80211_mgmt *) skb->data;
376 fc = mgmt->frame_control;
377
378 if (ieee80211_is_ctl(fc))
379 return RX_CONTINUE;
380
381 if (skb->len < 24)
382 return RX_DROP_MONITOR;
383
384 presp = ieee80211_is_probe_resp(fc);
385 if (presp) {
386 /* ignore ProbeResp to foreign address */
387 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
388 return RX_DROP_MONITOR;
389
390 presp = true;
391 elements = mgmt->u.probe_resp.variable;
392 baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
393 } else {
394 beacon = ieee80211_is_beacon(fc);
395 baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable);
396 elements = mgmt->u.beacon.variable;
397 }
398
399 if (!presp && !beacon)
400 return RX_CONTINUE;
401
402 if (baselen > skb->len)
403 return RX_DROP_MONITOR;
404
405 ieee802_11_parse_elems(elements, skb->len - baselen, &elems);
406
407 if (elems.ds_params && elems.ds_params_len == 1)
408 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
409 else
410 freq = rx_status->freq;
411
412 channel = ieee80211_get_channel(sdata->local->hw.wiphy, freq);
413
414 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
415 return RX_DROP_MONITOR;
416
417 bss = ieee80211_bss_info_update(sdata->local, rx_status,
418 mgmt, skb->len, &elems,
2a519311 419 channel, beacon);
d048e503
JM
420 if (bss)
421 ieee80211_rx_bss_put(sdata->local, bss);
98c8fccf
JB
422
423 dev_kfree_skb(skb);
424 return RX_QUEUED;
425}
426
a97b77b9 427void ieee80211_send_nullfunc(struct ieee80211_local *local,
0a51b27e
JB
428 struct ieee80211_sub_if_data *sdata,
429 int powersave)
430{
431 struct sk_buff *skb;
432 struct ieee80211_hdr *nullfunc;
433 __le16 fc;
434
435 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
436 if (!skb) {
437 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
438 "frame\n", sdata->dev->name);
439 return;
440 }
441 skb_reserve(skb, local->hw.extra_tx_headroom);
442
443 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
444 memset(nullfunc, 0, 24);
445 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
446 IEEE80211_FCTL_TODS);
447 if (powersave)
448 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
449 nullfunc->frame_control = fc;
450 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
451 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
452 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
453
e50db65c 454 ieee80211_tx_skb(sdata, skb, 0);
0a51b27e
JB
455}
456
2a519311 457void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
0a51b27e
JB
458{
459 struct ieee80211_local *local = hw_to_local(hw);
460 struct ieee80211_sub_if_data *sdata;
0a51b27e 461
c2b13452 462 if (WARN_ON(!local->hw_scanning && !local->sw_scanning))
5bc75728
JB
463 return;
464
2a519311
JB
465 if (WARN_ON(!local->scan_req))
466 return;
5bc75728 467
2a519311
JB
468 if (local->scan_req != &local->int_scan_req)
469 cfg80211_scan_done(local->scan_req, aborted);
470 local->scan_req = NULL;
471
472 local->last_scan_completed = jiffies;
0a51b27e 473
c2b13452
JB
474 if (local->hw_scanning) {
475 local->hw_scanning = false;
e8975581
JB
476 /*
477 * Somebody might have requested channel change during scan
478 * that we won't have acted upon, try now. ieee80211_hw_config
479 * will set the flag based on actual changes.
480 */
481 ieee80211_hw_config(local, 0);
0a51b27e
JB
482 goto done;
483 }
484
c2b13452 485 local->sw_scanning = false;
e8975581 486 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
0a51b27e
JB
487
488 netif_tx_lock_bh(local->mdev);
489 netif_addr_lock(local->mdev);
490 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
491 local->ops->configure_filter(local_to_hw(local),
492 FIF_BCN_PRBRESP_PROMISC,
493 &local->filter_flags,
494 local->mdev->mc_count,
495 local->mdev->mc_list);
496
497 netif_addr_unlock(local->mdev);
498 netif_tx_unlock_bh(local->mdev);
499
078e1e60
JB
500 mutex_lock(&local->iflist_mtx);
501 list_for_each_entry(sdata, &local->interfaces, list) {
fb9ddbf0
JB
502 if (!netif_running(sdata->dev))
503 continue;
504
0a51b27e 505 /* Tell AP we're back */
05c914fe 506 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
0a51b27e
JB
507 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) {
508 ieee80211_send_nullfunc(local, sdata, 0);
509 netif_tx_wake_all_queues(sdata->dev);
510 }
511 } else
512 netif_tx_wake_all_queues(sdata->dev);
078e1e60 513
14b80724
JB
514 /* re-enable beaconing */
515 if (sdata->vif.type == NL80211_IFTYPE_AP ||
516 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
517 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
518 ieee80211_if_config(sdata,
519 IEEE80211_IFCC_BEACON_ENABLED);
0a51b27e 520 }
078e1e60 521 mutex_unlock(&local->iflist_mtx);
0a51b27e
JB
522
523 done:
524 ieee80211_mlme_notify_scan_completed(local);
472dbc45 525 ieee80211_mesh_notify_scan_completed(local);
0a51b27e
JB
526}
527EXPORT_SYMBOL(ieee80211_scan_completed);
528
c2b13452 529void ieee80211_scan_work(struct work_struct *work)
0a51b27e
JB
530{
531 struct ieee80211_local *local =
532 container_of(work, struct ieee80211_local, scan_work.work);
533 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
0a51b27e 534 struct ieee80211_channel *chan;
2a519311 535 int skip, i;
0a51b27e
JB
536 unsigned long next_delay = 0;
537
5bc75728
JB
538 /*
539 * Avoid re-scheduling when the sdata is going away.
540 */
541 if (!netif_running(sdata->dev))
0a51b27e
JB
542 return;
543
544 switch (local->scan_state) {
545 case SCAN_SET_CHANNEL:
0a51b27e 546 /* if no more bands/channels left, complete scan */
2a519311
JB
547 if (local->scan_channel_idx >= local->scan_req->n_channels) {
548 ieee80211_scan_completed(local_to_hw(local), false);
0a51b27e
JB
549 return;
550 }
551 skip = 0;
2a519311 552 chan = local->scan_req->channels[local->scan_channel_idx];
0a51b27e
JB
553
554 if (chan->flags & IEEE80211_CHAN_DISABLED ||
05c914fe 555 (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
0a51b27e
JB
556 chan->flags & IEEE80211_CHAN_NO_IBSS))
557 skip = 1;
558
559 if (!skip) {
560 local->scan_channel = chan;
e8975581
JB
561 if (ieee80211_hw_config(local,
562 IEEE80211_CONF_CHANGE_CHANNEL))
0a51b27e 563 skip = 1;
0a51b27e
JB
564 }
565
566 /* advance state machine to next channel/band */
567 local->scan_channel_idx++;
0a51b27e
JB
568
569 if (skip)
570 break;
571
572 next_delay = IEEE80211_PROBE_DELAY +
573 usecs_to_jiffies(local->hw.channel_change_time);
574 local->scan_state = SCAN_SEND_PROBE;
575 break;
576 case SCAN_SEND_PROBE:
577 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
578 local->scan_state = SCAN_SET_CHANNEL;
579
2a519311
JB
580 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
581 !local->scan_req->n_ssids)
0a51b27e 582 break;
2a519311
JB
583 for (i = 0; i < local->scan_req->n_ssids; i++)
584 ieee80211_send_probe_req(
585 sdata, NULL,
586 local->scan_req->ssids[i].ssid,
587 local->scan_req->ssids[i].ssid_len);
0a51b27e
JB
588 next_delay = IEEE80211_CHANNEL_TIME;
589 break;
590 }
591
5bc75728
JB
592 queue_delayed_work(local->hw.workqueue, &local->scan_work,
593 next_delay);
0a51b27e
JB
594}
595
596
c2b13452 597int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata,
2a519311 598 struct cfg80211_scan_request *req)
0a51b27e
JB
599{
600 struct ieee80211_local *local = scan_sdata->local;
601 struct ieee80211_sub_if_data *sdata;
602
2a519311 603 if (!req)
0a51b27e
JB
604 return -EINVAL;
605
2a519311
JB
606 if (local->scan_req && local->scan_req != req)
607 return -EBUSY;
608
609 local->scan_req = req;
610
0a51b27e
JB
611 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
612 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
613 * BSSID: MACAddress
614 * SSID
615 * ScanType: ACTIVE, PASSIVE
616 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
617 * a Probe frame during active scanning
618 * ChannelList
619 * MinChannelTime (>= ProbeDelay), in TU
620 * MaxChannelTime: (>= MinChannelTime), in TU
621 */
622
623 /* MLME-SCAN.confirm
624 * BSSDescriptionSet
625 * ResultCode: SUCCESS, INVALID_PARAMETERS
626 */
627
c2b13452 628 if (local->sw_scanning || local->hw_scanning) {
0a51b27e
JB
629 if (local->scan_sdata == scan_sdata)
630 return 0;
631 return -EBUSY;
632 }
633
634 if (local->ops->hw_scan) {
5bc75728
JB
635 int rc;
636
c2b13452 637 local->hw_scanning = true;
2a519311 638 rc = local->ops->hw_scan(local_to_hw(local), req);
5bc75728 639 if (rc) {
c2b13452 640 local->hw_scanning = false;
5bc75728 641 return rc;
0a51b27e 642 }
5bc75728
JB
643 local->scan_sdata = scan_sdata;
644 return 0;
0a51b27e
JB
645 }
646
c2b13452 647 local->sw_scanning = true;
0a51b27e 648
078e1e60
JB
649 mutex_lock(&local->iflist_mtx);
650 list_for_each_entry(sdata, &local->interfaces, list) {
fb9ddbf0
JB
651 if (!netif_running(sdata->dev))
652 continue;
653
14b80724
JB
654 /* disable beaconing */
655 if (sdata->vif.type == NL80211_IFTYPE_AP ||
656 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
657 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
658 ieee80211_if_config(sdata,
659 IEEE80211_IFCC_BEACON_ENABLED);
078e1e60 660
05c914fe 661 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
0a51b27e
JB
662 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) {
663 netif_tx_stop_all_queues(sdata->dev);
664 ieee80211_send_nullfunc(local, sdata, 1);
665 }
666 } else
667 netif_tx_stop_all_queues(sdata->dev);
668 }
078e1e60 669 mutex_unlock(&local->iflist_mtx);
0a51b27e 670
0a51b27e
JB
671 local->scan_state = SCAN_SET_CHANNEL;
672 local->scan_channel_idx = 0;
0a51b27e 673 local->scan_sdata = scan_sdata;
2a519311 674 local->scan_req = req;
0a51b27e
JB
675
676 netif_addr_lock_bh(local->mdev);
677 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
678 local->ops->configure_filter(local_to_hw(local),
679 FIF_BCN_PRBRESP_PROMISC,
680 &local->filter_flags,
681 local->mdev->mc_count,
682 local->mdev->mc_list);
683 netif_addr_unlock_bh(local->mdev);
684
685 /* TODO: start scan as soon as all nullfunc frames are ACKed */
686 queue_delayed_work(local->hw.workqueue, &local->scan_work,
687 IEEE80211_CHANNEL_TIME);
688
689 return 0;
690}
691
692
c2b13452 693int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
2a519311 694 struct cfg80211_scan_request *req)
0a51b27e 695{
0a51b27e 696 struct ieee80211_local *local = sdata->local;
9116dd01 697 struct ieee80211_if_sta *ifsta;
0a51b27e 698
2a519311
JB
699 if (!req)
700 return -EINVAL;
701
702 if (local->scan_req && local->scan_req != req)
703 return -EBUSY;
704
705 local->scan_req = req;
706
05c914fe 707 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2a519311 708 return ieee80211_start_scan(sdata, req);
0a51b27e 709
9116dd01
JB
710 /*
711 * STA has a state machine that might need to defer scanning
712 * while it's trying to associate/authenticate, therefore we
713 * queue it up to the state machine in that case.
714 */
715
c2b13452 716 if (local->sw_scanning || local->hw_scanning) {
0a51b27e
JB
717 if (local->scan_sdata == sdata)
718 return 0;
719 return -EBUSY;
720 }
721
9116dd01 722 ifsta = &sdata->u.sta;
0a51b27e
JB
723 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
724 queue_work(local->hw.workqueue, &ifsta->work);
9116dd01 725
0a51b27e
JB
726 return 0;
727}
This page took 0.142358 seconds and 5 git commands to generate.