ALSA: usb-line6: use the same declaration as definition in header for MIDI manufactur...
[deliverable/linux.git] / net / wireless / scan.c
CommitLineData
2a519311
JB
1/*
2 * cfg80211 scan result handling
3 *
4 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
2740f0cf 5 * Copyright 2013-2014 Intel Mobile Communications GmbH
1d76250b 6 * Copyright 2016 Intel Deutschland GmbH
2a519311
JB
7 */
8#include <linux/kernel.h>
5a0e3ad6 9#include <linux/slab.h>
2a519311
JB
10#include <linux/module.h>
11#include <linux/netdevice.h>
12#include <linux/wireless.h>
13#include <linux/nl80211.h>
14#include <linux/etherdevice.h>
15#include <net/arp.h>
16#include <net/cfg80211.h>
262eb9b2 17#include <net/cfg80211-wext.h>
2a519311
JB
18#include <net/iw_handler.h>
19#include "core.h"
20#include "nl80211.h"
a9a11622 21#include "wext-compat.h"
e35e4d28 22#include "rdev-ops.h"
2a519311 23
776b3580
JB
24/**
25 * DOC: BSS tree/list structure
26 *
27 * At the top level, the BSS list is kept in both a list in each
28 * registered device (@bss_list) as well as an RB-tree for faster
29 * lookup. In the RB-tree, entries can be looked up using their
30 * channel, MESHID, MESHCONF (for MBSSes) or channel, BSSID, SSID
31 * for other BSSes.
32 *
33 * Due to the possibility of hidden SSIDs, there's a second level
34 * structure, the "hidden_list" and "hidden_beacon_bss" pointer.
35 * The hidden_list connects all BSSes belonging to a single AP
36 * that has a hidden SSID, and connects beacon and probe response
37 * entries. For a probe response entry for a hidden SSID, the
38 * hidden_beacon_bss pointer points to the BSS struct holding the
39 * beacon's information.
40 *
41 * Reference counting is done for all these references except for
42 * the hidden_list, so that a beacon BSS struct that is otherwise
43 * not referenced has one reference for being on the bss_list and
44 * one for each probe response entry that points to it using the
45 * hidden_beacon_bss pointer. When a BSS struct that has such a
46 * pointer is get/put, the refcount update is also propagated to
47 * the referenced struct, this ensure that it cannot get removed
48 * while somebody is using the probe response version.
49 *
50 * Note that the hidden_beacon_bss pointer never changes, due to
51 * the reference counting. Therefore, no locking is needed for
52 * it.
53 *
54 * Also note that the hidden_beacon_bss pointer is only relevant
55 * if the driver uses something other than the IEs, e.g. private
56 * data stored stored in the BSS struct, since the beacon IEs are
57 * also linked into the probe response struct.
58 */
59
f9616e0f 60#define IEEE80211_SCAN_RESULT_EXPIRE (30 * HZ)
2a519311 61
776b3580 62static void bss_free(struct cfg80211_internal_bss *bss)
e8e27c66 63{
9caf0364 64 struct cfg80211_bss_ies *ies;
b629ea3d
JB
65
66 if (WARN_ON(atomic_read(&bss->hold)))
67 return;
68
9caf0364 69 ies = (void *)rcu_access_pointer(bss->pub.beacon_ies);
776b3580 70 if (ies && !bss->pub.hidden_beacon_bss)
9caf0364
JB
71 kfree_rcu(ies, rcu_head);
72 ies = (void *)rcu_access_pointer(bss->pub.proberesp_ies);
73 if (ies)
74 kfree_rcu(ies, rcu_head);
e8e27c66 75
776b3580
JB
76 /*
77 * This happens when the module is removed, it doesn't
78 * really matter any more save for completeness
79 */
80 if (!list_empty(&bss->hidden_list))
81 list_del(&bss->hidden_list);
82
e8e27c66
AK
83 kfree(bss);
84}
85
1b8ec87a 86static inline void bss_ref_get(struct cfg80211_registered_device *rdev,
776b3580 87 struct cfg80211_internal_bss *bss)
0532d4f1 88{
1b8ec87a 89 lockdep_assert_held(&rdev->bss_lock);
776b3580
JB
90
91 bss->refcount++;
92 if (bss->pub.hidden_beacon_bss) {
93 bss = container_of(bss->pub.hidden_beacon_bss,
94 struct cfg80211_internal_bss,
95 pub);
96 bss->refcount++;
97 }
0532d4f1
JB
98}
99
1b8ec87a 100static inline void bss_ref_put(struct cfg80211_registered_device *rdev,
776b3580 101 struct cfg80211_internal_bss *bss)
0532d4f1 102{
1b8ec87a 103 lockdep_assert_held(&rdev->bss_lock);
776b3580
JB
104
105 if (bss->pub.hidden_beacon_bss) {
106 struct cfg80211_internal_bss *hbss;
107 hbss = container_of(bss->pub.hidden_beacon_bss,
108 struct cfg80211_internal_bss,
109 pub);
110 hbss->refcount--;
111 if (hbss->refcount == 0)
112 bss_free(hbss);
113 }
114 bss->refcount--;
115 if (bss->refcount == 0)
116 bss_free(bss);
0532d4f1
JB
117}
118
1b8ec87a 119static bool __cfg80211_unlink_bss(struct cfg80211_registered_device *rdev,
e8e27c66
AK
120 struct cfg80211_internal_bss *bss)
121{
1b8ec87a 122 lockdep_assert_held(&rdev->bss_lock);
4b1af479 123
776b3580
JB
124 if (!list_empty(&bss->hidden_list)) {
125 /*
126 * don't remove the beacon entry if it has
127 * probe responses associated with it
128 */
129 if (!bss->pub.hidden_beacon_bss)
130 return false;
131 /*
132 * if it's a probe response entry break its
133 * link to the other entries in the group
134 */
135 list_del_init(&bss->hidden_list);
136 }
137
e8e27c66 138 list_del_init(&bss->list);
1b8ec87a
ZG
139 rb_erase(&bss->rbn, &rdev->bss_tree);
140 bss_ref_put(rdev, bss);
776b3580 141 return true;
e8e27c66
AK
142}
143
1b8ec87a 144static void __cfg80211_bss_expire(struct cfg80211_registered_device *rdev,
15d6030b
SL
145 unsigned long expire_time)
146{
147 struct cfg80211_internal_bss *bss, *tmp;
148 bool expired = false;
149
1b8ec87a 150 lockdep_assert_held(&rdev->bss_lock);
4b1af479 151
1b8ec87a 152 list_for_each_entry_safe(bss, tmp, &rdev->bss_list, list) {
15d6030b
SL
153 if (atomic_read(&bss->hold))
154 continue;
155 if (!time_after(expire_time, bss->ts))
156 continue;
157
1b8ec87a 158 if (__cfg80211_unlink_bss(rdev, bss))
776b3580 159 expired = true;
15d6030b
SL
160 }
161
162 if (expired)
1b8ec87a 163 rdev->bss_generation++;
15d6030b
SL
164}
165
f9d15d16
JB
166void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
167 bool send_message)
2a519311 168{
667503dd 169 struct cfg80211_scan_request *request;
fd014284 170 struct wireless_dev *wdev;
f9d15d16 171 struct sk_buff *msg;
3d23e349 172#ifdef CONFIG_CFG80211_WEXT
2a519311
JB
173 union iwreq_data wrqu;
174#endif
175
5fe231e8 176 ASSERT_RTNL();
01a0ac41 177
f9d15d16
JB
178 if (rdev->scan_msg) {
179 nl80211_send_scan_result(rdev, rdev->scan_msg);
180 rdev->scan_msg = NULL;
181 return;
182 }
667503dd 183
f9d15d16 184 request = rdev->scan_req;
01a0ac41
JB
185 if (!request)
186 return;
187
fd014284 188 wdev = request->wdev;
2a519311 189
6829c878
JB
190 /*
191 * This must be before sending the other events!
192 * Otherwise, wpa_supplicant gets completely confused with
193 * wext events.
194 */
fd014284
JB
195 if (wdev->netdev)
196 cfg80211_sme_scan_done(wdev->netdev);
6829c878 197
1d76250b 198 if (!request->info.aborted &&
f9d15d16
JB
199 request->flags & NL80211_SCAN_FLAG_FLUSH) {
200 /* flush entries from previous scans */
201 spin_lock_bh(&rdev->bss_lock);
202 __cfg80211_bss_expire(rdev, request->scan_start);
203 spin_unlock_bh(&rdev->bss_lock);
15d6030b 204 }
2a519311 205
1d76250b 206 msg = nl80211_build_scan_msg(rdev, wdev, request->info.aborted);
f9d15d16 207
3d23e349 208#ifdef CONFIG_CFG80211_WEXT
1d76250b 209 if (wdev->netdev && !request->info.aborted) {
2a519311
JB
210 memset(&wrqu, 0, sizeof(wrqu));
211
fd014284 212 wireless_send_event(wdev->netdev, SIOCGIWSCAN, &wrqu, NULL);
2a519311
JB
213 }
214#endif
215
fd014284
JB
216 if (wdev->netdev)
217 dev_put(wdev->netdev);
2a519311 218
36e6fea8 219 rdev->scan_req = NULL;
4a58e7c3 220 kfree(request);
f9d15d16
JB
221
222 if (!send_message)
223 rdev->scan_msg = msg;
224 else
225 nl80211_send_scan_result(rdev, msg);
2a519311 226}
667503dd 227
36e6fea8
JB
228void __cfg80211_scan_done(struct work_struct *wk)
229{
230 struct cfg80211_registered_device *rdev;
231
232 rdev = container_of(wk, struct cfg80211_registered_device,
233 scan_done_wk);
234
5fe231e8 235 rtnl_lock();
f9d15d16 236 ___cfg80211_scan_done(rdev, true);
5fe231e8 237 rtnl_unlock();
36e6fea8
JB
238}
239
1d76250b
AS
240void cfg80211_scan_done(struct cfg80211_scan_request *request,
241 struct cfg80211_scan_info *info)
667503dd 242{
1d76250b 243 trace_cfg80211_scan_done(request, info);
f26cbf40 244 WARN_ON(request != wiphy_to_rdev(request->wiphy)->scan_req);
667503dd 245
1d76250b 246 request->info = *info;
5fe231e8 247 request->notified = true;
f26cbf40 248 queue_work(cfg80211_wq, &wiphy_to_rdev(request->wiphy)->scan_done_wk);
667503dd 249}
2a519311
JB
250EXPORT_SYMBOL(cfg80211_scan_done);
251
807f8a8c
LC
252void __cfg80211_sched_scan_results(struct work_struct *wk)
253{
254 struct cfg80211_registered_device *rdev;
15d6030b 255 struct cfg80211_sched_scan_request *request;
807f8a8c
LC
256
257 rdev = container_of(wk, struct cfg80211_registered_device,
258 sched_scan_results_wk);
259
5fe231e8 260 rtnl_lock();
807f8a8c 261
31a60ed1 262 request = rtnl_dereference(rdev->sched_scan_req);
79845c66 263
807f8a8c 264 /* we don't have sched_scan_req anymore if the scan is stopping */
15d6030b
SL
265 if (request) {
266 if (request->flags & NL80211_SCAN_FLAG_FLUSH) {
267 /* flush entries from previous scans */
268 spin_lock_bh(&rdev->bss_lock);
269 __cfg80211_bss_expire(rdev, request->scan_start);
270 spin_unlock_bh(&rdev->bss_lock);
3b06d277 271 request->scan_start = jiffies;
15d6030b
SL
272 }
273 nl80211_send_sched_scan_results(rdev, request->dev);
274 }
807f8a8c 275
5fe231e8 276 rtnl_unlock();
807f8a8c
LC
277}
278
279void cfg80211_sched_scan_results(struct wiphy *wiphy)
280{
4ee3e063 281 trace_cfg80211_sched_scan_results(wiphy);
807f8a8c 282 /* ignore if we're not scanning */
31a60ed1
JR
283
284 if (rcu_access_pointer(wiphy_to_rdev(wiphy)->sched_scan_req))
807f8a8c 285 queue_work(cfg80211_wq,
f26cbf40 286 &wiphy_to_rdev(wiphy)->sched_scan_results_wk);
807f8a8c
LC
287}
288EXPORT_SYMBOL(cfg80211_sched_scan_results);
289
792e6aa7 290void cfg80211_sched_scan_stopped_rtnl(struct wiphy *wiphy)
807f8a8c 291{
f26cbf40 292 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
807f8a8c 293
792e6aa7
EP
294 ASSERT_RTNL();
295
4ee3e063
BL
296 trace_cfg80211_sched_scan_stopped(wiphy);
297
807f8a8c 298 __cfg80211_stop_sched_scan(rdev, true);
792e6aa7
EP
299}
300EXPORT_SYMBOL(cfg80211_sched_scan_stopped_rtnl);
301
302void cfg80211_sched_scan_stopped(struct wiphy *wiphy)
303{
304 rtnl_lock();
305 cfg80211_sched_scan_stopped_rtnl(wiphy);
5fe231e8 306 rtnl_unlock();
807f8a8c 307}
807f8a8c
LC
308EXPORT_SYMBOL(cfg80211_sched_scan_stopped);
309
310int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
311 bool driver_initiated)
312{
31a60ed1 313 struct cfg80211_sched_scan_request *sched_scan_req;
807f8a8c
LC
314 struct net_device *dev;
315
5fe231e8 316 ASSERT_RTNL();
807f8a8c
LC
317
318 if (!rdev->sched_scan_req)
1a84ff75 319 return -ENOENT;
807f8a8c 320
31a60ed1
JR
321 sched_scan_req = rtnl_dereference(rdev->sched_scan_req);
322 dev = sched_scan_req->dev;
807f8a8c 323
85a9994a 324 if (!driver_initiated) {
e35e4d28 325 int err = rdev_sched_scan_stop(rdev, dev);
85a9994a
LC
326 if (err)
327 return err;
328 }
807f8a8c
LC
329
330 nl80211_send_sched_scan(rdev, dev, NL80211_CMD_SCHED_SCAN_STOPPED);
331
31a60ed1
JR
332 RCU_INIT_POINTER(rdev->sched_scan_req, NULL);
333 kfree_rcu(sched_scan_req, rcu_head);
807f8a8c 334
3b4670ff 335 return 0;
807f8a8c
LC
336}
337
1b8ec87a 338void cfg80211_bss_age(struct cfg80211_registered_device *rdev,
cb3a8eec
DW
339 unsigned long age_secs)
340{
341 struct cfg80211_internal_bss *bss;
342 unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC);
343
1b8ec87a
ZG
344 spin_lock_bh(&rdev->bss_lock);
345 list_for_each_entry(bss, &rdev->bss_list, list)
cb3a8eec 346 bss->ts -= age_jiffies;
1b8ec87a 347 spin_unlock_bh(&rdev->bss_lock);
cb3a8eec
DW
348}
349
1b8ec87a 350void cfg80211_bss_expire(struct cfg80211_registered_device *rdev)
2a519311 351{
1b8ec87a 352 __cfg80211_bss_expire(rdev, jiffies - IEEE80211_SCAN_RESULT_EXPIRE);
2a519311
JB
353}
354
c21dbf92 355const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len)
2a519311 356{
c21dbf92 357 while (len > 2 && ies[0] != eid) {
2a519311
JB
358 len -= ies[1] + 2;
359 ies += ies[1] + 2;
360 }
361 if (len < 2)
362 return NULL;
363 if (len < 2 + ies[1])
364 return NULL;
365 return ies;
366}
c21dbf92 367EXPORT_SYMBOL(cfg80211_find_ie);
2a519311 368
9e9ea439 369const u8 *cfg80211_find_vendor_ie(unsigned int oui, int oui_type,
0c28ec58
EP
370 const u8 *ies, int len)
371{
372 struct ieee80211_vendor_ie *ie;
373 const u8 *pos = ies, *end = ies + len;
374 int ie_oui;
375
9e9ea439
EG
376 if (WARN_ON(oui_type > 0xff))
377 return NULL;
378
0c28ec58
EP
379 while (pos < end) {
380 pos = cfg80211_find_ie(WLAN_EID_VENDOR_SPECIFIC, pos,
381 end - pos);
382 if (!pos)
383 return NULL;
384
0c28ec58 385 ie = (struct ieee80211_vendor_ie *)pos;
6719429d
LC
386
387 /* make sure we can access ie->len */
388 BUILD_BUG_ON(offsetof(struct ieee80211_vendor_ie, len) != 1);
389
390 if (ie->len < sizeof(*ie))
391 goto cont;
392
0c28ec58 393 ie_oui = ie->oui[0] << 16 | ie->oui[1] << 8 | ie->oui[2];
9e9ea439
EG
394 if (ie_oui == oui &&
395 (oui_type < 0 || ie->oui_type == oui_type))
0c28ec58 396 return pos;
6719429d 397cont:
0c28ec58
EP
398 pos += 2 + ie->len;
399 }
400 return NULL;
401}
402EXPORT_SYMBOL(cfg80211_find_vendor_ie);
403
915de2ff 404static bool is_bss(struct cfg80211_bss *a, const u8 *bssid,
2a519311
JB
405 const u8 *ssid, size_t ssid_len)
406{
9caf0364 407 const struct cfg80211_bss_ies *ies;
2a519311
JB
408 const u8 *ssidie;
409
ac422d3c 410 if (bssid && !ether_addr_equal(a->bssid, bssid))
2a519311
JB
411 return false;
412
79420f09
JB
413 if (!ssid)
414 return true;
415
9caf0364
JB
416 ies = rcu_access_pointer(a->ies);
417 if (!ies)
418 return false;
419 ssidie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
2a519311
JB
420 if (!ssidie)
421 return false;
422 if (ssidie[1] != ssid_len)
423 return false;
424 return memcmp(ssidie + 2, ssid, ssid_len) == 0;
425}
426
4593c4cb
JB
427/**
428 * enum bss_compare_mode - BSS compare mode
429 * @BSS_CMP_REGULAR: regular compare mode (for insertion and normal find)
430 * @BSS_CMP_HIDE_ZLEN: find hidden SSID with zero-length mode
431 * @BSS_CMP_HIDE_NUL: find hidden SSID with NUL-ed out mode
432 */
433enum bss_compare_mode {
434 BSS_CMP_REGULAR,
435 BSS_CMP_HIDE_ZLEN,
436 BSS_CMP_HIDE_NUL,
437};
438
dd9dfb9f 439static int cmp_bss(struct cfg80211_bss *a,
5622f5bb 440 struct cfg80211_bss *b,
4593c4cb 441 enum bss_compare_mode mode)
dd9dfb9f 442{
9caf0364 443 const struct cfg80211_bss_ies *a_ies, *b_ies;
3af6341c
JB
444 const u8 *ie1 = NULL;
445 const u8 *ie2 = NULL;
5622f5bb 446 int i, r;
dd9dfb9f 447
3af6341c
JB
448 if (a->channel != b->channel)
449 return b->channel->center_freq - a->channel->center_freq;
dd9dfb9f 450
9caf0364
JB
451 a_ies = rcu_access_pointer(a->ies);
452 if (!a_ies)
453 return -1;
454 b_ies = rcu_access_pointer(b->ies);
455 if (!b_ies)
456 return 1;
457
3af6341c
JB
458 if (WLAN_CAPABILITY_IS_STA_BSS(a->capability))
459 ie1 = cfg80211_find_ie(WLAN_EID_MESH_ID,
460 a_ies->data, a_ies->len);
461 if (WLAN_CAPABILITY_IS_STA_BSS(b->capability))
462 ie2 = cfg80211_find_ie(WLAN_EID_MESH_ID,
463 b_ies->data, b_ies->len);
464 if (ie1 && ie2) {
465 int mesh_id_cmp;
466
467 if (ie1[1] == ie2[1])
468 mesh_id_cmp = memcmp(ie1 + 2, ie2 + 2, ie1[1]);
469 else
470 mesh_id_cmp = ie2[1] - ie1[1];
471
472 ie1 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
473 a_ies->data, a_ies->len);
474 ie2 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
475 b_ies->data, b_ies->len);
476 if (ie1 && ie2) {
477 if (mesh_id_cmp)
478 return mesh_id_cmp;
479 if (ie1[1] != ie2[1])
480 return ie2[1] - ie1[1];
481 return memcmp(ie1 + 2, ie2 + 2, ie1[1]);
482 }
483 }
484
3af6341c
JB
485 r = memcmp(a->bssid, b->bssid, sizeof(a->bssid));
486 if (r)
487 return r;
488
9caf0364
JB
489 ie1 = cfg80211_find_ie(WLAN_EID_SSID, a_ies->data, a_ies->len);
490 ie2 = cfg80211_find_ie(WLAN_EID_SSID, b_ies->data, b_ies->len);
dd9dfb9f 491
5622f5bb
JB
492 if (!ie1 && !ie2)
493 return 0;
494
f94f8b16 495 /*
5622f5bb
JB
496 * Note that with "hide_ssid", the function returns a match if
497 * the already-present BSS ("b") is a hidden SSID beacon for
498 * the new BSS ("a").
f94f8b16 499 */
dd9dfb9f
DT
500
501 /* sort missing IE before (left of) present IE */
502 if (!ie1)
503 return -1;
504 if (!ie2)
505 return 1;
506
4593c4cb
JB
507 switch (mode) {
508 case BSS_CMP_HIDE_ZLEN:
509 /*
510 * In ZLEN mode we assume the BSS entry we're
511 * looking for has a zero-length SSID. So if
512 * the one we're looking at right now has that,
513 * return 0. Otherwise, return the difference
514 * in length, but since we're looking for the
515 * 0-length it's really equivalent to returning
516 * the length of the one we're looking at.
517 *
518 * No content comparison is needed as we assume
519 * the content length is zero.
520 */
521 return ie2[1];
522 case BSS_CMP_REGULAR:
523 default:
524 /* sort by length first, then by contents */
525 if (ie1[1] != ie2[1])
526 return ie2[1] - ie1[1];
5622f5bb 527 return memcmp(ie1 + 2, ie2 + 2, ie1[1]);
4593c4cb
JB
528 case BSS_CMP_HIDE_NUL:
529 if (ie1[1] != ie2[1])
530 return ie2[1] - ie1[1];
531 /* this is equivalent to memcmp(zeroes, ie2 + 2, len) */
532 for (i = 0; i < ie2[1]; i++)
533 if (ie2[i + 2])
534 return -1;
535 return 0;
536 }
dd9dfb9f
DT
537}
538
6eb18137 539static bool cfg80211_bss_type_match(u16 capability,
57fbcce3 540 enum nl80211_band band,
6eb18137
DL
541 enum ieee80211_bss_type bss_type)
542{
543 bool ret = true;
544 u16 mask, val;
545
546 if (bss_type == IEEE80211_BSS_TYPE_ANY)
547 return ret;
548
57fbcce3 549 if (band == NL80211_BAND_60GHZ) {
6eb18137
DL
550 mask = WLAN_CAPABILITY_DMG_TYPE_MASK;
551 switch (bss_type) {
552 case IEEE80211_BSS_TYPE_ESS:
553 val = WLAN_CAPABILITY_DMG_TYPE_AP;
554 break;
555 case IEEE80211_BSS_TYPE_PBSS:
556 val = WLAN_CAPABILITY_DMG_TYPE_PBSS;
557 break;
558 case IEEE80211_BSS_TYPE_IBSS:
559 val = WLAN_CAPABILITY_DMG_TYPE_IBSS;
560 break;
561 default:
562 return false;
563 }
564 } else {
565 mask = WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS;
566 switch (bss_type) {
567 case IEEE80211_BSS_TYPE_ESS:
568 val = WLAN_CAPABILITY_ESS;
569 break;
570 case IEEE80211_BSS_TYPE_IBSS:
571 val = WLAN_CAPABILITY_IBSS;
572 break;
573 case IEEE80211_BSS_TYPE_MBSS:
574 val = 0;
575 break;
576 default:
577 return false;
578 }
579 }
580
581 ret = ((capability & mask) == val);
582 return ret;
583}
584
0e3a39b5 585/* Returned bss is reference counted and must be cleaned up appropriately. */
2a519311
JB
586struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy,
587 struct ieee80211_channel *channel,
588 const u8 *bssid,
79420f09 589 const u8 *ssid, size_t ssid_len,
6eb18137
DL
590 enum ieee80211_bss_type bss_type,
591 enum ieee80211_privacy privacy)
2a519311 592{
f26cbf40 593 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
2a519311 594 struct cfg80211_internal_bss *bss, *res = NULL;
ccb6c136 595 unsigned long now = jiffies;
6eb18137 596 int bss_privacy;
2a519311 597
6eb18137
DL
598 trace_cfg80211_get_bss(wiphy, channel, bssid, ssid, ssid_len, bss_type,
599 privacy);
4ee3e063 600
1b8ec87a 601 spin_lock_bh(&rdev->bss_lock);
2a519311 602
1b8ec87a 603 list_for_each_entry(bss, &rdev->bss_list, list) {
6eb18137
DL
604 if (!cfg80211_bss_type_match(bss->pub.capability,
605 bss->pub.channel->band, bss_type))
606 continue;
607
608 bss_privacy = (bss->pub.capability & WLAN_CAPABILITY_PRIVACY);
609 if ((privacy == IEEE80211_PRIVACY_ON && !bss_privacy) ||
610 (privacy == IEEE80211_PRIVACY_OFF && bss_privacy))
79420f09 611 continue;
2a519311
JB
612 if (channel && bss->pub.channel != channel)
613 continue;
c14a7400
JB
614 if (!is_valid_ether_addr(bss->pub.bssid))
615 continue;
ccb6c136
JB
616 /* Don't get expired BSS structs */
617 if (time_after(now, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE) &&
618 !atomic_read(&bss->hold))
619 continue;
2a519311
JB
620 if (is_bss(&bss->pub, bssid, ssid, ssid_len)) {
621 res = bss;
1b8ec87a 622 bss_ref_get(rdev, res);
2a519311
JB
623 break;
624 }
625 }
626
1b8ec87a 627 spin_unlock_bh(&rdev->bss_lock);
2a519311
JB
628 if (!res)
629 return NULL;
4ee3e063 630 trace_cfg80211_return_bss(&res->pub);
2a519311
JB
631 return &res->pub;
632}
633EXPORT_SYMBOL(cfg80211_get_bss);
634
1b8ec87a 635static void rb_insert_bss(struct cfg80211_registered_device *rdev,
2a519311
JB
636 struct cfg80211_internal_bss *bss)
637{
1b8ec87a 638 struct rb_node **p = &rdev->bss_tree.rb_node;
2a519311
JB
639 struct rb_node *parent = NULL;
640 struct cfg80211_internal_bss *tbss;
641 int cmp;
642
643 while (*p) {
644 parent = *p;
645 tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn);
646
4593c4cb 647 cmp = cmp_bss(&bss->pub, &tbss->pub, BSS_CMP_REGULAR);
2a519311
JB
648
649 if (WARN_ON(!cmp)) {
650 /* will sort of leak this BSS */
651 return;
652 }
653
654 if (cmp < 0)
655 p = &(*p)->rb_left;
656 else
657 p = &(*p)->rb_right;
658 }
659
660 rb_link_node(&bss->rbn, parent, p);
1b8ec87a 661 rb_insert_color(&bss->rbn, &rdev->bss_tree);
2a519311
JB
662}
663
664static struct cfg80211_internal_bss *
1b8ec87a 665rb_find_bss(struct cfg80211_registered_device *rdev,
5622f5bb 666 struct cfg80211_internal_bss *res,
4593c4cb 667 enum bss_compare_mode mode)
dd9dfb9f 668{
1b8ec87a 669 struct rb_node *n = rdev->bss_tree.rb_node;
dd9dfb9f
DT
670 struct cfg80211_internal_bss *bss;
671 int r;
672
673 while (n) {
674 bss = rb_entry(n, struct cfg80211_internal_bss, rbn);
4593c4cb 675 r = cmp_bss(&res->pub, &bss->pub, mode);
dd9dfb9f
DT
676
677 if (r == 0)
678 return bss;
679 else if (r < 0)
680 n = n->rb_left;
681 else
682 n = n->rb_right;
683 }
684
685 return NULL;
686}
687
1b8ec87a 688static bool cfg80211_combine_bsses(struct cfg80211_registered_device *rdev,
776b3580 689 struct cfg80211_internal_bss *new)
dd9dfb9f 690{
9caf0364 691 const struct cfg80211_bss_ies *ies;
776b3580
JB
692 struct cfg80211_internal_bss *bss;
693 const u8 *ie;
694 int i, ssidlen;
695 u8 fold = 0;
9caf0364 696
776b3580 697 ies = rcu_access_pointer(new->pub.beacon_ies);
9caf0364 698 if (WARN_ON(!ies))
776b3580 699 return false;
dd9dfb9f 700
776b3580
JB
701 ie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
702 if (!ie) {
703 /* nothing to do */
704 return true;
705 }
706
707 ssidlen = ie[1];
708 for (i = 0; i < ssidlen; i++)
709 fold |= ie[2 + i];
710
711 if (fold) {
712 /* not a hidden SSID */
713 return true;
714 }
715
716 /* This is the bad part ... */
717
1b8ec87a 718 list_for_each_entry(bss, &rdev->bss_list, list) {
776b3580
JB
719 if (!ether_addr_equal(bss->pub.bssid, new->pub.bssid))
720 continue;
721 if (bss->pub.channel != new->pub.channel)
722 continue;
dcd6eac1
SW
723 if (bss->pub.scan_width != new->pub.scan_width)
724 continue;
776b3580
JB
725 if (rcu_access_pointer(bss->pub.beacon_ies))
726 continue;
727 ies = rcu_access_pointer(bss->pub.ies);
728 if (!ies)
729 continue;
730 ie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
731 if (!ie)
732 continue;
733 if (ssidlen && ie[1] != ssidlen)
734 continue;
776b3580
JB
735 if (WARN_ON_ONCE(bss->pub.hidden_beacon_bss))
736 continue;
737 if (WARN_ON_ONCE(!list_empty(&bss->hidden_list)))
738 list_del(&bss->hidden_list);
739 /* combine them */
740 list_add(&bss->hidden_list, &new->hidden_list);
741 bss->pub.hidden_beacon_bss = &new->pub;
742 new->refcount += bss->refcount;
743 rcu_assign_pointer(bss->pub.beacon_ies,
744 new->pub.beacon_ies);
745 }
746
747 return true;
dd9dfb9f
DT
748}
749
0e3a39b5 750/* Returned bss is reference counted and must be cleaned up appropriately. */
2a519311 751static struct cfg80211_internal_bss *
1b8ec87a 752cfg80211_bss_update(struct cfg80211_registered_device *rdev,
3afc2167
EG
753 struct cfg80211_internal_bss *tmp,
754 bool signal_valid)
2a519311
JB
755{
756 struct cfg80211_internal_bss *found = NULL;
2a519311 757
9caf0364 758 if (WARN_ON(!tmp->pub.channel))
2a519311 759 return NULL;
2a519311 760
9caf0364 761 tmp->ts = jiffies;
2a519311 762
1b8ec87a 763 spin_lock_bh(&rdev->bss_lock);
2a519311 764
9caf0364 765 if (WARN_ON(!rcu_access_pointer(tmp->pub.ies))) {
1b8ec87a 766 spin_unlock_bh(&rdev->bss_lock);
9caf0364
JB
767 return NULL;
768 }
769
1b8ec87a 770 found = rb_find_bss(rdev, tmp, BSS_CMP_REGULAR);
2a519311 771
cd1658f5 772 if (found) {
34a6eddb 773 /* Update IEs */
9caf0364
JB
774 if (rcu_access_pointer(tmp->pub.proberesp_ies)) {
775 const struct cfg80211_bss_ies *old;
776
777 old = rcu_access_pointer(found->pub.proberesp_ies);
cd1658f5 778
9caf0364
JB
779 rcu_assign_pointer(found->pub.proberesp_ies,
780 tmp->pub.proberesp_ies);
34a6eddb 781 /* Override possible earlier Beacon frame IEs */
9caf0364
JB
782 rcu_assign_pointer(found->pub.ies,
783 tmp->pub.proberesp_ies);
784 if (old)
785 kfree_rcu((struct cfg80211_bss_ies *)old,
786 rcu_head);
787 } else if (rcu_access_pointer(tmp->pub.beacon_ies)) {
9537f227 788 const struct cfg80211_bss_ies *old;
776b3580
JB
789 struct cfg80211_internal_bss *bss;
790
791 if (found->pub.hidden_beacon_bss &&
792 !list_empty(&found->hidden_list)) {
1345ee6a
JB
793 const struct cfg80211_bss_ies *f;
794
776b3580
JB
795 /*
796 * The found BSS struct is one of the probe
797 * response members of a group, but we're
798 * receiving a beacon (beacon_ies in the tmp
799 * bss is used). This can only mean that the
800 * AP changed its beacon from not having an
801 * SSID to showing it, which is confusing so
802 * drop this information.
803 */
1345ee6a
JB
804
805 f = rcu_access_pointer(tmp->pub.beacon_ies);
806 kfree_rcu((struct cfg80211_bss_ies *)f,
807 rcu_head);
776b3580
JB
808 goto drop;
809 }
915de2ff 810
9caf0364 811 old = rcu_access_pointer(found->pub.beacon_ies);
9caf0364
JB
812
813 rcu_assign_pointer(found->pub.beacon_ies,
814 tmp->pub.beacon_ies);
01123e23
SN
815
816 /* Override IEs if they were from a beacon before */
9537f227 817 if (old == rcu_access_pointer(found->pub.ies))
9caf0364
JB
818 rcu_assign_pointer(found->pub.ies,
819 tmp->pub.beacon_ies);
cd1658f5 820
776b3580
JB
821 /* Assign beacon IEs to all sub entries */
822 list_for_each_entry(bss, &found->hidden_list,
823 hidden_list) {
824 const struct cfg80211_bss_ies *ies;
825
826 ies = rcu_access_pointer(bss->pub.beacon_ies);
827 WARN_ON(ies != old);
828
829 rcu_assign_pointer(bss->pub.beacon_ies,
830 tmp->pub.beacon_ies);
831 }
832
9caf0364
JB
833 if (old)
834 kfree_rcu((struct cfg80211_bss_ies *)old,
835 rcu_head);
836 }
1345ee6a
JB
837
838 found->pub.beacon_interval = tmp->pub.beacon_interval;
3afc2167
EG
839 /*
840 * don't update the signal if beacon was heard on
841 * adjacent channel.
842 */
843 if (signal_valid)
844 found->pub.signal = tmp->pub.signal;
1345ee6a
JB
845 found->pub.capability = tmp->pub.capability;
846 found->ts = tmp->ts;
6e19bc4b 847 found->ts_boottime = tmp->ts_boottime;
1d76250b
AS
848 found->parent_tsf = tmp->parent_tsf;
849 ether_addr_copy(found->parent_bssid, tmp->parent_bssid);
2a519311 850 } else {
9caf0364 851 struct cfg80211_internal_bss *new;
dd9dfb9f 852 struct cfg80211_internal_bss *hidden;
9caf0364 853 struct cfg80211_bss_ies *ies;
dd9dfb9f 854
9caf0364
JB
855 /*
856 * create a copy -- the "res" variable that is passed in
857 * is allocated on the stack since it's not needed in the
858 * more common case of an update
859 */
1b8ec87a 860 new = kzalloc(sizeof(*new) + rdev->wiphy.bss_priv_size,
9caf0364
JB
861 GFP_ATOMIC);
862 if (!new) {
863 ies = (void *)rcu_dereference(tmp->pub.beacon_ies);
864 if (ies)
865 kfree_rcu(ies, rcu_head);
866 ies = (void *)rcu_dereference(tmp->pub.proberesp_ies);
867 if (ies)
868 kfree_rcu(ies, rcu_head);
776b3580 869 goto drop;
9caf0364
JB
870 }
871 memcpy(new, tmp, sizeof(*new));
776b3580
JB
872 new->refcount = 1;
873 INIT_LIST_HEAD(&new->hidden_list);
874
875 if (rcu_access_pointer(tmp->pub.proberesp_ies)) {
1b8ec87a 876 hidden = rb_find_bss(rdev, tmp, BSS_CMP_HIDE_ZLEN);
776b3580 877 if (!hidden)
1b8ec87a 878 hidden = rb_find_bss(rdev, tmp,
776b3580
JB
879 BSS_CMP_HIDE_NUL);
880 if (hidden) {
881 new->pub.hidden_beacon_bss = &hidden->pub;
882 list_add(&new->hidden_list,
883 &hidden->hidden_list);
884 hidden->refcount++;
885 rcu_assign_pointer(new->pub.beacon_ies,
886 hidden->pub.beacon_ies);
887 }
888 } else {
889 /*
890 * Ok so we found a beacon, and don't have an entry. If
891 * it's a beacon with hidden SSID, we might be in for an
892 * expensive search for any probe responses that should
893 * be grouped with this beacon for updates ...
894 */
1b8ec87a 895 if (!cfg80211_combine_bsses(rdev, new)) {
776b3580
JB
896 kfree(new);
897 goto drop;
898 }
899 }
900
1b8ec87a
ZG
901 list_add_tail(&new->list, &rdev->bss_list);
902 rb_insert_bss(rdev, new);
9caf0364 903 found = new;
2a519311
JB
904 }
905
1b8ec87a
ZG
906 rdev->bss_generation++;
907 bss_ref_get(rdev, found);
908 spin_unlock_bh(&rdev->bss_lock);
2a519311 909
2a519311 910 return found;
776b3580 911 drop:
1b8ec87a 912 spin_unlock_bh(&rdev->bss_lock);
776b3580 913 return NULL;
2a519311
JB
914}
915
0172bb75
JB
916static struct ieee80211_channel *
917cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen,
918 struct ieee80211_channel *channel)
919{
920 const u8 *tmp;
921 u32 freq;
922 int channel_number = -1;
923
924 tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen);
925 if (tmp && tmp[1] == 1) {
926 channel_number = tmp[2];
927 } else {
928 tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen);
929 if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) {
930 struct ieee80211_ht_operation *htop = (void *)(tmp + 2);
931
932 channel_number = htop->primary_chan;
933 }
934 }
935
936 if (channel_number < 0)
937 return channel;
938
939 freq = ieee80211_channel_to_frequency(channel_number, channel->band);
940 channel = ieee80211_get_channel(wiphy, freq);
941 if (!channel)
942 return NULL;
943 if (channel->flags & IEEE80211_CHAN_DISABLED)
944 return NULL;
945 return channel;
946}
947
0e3a39b5 948/* Returned bss is reference counted and must be cleaned up appropriately. */
6e19bc4b
DS
949struct cfg80211_bss *
950cfg80211_inform_bss_data(struct wiphy *wiphy,
951 struct cfg80211_inform_bss *data,
952 enum cfg80211_bss_frame_type ftype,
953 const u8 *bssid, u64 tsf, u16 capability,
954 u16 beacon_interval, const u8 *ie, size_t ielen,
955 gfp_t gfp)
06aa7afa 956{
9caf0364 957 struct cfg80211_bss_ies *ies;
3afc2167 958 struct ieee80211_channel *channel;
9caf0364 959 struct cfg80211_internal_bss tmp = {}, *res;
6eb18137 960 int bss_type;
67af9811 961 bool signal_valid;
06aa7afa
JK
962
963 if (WARN_ON(!wiphy))
964 return NULL;
965
22fe88d3 966 if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC &&
6e19bc4b 967 (data->signal < 0 || data->signal > 100)))
06aa7afa
JK
968 return NULL;
969
6e19bc4b 970 channel = cfg80211_get_bss_channel(wiphy, ie, ielen, data->chan);
0172bb75
JB
971 if (!channel)
972 return NULL;
973
9caf0364
JB
974 memcpy(tmp.pub.bssid, bssid, ETH_ALEN);
975 tmp.pub.channel = channel;
6e19bc4b
DS
976 tmp.pub.scan_width = data->scan_width;
977 tmp.pub.signal = data->signal;
9caf0364
JB
978 tmp.pub.beacon_interval = beacon_interval;
979 tmp.pub.capability = capability;
6e19bc4b
DS
980 tmp.ts_boottime = data->boottime_ns;
981
34a6eddb 982 /*
5bc8c1f2 983 * If we do not know here whether the IEs are from a Beacon or Probe
34a6eddb
JM
984 * Response frame, we need to pick one of the options and only use it
985 * with the driver that does not provide the full Beacon/Probe Response
986 * frame. Use Beacon frame pointer to avoid indicating that this should
50521aa8 987 * override the IEs pointer should we have received an earlier
9caf0364 988 * indication of Probe Response data.
34a6eddb 989 */
0e227084 990 ies = kzalloc(sizeof(*ies) + ielen, gfp);
9caf0364
JB
991 if (!ies)
992 return NULL;
993 ies->len = ielen;
8cef2c9d 994 ies->tsf = tsf;
0e227084 995 ies->from_beacon = false;
9caf0364 996 memcpy(ies->data, ie, ielen);
06aa7afa 997
5bc8c1f2
JB
998 switch (ftype) {
999 case CFG80211_BSS_FTYPE_BEACON:
1000 ies->from_beacon = true;
1001 /* fall through to assign */
1002 case CFG80211_BSS_FTYPE_UNKNOWN:
1003 rcu_assign_pointer(tmp.pub.beacon_ies, ies);
1004 break;
1005 case CFG80211_BSS_FTYPE_PRESP:
1006 rcu_assign_pointer(tmp.pub.proberesp_ies, ies);
1007 break;
1008 }
9caf0364 1009 rcu_assign_pointer(tmp.pub.ies, ies);
06aa7afa 1010
6e19bc4b 1011 signal_valid = abs(data->chan->center_freq - channel->center_freq) <=
67af9811
EG
1012 wiphy->max_adj_channel_rssi_comp;
1013 res = cfg80211_bss_update(wiphy_to_rdev(wiphy), &tmp, signal_valid);
06aa7afa
JK
1014 if (!res)
1015 return NULL;
1016
57fbcce3 1017 if (channel->band == NL80211_BAND_60GHZ) {
6eb18137
DL
1018 bss_type = res->pub.capability & WLAN_CAPABILITY_DMG_TYPE_MASK;
1019 if (bss_type == WLAN_CAPABILITY_DMG_TYPE_AP ||
1020 bss_type == WLAN_CAPABILITY_DMG_TYPE_PBSS)
1021 regulatory_hint_found_beacon(wiphy, channel, gfp);
1022 } else {
1023 if (res->pub.capability & WLAN_CAPABILITY_ESS)
1024 regulatory_hint_found_beacon(wiphy, channel, gfp);
1025 }
06aa7afa 1026
4ee3e063 1027 trace_cfg80211_return_bss(&res->pub);
06aa7afa
JK
1028 /* cfg80211_bss_update gives us a referenced result */
1029 return &res->pub;
1030}
6e19bc4b 1031EXPORT_SYMBOL(cfg80211_inform_bss_data);
06aa7afa 1032
6e19bc4b 1033/* cfg80211_inform_bss_width_frame helper */
2a519311 1034struct cfg80211_bss *
6e19bc4b
DS
1035cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
1036 struct cfg80211_inform_bss *data,
1037 struct ieee80211_mgmt *mgmt, size_t len,
1038 gfp_t gfp)
1039
2a519311 1040{
9caf0364
JB
1041 struct cfg80211_internal_bss tmp = {}, *res;
1042 struct cfg80211_bss_ies *ies;
3afc2167 1043 struct ieee80211_channel *channel;
67af9811 1044 bool signal_valid;
2a519311
JB
1045 size_t ielen = len - offsetof(struct ieee80211_mgmt,
1046 u.probe_resp.variable);
6eb18137 1047 int bss_type;
bef9bacc 1048
0172bb75
JB
1049 BUILD_BUG_ON(offsetof(struct ieee80211_mgmt, u.probe_resp.variable) !=
1050 offsetof(struct ieee80211_mgmt, u.beacon.variable));
1051
6e19bc4b 1052 trace_cfg80211_inform_bss_frame(wiphy, data, mgmt, len);
4ee3e063 1053
bef9bacc
MK
1054 if (WARN_ON(!mgmt))
1055 return NULL;
1056
1057 if (WARN_ON(!wiphy))
1058 return NULL;
2a519311 1059
22fe88d3 1060 if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC &&
6e19bc4b 1061 (data->signal < 0 || data->signal > 100)))
2a519311
JB
1062 return NULL;
1063
bef9bacc 1064 if (WARN_ON(len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable)))
2a519311
JB
1065 return NULL;
1066
0172bb75 1067 channel = cfg80211_get_bss_channel(wiphy, mgmt->u.beacon.variable,
6e19bc4b 1068 ielen, data->chan);
0172bb75
JB
1069 if (!channel)
1070 return NULL;
1071
0e227084 1072 ies = kzalloc(sizeof(*ies) + ielen, gfp);
9caf0364 1073 if (!ies)
2a519311 1074 return NULL;
9caf0364 1075 ies->len = ielen;
8cef2c9d 1076 ies->tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
0e227084 1077 ies->from_beacon = ieee80211_is_beacon(mgmt->frame_control);
9caf0364 1078 memcpy(ies->data, mgmt->u.probe_resp.variable, ielen);
2a519311 1079
9caf0364
JB
1080 if (ieee80211_is_probe_resp(mgmt->frame_control))
1081 rcu_assign_pointer(tmp.pub.proberesp_ies, ies);
1082 else
1083 rcu_assign_pointer(tmp.pub.beacon_ies, ies);
1084 rcu_assign_pointer(tmp.pub.ies, ies);
1085
1086 memcpy(tmp.pub.bssid, mgmt->bssid, ETH_ALEN);
1087 tmp.pub.channel = channel;
6e19bc4b
DS
1088 tmp.pub.scan_width = data->scan_width;
1089 tmp.pub.signal = data->signal;
9caf0364
JB
1090 tmp.pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int);
1091 tmp.pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info);
6e19bc4b 1092 tmp.ts_boottime = data->boottime_ns;
1d76250b
AS
1093 tmp.parent_tsf = data->parent_tsf;
1094 ether_addr_copy(tmp.parent_bssid, data->parent_bssid);
9caf0364 1095
6e19bc4b 1096 signal_valid = abs(data->chan->center_freq - channel->center_freq) <=
67af9811
EG
1097 wiphy->max_adj_channel_rssi_comp;
1098 res = cfg80211_bss_update(wiphy_to_rdev(wiphy), &tmp, signal_valid);
2a519311
JB
1099 if (!res)
1100 return NULL;
1101
57fbcce3 1102 if (channel->band == NL80211_BAND_60GHZ) {
6eb18137
DL
1103 bss_type = res->pub.capability & WLAN_CAPABILITY_DMG_TYPE_MASK;
1104 if (bss_type == WLAN_CAPABILITY_DMG_TYPE_AP ||
1105 bss_type == WLAN_CAPABILITY_DMG_TYPE_PBSS)
1106 regulatory_hint_found_beacon(wiphy, channel, gfp);
1107 } else {
1108 if (res->pub.capability & WLAN_CAPABILITY_ESS)
1109 regulatory_hint_found_beacon(wiphy, channel, gfp);
1110 }
e38f8a7a 1111
4ee3e063 1112 trace_cfg80211_return_bss(&res->pub);
2a519311
JB
1113 /* cfg80211_bss_update gives us a referenced result */
1114 return &res->pub;
1115}
6e19bc4b 1116EXPORT_SYMBOL(cfg80211_inform_bss_frame_data);
2a519311 1117
5b112d3d 1118void cfg80211_ref_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
4c0c0b75 1119{
f26cbf40 1120 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
4c0c0b75
JB
1121 struct cfg80211_internal_bss *bss;
1122
1123 if (!pub)
1124 return;
1125
1126 bss = container_of(pub, struct cfg80211_internal_bss, pub);
776b3580 1127
1b8ec87a
ZG
1128 spin_lock_bh(&rdev->bss_lock);
1129 bss_ref_get(rdev, bss);
1130 spin_unlock_bh(&rdev->bss_lock);
4c0c0b75
JB
1131}
1132EXPORT_SYMBOL(cfg80211_ref_bss);
1133
5b112d3d 1134void cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
2a519311 1135{
f26cbf40 1136 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
2a519311
JB
1137 struct cfg80211_internal_bss *bss;
1138
1139 if (!pub)
1140 return;
1141
1142 bss = container_of(pub, struct cfg80211_internal_bss, pub);
776b3580 1143
1b8ec87a
ZG
1144 spin_lock_bh(&rdev->bss_lock);
1145 bss_ref_put(rdev, bss);
1146 spin_unlock_bh(&rdev->bss_lock);
2a519311
JB
1147}
1148EXPORT_SYMBOL(cfg80211_put_bss);
1149
d491af19
JB
1150void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
1151{
f26cbf40 1152 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
d491af19
JB
1153 struct cfg80211_internal_bss *bss;
1154
1155 if (WARN_ON(!pub))
1156 return;
1157
1158 bss = container_of(pub, struct cfg80211_internal_bss, pub);
1159
1b8ec87a 1160 spin_lock_bh(&rdev->bss_lock);
3207390a 1161 if (!list_empty(&bss->list)) {
1b8ec87a
ZG
1162 if (__cfg80211_unlink_bss(rdev, bss))
1163 rdev->bss_generation++;
3207390a 1164 }
1b8ec87a 1165 spin_unlock_bh(&rdev->bss_lock);
d491af19
JB
1166}
1167EXPORT_SYMBOL(cfg80211_unlink_bss);
1168
3d23e349 1169#ifdef CONFIG_CFG80211_WEXT
9f419f38
JB
1170static struct cfg80211_registered_device *
1171cfg80211_get_dev_from_ifindex(struct net *net, int ifindex)
1172{
5fe231e8 1173 struct cfg80211_registered_device *rdev;
9f419f38
JB
1174 struct net_device *dev;
1175
5fe231e8
JB
1176 ASSERT_RTNL();
1177
9f419f38
JB
1178 dev = dev_get_by_index(net, ifindex);
1179 if (!dev)
5fe231e8
JB
1180 return ERR_PTR(-ENODEV);
1181 if (dev->ieee80211_ptr)
f26cbf40 1182 rdev = wiphy_to_rdev(dev->ieee80211_ptr->wiphy);
5fe231e8 1183 else
9f419f38
JB
1184 rdev = ERR_PTR(-ENODEV);
1185 dev_put(dev);
9f419f38
JB
1186 return rdev;
1187}
1188
2a519311
JB
1189int cfg80211_wext_siwscan(struct net_device *dev,
1190 struct iw_request_info *info,
1191 union iwreq_data *wrqu, char *extra)
1192{
1193 struct cfg80211_registered_device *rdev;
1194 struct wiphy *wiphy;
1195 struct iw_scan_req *wreq = NULL;
65486c8b 1196 struct cfg80211_scan_request *creq = NULL;
2a519311 1197 int i, err, n_channels = 0;
57fbcce3 1198 enum nl80211_band band;
2a519311
JB
1199
1200 if (!netif_running(dev))
1201 return -ENETDOWN;
1202
b2e3abdc
HS
1203 if (wrqu->data.length == sizeof(struct iw_scan_req))
1204 wreq = (struct iw_scan_req *)extra;
1205
463d0183 1206 rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
2a519311
JB
1207
1208 if (IS_ERR(rdev))
1209 return PTR_ERR(rdev);
1210
f9d15d16 1211 if (rdev->scan_req || rdev->scan_msg) {
2a519311
JB
1212 err = -EBUSY;
1213 goto out;
1214 }
1215
1216 wiphy = &rdev->wiphy;
1217
b2e3abdc
HS
1218 /* Determine number of channels, needed to allocate creq */
1219 if (wreq && wreq->num_channels)
1220 n_channels = wreq->num_channels;
bdfbec2d
IP
1221 else
1222 n_channels = ieee80211_get_num_supported_channels(wiphy);
2a519311
JB
1223
1224 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
1225 n_channels * sizeof(void *),
1226 GFP_ATOMIC);
1227 if (!creq) {
1228 err = -ENOMEM;
1229 goto out;
1230 }
1231
1232 creq->wiphy = wiphy;
fd014284 1233 creq->wdev = dev->ieee80211_ptr;
5ba63533
JB
1234 /* SSIDs come after channels */
1235 creq->ssids = (void *)&creq->channels[n_channels];
2a519311
JB
1236 creq->n_channels = n_channels;
1237 creq->n_ssids = 1;
15d6030b 1238 creq->scan_start = jiffies;
2a519311 1239
b2e3abdc 1240 /* translate "Scan on frequencies" request */
2a519311 1241 i = 0;
57fbcce3 1242 for (band = 0; band < NUM_NL80211_BANDS; band++) {
2a519311 1243 int j;
584991dc 1244
2a519311
JB
1245 if (!wiphy->bands[band])
1246 continue;
584991dc 1247
2a519311 1248 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
584991dc
JB
1249 /* ignore disabled channels */
1250 if (wiphy->bands[band]->channels[j].flags &
1251 IEEE80211_CHAN_DISABLED)
1252 continue;
b2e3abdc
HS
1253
1254 /* If we have a wireless request structure and the
1255 * wireless request specifies frequencies, then search
1256 * for the matching hardware channel.
1257 */
1258 if (wreq && wreq->num_channels) {
1259 int k;
1260 int wiphy_freq = wiphy->bands[band]->channels[j].center_freq;
1261 for (k = 0; k < wreq->num_channels; k++) {
96998e3a
ZG
1262 struct iw_freq *freq =
1263 &wreq->channel_list[k];
1264 int wext_freq =
1265 cfg80211_wext_freq(freq);
1266
b2e3abdc
HS
1267 if (wext_freq == wiphy_freq)
1268 goto wext_freq_found;
1269 }
1270 goto wext_freq_not_found;
1271 }
1272
1273 wext_freq_found:
2a519311
JB
1274 creq->channels[i] = &wiphy->bands[band]->channels[j];
1275 i++;
b2e3abdc 1276 wext_freq_not_found: ;
2a519311
JB
1277 }
1278 }
8862dc5f
HS
1279 /* No channels found? */
1280 if (!i) {
1281 err = -EINVAL;
1282 goto out;
1283 }
2a519311 1284
b2e3abdc
HS
1285 /* Set real number of channels specified in creq->channels[] */
1286 creq->n_channels = i;
2a519311 1287
b2e3abdc
HS
1288 /* translate "Scan for SSID" request */
1289 if (wreq) {
2a519311 1290 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
65486c8b
JB
1291 if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) {
1292 err = -EINVAL;
1293 goto out;
1294 }
2a519311
JB
1295 memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len);
1296 creq->ssids[0].ssid_len = wreq->essid_len;
1297 }
1298 if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE)
1299 creq->n_ssids = 0;
1300 }
1301
57fbcce3 1302 for (i = 0; i < NUM_NL80211_BANDS; i++)
a401d2bb
JB
1303 if (wiphy->bands[i])
1304 creq->rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1;
34850ab2 1305
818965d3
JM
1306 eth_broadcast_addr(creq->bssid);
1307
2a519311 1308 rdev->scan_req = creq;
e35e4d28 1309 err = rdev_scan(rdev, creq);
2a519311
JB
1310 if (err) {
1311 rdev->scan_req = NULL;
65486c8b 1312 /* creq will be freed below */
463d0183 1313 } else {
fd014284 1314 nl80211_send_scan_start(rdev, dev->ieee80211_ptr);
65486c8b
JB
1315 /* creq now owned by driver */
1316 creq = NULL;
463d0183
JB
1317 dev_hold(dev);
1318 }
2a519311 1319 out:
65486c8b 1320 kfree(creq);
2a519311
JB
1321 return err;
1322}
2afe38d1 1323EXPORT_WEXT_HANDLER(cfg80211_wext_siwscan);
2a519311 1324
76a70e9c
JM
1325static char *ieee80211_scan_add_ies(struct iw_request_info *info,
1326 const struct cfg80211_bss_ies *ies,
1327 char *current_ev, char *end_buf)
2a519311 1328{
9caf0364 1329 const u8 *pos, *end, *next;
2a519311
JB
1330 struct iw_event iwe;
1331
9caf0364 1332 if (!ies)
76a70e9c 1333 return current_ev;
2a519311
JB
1334
1335 /*
1336 * If needed, fragment the IEs buffer (at IE boundaries) into short
1337 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
1338 */
9caf0364
JB
1339 pos = ies->data;
1340 end = pos + ies->len;
2a519311
JB
1341
1342 while (end - pos > IW_GENERIC_IE_MAX) {
1343 next = pos + 2 + pos[1];
1344 while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX)
1345 next = next + 2 + next[1];
1346
1347 memset(&iwe, 0, sizeof(iwe));
1348 iwe.cmd = IWEVGENIE;
1349 iwe.u.data.length = next - pos;
76a70e9c
JM
1350 current_ev = iwe_stream_add_point_check(info, current_ev,
1351 end_buf, &iwe,
1352 (void *)pos);
1353 if (IS_ERR(current_ev))
1354 return current_ev;
2a519311
JB
1355 pos = next;
1356 }
1357
1358 if (end > pos) {
1359 memset(&iwe, 0, sizeof(iwe));
1360 iwe.cmd = IWEVGENIE;
1361 iwe.u.data.length = end - pos;
76a70e9c
JM
1362 current_ev = iwe_stream_add_point_check(info, current_ev,
1363 end_buf, &iwe,
1364 (void *)pos);
1365 if (IS_ERR(current_ev))
1366 return current_ev;
2a519311 1367 }
76a70e9c
JM
1368
1369 return current_ev;
2a519311
JB
1370}
1371
2a519311 1372static char *
77965c97
JB
1373ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
1374 struct cfg80211_internal_bss *bss, char *current_ev,
1375 char *end_buf)
2a519311 1376{
9caf0364 1377 const struct cfg80211_bss_ies *ies;
2a519311 1378 struct iw_event iwe;
9caf0364 1379 const u8 *ie;
76a70e9c
JM
1380 u8 buf[50];
1381 u8 *cfg, *p, *tmp;
9caf0364 1382 int rem, i, sig;
2a519311
JB
1383 bool ismesh = false;
1384
1385 memset(&iwe, 0, sizeof(iwe));
1386 iwe.cmd = SIOCGIWAP;
1387 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1388 memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN);
76a70e9c
JM
1389 current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe,
1390 IW_EV_ADDR_LEN);
1391 if (IS_ERR(current_ev))
1392 return current_ev;
2a519311
JB
1393
1394 memset(&iwe, 0, sizeof(iwe));
1395 iwe.cmd = SIOCGIWFREQ;
1396 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq);
1397 iwe.u.freq.e = 0;
76a70e9c
JM
1398 current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe,
1399 IW_EV_FREQ_LEN);
1400 if (IS_ERR(current_ev))
1401 return current_ev;
2a519311
JB
1402
1403 memset(&iwe, 0, sizeof(iwe));
1404 iwe.cmd = SIOCGIWFREQ;
1405 iwe.u.freq.m = bss->pub.channel->center_freq;
1406 iwe.u.freq.e = 6;
76a70e9c
JM
1407 current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe,
1408 IW_EV_FREQ_LEN);
1409 if (IS_ERR(current_ev))
1410 return current_ev;
2a519311 1411
77965c97 1412 if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) {
2a519311
JB
1413 memset(&iwe, 0, sizeof(iwe));
1414 iwe.cmd = IWEVQUAL;
1415 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED |
1416 IW_QUAL_NOISE_INVALID |
a77b8552 1417 IW_QUAL_QUAL_UPDATED;
77965c97 1418 switch (wiphy->signal_type) {
2a519311 1419 case CFG80211_SIGNAL_TYPE_MBM:
a77b8552
JB
1420 sig = bss->pub.signal / 100;
1421 iwe.u.qual.level = sig;
2a519311 1422 iwe.u.qual.updated |= IW_QUAL_DBM;
a77b8552
JB
1423 if (sig < -110) /* rather bad */
1424 sig = -110;
1425 else if (sig > -40) /* perfect */
1426 sig = -40;
1427 /* will give a range of 0 .. 70 */
1428 iwe.u.qual.qual = sig + 110;
2a519311
JB
1429 break;
1430 case CFG80211_SIGNAL_TYPE_UNSPEC:
1431 iwe.u.qual.level = bss->pub.signal;
a77b8552
JB
1432 /* will give range 0 .. 100 */
1433 iwe.u.qual.qual = bss->pub.signal;
2a519311
JB
1434 break;
1435 default:
1436 /* not reached */
1437 break;
1438 }
76a70e9c
JM
1439 current_ev = iwe_stream_add_event_check(info, current_ev,
1440 end_buf, &iwe,
1441 IW_EV_QUAL_LEN);
1442 if (IS_ERR(current_ev))
1443 return current_ev;
2a519311
JB
1444 }
1445
1446 memset(&iwe, 0, sizeof(iwe));
1447 iwe.cmd = SIOCGIWENCODE;
1448 if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY)
1449 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1450 else
1451 iwe.u.data.flags = IW_ENCODE_DISABLED;
1452 iwe.u.data.length = 0;
76a70e9c
JM
1453 current_ev = iwe_stream_add_point_check(info, current_ev, end_buf,
1454 &iwe, "");
1455 if (IS_ERR(current_ev))
1456 return current_ev;
2a519311 1457
9caf0364
JB
1458 rcu_read_lock();
1459 ies = rcu_dereference(bss->pub.ies);
83c7aa1a
JB
1460 rem = ies->len;
1461 ie = ies->data;
9caf0364 1462
83c7aa1a 1463 while (rem >= 2) {
2a519311
JB
1464 /* invalid data */
1465 if (ie[1] > rem - 2)
1466 break;
1467
1468 switch (ie[0]) {
1469 case WLAN_EID_SSID:
1470 memset(&iwe, 0, sizeof(iwe));
1471 iwe.cmd = SIOCGIWESSID;
1472 iwe.u.data.length = ie[1];
1473 iwe.u.data.flags = 1;
76a70e9c
JM
1474 current_ev = iwe_stream_add_point_check(info,
1475 current_ev,
1476 end_buf, &iwe,
1477 (u8 *)ie + 2);
1478 if (IS_ERR(current_ev))
1479 goto unlock;
2a519311
JB
1480 break;
1481 case WLAN_EID_MESH_ID:
1482 memset(&iwe, 0, sizeof(iwe));
1483 iwe.cmd = SIOCGIWESSID;
1484 iwe.u.data.length = ie[1];
1485 iwe.u.data.flags = 1;
76a70e9c
JM
1486 current_ev = iwe_stream_add_point_check(info,
1487 current_ev,
1488 end_buf, &iwe,
1489 (u8 *)ie + 2);
1490 if (IS_ERR(current_ev))
1491 goto unlock;
2a519311
JB
1492 break;
1493 case WLAN_EID_MESH_CONFIG:
1494 ismesh = true;
136cfa28 1495 if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
2a519311 1496 break;
9caf0364 1497 cfg = (u8 *)ie + 2;
2a519311
JB
1498 memset(&iwe, 0, sizeof(iwe));
1499 iwe.cmd = IWEVCUSTOM;
76aa5e70
RP
1500 sprintf(buf, "Mesh Network Path Selection Protocol ID: "
1501 "0x%02X", cfg[0]);
2a519311 1502 iwe.u.data.length = strlen(buf);
76a70e9c
JM
1503 current_ev = iwe_stream_add_point_check(info,
1504 current_ev,
1505 end_buf,
1506 &iwe, buf);
1507 if (IS_ERR(current_ev))
1508 goto unlock;
76aa5e70
RP
1509 sprintf(buf, "Path Selection Metric ID: 0x%02X",
1510 cfg[1]);
2a519311 1511 iwe.u.data.length = strlen(buf);
76a70e9c
JM
1512 current_ev = iwe_stream_add_point_check(info,
1513 current_ev,
1514 end_buf,
1515 &iwe, buf);
1516 if (IS_ERR(current_ev))
1517 goto unlock;
76aa5e70
RP
1518 sprintf(buf, "Congestion Control Mode ID: 0x%02X",
1519 cfg[2]);
2a519311 1520 iwe.u.data.length = strlen(buf);
76a70e9c
JM
1521 current_ev = iwe_stream_add_point_check(info,
1522 current_ev,
1523 end_buf,
1524 &iwe, buf);
1525 if (IS_ERR(current_ev))
1526 goto unlock;
76aa5e70 1527 sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]);
2a519311 1528 iwe.u.data.length = strlen(buf);
76a70e9c
JM
1529 current_ev = iwe_stream_add_point_check(info,
1530 current_ev,
1531 end_buf,
1532 &iwe, buf);
1533 if (IS_ERR(current_ev))
1534 goto unlock;
76aa5e70
RP
1535 sprintf(buf, "Authentication ID: 0x%02X", cfg[4]);
1536 iwe.u.data.length = strlen(buf);
76a70e9c
JM
1537 current_ev = iwe_stream_add_point_check(info,
1538 current_ev,
1539 end_buf,
1540 &iwe, buf);
1541 if (IS_ERR(current_ev))
1542 goto unlock;
76aa5e70
RP
1543 sprintf(buf, "Formation Info: 0x%02X", cfg[5]);
1544 iwe.u.data.length = strlen(buf);
76a70e9c
JM
1545 current_ev = iwe_stream_add_point_check(info,
1546 current_ev,
1547 end_buf,
1548 &iwe, buf);
1549 if (IS_ERR(current_ev))
1550 goto unlock;
76aa5e70 1551 sprintf(buf, "Capabilities: 0x%02X", cfg[6]);
2a519311 1552 iwe.u.data.length = strlen(buf);
76a70e9c
JM
1553 current_ev = iwe_stream_add_point_check(info,
1554 current_ev,
1555 end_buf,
1556 &iwe, buf);
1557 if (IS_ERR(current_ev))
1558 goto unlock;
2a519311
JB
1559 break;
1560 case WLAN_EID_SUPP_RATES:
1561 case WLAN_EID_EXT_SUPP_RATES:
1562 /* display all supported rates in readable format */
1563 p = current_ev + iwe_stream_lcp_len(info);
1564
1565 memset(&iwe, 0, sizeof(iwe));
1566 iwe.cmd = SIOCGIWRATE;
1567 /* Those two flags are ignored... */
1568 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1569
1570 for (i = 0; i < ie[1]; i++) {
1571 iwe.u.bitrate.value =
1572 ((ie[i + 2] & 0x7f) * 500000);
76a70e9c 1573 tmp = p;
2a519311 1574 p = iwe_stream_add_value(info, current_ev, p,
76a70e9c
JM
1575 end_buf, &iwe,
1576 IW_EV_PARAM_LEN);
1577 if (p == tmp) {
1578 current_ev = ERR_PTR(-E2BIG);
1579 goto unlock;
1580 }
2a519311
JB
1581 }
1582 current_ev = p;
1583 break;
1584 }
1585 rem -= ie[1] + 2;
1586 ie += ie[1] + 2;
1587 }
1588
f64f9e71
JP
1589 if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) ||
1590 ismesh) {
2a519311
JB
1591 memset(&iwe, 0, sizeof(iwe));
1592 iwe.cmd = SIOCGIWMODE;
1593 if (ismesh)
1594 iwe.u.mode = IW_MODE_MESH;
1595 else if (bss->pub.capability & WLAN_CAPABILITY_ESS)
1596 iwe.u.mode = IW_MODE_MASTER;
1597 else
1598 iwe.u.mode = IW_MODE_ADHOC;
76a70e9c
JM
1599 current_ev = iwe_stream_add_event_check(info, current_ev,
1600 end_buf, &iwe,
1601 IW_EV_UINT_LEN);
1602 if (IS_ERR(current_ev))
1603 goto unlock;
2a519311
JB
1604 }
1605
76a70e9c
JM
1606 memset(&iwe, 0, sizeof(iwe));
1607 iwe.cmd = IWEVCUSTOM;
1608 sprintf(buf, "tsf=%016llx", (unsigned long long)(ies->tsf));
1609 iwe.u.data.length = strlen(buf);
1610 current_ev = iwe_stream_add_point_check(info, current_ev, end_buf,
1611 &iwe, buf);
1612 if (IS_ERR(current_ev))
1613 goto unlock;
1614 memset(&iwe, 0, sizeof(iwe));
1615 iwe.cmd = IWEVCUSTOM;
1616 sprintf(buf, " Last beacon: %ums ago",
1617 elapsed_jiffies_msecs(bss->ts));
1618 iwe.u.data.length = strlen(buf);
1619 current_ev = iwe_stream_add_point_check(info, current_ev,
1620 end_buf, &iwe, buf);
1621 if (IS_ERR(current_ev))
1622 goto unlock;
1623
1624 current_ev = ieee80211_scan_add_ies(info, ies, current_ev, end_buf);
1625
1626 unlock:
9caf0364 1627 rcu_read_unlock();
2a519311
JB
1628 return current_ev;
1629}
1630
1631
1b8ec87a 1632static int ieee80211_scan_results(struct cfg80211_registered_device *rdev,
2a519311
JB
1633 struct iw_request_info *info,
1634 char *buf, size_t len)
1635{
1636 char *current_ev = buf;
1637 char *end_buf = buf + len;
1638 struct cfg80211_internal_bss *bss;
76a70e9c 1639 int err = 0;
2a519311 1640
1b8ec87a
ZG
1641 spin_lock_bh(&rdev->bss_lock);
1642 cfg80211_bss_expire(rdev);
2a519311 1643
1b8ec87a 1644 list_for_each_entry(bss, &rdev->bss_list, list) {
2a519311 1645 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
76a70e9c
JM
1646 err = -E2BIG;
1647 break;
2a519311 1648 }
1b8ec87a 1649 current_ev = ieee80211_bss(&rdev->wiphy, info, bss,
77965c97 1650 current_ev, end_buf);
76a70e9c
JM
1651 if (IS_ERR(current_ev)) {
1652 err = PTR_ERR(current_ev);
1653 break;
1654 }
2a519311 1655 }
1b8ec87a 1656 spin_unlock_bh(&rdev->bss_lock);
76a70e9c
JM
1657
1658 if (err)
1659 return err;
2a519311
JB
1660 return current_ev - buf;
1661}
1662
1663
1664int cfg80211_wext_giwscan(struct net_device *dev,
1665 struct iw_request_info *info,
1666 struct iw_point *data, char *extra)
1667{
1668 struct cfg80211_registered_device *rdev;
1669 int res;
1670
1671 if (!netif_running(dev))
1672 return -ENETDOWN;
1673
463d0183 1674 rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
2a519311
JB
1675
1676 if (IS_ERR(rdev))
1677 return PTR_ERR(rdev);
1678
f9d15d16 1679 if (rdev->scan_req || rdev->scan_msg)
5fe231e8 1680 return -EAGAIN;
2a519311
JB
1681
1682 res = ieee80211_scan_results(rdev, info, extra, data->length);
1683 data->length = 0;
1684 if (res >= 0) {
1685 data->length = res;
1686 res = 0;
1687 }
1688
2a519311
JB
1689 return res;
1690}
2afe38d1 1691EXPORT_WEXT_HANDLER(cfg80211_wext_giwscan);
2a519311 1692#endif
This page took 0.496624 seconds and 5 git commands to generate.