1 // SPDX-License-Identifier: GPL-2.0
3 * cfg80211 scan result handling
5 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 * Copyright 2016 Intel Deutschland GmbH
8 * Copyright (C) 2018-2019 Intel Corporation
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
12 #include <linux/module.h>
13 #include <linux/netdevice.h>
14 #include <linux/wireless.h>
15 #include <linux/nl80211.h>
16 #include <linux/etherdevice.h>
18 #include <net/cfg80211.h>
19 #include <net/cfg80211-wext.h>
20 #include <net/iw_handler.h>
23 #include "wext-compat.h"
27 * DOC: BSS tree/list structure
29 * At the top level, the BSS list is kept in both a list in each
30 * registered device (@bss_list) as well as an RB-tree for faster
31 * lookup. In the RB-tree, entries can be looked up using their
32 * channel, MESHID, MESHCONF (for MBSSes) or channel, BSSID, SSID
35 * Due to the possibility of hidden SSIDs, there's a second level
36 * structure, the "hidden_list" and "hidden_beacon_bss" pointer.
37 * The hidden_list connects all BSSes belonging to a single AP
38 * that has a hidden SSID, and connects beacon and probe response
39 * entries. For a probe response entry for a hidden SSID, the
40 * hidden_beacon_bss pointer points to the BSS struct holding the
41 * beacon's information.
43 * Reference counting is done for all these references except for
44 * the hidden_list, so that a beacon BSS struct that is otherwise
45 * not referenced has one reference for being on the bss_list and
46 * one for each probe response entry that points to it using the
47 * hidden_beacon_bss pointer. When a BSS struct that has such a
48 * pointer is get/put, the refcount update is also propagated to
49 * the referenced struct, this ensure that it cannot get removed
50 * while somebody is using the probe response version.
52 * Note that the hidden_beacon_bss pointer never changes, due to
53 * the reference counting. Therefore, no locking is needed for
56 * Also note that the hidden_beacon_bss pointer is only relevant
57 * if the driver uses something other than the IEs, e.g. private
58 * data stored stored in the BSS struct, since the beacon IEs are
59 * also linked into the probe response struct.
63 * Limit the number of BSS entries stored in mac80211. Each one is
64 * a bit over 4k at most, so this limits to roughly 4-5M of memory.
65 * If somebody wants to really attack this though, they'd likely
66 * use small beacons, and only one type of frame, limiting each of
67 * the entries to a much smaller size (in order to generate more
68 * entries in total, so overhead is bigger.)
70 static int bss_entries_limit
= 1000;
71 module_param(bss_entries_limit
, int, 0644);
72 MODULE_PARM_DESC(bss_entries_limit
,
73 "limit to number of scan BSS entries (per wiphy, default 1000)");
75 #define IEEE80211_SCAN_RESULT_EXPIRE (30 * HZ)
77 static void bss_free(struct cfg80211_internal_bss
*bss
)
79 struct cfg80211_bss_ies
*ies
;
81 if (WARN_ON(atomic_read(&bss
->hold
)))
84 ies
= (void *)rcu_access_pointer(bss
->pub
.beacon_ies
);
85 if (ies
&& !bss
->pub
.hidden_beacon_bss
)
86 kfree_rcu(ies
, rcu_head
);
87 ies
= (void *)rcu_access_pointer(bss
->pub
.proberesp_ies
);
89 kfree_rcu(ies
, rcu_head
);
92 * This happens when the module is removed, it doesn't
93 * really matter any more save for completeness
95 if (!list_empty(&bss
->hidden_list
))
96 list_del(&bss
->hidden_list
);
101 static inline void bss_ref_get(struct cfg80211_registered_device
*rdev
,
102 struct cfg80211_internal_bss
*bss
)
104 lockdep_assert_held(&rdev
->bss_lock
);
107 if (bss
->pub
.hidden_beacon_bss
) {
108 bss
= container_of(bss
->pub
.hidden_beacon_bss
,
109 struct cfg80211_internal_bss
,
113 if (bss
->pub
.transmitted_bss
) {
114 bss
= container_of(bss
->pub
.transmitted_bss
,
115 struct cfg80211_internal_bss
,
121 static inline void bss_ref_put(struct cfg80211_registered_device
*rdev
,
122 struct cfg80211_internal_bss
*bss
)
124 lockdep_assert_held(&rdev
->bss_lock
);
126 if (bss
->pub
.hidden_beacon_bss
) {
127 struct cfg80211_internal_bss
*hbss
;
128 hbss
= container_of(bss
->pub
.hidden_beacon_bss
,
129 struct cfg80211_internal_bss
,
132 if (hbss
->refcount
== 0)
136 if (bss
->pub
.transmitted_bss
) {
137 struct cfg80211_internal_bss
*tbss
;
139 tbss
= container_of(bss
->pub
.transmitted_bss
,
140 struct cfg80211_internal_bss
,
143 if (tbss
->refcount
== 0)
148 if (bss
->refcount
== 0)
152 static bool __cfg80211_unlink_bss(struct cfg80211_registered_device
*rdev
,
153 struct cfg80211_internal_bss
*bss
)
155 lockdep_assert_held(&rdev
->bss_lock
);
157 if (!list_empty(&bss
->hidden_list
)) {
159 * don't remove the beacon entry if it has
160 * probe responses associated with it
162 if (!bss
->pub
.hidden_beacon_bss
)
165 * if it's a probe response entry break its
166 * link to the other entries in the group
168 list_del_init(&bss
->hidden_list
);
171 list_del_init(&bss
->list
);
172 list_del_init(&bss
->pub
.nontrans_list
);
173 rb_erase(&bss
->rbn
, &rdev
->bss_tree
);
175 WARN_ONCE((rdev
->bss_entries
== 0) ^ list_empty(&rdev
->bss_list
),
176 "rdev bss entries[%d]/list[empty:%d] corruption\n",
177 rdev
->bss_entries
, list_empty(&rdev
->bss_list
));
178 bss_ref_put(rdev
, bss
);
182 bool cfg80211_is_element_inherited(const struct element
*elem
,
183 const struct element
*non_inherit_elem
)
185 u8 id_len
, ext_id_len
, i
, loop_len
, id
;
188 if (elem
->id
== WLAN_EID_MULTIPLE_BSSID
)
191 if (!non_inherit_elem
|| non_inherit_elem
->datalen
< 2)
195 * non inheritance element format is:
196 * ext ID (56) | IDs list len | list | extension IDs list len | list
197 * Both lists are optional. Both lengths are mandatory.
198 * This means valid length is:
199 * elem_len = 1 (extension ID) + 2 (list len fields) + list lengths
201 id_len
= non_inherit_elem
->data
[1];
202 if (non_inherit_elem
->datalen
< 3 + id_len
)
205 ext_id_len
= non_inherit_elem
->data
[2 + id_len
];
206 if (non_inherit_elem
->datalen
< 3 + id_len
+ ext_id_len
)
209 if (elem
->id
== WLAN_EID_EXTENSION
) {
212 loop_len
= ext_id_len
;
213 list
= &non_inherit_elem
->data
[3 + id_len
];
219 list
= &non_inherit_elem
->data
[2];
223 for (i
= 0; i
< loop_len
; i
++) {
230 EXPORT_SYMBOL(cfg80211_is_element_inherited
);
232 static size_t cfg80211_gen_new_ie(const u8
*ie
, size_t ielen
,
233 const u8
*subelement
, size_t subie_len
,
234 u8
*new_ie
, gfp_t gfp
)
237 const u8
*tmp_old
, *tmp_new
;
238 const struct element
*non_inherit_elem
;
241 /* copy subelement as we need to change its content to
242 * mark an ie after it is processed.
244 sub_copy
= kmemdup(subelement
, subie_len
, gfp
);
251 tmp_new
= cfg80211_find_ie(WLAN_EID_SSID
, sub_copy
, subie_len
);
253 memcpy(pos
, tmp_new
, tmp_new
[1] + 2);
254 pos
+= (tmp_new
[1] + 2);
257 /* get non inheritance list if exists */
259 cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE
,
260 sub_copy
, subie_len
);
262 /* go through IEs in ie (skip SSID) and subelement,
263 * merge them into new_ie
265 tmp_old
= cfg80211_find_ie(WLAN_EID_SSID
, ie
, ielen
);
266 tmp_old
= (tmp_old
) ? tmp_old
+ tmp_old
[1] + 2 : ie
;
268 while (tmp_old
+ tmp_old
[1] + 2 - ie
<= ielen
) {
269 if (tmp_old
[0] == 0) {
274 if (tmp_old
[0] == WLAN_EID_EXTENSION
)
275 tmp
= (u8
*)cfg80211_find_ext_ie(tmp_old
[2], sub_copy
,
278 tmp
= (u8
*)cfg80211_find_ie(tmp_old
[0], sub_copy
,
282 const struct element
*old_elem
= (void *)tmp_old
;
284 /* ie in old ie but not in subelement */
285 if (cfg80211_is_element_inherited(old_elem
,
287 memcpy(pos
, tmp_old
, tmp_old
[1] + 2);
288 pos
+= tmp_old
[1] + 2;
291 /* ie in transmitting ie also in subelement,
292 * copy from subelement and flag the ie in subelement
293 * as copied (by setting eid field to WLAN_EID_SSID,
294 * which is skipped anyway).
295 * For vendor ie, compare OUI + type + subType to
296 * determine if they are the same ie.
298 if (tmp_old
[0] == WLAN_EID_VENDOR_SPECIFIC
) {
299 if (!memcmp(tmp_old
+ 2, tmp
+ 2, 5)) {
300 /* same vendor ie, copy from
303 memcpy(pos
, tmp
, tmp
[1] + 2);
305 tmp
[0] = WLAN_EID_SSID
;
307 memcpy(pos
, tmp_old
, tmp_old
[1] + 2);
308 pos
+= tmp_old
[1] + 2;
311 /* copy ie from subelement into new ie */
312 memcpy(pos
, tmp
, tmp
[1] + 2);
314 tmp
[0] = WLAN_EID_SSID
;
318 if (tmp_old
+ tmp_old
[1] + 2 - ie
== ielen
)
321 tmp_old
+= tmp_old
[1] + 2;
324 /* go through subelement again to check if there is any ie not
325 * copied to new ie, skip ssid, capability, bssid-index ie
328 while (tmp_new
+ tmp_new
[1] + 2 - sub_copy
<= subie_len
) {
329 if (!(tmp_new
[0] == WLAN_EID_NON_TX_BSSID_CAP
||
330 tmp_new
[0] == WLAN_EID_SSID
)) {
331 memcpy(pos
, tmp_new
, tmp_new
[1] + 2);
332 pos
+= tmp_new
[1] + 2;
334 if (tmp_new
+ tmp_new
[1] + 2 - sub_copy
== subie_len
)
336 tmp_new
+= tmp_new
[1] + 2;
343 static bool is_bss(struct cfg80211_bss
*a
, const u8
*bssid
,
344 const u8
*ssid
, size_t ssid_len
)
346 const struct cfg80211_bss_ies
*ies
;
349 if (bssid
&& !ether_addr_equal(a
->bssid
, bssid
))
355 ies
= rcu_access_pointer(a
->ies
);
358 ssidie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
361 if (ssidie
[1] != ssid_len
)
363 return memcmp(ssidie
+ 2, ssid
, ssid_len
) == 0;
367 cfg80211_add_nontrans_list(struct cfg80211_bss
*trans_bss
,
368 struct cfg80211_bss
*nontrans_bss
)
372 struct cfg80211_bss
*bss
= NULL
;
375 ssid
= ieee80211_bss_get_ie(nontrans_bss
, WLAN_EID_SSID
);
384 /* check if nontrans_bss is in the list */
385 list_for_each_entry(bss
, &trans_bss
->nontrans_list
, nontrans_list
) {
386 if (is_bss(bss
, nontrans_bss
->bssid
, ssid
, ssid_len
))
390 /* add to the list */
391 list_add_tail(&nontrans_bss
->nontrans_list
, &trans_bss
->nontrans_list
);
395 static void __cfg80211_bss_expire(struct cfg80211_registered_device
*rdev
,
396 unsigned long expire_time
)
398 struct cfg80211_internal_bss
*bss
, *tmp
;
399 bool expired
= false;
401 lockdep_assert_held(&rdev
->bss_lock
);
403 list_for_each_entry_safe(bss
, tmp
, &rdev
->bss_list
, list
) {
404 if (atomic_read(&bss
->hold
))
406 if (!time_after(expire_time
, bss
->ts
))
409 if (__cfg80211_unlink_bss(rdev
, bss
))
414 rdev
->bss_generation
++;
417 static bool cfg80211_bss_expire_oldest(struct cfg80211_registered_device
*rdev
)
419 struct cfg80211_internal_bss
*bss
, *oldest
= NULL
;
422 lockdep_assert_held(&rdev
->bss_lock
);
424 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
425 if (atomic_read(&bss
->hold
))
428 if (!list_empty(&bss
->hidden_list
) &&
429 !bss
->pub
.hidden_beacon_bss
)
432 if (oldest
&& time_before(oldest
->ts
, bss
->ts
))
437 if (WARN_ON(!oldest
))
441 * The callers make sure to increase rdev->bss_generation if anything
442 * gets removed (and a new entry added), so there's no need to also do
446 ret
= __cfg80211_unlink_bss(rdev
, oldest
);
451 void ___cfg80211_scan_done(struct cfg80211_registered_device
*rdev
,
454 struct cfg80211_scan_request
*request
;
455 struct wireless_dev
*wdev
;
457 #ifdef CONFIG_CFG80211_WEXT
458 union iwreq_data wrqu
;
463 if (rdev
->scan_msg
) {
464 nl80211_send_scan_msg(rdev
, rdev
->scan_msg
);
465 rdev
->scan_msg
= NULL
;
469 request
= rdev
->scan_req
;
473 wdev
= request
->wdev
;
476 * This must be before sending the other events!
477 * Otherwise, wpa_supplicant gets completely confused with
481 cfg80211_sme_scan_done(wdev
->netdev
);
483 if (!request
->info
.aborted
&&
484 request
->flags
& NL80211_SCAN_FLAG_FLUSH
) {
485 /* flush entries from previous scans */
486 spin_lock_bh(&rdev
->bss_lock
);
487 __cfg80211_bss_expire(rdev
, request
->scan_start
);
488 spin_unlock_bh(&rdev
->bss_lock
);
491 msg
= nl80211_build_scan_msg(rdev
, wdev
, request
->info
.aborted
);
493 #ifdef CONFIG_CFG80211_WEXT
494 if (wdev
->netdev
&& !request
->info
.aborted
) {
495 memset(&wrqu
, 0, sizeof(wrqu
));
497 wireless_send_event(wdev
->netdev
, SIOCGIWSCAN
, &wrqu
, NULL
);
502 dev_put(wdev
->netdev
);
504 rdev
->scan_req
= NULL
;
508 rdev
->scan_msg
= msg
;
510 nl80211_send_scan_msg(rdev
, msg
);
513 void __cfg80211_scan_done(struct work_struct
*wk
)
515 struct cfg80211_registered_device
*rdev
;
517 rdev
= container_of(wk
, struct cfg80211_registered_device
,
521 ___cfg80211_scan_done(rdev
, true);
525 void cfg80211_scan_done(struct cfg80211_scan_request
*request
,
526 struct cfg80211_scan_info
*info
)
528 trace_cfg80211_scan_done(request
, info
);
529 WARN_ON(request
!= wiphy_to_rdev(request
->wiphy
)->scan_req
);
531 request
->info
= *info
;
532 request
->notified
= true;
533 queue_work(cfg80211_wq
, &wiphy_to_rdev(request
->wiphy
)->scan_done_wk
);
535 EXPORT_SYMBOL(cfg80211_scan_done
);
537 void cfg80211_add_sched_scan_req(struct cfg80211_registered_device
*rdev
,
538 struct cfg80211_sched_scan_request
*req
)
542 list_add_rcu(&req
->list
, &rdev
->sched_scan_req_list
);
545 static void cfg80211_del_sched_scan_req(struct cfg80211_registered_device
*rdev
,
546 struct cfg80211_sched_scan_request
*req
)
550 list_del_rcu(&req
->list
);
551 kfree_rcu(req
, rcu_head
);
554 static struct cfg80211_sched_scan_request
*
555 cfg80211_find_sched_scan_req(struct cfg80211_registered_device
*rdev
, u64 reqid
)
557 struct cfg80211_sched_scan_request
*pos
;
559 list_for_each_entry_rcu(pos
, &rdev
->sched_scan_req_list
, list
,
560 lockdep_rtnl_is_held()) {
561 if (pos
->reqid
== reqid
)
568 * Determines if a scheduled scan request can be handled. When a legacy
569 * scheduled scan is running no other scheduled scan is allowed regardless
570 * whether the request is for legacy or multi-support scan. When a multi-support
571 * scheduled scan is running a request for legacy scan is not allowed. In this
572 * case a request for multi-support scan can be handled if resources are
573 * available, ie. struct wiphy::max_sched_scan_reqs limit is not yet reached.
575 int cfg80211_sched_scan_req_possible(struct cfg80211_registered_device
*rdev
,
578 struct cfg80211_sched_scan_request
*pos
;
581 list_for_each_entry(pos
, &rdev
->sched_scan_req_list
, list
) {
582 /* request id zero means legacy in progress */
583 if (!i
&& !pos
->reqid
)
589 /* no legacy allowed when multi request(s) are active */
593 /* resource limit reached */
594 if (i
== rdev
->wiphy
.max_sched_scan_reqs
)
600 void cfg80211_sched_scan_results_wk(struct work_struct
*work
)
602 struct cfg80211_registered_device
*rdev
;
603 struct cfg80211_sched_scan_request
*req
, *tmp
;
605 rdev
= container_of(work
, struct cfg80211_registered_device
,
609 list_for_each_entry_safe(req
, tmp
, &rdev
->sched_scan_req_list
, list
) {
610 if (req
->report_results
) {
611 req
->report_results
= false;
612 if (req
->flags
& NL80211_SCAN_FLAG_FLUSH
) {
613 /* flush entries from previous scans */
614 spin_lock_bh(&rdev
->bss_lock
);
615 __cfg80211_bss_expire(rdev
, req
->scan_start
);
616 spin_unlock_bh(&rdev
->bss_lock
);
617 req
->scan_start
= jiffies
;
619 nl80211_send_sched_scan(req
,
620 NL80211_CMD_SCHED_SCAN_RESULTS
);
626 void cfg80211_sched_scan_results(struct wiphy
*wiphy
, u64 reqid
)
628 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
629 struct cfg80211_sched_scan_request
*request
;
631 trace_cfg80211_sched_scan_results(wiphy
, reqid
);
632 /* ignore if we're not scanning */
635 request
= cfg80211_find_sched_scan_req(rdev
, reqid
);
637 request
->report_results
= true;
638 queue_work(cfg80211_wq
, &rdev
->sched_scan_res_wk
);
642 EXPORT_SYMBOL(cfg80211_sched_scan_results
);
644 void cfg80211_sched_scan_stopped_rtnl(struct wiphy
*wiphy
, u64 reqid
)
646 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
650 trace_cfg80211_sched_scan_stopped(wiphy
, reqid
);
652 __cfg80211_stop_sched_scan(rdev
, reqid
, true);
654 EXPORT_SYMBOL(cfg80211_sched_scan_stopped_rtnl
);
656 void cfg80211_sched_scan_stopped(struct wiphy
*wiphy
, u64 reqid
)
659 cfg80211_sched_scan_stopped_rtnl(wiphy
, reqid
);
662 EXPORT_SYMBOL(cfg80211_sched_scan_stopped
);
664 int cfg80211_stop_sched_scan_req(struct cfg80211_registered_device
*rdev
,
665 struct cfg80211_sched_scan_request
*req
,
666 bool driver_initiated
)
670 if (!driver_initiated
) {
671 int err
= rdev_sched_scan_stop(rdev
, req
->dev
, req
->reqid
);
676 nl80211_send_sched_scan(req
, NL80211_CMD_SCHED_SCAN_STOPPED
);
678 cfg80211_del_sched_scan_req(rdev
, req
);
683 int __cfg80211_stop_sched_scan(struct cfg80211_registered_device
*rdev
,
684 u64 reqid
, bool driver_initiated
)
686 struct cfg80211_sched_scan_request
*sched_scan_req
;
690 sched_scan_req
= cfg80211_find_sched_scan_req(rdev
, reqid
);
694 return cfg80211_stop_sched_scan_req(rdev
, sched_scan_req
,
698 void cfg80211_bss_age(struct cfg80211_registered_device
*rdev
,
699 unsigned long age_secs
)
701 struct cfg80211_internal_bss
*bss
;
702 unsigned long age_jiffies
= msecs_to_jiffies(age_secs
* MSEC_PER_SEC
);
704 spin_lock_bh(&rdev
->bss_lock
);
705 list_for_each_entry(bss
, &rdev
->bss_list
, list
)
706 bss
->ts
-= age_jiffies
;
707 spin_unlock_bh(&rdev
->bss_lock
);
710 void cfg80211_bss_expire(struct cfg80211_registered_device
*rdev
)
712 __cfg80211_bss_expire(rdev
, jiffies
- IEEE80211_SCAN_RESULT_EXPIRE
);
715 const struct element
*
716 cfg80211_find_elem_match(u8 eid
, const u8
*ies
, unsigned int len
,
717 const u8
*match
, unsigned int match_len
,
718 unsigned int match_offset
)
720 const struct element
*elem
;
722 for_each_element_id(elem
, eid
, ies
, len
) {
723 if (elem
->datalen
>= match_offset
+ match_len
&&
724 !memcmp(elem
->data
+ match_offset
, match
, match_len
))
730 EXPORT_SYMBOL(cfg80211_find_elem_match
);
732 const struct element
*cfg80211_find_vendor_elem(unsigned int oui
, int oui_type
,
736 const struct element
*elem
;
737 u8 match
[] = { oui
>> 16, oui
>> 8, oui
, oui_type
};
738 int match_len
= (oui_type
< 0) ? 3 : sizeof(match
);
740 if (WARN_ON(oui_type
> 0xff))
743 elem
= cfg80211_find_elem_match(WLAN_EID_VENDOR_SPECIFIC
, ies
, len
,
744 match
, match_len
, 0);
746 if (!elem
|| elem
->datalen
< 4)
751 EXPORT_SYMBOL(cfg80211_find_vendor_elem
);
754 * enum bss_compare_mode - BSS compare mode
755 * @BSS_CMP_REGULAR: regular compare mode (for insertion and normal find)
756 * @BSS_CMP_HIDE_ZLEN: find hidden SSID with zero-length mode
757 * @BSS_CMP_HIDE_NUL: find hidden SSID with NUL-ed out mode
759 enum bss_compare_mode
{
765 static int cmp_bss(struct cfg80211_bss
*a
,
766 struct cfg80211_bss
*b
,
767 enum bss_compare_mode mode
)
769 const struct cfg80211_bss_ies
*a_ies
, *b_ies
;
770 const u8
*ie1
= NULL
;
771 const u8
*ie2
= NULL
;
774 if (a
->channel
!= b
->channel
)
775 return b
->channel
->center_freq
- a
->channel
->center_freq
;
777 a_ies
= rcu_access_pointer(a
->ies
);
780 b_ies
= rcu_access_pointer(b
->ies
);
784 if (WLAN_CAPABILITY_IS_STA_BSS(a
->capability
))
785 ie1
= cfg80211_find_ie(WLAN_EID_MESH_ID
,
786 a_ies
->data
, a_ies
->len
);
787 if (WLAN_CAPABILITY_IS_STA_BSS(b
->capability
))
788 ie2
= cfg80211_find_ie(WLAN_EID_MESH_ID
,
789 b_ies
->data
, b_ies
->len
);
793 if (ie1
[1] == ie2
[1])
794 mesh_id_cmp
= memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
796 mesh_id_cmp
= ie2
[1] - ie1
[1];
798 ie1
= cfg80211_find_ie(WLAN_EID_MESH_CONFIG
,
799 a_ies
->data
, a_ies
->len
);
800 ie2
= cfg80211_find_ie(WLAN_EID_MESH_CONFIG
,
801 b_ies
->data
, b_ies
->len
);
805 if (ie1
[1] != ie2
[1])
806 return ie2
[1] - ie1
[1];
807 return memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
811 r
= memcmp(a
->bssid
, b
->bssid
, sizeof(a
->bssid
));
815 ie1
= cfg80211_find_ie(WLAN_EID_SSID
, a_ies
->data
, a_ies
->len
);
816 ie2
= cfg80211_find_ie(WLAN_EID_SSID
, b_ies
->data
, b_ies
->len
);
822 * Note that with "hide_ssid", the function returns a match if
823 * the already-present BSS ("b") is a hidden SSID beacon for
827 /* sort missing IE before (left of) present IE */
834 case BSS_CMP_HIDE_ZLEN
:
836 * In ZLEN mode we assume the BSS entry we're
837 * looking for has a zero-length SSID. So if
838 * the one we're looking at right now has that,
839 * return 0. Otherwise, return the difference
840 * in length, but since we're looking for the
841 * 0-length it's really equivalent to returning
842 * the length of the one we're looking at.
844 * No content comparison is needed as we assume
845 * the content length is zero.
848 case BSS_CMP_REGULAR
:
850 /* sort by length first, then by contents */
851 if (ie1
[1] != ie2
[1])
852 return ie2
[1] - ie1
[1];
853 return memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
854 case BSS_CMP_HIDE_NUL
:
855 if (ie1
[1] != ie2
[1])
856 return ie2
[1] - ie1
[1];
857 /* this is equivalent to memcmp(zeroes, ie2 + 2, len) */
858 for (i
= 0; i
< ie2
[1]; i
++)
865 static bool cfg80211_bss_type_match(u16 capability
,
866 enum nl80211_band band
,
867 enum ieee80211_bss_type bss_type
)
872 if (bss_type
== IEEE80211_BSS_TYPE_ANY
)
875 if (band
== NL80211_BAND_60GHZ
) {
876 mask
= WLAN_CAPABILITY_DMG_TYPE_MASK
;
878 case IEEE80211_BSS_TYPE_ESS
:
879 val
= WLAN_CAPABILITY_DMG_TYPE_AP
;
881 case IEEE80211_BSS_TYPE_PBSS
:
882 val
= WLAN_CAPABILITY_DMG_TYPE_PBSS
;
884 case IEEE80211_BSS_TYPE_IBSS
:
885 val
= WLAN_CAPABILITY_DMG_TYPE_IBSS
;
891 mask
= WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
;
893 case IEEE80211_BSS_TYPE_ESS
:
894 val
= WLAN_CAPABILITY_ESS
;
896 case IEEE80211_BSS_TYPE_IBSS
:
897 val
= WLAN_CAPABILITY_IBSS
;
899 case IEEE80211_BSS_TYPE_MBSS
:
907 ret
= ((capability
& mask
) == val
);
911 /* Returned bss is reference counted and must be cleaned up appropriately. */
912 struct cfg80211_bss
*cfg80211_get_bss(struct wiphy
*wiphy
,
913 struct ieee80211_channel
*channel
,
915 const u8
*ssid
, size_t ssid_len
,
916 enum ieee80211_bss_type bss_type
,
917 enum ieee80211_privacy privacy
)
919 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
920 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
921 unsigned long now
= jiffies
;
924 trace_cfg80211_get_bss(wiphy
, channel
, bssid
, ssid
, ssid_len
, bss_type
,
927 spin_lock_bh(&rdev
->bss_lock
);
929 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
930 if (!cfg80211_bss_type_match(bss
->pub
.capability
,
931 bss
->pub
.channel
->band
, bss_type
))
934 bss_privacy
= (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
);
935 if ((privacy
== IEEE80211_PRIVACY_ON
&& !bss_privacy
) ||
936 (privacy
== IEEE80211_PRIVACY_OFF
&& bss_privacy
))
938 if (channel
&& bss
->pub
.channel
!= channel
)
940 if (!is_valid_ether_addr(bss
->pub
.bssid
))
942 /* Don't get expired BSS structs */
943 if (time_after(now
, bss
->ts
+ IEEE80211_SCAN_RESULT_EXPIRE
) &&
944 !atomic_read(&bss
->hold
))
946 if (is_bss(&bss
->pub
, bssid
, ssid
, ssid_len
)) {
948 bss_ref_get(rdev
, res
);
953 spin_unlock_bh(&rdev
->bss_lock
);
956 trace_cfg80211_return_bss(&res
->pub
);
959 EXPORT_SYMBOL(cfg80211_get_bss
);
961 static void rb_insert_bss(struct cfg80211_registered_device
*rdev
,
962 struct cfg80211_internal_bss
*bss
)
964 struct rb_node
**p
= &rdev
->bss_tree
.rb_node
;
965 struct rb_node
*parent
= NULL
;
966 struct cfg80211_internal_bss
*tbss
;
971 tbss
= rb_entry(parent
, struct cfg80211_internal_bss
, rbn
);
973 cmp
= cmp_bss(&bss
->pub
, &tbss
->pub
, BSS_CMP_REGULAR
);
976 /* will sort of leak this BSS */
986 rb_link_node(&bss
->rbn
, parent
, p
);
987 rb_insert_color(&bss
->rbn
, &rdev
->bss_tree
);
990 static struct cfg80211_internal_bss
*
991 rb_find_bss(struct cfg80211_registered_device
*rdev
,
992 struct cfg80211_internal_bss
*res
,
993 enum bss_compare_mode mode
)
995 struct rb_node
*n
= rdev
->bss_tree
.rb_node
;
996 struct cfg80211_internal_bss
*bss
;
1000 bss
= rb_entry(n
, struct cfg80211_internal_bss
, rbn
);
1001 r
= cmp_bss(&res
->pub
, &bss
->pub
, mode
);
1014 static bool cfg80211_combine_bsses(struct cfg80211_registered_device
*rdev
,
1015 struct cfg80211_internal_bss
*new)
1017 const struct cfg80211_bss_ies
*ies
;
1018 struct cfg80211_internal_bss
*bss
;
1024 ies
= rcu_access_pointer(new->pub
.beacon_ies
);
1028 ie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
1035 for (i
= 0; i
< ssidlen
; i
++)
1039 /* not a hidden SSID */
1043 /* This is the bad part ... */
1045 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
1047 * we're iterating all the entries anyway, so take the
1048 * opportunity to validate the list length accounting
1052 if (!ether_addr_equal(bss
->pub
.bssid
, new->pub
.bssid
))
1054 if (bss
->pub
.channel
!= new->pub
.channel
)
1056 if (bss
->pub
.scan_width
!= new->pub
.scan_width
)
1058 if (rcu_access_pointer(bss
->pub
.beacon_ies
))
1060 ies
= rcu_access_pointer(bss
->pub
.ies
);
1063 ie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
1066 if (ssidlen
&& ie
[1] != ssidlen
)
1068 if (WARN_ON_ONCE(bss
->pub
.hidden_beacon_bss
))
1070 if (WARN_ON_ONCE(!list_empty(&bss
->hidden_list
)))
1071 list_del(&bss
->hidden_list
);
1073 list_add(&bss
->hidden_list
, &new->hidden_list
);
1074 bss
->pub
.hidden_beacon_bss
= &new->pub
;
1075 new->refcount
+= bss
->refcount
;
1076 rcu_assign_pointer(bss
->pub
.beacon_ies
,
1077 new->pub
.beacon_ies
);
1080 WARN_ONCE(n_entries
!= rdev
->bss_entries
,
1081 "rdev bss entries[%d]/list[len:%d] corruption\n",
1082 rdev
->bss_entries
, n_entries
);
1087 struct cfg80211_non_tx_bss
{
1088 struct cfg80211_bss
*tx_bss
;
1089 u8 max_bssid_indicator
;
1094 cfg80211_update_known_bss(struct cfg80211_registered_device
*rdev
,
1095 struct cfg80211_internal_bss
*known
,
1096 struct cfg80211_internal_bss
*new,
1099 lockdep_assert_held(&rdev
->bss_lock
);
1102 if (rcu_access_pointer(new->pub
.proberesp_ies
)) {
1103 const struct cfg80211_bss_ies
*old
;
1105 old
= rcu_access_pointer(known
->pub
.proberesp_ies
);
1107 rcu_assign_pointer(known
->pub
.proberesp_ies
,
1108 new->pub
.proberesp_ies
);
1109 /* Override possible earlier Beacon frame IEs */
1110 rcu_assign_pointer(known
->pub
.ies
,
1111 new->pub
.proberesp_ies
);
1113 kfree_rcu((struct cfg80211_bss_ies
*)old
, rcu_head
);
1114 } else if (rcu_access_pointer(new->pub
.beacon_ies
)) {
1115 const struct cfg80211_bss_ies
*old
;
1116 struct cfg80211_internal_bss
*bss
;
1118 if (known
->pub
.hidden_beacon_bss
&&
1119 !list_empty(&known
->hidden_list
)) {
1120 const struct cfg80211_bss_ies
*f
;
1122 /* The known BSS struct is one of the probe
1123 * response members of a group, but we're
1124 * receiving a beacon (beacon_ies in the new
1125 * bss is used). This can only mean that the
1126 * AP changed its beacon from not having an
1127 * SSID to showing it, which is confusing so
1128 * drop this information.
1131 f
= rcu_access_pointer(new->pub
.beacon_ies
);
1132 kfree_rcu((struct cfg80211_bss_ies
*)f
, rcu_head
);
1136 old
= rcu_access_pointer(known
->pub
.beacon_ies
);
1138 rcu_assign_pointer(known
->pub
.beacon_ies
, new->pub
.beacon_ies
);
1140 /* Override IEs if they were from a beacon before */
1141 if (old
== rcu_access_pointer(known
->pub
.ies
))
1142 rcu_assign_pointer(known
->pub
.ies
, new->pub
.beacon_ies
);
1144 /* Assign beacon IEs to all sub entries */
1145 list_for_each_entry(bss
, &known
->hidden_list
, hidden_list
) {
1146 const struct cfg80211_bss_ies
*ies
;
1148 ies
= rcu_access_pointer(bss
->pub
.beacon_ies
);
1149 WARN_ON(ies
!= old
);
1151 rcu_assign_pointer(bss
->pub
.beacon_ies
,
1152 new->pub
.beacon_ies
);
1156 kfree_rcu((struct cfg80211_bss_ies
*)old
, rcu_head
);
1159 known
->pub
.beacon_interval
= new->pub
.beacon_interval
;
1161 /* don't update the signal if beacon was heard on
1165 known
->pub
.signal
= new->pub
.signal
;
1166 known
->pub
.capability
= new->pub
.capability
;
1167 known
->ts
= new->ts
;
1168 known
->ts_boottime
= new->ts_boottime
;
1169 known
->parent_tsf
= new->parent_tsf
;
1170 known
->pub
.chains
= new->pub
.chains
;
1171 memcpy(known
->pub
.chain_signal
, new->pub
.chain_signal
,
1172 IEEE80211_MAX_CHAINS
);
1173 ether_addr_copy(known
->parent_bssid
, new->parent_bssid
);
1174 known
->pub
.max_bssid_indicator
= new->pub
.max_bssid_indicator
;
1175 known
->pub
.bssid_index
= new->pub
.bssid_index
;
1180 /* Returned bss is reference counted and must be cleaned up appropriately. */
1181 struct cfg80211_internal_bss
*
1182 cfg80211_bss_update(struct cfg80211_registered_device
*rdev
,
1183 struct cfg80211_internal_bss
*tmp
,
1184 bool signal_valid
, unsigned long ts
)
1186 struct cfg80211_internal_bss
*found
= NULL
;
1188 if (WARN_ON(!tmp
->pub
.channel
))
1193 spin_lock_bh(&rdev
->bss_lock
);
1195 if (WARN_ON(!rcu_access_pointer(tmp
->pub
.ies
))) {
1196 spin_unlock_bh(&rdev
->bss_lock
);
1200 found
= rb_find_bss(rdev
, tmp
, BSS_CMP_REGULAR
);
1203 if (!cfg80211_update_known_bss(rdev
, found
, tmp
, signal_valid
))
1206 struct cfg80211_internal_bss
*new;
1207 struct cfg80211_internal_bss
*hidden
;
1208 struct cfg80211_bss_ies
*ies
;
1211 * create a copy -- the "res" variable that is passed in
1212 * is allocated on the stack since it's not needed in the
1213 * more common case of an update
1215 new = kzalloc(sizeof(*new) + rdev
->wiphy
.bss_priv_size
,
1218 ies
= (void *)rcu_dereference(tmp
->pub
.beacon_ies
);
1220 kfree_rcu(ies
, rcu_head
);
1221 ies
= (void *)rcu_dereference(tmp
->pub
.proberesp_ies
);
1223 kfree_rcu(ies
, rcu_head
);
1226 memcpy(new, tmp
, sizeof(*new));
1228 INIT_LIST_HEAD(&new->hidden_list
);
1229 INIT_LIST_HEAD(&new->pub
.nontrans_list
);
1231 if (rcu_access_pointer(tmp
->pub
.proberesp_ies
)) {
1232 hidden
= rb_find_bss(rdev
, tmp
, BSS_CMP_HIDE_ZLEN
);
1234 hidden
= rb_find_bss(rdev
, tmp
,
1237 new->pub
.hidden_beacon_bss
= &hidden
->pub
;
1238 list_add(&new->hidden_list
,
1239 &hidden
->hidden_list
);
1241 rcu_assign_pointer(new->pub
.beacon_ies
,
1242 hidden
->pub
.beacon_ies
);
1246 * Ok so we found a beacon, and don't have an entry. If
1247 * it's a beacon with hidden SSID, we might be in for an
1248 * expensive search for any probe responses that should
1249 * be grouped with this beacon for updates ...
1251 if (!cfg80211_combine_bsses(rdev
, new)) {
1257 if (rdev
->bss_entries
>= bss_entries_limit
&&
1258 !cfg80211_bss_expire_oldest(rdev
)) {
1263 /* This must be before the call to bss_ref_get */
1264 if (tmp
->pub
.transmitted_bss
) {
1265 struct cfg80211_internal_bss
*pbss
=
1266 container_of(tmp
->pub
.transmitted_bss
,
1267 struct cfg80211_internal_bss
,
1270 new->pub
.transmitted_bss
= tmp
->pub
.transmitted_bss
;
1271 bss_ref_get(rdev
, pbss
);
1274 list_add_tail(&new->list
, &rdev
->bss_list
);
1275 rdev
->bss_entries
++;
1276 rb_insert_bss(rdev
, new);
1280 rdev
->bss_generation
++;
1281 bss_ref_get(rdev
, found
);
1282 spin_unlock_bh(&rdev
->bss_lock
);
1286 spin_unlock_bh(&rdev
->bss_lock
);
1291 * Update RX channel information based on the available frame payload
1292 * information. This is mainly for the 2.4 GHz band where frames can be received
1293 * from neighboring channels and the Beacon frames use the DSSS Parameter Set
1294 * element to indicate the current (transmitting) channel, but this might also
1295 * be needed on other bands if RX frequency does not match with the actual
1296 * operating channel of a BSS.
1298 static struct ieee80211_channel
*
1299 cfg80211_get_bss_channel(struct wiphy
*wiphy
, const u8
*ie
, size_t ielen
,
1300 struct ieee80211_channel
*channel
,
1301 enum nl80211_bss_scan_width scan_width
)
1305 int channel_number
= -1;
1306 struct ieee80211_channel
*alt_channel
;
1308 tmp
= cfg80211_find_ie(WLAN_EID_DS_PARAMS
, ie
, ielen
);
1309 if (tmp
&& tmp
[1] == 1) {
1310 channel_number
= tmp
[2];
1312 tmp
= cfg80211_find_ie(WLAN_EID_HT_OPERATION
, ie
, ielen
);
1313 if (tmp
&& tmp
[1] >= sizeof(struct ieee80211_ht_operation
)) {
1314 struct ieee80211_ht_operation
*htop
= (void *)(tmp
+ 2);
1316 channel_number
= htop
->primary_chan
;
1320 if (channel_number
< 0) {
1321 /* No channel information in frame payload */
1325 freq
= ieee80211_channel_to_frequency(channel_number
, channel
->band
);
1326 alt_channel
= ieee80211_get_channel(wiphy
, freq
);
1328 if (channel
->band
== NL80211_BAND_2GHZ
) {
1330 * Better not allow unexpected channels when that could
1331 * be going beyond the 1-11 range (e.g., discovering
1332 * BSS on channel 12 when radio is configured for
1338 /* No match for the payload channel number - ignore it */
1342 if (scan_width
== NL80211_BSS_CHAN_WIDTH_10
||
1343 scan_width
== NL80211_BSS_CHAN_WIDTH_5
) {
1345 * Ignore channel number in 5 and 10 MHz channels where there
1346 * may not be an n:1 or 1:n mapping between frequencies and
1353 * Use the channel determined through the payload channel number
1354 * instead of the RX channel reported by the driver.
1356 if (alt_channel
->flags
& IEEE80211_CHAN_DISABLED
)
1361 /* Returned bss is reference counted and must be cleaned up appropriately. */
1362 static struct cfg80211_bss
*
1363 cfg80211_inform_single_bss_data(struct wiphy
*wiphy
,
1364 struct cfg80211_inform_bss
*data
,
1365 enum cfg80211_bss_frame_type ftype
,
1366 const u8
*bssid
, u64 tsf
, u16 capability
,
1367 u16 beacon_interval
, const u8
*ie
, size_t ielen
,
1368 struct cfg80211_non_tx_bss
*non_tx_data
,
1371 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1372 struct cfg80211_bss_ies
*ies
;
1373 struct ieee80211_channel
*channel
;
1374 struct cfg80211_internal_bss tmp
= {}, *res
;
1379 if (WARN_ON(!wiphy
))
1382 if (WARN_ON(wiphy
->signal_type
== CFG80211_SIGNAL_TYPE_UNSPEC
&&
1383 (data
->signal
< 0 || data
->signal
> 100)))
1386 channel
= cfg80211_get_bss_channel(wiphy
, ie
, ielen
, data
->chan
,
1391 memcpy(tmp
.pub
.bssid
, bssid
, ETH_ALEN
);
1392 tmp
.pub
.channel
= channel
;
1393 tmp
.pub
.scan_width
= data
->scan_width
;
1394 tmp
.pub
.signal
= data
->signal
;
1395 tmp
.pub
.beacon_interval
= beacon_interval
;
1396 tmp
.pub
.capability
= capability
;
1397 tmp
.ts_boottime
= data
->boottime_ns
;
1399 tmp
.pub
.transmitted_bss
= non_tx_data
->tx_bss
;
1400 ts
= bss_from_pub(non_tx_data
->tx_bss
)->ts
;
1401 tmp
.pub
.bssid_index
= non_tx_data
->bssid_index
;
1402 tmp
.pub
.max_bssid_indicator
= non_tx_data
->max_bssid_indicator
;
1408 * If we do not know here whether the IEs are from a Beacon or Probe
1409 * Response frame, we need to pick one of the options and only use it
1410 * with the driver that does not provide the full Beacon/Probe Response
1411 * frame. Use Beacon frame pointer to avoid indicating that this should
1412 * override the IEs pointer should we have received an earlier
1413 * indication of Probe Response data.
1415 ies
= kzalloc(sizeof(*ies
) + ielen
, gfp
);
1420 ies
->from_beacon
= false;
1421 memcpy(ies
->data
, ie
, ielen
);
1424 case CFG80211_BSS_FTYPE_BEACON
:
1425 ies
->from_beacon
= true;
1427 case CFG80211_BSS_FTYPE_UNKNOWN
:
1428 rcu_assign_pointer(tmp
.pub
.beacon_ies
, ies
);
1430 case CFG80211_BSS_FTYPE_PRESP
:
1431 rcu_assign_pointer(tmp
.pub
.proberesp_ies
, ies
);
1434 rcu_assign_pointer(tmp
.pub
.ies
, ies
);
1436 signal_valid
= data
->chan
== channel
;
1437 res
= cfg80211_bss_update(wiphy_to_rdev(wiphy
), &tmp
, signal_valid
, ts
);
1441 if (channel
->band
== NL80211_BAND_60GHZ
) {
1442 bss_type
= res
->pub
.capability
& WLAN_CAPABILITY_DMG_TYPE_MASK
;
1443 if (bss_type
== WLAN_CAPABILITY_DMG_TYPE_AP
||
1444 bss_type
== WLAN_CAPABILITY_DMG_TYPE_PBSS
)
1445 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1447 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
1448 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1452 /* this is a nontransmitting bss, we need to add it to
1453 * transmitting bss' list if it is not there
1455 if (cfg80211_add_nontrans_list(non_tx_data
->tx_bss
,
1457 if (__cfg80211_unlink_bss(rdev
, res
))
1458 rdev
->bss_generation
++;
1462 trace_cfg80211_return_bss(&res
->pub
);
1463 /* cfg80211_bss_update gives us a referenced result */
1467 static const struct element
1468 *cfg80211_get_profile_continuation(const u8
*ie
, size_t ielen
,
1469 const struct element
*mbssid_elem
,
1470 const struct element
*sub_elem
)
1472 const u8
*mbssid_end
= mbssid_elem
->data
+ mbssid_elem
->datalen
;
1473 const struct element
*next_mbssid
;
1474 const struct element
*next_sub
;
1476 next_mbssid
= cfg80211_find_elem(WLAN_EID_MULTIPLE_BSSID
,
1478 ielen
- (mbssid_end
- ie
));
1481 * If is is not the last subelement in current MBSSID IE or there isn't
1482 * a next MBSSID IE - profile is complete.
1484 if ((sub_elem
->data
+ sub_elem
->datalen
< mbssid_end
- 1) ||
1488 /* For any length error, just return NULL */
1490 if (next_mbssid
->datalen
< 4)
1493 next_sub
= (void *)&next_mbssid
->data
[1];
1495 if (next_mbssid
->data
+ next_mbssid
->datalen
<
1496 next_sub
->data
+ next_sub
->datalen
)
1499 if (next_sub
->id
!= 0 || next_sub
->datalen
< 2)
1503 * Check if the first element in the next sub element is a start
1506 return next_sub
->data
[0] == WLAN_EID_NON_TX_BSSID_CAP
?
1510 size_t cfg80211_merge_profile(const u8
*ie
, size_t ielen
,
1511 const struct element
*mbssid_elem
,
1512 const struct element
*sub_elem
,
1513 u8
*merged_ie
, size_t max_copy_len
)
1515 size_t copied_len
= sub_elem
->datalen
;
1516 const struct element
*next_mbssid
;
1518 if (sub_elem
->datalen
> max_copy_len
)
1521 memcpy(merged_ie
, sub_elem
->data
, sub_elem
->datalen
);
1523 while ((next_mbssid
= cfg80211_get_profile_continuation(ie
, ielen
,
1526 const struct element
*next_sub
= (void *)&next_mbssid
->data
[1];
1528 if (copied_len
+ next_sub
->datalen
> max_copy_len
)
1530 memcpy(merged_ie
+ copied_len
, next_sub
->data
,
1532 copied_len
+= next_sub
->datalen
;
1537 EXPORT_SYMBOL(cfg80211_merge_profile
);
1539 static void cfg80211_parse_mbssid_data(struct wiphy
*wiphy
,
1540 struct cfg80211_inform_bss
*data
,
1541 enum cfg80211_bss_frame_type ftype
,
1542 const u8
*bssid
, u64 tsf
,
1543 u16 beacon_interval
, const u8
*ie
,
1545 struct cfg80211_non_tx_bss
*non_tx_data
,
1548 const u8
*mbssid_index_ie
;
1549 const struct element
*elem
, *sub
;
1551 u8 new_bssid
[ETH_ALEN
];
1552 u8
*new_ie
, *profile
;
1553 u64 seen_indices
= 0;
1555 struct cfg80211_bss
*bss
;
1559 if (!cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID
, ie
, ielen
))
1561 if (!wiphy
->support_mbssid
)
1563 if (wiphy
->support_only_he_mbssid
&&
1564 !cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY
, ie
, ielen
))
1567 new_ie
= kmalloc(IEEE80211_MAX_DATA_LEN
, gfp
);
1571 profile
= kmalloc(ielen
, gfp
);
1575 for_each_element_id(elem
, WLAN_EID_MULTIPLE_BSSID
, ie
, ielen
) {
1576 if (elem
->datalen
< 4)
1578 for_each_element(sub
, elem
->data
+ 1, elem
->datalen
- 1) {
1581 if (sub
->id
!= 0 || sub
->datalen
< 4) {
1582 /* not a valid BSS profile */
1586 if (sub
->data
[0] != WLAN_EID_NON_TX_BSSID_CAP
||
1587 sub
->data
[1] != 2) {
1588 /* The first element within the Nontransmitted
1589 * BSSID Profile is not the Nontransmitted
1590 * BSSID Capability element.
1595 memset(profile
, 0, ielen
);
1596 profile_len
= cfg80211_merge_profile(ie
, ielen
,
1602 /* found a Nontransmitted BSSID Profile */
1603 mbssid_index_ie
= cfg80211_find_ie
1604 (WLAN_EID_MULTI_BSSID_IDX
,
1605 profile
, profile_len
);
1606 if (!mbssid_index_ie
|| mbssid_index_ie
[1] < 1 ||
1607 mbssid_index_ie
[2] == 0 ||
1608 mbssid_index_ie
[2] > 46) {
1609 /* No valid Multiple BSSID-Index element */
1613 if (seen_indices
& BIT_ULL(mbssid_index_ie
[2]))
1614 /* We don't support legacy split of a profile */
1615 net_dbg_ratelimited("Partial info for BSSID index %d\n",
1616 mbssid_index_ie
[2]);
1618 seen_indices
|= BIT_ULL(mbssid_index_ie
[2]);
1620 non_tx_data
->bssid_index
= mbssid_index_ie
[2];
1621 non_tx_data
->max_bssid_indicator
= elem
->data
[0];
1623 cfg80211_gen_new_bssid(bssid
,
1624 non_tx_data
->max_bssid_indicator
,
1625 non_tx_data
->bssid_index
,
1627 memset(new_ie
, 0, IEEE80211_MAX_DATA_LEN
);
1628 new_ie_len
= cfg80211_gen_new_ie(ie
, ielen
,
1630 profile_len
, new_ie
,
1635 capability
= get_unaligned_le16(profile
+ 2);
1636 bss
= cfg80211_inform_single_bss_data(wiphy
, data
,
1647 cfg80211_put_bss(wiphy
, bss
);
1656 struct cfg80211_bss
*
1657 cfg80211_inform_bss_data(struct wiphy
*wiphy
,
1658 struct cfg80211_inform_bss
*data
,
1659 enum cfg80211_bss_frame_type ftype
,
1660 const u8
*bssid
, u64 tsf
, u16 capability
,
1661 u16 beacon_interval
, const u8
*ie
, size_t ielen
,
1664 struct cfg80211_bss
*res
;
1665 struct cfg80211_non_tx_bss non_tx_data
;
1667 res
= cfg80211_inform_single_bss_data(wiphy
, data
, ftype
, bssid
, tsf
,
1668 capability
, beacon_interval
, ie
,
1672 non_tx_data
.tx_bss
= res
;
1673 cfg80211_parse_mbssid_data(wiphy
, data
, ftype
, bssid
, tsf
,
1674 beacon_interval
, ie
, ielen
, &non_tx_data
,
1678 EXPORT_SYMBOL(cfg80211_inform_bss_data
);
1681 cfg80211_parse_mbssid_frame_data(struct wiphy
*wiphy
,
1682 struct cfg80211_inform_bss
*data
,
1683 struct ieee80211_mgmt
*mgmt
, size_t len
,
1684 struct cfg80211_non_tx_bss
*non_tx_data
,
1687 enum cfg80211_bss_frame_type ftype
;
1688 const u8
*ie
= mgmt
->u
.probe_resp
.variable
;
1689 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
1690 u
.probe_resp
.variable
);
1692 ftype
= ieee80211_is_beacon(mgmt
->frame_control
) ?
1693 CFG80211_BSS_FTYPE_BEACON
: CFG80211_BSS_FTYPE_PRESP
;
1695 cfg80211_parse_mbssid_data(wiphy
, data
, ftype
, mgmt
->bssid
,
1696 le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
),
1697 le16_to_cpu(mgmt
->u
.probe_resp
.beacon_int
),
1698 ie
, ielen
, non_tx_data
, gfp
);
1702 cfg80211_update_notlisted_nontrans(struct wiphy
*wiphy
,
1703 struct cfg80211_bss
*nontrans_bss
,
1704 struct ieee80211_mgmt
*mgmt
, size_t len
)
1706 u8
*ie
, *new_ie
, *pos
;
1707 const u8
*nontrans_ssid
, *trans_ssid
, *mbssid
;
1708 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
1709 u
.probe_resp
.variable
);
1711 struct cfg80211_bss_ies
*new_ies
;
1712 const struct cfg80211_bss_ies
*old
;
1715 lockdep_assert_held(&wiphy_to_rdev(wiphy
)->bss_lock
);
1717 ie
= mgmt
->u
.probe_resp
.variable
;
1720 trans_ssid
= cfg80211_find_ie(WLAN_EID_SSID
, ie
, ielen
);
1723 new_ie_len
-= trans_ssid
[1];
1724 mbssid
= cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID
, ie
, ielen
);
1726 * It's not valid to have the MBSSID element before SSID
1727 * ignore if that happens - the code below assumes it is
1728 * after (while copying things inbetween).
1730 if (!mbssid
|| mbssid
< trans_ssid
)
1732 new_ie_len
-= mbssid
[1];
1734 nontrans_ssid
= ieee80211_bss_get_ie(nontrans_bss
, WLAN_EID_SSID
);
1738 new_ie_len
+= nontrans_ssid
[1];
1740 /* generate new ie for nontrans BSS
1741 * 1. replace SSID with nontrans BSS' SSID
1744 new_ie
= kzalloc(new_ie_len
, GFP_ATOMIC
);
1748 new_ies
= kzalloc(sizeof(*new_ies
) + new_ie_len
, GFP_ATOMIC
);
1754 /* copy the nontransmitted SSID */
1755 cpy_len
= nontrans_ssid
[1] + 2;
1756 memcpy(pos
, nontrans_ssid
, cpy_len
);
1758 /* copy the IEs between SSID and MBSSID */
1759 cpy_len
= trans_ssid
[1] + 2;
1760 memcpy(pos
, (trans_ssid
+ cpy_len
), (mbssid
- (trans_ssid
+ cpy_len
)));
1761 pos
+= (mbssid
- (trans_ssid
+ cpy_len
));
1762 /* copy the IEs after MBSSID */
1763 cpy_len
= mbssid
[1] + 2;
1764 memcpy(pos
, mbssid
+ cpy_len
, ((ie
+ ielen
) - (mbssid
+ cpy_len
)));
1767 new_ies
->len
= new_ie_len
;
1768 new_ies
->tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
1769 new_ies
->from_beacon
= ieee80211_is_beacon(mgmt
->frame_control
);
1770 memcpy(new_ies
->data
, new_ie
, new_ie_len
);
1771 if (ieee80211_is_probe_resp(mgmt
->frame_control
)) {
1772 old
= rcu_access_pointer(nontrans_bss
->proberesp_ies
);
1773 rcu_assign_pointer(nontrans_bss
->proberesp_ies
, new_ies
);
1774 rcu_assign_pointer(nontrans_bss
->ies
, new_ies
);
1776 kfree_rcu((struct cfg80211_bss_ies
*)old
, rcu_head
);
1778 old
= rcu_access_pointer(nontrans_bss
->beacon_ies
);
1779 rcu_assign_pointer(nontrans_bss
->beacon_ies
, new_ies
);
1780 rcu_assign_pointer(nontrans_bss
->ies
, new_ies
);
1782 kfree_rcu((struct cfg80211_bss_ies
*)old
, rcu_head
);
1789 /* cfg80211_inform_bss_width_frame helper */
1790 static struct cfg80211_bss
*
1791 cfg80211_inform_single_bss_frame_data(struct wiphy
*wiphy
,
1792 struct cfg80211_inform_bss
*data
,
1793 struct ieee80211_mgmt
*mgmt
, size_t len
,
1796 struct cfg80211_internal_bss tmp
= {}, *res
;
1797 struct cfg80211_bss_ies
*ies
;
1798 struct ieee80211_channel
*channel
;
1800 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
1801 u
.probe_resp
.variable
);
1804 BUILD_BUG_ON(offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
) !=
1805 offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
));
1807 trace_cfg80211_inform_bss_frame(wiphy
, data
, mgmt
, len
);
1812 if (WARN_ON(!wiphy
))
1815 if (WARN_ON(wiphy
->signal_type
== CFG80211_SIGNAL_TYPE_UNSPEC
&&
1816 (data
->signal
< 0 || data
->signal
> 100)))
1819 if (WARN_ON(len
< offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
)))
1822 channel
= cfg80211_get_bss_channel(wiphy
, mgmt
->u
.beacon
.variable
,
1823 ielen
, data
->chan
, data
->scan_width
);
1827 ies
= kzalloc(sizeof(*ies
) + ielen
, gfp
);
1831 ies
->tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
1832 ies
->from_beacon
= ieee80211_is_beacon(mgmt
->frame_control
);
1833 memcpy(ies
->data
, mgmt
->u
.probe_resp
.variable
, ielen
);
1835 if (ieee80211_is_probe_resp(mgmt
->frame_control
))
1836 rcu_assign_pointer(tmp
.pub
.proberesp_ies
, ies
);
1838 rcu_assign_pointer(tmp
.pub
.beacon_ies
, ies
);
1839 rcu_assign_pointer(tmp
.pub
.ies
, ies
);
1841 memcpy(tmp
.pub
.bssid
, mgmt
->bssid
, ETH_ALEN
);
1842 tmp
.pub
.channel
= channel
;
1843 tmp
.pub
.scan_width
= data
->scan_width
;
1844 tmp
.pub
.signal
= data
->signal
;
1845 tmp
.pub
.beacon_interval
= le16_to_cpu(mgmt
->u
.probe_resp
.beacon_int
);
1846 tmp
.pub
.capability
= le16_to_cpu(mgmt
->u
.probe_resp
.capab_info
);
1847 tmp
.ts_boottime
= data
->boottime_ns
;
1848 tmp
.parent_tsf
= data
->parent_tsf
;
1849 tmp
.pub
.chains
= data
->chains
;
1850 memcpy(tmp
.pub
.chain_signal
, data
->chain_signal
, IEEE80211_MAX_CHAINS
);
1851 ether_addr_copy(tmp
.parent_bssid
, data
->parent_bssid
);
1853 signal_valid
= data
->chan
== channel
;
1854 res
= cfg80211_bss_update(wiphy_to_rdev(wiphy
), &tmp
, signal_valid
,
1859 if (channel
->band
== NL80211_BAND_60GHZ
) {
1860 bss_type
= res
->pub
.capability
& WLAN_CAPABILITY_DMG_TYPE_MASK
;
1861 if (bss_type
== WLAN_CAPABILITY_DMG_TYPE_AP
||
1862 bss_type
== WLAN_CAPABILITY_DMG_TYPE_PBSS
)
1863 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1865 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
1866 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1869 trace_cfg80211_return_bss(&res
->pub
);
1870 /* cfg80211_bss_update gives us a referenced result */
1874 struct cfg80211_bss
*
1875 cfg80211_inform_bss_frame_data(struct wiphy
*wiphy
,
1876 struct cfg80211_inform_bss
*data
,
1877 struct ieee80211_mgmt
*mgmt
, size_t len
,
1880 struct cfg80211_bss
*res
, *tmp_bss
;
1881 const u8
*ie
= mgmt
->u
.probe_resp
.variable
;
1882 const struct cfg80211_bss_ies
*ies1
, *ies2
;
1883 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
1884 u
.probe_resp
.variable
);
1885 struct cfg80211_non_tx_bss non_tx_data
;
1887 res
= cfg80211_inform_single_bss_frame_data(wiphy
, data
, mgmt
,
1889 if (!res
|| !wiphy
->support_mbssid
||
1890 !cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID
, ie
, ielen
))
1892 if (wiphy
->support_only_he_mbssid
&&
1893 !cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY
, ie
, ielen
))
1896 non_tx_data
.tx_bss
= res
;
1897 /* process each non-transmitting bss */
1898 cfg80211_parse_mbssid_frame_data(wiphy
, data
, mgmt
, len
,
1901 spin_lock_bh(&wiphy_to_rdev(wiphy
)->bss_lock
);
1903 /* check if the res has other nontransmitting bss which is not
1906 ies1
= rcu_access_pointer(res
->ies
);
1908 /* go through nontrans_list, if the timestamp of the BSS is
1909 * earlier than the timestamp of the transmitting BSS then
1912 list_for_each_entry(tmp_bss
, &res
->nontrans_list
,
1914 ies2
= rcu_access_pointer(tmp_bss
->ies
);
1915 if (ies2
->tsf
< ies1
->tsf
)
1916 cfg80211_update_notlisted_nontrans(wiphy
, tmp_bss
,
1919 spin_unlock_bh(&wiphy_to_rdev(wiphy
)->bss_lock
);
1923 EXPORT_SYMBOL(cfg80211_inform_bss_frame_data
);
1925 void cfg80211_ref_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1927 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1928 struct cfg80211_internal_bss
*bss
;
1933 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1935 spin_lock_bh(&rdev
->bss_lock
);
1936 bss_ref_get(rdev
, bss
);
1937 spin_unlock_bh(&rdev
->bss_lock
);
1939 EXPORT_SYMBOL(cfg80211_ref_bss
);
1941 void cfg80211_put_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1943 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1944 struct cfg80211_internal_bss
*bss
;
1949 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1951 spin_lock_bh(&rdev
->bss_lock
);
1952 bss_ref_put(rdev
, bss
);
1953 spin_unlock_bh(&rdev
->bss_lock
);
1955 EXPORT_SYMBOL(cfg80211_put_bss
);
1957 void cfg80211_unlink_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1959 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1960 struct cfg80211_internal_bss
*bss
, *tmp1
;
1961 struct cfg80211_bss
*nontrans_bss
, *tmp
;
1966 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1968 spin_lock_bh(&rdev
->bss_lock
);
1969 if (list_empty(&bss
->list
))
1972 list_for_each_entry_safe(nontrans_bss
, tmp
,
1973 &pub
->nontrans_list
,
1975 tmp1
= container_of(nontrans_bss
,
1976 struct cfg80211_internal_bss
, pub
);
1977 if (__cfg80211_unlink_bss(rdev
, tmp1
))
1978 rdev
->bss_generation
++;
1981 if (__cfg80211_unlink_bss(rdev
, bss
))
1982 rdev
->bss_generation
++;
1984 spin_unlock_bh(&rdev
->bss_lock
);
1986 EXPORT_SYMBOL(cfg80211_unlink_bss
);
1988 void cfg80211_bss_iter(struct wiphy
*wiphy
,
1989 struct cfg80211_chan_def
*chandef
,
1990 void (*iter
)(struct wiphy
*wiphy
,
1991 struct cfg80211_bss
*bss
,
1995 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1996 struct cfg80211_internal_bss
*bss
;
1998 spin_lock_bh(&rdev
->bss_lock
);
2000 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
2001 if (!chandef
|| cfg80211_is_sub_chan(chandef
, bss
->pub
.channel
))
2002 iter(wiphy
, &bss
->pub
, iter_data
);
2005 spin_unlock_bh(&rdev
->bss_lock
);
2007 EXPORT_SYMBOL(cfg80211_bss_iter
);
2009 void cfg80211_update_assoc_bss_entry(struct wireless_dev
*wdev
,
2010 struct ieee80211_channel
*chan
)
2012 struct wiphy
*wiphy
= wdev
->wiphy
;
2013 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
2014 struct cfg80211_internal_bss
*cbss
= wdev
->current_bss
;
2015 struct cfg80211_internal_bss
*new = NULL
;
2016 struct cfg80211_internal_bss
*bss
;
2017 struct cfg80211_bss
*nontrans_bss
;
2018 struct cfg80211_bss
*tmp
;
2020 spin_lock_bh(&rdev
->bss_lock
);
2023 * Some APs use CSA also for bandwidth changes, i.e., without actually
2024 * changing the control channel, so no need to update in such a case.
2026 if (cbss
->pub
.channel
== chan
)
2029 /* use transmitting bss */
2030 if (cbss
->pub
.transmitted_bss
)
2031 cbss
= container_of(cbss
->pub
.transmitted_bss
,
2032 struct cfg80211_internal_bss
,
2035 cbss
->pub
.channel
= chan
;
2037 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
2038 if (!cfg80211_bss_type_match(bss
->pub
.capability
,
2039 bss
->pub
.channel
->band
,
2040 wdev
->conn_bss_type
))
2046 if (!cmp_bss(&bss
->pub
, &cbss
->pub
, BSS_CMP_REGULAR
)) {
2053 /* to save time, update IEs for transmitting bss only */
2054 if (cfg80211_update_known_bss(rdev
, cbss
, new, false)) {
2055 new->pub
.proberesp_ies
= NULL
;
2056 new->pub
.beacon_ies
= NULL
;
2059 list_for_each_entry_safe(nontrans_bss
, tmp
,
2060 &new->pub
.nontrans_list
,
2062 bss
= container_of(nontrans_bss
,
2063 struct cfg80211_internal_bss
, pub
);
2064 if (__cfg80211_unlink_bss(rdev
, bss
))
2065 rdev
->bss_generation
++;
2068 WARN_ON(atomic_read(&new->hold
));
2069 if (!WARN_ON(!__cfg80211_unlink_bss(rdev
, new)))
2070 rdev
->bss_generation
++;
2073 rb_erase(&cbss
->rbn
, &rdev
->bss_tree
);
2074 rb_insert_bss(rdev
, cbss
);
2075 rdev
->bss_generation
++;
2077 list_for_each_entry_safe(nontrans_bss
, tmp
,
2078 &cbss
->pub
.nontrans_list
,
2080 bss
= container_of(nontrans_bss
,
2081 struct cfg80211_internal_bss
, pub
);
2082 bss
->pub
.channel
= chan
;
2083 rb_erase(&bss
->rbn
, &rdev
->bss_tree
);
2084 rb_insert_bss(rdev
, bss
);
2085 rdev
->bss_generation
++;
2089 spin_unlock_bh(&rdev
->bss_lock
);
2092 #ifdef CONFIG_CFG80211_WEXT
2093 static struct cfg80211_registered_device
*
2094 cfg80211_get_dev_from_ifindex(struct net
*net
, int ifindex
)
2096 struct cfg80211_registered_device
*rdev
;
2097 struct net_device
*dev
;
2101 dev
= dev_get_by_index(net
, ifindex
);
2103 return ERR_PTR(-ENODEV
);
2104 if (dev
->ieee80211_ptr
)
2105 rdev
= wiphy_to_rdev(dev
->ieee80211_ptr
->wiphy
);
2107 rdev
= ERR_PTR(-ENODEV
);
2112 int cfg80211_wext_siwscan(struct net_device
*dev
,
2113 struct iw_request_info
*info
,
2114 union iwreq_data
*wrqu
, char *extra
)
2116 struct cfg80211_registered_device
*rdev
;
2117 struct wiphy
*wiphy
;
2118 struct iw_scan_req
*wreq
= NULL
;
2119 struct cfg80211_scan_request
*creq
= NULL
;
2120 int i
, err
, n_channels
= 0;
2121 enum nl80211_band band
;
2123 if (!netif_running(dev
))
2126 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
))
2127 wreq
= (struct iw_scan_req
*)extra
;
2129 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
2132 return PTR_ERR(rdev
);
2134 if (rdev
->scan_req
|| rdev
->scan_msg
) {
2139 wiphy
= &rdev
->wiphy
;
2141 /* Determine number of channels, needed to allocate creq */
2142 if (wreq
&& wreq
->num_channels
)
2143 n_channels
= wreq
->num_channels
;
2145 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
2147 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
2148 n_channels
* sizeof(void *),
2155 creq
->wiphy
= wiphy
;
2156 creq
->wdev
= dev
->ieee80211_ptr
;
2157 /* SSIDs come after channels */
2158 creq
->ssids
= (void *)&creq
->channels
[n_channels
];
2159 creq
->n_channels
= n_channels
;
2161 creq
->scan_start
= jiffies
;
2163 /* translate "Scan on frequencies" request */
2165 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
2168 if (!wiphy
->bands
[band
])
2171 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
2172 /* ignore disabled channels */
2173 if (wiphy
->bands
[band
]->channels
[j
].flags
&
2174 IEEE80211_CHAN_DISABLED
)
2177 /* If we have a wireless request structure and the
2178 * wireless request specifies frequencies, then search
2179 * for the matching hardware channel.
2181 if (wreq
&& wreq
->num_channels
) {
2183 int wiphy_freq
= wiphy
->bands
[band
]->channels
[j
].center_freq
;
2184 for (k
= 0; k
< wreq
->num_channels
; k
++) {
2185 struct iw_freq
*freq
=
2186 &wreq
->channel_list
[k
];
2188 cfg80211_wext_freq(freq
);
2190 if (wext_freq
== wiphy_freq
)
2191 goto wext_freq_found
;
2193 goto wext_freq_not_found
;
2197 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
2199 wext_freq_not_found
: ;
2202 /* No channels found? */
2208 /* Set real number of channels specified in creq->channels[] */
2209 creq
->n_channels
= i
;
2211 /* translate "Scan for SSID" request */
2213 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
2214 if (wreq
->essid_len
> IEEE80211_MAX_SSID_LEN
) {
2218 memcpy(creq
->ssids
[0].ssid
, wreq
->essid
, wreq
->essid_len
);
2219 creq
->ssids
[0].ssid_len
= wreq
->essid_len
;
2221 if (wreq
->scan_type
== IW_SCAN_TYPE_PASSIVE
)
2225 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
2226 if (wiphy
->bands
[i
])
2227 creq
->rates
[i
] = (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
2229 eth_broadcast_addr(creq
->bssid
);
2231 rdev
->scan_req
= creq
;
2232 err
= rdev_scan(rdev
, creq
);
2234 rdev
->scan_req
= NULL
;
2235 /* creq will be freed below */
2237 nl80211_send_scan_start(rdev
, dev
->ieee80211_ptr
);
2238 /* creq now owned by driver */
2246 EXPORT_WEXT_HANDLER(cfg80211_wext_siwscan
);
2248 static char *ieee80211_scan_add_ies(struct iw_request_info
*info
,
2249 const struct cfg80211_bss_ies
*ies
,
2250 char *current_ev
, char *end_buf
)
2252 const u8
*pos
, *end
, *next
;
2253 struct iw_event iwe
;
2259 * If needed, fragment the IEs buffer (at IE boundaries) into short
2260 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
2263 end
= pos
+ ies
->len
;
2265 while (end
- pos
> IW_GENERIC_IE_MAX
) {
2266 next
= pos
+ 2 + pos
[1];
2267 while (next
+ 2 + next
[1] - pos
< IW_GENERIC_IE_MAX
)
2268 next
= next
+ 2 + next
[1];
2270 memset(&iwe
, 0, sizeof(iwe
));
2271 iwe
.cmd
= IWEVGENIE
;
2272 iwe
.u
.data
.length
= next
- pos
;
2273 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
2276 if (IS_ERR(current_ev
))
2282 memset(&iwe
, 0, sizeof(iwe
));
2283 iwe
.cmd
= IWEVGENIE
;
2284 iwe
.u
.data
.length
= end
- pos
;
2285 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
2288 if (IS_ERR(current_ev
))
2296 ieee80211_bss(struct wiphy
*wiphy
, struct iw_request_info
*info
,
2297 struct cfg80211_internal_bss
*bss
, char *current_ev
,
2300 const struct cfg80211_bss_ies
*ies
;
2301 struct iw_event iwe
;
2306 bool ismesh
= false;
2308 memset(&iwe
, 0, sizeof(iwe
));
2309 iwe
.cmd
= SIOCGIWAP
;
2310 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
2311 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->pub
.bssid
, ETH_ALEN
);
2312 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
2314 if (IS_ERR(current_ev
))
2317 memset(&iwe
, 0, sizeof(iwe
));
2318 iwe
.cmd
= SIOCGIWFREQ
;
2319 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->pub
.channel
->center_freq
);
2321 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
2323 if (IS_ERR(current_ev
))
2326 memset(&iwe
, 0, sizeof(iwe
));
2327 iwe
.cmd
= SIOCGIWFREQ
;
2328 iwe
.u
.freq
.m
= bss
->pub
.channel
->center_freq
;
2330 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
2332 if (IS_ERR(current_ev
))
2335 if (wiphy
->signal_type
!= CFG80211_SIGNAL_TYPE_NONE
) {
2336 memset(&iwe
, 0, sizeof(iwe
));
2338 iwe
.u
.qual
.updated
= IW_QUAL_LEVEL_UPDATED
|
2339 IW_QUAL_NOISE_INVALID
|
2340 IW_QUAL_QUAL_UPDATED
;
2341 switch (wiphy
->signal_type
) {
2342 case CFG80211_SIGNAL_TYPE_MBM
:
2343 sig
= bss
->pub
.signal
/ 100;
2344 iwe
.u
.qual
.level
= sig
;
2345 iwe
.u
.qual
.updated
|= IW_QUAL_DBM
;
2346 if (sig
< -110) /* rather bad */
2348 else if (sig
> -40) /* perfect */
2350 /* will give a range of 0 .. 70 */
2351 iwe
.u
.qual
.qual
= sig
+ 110;
2353 case CFG80211_SIGNAL_TYPE_UNSPEC
:
2354 iwe
.u
.qual
.level
= bss
->pub
.signal
;
2355 /* will give range 0 .. 100 */
2356 iwe
.u
.qual
.qual
= bss
->pub
.signal
;
2362 current_ev
= iwe_stream_add_event_check(info
, current_ev
,
2365 if (IS_ERR(current_ev
))
2369 memset(&iwe
, 0, sizeof(iwe
));
2370 iwe
.cmd
= SIOCGIWENCODE
;
2371 if (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
)
2372 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
2374 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
2375 iwe
.u
.data
.length
= 0;
2376 current_ev
= iwe_stream_add_point_check(info
, current_ev
, end_buf
,
2378 if (IS_ERR(current_ev
))
2382 ies
= rcu_dereference(bss
->pub
.ies
);
2388 if (ie
[1] > rem
- 2)
2393 memset(&iwe
, 0, sizeof(iwe
));
2394 iwe
.cmd
= SIOCGIWESSID
;
2395 iwe
.u
.data
.length
= ie
[1];
2396 iwe
.u
.data
.flags
= 1;
2397 current_ev
= iwe_stream_add_point_check(info
,
2401 if (IS_ERR(current_ev
))
2404 case WLAN_EID_MESH_ID
:
2405 memset(&iwe
, 0, sizeof(iwe
));
2406 iwe
.cmd
= SIOCGIWESSID
;
2407 iwe
.u
.data
.length
= ie
[1];
2408 iwe
.u
.data
.flags
= 1;
2409 current_ev
= iwe_stream_add_point_check(info
,
2413 if (IS_ERR(current_ev
))
2416 case WLAN_EID_MESH_CONFIG
:
2418 if (ie
[1] != sizeof(struct ieee80211_meshconf_ie
))
2421 memset(&iwe
, 0, sizeof(iwe
));
2422 iwe
.cmd
= IWEVCUSTOM
;
2423 sprintf(buf
, "Mesh Network Path Selection Protocol ID: "
2425 iwe
.u
.data
.length
= strlen(buf
);
2426 current_ev
= iwe_stream_add_point_check(info
,
2430 if (IS_ERR(current_ev
))
2432 sprintf(buf
, "Path Selection Metric ID: 0x%02X",
2434 iwe
.u
.data
.length
= strlen(buf
);
2435 current_ev
= iwe_stream_add_point_check(info
,
2439 if (IS_ERR(current_ev
))
2441 sprintf(buf
, "Congestion Control Mode ID: 0x%02X",
2443 iwe
.u
.data
.length
= strlen(buf
);
2444 current_ev
= iwe_stream_add_point_check(info
,
2448 if (IS_ERR(current_ev
))
2450 sprintf(buf
, "Synchronization ID: 0x%02X", cfg
[3]);
2451 iwe
.u
.data
.length
= strlen(buf
);
2452 current_ev
= iwe_stream_add_point_check(info
,
2456 if (IS_ERR(current_ev
))
2458 sprintf(buf
, "Authentication ID: 0x%02X", cfg
[4]);
2459 iwe
.u
.data
.length
= strlen(buf
);
2460 current_ev
= iwe_stream_add_point_check(info
,
2464 if (IS_ERR(current_ev
))
2466 sprintf(buf
, "Formation Info: 0x%02X", cfg
[5]);
2467 iwe
.u
.data
.length
= strlen(buf
);
2468 current_ev
= iwe_stream_add_point_check(info
,
2472 if (IS_ERR(current_ev
))
2474 sprintf(buf
, "Capabilities: 0x%02X", cfg
[6]);
2475 iwe
.u
.data
.length
= strlen(buf
);
2476 current_ev
= iwe_stream_add_point_check(info
,
2480 if (IS_ERR(current_ev
))
2483 case WLAN_EID_SUPP_RATES
:
2484 case WLAN_EID_EXT_SUPP_RATES
:
2485 /* display all supported rates in readable format */
2486 p
= current_ev
+ iwe_stream_lcp_len(info
);
2488 memset(&iwe
, 0, sizeof(iwe
));
2489 iwe
.cmd
= SIOCGIWRATE
;
2490 /* Those two flags are ignored... */
2491 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
2493 for (i
= 0; i
< ie
[1]; i
++) {
2494 iwe
.u
.bitrate
.value
=
2495 ((ie
[i
+ 2] & 0x7f) * 500000);
2497 p
= iwe_stream_add_value(info
, current_ev
, p
,
2501 current_ev
= ERR_PTR(-E2BIG
);
2512 if (bss
->pub
.capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
) ||
2514 memset(&iwe
, 0, sizeof(iwe
));
2515 iwe
.cmd
= SIOCGIWMODE
;
2517 iwe
.u
.mode
= IW_MODE_MESH
;
2518 else if (bss
->pub
.capability
& WLAN_CAPABILITY_ESS
)
2519 iwe
.u
.mode
= IW_MODE_MASTER
;
2521 iwe
.u
.mode
= IW_MODE_ADHOC
;
2522 current_ev
= iwe_stream_add_event_check(info
, current_ev
,
2525 if (IS_ERR(current_ev
))
2529 memset(&iwe
, 0, sizeof(iwe
));
2530 iwe
.cmd
= IWEVCUSTOM
;
2531 sprintf(buf
, "tsf=%016llx", (unsigned long long)(ies
->tsf
));
2532 iwe
.u
.data
.length
= strlen(buf
);
2533 current_ev
= iwe_stream_add_point_check(info
, current_ev
, end_buf
,
2535 if (IS_ERR(current_ev
))
2537 memset(&iwe
, 0, sizeof(iwe
));
2538 iwe
.cmd
= IWEVCUSTOM
;
2539 sprintf(buf
, " Last beacon: %ums ago",
2540 elapsed_jiffies_msecs(bss
->ts
));
2541 iwe
.u
.data
.length
= strlen(buf
);
2542 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
2543 end_buf
, &iwe
, buf
);
2544 if (IS_ERR(current_ev
))
2547 current_ev
= ieee80211_scan_add_ies(info
, ies
, current_ev
, end_buf
);
2555 static int ieee80211_scan_results(struct cfg80211_registered_device
*rdev
,
2556 struct iw_request_info
*info
,
2557 char *buf
, size_t len
)
2559 char *current_ev
= buf
;
2560 char *end_buf
= buf
+ len
;
2561 struct cfg80211_internal_bss
*bss
;
2564 spin_lock_bh(&rdev
->bss_lock
);
2565 cfg80211_bss_expire(rdev
);
2567 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
2568 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
2572 current_ev
= ieee80211_bss(&rdev
->wiphy
, info
, bss
,
2573 current_ev
, end_buf
);
2574 if (IS_ERR(current_ev
)) {
2575 err
= PTR_ERR(current_ev
);
2579 spin_unlock_bh(&rdev
->bss_lock
);
2583 return current_ev
- buf
;
2587 int cfg80211_wext_giwscan(struct net_device
*dev
,
2588 struct iw_request_info
*info
,
2589 struct iw_point
*data
, char *extra
)
2591 struct cfg80211_registered_device
*rdev
;
2594 if (!netif_running(dev
))
2597 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
2600 return PTR_ERR(rdev
);
2602 if (rdev
->scan_req
|| rdev
->scan_msg
)
2605 res
= ieee80211_scan_results(rdev
, info
, extra
, data
->length
);
2614 EXPORT_WEXT_HANDLER(cfg80211_wext_giwscan
);