blob: e041af2f021ad68c5c001931c5bf4a8def849a57 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Jiri Bencf0706e82007-05-05 11:45:53 -07002/*
3 * BSS client mode implementation
Jouni Malinen5394af42009-01-08 13:31:59 +02004 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
Jiri Bencf0706e82007-05-05 11:45:53 -07005 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
Johannes Bergd98ad832014-09-03 15:24:57 +03009 * Copyright 2013-2014 Intel Mobile Communications GmbH
Avraham Sterne38a0172017-04-26 10:58:47 +030010 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
Sara Sharon2bf973f2020-01-31 13:12:51 +020011 * Copyright (C) 2018 - 2020 Intel Corporation
Jiri Bencf0706e82007-05-05 11:45:53 -070012 */
13
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070014#include <linux/delay.h>
Ard Biesheuvel5fdb3732019-06-12 18:19:54 +020015#include <linux/fips.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070016#include <linux/if_ether.h>
17#include <linux/skbuff.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018#include <linux/if_arp.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070019#include <linux/etherdevice.h>
Paul Gortmakerd9b93842011-09-18 13:21:27 -040020#include <linux/moduleparam.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010021#include <linux/rtnetlink.h>
Johannes Bergd91f36d2009-04-16 13:17:26 +020022#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040024#include <linux/export.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070025#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020026#include <asm/unaligned.h>
Johannes Berg60f8b39c2008-09-08 17:44:22 +020027
Jiri Bencf0706e82007-05-05 11:45:53 -070028#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020029#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040030#include "rate.h"
31#include "led.h"
Jouni Malinen39404fe2016-10-27 00:42:05 +030032#include "fils_aead.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070033
Johannes Berg1672c0e32013-01-29 15:02:27 +010034#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020035#define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010036#define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
Ilan Peer407879b2018-04-20 13:49:20 +030037#define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010038#define IEEE80211_AUTH_MAX_TRIES 3
39#define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
40#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020041#define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010042#define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
43#define IEEE80211_ASSOC_MAX_TRIES 3
Johannes Berg66e67e42012-01-20 13:55:27 +010044
Ben Greear180205b2011-02-04 15:30:24 -080045static int max_nullfunc_tries = 2;
46module_param(max_nullfunc_tries, int, 0644);
47MODULE_PARM_DESC(max_nullfunc_tries,
48 "Maximum nullfunc tx tries before disconnecting (reason 4).");
49
50static int max_probe_tries = 5;
51module_param(max_probe_tries, int, 0644);
52MODULE_PARM_DESC(max_probe_tries,
53 "Maximum probe tries before disconnecting (reason 4).");
Johannes Bergb291ba12009-07-10 15:29:03 +020054
55/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010056 * Beacon loss timeout is calculated as N frames times the
57 * advertised beacon interval. This may need to be somewhat
58 * higher than what hardware might detect to account for
59 * delays in the host processing frames. But since we also
60 * probe on beacon miss before declaring the connection lost
61 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020062 */
Ben Greear59c1ec22013-03-19 14:19:56 -070063static int beacon_loss_count = 7;
64module_param(beacon_loss_count, int, 0644);
65MODULE_PARM_DESC(beacon_loss_count,
66 "Number of beacon intervals before we decide beacon was lost.");
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010067
Johannes Bergb291ba12009-07-10 15:29:03 +020068/*
69 * Time the connection can be idle before we probe
70 * it to see if we can still talk to the AP.
71 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030072#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020073/*
74 * Time we wait for a probe response after sending
75 * a probe request because of beacon loss or for
76 * checking the connection still works.
77 */
Ben Greear180205b2011-02-04 15:30:24 -080078static int probe_wait_ms = 500;
79module_param(probe_wait_ms, int, 0644);
80MODULE_PARM_DESC(probe_wait_ms,
81 "Maximum time(ms) to wait for probe response"
82 " before disconnecting (reason 4).");
Jiri Bencf0706e82007-05-05 11:45:53 -070083
Jouni Malinen17e4ec12010-03-29 23:28:30 -070084/*
Jouni Malinen391a2002010-08-27 22:22:00 +030085 * How many Beacon frames need to have been used in average signal strength
86 * before starting to indicate signal change events.
87 */
88#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
89
Johannes Berg77fdaa12009-07-07 03:45:17 +020090/*
Johannes Bergca386f32009-07-10 02:39:48 +020091 * We can have multiple work items (and connection probing)
92 * scheduling this timer, but we need to take care to only
93 * reschedule it when it should fire _earlier_ than it was
94 * asked for before, or if it's not pending right now. This
95 * function ensures that. Note that it then is required to
96 * run this function for all timeouts after the first one
97 * has happened -- the work that runs from this timer will
98 * do that.
99 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200100static void run_again(struct ieee80211_sub_if_data *sdata,
101 unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200102{
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200103 sdata_assert_lock(sdata);
Johannes Bergca386f32009-07-10 02:39:48 +0200104
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200105 if (!timer_pending(&sdata->u.mgd.timer) ||
106 time_before(timeout, sdata->u.mgd.timer.expires))
107 mod_timer(&sdata->u.mgd.timer, timeout);
Johannes Bergca386f32009-07-10 02:39:48 +0200108}
109
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400110void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200111{
Johannes Bergc1288b12012-01-19 09:29:57 +0100112 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200113 return;
114
Johannes Berg30686bf2015-06-02 21:39:54 +0200115 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Johannes Berg7eeff742012-07-18 10:27:27 +0200116 return;
117
Johannes Bergb291ba12009-07-10 15:29:03 +0200118 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100119 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200120}
121
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400122void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
123{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400124 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
125
Johannes Bergb100e5d2016-03-17 15:41:37 +0200126 if (unlikely(!ifmgd->associated))
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100127 return;
128
Johannes Bergb100e5d2016-03-17 15:41:37 +0200129 if (ifmgd->probe_send_count)
130 ifmgd->probe_send_count = 0;
Eliad Peller448cd2e2014-02-11 12:30:18 +0200131
Johannes Berg30686bf2015-06-02 21:39:54 +0200132 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400133 return;
134
Johannes Bergb100e5d2016-03-17 15:41:37 +0200135 mod_timer(&ifmgd->conn_mon_timer,
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400136 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
137}
138
Johannes Berg5484e232008-09-08 17:44:27 +0200139static int ecw2cw(int ecw)
Johannes Berg60f8b39c2008-09-08 17:44:22 +0200140{
Johannes Berg5484e232008-09-08 17:44:27 +0200141 return (1 << ecw) - 1;
Johannes Berg60f8b39c2008-09-08 17:44:22 +0200142}
143
Johannes Berg6565ec92013-02-08 14:52:32 +0100144static u32
145ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
146 struct ieee80211_supported_band *sband,
147 struct ieee80211_channel *channel,
148 const struct ieee80211_ht_operation *ht_oper,
149 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300150 const struct ieee80211_he_operation *he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +0200151 struct cfg80211_chan_def *chandef, bool tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100152{
Johannes Berg5cdaed12013-07-31 11:23:06 +0200153 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg6565ec92013-02-08 14:52:32 +0100154 struct cfg80211_chan_def vht_chandef;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200155 struct ieee80211_sta_ht_cap sta_ht_cap;
Johannes Berg6565ec92013-02-08 14:52:32 +0100156 u32 ht_cfreq, ret;
157
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200158 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
159 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
160
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +0300161 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
Johannes Berg6565ec92013-02-08 14:52:32 +0100162 chandef->chan = channel;
163 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
164 chandef->center_freq1 = channel->center_freq;
Johannes Berg6565ec92013-02-08 14:52:32 +0100165
Johannes Bergb1b1ae22017-10-13 15:26:01 +0300166 if (!ht_oper || !sta_ht_cap.ht_supported) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100167 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
168 goto out;
169 }
170
171 chandef->width = NL80211_CHAN_WIDTH_20;
172
173 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
174 channel->band);
175 /* check that channel matches the right operating channel */
Johannes Berg5cdaed12013-07-31 11:23:06 +0200176 if (!tracking && channel->center_freq != ht_cfreq) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100177 /*
178 * It's possible that some APs are confused here;
179 * Netgear WNDR3700 sometimes reports 4 higher than
180 * the actual channel in association responses, but
181 * since we look at probe response/beacon data here
182 * it should be OK.
183 */
Johannes Berg5cdaed12013-07-31 11:23:06 +0200184 sdata_info(sdata,
185 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
186 channel->center_freq, ht_cfreq,
187 ht_oper->primary_chan, channel->band);
Johannes Berg6565ec92013-02-08 14:52:32 +0100188 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
189 goto out;
190 }
191
192 /* check 40 MHz support, if we have it */
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200193 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100194 ieee80211_chandef_ht_oper(ht_oper, chandef);
Johannes Berg6565ec92013-02-08 14:52:32 +0100195 } else {
196 /* 40 MHz (and 80 MHz) must be supported for VHT */
197 ret = IEEE80211_STA_DISABLE_VHT;
Johannes Berg85220d72013-03-25 18:29:27 +0100198 /* also mark 40 MHz disabled */
199 ret |= IEEE80211_STA_DISABLE_40MHZ;
Johannes Berg6565ec92013-02-08 14:52:32 +0100200 goto out;
201 }
202
203 if (!vht_oper || !sband->vht_cap.vht_supported) {
204 ret = IEEE80211_STA_DISABLE_VHT;
205 goto out;
206 }
207
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100208 vht_chandef = *chandef;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300209 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
210 (le32_to_cpu(he_oper->he_oper_params) &
211 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
212 struct ieee80211_vht_operation he_oper_vht_cap;
213
214 /*
215 * Set only first 3 bytes (other 2 aren't used in
216 * ieee80211_chandef_vht_oper() anyway)
217 */
218 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
219 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
220
Johannes Berg7eb26df2018-08-31 11:31:18 +0300221 if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
222 &he_oper_vht_cap, ht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300223 &vht_chandef)) {
224 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
225 sdata_info(sdata,
226 "HE AP VHT information is invalid, disable HE\n");
227 ret = IEEE80211_STA_DISABLE_HE;
228 goto out;
229 }
Johannes Berg7eb26df2018-08-31 11:31:18 +0300230 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_oper,
231 ht_oper, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200232 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100233 sdata_info(sdata,
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100234 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100235 ret = IEEE80211_STA_DISABLE_VHT;
236 goto out;
237 }
238
239 if (!cfg80211_chandef_valid(&vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200240 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100241 sdata_info(sdata,
242 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100243 ret = IEEE80211_STA_DISABLE_VHT;
244 goto out;
245 }
246
247 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
248 ret = 0;
249 goto out;
250 }
251
252 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200253 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100254 sdata_info(sdata,
255 "AP VHT information doesn't match HT, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100256 ret = IEEE80211_STA_DISABLE_VHT;
257 goto out;
258 }
259
260 *chandef = vht_chandef;
261
262 ret = 0;
263
264out:
Johannes Berg963a18522014-02-21 20:34:34 +0100265 /*
266 * When tracking the current AP, don't do any further checks if the
267 * new chandef is identical to the one we're currently using for the
268 * connection. This keeps us from playing ping-pong with regulatory,
269 * without it the following can happen (for example):
270 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
271 * - AP advertises regdom US
272 * - CRDA loads regdom US with 80 MHz prohibited (old database)
273 * - the code below detects an unsupported channel, downgrades, and
274 * we disconnect from the AP in the caller
275 * - disconnect causes CRDA to reload world regdomain and the game
276 * starts anew.
277 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
278 *
279 * It seems possible that there are still scenarios with CSA or real
280 * bandwidth changes where a this could happen, but those cases are
281 * less common and wouldn't completely prevent using the AP.
282 */
283 if (tracking &&
284 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
285 return ret;
286
Johannes Berg586e01e2013-02-14 12:13:53 +0100287 /* don't print the message below for VHT mismatch if VHT is disabled */
288 if (ret & IEEE80211_STA_DISABLE_VHT)
289 vht_chandef = *chandef;
290
Johannes Bergddfe49b2013-07-31 20:52:03 +0200291 /*
292 * Ignore the DISABLED flag when we're already connected and only
293 * tracking the APs beacon for bandwidth changes - otherwise we
294 * might get disconnected here if we connect to an AP, update our
295 * regulatory information based on the AP's country IE and the
296 * information we have is wrong/outdated and disables the channel
297 * that we're actually using for the connection to the AP.
298 */
Johannes Berg6565ec92013-02-08 14:52:32 +0100299 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
Johannes Bergddfe49b2013-07-31 20:52:03 +0200300 tracking ? 0 :
301 IEEE80211_CHAN_DISABLED)) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100302 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
303 ret = IEEE80211_STA_DISABLE_HT |
304 IEEE80211_STA_DISABLE_VHT;
Chris Wrightb56e4b82013-07-31 12:12:24 -0700305 break;
Johannes Berg6565ec92013-02-08 14:52:32 +0100306 }
307
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200308 ret |= ieee80211_chandef_downgrade(chandef);
Johannes Berg6565ec92013-02-08 14:52:32 +0100309 }
310
Johannes Berg5cdaed12013-07-31 11:23:06 +0200311 if (chandef->width != vht_chandef.width && !tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100312 sdata_info(sdata,
313 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
314
315 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
316 return ret;
317}
318
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100319static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
320 struct sta_info *sta,
Eliad Peller53b954e2014-07-24 11:20:05 +0300321 const struct ieee80211_ht_cap *ht_cap,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100322 const struct ieee80211_ht_operation *ht_oper,
323 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300324 const struct ieee80211_he_operation *he_oper,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100325 const u8 *bssid, u32 *changed)
Johannes Bergd5522e02009-03-30 13:23:35 +0200326{
327 struct ieee80211_local *local = sdata->local;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100328 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300329 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
330 struct ieee80211_supported_band *sband =
331 local->hw.wiphy->bands[chan->band];
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100332 struct cfg80211_chan_def chandef;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200333 u16 ht_opmode;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100334 u32 flags;
335 enum ieee80211_sta_rx_bandwidth new_sta_bw;
336 int ret;
337
338 /* if HT was/is disabled, don't track any bandwidth changes */
339 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
340 return 0;
341
342 /* don't check VHT if we associated as non-VHT station */
343 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
344 vht_oper = NULL;
Johannes Bergd5522e02009-03-30 13:23:35 +0200345
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300346 /* don't check HE if we associated as non-HE station */
347 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
348 !ieee80211_get_he_sta_cap(sband))
349 he_oper = NULL;
350
Johannes Berg11289582013-02-07 17:36:12 +0100351 if (WARN_ON_ONCE(!sta))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100352 return -EINVAL;
Johannes Berg11289582013-02-07 17:36:12 +0100353
Avri Altman017b45b2013-11-18 19:06:48 +0200354 /*
355 * if bss configuration changed store the new one -
356 * this may be applicable even if channel is identical
357 */
358 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
359 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
360 *changed |= BSS_CHANGED_HT;
361 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
362 }
363
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300364 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
Eliad Peller53b954e2014-07-24 11:20:05 +0300365 flags = ieee80211_determine_chantype(sdata, sband, chan,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300366 ht_oper, vht_oper, he_oper,
Eliad Peller53b954e2014-07-24 11:20:05 +0300367 &chandef, true);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100368
369 /*
370 * Downgrade the new channel if we associated with restricted
371 * capabilities. For example, if we associated as a 20 MHz STA
372 * to a 40 MHz AP (due to regulatory, capabilities or config
373 * reasons) then switching to a 40 MHz channel now won't do us
374 * any good -- we couldn't use it with the AP.
375 */
376 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
377 chandef.width == NL80211_CHAN_WIDTH_80P80)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200378 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100379 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
380 chandef.width == NL80211_CHAN_WIDTH_160)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200381 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100382 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
383 chandef.width > NL80211_CHAN_WIDTH_20)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200384 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100385
386 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
387 return 0;
388
389 sdata_info(sdata,
390 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
391 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
392 chandef.center_freq1, chandef.center_freq2);
393
394 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
395 IEEE80211_STA_DISABLE_VHT |
396 IEEE80211_STA_DISABLE_40MHZ |
397 IEEE80211_STA_DISABLE_80P80MHZ |
398 IEEE80211_STA_DISABLE_160MHZ)) ||
399 !cfg80211_chandef_valid(&chandef)) {
400 sdata_info(sdata,
401 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
402 ifmgd->bssid);
403 return -EINVAL;
Johannes Berg64f68e52012-03-28 10:58:37 +0200404 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200405
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100406 switch (chandef.width) {
407 case NL80211_CHAN_WIDTH_20_NOHT:
408 case NL80211_CHAN_WIDTH_20:
409 new_sta_bw = IEEE80211_STA_RX_BW_20;
410 break;
411 case NL80211_CHAN_WIDTH_40:
412 new_sta_bw = IEEE80211_STA_RX_BW_40;
413 break;
414 case NL80211_CHAN_WIDTH_80:
415 new_sta_bw = IEEE80211_STA_RX_BW_80;
416 break;
417 case NL80211_CHAN_WIDTH_80P80:
418 case NL80211_CHAN_WIDTH_160:
419 new_sta_bw = IEEE80211_STA_RX_BW_160;
420 break;
421 default:
422 return -EINVAL;
423 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200424
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100425 if (new_sta_bw > sta->cur_max_bandwidth)
426 new_sta_bw = sta->cur_max_bandwidth;
Johannes Berg64f68e52012-03-28 10:58:37 +0200427
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100428 if (new_sta_bw < sta->sta.bandwidth) {
429 sta->sta.bandwidth = new_sta_bw;
430 rate_control_rate_update(local, sband, sta,
431 IEEE80211_RC_BW_CHANGED);
432 }
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530433
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100434 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
435 if (ret) {
436 sdata_info(sdata,
437 "AP %pM changed bandwidth to incompatible one - disconnect\n",
438 ifmgd->bssid);
439 return ret;
440 }
441
442 if (new_sta_bw > sta->sta.bandwidth) {
443 sta->sta.bandwidth = new_sta_bw;
444 rate_control_rate_update(local, sband, sta,
445 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200446 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200447
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100448 return 0;
Johannes Bergd5522e02009-03-30 13:23:35 +0200449}
450
Johannes Berg9c6bd792008-09-11 00:01:52 +0200451/* frame sending functions */
452
Johannes Berg66e67e42012-01-20 13:55:27 +0100453static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200454 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100455 struct ieee80211_supported_band *sband,
456 struct ieee80211_channel *channel,
457 enum ieee80211_smps_mode smps)
458{
Johannes Berg66e67e42012-01-20 13:55:27 +0100459 u8 *pos;
460 u32 flags = channel->flags;
461 u16 cap;
462 struct ieee80211_sta_ht_cap ht_cap;
463
464 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
465
Johannes Berg66e67e42012-01-20 13:55:27 +0100466 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
467 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
468
Johannes Berg66e67e42012-01-20 13:55:27 +0100469 /* determine capability flags */
470 cap = ht_cap.cap;
471
Johannes Berg9dde6422012-05-16 23:43:19 +0200472 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100473 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
474 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
475 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
476 cap &= ~IEEE80211_HT_CAP_SGI_40;
477 }
478 break;
479 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
480 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
481 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
482 cap &= ~IEEE80211_HT_CAP_SGI_40;
483 }
484 break;
485 }
486
Johannes Berg24398e32012-03-28 10:58:36 +0200487 /*
488 * If 40 MHz was disabled associate as though we weren't
489 * capable of 40 MHz -- some broken APs will never fall
490 * back to trying to transmit in 20 MHz.
491 */
492 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
493 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
494 cap &= ~IEEE80211_HT_CAP_SGI_40;
495 }
496
Johannes Berg66e67e42012-01-20 13:55:27 +0100497 /* set SM PS mode properly */
498 cap &= ~IEEE80211_HT_CAP_SM_PS;
499 switch (smps) {
500 case IEEE80211_SMPS_AUTOMATIC:
501 case IEEE80211_SMPS_NUM_MODES:
502 WARN_ON(1);
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500503 /* fall through */
Johannes Berg66e67e42012-01-20 13:55:27 +0100504 case IEEE80211_SMPS_OFF:
505 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
506 IEEE80211_HT_CAP_SM_PS_SHIFT;
507 break;
508 case IEEE80211_SMPS_STATIC:
509 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
510 IEEE80211_HT_CAP_SM_PS_SHIFT;
511 break;
512 case IEEE80211_SMPS_DYNAMIC:
513 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
514 IEEE80211_HT_CAP_SM_PS_SHIFT;
515 break;
516 }
517
518 /* reserve and fill IE */
519 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
520 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
521}
522
Sara Sharon322cd402015-07-08 15:41:43 +0300523/* This function determines vht capability flags for the association
524 * and builds the IE.
525 * Note - the function may set the owner of the MU-MIMO capability
526 */
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000527static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
528 struct sk_buff *skb,
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100529 struct ieee80211_supported_band *sband,
530 struct ieee80211_vht_cap *ap_vht_cap)
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000531{
Sara Sharon322cd402015-07-08 15:41:43 +0300532 struct ieee80211_local *local = sdata->local;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000533 u8 *pos;
534 u32 cap;
535 struct ieee80211_sta_vht_cap vht_cap;
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200536 u32 mask, ap_bf_sts, our_bf_sts;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000537
538 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
539
540 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +0100541 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000542
543 /* determine capability flags */
544 cap = vht_cap.cap;
545
Johannes Bergf2d9d272012-11-22 14:11:39 +0100546 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
Johannes Berg575f0532014-11-24 16:51:33 +0100547 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
548
549 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
550 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
551 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
552 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100553 }
554
555 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
556 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
Johannes Berg575f0532014-11-24 16:51:33 +0100557 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100558 }
559
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100560 /*
561 * Some APs apparently get confused if our capabilities are better
562 * than theirs, so restrict what we advertise in the assoc request.
563 */
564 if (!(ap_vht_cap->vht_cap_info &
565 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
Sara Sharon322cd402015-07-08 15:41:43 +0300566 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
567 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
568 else if (!(ap_vht_cap->vht_cap_info &
569 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
570 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
571
572 /*
573 * If some other vif is using the MU-MIMO capablity we cannot associate
574 * using MU-MIMO - this will lead to contradictions in the group-id
575 * mechanism.
576 * Ownership is defined since association request, in order to avoid
577 * simultaneous associations with MU-MIMO.
578 */
579 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
580 bool disable_mu_mimo = false;
581 struct ieee80211_sub_if_data *other;
582
583 list_for_each_entry_rcu(other, &local->interfaces, list) {
Sara Sharonb5a33d52016-02-16 12:48:18 +0200584 if (other->vif.mu_mimo_owner) {
Sara Sharon322cd402015-07-08 15:41:43 +0300585 disable_mu_mimo = true;
586 break;
587 }
588 }
589 if (disable_mu_mimo)
590 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
591 else
Sara Sharonb5a33d52016-02-16 12:48:18 +0200592 sdata->vif.mu_mimo_owner = true;
Sara Sharon322cd402015-07-08 15:41:43 +0300593 }
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100594
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200595 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
596
597 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
598 our_bf_sts = cap & mask;
599
600 if (ap_bf_sts < our_bf_sts) {
601 cap &= ~mask;
602 cap |= ap_bf_sts;
603 }
604
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000605 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000606 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000607 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
608}
609
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300610/* This function determines HE capability flags for the association
611 * and builds the IE.
612 */
613static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
614 struct sk_buff *skb,
615 struct ieee80211_supported_band *sband)
616{
617 u8 *pos;
618 const struct ieee80211_sta_he_cap *he_cap = NULL;
619 u8 he_cap_size;
620
621 he_cap = ieee80211_get_he_sta_cap(sband);
622 if (!he_cap)
623 return;
624
625 /*
626 * TODO: the 1 added is because this temporarily is under the EXTENSION
627 * IE. Get rid of it when it moves.
628 */
629 he_cap_size =
630 2 + 1 + sizeof(he_cap->he_cap_elem) +
631 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
632 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
633 he_cap->he_cap_elem.phy_cap_info);
634 pos = skb_put(skb, he_cap_size);
635 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
636}
637
Johannes Berg66e67e42012-01-20 13:55:27 +0100638static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
639{
640 struct ieee80211_local *local = sdata->local;
641 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
642 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
643 struct sk_buff *skb;
644 struct ieee80211_mgmt *mgmt;
Jouni Malinen4d9ec732019-02-15 02:14:33 +0200645 u8 *pos, qos_info, *ie_start;
Johannes Berg66e67e42012-01-20 13:55:27 +0100646 size_t offset = 0, noffset;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200647 int i, count, rates_len, supp_rates_len, shift;
Johannes Berg66e67e42012-01-20 13:55:27 +0100648 u16 capab;
649 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200650 struct ieee80211_chanctx_conf *chanctx_conf;
651 struct ieee80211_channel *chan;
Johannes Berg44f6d422017-06-10 13:52:44 +0300652 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100653
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200654 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +0100655
Johannes Berg55de9082012-07-26 17:24:39 +0200656 rcu_read_lock();
657 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
658 if (WARN_ON(!chanctx_conf)) {
659 rcu_read_unlock();
660 return;
661 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100662 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200663 rcu_read_unlock();
664 sband = local->hw.wiphy->bands[chan->band];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200665 shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg66e67e42012-01-20 13:55:27 +0100666
667 if (assoc_data->supp_rates_len) {
668 /*
669 * Get all rates supported by the device and the AP as
670 * some APs don't like getting a superset of their rates
671 * in the association request (e.g. D-Link DAP 1353 in
672 * b-only mode)...
673 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200674 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
675 assoc_data->supp_rates,
676 assoc_data->supp_rates_len,
677 &rates);
Johannes Berg66e67e42012-01-20 13:55:27 +0100678 } else {
679 /*
680 * In case AP not provide any supported rates information
681 * before association, we send information element(s) with
682 * all rates that we support.
683 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200684 rates_len = 0;
685 for (i = 0; i < sband->n_bitrates; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200686 rates |= BIT(i);
687 rates_len++;
688 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100689 }
690
691 skb = alloc_skb(local->hw.extra_tx_headroom +
692 sizeof(*mgmt) + /* bit too much but doesn't matter */
693 2 + assoc_data->ssid_len + /* SSID */
694 4 + rates_len + /* (extended) rates */
695 4 + /* power capability */
696 2 + 2 * sband->n_channels + /* supported channels */
697 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000698 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300699 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
700 sizeof(struct ieee80211_he_mcs_nss_supp) +
701 IEEE80211_HE_PPE_THRES_MAX_LEN +
Johannes Berg66e67e42012-01-20 13:55:27 +0100702 assoc_data->ie_len + /* extra IEs */
Jouni Malinen39404fe2016-10-27 00:42:05 +0300703 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
Johannes Berg66e67e42012-01-20 13:55:27 +0100704 9, /* WMM */
705 GFP_KERNEL);
706 if (!skb)
707 return;
708
709 skb_reserve(skb, local->hw.extra_tx_headroom);
710
711 capab = WLAN_CAPABILITY_ESS;
712
Johannes Berg57fbcce2016-04-12 15:56:15 +0200713 if (sband->band == NL80211_BAND_2GHZ) {
Johannes Bergea1b2b452015-06-02 20:15:49 +0200714 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
715 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
Johannes Berg66e67e42012-01-20 13:55:27 +0100716 }
717
718 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
719 capab |= WLAN_CAPABILITY_PRIVACY;
720
721 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg30686bf2015-06-02 21:39:54 +0200722 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
Johannes Berg66e67e42012-01-20 13:55:27 +0100723 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
724
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300725 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
726 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
727
Johannes Bergb080db52017-06-16 14:29:19 +0200728 mgmt = skb_put_zero(skb, 24);
Johannes Berg66e67e42012-01-20 13:55:27 +0100729 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
730 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
731 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
732
733 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
734 skb_put(skb, 10);
735 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
736 IEEE80211_STYPE_REASSOC_REQ);
737 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
738 mgmt->u.reassoc_req.listen_interval =
739 cpu_to_le16(local->hw.conf.listen_interval);
740 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
741 ETH_ALEN);
742 } else {
743 skb_put(skb, 4);
744 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
745 IEEE80211_STYPE_ASSOC_REQ);
746 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
747 mgmt->u.assoc_req.listen_interval =
748 cpu_to_le16(local->hw.conf.listen_interval);
749 }
750
751 /* SSID */
752 pos = skb_put(skb, 2 + assoc_data->ssid_len);
Jouni Malinen4d9ec732019-02-15 02:14:33 +0200753 ie_start = pos;
Johannes Berg66e67e42012-01-20 13:55:27 +0100754 *pos++ = WLAN_EID_SSID;
755 *pos++ = assoc_data->ssid_len;
756 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
757
758 /* add all rates which were marked to be used above */
759 supp_rates_len = rates_len;
760 if (supp_rates_len > 8)
761 supp_rates_len = 8;
762
763 pos = skb_put(skb, supp_rates_len + 2);
764 *pos++ = WLAN_EID_SUPP_RATES;
765 *pos++ = supp_rates_len;
766
767 count = 0;
768 for (i = 0; i < sband->n_bitrates; i++) {
769 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200770 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
771 5 * (1 << shift));
772 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100773 if (++count == 8)
774 break;
775 }
776 }
777
778 if (rates_len > count) {
779 pos = skb_put(skb, rates_len - count + 2);
780 *pos++ = WLAN_EID_EXT_SUPP_RATES;
781 *pos++ = rates_len - count;
782
783 for (i++; i < sband->n_bitrates; i++) {
784 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200785 int rate;
786 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
787 5 * (1 << shift));
788 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100789 }
790 }
791 }
792
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300793 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
794 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100795 pos = skb_put(skb, 4);
796 *pos++ = WLAN_EID_PWR_CAPABILITY;
797 *pos++ = 2;
798 *pos++ = 0; /* min tx power */
Simon Wunderlich0430c882013-07-08 16:55:55 +0200799 /* max tx power */
800 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300801 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100802
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300803 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100804 /* TODO: get this in reg domain format */
805 pos = skb_put(skb, 2 * sband->n_channels + 2);
806 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
807 *pos++ = 2 * sband->n_channels;
808 for (i = 0; i < sband->n_channels; i++) {
809 *pos++ = ieee80211_frequency_to_channel(
810 sband->channels[i].center_freq);
811 *pos++ = 1; /* one channel in the subband*/
812 }
813 }
814
Sara Sharoncaf56332019-01-16 23:03:25 +0200815 /* Set MBSSID support for HE AP if needed */
816 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
817 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len) {
818 struct element *elem;
819
820 /* we know it's writable, cast away the const */
821 elem = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
822 assoc_data->ie,
823 assoc_data->ie_len);
824
825 /* We can probably assume both always true */
826 if (elem && elem->datalen >= 3)
827 elem->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
828 }
829
Johannes Berg66e67e42012-01-20 13:55:27 +0100830 /* if present, add any custom IEs that go before HT */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200831 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100832 static const u8 before_ht[] = {
833 WLAN_EID_SSID,
834 WLAN_EID_SUPP_RATES,
835 WLAN_EID_EXT_SUPP_RATES,
836 WLAN_EID_PWR_CAPABILITY,
837 WLAN_EID_SUPPORTED_CHANNELS,
838 WLAN_EID_RSN,
839 WLAN_EID_QOS_CAPA,
840 WLAN_EID_RRM_ENABLED_CAPABILITIES,
841 WLAN_EID_MOBILITY_DOMAIN,
Johannes Berg8ed28742014-10-27 12:03:19 +0100842 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
843 WLAN_EID_RIC_DATA, /* reassoc only */
Johannes Berg66e67e42012-01-20 13:55:27 +0100844 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
845 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100846 static const u8 after_ric[] = {
847 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
848 WLAN_EID_HT_CAPABILITY,
849 WLAN_EID_BSS_COEX_2040,
Johannes Berga7f26d82017-08-05 11:44:32 +0300850 /* luckily this is almost always there */
Johannes Berg8ed28742014-10-27 12:03:19 +0100851 WLAN_EID_EXT_CAPABILITY,
852 WLAN_EID_QOS_TRAFFIC_CAPA,
853 WLAN_EID_TIM_BCAST_REQ,
854 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300855 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg8ed28742014-10-27 12:03:19 +0100856 WLAN_EID_VHT_CAPABILITY,
857 WLAN_EID_OPMODE_NOTIF,
858 };
859
860 noffset = ieee80211_ie_split_ric(assoc_data->ie,
861 assoc_data->ie_len,
862 before_ht,
863 ARRAY_SIZE(before_ht),
864 after_ric,
865 ARRAY_SIZE(after_ric),
866 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800867 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100868 offset = noffset;
869 }
870
Johannes Bergf2d9d272012-11-22 14:11:39 +0100871 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
872 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
873 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
874
Johannes Berga8243b72012-11-22 14:32:09 +0100875 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200876 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200877 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100878
Johannes Berg3de38022014-02-04 09:54:07 +0100879 /* if present, add any custom IEs that go before VHT */
880 if (assoc_data->ie_len) {
881 static const u8 before_vht[] = {
Johannes Berga7f26d82017-08-05 11:44:32 +0300882 /*
883 * no need to list the ones split off before HT
884 * or generated here
885 */
Johannes Berg3de38022014-02-04 09:54:07 +0100886 WLAN_EID_BSS_COEX_2040,
887 WLAN_EID_EXT_CAPABILITY,
888 WLAN_EID_QOS_TRAFFIC_CAPA,
889 WLAN_EID_TIM_BCAST_REQ,
890 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300891 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg3de38022014-02-04 09:54:07 +0100892 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100893
894 /* RIC already taken above, so no need to handle here anymore */
Johannes Berg3de38022014-02-04 09:54:07 +0100895 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
896 before_vht, ARRAY_SIZE(before_vht),
897 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800898 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg3de38022014-02-04 09:54:07 +0100899 offset = noffset;
900 }
901
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300902 /* if present, add any custom IEs that go before HE */
903 if (assoc_data->ie_len) {
904 static const u8 before_he[] = {
905 /*
906 * no need to list the ones split off before VHT
907 * or generated here
908 */
909 WLAN_EID_OPMODE_NOTIF,
910 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
911 /* 11ai elements */
912 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
913 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
914 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
915 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
916 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
917 /* TODO: add 11ah/11aj/11ak elements */
918 };
919
920 /* RIC already taken above, so no need to handle here anymore */
921 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
922 before_he, ARRAY_SIZE(before_he),
923 offset);
924 pos = skb_put(skb, noffset - offset);
925 memcpy(pos, assoc_data->ie + offset, noffset - offset);
926 offset = noffset;
927 }
928
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000929 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100930 ieee80211_add_vht_ie(sdata, skb, sband,
931 &assoc_data->ap_vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000932
Shaul Triebitzdc7eb0f2018-12-15 11:03:20 +0200933 /*
934 * If AP doesn't support HT, mark HE as disabled.
935 * If on the 5GHz band, make sure it supports VHT.
936 */
937 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
938 (sband->band == NL80211_BAND_5GHZ &&
939 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
940 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
941
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300942 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
943 ieee80211_add_he_ie(sdata, skb, sband);
944
945 /* if present, add any custom non-vendor IEs that go after HE */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200946 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100947 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
948 assoc_data->ie_len,
949 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800950 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100951 offset = noffset;
952 }
953
Johannes Berg76f03032012-03-08 15:02:05 +0100954 if (assoc_data->wmm) {
955 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200956 qos_info = ifmgd->uapsd_queues;
957 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100958 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
959 } else {
960 qos_info = 0;
961 }
962
Arik Nemtsov40b861a2014-07-17 17:14:23 +0300963 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
Johannes Berg66e67e42012-01-20 13:55:27 +0100964 }
965
966 /* add any remaining custom (i.e. vendor specific here) IEs */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200967 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100968 noffset = assoc_data->ie_len;
yuan linyub952f4d2017-06-18 22:52:04 +0800969 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100970 }
971
Jouni Malinen39404fe2016-10-27 00:42:05 +0300972 if (assoc_data->fils_kek_len &&
973 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
974 dev_kfree_skb(skb);
975 return;
976 }
977
Jouni Malinen4d9ec732019-02-15 02:14:33 +0200978 pos = skb_tail_pointer(skb);
979 kfree(ifmgd->assoc_req_ies);
980 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
981 ifmgd->assoc_req_ies_len = pos - ie_start;
982
Ilan Peerd4e36e52018-04-20 13:49:25 +0300983 drv_mgd_prepare_tx(local, sdata, 0);
Johannes Berga1845fc2012-06-27 13:18:36 +0200984
Johannes Berg66e67e42012-01-20 13:55:27 +0100985 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Johannes Berg30686bf2015-06-02 21:39:54 +0200986 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +0100987 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
988 IEEE80211_TX_INTFL_MLME_CONN_TX;
Johannes Berg66e67e42012-01-20 13:55:27 +0100989 ieee80211_tx_skb(sdata, skb);
990}
991
Kalle Valo572e0012009-02-10 17:09:31 +0200992void ieee80211_send_pspoll(struct ieee80211_local *local,
993 struct ieee80211_sub_if_data *sdata)
994{
Kalle Valo572e0012009-02-10 17:09:31 +0200995 struct ieee80211_pspoll *pspoll;
996 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200997
Kalle Valod8cd1892010-01-05 20:16:26 +0200998 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
999 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +02001000 return;
Kalle Valo572e0012009-02-10 17:09:31 +02001001
Kalle Valod8cd1892010-01-05 20:16:26 +02001002 pspoll = (struct ieee80211_pspoll *) skb->data;
1003 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +02001004
Johannes Berg62ae67b2009-11-18 18:42:05 +01001005 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1006 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +02001007}
1008
Johannes Berg965beda2009-04-16 13:17:24 +02001009void ieee80211_send_nullfunc(struct ieee80211_local *local,
1010 struct ieee80211_sub_if_data *sdata,
Johannes Berg076cdcb2015-09-24 16:14:55 +02001011 bool powersave)
Johannes Berg965beda2009-04-16 13:17:24 +02001012{
1013 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +02001014 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +05301015 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +02001016
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001017 /* Don't send NDPs when STA is connected HE */
1018 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1019 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
1020 return;
1021
Ben Caradoc-Davies7c181f42018-03-19 12:57:44 +13001022 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1023 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
Kalle Valod8cd1892010-01-05 20:16:26 +02001024 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +02001025 return;
1026
Kalle Valod8cd1892010-01-05 20:16:26 +02001027 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +02001028 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +02001029 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +02001030
Seth Forshee6c17b772013-02-11 11:21:07 -06001031 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1032 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Pontus Fuchsff40b422013-06-04 12:44:52 +02001033
Johannes Berg30686bf2015-06-02 21:39:54 +02001034 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Pontus Fuchsff40b422013-06-04 12:44:52 +02001035 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1036
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001037 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +05301038 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1039
Johannes Berg62ae67b2009-11-18 18:42:05 +01001040 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +02001041}
1042
Felix Fietkaud5242152010-01-08 18:06:26 +01001043static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1044 struct ieee80211_sub_if_data *sdata)
1045{
1046 struct sk_buff *skb;
1047 struct ieee80211_hdr *nullfunc;
1048 __le16 fc;
1049
1050 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1051 return;
1052
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001053 /* Don't send NDPs when connected HE */
1054 if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE))
1055 return;
1056
Felix Fietkaud5242152010-01-08 18:06:26 +01001057 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -07001058 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +01001059 return;
Joe Perchesd15b8452011-08-29 14:17:31 -07001060
Felix Fietkaud5242152010-01-08 18:06:26 +01001061 skb_reserve(skb, local->hw.extra_tx_headroom);
1062
Johannes Bergb080db52017-06-16 14:29:19 +02001063 nullfunc = skb_put_zero(skb, 30);
Felix Fietkaud5242152010-01-08 18:06:26 +01001064 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1065 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1066 nullfunc->frame_control = fc;
1067 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1068 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1069 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1070 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1071
1072 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1073 ieee80211_tx_skb(sdata, skb);
1074}
1075
Johannes Bergcc32abd2009-05-15 11:52:31 +02001076/* spectrum management related things */
1077static void ieee80211_chswitch_work(struct work_struct *work)
1078{
1079 struct ieee80211_sub_if_data *sdata =
1080 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Karl Beldan675a0b02013-03-25 16:26:57 +01001081 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001082 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001083 int ret;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001084
Johannes Berg9607e6b662009-12-23 13:15:31 +01001085 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +02001086 return;
1087
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001088 sdata_lock(sdata);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001089 mutex_lock(&local->mtx);
1090 mutex_lock(&local->chanctx_mtx);
1091
Johannes Berg77fdaa12009-07-07 03:45:17 +02001092 if (!ifmgd->associated)
1093 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001094
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001095 if (!sdata->vif.csa_active)
1096 goto out;
1097
1098 /*
1099 * using reservation isn't immediate as it may be deferred until later
1100 * with multi-vif. once reservation is complete it will re-schedule the
1101 * work with no reserved_chanctx so verify chandef to check if it
1102 * completed successfully
1103 */
1104
1105 if (sdata->reserved_chanctx) {
Ilan Peer0007e942018-08-31 11:31:10 +03001106 struct ieee80211_supported_band *sband = NULL;
1107 struct sta_info *mgd_sta = NULL;
1108 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
1109
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001110 /*
1111 * with multi-vif csa driver may call ieee80211_csa_finish()
1112 * many times while waiting for other interfaces to use their
1113 * reservations
1114 */
1115 if (sdata->reserved_ready)
1116 goto out;
1117
Ilan Peer0007e942018-08-31 11:31:10 +03001118 if (sdata->vif.bss_conf.chandef.width !=
1119 sdata->csa_chandef.width) {
1120 /*
1121 * For managed interface, we need to also update the AP
1122 * station bandwidth and align the rate scale algorithm
1123 * on the bandwidth change. Here we only consider the
1124 * bandwidth of the new channel definition (as channel
1125 * switch flow does not have the full HT/VHT/HE
1126 * information), assuming that if additional changes are
1127 * required they would be done as part of the processing
1128 * of the next beacon from the AP.
1129 */
1130 switch (sdata->csa_chandef.width) {
1131 case NL80211_CHAN_WIDTH_20_NOHT:
1132 case NL80211_CHAN_WIDTH_20:
1133 default:
1134 bw = IEEE80211_STA_RX_BW_20;
1135 break;
1136 case NL80211_CHAN_WIDTH_40:
1137 bw = IEEE80211_STA_RX_BW_40;
1138 break;
1139 case NL80211_CHAN_WIDTH_80:
1140 bw = IEEE80211_STA_RX_BW_80;
1141 break;
1142 case NL80211_CHAN_WIDTH_80P80:
1143 case NL80211_CHAN_WIDTH_160:
1144 bw = IEEE80211_STA_RX_BW_160;
1145 break;
1146 }
1147
1148 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1149 sband =
1150 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1151 }
1152
1153 if (sdata->vif.bss_conf.chandef.width >
1154 sdata->csa_chandef.width) {
1155 mgd_sta->sta.bandwidth = bw;
1156 rate_control_rate_update(local, sband, mgd_sta,
1157 IEEE80211_RC_BW_CHANGED);
1158 }
1159
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001160 ret = ieee80211_vif_use_reserved_context(sdata);
1161 if (ret) {
1162 sdata_info(sdata,
1163 "failed to use reserved channel context, disconnecting (err=%d)\n",
1164 ret);
1165 ieee80211_queue_work(&sdata->local->hw,
1166 &ifmgd->csa_connection_drop_work);
1167 goto out;
1168 }
1169
Ilan Peer0007e942018-08-31 11:31:10 +03001170 if (sdata->vif.bss_conf.chandef.width <
1171 sdata->csa_chandef.width) {
1172 mgd_sta->sta.bandwidth = bw;
1173 rate_control_rate_update(local, sband, mgd_sta,
1174 IEEE80211_RC_BW_CHANGED);
1175 }
1176
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001177 goto out;
1178 }
1179
1180 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1181 &sdata->csa_chandef)) {
Arik Nemtsov7578d572013-09-01 17:15:51 +03001182 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001183 "failed to finalize channel switch, disconnecting\n");
Arik Nemtsov7578d572013-09-01 17:15:51 +03001184 ieee80211_queue_work(&sdata->local->hw,
1185 &ifmgd->csa_connection_drop_work);
1186 goto out;
1187 }
Karl Beldan675a0b02013-03-25 16:26:57 +01001188
Luciano Coelho0c21e632014-10-08 09:48:39 +03001189 ifmgd->csa_waiting_bcn = true;
Luciano Coelhof1d65582014-10-08 09:48:38 +03001190
Michal Kaziore5593f52014-04-09 15:45:36 +02001191 ieee80211_sta_reset_beacon_monitor(sdata);
1192 ieee80211_sta_reset_conn_monitor(sdata);
1193
Michal Kazior59af6922014-04-09 15:10:59 +02001194out:
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001195 mutex_unlock(&local->chanctx_mtx);
1196 mutex_unlock(&local->mtx);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001197 sdata_unlock(sdata);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001198}
1199
Luciano Coelho0c21e632014-10-08 09:48:39 +03001200static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1201{
1202 struct ieee80211_local *local = sdata->local;
1203 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1204 int ret;
1205
1206 sdata_assert_lock(sdata);
1207
1208 WARN_ON(!sdata->vif.csa_active);
1209
1210 if (sdata->csa_block_tx) {
1211 ieee80211_wake_vif_queues(local, sdata,
1212 IEEE80211_QUEUE_STOP_REASON_CSA);
1213 sdata->csa_block_tx = false;
1214 }
1215
1216 sdata->vif.csa_active = false;
1217 ifmgd->csa_waiting_bcn = false;
1218
1219 ret = drv_post_channel_switch(sdata);
1220 if (ret) {
1221 sdata_info(sdata,
1222 "driver post channel switch failed, disconnecting\n");
1223 ieee80211_queue_work(&local->hw,
1224 &ifmgd->csa_connection_drop_work);
1225 return;
1226 }
Luciano Coelho688b1ec2014-12-16 16:01:39 +02001227
1228 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
Luciano Coelho0c21e632014-10-08 09:48:39 +03001229}
1230
Johannes Berg5ce6e432010-05-11 16:20:57 +02001231void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1232{
Johannes Berg55de9082012-07-26 17:24:39 +02001233 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1234 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001235
1236 trace_api_chswitch_done(sdata, success);
1237 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001238 sdata_info(sdata,
1239 "driver channel switch failed, disconnecting\n");
1240 ieee80211_queue_work(&sdata->local->hw,
1241 &ifmgd->csa_connection_drop_work);
1242 } else {
1243 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001244 }
Johannes Berg5ce6e432010-05-11 16:20:57 +02001245}
1246EXPORT_SYMBOL(ieee80211_chswitch_done);
1247
Kees Cook34f11cd2017-10-16 16:35:49 -07001248static void ieee80211_chswitch_timer(struct timer_list *t)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001249{
1250 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07001251 from_timer(sdata, t, u.mgd.chswitch_timer);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001252
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01001253 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001254}
1255
Johannes Berg37799e52013-03-26 14:02:26 +01001256static void
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001257ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata)
1258{
1259 struct ieee80211_local *local = sdata->local;
1260
1261 if (!local->ops->abort_channel_switch)
1262 return;
1263
1264 mutex_lock(&local->mtx);
1265
1266 mutex_lock(&local->chanctx_mtx);
1267 ieee80211_vif_unreserve_chanctx(sdata);
1268 mutex_unlock(&local->chanctx_mtx);
1269
1270 if (sdata->csa_block_tx)
1271 ieee80211_wake_vif_queues(local, sdata,
1272 IEEE80211_QUEUE_STOP_REASON_CSA);
1273
1274 sdata->csa_block_tx = false;
1275 sdata->vif.csa_active = false;
1276
1277 mutex_unlock(&local->mtx);
1278
1279 drv_abort_channel_switch(sdata);
1280}
1281
1282static void
Johannes Berg4a3cb702013-02-12 16:43:19 +01001283ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03001284 u64 timestamp, u32 device_timestamp,
1285 struct ieee802_11_elems *elems,
Johannes Berg04a161f2013-05-03 09:35:35 +02001286 bool beacon)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001287{
Johannes Bergb4f286a12013-03-26 14:13:58 +01001288 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001289 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg37799e52013-03-26 14:02:26 +01001290 struct cfg80211_bss *cbss = ifmgd->associated;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001291 struct ieee80211_chanctx_conf *conf;
Johannes Berg55de9082012-07-26 17:24:39 +02001292 struct ieee80211_chanctx *chanctx;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001293 enum nl80211_band current_band;
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001294 struct ieee80211_csa_ie csa_ie;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001295 struct ieee80211_channel_switch ch_switch;
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001296 int res;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001297
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001298 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001299
Johannes Berg37799e52013-03-26 14:02:26 +01001300 if (!cbss)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001301 return;
1302
Johannes Bergb4f286a12013-03-26 14:13:58 +01001303 if (local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001304 return;
1305
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001306 current_band = cbss->channel->band;
Luciano Coelho84469a42014-10-28 13:33:04 +02001307 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001308 ifmgd->flags,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001309 ifmgd->associated->bssid, &csa_ie);
Sara Sharonfafd2bc2019-02-06 13:17:15 +02001310
1311 if (!res) {
1312 ch_switch.timestamp = timestamp;
1313 ch_switch.device_timestamp = device_timestamp;
Sara Sharon2bf973f2020-01-31 13:12:51 +02001314 ch_switch.block_tx = csa_ie.mode;
Sara Sharonfafd2bc2019-02-06 13:17:15 +02001315 ch_switch.chandef = csa_ie.chandef;
1316 ch_switch.count = csa_ie.count;
1317 ch_switch.delay = csa_ie.max_switch_time;
1318 }
1319
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001320 if (res < 0) {
Johannes Bergb4f286a12013-03-26 14:13:58 +01001321 ieee80211_queue_work(&local->hw,
Johannes Berg882a7c62012-08-01 22:32:45 +02001322 &ifmgd->csa_connection_drop_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001323 return;
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001324 }
1325
Sara Sharonfafd2bc2019-02-06 13:17:15 +02001326 if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) {
1327 if (res)
1328 ieee80211_sta_abort_chanswitch(sdata);
1329 else
1330 drv_channel_switch_rx_beacon(sdata, &ch_switch);
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001331 return;
1332 } else if (sdata->vif.csa_active || res) {
1333 /* disregard subsequent announcements if already processing */
1334 return;
1335 }
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001336
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001337 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
Johannes Berg85220d72013-03-25 18:29:27 +01001338 IEEE80211_CHAN_DISABLED)) {
1339 sdata_info(sdata,
1340 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001341 ifmgd->associated->bssid,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001342 csa_ie.chandef.chan->center_freq,
1343 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1344 csa_ie.chandef.center_freq2);
Johannes Berg85220d72013-03-25 18:29:27 +01001345 ieee80211_queue_work(&local->hw,
1346 &ifmgd->csa_connection_drop_work);
1347 return;
1348 }
1349
Johannes Bergf84eaa12015-03-12 08:53:26 +02001350 if (cfg80211_chandef_identical(&csa_ie.chandef,
Sara Sharon97928752019-02-06 13:17:16 +02001351 &sdata->vif.bss_conf.chandef) &&
1352 (!csa_ie.mode || !beacon)) {
Johannes Bergf84eaa12015-03-12 08:53:26 +02001353 if (ifmgd->csa_ignored_same_chan)
1354 return;
1355 sdata_info(sdata,
1356 "AP %pM tries to chanswitch to same channel, ignore\n",
1357 ifmgd->associated->bssid);
1358 ifmgd->csa_ignored_same_chan = true;
1359 return;
1360 }
1361
Arik Nemtsovc5a71682015-05-19 14:36:48 +03001362 /*
1363 * Drop all TDLS peers - either we disconnect or move to a different
1364 * channel from this point on. There's no telling what our peer will do.
1365 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1366 * have an incompatible wider chandef.
1367 */
1368 ieee80211_teardown_tdls_peers(sdata);
1369
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001370 mutex_lock(&local->mtx);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001371 mutex_lock(&local->chanctx_mtx);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001372 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1373 lockdep_is_held(&local->chanctx_mtx));
1374 if (!conf) {
1375 sdata_info(sdata,
1376 "no channel context assigned to vif?, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001377 goto drop_connection;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001378 }
1379
1380 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1381
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001382 if (local->use_chanctx &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001383 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001384 sdata_info(sdata,
1385 "driver doesn't support chan-switch with channel contexts\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001386 goto drop_connection;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001387 }
1388
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001389 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1390 sdata_info(sdata,
1391 "preparing for channel switch failed, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001392 goto drop_connection;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001393 }
1394
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001395 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1396 chanctx->mode, false);
1397 if (res) {
Johannes Berg55de9082012-07-26 17:24:39 +02001398 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001399 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1400 res);
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001401 goto drop_connection;
Johannes Berg55de9082012-07-26 17:24:39 +02001402 }
Johannes Bergb4f286a12013-03-26 14:13:58 +01001403 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001404
Michal Kazior59af6922014-04-09 15:10:59 +02001405 sdata->vif.csa_active = true;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001406 sdata->csa_chandef = csa_ie.chandef;
Sara Sharon2bf973f2020-01-31 13:12:51 +02001407 sdata->csa_block_tx = csa_ie.mode;
Johannes Bergf84eaa12015-03-12 08:53:26 +02001408 ifmgd->csa_ignored_same_chan = false;
Michal Kazior59af6922014-04-09 15:10:59 +02001409
1410 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03001411 ieee80211_stop_vif_queues(local, sdata,
1412 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02001413 mutex_unlock(&local->mtx);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001414
Luciano Coelho2f457292014-11-07 14:31:36 +02001415 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1416 csa_ie.count);
1417
Johannes Bergb4f286a12013-03-26 14:13:58 +01001418 if (local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +02001419 /* use driver's channel switch callback */
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001420 drv_channel_switch(local, sdata, &ch_switch);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001421 return;
1422 }
1423
1424 /* channel switch handled in software */
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001425 if (csa_ie.count <= 1)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001426 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001427 else
Johannes Bergcc32abd2009-05-15 11:52:31 +02001428 mod_timer(&ifmgd->chswitch_timer,
Luciano Coelhoff1e4172014-10-28 13:33:05 +02001429 TU_TO_EXP_TIME((csa_ie.count - 1) *
1430 cbss->beacon_interval));
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001431 return;
1432 drop_connection:
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03001433 /*
1434 * This is just so that the disconnect flow will know that
1435 * we were trying to switch channel and failed. In case the
1436 * mode is 1 (we are not allowed to Tx), we will know not to
1437 * send a deauthentication frame. Those two fields will be
1438 * reset when the disconnection worker runs.
1439 */
1440 sdata->vif.csa_active = true;
Sara Sharon2bf973f2020-01-31 13:12:51 +02001441 sdata->csa_block_tx = csa_ie.mode;
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03001442
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001443 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1444 mutex_unlock(&local->chanctx_mtx);
1445 mutex_unlock(&local->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001446}
1447
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001448static bool
1449ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1450 struct ieee80211_channel *channel,
1451 const u8 *country_ie, u8 country_ie_len,
1452 const u8 *pwr_constr_elem,
1453 int *chan_pwr, int *pwr_reduction)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001454{
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001455 struct ieee80211_country_ie_triplet *triplet;
1456 int chan = ieee80211_frequency_to_channel(channel->center_freq);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001457 int i, chan_increment;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001458 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001459
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001460 /* Invalid IE */
1461 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001462 return false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001463
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001464 triplet = (void *)(country_ie + 3);
1465 country_ie_len -= 3;
1466
1467 switch (channel->band) {
1468 default:
1469 WARN_ON_ONCE(1);
1470 /* fall through */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001471 case NL80211_BAND_2GHZ:
1472 case NL80211_BAND_60GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001473 chan_increment = 1;
1474 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001475 case NL80211_BAND_5GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001476 chan_increment = 4;
1477 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001478 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001479
1480 /* find channel */
1481 while (country_ie_len >= 3) {
1482 u8 first_channel = triplet->chans.first_channel;
1483
1484 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1485 goto next;
1486
1487 for (i = 0; i < triplet->chans.num_channels; i++) {
1488 if (first_channel + i * chan_increment == chan) {
1489 have_chan_pwr = true;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001490 *chan_pwr = triplet->chans.max_power;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001491 break;
1492 }
1493 }
1494 if (have_chan_pwr)
1495 break;
1496
1497 next:
1498 triplet++;
1499 country_ie_len -= 3;
1500 }
1501
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001502 if (have_chan_pwr && pwr_constr_elem)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001503 *pwr_reduction = *pwr_constr_elem;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001504 else
1505 *pwr_reduction = 0;
1506
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001507 return have_chan_pwr;
1508}
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001509
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001510static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1511 struct ieee80211_channel *channel,
1512 const u8 *cisco_dtpc_ie,
1513 int *pwr_level)
1514{
1515 /* From practical testing, the first data byte of the DTPC element
1516 * seems to contain the requested dBm level, and the CLI on Cisco
1517 * APs clearly state the range is -127 to 127 dBm, which indicates
1518 * a signed byte, although it seemingly never actually goes negative.
1519 * The other byte seems to always be zero.
1520 */
1521 *pwr_level = (__s8)cisco_dtpc_ie[4];
1522}
1523
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001524static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1525 struct ieee80211_channel *channel,
1526 struct ieee80211_mgmt *mgmt,
1527 const u8 *country_ie, u8 country_ie_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001528 const u8 *pwr_constr_ie,
1529 const u8 *cisco_dtpc_ie)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001530{
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001531 bool has_80211h_pwr = false, has_cisco_pwr = false;
1532 int chan_pwr = 0, pwr_reduction_80211h = 0;
1533 int pwr_level_cisco, pwr_level_80211h;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001534 int new_ap_level;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001535 __le16 capab = mgmt->u.probe_resp.capab_info;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001536
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001537 if (country_ie &&
1538 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1539 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001540 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1541 sdata, channel, country_ie, country_ie_len,
1542 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001543 pwr_level_80211h =
1544 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001545 }
1546
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001547 if (cisco_dtpc_ie) {
1548 ieee80211_find_cisco_dtpc(
1549 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1550 has_cisco_pwr = true;
1551 }
1552
1553 if (!has_80211h_pwr && !has_cisco_pwr)
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001554 return 0;
1555
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001556 /* If we have both 802.11h and Cisco DTPC, apply both limits
1557 * by picking the smallest of the two power levels advertised.
1558 */
1559 if (has_80211h_pwr &&
1560 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
Johannes Berga87da0c2015-12-08 16:04:37 +02001561 new_ap_level = pwr_level_80211h;
1562
1563 if (sdata->ap_power_level == new_ap_level)
1564 return 0;
1565
John Linvillecef2fc12015-03-31 10:49:14 -04001566 sdata_dbg(sdata,
1567 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1568 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1569 sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001570 } else { /* has_cisco_pwr is always true here. */
Johannes Berga87da0c2015-12-08 16:04:37 +02001571 new_ap_level = pwr_level_cisco;
1572
1573 if (sdata->ap_power_level == new_ap_level)
1574 return 0;
1575
John Linvillecef2fc12015-03-31 10:49:14 -04001576 sdata_dbg(sdata,
1577 "Limiting TX power to %d dBm as advertised by %pM\n",
1578 pwr_level_cisco, sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001579 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001580
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001581 sdata->ap_power_level = new_ap_level;
1582 if (__ieee80211_recalc_txpower(sdata))
1583 return BSS_CHANGED_TXPOWER;
1584 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001585}
1586
Johannes Berg965beda2009-04-16 13:17:24 +02001587/* powersave */
1588static void ieee80211_enable_ps(struct ieee80211_local *local,
1589 struct ieee80211_sub_if_data *sdata)
1590{
1591 struct ieee80211_conf *conf = &local->hw.conf;
1592
Johannes Bergd5edaed2009-04-22 23:02:51 +02001593 /*
1594 * If we are scanning right now then the parameters will
1595 * take effect when scan finishes.
1596 */
Helmut Schaafbe9c4292009-07-23 12:14:04 +02001597 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +02001598 return;
1599
Johannes Berg965beda2009-04-16 13:17:24 +02001600 if (conf->dynamic_ps_timeout > 0 &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001601 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001602 mod_timer(&local->dynamic_ps_timer, jiffies +
1603 msecs_to_jiffies(conf->dynamic_ps_timeout));
1604 } else {
Johannes Berg30686bf2015-06-02 21:39:54 +02001605 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
Johannes Berg076cdcb2015-09-24 16:14:55 +02001606 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajan375177b2010-02-09 14:50:28 +05301607
Johannes Berg30686bf2015-06-02 21:39:54 +02001608 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1609 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001610 return;
1611
1612 conf->flags |= IEEE80211_CONF_PS;
1613 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +02001614 }
1615}
1616
1617static void ieee80211_change_ps(struct ieee80211_local *local)
1618{
1619 struct ieee80211_conf *conf = &local->hw.conf;
1620
1621 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +02001622 ieee80211_enable_ps(local, local->ps_sdata);
1623 } else if (conf->flags & IEEE80211_CONF_PS) {
1624 conf->flags &= ~IEEE80211_CONF_PS;
1625 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1626 del_timer_sync(&local->dynamic_ps_timer);
1627 cancel_work_sync(&local->dynamic_ps_enable_work);
1628 }
1629}
1630
Jason Young808118c2011-03-10 16:43:19 -08001631static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1632{
1633 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1634 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001635 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001636
1637 if (!mgd->powersave)
1638 return false;
1639
Johannes Berg05cb9102011-10-28 11:59:47 +02001640 if (mgd->broken_ap)
1641 return false;
1642
Jason Young808118c2011-03-10 16:43:19 -08001643 if (!mgd->associated)
1644 return false;
1645
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001646 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
Jason Young808118c2011-03-10 16:43:19 -08001647 return false;
1648
Alexander Bondar989c6502013-05-16 17:34:17 +03001649 if (!mgd->have_beacon)
Alexander Bondarce857882013-05-06 17:17:04 +03001650 return false;
1651
Jason Young808118c2011-03-10 16:43:19 -08001652 rcu_read_lock();
1653 sta = sta_info_get(sdata, mgd->bssid);
1654 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001655 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001656 rcu_read_unlock();
1657
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001658 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001659}
1660
Johannes Berg965beda2009-04-16 13:17:24 +02001661/* need to hold RTNL or interface lock */
Johannes Berg4a733ef2015-10-14 18:02:43 +02001662void ieee80211_recalc_ps(struct ieee80211_local *local)
Johannes Berg965beda2009-04-16 13:17:24 +02001663{
1664 struct ieee80211_sub_if_data *sdata, *found = NULL;
1665 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001666 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001667
Johannes Berg30686bf2015-06-02 21:39:54 +02001668 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001669 local->ps_sdata = NULL;
1670 return;
1671 }
1672
1673 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b662009-12-23 13:15:31 +01001674 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001675 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301676 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1677 /* If an AP vif is found, then disable PS
1678 * by setting the count to zero thereby setting
1679 * ps_sdata to NULL.
1680 */
1681 count = 0;
1682 break;
1683 }
Johannes Berg965beda2009-04-16 13:17:24 +02001684 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1685 continue;
1686 found = sdata;
1687 count++;
1688 }
1689
Jason Young808118c2011-03-10 16:43:19 -08001690 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg4a733ef2015-10-14 18:02:43 +02001691 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg10f644a2009-04-16 13:17:25 +02001692
Juuso Oikarinenff616382010-06-09 09:51:52 +03001693 timeout = local->dynamic_ps_forced_timeout;
Johannes Berg4a733ef2015-10-14 18:02:43 +02001694 if (timeout < 0)
1695 timeout = 100;
Johannes Berg09b85562013-02-06 23:07:41 +01001696 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001697
Johannes Berg4a733ef2015-10-14 18:02:43 +02001698 /* If the TIM IE is invalid, pretend the value is 1 */
1699 if (!dtimper)
1700 dtimper = 1;
Johannes Berg56007a02010-01-26 14:19:52 +01001701
Johannes Berg4a733ef2015-10-14 18:02:43 +02001702 local->hw.conf.ps_dtim_period = dtimper;
1703 local->ps_sdata = found;
Johannes Berg10f644a2009-04-16 13:17:25 +02001704 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001705 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001706 }
Johannes Berg965beda2009-04-16 13:17:24 +02001707
1708 ieee80211_change_ps(local);
1709}
1710
Eliad Pellerab095872012-07-27 12:33:22 +03001711void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1712{
1713 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1714
1715 if (sdata->vif.bss_conf.ps != ps_allowed) {
1716 sdata->vif.bss_conf.ps = ps_allowed;
1717 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1718 }
1719}
1720
Johannes Berg965beda2009-04-16 13:17:24 +02001721void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1722{
1723 struct ieee80211_local *local =
1724 container_of(work, struct ieee80211_local,
1725 dynamic_ps_disable_work);
1726
1727 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1728 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1729 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1730 }
1731
1732 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001733 IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +03001734 IEEE80211_QUEUE_STOP_REASON_PS,
1735 false);
Johannes Berg965beda2009-04-16 13:17:24 +02001736}
1737
1738void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1739{
1740 struct ieee80211_local *local =
1741 container_of(work, struct ieee80211_local,
1742 dynamic_ps_enable_work);
1743 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001744 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301745 unsigned long flags;
1746 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001747
1748 /* can only happen when PS was just disabled anyway */
1749 if (!sdata)
1750 return;
1751
Christian Lamparter5e340692011-06-30 21:08:43 +02001752 ifmgd = &sdata->u.mgd;
1753
Johannes Berg965beda2009-04-16 13:17:24 +02001754 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1755 return;
1756
Johannes Berg09b85562013-02-06 23:07:41 +01001757 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001758 /* don't enter PS if TX frames are pending */
1759 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301760 mod_timer(&local->dynamic_ps_timer, jiffies +
1761 msecs_to_jiffies(
1762 local->hw.conf.dynamic_ps_timeout));
1763 return;
1764 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001765
1766 /*
1767 * transmission can be stopped by others which leads to
1768 * dynamic_ps_timer expiry. Postpone the ps timer if it
1769 * is not the actual idle state.
1770 */
1771 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1772 for (q = 0; q < local->hw.queues; q++) {
1773 if (local->queue_stop_reasons[q]) {
1774 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1775 flags);
1776 mod_timer(&local->dynamic_ps_timer, jiffies +
1777 msecs_to_jiffies(
1778 local->hw.conf.dynamic_ps_timeout));
1779 return;
1780 }
1781 }
1782 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301783 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301784
Johannes Berg30686bf2015-06-02 21:39:54 +02001785 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301786 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Johannes Berga1598382013-03-26 22:02:42 +01001787 if (drv_tx_frames_pending(local)) {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301788 mod_timer(&local->dynamic_ps_timer, jiffies +
1789 msecs_to_jiffies(
1790 local->hw.conf.dynamic_ps_timeout));
Johannes Berga1598382013-03-26 22:02:42 +01001791 } else {
Johannes Berg076cdcb2015-09-24 16:14:55 +02001792 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301793 /* Flush to get the tx status of nullfunc frame */
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001794 ieee80211_flush_queues(local, sdata, false);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301795 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301796 }
1797
Johannes Berg30686bf2015-06-02 21:39:54 +02001798 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1799 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301800 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1801 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1802 local->hw.conf.flags |= IEEE80211_CONF_PS;
1803 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1804 }
Johannes Berg965beda2009-04-16 13:17:24 +02001805}
1806
Kees Cook34f11cd2017-10-16 16:35:49 -07001807void ieee80211_dynamic_ps_timer(struct timer_list *t)
Johannes Berg965beda2009-04-16 13:17:24 +02001808{
Kees Cook34f11cd2017-10-16 16:35:49 -07001809 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
Johannes Berg965beda2009-04-16 13:17:24 +02001810
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001811 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001812}
1813
Simon Wunderlich164eb022013-02-08 18:16:20 +01001814void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1815{
Geliang Tanga85a7e22016-01-01 23:48:52 +08001816 struct delayed_work *delayed_work = to_delayed_work(work);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001817 struct ieee80211_sub_if_data *sdata =
1818 container_of(delayed_work, struct ieee80211_sub_if_data,
1819 dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001820 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlich164eb022013-02-08 18:16:20 +01001821
Johannes Berg34a37402013-12-18 09:43:33 +01001822 mutex_lock(&sdata->local->mtx);
1823 if (sdata->wdev.cac_started) {
1824 ieee80211_vif_release_channel(sdata);
1825 cfg80211_cac_event(sdata->dev, &chandef,
1826 NL80211_RADAR_CAC_FINISHED,
1827 GFP_KERNEL);
1828 }
1829 mutex_unlock(&sdata->local->mtx);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001830}
1831
Johannes Berg02219b32014-10-07 10:38:50 +03001832static bool
1833__ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1834{
1835 struct ieee80211_local *local = sdata->local;
1836 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
John Linvillecc72f6e2015-01-06 14:39:33 -05001837 bool ret = false;
Johannes Berg02219b32014-10-07 10:38:50 +03001838 int ac;
1839
1840 if (local->hw.queues < IEEE80211_NUM_ACS)
1841 return false;
1842
1843 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1844 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1845 int non_acm_ac;
1846 unsigned long now = jiffies;
1847
1848 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1849 tx_tspec->admitted_time &&
1850 time_after(now, tx_tspec->time_slice_start + HZ)) {
1851 tx_tspec->consumed_tx_time = 0;
1852 tx_tspec->time_slice_start = now;
1853
1854 if (tx_tspec->downgraded)
1855 tx_tspec->action =
1856 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1857 }
1858
1859 switch (tx_tspec->action) {
1860 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1861 /* take the original parameters */
1862 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1863 sdata_err(sdata,
1864 "failed to set TX queue parameters for queue %d\n",
1865 ac);
1866 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1867 tx_tspec->downgraded = false;
1868 ret = true;
1869 break;
1870 case TX_TSPEC_ACTION_DOWNGRADE:
1871 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1872 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1873 ret = true;
1874 break;
1875 }
1876 /* downgrade next lower non-ACM AC */
1877 for (non_acm_ac = ac + 1;
1878 non_acm_ac < IEEE80211_NUM_ACS;
1879 non_acm_ac++)
1880 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1881 break;
Johannes Berg93db1d92016-09-14 09:23:51 +02001882 /* Usually the loop will result in using BK even if it
1883 * requires admission control, but such a configuration
1884 * makes no sense and we have to transmit somehow - the
1885 * AC selection does the same thing.
1886 * If we started out trying to downgrade from BK, then
1887 * the extra condition here might be needed.
Johannes Berg02219b32014-10-07 10:38:50 +03001888 */
Johannes Berg93db1d92016-09-14 09:23:51 +02001889 if (non_acm_ac >= IEEE80211_NUM_ACS)
1890 non_acm_ac = IEEE80211_AC_BK;
Johannes Berg02219b32014-10-07 10:38:50 +03001891 if (drv_conf_tx(local, sdata, ac,
1892 &sdata->tx_conf[non_acm_ac]))
1893 sdata_err(sdata,
1894 "failed to set TX queue parameters for queue %d\n",
1895 ac);
1896 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1897 ret = true;
1898 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1899 tx_tspec->time_slice_start + HZ - now + 1);
1900 break;
1901 case TX_TSPEC_ACTION_NONE:
1902 /* nothing now */
1903 break;
1904 }
1905 }
1906
1907 return ret;
1908}
1909
1910void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1911{
1912 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1913 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1914}
1915
1916static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1917{
1918 struct ieee80211_sub_if_data *sdata;
1919
1920 sdata = container_of(work, struct ieee80211_sub_if_data,
1921 u.mgd.tx_tspec_wk.work);
1922 ieee80211_sta_handle_tspec_ac_params(sdata);
1923}
1924
Johannes Berg60f8b39c2008-09-08 17:44:22 +02001925/* MLME */
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001926static bool
1927ieee80211_sta_wmm_params(struct ieee80211_local *local,
1928 struct ieee80211_sub_if_data *sdata,
1929 const u8 *wmm_param, size_t wmm_param_len,
1930 const struct ieee80211_mu_edca_param_set *mu_edca)
Jiri Bencf0706e82007-05-05 11:45:53 -07001931{
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001932 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
Johannes Berg4ced3f72010-07-19 16:39:04 +02001933 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001934 size_t left;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001935 int count, mu_edca_count, ac;
Johannes Berg4a3cb702013-02-12 16:43:19 +01001936 const u8 *pos;
1937 u8 uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001938
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001939 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001940 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001941
Johannes Berg32c50572012-03-28 11:04:29 +02001942 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001943 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001944
1945 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001946 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001947
Jiri Bencf0706e82007-05-05 11:45:53 -07001948 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001949 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001950
1951 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001952 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001953
Jiri Bencf0706e82007-05-05 11:45:53 -07001954 count = wmm_param[6] & 0x0f;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001955 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
1956 * if mu_edca was preset before and now it disappeared tell
1957 * the driver about it.
1958 */
1959 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
1960 if (count == ifmgd->wmm_last_param_set &&
1961 mu_edca_count == ifmgd->mu_edca_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001962 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001963 ifmgd->wmm_last_param_set = count;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001964 ifmgd->mu_edca_last_param_set = mu_edca_count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001965
1966 pos = wmm_param + 8;
1967 left = wmm_param_len - 8;
1968
1969 memset(&params, 0, sizeof(params));
1970
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001971 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001972 for (; left >= 4; left -= 4, pos += 4) {
1973 int aci = (pos[0] >> 5) & 0x03;
1974 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001975 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001976
1977 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001978 case 1: /* AC_BK */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001979 ac = IEEE80211_AC_BK;
Johannes Berg988c0f72008-04-17 19:21:22 +02001980 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001981 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001982 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1983 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001984 params[ac].mu_edca = !!mu_edca;
1985 if (mu_edca)
1986 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
Jiri Bencf0706e82007-05-05 11:45:53 -07001987 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001988 case 2: /* AC_VI */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001989 ac = IEEE80211_AC_VI;
Johannes Berg988c0f72008-04-17 19:21:22 +02001990 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001991 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001992 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1993 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001994 params[ac].mu_edca = !!mu_edca;
1995 if (mu_edca)
1996 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
Jiri Bencf0706e82007-05-05 11:45:53 -07001997 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001998 case 3: /* AC_VO */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001999 ac = IEEE80211_AC_VO;
Johannes Berg988c0f72008-04-17 19:21:22 +02002000 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03002001 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02002002 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2003 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03002004 params[ac].mu_edca = !!mu_edca;
2005 if (mu_edca)
2006 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
Jiri Bencf0706e82007-05-05 11:45:53 -07002007 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02002008 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07002009 default:
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002010 ac = IEEE80211_AC_BE;
Johannes Berg988c0f72008-04-17 19:21:22 +02002011 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03002012 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02002013 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2014 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03002015 params[ac].mu_edca = !!mu_edca;
2016 if (mu_edca)
2017 params[ac].mu_edca_param_rec = mu_edca->ac_be;
Jiri Bencf0706e82007-05-05 11:45:53 -07002018 break;
2019 }
2020
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002021 params[ac].aifs = pos[0] & 0x0f;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02002022
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002023 if (params[ac].aifs < 2) {
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02002024 sdata_info(sdata,
2025 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002026 params[ac].aifs, aci);
2027 params[ac].aifs = 2;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02002028 }
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002029 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2030 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2031 params[ac].txop = get_unaligned_le16(pos + 2);
2032 params[ac].acm = acm;
2033 params[ac].uapsd = uapsd;
Kalle Valoab133152010-01-12 10:42:31 +02002034
Ilan Peer911a2642018-04-03 11:35:22 +03002035 if (params[ac].cw_min == 0 ||
Emmanuel Grumbachc470bdc2018-03-26 16:21:04 +03002036 params[ac].cw_min > params[ac].cw_max) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002037 sdata_info(sdata,
2038 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2039 params[ac].cw_min, params[ac].cw_max, aci);
2040 return false;
2041 }
Haim Dreyfusse552af02018-03-28 13:24:10 +03002042 ieee80211_regulatory_limit_wmm_params(sdata, &params[ac], ac);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002043 }
2044
Brian Norris05aaa5c2019-07-26 15:47:58 -07002045 /* WMM specification requires all 4 ACIs. */
2046 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2047 if (params[ac].cw_min == 0) {
2048 sdata_info(sdata,
2049 "AP has invalid WMM params (missing AC %d), using defaults\n",
2050 ac);
2051 return false;
2052 }
2053 }
2054
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002055 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002056 mlme_dbg(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002057 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2058 ac, params[ac].acm,
2059 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2060 params[ac].txop, params[ac].uapsd,
2061 ifmgd->tx_tspec[ac].downgraded);
2062 sdata->tx_conf[ac] = params[ac];
2063 if (!ifmgd->tx_tspec[ac].downgraded &&
2064 drv_conf_tx(local, sdata, ac, &params[ac]))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002065 sdata_err(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002066 "failed to set TX queue parameters for AC %d\n",
2067 ac);
Jiri Bencf0706e82007-05-05 11:45:53 -07002068 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02002069
2070 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02002071 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02002072 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07002073}
2074
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002075static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2076{
2077 lockdep_assert_held(&sdata->local->mtx);
2078
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002079 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002080 ieee80211_run_deferred_scan(sdata->local);
2081}
2082
2083static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2084{
2085 mutex_lock(&sdata->local->mtx);
2086 __ieee80211_stop_poll(sdata);
2087 mutex_unlock(&sdata->local->mtx);
2088}
2089
Johannes Berg7a5158e2008-10-08 10:59:33 +02002090static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2091 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02002092{
Johannes Bergbda39332008-10-11 01:51:51 +02002093 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302094 struct ieee80211_supported_band *sband;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002095 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002096 bool use_protection;
2097 bool use_short_preamble;
2098 bool use_short_slot;
2099
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302100 sband = ieee80211_get_sband(sdata);
2101 if (!sband)
2102 return changed;
2103
Johannes Berg7a5158e2008-10-08 10:59:33 +02002104 if (erp_valid) {
2105 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2106 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2107 } else {
2108 use_protection = false;
2109 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2110 }
2111
2112 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302113 if (sband->band == NL80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01002114 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02002115
Johannes Berg471b3ef2007-12-28 14:32:58 +01002116 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01002117 bss_conf->use_cts_prot = use_protection;
2118 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02002119 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02002120
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002121 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002122 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002123 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02002124 }
Daniel Draked9430a32007-07-27 15:43:24 +02002125
Johannes Berg7a5158e2008-10-08 10:59:33 +02002126 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02002127 bss_conf->use_short_slot = use_short_slot;
2128 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04002129 }
2130
2131 return changed;
2132}
2133
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002134static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002135 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02002136 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07002137{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002138 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002139 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002140 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002141
Johannes Bergae5eb022008-10-14 16:58:37 +02002142 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002143 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03002144 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002145
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002146 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
Ben Greear59c1ec22013-03-19 14:19:56 -07002147 beacon_loss_count * bss_conf->beacon_int));
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002148
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002149 sdata->u.mgd.associated = cbss;
2150 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002151
Johannes Berge8e4f522017-03-08 11:12:10 +01002152 ieee80211_check_rate_mask(sdata);
2153
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002154 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2155
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01002156 if (sdata->vif.p2p ||
2157 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002158 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01002159
Johannes Berg9caf0362012-11-29 01:25:20 +01002160 rcu_read_lock();
2161 ies = rcu_dereference(cbss->ies);
2162 if (ies) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002163 int ret;
2164
2165 ret = cfg80211_get_p2p_attr(
2166 ies->data, ies->len,
2167 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002168 (u8 *) &bss_conf->p2p_noa_attr,
2169 sizeof(bss_conf->p2p_noa_attr));
Johannes Berg9caf0362012-11-29 01:25:20 +01002170 if (ret >= 2) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002171 sdata->u.mgd.p2p_noa_index =
2172 bss_conf->p2p_noa_attr.index;
Johannes Berg9caf0362012-11-29 01:25:20 +01002173 bss_info_changed |= BSS_CHANGED_P2P_PS;
Johannes Berg9caf0362012-11-29 01:25:20 +01002174 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01002175 }
Johannes Berg9caf0362012-11-29 01:25:20 +01002176 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01002177 }
2178
Johannes Bergb291ba12009-07-10 15:29:03 +02002179 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002180 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002181
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002182 ieee80211_led_assoc(local, 1);
2183
Alexander Bondar989c6502013-05-16 17:34:17 +03002184 if (sdata->u.mgd.have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02002185 /*
2186 * If the AP is buggy we may get here with no DTIM period
2187 * known, so assume it's 1 which is the only safe assumption
2188 * in that case, although if the TIM IE is broken powersave
2189 * probably just won't work at all.
2190 */
2191 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Alexander Bondar817cee72013-05-19 14:23:57 +03002192 bss_conf->beacon_rate = bss->beacon_rate;
Alexander Bondar989c6502013-05-16 17:34:17 +03002193 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
Johannes Berg826262c2012-12-10 16:38:14 +02002194 } else {
Alexander Bondar817cee72013-05-19 14:23:57 +03002195 bss_conf->beacon_rate = NULL;
Johannes Berge5b900d2010-07-29 16:08:55 +02002196 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02002197 }
Johannes Berge5b900d2010-07-29 16:08:55 +02002198
Juuso Oikarinen68542962010-06-09 13:43:26 +03002199 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02002200
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002201 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01002202 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03002203 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002204 bss_info_changed |= BSS_CHANGED_CQM;
2205
Juuso Oikarinen68542962010-06-09 13:43:26 +03002206 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002207 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002208 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002209
Johannes Bergae5eb022008-10-14 16:58:37 +02002210 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03002211
Johannes Berg056508d2009-07-30 21:43:55 +02002212 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002213 ieee80211_recalc_ps(local);
Johannes Berg056508d2009-07-30 21:43:55 +02002214 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02002215
Johannes Berg04ecd252012-09-11 14:34:12 +02002216 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03002217 ieee80211_recalc_ps_vif(sdata);
2218
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002219 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07002220}
2221
Jouni Malinene69e95d2010-03-29 23:29:31 -07002222static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01002223 u16 stype, u16 reason, bool tx,
2224 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03002225{
Johannes Berg46900292009-02-15 12:44:28 +01002226 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002227 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01002228 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002229
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002230 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002231
Johannes Berg37ad3882012-02-24 13:50:54 +01002232 if (WARN_ON_ONCE(tx && !frame_buf))
2233 return;
2234
Johannes Bergb291ba12009-07-10 15:29:03 +02002235 if (WARN_ON(!ifmgd->associated))
2236 return;
2237
David Spinadel79543d82012-06-12 09:59:45 +03002238 ieee80211_stop_poll(sdata);
2239
Johannes Berg77fdaa12009-07-07 03:45:17 +02002240 ifmgd->associated = NULL;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002241 netif_carrier_off(sdata->dev);
2242
Eliad Peller88bc40e2012-07-12 17:35:33 +03002243 /*
2244 * if we want to get out of ps before disassoc (why?) we have
2245 * to do it before sending disassoc, as otherwise the null-packet
2246 * won't be valid.
2247 */
2248 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2249 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2250 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2251 }
2252 local->ps_sdata = NULL;
2253
Eliad Pellerab095872012-07-27 12:33:22 +03002254 /* disable per-vif ps */
2255 ieee80211_recalc_ps_vif(sdata);
2256
Emmanuel Grumbach14f2ae82015-01-22 23:30:19 +02002257 /* make sure ongoing transmission finishes */
2258 synchronize_net();
2259
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002260 /*
2261 * drop any frame before deauth/disassoc, this can be data or
2262 * management frame. Since we are disconnecting, we should not
2263 * insist sending these frames which can take time and delay
2264 * the disconnection and possible the roaming.
2265 */
Eliad Pellerf8239812012-06-27 14:18:22 +03002266 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002267 ieee80211_flush_queues(local, sdata, true);
Eliad Pellerf8239812012-06-27 14:18:22 +03002268
Johannes Berg37ad3882012-02-24 13:50:54 +01002269 /* deauthenticate/disassociate now */
Ilan Peer94ba9272018-02-19 14:48:41 +02002270 if (tx || frame_buf) {
Ilan Peer94ba9272018-02-19 14:48:41 +02002271 /*
2272 * In multi channel scenarios guarantee that the virtual
2273 * interface is granted immediate airtime to transmit the
2274 * deauthentication frame by calling mgd_prepare_tx, if the
2275 * driver requested so.
2276 */
2277 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2278 !ifmgd->have_beacon)
Ilan Peerd4e36e52018-04-20 13:49:25 +03002279 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Ilan Peer94ba9272018-02-19 14:48:41 +02002280
Johannes Berg4b08d1b2019-08-30 14:24:51 +03002281 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid,
2282 ifmgd->bssid, stype, reason,
2283 tx, frame_buf);
Ilan Peer94ba9272018-02-19 14:48:41 +02002284 }
Johannes Berg37ad3882012-02-24 13:50:54 +01002285
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002286 /* flush out frame - make sure the deauth was actually sent */
Johannes Berg37ad3882012-02-24 13:50:54 +01002287 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002288 ieee80211_flush_queues(local, sdata, false);
Johannes Berg37ad3882012-02-24 13:50:54 +01002289
Eliad Peller88a9e312012-06-01 11:14:03 +03002290 /* clear bssid only after building the needed mgmt frames */
Joe Perchesc84a67a2015-03-02 19:54:57 -08002291 eth_zero_addr(ifmgd->bssid);
Eliad Peller88a9e312012-06-01 11:14:03 +03002292
Johannes Berg37ad3882012-02-24 13:50:54 +01002293 /* remove AP and TDLS peers */
Johannes Bergd34ba212013-12-04 22:46:11 +01002294 sta_info_flush(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01002295
2296 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002297 changed |= ieee80211_reset_erp_info(sdata);
2298
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002299 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02002300 changed |= BSS_CHANGED_ASSOC;
2301 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002302
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002303 ifmgd->p2p_noa_index = -1;
2304 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2305 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01002306
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002307 /* on the next assoc, re-program HT/VHT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08002308 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2309 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002310 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2311 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
Sara Sharon23a1f8d2015-12-08 16:04:31 +02002312
2313 /* reset MU-MIMO ownership and group data */
2314 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2315 sizeof(sdata->vif.bss_conf.mu_group.membership));
2316 memset(sdata->vif.bss_conf.mu_group.position, 0,
2317 sizeof(sdata->vif.bss_conf.mu_group.position));
2318 changed |= BSS_CHANGED_MU_GROUPS;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002319 sdata->vif.mu_mimo_owner = false;
Johannes Berg413ad502009-05-08 21:21:06 +02002320
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002321 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05302322
Kalle Valo520eb822008-12-18 23:35:27 +02002323 del_timer_sync(&local->dynamic_ps_timer);
2324 cancel_work_sync(&local->dynamic_ps_enable_work);
2325
Juuso Oikarinen68542962010-06-09 13:43:26 +03002326 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002327 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002328 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002329
Johannes Berg3abead52012-03-02 15:56:59 +01002330 sdata->vif.bss_conf.qos = false;
2331 changed |= BSS_CHANGED_QOS;
2332
Johannes Berg0aaffa92010-05-05 15:28:27 +02002333 /* The BSSID (not really interesting) and HT changed */
2334 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02002335 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02002336
Johannes Berg3abead52012-03-02 15:56:59 +01002337 /* disassociated - set to defaults now */
Johannes Bergcec66282015-10-22 17:46:04 +02002338 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg3abead52012-03-02 15:56:59 +01002339
Johannes Bergb9dcf712010-08-27 12:35:54 +02002340 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2341 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2342 del_timer_sync(&sdata->u.mgd.timer);
2343 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02002344
Johannes Berg826262c2012-12-10 16:38:14 +02002345 sdata->vif.bss_conf.dtim_period = 0;
Alexander Bondar817cee72013-05-19 14:23:57 +03002346 sdata->vif.bss_conf.beacon_rate = NULL;
2347
Alexander Bondar989c6502013-05-16 17:34:17 +03002348 ifmgd->have_beacon = false;
Johannes Berg826262c2012-12-10 16:38:14 +02002349
Johannes Berg028e8da02012-11-26 11:57:41 +01002350 ifmgd->flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002351 mutex_lock(&local->mtx);
Johannes Berg028e8da02012-11-26 11:57:41 +01002352 ieee80211_vif_release_channel(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002353
2354 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002355 ifmgd->csa_waiting_bcn = false;
Johannes Bergf84eaa12015-03-12 08:53:26 +02002356 ifmgd->csa_ignored_same_chan = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002357 if (sdata->csa_block_tx) {
2358 ieee80211_wake_vif_queues(local, sdata,
2359 IEEE80211_QUEUE_STOP_REASON_CSA);
2360 sdata->csa_block_tx = false;
2361 }
Johannes Berg34a37402013-12-18 09:43:33 +01002362 mutex_unlock(&local->mtx);
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002363
Johannes Berg02219b32014-10-07 10:38:50 +03002364 /* existing TX TSPEC sessions no longer exist */
2365 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2366 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2367
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002368 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002369}
Jiri Bencf0706e82007-05-05 11:45:53 -07002370
Kalle Valo3cf335d52009-03-22 21:57:06 +02002371void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2372 struct ieee80211_hdr *hdr)
2373{
2374 /*
2375 * We can postpone the mgd.timer whenever receiving unicast frames
2376 * from AP because we know that the connection is working both ways
2377 * at that time. But multicast frames (and hence also beacons) must
2378 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02002379 * data idle periods for sending the periodic probe request to the
2380 * AP we're connected to.
Kalle Valo3cf335d52009-03-22 21:57:06 +02002381 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002382 if (is_multicast_ether_addr(hdr->addr1))
2383 return;
2384
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04002385 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d52009-03-22 21:57:06 +02002386}
Jiri Bencf0706e82007-05-05 11:45:53 -07002387
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002388static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2389{
2390 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002391 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002392
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002393 mutex_lock(&local->mtx);
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002394 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2395 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002396
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002397 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002398
2399 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002400 ieee80211_recalc_ps(local);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002401 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002402
Johannes Berg30686bf2015-06-02 21:39:54 +02002403 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002404 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002405
2406 /*
2407 * We've received a probe response, but are not sure whether
2408 * we have or will be receiving any beacons or data, so let's
2409 * schedule the timers again, just in case.
2410 */
2411 ieee80211_sta_reset_beacon_monitor(sdata);
2412
2413 mod_timer(&ifmgd->conn_mon_timer,
2414 round_jiffies_up(jiffies +
2415 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002416out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002417 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002418}
2419
Johannes Berg02219b32014-10-07 10:38:50 +03002420static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2421 struct ieee80211_hdr *hdr,
2422 u16 tx_time)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002423{
Johannes Berg02219b32014-10-07 10:38:50 +03002424 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Sara Sharona1f2ba04c2018-02-19 14:48:40 +02002425 u16 tid = ieee80211_get_tid(hdr);
Johannes Berg02219b32014-10-07 10:38:50 +03002426 int ac = ieee80211_ac_from_tid(tid);
2427 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2428 unsigned long now = jiffies;
2429
2430 if (likely(!tx_tspec->admitted_time))
2431 return;
2432
2433 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2434 tx_tspec->consumed_tx_time = 0;
2435 tx_tspec->time_slice_start = now;
2436
2437 if (tx_tspec->downgraded) {
2438 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2439 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2440 }
2441 }
2442
2443 if (tx_tspec->downgraded)
2444 return;
2445
2446 tx_tspec->consumed_tx_time += tx_time;
2447
2448 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2449 tx_tspec->downgraded = true;
2450 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2451 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2452 }
2453}
2454
2455void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2456 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2457{
2458 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2459
Felix Fietkau75706d02010-12-02 21:01:07 +01002460 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002461 return;
2462
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002463 if (ieee80211_is_nullfunc(hdr->frame_control) &&
2464 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002465 if (ack)
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002466 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002467 else
2468 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002469 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002470 return;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002471 }
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002472
2473 if (ack)
2474 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002475}
2476
Johannes Berg45ad6832018-05-28 15:47:39 +02002477static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2478 const u8 *src, const u8 *dst,
2479 const u8 *ssid, size_t ssid_len,
2480 struct ieee80211_channel *channel)
2481{
2482 struct sk_buff *skb;
2483
2484 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2485 ssid, ssid_len, NULL, 0,
2486 IEEE80211_PROBE_FLAG_DIRECTED);
2487 if (skb)
2488 ieee80211_tx_skb(sdata, skb);
2489}
2490
Maxim Levitskya43abf22009-07-31 18:54:12 +03002491static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2492{
2493 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2494 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002495 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08002496 u8 unicast_limit = max(1, max_probe_tries - 3);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002497 struct sta_info *sta;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002498
2499 /*
2500 * Try sending broadcast probe requests for the last three
2501 * probe requests after the first ones failed since some
2502 * buggy APs only support broadcast probe requests.
2503 */
2504 if (ifmgd->probe_send_count >= unicast_limit)
2505 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002506
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002507 /*
2508 * When the hardware reports an accurate Tx ACK status, it's
2509 * better to send a nullfunc frame instead of a probe request,
2510 * as it will kick us off the AP quickly if we aren't associated
2511 * anymore. The timeout will be reset if the frame is ACKed by
2512 * the AP.
2513 */
Soumik Das992e68b2012-05-20 15:31:13 +05302514 ifmgd->probe_send_count++;
2515
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002516 if (dst) {
2517 mutex_lock(&sdata->local->sta_mtx);
2518 sta = sta_info_get(sdata, dst);
2519 if (!WARN_ON(!sta))
2520 ieee80211_check_fast_rx(sta);
2521 mutex_unlock(&sdata->local->sta_mtx);
2522 }
2523
Johannes Berg30686bf2015-06-02 21:39:54 +02002524 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002525 ifmgd->nullfunc_failed = false;
Shay Barf39b07f2019-07-03 16:18:48 +03002526 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
2527 ifmgd->probe_send_count--;
2528 else
2529 ieee80211_send_nullfunc(sdata->local, sdata, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002530 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002531 int ssid_len;
2532
Johannes Berg9caf0362012-11-29 01:25:20 +01002533 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002534 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002535 if (WARN_ON_ONCE(ssid == NULL))
2536 ssid_len = 0;
2537 else
2538 ssid_len = ssid[1];
2539
Johannes Berg45ad6832018-05-28 15:47:39 +02002540 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2541 ssid + 2, ssid_len,
2542 ifmgd->associated->channel);
Johannes Berg9caf0362012-11-29 01:25:20 +01002543 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002544 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03002545
Ben Greear180205b2011-02-04 15:30:24 -08002546 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002547 run_again(sdata, ifmgd->probe_timeout);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002548}
2549
Johannes Bergb291ba12009-07-10 15:29:03 +02002550static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2551 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02002552{
Kalle Valo04de8382009-03-22 21:57:35 +02002553 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002554 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02002555
Johannes Berg9607e6b662009-12-23 13:15:31 +01002556 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02002557 return;
2558
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002559 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002560
2561 if (!ifmgd->associated)
2562 goto out;
2563
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002564 mutex_lock(&sdata->local->mtx);
2565
2566 if (sdata->local->tmp_channel || sdata->local->scanning) {
2567 mutex_unlock(&sdata->local->mtx);
2568 goto out;
2569 }
2570
Ben Greeara13fbe52013-03-25 11:19:35 -07002571 if (beacon) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002572 mlme_dbg_ratelimited(sdata,
Ben Greear59c1ec22013-03-19 14:19:56 -07002573 "detected beacon loss from AP (missed %d beacons) - probing\n",
2574 beacon_loss_count);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002575
Johannes Berg98f03342014-11-26 12:42:02 +01002576 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
Ben Greeara13fbe52013-03-25 11:19:35 -07002577 }
Kalle Valo04de8382009-03-22 21:57:35 +02002578
Johannes Bergb291ba12009-07-10 15:29:03 +02002579 /*
2580 * The driver/our work has already reported this event or the
2581 * connection monitoring has kicked in and we have already sent
2582 * a probe request. Or maybe the AP died and the driver keeps
2583 * reporting until we disassociate...
2584 *
2585 * In either case we have to ignore the current call to this
2586 * function (except for setting the correct probe reason bit)
2587 * because otherwise we would reset the timer every time and
2588 * never check whether we received a probe response!
2589 */
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002590 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Johannes Bergb291ba12009-07-10 15:29:03 +02002591 already = true;
2592
Eliad Peller12b5f342013-11-18 19:06:46 +02002593 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2594
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002595 mutex_unlock(&sdata->local->mtx);
2596
Johannes Bergb291ba12009-07-10 15:29:03 +02002597 if (already)
2598 goto out;
2599
Johannes Berg4e751842009-06-10 15:16:52 +02002600 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002601 ieee80211_recalc_ps(sdata->local);
Johannes Berg4e751842009-06-10 15:16:52 +02002602 mutex_unlock(&sdata->local->iflist_mtx);
2603
Maxim Levitskya43abf22009-07-31 18:54:12 +03002604 ifmgd->probe_send_count = 0;
2605 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002606 out:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002607 sdata_unlock(sdata);
Kalle Valo04de8382009-03-22 21:57:35 +02002608}
2609
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002610struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2611 struct ieee80211_vif *vif)
2612{
2613 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2614 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002615 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002616 struct sk_buff *skb;
2617 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002618 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002619
2620 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2621 return NULL;
2622
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002623 sdata_assert_lock(sdata);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002624
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002625 if (ifmgd->associated)
2626 cbss = ifmgd->associated;
2627 else if (ifmgd->auth_data)
2628 cbss = ifmgd->auth_data->bss;
2629 else if (ifmgd->assoc_data)
2630 cbss = ifmgd->assoc_data->bss;
2631 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002632 return NULL;
2633
Johannes Berg9caf0362012-11-29 01:25:20 +01002634 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002635 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Will Deacon41525612019-10-04 10:51:31 +01002636 if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
2637 "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002638 ssid_len = 0;
2639 else
2640 ssid_len = ssid[1];
2641
Johannes Berga344d672014-06-12 22:24:31 +02002642 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02002643 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02002644 ssid + 2, ssid_len,
Johannes Berg00387f32018-05-28 15:47:38 +02002645 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
Johannes Berg9caf0362012-11-29 01:25:20 +01002646 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002647
2648 return skb;
2649}
2650EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2651
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002652static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2653 const u8 *buf, size_t len, bool tx,
2654 u16 reason)
2655{
2656 struct ieee80211_event event = {
2657 .type = MLME_EVENT,
2658 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2659 .u.mlme.reason = reason,
2660 };
2661
2662 if (tx)
2663 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2664 else
2665 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2666
2667 drv_event_callback(sdata->local, sdata, &event);
2668}
2669
Johannes Bergeef9e542013-01-29 13:09:34 +01002670static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002671{
Michal Kazior59af6922014-04-09 15:10:59 +02002672 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002673 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002674 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002675 bool tx;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002676
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002677 sdata_lock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002678 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002679 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002680 return;
2681 }
2682
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002683 tx = !sdata->csa_block_tx;
2684
David Spinadel20eb7ea2016-05-03 16:05:02 +03002685 /* AP is probably out of range (or not reachable for another reason) so
2686 * remove the bss struct for that AP.
2687 */
2688 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2689
Johannes Berg37ad3882012-02-24 13:50:54 +01002690 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2691 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002692 tx, frame_buf);
Michal Kazior59af6922014-04-09 15:10:59 +02002693 mutex_lock(&local->mtx);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002694 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002695 ifmgd->csa_waiting_bcn = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002696 if (sdata->csa_block_tx) {
2697 ieee80211_wake_vif_queues(local, sdata,
2698 IEEE80211_QUEUE_STOP_REASON_CSA);
2699 sdata->csa_block_tx = false;
2700 }
Michal Kazior59af6922014-04-09 15:10:59 +02002701 mutex_unlock(&local->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002702
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002703 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002704 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2705
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002706 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002707}
2708
Johannes Bergcc74c0c2012-08-01 16:49:34 +02002709static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02002710{
2711 struct ieee80211_sub_if_data *sdata =
2712 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002713 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002714 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Paul Stewarta85e1d52011-12-09 11:01:49 -08002715
Johannes Berg976bd9e2015-10-16 17:18:11 +02002716 if (ifmgd->associated)
2717 ifmgd->beacon_loss_count++;
Johannes Bergb291ba12009-07-10 15:29:03 +02002718
Johannes Berg682bd382013-01-29 13:13:50 +01002719 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02002720 sdata_info(sdata, "Connection to AP %pM lost\n",
2721 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01002722 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02002723 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002724 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02002725 }
2726}
2727
2728static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2729{
2730 struct ieee80211_sub_if_data *sdata =
2731 container_of(work, struct ieee80211_sub_if_data,
2732 u.mgd.csa_connection_drop_work);
2733
Johannes Bergeef9e542013-01-29 13:09:34 +01002734 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002735}
2736
Kalle Valo04de8382009-03-22 21:57:35 +02002737void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2738{
2739 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002740 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02002741
Johannes Bergb5878a22010-04-07 16:48:40 +02002742 trace_api_beacon_loss(sdata);
2743
Johannes Berg682bd382013-01-29 13:13:50 +01002744 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002745 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002746}
2747EXPORT_SYMBOL(ieee80211_beacon_loss);
2748
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002749void ieee80211_connection_loss(struct ieee80211_vif *vif)
2750{
2751 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2752 struct ieee80211_hw *hw = &sdata->local->hw;
2753
Johannes Bergb5878a22010-04-07 16:48:40 +02002754 trace_api_connection_loss(sdata);
2755
Johannes Berg682bd382013-01-29 13:13:50 +01002756 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002757 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2758}
2759EXPORT_SYMBOL(ieee80211_connection_loss);
2760
2761
Johannes Berg66e67e42012-01-20 13:55:27 +01002762static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2763 bool assoc)
2764{
2765 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2766
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002767 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002768
Johannes Berg66e67e42012-01-20 13:55:27 +01002769 if (!assoc) {
Emmanuel Grumbachc1e140b2015-01-19 16:53:06 +02002770 /*
2771 * we are not authenticated yet, the only timer that could be
2772 * running is the timeout for the authentication response which
2773 * which is not relevant anymore.
2774 */
2775 del_timer_sync(&sdata->u.mgd.timer);
Johannes Berg66e67e42012-01-20 13:55:27 +01002776 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2777
Joe Perchesc84a67a2015-03-02 19:54:57 -08002778 eth_zero_addr(sdata->u.mgd.bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002779 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002780 sdata->u.mgd.flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002781 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002782 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002783 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01002784 }
2785
Johannes Berg5b112d32013-02-01 01:49:58 +01002786 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002787 kfree(auth_data);
2788 sdata->u.mgd.auth_data = NULL;
2789}
2790
Johannes Bergc9c99f82015-06-01 14:10:09 +02002791static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
Johannes Berge6f462d2016-12-08 17:22:09 +01002792 bool assoc, bool abandon)
Johannes Bergc9c99f82015-06-01 14:10:09 +02002793{
2794 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2795
2796 sdata_assert_lock(sdata);
2797
2798 if (!assoc) {
2799 /*
2800 * we are not associated yet, the only timer that could be
2801 * running is the timeout for the association response which
2802 * which is not relevant anymore.
2803 */
2804 del_timer_sync(&sdata->u.mgd.timer);
2805 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2806
2807 eth_zero_addr(sdata->u.mgd.bssid);
2808 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2809 sdata->u.mgd.flags = 0;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002810 sdata->vif.mu_mimo_owner = false;
2811
Johannes Bergc9c99f82015-06-01 14:10:09 +02002812 mutex_lock(&sdata->local->mtx);
2813 ieee80211_vif_release_channel(sdata);
2814 mutex_unlock(&sdata->local->mtx);
Johannes Berge6f462d2016-12-08 17:22:09 +01002815
2816 if (abandon)
2817 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
Johannes Bergc9c99f82015-06-01 14:10:09 +02002818 }
2819
2820 kfree(assoc_data);
2821 sdata->u.mgd.assoc_data = NULL;
2822}
2823
Johannes Berg66e67e42012-01-20 13:55:27 +01002824static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2825 struct ieee80211_mgmt *mgmt, size_t len)
2826{
Johannes Berg1672c0e32013-01-29 15:02:27 +01002827 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01002828 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2829 u8 *pos;
2830 struct ieee802_11_elems elems;
Johannes Berg1672c0e32013-01-29 15:02:27 +01002831 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002832
2833 pos = mgmt->u.auth.variable;
Sara Sharon4abb52a2019-01-16 12:14:41 +02002834 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
2835 mgmt->bssid, auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002836 if (!elems.challenge)
2837 return;
2838 auth_data->expected_transaction = 4;
Ilan Peerd4e36e52018-04-20 13:49:25 +03002839 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg30686bf2015-06-02 21:39:54 +02002840 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +01002841 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2842 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03002843 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01002844 elems.challenge - 2, elems.challenge_len + 2,
2845 auth_data->bss->bssid, auth_data->bss->bssid,
2846 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002847 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002848}
2849
Jouni Malinenfc107a92018-10-11 00:21:19 +03002850static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2851 const u8 *bssid)
2852{
Jouni Malinenefb543e2018-10-11 00:21:21 +03002853 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002854 struct sta_info *sta;
Wei Yongjun33483a62018-10-16 02:35:30 +00002855 bool result = true;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002856
Jouni Malinenefb543e2018-10-11 00:21:21 +03002857 sdata_info(sdata, "authenticated\n");
2858 ifmgd->auth_data->done = true;
2859 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2860 ifmgd->auth_data->timeout_started = true;
2861 run_again(sdata, ifmgd->auth_data->timeout);
2862
Jouni Malinenfc107a92018-10-11 00:21:19 +03002863 /* move station state to auth */
2864 mutex_lock(&sdata->local->sta_mtx);
2865 sta = sta_info_get(sdata, bssid);
2866 if (!sta) {
2867 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
Wei Yongjun33483a62018-10-16 02:35:30 +00002868 result = false;
2869 goto out;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002870 }
2871 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2872 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Wei Yongjun33483a62018-10-16 02:35:30 +00002873 result = false;
2874 goto out;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002875 }
Jouni Malinenfc107a92018-10-11 00:21:19 +03002876
Wei Yongjun33483a62018-10-16 02:35:30 +00002877out:
2878 mutex_unlock(&sdata->local->sta_mtx);
2879 return result;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002880}
2881
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002882static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2883 struct ieee80211_mgmt *mgmt, size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002884{
2885 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2886 u8 bssid[ETH_ALEN];
2887 u16 auth_alg, auth_transaction, status_code;
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002888 struct ieee80211_event event = {
2889 .type = MLME_EVENT,
2890 .u.mlme.data = AUTH_EVENT,
2891 };
Johannes Berg66e67e42012-01-20 13:55:27 +01002892
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002893 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002894
2895 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002896 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002897
2898 if (!ifmgd->auth_data || ifmgd->auth_data->done)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002899 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002900
2901 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2902
Joe Perchesb203ca32012-05-08 18:56:52 +00002903 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002904 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002905
2906 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2907 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2908 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2909
2910 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinenefb543e2018-10-11 00:21:21 +03002911 (auth_alg != WLAN_AUTH_SAE &&
2912 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2913 (auth_alg == WLAN_AUTH_SAE &&
2914 (auth_transaction < ifmgd->auth_data->expected_transaction ||
2915 auth_transaction > 2))) {
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002916 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2917 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2918 auth_transaction,
2919 ifmgd->auth_data->expected_transaction);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002920 return;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002921 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002922
2923 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002924 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2925 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002926 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002927 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002928 event.u.mlme.status = MLME_DENIED;
2929 event.u.mlme.reason = status_code;
2930 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002931 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002932 }
2933
2934 switch (ifmgd->auth_data->algorithm) {
2935 case WLAN_AUTH_OPEN:
2936 case WLAN_AUTH_LEAP:
2937 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002938 case WLAN_AUTH_SAE:
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03002939 case WLAN_AUTH_FILS_SK:
2940 case WLAN_AUTH_FILS_SK_PFS:
2941 case WLAN_AUTH_FILS_PK:
Johannes Berg66e67e42012-01-20 13:55:27 +01002942 break;
2943 case WLAN_AUTH_SHARED_KEY:
2944 if (ifmgd->auth_data->expected_transaction != 4) {
2945 ieee80211_auth_challenge(sdata, mgmt, len);
2946 /* need another frame */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002947 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002948 }
2949 break;
2950 default:
2951 WARN_ONCE(1, "invalid auth alg %d",
2952 ifmgd->auth_data->algorithm);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002953 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002954 }
2955
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002956 event.u.mlme.status = MLME_SUCCESS;
2957 drv_event_callback(sdata->local, sdata, &event);
Jouni Malinenefb543e2018-10-11 00:21:21 +03002958 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
2959 (auth_transaction == 2 &&
2960 ifmgd->auth_data->expected_transaction == 2)) {
2961 if (!ieee80211_mark_sta_auth(sdata, bssid))
2962 goto out_err;
2963 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2964 auth_transaction == 2) {
2965 sdata_info(sdata, "SAE peer confirmed\n");
2966 ifmgd->auth_data->peer_confirmed = true;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002967 }
2968
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002969 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002970 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002971 out_err:
2972 mutex_unlock(&sdata->local->sta_mtx);
2973 /* ignore frame -- wait for timeout */
Johannes Berg66e67e42012-01-20 13:55:27 +01002974}
2975
Calvin Owensdfa1ad22014-02-11 12:36:24 -06002976#define case_WLAN(type) \
2977 case WLAN_REASON_##type: return #type
2978
Yu Wang79c92ca2019-05-10 17:04:52 +08002979const char *ieee80211_get_reason_code_string(u16 reason_code)
Calvin Owensdfa1ad22014-02-11 12:36:24 -06002980{
2981 switch (reason_code) {
2982 case_WLAN(UNSPECIFIED);
2983 case_WLAN(PREV_AUTH_NOT_VALID);
2984 case_WLAN(DEAUTH_LEAVING);
2985 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2986 case_WLAN(DISASSOC_AP_BUSY);
2987 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2988 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2989 case_WLAN(DISASSOC_STA_HAS_LEFT);
2990 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2991 case_WLAN(DISASSOC_BAD_POWER);
2992 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2993 case_WLAN(INVALID_IE);
2994 case_WLAN(MIC_FAILURE);
2995 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
2996 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
2997 case_WLAN(IE_DIFFERENT);
2998 case_WLAN(INVALID_GROUP_CIPHER);
2999 case_WLAN(INVALID_PAIRWISE_CIPHER);
3000 case_WLAN(INVALID_AKMP);
3001 case_WLAN(UNSUPP_RSN_VERSION);
3002 case_WLAN(INVALID_RSN_IE_CAP);
3003 case_WLAN(IEEE8021X_FAILED);
3004 case_WLAN(CIPHER_SUITE_REJECTED);
3005 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3006 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3007 case_WLAN(DISASSOC_LOW_ACK);
3008 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3009 case_WLAN(QSTA_LEAVE_QBSS);
3010 case_WLAN(QSTA_NOT_USE);
3011 case_WLAN(QSTA_REQUIRE_SETUP);
3012 case_WLAN(QSTA_TIMEOUT);
3013 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3014 case_WLAN(MESH_PEER_CANCELED);
3015 case_WLAN(MESH_MAX_PEERS);
3016 case_WLAN(MESH_CONFIG);
3017 case_WLAN(MESH_CLOSE);
3018 case_WLAN(MESH_MAX_RETRIES);
3019 case_WLAN(MESH_CONFIRM_TIMEOUT);
3020 case_WLAN(MESH_INVALID_GTK);
3021 case_WLAN(MESH_INCONSISTENT_PARAM);
3022 case_WLAN(MESH_INVALID_SECURITY);
3023 case_WLAN(MESH_PATH_ERROR);
3024 case_WLAN(MESH_PATH_NOFORWARD);
3025 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3026 case_WLAN(MAC_EXISTS_IN_MBSS);
3027 case_WLAN(MESH_CHAN_REGULATORY);
3028 case_WLAN(MESH_CHAN);
3029 default: return "<unknown>";
3030 }
3031}
Johannes Berg66e67e42012-01-20 13:55:27 +01003032
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003033static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3034 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003035{
Johannes Berg46900292009-02-15 12:44:28 +01003036 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergc9c99f82015-06-01 14:10:09 +02003037 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07003038
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003039 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003040
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003041 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003042 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003043
Yu Wang79c92ca2019-05-10 17:04:52 +08003044 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3045 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3046 return;
3047 }
3048
Johannes Bergc9c99f82015-06-01 14:10:09 +02003049 if (ifmgd->associated &&
3050 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3051 const u8 *bssid = ifmgd->associated->bssid;
3052
3053 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3054 bssid, reason_code,
3055 ieee80211_get_reason_code_string(reason_code));
3056
3057 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3058
3059 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3060 reason_code);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003061 return;
Johannes Bergc9c99f82015-06-01 14:10:09 +02003062 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003063
Johannes Bergc9c99f82015-06-01 14:10:09 +02003064 if (ifmgd->assoc_data &&
3065 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3066 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07003067
Johannes Bergc9c99f82015-06-01 14:10:09 +02003068 sdata_info(sdata,
3069 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3070 bssid, reason_code,
3071 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07003072
Johannes Berge6f462d2016-12-08 17:22:09 +01003073 ieee80211_destroy_assoc_data(sdata, false, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07003074
Johannes Bergc9c99f82015-06-01 14:10:09 +02003075 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3076 return;
3077 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003078}
3079
3080
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003081static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3082 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003083{
Johannes Berg46900292009-02-15 12:44:28 +01003084 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07003085 u16 reason_code;
3086
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003087 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003088
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003089 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003090 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003091
Johannes Berg66e67e42012-01-20 13:55:27 +01003092 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00003093 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003094 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003095
3096 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3097
Yu Wang79c92ca2019-05-10 17:04:52 +08003098 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3099 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3100 return;
3101 }
3102
Arkadiusz Miskiewicz68506e92017-02-15 14:21:27 +01003103 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3104 mgmt->sa, reason_code,
3105 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07003106
Johannes Berg37ad3882012-02-24 13:50:54 +01003107 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3108
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003109 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07003110}
3111
Christian Lamparterc74d0842011-10-15 00:14:49 +02003112static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3113 u8 *supp_rates, unsigned int supp_rates_len,
3114 u32 *rates, u32 *basic_rates,
3115 bool *have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003116 int *min_rate, int *min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03003117 int shift)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003118{
3119 int i, j;
3120
3121 for (i = 0; i < supp_rates_len; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003122 int rate = supp_rates[i] & 0x7f;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003123 bool is_basic = !!(supp_rates[i] & 0x80);
3124
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003125 if ((rate * 5 * (1 << shift)) > 110)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003126 *have_higher_than_11mbit = true;
3127
3128 /*
Johannes Berga6289d32017-03-06 22:59:04 +01003129 * Skip HT and VHT BSS membership selectors since they're not
3130 * rates.
Christian Lamparterc74d0842011-10-15 00:14:49 +02003131 *
Johannes Berga6289d32017-03-06 22:59:04 +01003132 * Note: Even though the membership selector and the basic
Christian Lamparterc74d0842011-10-15 00:14:49 +02003133 * rate flag share the same bit, they are not exactly
3134 * the same.
3135 */
Johannes Berga6289d32017-03-06 22:59:04 +01003136 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3137 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
Christian Lamparterc74d0842011-10-15 00:14:49 +02003138 continue;
3139
3140 for (j = 0; j < sband->n_bitrates; j++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003141 struct ieee80211_rate *br;
3142 int brate;
3143
3144 br = &sband->bitrates[j];
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003145
3146 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3147 if (brate == rate) {
Christian Lamparterc74d0842011-10-15 00:14:49 +02003148 *rates |= BIT(j);
3149 if (is_basic)
3150 *basic_rates |= BIT(j);
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003151 if ((rate * 5) < *min_rate) {
3152 *min_rate = rate * 5;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003153 *min_rate_index = j;
3154 }
3155 break;
3156 }
3157 }
3158 }
3159}
Jiri Bencf0706e82007-05-05 11:45:53 -07003160
Emmanuel Grumbach55ebd6e2018-12-15 11:03:04 +02003161static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3162 const struct ieee802_11_elems *elems)
3163{
3164 if (elems->ext_capab_len < 10)
3165 return false;
3166
3167 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3168 return false;
3169
3170 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3171 IEEE80211_HE_MAC_CAP0_TWT_RES;
3172}
3173
John Crispinc9d32452019-05-28 13:49:47 +02003174static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3175 struct sta_info *sta,
3176 struct ieee802_11_elems *elems)
3177{
3178 bool twt = ieee80211_twt_req_supported(sta, elems);
3179
3180 if (sdata->vif.bss_conf.twt_requester != twt) {
3181 sdata->vif.bss_conf.twt_requester = twt;
3182 return BSS_CHANGED_TWT;
3183 }
3184 return 0;
3185}
3186
Johannes Berg66e67e42012-01-20 13:55:27 +01003187static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3188 struct cfg80211_bss *cbss,
Johannes Bergf61d7882019-10-28 12:52:42 +01003189 struct ieee80211_mgmt *mgmt, size_t len,
3190 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07003191{
Johannes Berg46900292009-02-15 12:44:28 +01003192 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01003193 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01003194 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003195 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003196 u16 capab_info, aid;
Johannes Bergbda39332008-10-11 01:51:51 +02003197 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg35d865a2013-05-28 10:54:03 +02003198 const struct cfg80211_bss_ies *bss_ies = NULL;
3199 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
Johannes Bergae5eb022008-10-14 16:58:37 +02003200 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003201 int err;
Johannes Berg35d865a2013-05-28 10:54:03 +02003202 bool ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003203
Johannes Bergaf6b6372009-12-23 13:15:35 +01003204 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07003205
Jiri Bencf0706e82007-05-05 11:45:53 -07003206 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003207 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07003208
Johannes Bergc7c477b2017-12-01 13:50:51 +02003209 /*
3210 * The 5 MSB of the AID field are reserved
3211 * (802.11-2016 9.4.1.8 AID field)
3212 */
3213 aid &= 0x7ff;
Johannes Berg1dd84aa2007-10-10 12:03:41 +02003214
Johannes Berg05cb9102011-10-28 11:59:47 +02003215 ifmgd->broken_ap = false;
3216
3217 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003218 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3219 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02003220 aid = 0;
3221 ifmgd->broken_ap = true;
3222 }
3223
Johannes Bergf61d7882019-10-28 12:52:42 +01003224 if (!elems->supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003225 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01003226 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07003227 }
3228
Johannes Berg46900292009-02-15 12:44:28 +01003229 ifmgd->aid = aid;
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02003230 ifmgd->tdls_chan_switch_prohibited =
Johannes Bergf61d7882019-10-28 12:52:42 +01003231 elems->ext_capab && elems->ext_capab_len >= 5 &&
3232 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
Jiri Bencf0706e82007-05-05 11:45:53 -07003233
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003234 /*
Johannes Berg35d865a2013-05-28 10:54:03 +02003235 * Some APs are erroneously not including some information in their
3236 * (re)association response frames. Try to recover by using the data
3237 * from the beacon or probe response. This seems to afflict mobile
3238 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3239 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3240 */
Johannes Bergf61d7882019-10-28 12:52:42 +01003241 if ((assoc_data->wmm && !elems->wmm_param) ||
Johannes Berg35d865a2013-05-28 10:54:03 +02003242 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003243 (!elems->ht_cap_elem || !elems->ht_operation)) ||
Johannes Berg35d865a2013-05-28 10:54:03 +02003244 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003245 (!elems->vht_cap_elem || !elems->vht_operation))) {
Johannes Berg35d865a2013-05-28 10:54:03 +02003246 const struct cfg80211_bss_ies *ies;
3247 struct ieee802_11_elems bss_elems;
3248
3249 rcu_read_lock();
3250 ies = rcu_dereference(cbss->ies);
3251 if (ies)
3252 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3253 GFP_ATOMIC);
3254 rcu_read_unlock();
3255 if (!bss_ies)
3256 return false;
3257
3258 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003259 false, &bss_elems,
3260 mgmt->bssid,
3261 assoc_data->bss->bssid);
Johannes Berg35d865a2013-05-28 10:54:03 +02003262 if (assoc_data->wmm &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003263 !elems->wmm_param && bss_elems.wmm_param) {
3264 elems->wmm_param = bss_elems.wmm_param;
Johannes Berg35d865a2013-05-28 10:54:03 +02003265 sdata_info(sdata,
3266 "AP bug: WMM param missing from AssocResp\n");
3267 }
3268
3269 /*
3270 * Also check if we requested HT/VHT, otherwise the AP doesn't
3271 * have to include the IEs in the (re)association response.
3272 */
Johannes Bergf61d7882019-10-28 12:52:42 +01003273 if (!elems->ht_cap_elem && bss_elems.ht_cap_elem &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003274 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003275 elems->ht_cap_elem = bss_elems.ht_cap_elem;
Johannes Berg35d865a2013-05-28 10:54:03 +02003276 sdata_info(sdata,
3277 "AP bug: HT capability missing from AssocResp\n");
3278 }
Johannes Bergf61d7882019-10-28 12:52:42 +01003279 if (!elems->ht_operation && bss_elems.ht_operation &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003280 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003281 elems->ht_operation = bss_elems.ht_operation;
Johannes Berg35d865a2013-05-28 10:54:03 +02003282 sdata_info(sdata,
3283 "AP bug: HT operation missing from AssocResp\n");
3284 }
Johannes Bergf61d7882019-10-28 12:52:42 +01003285 if (!elems->vht_cap_elem && bss_elems.vht_cap_elem &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003286 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003287 elems->vht_cap_elem = bss_elems.vht_cap_elem;
Johannes Berg35d865a2013-05-28 10:54:03 +02003288 sdata_info(sdata,
3289 "AP bug: VHT capa missing from AssocResp\n");
3290 }
Johannes Bergf61d7882019-10-28 12:52:42 +01003291 if (!elems->vht_operation && bss_elems.vht_operation &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003292 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003293 elems->vht_operation = bss_elems.vht_operation;
Johannes Berg35d865a2013-05-28 10:54:03 +02003294 sdata_info(sdata,
3295 "AP bug: VHT operation missing from AssocResp\n");
3296 }
3297 }
3298
3299 /*
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003300 * We previously checked these in the beacon/probe response, so
3301 * they should be present here. This is just a safety net.
3302 */
3303 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003304 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003305 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003306 "HT AP is missing WMM params or HT capability/operation\n");
3307 ret = false;
3308 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003309 }
3310
3311 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003312 (!elems->vht_cap_elem || !elems->vht_operation)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003313 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003314 "VHT AP is missing VHT capability/operation\n");
3315 ret = false;
3316 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003317 }
3318
Guy Eilam2a33bee2011-08-17 15:18:15 +03003319 mutex_lock(&sdata->local->sta_mtx);
3320 /*
3321 * station info was already allocated and inserted before
3322 * the association and should be available to us
3323 */
Johannes Berg7852e362012-01-20 13:55:24 +01003324 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003325 if (WARN_ON(!sta)) {
3326 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003327 ret = false;
3328 goto out;
Jiri Bencf0706e82007-05-05 11:45:53 -07003329 }
3330
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05303331 sband = ieee80211_get_sband(sdata);
3332 if (!sband) {
3333 mutex_unlock(&sdata->local->sta_mtx);
3334 ret = false;
3335 goto out;
3336 }
Johannes Berg8318d782008-01-24 19:38:38 +01003337
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003338 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003339 (!elems->he_cap || !elems->he_operation)) {
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003340 mutex_unlock(&sdata->local->sta_mtx);
3341 sdata_info(sdata,
3342 "HE AP is missing HE capability/operation\n");
3343 ret = false;
3344 goto out;
3345 }
3346
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003347 /* Set up internal HT/VHT capabilities */
Johannes Bergf61d7882019-10-28 12:52:42 +01003348 if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08003349 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergf61d7882019-10-28 12:52:42 +01003350 elems->ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02003351
Johannes Bergf61d7882019-10-28 12:52:42 +01003352 if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Mahesh Palivela818255e2012-10-10 11:33:04 +00003353 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Bergf61d7882019-10-28 12:52:42 +01003354 elems->vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00003355
Johannes Bergf61d7882019-10-28 12:52:42 +01003356 if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3357 elems->he_cap) {
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003358 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
Johannes Bergf61d7882019-10-28 12:52:42 +01003359 elems->he_cap,
3360 elems->he_cap_len,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003361 sta);
3362
3363 bss_conf->he_support = sta->sta.he_cap.has_he;
Johannes Bergf61d7882019-10-28 12:52:42 +01003364 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003365 } else {
3366 bss_conf->he_support = false;
Emmanuel Grumbach55ebd6e2018-12-15 11:03:04 +02003367 bss_conf->twt_requester = false;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003368 }
3369
3370 if (bss_conf->he_support) {
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003371 bss_conf->bss_color =
Johannes Bergf61d7882019-10-28 12:52:42 +01003372 le32_get_bits(elems->he_operation->he_oper_params,
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003373 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003374
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003375 bss_conf->htc_trig_based_pkt_ext =
Johannes Bergf61d7882019-10-28 12:52:42 +01003376 le32_get_bits(elems->he_operation->he_oper_params,
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003377 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003378 bss_conf->frame_time_rts_th =
Johannes Bergf61d7882019-10-28 12:52:42 +01003379 le32_get_bits(elems->he_operation->he_oper_params,
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003380 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003381
3382 bss_conf->multi_sta_back_32bit =
3383 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3384 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
3385
3386 bss_conf->ack_enabled =
3387 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3388 IEEE80211_HE_MAC_CAP2_ACK_EN;
3389
Johannes Bergf61d7882019-10-28 12:52:42 +01003390 bss_conf->uora_exists = !!elems->uora_element;
3391 if (elems->uora_element)
3392 bss_conf->uora_ocw_range = elems->uora_element[0];
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003393
Johannes Bergf61d7882019-10-28 12:52:42 +01003394 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3395 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003396 /* TODO: OPEN: what happens if BSS color disable is set? */
3397 }
3398
Sara Sharon78ac51f2019-01-16 18:22:56 +02003399 if (cbss->transmitted_bss) {
3400 bss_conf->nontransmitted = true;
3401 ether_addr_copy(bss_conf->transmitter_bssid,
3402 cbss->transmitted_bss->bssid);
3403 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3404 bss_conf->bssid_index = cbss->bssid_index;
3405 }
3406
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003407 /*
3408 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3409 * in their association response, so ignore that data for our own
3410 * configuration. If it changed since the last beacon, we'll get the
3411 * next beacon and update then.
3412 */
Johannes Berg11289582013-02-07 17:36:12 +01003413
Johannes Bergbee7f5862013-02-07 22:24:55 +01003414 /*
3415 * If an operating mode notification IE is present, override the
3416 * NSS calculation (that would be done in rate_control_rate_init())
3417 * and use the # of streams from that element.
3418 */
Johannes Bergf61d7882019-10-28 12:52:42 +01003419 if (elems->opmode_notif &&
3420 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
Johannes Bergbee7f5862013-02-07 22:24:55 +01003421 u8 nss;
3422
Johannes Bergf61d7882019-10-28 12:52:42 +01003423 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
Johannes Bergbee7f5862013-02-07 22:24:55 +01003424 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3425 nss += 1;
3426 sta->sta.rx_nss = nss;
3427 }
3428
Johannes Berg4b7679a2008-09-18 18:14:18 +02003429 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003430
Tamizh chelvam93f04902015-10-07 10:40:04 +05303431 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003432 set_sta_flag(sta, WLAN_STA_MFP);
Tamizh chelvam93f04902015-10-07 10:40:04 +05303433 sta->sta.mfp = true;
3434 } else {
3435 sta->sta.mfp = false;
3436 }
Jouni Malinen5394af42009-01-08 13:31:59 +02003437
Johannes Bergf61d7882019-10-28 12:52:42 +01003438 sta->sta.wme = elems->wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
Johannes Bergddf4ac52008-10-22 11:41:38 +02003439
Johannes Berg3e4d40f2013-02-07 17:19:08 +01003440 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01003441 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3442 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3443 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003444 sdata_info(sdata,
3445 "failed to move station %pM to desired state\n",
3446 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01003447 WARN_ON(__sta_info_destroy(sta));
3448 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003449 ret = false;
3450 goto out;
Johannes Bergc8987872012-01-20 13:55:17 +01003451 }
3452
Johannes Berg7852e362012-01-20 13:55:24 +01003453 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02003454
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003455 /*
3456 * Always handle WMM once after association regardless
3457 * of the first value the AP uses. Setting -1 here has
3458 * that effect because the AP values is an unsigned
3459 * 4-bit value.
3460 */
3461 ifmgd->wmm_last_param_set = -1;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02003462 ifmgd->mu_edca_last_param_set = -1;
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003463
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003464 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Bergcec66282015-10-22 17:46:04 +02003465 ieee80211_set_wmm_default(sdata, false, false);
Johannes Bergf61d7882019-10-28 12:52:42 +01003466 } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
3467 elems->wmm_param_len,
3468 elems->mu_edca_param_set)) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003469 /* still enable QoS since we might have HT/VHT */
3470 ieee80211_set_wmm_default(sdata, false, true);
3471 /* set the disable-WMM flag in this case to disable
3472 * tracking WMM parameter changes in the beacon if
3473 * the parameters weren't actually valid. Doing so
3474 * avoids changing parameters very strangely when
3475 * the AP is going back and forth between valid and
3476 * invalid parameters.
3477 */
3478 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3479 }
Johannes Berg3abead52012-03-02 15:56:59 +01003480 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07003481
Johannes Bergf61d7882019-10-28 12:52:42 +01003482 if (elems->max_idle_period_ie) {
Avraham Sterne38a0172017-04-26 10:58:47 +03003483 bss_conf->max_idle_period =
Johannes Bergf61d7882019-10-28 12:52:42 +01003484 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
Avraham Sterne38a0172017-04-26 10:58:47 +03003485 bss_conf->protected_keep_alive =
Johannes Bergf61d7882019-10-28 12:52:42 +01003486 !!(elems->max_idle_period_ie->idle_options &
Avraham Sterne38a0172017-04-26 10:58:47 +03003487 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3488 changed |= BSS_CHANGED_KEEP_ALIVE;
3489 } else {
3490 bss_conf->max_idle_period = 0;
3491 bss_conf->protected_keep_alive = false;
3492 }
3493
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003494 /* set AID and assoc capability,
3495 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01003496 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003497 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003498 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003499
Kalle Valo15b7b062009-03-22 21:57:14 +02003500 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01003501 * If we're using 4-addr mode, let the AP know that we're
3502 * doing so, so that it can create the STA VLAN on its side
3503 */
3504 if (ifmgd->use_4addr)
3505 ieee80211_send_4addr_nullfunc(local, sdata);
3506
3507 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02003508 * Start timer to probe the connection to the AP now.
3509 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02003510 */
Johannes Bergb291ba12009-07-10 15:29:03 +02003511 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003512 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02003513
Johannes Berg35d865a2013-05-28 10:54:03 +02003514 ret = true;
3515 out:
3516 kfree(bss_ies);
3517 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003518}
3519
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003520static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3521 struct ieee80211_mgmt *mgmt,
3522 size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01003523{
3524 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3525 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3526 u16 capab_info, status_code, aid;
3527 struct ieee802_11_elems elems;
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003528 int ac, uapsd_queues = -1;
Johannes Berg66e67e42012-01-20 13:55:27 +01003529 u8 *pos;
3530 bool reassoc;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003531 struct cfg80211_bss *bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003532 struct ieee80211_event event = {
3533 .type = MLME_EVENT,
3534 .u.mlme.data = ASSOC_EVENT,
3535 };
Jiri Bencf0706e82007-05-05 11:45:53 -07003536
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003537 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003538
3539 if (!assoc_data)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003540 return;
Joe Perchesb203ca32012-05-08 18:56:52 +00003541 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003542 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003543
3544 /*
3545 * AssocResp and ReassocResp have identical structure, so process both
3546 * of them in this function.
3547 */
3548
3549 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003550 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003551
Simon Dinkin7a7d3e42017-08-31 13:09:36 +03003552 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
Johannes Berg66e67e42012-01-20 13:55:27 +01003553 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3554 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3555 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3556
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003557 sdata_info(sdata,
3558 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3559 reassoc ? "Rea" : "A", mgmt->sa,
3560 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01003561
Jouni Malinen39404fe2016-10-27 00:42:05 +03003562 if (assoc_data->fils_kek_len &&
3563 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3564 return;
3565
Johannes Berg66e67e42012-01-20 13:55:27 +01003566 pos = mgmt->u.assoc_resp.variable;
Sara Sharon4abb52a2019-01-16 12:14:41 +02003567 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3568 mgmt->bssid, assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003569
3570 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01003571 elems.timeout_int &&
3572 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003573 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01003574 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01003575 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003576 sdata_info(sdata,
3577 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3578 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01003579 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01003580 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01003581 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003582 run_again(sdata, assoc_data->timeout);
3583 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003584 }
3585
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003586 bss = assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01003587
3588 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003589 sdata_info(sdata, "%pM denied association (code=%d)\n",
3590 mgmt->sa, status_code);
Johannes Berge6f462d2016-12-08 17:22:09 +01003591 ieee80211_destroy_assoc_data(sdata, false, false);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003592 event.u.mlme.status = MLME_DENIED;
3593 event.u.mlme.reason = status_code;
3594 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01003595 } else {
Johannes Bergf61d7882019-10-28 12:52:42 +01003596 if (!ieee80211_assoc_success(sdata, bss, mgmt, len, &elems)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003597 /* oops -- internal error -- send timeout for now */
Johannes Berge6f462d2016-12-08 17:22:09 +01003598 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02003599 cfg80211_assoc_timeout(sdata->dev, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003600 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003601 }
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003602 event.u.mlme.status = MLME_SUCCESS;
3603 drv_event_callback(sdata->local, sdata, &event);
John W. Linville635d9992012-07-09 16:34:34 -04003604 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01003605
3606 /*
3607 * destroy assoc_data afterwards, as otherwise an idle
3608 * recalc after assoc_data is NULL but before associated
3609 * is set can cause the interface to go idle
3610 */
Johannes Berge6f462d2016-12-08 17:22:09 +01003611 ieee80211_destroy_assoc_data(sdata, true, false);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003612
3613 /* get uapsd queues configuration */
3614 uapsd_queues = 0;
3615 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3616 if (sdata->tx_conf[ac].uapsd)
Emmanuel Grumbachf438ceb2016-10-18 23:12:12 +03003617 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
Johannes Berg66e67e42012-01-20 13:55:27 +01003618 }
3619
Jouni Malinen4d9ec732019-02-15 02:14:33 +02003620 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues,
3621 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003622}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003623
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003624static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003625 struct ieee80211_mgmt *mgmt, size_t len,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003626 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003627{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003628 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02003629 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01003630 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01003631
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003632 sdata_assert_lock(sdata);
Johannes Bergb4f286a12013-03-26 14:13:58 +01003633
Emmanuel Grumbach3afc2162014-03-04 16:50:13 +02003634 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3635 if (!channel)
Johannes Berg5bda6172008-09-08 11:05:10 +02003636 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003637
Sara Sharon4abb52a2019-01-16 12:14:41 +02003638 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
Alexander Bondar817cee72013-05-19 14:23:57 +03003639 if (bss) {
Alexander Bondar817cee72013-05-19 14:23:57 +03003640 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
Johannes Bergd2722f82014-03-04 11:43:28 +01003641 ieee80211_rx_bss_put(local, bss);
Alexander Bondar817cee72013-05-19 14:23:57 +03003642 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003643}
3644
3645
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003646static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003647 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003648{
Johannes Bergaf6b6372009-12-23 13:15:35 +01003649 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02003650 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003651 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3652 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03003653
Kalle Valo15b7b062009-03-22 21:57:14 +02003654 ifmgd = &sdata->u.mgd;
3655
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003656 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003657
Joe Perchesb203ca32012-05-08 18:56:52 +00003658 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03003659 return; /* ignore ProbeResp to foreign address */
3660
Ester Kummerae6a44e2008-06-27 18:54:48 +03003661 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3662 if (baselen > len)
3663 return;
3664
Sara Sharon4abb52a2019-01-16 12:14:41 +02003665 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03003666
Johannes Berg77fdaa12009-07-07 03:45:17 +02003667 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003668 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003669 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003670}
3671
Johannes Bergd91f36d2009-04-16 13:17:26 +02003672/*
3673 * This is the canonical list of information elements we care about,
3674 * the filter code also gives us all changes to the Microsoft OUI
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003675 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3676 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3677 * changes to requested client power.
Johannes Bergd91f36d2009-04-16 13:17:26 +02003678 *
3679 * We implement beacon filtering in software since that means we can
3680 * avoid processing the frame here and in cfg80211, and userspace
3681 * will not be able to tell whether the hardware supports it or not.
3682 *
3683 * XXX: This list needs to be dynamic -- userspace needs to be able to
3684 * add items it requires. It also needs to be able to tell us to
3685 * look out for other vendor IEs.
3686 */
3687static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02003688 (1ULL << WLAN_EID_COUNTRY) |
3689 (1ULL << WLAN_EID_ERP_INFO) |
3690 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3691 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3692 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg70a3fd62015-03-12 08:53:29 +02003693 (1ULL << WLAN_EID_HT_OPERATION) |
3694 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003695
Tosoni1ad22fb2018-03-14 16:58:34 +00003696static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3697 struct ieee80211_if_managed *ifmgd,
3698 struct ieee80211_bss_conf *bss_conf,
3699 struct ieee80211_local *local,
3700 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003701{
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003702 /* Track average RSSI from the Beacon frames of the current AP */
Tosoni1ad22fb2018-03-14 16:58:34 +00003703
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003704 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3705 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Johannes Berg338c17a2015-08-28 10:52:54 +02003706 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003707 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03003708 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003709 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003710 } else {
Jouni Malinen391a2002010-08-27 22:22:00 +03003711 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003712 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003713
Johannes Berg338c17a2015-08-28 10:52:54 +02003714 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3715
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003716 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3717 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003718 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003719 int last_sig = ifmgd->last_ave_beacon_signal;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003720 struct ieee80211_event event = {
3721 .type = RSSI_EVENT,
3722 };
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003723
3724 /*
3725 * if signal crosses either of the boundaries, invoke callback
3726 * with appropriate parameters
3727 */
3728 if (sig > ifmgd->rssi_max_thold &&
3729 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3730 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003731 event.u.rssi.data = RSSI_EVENT_HIGH;
3732 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003733 } else if (sig < ifmgd->rssi_min_thold &&
3734 (last_sig >= ifmgd->rssi_max_thold ||
3735 last_sig == 0)) {
3736 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003737 event.u.rssi.data = RSSI_EVENT_LOW;
3738 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003739 }
3740 }
3741
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003742 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03003743 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01003744 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003745 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003746 int last_event = ifmgd->last_cqm_event_signal;
3747 int thold = bss_conf->cqm_rssi_thold;
3748 int hyst = bss_conf->cqm_rssi_hyst;
Johannes Berg338c17a2015-08-28 10:52:54 +02003749
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003750 if (sig < thold &&
3751 (last_event == 0 || sig < last_event - hyst)) {
3752 ifmgd->last_cqm_event_signal = sig;
3753 ieee80211_cqm_rssi_notify(
3754 &sdata->vif,
3755 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003756 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003757 } else if (sig > thold &&
3758 (last_event == 0 || sig > last_event + hyst)) {
3759 ifmgd->last_cqm_event_signal = sig;
3760 ieee80211_cqm_rssi_notify(
3761 &sdata->vif,
3762 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003763 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003764 }
3765 }
3766
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003767 if (bss_conf->cqm_rssi_low &&
3768 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3769 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3770 int last_event = ifmgd->last_cqm_event_signal;
3771 int low = bss_conf->cqm_rssi_low;
3772 int high = bss_conf->cqm_rssi_high;
3773
3774 if (sig < low &&
3775 (last_event == 0 || last_event >= low)) {
3776 ifmgd->last_cqm_event_signal = sig;
3777 ieee80211_cqm_rssi_notify(
3778 &sdata->vif,
3779 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3780 sig, GFP_KERNEL);
3781 } else if (sig > high &&
3782 (last_event == 0 || last_event <= high)) {
3783 ifmgd->last_cqm_event_signal = sig;
3784 ieee80211_cqm_rssi_notify(
3785 &sdata->vif,
3786 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3787 sig, GFP_KERNEL);
3788 }
3789 }
Tosoni1ad22fb2018-03-14 16:58:34 +00003790}
3791
Sara Sharon78ac51f2019-01-16 18:22:56 +02003792static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
3793 struct cfg80211_bss *bss)
3794{
3795 if (ether_addr_equal(tx_bssid, bss->bssid))
3796 return true;
3797 if (!bss->transmitted_bss)
3798 return false;
3799 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
3800}
3801
Tosoni1ad22fb2018-03-14 16:58:34 +00003802static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3803 struct ieee80211_mgmt *mgmt, size_t len,
3804 struct ieee80211_rx_status *rx_status)
3805{
3806 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3807 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3808 size_t baselen;
3809 struct ieee802_11_elems elems;
3810 struct ieee80211_local *local = sdata->local;
3811 struct ieee80211_chanctx_conf *chanctx_conf;
3812 struct ieee80211_channel *chan;
3813 struct sta_info *sta;
3814 u32 changed = 0;
3815 bool erp_valid;
3816 u8 erp_value = 0;
3817 u32 ncrc;
3818 u8 *bssid;
3819 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3820
3821 sdata_assert_lock(sdata);
3822
3823 /* Process beacon from the current BSS */
3824 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3825 if (baselen > len)
3826 return;
3827
3828 rcu_read_lock();
3829 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3830 if (!chanctx_conf) {
3831 rcu_read_unlock();
3832 return;
3833 }
3834
3835 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3836 rcu_read_unlock();
3837 return;
3838 }
3839 chan = chanctx_conf->def.chan;
3840 rcu_read_unlock();
3841
3842 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
Sara Sharon78ac51f2019-01-16 18:22:56 +02003843 ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->assoc_data->bss)) {
Tosoni1ad22fb2018-03-14 16:58:34 +00003844 ieee802_11_parse_elems(mgmt->u.beacon.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003845 len - baselen, false, &elems,
3846 mgmt->bssid,
3847 ifmgd->assoc_data->bss->bssid);
Tosoni1ad22fb2018-03-14 16:58:34 +00003848
Sara Sharon4abb52a2019-01-16 12:14:41 +02003849 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Sara Sharon78ac51f2019-01-16 18:22:56 +02003850
3851 if (elems.dtim_period)
3852 ifmgd->dtim_period = elems.dtim_period;
Tosoni1ad22fb2018-03-14 16:58:34 +00003853 ifmgd->have_beacon = true;
3854 ifmgd->assoc_data->need_beacon = false;
3855 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3856 sdata->vif.bss_conf.sync_tsf =
3857 le64_to_cpu(mgmt->u.beacon.timestamp);
3858 sdata->vif.bss_conf.sync_device_ts =
3859 rx_status->device_timestamp;
Sara Sharon78ac51f2019-01-16 18:22:56 +02003860 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
Tosoni1ad22fb2018-03-14 16:58:34 +00003861 }
Sara Sharon78ac51f2019-01-16 18:22:56 +02003862
3863 if (elems.mbssid_config_ie)
3864 bss_conf->profile_periodicity =
3865 elems.mbssid_config_ie->profile_periodicity;
3866
3867 if (elems.ext_capab_len >= 11 &&
3868 (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
3869 bss_conf->ema_ap = true;
3870
Tosoni1ad22fb2018-03-14 16:58:34 +00003871 /* continue assoc process */
3872 ifmgd->assoc_data->timeout = jiffies;
3873 ifmgd->assoc_data->timeout_started = true;
3874 run_again(sdata, ifmgd->assoc_data->timeout);
3875 return;
3876 }
3877
3878 if (!ifmgd->associated ||
Sara Sharon78ac51f2019-01-16 18:22:56 +02003879 !ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->associated))
Tosoni1ad22fb2018-03-14 16:58:34 +00003880 return;
3881 bssid = ifmgd->associated->bssid;
3882
3883 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3884 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
3885 local, rx_status);
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003886
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003887 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003888 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01003889 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003890 ieee80211_reset_ap_probe(sdata);
Jouni Malinen92778182009-05-14 21:15:36 +03003891 }
3892
Johannes Bergb291ba12009-07-10 15:29:03 +02003893 /*
3894 * Push the beacon loss detection into the future since
3895 * we are processing a beacon from the AP just now.
3896 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003897 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003898
Johannes Bergd91f36d2009-04-16 13:17:26 +02003899 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3900 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003901 len - baselen, false, &elems,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003902 care_about_ies, ncrc,
3903 mgmt->bssid, bssid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003904
Johannes Berg90d13e82015-09-24 16:13:07 +02003905 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3906 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3907 if (local->hw.conf.dynamic_ps_timeout > 0) {
3908 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3909 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3910 ieee80211_hw_config(local,
3911 IEEE80211_CONF_CHANGE_PS);
Kalle Valo572e0012009-02-10 17:09:31 +02003912 }
Johannes Berg076cdcb2015-09-24 16:14:55 +02003913 ieee80211_send_nullfunc(local, sdata, false);
Johannes Berg90d13e82015-09-24 16:13:07 +02003914 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3915 local->pspolling = true;
3916
3917 /*
3918 * Here is assumed that the driver will be
3919 * able to send ps-poll frame and receive a
3920 * response even though power save mode is
3921 * enabled, but some drivers might require
3922 * to disable power save here. This needs
3923 * to be investigated.
3924 */
3925 ieee80211_send_pspoll(local, sdata);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003926 }
3927 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003928
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01003929 if (sdata->vif.p2p ||
3930 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003931 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003932 int ret;
3933
3934 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3935 len - baselen,
3936 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003937 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003938 if (ret >= 2) {
3939 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3940 /* valid noa_attr and index changed */
3941 sdata->u.mgd.p2p_noa_index = noa.index;
3942 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3943 changed |= BSS_CHANGED_P2P_PS;
3944 /*
3945 * make sure we update all information, the CRC
3946 * mechanism doesn't look at P2P attributes.
3947 */
3948 ifmgd->beacon_crc_valid = false;
3949 }
3950 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3951 /* noa_attr not found and we had valid noa_attr before */
3952 sdata->u.mgd.p2p_noa_index = -1;
3953 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003954 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003955 ifmgd->beacon_crc_valid = false;
3956 }
3957 }
3958
Luciano Coelho0c21e632014-10-08 09:48:39 +03003959 if (ifmgd->csa_waiting_bcn)
3960 ieee80211_chswitch_post_beacon(sdata);
3961
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003962 /*
3963 * Update beacon timing and dtim count on every beacon appearance. This
3964 * will allow the driver to use the most updated values. Do it before
3965 * comparing this one with last received beacon.
3966 * IMPORTANT: These parameters would possibly be out of sync by the time
3967 * the driver will use them. The synchronized view is currently
3968 * guaranteed only in certain callbacks.
3969 */
Johannes Berg30686bf2015-06-02 21:39:54 +02003970 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003971 sdata->vif.bss_conf.sync_tsf =
3972 le64_to_cpu(mgmt->u.beacon.timestamp);
3973 sdata->vif.bss_conf.sync_device_ts =
3974 rx_status->device_timestamp;
Sara Sharon78ac51f2019-01-16 18:22:56 +02003975 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003976 }
3977
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003978 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003979 return;
Jouni Malinen30196672009-05-19 17:01:43 +03003980 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003981 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03003982
Sara Sharon4abb52a2019-01-16 12:14:41 +02003983 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Johannes Berg7d257452012-07-06 17:37:43 +02003984
Johannes Bergd70b7612013-08-23 15:48:48 +02003985 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003986 rx_status->device_timestamp,
Johannes Bergd70b7612013-08-23 15:48:48 +02003987 &elems, true);
3988
Johannes Berg095d81c2013-10-15 12:25:07 +02003989 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
3990 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003991 elems.wmm_param_len,
3992 elems.mu_edca_param_set))
Johannes Berg7d257452012-07-06 17:37:43 +02003993 changed |= BSS_CHANGED_QOS;
3994
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003995 /*
3996 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01003997 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003998 */
Alexander Bondar989c6502013-05-16 17:34:17 +03003999 if (!ifmgd->have_beacon) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004000 /* a few bogus AP send dtim_period = 0 or no TIM IE */
Sara Sharon78ac51f2019-01-16 18:22:56 +02004001 bss_conf->dtim_period = elems.dtim_period ?: 1;
Johannes Bergef429da2013-02-05 17:48:40 +01004002
Alexander Bondar989c6502013-05-16 17:34:17 +03004003 changed |= BSS_CHANGED_BEACON_INFO;
4004 ifmgd->have_beacon = true;
Alexander Bondar482a9c72013-06-03 17:29:33 +03004005
4006 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02004007 ieee80211_recalc_ps(local);
Alexander Bondar482a9c72013-06-03 17:29:33 +03004008 mutex_unlock(&local->iflist_mtx);
4009
Alexander Bondarce857882013-05-06 17:17:04 +03004010 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004011 }
4012
Johannes Berg1946bed2013-03-27 14:31:53 +01004013 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02004014 erp_valid = true;
4015 erp_value = elems.erp_info[0];
4016 } else {
4017 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04004018 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02004019 changed |= ieee80211_handle_bss_capability(sdata,
4020 le16_to_cpu(mgmt->u.beacon.capab_info),
4021 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07004022
Johannes Berg11289582013-02-07 17:36:12 +01004023 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f5862013-02-07 22:24:55 +01004024 sta = sta_info_get(sdata, bssid);
4025
John Crispinc9d32452019-05-28 13:49:47 +02004026 changed |= ieee80211_recalc_twt_req(sdata, sta, &elems);
4027
Eliad Peller53b954e2014-07-24 11:20:05 +03004028 if (ieee80211_config_bw(sdata, sta,
4029 elems.ht_cap_elem, elems.ht_operation,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004030 elems.vht_operation, elems.he_operation,
4031 bssid, &changed)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01004032 mutex_unlock(&local->sta_mtx);
Johannes Berg89f774e2016-01-25 15:46:36 +02004033 sdata_info(sdata,
4034 "failed to follow AP %pM bandwidth change, disconnect\n",
4035 bssid);
Johannes Berg30eb1dc2013-02-08 15:12:14 +01004036 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4037 WLAN_REASON_DEAUTH_LEAVING,
4038 true, deauth_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004039 ieee80211_report_disconnect(sdata, deauth_buf,
4040 sizeof(deauth_buf), true,
4041 WLAN_REASON_DEAUTH_LEAVING);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004042 return;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01004043 }
Johannes Bergbee7f5862013-02-07 22:24:55 +01004044
4045 if (sta && elems.opmode_notif)
4046 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
Eyal Shapiracf1e05c2015-12-08 16:04:36 +02004047 rx_status->band);
Johannes Berg11289582013-02-07 17:36:12 +01004048 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02004049
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07004050 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4051 elems.country_elem,
4052 elems.country_elem_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07004053 elems.pwr_constr_elem,
4054 elems.cisco_dtpc_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08004055
Johannes Berg471b3ef2007-12-28 14:32:58 +01004056 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07004057}
4058
Johannes Berg1fa57d02010-06-10 10:21:32 +02004059void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4060 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07004061{
4062 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07004063 struct ieee80211_mgmt *mgmt;
4064 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004065 struct ieee802_11_elems elems;
4066 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07004067
Jiri Bencf0706e82007-05-05 11:45:53 -07004068 rx_status = (struct ieee80211_rx_status *) skb->cb;
4069 mgmt = (struct ieee80211_mgmt *) skb->data;
4070 fc = le16_to_cpu(mgmt->frame_control);
4071
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004072 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004073
Johannes Berg66e67e42012-01-20 13:55:27 +01004074 switch (fc & IEEE80211_FCTL_STYPE) {
4075 case IEEE80211_STYPE_BEACON:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004076 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01004077 break;
4078 case IEEE80211_STYPE_PROBE_RESP:
4079 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4080 break;
4081 case IEEE80211_STYPE_AUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004082 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004083 break;
4084 case IEEE80211_STYPE_DEAUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004085 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004086 break;
4087 case IEEE80211_STYPE_DISASSOC:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004088 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004089 break;
4090 case IEEE80211_STYPE_ASSOC_RESP:
4091 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004092 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004093 break;
4094 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01004095 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004096 ies_len = skb->len -
4097 offsetof(struct ieee80211_mgmt,
4098 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01004099
4100 if (ies_len < 0)
4101 break;
4102
Sara Sharon4abb52a2019-01-16 12:14:41 +02004103 /* CSA IE cannot be overridden, no need for BSSID */
Johannes Berg37799e52013-03-26 14:02:26 +01004104 ieee802_11_parse_elems(
4105 mgmt->u.action.u.chan_switch.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02004106 ies_len, true, &elems, mgmt->bssid, NULL);
Johannes Berg37799e52013-03-26 14:02:26 +01004107
4108 if (elems.parse_error)
4109 break;
4110
Johannes Berg66e67e42012-01-20 13:55:27 +01004111 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03004112 rx_status->mactime,
4113 rx_status->device_timestamp,
4114 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004115 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4116 ies_len = skb->len -
4117 offsetof(struct ieee80211_mgmt,
4118 u.action.u.ext_chan_switch.variable);
4119
4120 if (ies_len < 0)
4121 break;
4122
Sara Sharon4abb52a2019-01-16 12:14:41 +02004123 /*
4124 * extended CSA IE can't be overridden, no need for
4125 * BSSID
4126 */
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004127 ieee802_11_parse_elems(
4128 mgmt->u.action.u.ext_chan_switch.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02004129 ies_len, true, &elems, mgmt->bssid, NULL);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004130
4131 if (elems.parse_error)
4132 break;
4133
4134 /* for the handling code pretend this was also an IE */
4135 elems.ext_chansw_ie =
4136 &mgmt->u.action.u.ext_chan_switch.data;
4137
4138 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03004139 rx_status->mactime,
4140 rx_status->device_timestamp,
4141 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004142 }
Johannes Berg37799e52013-03-26 14:02:26 +01004143 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004144 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004145 sdata_unlock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07004146}
4147
Kees Cook34f11cd2017-10-16 16:35:49 -07004148static void ieee80211_sta_timer(struct timer_list *t)
Jiri Bencf0706e82007-05-05 11:45:53 -07004149{
4150 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004151 from_timer(sdata, t, u.mgd.timer);
Jiri Bencf0706e82007-05-05 11:45:53 -07004152
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01004153 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07004154}
4155
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004156static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01004157 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004158{
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004159 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004160
Johannes Berg37ad3882012-02-24 13:50:54 +01004161 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01004162 tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01004163
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004164 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4165 reason);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004166}
4167
Johannes Berg46cad4b2015-08-15 22:39:54 +03004168static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg66e67e42012-01-20 13:55:27 +01004169{
4170 struct ieee80211_local *local = sdata->local;
4171 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4172 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004173 u32 tx_flags = 0;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004174 u16 trans = 1;
4175 u16 status = 0;
Ilan Peerd4e36e52018-04-20 13:49:25 +03004176 u16 prepare_tx_duration = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004177
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004178 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004179
4180 if (WARN_ON_ONCE(!auth_data))
4181 return -EINVAL;
4182
Johannes Berg66e67e42012-01-20 13:55:27 +01004183 auth_data->tries++;
4184
4185 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004186 sdata_info(sdata, "authentication with %pM timed out\n",
4187 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004188
4189 /*
4190 * Most likely AP is not in the range so remove the
4191 * bss struct for that AP.
4192 */
4193 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4194
4195 return -ETIMEDOUT;
4196 }
4197
Ilan Peerd4e36e52018-04-20 13:49:25 +03004198 if (auth_data->algorithm == WLAN_AUTH_SAE)
4199 prepare_tx_duration =
4200 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4201
4202 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
Johannes Berga1845fc2012-06-27 13:18:36 +02004203
Johannes Berg46cad4b2015-08-15 22:39:54 +03004204 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4205 auth_data->bss->bssid, auth_data->tries,
4206 IEEE80211_AUTH_MAX_TRIES);
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004207
Johannes Berg46cad4b2015-08-15 22:39:54 +03004208 auth_data->expected_transaction = 2;
Johannes Berg66e67e42012-01-20 13:55:27 +01004209
Johannes Berg46cad4b2015-08-15 22:39:54 +03004210 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4211 trans = auth_data->sae_trans;
4212 status = auth_data->sae_status;
4213 auth_data->expected_transaction = trans;
Johannes Berg66e67e42012-01-20 13:55:27 +01004214 }
4215
Johannes Berg46cad4b2015-08-15 22:39:54 +03004216 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4217 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4218 IEEE80211_TX_INTFL_MLME_CONN_TX;
4219
4220 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4221 auth_data->data, auth_data->data_len,
4222 auth_data->bss->bssid,
4223 auth_data->bss->bssid, NULL, 0, 0,
4224 tx_flags);
4225
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02004226 if (tx_flags == 0) {
Ilan Peer407879b2018-04-20 13:49:20 +03004227 if (auth_data->algorithm == WLAN_AUTH_SAE)
4228 auth_data->timeout = jiffies +
4229 IEEE80211_AUTH_TIMEOUT_SAE;
4230 else
4231 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004232 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004233 auth_data->timeout =
4234 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004235 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004236
Ilan Peer407879b2018-04-20 13:49:20 +03004237 auth_data->timeout_started = true;
4238 run_again(sdata, auth_data->timeout);
4239
Johannes Berg66e67e42012-01-20 13:55:27 +01004240 return 0;
4241}
4242
4243static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4244{
4245 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4246 struct ieee80211_local *local = sdata->local;
4247
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004248 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004249
Johannes Berg66e67e42012-01-20 13:55:27 +01004250 assoc_data->tries++;
4251 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004252 sdata_info(sdata, "association with %pM timed out\n",
4253 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004254
4255 /*
4256 * Most likely AP is not in the range so remove the
4257 * bss struct for that AP.
4258 */
4259 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4260
4261 return -ETIMEDOUT;
4262 }
4263
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004264 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4265 assoc_data->bss->bssid, assoc_data->tries,
4266 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01004267 ieee80211_send_assoc(sdata);
4268
Johannes Berg30686bf2015-06-02 21:39:54 +02004269 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004270 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004271 assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004272 run_again(sdata, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01004273 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004274 assoc_data->timeout =
4275 round_jiffies_up(jiffies +
4276 IEEE80211_ASSOC_TIMEOUT_LONG);
4277 assoc_data->timeout_started = true;
4278 run_again(sdata, assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004279 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004280
4281 return 0;
4282}
4283
Johannes Berg1672c0e32013-01-29 15:02:27 +01004284void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4285 __le16 fc, bool acked)
4286{
4287 struct ieee80211_local *local = sdata->local;
4288
4289 sdata->u.mgd.status_fc = fc;
4290 sdata->u.mgd.status_acked = acked;
4291 sdata->u.mgd.status_received = true;
4292
4293 ieee80211_queue_work(&local->hw, &sdata->work);
4294}
4295
Johannes Berg1fa57d02010-06-10 10:21:32 +02004296void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004297{
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004298 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02004299 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004300
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004301 sdata_lock(sdata);
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004302
Johannes Berg1672c0e32013-01-29 15:02:27 +01004303 if (ifmgd->status_received) {
4304 __le16 fc = ifmgd->status_fc;
4305 bool status_acked = ifmgd->status_acked;
4306
4307 ifmgd->status_received = false;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004308 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004309 if (status_acked) {
Ilan Peer407879b2018-04-20 13:49:20 +03004310 if (ifmgd->auth_data->algorithm ==
4311 WLAN_AUTH_SAE)
4312 ifmgd->auth_data->timeout =
4313 jiffies +
4314 IEEE80211_AUTH_TIMEOUT_SAE;
4315 else
4316 ifmgd->auth_data->timeout =
4317 jiffies +
4318 IEEE80211_AUTH_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004319 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004320 } else {
4321 ifmgd->auth_data->timeout = jiffies - 1;
4322 }
Johannes Berg89afe612013-02-13 15:39:57 +01004323 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004324 } else if (ifmgd->assoc_data &&
4325 (ieee80211_is_assoc_req(fc) ||
4326 ieee80211_is_reassoc_req(fc))) {
4327 if (status_acked) {
4328 ifmgd->assoc_data->timeout =
4329 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004330 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004331 } else {
4332 ifmgd->assoc_data->timeout = jiffies - 1;
4333 }
Johannes Berg89afe612013-02-13 15:39:57 +01004334 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004335 }
4336 }
4337
Johannes Berg89afe612013-02-13 15:39:57 +01004338 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004339 time_after(jiffies, ifmgd->auth_data->timeout)) {
4340 if (ifmgd->auth_data->done) {
4341 /*
4342 * ok ... we waited for assoc but userspace didn't,
4343 * so let's just kill the auth data
4344 */
4345 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg46cad4b2015-08-15 22:39:54 +03004346 } else if (ieee80211_auth(sdata)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004347 u8 bssid[ETH_ALEN];
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004348 struct ieee80211_event event = {
4349 .type = MLME_EVENT,
4350 .u.mlme.data = AUTH_EVENT,
4351 .u.mlme.status = MLME_TIMEOUT,
4352 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004353
4354 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4355
4356 ieee80211_destroy_auth_data(sdata, false);
4357
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004358 cfg80211_auth_timeout(sdata->dev, bssid);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004359 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004360 }
Johannes Berg89afe612013-02-13 15:39:57 +01004361 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004362 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004363
Johannes Berg89afe612013-02-13 15:39:57 +01004364 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004365 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Alexander Bondar989c6502013-05-16 17:34:17 +03004366 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01004367 ieee80211_do_assoc(sdata)) {
Johannes Berg959867f2013-06-19 13:05:42 +02004368 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004369 struct ieee80211_event event = {
4370 .type = MLME_EVENT,
4371 .u.mlme.data = ASSOC_EVENT,
4372 .u.mlme.status = MLME_TIMEOUT,
4373 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004374
Johannes Berge6f462d2016-12-08 17:22:09 +01004375 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02004376 cfg80211_assoc_timeout(sdata->dev, bss);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004377 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004378 }
Johannes Berg89afe612013-02-13 15:39:57 +01004379 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004380 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004381
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02004382 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
Johannes Bergb291ba12009-07-10 15:29:03 +02004383 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03004384 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004385 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03004386
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004387 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004388
Johannes Berg30686bf2015-06-02 21:39:54 +02004389 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Ben Greear180205b2011-02-04 15:30:24 -08004390 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004391 else
Ben Greear180205b2011-02-04 15:30:24 -08004392 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004393
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004394 /* ACK received for nullfunc probing frame */
4395 if (!ifmgd->probe_send_count)
4396 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004397 else if (ifmgd->nullfunc_failed) {
4398 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004399 mlme_dbg(sdata,
4400 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4401 bssid, ifmgd->probe_send_count,
4402 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004403 ieee80211_mgd_probe_ap_send(sdata);
4404 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004405 mlme_dbg(sdata,
4406 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4407 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02004408 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004409 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4410 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004411 }
4412 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004413 run_again(sdata, ifmgd->probe_timeout);
Johannes Berg30686bf2015-06-02 21:39:54 +02004414 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004415 mlme_dbg(sdata,
4416 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4417 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02004418 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004419 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004420 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004421 mlme_dbg(sdata,
4422 "No probe response from AP %pM after %dms, try %d/%i\n",
4423 bssid, probe_wait_ms,
4424 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03004425 ieee80211_mgd_probe_ap_send(sdata);
4426 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02004427 /*
4428 * We actually lost the connection ... or did we?
4429 * Let's make sure!
4430 */
Johannes Berg89f774e2016-01-25 15:46:36 +02004431 mlme_dbg(sdata,
4432 "No probe response from AP %pM after %dms, disconnecting.\n",
4433 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004434
Johannes Berg95acac62011-07-12 12:30:59 +02004435 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004436 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02004437 }
4438 }
4439
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004440 sdata_unlock(sdata);
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004441}
Johannes Berg0a51b272008-09-08 17:44:25 +02004442
Kees Cook34f11cd2017-10-16 16:35:49 -07004443static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004444{
4445 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004446 from_timer(sdata, t, u.mgd.bcn_mon_timer);
Luciano Coelho0c21e632014-10-08 09:48:39 +03004447 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004448
Luciano Coelho0c21e632014-10-08 09:48:39 +03004449 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004450 return;
4451
Johannes Berg682bd382013-01-29 13:13:50 +01004452 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004453 ieee80211_queue_work(&sdata->local->hw,
4454 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004455}
4456
Kees Cook34f11cd2017-10-16 16:35:49 -07004457static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004458{
4459 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004460 from_timer(sdata, t, u.mgd.conn_mon_timer);
Johannes Bergb291ba12009-07-10 15:29:03 +02004461 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4462 struct ieee80211_local *local = sdata->local;
4463
Luciano Coelho0c21e632014-10-08 09:48:39 +03004464 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004465 return;
4466
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04004467 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004468}
4469
4470static void ieee80211_sta_monitor_work(struct work_struct *work)
4471{
4472 struct ieee80211_sub_if_data *sdata =
4473 container_of(work, struct ieee80211_sub_if_data,
4474 u.mgd.monitor_work);
4475
4476 ieee80211_mgd_probe_ap(sdata, false);
4477}
4478
Johannes Berga1678f82008-09-11 00:01:47 +02004479static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4480{
Kalle Vaload935682009-04-19 08:47:19 +03004481 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02004482 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03004483
Johannes Bergb291ba12009-07-10 15:29:03 +02004484 /* let's probe the connection once */
Johannes Berg30686bf2015-06-02 21:39:54 +02004485 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Eliad Peller494f1fe2012-02-19 15:26:09 +02004486 ieee80211_queue_work(&sdata->local->hw,
4487 &sdata->u.mgd.monitor_work);
Kalle Vaload935682009-04-19 08:47:19 +03004488 }
Johannes Berga1678f82008-09-11 00:01:47 +02004489}
4490
Johannes Bergb8360ab2013-04-29 14:57:44 +02004491#ifdef CONFIG_PM
Johannes Berg1a1cb742014-03-19 09:55:55 +01004492void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4493{
4494 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4495 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4496
4497 sdata_lock(sdata);
4498
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004499 if (ifmgd->auth_data || ifmgd->assoc_data) {
4500 const u8 *bssid = ifmgd->auth_data ?
4501 ifmgd->auth_data->bss->bssid :
4502 ifmgd->assoc_data->bss->bssid;
4503
Johannes Berg1a1cb742014-03-19 09:55:55 +01004504 /*
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004505 * If we are trying to authenticate / associate while suspending,
4506 * cfg80211 won't know and won't actually abort those attempts,
4507 * thus we need to do that ourselves.
Johannes Berg1a1cb742014-03-19 09:55:55 +01004508 */
Johannes Berg4b08d1b2019-08-30 14:24:51 +03004509 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
Johannes Berg1a1cb742014-03-19 09:55:55 +01004510 IEEE80211_STYPE_DEAUTH,
4511 WLAN_REASON_DEAUTH_LEAVING,
4512 false, frame_buf);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004513 if (ifmgd->assoc_data)
Johannes Berge6f462d2016-12-08 17:22:09 +01004514 ieee80211_destroy_assoc_data(sdata, false, true);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004515 if (ifmgd->auth_data)
4516 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg1a1cb742014-03-19 09:55:55 +01004517 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4518 IEEE80211_DEAUTH_FRAME_LEN);
4519 }
4520
Johannes Bergbe72afe2015-03-01 09:10:03 +02004521 /* This is a bit of a hack - we should find a better and more generic
4522 * solution to this. Normally when suspending, cfg80211 will in fact
4523 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4524 * auth (not so important) or assoc (this is the problem) process.
4525 *
4526 * As a consequence, it can happen that we are in the process of both
4527 * associating and suspending, and receive an association response
4528 * after cfg80211 has checked if it needs to disconnect, but before
4529 * we actually set the flag to drop incoming frames. This will then
4530 * cause the workqueue flush to process the association response in
4531 * the suspend, resulting in a successful association just before it
4532 * tries to remove the interface from the driver, which now though
4533 * has a channel context assigned ... this results in issues.
4534 *
4535 * To work around this (for now) simply deauth here again if we're
4536 * now connected.
4537 */
4538 if (ifmgd->associated && !sdata->local->wowlan) {
4539 u8 bssid[ETH_ALEN];
4540 struct cfg80211_deauth_request req = {
4541 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4542 .bssid = bssid,
4543 };
4544
4545 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4546 ieee80211_mgd_deauth(sdata, &req);
4547 }
4548
Johannes Berg1a1cb742014-03-19 09:55:55 +01004549 sdata_unlock(sdata);
4550}
4551
Johannes Bergb8360ab2013-04-29 14:57:44 +02004552void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4553{
4554 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4555
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004556 sdata_lock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004557 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004558 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004559 return;
4560 }
4561
4562 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4563 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4564 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4565 ieee80211_sta_connection_lost(sdata,
4566 ifmgd->associated->bssid,
4567 WLAN_REASON_UNSPECIFIED,
4568 true);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004569 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004570 return;
4571 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004572 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004573}
4574#endif
4575
Johannes Berg9c6bd792008-09-11 00:01:52 +02004576/* interface setup */
4577void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4578{
Johannes Berg46900292009-02-15 12:44:28 +01004579 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004580
Johannes Berg46900292009-02-15 12:44:28 +01004581 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004582 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01004583 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004584 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4585 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02004586 INIT_WORK(&ifmgd->csa_connection_drop_work,
4587 ieee80211_csa_connection_drop_work);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03004588 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03004589 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4590 ieee80211_tdls_peer_del_work);
Kees Cook34f11cd2017-10-16 16:35:49 -07004591 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4592 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4593 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4594 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
Johannes Berg02219b32014-10-07 10:38:50 +03004595 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4596 ieee80211_sta_handle_tspec_ac_params_wk);
Johannes Berg9c6bd792008-09-11 00:01:52 +02004597
Johannes Bergab1faea2009-07-01 21:41:17 +02004598 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05304599 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02004600 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4601 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01004602 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02004603
Eliad Peller0d8614b2014-09-10 14:07:36 +03004604 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
Johannes Berg0f782312009-12-01 13:37:02 +01004605 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4606 else
4607 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02004608
4609 /* Setup TDLS data */
4610 spin_lock_init(&ifmgd->teardown_lock);
4611 ifmgd->teardown_skb = NULL;
4612 ifmgd->orig_teardown_skb = NULL;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004613}
4614
4615/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02004616void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4617{
Johannes Berg31ee67a2012-07-06 21:18:24 +02004618 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02004619
4620 /* Restart STA timers */
4621 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07004622 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4623 if (ieee80211_sdata_running(sdata))
4624 ieee80211_restart_sta_timer(sdata);
4625 }
Johannes Berga1678f82008-09-11 00:01:47 +02004626 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02004627}
Johannes Berg10f644a2009-04-16 13:17:25 +02004628
Johannes Bergf2d9d272012-11-22 14:11:39 +01004629static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4630 struct cfg80211_bss *cbss)
4631{
4632 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4633 const u8 *ht_cap_ie, *vht_cap_ie;
4634 const struct ieee80211_ht_cap *ht_cap;
4635 const struct ieee80211_vht_cap *vht_cap;
4636 u8 chains = 1;
4637
4638 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4639 return chains;
4640
Johannes Berg9caf0362012-11-29 01:25:20 +01004641 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004642 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4643 ht_cap = (void *)(ht_cap_ie + 2);
4644 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4645 /*
4646 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4647 * "Tx Unequal Modulation Supported" fields.
4648 */
4649 }
4650
4651 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4652 return chains;
4653
Johannes Berg9caf0362012-11-29 01:25:20 +01004654 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004655 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4656 u8 nss;
4657 u16 tx_mcs_map;
4658
4659 vht_cap = (void *)(vht_cap_ie + 2);
4660 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4661 for (nss = 8; nss > 0; nss--) {
4662 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4663 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4664 break;
4665 }
4666 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4667 chains = max(chains, nss);
4668 }
4669
4670 return chains;
4671}
4672
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004673static bool
4674ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4675 const struct ieee80211_he_operation *he_op)
4676{
4677 const struct ieee80211_sta_he_cap *sta_he_cap =
4678 ieee80211_get_he_sta_cap(sband);
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004679 u16 ap_min_req_set;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004680 int i;
4681
4682 if (!sta_he_cap || !he_op)
4683 return false;
4684
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004685 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4686
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004687 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4688 for (i = 0; i < 3; i++) {
4689 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4690 &sta_he_cap->he_mcs_nss_supp;
4691 u16 sta_mcs_map_rx =
4692 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4693 u16 sta_mcs_map_tx =
4694 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4695 u8 nss;
4696 bool verified = true;
4697
4698 /*
4699 * For each band there is a maximum of 8 spatial streams
4700 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4701 * of 2 bits per NSS (1-8), with the values defined in enum
4702 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4703 * capabilities aren't less than the AP's minimum requirements
4704 * for this HE BSS per SS.
4705 * It is enough to find one such band that meets the reqs.
4706 */
4707 for (nss = 8; nss > 0; nss--) {
4708 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4709 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4710 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4711
4712 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4713 continue;
4714
4715 /*
4716 * Make sure the HE AP doesn't require MCSs that aren't
4717 * supported by the client
4718 */
4719 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4720 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4721 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4722 verified = false;
4723 break;
4724 }
4725 }
4726
4727 if (verified)
4728 return true;
4729 }
4730
4731 /* If here, STA doesn't meet AP's HE min requirements */
4732 return false;
4733}
4734
Johannes Bergb17166a2012-07-27 11:41:27 +02004735static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4736 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01004737{
4738 struct ieee80211_local *local = sdata->local;
4739 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Peller53b954e2014-07-24 11:20:05 +03004740 const struct ieee80211_ht_cap *ht_cap = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004741 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004742 const struct ieee80211_vht_operation *vht_oper = NULL;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004743 const struct ieee80211_he_operation *he_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004744 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01004745 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004746 int ret;
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004747 u32 i;
4748 bool have_80mhz;
Johannes Berga1cf7752012-03-08 15:02:07 +01004749
Johannes Berg24398e32012-03-28 10:58:36 +02004750 sband = local->hw.wiphy->bands[cbss->channel->band];
4751
Johannes Bergf2d9d272012-11-22 14:11:39 +01004752 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4753 IEEE80211_STA_DISABLE_80P80MHZ |
4754 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02004755
Johannes Berg9caf0362012-11-29 01:25:20 +01004756 rcu_read_lock();
4757
Johannes Bergf2d9d272012-11-22 14:11:39 +01004758 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
4759 sband->ht_cap.ht_supported) {
Eliad Peller53b954e2014-07-24 11:20:05 +03004760 const u8 *ht_oper_ie, *ht_cap_ie;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004761
Johannes Berg9caf0362012-11-29 01:25:20 +01004762 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02004763 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4764 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6effa2013-02-07 23:33:32 +01004765
Eliad Peller53b954e2014-07-24 11:20:05 +03004766 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4767 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4768 ht_cap = (void *)(ht_cap_ie + 2);
4769
4770 if (!ht_cap) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004771 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4772 ht_oper = NULL;
4773 }
Johannes Berg24398e32012-03-28 10:58:36 +02004774 }
4775
Johannes Bergf2d9d272012-11-22 14:11:39 +01004776 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4777 sband->vht_cap.vht_supported) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004778 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004779
Johannes Berg9caf0362012-11-29 01:25:20 +01004780 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4781 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004782 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4783 vht_oper = (void *)(vht_oper_ie + 2);
4784 if (vht_oper && !ht_oper) {
4785 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004786 sdata_info(sdata,
Johannes Bergf2d9d272012-11-22 14:11:39 +01004787 "AP advertised VHT without HT, disabling both\n");
Johannes Bergcb145022013-02-07 20:41:50 +01004788 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4789 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg24398e32012-03-28 10:58:36 +02004790 }
Johannes Berg08e6effa2013-02-07 23:33:32 +01004791
4792 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4793 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4794 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4795 vht_oper = NULL;
4796 }
Johannes Berg24398e32012-03-28 10:58:36 +02004797 }
4798
Shaul Triebitz002245e2018-12-15 11:03:19 +02004799 if (!ieee80211_get_he_sta_cap(sband))
4800 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4801
4802 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004803 const struct cfg80211_bss_ies *ies;
4804 const u8 *he_oper_ie;
4805
4806 ies = rcu_dereference(cbss->ies);
4807 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
4808 ies->data, ies->len);
4809 if (he_oper_ie &&
4810 he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
4811 he_oper = (void *)(he_oper_ie + 3);
4812 else
4813 he_oper = NULL;
4814
Johannes Bergf0c04072018-06-29 09:51:39 +02004815 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004816 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4817 }
4818
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004819 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4820 have_80mhz = false;
4821 for (i = 0; i < sband->n_channels; i++) {
4822 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4823 IEEE80211_CHAN_NO_80MHZ))
4824 continue;
4825
4826 have_80mhz = true;
4827 break;
4828 }
4829
4830 if (!have_80mhz)
4831 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4832
Johannes Bergf2d9d272012-11-22 14:11:39 +01004833 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4834 cbss->channel,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004835 ht_oper, vht_oper, he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +02004836 &chandef, false);
Johannes Berg04ecd252012-09-11 14:34:12 +02004837
Johannes Bergf2d9d272012-11-22 14:11:39 +01004838 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4839 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02004840
Johannes Berg9caf0362012-11-29 01:25:20 +01004841 rcu_read_unlock();
4842
Johannes Berg04ecd252012-09-11 14:34:12 +02004843 /* will change later if needed */
4844 sdata->smps_mode = IEEE80211_SMPS_OFF;
4845
Johannes Berg34a37402013-12-18 09:43:33 +01004846 mutex_lock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004847 /*
4848 * If this fails (possibly due to channel context sharing
4849 * on incompatible channels, e.g. 80+80 and 160 sharing the
4850 * same control channel) try to use a smaller bandwidth.
4851 */
4852 ret = ieee80211_vif_use_channel(sdata, &chandef,
4853 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich0418a442013-05-16 13:00:31 +02004854
4855 /* don't downgrade for 5 and 10 MHz channels, though. */
4856 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4857 chandef.width == NL80211_CHAN_WIDTH_10)
Johannes Berg34a37402013-12-18 09:43:33 +01004858 goto out;
Simon Wunderlich0418a442013-05-16 13:00:31 +02004859
Johannes Bergd601cd82013-02-07 20:54:51 +01004860 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02004861 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01004862 ret = ieee80211_vif_use_channel(sdata, &chandef,
4863 IEEE80211_CHANCTX_SHARED);
4864 }
Johannes Berg34a37402013-12-18 09:43:33 +01004865 out:
4866 mutex_unlock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004867 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02004868}
4869
Sara Sharon78ac51f2019-01-16 18:22:56 +02004870static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
4871 u8 *dtim_count, u8 *dtim_period)
4872{
4873 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
4874 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
4875 ies->len);
4876 const struct ieee80211_tim_ie *tim = NULL;
4877 const struct ieee80211_bssid_index *idx;
4878 bool valid = tim_ie && tim_ie[1] >= 2;
4879
4880 if (valid)
4881 tim = (void *)(tim_ie + 2);
4882
4883 if (dtim_count)
4884 *dtim_count = valid ? tim->dtim_count : 0;
4885
4886 if (dtim_period)
4887 *dtim_period = valid ? tim->dtim_period : 0;
4888
4889 /* Check if value is overridden by non-transmitted profile */
4890 if (!idx_ie || idx_ie[1] < 3)
4891 return valid;
4892
4893 idx = (void *)(idx_ie + 2);
4894
4895 if (dtim_count)
4896 *dtim_count = idx->dtim_count;
4897
4898 if (dtim_period)
4899 *dtim_period = idx->dtim_period;
4900
4901 return true;
4902}
4903
Johannes Bergb17166a2012-07-27 11:41:27 +02004904static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004905 struct cfg80211_bss *cbss, bool assoc,
4906 bool override)
Johannes Bergb17166a2012-07-27 11:41:27 +02004907{
4908 struct ieee80211_local *local = sdata->local;
4909 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4910 struct ieee80211_bss *bss = (void *)cbss->priv;
4911 struct sta_info *new_sta = NULL;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004912 struct ieee80211_supported_band *sband;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004913 bool have_sta = false;
Johannes Bergb17166a2012-07-27 11:41:27 +02004914 int err;
4915
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004916 sband = local->hw.wiphy->bands[cbss->channel->band];
4917
Johannes Bergb17166a2012-07-27 11:41:27 +02004918 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4919 return -EINVAL;
4920
Luca Coelhof8860ce2017-05-02 17:56:21 +03004921 /* If a reconfig is happening, bail out */
4922 if (local->in_reconfig)
4923 return -EBUSY;
4924
Johannes Bergb17166a2012-07-27 11:41:27 +02004925 if (assoc) {
4926 rcu_read_lock();
4927 have_sta = sta_info_get(sdata, cbss->bssid);
4928 rcu_read_unlock();
4929 }
4930
4931 if (!have_sta) {
4932 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4933 if (!new_sta)
4934 return -ENOMEM;
4935 }
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004936
Johannes Bergc87905b2017-06-10 13:52:43 +03004937 /*
4938 * Set up the information for the new channel before setting the
4939 * new channel. We can't - completely race-free - change the basic
4940 * rates bitmap and the channel (sband) that it refers to, but if
4941 * we set it up before we at least avoid calling into the driver's
4942 * bss_info_changed() method with invalid information (since we do
4943 * call that from changing the channel - only for IDLE and perhaps
4944 * some others, but ...).
4945 *
4946 * So to avoid that, just set up all the new information before the
4947 * channel, but tell the driver to apply it only afterwards, since
4948 * it might need the new channel for that.
4949 */
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004950 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004951 u32 rates = 0, basic_rates = 0;
4952 bool have_higher_than_11mbit;
4953 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004954 const struct cfg80211_bss_ies *ies;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004955 int shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004956
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004957 ieee80211_get_rates(sband, bss->supp_rates,
4958 bss->supp_rates_len,
4959 &rates, &basic_rates,
4960 &have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02004961 &min_rate, &min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03004962 shift);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004963
4964 /*
4965 * This used to be a workaround for basic rates missing
4966 * in the association response frame. Now that we no
4967 * longer use the basic rates from there, it probably
4968 * doesn't happen any more, but keep the workaround so
4969 * in case some *other* APs are buggy in different ways
4970 * we can connect -- with a warning.
4971 */
4972 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004973 sdata_info(sdata,
4974 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004975 basic_rates = BIT(min_rate_index);
4976 }
4977
Johannes Bergbd718fc2019-05-29 15:25:35 +03004978 if (rates)
4979 new_sta->sta.supp_rates[cbss->channel->band] = rates;
4980 else
4981 sdata_info(sdata,
4982 "No rates found, keeping mandatory only\n");
4983
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004984 sdata->vif.bss_conf.basic_rates = basic_rates;
4985
4986 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg57fbcce2016-04-12 15:56:15 +02004987 if (cbss->channel->band == NL80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004988 have_higher_than_11mbit)
4989 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
4990 else
4991 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
4992
4993 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
4994
Johannes Berg8c358bc2012-05-22 22:13:05 +02004995 /* set timing information */
4996 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004997 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01004998 ies = rcu_dereference(cbss->beacon_ies);
4999 if (ies) {
Johannes Bergef429da2013-02-05 17:48:40 +01005000 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5001 sdata->vif.bss_conf.sync_device_ts =
5002 bss->device_ts_beacon;
Sara Sharon78ac51f2019-01-16 18:22:56 +02005003
5004 ieee80211_get_dtim(ies,
5005 &sdata->vif.bss_conf.sync_dtim_count,
5006 NULL);
Johannes Berg30686bf2015-06-02 21:39:54 +02005007 } else if (!ieee80211_hw_check(&sdata->local->hw,
5008 TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005009 ies = rcu_dereference(cbss->proberesp_ies);
5010 /* must be non-NULL since beacon IEs were NULL */
5011 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5012 sdata->vif.bss_conf.sync_device_ts =
5013 bss->device_ts_presp;
5014 sdata->vif.bss_conf.sync_dtim_count = 0;
5015 } else {
5016 sdata->vif.bss_conf.sync_tsf = 0;
5017 sdata->vif.bss_conf.sync_device_ts = 0;
5018 sdata->vif.bss_conf.sync_dtim_count = 0;
5019 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01005020 rcu_read_unlock();
Johannes Bergc87905b2017-06-10 13:52:43 +03005021 }
Johannes Berg8c358bc2012-05-22 22:13:05 +02005022
Johannes Bergc87905b2017-06-10 13:52:43 +03005023 if (new_sta || override) {
5024 err = ieee80211_prep_channel(sdata, cbss);
5025 if (err) {
5026 if (new_sta)
5027 sta_info_free(local, new_sta);
5028 return -EINVAL;
5029 }
5030 }
5031
5032 if (new_sta) {
5033 /*
5034 * tell driver about BSSID, basic rates and timing
5035 * this was set up above, before setting the channel
5036 */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01005037 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02005038 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5039 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01005040
5041 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02005042 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01005043
Johannes Berg13e0c8e2012-07-27 10:43:16 +02005044 err = sta_info_insert(new_sta);
5045 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01005046 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005047 sdata_info(sdata,
5048 "failed to insert STA entry for the AP (error %d)\n",
5049 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01005050 return err;
5051 }
5052 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00005053 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01005054
David Spinadel7d830a12015-03-17 19:58:38 +02005055 /* Cancel scan to ensure that nothing interferes with connection */
5056 if (local->scanning)
5057 ieee80211_scan_cancel(local);
5058
Johannes Berga1cf7752012-03-08 15:02:07 +01005059 return 0;
5060}
5061
Johannes Berg77fdaa12009-07-07 03:45:17 +02005062/* config hooks */
5063int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5064 struct cfg80211_auth_request *req)
5065{
Johannes Berg66e67e42012-01-20 13:55:27 +01005066 struct ieee80211_local *local = sdata->local;
5067 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5068 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005069 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01005070 int err;
Jouni Malinenefb543e2018-10-11 00:21:21 +03005071 bool cont_auth;
Johannes Berg66e67e42012-01-20 13:55:27 +01005072
5073 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02005074
5075 switch (req->auth_type) {
5076 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5077 auth_alg = WLAN_AUTH_OPEN;
5078 break;
5079 case NL80211_AUTHTYPE_SHARED_KEY:
Ard Biesheuvel5fdb3732019-06-12 18:19:54 +02005080 if (fips_enabled)
Johannes Berg9dca9c42010-07-21 10:09:25 +02005081 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005082 auth_alg = WLAN_AUTH_SHARED_KEY;
5083 break;
5084 case NL80211_AUTHTYPE_FT:
5085 auth_alg = WLAN_AUTH_FT;
5086 break;
5087 case NL80211_AUTHTYPE_NETWORK_EAP:
5088 auth_alg = WLAN_AUTH_LEAP;
5089 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005090 case NL80211_AUTHTYPE_SAE:
5091 auth_alg = WLAN_AUTH_SAE;
5092 break;
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03005093 case NL80211_AUTHTYPE_FILS_SK:
5094 auth_alg = WLAN_AUTH_FILS_SK;
5095 break;
5096 case NL80211_AUTHTYPE_FILS_SK_PFS:
5097 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5098 break;
5099 case NL80211_AUTHTYPE_FILS_PK:
5100 auth_alg = WLAN_AUTH_FILS_PK;
5101 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005102 default:
5103 return -EOPNOTSUPP;
5104 }
5105
Jouni Malinenefb543e2018-10-11 00:21:21 +03005106 if (ifmgd->assoc_data)
Jouni Malinen8d7432a2018-10-11 00:21:20 +03005107 return -EBUSY;
5108
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03005109 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005110 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01005111 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005112 return -ENOMEM;
5113
Johannes Berg66e67e42012-01-20 13:55:27 +01005114 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005115
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03005116 if (req->auth_data_len >= 4) {
Jouni Malinen6ec63612016-10-27 00:41:59 +03005117 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5118 __le16 *pos = (__le16 *) req->auth_data;
5119
5120 auth_data->sae_trans = le16_to_cpu(pos[0]);
5121 auth_data->sae_status = le16_to_cpu(pos[1]);
5122 }
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03005123 memcpy(auth_data->data, req->auth_data + 4,
5124 req->auth_data_len - 4);
5125 auth_data->data_len += req->auth_data_len - 4;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005126 }
5127
Jouni Malinenefb543e2018-10-11 00:21:21 +03005128 /* Check if continuing authentication or trying to authenticate with the
5129 * same BSS that we were in the process of authenticating with and avoid
5130 * removal and re-addition of the STA entry in
5131 * ieee80211_prep_connection().
5132 */
5133 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5134
Johannes Berg77fdaa12009-07-07 03:45:17 +02005135 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005136 memcpy(&auth_data->data[auth_data->data_len],
5137 req->ie, req->ie_len);
5138 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005139 }
5140
Johannes Bergfffd0932009-07-08 14:22:54 +02005141 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005142 auth_data->key_len = req->key_len;
5143 auth_data->key_idx = req->key_idx;
5144 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02005145 }
5146
Johannes Berg66e67e42012-01-20 13:55:27 +01005147 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005148
Johannes Berg66e67e42012-01-20 13:55:27 +01005149 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01005150
Jouni Malinenefb543e2018-10-11 00:21:21 +03005151 if (ifmgd->auth_data) {
5152 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5153 auth_data->peer_confirmed =
5154 ifmgd->auth_data->peer_confirmed;
5155 }
5156 ieee80211_destroy_auth_data(sdata, cont_auth);
5157 }
Guy Eilam2a33bee2011-08-17 15:18:15 +03005158
Johannes Berg66e67e42012-01-20 13:55:27 +01005159 /* prep auth_data so we don't go into idle on disassoc */
5160 ifmgd->auth_data = auth_data;
5161
Jouni Malinenefb543e2018-10-11 00:21:21 +03005162 /* If this is continuation of an ongoing SAE authentication exchange
5163 * (i.e., request to send SAE Confirm) and the peer has already
5164 * confirmed, mark authentication completed since we are about to send
5165 * out SAE Confirm.
5166 */
5167 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5168 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5169 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5170
Johannes Berg7b119dc2013-04-10 21:38:36 +02005171 if (ifmgd->associated) {
5172 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5173
Johannes Berg89f774e2016-01-25 15:46:36 +02005174 sdata_info(sdata,
5175 "disconnect from AP %pM for new auth to %pM\n",
5176 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005177 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5178 WLAN_REASON_UNSPECIFIED,
5179 false, frame_buf);
5180
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005181 ieee80211_report_disconnect(sdata, frame_buf,
5182 sizeof(frame_buf), true,
5183 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005184 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005185
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005186 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005187
Jouni Malinenefb543e2018-10-11 00:21:21 +03005188 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
Johannes Berga1cf7752012-03-08 15:02:07 +01005189 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01005190 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005191
Johannes Berg46cad4b2015-08-15 22:39:54 +03005192 err = ieee80211_auth(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01005193 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005194 sta_info_destroy_addr(sdata, req->bss->bssid);
5195 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005196 }
5197
Johannes Berg66e67e42012-01-20 13:55:27 +01005198 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01005199 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005200 return 0;
Johannes Berge5b900d2010-07-29 16:08:55 +02005201
Johannes Berg66e67e42012-01-20 13:55:27 +01005202 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005203 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005204 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005205 ifmgd->auth_data = NULL;
Michal Kaziord01f8582015-06-03 08:36:13 +02005206 mutex_lock(&sdata->local->mtx);
5207 ieee80211_vif_release_channel(sdata);
5208 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01005209 kfree(auth_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005210 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005211}
5212
Johannes Berg77fdaa12009-07-07 03:45:17 +02005213int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5214 struct cfg80211_assoc_request *req)
5215{
Johannes Berg66e67e42012-01-20 13:55:27 +01005216 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005217 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01005218 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01005219 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005220 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005221 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005222 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005223 int i, err;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005224 bool override = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005225
Johannes Berg66e67e42012-01-20 13:55:27 +01005226 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5227 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01005228 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005229
Johannes Berg9caf0362012-11-29 01:25:20 +01005230 rcu_read_lock();
5231 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Will Deacon41525612019-10-04 10:51:31 +01005232 if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
Johannes Berg9caf0362012-11-29 01:25:20 +01005233 rcu_read_unlock();
5234 kfree(assoc_data);
5235 return -EINVAL;
5236 }
5237 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5238 assoc_data->ssid_len = ssidie[1];
5239 rcu_read_unlock();
5240
Johannes Berg7b119dc2013-04-10 21:38:36 +02005241 if (ifmgd->associated) {
5242 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5243
Johannes Berg89f774e2016-01-25 15:46:36 +02005244 sdata_info(sdata,
5245 "disconnect from AP %pM for new assoc to %pM\n",
5246 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005247 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5248 WLAN_REASON_UNSPECIFIED,
5249 false, frame_buf);
5250
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005251 ieee80211_report_disconnect(sdata, frame_buf,
5252 sizeof(frame_buf), true,
5253 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005254 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005255
5256 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5257 err = -EBUSY;
5258 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005259 }
5260
Johannes Berg66e67e42012-01-20 13:55:27 +01005261 if (ifmgd->assoc_data) {
5262 err = -EBUSY;
5263 goto err_free;
5264 }
5265
5266 if (ifmgd->auth_data) {
5267 bool match;
5268
5269 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00005270 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005271 ieee80211_destroy_auth_data(sdata, match);
5272 }
5273
5274 /* prepare assoc data */
Johannes Berg095d81c2013-10-15 12:25:07 +02005275
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03005276 ifmgd->beacon_crc_valid = false;
5277
Johannes Berg095d81c2013-10-15 12:25:07 +02005278 assoc_data->wmm = bss->wmm_used &&
5279 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg095d81c2013-10-15 12:25:07 +02005280
Johannes Bergde5036a2012-03-08 15:02:03 +01005281 /*
5282 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5283 * We still associate in non-HT mode (11a/b/g) if any one of these
5284 * ciphers is configured as pairwise.
5285 * We can set this to true for non-11n hardware, that'll be checked
5286 * separately along with the peer capabilities.
5287 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02005288 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02005289 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5290 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02005291 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01005292 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005293 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005294 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Johannes Berg1c4cb922012-05-30 15:57:00 +02005295 netdev_info(sdata->dev,
Johannes Berg54626322019-08-30 14:24:46 +03005296 "disabling HT/VHT/HE due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005297 }
5298 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005299
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005300 /* Also disable HT if we don't support it or the AP doesn't use WMM */
5301 sband = local->hw.wiphy->bands[req->bss->channel->band];
5302 if (!sband->ht_cap.ht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005303 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5304 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Berga8243b72012-11-22 14:32:09 +01005305 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005306 if (!bss->wmm_used &&
5307 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005308 netdev_info(sdata->dev,
5309 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005310 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005311
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005312 /* disable VHT if we don't support it or the AP doesn't use WMM */
5313 if (!sband->vht_cap.vht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005314 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5315 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005316 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005317 if (!bss->wmm_used &&
5318 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005319 netdev_info(sdata->dev,
5320 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005321 }
5322
Ben Greearef96a8422011-11-18 11:32:00 -08005323 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5324 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5325 sizeof(ifmgd->ht_capa_mask));
5326
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01005327 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5328 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5329 sizeof(ifmgd->vht_capa_mask));
5330
Johannes Berg77fdaa12009-07-07 03:45:17 +02005331 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005332 memcpy(assoc_data->ie, req->ie, req->ie_len);
5333 assoc_data->ie_len = req->ie_len;
5334 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005335
Jouni Malinen39404fe2016-10-27 00:42:05 +03005336 if (req->fils_kek) {
5337 /* should already be checked in cfg80211 - so warn */
5338 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5339 err = -EINVAL;
5340 goto err_free;
5341 }
5342 memcpy(assoc_data->fils_kek, req->fils_kek,
5343 req->fils_kek_len);
5344 assoc_data->fils_kek_len = req->fils_kek_len;
5345 }
5346
5347 if (req->fils_nonces)
5348 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5349 2 * FILS_NONCE_LEN);
5350
Johannes Berg66e67e42012-01-20 13:55:27 +01005351 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01005352
Johannes Bergaf6b6372009-12-23 13:15:35 +01005353 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5354 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02005355 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005356 else
Johannes Berg04ecd252012-09-11 14:34:12 +02005357 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005358 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02005359 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005360
Johannes Berg66e67e42012-01-20 13:55:27 +01005361 assoc_data->capability = req->bss->capability;
Johannes Berg66e67e42012-01-20 13:55:27 +01005362 assoc_data->supp_rates = bss->supp_rates;
5363 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02005364
Johannes Berg9caf0362012-11-29 01:25:20 +01005365 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02005366 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5367 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5368 assoc_data->ap_ht_param =
5369 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5370 else
Johannes Berga8243b72012-11-22 14:32:09 +01005371 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005372 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5373 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5374 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5375 sizeof(struct ieee80211_vht_cap));
5376 else
5377 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01005378 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01005379
Johannes Berg848955c2014-11-11 12:48:42 +01005380 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02005381 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
Johannes Berg848955c2014-11-11 12:48:42 +01005382 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5383 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5384
Kalle Valoab133152010-01-12 10:42:31 +02005385 if (bss->wmm_used && bss->uapsd_supported &&
Johannes Berg848955c2014-11-11 12:48:42 +01005386 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01005387 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02005388 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5389 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01005390 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02005391 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5392 }
5393
Johannes Berg77fdaa12009-07-07 03:45:17 +02005394 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01005395 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005396
5397 if (req->use_mfp) {
5398 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5399 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5400 } else {
5401 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5402 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5403 }
5404
Assaf Krausscd2f5dd2014-09-03 15:25:02 +03005405 if (req->flags & ASSOC_REQ_USE_RRM)
5406 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5407 else
5408 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5409
Johannes Berg77fdaa12009-07-07 03:45:17 +02005410 if (req->crypto.control_port)
5411 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5412 else
5413 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5414
Johannes Berga621fa42010-08-27 14:26:54 +03005415 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5416 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05005417 sdata->control_port_over_nl80211 =
5418 req->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02005419 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5420 sdata->vif.type);
Johannes Berga621fa42010-08-27 14:26:54 +03005421
Johannes Berg66e67e42012-01-20 13:55:27 +01005422 /* kick off associate process */
5423
5424 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02005425 ifmgd->dtim_period = 0;
Alexander Bondar989c6502013-05-16 17:34:17 +03005426 ifmgd->have_beacon = false;
Johannes Berg66e67e42012-01-20 13:55:27 +01005427
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005428 /* override HT/VHT configuration only if the AP and we support it */
5429 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5430 struct ieee80211_sta_ht_cap sta_ht_cap;
5431
5432 if (req->flags & ASSOC_REQ_DISABLE_HT)
5433 override = true;
5434
5435 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5436 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5437
5438 /* check for 40 MHz disable override */
5439 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5440 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5441 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5442 override = true;
5443
5444 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5445 req->flags & ASSOC_REQ_DISABLE_VHT)
5446 override = true;
5447 }
5448
5449 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5450 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5451 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5452 }
5453
5454 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5455 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5456
5457 err = ieee80211_prep_connection(sdata, req->bss, true, override);
Johannes Berga1cf7752012-03-08 15:02:07 +01005458 if (err)
5459 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01005460
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005461 rcu_read_lock();
5462 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02005463
Johannes Berg30686bf2015-06-02 21:39:54 +02005464 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005465 !beacon_ies) {
5466 /*
5467 * Wait up to one beacon interval ...
5468 * should this be more if we miss one?
5469 */
5470 sdata_info(sdata, "waiting for beacon from %pM\n",
5471 ifmgd->bssid);
5472 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01005473 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005474 assoc_data->need_beacon = true;
5475 } else if (beacon_ies) {
Sara Sharon78ac51f2019-01-16 18:22:56 +02005476 const u8 *ie;
Johannes Bergef429da2013-02-05 17:48:40 +01005477 u8 dtim_count = 0;
5478
Sara Sharon78ac51f2019-01-16 18:22:56 +02005479 ieee80211_get_dtim(beacon_ies, &dtim_count,
5480 &ifmgd->dtim_period);
5481
Alexander Bondar989c6502013-05-16 17:34:17 +03005482 ifmgd->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005483 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005484 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01005485
Johannes Berg30686bf2015-06-02 21:39:54 +02005486 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005487 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5488 sdata->vif.bss_conf.sync_device_ts =
5489 bss->device_ts_beacon;
5490 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5491 }
Sara Sharon78ac51f2019-01-16 18:22:56 +02005492
5493 ie = cfg80211_find_ext_ie(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5494 beacon_ies->data, beacon_ies->len);
5495 if (ie && ie[1] >= 3)
5496 sdata->vif.bss_conf.profile_periodicity = ie[4];
5497
5498 ie = cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY,
5499 beacon_ies->data, beacon_ies->len);
5500 if (ie && ie[1] >= 11 &&
5501 (ie[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5502 sdata->vif.bss_conf.ema_ap = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005503 } else {
5504 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005505 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005506 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005507 rcu_read_unlock();
5508
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005509 run_again(sdata, assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01005510
Paul Stewartfcff4f12012-02-23 17:59:53 -08005511 if (bss->corrupt_data) {
5512 char *corrupt_type = "data";
5513 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5514 if (bss->corrupt_data &
5515 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5516 corrupt_type = "beacon and probe response";
5517 else
5518 corrupt_type = "beacon";
5519 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5520 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005521 sdata_info(sdata, "associating with AP with corrupt %s\n",
5522 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08005523 }
5524
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005525 return 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01005526 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005527 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005528 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005529 ifmgd->assoc_data = NULL;
5530 err_free:
5531 kfree(assoc_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005532 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005533}
5534
5535int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005536 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005537{
5538 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005539 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005540 bool tx = !req->local_state_change;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005541
Johannes Bergc9c3a062014-03-19 09:11:19 +01005542 if (ifmgd->auth_data &&
5543 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5544 sdata_info(sdata,
5545 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5546 req->bssid, req->reason_code,
5547 ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005548
Ilan Peerd4e36e52018-04-20 13:49:25 +03005549 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg4b08d1b2019-08-30 14:24:51 +03005550 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
Johannes Berg37ad3882012-02-24 13:50:54 +01005551 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005552 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01005553 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01005554 ieee80211_destroy_auth_data(sdata, false);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005555 ieee80211_report_disconnect(sdata, frame_buf,
5556 sizeof(frame_buf), true,
5557 req->reason_code);
Johannes Berg86552012012-10-29 09:46:31 +01005558
Johannes Bergc9c3a062014-03-19 09:11:19 +01005559 return 0;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03005560 }
5561
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005562 if (ifmgd->assoc_data &&
5563 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5564 sdata_info(sdata,
5565 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5566 req->bssid, req->reason_code,
5567 ieee80211_get_reason_code_string(req->reason_code));
5568
Ilan Peerd4e36e52018-04-20 13:49:25 +03005569 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg4b08d1b2019-08-30 14:24:51 +03005570 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005571 IEEE80211_STYPE_DEAUTH,
5572 req->reason_code, tx,
5573 frame_buf);
Johannes Berge6f462d2016-12-08 17:22:09 +01005574 ieee80211_destroy_assoc_data(sdata, false, true);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005575 ieee80211_report_disconnect(sdata, frame_buf,
5576 sizeof(frame_buf), true,
5577 req->reason_code);
5578 return 0;
5579 }
5580
Johannes Berg86552012012-10-29 09:46:31 +01005581 if (ifmgd->associated &&
5582 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
Johannes Bergc9c3a062014-03-19 09:11:19 +01005583 sdata_info(sdata,
5584 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5585 req->bssid, req->reason_code,
5586 ieee80211_get_reason_code_string(req->reason_code));
5587
Johannes Berg86552012012-10-29 09:46:31 +01005588 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5589 req->reason_code, tx, frame_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005590 ieee80211_report_disconnect(sdata, frame_buf,
5591 sizeof(frame_buf), true,
5592 req->reason_code);
Johannes Bergc9c3a062014-03-19 09:11:19 +01005593 return 0;
5594 }
Johannes Berg86552012012-10-29 09:46:31 +01005595
Johannes Bergc9c3a062014-03-19 09:11:19 +01005596 return -ENOTCONN;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005597}
5598
5599int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005600 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005601{
5602 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07005603 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005604 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02005605
Johannes Berg8d8b2612009-07-25 11:58:36 +02005606 /*
5607 * cfg80211 should catch this ... but it's racy since
5608 * we can receive a disassoc frame, process it, hand it
5609 * to cfg80211 while that's in a locked section already
5610 * trying to tell us that the user wants to disconnect.
5611 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005612 if (ifmgd->associated != req->bss)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005613 return -ENOLINK;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005614
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005615 sdata_info(sdata,
Calvin Owensdfa1ad22014-02-11 12:36:24 -06005616 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5617 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005618
Jouni Malinene69e95d2010-03-29 23:29:31 -07005619 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01005620 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5621 req->reason_code, !req->local_state_change,
5622 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005623
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005624 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5625 req->reason_code);
Johannes Bergbc83b682009-11-29 12:19:06 +01005626
Johannes Berg77fdaa12009-07-07 03:45:17 +02005627 return 0;
5628}
Jouni Malinen026331c2010-02-15 12:53:10 +02005629
Eliad Pellerafa762f2012-04-23 14:45:15 +03005630void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005631{
5632 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5633
Ben Greear49921852013-02-20 09:41:09 -08005634 /*
5635 * Make sure some work items will not run after this,
5636 * they will not do anything but might not have been
5637 * cancelled when disconnecting.
5638 */
5639 cancel_work_sync(&ifmgd->monitor_work);
5640 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5641 cancel_work_sync(&ifmgd->request_smps_work);
5642 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5643 cancel_work_sync(&ifmgd->chswitch_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03005644 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
Ben Greear49921852013-02-20 09:41:09 -08005645
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005646 sdata_lock(sdata);
Johannes Berg959867f2013-06-19 13:05:42 +02005647 if (ifmgd->assoc_data) {
5648 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Johannes Berge6f462d2016-12-08 17:22:09 +01005649 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02005650 cfg80211_assoc_timeout(sdata->dev, bss);
5651 }
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005652 if (ifmgd->auth_data)
5653 ieee80211_destroy_auth_data(sdata, false);
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005654 spin_lock_bh(&ifmgd->teardown_lock);
5655 if (ifmgd->teardown_skb) {
5656 kfree_skb(ifmgd->teardown_skb);
5657 ifmgd->teardown_skb = NULL;
5658 ifmgd->orig_teardown_skb = NULL;
5659 }
Jouni Malinen4d9ec732019-02-15 02:14:33 +02005660 kfree(ifmgd->assoc_req_ies);
5661 ifmgd->assoc_req_ies = NULL;
5662 ifmgd->assoc_req_ies_len = 0;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005663 spin_unlock_bh(&ifmgd->teardown_lock);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005664 del_timer_sync(&ifmgd->timer);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005665 sdata_unlock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005666}
5667
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005668void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5669 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005670 s32 rssi_level,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005671 gfp_t gfp)
5672{
5673 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5674
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005675 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
Johannes Bergb5878a22010-04-07 16:48:40 +02005676
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01005677 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005678}
5679EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
Johannes Berg98f03342014-11-26 12:42:02 +01005680
5681void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5682{
5683 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5684
5685 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5686
5687 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5688}
5689EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);