2 * cfg80211 scan result handling
4 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 #include <linux/kernel.h>
8 #include <linux/slab.h>
9 #include <linux/module.h>
10 #include <linux/netdevice.h>
11 #include <linux/wireless.h>
12 #include <linux/nl80211.h>
13 #include <linux/etherdevice.h>
15 #include <net/cfg80211.h>
16 #include <net/cfg80211-wext.h>
17 #include <net/iw_handler.h>
20 #include "wext-compat.h"
24 * DOC: BSS tree/list structure
26 * At the top level, the BSS list is kept in both a list in each
27 * registered device (@bss_list) as well as an RB-tree for faster
28 * lookup. In the RB-tree, entries can be looked up using their
29 * channel, MESHID, MESHCONF (for MBSSes) or channel, BSSID, SSID
32 * Due to the possibility of hidden SSIDs, there's a second level
33 * structure, the "hidden_list" and "hidden_beacon_bss" pointer.
34 * The hidden_list connects all BSSes belonging to a single AP
35 * that has a hidden SSID, and connects beacon and probe response
36 * entries. For a probe response entry for a hidden SSID, the
37 * hidden_beacon_bss pointer points to the BSS struct holding the
38 * beacon's information.
40 * Reference counting is done for all these references except for
41 * the hidden_list, so that a beacon BSS struct that is otherwise
42 * not referenced has one reference for being on the bss_list and
43 * one for each probe response entry that points to it using the
44 * hidden_beacon_bss pointer. When a BSS struct that has such a
45 * pointer is get/put, the refcount update is also propagated to
46 * the referenced struct, this ensure that it cannot get removed
47 * while somebody is using the probe response version.
49 * Note that the hidden_beacon_bss pointer never changes, due to
50 * the reference counting. Therefore, no locking is needed for
53 * Also note that the hidden_beacon_bss pointer is only relevant
54 * if the driver uses something other than the IEs, e.g. private
55 * data stored stored in the BSS struct, since the beacon IEs are
56 * also linked into the probe response struct.
60 * Limit the number of BSS entries stored in mac80211. Each one is
61 * a bit over 4k at most, so this limits to roughly 4-5M of memory.
62 * If somebody wants to really attack this though, they'd likely
63 * use small beacons, and only one type of frame, limiting each of
64 * the entries to a much smaller size (in order to generate more
65 * entries in total, so overhead is bigger.)
67 static int bss_entries_limit
= 1000;
68 module_param(bss_entries_limit
, int, 0644);
69 MODULE_PARM_DESC(bss_entries_limit
,
70 "limit to number of scan BSS entries (per wiphy, default 1000)");
72 #define IEEE80211_SCAN_RESULT_EXPIRE (7 * HZ)
74 static void bss_free(struct cfg80211_internal_bss
*bss
)
76 struct cfg80211_bss_ies
*ies
;
78 if (WARN_ON(atomic_read(&bss
->hold
)))
81 ies
= (void *)rcu_access_pointer(bss
->pub
.beacon_ies
);
82 if (ies
&& !bss
->pub
.hidden_beacon_bss
)
83 kfree_rcu(ies
, rcu_head
);
84 ies
= (void *)rcu_access_pointer(bss
->pub
.proberesp_ies
);
86 kfree_rcu(ies
, rcu_head
);
89 * This happens when the module is removed, it doesn't
90 * really matter any more save for completeness
92 if (!list_empty(&bss
->hidden_list
))
93 list_del(&bss
->hidden_list
);
98 static inline void bss_ref_get(struct cfg80211_registered_device
*rdev
,
99 struct cfg80211_internal_bss
*bss
)
101 lockdep_assert_held(&rdev
->bss_lock
);
104 if (bss
->pub
.hidden_beacon_bss
) {
105 bss
= container_of(bss
->pub
.hidden_beacon_bss
,
106 struct cfg80211_internal_bss
,
112 static inline void bss_ref_put(struct cfg80211_registered_device
*rdev
,
113 struct cfg80211_internal_bss
*bss
)
115 lockdep_assert_held(&rdev
->bss_lock
);
117 if (bss
->pub
.hidden_beacon_bss
) {
118 struct cfg80211_internal_bss
*hbss
;
119 hbss
= container_of(bss
->pub
.hidden_beacon_bss
,
120 struct cfg80211_internal_bss
,
123 if (hbss
->refcount
== 0)
127 if (bss
->refcount
== 0)
131 static bool __cfg80211_unlink_bss(struct cfg80211_registered_device
*rdev
,
132 struct cfg80211_internal_bss
*bss
)
134 lockdep_assert_held(&rdev
->bss_lock
);
136 if (!list_empty(&bss
->hidden_list
)) {
138 * don't remove the beacon entry if it has
139 * probe responses associated with it
141 if (!bss
->pub
.hidden_beacon_bss
)
144 * if it's a probe response entry break its
145 * link to the other entries in the group
147 list_del_init(&bss
->hidden_list
);
150 list_del_init(&bss
->list
);
151 rb_erase(&bss
->rbn
, &rdev
->bss_tree
);
153 WARN_ONCE((rdev
->bss_entries
== 0) ^ list_empty(&rdev
->bss_list
),
154 "rdev bss entries[%d]/list[empty:%d] corruption\n",
155 rdev
->bss_entries
, list_empty(&rdev
->bss_list
));
156 bss_ref_put(rdev
, bss
);
160 static void __cfg80211_bss_expire(struct cfg80211_registered_device
*rdev
,
161 unsigned long expire_time
)
163 struct cfg80211_internal_bss
*bss
, *tmp
;
164 bool expired
= false;
166 lockdep_assert_held(&rdev
->bss_lock
);
168 list_for_each_entry_safe(bss
, tmp
, &rdev
->bss_list
, list
) {
169 if (atomic_read(&bss
->hold
))
171 if (!time_after(expire_time
, bss
->ts
))
174 if (__cfg80211_unlink_bss(rdev
, bss
))
179 rdev
->bss_generation
++;
182 static bool cfg80211_bss_expire_oldest(struct cfg80211_registered_device
*rdev
)
184 struct cfg80211_internal_bss
*bss
, *oldest
= NULL
;
187 lockdep_assert_held(&rdev
->bss_lock
);
189 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
190 if (atomic_read(&bss
->hold
))
193 if (!list_empty(&bss
->hidden_list
) &&
194 !bss
->pub
.hidden_beacon_bss
)
197 if (oldest
&& time_before(oldest
->ts
, bss
->ts
))
202 if (WARN_ON(!oldest
))
206 * The callers make sure to increase rdev->bss_generation if anything
207 * gets removed (and a new entry added), so there's no need to also do
211 ret
= __cfg80211_unlink_bss(rdev
, oldest
);
216 void ___cfg80211_scan_done(struct cfg80211_registered_device
*rdev
,
219 struct cfg80211_scan_request
*request
;
220 struct wireless_dev
*wdev
;
222 #ifdef CONFIG_CFG80211_WEXT
223 union iwreq_data wrqu
;
228 if (rdev
->scan_msg
) {
229 nl80211_send_scan_result(rdev
, rdev
->scan_msg
);
230 rdev
->scan_msg
= NULL
;
234 request
= rdev
->scan_req
;
238 wdev
= request
->wdev
;
241 * This must be before sending the other events!
242 * Otherwise, wpa_supplicant gets completely confused with
246 cfg80211_sme_scan_done(wdev
->netdev
);
248 if (!request
->aborted
&&
249 request
->flags
& NL80211_SCAN_FLAG_FLUSH
) {
250 /* flush entries from previous scans */
251 spin_lock_bh(&rdev
->bss_lock
);
252 __cfg80211_bss_expire(rdev
, request
->scan_start
);
253 spin_unlock_bh(&rdev
->bss_lock
);
256 msg
= nl80211_build_scan_msg(rdev
, wdev
, request
->aborted
);
258 #ifdef CONFIG_CFG80211_WEXT
259 if (wdev
->netdev
&& !request
->aborted
) {
260 memset(&wrqu
, 0, sizeof(wrqu
));
262 wireless_send_event(wdev
->netdev
, SIOCGIWSCAN
, &wrqu
, NULL
);
267 dev_put(wdev
->netdev
);
269 rdev
->scan_req
= NULL
;
273 rdev
->scan_msg
= msg
;
275 nl80211_send_scan_result(rdev
, msg
);
278 void __cfg80211_scan_done(struct work_struct
*wk
)
280 struct cfg80211_registered_device
*rdev
;
282 rdev
= container_of(wk
, struct cfg80211_registered_device
,
286 ___cfg80211_scan_done(rdev
, true);
290 void cfg80211_scan_done(struct cfg80211_scan_request
*request
, bool aborted
)
292 trace_cfg80211_scan_done(request
, aborted
);
293 WARN_ON(request
!= wiphy_to_rdev(request
->wiphy
)->scan_req
);
295 request
->aborted
= aborted
;
296 request
->notified
= true;
297 queue_work(cfg80211_wq
, &wiphy_to_rdev(request
->wiphy
)->scan_done_wk
);
299 EXPORT_SYMBOL(cfg80211_scan_done
);
301 void __cfg80211_sched_scan_results(struct work_struct
*wk
)
303 struct cfg80211_registered_device
*rdev
;
304 struct cfg80211_sched_scan_request
*request
;
306 rdev
= container_of(wk
, struct cfg80211_registered_device
,
307 sched_scan_results_wk
);
311 request
= rtnl_dereference(rdev
->sched_scan_req
);
313 /* we don't have sched_scan_req anymore if the scan is stopping */
315 if (request
->flags
& NL80211_SCAN_FLAG_FLUSH
) {
316 /* flush entries from previous scans */
317 spin_lock_bh(&rdev
->bss_lock
);
318 __cfg80211_bss_expire(rdev
, request
->scan_start
);
319 spin_unlock_bh(&rdev
->bss_lock
);
320 request
->scan_start
= jiffies
;
322 nl80211_send_sched_scan_results(rdev
, request
->dev
);
328 void cfg80211_sched_scan_results(struct wiphy
*wiphy
)
330 trace_cfg80211_sched_scan_results(wiphy
);
331 /* ignore if we're not scanning */
333 if (rcu_access_pointer(wiphy_to_rdev(wiphy
)->sched_scan_req
))
334 queue_work(cfg80211_wq
,
335 &wiphy_to_rdev(wiphy
)->sched_scan_results_wk
);
337 EXPORT_SYMBOL(cfg80211_sched_scan_results
);
339 void cfg80211_sched_scan_stopped_rtnl(struct wiphy
*wiphy
)
341 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
345 trace_cfg80211_sched_scan_stopped(wiphy
);
347 __cfg80211_stop_sched_scan(rdev
, true);
349 EXPORT_SYMBOL(cfg80211_sched_scan_stopped_rtnl
);
351 void cfg80211_sched_scan_stopped(struct wiphy
*wiphy
)
354 cfg80211_sched_scan_stopped_rtnl(wiphy
);
357 EXPORT_SYMBOL(cfg80211_sched_scan_stopped
);
359 int __cfg80211_stop_sched_scan(struct cfg80211_registered_device
*rdev
,
360 bool driver_initiated
)
362 struct cfg80211_sched_scan_request
*sched_scan_req
;
363 struct net_device
*dev
;
367 if (!rdev
->sched_scan_req
)
370 sched_scan_req
= rtnl_dereference(rdev
->sched_scan_req
);
371 dev
= sched_scan_req
->dev
;
373 if (!driver_initiated
) {
374 int err
= rdev_sched_scan_stop(rdev
, dev
);
379 nl80211_send_sched_scan(rdev
, dev
, NL80211_CMD_SCHED_SCAN_STOPPED
);
381 RCU_INIT_POINTER(rdev
->sched_scan_req
, NULL
);
382 kfree_rcu(sched_scan_req
, rcu_head
);
387 void cfg80211_bss_age(struct cfg80211_registered_device
*rdev
,
388 unsigned long age_secs
)
390 struct cfg80211_internal_bss
*bss
;
391 unsigned long age_jiffies
= msecs_to_jiffies(age_secs
* MSEC_PER_SEC
);
393 spin_lock_bh(&rdev
->bss_lock
);
394 list_for_each_entry(bss
, &rdev
->bss_list
, list
)
395 bss
->ts
-= age_jiffies
;
396 spin_unlock_bh(&rdev
->bss_lock
);
399 void cfg80211_bss_expire(struct cfg80211_registered_device
*rdev
)
401 __cfg80211_bss_expire(rdev
, jiffies
- IEEE80211_SCAN_RESULT_EXPIRE
);
404 const u8
*cfg80211_find_ie(u8 eid
, const u8
*ies
, int len
)
406 while (len
> 2 && ies
[0] != eid
) {
412 if (len
< 2 + ies
[1])
416 EXPORT_SYMBOL(cfg80211_find_ie
);
418 const u8
*cfg80211_find_vendor_ie(unsigned int oui
, u8 oui_type
,
419 const u8
*ies
, int len
)
421 struct ieee80211_vendor_ie
*ie
;
422 const u8
*pos
= ies
, *end
= ies
+ len
;
426 pos
= cfg80211_find_ie(WLAN_EID_VENDOR_SPECIFIC
, pos
,
431 ie
= (struct ieee80211_vendor_ie
*)pos
;
433 /* make sure we can access ie->len */
434 BUILD_BUG_ON(offsetof(struct ieee80211_vendor_ie
, len
) != 1);
436 if (ie
->len
< sizeof(*ie
))
439 ie_oui
= ie
->oui
[0] << 16 | ie
->oui
[1] << 8 | ie
->oui
[2];
440 if (ie_oui
== oui
&& ie
->oui_type
== oui_type
)
447 EXPORT_SYMBOL(cfg80211_find_vendor_ie
);
449 static bool is_bss(struct cfg80211_bss
*a
, const u8
*bssid
,
450 const u8
*ssid
, size_t ssid_len
)
452 const struct cfg80211_bss_ies
*ies
;
455 if (bssid
&& !ether_addr_equal(a
->bssid
, bssid
))
461 ies
= rcu_access_pointer(a
->ies
);
464 ssidie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
467 if (ssidie
[1] != ssid_len
)
469 return memcmp(ssidie
+ 2, ssid
, ssid_len
) == 0;
473 * enum bss_compare_mode - BSS compare mode
474 * @BSS_CMP_REGULAR: regular compare mode (for insertion and normal find)
475 * @BSS_CMP_HIDE_ZLEN: find hidden SSID with zero-length mode
476 * @BSS_CMP_HIDE_NUL: find hidden SSID with NUL-ed out mode
478 enum bss_compare_mode
{
484 static int cmp_bss(struct cfg80211_bss
*a
,
485 struct cfg80211_bss
*b
,
486 enum bss_compare_mode mode
)
488 const struct cfg80211_bss_ies
*a_ies
, *b_ies
;
489 const u8
*ie1
= NULL
;
490 const u8
*ie2
= NULL
;
492 #if !(defined(CONFIG_BCM4335) || defined(CONFIG_BCM4335_MODULE) \
493 || defined(CONFIG_BCM4339) || defined(CONFIG_BCM4339_MODULE) \
494 || defined(CONFIG_BCM43438) || defined(CONFIG_BCM43438_MODULE) \
495 || defined(CONFIG_BCM43454) || defined(CONFIG_BCM43454_MODULE) \
496 || defined(CONFIG_BCM43455) || defined(CONFIG_BCM43455_MODULE) \
497 || defined(CONFIG_BCM4354) || defined(CONFIG_BCM4354_MODULE) \
498 || defined(CONFIG_BCM4356) || defined(CONFIG_BCM4356_MODULE) \
499 || defined(CONFIG_BCM4358) || defined(CONFIG_BCM4358_MODULE)\
500 || defined(CONFIG_BCM4359) || defined(CONFIG_BCM4359_MODULE)\
501 || defined(CONFIG_BCM4361) || defined(CONFIG_BCM4361_MODULE))
502 if (a
->channel
!= b
->channel
)
503 return b
->channel
->center_freq
- a
->channel
->center_freq
;
504 #endif /* CONFIG_BCM43xx */
506 a_ies
= rcu_access_pointer(a
->ies
);
509 b_ies
= rcu_access_pointer(b
->ies
);
513 if (WLAN_CAPABILITY_IS_STA_BSS(a
->capability
))
514 ie1
= cfg80211_find_ie(WLAN_EID_MESH_ID
,
515 a_ies
->data
, a_ies
->len
);
516 if (WLAN_CAPABILITY_IS_STA_BSS(b
->capability
))
517 ie2
= cfg80211_find_ie(WLAN_EID_MESH_ID
,
518 b_ies
->data
, b_ies
->len
);
522 if (ie1
[1] == ie2
[1])
523 mesh_id_cmp
= memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
525 mesh_id_cmp
= ie2
[1] - ie1
[1];
527 ie1
= cfg80211_find_ie(WLAN_EID_MESH_CONFIG
,
528 a_ies
->data
, a_ies
->len
);
529 ie2
= cfg80211_find_ie(WLAN_EID_MESH_CONFIG
,
530 b_ies
->data
, b_ies
->len
);
534 if (ie1
[1] != ie2
[1])
535 return ie2
[1] - ie1
[1];
536 return memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
540 r
= memcmp(a
->bssid
, b
->bssid
, sizeof(a
->bssid
));
544 #if (defined(CONFIG_BCM4335) || defined(CONFIG_BCM4335_MODULE) \
545 || defined(CONFIG_BCM4339) || defined(CONFIG_BCM4339_MODULE) \
546 || defined(CONFIG_BCM43438) || defined(CONFIG_BCM43438_MODULE) \
547 || defined(CONFIG_BCM43454) || defined(CONFIG_BCM43454_MODULE) \
548 || defined(CONFIG_BCM43455) || defined(CONFIG_BCM43455_MODULE) \
549 || defined(CONFIG_BCM4354) || defined(CONFIG_BCM4354_MODULE) \
550 || defined(CONFIG_BCM4356) || defined(CONFIG_BCM4356_MODULE) \
551 || defined(CONFIG_BCM4358) || defined(CONFIG_BCM4358_MODULE)\
552 || defined(CONFIG_BCM4359) || defined(CONFIG_BCM4359_MODULE)\
553 || defined(CONFIG_BCM4361) || defined(CONFIG_BCM4361_MODULE))
554 if (a
->channel
!= b
->channel
)
555 return b
->channel
->center_freq
- a
->channel
->center_freq
;
556 #endif /* CONFIG_BCM43xx */
558 ie1
= cfg80211_find_ie(WLAN_EID_SSID
, a_ies
->data
, a_ies
->len
);
559 ie2
= cfg80211_find_ie(WLAN_EID_SSID
, b_ies
->data
, b_ies
->len
);
565 * Note that with "hide_ssid", the function returns a match if
566 * the already-present BSS ("b") is a hidden SSID beacon for
570 /* sort missing IE before (left of) present IE */
577 case BSS_CMP_HIDE_ZLEN
:
579 * In ZLEN mode we assume the BSS entry we're
580 * looking for has a zero-length SSID. So if
581 * the one we're looking at right now has that,
582 * return 0. Otherwise, return the difference
583 * in length, but since we're looking for the
584 * 0-length it's really equivalent to returning
585 * the length of the one we're looking at.
587 * No content comparison is needed as we assume
588 * the content length is zero.
591 case BSS_CMP_REGULAR
:
593 /* sort by length first, then by contents */
594 if (ie1
[1] != ie2
[1])
595 return ie2
[1] - ie1
[1];
596 return memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
597 case BSS_CMP_HIDE_NUL
:
598 if (ie1
[1] != ie2
[1])
599 return ie2
[1] - ie1
[1];
600 /* this is equivalent to memcmp(zeroes, ie2 + 2, len) */
601 for (i
= 0; i
< ie2
[1]; i
++)
608 static bool cfg80211_bss_type_match(u16 capability
,
609 enum nl80211_band band
,
610 enum ieee80211_bss_type bss_type
)
615 if (bss_type
== IEEE80211_BSS_TYPE_ANY
)
618 if (band
== NL80211_BAND_60GHZ
) {
619 mask
= WLAN_CAPABILITY_DMG_TYPE_MASK
;
621 case IEEE80211_BSS_TYPE_ESS
:
622 val
= WLAN_CAPABILITY_DMG_TYPE_AP
;
624 case IEEE80211_BSS_TYPE_PBSS
:
625 val
= WLAN_CAPABILITY_DMG_TYPE_PBSS
;
627 case IEEE80211_BSS_TYPE_IBSS
:
628 val
= WLAN_CAPABILITY_DMG_TYPE_IBSS
;
634 mask
= WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
;
636 case IEEE80211_BSS_TYPE_ESS
:
637 val
= WLAN_CAPABILITY_ESS
;
639 case IEEE80211_BSS_TYPE_IBSS
:
640 val
= WLAN_CAPABILITY_IBSS
;
642 case IEEE80211_BSS_TYPE_MBSS
:
650 ret
= ((capability
& mask
) == val
);
654 /* Returned bss is reference counted and must be cleaned up appropriately. */
655 struct cfg80211_bss
*cfg80211_get_bss(struct wiphy
*wiphy
,
656 struct ieee80211_channel
*channel
,
658 const u8
*ssid
, size_t ssid_len
,
659 enum ieee80211_bss_type bss_type
,
660 enum ieee80211_privacy privacy
)
662 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
663 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
664 unsigned long now
= jiffies
;
667 trace_cfg80211_get_bss(wiphy
, channel
, bssid
, ssid
, ssid_len
, bss_type
,
670 spin_lock_bh(&rdev
->bss_lock
);
672 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
673 if (!cfg80211_bss_type_match(bss
->pub
.capability
,
674 bss
->pub
.channel
->band
, bss_type
))
677 bss_privacy
= (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
);
678 if ((privacy
== IEEE80211_PRIVACY_ON
&& !bss_privacy
) ||
679 (privacy
== IEEE80211_PRIVACY_OFF
&& bss_privacy
))
681 if (channel
&& bss
->pub
.channel
!= channel
)
683 if (!is_valid_ether_addr(bss
->pub
.bssid
))
685 /* Don't get expired BSS structs */
686 if (time_after(now
, bss
->ts
+ IEEE80211_SCAN_RESULT_EXPIRE
) &&
687 !atomic_read(&bss
->hold
))
689 if (is_bss(&bss
->pub
, bssid
, ssid
, ssid_len
)) {
691 bss_ref_get(rdev
, res
);
696 spin_unlock_bh(&rdev
->bss_lock
);
699 trace_cfg80211_return_bss(&res
->pub
);
702 EXPORT_SYMBOL(cfg80211_get_bss
);
704 static void rb_insert_bss(struct cfg80211_registered_device
*rdev
,
705 struct cfg80211_internal_bss
*bss
)
707 struct rb_node
**p
= &rdev
->bss_tree
.rb_node
;
708 struct rb_node
*parent
= NULL
;
709 struct cfg80211_internal_bss
*tbss
;
714 tbss
= rb_entry(parent
, struct cfg80211_internal_bss
, rbn
);
716 cmp
= cmp_bss(&bss
->pub
, &tbss
->pub
, BSS_CMP_REGULAR
);
719 /* will sort of leak this BSS */
729 rb_link_node(&bss
->rbn
, parent
, p
);
730 rb_insert_color(&bss
->rbn
, &rdev
->bss_tree
);
733 static struct cfg80211_internal_bss
*
734 rb_find_bss(struct cfg80211_registered_device
*rdev
,
735 struct cfg80211_internal_bss
*res
,
736 enum bss_compare_mode mode
)
738 struct rb_node
*n
= rdev
->bss_tree
.rb_node
;
739 struct cfg80211_internal_bss
*bss
;
743 bss
= rb_entry(n
, struct cfg80211_internal_bss
, rbn
);
744 r
= cmp_bss(&res
->pub
, &bss
->pub
, mode
);
757 static bool cfg80211_combine_bsses(struct cfg80211_registered_device
*rdev
,
758 struct cfg80211_internal_bss
*new)
760 const struct cfg80211_bss_ies
*ies
;
761 struct cfg80211_internal_bss
*bss
;
767 ies
= rcu_access_pointer(new->pub
.beacon_ies
);
771 ie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
778 for (i
= 0; i
< ssidlen
; i
++)
782 /* not a hidden SSID */
786 /* This is the bad part ... */
788 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
790 * we're iterating all the entries anyway, so take the
791 * opportunity to validate the list length accounting
795 if (!ether_addr_equal(bss
->pub
.bssid
, new->pub
.bssid
))
797 if (bss
->pub
.channel
!= new->pub
.channel
)
799 if (bss
->pub
.scan_width
!= new->pub
.scan_width
)
801 if (rcu_access_pointer(bss
->pub
.beacon_ies
))
803 ies
= rcu_access_pointer(bss
->pub
.ies
);
806 ie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
809 if (ssidlen
&& ie
[1] != ssidlen
)
811 if (WARN_ON_ONCE(bss
->pub
.hidden_beacon_bss
))
813 if (WARN_ON_ONCE(!list_empty(&bss
->hidden_list
)))
814 list_del(&bss
->hidden_list
);
816 list_add(&bss
->hidden_list
, &new->hidden_list
);
817 bss
->pub
.hidden_beacon_bss
= &new->pub
;
818 new->refcount
+= bss
->refcount
;
819 rcu_assign_pointer(bss
->pub
.beacon_ies
,
820 new->pub
.beacon_ies
);
823 WARN_ONCE(n_entries
!= rdev
->bss_entries
,
824 "rdev bss entries[%d]/list[len:%d] corruption\n",
825 rdev
->bss_entries
, n_entries
);
830 /* Returned bss is reference counted and must be cleaned up appropriately. */
831 static struct cfg80211_internal_bss
*
832 cfg80211_bss_update(struct cfg80211_registered_device
*rdev
,
833 struct cfg80211_internal_bss
*tmp
,
836 struct cfg80211_internal_bss
*found
= NULL
;
838 if (WARN_ON(!tmp
->pub
.channel
))
843 spin_lock_bh(&rdev
->bss_lock
);
845 if (WARN_ON(!rcu_access_pointer(tmp
->pub
.ies
))) {
846 spin_unlock_bh(&rdev
->bss_lock
);
850 found
= rb_find_bss(rdev
, tmp
, BSS_CMP_REGULAR
);
854 if (rcu_access_pointer(tmp
->pub
.proberesp_ies
)) {
855 const struct cfg80211_bss_ies
*old
;
857 old
= rcu_access_pointer(found
->pub
.proberesp_ies
);
859 rcu_assign_pointer(found
->pub
.proberesp_ies
,
860 tmp
->pub
.proberesp_ies
);
861 /* Override possible earlier Beacon frame IEs */
862 rcu_assign_pointer(found
->pub
.ies
,
863 tmp
->pub
.proberesp_ies
);
865 kfree_rcu((struct cfg80211_bss_ies
*)old
,
867 } else if (rcu_access_pointer(tmp
->pub
.beacon_ies
)) {
868 const struct cfg80211_bss_ies
*old
;
869 struct cfg80211_internal_bss
*bss
;
871 if (found
->pub
.hidden_beacon_bss
&&
872 !list_empty(&found
->hidden_list
)) {
873 const struct cfg80211_bss_ies
*f
;
876 * The found BSS struct is one of the probe
877 * response members of a group, but we're
878 * receiving a beacon (beacon_ies in the tmp
879 * bss is used). This can only mean that the
880 * AP changed its beacon from not having an
881 * SSID to showing it, which is confusing so
882 * drop this information.
885 f
= rcu_access_pointer(tmp
->pub
.beacon_ies
);
886 kfree_rcu((struct cfg80211_bss_ies
*)f
,
891 old
= rcu_access_pointer(found
->pub
.beacon_ies
);
893 rcu_assign_pointer(found
->pub
.beacon_ies
,
894 tmp
->pub
.beacon_ies
);
896 /* Override IEs if they were from a beacon before */
897 if (old
== rcu_access_pointer(found
->pub
.ies
))
898 rcu_assign_pointer(found
->pub
.ies
,
899 tmp
->pub
.beacon_ies
);
901 /* Assign beacon IEs to all sub entries */
902 list_for_each_entry(bss
, &found
->hidden_list
,
904 const struct cfg80211_bss_ies
*ies
;
906 ies
= rcu_access_pointer(bss
->pub
.beacon_ies
);
909 rcu_assign_pointer(bss
->pub
.beacon_ies
,
910 tmp
->pub
.beacon_ies
);
914 kfree_rcu((struct cfg80211_bss_ies
*)old
,
918 found
->pub
.beacon_interval
= tmp
->pub
.beacon_interval
;
920 * don't update the signal if beacon was heard on
924 found
->pub
.signal
= tmp
->pub
.signal
;
925 found
->pub
.capability
= tmp
->pub
.capability
;
927 found
->ts_boottime
= tmp
->ts_boottime
;
929 struct cfg80211_internal_bss
*new;
930 struct cfg80211_internal_bss
*hidden
;
931 struct cfg80211_bss_ies
*ies
;
934 * create a copy -- the "res" variable that is passed in
935 * is allocated on the stack since it's not needed in the
936 * more common case of an update
938 new = kzalloc(sizeof(*new) + rdev
->wiphy
.bss_priv_size
,
941 ies
= (void *)rcu_dereference(tmp
->pub
.beacon_ies
);
943 kfree_rcu(ies
, rcu_head
);
944 ies
= (void *)rcu_dereference(tmp
->pub
.proberesp_ies
);
946 kfree_rcu(ies
, rcu_head
);
949 memcpy(new, tmp
, sizeof(*new));
951 INIT_LIST_HEAD(&new->hidden_list
);
953 if (rcu_access_pointer(tmp
->pub
.proberesp_ies
)) {
954 hidden
= rb_find_bss(rdev
, tmp
, BSS_CMP_HIDE_ZLEN
);
956 hidden
= rb_find_bss(rdev
, tmp
,
959 new->pub
.hidden_beacon_bss
= &hidden
->pub
;
960 list_add(&new->hidden_list
,
961 &hidden
->hidden_list
);
963 rcu_assign_pointer(new->pub
.beacon_ies
,
964 hidden
->pub
.beacon_ies
);
968 * Ok so we found a beacon, and don't have an entry. If
969 * it's a beacon with hidden SSID, we might be in for an
970 * expensive search for any probe responses that should
971 * be grouped with this beacon for updates ...
973 if (!cfg80211_combine_bsses(rdev
, new)) {
979 if (rdev
->bss_entries
>= bss_entries_limit
&&
980 !cfg80211_bss_expire_oldest(rdev
)) {
985 list_add_tail(&new->list
, &rdev
->bss_list
);
987 rb_insert_bss(rdev
, new);
991 rdev
->bss_generation
++;
992 bss_ref_get(rdev
, found
);
993 spin_unlock_bh(&rdev
->bss_lock
);
997 spin_unlock_bh(&rdev
->bss_lock
);
1001 static struct ieee80211_channel
*
1002 cfg80211_get_bss_channel(struct wiphy
*wiphy
, const u8
*ie
, size_t ielen
,
1003 struct ieee80211_channel
*channel
)
1007 int channel_number
= -1;
1009 tmp
= cfg80211_find_ie(WLAN_EID_DS_PARAMS
, ie
, ielen
);
1010 if (tmp
&& tmp
[1] == 1) {
1011 channel_number
= tmp
[2];
1013 tmp
= cfg80211_find_ie(WLAN_EID_HT_OPERATION
, ie
, ielen
);
1014 if (tmp
&& tmp
[1] >= sizeof(struct ieee80211_ht_operation
)) {
1015 struct ieee80211_ht_operation
*htop
= (void *)(tmp
+ 2);
1017 channel_number
= htop
->primary_chan
;
1021 if (channel_number
< 0)
1024 freq
= ieee80211_channel_to_frequency(channel_number
, channel
->band
);
1025 channel
= ieee80211_get_channel(wiphy
, freq
);
1028 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
1033 /* Returned bss is reference counted and must be cleaned up appropriately. */
1034 struct cfg80211_bss
*
1035 cfg80211_inform_bss_data(struct wiphy
*wiphy
,
1036 struct cfg80211_inform_bss
*data
,
1037 enum cfg80211_bss_frame_type ftype
,
1038 const u8
*bssid
, u64 tsf
, u16 capability
,
1039 u16 beacon_interval
, const u8
*ie
, size_t ielen
,
1042 struct cfg80211_bss_ies
*ies
;
1043 struct ieee80211_channel
*channel
;
1044 struct cfg80211_internal_bss tmp
= {}, *res
;
1048 if (WARN_ON(!wiphy
))
1051 if (WARN_ON(wiphy
->signal_type
== CFG80211_SIGNAL_TYPE_UNSPEC
&&
1052 (data
->signal
< 0 || data
->signal
> 100)))
1055 channel
= cfg80211_get_bss_channel(wiphy
, ie
, ielen
, data
->chan
);
1059 memcpy(tmp
.pub
.bssid
, bssid
, ETH_ALEN
);
1060 tmp
.pub
.channel
= channel
;
1061 tmp
.pub
.scan_width
= data
->scan_width
;
1062 tmp
.pub
.signal
= data
->signal
;
1063 tmp
.pub
.beacon_interval
= beacon_interval
;
1064 tmp
.pub
.capability
= capability
;
1065 tmp
.ts_boottime
= data
->boottime_ns
;
1068 * If we do not know here whether the IEs are from a Beacon or Probe
1069 * Response frame, we need to pick one of the options and only use it
1070 * with the driver that does not provide the full Beacon/Probe Response
1071 * frame. Use Beacon frame pointer to avoid indicating that this should
1072 * override the IEs pointer should we have received an earlier
1073 * indication of Probe Response data.
1075 ies
= kzalloc(sizeof(*ies
) + ielen
, gfp
);
1080 ies
->from_beacon
= false;
1081 memcpy(ies
->data
, ie
, ielen
);
1084 case CFG80211_BSS_FTYPE_BEACON
:
1085 ies
->from_beacon
= true;
1086 /* fall through to assign */
1087 case CFG80211_BSS_FTYPE_UNKNOWN
:
1088 rcu_assign_pointer(tmp
.pub
.beacon_ies
, ies
);
1090 case CFG80211_BSS_FTYPE_PRESP
:
1091 rcu_assign_pointer(tmp
.pub
.proberesp_ies
, ies
);
1094 rcu_assign_pointer(tmp
.pub
.ies
, ies
);
1096 signal_valid
= abs(data
->chan
->center_freq
- channel
->center_freq
) <=
1097 wiphy
->max_adj_channel_rssi_comp
;
1098 res
= cfg80211_bss_update(wiphy_to_rdev(wiphy
), &tmp
, signal_valid
);
1102 if (channel
->band
== NL80211_BAND_60GHZ
) {
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
);
1108 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
1109 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1112 trace_cfg80211_return_bss(&res
->pub
);
1113 /* cfg80211_bss_update gives us a referenced result */
1116 EXPORT_SYMBOL(cfg80211_inform_bss_data
);
1118 /* cfg80211_inform_bss_width_frame helper */
1119 struct cfg80211_bss
*
1120 cfg80211_inform_bss_frame_data(struct wiphy
*wiphy
,
1121 struct cfg80211_inform_bss
*data
,
1122 struct ieee80211_mgmt
*mgmt
, size_t len
,
1126 struct cfg80211_internal_bss tmp
= {}, *res
;
1127 struct cfg80211_bss_ies
*ies
;
1128 struct ieee80211_channel
*channel
;
1130 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
1131 u
.probe_resp
.variable
);
1134 BUILD_BUG_ON(offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
) !=
1135 offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
));
1137 trace_cfg80211_inform_bss_frame(wiphy
, data
, mgmt
, len
);
1142 if (WARN_ON(!wiphy
))
1145 if (WARN_ON(wiphy
->signal_type
== CFG80211_SIGNAL_TYPE_UNSPEC
&&
1146 (data
->signal
< 0 || data
->signal
> 100)))
1149 if (WARN_ON(len
< offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
)))
1152 channel
= cfg80211_get_bss_channel(wiphy
, mgmt
->u
.beacon
.variable
,
1157 ies
= kzalloc(sizeof(*ies
) + ielen
, gfp
);
1161 ies
->tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
1162 ies
->from_beacon
= ieee80211_is_beacon(mgmt
->frame_control
);
1163 memcpy(ies
->data
, mgmt
->u
.probe_resp
.variable
, ielen
);
1165 if (ieee80211_is_probe_resp(mgmt
->frame_control
))
1166 rcu_assign_pointer(tmp
.pub
.proberesp_ies
, ies
);
1168 rcu_assign_pointer(tmp
.pub
.beacon_ies
, ies
);
1169 rcu_assign_pointer(tmp
.pub
.ies
, ies
);
1171 memcpy(tmp
.pub
.bssid
, mgmt
->bssid
, ETH_ALEN
);
1172 tmp
.pub
.channel
= channel
;
1173 tmp
.pub
.scan_width
= data
->scan_width
;
1174 tmp
.pub
.signal
= data
->signal
;
1175 tmp
.pub
.beacon_interval
= le16_to_cpu(mgmt
->u
.probe_resp
.beacon_int
);
1176 tmp
.pub
.capability
= le16_to_cpu(mgmt
->u
.probe_resp
.capab_info
);
1177 tmp
.ts_boottime
= data
->boottime_ns
;
1179 signal_valid
= abs(data
->chan
->center_freq
- channel
->center_freq
) <=
1180 wiphy
->max_adj_channel_rssi_comp
;
1181 res
= cfg80211_bss_update(wiphy_to_rdev(wiphy
), &tmp
, signal_valid
);
1185 if (channel
->band
== NL80211_BAND_60GHZ
) {
1186 bss_type
= res
->pub
.capability
& WLAN_CAPABILITY_DMG_TYPE_MASK
;
1187 if (bss_type
== WLAN_CAPABILITY_DMG_TYPE_AP
||
1188 bss_type
== WLAN_CAPABILITY_DMG_TYPE_PBSS
)
1189 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1191 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
1192 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1195 trace_cfg80211_return_bss(&res
->pub
);
1196 /* cfg80211_bss_update gives us a referenced result */
1199 EXPORT_SYMBOL(cfg80211_inform_bss_frame_data
);
1201 void cfg80211_ref_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1203 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1204 struct cfg80211_internal_bss
*bss
;
1209 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1211 spin_lock_bh(&rdev
->bss_lock
);
1212 bss_ref_get(rdev
, bss
);
1213 spin_unlock_bh(&rdev
->bss_lock
);
1215 EXPORT_SYMBOL(cfg80211_ref_bss
);
1217 void cfg80211_put_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1219 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1220 struct cfg80211_internal_bss
*bss
;
1225 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1227 spin_lock_bh(&rdev
->bss_lock
);
1228 bss_ref_put(rdev
, bss
);
1229 spin_unlock_bh(&rdev
->bss_lock
);
1231 EXPORT_SYMBOL(cfg80211_put_bss
);
1233 void cfg80211_unlink_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1235 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1236 struct cfg80211_internal_bss
*bss
;
1241 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1243 spin_lock_bh(&rdev
->bss_lock
);
1244 if (!list_empty(&bss
->list
)) {
1245 if (__cfg80211_unlink_bss(rdev
, bss
))
1246 rdev
->bss_generation
++;
1248 spin_unlock_bh(&rdev
->bss_lock
);
1250 EXPORT_SYMBOL(cfg80211_unlink_bss
);
1252 #ifdef CONFIG_CFG80211_WEXT
1253 static struct cfg80211_registered_device
*
1254 cfg80211_get_dev_from_ifindex(struct net
*net
, int ifindex
)
1256 struct cfg80211_registered_device
*rdev
;
1257 struct net_device
*dev
;
1261 dev
= dev_get_by_index(net
, ifindex
);
1263 return ERR_PTR(-ENODEV
);
1264 if (dev
->ieee80211_ptr
)
1265 rdev
= wiphy_to_rdev(dev
->ieee80211_ptr
->wiphy
);
1267 rdev
= ERR_PTR(-ENODEV
);
1272 int cfg80211_wext_siwscan(struct net_device
*dev
,
1273 struct iw_request_info
*info
,
1274 union iwreq_data
*wrqu
, char *extra
)
1276 struct cfg80211_registered_device
*rdev
;
1277 struct wiphy
*wiphy
;
1278 struct iw_scan_req
*wreq
= NULL
;
1279 struct cfg80211_scan_request
*creq
= NULL
;
1280 int i
, err
, n_channels
= 0;
1281 enum nl80211_band band
;
1283 if (!netif_running(dev
))
1286 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
))
1287 wreq
= (struct iw_scan_req
*)extra
;
1289 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
1292 return PTR_ERR(rdev
);
1294 if (rdev
->scan_req
|| rdev
->scan_msg
) {
1299 wiphy
= &rdev
->wiphy
;
1301 /* Determine number of channels, needed to allocate creq */
1302 if (wreq
&& wreq
->num_channels
)
1303 n_channels
= wreq
->num_channels
;
1305 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
1307 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
1308 n_channels
* sizeof(void *),
1315 creq
->wiphy
= wiphy
;
1316 creq
->wdev
= dev
->ieee80211_ptr
;
1317 /* SSIDs come after channels */
1318 creq
->ssids
= (void *)&creq
->channels
[n_channels
];
1319 creq
->n_channels
= n_channels
;
1321 creq
->scan_start
= jiffies
;
1323 /* translate "Scan on frequencies" request */
1325 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
1328 if (!wiphy
->bands
[band
])
1331 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
1332 /* ignore disabled channels */
1333 if (wiphy
->bands
[band
]->channels
[j
].flags
&
1334 IEEE80211_CHAN_DISABLED
)
1337 /* If we have a wireless request structure and the
1338 * wireless request specifies frequencies, then search
1339 * for the matching hardware channel.
1341 if (wreq
&& wreq
->num_channels
) {
1343 int wiphy_freq
= wiphy
->bands
[band
]->channels
[j
].center_freq
;
1344 for (k
= 0; k
< wreq
->num_channels
; k
++) {
1345 struct iw_freq
*freq
=
1346 &wreq
->channel_list
[k
];
1348 cfg80211_wext_freq(freq
);
1350 if (wext_freq
== wiphy_freq
)
1351 goto wext_freq_found
;
1353 goto wext_freq_not_found
;
1357 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
1359 wext_freq_not_found
: ;
1362 /* No channels found? */
1368 /* Set real number of channels specified in creq->channels[] */
1369 creq
->n_channels
= i
;
1371 /* translate "Scan for SSID" request */
1373 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
1374 if (wreq
->essid_len
> IEEE80211_MAX_SSID_LEN
) {
1378 memcpy(creq
->ssids
[0].ssid
, wreq
->essid
, wreq
->essid_len
);
1379 creq
->ssids
[0].ssid_len
= wreq
->essid_len
;
1381 if (wreq
->scan_type
== IW_SCAN_TYPE_PASSIVE
)
1385 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
1386 if (wiphy
->bands
[i
])
1387 creq
->rates
[i
] = (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
1389 rdev
->scan_req
= creq
;
1390 err
= rdev_scan(rdev
, creq
);
1392 rdev
->scan_req
= NULL
;
1393 /* creq will be freed below */
1395 nl80211_send_scan_start(rdev
, dev
->ieee80211_ptr
);
1396 /* creq now owned by driver */
1404 EXPORT_WEXT_HANDLER(cfg80211_wext_siwscan
);
1406 static char *ieee80211_scan_add_ies(struct iw_request_info
*info
,
1407 const struct cfg80211_bss_ies
*ies
,
1408 char *current_ev
, char *end_buf
)
1410 const u8
*pos
, *end
, *next
;
1411 struct iw_event iwe
;
1417 * If needed, fragment the IEs buffer (at IE boundaries) into short
1418 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
1421 end
= pos
+ ies
->len
;
1423 while (end
- pos
> IW_GENERIC_IE_MAX
) {
1424 next
= pos
+ 2 + pos
[1];
1425 while (next
+ 2 + next
[1] - pos
< IW_GENERIC_IE_MAX
)
1426 next
= next
+ 2 + next
[1];
1428 memset(&iwe
, 0, sizeof(iwe
));
1429 iwe
.cmd
= IWEVGENIE
;
1430 iwe
.u
.data
.length
= next
- pos
;
1431 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
1434 if (IS_ERR(current_ev
))
1440 memset(&iwe
, 0, sizeof(iwe
));
1441 iwe
.cmd
= IWEVGENIE
;
1442 iwe
.u
.data
.length
= end
- pos
;
1443 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
1446 if (IS_ERR(current_ev
))
1454 ieee80211_bss(struct wiphy
*wiphy
, struct iw_request_info
*info
,
1455 struct cfg80211_internal_bss
*bss
, char *current_ev
,
1458 const struct cfg80211_bss_ies
*ies
;
1459 struct iw_event iwe
;
1464 bool ismesh
= false;
1466 memset(&iwe
, 0, sizeof(iwe
));
1467 iwe
.cmd
= SIOCGIWAP
;
1468 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1469 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->pub
.bssid
, ETH_ALEN
);
1470 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
1472 if (IS_ERR(current_ev
))
1475 memset(&iwe
, 0, sizeof(iwe
));
1476 iwe
.cmd
= SIOCGIWFREQ
;
1477 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->pub
.channel
->center_freq
);
1479 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
1481 if (IS_ERR(current_ev
))
1484 memset(&iwe
, 0, sizeof(iwe
));
1485 iwe
.cmd
= SIOCGIWFREQ
;
1486 iwe
.u
.freq
.m
= bss
->pub
.channel
->center_freq
;
1488 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
1490 if (IS_ERR(current_ev
))
1493 if (wiphy
->signal_type
!= CFG80211_SIGNAL_TYPE_NONE
) {
1494 memset(&iwe
, 0, sizeof(iwe
));
1496 iwe
.u
.qual
.updated
= IW_QUAL_LEVEL_UPDATED
|
1497 IW_QUAL_NOISE_INVALID
|
1498 IW_QUAL_QUAL_UPDATED
;
1499 switch (wiphy
->signal_type
) {
1500 case CFG80211_SIGNAL_TYPE_MBM
:
1501 sig
= bss
->pub
.signal
/ 100;
1502 iwe
.u
.qual
.level
= sig
;
1503 iwe
.u
.qual
.updated
|= IW_QUAL_DBM
;
1504 if (sig
< -110) /* rather bad */
1506 else if (sig
> -40) /* perfect */
1508 /* will give a range of 0 .. 70 */
1509 iwe
.u
.qual
.qual
= sig
+ 110;
1511 case CFG80211_SIGNAL_TYPE_UNSPEC
:
1512 iwe
.u
.qual
.level
= bss
->pub
.signal
;
1513 /* will give range 0 .. 100 */
1514 iwe
.u
.qual
.qual
= bss
->pub
.signal
;
1520 current_ev
= iwe_stream_add_event_check(info
, current_ev
,
1523 if (IS_ERR(current_ev
))
1527 memset(&iwe
, 0, sizeof(iwe
));
1528 iwe
.cmd
= SIOCGIWENCODE
;
1529 if (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
)
1530 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
1532 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
1533 iwe
.u
.data
.length
= 0;
1534 current_ev
= iwe_stream_add_point_check(info
, current_ev
, end_buf
,
1536 if (IS_ERR(current_ev
))
1540 ies
= rcu_dereference(bss
->pub
.ies
);
1546 if (ie
[1] > rem
- 2)
1551 memset(&iwe
, 0, sizeof(iwe
));
1552 iwe
.cmd
= SIOCGIWESSID
;
1553 iwe
.u
.data
.length
= ie
[1];
1554 iwe
.u
.data
.flags
= 1;
1555 current_ev
= iwe_stream_add_point_check(info
,
1559 if (IS_ERR(current_ev
))
1562 case WLAN_EID_MESH_ID
:
1563 memset(&iwe
, 0, sizeof(iwe
));
1564 iwe
.cmd
= SIOCGIWESSID
;
1565 iwe
.u
.data
.length
= ie
[1];
1566 iwe
.u
.data
.flags
= 1;
1567 current_ev
= iwe_stream_add_point_check(info
,
1571 if (IS_ERR(current_ev
))
1574 case WLAN_EID_MESH_CONFIG
:
1576 if (ie
[1] != sizeof(struct ieee80211_meshconf_ie
))
1579 memset(&iwe
, 0, sizeof(iwe
));
1580 iwe
.cmd
= IWEVCUSTOM
;
1581 sprintf(buf
, "Mesh Network Path Selection Protocol ID: "
1583 iwe
.u
.data
.length
= strlen(buf
);
1584 current_ev
= iwe_stream_add_point_check(info
,
1588 if (IS_ERR(current_ev
))
1590 sprintf(buf
, "Path Selection Metric ID: 0x%02X",
1592 iwe
.u
.data
.length
= strlen(buf
);
1593 current_ev
= iwe_stream_add_point_check(info
,
1597 if (IS_ERR(current_ev
))
1599 sprintf(buf
, "Congestion Control Mode ID: 0x%02X",
1601 iwe
.u
.data
.length
= strlen(buf
);
1602 current_ev
= iwe_stream_add_point_check(info
,
1606 if (IS_ERR(current_ev
))
1608 sprintf(buf
, "Synchronization ID: 0x%02X", cfg
[3]);
1609 iwe
.u
.data
.length
= strlen(buf
);
1610 current_ev
= iwe_stream_add_point_check(info
,
1614 if (IS_ERR(current_ev
))
1616 sprintf(buf
, "Authentication ID: 0x%02X", cfg
[4]);
1617 iwe
.u
.data
.length
= strlen(buf
);
1618 current_ev
= iwe_stream_add_point_check(info
,
1622 if (IS_ERR(current_ev
))
1624 sprintf(buf
, "Formation Info: 0x%02X", cfg
[5]);
1625 iwe
.u
.data
.length
= strlen(buf
);
1626 current_ev
= iwe_stream_add_point_check(info
,
1630 if (IS_ERR(current_ev
))
1632 sprintf(buf
, "Capabilities: 0x%02X", cfg
[6]);
1633 iwe
.u
.data
.length
= strlen(buf
);
1634 current_ev
= iwe_stream_add_point_check(info
,
1638 if (IS_ERR(current_ev
))
1641 case WLAN_EID_SUPP_RATES
:
1642 case WLAN_EID_EXT_SUPP_RATES
:
1643 /* display all supported rates in readable format */
1644 p
= current_ev
+ iwe_stream_lcp_len(info
);
1646 memset(&iwe
, 0, sizeof(iwe
));
1647 iwe
.cmd
= SIOCGIWRATE
;
1648 /* Those two flags are ignored... */
1649 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
1651 for (i
= 0; i
< ie
[1]; i
++) {
1652 iwe
.u
.bitrate
.value
=
1653 ((ie
[i
+ 2] & 0x7f) * 500000);
1655 p
= iwe_stream_add_value(info
, current_ev
, p
,
1659 current_ev
= ERR_PTR(-E2BIG
);
1670 if (bss
->pub
.capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
) ||
1672 memset(&iwe
, 0, sizeof(iwe
));
1673 iwe
.cmd
= SIOCGIWMODE
;
1675 iwe
.u
.mode
= IW_MODE_MESH
;
1676 else if (bss
->pub
.capability
& WLAN_CAPABILITY_ESS
)
1677 iwe
.u
.mode
= IW_MODE_MASTER
;
1679 iwe
.u
.mode
= IW_MODE_ADHOC
;
1680 current_ev
= iwe_stream_add_event_check(info
, current_ev
,
1683 if (IS_ERR(current_ev
))
1687 memset(&iwe
, 0, sizeof(iwe
));
1688 iwe
.cmd
= IWEVCUSTOM
;
1689 sprintf(buf
, "tsf=%016llx", (unsigned long long)(ies
->tsf
));
1690 iwe
.u
.data
.length
= strlen(buf
);
1691 current_ev
= iwe_stream_add_point_check(info
, current_ev
, end_buf
,
1693 if (IS_ERR(current_ev
))
1695 memset(&iwe
, 0, sizeof(iwe
));
1696 iwe
.cmd
= IWEVCUSTOM
;
1697 sprintf(buf
, " Last beacon: %ums ago",
1698 elapsed_jiffies_msecs(bss
->ts
));
1699 iwe
.u
.data
.length
= strlen(buf
);
1700 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
1701 end_buf
, &iwe
, buf
);
1702 if (IS_ERR(current_ev
))
1705 current_ev
= ieee80211_scan_add_ies(info
, ies
, current_ev
, end_buf
);
1713 static int ieee80211_scan_results(struct cfg80211_registered_device
*rdev
,
1714 struct iw_request_info
*info
,
1715 char *buf
, size_t len
)
1717 char *current_ev
= buf
;
1718 char *end_buf
= buf
+ len
;
1719 struct cfg80211_internal_bss
*bss
;
1722 spin_lock_bh(&rdev
->bss_lock
);
1723 cfg80211_bss_expire(rdev
);
1725 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
1726 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
1730 current_ev
= ieee80211_bss(&rdev
->wiphy
, info
, bss
,
1731 current_ev
, end_buf
);
1732 if (IS_ERR(current_ev
)) {
1733 err
= PTR_ERR(current_ev
);
1737 spin_unlock_bh(&rdev
->bss_lock
);
1741 return current_ev
- buf
;
1745 int cfg80211_wext_giwscan(struct net_device
*dev
,
1746 struct iw_request_info
*info
,
1747 struct iw_point
*data
, char *extra
)
1749 struct cfg80211_registered_device
*rdev
;
1752 if (!netif_running(dev
))
1755 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
1758 return PTR_ERR(rdev
);
1760 if (rdev
->scan_req
|| rdev
->scan_msg
)
1763 res
= ieee80211_scan_results(rdev
, info
, extra
, data
->length
);
1772 EXPORT_WEXT_HANDLER(cfg80211_wext_giwscan
);