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 static size_t cfg80211_gen_new_ie(const u8
*ie
, size_t ielen
,
183 const u8
*subelement
, size_t subie_len
,
184 u8
*new_ie
, gfp_t gfp
)
187 const u8
*tmp_old
, *tmp_new
;
190 /* copy subelement as we need to change its content to
191 * mark an ie after it is processed.
193 sub_copy
= kmemdup(subelement
, subie_len
, gfp
);
200 tmp_new
= cfg80211_find_ie(WLAN_EID_SSID
, sub_copy
, subie_len
);
202 memcpy(pos
, tmp_new
, tmp_new
[1] + 2);
203 pos
+= (tmp_new
[1] + 2);
206 /* go through IEs in ie (skip SSID) and subelement,
207 * merge them into new_ie
209 tmp_old
= cfg80211_find_ie(WLAN_EID_SSID
, ie
, ielen
);
210 tmp_old
= (tmp_old
) ? tmp_old
+ tmp_old
[1] + 2 : ie
;
212 while (tmp_old
+ tmp_old
[1] + 2 - ie
<= ielen
) {
213 if (tmp_old
[0] == 0) {
218 if (tmp_old
[0] == WLAN_EID_EXTENSION
)
219 tmp
= (u8
*)cfg80211_find_ext_ie(tmp_old
[2], sub_copy
,
222 tmp
= (u8
*)cfg80211_find_ie(tmp_old
[0], sub_copy
,
226 /* ie in old ie but not in subelement */
227 if (tmp_old
[0] != WLAN_EID_MULTIPLE_BSSID
) {
228 memcpy(pos
, tmp_old
, tmp_old
[1] + 2);
229 pos
+= tmp_old
[1] + 2;
232 /* ie in transmitting ie also in subelement,
233 * copy from subelement and flag the ie in subelement
234 * as copied (by setting eid field to WLAN_EID_SSID,
235 * which is skipped anyway).
236 * For vendor ie, compare OUI + type + subType to
237 * determine if they are the same ie.
239 if (tmp_old
[0] == WLAN_EID_VENDOR_SPECIFIC
) {
240 if (!memcmp(tmp_old
+ 2, tmp
+ 2, 5)) {
241 /* same vendor ie, copy from
244 memcpy(pos
, tmp
, tmp
[1] + 2);
246 tmp
[0] = WLAN_EID_SSID
;
248 memcpy(pos
, tmp_old
, tmp_old
[1] + 2);
249 pos
+= tmp_old
[1] + 2;
252 /* copy ie from subelement into new ie */
253 memcpy(pos
, tmp
, tmp
[1] + 2);
255 tmp
[0] = WLAN_EID_SSID
;
259 if (tmp_old
+ tmp_old
[1] + 2 - ie
== ielen
)
262 tmp_old
+= tmp_old
[1] + 2;
265 /* go through subelement again to check if there is any ie not
266 * copied to new ie, skip ssid, capability, bssid-index ie
269 while (tmp_new
+ tmp_new
[1] + 2 - sub_copy
<= subie_len
) {
270 if (!(tmp_new
[0] == WLAN_EID_NON_TX_BSSID_CAP
||
271 tmp_new
[0] == WLAN_EID_SSID
||
272 tmp_new
[0] == WLAN_EID_MULTI_BSSID_IDX
)) {
273 memcpy(pos
, tmp_new
, tmp_new
[1] + 2);
274 pos
+= tmp_new
[1] + 2;
276 if (tmp_new
+ tmp_new
[1] + 2 - sub_copy
== subie_len
)
278 tmp_new
+= tmp_new
[1] + 2;
285 static bool is_bss(struct cfg80211_bss
*a
, const u8
*bssid
,
286 const u8
*ssid
, size_t ssid_len
)
288 const struct cfg80211_bss_ies
*ies
;
291 if (bssid
&& !ether_addr_equal(a
->bssid
, bssid
))
297 ies
= rcu_access_pointer(a
->ies
);
300 ssidie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
303 if (ssidie
[1] != ssid_len
)
305 return memcmp(ssidie
+ 2, ssid
, ssid_len
) == 0;
309 cfg80211_add_nontrans_list(struct cfg80211_bss
*trans_bss
,
310 struct cfg80211_bss
*nontrans_bss
)
314 struct cfg80211_bss
*bss
= NULL
;
317 ssid
= ieee80211_bss_get_ie(nontrans_bss
, WLAN_EID_SSID
);
326 /* check if nontrans_bss is in the list */
327 list_for_each_entry(bss
, &trans_bss
->nontrans_list
, nontrans_list
) {
328 if (is_bss(bss
, nontrans_bss
->bssid
, ssid
, ssid_len
))
332 /* add to the list */
333 list_add_tail(&nontrans_bss
->nontrans_list
, &trans_bss
->nontrans_list
);
337 static void __cfg80211_bss_expire(struct cfg80211_registered_device
*rdev
,
338 unsigned long expire_time
)
340 struct cfg80211_internal_bss
*bss
, *tmp
;
341 bool expired
= false;
343 lockdep_assert_held(&rdev
->bss_lock
);
345 list_for_each_entry_safe(bss
, tmp
, &rdev
->bss_list
, list
) {
346 if (atomic_read(&bss
->hold
))
348 if (!time_after(expire_time
, bss
->ts
))
351 if (__cfg80211_unlink_bss(rdev
, bss
))
356 rdev
->bss_generation
++;
359 static bool cfg80211_bss_expire_oldest(struct cfg80211_registered_device
*rdev
)
361 struct cfg80211_internal_bss
*bss
, *oldest
= NULL
;
364 lockdep_assert_held(&rdev
->bss_lock
);
366 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
367 if (atomic_read(&bss
->hold
))
370 if (!list_empty(&bss
->hidden_list
) &&
371 !bss
->pub
.hidden_beacon_bss
)
374 if (oldest
&& time_before(oldest
->ts
, bss
->ts
))
379 if (WARN_ON(!oldest
))
383 * The callers make sure to increase rdev->bss_generation if anything
384 * gets removed (and a new entry added), so there's no need to also do
388 ret
= __cfg80211_unlink_bss(rdev
, oldest
);
393 void ___cfg80211_scan_done(struct cfg80211_registered_device
*rdev
,
396 struct cfg80211_scan_request
*request
;
397 struct wireless_dev
*wdev
;
399 #ifdef CONFIG_CFG80211_WEXT
400 union iwreq_data wrqu
;
405 if (rdev
->scan_msg
) {
406 nl80211_send_scan_msg(rdev
, rdev
->scan_msg
);
407 rdev
->scan_msg
= NULL
;
411 request
= rdev
->scan_req
;
415 wdev
= request
->wdev
;
418 * This must be before sending the other events!
419 * Otherwise, wpa_supplicant gets completely confused with
423 cfg80211_sme_scan_done(wdev
->netdev
);
425 if (!request
->info
.aborted
&&
426 request
->flags
& NL80211_SCAN_FLAG_FLUSH
) {
427 /* flush entries from previous scans */
428 spin_lock_bh(&rdev
->bss_lock
);
429 __cfg80211_bss_expire(rdev
, request
->scan_start
);
430 spin_unlock_bh(&rdev
->bss_lock
);
433 msg
= nl80211_build_scan_msg(rdev
, wdev
, request
->info
.aborted
);
435 #ifdef CONFIG_CFG80211_WEXT
436 if (wdev
->netdev
&& !request
->info
.aborted
) {
437 memset(&wrqu
, 0, sizeof(wrqu
));
439 wireless_send_event(wdev
->netdev
, SIOCGIWSCAN
, &wrqu
, NULL
);
444 dev_put(wdev
->netdev
);
446 rdev
->scan_req
= NULL
;
450 rdev
->scan_msg
= msg
;
452 nl80211_send_scan_msg(rdev
, msg
);
455 void __cfg80211_scan_done(struct work_struct
*wk
)
457 struct cfg80211_registered_device
*rdev
;
459 rdev
= container_of(wk
, struct cfg80211_registered_device
,
463 ___cfg80211_scan_done(rdev
, true);
467 void cfg80211_scan_done(struct cfg80211_scan_request
*request
,
468 struct cfg80211_scan_info
*info
)
470 trace_cfg80211_scan_done(request
, info
);
471 WARN_ON(request
!= wiphy_to_rdev(request
->wiphy
)->scan_req
);
473 request
->info
= *info
;
474 request
->notified
= true;
475 queue_work(cfg80211_wq
, &wiphy_to_rdev(request
->wiphy
)->scan_done_wk
);
477 EXPORT_SYMBOL(cfg80211_scan_done
);
479 void cfg80211_add_sched_scan_req(struct cfg80211_registered_device
*rdev
,
480 struct cfg80211_sched_scan_request
*req
)
484 list_add_rcu(&req
->list
, &rdev
->sched_scan_req_list
);
487 static void cfg80211_del_sched_scan_req(struct cfg80211_registered_device
*rdev
,
488 struct cfg80211_sched_scan_request
*req
)
492 list_del_rcu(&req
->list
);
493 kfree_rcu(req
, rcu_head
);
496 static struct cfg80211_sched_scan_request
*
497 cfg80211_find_sched_scan_req(struct cfg80211_registered_device
*rdev
, u64 reqid
)
499 struct cfg80211_sched_scan_request
*pos
;
501 WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_rtnl_is_held());
503 list_for_each_entry_rcu(pos
, &rdev
->sched_scan_req_list
, list
) {
504 if (pos
->reqid
== reqid
)
511 * Determines if a scheduled scan request can be handled. When a legacy
512 * scheduled scan is running no other scheduled scan is allowed regardless
513 * whether the request is for legacy or multi-support scan. When a multi-support
514 * scheduled scan is running a request for legacy scan is not allowed. In this
515 * case a request for multi-support scan can be handled if resources are
516 * available, ie. struct wiphy::max_sched_scan_reqs limit is not yet reached.
518 int cfg80211_sched_scan_req_possible(struct cfg80211_registered_device
*rdev
,
521 struct cfg80211_sched_scan_request
*pos
;
524 list_for_each_entry(pos
, &rdev
->sched_scan_req_list
, list
) {
525 /* request id zero means legacy in progress */
526 if (!i
&& !pos
->reqid
)
532 /* no legacy allowed when multi request(s) are active */
536 /* resource limit reached */
537 if (i
== rdev
->wiphy
.max_sched_scan_reqs
)
543 void cfg80211_sched_scan_results_wk(struct work_struct
*work
)
545 struct cfg80211_registered_device
*rdev
;
546 struct cfg80211_sched_scan_request
*req
, *tmp
;
548 rdev
= container_of(work
, struct cfg80211_registered_device
,
552 list_for_each_entry_safe(req
, tmp
, &rdev
->sched_scan_req_list
, list
) {
553 if (req
->report_results
) {
554 req
->report_results
= false;
555 if (req
->flags
& NL80211_SCAN_FLAG_FLUSH
) {
556 /* flush entries from previous scans */
557 spin_lock_bh(&rdev
->bss_lock
);
558 __cfg80211_bss_expire(rdev
, req
->scan_start
);
559 spin_unlock_bh(&rdev
->bss_lock
);
560 req
->scan_start
= jiffies
;
562 nl80211_send_sched_scan(req
,
563 NL80211_CMD_SCHED_SCAN_RESULTS
);
569 void cfg80211_sched_scan_results(struct wiphy
*wiphy
, u64 reqid
)
571 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
572 struct cfg80211_sched_scan_request
*request
;
574 trace_cfg80211_sched_scan_results(wiphy
, reqid
);
575 /* ignore if we're not scanning */
578 request
= cfg80211_find_sched_scan_req(rdev
, reqid
);
580 request
->report_results
= true;
581 queue_work(cfg80211_wq
, &rdev
->sched_scan_res_wk
);
585 EXPORT_SYMBOL(cfg80211_sched_scan_results
);
587 void cfg80211_sched_scan_stopped_rtnl(struct wiphy
*wiphy
, u64 reqid
)
589 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
593 trace_cfg80211_sched_scan_stopped(wiphy
, reqid
);
595 __cfg80211_stop_sched_scan(rdev
, reqid
, true);
597 EXPORT_SYMBOL(cfg80211_sched_scan_stopped_rtnl
);
599 void cfg80211_sched_scan_stopped(struct wiphy
*wiphy
, u64 reqid
)
602 cfg80211_sched_scan_stopped_rtnl(wiphy
, reqid
);
605 EXPORT_SYMBOL(cfg80211_sched_scan_stopped
);
607 int cfg80211_stop_sched_scan_req(struct cfg80211_registered_device
*rdev
,
608 struct cfg80211_sched_scan_request
*req
,
609 bool driver_initiated
)
613 if (!driver_initiated
) {
614 int err
= rdev_sched_scan_stop(rdev
, req
->dev
, req
->reqid
);
619 nl80211_send_sched_scan(req
, NL80211_CMD_SCHED_SCAN_STOPPED
);
621 cfg80211_del_sched_scan_req(rdev
, req
);
626 int __cfg80211_stop_sched_scan(struct cfg80211_registered_device
*rdev
,
627 u64 reqid
, bool driver_initiated
)
629 struct cfg80211_sched_scan_request
*sched_scan_req
;
633 sched_scan_req
= cfg80211_find_sched_scan_req(rdev
, reqid
);
637 return cfg80211_stop_sched_scan_req(rdev
, sched_scan_req
,
641 void cfg80211_bss_age(struct cfg80211_registered_device
*rdev
,
642 unsigned long age_secs
)
644 struct cfg80211_internal_bss
*bss
;
645 unsigned long age_jiffies
= msecs_to_jiffies(age_secs
* MSEC_PER_SEC
);
647 spin_lock_bh(&rdev
->bss_lock
);
648 list_for_each_entry(bss
, &rdev
->bss_list
, list
)
649 bss
->ts
-= age_jiffies
;
650 spin_unlock_bh(&rdev
->bss_lock
);
653 void cfg80211_bss_expire(struct cfg80211_registered_device
*rdev
)
655 __cfg80211_bss_expire(rdev
, jiffies
- IEEE80211_SCAN_RESULT_EXPIRE
);
658 const struct element
*
659 cfg80211_find_elem_match(u8 eid
, const u8
*ies
, unsigned int len
,
660 const u8
*match
, unsigned int match_len
,
661 unsigned int match_offset
)
663 const struct element
*elem
;
665 for_each_element_id(elem
, eid
, ies
, len
) {
666 if (elem
->datalen
>= match_offset
+ match_len
&&
667 !memcmp(elem
->data
+ match_offset
, match
, match_len
))
673 EXPORT_SYMBOL(cfg80211_find_elem_match
);
675 const struct element
*cfg80211_find_vendor_elem(unsigned int oui
, int oui_type
,
679 const struct element
*elem
;
680 u8 match
[] = { oui
>> 16, oui
>> 8, oui
, oui_type
};
681 int match_len
= (oui_type
< 0) ? 3 : sizeof(match
);
683 if (WARN_ON(oui_type
> 0xff))
686 elem
= cfg80211_find_elem_match(WLAN_EID_VENDOR_SPECIFIC
, ies
, len
,
687 match
, match_len
, 0);
689 if (!elem
|| elem
->datalen
< 4)
694 EXPORT_SYMBOL(cfg80211_find_vendor_elem
);
697 * enum bss_compare_mode - BSS compare mode
698 * @BSS_CMP_REGULAR: regular compare mode (for insertion and normal find)
699 * @BSS_CMP_HIDE_ZLEN: find hidden SSID with zero-length mode
700 * @BSS_CMP_HIDE_NUL: find hidden SSID with NUL-ed out mode
702 enum bss_compare_mode
{
708 static int cmp_bss(struct cfg80211_bss
*a
,
709 struct cfg80211_bss
*b
,
710 enum bss_compare_mode mode
)
712 const struct cfg80211_bss_ies
*a_ies
, *b_ies
;
713 const u8
*ie1
= NULL
;
714 const u8
*ie2
= NULL
;
717 if (a
->channel
!= b
->channel
)
718 return b
->channel
->center_freq
- a
->channel
->center_freq
;
720 a_ies
= rcu_access_pointer(a
->ies
);
723 b_ies
= rcu_access_pointer(b
->ies
);
727 if (WLAN_CAPABILITY_IS_STA_BSS(a
->capability
))
728 ie1
= cfg80211_find_ie(WLAN_EID_MESH_ID
,
729 a_ies
->data
, a_ies
->len
);
730 if (WLAN_CAPABILITY_IS_STA_BSS(b
->capability
))
731 ie2
= cfg80211_find_ie(WLAN_EID_MESH_ID
,
732 b_ies
->data
, b_ies
->len
);
736 if (ie1
[1] == ie2
[1])
737 mesh_id_cmp
= memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
739 mesh_id_cmp
= ie2
[1] - ie1
[1];
741 ie1
= cfg80211_find_ie(WLAN_EID_MESH_CONFIG
,
742 a_ies
->data
, a_ies
->len
);
743 ie2
= cfg80211_find_ie(WLAN_EID_MESH_CONFIG
,
744 b_ies
->data
, b_ies
->len
);
748 if (ie1
[1] != ie2
[1])
749 return ie2
[1] - ie1
[1];
750 return memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
754 r
= memcmp(a
->bssid
, b
->bssid
, sizeof(a
->bssid
));
758 ie1
= cfg80211_find_ie(WLAN_EID_SSID
, a_ies
->data
, a_ies
->len
);
759 ie2
= cfg80211_find_ie(WLAN_EID_SSID
, b_ies
->data
, b_ies
->len
);
765 * Note that with "hide_ssid", the function returns a match if
766 * the already-present BSS ("b") is a hidden SSID beacon for
770 /* sort missing IE before (left of) present IE */
777 case BSS_CMP_HIDE_ZLEN
:
779 * In ZLEN mode we assume the BSS entry we're
780 * looking for has a zero-length SSID. So if
781 * the one we're looking at right now has that,
782 * return 0. Otherwise, return the difference
783 * in length, but since we're looking for the
784 * 0-length it's really equivalent to returning
785 * the length of the one we're looking at.
787 * No content comparison is needed as we assume
788 * the content length is zero.
791 case BSS_CMP_REGULAR
:
793 /* sort by length first, then by contents */
794 if (ie1
[1] != ie2
[1])
795 return ie2
[1] - ie1
[1];
796 return memcmp(ie1
+ 2, ie2
+ 2, ie1
[1]);
797 case BSS_CMP_HIDE_NUL
:
798 if (ie1
[1] != ie2
[1])
799 return ie2
[1] - ie1
[1];
800 /* this is equivalent to memcmp(zeroes, ie2 + 2, len) */
801 for (i
= 0; i
< ie2
[1]; i
++)
808 static bool cfg80211_bss_type_match(u16 capability
,
809 enum nl80211_band band
,
810 enum ieee80211_bss_type bss_type
)
815 if (bss_type
== IEEE80211_BSS_TYPE_ANY
)
818 if (band
== NL80211_BAND_60GHZ
) {
819 mask
= WLAN_CAPABILITY_DMG_TYPE_MASK
;
821 case IEEE80211_BSS_TYPE_ESS
:
822 val
= WLAN_CAPABILITY_DMG_TYPE_AP
;
824 case IEEE80211_BSS_TYPE_PBSS
:
825 val
= WLAN_CAPABILITY_DMG_TYPE_PBSS
;
827 case IEEE80211_BSS_TYPE_IBSS
:
828 val
= WLAN_CAPABILITY_DMG_TYPE_IBSS
;
834 mask
= WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
;
836 case IEEE80211_BSS_TYPE_ESS
:
837 val
= WLAN_CAPABILITY_ESS
;
839 case IEEE80211_BSS_TYPE_IBSS
:
840 val
= WLAN_CAPABILITY_IBSS
;
842 case IEEE80211_BSS_TYPE_MBSS
:
850 ret
= ((capability
& mask
) == val
);
854 /* Returned bss is reference counted and must be cleaned up appropriately. */
855 struct cfg80211_bss
*cfg80211_get_bss(struct wiphy
*wiphy
,
856 struct ieee80211_channel
*channel
,
858 const u8
*ssid
, size_t ssid_len
,
859 enum ieee80211_bss_type bss_type
,
860 enum ieee80211_privacy privacy
)
862 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
863 struct cfg80211_internal_bss
*bss
, *res
= NULL
;
864 unsigned long now
= jiffies
;
867 trace_cfg80211_get_bss(wiphy
, channel
, bssid
, ssid
, ssid_len
, bss_type
,
870 spin_lock_bh(&rdev
->bss_lock
);
872 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
873 if (!cfg80211_bss_type_match(bss
->pub
.capability
,
874 bss
->pub
.channel
->band
, bss_type
))
877 bss_privacy
= (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
);
878 if ((privacy
== IEEE80211_PRIVACY_ON
&& !bss_privacy
) ||
879 (privacy
== IEEE80211_PRIVACY_OFF
&& bss_privacy
))
881 if (channel
&& bss
->pub
.channel
!= channel
)
883 if (!is_valid_ether_addr(bss
->pub
.bssid
))
885 /* Don't get expired BSS structs */
886 if (time_after(now
, bss
->ts
+ IEEE80211_SCAN_RESULT_EXPIRE
) &&
887 !atomic_read(&bss
->hold
))
889 if (is_bss(&bss
->pub
, bssid
, ssid
, ssid_len
)) {
891 bss_ref_get(rdev
, res
);
896 spin_unlock_bh(&rdev
->bss_lock
);
899 trace_cfg80211_return_bss(&res
->pub
);
902 EXPORT_SYMBOL(cfg80211_get_bss
);
904 static void rb_insert_bss(struct cfg80211_registered_device
*rdev
,
905 struct cfg80211_internal_bss
*bss
)
907 struct rb_node
**p
= &rdev
->bss_tree
.rb_node
;
908 struct rb_node
*parent
= NULL
;
909 struct cfg80211_internal_bss
*tbss
;
914 tbss
= rb_entry(parent
, struct cfg80211_internal_bss
, rbn
);
916 cmp
= cmp_bss(&bss
->pub
, &tbss
->pub
, BSS_CMP_REGULAR
);
919 /* will sort of leak this BSS */
929 rb_link_node(&bss
->rbn
, parent
, p
);
930 rb_insert_color(&bss
->rbn
, &rdev
->bss_tree
);
933 static struct cfg80211_internal_bss
*
934 rb_find_bss(struct cfg80211_registered_device
*rdev
,
935 struct cfg80211_internal_bss
*res
,
936 enum bss_compare_mode mode
)
938 struct rb_node
*n
= rdev
->bss_tree
.rb_node
;
939 struct cfg80211_internal_bss
*bss
;
943 bss
= rb_entry(n
, struct cfg80211_internal_bss
, rbn
);
944 r
= cmp_bss(&res
->pub
, &bss
->pub
, mode
);
957 static bool cfg80211_combine_bsses(struct cfg80211_registered_device
*rdev
,
958 struct cfg80211_internal_bss
*new)
960 const struct cfg80211_bss_ies
*ies
;
961 struct cfg80211_internal_bss
*bss
;
967 ies
= rcu_access_pointer(new->pub
.beacon_ies
);
971 ie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
978 for (i
= 0; i
< ssidlen
; i
++)
982 /* not a hidden SSID */
986 /* This is the bad part ... */
988 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
990 * we're iterating all the entries anyway, so take the
991 * opportunity to validate the list length accounting
995 if (!ether_addr_equal(bss
->pub
.bssid
, new->pub
.bssid
))
997 if (bss
->pub
.channel
!= new->pub
.channel
)
999 if (bss
->pub
.scan_width
!= new->pub
.scan_width
)
1001 if (rcu_access_pointer(bss
->pub
.beacon_ies
))
1003 ies
= rcu_access_pointer(bss
->pub
.ies
);
1006 ie
= cfg80211_find_ie(WLAN_EID_SSID
, ies
->data
, ies
->len
);
1009 if (ssidlen
&& ie
[1] != ssidlen
)
1011 if (WARN_ON_ONCE(bss
->pub
.hidden_beacon_bss
))
1013 if (WARN_ON_ONCE(!list_empty(&bss
->hidden_list
)))
1014 list_del(&bss
->hidden_list
);
1016 list_add(&bss
->hidden_list
, &new->hidden_list
);
1017 bss
->pub
.hidden_beacon_bss
= &new->pub
;
1018 new->refcount
+= bss
->refcount
;
1019 rcu_assign_pointer(bss
->pub
.beacon_ies
,
1020 new->pub
.beacon_ies
);
1023 WARN_ONCE(n_entries
!= rdev
->bss_entries
,
1024 "rdev bss entries[%d]/list[len:%d] corruption\n",
1025 rdev
->bss_entries
, n_entries
);
1030 struct cfg80211_non_tx_bss
{
1031 struct cfg80211_bss
*tx_bss
;
1032 u8 max_bssid_indicator
;
1036 /* Returned bss is reference counted and must be cleaned up appropriately. */
1037 static struct cfg80211_internal_bss
*
1038 cfg80211_bss_update(struct cfg80211_registered_device
*rdev
,
1039 struct cfg80211_internal_bss
*tmp
,
1042 struct cfg80211_internal_bss
*found
= NULL
;
1044 if (WARN_ON(!tmp
->pub
.channel
))
1049 spin_lock_bh(&rdev
->bss_lock
);
1051 if (WARN_ON(!rcu_access_pointer(tmp
->pub
.ies
))) {
1052 spin_unlock_bh(&rdev
->bss_lock
);
1056 found
= rb_find_bss(rdev
, tmp
, BSS_CMP_REGULAR
);
1060 if (rcu_access_pointer(tmp
->pub
.proberesp_ies
)) {
1061 const struct cfg80211_bss_ies
*old
;
1063 old
= rcu_access_pointer(found
->pub
.proberesp_ies
);
1065 rcu_assign_pointer(found
->pub
.proberesp_ies
,
1066 tmp
->pub
.proberesp_ies
);
1067 /* Override possible earlier Beacon frame IEs */
1068 rcu_assign_pointer(found
->pub
.ies
,
1069 tmp
->pub
.proberesp_ies
);
1071 kfree_rcu((struct cfg80211_bss_ies
*)old
,
1073 } else if (rcu_access_pointer(tmp
->pub
.beacon_ies
)) {
1074 const struct cfg80211_bss_ies
*old
;
1075 struct cfg80211_internal_bss
*bss
;
1077 if (found
->pub
.hidden_beacon_bss
&&
1078 !list_empty(&found
->hidden_list
)) {
1079 const struct cfg80211_bss_ies
*f
;
1082 * The found BSS struct is one of the probe
1083 * response members of a group, but we're
1084 * receiving a beacon (beacon_ies in the tmp
1085 * bss is used). This can only mean that the
1086 * AP changed its beacon from not having an
1087 * SSID to showing it, which is confusing so
1088 * drop this information.
1091 f
= rcu_access_pointer(tmp
->pub
.beacon_ies
);
1092 kfree_rcu((struct cfg80211_bss_ies
*)f
,
1097 old
= rcu_access_pointer(found
->pub
.beacon_ies
);
1099 rcu_assign_pointer(found
->pub
.beacon_ies
,
1100 tmp
->pub
.beacon_ies
);
1102 /* Override IEs if they were from a beacon before */
1103 if (old
== rcu_access_pointer(found
->pub
.ies
))
1104 rcu_assign_pointer(found
->pub
.ies
,
1105 tmp
->pub
.beacon_ies
);
1107 /* Assign beacon IEs to all sub entries */
1108 list_for_each_entry(bss
, &found
->hidden_list
,
1110 const struct cfg80211_bss_ies
*ies
;
1112 ies
= rcu_access_pointer(bss
->pub
.beacon_ies
);
1113 WARN_ON(ies
!= old
);
1115 rcu_assign_pointer(bss
->pub
.beacon_ies
,
1116 tmp
->pub
.beacon_ies
);
1120 kfree_rcu((struct cfg80211_bss_ies
*)old
,
1124 found
->pub
.beacon_interval
= tmp
->pub
.beacon_interval
;
1126 * don't update the signal if beacon was heard on
1130 found
->pub
.signal
= tmp
->pub
.signal
;
1131 found
->pub
.capability
= tmp
->pub
.capability
;
1132 found
->ts
= tmp
->ts
;
1133 found
->ts_boottime
= tmp
->ts_boottime
;
1134 found
->parent_tsf
= tmp
->parent_tsf
;
1135 found
->pub
.chains
= tmp
->pub
.chains
;
1136 memcpy(found
->pub
.chain_signal
, tmp
->pub
.chain_signal
,
1137 IEEE80211_MAX_CHAINS
);
1138 ether_addr_copy(found
->parent_bssid
, tmp
->parent_bssid
);
1139 found
->pub
.max_bssid_indicator
= tmp
->pub
.max_bssid_indicator
;
1140 found
->pub
.bssid_index
= tmp
->pub
.bssid_index
;
1142 struct cfg80211_internal_bss
*new;
1143 struct cfg80211_internal_bss
*hidden
;
1144 struct cfg80211_bss_ies
*ies
;
1147 * create a copy -- the "res" variable that is passed in
1148 * is allocated on the stack since it's not needed in the
1149 * more common case of an update
1151 new = kzalloc(sizeof(*new) + rdev
->wiphy
.bss_priv_size
,
1154 ies
= (void *)rcu_dereference(tmp
->pub
.beacon_ies
);
1156 kfree_rcu(ies
, rcu_head
);
1157 ies
= (void *)rcu_dereference(tmp
->pub
.proberesp_ies
);
1159 kfree_rcu(ies
, rcu_head
);
1162 memcpy(new, tmp
, sizeof(*new));
1164 INIT_LIST_HEAD(&new->hidden_list
);
1165 INIT_LIST_HEAD(&new->pub
.nontrans_list
);
1167 if (rcu_access_pointer(tmp
->pub
.proberesp_ies
)) {
1168 hidden
= rb_find_bss(rdev
, tmp
, BSS_CMP_HIDE_ZLEN
);
1170 hidden
= rb_find_bss(rdev
, tmp
,
1173 new->pub
.hidden_beacon_bss
= &hidden
->pub
;
1174 list_add(&new->hidden_list
,
1175 &hidden
->hidden_list
);
1177 rcu_assign_pointer(new->pub
.beacon_ies
,
1178 hidden
->pub
.beacon_ies
);
1182 * Ok so we found a beacon, and don't have an entry. If
1183 * it's a beacon with hidden SSID, we might be in for an
1184 * expensive search for any probe responses that should
1185 * be grouped with this beacon for updates ...
1187 if (!cfg80211_combine_bsses(rdev
, new)) {
1193 if (rdev
->bss_entries
>= bss_entries_limit
&&
1194 !cfg80211_bss_expire_oldest(rdev
)) {
1199 /* This must be before the call to bss_ref_get */
1200 if (tmp
->pub
.transmitted_bss
) {
1201 struct cfg80211_internal_bss
*pbss
=
1202 container_of(tmp
->pub
.transmitted_bss
,
1203 struct cfg80211_internal_bss
,
1206 new->pub
.transmitted_bss
= tmp
->pub
.transmitted_bss
;
1207 bss_ref_get(rdev
, pbss
);
1210 list_add_tail(&new->list
, &rdev
->bss_list
);
1211 rdev
->bss_entries
++;
1212 rb_insert_bss(rdev
, new);
1216 rdev
->bss_generation
++;
1217 bss_ref_get(rdev
, found
);
1218 spin_unlock_bh(&rdev
->bss_lock
);
1222 spin_unlock_bh(&rdev
->bss_lock
);
1227 * Update RX channel information based on the available frame payload
1228 * information. This is mainly for the 2.4 GHz band where frames can be received
1229 * from neighboring channels and the Beacon frames use the DSSS Parameter Set
1230 * element to indicate the current (transmitting) channel, but this might also
1231 * be needed on other bands if RX frequency does not match with the actual
1232 * operating channel of a BSS.
1234 static struct ieee80211_channel
*
1235 cfg80211_get_bss_channel(struct wiphy
*wiphy
, const u8
*ie
, size_t ielen
,
1236 struct ieee80211_channel
*channel
,
1237 enum nl80211_bss_scan_width scan_width
)
1241 int channel_number
= -1;
1242 struct ieee80211_channel
*alt_channel
;
1244 tmp
= cfg80211_find_ie(WLAN_EID_DS_PARAMS
, ie
, ielen
);
1245 if (tmp
&& tmp
[1] == 1) {
1246 channel_number
= tmp
[2];
1248 tmp
= cfg80211_find_ie(WLAN_EID_HT_OPERATION
, ie
, ielen
);
1249 if (tmp
&& tmp
[1] >= sizeof(struct ieee80211_ht_operation
)) {
1250 struct ieee80211_ht_operation
*htop
= (void *)(tmp
+ 2);
1252 channel_number
= htop
->primary_chan
;
1256 if (channel_number
< 0) {
1257 /* No channel information in frame payload */
1261 freq
= ieee80211_channel_to_frequency(channel_number
, channel
->band
);
1262 alt_channel
= ieee80211_get_channel(wiphy
, freq
);
1264 if (channel
->band
== NL80211_BAND_2GHZ
) {
1266 * Better not allow unexpected channels when that could
1267 * be going beyond the 1-11 range (e.g., discovering
1268 * BSS on channel 12 when radio is configured for
1274 /* No match for the payload channel number - ignore it */
1278 if (scan_width
== NL80211_BSS_CHAN_WIDTH_10
||
1279 scan_width
== NL80211_BSS_CHAN_WIDTH_5
) {
1281 * Ignore channel number in 5 and 10 MHz channels where there
1282 * may not be an n:1 or 1:n mapping between frequencies and
1289 * Use the channel determined through the payload channel number
1290 * instead of the RX channel reported by the driver.
1292 if (alt_channel
->flags
& IEEE80211_CHAN_DISABLED
)
1297 /* Returned bss is reference counted and must be cleaned up appropriately. */
1298 static struct cfg80211_bss
*
1299 cfg80211_inform_single_bss_data(struct wiphy
*wiphy
,
1300 struct cfg80211_inform_bss
*data
,
1301 enum cfg80211_bss_frame_type ftype
,
1302 const u8
*bssid
, u64 tsf
, u16 capability
,
1303 u16 beacon_interval
, const u8
*ie
, size_t ielen
,
1304 struct cfg80211_non_tx_bss
*non_tx_data
,
1307 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1308 struct cfg80211_bss_ies
*ies
;
1309 struct ieee80211_channel
*channel
;
1310 struct cfg80211_internal_bss tmp
= {}, *res
;
1314 if (WARN_ON(!wiphy
))
1317 if (WARN_ON(wiphy
->signal_type
== CFG80211_SIGNAL_TYPE_UNSPEC
&&
1318 (data
->signal
< 0 || data
->signal
> 100)))
1321 channel
= cfg80211_get_bss_channel(wiphy
, ie
, ielen
, data
->chan
,
1326 memcpy(tmp
.pub
.bssid
, bssid
, ETH_ALEN
);
1327 tmp
.pub
.channel
= channel
;
1328 tmp
.pub
.scan_width
= data
->scan_width
;
1329 tmp
.pub
.signal
= data
->signal
;
1330 tmp
.pub
.beacon_interval
= beacon_interval
;
1331 tmp
.pub
.capability
= capability
;
1332 tmp
.ts_boottime
= data
->boottime_ns
;
1334 tmp
.pub
.transmitted_bss
= non_tx_data
->tx_bss
;
1335 tmp
.pub
.bssid_index
= non_tx_data
->bssid_index
;
1336 tmp
.pub
.max_bssid_indicator
= non_tx_data
->max_bssid_indicator
;
1340 * If we do not know here whether the IEs are from a Beacon or Probe
1341 * Response frame, we need to pick one of the options and only use it
1342 * with the driver that does not provide the full Beacon/Probe Response
1343 * frame. Use Beacon frame pointer to avoid indicating that this should
1344 * override the IEs pointer should we have received an earlier
1345 * indication of Probe Response data.
1347 ies
= kzalloc(sizeof(*ies
) + ielen
, gfp
);
1352 ies
->from_beacon
= false;
1353 memcpy(ies
->data
, ie
, ielen
);
1356 case CFG80211_BSS_FTYPE_BEACON
:
1357 ies
->from_beacon
= true;
1359 case CFG80211_BSS_FTYPE_UNKNOWN
:
1360 rcu_assign_pointer(tmp
.pub
.beacon_ies
, ies
);
1362 case CFG80211_BSS_FTYPE_PRESP
:
1363 rcu_assign_pointer(tmp
.pub
.proberesp_ies
, ies
);
1366 rcu_assign_pointer(tmp
.pub
.ies
, ies
);
1368 signal_valid
= abs(data
->chan
->center_freq
- channel
->center_freq
) <=
1369 wiphy
->max_adj_channel_rssi_comp
;
1370 res
= cfg80211_bss_update(wiphy_to_rdev(wiphy
), &tmp
, signal_valid
);
1374 if (channel
->band
== NL80211_BAND_60GHZ
) {
1375 bss_type
= res
->pub
.capability
& WLAN_CAPABILITY_DMG_TYPE_MASK
;
1376 if (bss_type
== WLAN_CAPABILITY_DMG_TYPE_AP
||
1377 bss_type
== WLAN_CAPABILITY_DMG_TYPE_PBSS
)
1378 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1380 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
1381 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1384 if (non_tx_data
&& non_tx_data
->tx_bss
) {
1385 /* this is a nontransmitting bss, we need to add it to
1386 * transmitting bss' list if it is not there
1388 if (cfg80211_add_nontrans_list(non_tx_data
->tx_bss
,
1390 if (__cfg80211_unlink_bss(rdev
, res
))
1391 rdev
->bss_generation
++;
1395 trace_cfg80211_return_bss(&res
->pub
);
1396 /* cfg80211_bss_update gives us a referenced result */
1400 static void cfg80211_parse_mbssid_data(struct wiphy
*wiphy
,
1401 struct cfg80211_inform_bss
*data
,
1402 enum cfg80211_bss_frame_type ftype
,
1403 const u8
*bssid
, u64 tsf
,
1404 u16 beacon_interval
, const u8
*ie
,
1406 struct cfg80211_non_tx_bss
*non_tx_data
,
1409 const u8
*mbssid_index_ie
;
1410 const struct element
*elem
, *sub
;
1412 u8 new_bssid
[ETH_ALEN
];
1415 struct cfg80211_bss
*bss
;
1419 if (!cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID
, ie
, ielen
))
1421 if (!wiphy
->support_mbssid
)
1423 if (wiphy
->support_only_he_mbssid
&&
1424 !cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY
, ie
, ielen
))
1427 new_ie
= kmalloc(IEEE80211_MAX_DATA_LEN
, gfp
);
1431 for_each_element_id(elem
, WLAN_EID_MULTIPLE_BSSID
, ie
, ielen
) {
1432 if (elem
->datalen
< 4)
1434 for_each_element(sub
, elem
->data
+ 1, elem
->datalen
- 1) {
1435 if (sub
->id
!= 0 || sub
->datalen
< 4) {
1436 /* not a valid BSS profile */
1440 if (sub
->data
[0] != WLAN_EID_NON_TX_BSSID_CAP
||
1441 sub
->data
[1] != 2) {
1442 /* The first element within the Nontransmitted
1443 * BSSID Profile is not the Nontransmitted
1444 * BSSID Capability element.
1449 /* found a Nontransmitted BSSID Profile */
1450 mbssid_index_ie
= cfg80211_find_ie
1451 (WLAN_EID_MULTI_BSSID_IDX
,
1452 sub
->data
, sub
->datalen
);
1453 if (!mbssid_index_ie
|| mbssid_index_ie
[1] < 1 ||
1454 mbssid_index_ie
[2] == 0) {
1455 /* No valid Multiple BSSID-Index element */
1459 non_tx_data
->bssid_index
= mbssid_index_ie
[2];
1460 non_tx_data
->max_bssid_indicator
= elem
->data
[0];
1462 cfg80211_gen_new_bssid(bssid
,
1463 non_tx_data
->max_bssid_indicator
,
1464 non_tx_data
->bssid_index
,
1466 memset(new_ie
, 0, IEEE80211_MAX_DATA_LEN
);
1467 new_ie_len
= cfg80211_gen_new_ie(ie
, ielen
, sub
->data
,
1468 sub
->datalen
, new_ie
,
1473 capability
= get_unaligned_le16(sub
->data
+ 2);
1474 bss
= cfg80211_inform_single_bss_data(wiphy
, data
,
1485 cfg80211_put_bss(wiphy
, bss
);
1492 struct cfg80211_bss
*
1493 cfg80211_inform_bss_data(struct wiphy
*wiphy
,
1494 struct cfg80211_inform_bss
*data
,
1495 enum cfg80211_bss_frame_type ftype
,
1496 const u8
*bssid
, u64 tsf
, u16 capability
,
1497 u16 beacon_interval
, const u8
*ie
, size_t ielen
,
1500 struct cfg80211_bss
*res
;
1501 struct cfg80211_non_tx_bss non_tx_data
;
1503 res
= cfg80211_inform_single_bss_data(wiphy
, data
, ftype
, bssid
, tsf
,
1504 capability
, beacon_interval
, ie
,
1506 non_tx_data
.tx_bss
= res
;
1507 cfg80211_parse_mbssid_data(wiphy
, data
, ftype
, bssid
, tsf
,
1508 beacon_interval
, ie
, ielen
, &non_tx_data
,
1512 EXPORT_SYMBOL(cfg80211_inform_bss_data
);
1515 cfg80211_parse_mbssid_frame_data(struct wiphy
*wiphy
,
1516 struct cfg80211_inform_bss
*data
,
1517 struct ieee80211_mgmt
*mgmt
, size_t len
,
1518 struct cfg80211_non_tx_bss
*non_tx_data
,
1521 enum cfg80211_bss_frame_type ftype
;
1522 const u8
*ie
= mgmt
->u
.probe_resp
.variable
;
1523 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
1524 u
.probe_resp
.variable
);
1526 ftype
= ieee80211_is_beacon(mgmt
->frame_control
) ?
1527 CFG80211_BSS_FTYPE_BEACON
: CFG80211_BSS_FTYPE_PRESP
;
1529 cfg80211_parse_mbssid_data(wiphy
, data
, ftype
, mgmt
->bssid
,
1530 le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
),
1531 le16_to_cpu(mgmt
->u
.probe_resp
.beacon_int
),
1532 ie
, ielen
, non_tx_data
, gfp
);
1536 cfg80211_update_notlisted_nontrans(struct wiphy
*wiphy
,
1537 struct cfg80211_bss
*nontrans_bss
,
1538 struct ieee80211_mgmt
*mgmt
, size_t len
,
1541 u8
*ie
, *new_ie
, *pos
;
1542 const u8
*nontrans_ssid
, *trans_ssid
, *mbssid
;
1543 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
1544 u
.probe_resp
.variable
);
1546 struct cfg80211_bss_ies
*new_ies
;
1547 const struct cfg80211_bss_ies
*old
;
1550 ie
= mgmt
->u
.probe_resp
.variable
;
1553 trans_ssid
= cfg80211_find_ie(WLAN_EID_SSID
, ie
, ielen
);
1556 new_ie_len
-= trans_ssid
[1];
1557 mbssid
= cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID
, ie
, ielen
);
1560 new_ie_len
-= mbssid
[1];
1562 nontrans_ssid
= ieee80211_bss_get_ie(nontrans_bss
, WLAN_EID_SSID
);
1563 if (!nontrans_ssid
) {
1567 new_ie_len
+= nontrans_ssid
[1];
1570 /* generate new ie for nontrans BSS
1571 * 1. replace SSID with nontrans BSS' SSID
1574 new_ie
= kzalloc(new_ie_len
, gfp
);
1577 new_ies
= kzalloc(sizeof(*new_ies
) + new_ie_len
, gfp
);
1583 /* copy the nontransmitted SSID */
1584 cpy_len
= nontrans_ssid
[1] + 2;
1585 memcpy(pos
, nontrans_ssid
, cpy_len
);
1587 /* copy the IEs between SSID and MBSSID */
1588 cpy_len
= trans_ssid
[1] + 2;
1589 memcpy(pos
, (trans_ssid
+ cpy_len
), (mbssid
- (trans_ssid
+ cpy_len
)));
1590 pos
+= (mbssid
- (trans_ssid
+ cpy_len
));
1591 /* copy the IEs after MBSSID */
1592 cpy_len
= mbssid
[1] + 2;
1593 memcpy(pos
, mbssid
+ cpy_len
, ((ie
+ ielen
) - (mbssid
+ cpy_len
)));
1596 new_ies
->len
= new_ie_len
;
1597 new_ies
->tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
1598 new_ies
->from_beacon
= ieee80211_is_beacon(mgmt
->frame_control
);
1599 memcpy(new_ies
->data
, new_ie
, new_ie_len
);
1600 if (ieee80211_is_probe_resp(mgmt
->frame_control
)) {
1601 old
= rcu_access_pointer(nontrans_bss
->proberesp_ies
);
1602 rcu_assign_pointer(nontrans_bss
->proberesp_ies
, new_ies
);
1603 rcu_assign_pointer(nontrans_bss
->ies
, new_ies
);
1605 kfree_rcu((struct cfg80211_bss_ies
*)old
, rcu_head
);
1607 old
= rcu_access_pointer(nontrans_bss
->beacon_ies
);
1608 rcu_assign_pointer(nontrans_bss
->beacon_ies
, new_ies
);
1609 rcu_assign_pointer(nontrans_bss
->ies
, new_ies
);
1611 kfree_rcu((struct cfg80211_bss_ies
*)old
, rcu_head
);
1618 /* cfg80211_inform_bss_width_frame helper */
1619 static struct cfg80211_bss
*
1620 cfg80211_inform_single_bss_frame_data(struct wiphy
*wiphy
,
1621 struct cfg80211_inform_bss
*data
,
1622 struct ieee80211_mgmt
*mgmt
, size_t len
,
1623 struct cfg80211_non_tx_bss
*non_tx_data
,
1626 struct cfg80211_internal_bss tmp
= {}, *res
;
1627 struct cfg80211_bss_ies
*ies
;
1628 struct ieee80211_channel
*channel
;
1630 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
1631 u
.probe_resp
.variable
);
1634 BUILD_BUG_ON(offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
) !=
1635 offsetof(struct ieee80211_mgmt
, u
.beacon
.variable
));
1637 trace_cfg80211_inform_bss_frame(wiphy
, data
, mgmt
, len
);
1642 if (WARN_ON(!wiphy
))
1645 if (WARN_ON(wiphy
->signal_type
== CFG80211_SIGNAL_TYPE_UNSPEC
&&
1646 (data
->signal
< 0 || data
->signal
> 100)))
1649 if (WARN_ON(len
< offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
)))
1652 channel
= cfg80211_get_bss_channel(wiphy
, mgmt
->u
.beacon
.variable
,
1653 ielen
, data
->chan
, data
->scan_width
);
1657 ies
= kzalloc(sizeof(*ies
) + ielen
, gfp
);
1661 ies
->tsf
= le64_to_cpu(mgmt
->u
.probe_resp
.timestamp
);
1662 ies
->from_beacon
= ieee80211_is_beacon(mgmt
->frame_control
);
1663 memcpy(ies
->data
, mgmt
->u
.probe_resp
.variable
, ielen
);
1665 if (ieee80211_is_probe_resp(mgmt
->frame_control
))
1666 rcu_assign_pointer(tmp
.pub
.proberesp_ies
, ies
);
1668 rcu_assign_pointer(tmp
.pub
.beacon_ies
, ies
);
1669 rcu_assign_pointer(tmp
.pub
.ies
, ies
);
1671 memcpy(tmp
.pub
.bssid
, mgmt
->bssid
, ETH_ALEN
);
1672 tmp
.pub
.channel
= channel
;
1673 tmp
.pub
.scan_width
= data
->scan_width
;
1674 tmp
.pub
.signal
= data
->signal
;
1675 tmp
.pub
.beacon_interval
= le16_to_cpu(mgmt
->u
.probe_resp
.beacon_int
);
1676 tmp
.pub
.capability
= le16_to_cpu(mgmt
->u
.probe_resp
.capab_info
);
1677 tmp
.ts_boottime
= data
->boottime_ns
;
1678 tmp
.parent_tsf
= data
->parent_tsf
;
1679 tmp
.pub
.chains
= data
->chains
;
1680 memcpy(tmp
.pub
.chain_signal
, data
->chain_signal
, IEEE80211_MAX_CHAINS
);
1681 ether_addr_copy(tmp
.parent_bssid
, data
->parent_bssid
);
1683 tmp
.pub
.transmitted_bss
= non_tx_data
->tx_bss
;
1684 tmp
.pub
.bssid_index
= non_tx_data
->bssid_index
;
1685 tmp
.pub
.max_bssid_indicator
= non_tx_data
->max_bssid_indicator
;
1688 signal_valid
= abs(data
->chan
->center_freq
- channel
->center_freq
) <=
1689 wiphy
->max_adj_channel_rssi_comp
;
1690 res
= cfg80211_bss_update(wiphy_to_rdev(wiphy
), &tmp
, signal_valid
);
1694 if (channel
->band
== NL80211_BAND_60GHZ
) {
1695 bss_type
= res
->pub
.capability
& WLAN_CAPABILITY_DMG_TYPE_MASK
;
1696 if (bss_type
== WLAN_CAPABILITY_DMG_TYPE_AP
||
1697 bss_type
== WLAN_CAPABILITY_DMG_TYPE_PBSS
)
1698 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1700 if (res
->pub
.capability
& WLAN_CAPABILITY_ESS
)
1701 regulatory_hint_found_beacon(wiphy
, channel
, gfp
);
1704 trace_cfg80211_return_bss(&res
->pub
);
1705 /* cfg80211_bss_update gives us a referenced result */
1709 struct cfg80211_bss
*
1710 cfg80211_inform_bss_frame_data(struct wiphy
*wiphy
,
1711 struct cfg80211_inform_bss
*data
,
1712 struct ieee80211_mgmt
*mgmt
, size_t len
,
1715 struct cfg80211_bss
*res
, *tmp_bss
;
1716 const u8
*ie
= mgmt
->u
.probe_resp
.variable
;
1717 const struct cfg80211_bss_ies
*ies1
, *ies2
;
1718 size_t ielen
= len
- offsetof(struct ieee80211_mgmt
,
1719 u
.probe_resp
.variable
);
1720 struct cfg80211_non_tx_bss non_tx_data
;
1722 res
= cfg80211_inform_single_bss_frame_data(wiphy
, data
, mgmt
,
1724 if (!res
|| !wiphy
->support_mbssid
||
1725 !cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID
, ie
, ielen
))
1727 if (wiphy
->support_only_he_mbssid
&&
1728 !cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY
, ie
, ielen
))
1731 non_tx_data
.tx_bss
= res
;
1732 /* process each non-transmitting bss */
1733 cfg80211_parse_mbssid_frame_data(wiphy
, data
, mgmt
, len
,
1736 /* check if the res has other nontransmitting bss which is not
1739 ies1
= rcu_access_pointer(res
->ies
);
1741 /* go through nontrans_list, if the timestamp of the BSS is
1742 * earlier than the timestamp of the transmitting BSS then
1745 list_for_each_entry(tmp_bss
, &res
->nontrans_list
,
1747 ies2
= rcu_access_pointer(tmp_bss
->ies
);
1748 if (ies2
->tsf
< ies1
->tsf
)
1749 cfg80211_update_notlisted_nontrans(wiphy
, tmp_bss
,
1755 EXPORT_SYMBOL(cfg80211_inform_bss_frame_data
);
1757 void cfg80211_ref_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1759 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1760 struct cfg80211_internal_bss
*bss
;
1765 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1767 spin_lock_bh(&rdev
->bss_lock
);
1768 bss_ref_get(rdev
, bss
);
1769 spin_unlock_bh(&rdev
->bss_lock
);
1771 EXPORT_SYMBOL(cfg80211_ref_bss
);
1773 void cfg80211_put_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1775 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1776 struct cfg80211_internal_bss
*bss
;
1781 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1783 spin_lock_bh(&rdev
->bss_lock
);
1784 bss_ref_put(rdev
, bss
);
1785 spin_unlock_bh(&rdev
->bss_lock
);
1787 EXPORT_SYMBOL(cfg80211_put_bss
);
1789 void cfg80211_unlink_bss(struct wiphy
*wiphy
, struct cfg80211_bss
*pub
)
1791 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
1792 struct cfg80211_internal_bss
*bss
, *tmp1
;
1793 struct cfg80211_bss
*nontrans_bss
, *tmp
;
1798 bss
= container_of(pub
, struct cfg80211_internal_bss
, pub
);
1800 spin_lock_bh(&rdev
->bss_lock
);
1801 if (list_empty(&bss
->list
))
1804 list_for_each_entry_safe(nontrans_bss
, tmp
,
1805 &pub
->nontrans_list
,
1807 tmp1
= container_of(nontrans_bss
,
1808 struct cfg80211_internal_bss
, pub
);
1809 if (__cfg80211_unlink_bss(rdev
, tmp1
))
1810 rdev
->bss_generation
++;
1813 if (__cfg80211_unlink_bss(rdev
, bss
))
1814 rdev
->bss_generation
++;
1816 spin_unlock_bh(&rdev
->bss_lock
);
1818 EXPORT_SYMBOL(cfg80211_unlink_bss
);
1820 #ifdef CONFIG_CFG80211_WEXT
1821 static struct cfg80211_registered_device
*
1822 cfg80211_get_dev_from_ifindex(struct net
*net
, int ifindex
)
1824 struct cfg80211_registered_device
*rdev
;
1825 struct net_device
*dev
;
1829 dev
= dev_get_by_index(net
, ifindex
);
1831 return ERR_PTR(-ENODEV
);
1832 if (dev
->ieee80211_ptr
)
1833 rdev
= wiphy_to_rdev(dev
->ieee80211_ptr
->wiphy
);
1835 rdev
= ERR_PTR(-ENODEV
);
1840 int cfg80211_wext_siwscan(struct net_device
*dev
,
1841 struct iw_request_info
*info
,
1842 union iwreq_data
*wrqu
, char *extra
)
1844 struct cfg80211_registered_device
*rdev
;
1845 struct wiphy
*wiphy
;
1846 struct iw_scan_req
*wreq
= NULL
;
1847 struct cfg80211_scan_request
*creq
= NULL
;
1848 int i
, err
, n_channels
= 0;
1849 enum nl80211_band band
;
1851 if (!netif_running(dev
))
1854 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
))
1855 wreq
= (struct iw_scan_req
*)extra
;
1857 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
1860 return PTR_ERR(rdev
);
1862 if (rdev
->scan_req
|| rdev
->scan_msg
) {
1867 wiphy
= &rdev
->wiphy
;
1869 /* Determine number of channels, needed to allocate creq */
1870 if (wreq
&& wreq
->num_channels
)
1871 n_channels
= wreq
->num_channels
;
1873 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
1875 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
1876 n_channels
* sizeof(void *),
1883 creq
->wiphy
= wiphy
;
1884 creq
->wdev
= dev
->ieee80211_ptr
;
1885 /* SSIDs come after channels */
1886 creq
->ssids
= (void *)&creq
->channels
[n_channels
];
1887 creq
->n_channels
= n_channels
;
1889 creq
->scan_start
= jiffies
;
1891 /* translate "Scan on frequencies" request */
1893 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
1896 if (!wiphy
->bands
[band
])
1899 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
1900 /* ignore disabled channels */
1901 if (wiphy
->bands
[band
]->channels
[j
].flags
&
1902 IEEE80211_CHAN_DISABLED
)
1905 /* If we have a wireless request structure and the
1906 * wireless request specifies frequencies, then search
1907 * for the matching hardware channel.
1909 if (wreq
&& wreq
->num_channels
) {
1911 int wiphy_freq
= wiphy
->bands
[band
]->channels
[j
].center_freq
;
1912 for (k
= 0; k
< wreq
->num_channels
; k
++) {
1913 struct iw_freq
*freq
=
1914 &wreq
->channel_list
[k
];
1916 cfg80211_wext_freq(freq
);
1918 if (wext_freq
== wiphy_freq
)
1919 goto wext_freq_found
;
1921 goto wext_freq_not_found
;
1925 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
1927 wext_freq_not_found
: ;
1930 /* No channels found? */
1936 /* Set real number of channels specified in creq->channels[] */
1937 creq
->n_channels
= i
;
1939 /* translate "Scan for SSID" request */
1941 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
1942 if (wreq
->essid_len
> IEEE80211_MAX_SSID_LEN
) {
1946 memcpy(creq
->ssids
[0].ssid
, wreq
->essid
, wreq
->essid_len
);
1947 creq
->ssids
[0].ssid_len
= wreq
->essid_len
;
1949 if (wreq
->scan_type
== IW_SCAN_TYPE_PASSIVE
)
1953 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
1954 if (wiphy
->bands
[i
])
1955 creq
->rates
[i
] = (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
1957 eth_broadcast_addr(creq
->bssid
);
1959 rdev
->scan_req
= creq
;
1960 err
= rdev_scan(rdev
, creq
);
1962 rdev
->scan_req
= NULL
;
1963 /* creq will be freed below */
1965 nl80211_send_scan_start(rdev
, dev
->ieee80211_ptr
);
1966 /* creq now owned by driver */
1974 EXPORT_WEXT_HANDLER(cfg80211_wext_siwscan
);
1976 static char *ieee80211_scan_add_ies(struct iw_request_info
*info
,
1977 const struct cfg80211_bss_ies
*ies
,
1978 char *current_ev
, char *end_buf
)
1980 const u8
*pos
, *end
, *next
;
1981 struct iw_event iwe
;
1987 * If needed, fragment the IEs buffer (at IE boundaries) into short
1988 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
1991 end
= pos
+ ies
->len
;
1993 while (end
- pos
> IW_GENERIC_IE_MAX
) {
1994 next
= pos
+ 2 + pos
[1];
1995 while (next
+ 2 + next
[1] - pos
< IW_GENERIC_IE_MAX
)
1996 next
= next
+ 2 + next
[1];
1998 memset(&iwe
, 0, sizeof(iwe
));
1999 iwe
.cmd
= IWEVGENIE
;
2000 iwe
.u
.data
.length
= next
- pos
;
2001 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
2004 if (IS_ERR(current_ev
))
2010 memset(&iwe
, 0, sizeof(iwe
));
2011 iwe
.cmd
= IWEVGENIE
;
2012 iwe
.u
.data
.length
= end
- pos
;
2013 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
2016 if (IS_ERR(current_ev
))
2024 ieee80211_bss(struct wiphy
*wiphy
, struct iw_request_info
*info
,
2025 struct cfg80211_internal_bss
*bss
, char *current_ev
,
2028 const struct cfg80211_bss_ies
*ies
;
2029 struct iw_event iwe
;
2034 bool ismesh
= false;
2036 memset(&iwe
, 0, sizeof(iwe
));
2037 iwe
.cmd
= SIOCGIWAP
;
2038 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
2039 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->pub
.bssid
, ETH_ALEN
);
2040 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
2042 if (IS_ERR(current_ev
))
2045 memset(&iwe
, 0, sizeof(iwe
));
2046 iwe
.cmd
= SIOCGIWFREQ
;
2047 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->pub
.channel
->center_freq
);
2049 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
2051 if (IS_ERR(current_ev
))
2054 memset(&iwe
, 0, sizeof(iwe
));
2055 iwe
.cmd
= SIOCGIWFREQ
;
2056 iwe
.u
.freq
.m
= bss
->pub
.channel
->center_freq
;
2058 current_ev
= iwe_stream_add_event_check(info
, current_ev
, end_buf
, &iwe
,
2060 if (IS_ERR(current_ev
))
2063 if (wiphy
->signal_type
!= CFG80211_SIGNAL_TYPE_NONE
) {
2064 memset(&iwe
, 0, sizeof(iwe
));
2066 iwe
.u
.qual
.updated
= IW_QUAL_LEVEL_UPDATED
|
2067 IW_QUAL_NOISE_INVALID
|
2068 IW_QUAL_QUAL_UPDATED
;
2069 switch (wiphy
->signal_type
) {
2070 case CFG80211_SIGNAL_TYPE_MBM
:
2071 sig
= bss
->pub
.signal
/ 100;
2072 iwe
.u
.qual
.level
= sig
;
2073 iwe
.u
.qual
.updated
|= IW_QUAL_DBM
;
2074 if (sig
< -110) /* rather bad */
2076 else if (sig
> -40) /* perfect */
2078 /* will give a range of 0 .. 70 */
2079 iwe
.u
.qual
.qual
= sig
+ 110;
2081 case CFG80211_SIGNAL_TYPE_UNSPEC
:
2082 iwe
.u
.qual
.level
= bss
->pub
.signal
;
2083 /* will give range 0 .. 100 */
2084 iwe
.u
.qual
.qual
= bss
->pub
.signal
;
2090 current_ev
= iwe_stream_add_event_check(info
, current_ev
,
2093 if (IS_ERR(current_ev
))
2097 memset(&iwe
, 0, sizeof(iwe
));
2098 iwe
.cmd
= SIOCGIWENCODE
;
2099 if (bss
->pub
.capability
& WLAN_CAPABILITY_PRIVACY
)
2100 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
2102 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
2103 iwe
.u
.data
.length
= 0;
2104 current_ev
= iwe_stream_add_point_check(info
, current_ev
, end_buf
,
2106 if (IS_ERR(current_ev
))
2110 ies
= rcu_dereference(bss
->pub
.ies
);
2116 if (ie
[1] > rem
- 2)
2121 memset(&iwe
, 0, sizeof(iwe
));
2122 iwe
.cmd
= SIOCGIWESSID
;
2123 iwe
.u
.data
.length
= ie
[1];
2124 iwe
.u
.data
.flags
= 1;
2125 current_ev
= iwe_stream_add_point_check(info
,
2129 if (IS_ERR(current_ev
))
2132 case WLAN_EID_MESH_ID
:
2133 memset(&iwe
, 0, sizeof(iwe
));
2134 iwe
.cmd
= SIOCGIWESSID
;
2135 iwe
.u
.data
.length
= ie
[1];
2136 iwe
.u
.data
.flags
= 1;
2137 current_ev
= iwe_stream_add_point_check(info
,
2141 if (IS_ERR(current_ev
))
2144 case WLAN_EID_MESH_CONFIG
:
2146 if (ie
[1] != sizeof(struct ieee80211_meshconf_ie
))
2149 memset(&iwe
, 0, sizeof(iwe
));
2150 iwe
.cmd
= IWEVCUSTOM
;
2151 sprintf(buf
, "Mesh Network Path Selection Protocol ID: "
2153 iwe
.u
.data
.length
= strlen(buf
);
2154 current_ev
= iwe_stream_add_point_check(info
,
2158 if (IS_ERR(current_ev
))
2160 sprintf(buf
, "Path Selection Metric ID: 0x%02X",
2162 iwe
.u
.data
.length
= strlen(buf
);
2163 current_ev
= iwe_stream_add_point_check(info
,
2167 if (IS_ERR(current_ev
))
2169 sprintf(buf
, "Congestion Control Mode ID: 0x%02X",
2171 iwe
.u
.data
.length
= strlen(buf
);
2172 current_ev
= iwe_stream_add_point_check(info
,
2176 if (IS_ERR(current_ev
))
2178 sprintf(buf
, "Synchronization ID: 0x%02X", cfg
[3]);
2179 iwe
.u
.data
.length
= strlen(buf
);
2180 current_ev
= iwe_stream_add_point_check(info
,
2184 if (IS_ERR(current_ev
))
2186 sprintf(buf
, "Authentication ID: 0x%02X", cfg
[4]);
2187 iwe
.u
.data
.length
= strlen(buf
);
2188 current_ev
= iwe_stream_add_point_check(info
,
2192 if (IS_ERR(current_ev
))
2194 sprintf(buf
, "Formation Info: 0x%02X", cfg
[5]);
2195 iwe
.u
.data
.length
= strlen(buf
);
2196 current_ev
= iwe_stream_add_point_check(info
,
2200 if (IS_ERR(current_ev
))
2202 sprintf(buf
, "Capabilities: 0x%02X", cfg
[6]);
2203 iwe
.u
.data
.length
= strlen(buf
);
2204 current_ev
= iwe_stream_add_point_check(info
,
2208 if (IS_ERR(current_ev
))
2211 case WLAN_EID_SUPP_RATES
:
2212 case WLAN_EID_EXT_SUPP_RATES
:
2213 /* display all supported rates in readable format */
2214 p
= current_ev
+ iwe_stream_lcp_len(info
);
2216 memset(&iwe
, 0, sizeof(iwe
));
2217 iwe
.cmd
= SIOCGIWRATE
;
2218 /* Those two flags are ignored... */
2219 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
2221 for (i
= 0; i
< ie
[1]; i
++) {
2222 iwe
.u
.bitrate
.value
=
2223 ((ie
[i
+ 2] & 0x7f) * 500000);
2225 p
= iwe_stream_add_value(info
, current_ev
, p
,
2229 current_ev
= ERR_PTR(-E2BIG
);
2240 if (bss
->pub
.capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
) ||
2242 memset(&iwe
, 0, sizeof(iwe
));
2243 iwe
.cmd
= SIOCGIWMODE
;
2245 iwe
.u
.mode
= IW_MODE_MESH
;
2246 else if (bss
->pub
.capability
& WLAN_CAPABILITY_ESS
)
2247 iwe
.u
.mode
= IW_MODE_MASTER
;
2249 iwe
.u
.mode
= IW_MODE_ADHOC
;
2250 current_ev
= iwe_stream_add_event_check(info
, current_ev
,
2253 if (IS_ERR(current_ev
))
2257 memset(&iwe
, 0, sizeof(iwe
));
2258 iwe
.cmd
= IWEVCUSTOM
;
2259 sprintf(buf
, "tsf=%016llx", (unsigned long long)(ies
->tsf
));
2260 iwe
.u
.data
.length
= strlen(buf
);
2261 current_ev
= iwe_stream_add_point_check(info
, current_ev
, end_buf
,
2263 if (IS_ERR(current_ev
))
2265 memset(&iwe
, 0, sizeof(iwe
));
2266 iwe
.cmd
= IWEVCUSTOM
;
2267 sprintf(buf
, " Last beacon: %ums ago",
2268 elapsed_jiffies_msecs(bss
->ts
));
2269 iwe
.u
.data
.length
= strlen(buf
);
2270 current_ev
= iwe_stream_add_point_check(info
, current_ev
,
2271 end_buf
, &iwe
, buf
);
2272 if (IS_ERR(current_ev
))
2275 current_ev
= ieee80211_scan_add_ies(info
, ies
, current_ev
, end_buf
);
2283 static int ieee80211_scan_results(struct cfg80211_registered_device
*rdev
,
2284 struct iw_request_info
*info
,
2285 char *buf
, size_t len
)
2287 char *current_ev
= buf
;
2288 char *end_buf
= buf
+ len
;
2289 struct cfg80211_internal_bss
*bss
;
2292 spin_lock_bh(&rdev
->bss_lock
);
2293 cfg80211_bss_expire(rdev
);
2295 list_for_each_entry(bss
, &rdev
->bss_list
, list
) {
2296 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
2300 current_ev
= ieee80211_bss(&rdev
->wiphy
, info
, bss
,
2301 current_ev
, end_buf
);
2302 if (IS_ERR(current_ev
)) {
2303 err
= PTR_ERR(current_ev
);
2307 spin_unlock_bh(&rdev
->bss_lock
);
2311 return current_ev
- buf
;
2315 int cfg80211_wext_giwscan(struct net_device
*dev
,
2316 struct iw_request_info
*info
,
2317 struct iw_point
*data
, char *extra
)
2319 struct cfg80211_registered_device
*rdev
;
2322 if (!netif_running(dev
))
2325 rdev
= cfg80211_get_dev_from_ifindex(dev_net(dev
), dev
->ifindex
);
2328 return PTR_ERR(rdev
);
2330 if (rdev
->scan_req
|| rdev
->scan_msg
)
2333 res
= ieee80211_scan_results(rdev
, info
, extra
, data
->length
);
2342 EXPORT_WEXT_HANDLER(cfg80211_wext_giwscan
);