^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Scanning implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2004, Instant802 Networks, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright 2005, Devicescape Software, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright 2013-2015 Intel Mobile Communications GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright 2016-2017 Intel Deutschland GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (C) 2018-2020 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/sch_generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <net/mac80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "ieee80211_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "driver-ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "mesh.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define IEEE80211_PROBE_DELAY (HZ / 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define IEEE80211_CHANNEL_TIME (HZ / 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) void ieee80211_rx_bss_put(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct ieee80211_bss *bss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (!bss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) cfg80211_put_bss(local->hw.wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) container_of((void *)bss, struct cfg80211_bss, priv));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static bool is_uapsd_supported(struct ieee802_11_elems *elems)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) u8 qos_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (elems->wmm_info && elems->wmm_info_len == 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) && elems->wmm_info[5] == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) qos_info = elems->wmm_info[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) else if (elems->wmm_param && elems->wmm_param_len == 24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) && elems->wmm_param[5] == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) qos_info = elems->wmm_param[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* no valid wmm information or parameter element found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return qos_info & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ieee80211_update_bss_from_elems(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct ieee80211_bss *bss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct ieee802_11_elems *elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct ieee80211_rx_status *rx_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) bool beacon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int clen, srlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (beacon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) bss->device_ts_beacon = rx_status->device_timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) bss->device_ts_presp = rx_status->device_timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (elems->parse_error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (beacon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) bss->corrupt_data |= IEEE80211_BSS_CORRUPT_BEACON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) bss->corrupt_data |= IEEE80211_BSS_CORRUPT_PROBE_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (beacon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) bss->corrupt_data &= ~IEEE80211_BSS_CORRUPT_BEACON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) bss->corrupt_data &= ~IEEE80211_BSS_CORRUPT_PROBE_RESP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* save the ERP value so that it is available at association time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (elems->erp_info && (!elems->parse_error ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) !(bss->valid_data & IEEE80211_BSS_VALID_ERP))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) bss->erp_value = elems->erp_info[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) bss->has_erp_value = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (!elems->parse_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) bss->valid_data |= IEEE80211_BSS_VALID_ERP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* replace old supported rates if we get new values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (!elems->parse_error ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) !(bss->valid_data & IEEE80211_BSS_VALID_RATES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) srlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (elems->supp_rates) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) clen = IEEE80211_MAX_SUPP_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (clen > elems->supp_rates_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) clen = elems->supp_rates_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) memcpy(bss->supp_rates, elems->supp_rates, clen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) srlen += clen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (elems->ext_supp_rates) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) clen = IEEE80211_MAX_SUPP_RATES - srlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (clen > elems->ext_supp_rates_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) clen = elems->ext_supp_rates_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) memcpy(bss->supp_rates + srlen, elems->ext_supp_rates,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) clen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) srlen += clen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (srlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) bss->supp_rates_len = srlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (!elems->parse_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) bss->valid_data |= IEEE80211_BSS_VALID_RATES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (!elems->parse_error ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) !(bss->valid_data & IEEE80211_BSS_VALID_WMM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) bss->wmm_used = elems->wmm_param || elems->wmm_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) bss->uapsd_supported = is_uapsd_supported(elems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (!elems->parse_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) bss->valid_data |= IEEE80211_BSS_VALID_WMM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (beacon) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct ieee80211_supported_band *sband =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) local->hw.wiphy->bands[rx_status->band];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!(rx_status->encoding == RX_ENC_HT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) !(rx_status->encoding == RX_ENC_VHT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) bss->beacon_rate =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) &sband->bitrates[rx_status->rate_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (elems->vht_cap_elem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) bss->vht_cap_info =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) le32_to_cpu(elems->vht_cap_elem->vht_cap_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) bss->vht_cap_info = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct ieee80211_bss *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ieee80211_bss_info_update(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct ieee80211_rx_status *rx_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct ieee80211_mgmt *mgmt, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct ieee80211_channel *channel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) bool beacon = ieee80211_is_beacon(mgmt->frame_control) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ieee80211_is_s1g_beacon(mgmt->frame_control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct cfg80211_bss *cbss, *non_tx_cbss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct ieee80211_bss *bss, *non_tx_bss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct cfg80211_inform_bss bss_meta = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .boottime_ns = rx_status->boottime_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) bool signal_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct ieee80211_sub_if_data *scan_sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct ieee802_11_elems elems;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) size_t baselen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) u8 *elements;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) bss_meta.signal = 0; /* invalid signal indication */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) else if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) bss_meta.signal = rx_status->signal * 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) else if (ieee80211_hw_check(&local->hw, SIGNAL_UNSPEC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) bss_meta.signal = (rx_status->signal * 100) / local->hw.max_signal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) bss_meta.scan_width = NL80211_BSS_CHAN_WIDTH_20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (rx_status->bw == RATE_INFO_BW_5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) bss_meta.scan_width = NL80211_BSS_CHAN_WIDTH_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) else if (rx_status->bw == RATE_INFO_BW_10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) bss_meta.scan_width = NL80211_BSS_CHAN_WIDTH_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) bss_meta.chan = channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) scan_sdata = rcu_dereference(local->scan_sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (scan_sdata && scan_sdata->vif.type == NL80211_IFTYPE_STATION &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) scan_sdata->vif.bss_conf.assoc &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ieee80211_have_rx_timestamp(rx_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) bss_meta.parent_tsf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ieee80211_calculate_rx_timestamp(local, rx_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) len + FCS_LEN, 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ether_addr_copy(bss_meta.parent_bssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) scan_sdata->vif.bss_conf.bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) cbss = cfg80211_inform_bss_frame_data(local->hw.wiphy, &bss_meta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) mgmt, len, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (!cbss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (ieee80211_is_probe_resp(mgmt->frame_control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) elements = mgmt->u.probe_resp.variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) baselen = offsetof(struct ieee80211_mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) u.probe_resp.variable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) } else if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct ieee80211_ext *ext = (void *) mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) baselen = offsetof(struct ieee80211_ext, u.s1g_beacon.variable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) elements = ext->u.s1g_beacon.variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) elements = mgmt->u.beacon.variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (baselen > len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ieee802_11_parse_elems(elements, len - baselen, false, &elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) mgmt->bssid, cbss->bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /* In case the signal is invalid update the status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) signal_valid = channel == cbss->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (!signal_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) bss = (void *)cbss->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) ieee80211_update_bss_from_elems(local, bss, &elems, rx_status, beacon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) list_for_each_entry(non_tx_cbss, &cbss->nontrans_list, nontrans_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) non_tx_bss = (void *)non_tx_cbss->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ieee80211_update_bss_from_elems(local, non_tx_bss, &elems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) rx_status, beacon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return bss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static bool ieee80211_scan_accept_presp(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) u32 scan_flags, const u8 *da)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (!sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /* accept broadcast for OCE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (scan_flags & NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) is_broadcast_ether_addr(da))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (scan_flags & NL80211_SCAN_FLAG_RANDOM_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return ether_addr_equal(da, sdata->vif.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct ieee80211_sub_if_data *sdata1, *sdata2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct ieee80211_mgmt *mgmt = (void *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct ieee80211_bss *bss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct ieee80211_channel *channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) size_t min_hdr_len = offsetof(struct ieee80211_mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) u.probe_resp.variable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!ieee80211_is_probe_resp(mgmt->frame_control) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) !ieee80211_is_beacon(mgmt->frame_control) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) !ieee80211_is_s1g_beacon(mgmt->frame_control))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (ieee80211_is_s1g_short_beacon(mgmt->frame_control))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) min_hdr_len = offsetof(struct ieee80211_ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) u.s1g_short_beacon.variable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) min_hdr_len = offsetof(struct ieee80211_ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) u.s1g_beacon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (skb->len < min_hdr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) sdata1 = rcu_dereference(local->scan_sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) sdata2 = rcu_dereference(local->sched_scan_sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (likely(!sdata1 && !sdata2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (ieee80211_is_probe_resp(mgmt->frame_control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct cfg80211_scan_request *scan_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct cfg80211_sched_scan_request *sched_scan_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) u32 scan_req_flags = 0, sched_scan_req_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) scan_req = rcu_dereference(local->scan_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) sched_scan_req = rcu_dereference(local->sched_scan_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (scan_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) scan_req_flags = scan_req->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (sched_scan_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) sched_scan_req_flags = sched_scan_req->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /* ignore ProbeResp to foreign address or non-bcast (OCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * unless scanning with randomised address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (!ieee80211_scan_accept_presp(sdata1, scan_req_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) mgmt->da) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) !ieee80211_scan_accept_presp(sdata2, sched_scan_req_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) mgmt->da))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) channel = ieee80211_get_channel_khz(local->hw.wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) ieee80211_rx_status_to_khz(rx_status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) bss = ieee80211_bss_info_update(local, rx_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) mgmt, skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (bss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ieee80211_rx_bss_put(local, bss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) ieee80211_prepare_scan_chandef(struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) enum nl80211_bss_scan_width scan_width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) memset(chandef, 0, sizeof(*chandef));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) switch (scan_width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) case NL80211_BSS_CHAN_WIDTH_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) chandef->width = NL80211_CHAN_WIDTH_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) case NL80211_BSS_CHAN_WIDTH_10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) chandef->width = NL80211_CHAN_WIDTH_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* return false if no more work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static bool ieee80211_prep_hw_scan(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct cfg80211_scan_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct cfg80211_chan_def chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) u8 bands_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int i, ielen, n_chans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) u32 flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) req = rcu_dereference_protected(local->scan_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (test_bit(SCAN_HW_CANCELLED, &local->scanning))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (ieee80211_hw_check(&local->hw, SINGLE_SCAN_ON_ALL_BANDS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) for (i = 0; i < req->n_channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) local->hw_scan_req->req.channels[i] = req->channels[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) bands_used |= BIT(req->channels[i]->band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) n_chans = req->n_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (local->hw_scan_band == NUM_NL80211_BANDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) n_chans = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) for (i = 0; i < req->n_channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (req->channels[i]->band !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) local->hw_scan_band)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) local->hw_scan_req->req.channels[n_chans] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) req->channels[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) n_chans++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) bands_used |= BIT(req->channels[i]->band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) local->hw_scan_band++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) } while (!n_chans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) local->hw_scan_req->req.n_channels = n_chans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ieee80211_prepare_scan_chandef(&chandef, req->scan_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (req->flags & NL80211_SCAN_FLAG_MIN_PREQ_CONTENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) flags |= IEEE80211_PROBE_FLAG_MIN_CONTENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) ielen = ieee80211_build_preq_ies(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) (u8 *)local->hw_scan_req->req.ie,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) local->hw_scan_ies_bufsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) &local->hw_scan_req->ies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) req->ie, req->ie_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) bands_used, req->rates, &chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) local->hw_scan_req->req.ie_len = ielen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) local->hw_scan_req->req.no_cck = req->no_cck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ether_addr_copy(local->hw_scan_req->req.mac_addr, req->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) ether_addr_copy(local->hw_scan_req->req.mac_addr_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) req->mac_addr_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ether_addr_copy(local->hw_scan_req->req.bssid, req->bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) bool hw_scan = test_bit(SCAN_HW_SCANNING, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) bool was_scanning = local->scanning;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct cfg80211_scan_request *scan_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct ieee80211_sub_if_data *scan_sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * It's ok to abort a not-yet-running scan (that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * we have one at all will be verified by checking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * local->scan_req next), but not to complete it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) * successfully.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (WARN_ON(!local->scanning && !aborted))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (WARN_ON(!local->scan_req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) scan_sdata = rcu_dereference_protected(local->scan_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (hw_scan && !aborted &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) !ieee80211_hw_check(&local->hw, SINGLE_SCAN_ON_ALL_BANDS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) ieee80211_prep_hw_scan(scan_sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) rc = drv_hw_scan(local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) rcu_dereference_protected(local->scan_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) lockdep_is_held(&local->mtx)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) local->hw_scan_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /* HW scan failed and is going to be reported as aborted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * so clear old scan info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) memset(&local->scan_info, 0, sizeof(local->scan_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) kfree(local->hw_scan_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) local->hw_scan_req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) scan_req = rcu_dereference_protected(local->scan_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (scan_req != local->int_scan_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) local->scan_info.aborted = aborted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) cfg80211_scan_done(scan_req, &local->scan_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) RCU_INIT_POINTER(local->scan_req, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) RCU_INIT_POINTER(local->scan_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) local->scanning = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) local->scan_chandef.chan = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /* Set power back to normal operating levels. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) ieee80211_hw_config(local, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (!hw_scan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) ieee80211_configure_filter(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) drv_sw_scan_complete(local, scan_sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) ieee80211_offchannel_return(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) ieee80211_recalc_idle(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) ieee80211_mlme_notify_scan_completed(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) ieee80211_ibss_notify_scan_completed(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* Requeue all the work that might have been ignored while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) * the scan was in progress; if there was none this will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) * just be a no-op for the particular interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) ieee80211_queue_work(&sdata->local->hw, &sdata->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (was_scanning)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) ieee80211_start_next_roc(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) void ieee80211_scan_completed(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct cfg80211_scan_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) trace_api_scan_completed(local, info->aborted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) set_bit(SCAN_COMPLETED, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) if (info->aborted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) set_bit(SCAN_ABORTED, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) memcpy(&local->scan_info, info, sizeof(*info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) ieee80211_queue_delayed_work(&local->hw, &local->scan_work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) EXPORT_SYMBOL(ieee80211_scan_completed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static int ieee80211_start_sw_scan(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /* Software scan is not supported in multi-channel cases */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (local->use_chanctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * Hardware/driver doesn't support hw_scan, so use software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * scanning instead. First send a nullfunc frame with power save
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * bit on so that AP will buffer the frames for us while we are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * listening, then send probe requests to each channel and wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * the responses. After all channels are scanned, tune back to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * original channel and send a nullfunc frame with power save bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * off to trigger the AP to send us all the buffered frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * Note that while local->sw_scanning is true everything else but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * nullfunc frames and probe requests will be dropped in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) * ieee80211_tx_h_check_assoc().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) drv_sw_scan_start(local, sdata, local->scan_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) local->leave_oper_channel_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) local->next_scan_state = SCAN_DECISION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) local->scan_channel_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) ieee80211_offchannel_stop_vifs(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) /* ensure nullfunc is transmitted before leaving operating channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) ieee80211_flush_queues(local, NULL, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) ieee80211_configure_filter(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /* We need to set power level at maximum rate for scanning. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) ieee80211_hw_config(local, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) ieee80211_queue_delayed_work(&local->hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) &local->scan_work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static bool __ieee80211_can_leave_ch(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct ieee80211_sub_if_data *sdata_iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (!ieee80211_is_radar_required(local))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (!regulatory_pre_cac_allowed(local->hw.wiphy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) list_for_each_entry(sdata_iter, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (sdata_iter->wdev.cac_started) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) static bool ieee80211_can_scan(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (!__ieee80211_can_leave_ch(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (!list_empty(&local->roc_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (sdata->vif.type == NL80211_IFTYPE_STATION &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) sdata->u.mgd.flags & IEEE80211_STA_CONNECTION_POLL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) void ieee80211_run_deferred_scan(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (!local->scan_req || local->scanning)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (!ieee80211_can_scan(local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) rcu_dereference_protected(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) local->scan_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) lockdep_is_held(&local->mtx))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) ieee80211_queue_delayed_work(&local->hw, &local->scan_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) round_jiffies_relative(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) static void ieee80211_send_scan_probe_req(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) const u8 *src, const u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) const u8 *ssid, size_t ssid_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) const u8 *ie, size_t ie_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) u32 ratemask, u32 flags, u32 tx_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct ieee80211_channel *channel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) skb = ieee80211_build_probe_req(sdata, src, dst, ratemask, channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) ssid, ssid_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) ie, ie_len, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) if (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (flags & IEEE80211_PROBE_FLAG_RANDOM_SN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) struct ieee80211_hdr *hdr = (void *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) u16 sn = get_random_u32();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) info->control.flags |= IEEE80211_TX_CTRL_NO_SEQNO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) hdr->seq_ctrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) cpu_to_le16(IEEE80211_SN_TO_SEQ(sn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) IEEE80211_SKB_CB(skb)->flags |= tx_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) ieee80211_tx_skb_tid_band(sdata, skb, 7, channel->band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static void ieee80211_scan_state_send_probe(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) unsigned long *next_delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) struct cfg80211_scan_request *scan_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) enum nl80211_band band = local->hw.conf.chandef.chan->band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) u32 flags = 0, tx_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) scan_req = rcu_dereference_protected(local->scan_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) tx_flags = IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (scan_req->no_cck)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) tx_flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (scan_req->flags & NL80211_SCAN_FLAG_MIN_PREQ_CONTENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) flags |= IEEE80211_PROBE_FLAG_MIN_CONTENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (scan_req->flags & NL80211_SCAN_FLAG_RANDOM_SN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) flags |= IEEE80211_PROBE_FLAG_RANDOM_SN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) sdata = rcu_dereference_protected(local->scan_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) for (i = 0; i < scan_req->n_ssids; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) ieee80211_send_scan_probe_req(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) sdata, local->scan_addr, scan_req->bssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) scan_req->ssids[i].ssid, scan_req->ssids[i].ssid_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) scan_req->ie, scan_req->ie_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) scan_req->rates[band], flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) tx_flags, local->hw.conf.chandef.chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * After sending probe requests, wait for probe responses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * on the channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) *next_delay = IEEE80211_CHANNEL_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) local->next_scan_state = SCAN_DECISION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) struct cfg80211_scan_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) bool hw_scan = local->ops->hw_scan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if (local->scan_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (!__ieee80211_can_leave_ch(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (!ieee80211_can_scan(local, sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) /* wait for the work to finish/time out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) rcu_assign_pointer(local->scan_req, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) rcu_assign_pointer(local->scan_sdata, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) if (hw_scan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) u8 *ies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) local->hw_scan_ies_bufsize = local->scan_ies_len + req->ie_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) if (ieee80211_hw_check(&local->hw, SINGLE_SCAN_ON_ALL_BANDS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) int i, n_bands = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) u8 bands_counted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) for (i = 0; i < req->n_channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) if (bands_counted & BIT(req->channels[i]->band))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) bands_counted |= BIT(req->channels[i]->band);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) n_bands++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) local->hw_scan_ies_bufsize *= n_bands;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) local->hw_scan_req = kmalloc(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) sizeof(*local->hw_scan_req) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) req->n_channels * sizeof(req->channels[0]) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) local->hw_scan_ies_bufsize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (!local->hw_scan_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) local->hw_scan_req->req.ssids = req->ssids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) local->hw_scan_req->req.n_ssids = req->n_ssids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) ies = (u8 *)local->hw_scan_req +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) sizeof(*local->hw_scan_req) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) req->n_channels * sizeof(req->channels[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) local->hw_scan_req->req.ie = ies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) local->hw_scan_req->req.flags = req->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) eth_broadcast_addr(local->hw_scan_req->req.bssid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) local->hw_scan_req->req.duration = req->duration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) local->hw_scan_req->req.duration_mandatory =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) req->duration_mandatory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) local->hw_scan_band = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) local->hw_scan_req->req.n_6ghz_params = req->n_6ghz_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) local->hw_scan_req->req.scan_6ghz_params =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) req->scan_6ghz_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) local->hw_scan_req->req.scan_6ghz = req->scan_6ghz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) * After allocating local->hw_scan_req, we must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) * go through until ieee80211_prep_hw_scan(), so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) * anything that might be changed here and leave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * this function early must not go after this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) * allocation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) rcu_assign_pointer(local->scan_req, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) rcu_assign_pointer(local->scan_sdata, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) get_random_mask_addr(local->scan_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) req->mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) req->mac_addr_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) memcpy(local->scan_addr, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (hw_scan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) __set_bit(SCAN_HW_SCANNING, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) } else if ((req->n_channels == 1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) (req->channels[0] == local->_oper_chandef.chan)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) * If we are scanning only on the operating channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) * then we do not need to stop normal activities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) unsigned long next_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) __set_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) ieee80211_recalc_idle(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) /* Notify driver scan is starting, keep order of operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) * same as normal software scan, in case that matters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) drv_sw_scan_start(local, sdata, local->scan_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) ieee80211_configure_filter(local); /* accept probe-responses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) /* We need to ensure power level is at max for scanning. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) ieee80211_hw_config(local, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) if ((req->channels[0]->flags & (IEEE80211_CHAN_NO_IR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) IEEE80211_CHAN_RADAR)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) !req->n_ssids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) ieee80211_scan_state_send_probe(local, &next_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) next_delay = IEEE80211_CHANNEL_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) /* Now, just wait a bit and we are all done! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) ieee80211_queue_delayed_work(&local->hw, &local->scan_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) next_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) /* Do normal software scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) __set_bit(SCAN_SW_SCANNING, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) ieee80211_recalc_idle(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (hw_scan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) WARN_ON(!ieee80211_prep_hw_scan(sdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) rc = drv_hw_scan(local, sdata, local->hw_scan_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) rc = ieee80211_start_sw_scan(local, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) kfree(local->hw_scan_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) local->hw_scan_req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) local->scanning = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) ieee80211_recalc_idle(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) local->scan_req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) RCU_INIT_POINTER(local->scan_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) if (hw_scan && rc == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) * we can't fall back to software for P2P-GO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) * as it must update NoA etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) if (ieee80211_vif_type_p2p(&sdata->vif) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) NL80211_IFTYPE_P2P_GO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) hw_scan = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) static unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) ieee80211_scan_get_channel_time(struct ieee80211_channel *chan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) * TODO: channel switching also consumes quite some time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) * add that delay as well to get a better estimation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) return IEEE80211_PASSIVE_CHANNEL_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) return IEEE80211_PROBE_DELAY + IEEE80211_CHANNEL_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) static void ieee80211_scan_state_decision(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) unsigned long *next_delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) bool associated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) bool tx_empty = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) bool bad_latency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct ieee80211_channel *next_chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) enum mac80211_scan_state next_scan_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) struct cfg80211_scan_request *scan_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) * check if at least one STA interface is associated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) * check if at least one STA interface has pending tx frames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) * and grab the lowest used beacon interval
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) mutex_lock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) list_for_each_entry(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) if (!ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) if (sdata->vif.type == NL80211_IFTYPE_STATION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) if (sdata->u.mgd.associated) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) associated = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (!qdisc_all_tx_empty(sdata->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) tx_empty = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) mutex_unlock(&local->iflist_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) scan_req = rcu_dereference_protected(local->scan_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) next_chan = scan_req->channels[local->scan_channel_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) * we're currently scanning a different channel, let's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) * see if we can scan another channel without interfering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) * with the current traffic situation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) * Keep good latency, do not stay off-channel more than 125 ms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) bad_latency = time_after(jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) ieee80211_scan_get_channel_time(next_chan),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) local->leave_oper_channel_time + HZ / 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) if (associated && !tx_empty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (scan_req->flags & NL80211_SCAN_FLAG_LOW_PRIORITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) next_scan_state = SCAN_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) next_scan_state = SCAN_SUSPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) } else if (associated && bad_latency) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) next_scan_state = SCAN_SUSPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) next_scan_state = SCAN_SET_CHANNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) local->next_scan_state = next_scan_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) *next_delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) static void ieee80211_scan_state_set_channel(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) unsigned long *next_delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) int skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) struct ieee80211_channel *chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) enum nl80211_bss_scan_width oper_scan_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) struct cfg80211_scan_request *scan_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) scan_req = rcu_dereference_protected(local->scan_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) chan = scan_req->channels[local->scan_channel_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) local->scan_chandef.chan = chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) local->scan_chandef.center_freq1 = chan->center_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) local->scan_chandef.freq1_offset = chan->freq_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) local->scan_chandef.center_freq2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) /* For scanning on the S1G band, ignore scan_width (which is constant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) * across all channels) for now since channel width is specific to each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) * channel. Detect the required channel width here and likely revisit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) * later. Maybe scan_width could be used to build the channel scan list?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) if (chan->band == NL80211_BAND_S1GHZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) local->scan_chandef.width = ieee80211_s1g_channel_width(chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) goto set_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) switch (scan_req->scan_width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) case NL80211_BSS_CHAN_WIDTH_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) local->scan_chandef.width = NL80211_CHAN_WIDTH_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) case NL80211_BSS_CHAN_WIDTH_10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) local->scan_chandef.width = NL80211_CHAN_WIDTH_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) case NL80211_BSS_CHAN_WIDTH_20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) /* If scanning on oper channel, use whatever channel-type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) * is currently in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) oper_scan_width = cfg80211_chandef_to_scan_width(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) &local->_oper_chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (chan == local->_oper_chandef.chan &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) oper_scan_width == scan_req->scan_width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) local->scan_chandef = local->_oper_chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) local->scan_chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) case NL80211_BSS_CHAN_WIDTH_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) case NL80211_BSS_CHAN_WIDTH_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) /* shouldn't get here, S1G handled above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) set_channel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) skip = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) /* advance state machine to next channel/band */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) local->scan_channel_idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (skip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) /* if we skip this channel return to the decision state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) local->next_scan_state = SCAN_DECISION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) * Probe delay is used to update the NAV, cf. 11.1.3.2.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) * (which unfortunately doesn't say _why_ step a) is done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) * but it waits for the probe delay or until a frame is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) * received - and the received frame would update the NAV).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) * For now, we do not support waiting until a frame is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) * received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) * In any case, it is not necessary for a passive scan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) if ((chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) !scan_req->n_ssids) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) *next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) local->next_scan_state = SCAN_DECISION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) /* active scan, send probes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) *next_delay = IEEE80211_PROBE_DELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) local->next_scan_state = SCAN_SEND_PROBE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) static void ieee80211_scan_state_suspend(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) unsigned long *next_delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) /* switch back to the operating channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) local->scan_chandef.chan = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) /* disable PS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) ieee80211_offchannel_return(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) *next_delay = HZ / 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) /* afterwards, resume scan & go to next channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) local->next_scan_state = SCAN_RESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) static void ieee80211_scan_state_resume(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) unsigned long *next_delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) ieee80211_offchannel_stop_vifs(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) if (local->ops->flush) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) ieee80211_flush_queues(local, NULL, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) *next_delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) *next_delay = HZ / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) /* remember when we left the operating channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) local->leave_oper_channel_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) /* advance to the next channel to be scanned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) local->next_scan_state = SCAN_SET_CHANNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) void ieee80211_scan_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) struct ieee80211_local *local =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) container_of(work, struct ieee80211_local, scan_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) struct cfg80211_scan_request *scan_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) unsigned long next_delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) bool aborted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (!ieee80211_can_run_worker(local)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) goto out_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) sdata = rcu_dereference_protected(local->scan_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) scan_req = rcu_dereference_protected(local->scan_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) /* When scanning on-channel, the first-callback means completed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) if (test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) aborted = test_and_clear_bit(SCAN_ABORTED, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) goto out_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (test_and_clear_bit(SCAN_COMPLETED, &local->scanning)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) aborted = test_and_clear_bit(SCAN_ABORTED, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) goto out_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) if (!sdata || !scan_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) if (!local->scanning) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) RCU_INIT_POINTER(local->scan_req, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) RCU_INIT_POINTER(local->scan_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) rc = __ieee80211_start_scan(sdata, scan_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) /* need to complete scan in cfg80211 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) rcu_assign_pointer(local->scan_req, scan_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) goto out_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) * as long as no delay is required advance immediately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) * without scheduling a new work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (!ieee80211_sdata_running(sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) goto out_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) switch (local->next_scan_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) case SCAN_DECISION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) /* if no more bands/channels left, complete scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (local->scan_channel_idx >= scan_req->n_channels) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) aborted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) goto out_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) ieee80211_scan_state_decision(local, &next_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) case SCAN_SET_CHANNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) ieee80211_scan_state_set_channel(local, &next_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) case SCAN_SEND_PROBE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) ieee80211_scan_state_send_probe(local, &next_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) case SCAN_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) ieee80211_scan_state_suspend(local, &next_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) case SCAN_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) ieee80211_scan_state_resume(local, &next_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) case SCAN_ABORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) goto out_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) } while (next_delay == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) ieee80211_queue_delayed_work(&local->hw, &local->scan_work, next_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) out_complete:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) __ieee80211_scan_completed(&local->hw, aborted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) struct cfg80211_scan_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) mutex_lock(&sdata->local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) res = __ieee80211_start_scan(sdata, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) mutex_unlock(&sdata->local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) const u8 *ssid, u8 ssid_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) struct ieee80211_channel **channels,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) unsigned int n_channels,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) enum nl80211_bss_scan_width scan_width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) int ret = -EBUSY, i, n_ch = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) enum nl80211_band band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) /* busy scanning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) if (local->scan_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) /* fill internal scan request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) if (!channels) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) int max_n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) for (band = 0; band < NUM_NL80211_BANDS; band++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) if (!local->hw.wiphy->bands[band] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) band == NL80211_BAND_6GHZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) max_n = local->hw.wiphy->bands[band]->n_channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) for (i = 0; i < max_n; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) struct ieee80211_channel *tmp_ch =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) &local->hw.wiphy->bands[band]->channels[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) if (tmp_ch->flags & (IEEE80211_CHAN_NO_IR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) IEEE80211_CHAN_DISABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) local->int_scan_req->channels[n_ch] = tmp_ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) n_ch++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) if (WARN_ON_ONCE(n_ch == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) local->int_scan_req->n_channels = n_ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) for (i = 0; i < n_channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) if (channels[i]->flags & (IEEE80211_CHAN_NO_IR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) IEEE80211_CHAN_DISABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) local->int_scan_req->channels[n_ch] = channels[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) n_ch++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) if (WARN_ON_ONCE(n_ch == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) local->int_scan_req->n_channels = n_ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) local->int_scan_req->ssids = &local->scan_ssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) local->int_scan_req->n_ssids = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) local->int_scan_req->scan_width = scan_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) memcpy(local->int_scan_req->ssids[0].ssid, ssid, IEEE80211_MAX_SSID_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) local->int_scan_req->ssids[0].ssid_len = ssid_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) ret = __ieee80211_start_scan(sdata, sdata->local->int_scan_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) * Only call this function when a scan can't be queued -- under RTNL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) void ieee80211_scan_cancel(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) * We are canceling software scan, or deferred scan that was not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) * yet really started (see __ieee80211_start_scan ).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) * Regarding hardware scan:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) * - we can not call __ieee80211_scan_completed() as when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) * SCAN_HW_SCANNING bit is set this function change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) * local->hw_scan_req to operate on 5G band, what race with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) * driver which can use local->hw_scan_req
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) * - we can not cancel scan_work since driver can schedule it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) * by ieee80211_scan_completed(..., true) to finish scan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) * Hence we only call the cancel_hw_scan() callback, but the low-level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) * driver is still responsible for calling ieee80211_scan_completed()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) * after the scan was completed/aborted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) if (!local->scan_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) * We have a scan running and the driver already reported completion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) * but the worker hasn't run yet or is stuck on the mutex - mark it as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) * cancelled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) if (test_bit(SCAN_HW_SCANNING, &local->scanning) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) test_bit(SCAN_COMPLETED, &local->scanning)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) set_bit(SCAN_HW_CANCELLED, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) if (test_bit(SCAN_HW_SCANNING, &local->scanning)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) * Make sure that __ieee80211_scan_completed doesn't trigger a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) * scan on another band.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) set_bit(SCAN_HW_CANCELLED, &local->scanning);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) if (local->ops->cancel_hw_scan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) drv_cancel_hw_scan(local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) rcu_dereference_protected(local->scan_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) lockdep_is_held(&local->mtx)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) * If the work is currently running, it must be blocked on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) * the mutex, but we'll set scan_sdata = NULL and it'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) * simply exit once it acquires the mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) cancel_delayed_work(&local->scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) /* and clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) memset(&local->scan_info, 0, sizeof(local->scan_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) __ieee80211_scan_completed(&local->hw, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) int __ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) struct cfg80211_sched_scan_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) struct ieee80211_scan_ies sched_scan_ies = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) struct cfg80211_chan_def chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) int ret, i, iebufsz, num_bands = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) u32 rate_masks[NUM_NL80211_BANDS] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) u8 bands_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) u8 *ie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) u32 flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) iebufsz = local->scan_ies_len + req->ie_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) if (!local->ops->sched_scan_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) for (i = 0; i < NUM_NL80211_BANDS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) if (local->hw.wiphy->bands[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) bands_used |= BIT(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) rate_masks[i] = (u32) -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) num_bands++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) if (req->flags & NL80211_SCAN_FLAG_MIN_PREQ_CONTENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) flags |= IEEE80211_PROBE_FLAG_MIN_CONTENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) ie = kcalloc(iebufsz, num_bands, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) if (!ie) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) ieee80211_prepare_scan_chandef(&chandef, req->scan_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) ieee80211_build_preq_ies(sdata, ie, num_bands * iebufsz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) &sched_scan_ies, req->ie,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) req->ie_len, bands_used, rate_masks, &chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) ret = drv_sched_scan_start(local, sdata, req, &sched_scan_ies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) rcu_assign_pointer(local->sched_scan_sdata, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) rcu_assign_pointer(local->sched_scan_req, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) kfree(ie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) /* Clean in case of failure after HW restart or upon resume. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) RCU_INIT_POINTER(local->sched_scan_req, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) struct cfg80211_sched_scan_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) if (rcu_access_pointer(local->sched_scan_sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) ret = __ieee80211_request_sched_scan_start(sdata, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) int ieee80211_request_sched_scan_stop(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) struct ieee80211_sub_if_data *sched_scan_sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) int ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) if (!local->ops->sched_scan_stop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) ret = -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) /* We don't want to restart sched scan anymore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) RCU_INIT_POINTER(local->sched_scan_req, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) sched_scan_sdata = rcu_dereference_protected(local->sched_scan_sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) lockdep_is_held(&local->mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) if (sched_scan_sdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) ret = drv_sched_scan_stop(local, sched_scan_sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) void ieee80211_sched_scan_results(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) trace_api_sched_scan_results(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) cfg80211_sched_scan_results(hw->wiphy, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) EXPORT_SYMBOL(ieee80211_sched_scan_results);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) void ieee80211_sched_scan_end(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) mutex_lock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) if (!rcu_access_pointer(local->sched_scan_sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) /* If sched scan was aborted by the driver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) RCU_INIT_POINTER(local->sched_scan_req, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) mutex_unlock(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) cfg80211_sched_scan_stopped(local->hw.wiphy, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) void ieee80211_sched_scan_stopped_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) struct ieee80211_local *local =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) container_of(work, struct ieee80211_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) sched_scan_stopped_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) ieee80211_sched_scan_end(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) void ieee80211_sched_scan_stopped(struct ieee80211_hw *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) trace_api_sched_scan_stopped(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) * this shouldn't really happen, so for simplicity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) * simply ignore it, and let mac80211 reconfigure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) * the sched scan later on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) if (local->in_reconfig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) schedule_work(&local->sched_scan_stopped_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) EXPORT_SYMBOL(ieee80211_sched_scan_stopped);