2 * cfg80211 scan result handling
4 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
6 * Copyright 2016 Intel Deutschland GmbH
8 #include <linux/kernel.h>
9 #include <linux/slab.h>
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>
16 #include <net/cfg80211.h>
17 #include <net/cfg80211-wext.h>
18 #include <net/iw_handler.h>
21 #include "wext-compat.h"
25 * DOC: BSS tree/list structure
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
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.
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.
50 * Note that the hidden_beacon_bss pointer never changes, due to
51 * the reference counting. Therefore, no locking is needed for
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.
60 #define IEEE80211_SCAN_RESULT_EXPIRE (30 * HZ)
62 static void bss_free(struct cfg80211_internal_bss
*bss
)
64 struct cfg80211_bss_ies
*ies
;
66 if (WARN_ON(atomic_read(&bss
->hold
)))
69 ies
= (void *)rcu_access_pointer(bss
->pub
.beacon_ies
);
70 if (ies
&& !bss
->pub
.hidden_beacon_bss
)
71 kfree_rcu(ies
, rcu_head
);
72 ies
= (void *)rcu_access_pointer(bss
->pub
.proberesp_ies
);
74 kfree_rcu(ies
, rcu_head
);
77 * This happens when the module is removed, it doesn't
78 * really matter any more save for completeness
80 if (!list_empty(&bss
->hidden_list
))
81 list_del(&bss
->hidden_list
);
86 static inline void bss_ref_get(struct cfg80211_registered_device
*rdev
,
87 struct cfg80211_internal_bss
*bss
)
89 lockdep_assert_held(&rdev
->bss_lock
);
92 if (bss
->pub
.hidden_beacon_bss
) {
93 bss
= container_of(bss
->pub
.hidden_beacon_bss
,
94 struct cfg80211_internal_bss
,
100 static inline void bss_ref_put(struct cfg80211_registered_device
*rdev
,
101 struct cfg80211_internal_bss
*bss
)
103 lockdep_assert_held(&rdev
->bss_lock
);
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
,
111 if (hbss
->refcount
== 0)
115 if (bss
->refcount
== 0)
119 static bool __cfg80211_unlink_bss(struct cfg80211_registered_device
*rdev
,
120 struct cfg80211_internal_bss
*bss
)
122 lockdep_assert_held(&rdev
->bss_lock
);
124 if (!list_empty(&bss
->hidden_list
)) {
126 * don't remove the beacon entry if it has
127 * probe responses associated with it
129 if (!bss
->pub
.hidden_beacon_bss
)
132 * if it's a probe response entry break its
133 * link to the other entries in the group
135 list_del_init(&bss
->hidden_list
);
138 list_del_init(&bss
->list
);
139 rb_erase(&bss
->rbn
, &rdev
->bss_tree
);
140 bss_ref_put(rdev
, bss
);
144 static void __cfg80211_bss_expire(struct cfg80211_registered_device
*rdev
,
145 unsigned long expire_time
)
147 struct cfg80211_internal_bss
*bss
, *tmp
;
148 bool expired
= false;
150 lockdep_assert_held(&rdev
->bss_lock
);
152 list_for_each_entry_safe(bss
, tmp
, &rdev
->bss_list
, list
) {
153 if (atomic_read(&bss
->hold
))
155 if (!time_after(expire_time
, bss
->ts
))
158 if (__cfg80211_unlink_bss(rdev
, bss
))
163 rdev
->bss_generation
++;
166 void ___cfg80211_scan_done(struct cfg80211_registered_device
*rdev
,
169 struct cfg80211_scan_request
*request
;
170 struct wireless_dev
*wdev
;
172 #ifdef CONFIG_CFG80211_WEXT
173 union iwreq_data wrqu
;
178 if (rdev
->scan_msg
) {
179 nl80211_send_scan_result(rdev
, rdev
->scan_msg
);
180 rdev
->scan_msg
= NULL
;
184 request
= rdev
->scan_req
;
188 wdev
= request
->wdev
;
191 * This must be before sending the other events!
192 * Otherwise, wpa_supplicant gets completely confused with
196 cfg80211_sme_scan_done(wdev
->netdev
);
198 if (!request
->info
.aborted
&&
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
);
206 msg
= nl80211_build_scan_msg(rdev
, wdev
, request
->info
.aborted
);
208 #ifdef CONFIG_CFG80211_WEXT
209 if (wdev
->netdev
&& !request
->info
.aborted
) {
210 memset(&wrqu
, 0, sizeof(wrqu
));
212 wireless_send_event(wdev
->netdev
, SIOCGIWSCAN
, &wrqu
, NULL
);
217 dev_put(wdev
->netdev
);
219 rdev
->scan_req
= NULL
;
223 rdev
->scan_msg
= msg
;
225 nl80211_send_scan_result(rdev
, msg
);
228 void __cfg80211_scan_done(struct work_struct
*wk
)
230 struct cfg80211_registered_device
*rdev
;
232 rdev
= container_of(wk
, struct cfg80211_registered_device
,
236 ___cfg80211_scan_done(rdev
, true);
240 void cfg80211_scan_done(struct cfg80211_scan_request
*request
,
241 struct cfg80211_scan_info
*info
)
243 trace_cfg80211_scan_done(request
, info
);
244 WARN_ON(request
!= wiphy_to_rdev(request
->wiphy
)->scan_req
);
246 request
->info
= *info
;
247 request
->notified
= true;
248 queue_work(cfg80211_wq
, &wiphy_to_rdev(request
->wiphy
)->scan_done_wk
);
250 EXPORT_SYMBOL(cfg80211_scan_done
);
252 void __cfg80211_sched_scan_results(struct work_struct
*wk
)
254 struct cfg80211_registered_device
*rdev
;
255 struct cfg80211_sched_scan_request
*request
;
257 rdev
= container_of(wk
, struct cfg80211_registered_device
,
258 sched_scan_results_wk
);
262 request
= rtnl_dereference(rdev
->sched_scan_req
);
264 /* we don't have sched_scan_req anymore if the scan is stopping */
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
);
271 request
->scan_start
= jiffies
;
273 nl80211_send_sched_scan_results(rdev
, request
->dev
);
279 void cfg80211_sched_scan_results(struct wiphy
*wiphy
)
281 trace_cfg80211_sched_scan_results(wiphy
);
282 /* ignore if we're not scanning */
284 if (rcu_access_pointer(wiphy_to_rdev(wiphy
)->sched_scan_req
))
285 queue_work(cfg80211_wq
,
286 &wiphy_to_rdev(wiphy
)->sched_scan_results_wk
);
288 EXPORT_SYMBOL(cfg80211_sched_scan_results
);
290 void cfg80211_sched_scan_stopped_rtnl(struct wiphy
*wiphy
)
292 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
296 trace_cfg80211_sched_scan_stopped(wiphy
);
298 __cfg80211_stop_sched_scan(rdev
, true);
300 EXPORT_SYMBOL(cfg80211_sched_scan_stopped_rtnl
);
302 void cfg80211_sched_scan_stopped(struct wiphy
*wiphy
)
305 cfg80211_sched_scan_stopped_rtnl(wiphy
);
308 EXPORT_SYMBOL(cfg80211_sched_scan_stopped
);
310 int __cfg80211_stop_sched_scan(struct cfg80211_registered_device
*rdev
,
311 bool driver_initiated
)
313 struct cfg80211_sched_scan_request
*sched_scan_req
;
314 struct net_device
*dev
;
318 if (!rdev
->sched_scan_req
)
321 sched_scan_req
= rtnl_dereference(rdev
->sched_scan_req
);
322 dev
= sched_scan_req
->dev
;
324 if (!driver_initiated
) {
325 int err
= rdev_sched_scan_stop(rdev
, dev
);
330 nl80211_send_sched_scan(rdev
, dev
, NL80211_CMD_SCHED_SCAN_STOPPED
);
332 RCU_INIT_POINTER(rdev
->sched_scan_req
, NULL
);
333 kfree_rcu(sched_scan_req
, rcu_head
);
338 void cfg80211_bss_age(struct cfg80211_registered_device
*rdev
,
339 unsigned long age_secs
)
341 struct cfg80211_internal_bss
*bss
;
342 unsigned long age_jiffies
= msecs_to_jiffies(age_secs
* MSEC_PER_SEC
);
344 spin_lock_bh(&rdev
->bss_lock
);
345 list_for_each_entry(bss
, &rdev
->bss_list
, list
)
346 bss
->ts
-= age_jiffies
;
347 spin_unlock_bh(&rdev
->bss_lock
);
350 void cfg80211_bss_expire(struct cfg80211_registered_device
*rdev
)
352 __cfg80211_bss_expire(rdev
, jiffies
- IEEE80211_SCAN_RESULT_EXPIRE
);
355 const u8
*cfg80211_find_ie(u8 eid
, const u8
*ies
, int len
)
357 while (len
> 2 && ies
[0] != eid
) {
363 if (len
< 2 + ies
[1])
367 EXPORT_SYMBOL(cfg80211_find_ie
);
369 const u8
*cfg80211_find_vendor_ie(unsigned int oui
, int oui_type
,
370 const u8
*ies
, int len
)
372 struct ieee80211_vendor_ie
*ie
;
373 const u8
*pos
= ies
, *end
= ies
+ len
;
376 if (WARN_ON(oui_type
> 0xff))
380 pos
= cfg80211_find_ie(WLAN_EID_VENDOR_SPECIFIC
, pos
,
385 ie
= (struct ieee80211_vendor_ie
*)pos
;
387 /* make sure we can access ie->len */
388 BUILD_BUG_ON(offsetof(struct ieee80211_vendor_ie
, len
) != 1);
390 if (ie
->len
< sizeof(*ie
))
393 ie_oui
= ie
->oui
[0] << 16 | ie
->oui
[1] << 8 | ie
->oui
[2];
395 (oui_type
< 0 || ie
->oui_type
== oui_type
))
402 EXPORT_SYMBOL(cfg80211_find_vendor_ie
);
404 static bool is_bss(struct cfg80211_bss
*a
, const u8
*bssid
,
405 const u8
*ssid
, size_t ssid_len
)
407 const struct cfg80211_bss_ies
*ies
;
410 if (bssid
&& !ether_addr_equal(a
->bssid
, bssid
))
416 ies
= rcu_access_pointer(a
->ies
);
419 ssidie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
422 if (ssidie
[1] != ssid_len
)
424 return memcmp(ssidie
+ 2, ssid
, ssid_len
) == 0;
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
433 enum bss_compare_mode
{
439 static int cmp_bss(struct cfg80211_bss
*a
,
440 struct cfg80211_bss
*b
,
441 enum bss_compare_mode mode
)
443 const struct cfg80211_bss_ies
*a_ies
, *b_ies
;
444 const u8
*ie1
= NULL
;
445 const u8
*ie2
= NULL
;
448 if (a
->channel
!= b
->channel
)
449 return b
->channel
->center_freq
- a
->channel
->center_freq
;
451 a_ies
= rcu_access_pointer(a
->ies
);
454 b_ies
= rcu_access_pointer(b
->ies
);
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
);
467 if (ie1
[1] == ie2
[1])
468 mesh_id_cmp
= memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
470 mesh_id_cmp
= ie2
[1] - ie1
[1];
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
);
479 if (ie1
[1] != ie2
[1])
480 return ie2
[1] - ie1
[1];
481 return memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
485 r
= memcmp(a
->bssid
, b
->bssid
, sizeof(a
->bssid
));
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
);
496 * Note that with "hide_ssid", the function returns a match if
497 * the already-present BSS ("b") is a hidden SSID beacon for
501 /* sort missing IE before (left of) present IE */
508 case BSS_CMP_HIDE_ZLEN
:
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.
518 * No content comparison is needed as we assume
519 * the content length is zero.
522 case BSS_CMP_REGULAR
:
524 /* sort by length first, then by contents */
525 if (ie1
[1] != ie2
[1])
526 return ie2
[1] - ie1
[1];
527 return memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
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
++)
539 static bool cfg80211_bss_type_match(u16 capability
,
540 enum nl80211_band band
,
541 enum ieee80211_bss_type bss_type
)
546 if (bss_type
== IEEE80211_BSS_TYPE_ANY
)
549 if (band
== NL80211_BAND_60GHZ
) {
550 mask
= WLAN_CAPABILITY_DMG_TYPE_MASK
;
552 case IEEE80211_BSS_TYPE_ESS
:
553 val
= WLAN_CAPABILITY_DMG_TYPE_AP
;
555 case IEEE80211_BSS_TYPE_PBSS
:
556 val
= WLAN_CAPABILITY_DMG_TYPE_PBSS
;
558 case IEEE80211_BSS_TYPE_IBSS
:
559 val
= WLAN_CAPABILITY_DMG_TYPE_IBSS
;
565 mask
= WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
;
567 case IEEE80211_BSS_TYPE_ESS
:
568 val
= WLAN_CAPABILITY_ESS
;
570 case IEEE80211_BSS_TYPE_IBSS
:
571 val
= WLAN_CAPABILITY_IBSS
;
573 case IEEE80211_BSS_TYPE_MBSS
:
581 ret
= ((capability
& mask
) == val
);
585 /* Returned bss is reference counted and must be cleaned up appropriately. */
586 struct cfg80211_bss
*cfg80211_get_bss(struct wiphy
*wiphy
,
587 struct ieee80211_channel
*channel
,
589 const u8
*ssid
, size_t ssid_len
,
590 enum ieee80211_bss_type bss_type
,
591 enum ieee80211_privacy privacy
)
593 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
594 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
595 unsigned long now
= jiffies
;
598 trace_cfg80211_get_bss(wiphy
, channel
, bssid
, ssid
, ssid_len
, bss_type
,
601 spin_lock_bh(&rdev
->bss_lock
);
603 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
604 if (!cfg80211_bss_type_match(bss
->pub
.capability
,
605 bss
->pub
.channel
->band
, bss_type
))
608 bss_privacy
= (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
);
609 if ((privacy
== IEEE80211_PRIVACY_ON
&& !bss_privacy
) ||
610 (privacy
== IEEE80211_PRIVACY_OFF
&& bss_privacy
))
612 if (channel
&& bss
->pub
.channel
!= channel
)
614 if (!is_valid_ether_addr(bss
->pub
.bssid
))
616 /* Don't get expired BSS structs */
617 if (time_after(now
, bss
->ts
+ IEEE80211_SCAN_RESULT_EXPIRE
) &&
618 !atomic_read(&bss
->hold
))
620 if (is_bss(&bss
->pub
, bssid
, ssid
, ssid_len
)) {
622 bss_ref_get(rdev
, res
);
627 spin_unlock_bh(&rdev
->bss_lock
);
630 trace_cfg80211_return_bss(&res
->pub
);
633 EXPORT_SYMBOL(cfg80211_get_bss
);
635 static void rb_insert_bss(struct cfg80211_registered_device
*rdev
,
636 struct cfg80211_internal_bss
*bss
)
638 struct rb_node
**p
= &rdev
->bss_tree
.rb_node
;
639 struct rb_node
*parent
= NULL
;
640 struct cfg80211_internal_bss
*tbss
;
645 tbss
= rb_entry(parent
, struct cfg80211_internal_bss
, rbn
);
647 cmp
= cmp_bss(&bss
->pub
, &tbss
->pub
, BSS_CMP_REGULAR
);
650 /* will sort of leak this BSS */
660 rb_link_node(&bss
->rbn
, parent
, p
);
661 rb_insert_color(&bss
->rbn
, &rdev
->bss_tree
);
664 static struct cfg80211_internal_bss
*
665 rb_find_bss(struct cfg80211_registered_device
*rdev
,
666 struct cfg80211_internal_bss
*res
,
667 enum bss_compare_mode mode
)
669 struct rb_node
*n
= rdev
->bss_tree
.rb_node
;
670 struct cfg80211_internal_bss
*bss
;
674 bss
= rb_entry(n
, struct cfg80211_internal_bss
, rbn
);
675 r
= cmp_bss(&res
->pub
, &bss
->pub
, mode
);
688 static bool cfg80211_combine_bsses(struct cfg80211_registered_device
*rdev
,
689 struct cfg80211_internal_bss
*new)
691 const struct cfg80211_bss_ies
*ies
;
692 struct cfg80211_internal_bss
*bss
;
697 ies
= rcu_access_pointer(new->pub
.beacon_ies
);
701 ie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
708 for (i
= 0; i
< ssidlen
; i
++)
712 /* not a hidden SSID */
716 /* This is the bad part ... */
718 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
719 if (!ether_addr_equal(bss
->pub
.bssid
, new->pub
.bssid
))
721 if (bss
->pub
.channel
!= new->pub
.channel
)
723 if (bss
->pub
.scan_width
!= new->pub
.scan_width
)
725 if (rcu_access_pointer(bss
->pub
.beacon_ies
))
727 ies
= rcu_access_pointer(bss
->pub
.ies
);
730 ie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
733 if (ssidlen
&& ie
[1] != ssidlen
)
735 if (WARN_ON_ONCE(bss
->pub
.hidden_beacon_bss
))
737 if (WARN_ON_ONCE(!list_empty(&bss
->hidden_list
)))
738 list_del(&bss
->hidden_list
);
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
);
750 /* Returned bss is reference counted and must be cleaned up appropriately. */
751 static struct cfg80211_internal_bss
*
752 cfg80211_bss_update(struct cfg80211_registered_device
*rdev
,
753 struct cfg80211_internal_bss
*tmp
,
756 struct cfg80211_internal_bss
*found
= NULL
;
758 if (WARN_ON(!tmp
->pub
.channel
))
763 spin_lock_bh(&rdev
->bss_lock
);
765 if (WARN_ON(!rcu_access_pointer(tmp
->pub
.ies
))) {
766 spin_unlock_bh(&rdev
->bss_lock
);
770 found
= rb_find_bss(rdev
, tmp
, BSS_CMP_REGULAR
);
774 if (rcu_access_pointer(tmp
->pub
.proberesp_ies
)) {
775 const struct cfg80211_bss_ies
*old
;
777 old
= rcu_access_pointer(found
->pub
.proberesp_ies
);
779 rcu_assign_pointer(found
->pub
.proberesp_ies
,
780 tmp
->pub
.proberesp_ies
);
781 /* Override possible earlier Beacon frame IEs */
782 rcu_assign_pointer(found
->pub
.ies
,
783 tmp
->pub
.proberesp_ies
);
785 kfree_rcu((struct cfg80211_bss_ies
*)old
,
787 } else if (rcu_access_pointer(tmp
->pub
.beacon_ies
)) {
788 const struct cfg80211_bss_ies
*old
;
789 struct cfg80211_internal_bss
*bss
;
791 if (found
->pub
.hidden_beacon_bss
&&
792 !list_empty(&found
->hidden_list
)) {
793 const struct cfg80211_bss_ies
*f
;
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.
805 f
= rcu_access_pointer(tmp
->pub
.beacon_ies
);
806 kfree_rcu((struct cfg80211_bss_ies
*)f
,
811 old
= rcu_access_pointer(found
->pub
.beacon_ies
);
813 rcu_assign_pointer(found
->pub
.beacon_ies
,
814 tmp
->pub
.beacon_ies
);
816 /* Override IEs if they were from a beacon before */
817 if (old
== rcu_access_pointer(found
->pub
.ies
))
818 rcu_assign_pointer(found
->pub
.ies
,
819 tmp
->pub
.beacon_ies
);
821 /* Assign beacon IEs to all sub entries */
822 list_for_each_entry(bss
, &found
->hidden_list
,
824 const struct cfg80211_bss_ies
*ies
;
826 ies
= rcu_access_pointer(bss
->pub
.beacon_ies
);
829 rcu_assign_pointer(bss
->pub
.beacon_ies
,
830 tmp
->pub
.beacon_ies
);
834 kfree_rcu((struct cfg80211_bss_ies
*)old
,
838 found
->pub
.beacon_interval
= tmp
->pub
.beacon_interval
;
840 * don't update the signal if beacon was heard on
844 found
->pub
.signal
= tmp
->pub
.signal
;
845 found
->pub
.capability
= tmp
->pub
.capability
;
847 found
->ts_boottime
= tmp
->ts_boottime
;
848 found
->parent_tsf
= tmp
->parent_tsf
;
849 ether_addr_copy(found
->parent_bssid
, tmp
->parent_bssid
);
851 struct cfg80211_internal_bss
*new;
852 struct cfg80211_internal_bss
*hidden
;
853 struct cfg80211_bss_ies
*ies
;
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
860 new = kzalloc(sizeof(*new) + rdev
->wiphy
.bss_priv_size
,
863 ies
= (void *)rcu_dereference(tmp
->pub
.beacon_ies
);
865 kfree_rcu(ies
, rcu_head
);
866 ies
= (void *)rcu_dereference(tmp
->pub
.proberesp_ies
);
868 kfree_rcu(ies
, rcu_head
);
871 memcpy(new, tmp
, sizeof(*new));
873 INIT_LIST_HEAD(&new->hidden_list
);
875 if (rcu_access_pointer(tmp
->pub
.proberesp_ies
)) {
876 hidden
= rb_find_bss(rdev
, tmp
, BSS_CMP_HIDE_ZLEN
);
878 hidden
= rb_find_bss(rdev
, tmp
,
881 new->pub
.hidden_beacon_bss
= &hidden
->pub
;
882 list_add(&new->hidden_list
,
883 &hidden
->hidden_list
);
885 rcu_assign_pointer(new->pub
.beacon_ies
,
886 hidden
->pub
.beacon_ies
);
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 ...
895 if (!cfg80211_combine_bsses(rdev
, new)) {
901 list_add_tail(&new->list
, &rdev
->bss_list
);
902 rb_insert_bss(rdev
, new);
906 rdev
->bss_generation
++;
907 bss_ref_get(rdev
, found
);
908 spin_unlock_bh(&rdev
->bss_lock
);
912 spin_unlock_bh(&rdev
->bss_lock
);
916 static struct ieee80211_channel
*
917 cfg80211_get_bss_channel(struct wiphy
*wiphy
, const u8
*ie
, size_t ielen
,
918 struct ieee80211_channel
*channel
)
922 int channel_number
= -1;
924 tmp
= cfg80211_find_ie(WLAN_EID_DS_PARAMS
, ie
, ielen
);
925 if (tmp
&& tmp
[1] == 1) {
926 channel_number
= tmp
[2];
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);
932 channel_number
= htop
->primary_chan
;
936 if (channel_number
< 0)
939 freq
= ieee80211_channel_to_frequency(channel_number
, channel
->band
);
940 channel
= ieee80211_get_channel(wiphy
, freq
);
943 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
948 /* Returned bss is reference counted and must be cleaned up appropriately. */
949 struct cfg80211_bss
*
950 cfg80211_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
,
957 struct cfg80211_bss_ies
*ies
;
958 struct ieee80211_channel
*channel
;
959 struct cfg80211_internal_bss tmp
= {}, *res
;
966 if (WARN_ON(wiphy
->signal_type
== CFG80211_SIGNAL_TYPE_UNSPEC
&&
967 (data
->signal
< 0 || data
->signal
> 100)))
970 channel
= cfg80211_get_bss_channel(wiphy
, ie
, ielen
, data
->chan
);
974 memcpy(tmp
.pub
.bssid
, bssid
, ETH_ALEN
);
975 tmp
.pub
.channel
= channel
;
976 tmp
.pub
.scan_width
= data
->scan_width
;
977 tmp
.pub
.signal
= data
->signal
;
978 tmp
.pub
.beacon_interval
= beacon_interval
;
979 tmp
.pub
.capability
= capability
;
980 tmp
.ts_boottime
= data
->boottime_ns
;
983 * If we do not know here whether the IEs are from a Beacon or Probe
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
987 * override the IEs pointer should we have received an earlier
988 * indication of Probe Response data.
990 ies
= kzalloc(sizeof(*ies
) + ielen
, gfp
);
995 ies
->from_beacon
= false;
996 memcpy(ies
->data
, ie
, ielen
);
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
);
1005 case CFG80211_BSS_FTYPE_PRESP
:
1006 rcu_assign_pointer(tmp
.pub
.proberesp_ies
, ies
);
1009 rcu_assign_pointer(tmp
.pub
.ies
, ies
);
1011 signal_valid
= abs(data
->chan
->center_freq
- channel
->center_freq
) <=
1012 wiphy
->max_adj_channel_rssi_comp
;
1013 res
= cfg80211_bss_update(wiphy_to_rdev(wiphy
), &tmp
, signal_valid
);
1017 if (channel
->band
== NL80211_BAND_60GHZ
) {
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
);
1023 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
1024 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1027 trace_cfg80211_return_bss(&res
->pub
);
1028 /* cfg80211_bss_update gives us a referenced result */
1031 EXPORT_SYMBOL(cfg80211_inform_bss_data
);
1033 /* cfg80211_inform_bss_width_frame helper */
1034 struct cfg80211_bss
*
1035 cfg80211_inform_bss_frame_data(struct wiphy
*wiphy
,
1036 struct cfg80211_inform_bss
*data
,
1037 struct ieee80211_mgmt
*mgmt
, size_t len
,
1041 struct cfg80211_internal_bss tmp
= {}, *res
;
1042 struct cfg80211_bss_ies
*ies
;
1043 struct ieee80211_channel
*channel
;
1045 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
1046 u
.probe_resp
.variable
);
1049 BUILD_BUG_ON(offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
) !=
1050 offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
));
1052 trace_cfg80211_inform_bss_frame(wiphy
, data
, mgmt
, len
);
1057 if (WARN_ON(!wiphy
))
1060 if (WARN_ON(wiphy
->signal_type
== CFG80211_SIGNAL_TYPE_UNSPEC
&&
1061 (data
->signal
< 0 || data
->signal
> 100)))
1064 if (WARN_ON(len
< offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
)))
1067 channel
= cfg80211_get_bss_channel(wiphy
, mgmt
->u
.beacon
.variable
,
1072 ies
= kzalloc(sizeof(*ies
) + ielen
, gfp
);
1076 ies
->tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
1077 ies
->from_beacon
= ieee80211_is_beacon(mgmt
->frame_control
);
1078 memcpy(ies
->data
, mgmt
->u
.probe_resp
.variable
, ielen
);
1080 if (ieee80211_is_probe_resp(mgmt
->frame_control
))
1081 rcu_assign_pointer(tmp
.pub
.proberesp_ies
, ies
);
1083 rcu_assign_pointer(tmp
.pub
.beacon_ies
, ies
);
1084 rcu_assign_pointer(tmp
.pub
.ies
, ies
);
1086 memcpy(tmp
.pub
.bssid
, mgmt
->bssid
, ETH_ALEN
);
1087 tmp
.pub
.channel
= channel
;
1088 tmp
.pub
.scan_width
= data
->scan_width
;
1089 tmp
.pub
.signal
= data
->signal
;
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
);
1092 tmp
.ts_boottime
= data
->boottime_ns
;
1093 tmp
.parent_tsf
= data
->parent_tsf
;
1094 ether_addr_copy(tmp
.parent_bssid
, data
->parent_bssid
);
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_frame_data
);
1118 void cfg80211_ref_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1120 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1121 struct cfg80211_internal_bss
*bss
;
1126 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1128 spin_lock_bh(&rdev
->bss_lock
);
1129 bss_ref_get(rdev
, bss
);
1130 spin_unlock_bh(&rdev
->bss_lock
);
1132 EXPORT_SYMBOL(cfg80211_ref_bss
);
1134 void cfg80211_put_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1136 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1137 struct cfg80211_internal_bss
*bss
;
1142 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1144 spin_lock_bh(&rdev
->bss_lock
);
1145 bss_ref_put(rdev
, bss
);
1146 spin_unlock_bh(&rdev
->bss_lock
);
1148 EXPORT_SYMBOL(cfg80211_put_bss
);
1150 void cfg80211_unlink_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1152 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1153 struct cfg80211_internal_bss
*bss
;
1158 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1160 spin_lock_bh(&rdev
->bss_lock
);
1161 if (!list_empty(&bss
->list
)) {
1162 if (__cfg80211_unlink_bss(rdev
, bss
))
1163 rdev
->bss_generation
++;
1165 spin_unlock_bh(&rdev
->bss_lock
);
1167 EXPORT_SYMBOL(cfg80211_unlink_bss
);
1169 #ifdef CONFIG_CFG80211_WEXT
1170 static struct cfg80211_registered_device
*
1171 cfg80211_get_dev_from_ifindex(struct net
*net
, int ifindex
)
1173 struct cfg80211_registered_device
*rdev
;
1174 struct net_device
*dev
;
1178 dev
= dev_get_by_index(net
, ifindex
);
1180 return ERR_PTR(-ENODEV
);
1181 if (dev
->ieee80211_ptr
)
1182 rdev
= wiphy_to_rdev(dev
->ieee80211_ptr
->wiphy
);
1184 rdev
= ERR_PTR(-ENODEV
);
1189 int cfg80211_wext_siwscan(struct net_device
*dev
,
1190 struct iw_request_info
*info
,
1191 union iwreq_data
*wrqu
, char *extra
)
1193 struct cfg80211_registered_device
*rdev
;
1194 struct wiphy
*wiphy
;
1195 struct iw_scan_req
*wreq
= NULL
;
1196 struct cfg80211_scan_request
*creq
= NULL
;
1197 int i
, err
, n_channels
= 0;
1198 enum nl80211_band band
;
1200 if (!netif_running(dev
))
1203 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
))
1204 wreq
= (struct iw_scan_req
*)extra
;
1206 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
1209 return PTR_ERR(rdev
);
1211 if (rdev
->scan_req
|| rdev
->scan_msg
) {
1216 wiphy
= &rdev
->wiphy
;
1218 /* Determine number of channels, needed to allocate creq */
1219 if (wreq
&& wreq
->num_channels
)
1220 n_channels
= wreq
->num_channels
;
1222 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
1224 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
1225 n_channels
* sizeof(void *),
1232 creq
->wiphy
= wiphy
;
1233 creq
->wdev
= dev
->ieee80211_ptr
;
1234 /* SSIDs come after channels */
1235 creq
->ssids
= (void *)&creq
->channels
[n_channels
];
1236 creq
->n_channels
= n_channels
;
1238 creq
->scan_start
= jiffies
;
1240 /* translate "Scan on frequencies" request */
1242 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
1245 if (!wiphy
->bands
[band
])
1248 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
1249 /* ignore disabled channels */
1250 if (wiphy
->bands
[band
]->channels
[j
].flags
&
1251 IEEE80211_CHAN_DISABLED
)
1254 /* If we have a wireless request structure and the
1255 * wireless request specifies frequencies, then search
1256 * for the matching hardware channel.
1258 if (wreq
&& wreq
->num_channels
) {
1260 int wiphy_freq
= wiphy
->bands
[band
]->channels
[j
].center_freq
;
1261 for (k
= 0; k
< wreq
->num_channels
; k
++) {
1262 struct iw_freq
*freq
=
1263 &wreq
->channel_list
[k
];
1265 cfg80211_wext_freq(freq
);
1267 if (wext_freq
== wiphy_freq
)
1268 goto wext_freq_found
;
1270 goto wext_freq_not_found
;
1274 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
1276 wext_freq_not_found
: ;
1279 /* No channels found? */
1285 /* Set real number of channels specified in creq->channels[] */
1286 creq
->n_channels
= i
;
1288 /* translate "Scan for SSID" request */
1290 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
1291 if (wreq
->essid_len
> IEEE80211_MAX_SSID_LEN
) {
1295 memcpy(creq
->ssids
[0].ssid
, wreq
->essid
, wreq
->essid_len
);
1296 creq
->ssids
[0].ssid_len
= wreq
->essid_len
;
1298 if (wreq
->scan_type
== IW_SCAN_TYPE_PASSIVE
)
1302 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
1303 if (wiphy
->bands
[i
])
1304 creq
->rates
[i
] = (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
1306 eth_broadcast_addr(creq
->bssid
);
1308 rdev
->scan_req
= creq
;
1309 err
= rdev_scan(rdev
, creq
);
1311 rdev
->scan_req
= NULL
;
1312 /* creq will be freed below */
1314 nl80211_send_scan_start(rdev
, dev
->ieee80211_ptr
);
1315 /* creq now owned by driver */
1323 EXPORT_WEXT_HANDLER(cfg80211_wext_siwscan
);
1325 static char *ieee80211_scan_add_ies(struct iw_request_info
*info
,
1326 const struct cfg80211_bss_ies
*ies
,
1327 char *current_ev
, char *end_buf
)
1329 const u8
*pos
, *end
, *next
;
1330 struct iw_event iwe
;
1336 * If needed, fragment the IEs buffer (at IE boundaries) into short
1337 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
1340 end
= pos
+ ies
->len
;
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];
1347 memset(&iwe
, 0, sizeof(iwe
));
1348 iwe
.cmd
= IWEVGENIE
;
1349 iwe
.u
.data
.length
= next
- pos
;
1350 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
1353 if (IS_ERR(current_ev
))
1359 memset(&iwe
, 0, sizeof(iwe
));
1360 iwe
.cmd
= IWEVGENIE
;
1361 iwe
.u
.data
.length
= end
- pos
;
1362 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
1365 if (IS_ERR(current_ev
))
1373 ieee80211_bss(struct wiphy
*wiphy
, struct iw_request_info
*info
,
1374 struct cfg80211_internal_bss
*bss
, char *current_ev
,
1377 const struct cfg80211_bss_ies
*ies
;
1378 struct iw_event iwe
;
1383 bool ismesh
= false;
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
);
1389 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
1391 if (IS_ERR(current_ev
))
1394 memset(&iwe
, 0, sizeof(iwe
));
1395 iwe
.cmd
= SIOCGIWFREQ
;
1396 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->pub
.channel
->center_freq
);
1398 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
1400 if (IS_ERR(current_ev
))
1403 memset(&iwe
, 0, sizeof(iwe
));
1404 iwe
.cmd
= SIOCGIWFREQ
;
1405 iwe
.u
.freq
.m
= bss
->pub
.channel
->center_freq
;
1407 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
1409 if (IS_ERR(current_ev
))
1412 if (wiphy
->signal_type
!= CFG80211_SIGNAL_TYPE_NONE
) {
1413 memset(&iwe
, 0, sizeof(iwe
));
1415 iwe
.u
.qual
.updated
= IW_QUAL_LEVEL_UPDATED
|
1416 IW_QUAL_NOISE_INVALID
|
1417 IW_QUAL_QUAL_UPDATED
;
1418 switch (wiphy
->signal_type
) {
1419 case CFG80211_SIGNAL_TYPE_MBM
:
1420 sig
= bss
->pub
.signal
/ 100;
1421 iwe
.u
.qual
.level
= sig
;
1422 iwe
.u
.qual
.updated
|= IW_QUAL_DBM
;
1423 if (sig
< -110) /* rather bad */
1425 else if (sig
> -40) /* perfect */
1427 /* will give a range of 0 .. 70 */
1428 iwe
.u
.qual
.qual
= sig
+ 110;
1430 case CFG80211_SIGNAL_TYPE_UNSPEC
:
1431 iwe
.u
.qual
.level
= bss
->pub
.signal
;
1432 /* will give range 0 .. 100 */
1433 iwe
.u
.qual
.qual
= bss
->pub
.signal
;
1439 current_ev
= iwe_stream_add_event_check(info
, current_ev
,
1442 if (IS_ERR(current_ev
))
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
;
1451 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
1452 iwe
.u
.data
.length
= 0;
1453 current_ev
= iwe_stream_add_point_check(info
, current_ev
, end_buf
,
1455 if (IS_ERR(current_ev
))
1459 ies
= rcu_dereference(bss
->pub
.ies
);
1465 if (ie
[1] > rem
- 2)
1470 memset(&iwe
, 0, sizeof(iwe
));
1471 iwe
.cmd
= SIOCGIWESSID
;
1472 iwe
.u
.data
.length
= ie
[1];
1473 iwe
.u
.data
.flags
= 1;
1474 current_ev
= iwe_stream_add_point_check(info
,
1478 if (IS_ERR(current_ev
))
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;
1486 current_ev
= iwe_stream_add_point_check(info
,
1490 if (IS_ERR(current_ev
))
1493 case WLAN_EID_MESH_CONFIG
:
1495 if (ie
[1] != sizeof(struct ieee80211_meshconf_ie
))
1498 memset(&iwe
, 0, sizeof(iwe
));
1499 iwe
.cmd
= IWEVCUSTOM
;
1500 sprintf(buf
, "Mesh Network Path Selection Protocol ID: "
1502 iwe
.u
.data
.length
= strlen(buf
);
1503 current_ev
= iwe_stream_add_point_check(info
,
1507 if (IS_ERR(current_ev
))
1509 sprintf(buf
, "Path Selection Metric ID: 0x%02X",
1511 iwe
.u
.data
.length
= strlen(buf
);
1512 current_ev
= iwe_stream_add_point_check(info
,
1516 if (IS_ERR(current_ev
))
1518 sprintf(buf
, "Congestion Control Mode ID: 0x%02X",
1520 iwe
.u
.data
.length
= strlen(buf
);
1521 current_ev
= iwe_stream_add_point_check(info
,
1525 if (IS_ERR(current_ev
))
1527 sprintf(buf
, "Synchronization ID: 0x%02X", cfg
[3]);
1528 iwe
.u
.data
.length
= strlen(buf
);
1529 current_ev
= iwe_stream_add_point_check(info
,
1533 if (IS_ERR(current_ev
))
1535 sprintf(buf
, "Authentication ID: 0x%02X", cfg
[4]);
1536 iwe
.u
.data
.length
= strlen(buf
);
1537 current_ev
= iwe_stream_add_point_check(info
,
1541 if (IS_ERR(current_ev
))
1543 sprintf(buf
, "Formation Info: 0x%02X", cfg
[5]);
1544 iwe
.u
.data
.length
= strlen(buf
);
1545 current_ev
= iwe_stream_add_point_check(info
,
1549 if (IS_ERR(current_ev
))
1551 sprintf(buf
, "Capabilities: 0x%02X", cfg
[6]);
1552 iwe
.u
.data
.length
= strlen(buf
);
1553 current_ev
= iwe_stream_add_point_check(info
,
1557 if (IS_ERR(current_ev
))
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
);
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;
1570 for (i
= 0; i
< ie
[1]; i
++) {
1571 iwe
.u
.bitrate
.value
=
1572 ((ie
[i
+ 2] & 0x7f) * 500000);
1574 p
= iwe_stream_add_value(info
, current_ev
, p
,
1578 current_ev
= ERR_PTR(-E2BIG
);
1589 if (bss
->pub
.capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
) ||
1591 memset(&iwe
, 0, sizeof(iwe
));
1592 iwe
.cmd
= SIOCGIWMODE
;
1594 iwe
.u
.mode
= IW_MODE_MESH
;
1595 else if (bss
->pub
.capability
& WLAN_CAPABILITY_ESS
)
1596 iwe
.u
.mode
= IW_MODE_MASTER
;
1598 iwe
.u
.mode
= IW_MODE_ADHOC
;
1599 current_ev
= iwe_stream_add_event_check(info
, current_ev
,
1602 if (IS_ERR(current_ev
))
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
,
1612 if (IS_ERR(current_ev
))
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
))
1624 current_ev
= ieee80211_scan_add_ies(info
, ies
, current_ev
, end_buf
);
1632 static int ieee80211_scan_results(struct cfg80211_registered_device
*rdev
,
1633 struct iw_request_info
*info
,
1634 char *buf
, size_t len
)
1636 char *current_ev
= buf
;
1637 char *end_buf
= buf
+ len
;
1638 struct cfg80211_internal_bss
*bss
;
1641 spin_lock_bh(&rdev
->bss_lock
);
1642 cfg80211_bss_expire(rdev
);
1644 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
1645 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
1649 current_ev
= ieee80211_bss(&rdev
->wiphy
, info
, bss
,
1650 current_ev
, end_buf
);
1651 if (IS_ERR(current_ev
)) {
1652 err
= PTR_ERR(current_ev
);
1656 spin_unlock_bh(&rdev
->bss_lock
);
1660 return current_ev
- buf
;
1664 int cfg80211_wext_giwscan(struct net_device
*dev
,
1665 struct iw_request_info
*info
,
1666 struct iw_point
*data
, char *extra
)
1668 struct cfg80211_registered_device
*rdev
;
1671 if (!netif_running(dev
))
1674 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
1677 return PTR_ERR(rdev
);
1679 if (rdev
->scan_req
|| rdev
->scan_msg
)
1682 res
= ieee80211_scan_results(rdev
, info
, extra
, data
->length
);
1691 EXPORT_WEXT_HANDLER(cfg80211_wext_giwscan
);