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-2021 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>
17 #include <linux/crc32.h>
18 #include <linux/bitfield.h>
20 #include <net/cfg80211.h>
21 #include <net/cfg80211-wext.h>
22 #include <net/iw_handler.h>
25 #include "wext-compat.h"
29 * DOC: BSS tree/list structure
31 * At the top level, the BSS list is kept in both a list in each
32 * registered device (@bss_list) as well as an RB-tree for faster
33 * lookup. In the RB-tree, entries can be looked up using their
34 * channel, MESHID, MESHCONF (for MBSSes) or channel, BSSID, SSID
37 * Due to the possibility of hidden SSIDs, there's a second level
38 * structure, the "hidden_list" and "hidden_beacon_bss" pointer.
39 * The hidden_list connects all BSSes belonging to a single AP
40 * that has a hidden SSID, and connects beacon and probe response
41 * entries. For a probe response entry for a hidden SSID, the
42 * hidden_beacon_bss pointer points to the BSS struct holding the
43 * beacon's information.
45 * Reference counting is done for all these references except for
46 * the hidden_list, so that a beacon BSS struct that is otherwise
47 * not referenced has one reference for being on the bss_list and
48 * one for each probe response entry that points to it using the
49 * hidden_beacon_bss pointer. When a BSS struct that has such a
50 * pointer is get/put, the refcount update is also propagated to
51 * the referenced struct, this ensure that it cannot get removed
52 * while somebody is using the probe response version.
54 * Note that the hidden_beacon_bss pointer never changes, due to
55 * the reference counting. Therefore, no locking is needed for
58 * Also note that the hidden_beacon_bss pointer is only relevant
59 * if the driver uses something other than the IEs, e.g. private
60 * data stored in the BSS struct, since the beacon IEs are
61 * also linked into the probe response struct.
65 * Limit the number of BSS entries stored in mac80211. Each one is
66 * a bit over 4k at most, so this limits to roughly 4-5M of memory.
67 * If somebody wants to really attack this though, they'd likely
68 * use small beacons, and only one type of frame, limiting each of
69 * the entries to a much smaller size (in order to generate more
70 * entries in total, so overhead is bigger.)
72 static int bss_entries_limit = 1000;
73 module_param(bss_entries_limit, int, 0644);
74 MODULE_PARM_DESC(bss_entries_limit,
75 "limit to number of scan BSS entries (per wiphy, default 1000)");
77 #define IEEE80211_SCAN_RESULT_EXPIRE (30 * HZ)
80 * struct cfg80211_colocated_ap - colocated AP information
82 * @list: linked list to all colocated aPS
83 * @bssid: BSSID of the reported AP
84 * @ssid: SSID of the reported AP
85 * @ssid_len: length of the ssid
86 * @center_freq: frequency the reported AP is on
87 * @unsolicited_probe: the reported AP is part of an ESS, where all the APs
88 * that operate in the same channel as the reported AP and that might be
89 * detected by a STA receiving this frame, are transmitting unsolicited
90 * Probe Response frames every 20 TUs
91 * @oct_recommended: OCT is recommended to exchange MMPDUs with the reported AP
92 * @same_ssid: the reported AP has the same SSID as the reporting AP
93 * @multi_bss: the reported AP is part of a multiple BSSID set
94 * @transmitted_bssid: the reported AP is the transmitting BSSID
95 * @colocated_ess: all the APs that share the same ESS as the reported AP are
96 * colocated and can be discovered via legacy bands.
97 * @short_ssid_valid: short_ssid is valid and can be used
98 * @short_ssid: the short SSID for this SSID
100 struct cfg80211_colocated_ap {
101 struct list_head list;
103 u8 ssid[IEEE80211_MAX_SSID_LEN];
107 u8 unsolicited_probe:1,
116 static void bss_free(struct cfg80211_internal_bss *bss)
118 struct cfg80211_bss_ies *ies;
120 if (WARN_ON(atomic_read(&bss->hold)))
123 ies = (void *)rcu_access_pointer(bss->pub.beacon_ies);
124 if (ies && !bss->pub.hidden_beacon_bss)
125 kfree_rcu(ies, rcu_head);
126 ies = (void *)rcu_access_pointer(bss->pub.proberesp_ies);
128 kfree_rcu(ies, rcu_head);
131 * This happens when the module is removed, it doesn't
132 * really matter any more save for completeness
134 if (!list_empty(&bss->hidden_list))
135 list_del(&bss->hidden_list);
140 static inline void bss_ref_get(struct cfg80211_registered_device *rdev,
141 struct cfg80211_internal_bss *bss)
143 lockdep_assert_held(&rdev->bss_lock);
147 if (bss->pub.hidden_beacon_bss)
148 bss_from_pub(bss->pub.hidden_beacon_bss)->refcount++;
150 if (bss->pub.transmitted_bss)
151 bss_from_pub(bss->pub.transmitted_bss)->refcount++;
154 static inline void bss_ref_put(struct cfg80211_registered_device *rdev,
155 struct cfg80211_internal_bss *bss)
157 lockdep_assert_held(&rdev->bss_lock);
159 if (bss->pub.hidden_beacon_bss) {
160 struct cfg80211_internal_bss *hbss;
161 hbss = container_of(bss->pub.hidden_beacon_bss,
162 struct cfg80211_internal_bss,
165 if (hbss->refcount == 0)
169 if (bss->pub.transmitted_bss) {
170 struct cfg80211_internal_bss *tbss;
172 tbss = container_of(bss->pub.transmitted_bss,
173 struct cfg80211_internal_bss,
176 if (tbss->refcount == 0)
181 if (bss->refcount == 0)
185 static bool __cfg80211_unlink_bss(struct cfg80211_registered_device *rdev,
186 struct cfg80211_internal_bss *bss)
188 lockdep_assert_held(&rdev->bss_lock);
190 if (!list_empty(&bss->hidden_list)) {
192 * don't remove the beacon entry if it has
193 * probe responses associated with it
195 if (!bss->pub.hidden_beacon_bss)
198 * if it's a probe response entry break its
199 * link to the other entries in the group
201 list_del_init(&bss->hidden_list);
204 list_del_init(&bss->list);
205 list_del_init(&bss->pub.nontrans_list);
206 rb_erase(&bss->rbn, &rdev->bss_tree);
208 WARN_ONCE((rdev->bss_entries == 0) ^ list_empty(&rdev->bss_list),
209 "rdev bss entries[%d]/list[empty:%d] corruption\n",
210 rdev->bss_entries, list_empty(&rdev->bss_list));
211 bss_ref_put(rdev, bss);
215 bool cfg80211_is_element_inherited(const struct element *elem,
216 const struct element *non_inherit_elem)
218 u8 id_len, ext_id_len, i, loop_len, id;
221 if (elem->id == WLAN_EID_MULTIPLE_BSSID)
224 if (!non_inherit_elem || non_inherit_elem->datalen < 2)
228 * non inheritance element format is:
229 * ext ID (56) | IDs list len | list | extension IDs list len | list
230 * Both lists are optional. Both lengths are mandatory.
231 * This means valid length is:
232 * elem_len = 1 (extension ID) + 2 (list len fields) + list lengths
234 id_len = non_inherit_elem->data[1];
235 if (non_inherit_elem->datalen < 3 + id_len)
238 ext_id_len = non_inherit_elem->data[2 + id_len];
239 if (non_inherit_elem->datalen < 3 + id_len + ext_id_len)
242 if (elem->id == WLAN_EID_EXTENSION) {
245 loop_len = ext_id_len;
246 list = &non_inherit_elem->data[3 + id_len];
252 list = &non_inherit_elem->data[2];
256 for (i = 0; i < loop_len; i++) {
263 EXPORT_SYMBOL(cfg80211_is_element_inherited);
265 static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
266 const u8 *subelement, size_t subie_len,
267 u8 *new_ie, gfp_t gfp)
270 const u8 *tmp_old, *tmp_new;
271 const struct element *non_inherit_elem;
274 /* copy subelement as we need to change its content to
275 * mark an ie after it is processed.
277 sub_copy = kmemdup(subelement, subie_len, gfp);
284 tmp_new = cfg80211_find_ie(WLAN_EID_SSID, sub_copy, subie_len);
286 memcpy(pos, tmp_new, tmp_new[1] + 2);
287 pos += (tmp_new[1] + 2);
290 /* get non inheritance list if exists */
292 cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
293 sub_copy, subie_len);
295 /* go through IEs in ie (skip SSID) and subelement,
296 * merge them into new_ie
298 tmp_old = cfg80211_find_ie(WLAN_EID_SSID, ie, ielen);
299 tmp_old = (tmp_old) ? tmp_old + tmp_old[1] + 2 : ie;
301 while (tmp_old + 2 - ie <= ielen &&
302 tmp_old + tmp_old[1] + 2 - ie <= ielen) {
303 if (tmp_old[0] == 0) {
308 if (tmp_old[0] == WLAN_EID_EXTENSION)
309 tmp = (u8 *)cfg80211_find_ext_ie(tmp_old[2], sub_copy,
312 tmp = (u8 *)cfg80211_find_ie(tmp_old[0], sub_copy,
316 const struct element *old_elem = (void *)tmp_old;
318 /* ie in old ie but not in subelement */
319 if (cfg80211_is_element_inherited(old_elem,
321 memcpy(pos, tmp_old, tmp_old[1] + 2);
322 pos += tmp_old[1] + 2;
325 /* ie in transmitting ie also in subelement,
326 * copy from subelement and flag the ie in subelement
327 * as copied (by setting eid field to WLAN_EID_SSID,
328 * which is skipped anyway).
329 * For vendor ie, compare OUI + type + subType to
330 * determine if they are the same ie.
332 if (tmp_old[0] == WLAN_EID_VENDOR_SPECIFIC) {
333 if (tmp_old[1] >= 5 && tmp[1] >= 5 &&
334 !memcmp(tmp_old + 2, tmp + 2, 5)) {
335 /* same vendor ie, copy from
338 memcpy(pos, tmp, tmp[1] + 2);
340 tmp[0] = WLAN_EID_SSID;
342 memcpy(pos, tmp_old, tmp_old[1] + 2);
343 pos += tmp_old[1] + 2;
346 /* copy ie from subelement into new ie */
347 memcpy(pos, tmp, tmp[1] + 2);
349 tmp[0] = WLAN_EID_SSID;
353 if (tmp_old + tmp_old[1] + 2 - ie == ielen)
356 tmp_old += tmp_old[1] + 2;
359 /* go through subelement again to check if there is any ie not
360 * copied to new ie, skip ssid, capability, bssid-index ie
363 while (tmp_new + 2 - sub_copy <= subie_len &&
364 tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) {
365 if (!(tmp_new[0] == WLAN_EID_NON_TX_BSSID_CAP ||
366 tmp_new[0] == WLAN_EID_SSID)) {
367 memcpy(pos, tmp_new, tmp_new[1] + 2);
368 pos += tmp_new[1] + 2;
370 if (tmp_new + tmp_new[1] + 2 - sub_copy == subie_len)
372 tmp_new += tmp_new[1] + 2;
379 static bool is_bss(struct cfg80211_bss *a, const u8 *bssid,
380 const u8 *ssid, size_t ssid_len)
382 const struct cfg80211_bss_ies *ies;
385 if (bssid && !ether_addr_equal(a->bssid, bssid))
391 ies = rcu_access_pointer(a->ies);
394 ssidie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
397 if (ssidie[1] != ssid_len)
399 return memcmp(ssidie + 2, ssid, ssid_len) == 0;
403 cfg80211_add_nontrans_list(struct cfg80211_bss *trans_bss,
404 struct cfg80211_bss *nontrans_bss)
408 struct cfg80211_bss *bss = NULL;
411 ssid = ieee80211_bss_get_ie(nontrans_bss, WLAN_EID_SSID);
419 /* check if nontrans_bss is in the list */
420 list_for_each_entry(bss, &trans_bss->nontrans_list, nontrans_list) {
421 if (is_bss(bss, nontrans_bss->bssid, ssid, ssid_len)) {
430 * This is a bit weird - it's not on the list, but already on another
431 * one! The only way that could happen is if there's some BSSID/SSID
432 * shared by multiple APs in their multi-BSSID profiles, potentially
433 * with hidden SSID mixed in ... ignore it.
435 if (!list_empty(&nontrans_bss->nontrans_list))
438 /* add to the list */
439 list_add_tail(&nontrans_bss->nontrans_list, &trans_bss->nontrans_list);
443 static void __cfg80211_bss_expire(struct cfg80211_registered_device *rdev,
444 unsigned long expire_time)
446 struct cfg80211_internal_bss *bss, *tmp;
447 bool expired = false;
449 lockdep_assert_held(&rdev->bss_lock);
451 list_for_each_entry_safe(bss, tmp, &rdev->bss_list, list) {
452 if (atomic_read(&bss->hold))
454 if (!time_after(expire_time, bss->ts))
457 if (__cfg80211_unlink_bss(rdev, bss))
462 rdev->bss_generation++;
465 static bool cfg80211_bss_expire_oldest(struct cfg80211_registered_device *rdev)
467 struct cfg80211_internal_bss *bss, *oldest = NULL;
470 lockdep_assert_held(&rdev->bss_lock);
472 list_for_each_entry(bss, &rdev->bss_list, list) {
473 if (atomic_read(&bss->hold))
476 if (!list_empty(&bss->hidden_list) &&
477 !bss->pub.hidden_beacon_bss)
480 if (oldest && time_before(oldest->ts, bss->ts))
485 if (WARN_ON(!oldest))
489 * The callers make sure to increase rdev->bss_generation if anything
490 * gets removed (and a new entry added), so there's no need to also do
494 ret = __cfg80211_unlink_bss(rdev, oldest);
499 static u8 cfg80211_parse_bss_param(u8 data,
500 struct cfg80211_colocated_ap *coloc_ap)
502 coloc_ap->oct_recommended =
503 u8_get_bits(data, IEEE80211_RNR_TBTT_PARAMS_OCT_RECOMMENDED);
504 coloc_ap->same_ssid =
505 u8_get_bits(data, IEEE80211_RNR_TBTT_PARAMS_SAME_SSID);
506 coloc_ap->multi_bss =
507 u8_get_bits(data, IEEE80211_RNR_TBTT_PARAMS_MULTI_BSSID);
508 coloc_ap->transmitted_bssid =
509 u8_get_bits(data, IEEE80211_RNR_TBTT_PARAMS_TRANSMITTED_BSSID);
510 coloc_ap->unsolicited_probe =
511 u8_get_bits(data, IEEE80211_RNR_TBTT_PARAMS_PROBE_ACTIVE);
512 coloc_ap->colocated_ess =
513 u8_get_bits(data, IEEE80211_RNR_TBTT_PARAMS_COLOC_ESS);
515 return u8_get_bits(data, IEEE80211_RNR_TBTT_PARAMS_COLOC_AP);
518 static int cfg80211_calc_short_ssid(const struct cfg80211_bss_ies *ies,
519 const struct element **elem, u32 *s_ssid)
522 *elem = cfg80211_find_elem(WLAN_EID_SSID, ies->data, ies->len);
523 if (!*elem || (*elem)->datalen > IEEE80211_MAX_SSID_LEN)
526 *s_ssid = ~crc32_le(~0, (*elem)->data, (*elem)->datalen);
530 static void cfg80211_free_coloc_ap_list(struct list_head *coloc_ap_list)
532 struct cfg80211_colocated_ap *ap, *tmp_ap;
534 list_for_each_entry_safe(ap, tmp_ap, coloc_ap_list, list) {
540 static int cfg80211_parse_ap_info(struct cfg80211_colocated_ap *entry,
541 const u8 *pos, u8 length,
542 const struct element *ssid_elem,
545 /* skip the TBTT offset */
548 memcpy(entry->bssid, pos, ETH_ALEN);
551 if (length == IEEE80211_TBTT_INFO_OFFSET_BSSID_SSSID_BSS_PARAM) {
552 memcpy(&entry->short_ssid, pos,
553 sizeof(entry->short_ssid));
554 entry->short_ssid_valid = true;
558 /* skip non colocated APs */
559 if (!cfg80211_parse_bss_param(*pos, entry))
563 if (length == IEEE80211_TBTT_INFO_OFFSET_BSSID_BSS_PARAM) {
565 * no information about the short ssid. Consider the entry valid
566 * for now. It would later be dropped in case there are explicit
567 * SSIDs that need to be matched
569 if (!entry->same_ssid)
573 if (entry->same_ssid) {
574 entry->short_ssid = s_ssid_tmp;
575 entry->short_ssid_valid = true;
578 * This is safe because we validate datalen in
579 * cfg80211_parse_colocated_ap(), before calling this
582 memcpy(&entry->ssid, &ssid_elem->data,
584 entry->ssid_len = ssid_elem->datalen;
589 static int cfg80211_parse_colocated_ap(const struct cfg80211_bss_ies *ies,
590 struct list_head *list)
592 struct ieee80211_neighbor_ap_info *ap_info;
593 const struct element *elem, *ssid_elem;
596 int n_coloc = 0, ret;
599 elem = cfg80211_find_elem(WLAN_EID_REDUCED_NEIGHBOR_REPORT, ies->data,
605 end = pos + elem->datalen;
607 ret = cfg80211_calc_short_ssid(ies, &ssid_elem, &s_ssid_tmp);
611 /* RNR IE may contain more than one NEIGHBOR_AP_INFO */
612 while (pos + sizeof(*ap_info) <= end) {
613 enum nl80211_band band;
617 ap_info = (void *)pos;
618 count = u8_get_bits(ap_info->tbtt_info_hdr,
619 IEEE80211_AP_INFO_TBTT_HDR_COUNT) + 1;
620 length = ap_info->tbtt_info_len;
622 pos += sizeof(*ap_info);
624 if (!ieee80211_operating_class_to_band(ap_info->op_class,
628 freq = ieee80211_channel_to_frequency(ap_info->channel, band);
630 if (end - pos < count * length)
634 * TBTT info must include bss param + BSSID +
635 * (short SSID or same_ssid bit to be set).
636 * ignore other options, and move to the
639 if (band != NL80211_BAND_6GHZ ||
640 (length != IEEE80211_TBTT_INFO_OFFSET_BSSID_BSS_PARAM &&
641 length < IEEE80211_TBTT_INFO_OFFSET_BSSID_SSSID_BSS_PARAM)) {
642 pos += count * length;
646 for (i = 0; i < count; i++) {
647 struct cfg80211_colocated_ap *entry;
649 entry = kzalloc(sizeof(*entry) + IEEE80211_MAX_SSID_LEN,
655 entry->center_freq = freq;
657 if (!cfg80211_parse_ap_info(entry, pos, length,
658 ssid_elem, s_ssid_tmp)) {
660 list_add_tail(&entry->list, &ap_list);
670 cfg80211_free_coloc_ap_list(&ap_list);
674 list_splice_tail(&ap_list, list);
678 static void cfg80211_scan_req_add_chan(struct cfg80211_scan_request *request,
679 struct ieee80211_channel *chan,
683 u32 n_channels = request->n_channels;
684 struct cfg80211_scan_6ghz_params *params =
685 &request->scan_6ghz_params[request->n_6ghz_params];
687 for (i = 0; i < n_channels; i++) {
688 if (request->channels[i] == chan) {
690 params->channel_idx = i;
695 request->channels[n_channels] = chan;
697 request->scan_6ghz_params[request->n_6ghz_params].channel_idx =
700 request->n_channels++;
703 static bool cfg80211_find_ssid_match(struct cfg80211_colocated_ap *ap,
704 struct cfg80211_scan_request *request)
709 for (i = 0; i < request->n_ssids; i++) {
710 /* wildcard ssid in the scan request */
711 if (!request->ssids[i].ssid_len) {
712 if (ap->multi_bss && !ap->transmitted_bssid)
719 ap->ssid_len == request->ssids[i].ssid_len) {
720 if (!memcmp(request->ssids[i].ssid, ap->ssid,
723 } else if (ap->short_ssid_valid) {
724 s_ssid = ~crc32_le(~0, request->ssids[i].ssid,
725 request->ssids[i].ssid_len);
727 if (ap->short_ssid == s_ssid)
735 static int cfg80211_scan_6ghz(struct cfg80211_registered_device *rdev)
738 struct cfg80211_colocated_ap *ap;
739 int n_channels, count = 0, err;
740 struct cfg80211_scan_request *request, *rdev_req = rdev->scan_req;
741 LIST_HEAD(coloc_ap_list);
742 bool need_scan_psc = true;
743 const struct ieee80211_sband_iftype_data *iftd;
745 rdev_req->scan_6ghz = true;
747 if (!rdev->wiphy.bands[NL80211_BAND_6GHZ])
750 iftd = ieee80211_get_sband_iftype_data(rdev->wiphy.bands[NL80211_BAND_6GHZ],
751 rdev_req->wdev->iftype);
752 if (!iftd || !iftd->he_cap.has_he)
755 n_channels = rdev->wiphy.bands[NL80211_BAND_6GHZ]->n_channels;
757 if (rdev_req->flags & NL80211_SCAN_FLAG_COLOCATED_6GHZ) {
758 struct cfg80211_internal_bss *intbss;
760 spin_lock_bh(&rdev->bss_lock);
761 list_for_each_entry(intbss, &rdev->bss_list, list) {
762 struct cfg80211_bss *res = &intbss->pub;
763 const struct cfg80211_bss_ies *ies;
765 ies = rcu_access_pointer(res->ies);
766 count += cfg80211_parse_colocated_ap(ies,
769 spin_unlock_bh(&rdev->bss_lock);
772 request = kzalloc(struct_size(request, channels, n_channels) +
773 sizeof(*request->scan_6ghz_params) * count +
774 sizeof(*request->ssids) * rdev_req->n_ssids,
777 cfg80211_free_coloc_ap_list(&coloc_ap_list);
781 *request = *rdev_req;
782 request->n_channels = 0;
783 request->scan_6ghz_params =
784 (void *)&request->channels[n_channels];
787 * PSC channels should not be scanned in case of direct scan with 1 SSID
788 * and at least one of the reported co-located APs with same SSID
789 * indicating that all APs in the same ESS are co-located
791 if (count && request->n_ssids == 1 && request->ssids[0].ssid_len) {
792 list_for_each_entry(ap, &coloc_ap_list, list) {
793 if (ap->colocated_ess &&
794 cfg80211_find_ssid_match(ap, request)) {
795 need_scan_psc = false;
802 * add to the scan request the channels that need to be scanned
803 * regardless of the collocated APs (PSC channels or all channels
804 * in case that NL80211_SCAN_FLAG_COLOCATED_6GHZ is not set)
806 for (i = 0; i < rdev_req->n_channels; i++) {
807 if (rdev_req->channels[i]->band == NL80211_BAND_6GHZ &&
809 cfg80211_channel_is_psc(rdev_req->channels[i])) ||
810 !(rdev_req->flags & NL80211_SCAN_FLAG_COLOCATED_6GHZ))) {
811 cfg80211_scan_req_add_chan(request,
812 rdev_req->channels[i],
817 if (!(rdev_req->flags & NL80211_SCAN_FLAG_COLOCATED_6GHZ))
820 list_for_each_entry(ap, &coloc_ap_list, list) {
822 struct cfg80211_scan_6ghz_params *scan_6ghz_params =
823 &request->scan_6ghz_params[request->n_6ghz_params];
824 struct ieee80211_channel *chan =
825 ieee80211_get_channel(&rdev->wiphy, ap->center_freq);
827 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
830 for (i = 0; i < rdev_req->n_channels; i++) {
831 if (rdev_req->channels[i] == chan)
838 if (request->n_ssids > 0 &&
839 !cfg80211_find_ssid_match(ap, request))
842 if (!request->n_ssids && ap->multi_bss && !ap->transmitted_bssid)
845 cfg80211_scan_req_add_chan(request, chan, true);
846 memcpy(scan_6ghz_params->bssid, ap->bssid, ETH_ALEN);
847 scan_6ghz_params->short_ssid = ap->short_ssid;
848 scan_6ghz_params->short_ssid_valid = ap->short_ssid_valid;
849 scan_6ghz_params->unsolicited_probe = ap->unsolicited_probe;
852 * If a PSC channel is added to the scan and 'need_scan_psc' is
853 * set to false, then all the APs that the scan logic is
854 * interested with on the channel are collocated and thus there
855 * is no need to perform the initial PSC channel listen.
857 if (cfg80211_channel_is_psc(chan) && !need_scan_psc)
858 scan_6ghz_params->psc_no_listen = true;
860 request->n_6ghz_params++;
864 cfg80211_free_coloc_ap_list(&coloc_ap_list);
866 if (request->n_channels) {
867 struct cfg80211_scan_request *old = rdev->int_scan_req;
868 rdev->int_scan_req = request;
871 * Add the ssids from the parent scan request to the new scan
872 * request, so the driver would be able to use them in its
873 * probe requests to discover hidden APs on PSC channels.
875 request->ssids = (void *)&request->channels[request->n_channels];
876 request->n_ssids = rdev_req->n_ssids;
877 memcpy(request->ssids, rdev_req->ssids, sizeof(*request->ssids) *
881 * If this scan follows a previous scan, save the scan start
882 * info from the first part of the scan
885 rdev->int_scan_req->info = old->info;
887 err = rdev_scan(rdev, request);
889 rdev->int_scan_req = old;
902 int cfg80211_scan(struct cfg80211_registered_device *rdev)
904 struct cfg80211_scan_request *request;
905 struct cfg80211_scan_request *rdev_req = rdev->scan_req;
906 u32 n_channels = 0, idx, i;
908 if (!(rdev->wiphy.flags & WIPHY_FLAG_SPLIT_SCAN_6GHZ))
909 return rdev_scan(rdev, rdev_req);
911 for (i = 0; i < rdev_req->n_channels; i++) {
912 if (rdev_req->channels[i]->band != NL80211_BAND_6GHZ)
917 return cfg80211_scan_6ghz(rdev);
919 request = kzalloc(struct_size(request, channels, n_channels),
924 *request = *rdev_req;
925 request->n_channels = n_channels;
927 for (i = idx = 0; i < rdev_req->n_channels; i++) {
928 if (rdev_req->channels[i]->band != NL80211_BAND_6GHZ)
929 request->channels[idx++] = rdev_req->channels[i];
932 rdev_req->scan_6ghz = false;
933 rdev->int_scan_req = request;
934 return rdev_scan(rdev, request);
937 void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
940 struct cfg80211_scan_request *request, *rdev_req;
941 struct wireless_dev *wdev;
943 #ifdef CONFIG_CFG80211_WEXT
944 union iwreq_data wrqu;
947 lockdep_assert_held(&rdev->wiphy.mtx);
949 if (rdev->scan_msg) {
950 nl80211_send_scan_msg(rdev, rdev->scan_msg);
951 rdev->scan_msg = NULL;
955 rdev_req = rdev->scan_req;
959 wdev = rdev_req->wdev;
960 request = rdev->int_scan_req ? rdev->int_scan_req : rdev_req;
962 if (wdev_running(wdev) &&
963 (rdev->wiphy.flags & WIPHY_FLAG_SPLIT_SCAN_6GHZ) &&
964 !rdev_req->scan_6ghz && !request->info.aborted &&
965 !cfg80211_scan_6ghz(rdev))
969 * This must be before sending the other events!
970 * Otherwise, wpa_supplicant gets completely confused with
974 cfg80211_sme_scan_done(wdev->netdev);
976 if (!request->info.aborted &&
977 request->flags & NL80211_SCAN_FLAG_FLUSH) {
978 /* flush entries from previous scans */
979 spin_lock_bh(&rdev->bss_lock);
980 __cfg80211_bss_expire(rdev, request->scan_start);
981 spin_unlock_bh(&rdev->bss_lock);
984 msg = nl80211_build_scan_msg(rdev, wdev, request->info.aborted);
986 #ifdef CONFIG_CFG80211_WEXT
987 if (wdev->netdev && !request->info.aborted) {
988 memset(&wrqu, 0, sizeof(wrqu));
990 wireless_send_event(wdev->netdev, SIOCGIWSCAN, &wrqu, NULL);
994 dev_put(wdev->netdev);
996 kfree(rdev->int_scan_req);
997 rdev->int_scan_req = NULL;
999 kfree(rdev->scan_req);
1000 rdev->scan_req = NULL;
1003 rdev->scan_msg = msg;
1005 nl80211_send_scan_msg(rdev, msg);
1008 void __cfg80211_scan_done(struct work_struct *wk)
1010 struct cfg80211_registered_device *rdev;
1012 rdev = container_of(wk, struct cfg80211_registered_device,
1015 wiphy_lock(&rdev->wiphy);
1016 ___cfg80211_scan_done(rdev, true);
1017 wiphy_unlock(&rdev->wiphy);
1020 void cfg80211_scan_done(struct cfg80211_scan_request *request,
1021 struct cfg80211_scan_info *info)
1023 struct cfg80211_scan_info old_info = request->info;
1025 trace_cfg80211_scan_done(request, info);
1026 WARN_ON(request != wiphy_to_rdev(request->wiphy)->scan_req &&
1027 request != wiphy_to_rdev(request->wiphy)->int_scan_req);
1029 request->info = *info;
1032 * In case the scan is split, the scan_start_tsf and tsf_bssid should
1033 * be of the first part. In such a case old_info.scan_start_tsf should
1036 if (request->scan_6ghz && old_info.scan_start_tsf) {
1037 request->info.scan_start_tsf = old_info.scan_start_tsf;
1038 memcpy(request->info.tsf_bssid, old_info.tsf_bssid,
1039 sizeof(request->info.tsf_bssid));
1042 request->notified = true;
1043 queue_work(cfg80211_wq, &wiphy_to_rdev(request->wiphy)->scan_done_wk);
1045 EXPORT_SYMBOL(cfg80211_scan_done);
1047 void cfg80211_add_sched_scan_req(struct cfg80211_registered_device *rdev,
1048 struct cfg80211_sched_scan_request *req)
1050 lockdep_assert_held(&rdev->wiphy.mtx);
1052 list_add_rcu(&req->list, &rdev->sched_scan_req_list);
1055 static void cfg80211_del_sched_scan_req(struct cfg80211_registered_device *rdev,
1056 struct cfg80211_sched_scan_request *req)
1058 lockdep_assert_held(&rdev->wiphy.mtx);
1060 list_del_rcu(&req->list);
1061 kfree_rcu(req, rcu_head);
1064 static struct cfg80211_sched_scan_request *
1065 cfg80211_find_sched_scan_req(struct cfg80211_registered_device *rdev, u64 reqid)
1067 struct cfg80211_sched_scan_request *pos;
1069 list_for_each_entry_rcu(pos, &rdev->sched_scan_req_list, list,
1070 lockdep_is_held(&rdev->wiphy.mtx)) {
1071 if (pos->reqid == reqid)
1078 * Determines if a scheduled scan request can be handled. When a legacy
1079 * scheduled scan is running no other scheduled scan is allowed regardless
1080 * whether the request is for legacy or multi-support scan. When a multi-support
1081 * scheduled scan is running a request for legacy scan is not allowed. In this
1082 * case a request for multi-support scan can be handled if resources are
1083 * available, ie. struct wiphy::max_sched_scan_reqs limit is not yet reached.
1085 int cfg80211_sched_scan_req_possible(struct cfg80211_registered_device *rdev,
1088 struct cfg80211_sched_scan_request *pos;
1091 list_for_each_entry(pos, &rdev->sched_scan_req_list, list) {
1092 /* request id zero means legacy in progress */
1093 if (!i && !pos->reqid)
1094 return -EINPROGRESS;
1099 /* no legacy allowed when multi request(s) are active */
1101 return -EINPROGRESS;
1103 /* resource limit reached */
1104 if (i == rdev->wiphy.max_sched_scan_reqs)
1110 void cfg80211_sched_scan_results_wk(struct work_struct *work)
1112 struct cfg80211_registered_device *rdev;
1113 struct cfg80211_sched_scan_request *req, *tmp;
1115 rdev = container_of(work, struct cfg80211_registered_device,
1118 wiphy_lock(&rdev->wiphy);
1119 list_for_each_entry_safe(req, tmp, &rdev->sched_scan_req_list, list) {
1120 if (req->report_results) {
1121 req->report_results = false;
1122 if (req->flags & NL80211_SCAN_FLAG_FLUSH) {
1123 /* flush entries from previous scans */
1124 spin_lock_bh(&rdev->bss_lock);
1125 __cfg80211_bss_expire(rdev, req->scan_start);
1126 spin_unlock_bh(&rdev->bss_lock);
1127 req->scan_start = jiffies;
1129 nl80211_send_sched_scan(req,
1130 NL80211_CMD_SCHED_SCAN_RESULTS);
1133 wiphy_unlock(&rdev->wiphy);
1136 void cfg80211_sched_scan_results(struct wiphy *wiphy, u64 reqid)
1138 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
1139 struct cfg80211_sched_scan_request *request;
1141 trace_cfg80211_sched_scan_results(wiphy, reqid);
1142 /* ignore if we're not scanning */
1145 request = cfg80211_find_sched_scan_req(rdev, reqid);
1147 request->report_results = true;
1148 queue_work(cfg80211_wq, &rdev->sched_scan_res_wk);
1152 EXPORT_SYMBOL(cfg80211_sched_scan_results);
1154 void cfg80211_sched_scan_stopped_locked(struct wiphy *wiphy, u64 reqid)
1156 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
1158 lockdep_assert_held(&wiphy->mtx);
1160 trace_cfg80211_sched_scan_stopped(wiphy, reqid);
1162 __cfg80211_stop_sched_scan(rdev, reqid, true);
1164 EXPORT_SYMBOL(cfg80211_sched_scan_stopped_locked);
1166 void cfg80211_sched_scan_stopped(struct wiphy *wiphy, u64 reqid)
1169 cfg80211_sched_scan_stopped_locked(wiphy, reqid);
1170 wiphy_unlock(wiphy);
1172 EXPORT_SYMBOL(cfg80211_sched_scan_stopped);
1174 int cfg80211_stop_sched_scan_req(struct cfg80211_registered_device *rdev,
1175 struct cfg80211_sched_scan_request *req,
1176 bool driver_initiated)
1178 lockdep_assert_held(&rdev->wiphy.mtx);
1180 if (!driver_initiated) {
1181 int err = rdev_sched_scan_stop(rdev, req->dev, req->reqid);
1186 nl80211_send_sched_scan(req, NL80211_CMD_SCHED_SCAN_STOPPED);
1188 cfg80211_del_sched_scan_req(rdev, req);
1193 int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
1194 u64 reqid, bool driver_initiated)
1196 struct cfg80211_sched_scan_request *sched_scan_req;
1198 lockdep_assert_held(&rdev->wiphy.mtx);
1200 sched_scan_req = cfg80211_find_sched_scan_req(rdev, reqid);
1201 if (!sched_scan_req)
1204 return cfg80211_stop_sched_scan_req(rdev, sched_scan_req,
1208 void cfg80211_bss_age(struct cfg80211_registered_device *rdev,
1209 unsigned long age_secs)
1211 struct cfg80211_internal_bss *bss;
1212 unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC);
1214 spin_lock_bh(&rdev->bss_lock);
1215 list_for_each_entry(bss, &rdev->bss_list, list)
1216 bss->ts -= age_jiffies;
1217 spin_unlock_bh(&rdev->bss_lock);
1220 void cfg80211_bss_expire(struct cfg80211_registered_device *rdev)
1222 __cfg80211_bss_expire(rdev, jiffies - IEEE80211_SCAN_RESULT_EXPIRE);
1225 void cfg80211_bss_flush(struct wiphy *wiphy)
1227 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
1229 spin_lock_bh(&rdev->bss_lock);
1230 __cfg80211_bss_expire(rdev, jiffies);
1231 spin_unlock_bh(&rdev->bss_lock);
1233 EXPORT_SYMBOL(cfg80211_bss_flush);
1235 const struct element *
1236 cfg80211_find_elem_match(u8 eid, const u8 *ies, unsigned int len,
1237 const u8 *match, unsigned int match_len,
1238 unsigned int match_offset)
1240 const struct element *elem;
1242 for_each_element_id(elem, eid, ies, len) {
1243 if (elem->datalen >= match_offset + match_len &&
1244 !memcmp(elem->data + match_offset, match, match_len))
1250 EXPORT_SYMBOL(cfg80211_find_elem_match);
1252 const struct element *cfg80211_find_vendor_elem(unsigned int oui, int oui_type,
1256 const struct element *elem;
1257 u8 match[] = { oui >> 16, oui >> 8, oui, oui_type };
1258 int match_len = (oui_type < 0) ? 3 : sizeof(match);
1260 if (WARN_ON(oui_type > 0xff))
1263 elem = cfg80211_find_elem_match(WLAN_EID_VENDOR_SPECIFIC, ies, len,
1264 match, match_len, 0);
1266 if (!elem || elem->datalen < 4)
1271 EXPORT_SYMBOL(cfg80211_find_vendor_elem);
1274 * enum bss_compare_mode - BSS compare mode
1275 * @BSS_CMP_REGULAR: regular compare mode (for insertion and normal find)
1276 * @BSS_CMP_HIDE_ZLEN: find hidden SSID with zero-length mode
1277 * @BSS_CMP_HIDE_NUL: find hidden SSID with NUL-ed out mode
1279 enum bss_compare_mode {
1285 static int cmp_bss(struct cfg80211_bss *a,
1286 struct cfg80211_bss *b,
1287 enum bss_compare_mode mode)
1289 const struct cfg80211_bss_ies *a_ies, *b_ies;
1290 const u8 *ie1 = NULL;
1291 const u8 *ie2 = NULL;
1294 if (a->channel != b->channel)
1295 return b->channel->center_freq - a->channel->center_freq;
1297 a_ies = rcu_access_pointer(a->ies);
1300 b_ies = rcu_access_pointer(b->ies);
1304 if (WLAN_CAPABILITY_IS_STA_BSS(a->capability))
1305 ie1 = cfg80211_find_ie(WLAN_EID_MESH_ID,
1306 a_ies->data, a_ies->len);
1307 if (WLAN_CAPABILITY_IS_STA_BSS(b->capability))
1308 ie2 = cfg80211_find_ie(WLAN_EID_MESH_ID,
1309 b_ies->data, b_ies->len);
1313 if (ie1[1] == ie2[1])
1314 mesh_id_cmp = memcmp(ie1 + 2, ie2 + 2, ie1[1]);
1316 mesh_id_cmp = ie2[1] - ie1[1];
1318 ie1 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
1319 a_ies->data, a_ies->len);
1320 ie2 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
1321 b_ies->data, b_ies->len);
1325 if (ie1[1] != ie2[1])
1326 return ie2[1] - ie1[1];
1327 return memcmp(ie1 + 2, ie2 + 2, ie1[1]);
1331 r = memcmp(a->bssid, b->bssid, sizeof(a->bssid));
1335 ie1 = cfg80211_find_ie(WLAN_EID_SSID, a_ies->data, a_ies->len);
1336 ie2 = cfg80211_find_ie(WLAN_EID_SSID, b_ies->data, b_ies->len);
1342 * Note that with "hide_ssid", the function returns a match if
1343 * the already-present BSS ("b") is a hidden SSID beacon for
1344 * the new BSS ("a").
1347 /* sort missing IE before (left of) present IE */
1354 case BSS_CMP_HIDE_ZLEN:
1356 * In ZLEN mode we assume the BSS entry we're
1357 * looking for has a zero-length SSID. So if
1358 * the one we're looking at right now has that,
1359 * return 0. Otherwise, return the difference
1360 * in length, but since we're looking for the
1361 * 0-length it's really equivalent to returning
1362 * the length of the one we're looking at.
1364 * No content comparison is needed as we assume
1365 * the content length is zero.
1368 case BSS_CMP_REGULAR:
1370 /* sort by length first, then by contents */
1371 if (ie1[1] != ie2[1])
1372 return ie2[1] - ie1[1];
1373 return memcmp(ie1 + 2, ie2 + 2, ie1[1]);
1374 case BSS_CMP_HIDE_NUL:
1375 if (ie1[1] != ie2[1])
1376 return ie2[1] - ie1[1];
1377 /* this is equivalent to memcmp(zeroes, ie2 + 2, len) */
1378 for (i = 0; i < ie2[1]; i++)
1385 static bool cfg80211_bss_type_match(u16 capability,
1386 enum nl80211_band band,
1387 enum ieee80211_bss_type bss_type)
1392 if (bss_type == IEEE80211_BSS_TYPE_ANY)
1395 if (band == NL80211_BAND_60GHZ) {
1396 mask = WLAN_CAPABILITY_DMG_TYPE_MASK;
1398 case IEEE80211_BSS_TYPE_ESS:
1399 val = WLAN_CAPABILITY_DMG_TYPE_AP;
1401 case IEEE80211_BSS_TYPE_PBSS:
1402 val = WLAN_CAPABILITY_DMG_TYPE_PBSS;
1404 case IEEE80211_BSS_TYPE_IBSS:
1405 val = WLAN_CAPABILITY_DMG_TYPE_IBSS;
1411 mask = WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS;
1413 case IEEE80211_BSS_TYPE_ESS:
1414 val = WLAN_CAPABILITY_ESS;
1416 case IEEE80211_BSS_TYPE_IBSS:
1417 val = WLAN_CAPABILITY_IBSS;
1419 case IEEE80211_BSS_TYPE_MBSS:
1427 ret = ((capability & mask) == val);
1431 /* Returned bss is reference counted and must be cleaned up appropriately. */
1432 struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy,
1433 struct ieee80211_channel *channel,
1435 const u8 *ssid, size_t ssid_len,
1436 enum ieee80211_bss_type bss_type,
1437 enum ieee80211_privacy privacy)
1439 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
1440 struct cfg80211_internal_bss *bss, *res = NULL;
1441 unsigned long now = jiffies;
1444 trace_cfg80211_get_bss(wiphy, channel, bssid, ssid, ssid_len, bss_type,
1447 spin_lock_bh(&rdev->bss_lock);
1449 list_for_each_entry(bss, &rdev->bss_list, list) {
1450 if (!cfg80211_bss_type_match(bss->pub.capability,
1451 bss->pub.channel->band, bss_type))
1454 bss_privacy = (bss->pub.capability & WLAN_CAPABILITY_PRIVACY);
1455 if ((privacy == IEEE80211_PRIVACY_ON && !bss_privacy) ||
1456 (privacy == IEEE80211_PRIVACY_OFF && bss_privacy))
1458 if (channel && bss->pub.channel != channel)
1460 if (!is_valid_ether_addr(bss->pub.bssid))
1462 /* Don't get expired BSS structs */
1463 if (time_after(now, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE) &&
1464 !atomic_read(&bss->hold))
1466 if (is_bss(&bss->pub, bssid, ssid, ssid_len)) {
1468 bss_ref_get(rdev, res);
1473 spin_unlock_bh(&rdev->bss_lock);
1476 trace_cfg80211_return_bss(&res->pub);
1479 EXPORT_SYMBOL(cfg80211_get_bss);
1481 static void rb_insert_bss(struct cfg80211_registered_device *rdev,
1482 struct cfg80211_internal_bss *bss)
1484 struct rb_node **p = &rdev->bss_tree.rb_node;
1485 struct rb_node *parent = NULL;
1486 struct cfg80211_internal_bss *tbss;
1491 tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn);
1493 cmp = cmp_bss(&bss->pub, &tbss->pub, BSS_CMP_REGULAR);
1495 if (WARN_ON(!cmp)) {
1496 /* will sort of leak this BSS */
1503 p = &(*p)->rb_right;
1506 rb_link_node(&bss->rbn, parent, p);
1507 rb_insert_color(&bss->rbn, &rdev->bss_tree);
1510 static struct cfg80211_internal_bss *
1511 rb_find_bss(struct cfg80211_registered_device *rdev,
1512 struct cfg80211_internal_bss *res,
1513 enum bss_compare_mode mode)
1515 struct rb_node *n = rdev->bss_tree.rb_node;
1516 struct cfg80211_internal_bss *bss;
1520 bss = rb_entry(n, struct cfg80211_internal_bss, rbn);
1521 r = cmp_bss(&res->pub, &bss->pub, mode);
1534 static bool cfg80211_combine_bsses(struct cfg80211_registered_device *rdev,
1535 struct cfg80211_internal_bss *new)
1537 const struct cfg80211_bss_ies *ies;
1538 struct cfg80211_internal_bss *bss;
1544 ies = rcu_access_pointer(new->pub.beacon_ies);
1548 ie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
1555 for (i = 0; i < ssidlen; i++)
1559 /* not a hidden SSID */
1563 /* This is the bad part ... */
1565 list_for_each_entry(bss, &rdev->bss_list, list) {
1567 * we're iterating all the entries anyway, so take the
1568 * opportunity to validate the list length accounting
1572 if (!ether_addr_equal(bss->pub.bssid, new->pub.bssid))
1574 if (bss->pub.channel != new->pub.channel)
1576 if (bss->pub.scan_width != new->pub.scan_width)
1578 if (rcu_access_pointer(bss->pub.beacon_ies))
1580 ies = rcu_access_pointer(bss->pub.ies);
1583 ie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
1586 if (ssidlen && ie[1] != ssidlen)
1588 if (WARN_ON_ONCE(bss->pub.hidden_beacon_bss))
1590 if (WARN_ON_ONCE(!list_empty(&bss->hidden_list)))
1591 list_del(&bss->hidden_list);
1593 list_add(&bss->hidden_list, &new->hidden_list);
1594 bss->pub.hidden_beacon_bss = &new->pub;
1595 new->refcount += bss->refcount;
1596 rcu_assign_pointer(bss->pub.beacon_ies,
1597 new->pub.beacon_ies);
1600 WARN_ONCE(n_entries != rdev->bss_entries,
1601 "rdev bss entries[%d]/list[len:%d] corruption\n",
1602 rdev->bss_entries, n_entries);
1607 struct cfg80211_non_tx_bss {
1608 struct cfg80211_bss *tx_bss;
1609 u8 max_bssid_indicator;
1613 static void cfg80211_update_hidden_bsses(struct cfg80211_internal_bss *known,
1614 const struct cfg80211_bss_ies *new_ies,
1615 const struct cfg80211_bss_ies *old_ies)
1617 struct cfg80211_internal_bss *bss;
1619 /* Assign beacon IEs to all sub entries */
1620 list_for_each_entry(bss, &known->hidden_list, hidden_list) {
1621 const struct cfg80211_bss_ies *ies;
1623 ies = rcu_access_pointer(bss->pub.beacon_ies);
1624 WARN_ON(ies != old_ies);
1626 rcu_assign_pointer(bss->pub.beacon_ies, new_ies);
1631 cfg80211_update_known_bss(struct cfg80211_registered_device *rdev,
1632 struct cfg80211_internal_bss *known,
1633 struct cfg80211_internal_bss *new,
1636 lockdep_assert_held(&rdev->bss_lock);
1639 if (rcu_access_pointer(new->pub.proberesp_ies)) {
1640 const struct cfg80211_bss_ies *old;
1642 old = rcu_access_pointer(known->pub.proberesp_ies);
1644 rcu_assign_pointer(known->pub.proberesp_ies,
1645 new->pub.proberesp_ies);
1646 /* Override possible earlier Beacon frame IEs */
1647 rcu_assign_pointer(known->pub.ies,
1648 new->pub.proberesp_ies);
1650 kfree_rcu((struct cfg80211_bss_ies *)old, rcu_head);
1651 } else if (rcu_access_pointer(new->pub.beacon_ies)) {
1652 const struct cfg80211_bss_ies *old;
1654 if (known->pub.hidden_beacon_bss &&
1655 !list_empty(&known->hidden_list)) {
1656 const struct cfg80211_bss_ies *f;
1658 /* The known BSS struct is one of the probe
1659 * response members of a group, but we're
1660 * receiving a beacon (beacon_ies in the new
1661 * bss is used). This can only mean that the
1662 * AP changed its beacon from not having an
1663 * SSID to showing it, which is confusing so
1664 * drop this information.
1667 f = rcu_access_pointer(new->pub.beacon_ies);
1668 kfree_rcu((struct cfg80211_bss_ies *)f, rcu_head);
1672 old = rcu_access_pointer(known->pub.beacon_ies);
1674 rcu_assign_pointer(known->pub.beacon_ies, new->pub.beacon_ies);
1676 /* Override IEs if they were from a beacon before */
1677 if (old == rcu_access_pointer(known->pub.ies))
1678 rcu_assign_pointer(known->pub.ies, new->pub.beacon_ies);
1680 cfg80211_update_hidden_bsses(known,
1681 rcu_access_pointer(new->pub.beacon_ies),
1685 kfree_rcu((struct cfg80211_bss_ies *)old, rcu_head);
1688 known->pub.beacon_interval = new->pub.beacon_interval;
1690 /* don't update the signal if beacon was heard on
1694 known->pub.signal = new->pub.signal;
1695 known->pub.capability = new->pub.capability;
1696 known->ts = new->ts;
1697 known->ts_boottime = new->ts_boottime;
1698 known->parent_tsf = new->parent_tsf;
1699 known->pub.chains = new->pub.chains;
1700 memcpy(known->pub.chain_signal, new->pub.chain_signal,
1701 IEEE80211_MAX_CHAINS);
1702 ether_addr_copy(known->parent_bssid, new->parent_bssid);
1703 known->pub.max_bssid_indicator = new->pub.max_bssid_indicator;
1704 known->pub.bssid_index = new->pub.bssid_index;
1709 /* Returned bss is reference counted and must be cleaned up appropriately. */
1710 struct cfg80211_internal_bss *
1711 cfg80211_bss_update(struct cfg80211_registered_device *rdev,
1712 struct cfg80211_internal_bss *tmp,
1713 bool signal_valid, unsigned long ts)
1715 struct cfg80211_internal_bss *found = NULL;
1717 if (WARN_ON(!tmp->pub.channel))
1722 spin_lock_bh(&rdev->bss_lock);
1724 if (WARN_ON(!rcu_access_pointer(tmp->pub.ies))) {
1725 spin_unlock_bh(&rdev->bss_lock);
1729 found = rb_find_bss(rdev, tmp, BSS_CMP_REGULAR);
1732 if (!cfg80211_update_known_bss(rdev, found, tmp, signal_valid))
1735 struct cfg80211_internal_bss *new;
1736 struct cfg80211_internal_bss *hidden;
1737 struct cfg80211_bss_ies *ies;
1740 * create a copy -- the "res" variable that is passed in
1741 * is allocated on the stack since it's not needed in the
1742 * more common case of an update
1744 new = kzalloc(sizeof(*new) + rdev->wiphy.bss_priv_size,
1747 ies = (void *)rcu_dereference(tmp->pub.beacon_ies);
1749 kfree_rcu(ies, rcu_head);
1750 ies = (void *)rcu_dereference(tmp->pub.proberesp_ies);
1752 kfree_rcu(ies, rcu_head);
1755 memcpy(new, tmp, sizeof(*new));
1757 INIT_LIST_HEAD(&new->hidden_list);
1758 INIT_LIST_HEAD(&new->pub.nontrans_list);
1759 /* we'll set this later if it was non-NULL */
1760 new->pub.transmitted_bss = NULL;
1762 if (rcu_access_pointer(tmp->pub.proberesp_ies)) {
1763 hidden = rb_find_bss(rdev, tmp, BSS_CMP_HIDE_ZLEN);
1765 hidden = rb_find_bss(rdev, tmp,
1768 new->pub.hidden_beacon_bss = &hidden->pub;
1769 list_add(&new->hidden_list,
1770 &hidden->hidden_list);
1772 rcu_assign_pointer(new->pub.beacon_ies,
1773 hidden->pub.beacon_ies);
1777 * Ok so we found a beacon, and don't have an entry. If
1778 * it's a beacon with hidden SSID, we might be in for an
1779 * expensive search for any probe responses that should
1780 * be grouped with this beacon for updates ...
1782 if (!cfg80211_combine_bsses(rdev, new)) {
1783 bss_ref_put(rdev, new);
1788 if (rdev->bss_entries >= bss_entries_limit &&
1789 !cfg80211_bss_expire_oldest(rdev)) {
1790 bss_ref_put(rdev, new);
1794 /* This must be before the call to bss_ref_get */
1795 if (tmp->pub.transmitted_bss) {
1796 struct cfg80211_internal_bss *pbss =
1797 container_of(tmp->pub.transmitted_bss,
1798 struct cfg80211_internal_bss,
1801 new->pub.transmitted_bss = tmp->pub.transmitted_bss;
1802 bss_ref_get(rdev, pbss);
1805 list_add_tail(&new->list, &rdev->bss_list);
1806 rdev->bss_entries++;
1807 rb_insert_bss(rdev, new);
1811 rdev->bss_generation++;
1812 bss_ref_get(rdev, found);
1813 spin_unlock_bh(&rdev->bss_lock);
1817 spin_unlock_bh(&rdev->bss_lock);
1822 * Update RX channel information based on the available frame payload
1823 * information. This is mainly for the 2.4 GHz band where frames can be received
1824 * from neighboring channels and the Beacon frames use the DSSS Parameter Set
1825 * element to indicate the current (transmitting) channel, but this might also
1826 * be needed on other bands if RX frequency does not match with the actual
1827 * operating channel of a BSS.
1829 static struct ieee80211_channel *
1830 cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen,
1831 struct ieee80211_channel *channel,
1832 enum nl80211_bss_scan_width scan_width)
1836 int channel_number = -1;
1837 struct ieee80211_channel *alt_channel;
1839 if (channel->band == NL80211_BAND_S1GHZ) {
1840 tmp = cfg80211_find_ie(WLAN_EID_S1G_OPERATION, ie, ielen);
1841 if (tmp && tmp[1] >= sizeof(struct ieee80211_s1g_oper_ie)) {
1842 struct ieee80211_s1g_oper_ie *s1gop = (void *)(tmp + 2);
1844 channel_number = s1gop->primary_ch;
1847 tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen);
1848 if (tmp && tmp[1] == 1) {
1849 channel_number = tmp[2];
1851 tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen);
1852 if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) {
1853 struct ieee80211_ht_operation *htop = (void *)(tmp + 2);
1855 channel_number = htop->primary_chan;
1860 if (channel_number < 0) {
1861 /* No channel information in frame payload */
1865 freq = ieee80211_channel_to_freq_khz(channel_number, channel->band);
1866 alt_channel = ieee80211_get_channel_khz(wiphy, freq);
1868 if (channel->band == NL80211_BAND_2GHZ) {
1870 * Better not allow unexpected channels when that could
1871 * be going beyond the 1-11 range (e.g., discovering
1872 * BSS on channel 12 when radio is configured for
1878 /* No match for the payload channel number - ignore it */
1882 if (scan_width == NL80211_BSS_CHAN_WIDTH_10 ||
1883 scan_width == NL80211_BSS_CHAN_WIDTH_5) {
1885 * Ignore channel number in 5 and 10 MHz channels where there
1886 * may not be an n:1 or 1:n mapping between frequencies and
1893 * Use the channel determined through the payload channel number
1894 * instead of the RX channel reported by the driver.
1896 if (alt_channel->flags & IEEE80211_CHAN_DISABLED)
1901 /* Returned bss is reference counted and must be cleaned up appropriately. */
1902 static struct cfg80211_bss *
1903 cfg80211_inform_single_bss_data(struct wiphy *wiphy,
1904 struct cfg80211_inform_bss *data,
1905 enum cfg80211_bss_frame_type ftype,
1906 const u8 *bssid, u64 tsf, u16 capability,
1907 u16 beacon_interval, const u8 *ie, size_t ielen,
1908 struct cfg80211_non_tx_bss *non_tx_data,
1911 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
1912 struct cfg80211_bss_ies *ies;
1913 struct ieee80211_channel *channel;
1914 struct cfg80211_internal_bss tmp = {}, *res;
1919 if (WARN_ON(!wiphy))
1922 if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC &&
1923 (data->signal < 0 || data->signal > 100)))
1926 channel = cfg80211_get_bss_channel(wiphy, ie, ielen, data->chan,
1931 memcpy(tmp.pub.bssid, bssid, ETH_ALEN);
1932 tmp.pub.channel = channel;
1933 tmp.pub.scan_width = data->scan_width;
1934 tmp.pub.signal = data->signal;
1935 tmp.pub.beacon_interval = beacon_interval;
1936 tmp.pub.capability = capability;
1937 tmp.ts_boottime = data->boottime_ns;
1938 tmp.parent_tsf = data->parent_tsf;
1939 ether_addr_copy(tmp.parent_bssid, data->parent_bssid);
1942 tmp.pub.transmitted_bss = non_tx_data->tx_bss;
1943 ts = bss_from_pub(non_tx_data->tx_bss)->ts;
1944 tmp.pub.bssid_index = non_tx_data->bssid_index;
1945 tmp.pub.max_bssid_indicator = non_tx_data->max_bssid_indicator;
1951 * If we do not know here whether the IEs are from a Beacon or Probe
1952 * Response frame, we need to pick one of the options and only use it
1953 * with the driver that does not provide the full Beacon/Probe Response
1954 * frame. Use Beacon frame pointer to avoid indicating that this should
1955 * override the IEs pointer should we have received an earlier
1956 * indication of Probe Response data.
1958 ies = kzalloc(sizeof(*ies) + ielen, gfp);
1963 ies->from_beacon = false;
1964 memcpy(ies->data, ie, ielen);
1967 case CFG80211_BSS_FTYPE_BEACON:
1968 ies->from_beacon = true;
1970 case CFG80211_BSS_FTYPE_UNKNOWN:
1971 rcu_assign_pointer(tmp.pub.beacon_ies, ies);
1973 case CFG80211_BSS_FTYPE_PRESP:
1974 rcu_assign_pointer(tmp.pub.proberesp_ies, ies);
1977 rcu_assign_pointer(tmp.pub.ies, ies);
1979 signal_valid = data->chan == channel;
1980 res = cfg80211_bss_update(wiphy_to_rdev(wiphy), &tmp, signal_valid, ts);
1984 if (channel->band == NL80211_BAND_60GHZ) {
1985 bss_type = res->pub.capability & WLAN_CAPABILITY_DMG_TYPE_MASK;
1986 if (bss_type == WLAN_CAPABILITY_DMG_TYPE_AP ||
1987 bss_type == WLAN_CAPABILITY_DMG_TYPE_PBSS)
1988 regulatory_hint_found_beacon(wiphy, channel, gfp);
1990 if (res->pub.capability & WLAN_CAPABILITY_ESS)
1991 regulatory_hint_found_beacon(wiphy, channel, gfp);
1995 /* this is a nontransmitting bss, we need to add it to
1996 * transmitting bss' list if it is not there
1998 spin_lock_bh(&rdev->bss_lock);
1999 if (cfg80211_add_nontrans_list(non_tx_data->tx_bss,
2001 if (__cfg80211_unlink_bss(rdev, res)) {
2002 rdev->bss_generation++;
2006 spin_unlock_bh(&rdev->bss_lock);
2012 trace_cfg80211_return_bss(&res->pub);
2013 /* cfg80211_bss_update gives us a referenced result */
2017 static const struct element
2018 *cfg80211_get_profile_continuation(const u8 *ie, size_t ielen,
2019 const struct element *mbssid_elem,
2020 const struct element *sub_elem)
2022 const u8 *mbssid_end = mbssid_elem->data + mbssid_elem->datalen;
2023 const struct element *next_mbssid;
2024 const struct element *next_sub;
2026 next_mbssid = cfg80211_find_elem(WLAN_EID_MULTIPLE_BSSID,
2028 ielen - (mbssid_end - ie));
2031 * If it is not the last subelement in current MBSSID IE or there isn't
2032 * a next MBSSID IE - profile is complete.
2034 if ((sub_elem->data + sub_elem->datalen < mbssid_end - 1) ||
2038 /* For any length error, just return NULL */
2040 if (next_mbssid->datalen < 4)
2043 next_sub = (void *)&next_mbssid->data[1];
2045 if (next_mbssid->data + next_mbssid->datalen <
2046 next_sub->data + next_sub->datalen)
2049 if (next_sub->id != 0 || next_sub->datalen < 2)
2053 * Check if the first element in the next sub element is a start
2056 return next_sub->data[0] == WLAN_EID_NON_TX_BSSID_CAP ?
2060 size_t cfg80211_merge_profile(const u8 *ie, size_t ielen,
2061 const struct element *mbssid_elem,
2062 const struct element *sub_elem,
2063 u8 *merged_ie, size_t max_copy_len)
2065 size_t copied_len = sub_elem->datalen;
2066 const struct element *next_mbssid;
2068 if (sub_elem->datalen > max_copy_len)
2071 memcpy(merged_ie, sub_elem->data, sub_elem->datalen);
2073 while ((next_mbssid = cfg80211_get_profile_continuation(ie, ielen,
2076 const struct element *next_sub = (void *)&next_mbssid->data[1];
2078 if (copied_len + next_sub->datalen > max_copy_len)
2080 memcpy(merged_ie + copied_len, next_sub->data,
2082 copied_len += next_sub->datalen;
2087 EXPORT_SYMBOL(cfg80211_merge_profile);
2089 static void cfg80211_parse_mbssid_data(struct wiphy *wiphy,
2090 struct cfg80211_inform_bss *data,
2091 enum cfg80211_bss_frame_type ftype,
2092 const u8 *bssid, u64 tsf,
2093 u16 beacon_interval, const u8 *ie,
2095 struct cfg80211_non_tx_bss *non_tx_data,
2098 const u8 *mbssid_index_ie;
2099 const struct element *elem, *sub;
2101 u8 new_bssid[ETH_ALEN];
2102 u8 *new_ie, *profile;
2103 u64 seen_indices = 0;
2105 struct cfg80211_bss *bss;
2109 if (!cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID, ie, ielen))
2111 if (!wiphy->support_mbssid)
2113 if (wiphy->support_only_he_mbssid &&
2114 !cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ie, ielen))
2117 new_ie = kmalloc(IEEE80211_MAX_DATA_LEN, gfp);
2121 profile = kmalloc(ielen, gfp);
2125 for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, ie, ielen) {
2126 if (elem->datalen < 4)
2128 if (elem->data[0] < 1 || (int)elem->data[0] > 8)
2130 for_each_element(sub, elem->data + 1, elem->datalen - 1) {
2133 if (sub->id != 0 || sub->datalen < 4) {
2134 /* not a valid BSS profile */
2138 if (sub->data[0] != WLAN_EID_NON_TX_BSSID_CAP ||
2139 sub->data[1] != 2) {
2140 /* The first element within the Nontransmitted
2141 * BSSID Profile is not the Nontransmitted
2142 * BSSID Capability element.
2147 memset(profile, 0, ielen);
2148 profile_len = cfg80211_merge_profile(ie, ielen,
2154 /* found a Nontransmitted BSSID Profile */
2155 mbssid_index_ie = cfg80211_find_ie
2156 (WLAN_EID_MULTI_BSSID_IDX,
2157 profile, profile_len);
2158 if (!mbssid_index_ie || mbssid_index_ie[1] < 1 ||
2159 mbssid_index_ie[2] == 0 ||
2160 mbssid_index_ie[2] > 46) {
2161 /* No valid Multiple BSSID-Index element */
2165 if (seen_indices & BIT_ULL(mbssid_index_ie[2]))
2166 /* We don't support legacy split of a profile */
2167 net_dbg_ratelimited("Partial info for BSSID index %d\n",
2168 mbssid_index_ie[2]);
2170 seen_indices |= BIT_ULL(mbssid_index_ie[2]);
2172 non_tx_data->bssid_index = mbssid_index_ie[2];
2173 non_tx_data->max_bssid_indicator = elem->data[0];
2175 cfg80211_gen_new_bssid(bssid,
2176 non_tx_data->max_bssid_indicator,
2177 non_tx_data->bssid_index,
2179 memset(new_ie, 0, IEEE80211_MAX_DATA_LEN);
2180 new_ie_len = cfg80211_gen_new_ie(ie, ielen,
2182 profile_len, new_ie,
2187 capability = get_unaligned_le16(profile + 2);
2188 bss = cfg80211_inform_single_bss_data(wiphy, data,
2199 cfg80211_put_bss(wiphy, bss);
2208 struct cfg80211_bss *
2209 cfg80211_inform_bss_data(struct wiphy *wiphy,
2210 struct cfg80211_inform_bss *data,
2211 enum cfg80211_bss_frame_type ftype,
2212 const u8 *bssid, u64 tsf, u16 capability,
2213 u16 beacon_interval, const u8 *ie, size_t ielen,
2216 struct cfg80211_bss *res;
2217 struct cfg80211_non_tx_bss non_tx_data;
2219 res = cfg80211_inform_single_bss_data(wiphy, data, ftype, bssid, tsf,
2220 capability, beacon_interval, ie,
2224 non_tx_data.tx_bss = res;
2225 cfg80211_parse_mbssid_data(wiphy, data, ftype, bssid, tsf,
2226 beacon_interval, ie, ielen, &non_tx_data,
2230 EXPORT_SYMBOL(cfg80211_inform_bss_data);
2233 cfg80211_parse_mbssid_frame_data(struct wiphy *wiphy,
2234 struct cfg80211_inform_bss *data,
2235 struct ieee80211_mgmt *mgmt, size_t len,
2236 struct cfg80211_non_tx_bss *non_tx_data,
2239 enum cfg80211_bss_frame_type ftype;
2240 const u8 *ie = mgmt->u.probe_resp.variable;
2241 size_t ielen = len - offsetof(struct ieee80211_mgmt,
2242 u.probe_resp.variable);
2244 ftype = ieee80211_is_beacon(mgmt->frame_control) ?
2245 CFG80211_BSS_FTYPE_BEACON : CFG80211_BSS_FTYPE_PRESP;
2247 cfg80211_parse_mbssid_data(wiphy, data, ftype, mgmt->bssid,
2248 le64_to_cpu(mgmt->u.probe_resp.timestamp),
2249 le16_to_cpu(mgmt->u.probe_resp.beacon_int),
2250 ie, ielen, non_tx_data, gfp);
2254 cfg80211_update_notlisted_nontrans(struct wiphy *wiphy,
2255 struct cfg80211_bss *nontrans_bss,
2256 struct ieee80211_mgmt *mgmt, size_t len)
2258 u8 *ie, *new_ie, *pos;
2259 const u8 *nontrans_ssid, *trans_ssid, *mbssid;
2260 size_t ielen = len - offsetof(struct ieee80211_mgmt,
2261 u.probe_resp.variable);
2263 struct cfg80211_bss_ies *new_ies;
2264 const struct cfg80211_bss_ies *old;
2267 lockdep_assert_held(&wiphy_to_rdev(wiphy)->bss_lock);
2269 ie = mgmt->u.probe_resp.variable;
2272 trans_ssid = cfg80211_find_ie(WLAN_EID_SSID, ie, ielen);
2275 new_ie_len -= trans_ssid[1];
2276 mbssid = cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID, ie, ielen);
2278 * It's not valid to have the MBSSID element before SSID
2279 * ignore if that happens - the code below assumes it is
2280 * after (while copying things inbetween).
2282 if (!mbssid || mbssid < trans_ssid)
2284 new_ie_len -= mbssid[1];
2286 nontrans_ssid = ieee80211_bss_get_ie(nontrans_bss, WLAN_EID_SSID);
2290 new_ie_len += nontrans_ssid[1];
2292 /* generate new ie for nontrans BSS
2293 * 1. replace SSID with nontrans BSS' SSID
2296 new_ie = kzalloc(new_ie_len, GFP_ATOMIC);
2300 new_ies = kzalloc(sizeof(*new_ies) + new_ie_len, GFP_ATOMIC);
2306 /* copy the nontransmitted SSID */
2307 cpy_len = nontrans_ssid[1] + 2;
2308 memcpy(pos, nontrans_ssid, cpy_len);
2310 /* copy the IEs between SSID and MBSSID */
2311 cpy_len = trans_ssid[1] + 2;
2312 memcpy(pos, (trans_ssid + cpy_len), (mbssid - (trans_ssid + cpy_len)));
2313 pos += (mbssid - (trans_ssid + cpy_len));
2314 /* copy the IEs after MBSSID */
2315 cpy_len = mbssid[1] + 2;
2316 memcpy(pos, mbssid + cpy_len, ((ie + ielen) - (mbssid + cpy_len)));
2319 new_ies->len = new_ie_len;
2320 new_ies->tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
2321 new_ies->from_beacon = ieee80211_is_beacon(mgmt->frame_control);
2322 memcpy(new_ies->data, new_ie, new_ie_len);
2323 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
2324 old = rcu_access_pointer(nontrans_bss->proberesp_ies);
2325 rcu_assign_pointer(nontrans_bss->proberesp_ies, new_ies);
2326 rcu_assign_pointer(nontrans_bss->ies, new_ies);
2328 kfree_rcu((struct cfg80211_bss_ies *)old, rcu_head);
2330 old = rcu_access_pointer(nontrans_bss->beacon_ies);
2331 rcu_assign_pointer(nontrans_bss->beacon_ies, new_ies);
2332 cfg80211_update_hidden_bsses(bss_from_pub(nontrans_bss),
2334 rcu_assign_pointer(nontrans_bss->ies, new_ies);
2336 kfree_rcu((struct cfg80211_bss_ies *)old, rcu_head);
2343 /* cfg80211_inform_bss_width_frame helper */
2344 static struct cfg80211_bss *
2345 cfg80211_inform_single_bss_frame_data(struct wiphy *wiphy,
2346 struct cfg80211_inform_bss *data,
2347 struct ieee80211_mgmt *mgmt, size_t len,
2350 struct cfg80211_internal_bss tmp = {}, *res;
2351 struct cfg80211_bss_ies *ies;
2352 struct ieee80211_channel *channel;
2354 struct ieee80211_ext *ext = NULL;
2355 u8 *bssid, *variable;
2356 u16 capability, beacon_int;
2357 size_t ielen, min_hdr_len = offsetof(struct ieee80211_mgmt,
2358 u.probe_resp.variable);
2361 BUILD_BUG_ON(offsetof(struct ieee80211_mgmt, u.probe_resp.variable) !=
2362 offsetof(struct ieee80211_mgmt, u.beacon.variable));
2364 trace_cfg80211_inform_bss_frame(wiphy, data, mgmt, len);
2369 if (WARN_ON(!wiphy))
2372 if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC &&
2373 (data->signal < 0 || data->signal > 100)))
2376 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
2377 ext = (void *) mgmt;
2378 min_hdr_len = offsetof(struct ieee80211_ext, u.s1g_beacon);
2379 if (ieee80211_is_s1g_short_beacon(mgmt->frame_control))
2380 min_hdr_len = offsetof(struct ieee80211_ext,
2381 u.s1g_short_beacon.variable);
2384 if (WARN_ON(len < min_hdr_len))
2387 ielen = len - min_hdr_len;
2388 variable = mgmt->u.probe_resp.variable;
2390 if (ieee80211_is_s1g_short_beacon(mgmt->frame_control))
2391 variable = ext->u.s1g_short_beacon.variable;
2393 variable = ext->u.s1g_beacon.variable;
2396 channel = cfg80211_get_bss_channel(wiphy, variable,
2397 ielen, data->chan, data->scan_width);
2402 const struct ieee80211_s1g_bcn_compat_ie *compat;
2403 const struct element *elem;
2405 elem = cfg80211_find_elem(WLAN_EID_S1G_BCN_COMPAT,
2409 if (elem->datalen < sizeof(*compat))
2411 compat = (void *)elem->data;
2412 bssid = ext->u.s1g_beacon.sa;
2413 capability = le16_to_cpu(compat->compat_info);
2414 beacon_int = le16_to_cpu(compat->beacon_int);
2416 bssid = mgmt->bssid;
2417 beacon_int = le16_to_cpu(mgmt->u.probe_resp.beacon_int);
2418 capability = le16_to_cpu(mgmt->u.probe_resp.capab_info);
2421 ies = kzalloc(sizeof(*ies) + ielen, gfp);
2425 ies->tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
2426 ies->from_beacon = ieee80211_is_beacon(mgmt->frame_control) ||
2427 ieee80211_is_s1g_beacon(mgmt->frame_control);
2428 memcpy(ies->data, variable, ielen);
2430 if (ieee80211_is_probe_resp(mgmt->frame_control))
2431 rcu_assign_pointer(tmp.pub.proberesp_ies, ies);
2433 rcu_assign_pointer(tmp.pub.beacon_ies, ies);
2434 rcu_assign_pointer(tmp.pub.ies, ies);
2436 memcpy(tmp.pub.bssid, bssid, ETH_ALEN);
2437 tmp.pub.beacon_interval = beacon_int;
2438 tmp.pub.capability = capability;
2439 tmp.pub.channel = channel;
2440 tmp.pub.scan_width = data->scan_width;
2441 tmp.pub.signal = data->signal;
2442 tmp.ts_boottime = data->boottime_ns;
2443 tmp.parent_tsf = data->parent_tsf;
2444 tmp.pub.chains = data->chains;
2445 memcpy(tmp.pub.chain_signal, data->chain_signal, IEEE80211_MAX_CHAINS);
2446 ether_addr_copy(tmp.parent_bssid, data->parent_bssid);
2448 signal_valid = data->chan == channel;
2449 res = cfg80211_bss_update(wiphy_to_rdev(wiphy), &tmp, signal_valid,
2454 if (channel->band == NL80211_BAND_60GHZ) {
2455 bss_type = res->pub.capability & WLAN_CAPABILITY_DMG_TYPE_MASK;
2456 if (bss_type == WLAN_CAPABILITY_DMG_TYPE_AP ||
2457 bss_type == WLAN_CAPABILITY_DMG_TYPE_PBSS)
2458 regulatory_hint_found_beacon(wiphy, channel, gfp);
2460 if (res->pub.capability & WLAN_CAPABILITY_ESS)
2461 regulatory_hint_found_beacon(wiphy, channel, gfp);
2464 trace_cfg80211_return_bss(&res->pub);
2465 /* cfg80211_bss_update gives us a referenced result */
2469 struct cfg80211_bss *
2470 cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
2471 struct cfg80211_inform_bss *data,
2472 struct ieee80211_mgmt *mgmt, size_t len,
2475 struct cfg80211_bss *res, *tmp_bss;
2476 const u8 *ie = mgmt->u.probe_resp.variable;
2477 const struct cfg80211_bss_ies *ies1, *ies2;
2478 size_t ielen = len - offsetof(struct ieee80211_mgmt,
2479 u.probe_resp.variable);
2480 struct cfg80211_non_tx_bss non_tx_data = {};
2482 res = cfg80211_inform_single_bss_frame_data(wiphy, data, mgmt,
2485 /* don't do any further MBSSID handling for S1G */
2486 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
2489 if (!res || !wiphy->support_mbssid ||
2490 !cfg80211_find_ie(WLAN_EID_MULTIPLE_BSSID, ie, ielen))
2492 if (wiphy->support_only_he_mbssid &&
2493 !cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ie, ielen))
2496 non_tx_data.tx_bss = res;
2497 /* process each non-transmitting bss */
2498 cfg80211_parse_mbssid_frame_data(wiphy, data, mgmt, len,
2501 spin_lock_bh(&wiphy_to_rdev(wiphy)->bss_lock);
2503 /* check if the res has other nontransmitting bss which is not
2506 ies1 = rcu_access_pointer(res->ies);
2508 /* go through nontrans_list, if the timestamp of the BSS is
2509 * earlier than the timestamp of the transmitting BSS then
2512 list_for_each_entry(tmp_bss, &res->nontrans_list,
2514 ies2 = rcu_access_pointer(tmp_bss->ies);
2515 if (ies2->tsf < ies1->tsf)
2516 cfg80211_update_notlisted_nontrans(wiphy, tmp_bss,
2519 spin_unlock_bh(&wiphy_to_rdev(wiphy)->bss_lock);
2523 EXPORT_SYMBOL(cfg80211_inform_bss_frame_data);
2525 void cfg80211_ref_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
2527 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
2528 struct cfg80211_internal_bss *bss;
2533 bss = container_of(pub, struct cfg80211_internal_bss, pub);
2535 spin_lock_bh(&rdev->bss_lock);
2536 bss_ref_get(rdev, bss);
2537 spin_unlock_bh(&rdev->bss_lock);
2539 EXPORT_SYMBOL(cfg80211_ref_bss);
2541 void cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
2543 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
2544 struct cfg80211_internal_bss *bss;
2549 bss = container_of(pub, struct cfg80211_internal_bss, pub);
2551 spin_lock_bh(&rdev->bss_lock);
2552 bss_ref_put(rdev, bss);
2553 spin_unlock_bh(&rdev->bss_lock);
2555 EXPORT_SYMBOL(cfg80211_put_bss);
2557 void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
2559 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
2560 struct cfg80211_internal_bss *bss, *tmp1;
2561 struct cfg80211_bss *nontrans_bss, *tmp;
2566 bss = container_of(pub, struct cfg80211_internal_bss, pub);
2568 spin_lock_bh(&rdev->bss_lock);
2569 if (list_empty(&bss->list))
2572 list_for_each_entry_safe(nontrans_bss, tmp,
2573 &pub->nontrans_list,
2575 tmp1 = container_of(nontrans_bss,
2576 struct cfg80211_internal_bss, pub);
2577 if (__cfg80211_unlink_bss(rdev, tmp1))
2578 rdev->bss_generation++;
2581 if (__cfg80211_unlink_bss(rdev, bss))
2582 rdev->bss_generation++;
2584 spin_unlock_bh(&rdev->bss_lock);
2586 EXPORT_SYMBOL(cfg80211_unlink_bss);
2588 void cfg80211_bss_iter(struct wiphy *wiphy,
2589 struct cfg80211_chan_def *chandef,
2590 void (*iter)(struct wiphy *wiphy,
2591 struct cfg80211_bss *bss,
2595 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
2596 struct cfg80211_internal_bss *bss;
2598 spin_lock_bh(&rdev->bss_lock);
2600 list_for_each_entry(bss, &rdev->bss_list, list) {
2601 if (!chandef || cfg80211_is_sub_chan(chandef, bss->pub.channel))
2602 iter(wiphy, &bss->pub, iter_data);
2605 spin_unlock_bh(&rdev->bss_lock);
2607 EXPORT_SYMBOL(cfg80211_bss_iter);
2609 void cfg80211_update_assoc_bss_entry(struct wireless_dev *wdev,
2610 struct ieee80211_channel *chan)
2612 struct wiphy *wiphy = wdev->wiphy;
2613 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
2614 struct cfg80211_internal_bss *cbss = wdev->current_bss;
2615 struct cfg80211_internal_bss *new = NULL;
2616 struct cfg80211_internal_bss *bss;
2617 struct cfg80211_bss *nontrans_bss;
2618 struct cfg80211_bss *tmp;
2620 spin_lock_bh(&rdev->bss_lock);
2623 * Some APs use CSA also for bandwidth changes, i.e., without actually
2624 * changing the control channel, so no need to update in such a case.
2626 if (cbss->pub.channel == chan)
2629 /* use transmitting bss */
2630 if (cbss->pub.transmitted_bss)
2631 cbss = container_of(cbss->pub.transmitted_bss,
2632 struct cfg80211_internal_bss,
2635 cbss->pub.channel = chan;
2637 list_for_each_entry(bss, &rdev->bss_list, list) {
2638 if (!cfg80211_bss_type_match(bss->pub.capability,
2639 bss->pub.channel->band,
2640 wdev->conn_bss_type))
2646 if (!cmp_bss(&bss->pub, &cbss->pub, BSS_CMP_REGULAR)) {
2653 /* to save time, update IEs for transmitting bss only */
2654 if (cfg80211_update_known_bss(rdev, cbss, new, false)) {
2655 new->pub.proberesp_ies = NULL;
2656 new->pub.beacon_ies = NULL;
2659 list_for_each_entry_safe(nontrans_bss, tmp,
2660 &new->pub.nontrans_list,
2662 bss = container_of(nontrans_bss,
2663 struct cfg80211_internal_bss, pub);
2664 if (__cfg80211_unlink_bss(rdev, bss))
2665 rdev->bss_generation++;
2668 WARN_ON(atomic_read(&new->hold));
2669 if (!WARN_ON(!__cfg80211_unlink_bss(rdev, new)))
2670 rdev->bss_generation++;
2673 rb_erase(&cbss->rbn, &rdev->bss_tree);
2674 rb_insert_bss(rdev, cbss);
2675 rdev->bss_generation++;
2677 list_for_each_entry_safe(nontrans_bss, tmp,
2678 &cbss->pub.nontrans_list,
2680 bss = container_of(nontrans_bss,
2681 struct cfg80211_internal_bss, pub);
2682 bss->pub.channel = chan;
2683 rb_erase(&bss->rbn, &rdev->bss_tree);
2684 rb_insert_bss(rdev, bss);
2685 rdev->bss_generation++;
2689 spin_unlock_bh(&rdev->bss_lock);
2692 #ifdef CONFIG_CFG80211_WEXT
2693 static struct cfg80211_registered_device *
2694 cfg80211_get_dev_from_ifindex(struct net *net, int ifindex)
2696 struct cfg80211_registered_device *rdev;
2697 struct net_device *dev;
2701 dev = dev_get_by_index(net, ifindex);
2703 return ERR_PTR(-ENODEV);
2704 if (dev->ieee80211_ptr)
2705 rdev = wiphy_to_rdev(dev->ieee80211_ptr->wiphy);
2707 rdev = ERR_PTR(-ENODEV);
2712 int cfg80211_wext_siwscan(struct net_device *dev,
2713 struct iw_request_info *info,
2714 union iwreq_data *wrqu, char *extra)
2716 struct cfg80211_registered_device *rdev;
2717 struct wiphy *wiphy;
2718 struct iw_scan_req *wreq = NULL;
2719 struct cfg80211_scan_request *creq = NULL;
2720 int i, err, n_channels = 0;
2721 enum nl80211_band band;
2723 if (!netif_running(dev))
2726 if (wrqu->data.length == sizeof(struct iw_scan_req))
2727 wreq = (struct iw_scan_req *)extra;
2729 rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
2732 return PTR_ERR(rdev);
2734 if (rdev->scan_req || rdev->scan_msg) {
2739 wiphy = &rdev->wiphy;
2741 /* Determine number of channels, needed to allocate creq */
2742 if (wreq && wreq->num_channels)
2743 n_channels = wreq->num_channels;
2745 n_channels = ieee80211_get_num_supported_channels(wiphy);
2747 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
2748 n_channels * sizeof(void *),
2755 creq->wiphy = wiphy;
2756 creq->wdev = dev->ieee80211_ptr;
2757 /* SSIDs come after channels */
2758 creq->ssids = (void *)&creq->channels[n_channels];
2759 creq->n_channels = n_channels;
2761 creq->scan_start = jiffies;
2763 /* translate "Scan on frequencies" request */
2765 for (band = 0; band < NUM_NL80211_BANDS; band++) {
2768 if (!wiphy->bands[band])
2771 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
2772 /* ignore disabled channels */
2773 if (wiphy->bands[band]->channels[j].flags &
2774 IEEE80211_CHAN_DISABLED)
2777 /* If we have a wireless request structure and the
2778 * wireless request specifies frequencies, then search
2779 * for the matching hardware channel.
2781 if (wreq && wreq->num_channels) {
2783 int wiphy_freq = wiphy->bands[band]->channels[j].center_freq;
2784 for (k = 0; k < wreq->num_channels; k++) {
2785 struct iw_freq *freq =
2786 &wreq->channel_list[k];
2788 cfg80211_wext_freq(freq);
2790 if (wext_freq == wiphy_freq)
2791 goto wext_freq_found;
2793 goto wext_freq_not_found;
2797 creq->channels[i] = &wiphy->bands[band]->channels[j];
2799 wext_freq_not_found: ;
2802 /* No channels found? */
2808 /* Set real number of channels specified in creq->channels[] */
2809 creq->n_channels = i;
2811 /* translate "Scan for SSID" request */
2813 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
2814 if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) {
2818 memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len);
2819 creq->ssids[0].ssid_len = wreq->essid_len;
2821 if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE)
2825 for (i = 0; i < NUM_NL80211_BANDS; i++)
2826 if (wiphy->bands[i])
2827 creq->rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1;
2829 eth_broadcast_addr(creq->bssid);
2831 wiphy_lock(&rdev->wiphy);
2833 rdev->scan_req = creq;
2834 err = rdev_scan(rdev, creq);
2836 rdev->scan_req = NULL;
2837 /* creq will be freed below */
2839 nl80211_send_scan_start(rdev, dev->ieee80211_ptr);
2840 /* creq now owned by driver */
2844 wiphy_unlock(&rdev->wiphy);
2849 EXPORT_WEXT_HANDLER(cfg80211_wext_siwscan);
2851 static char *ieee80211_scan_add_ies(struct iw_request_info *info,
2852 const struct cfg80211_bss_ies *ies,
2853 char *current_ev, char *end_buf)
2855 const u8 *pos, *end, *next;
2856 struct iw_event iwe;
2862 * If needed, fragment the IEs buffer (at IE boundaries) into short
2863 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
2866 end = pos + ies->len;
2868 while (end - pos > IW_GENERIC_IE_MAX) {
2869 next = pos + 2 + pos[1];
2870 while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX)
2871 next = next + 2 + next[1];
2873 memset(&iwe, 0, sizeof(iwe));
2874 iwe.cmd = IWEVGENIE;
2875 iwe.u.data.length = next - pos;
2876 current_ev = iwe_stream_add_point_check(info, current_ev,
2879 if (IS_ERR(current_ev))
2885 memset(&iwe, 0, sizeof(iwe));
2886 iwe.cmd = IWEVGENIE;
2887 iwe.u.data.length = end - pos;
2888 current_ev = iwe_stream_add_point_check(info, current_ev,
2891 if (IS_ERR(current_ev))
2899 ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
2900 struct cfg80211_internal_bss *bss, char *current_ev,
2903 const struct cfg80211_bss_ies *ies;
2904 struct iw_event iwe;
2909 bool ismesh = false;
2911 memset(&iwe, 0, sizeof(iwe));
2912 iwe.cmd = SIOCGIWAP;
2913 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
2914 memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN);
2915 current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe,
2917 if (IS_ERR(current_ev))
2920 memset(&iwe, 0, sizeof(iwe));
2921 iwe.cmd = SIOCGIWFREQ;
2922 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq);
2924 current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe,
2926 if (IS_ERR(current_ev))
2929 memset(&iwe, 0, sizeof(iwe));
2930 iwe.cmd = SIOCGIWFREQ;
2931 iwe.u.freq.m = bss->pub.channel->center_freq;
2933 current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe,
2935 if (IS_ERR(current_ev))
2938 if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) {
2939 memset(&iwe, 0, sizeof(iwe));
2941 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED |
2942 IW_QUAL_NOISE_INVALID |
2943 IW_QUAL_QUAL_UPDATED;
2944 switch (wiphy->signal_type) {
2945 case CFG80211_SIGNAL_TYPE_MBM:
2946 sig = bss->pub.signal / 100;
2947 iwe.u.qual.level = sig;
2948 iwe.u.qual.updated |= IW_QUAL_DBM;
2949 if (sig < -110) /* rather bad */
2951 else if (sig > -40) /* perfect */
2953 /* will give a range of 0 .. 70 */
2954 iwe.u.qual.qual = sig + 110;
2956 case CFG80211_SIGNAL_TYPE_UNSPEC:
2957 iwe.u.qual.level = bss->pub.signal;
2958 /* will give range 0 .. 100 */
2959 iwe.u.qual.qual = bss->pub.signal;
2965 current_ev = iwe_stream_add_event_check(info, current_ev,
2968 if (IS_ERR(current_ev))
2972 memset(&iwe, 0, sizeof(iwe));
2973 iwe.cmd = SIOCGIWENCODE;
2974 if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY)
2975 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
2977 iwe.u.data.flags = IW_ENCODE_DISABLED;
2978 iwe.u.data.length = 0;
2979 current_ev = iwe_stream_add_point_check(info, current_ev, end_buf,
2981 if (IS_ERR(current_ev))
2985 ies = rcu_dereference(bss->pub.ies);
2991 if (ie[1] > rem - 2)
2996 memset(&iwe, 0, sizeof(iwe));
2997 iwe.cmd = SIOCGIWESSID;
2998 iwe.u.data.length = ie[1];
2999 iwe.u.data.flags = 1;
3000 current_ev = iwe_stream_add_point_check(info,
3004 if (IS_ERR(current_ev))
3007 case WLAN_EID_MESH_ID:
3008 memset(&iwe, 0, sizeof(iwe));
3009 iwe.cmd = SIOCGIWESSID;
3010 iwe.u.data.length = ie[1];
3011 iwe.u.data.flags = 1;
3012 current_ev = iwe_stream_add_point_check(info,
3016 if (IS_ERR(current_ev))
3019 case WLAN_EID_MESH_CONFIG:
3021 if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
3024 memset(&iwe, 0, sizeof(iwe));
3025 iwe.cmd = IWEVCUSTOM;
3026 sprintf(buf, "Mesh Network Path Selection Protocol ID: "
3028 iwe.u.data.length = strlen(buf);
3029 current_ev = iwe_stream_add_point_check(info,
3033 if (IS_ERR(current_ev))
3035 sprintf(buf, "Path Selection Metric ID: 0x%02X",
3037 iwe.u.data.length = strlen(buf);
3038 current_ev = iwe_stream_add_point_check(info,
3042 if (IS_ERR(current_ev))
3044 sprintf(buf, "Congestion Control Mode ID: 0x%02X",
3046 iwe.u.data.length = strlen(buf);
3047 current_ev = iwe_stream_add_point_check(info,
3051 if (IS_ERR(current_ev))
3053 sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]);
3054 iwe.u.data.length = strlen(buf);
3055 current_ev = iwe_stream_add_point_check(info,
3059 if (IS_ERR(current_ev))
3061 sprintf(buf, "Authentication ID: 0x%02X", cfg[4]);
3062 iwe.u.data.length = strlen(buf);
3063 current_ev = iwe_stream_add_point_check(info,
3067 if (IS_ERR(current_ev))
3069 sprintf(buf, "Formation Info: 0x%02X", cfg[5]);
3070 iwe.u.data.length = strlen(buf);
3071 current_ev = iwe_stream_add_point_check(info,
3075 if (IS_ERR(current_ev))
3077 sprintf(buf, "Capabilities: 0x%02X", cfg[6]);
3078 iwe.u.data.length = strlen(buf);
3079 current_ev = iwe_stream_add_point_check(info,
3083 if (IS_ERR(current_ev))
3086 case WLAN_EID_SUPP_RATES:
3087 case WLAN_EID_EXT_SUPP_RATES:
3088 /* display all supported rates in readable format */
3089 p = current_ev + iwe_stream_lcp_len(info);
3091 memset(&iwe, 0, sizeof(iwe));
3092 iwe.cmd = SIOCGIWRATE;
3093 /* Those two flags are ignored... */
3094 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
3096 for (i = 0; i < ie[1]; i++) {
3097 iwe.u.bitrate.value =
3098 ((ie[i + 2] & 0x7f) * 500000);
3100 p = iwe_stream_add_value(info, current_ev, p,
3104 current_ev = ERR_PTR(-E2BIG);
3115 if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) ||
3117 memset(&iwe, 0, sizeof(iwe));
3118 iwe.cmd = SIOCGIWMODE;
3120 iwe.u.mode = IW_MODE_MESH;
3121 else if (bss->pub.capability & WLAN_CAPABILITY_ESS)
3122 iwe.u.mode = IW_MODE_MASTER;
3124 iwe.u.mode = IW_MODE_ADHOC;
3125 current_ev = iwe_stream_add_event_check(info, current_ev,
3128 if (IS_ERR(current_ev))
3132 memset(&iwe, 0, sizeof(iwe));
3133 iwe.cmd = IWEVCUSTOM;
3134 sprintf(buf, "tsf=%016llx", (unsigned long long)(ies->tsf));
3135 iwe.u.data.length = strlen(buf);
3136 current_ev = iwe_stream_add_point_check(info, current_ev, end_buf,
3138 if (IS_ERR(current_ev))
3140 memset(&iwe, 0, sizeof(iwe));
3141 iwe.cmd = IWEVCUSTOM;
3142 sprintf(buf, " Last beacon: %ums ago",
3143 elapsed_jiffies_msecs(bss->ts));
3144 iwe.u.data.length = strlen(buf);
3145 current_ev = iwe_stream_add_point_check(info, current_ev,
3146 end_buf, &iwe, buf);
3147 if (IS_ERR(current_ev))
3150 current_ev = ieee80211_scan_add_ies(info, ies, current_ev, end_buf);
3158 static int ieee80211_scan_results(struct cfg80211_registered_device *rdev,
3159 struct iw_request_info *info,
3160 char *buf, size_t len)
3162 char *current_ev = buf;
3163 char *end_buf = buf + len;
3164 struct cfg80211_internal_bss *bss;
3167 spin_lock_bh(&rdev->bss_lock);
3168 cfg80211_bss_expire(rdev);
3170 list_for_each_entry(bss, &rdev->bss_list, list) {
3171 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
3175 current_ev = ieee80211_bss(&rdev->wiphy, info, bss,
3176 current_ev, end_buf);
3177 if (IS_ERR(current_ev)) {
3178 err = PTR_ERR(current_ev);
3182 spin_unlock_bh(&rdev->bss_lock);
3186 return current_ev - buf;
3190 int cfg80211_wext_giwscan(struct net_device *dev,
3191 struct iw_request_info *info,
3192 struct iw_point *data, char *extra)
3194 struct cfg80211_registered_device *rdev;
3197 if (!netif_running(dev))
3200 rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
3203 return PTR_ERR(rdev);
3205 if (rdev->scan_req || rdev->scan_msg)
3208 res = ieee80211_scan_results(rdev, info, extra, data->length);
3217 EXPORT_WEXT_HANDLER(cfg80211_wext_giwscan);