blob: 977f8eb0a67bcce09f8aefdcbecdff32f807f5af [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Johannes Berg0a51b272008-09-08 17:44:25 +02002/*
Johannes Berg5484e232008-09-08 17:44:27 +02003 * Scanning implementation
4 *
Johannes Berg0a51b272008-09-08 17:44:25 +02005 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
6 * Copyright 2004, Instant802 Networks, Inc.
7 * Copyright 2005, Devicescape Software, Inc.
8 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
9 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
Sara Sharon74d803b2015-06-03 10:44:17 +030010 * Copyright 2013-2015 Intel Mobile Communications GmbH
Roee Zamir40b0bd22017-08-06 11:38:23 +030011 * Copyright 2016-2017 Intel Deutschland GmbH
Johannes Berg62a61832024-01-29 20:09:07 +010012 * Copyright (C) 2018-2024 Intel Corporation
Johannes Berg0a51b272008-09-08 17:44:25 +020013 */
14
Johannes Berg0a51b272008-09-08 17:44:25 +020015#include <linux/if_arp.h>
Felix Fietkau888d04d2012-03-01 15:22:09 +010016#include <linux/etherdevice.h>
Johannes Berg078e1e62009-01-22 18:07:31 +010017#include <linux/rtnetlink.h>
Helmut Schaadf13cce2010-02-24 14:19:21 +010018#include <net/sch_generic.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040020#include <linux/export.h>
Johannes Bergb9771d42018-05-28 15:47:41 +020021#include <linux/random.h>
Johannes Berg0a51b272008-09-08 17:44:25 +020022#include <net/mac80211.h>
Johannes Berg0a51b272008-09-08 17:44:25 +020023
24#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020025#include "driver-ops.h"
Johannes Berg5484e232008-09-08 17:44:27 +020026#include "mesh.h"
Johannes Berg0a51b272008-09-08 17:44:25 +020027
28#define IEEE80211_PROBE_DELAY (HZ / 33)
29#define IEEE80211_CHANNEL_TIME (HZ / 33)
Stanislaw Gruszka3f892b62013-01-23 12:32:45 +010030#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 9)
Johannes Berg0a51b272008-09-08 17:44:25 +020031
Johannes Berg5484e232008-09-08 17:44:27 +020032void ieee80211_rx_bss_put(struct ieee80211_local *local,
Johannes Bergc2b13452008-09-11 00:01:55 +020033 struct ieee80211_bss *bss)
Johannes Berg5484e232008-09-08 17:44:27 +020034{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +010035 if (!bss)
36 return;
Johannes Berg5b112d32013-02-01 01:49:58 +010037 cfg80211_put_bss(local->hw.wiphy,
38 container_of((void *)bss, struct cfg80211_bss, priv));
Johannes Berg5484e232008-09-08 17:44:27 +020039}
40
Kalle Valoab133152010-01-12 10:42:31 +020041static bool is_uapsd_supported(struct ieee802_11_elems *elems)
42{
43 u8 qos_info;
44
45 if (elems->wmm_info && elems->wmm_info_len == 7
46 && elems->wmm_info[5] == 1)
47 qos_info = elems->wmm_info[6];
48 else if (elems->wmm_param && elems->wmm_param_len == 24
49 && elems->wmm_param[5] == 1)
50 qos_info = elems->wmm_param[6];
51 else
52 /* no valid wmm information or parameter element found */
53 return false;
54
55 return qos_info & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD;
56}
57
Benjamin Berg108d20222023-06-16 09:54:01 +030058struct inform_bss_update_data {
59 struct ieee80211_rx_status *rx_status;
60 bool beacon;
61};
62
63void ieee80211_inform_bss(struct wiphy *wiphy,
64 struct cfg80211_bss *cbss,
65 const struct cfg80211_bss_ies *ies,
66 void *data)
Sara Sharonfcea7db2019-01-16 20:35:38 +020067{
Benjamin Berg108d20222023-06-16 09:54:01 +030068 struct ieee80211_local *local = wiphy_priv(wiphy);
69 struct inform_bss_update_data *update_data = data;
70 struct ieee80211_bss *bss = (void *)cbss->priv;
71 struct ieee80211_rx_status *rx_status;
72 struct ieee802_11_elems *elems;
Sara Sharonfcea7db2019-01-16 20:35:38 +020073 int clen, srlen;
74
Benjamin Berg108d20222023-06-16 09:54:01 +030075 /* This happens while joining an IBSS */
76 if (!update_data)
77 return;
78
79 elems = ieee802_11_parse_elems(ies->data, ies->len, false, NULL);
80 if (!elems)
81 return;
82
83 rx_status = update_data->rx_status;
84
85 if (update_data->beacon)
Sara Sharonfcea7db2019-01-16 20:35:38 +020086 bss->device_ts_beacon = rx_status->device_timestamp;
87 else
88 bss->device_ts_presp = rx_status->device_timestamp;
89
90 if (elems->parse_error) {
Benjamin Berg108d20222023-06-16 09:54:01 +030091 if (update_data->beacon)
Sara Sharonfcea7db2019-01-16 20:35:38 +020092 bss->corrupt_data |= IEEE80211_BSS_CORRUPT_BEACON;
93 else
94 bss->corrupt_data |= IEEE80211_BSS_CORRUPT_PROBE_RESP;
95 } else {
Benjamin Berg108d20222023-06-16 09:54:01 +030096 if (update_data->beacon)
Sara Sharonfcea7db2019-01-16 20:35:38 +020097 bss->corrupt_data &= ~IEEE80211_BSS_CORRUPT_BEACON;
98 else
99 bss->corrupt_data &= ~IEEE80211_BSS_CORRUPT_PROBE_RESP;
100 }
101
102 /* save the ERP value so that it is available at association time */
103 if (elems->erp_info && (!elems->parse_error ||
104 !(bss->valid_data & IEEE80211_BSS_VALID_ERP))) {
105 bss->erp_value = elems->erp_info[0];
106 bss->has_erp_value = true;
107 if (!elems->parse_error)
108 bss->valid_data |= IEEE80211_BSS_VALID_ERP;
109 }
110
111 /* replace old supported rates if we get new values */
112 if (!elems->parse_error ||
113 !(bss->valid_data & IEEE80211_BSS_VALID_RATES)) {
114 srlen = 0;
115 if (elems->supp_rates) {
116 clen = IEEE80211_MAX_SUPP_RATES;
117 if (clen > elems->supp_rates_len)
118 clen = elems->supp_rates_len;
119 memcpy(bss->supp_rates, elems->supp_rates, clen);
120 srlen += clen;
121 }
122 if (elems->ext_supp_rates) {
123 clen = IEEE80211_MAX_SUPP_RATES - srlen;
124 if (clen > elems->ext_supp_rates_len)
125 clen = elems->ext_supp_rates_len;
126 memcpy(bss->supp_rates + srlen, elems->ext_supp_rates,
127 clen);
128 srlen += clen;
129 }
130 if (srlen) {
131 bss->supp_rates_len = srlen;
132 if (!elems->parse_error)
133 bss->valid_data |= IEEE80211_BSS_VALID_RATES;
134 }
135 }
136
137 if (!elems->parse_error ||
138 !(bss->valid_data & IEEE80211_BSS_VALID_WMM)) {
139 bss->wmm_used = elems->wmm_param || elems->wmm_info;
140 bss->uapsd_supported = is_uapsd_supported(elems);
141 if (!elems->parse_error)
142 bss->valid_data |= IEEE80211_BSS_VALID_WMM;
143 }
144
Benjamin Berg108d20222023-06-16 09:54:01 +0300145 if (update_data->beacon) {
Sara Sharonfcea7db2019-01-16 20:35:38 +0200146 struct ieee80211_supported_band *sband =
147 local->hw.wiphy->bands[rx_status->band];
148 if (!(rx_status->encoding == RX_ENC_HT) &&
149 !(rx_status->encoding == RX_ENC_VHT))
150 bss->beacon_rate =
151 &sband->bitrates[rx_status->rate_idx];
152 }
Johannes Berg2a333a02020-05-28 21:34:35 +0200153
154 if (elems->vht_cap_elem)
155 bss->vht_cap_info =
156 le32_to_cpu(elems->vht_cap_elem->vht_cap_info);
157 else
158 bss->vht_cap_info = 0;
Benjamin Berg108d20222023-06-16 09:54:01 +0300159
160 kfree(elems);
Sara Sharonfcea7db2019-01-16 20:35:38 +0200161}
162
Johannes Bergc2b13452008-09-11 00:01:55 +0200163struct ieee80211_bss *
Johannes Berg5484e232008-09-08 17:44:27 +0200164ieee80211_bss_info_update(struct ieee80211_local *local,
165 struct ieee80211_rx_status *rx_status,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +0200166 struct ieee80211_mgmt *mgmt, size_t len,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +0200167 struct ieee80211_channel *channel)
Johannes Berg5484e232008-09-08 17:44:27 +0200168{
Thomas Pedersencd418ba2020-09-21 19:28:08 -0700169 bool beacon = ieee80211_is_beacon(mgmt->frame_control) ||
170 ieee80211_is_s1g_beacon(mgmt->frame_control);
Benjamin Berg108d20222023-06-16 09:54:01 +0300171 struct cfg80211_bss *cbss;
172 struct inform_bss_update_data update_data = {
173 .rx_status = rx_status,
174 .beacon = beacon,
175 };
Johannes Berg162dd6a2016-02-23 23:05:06 +0200176 struct cfg80211_inform_bss bss_meta = {
177 .boottime_ns = rx_status->boottime_ns,
Benjamin Berg108d20222023-06-16 09:54:01 +0300178 .drv_data = (void *)&update_data,
Johannes Berg162dd6a2016-02-23 23:05:06 +0200179 };
Sara Sharon74d803b2015-06-03 10:44:17 +0300180 bool signal_valid;
Avraham Stern7947d3e2016-07-05 15:23:12 +0300181 struct ieee80211_sub_if_data *scan_sdata;
Johannes Berg2a519312009-02-10 21:25:55 +0100182
Tosoni1ad22fb2018-03-14 16:58:34 +0000183 if (rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)
184 bss_meta.signal = 0; /* invalid signal indication */
185 else if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
Johannes Berg61f6bba2015-10-13 11:36:21 +0200186 bss_meta.signal = rx_status->signal * 100;
Johannes Berg30686bf2015-06-02 21:39:54 +0200187 else if (ieee80211_hw_check(&local->hw, SIGNAL_UNSPEC))
Johannes Berg61f6bba2015-10-13 11:36:21 +0200188 bss_meta.signal = (rx_status->signal * 100) / local->hw.max_signal;
Johannes Berg2a519312009-02-10 21:25:55 +0100189
Johannes Berg61f6bba2015-10-13 11:36:21 +0200190 bss_meta.chan = channel;
Avraham Stern7947d3e2016-07-05 15:23:12 +0300191
192 rcu_read_lock();
193 scan_sdata = rcu_dereference(local->scan_sdata);
194 if (scan_sdata && scan_sdata->vif.type == NL80211_IFTYPE_STATION &&
Johannes Bergf276e202022-05-10 17:05:04 +0200195 scan_sdata->vif.cfg.assoc &&
Avraham Stern7947d3e2016-07-05 15:23:12 +0300196 ieee80211_have_rx_timestamp(rx_status)) {
Ilan Peercbde0b42023-11-13 11:35:01 +0200197 struct ieee80211_bss_conf *link_conf = NULL;
198
199 /* for an MLO connection, set the TSF data only in case we have
200 * an indication on which of the links the frame was received
201 */
202 if (ieee80211_vif_is_mld(&scan_sdata->vif)) {
203 if (rx_status->link_valid) {
204 s8 link_id = rx_status->link_id;
205
206 link_conf =
207 rcu_dereference(scan_sdata->vif.link_conf[link_id]);
208 }
209 } else {
210 link_conf = &scan_sdata->vif.bss_conf;
211 }
212
213 if (link_conf) {
214 bss_meta.parent_tsf =
215 ieee80211_calculate_rx_timestamp(local,
216 rx_status,
217 len + FCS_LEN,
218 24);
219
220 ether_addr_copy(bss_meta.parent_bssid,
221 link_conf->bssid);
222 }
Avraham Stern7947d3e2016-07-05 15:23:12 +0300223 }
224 rcu_read_unlock();
225
Johannes Berg61f6bba2015-10-13 11:36:21 +0200226 cbss = cfg80211_inform_bss_frame_data(local->hw.wiphy, &bss_meta,
227 mgmt, len, GFP_ATOMIC);
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100228 if (!cbss)
Johannes Berg00d3f142009-02-10 21:26:00 +0100229 return NULL;
Sara Sharon4abb52a2019-01-16 12:14:41 +0200230
Sara Sharon74d803b2015-06-03 10:44:17 +0300231 /* In case the signal is invalid update the status */
Emmanuel Grumbach7bb106e2020-02-14 23:23:38 +0100232 signal_valid = channel == cbss->channel;
Sara Sharon74d803b2015-06-03 10:44:17 +0300233 if (!signal_valid)
234 rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
Johannes Berg00d3f142009-02-10 21:26:00 +0100235
Benjamin Berg108d20222023-06-16 09:54:01 +0300236 return (void *)cbss->priv;
Johannes Berg5484e232008-09-08 17:44:27 +0200237}
Johannes Berg0a51b272008-09-08 17:44:25 +0200238
Roee Zamir40b0bd22017-08-06 11:38:23 +0300239static bool ieee80211_scan_accept_presp(struct ieee80211_sub_if_data *sdata,
Johannes Berg62a61832024-01-29 20:09:07 +0100240 struct ieee80211_channel *channel,
Roee Zamir40b0bd22017-08-06 11:38:23 +0300241 u32 scan_flags, const u8 *da)
242{
243 if (!sdata)
244 return false;
Johannes Berg62a61832024-01-29 20:09:07 +0100245
246 /* accept broadcast on 6 GHz and for OCE */
247 if (is_broadcast_ether_addr(da) &&
248 (channel->band == NL80211_BAND_6GHZ ||
249 scan_flags & NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP))
Roee Zamir40b0bd22017-08-06 11:38:23 +0300250 return true;
Johannes Berg62a61832024-01-29 20:09:07 +0100251
Roee Zamir40b0bd22017-08-06 11:38:23 +0300252 if (scan_flags & NL80211_SCAN_FLAG_RANDOM_ADDR)
253 return true;
254 return ether_addr_equal(da, sdata->vif.addr);
255}
256
Johannes Bergd48b2962012-07-06 22:19:27 +0200257void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb)
Johannes Berg98c8fcc2008-09-08 17:44:26 +0200258{
Johannes Bergf1d58c22009-06-17 13:13:00 +0200259 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
Johannes Bergd48b2962012-07-06 22:19:27 +0200260 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Johannes Bergc2b13452008-09-11 00:01:55 +0200261 struct ieee80211_bss *bss;
Johannes Berg98c8fcc2008-09-08 17:44:26 +0200262 struct ieee80211_channel *channel;
Du Chenge298aa32021-05-10 12:16:49 +0800263 size_t min_hdr_len = offsetof(struct ieee80211_mgmt,
264 u.probe_resp.variable);
265
266 if (!ieee80211_is_probe_resp(mgmt->frame_control) &&
267 !ieee80211_is_beacon(mgmt->frame_control) &&
268 !ieee80211_is_s1g_beacon(mgmt->frame_control))
269 return;
Johannes Berg98c8fcc2008-09-08 17:44:26 +0200270
Thomas Pedersencd418ba2020-09-21 19:28:08 -0700271 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
Du Chenge298aa32021-05-10 12:16:49 +0800272 if (ieee80211_is_s1g_short_beacon(mgmt->frame_control))
273 min_hdr_len = offsetof(struct ieee80211_ext,
274 u.s1g_short_beacon.variable);
275 else
276 min_hdr_len = offsetof(struct ieee80211_ext,
277 u.s1g_beacon);
278 }
279
280 if (skb->len < min_hdr_len)
Johannes Bergd48b2962012-07-06 22:19:27 +0200281 return;
Johannes Berg98c8fcc2008-09-08 17:44:26 +0200282
Felix Fietkaub041b7b2022-04-20 12:49:07 +0200283 if (test_and_clear_bit(SCAN_BEACON_WAIT, &local->scanning)) {
284 /*
285 * we were passive scanning because of radar/no-IR, but
286 * the beacon/proberesp rx gives us an opportunity to upgrade
287 * to active scan
288 */
Johannes Berg20171252023-08-28 13:59:39 +0200289 set_bit(SCAN_BEACON_DONE, &local->scanning);
290 wiphy_delayed_work_queue(local->hw.wiphy, &local->scan_work, 0);
Felix Fietkaub041b7b2022-04-20 12:49:07 +0200291 }
292
Johannes Berg62a61832024-01-29 20:09:07 +0100293 channel = ieee80211_get_channel_khz(local->hw.wiphy,
294 ieee80211_rx_status_to_khz(rx_status));
295
296 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
297 return;
298
Johannes Bergd48b2962012-07-06 22:19:27 +0200299 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
Ilan Peerddf82e72024-02-28 09:47:39 +0100300 struct ieee80211_sub_if_data *sdata1, *sdata2;
Johannes Berga344d672014-06-12 22:24:31 +0200301 struct cfg80211_scan_request *scan_req;
302 struct cfg80211_sched_scan_request *sched_scan_req;
Roee Zamir40b0bd22017-08-06 11:38:23 +0300303 u32 scan_req_flags = 0, sched_scan_req_flags = 0;
Johannes Berga344d672014-06-12 22:24:31 +0200304
Ilan Peerddf82e72024-02-28 09:47:39 +0100305 sdata1 = rcu_dereference(local->scan_sdata);
306 sdata2 = rcu_dereference(local->sched_scan_sdata);
307
308 if (likely(!sdata1 && !sdata2))
309 return;
310
Johannes Berga344d672014-06-12 22:24:31 +0200311 scan_req = rcu_dereference(local->scan_req);
312 sched_scan_req = rcu_dereference(local->sched_scan_req);
313
Roee Zamir40b0bd22017-08-06 11:38:23 +0300314 if (scan_req)
315 scan_req_flags = scan_req->flags;
316
317 if (sched_scan_req)
318 sched_scan_req_flags = sched_scan_req->flags;
319
320 /* ignore ProbeResp to foreign address or non-bcast (OCE)
321 * unless scanning with randomised address
Johannes Berga344d672014-06-12 22:24:31 +0200322 */
Johannes Berg62a61832024-01-29 20:09:07 +0100323 if (!ieee80211_scan_accept_presp(sdata1, channel,
324 scan_req_flags,
Roee Zamir40b0bd22017-08-06 11:38:23 +0300325 mgmt->da) &&
Johannes Berg62a61832024-01-29 20:09:07 +0100326 !ieee80211_scan_accept_presp(sdata2, channel,
327 sched_scan_req_flags,
Roee Zamir40b0bd22017-08-06 11:38:23 +0300328 mgmt->da))
Johannes Bergd48b2962012-07-06 22:19:27 +0200329 return;
Ilan Peerddf82e72024-02-28 09:47:39 +0100330 } else {
331 /* Beacons are expected only with broadcast address */
332 if (!is_broadcast_ether_addr(mgmt->da))
333 return;
Johannes Berg98c8fcc2008-09-08 17:44:26 +0200334 }
335
Ilan Peerddf82e72024-02-28 09:47:39 +0100336 /* Do not update the BSS table in case of only monitor interfaces */
337 if (local->open_count == local->monitors)
338 return;
339
Johannes Bergd48b2962012-07-06 22:19:27 +0200340 bss = ieee80211_bss_info_update(local, rx_status,
Sara Sharon4abb52a2019-01-16 12:14:41 +0200341 mgmt, skb->len,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +0200342 channel);
Jouni Malinend048e502008-10-11 03:29:55 +0300343 if (bss)
Johannes Bergd48b2962012-07-06 22:19:27 +0200344 ieee80211_rx_bss_put(local, bss);
Johannes Berg98c8fcc2008-09-08 17:44:26 +0200345}
346
Johannes Berg5add3212023-08-29 12:17:43 +0200347static void ieee80211_prepare_scan_chandef(struct cfg80211_chan_def *chandef)
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200348{
349 memset(chandef, 0, sizeof(*chandef));
Johannes Berg5add3212023-08-29 12:17:43 +0200350
351 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200352}
353
Johannes Berg4d36ec52009-10-27 20:59:55 +0100354/* return false if no more work */
Ilan Peer2ad22742020-05-28 21:34:39 +0200355static bool ieee80211_prep_hw_scan(struct ieee80211_sub_if_data *sdata)
Johannes Berg4d36ec52009-10-27 20:59:55 +0100356{
Ilan Peer2ad22742020-05-28 21:34:39 +0200357 struct ieee80211_local *local = sdata->local;
Johannes Berg6ea0a692014-11-19 11:55:49 +0100358 struct cfg80211_scan_request *req;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200359 struct cfg80211_chan_def chandef;
David Spinadelc56ef672014-02-05 15:21:13 +0200360 u8 bands_used = 0;
Johannes Berg4d36ec52009-10-27 20:59:55 +0100361 int i, ielen, n_chans;
Johannes Bergb9771d42018-05-28 15:47:41 +0200362 u32 flags = 0;
Johannes Berg4d36ec52009-10-27 20:59:55 +0100363
Johannes Berg6ea0a692014-11-19 11:55:49 +0100364 req = rcu_dereference_protected(local->scan_req,
Johannes Berg0cd80802023-08-28 14:00:05 +0200365 lockdep_is_held(&local->hw.wiphy->mtx));
Johannes Berg6ea0a692014-11-19 11:55:49 +0100366
Emmanuel Grumbacha7540552013-09-16 11:12:07 +0300367 if (test_bit(SCAN_HW_CANCELLED, &local->scanning))
368 return false;
369
Johannes Berg30686bf2015-06-02 21:39:54 +0200370 if (ieee80211_hw_check(&local->hw, SINGLE_SCAN_ON_ALL_BANDS)) {
Johannes Berg4d36ec52009-10-27 20:59:55 +0100371 for (i = 0; i < req->n_channels; i++) {
David Spinadelc56ef672014-02-05 15:21:13 +0200372 local->hw_scan_req->req.channels[i] = req->channels[i];
373 bands_used |= BIT(req->channels[i]->band);
Johannes Berg4d36ec52009-10-27 20:59:55 +0100374 }
375
David Spinadelc56ef672014-02-05 15:21:13 +0200376 n_chans = req->n_channels;
377 } else {
378 do {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200379 if (local->hw_scan_band == NUM_NL80211_BANDS)
David Spinadelc56ef672014-02-05 15:21:13 +0200380 return false;
Johannes Berg4d36ec52009-10-27 20:59:55 +0100381
David Spinadelc56ef672014-02-05 15:21:13 +0200382 n_chans = 0;
383
384 for (i = 0; i < req->n_channels; i++) {
385 if (req->channels[i]->band !=
386 local->hw_scan_band)
387 continue;
388 local->hw_scan_req->req.channels[n_chans] =
389 req->channels[i];
390 n_chans++;
391 bands_used |= BIT(req->channels[i]->band);
392 }
393
394 local->hw_scan_band++;
395 } while (!n_chans);
396 }
397
398 local->hw_scan_req->req.n_channels = n_chans;
Johannes Berg5add3212023-08-29 12:17:43 +0200399 ieee80211_prepare_scan_chandef(&chandef);
Johannes Berg4d36ec52009-10-27 20:59:55 +0100400
Johannes Bergb9771d42018-05-28 15:47:41 +0200401 if (req->flags & NL80211_SCAN_FLAG_MIN_PREQ_CONTENT)
402 flags |= IEEE80211_PROBE_FLAG_MIN_CONTENT;
403
Ilan Peer2ad22742020-05-28 21:34:39 +0200404 ielen = ieee80211_build_preq_ies(sdata,
David Spinadelc56ef672014-02-05 15:21:13 +0200405 (u8 *)local->hw_scan_req->req.ie,
Johannes Bergc604b9f2012-11-29 12:45:18 +0100406 local->hw_scan_ies_bufsize,
David Spinadelc56ef672014-02-05 15:21:13 +0200407 &local->hw_scan_req->ies,
408 req->ie, req->ie_len,
Johannes Bergb9771d42018-05-28 15:47:41 +0200409 bands_used, req->rates, &chandef,
410 flags);
Johannes Berg07095d12024-01-29 20:19:33 +0100411 if (ielen < 0)
412 return false;
David Spinadelc56ef672014-02-05 15:21:13 +0200413 local->hw_scan_req->req.ie_len = ielen;
414 local->hw_scan_req->req.no_cck = req->no_cck;
Johannes Berga344d672014-06-12 22:24:31 +0200415 ether_addr_copy(local->hw_scan_req->req.mac_addr, req->mac_addr);
416 ether_addr_copy(local->hw_scan_req->req.mac_addr_mask,
417 req->mac_addr_mask);
Jouni Malinene345f442016-02-26 22:12:48 +0200418 ether_addr_copy(local->hw_scan_req->req.bssid, req->bssid);
Johannes Berg4d36ec52009-10-27 20:59:55 +0100419
420 return true;
421}
422
Eliad Peller8bd2a242013-12-05 11:21:27 +0200423static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
Johannes Berg0a51b272008-09-08 17:44:25 +0200424{
425 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berge9da68d2018-10-18 10:35:47 +0200426 bool hw_scan = test_bit(SCAN_HW_SCANNING, &local->scanning);
Eliad Pellera2b70e82013-12-05 11:21:28 +0200427 bool was_scanning = local->scanning;
Johannes Berg6ea0a692014-11-19 11:55:49 +0100428 struct cfg80211_scan_request *scan_req;
Johannes Berga344d672014-06-12 22:24:31 +0200429 struct ieee80211_sub_if_data *scan_sdata;
Sachin Kulkarni4fa11ec2016-01-12 14:30:19 +0530430 struct ieee80211_sub_if_data *sdata;
Johannes Berg0a51b272008-09-08 17:44:25 +0200431
Johannes Berg0cd80802023-08-28 14:00:05 +0200432 lockdep_assert_wiphy(local->hw.wiphy);
Johannes Bergf3b852522009-04-23 16:01:47 +0200433
Johannes Berg6d3560d2009-10-31 07:44:08 +0100434 /*
435 * It's ok to abort a not-yet-running scan (that
436 * we have one at all will be verified by checking
437 * local->scan_req next), but not to complete it
438 * successfully.
439 */
440 if (WARN_ON(!local->scanning && !aborted))
441 aborted = true;
Johannes Bergde95a54b2009-04-01 11:58:36 +0200442
Stanislaw Gruszkae229f842010-10-06 11:22:09 +0200443 if (WARN_ON(!local->scan_req))
Johannes Bergd07bfd82011-03-07 15:48:41 +0100444 return;
Johannes Bergf3b852522009-04-23 16:01:47 +0200445
Ilan Peer2ad22742020-05-28 21:34:39 +0200446 scan_sdata = rcu_dereference_protected(local->scan_sdata,
Johannes Berg0cd80802023-08-28 14:00:05 +0200447 lockdep_is_held(&local->hw.wiphy->mtx));
Ilan Peer2ad22742020-05-28 21:34:39 +0200448
David Spinadelc56ef672014-02-05 15:21:13 +0200449 if (hw_scan && !aborted &&
Johannes Berg30686bf2015-06-02 21:39:54 +0200450 !ieee80211_hw_check(&local->hw, SINGLE_SCAN_ON_ALL_BANDS) &&
Ilan Peer2ad22742020-05-28 21:34:39 +0200451 ieee80211_prep_hw_scan(scan_sdata)) {
Johannes Berge2fd5db2012-07-06 21:39:28 +0200452 int rc;
453
454 rc = drv_hw_scan(local,
455 rcu_dereference_protected(local->scan_sdata,
Johannes Berg0cd80802023-08-28 14:00:05 +0200456 lockdep_is_held(&local->hw.wiphy->mtx)),
Johannes Berge2fd5db2012-07-06 21:39:28 +0200457 local->hw_scan_req);
458
Stanislaw Gruszka6eb11a92010-10-06 11:22:11 +0200459 if (rc == 0)
Johannes Bergd07bfd82011-03-07 15:48:41 +0100460 return;
Avraham Stern7947d3e2016-07-05 15:23:12 +0300461
Johannes Berg7d10f6b2016-07-05 15:23:13 +0300462 /* HW scan failed and is going to be reported as aborted,
463 * so clear old scan info.
Avraham Stern7947d3e2016-07-05 15:23:12 +0300464 */
465 memset(&local->scan_info, 0, sizeof(local->scan_info));
Johannes Berg7d10f6b2016-07-05 15:23:13 +0300466 aborted = true;
Johannes Berg4d36ec52009-10-27 20:59:55 +0100467 }
468
469 kfree(local->hw_scan_req);
470 local->hw_scan_req = NULL;
Johannes Bergf3b852522009-04-23 16:01:47 +0200471
Johannes Berg6ea0a692014-11-19 11:55:49 +0100472 scan_req = rcu_dereference_protected(local->scan_req,
Johannes Berg0cd80802023-08-28 14:00:05 +0200473 lockdep_is_held(&local->hw.wiphy->mtx));
Johannes Berg6ea0a692014-11-19 11:55:49 +0100474
Johannes Berg6ea0a692014-11-19 11:55:49 +0100475 RCU_INIT_POINTER(local->scan_req, NULL);
Monam Agarwal0c2bef462014-03-24 00:51:43 +0530476 RCU_INIT_POINTER(local->scan_sdata, NULL);
Johannes Berg2a519312009-02-10 21:25:55 +0100477
Helmut Schaafbe9c4292009-07-23 12:14:04 +0200478 local->scanning = 0;
Simon Wunderlich7ca15a02013-07-08 16:55:56 +0200479 local->scan_chandef.chan = NULL;
Johannes Bergf3b852522009-04-23 16:01:47 +0200480
Siddh Raman Pant60deb9f2022-08-20 01:33:40 +0530481 synchronize_rcu();
482
483 if (scan_req != local->int_scan_req) {
484 local->scan_info.aborted = aborted;
485 cfg80211_scan_done(scan_req, &local->scan_info);
486 }
487
Johannes Berg07ef03e2011-11-08 16:21:21 +0100488 /* Set power back to normal operating levels. */
Johannes Berg0a44dfc2024-01-29 19:34:38 +0100489 ieee80211_hw_conf_chan(local);
Ben Greearb23b0252011-02-04 11:54:17 -0800490
Johannes Berga033afc2022-09-02 16:12:55 +0200491 if (!hw_scan && was_scanning) {
Ben Greearb23b0252011-02-04 11:54:17 -0800492 ieee80211_configure_filter(local);
Johannes Berga344d672014-06-12 22:24:31 +0200493 drv_sw_scan_complete(local, scan_sdata);
Stanislaw Gruszkaaacde9e2012-12-20 14:41:18 +0100494 ieee80211_offchannel_return(local);
Ben Greearb23b0252011-02-04 11:54:17 -0800495 }
496
Johannes Berg5cff20e2009-04-29 12:26:17 +0200497 ieee80211_recalc_idle(local);
Stanislaw Gruszkae229f842010-10-06 11:22:09 +0200498
Johannes Berg0a51b272008-09-08 17:44:25 +0200499 ieee80211_mlme_notify_scan_completed(local);
Johannes Berg46900292009-02-15 12:44:28 +0100500 ieee80211_ibss_notify_scan_completed(local);
Sachin Kulkarni4fa11ec2016-01-12 14:30:19 +0530501
502 /* Requeue all the work that might have been ignored while
503 * the scan was in progress; if there was none this will
504 * just be a no-op for the particular interface.
505 */
506 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
507 if (ieee80211_sdata_running(sdata))
Johannes Berg16114492023-06-06 14:49:26 +0200508 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
Sachin Kulkarni4fa11ec2016-01-12 14:30:19 +0530509 }
510
Eliad Pellera2b70e82013-12-05 11:21:28 +0200511 if (was_scanning)
512 ieee80211_start_next_roc(local);
Johannes Berg0a51b272008-09-08 17:44:25 +0200513}
Johannes Berg8789d452010-08-26 13:30:26 +0200514
Avraham Stern7947d3e2016-07-05 15:23:12 +0300515void ieee80211_scan_completed(struct ieee80211_hw *hw,
516 struct cfg80211_scan_info *info)
Johannes Berg8789d452010-08-26 13:30:26 +0200517{
518 struct ieee80211_local *local = hw_to_local(hw);
519
Johannes Berg58bd7f12016-09-14 09:37:54 +0200520 trace_api_scan_completed(local, info->aborted);
Johannes Berg8789d452010-08-26 13:30:26 +0200521
522 set_bit(SCAN_COMPLETED, &local->scanning);
Avraham Stern7947d3e2016-07-05 15:23:12 +0300523 if (info->aborted)
Johannes Berg8789d452010-08-26 13:30:26 +0200524 set_bit(SCAN_ABORTED, &local->scanning);
Avraham Stern7947d3e2016-07-05 15:23:12 +0300525
526 memcpy(&local->scan_info, info, sizeof(*info));
527
Johannes Berg20171252023-08-28 13:59:39 +0200528 wiphy_delayed_work_queue(local->hw.wiphy, &local->scan_work, 0);
Johannes Berg8789d452010-08-26 13:30:26 +0200529}
Johannes Berg0a51b272008-09-08 17:44:25 +0200530EXPORT_SYMBOL(ieee80211_scan_completed);
531
Johannes Berga344d672014-06-12 22:24:31 +0200532static int ieee80211_start_sw_scan(struct ieee80211_local *local,
533 struct ieee80211_sub_if_data *sdata)
Johannes Bergf3b852522009-04-23 16:01:47 +0200534{
Johannes Bergfe57d9f2012-07-26 14:55:08 +0200535 /* Software scan is not supported in multi-channel cases */
Johannes Berg0a44dfc2024-01-29 19:34:38 +0100536 if (!local->emulate_chanctx)
Johannes Bergfe57d9f2012-07-26 14:55:08 +0200537 return -EOPNOTSUPP;
538
Johannes Bergf3b852522009-04-23 16:01:47 +0200539 /*
540 * Hardware/driver doesn't support hw_scan, so use software
541 * scanning instead. First send a nullfunc frame with power save
542 * bit on so that AP will buffer the frames for us while we are not
543 * listening, then send probe requests to each channel and wait for
544 * the responses. After all channels are scanned, tune back to the
545 * original channel and send a nullfunc frame with power save bit
546 * off to trigger the AP to send us all the buffered frames.
547 *
548 * Note that while local->sw_scanning is true everything else but
549 * nullfunc frames and probe requests will be dropped in
550 * ieee80211_tx_h_check_assoc().
551 */
Johannes Berga344d672014-06-12 22:24:31 +0200552 drv_sw_scan_start(local, sdata, local->scan_addr);
Johannes Bergf3b852522009-04-23 16:01:47 +0200553
Rajkumar Manoharande312db2012-03-27 11:01:06 +0530554 local->leave_oper_channel_time = jiffies;
Helmut Schaa977923b2009-07-23 12:14:20 +0200555 local->next_scan_state = SCAN_DECISION;
Johannes Bergf3b852522009-04-23 16:01:47 +0200556 local->scan_channel_idx = 0;
557
Stanislaw Gruszkaaacde9e2012-12-20 14:41:18 +0100558 ieee80211_offchannel_stop_vifs(local);
Johannes Berga80f7c02009-12-23 13:15:32 +0100559
Seth Forshee9c35d7d2013-02-11 11:21:08 -0600560 /* ensure nullfunc is transmitted before leaving operating channel */
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +0200561 ieee80211_flush_queues(local, NULL, false);
Seth Forshee9c35d7d2013-02-11 11:21:08 -0600562
Johannes Berg3ac64be2009-08-17 16:16:53 +0200563 ieee80211_configure_filter(local);
Johannes Bergf3b852522009-04-23 16:01:47 +0200564
Ben Greear59bdf3b2011-02-07 13:44:38 -0800565 /* We need to set power level at maximum rate for scanning. */
Johannes Berg0a44dfc2024-01-29 19:34:38 +0100566 ieee80211_hw_conf_chan(local);
Ben Greear59bdf3b2011-02-07 13:44:38 -0800567
Johannes Berg20171252023-08-28 13:59:39 +0200568 wiphy_delayed_work_queue(local->hw.wiphy, &local->scan_work, 0);
Johannes Bergf3b852522009-04-23 16:01:47 +0200569
570 return 0;
571}
572
Aaron Komisardc0c18e2019-10-02 13:59:07 +0000573static bool __ieee80211_can_leave_ch(struct ieee80211_sub_if_data *sdata)
574{
575 struct ieee80211_local *local = sdata->local;
576 struct ieee80211_sub_if_data *sdata_iter;
577
Johannes Bergbe0df012023-08-28 14:00:06 +0200578 lockdep_assert_wiphy(local->hw.wiphy);
579
Aaron Komisardc0c18e2019-10-02 13:59:07 +0000580 if (!ieee80211_is_radar_required(local))
581 return true;
582
583 if (!regulatory_pre_cac_allowed(local->hw.wiphy))
584 return false;
585
Aaron Komisardc0c18e2019-10-02 13:59:07 +0000586 list_for_each_entry(sdata_iter, &local->interfaces, list) {
Johannes Bergbe0df012023-08-28 14:00:06 +0200587 if (sdata_iter->wdev.cac_started)
Aaron Komisardc0c18e2019-10-02 13:59:07 +0000588 return false;
Aaron Komisardc0c18e2019-10-02 13:59:07 +0000589 }
Aaron Komisardc0c18e2019-10-02 13:59:07 +0000590
591 return true;
592}
593
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +0200594static bool ieee80211_can_scan(struct ieee80211_local *local,
595 struct ieee80211_sub_if_data *sdata)
596{
Aaron Komisardc0c18e2019-10-02 13:59:07 +0000597 if (!__ieee80211_can_leave_ch(sdata))
Simon Wunderlich164eb022013-02-08 18:16:20 +0100598 return false;
599
Johannes Berg2eb278e2012-06-05 14:28:42 +0200600 if (!list_empty(&local->roc_list))
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +0200601 return false;
602
603 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +0200604 sdata->u.mgd.flags & IEEE80211_STA_CONNECTION_POLL)
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +0200605 return false;
606
607 return true;
608}
609
610void ieee80211_run_deferred_scan(struct ieee80211_local *local)
611{
Johannes Berg0cd80802023-08-28 14:00:05 +0200612 lockdep_assert_wiphy(local->hw.wiphy);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +0200613
614 if (!local->scan_req || local->scanning)
615 return;
616
Johannes Berge2fd5db2012-07-06 21:39:28 +0200617 if (!ieee80211_can_scan(local,
618 rcu_dereference_protected(
619 local->scan_sdata,
Johannes Berg0cd80802023-08-28 14:00:05 +0200620 lockdep_is_held(&local->hw.wiphy->mtx))))
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +0200621 return;
622
Johannes Berg20171252023-08-28 13:59:39 +0200623 wiphy_delayed_work_queue(local->hw.wiphy, &local->scan_work,
624 round_jiffies_relative(0));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +0200625}
Johannes Bergf3b852522009-04-23 16:01:47 +0200626
Johannes Berg45ad6832018-05-28 15:47:39 +0200627static void ieee80211_send_scan_probe_req(struct ieee80211_sub_if_data *sdata,
628 const u8 *src, const u8 *dst,
629 const u8 *ssid, size_t ssid_len,
630 const u8 *ie, size_t ie_len,
631 u32 ratemask, u32 flags, u32 tx_flags,
632 struct ieee80211_channel *channel)
633{
634 struct sk_buff *skb;
635
636 skb = ieee80211_build_probe_req(sdata, src, dst, ratemask, channel,
637 ssid, ssid_len,
638 ie, ie_len, flags);
Johannes Bergb9771d42018-05-28 15:47:41 +0200639
Johannes Berg45ad6832018-05-28 15:47:39 +0200640 if (skb) {
Johannes Bergb9771d42018-05-28 15:47:41 +0200641 if (flags & IEEE80211_PROBE_FLAG_RANDOM_SN) {
642 struct ieee80211_hdr *hdr = (void *)skb->data;
Mathy Vanhoef2b3dab12020-07-23 14:01:51 +0400643 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jason A. Donenfeld7e3cf082022-10-05 17:23:53 +0200644 u16 sn = get_random_u16();
Johannes Bergb9771d42018-05-28 15:47:41 +0200645
Mathy Vanhoef2b3dab12020-07-23 14:01:51 +0400646 info->control.flags |= IEEE80211_TX_CTRL_NO_SEQNO;
Johannes Bergb9771d42018-05-28 15:47:41 +0200647 hdr->seq_ctrl =
648 cpu_to_le16(IEEE80211_SN_TO_SEQ(sn));
649 }
Johannes Berg45ad6832018-05-28 15:47:39 +0200650 IEEE80211_SKB_CB(skb)->flags |= tx_flags;
Mathy Vanhoef08aca292020-07-23 14:01:52 +0400651 ieee80211_tx_skb_tid_band(sdata, skb, 7, channel->band);
Johannes Berg45ad6832018-05-28 15:47:39 +0200652 }
653}
654
Ben Greear8a690672012-04-17 10:54:16 -0700655static void ieee80211_scan_state_send_probe(struct ieee80211_local *local,
656 unsigned long *next_delay)
657{
658 int i;
Johannes Berge2fd5db2012-07-06 21:39:28 +0200659 struct ieee80211_sub_if_data *sdata;
Johannes Berg6ea0a692014-11-19 11:55:49 +0100660 struct cfg80211_scan_request *scan_req;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200661 enum nl80211_band band = local->hw.conf.chandef.chan->band;
Johannes Bergb9771d42018-05-28 15:47:41 +0200662 u32 flags = 0, tx_flags;
Seth Forshee6c17b772013-02-11 11:21:07 -0600663
Johannes Berg6ea0a692014-11-19 11:55:49 +0100664 scan_req = rcu_dereference_protected(local->scan_req,
Johannes Berg0cd80802023-08-28 14:00:05 +0200665 lockdep_is_held(&local->hw.wiphy->mtx));
Johannes Berg6ea0a692014-11-19 11:55:49 +0100666
Seth Forshee6c17b772013-02-11 11:21:07 -0600667 tx_flags = IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg6ea0a692014-11-19 11:55:49 +0100668 if (scan_req->no_cck)
Seth Forshee6c17b772013-02-11 11:21:07 -0600669 tx_flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
Johannes Bergb9771d42018-05-28 15:47:41 +0200670 if (scan_req->flags & NL80211_SCAN_FLAG_MIN_PREQ_CONTENT)
671 flags |= IEEE80211_PROBE_FLAG_MIN_CONTENT;
672 if (scan_req->flags & NL80211_SCAN_FLAG_RANDOM_SN)
673 flags |= IEEE80211_PROBE_FLAG_RANDOM_SN;
Ben Greear8a690672012-04-17 10:54:16 -0700674
Johannes Berge2fd5db2012-07-06 21:39:28 +0200675 sdata = rcu_dereference_protected(local->scan_sdata,
Johannes Berg0cd80802023-08-28 14:00:05 +0200676 lockdep_is_held(&local->hw.wiphy->mtx));
Johannes Berge2fd5db2012-07-06 21:39:28 +0200677
Johannes Berg6ea0a692014-11-19 11:55:49 +0100678 for (i = 0; i < scan_req->n_ssids; i++)
Johannes Berg45ad6832018-05-28 15:47:39 +0200679 ieee80211_send_scan_probe_req(
Jouni Malinene345f442016-02-26 22:12:48 +0200680 sdata, local->scan_addr, scan_req->bssid,
Johannes Berg6ea0a692014-11-19 11:55:49 +0100681 scan_req->ssids[i].ssid, scan_req->ssids[i].ssid_len,
682 scan_req->ie, scan_req->ie_len,
Johannes Bergb9771d42018-05-28 15:47:41 +0200683 scan_req->rates[band], flags,
Johannes Berg45ad6832018-05-28 15:47:39 +0200684 tx_flags, local->hw.conf.chandef.chan);
Ben Greear8a690672012-04-17 10:54:16 -0700685
686 /*
687 * After sending probe requests, wait for probe responses
688 * on the channel.
689 */
Michael-CY Leed60277a2024-01-23 13:47:52 +0800690 *next_delay = msecs_to_jiffies(scan_req->duration) >
691 IEEE80211_PROBE_DELAY + IEEE80211_CHANNEL_TIME ?
692 msecs_to_jiffies(scan_req->duration) - IEEE80211_PROBE_DELAY :
693 IEEE80211_CHANNEL_TIME;
Ben Greear8a690672012-04-17 10:54:16 -0700694 local->next_scan_state = SCAN_DECISION;
695}
696
Johannes Bergf3b852522009-04-23 16:01:47 +0200697static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
698 struct cfg80211_scan_request *req)
699{
700 struct ieee80211_local *local = sdata->local;
Johannes Berge9da68d2018-10-18 10:35:47 +0200701 bool hw_scan = local->ops->hw_scan;
Johannes Bergf3b852522009-04-23 16:01:47 +0200702 int rc;
703
Johannes Berg0cd80802023-08-28 14:00:05 +0200704 lockdep_assert_wiphy(local->hw.wiphy);
Stanislaw Gruszkae229f842010-10-06 11:22:09 +0200705
Aaron Komisardc0c18e2019-10-02 13:59:07 +0000706 if (local->scan_req)
707 return -EBUSY;
708
Ilan Peercbde0b42023-11-13 11:35:01 +0200709 /* For an MLO connection, if a link ID was specified, validate that it
Ayala Beker80b0aac2024-03-20 09:14:02 +0200710 * is indeed active.
Ilan Peercbde0b42023-11-13 11:35:01 +0200711 */
Ayala Beker80b0aac2024-03-20 09:14:02 +0200712 if (ieee80211_vif_is_mld(&sdata->vif) && req->tsf_report_link_id >= 0 &&
713 !(sdata->vif.active_links & BIT(req->tsf_report_link_id)))
714 return -EINVAL;
Ilan Peercbde0b42023-11-13 11:35:01 +0200715
Aaron Komisardc0c18e2019-10-02 13:59:07 +0000716 if (!__ieee80211_can_leave_ch(sdata))
Johannes Bergf3b852522009-04-23 16:01:47 +0200717 return -EBUSY;
718
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +0200719 if (!ieee80211_can_scan(local, sdata)) {
John W. Linville6e7e6212010-02-08 16:38:38 -0500720 /* wait for the work to finish/time out */
Johannes Berg6ea0a692014-11-19 11:55:49 +0100721 rcu_assign_pointer(local->scan_req, req);
Johannes Berge2fd5db2012-07-06 21:39:28 +0200722 rcu_assign_pointer(local->scan_sdata, sdata);
Johannes Bergc0ce77b2010-02-03 10:22:31 +0100723 return 0;
724 }
725
Johannes Berge9da68d2018-10-18 10:35:47 +0200726 again:
727 if (hw_scan) {
Johannes Bergf3b852522009-04-23 16:01:47 +0200728 u8 *ies;
Johannes Bergf3b852522009-04-23 16:01:47 +0200729
David Spinadele4dcbb32014-02-11 13:45:41 +0200730 local->hw_scan_ies_bufsize = local->scan_ies_len + req->ie_len;
David Spinadelc56ef672014-02-05 15:21:13 +0200731
Johannes Berg30686bf2015-06-02 21:39:54 +0200732 if (ieee80211_hw_check(&local->hw, SINGLE_SCAN_ON_ALL_BANDS)) {
David Spinadelc56ef672014-02-05 15:21:13 +0200733 int i, n_bands = 0;
734 u8 bands_counted = 0;
735
736 for (i = 0; i < req->n_channels; i++) {
737 if (bands_counted & BIT(req->channels[i]->band))
738 continue;
739 bands_counted |= BIT(req->channels[i]->band);
740 n_bands++;
741 }
742
743 local->hw_scan_ies_bufsize *= n_bands;
744 }
745
Johannes Berg4d36ec52009-10-27 20:59:55 +0100746 local->hw_scan_req = kmalloc(
747 sizeof(*local->hw_scan_req) +
748 req->n_channels * sizeof(req->channels[0]) +
Johannes Bergc604b9f2012-11-29 12:45:18 +0100749 local->hw_scan_ies_bufsize, GFP_KERNEL);
Johannes Berg4d36ec52009-10-27 20:59:55 +0100750 if (!local->hw_scan_req)
Johannes Bergf3b852522009-04-23 16:01:47 +0200751 return -ENOMEM;
752
David Spinadelc56ef672014-02-05 15:21:13 +0200753 local->hw_scan_req->req.ssids = req->ssids;
754 local->hw_scan_req->req.n_ssids = req->n_ssids;
Johannes Berg4d36ec52009-10-27 20:59:55 +0100755 ies = (u8 *)local->hw_scan_req +
756 sizeof(*local->hw_scan_req) +
757 req->n_channels * sizeof(req->channels[0]);
David Spinadelc56ef672014-02-05 15:21:13 +0200758 local->hw_scan_req->req.ie = ies;
759 local->hw_scan_req->req.flags = req->flags;
Jouni Malinene345f442016-02-26 22:12:48 +0200760 eth_broadcast_addr(local->hw_scan_req->req.bssid);
Avraham Stern7947d3e2016-07-05 15:23:12 +0300761 local->hw_scan_req->req.duration = req->duration;
762 local->hw_scan_req->req.duration_mandatory =
763 req->duration_mandatory;
Ilan Peercbde0b42023-11-13 11:35:01 +0200764 local->hw_scan_req->req.tsf_report_link_id =
765 req->tsf_report_link_id;
Johannes Berg4d36ec52009-10-27 20:59:55 +0100766
767 local->hw_scan_band = 0;
Tova Mussaic8cb5b82020-09-18 11:33:13 +0200768 local->hw_scan_req->req.n_6ghz_params = req->n_6ghz_params;
769 local->hw_scan_req->req.scan_6ghz_params =
770 req->scan_6ghz_params;
771 local->hw_scan_req->req.scan_6ghz = req->scan_6ghz;
John W. Linville6e7e6212010-02-08 16:38:38 -0500772
773 /*
774 * After allocating local->hw_scan_req, we must
775 * go through until ieee80211_prep_hw_scan(), so
776 * anything that might be changed here and leave
777 * this function early must not go after this
778 * allocation.
779 */
Johannes Bergf3b852522009-04-23 16:01:47 +0200780 }
781
Johannes Berg6ea0a692014-11-19 11:55:49 +0100782 rcu_assign_pointer(local->scan_req, req);
Johannes Berge2fd5db2012-07-06 21:39:28 +0200783 rcu_assign_pointer(local->scan_sdata, sdata);
Johannes Bergf3b852522009-04-23 16:01:47 +0200784
Johannes Berga344d672014-06-12 22:24:31 +0200785 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)
786 get_random_mask_addr(local->scan_addr,
787 req->mac_addr,
788 req->mac_addr_mask);
789 else
790 memcpy(local->scan_addr, sdata->vif.addr, ETH_ALEN);
791
Johannes Berge9da68d2018-10-18 10:35:47 +0200792 if (hw_scan) {
Helmut Schaafbe9c4292009-07-23 12:14:04 +0200793 __set_bit(SCAN_HW_SCANNING, &local->scanning);
Ben Greear8a690672012-04-17 10:54:16 -0700794 } else if ((req->n_channels == 1) &&
Johannes Berg0a44dfc2024-01-29 19:34:38 +0100795 (req->channels[0] == local->hw.conf.chandef.chan)) {
Johannes Berg9b864872012-07-26 14:38:32 +0200796 /*
797 * If we are scanning only on the operating channel
798 * then we do not need to stop normal activities
Ben Greear8a690672012-04-17 10:54:16 -0700799 */
800 unsigned long next_delay;
801
802 __set_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning);
803
804 ieee80211_recalc_idle(local);
805
806 /* Notify driver scan is starting, keep order of operations
807 * same as normal software scan, in case that matters. */
Johannes Berga344d672014-06-12 22:24:31 +0200808 drv_sw_scan_start(local, sdata, local->scan_addr);
Ben Greear8a690672012-04-17 10:54:16 -0700809
810 ieee80211_configure_filter(local); /* accept probe-responses */
811
812 /* We need to ensure power level is at max for scanning. */
Johannes Berg0a44dfc2024-01-29 19:34:38 +0100813 ieee80211_hw_conf_chan(local);
Ben Greear8a690672012-04-17 10:54:16 -0700814
Antonio Quartulli4e39cca2015-11-21 18:13:40 +0800815 if ((req->channels[0]->flags & (IEEE80211_CHAN_NO_IR |
816 IEEE80211_CHAN_RADAR)) ||
Johannes Berg6ea0a692014-11-19 11:55:49 +0100817 !req->n_ssids) {
Ben Greear8a690672012-04-17 10:54:16 -0700818 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
Felix Fietkaub041b7b2022-04-20 12:49:07 +0200819 if (req->n_ssids)
820 set_bit(SCAN_BEACON_WAIT, &local->scanning);
Ben Greear8a690672012-04-17 10:54:16 -0700821 } else {
822 ieee80211_scan_state_send_probe(local, &next_delay);
823 next_delay = IEEE80211_CHANNEL_TIME;
824 }
825
826 /* Now, just wait a bit and we are all done! */
Johannes Berg20171252023-08-28 13:59:39 +0200827 wiphy_delayed_work_queue(local->hw.wiphy, &local->scan_work,
828 next_delay);
Ben Greear8a690672012-04-17 10:54:16 -0700829 return 0;
830 } else {
831 /* Do normal software scan */
Helmut Schaafbe9c4292009-07-23 12:14:04 +0200832 __set_bit(SCAN_SW_SCANNING, &local->scanning);
Ben Greear8a690672012-04-17 10:54:16 -0700833 }
John W. Linville6e7e6212010-02-08 16:38:38 -0500834
Johannes Berg5cff20e2009-04-29 12:26:17 +0200835 ieee80211_recalc_idle(local);
Johannes Bergf3b852522009-04-23 16:01:47 +0200836
Johannes Berge9da68d2018-10-18 10:35:47 +0200837 if (hw_scan) {
Ilan Peer2ad22742020-05-28 21:34:39 +0200838 WARN_ON(!ieee80211_prep_hw_scan(sdata));
Johannes Berga060bbf2010-04-27 11:59:34 +0200839 rc = drv_hw_scan(local, sdata, local->hw_scan_req);
Johannes Berga344d672014-06-12 22:24:31 +0200840 } else {
841 rc = ieee80211_start_sw_scan(local, sdata);
842 }
Johannes Bergf3b852522009-04-23 16:01:47 +0200843
Johannes Bergf3b852522009-04-23 16:01:47 +0200844 if (rc) {
Johannes Berg4d36ec52009-10-27 20:59:55 +0100845 kfree(local->hw_scan_req);
846 local->hw_scan_req = NULL;
Helmut Schaafbe9c4292009-07-23 12:14:04 +0200847 local->scanning = 0;
Johannes Bergf3b852522009-04-23 16:01:47 +0200848
Johannes Berg5cff20e2009-04-29 12:26:17 +0200849 ieee80211_recalc_idle(local);
850
Johannes Bergf3b852522009-04-23 16:01:47 +0200851 local->scan_req = NULL;
Monam Agarwal0c2bef462014-03-24 00:51:43 +0530852 RCU_INIT_POINTER(local->scan_sdata, NULL);
Johannes Bergf3b852522009-04-23 16:01:47 +0200853 }
854
Johannes Berge9da68d2018-10-18 10:35:47 +0200855 if (hw_scan && rc == 1) {
856 /*
857 * we can't fall back to software for P2P-GO
858 * as it must update NoA etc.
859 */
860 if (ieee80211_vif_type_p2p(&sdata->vif) ==
861 NL80211_IFTYPE_P2P_GO)
862 return -EOPNOTSUPP;
863 hw_scan = false;
864 goto again;
865 }
866
Johannes Bergf3b852522009-04-23 16:01:47 +0200867 return rc;
868}
869
Helmut Schaadf13cce2010-02-24 14:19:21 +0100870static unsigned long
871ieee80211_scan_get_channel_time(struct ieee80211_channel *chan)
872{
873 /*
874 * TODO: channel switching also consumes quite some time,
875 * add that delay as well to get a better estimation
876 */
Antonio Quartulli4e39cca2015-11-21 18:13:40 +0800877 if (chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR))
Helmut Schaadf13cce2010-02-24 14:19:21 +0100878 return IEEE80211_PASSIVE_CHANNEL_TIME;
879 return IEEE80211_PROBE_DELAY + IEEE80211_CHANNEL_TIME;
880}
881
Stanislaw Gruszkae229f842010-10-06 11:22:09 +0200882static void ieee80211_scan_state_decision(struct ieee80211_local *local,
883 unsigned long *next_delay)
Helmut Schaa7d3be3c2009-07-23 12:13:41 +0200884{
Helmut Schaa142b9f52009-07-23 13:18:01 +0200885 bool associated = false;
Helmut Schaadf13cce2010-02-24 14:19:21 +0100886 bool tx_empty = true;
887 bool bad_latency;
Helmut Schaa142b9f52009-07-23 13:18:01 +0200888 struct ieee80211_sub_if_data *sdata;
Helmut Schaadf13cce2010-02-24 14:19:21 +0100889 struct ieee80211_channel *next_chan;
Sam Lefflercd2bb512012-10-11 21:03:35 -0700890 enum mac80211_scan_state next_scan_state;
Johannes Berg6ea0a692014-11-19 11:55:49 +0100891 struct cfg80211_scan_request *scan_req;
Helmut Schaa142b9f52009-07-23 13:18:01 +0200892
Johannes Bergbe0df012023-08-28 14:00:06 +0200893 lockdep_assert_wiphy(local->hw.wiphy);
894
Helmut Schaadf13cce2010-02-24 14:19:21 +0100895 /*
896 * check if at least one STA interface is associated,
897 * check if at least one STA interface has pending tx frames
898 * and grab the lowest used beacon interval
899 */
Helmut Schaa142b9f52009-07-23 13:18:01 +0200900 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b662009-12-23 13:15:31 +0100901 if (!ieee80211_sdata_running(sdata))
Helmut Schaa142b9f52009-07-23 13:18:01 +0200902 continue;
903
904 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
905 if (sdata->u.mgd.associated) {
906 associated = true;
Helmut Schaadf13cce2010-02-24 14:19:21 +0100907
Helmut Schaadf13cce2010-02-24 14:19:21 +0100908 if (!qdisc_all_tx_empty(sdata->dev)) {
909 tx_empty = false;
910 break;
911 }
Helmut Schaa142b9f52009-07-23 13:18:01 +0200912 }
913 }
914 }
Helmut Schaa142b9f52009-07-23 13:18:01 +0200915
Johannes Berg6ea0a692014-11-19 11:55:49 +0100916 scan_req = rcu_dereference_protected(local->scan_req,
Johannes Berg0cd80802023-08-28 14:00:05 +0200917 lockdep_is_held(&local->hw.wiphy->mtx));
Johannes Berg6ea0a692014-11-19 11:55:49 +0100918
919 next_chan = scan_req->channels[local->scan_channel_idx];
Ben Greearb23b0252011-02-04 11:54:17 -0800920
Johannes Berg07ef03e2011-11-08 16:21:21 +0100921 /*
922 * we're currently scanning a different channel, let's
923 * see if we can scan another channel without interfering
924 * with the current traffic situation.
925 *
Stanislaw Gruszka3f892b62013-01-23 12:32:45 +0100926 * Keep good latency, do not stay off-channel more than 125 ms.
Johannes Berg07ef03e2011-11-08 16:21:21 +0100927 */
Helmut Schaadf13cce2010-02-24 14:19:21 +0100928
Johannes Berg07ef03e2011-11-08 16:21:21 +0100929 bad_latency = time_after(jiffies +
Stanislaw Gruszka3f892b62013-01-23 12:32:45 +0100930 ieee80211_scan_get_channel_time(next_chan),
931 local->leave_oper_channel_time + HZ / 8);
Helmut Schaadf13cce2010-02-24 14:19:21 +0100932
Sam Lefflercd2bb512012-10-11 21:03:35 -0700933 if (associated && !tx_empty) {
Johannes Berg6ea0a692014-11-19 11:55:49 +0100934 if (scan_req->flags & NL80211_SCAN_FLAG_LOW_PRIORITY)
Sam Lefflercd2bb512012-10-11 21:03:35 -0700935 next_scan_state = SCAN_ABORT;
936 else
937 next_scan_state = SCAN_SUSPEND;
Stanislaw Gruszka3f892b62013-01-23 12:32:45 +0100938 } else if (associated && bad_latency) {
Sam Lefflercd2bb512012-10-11 21:03:35 -0700939 next_scan_state = SCAN_SUSPEND;
940 } else {
941 next_scan_state = SCAN_SET_CHANNEL;
942 }
943
944 local->next_scan_state = next_scan_state;
Helmut Schaa142b9f52009-07-23 13:18:01 +0200945
Helmut Schaa2fb3f022009-07-23 12:13:56 +0200946 *next_delay = 0;
Helmut Schaa2fb3f022009-07-23 12:13:56 +0200947}
948
949static void ieee80211_scan_state_set_channel(struct ieee80211_local *local,
950 unsigned long *next_delay)
951{
952 int skip;
953 struct ieee80211_channel *chan;
Johannes Berg6ea0a692014-11-19 11:55:49 +0100954 struct cfg80211_scan_request *scan_req;
955
956 scan_req = rcu_dereference_protected(local->scan_req,
Johannes Berg0cd80802023-08-28 14:00:05 +0200957 lockdep_is_held(&local->hw.wiphy->mtx));
Helmut Schaa2fb3f022009-07-23 12:13:56 +0200958
Helmut Schaa7d3be3c2009-07-23 12:13:41 +0200959 skip = 0;
Johannes Berg6ea0a692014-11-19 11:55:49 +0100960 chan = scan_req->channels[local->scan_channel_idx];
Helmut Schaa7d3be3c2009-07-23 12:13:41 +0200961
Simon Wunderlich7ca15a02013-07-08 16:55:56 +0200962 local->scan_chandef.chan = chan;
963 local->scan_chandef.center_freq1 = chan->center_freq;
Thomas Pedersenb60119602020-04-01 18:18:04 -0700964 local->scan_chandef.freq1_offset = chan->freq_offset;
Simon Wunderlich7ca15a02013-07-08 16:55:56 +0200965 local->scan_chandef.center_freq2 = 0;
Thomas Pedersen75b15932020-09-21 19:28:03 -0700966
Johannes Berg5add3212023-08-29 12:17:43 +0200967 /* For scanning on the S1G band, detect the channel width according to
968 * the channel being scanned.
Thomas Pedersen75b15932020-09-21 19:28:03 -0700969 */
970 if (chan->band == NL80211_BAND_S1GHZ) {
971 local->scan_chandef.width = ieee80211_s1g_channel_width(chan);
972 goto set_channel;
973 }
974
Johannes Berg5add3212023-08-29 12:17:43 +0200975 /* If scanning on oper channel, use whatever channel-type
976 * is currently in use.
977 */
Johannes Berg0a44dfc2024-01-29 19:34:38 +0100978 if (chan == local->hw.conf.chandef.chan)
979 local->scan_chandef = local->hw.conf.chandef;
Johannes Berg5add3212023-08-29 12:17:43 +0200980 else
981 local->scan_chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
Ben Greearb23b0252011-02-04 11:54:17 -0800982
Thomas Pedersen75b15932020-09-21 19:28:03 -0700983set_channel:
Johannes Berg0a44dfc2024-01-29 19:34:38 +0100984 if (ieee80211_hw_conf_chan(local))
Johannes Berg07ef03e2011-11-08 16:21:21 +0100985 skip = 1;
Helmut Schaa7d3be3c2009-07-23 12:13:41 +0200986
Helmut Schaa7d3be3c2009-07-23 12:13:41 +0200987 /* advance state machine to next channel/band */
988 local->scan_channel_idx++;
989
Helmut Schaa0ee9c132009-07-25 17:25:51 +0200990 if (skip) {
991 /* if we skip this channel return to the decision state */
992 local->next_scan_state = SCAN_DECISION;
Helmut Schaa2fb3f022009-07-23 12:13:56 +0200993 return;
Helmut Schaa0ee9c132009-07-25 17:25:51 +0200994 }
Helmut Schaa7d3be3c2009-07-23 12:13:41 +0200995
996 /*
997 * Probe delay is used to update the NAV, cf. 11.1.3.2.2
998 * (which unfortunately doesn't say _why_ step a) is done,
999 * but it waits for the probe delay or until a frame is
1000 * received - and the received frame would update the NAV).
1001 * For now, we do not support waiting until a frame is
1002 * received.
1003 *
1004 * In any case, it is not necessary for a passive scan.
1005 */
Antonio Quartulli4e39cca2015-11-21 18:13:40 +08001006 if ((chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR)) ||
1007 !scan_req->n_ssids) {
Michael-CY Leed60277a2024-01-23 13:47:52 +08001008 *next_delay = msecs_to_jiffies(scan_req->duration) >
1009 IEEE80211_PASSIVE_CHANNEL_TIME ?
1010 msecs_to_jiffies(scan_req->duration) :
1011 IEEE80211_PASSIVE_CHANNEL_TIME;
Helmut Schaa977923b2009-07-23 12:14:20 +02001012 local->next_scan_state = SCAN_DECISION;
Felix Fietkaub041b7b2022-04-20 12:49:07 +02001013 if (scan_req->n_ssids)
1014 set_bit(SCAN_BEACON_WAIT, &local->scanning);
Helmut Schaa2fb3f022009-07-23 12:13:56 +02001015 return;
Helmut Schaa7d3be3c2009-07-23 12:13:41 +02001016 }
1017
Helmut Schaa2fb3f022009-07-23 12:13:56 +02001018 /* active scan, send probes */
Helmut Schaa7d3be3c2009-07-23 12:13:41 +02001019 *next_delay = IEEE80211_PROBE_DELAY;
Helmut Schaa977923b2009-07-23 12:14:20 +02001020 local->next_scan_state = SCAN_SEND_PROBE;
Helmut Schaa7d3be3c2009-07-23 12:13:41 +02001021}
1022
Johannes Berg07ef03e2011-11-08 16:21:21 +01001023static void ieee80211_scan_state_suspend(struct ieee80211_local *local,
1024 unsigned long *next_delay)
1025{
1026 /* switch back to the operating channel */
Simon Wunderlich7ca15a02013-07-08 16:55:56 +02001027 local->scan_chandef.chan = NULL;
Johannes Berg0a44dfc2024-01-29 19:34:38 +01001028 ieee80211_hw_conf_chan(local);
Johannes Berg07ef03e2011-11-08 16:21:21 +01001029
Stanislaw Gruszkaaacde9e2012-12-20 14:41:18 +01001030 /* disable PS */
1031 ieee80211_offchannel_return(local);
Johannes Berg07ef03e2011-11-08 16:21:21 +01001032
1033 *next_delay = HZ / 5;
1034 /* afterwards, resume scan & go to next channel */
1035 local->next_scan_state = SCAN_RESUME;
1036}
1037
1038static void ieee80211_scan_state_resume(struct ieee80211_local *local,
1039 unsigned long *next_delay)
1040{
Stanislaw Gruszkaaacde9e2012-12-20 14:41:18 +01001041 ieee80211_offchannel_stop_vifs(local);
Johannes Berg07ef03e2011-11-08 16:21:21 +01001042
1043 if (local->ops->flush) {
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001044 ieee80211_flush_queues(local, NULL, false);
Johannes Berg07ef03e2011-11-08 16:21:21 +01001045 *next_delay = 0;
1046 } else
1047 *next_delay = HZ / 10;
1048
1049 /* remember when we left the operating channel */
1050 local->leave_oper_channel_time = jiffies;
1051
1052 /* advance to the next channel to be scanned */
Mohammed Shafi Shajakhande2ee842011-12-24 18:43:28 +05301053 local->next_scan_state = SCAN_SET_CHANNEL;
Johannes Berg07ef03e2011-11-08 16:21:21 +01001054}
1055
Johannes Berg20171252023-08-28 13:59:39 +02001056void ieee80211_scan_work(struct wiphy *wiphy, struct wiphy_work *work)
Johannes Berg0a51b272008-09-08 17:44:25 +02001057{
1058 struct ieee80211_local *local =
1059 container_of(work, struct ieee80211_local, scan_work.work);
Johannes Bergd07bfd82011-03-07 15:48:41 +01001060 struct ieee80211_sub_if_data *sdata;
Johannes Berg6ea0a692014-11-19 11:55:49 +01001061 struct cfg80211_scan_request *scan_req;
Johannes Berg0a51b272008-09-08 17:44:25 +02001062 unsigned long next_delay = 0;
Eliad Peller8bd2a242013-12-05 11:21:27 +02001063 bool aborted;
Johannes Berg8789d452010-08-26 13:30:26 +02001064
Johannes Berg0cd80802023-08-28 14:00:05 +02001065 lockdep_assert_wiphy(local->hw.wiphy);
Stanislaw Gruszka259b62e2010-10-06 11:22:08 +02001066
Luciano Coelho332ff7f2015-01-22 23:34:10 +02001067 if (!ieee80211_can_run_worker(local)) {
1068 aborted = true;
1069 goto out_complete;
1070 }
1071
Johannes Berge2fd5db2012-07-06 21:39:28 +02001072 sdata = rcu_dereference_protected(local->scan_sdata,
Johannes Berg0cd80802023-08-28 14:00:05 +02001073 lockdep_is_held(&local->hw.wiphy->mtx));
Johannes Berg6ea0a692014-11-19 11:55:49 +01001074 scan_req = rcu_dereference_protected(local->scan_req,
Johannes Berg0cd80802023-08-28 14:00:05 +02001075 lockdep_is_held(&local->hw.wiphy->mtx));
Johannes Bergd07bfd82011-03-07 15:48:41 +01001076
Ben Greear8a690672012-04-17 10:54:16 -07001077 /* When scanning on-channel, the first-callback means completed. */
1078 if (test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning)) {
1079 aborted = test_and_clear_bit(SCAN_ABORTED, &local->scanning);
1080 goto out_complete;
1081 }
1082
Stanislaw Gruszka259b62e2010-10-06 11:22:08 +02001083 if (test_and_clear_bit(SCAN_COMPLETED, &local->scanning)) {
1084 aborted = test_and_clear_bit(SCAN_ABORTED, &local->scanning);
1085 goto out_complete;
Johannes Bergf3b852522009-04-23 16:01:47 +02001086 }
1087
Johannes Berg6ea0a692014-11-19 11:55:49 +01001088 if (!sdata || !scan_req)
Johannes Berg0cd80802023-08-28 14:00:05 +02001089 return;
Stanislaw Gruszka259b62e2010-10-06 11:22:08 +02001090
Eliad Pellerff5db432014-11-12 10:08:29 +02001091 if (!local->scanning) {
Johannes Bergf3b852522009-04-23 16:01:47 +02001092 int rc;
1093
Johannes Berg6ea0a692014-11-19 11:55:49 +01001094 RCU_INIT_POINTER(local->scan_req, NULL);
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301095 RCU_INIT_POINTER(local->scan_sdata, NULL);
Johannes Bergf3b852522009-04-23 16:01:47 +02001096
Johannes Berg6ea0a692014-11-19 11:55:49 +01001097 rc = __ieee80211_start_scan(sdata, scan_req);
Johannes Berg0cd80802023-08-28 14:00:05 +02001098 if (!rc)
1099 return;
1100 /* need to complete scan in cfg80211 */
1101 rcu_assign_pointer(local->scan_req, scan_req);
1102 aborted = true;
1103 goto out_complete;
Johannes Bergf3b852522009-04-23 16:01:47 +02001104 }
1105
Felix Fietkaub041b7b2022-04-20 12:49:07 +02001106 clear_bit(SCAN_BEACON_WAIT, &local->scanning);
1107
Johannes Berg5bc75722008-09-11 00:01:51 +02001108 /*
Helmut Schaaf502d092009-07-23 12:13:48 +02001109 * as long as no delay is required advance immediately
1110 * without scheduling a new work
1111 */
1112 do {
Rajkumar Manoharanc29acf22011-05-14 09:43:28 +05301113 if (!ieee80211_sdata_running(sdata)) {
1114 aborted = true;
1115 goto out_complete;
1116 }
1117
Felix Fietkaub041b7b2022-04-20 12:49:07 +02001118 if (test_and_clear_bit(SCAN_BEACON_DONE, &local->scanning) &&
1119 local->next_scan_state == SCAN_DECISION)
1120 local->next_scan_state = SCAN_SEND_PROBE;
1121
Helmut Schaa977923b2009-07-23 12:14:20 +02001122 switch (local->next_scan_state) {
Helmut Schaa2fb3f022009-07-23 12:13:56 +02001123 case SCAN_DECISION:
Stanislaw Gruszkae229f842010-10-06 11:22:09 +02001124 /* if no more bands/channels left, complete scan */
Johannes Berg6ea0a692014-11-19 11:55:49 +01001125 if (local->scan_channel_idx >= scan_req->n_channels) {
Stanislaw Gruszkae229f842010-10-06 11:22:09 +02001126 aborted = false;
1127 goto out_complete;
1128 }
1129 ieee80211_scan_state_decision(local, &next_delay);
Helmut Schaaf502d092009-07-23 12:13:48 +02001130 break;
Helmut Schaa2fb3f022009-07-23 12:13:56 +02001131 case SCAN_SET_CHANNEL:
1132 ieee80211_scan_state_set_channel(local, &next_delay);
1133 break;
Helmut Schaaf502d092009-07-23 12:13:48 +02001134 case SCAN_SEND_PROBE:
1135 ieee80211_scan_state_send_probe(local, &next_delay);
1136 break;
Johannes Berg07ef03e2011-11-08 16:21:21 +01001137 case SCAN_SUSPEND:
1138 ieee80211_scan_state_suspend(local, &next_delay);
Helmut Schaa142b9f52009-07-23 13:18:01 +02001139 break;
Johannes Berg07ef03e2011-11-08 16:21:21 +01001140 case SCAN_RESUME:
1141 ieee80211_scan_state_resume(local, &next_delay);
Helmut Schaa142b9f52009-07-23 13:18:01 +02001142 break;
Sam Lefflercd2bb512012-10-11 21:03:35 -07001143 case SCAN_ABORT:
1144 aborted = true;
1145 goto out_complete;
Helmut Schaaf502d092009-07-23 12:13:48 +02001146 }
1147 } while (next_delay == 0);
Johannes Berg0a51b272008-09-08 17:44:25 +02001148
Johannes Berg20171252023-08-28 13:59:39 +02001149 wiphy_delayed_work_queue(local->hw.wiphy, &local->scan_work,
1150 next_delay);
Johannes Berg0cd80802023-08-28 14:00:05 +02001151 return;
Stanislaw Gruszka259b62e2010-10-06 11:22:08 +02001152
1153out_complete:
Eliad Peller8bd2a242013-12-05 11:21:27 +02001154 __ieee80211_scan_completed(&local->hw, aborted);
Johannes Berg0a51b272008-09-08 17:44:25 +02001155}
1156
Johannes Bergc2b13452008-09-11 00:01:55 +02001157int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
Johannes Berg2a519312009-02-10 21:25:55 +01001158 struct cfg80211_scan_request *req)
Johannes Berg0a51b272008-09-08 17:44:25 +02001159{
Johannes Berg0cd80802023-08-28 14:00:05 +02001160 lockdep_assert_wiphy(sdata->local->hw.wiphy);
Johannes Bergf3b852522009-04-23 16:01:47 +02001161
Johannes Berg0cd80802023-08-28 14:00:05 +02001162 return __ieee80211_start_scan(sdata, req);
Johannes Bergf3b852522009-04-23 16:01:47 +02001163}
1164
Stanislaw Gruszka34bcf712012-12-11 10:48:23 +01001165int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata,
1166 const u8 *ssid, u8 ssid_len,
Janusz.Dziedzic@tieto.com76bed0f2015-03-20 06:37:00 +01001167 struct ieee80211_channel **channels,
Johannes Berg5add3212023-08-29 12:17:43 +02001168 unsigned int n_channels)
Johannes Bergf3b852522009-04-23 16:01:47 +02001169{
Johannes Berg0a51b272008-09-08 17:44:25 +02001170 struct ieee80211_local *local = sdata->local;
Janusz.Dziedzic@tieto.com76bed0f2015-03-20 06:37:00 +01001171 int ret = -EBUSY, i, n_ch = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001172 enum nl80211_band band;
Johannes Berg0a51b272008-09-08 17:44:25 +02001173
Johannes Berg0cd80802023-08-28 14:00:05 +02001174 lockdep_assert_wiphy(local->hw.wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01001175
Johannes Bergf3b852522009-04-23 16:01:47 +02001176 /* busy scanning */
1177 if (local->scan_req)
1178 goto unlock;
Johannes Berg2a519312009-02-10 21:25:55 +01001179
Johannes Bergbe4a4b62010-05-03 08:49:48 +02001180 /* fill internal scan request */
Janusz.Dziedzic@tieto.com76bed0f2015-03-20 06:37:00 +01001181 if (!channels) {
1182 int max_n;
Johannes Bergbe4a4b62010-05-03 08:49:48 +02001183
Johannes Berg57fbcce2016-04-12 15:56:15 +02001184 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Tova Mussaic8cb5b82020-09-18 11:33:13 +02001185 if (!local->hw.wiphy->bands[band] ||
1186 band == NL80211_BAND_6GHZ)
Johannes Bergbe4a4b62010-05-03 08:49:48 +02001187 continue;
Stanislaw Gruszka34bcf712012-12-11 10:48:23 +01001188
1189 max_n = local->hw.wiphy->bands[band]->n_channels;
1190 for (i = 0; i < max_n; i++) {
1191 struct ieee80211_channel *tmp_ch =
Johannes Bergbe4a4b62010-05-03 08:49:48 +02001192 &local->hw.wiphy->bands[band]->channels[i];
Stanislaw Gruszka34bcf712012-12-11 10:48:23 +01001193
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001194 if (tmp_ch->flags & (IEEE80211_CHAN_NO_IR |
Stanislaw Gruszka34bcf712012-12-11 10:48:23 +01001195 IEEE80211_CHAN_DISABLED))
1196 continue;
1197
1198 local->int_scan_req->channels[n_ch] = tmp_ch;
1199 n_ch++;
Johannes Bergbe4a4b62010-05-03 08:49:48 +02001200 }
1201 }
1202
Stanislaw Gruszka34bcf712012-12-11 10:48:23 +01001203 if (WARN_ON_ONCE(n_ch == 0))
1204 goto unlock;
1205
1206 local->int_scan_req->n_channels = n_ch;
Johannes Bergbe4a4b62010-05-03 08:49:48 +02001207 } else {
Janusz.Dziedzic@tieto.com76bed0f2015-03-20 06:37:00 +01001208 for (i = 0; i < n_channels; i++) {
1209 if (channels[i]->flags & (IEEE80211_CHAN_NO_IR |
1210 IEEE80211_CHAN_DISABLED))
1211 continue;
1212
1213 local->int_scan_req->channels[n_ch] = channels[i];
1214 n_ch++;
1215 }
1216
1217 if (WARN_ON_ONCE(n_ch == 0))
Stanislaw Gruszka34bcf712012-12-11 10:48:23 +01001218 goto unlock;
1219
Janusz.Dziedzic@tieto.com76bed0f2015-03-20 06:37:00 +01001220 local->int_scan_req->n_channels = n_ch;
Johannes Bergbe4a4b62010-05-03 08:49:48 +02001221 }
1222
1223 local->int_scan_req->ssids = &local->scan_ssid;
1224 local->int_scan_req->n_ssids = 1;
Johannes Berg5ba63532009-08-07 17:54:07 +02001225 memcpy(local->int_scan_req->ssids[0].ssid, ssid, IEEE80211_MAX_SSID_LEN);
1226 local->int_scan_req->ssids[0].ssid_len = ssid_len;
Johannes Berg2a519312009-02-10 21:25:55 +01001227
Johannes Berg5ba63532009-08-07 17:54:07 +02001228 ret = __ieee80211_start_scan(sdata, sdata->local->int_scan_req);
Johannes Bergf3b852522009-04-23 16:01:47 +02001229 unlock:
Johannes Bergf3b852522009-04-23 16:01:47 +02001230 return ret;
Johannes Berg0a51b272008-09-08 17:44:25 +02001231}
Johannes Berg5bb644a2009-05-17 11:40:42 +02001232
1233void ieee80211_scan_cancel(struct ieee80211_local *local)
1234{
Johannes Berg0fd3af62023-03-01 12:09:14 +02001235 /* ensure a new scan cannot be queued */
1236 lockdep_assert_wiphy(local->hw.wiphy);
1237
Johannes Berg5bb644a2009-05-17 11:40:42 +02001238 /*
Eliad Pellerb8564392011-06-13 12:47:30 +03001239 * We are canceling software scan, or deferred scan that was not
Stanislaw Gruszka4136c422010-10-06 11:22:10 +02001240 * yet really started (see __ieee80211_start_scan ).
1241 *
1242 * Regarding hardware scan:
1243 * - we can not call __ieee80211_scan_completed() as when
1244 * SCAN_HW_SCANNING bit is set this function change
1245 * local->hw_scan_req to operate on 5G band, what race with
1246 * driver which can use local->hw_scan_req
1247 *
1248 * - we can not cancel scan_work since driver can schedule it
1249 * by ieee80211_scan_completed(..., true) to finish scan
1250 *
Eliad Pellerb8564392011-06-13 12:47:30 +03001251 * Hence we only call the cancel_hw_scan() callback, but the low-level
1252 * driver is still responsible for calling ieee80211_scan_completed()
1253 * after the scan was completed/aborted.
Johannes Berg5bb644a2009-05-17 11:40:42 +02001254 */
Stanislaw Gruszka4136c422010-10-06 11:22:10 +02001255
Eliad Pellerb8564392011-06-13 12:47:30 +03001256 if (!local->scan_req)
Johannes Berg0cd80802023-08-28 14:00:05 +02001257 return;
Eliad Pellerb8564392011-06-13 12:47:30 +03001258
Emmanuel Grumbacha7540552013-09-16 11:12:07 +03001259 /*
1260 * We have a scan running and the driver already reported completion,
1261 * but the worker hasn't run yet or is stuck on the mutex - mark it as
1262 * cancelled.
1263 */
1264 if (test_bit(SCAN_HW_SCANNING, &local->scanning) &&
1265 test_bit(SCAN_COMPLETED, &local->scanning)) {
1266 set_bit(SCAN_HW_CANCELLED, &local->scanning);
Johannes Berg0cd80802023-08-28 14:00:05 +02001267 return;
Emmanuel Grumbacha7540552013-09-16 11:12:07 +03001268 }
1269
Eliad Pellerb8564392011-06-13 12:47:30 +03001270 if (test_bit(SCAN_HW_SCANNING, &local->scanning)) {
Emmanuel Grumbacha7540552013-09-16 11:12:07 +03001271 /*
1272 * Make sure that __ieee80211_scan_completed doesn't trigger a
1273 * scan on another band.
1274 */
1275 set_bit(SCAN_HW_CANCELLED, &local->scanning);
Eliad Pellerb8564392011-06-13 12:47:30 +03001276 if (local->ops->cancel_hw_scan)
Johannes Berge2fd5db2012-07-06 21:39:28 +02001277 drv_cancel_hw_scan(local,
1278 rcu_dereference_protected(local->scan_sdata,
Johannes Berg0cd80802023-08-28 14:00:05 +02001279 lockdep_is_held(&local->hw.wiphy->mtx)));
1280 return;
Stanislaw Gruszka4136c422010-10-06 11:22:10 +02001281 }
Eliad Pellerb8564392011-06-13 12:47:30 +03001282
Johannes Berg20171252023-08-28 13:59:39 +02001283 wiphy_delayed_work_cancel(local->hw.wiphy, &local->scan_work);
Eliad Pellerb8564392011-06-13 12:47:30 +03001284 /* and clean up */
Avraham Stern7947d3e2016-07-05 15:23:12 +03001285 memset(&local->scan_info, 0, sizeof(local->scan_info));
Eliad Peller8bd2a242013-12-05 11:21:27 +02001286 __ieee80211_scan_completed(&local->hw, true);
Johannes Berg5bb644a2009-05-17 11:40:42 +02001287}
Luciano Coelho79f460c2011-05-11 17:09:36 +03001288
David Spinadeld43c6b62013-12-08 21:48:57 +02001289int __ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
1290 struct cfg80211_sched_scan_request *req)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001291{
1292 struct ieee80211_local *local = sdata->local;
David Spinadel633e2712014-02-06 16:15:23 +02001293 struct ieee80211_scan_ies sched_scan_ies = {};
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001294 struct cfg80211_chan_def chandef;
David Spinadel633e2712014-02-06 16:15:23 +02001295 int ret, i, iebufsz, num_bands = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001296 u32 rate_masks[NUM_NL80211_BANDS] = {};
David Spinadel633e2712014-02-06 16:15:23 +02001297 u8 bands_used = 0;
1298 u8 *ie;
Johannes Bergb9771d42018-05-28 15:47:41 +02001299 u32 flags = 0;
Johannes Bergc604b9f2012-11-29 12:45:18 +01001300
Johannes Berg0cd80802023-08-28 14:00:05 +02001301 lockdep_assert_wiphy(local->hw.wiphy);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001302
Johannes Berg0cd80802023-08-28 14:00:05 +02001303 iebufsz = local->scan_ies_len + req->ie_len;
Luciano Coelho79f460c2011-05-11 17:09:36 +03001304
David Spinadeld43c6b62013-12-08 21:48:57 +02001305 if (!local->ops->sched_scan_start)
Andrei Otcheretianski0528e0f2023-12-11 09:05:25 +02001306 return -EOPNOTSUPP;
Luciano Coelho79f460c2011-05-11 17:09:36 +03001307
Johannes Berg57fbcce2016-04-12 15:56:15 +02001308 for (i = 0; i < NUM_NL80211_BANDS; i++) {
David Spinadel633e2712014-02-06 16:15:23 +02001309 if (local->hw.wiphy->bands[i]) {
1310 bands_used |= BIT(i);
1311 rate_masks[i] = (u32) -1;
1312 num_bands++;
Luciano Coelho79f460c2011-05-11 17:09:36 +03001313 }
Luciano Coelho79f460c2011-05-11 17:09:36 +03001314 }
1315
Johannes Bergb9771d42018-05-28 15:47:41 +02001316 if (req->flags & NL80211_SCAN_FLAG_MIN_PREQ_CONTENT)
1317 flags |= IEEE80211_PROBE_FLAG_MIN_CONTENT;
1318
Kees Cook6396bb22018-06-12 14:03:40 -07001319 ie = kcalloc(iebufsz, num_bands, GFP_KERNEL);
David Spinadel633e2712014-02-06 16:15:23 +02001320 if (!ie) {
1321 ret = -ENOMEM;
1322 goto out;
1323 }
1324
Johannes Berg5add3212023-08-29 12:17:43 +02001325 ieee80211_prepare_scan_chandef(&chandef);
David Spinadel633e2712014-02-06 16:15:23 +02001326
Johannes Berg07095d12024-01-29 20:19:33 +01001327 ret = ieee80211_build_preq_ies(sdata, ie, num_bands * iebufsz,
1328 &sched_scan_ies, req->ie,
1329 req->ie_len, bands_used, rate_masks,
1330 &chandef, flags);
1331 if (ret < 0)
1332 goto error;
David Spinadel633e2712014-02-06 16:15:23 +02001333
Johannes Berg30dd3ed2012-09-04 19:15:01 +02001334 ret = drv_sched_scan_start(local, sdata, req, &sched_scan_ies);
David Spinadeld43c6b62013-12-08 21:48:57 +02001335 if (ret == 0) {
Johannes Berg5260a5b2012-07-06 21:55:11 +02001336 rcu_assign_pointer(local->sched_scan_sdata, sdata);
Johannes Berg6ea0a692014-11-19 11:55:49 +01001337 rcu_assign_pointer(local->sched_scan_req, req);
David Spinadeld43c6b62013-12-08 21:48:57 +02001338 }
Luciano Coelho79f460c2011-05-11 17:09:36 +03001339
Johannes Berg07095d12024-01-29 20:19:33 +01001340error:
David Spinadel633e2712014-02-06 16:15:23 +02001341 kfree(ie);
David Spinadel633e2712014-02-06 16:15:23 +02001342out:
David Spinadeld43c6b62013-12-08 21:48:57 +02001343 if (ret) {
1344 /* Clean in case of failure after HW restart or upon resume. */
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301345 RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
Johannes Berg6ea0a692014-11-19 11:55:49 +01001346 RCU_INIT_POINTER(local->sched_scan_req, NULL);
David Spinadeld43c6b62013-12-08 21:48:57 +02001347 }
1348
1349 return ret;
1350}
1351
1352int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
1353 struct cfg80211_sched_scan_request *req)
1354{
1355 struct ieee80211_local *local = sdata->local;
David Spinadeld43c6b62013-12-08 21:48:57 +02001356
Johannes Berg0cd80802023-08-28 14:00:05 +02001357 lockdep_assert_wiphy(local->hw.wiphy);
David Spinadeld43c6b62013-12-08 21:48:57 +02001358
Johannes Berg0cd80802023-08-28 14:00:05 +02001359 if (rcu_access_pointer(local->sched_scan_sdata))
David Spinadeld43c6b62013-12-08 21:48:57 +02001360 return -EBUSY;
David Spinadeld43c6b62013-12-08 21:48:57 +02001361
Johannes Berg0cd80802023-08-28 14:00:05 +02001362 return __ieee80211_request_sched_scan_start(sdata, req);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001363}
1364
Eliad Peller0d440ea2015-10-25 10:59:33 +02001365int ieee80211_request_sched_scan_stop(struct ieee80211_local *local)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001366{
Eliad Peller0d440ea2015-10-25 10:59:33 +02001367 struct ieee80211_sub_if_data *sched_scan_sdata;
1368 int ret = -ENOENT;
Luciano Coelho79f460c2011-05-11 17:09:36 +03001369
Johannes Berg0cd80802023-08-28 14:00:05 +02001370 lockdep_assert_wiphy(local->hw.wiphy);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001371
Johannes Berg0cd80802023-08-28 14:00:05 +02001372 if (!local->ops->sched_scan_stop)
Andrei Otcheretianski0528e0f2023-12-11 09:05:25 +02001373 return -EOPNOTSUPP;
Luciano Coelho79f460c2011-05-11 17:09:36 +03001374
David Spinadeld43c6b62013-12-08 21:48:57 +02001375 /* We don't want to restart sched scan anymore. */
Johannes Berg6ea0a692014-11-19 11:55:49 +01001376 RCU_INIT_POINTER(local->sched_scan_req, NULL);
David Spinadeld43c6b62013-12-08 21:48:57 +02001377
Eliad Peller0d440ea2015-10-25 10:59:33 +02001378 sched_scan_sdata = rcu_dereference_protected(local->sched_scan_sdata,
Johannes Berg0cd80802023-08-28 14:00:05 +02001379 lockdep_is_held(&local->hw.wiphy->mtx));
Eliad Peller0d440ea2015-10-25 10:59:33 +02001380 if (sched_scan_sdata) {
1381 ret = drv_sched_scan_stop(local, sched_scan_sdata);
Alexander Bondar71228a12014-03-16 10:49:54 +02001382 if (!ret)
Andreea-Cristina Bernatad053a962014-08-22 16:14:49 +03001383 RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
Alexander Bondar71228a12014-03-16 10:49:54 +02001384 }
Luciano Coelho79f460c2011-05-11 17:09:36 +03001385
1386 return ret;
1387}
1388
1389void ieee80211_sched_scan_results(struct ieee80211_hw *hw)
1390{
1391 struct ieee80211_local *local = hw_to_local(hw);
1392
1393 trace_api_sched_scan_results(local);
1394
Arend Van Sprielb34939b2017-04-28 13:40:28 +01001395 cfg80211_sched_scan_results(hw->wiphy, 0);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001396}
1397EXPORT_SYMBOL(ieee80211_sched_scan_results);
1398
Johannes Bergf6837ba82014-04-30 14:19:04 +02001399void ieee80211_sched_scan_end(struct ieee80211_local *local)
Luciano Coelho85a99942011-05-12 16:28:29 +03001400{
Johannes Berg0cd80802023-08-28 14:00:05 +02001401 lockdep_assert_wiphy(local->hw.wiphy);
Luciano Coelho85a99942011-05-12 16:28:29 +03001402
Johannes Berg0cd80802023-08-28 14:00:05 +02001403 if (!rcu_access_pointer(local->sched_scan_sdata))
Luciano Coelho85a99942011-05-12 16:28:29 +03001404 return;
Luciano Coelho85a99942011-05-12 16:28:29 +03001405
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301406 RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
Luciano Coelho85a99942011-05-12 16:28:29 +03001407
David Spinadeld43c6b62013-12-08 21:48:57 +02001408 /* If sched scan was aborted by the driver. */
Johannes Berg6ea0a692014-11-19 11:55:49 +01001409 RCU_INIT_POINTER(local->sched_scan_req, NULL);
David Spinadeld43c6b62013-12-08 21:48:57 +02001410
Johannes Bergeadfb542023-08-28 13:59:45 +02001411 cfg80211_sched_scan_stopped_locked(local->hw.wiphy, 0);
Luciano Coelho85a99942011-05-12 16:28:29 +03001412}
1413
Johannes Bergeadfb542023-08-28 13:59:45 +02001414void ieee80211_sched_scan_stopped_work(struct wiphy *wiphy,
1415 struct wiphy_work *work)
Johannes Bergf6837ba82014-04-30 14:19:04 +02001416{
1417 struct ieee80211_local *local =
1418 container_of(work, struct ieee80211_local,
1419 sched_scan_stopped_work);
1420
1421 ieee80211_sched_scan_end(local);
1422}
1423
Luciano Coelho79f460c2011-05-11 17:09:36 +03001424void ieee80211_sched_scan_stopped(struct ieee80211_hw *hw)
1425{
1426 struct ieee80211_local *local = hw_to_local(hw);
1427
1428 trace_api_sched_scan_stopped(local);
1429
Eliad Peller2bc533b2016-01-05 16:28:06 +02001430 /*
1431 * this shouldn't really happen, so for simplicity
1432 * simply ignore it, and let mac80211 reconfigure
1433 * the sched scan later on.
1434 */
1435 if (local->in_reconfig)
1436 return;
1437
Johannes Bergeadfb542023-08-28 13:59:45 +02001438 wiphy_work_queue(hw->wiphy, &local->sched_scan_stopped_work);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001439}
1440EXPORT_SYMBOL(ieee80211_sched_scan_stopped);