blob: 2733555a5f3bab068d7eb8dc135ecb1e8cf78482 [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 Sharonfafd2bc2019-02-06 13:17:15 +020011 * Copyright (C) 2018 - 2019 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 Berg60f8b392008-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 Berg60f8b392008-09-08 17:44:22 +0200140{
Johannes Berg5484e232008-09-08 17:44:27 +0200141 return (1 << ecw) - 1;
Johannes Berg60f8b392008-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 Berg75e296e2020-01-31 13:12:39 +0200167 ret = IEEE80211_STA_DISABLE_HT |
168 IEEE80211_STA_DISABLE_VHT |
169 IEEE80211_STA_DISABLE_HE;
Johannes Berg6565ec92013-02-08 14:52:32 +0100170 goto out;
171 }
172
173 chandef->width = NL80211_CHAN_WIDTH_20;
174
175 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
176 channel->band);
177 /* check that channel matches the right operating channel */
Johannes Berg5cdaed12013-07-31 11:23:06 +0200178 if (!tracking && channel->center_freq != ht_cfreq) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100179 /*
180 * It's possible that some APs are confused here;
181 * Netgear WNDR3700 sometimes reports 4 higher than
182 * the actual channel in association responses, but
183 * since we look at probe response/beacon data here
184 * it should be OK.
185 */
Johannes Berg5cdaed12013-07-31 11:23:06 +0200186 sdata_info(sdata,
187 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
188 channel->center_freq, ht_cfreq,
189 ht_oper->primary_chan, channel->band);
Johannes Berg75e296e2020-01-31 13:12:39 +0200190 ret = IEEE80211_STA_DISABLE_HT |
191 IEEE80211_STA_DISABLE_VHT |
192 IEEE80211_STA_DISABLE_HE;
Johannes Berg6565ec92013-02-08 14:52:32 +0100193 goto out;
194 }
195
196 /* check 40 MHz support, if we have it */
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200197 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100198 ieee80211_chandef_ht_oper(ht_oper, chandef);
Johannes Berg6565ec92013-02-08 14:52:32 +0100199 } else {
200 /* 40 MHz (and 80 MHz) must be supported for VHT */
201 ret = IEEE80211_STA_DISABLE_VHT;
Johannes Berg85220d72013-03-25 18:29:27 +0100202 /* also mark 40 MHz disabled */
203 ret |= IEEE80211_STA_DISABLE_40MHZ;
Johannes Berg6565ec92013-02-08 14:52:32 +0100204 goto out;
205 }
206
207 if (!vht_oper || !sband->vht_cap.vht_supported) {
208 ret = IEEE80211_STA_DISABLE_VHT;
209 goto out;
210 }
211
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100212 vht_chandef = *chandef;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300213 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
214 (le32_to_cpu(he_oper->he_oper_params) &
215 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
216 struct ieee80211_vht_operation he_oper_vht_cap;
217
218 /*
219 * Set only first 3 bytes (other 2 aren't used in
220 * ieee80211_chandef_vht_oper() anyway)
221 */
222 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
223 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
224
Johannes Berg7eb26df2018-08-31 11:31:18 +0300225 if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
226 &he_oper_vht_cap, ht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300227 &vht_chandef)) {
228 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
229 sdata_info(sdata,
230 "HE AP VHT information is invalid, disable HE\n");
231 ret = IEEE80211_STA_DISABLE_HE;
232 goto out;
233 }
Johannes Berg7eb26df2018-08-31 11:31:18 +0300234 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_oper,
235 ht_oper, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200236 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100237 sdata_info(sdata,
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100238 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100239 ret = IEEE80211_STA_DISABLE_VHT;
240 goto out;
241 }
242
243 if (!cfg80211_chandef_valid(&vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200244 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100245 sdata_info(sdata,
246 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100247 ret = IEEE80211_STA_DISABLE_VHT;
248 goto out;
249 }
250
251 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
252 ret = 0;
253 goto out;
254 }
255
256 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200257 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100258 sdata_info(sdata,
259 "AP VHT information doesn't match HT, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100260 ret = IEEE80211_STA_DISABLE_VHT;
261 goto out;
262 }
263
264 *chandef = vht_chandef;
265
266 ret = 0;
267
268out:
Johannes Berg963a18522014-02-21 20:34:34 +0100269 /*
270 * When tracking the current AP, don't do any further checks if the
271 * new chandef is identical to the one we're currently using for the
272 * connection. This keeps us from playing ping-pong with regulatory,
273 * without it the following can happen (for example):
274 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
275 * - AP advertises regdom US
276 * - CRDA loads regdom US with 80 MHz prohibited (old database)
277 * - the code below detects an unsupported channel, downgrades, and
278 * we disconnect from the AP in the caller
279 * - disconnect causes CRDA to reload world regdomain and the game
280 * starts anew.
281 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
282 *
283 * It seems possible that there are still scenarios with CSA or real
284 * bandwidth changes where a this could happen, but those cases are
285 * less common and wouldn't completely prevent using the AP.
286 */
287 if (tracking &&
288 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
289 return ret;
290
Johannes Berg586e01e2013-02-14 12:13:53 +0100291 /* don't print the message below for VHT mismatch if VHT is disabled */
292 if (ret & IEEE80211_STA_DISABLE_VHT)
293 vht_chandef = *chandef;
294
Johannes Bergddfe49b2013-07-31 20:52:03 +0200295 /*
296 * Ignore the DISABLED flag when we're already connected and only
297 * tracking the APs beacon for bandwidth changes - otherwise we
298 * might get disconnected here if we connect to an AP, update our
299 * regulatory information based on the AP's country IE and the
300 * information we have is wrong/outdated and disables the channel
301 * that we're actually using for the connection to the AP.
302 */
Johannes Berg6565ec92013-02-08 14:52:32 +0100303 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
Johannes Bergddfe49b2013-07-31 20:52:03 +0200304 tracking ? 0 :
305 IEEE80211_CHAN_DISABLED)) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100306 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
307 ret = IEEE80211_STA_DISABLE_HT |
Johannes Berg75e296e2020-01-31 13:12:39 +0200308 IEEE80211_STA_DISABLE_VHT |
309 IEEE80211_STA_DISABLE_HE;
Chris Wrightb56e4b82013-07-31 12:12:24 -0700310 break;
Johannes Berg6565ec92013-02-08 14:52:32 +0100311 }
312
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200313 ret |= ieee80211_chandef_downgrade(chandef);
Johannes Berg6565ec92013-02-08 14:52:32 +0100314 }
315
Daniel Gabay8cadb202020-01-31 13:12:52 +0200316 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
317 IEEE80211_CHAN_NO_HE))
Haim Dreyfussb5db1ac2020-01-31 13:12:44 +0200318 ret |= IEEE80211_STA_DISABLE_HE;
319
Johannes Berg5cdaed12013-07-31 11:23:06 +0200320 if (chandef->width != vht_chandef.width && !tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100321 sdata_info(sdata,
322 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
323
324 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
325 return ret;
326}
327
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100328static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
329 struct sta_info *sta,
Eliad Peller53b954e2014-07-24 11:20:05 +0300330 const struct ieee80211_ht_cap *ht_cap,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100331 const struct ieee80211_ht_operation *ht_oper,
332 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300333 const struct ieee80211_he_operation *he_oper,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100334 const u8 *bssid, u32 *changed)
Johannes Bergd5522e02009-03-30 13:23:35 +0200335{
336 struct ieee80211_local *local = sdata->local;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100337 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300338 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
339 struct ieee80211_supported_band *sband =
340 local->hw.wiphy->bands[chan->band];
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100341 struct cfg80211_chan_def chandef;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200342 u16 ht_opmode;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100343 u32 flags;
344 enum ieee80211_sta_rx_bandwidth new_sta_bw;
345 int ret;
346
347 /* if HT was/is disabled, don't track any bandwidth changes */
348 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
349 return 0;
350
351 /* don't check VHT if we associated as non-VHT station */
352 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
353 vht_oper = NULL;
Johannes Bergd5522e02009-03-30 13:23:35 +0200354
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300355 /* don't check HE if we associated as non-HE station */
356 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
357 !ieee80211_get_he_sta_cap(sband))
358 he_oper = NULL;
359
Johannes Berg11289582013-02-07 17:36:12 +0100360 if (WARN_ON_ONCE(!sta))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100361 return -EINVAL;
Johannes Berg11289582013-02-07 17:36:12 +0100362
Avri Altman017b45b2013-11-18 19:06:48 +0200363 /*
364 * if bss configuration changed store the new one -
365 * this may be applicable even if channel is identical
366 */
367 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
368 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
369 *changed |= BSS_CHANGED_HT;
370 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
371 }
372
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300373 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
Eliad Peller53b954e2014-07-24 11:20:05 +0300374 flags = ieee80211_determine_chantype(sdata, sband, chan,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300375 ht_oper, vht_oper, he_oper,
Eliad Peller53b954e2014-07-24 11:20:05 +0300376 &chandef, true);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100377
378 /*
379 * Downgrade the new channel if we associated with restricted
380 * capabilities. For example, if we associated as a 20 MHz STA
381 * to a 40 MHz AP (due to regulatory, capabilities or config
382 * reasons) then switching to a 40 MHz channel now won't do us
383 * any good -- we couldn't use it with the AP.
384 */
385 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
386 chandef.width == NL80211_CHAN_WIDTH_80P80)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200387 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100388 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
389 chandef.width == NL80211_CHAN_WIDTH_160)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200390 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100391 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
392 chandef.width > NL80211_CHAN_WIDTH_20)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200393 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100394
395 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
396 return 0;
397
398 sdata_info(sdata,
399 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
400 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
401 chandef.center_freq1, chandef.center_freq2);
402
403 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
404 IEEE80211_STA_DISABLE_VHT |
Johannes Berg75e296e2020-01-31 13:12:39 +0200405 IEEE80211_STA_DISABLE_HE |
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100406 IEEE80211_STA_DISABLE_40MHZ |
407 IEEE80211_STA_DISABLE_80P80MHZ |
408 IEEE80211_STA_DISABLE_160MHZ)) ||
409 !cfg80211_chandef_valid(&chandef)) {
410 sdata_info(sdata,
411 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
412 ifmgd->bssid);
413 return -EINVAL;
Johannes Berg64f68e52012-03-28 10:58:37 +0200414 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200415
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100416 switch (chandef.width) {
417 case NL80211_CHAN_WIDTH_20_NOHT:
418 case NL80211_CHAN_WIDTH_20:
419 new_sta_bw = IEEE80211_STA_RX_BW_20;
420 break;
421 case NL80211_CHAN_WIDTH_40:
422 new_sta_bw = IEEE80211_STA_RX_BW_40;
423 break;
424 case NL80211_CHAN_WIDTH_80:
425 new_sta_bw = IEEE80211_STA_RX_BW_80;
426 break;
427 case NL80211_CHAN_WIDTH_80P80:
428 case NL80211_CHAN_WIDTH_160:
429 new_sta_bw = IEEE80211_STA_RX_BW_160;
430 break;
431 default:
432 return -EINVAL;
433 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200434
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100435 if (new_sta_bw > sta->cur_max_bandwidth)
436 new_sta_bw = sta->cur_max_bandwidth;
Johannes Berg64f68e52012-03-28 10:58:37 +0200437
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100438 if (new_sta_bw < sta->sta.bandwidth) {
439 sta->sta.bandwidth = new_sta_bw;
440 rate_control_rate_update(local, sband, sta,
441 IEEE80211_RC_BW_CHANGED);
442 }
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530443
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100444 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
445 if (ret) {
446 sdata_info(sdata,
447 "AP %pM changed bandwidth to incompatible one - disconnect\n",
448 ifmgd->bssid);
449 return ret;
450 }
451
452 if (new_sta_bw > sta->sta.bandwidth) {
453 sta->sta.bandwidth = new_sta_bw;
454 rate_control_rate_update(local, sband, sta,
455 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200456 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200457
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100458 return 0;
Johannes Bergd5522e02009-03-30 13:23:35 +0200459}
460
Johannes Berg9c6bd792008-09-11 00:01:52 +0200461/* frame sending functions */
462
Johannes Berg66e67e42012-01-20 13:55:27 +0100463static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200464 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100465 struct ieee80211_supported_band *sband,
466 struct ieee80211_channel *channel,
467 enum ieee80211_smps_mode smps)
468{
Johannes Berg66e67e42012-01-20 13:55:27 +0100469 u8 *pos;
470 u32 flags = channel->flags;
471 u16 cap;
472 struct ieee80211_sta_ht_cap ht_cap;
473
474 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
475
Johannes Berg66e67e42012-01-20 13:55:27 +0100476 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
477 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
478
Johannes Berg66e67e42012-01-20 13:55:27 +0100479 /* determine capability flags */
480 cap = ht_cap.cap;
481
Johannes Berg9dde6422012-05-16 23:43:19 +0200482 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100483 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
484 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
485 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
486 cap &= ~IEEE80211_HT_CAP_SGI_40;
487 }
488 break;
489 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
490 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
491 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
492 cap &= ~IEEE80211_HT_CAP_SGI_40;
493 }
494 break;
495 }
496
Johannes Berg24398e32012-03-28 10:58:36 +0200497 /*
498 * If 40 MHz was disabled associate as though we weren't
499 * capable of 40 MHz -- some broken APs will never fall
500 * back to trying to transmit in 20 MHz.
501 */
502 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
503 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
504 cap &= ~IEEE80211_HT_CAP_SGI_40;
505 }
506
Johannes Berg66e67e42012-01-20 13:55:27 +0100507 /* set SM PS mode properly */
508 cap &= ~IEEE80211_HT_CAP_SM_PS;
509 switch (smps) {
510 case IEEE80211_SMPS_AUTOMATIC:
511 case IEEE80211_SMPS_NUM_MODES:
512 WARN_ON(1);
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500513 /* fall through */
Johannes Berg66e67e42012-01-20 13:55:27 +0100514 case IEEE80211_SMPS_OFF:
515 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
516 IEEE80211_HT_CAP_SM_PS_SHIFT;
517 break;
518 case IEEE80211_SMPS_STATIC:
519 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
520 IEEE80211_HT_CAP_SM_PS_SHIFT;
521 break;
522 case IEEE80211_SMPS_DYNAMIC:
523 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
524 IEEE80211_HT_CAP_SM_PS_SHIFT;
525 break;
526 }
527
528 /* reserve and fill IE */
529 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
530 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
531}
532
Sara Sharon322cd402015-07-08 15:41:43 +0300533/* This function determines vht capability flags for the association
534 * and builds the IE.
535 * Note - the function may set the owner of the MU-MIMO capability
536 */
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000537static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
538 struct sk_buff *skb,
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100539 struct ieee80211_supported_band *sband,
540 struct ieee80211_vht_cap *ap_vht_cap)
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000541{
Sara Sharon322cd402015-07-08 15:41:43 +0300542 struct ieee80211_local *local = sdata->local;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000543 u8 *pos;
544 u32 cap;
545 struct ieee80211_sta_vht_cap vht_cap;
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200546 u32 mask, ap_bf_sts, our_bf_sts;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000547
548 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
549
550 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +0100551 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000552
553 /* determine capability flags */
554 cap = vht_cap.cap;
555
Johannes Bergf2d9d272012-11-22 14:11:39 +0100556 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
Johannes Berg575f0532014-11-24 16:51:33 +0100557 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
558
559 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
560 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
561 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
562 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100563 }
564
565 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
566 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
Johannes Berg575f0532014-11-24 16:51:33 +0100567 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100568 }
569
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100570 /*
571 * Some APs apparently get confused if our capabilities are better
572 * than theirs, so restrict what we advertise in the assoc request.
573 */
574 if (!(ap_vht_cap->vht_cap_info &
575 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
Sara Sharon322cd402015-07-08 15:41:43 +0300576 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
577 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
578 else if (!(ap_vht_cap->vht_cap_info &
579 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
580 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
581
582 /*
583 * If some other vif is using the MU-MIMO capablity we cannot associate
584 * using MU-MIMO - this will lead to contradictions in the group-id
585 * mechanism.
586 * Ownership is defined since association request, in order to avoid
587 * simultaneous associations with MU-MIMO.
588 */
589 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
590 bool disable_mu_mimo = false;
591 struct ieee80211_sub_if_data *other;
592
593 list_for_each_entry_rcu(other, &local->interfaces, list) {
Sara Sharonb5a33d52016-02-16 12:48:18 +0200594 if (other->vif.mu_mimo_owner) {
Sara Sharon322cd402015-07-08 15:41:43 +0300595 disable_mu_mimo = true;
596 break;
597 }
598 }
599 if (disable_mu_mimo)
600 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
601 else
Sara Sharonb5a33d52016-02-16 12:48:18 +0200602 sdata->vif.mu_mimo_owner = true;
Sara Sharon322cd402015-07-08 15:41:43 +0300603 }
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100604
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200605 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
606
607 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
608 our_bf_sts = cap & mask;
609
610 if (ap_bf_sts < our_bf_sts) {
611 cap &= ~mask;
612 cap |= ap_bf_sts;
613 }
614
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000615 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000616 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000617 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
618}
619
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300620/* This function determines HE capability flags for the association
621 * and builds the IE.
622 */
623static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
624 struct sk_buff *skb,
625 struct ieee80211_supported_band *sband)
626{
627 u8 *pos;
628 const struct ieee80211_sta_he_cap *he_cap = NULL;
Haim Dreyfussb5db1ac2020-01-31 13:12:44 +0200629 struct ieee80211_chanctx_conf *chanctx_conf;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300630 u8 he_cap_size;
Haim Dreyfussb5db1ac2020-01-31 13:12:44 +0200631 bool reg_cap = false;
632
633 rcu_read_lock();
634 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
635 if (!WARN_ON_ONCE(!chanctx_conf))
636 reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy,
637 &chanctx_conf->def,
638 IEEE80211_CHAN_NO_HE);
639
640 rcu_read_unlock();
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300641
642 he_cap = ieee80211_get_he_sta_cap(sband);
Haim Dreyfussb5db1ac2020-01-31 13:12:44 +0200643 if (!he_cap || !reg_cap)
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300644 return;
645
646 /*
647 * TODO: the 1 added is because this temporarily is under the EXTENSION
648 * IE. Get rid of it when it moves.
649 */
650 he_cap_size =
651 2 + 1 + sizeof(he_cap->he_cap_elem) +
652 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
653 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
654 he_cap->he_cap_elem.phy_cap_info);
655 pos = skb_put(skb, he_cap_size);
656 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
657}
658
Johannes Berg66e67e42012-01-20 13:55:27 +0100659static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
660{
661 struct ieee80211_local *local = sdata->local;
662 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
663 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
664 struct sk_buff *skb;
665 struct ieee80211_mgmt *mgmt;
Jouni Malinen4d9ec732019-02-15 02:14:33 +0200666 u8 *pos, qos_info, *ie_start;
Johannes Berg66e67e42012-01-20 13:55:27 +0100667 size_t offset = 0, noffset;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200668 int i, count, rates_len, supp_rates_len, shift;
Johannes Berg66e67e42012-01-20 13:55:27 +0100669 u16 capab;
670 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200671 struct ieee80211_chanctx_conf *chanctx_conf;
672 struct ieee80211_channel *chan;
Johannes Berg44f6d422017-06-10 13:52:44 +0300673 u32 rates = 0;
Johannes Berg2ff69b02020-01-31 13:31:11 +0200674 struct element *ext_capa = NULL;
675
676 /* we know it's writable, cast away the const */
677 if (assoc_data->ie_len)
678 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
679 assoc_data->ie,
680 assoc_data->ie_len);
Johannes Berg66e67e42012-01-20 13:55:27 +0100681
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200682 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +0100683
Johannes Berg55de9082012-07-26 17:24:39 +0200684 rcu_read_lock();
685 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
686 if (WARN_ON(!chanctx_conf)) {
687 rcu_read_unlock();
688 return;
689 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100690 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200691 rcu_read_unlock();
692 sband = local->hw.wiphy->bands[chan->band];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200693 shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg66e67e42012-01-20 13:55:27 +0100694
695 if (assoc_data->supp_rates_len) {
696 /*
697 * Get all rates supported by the device and the AP as
698 * some APs don't like getting a superset of their rates
699 * in the association request (e.g. D-Link DAP 1353 in
700 * b-only mode)...
701 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200702 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
703 assoc_data->supp_rates,
704 assoc_data->supp_rates_len,
705 &rates);
Johannes Berg66e67e42012-01-20 13:55:27 +0100706 } else {
707 /*
708 * In case AP not provide any supported rates information
709 * before association, we send information element(s) with
710 * all rates that we support.
711 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200712 rates_len = 0;
713 for (i = 0; i < sband->n_bitrates; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200714 rates |= BIT(i);
715 rates_len++;
716 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100717 }
718
719 skb = alloc_skb(local->hw.extra_tx_headroom +
720 sizeof(*mgmt) + /* bit too much but doesn't matter */
721 2 + assoc_data->ssid_len + /* SSID */
722 4 + rates_len + /* (extended) rates */
723 4 + /* power capability */
724 2 + 2 * sband->n_channels + /* supported channels */
725 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000726 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300727 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
728 sizeof(struct ieee80211_he_mcs_nss_supp) +
729 IEEE80211_HE_PPE_THRES_MAX_LEN +
Johannes Berg66e67e42012-01-20 13:55:27 +0100730 assoc_data->ie_len + /* extra IEs */
Jouni Malinen39404fe2016-10-27 00:42:05 +0300731 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
Johannes Berg66e67e42012-01-20 13:55:27 +0100732 9, /* WMM */
733 GFP_KERNEL);
734 if (!skb)
735 return;
736
737 skb_reserve(skb, local->hw.extra_tx_headroom);
738
739 capab = WLAN_CAPABILITY_ESS;
740
Johannes Berg57fbcce2016-04-12 15:56:15 +0200741 if (sband->band == NL80211_BAND_2GHZ) {
Johannes Bergea1b2b452015-06-02 20:15:49 +0200742 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
743 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
Johannes Berg66e67e42012-01-20 13:55:27 +0100744 }
745
746 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
747 capab |= WLAN_CAPABILITY_PRIVACY;
748
749 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg30686bf2015-06-02 21:39:54 +0200750 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
Johannes Berg66e67e42012-01-20 13:55:27 +0100751 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
752
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300753 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
754 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
755
Johannes Bergb080db52017-06-16 14:29:19 +0200756 mgmt = skb_put_zero(skb, 24);
Johannes Berg66e67e42012-01-20 13:55:27 +0100757 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
758 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
759 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
760
761 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
762 skb_put(skb, 10);
763 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
764 IEEE80211_STYPE_REASSOC_REQ);
765 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
766 mgmt->u.reassoc_req.listen_interval =
767 cpu_to_le16(local->hw.conf.listen_interval);
768 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
769 ETH_ALEN);
770 } else {
771 skb_put(skb, 4);
772 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
773 IEEE80211_STYPE_ASSOC_REQ);
774 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
775 mgmt->u.assoc_req.listen_interval =
776 cpu_to_le16(local->hw.conf.listen_interval);
777 }
778
779 /* SSID */
780 pos = skb_put(skb, 2 + assoc_data->ssid_len);
Jouni Malinen4d9ec732019-02-15 02:14:33 +0200781 ie_start = pos;
Johannes Berg66e67e42012-01-20 13:55:27 +0100782 *pos++ = WLAN_EID_SSID;
783 *pos++ = assoc_data->ssid_len;
784 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
785
786 /* add all rates which were marked to be used above */
787 supp_rates_len = rates_len;
788 if (supp_rates_len > 8)
789 supp_rates_len = 8;
790
791 pos = skb_put(skb, supp_rates_len + 2);
792 *pos++ = WLAN_EID_SUPP_RATES;
793 *pos++ = supp_rates_len;
794
795 count = 0;
796 for (i = 0; i < sband->n_bitrates; i++) {
797 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200798 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
799 5 * (1 << shift));
800 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100801 if (++count == 8)
802 break;
803 }
804 }
805
806 if (rates_len > count) {
807 pos = skb_put(skb, rates_len - count + 2);
808 *pos++ = WLAN_EID_EXT_SUPP_RATES;
809 *pos++ = rates_len - count;
810
811 for (i++; i < sband->n_bitrates; i++) {
812 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200813 int rate;
814 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
815 5 * (1 << shift));
816 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100817 }
818 }
819 }
820
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300821 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
822 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100823 pos = skb_put(skb, 4);
824 *pos++ = WLAN_EID_PWR_CAPABILITY;
825 *pos++ = 2;
826 *pos++ = 0; /* min tx power */
Simon Wunderlich0430c882013-07-08 16:55:55 +0200827 /* max tx power */
828 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300829 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100830
Johannes Berg2ff69b02020-01-31 13:31:11 +0200831 /*
832 * Per spec, we shouldn't include the list of channels if we advertise
833 * support for extended channel switching, but we've always done that;
834 * (for now?) apply this restriction only on the (new) 6 GHz band.
835 */
836 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
837 (sband->band != NL80211_BAND_6GHZ ||
838 !ext_capa || ext_capa->datalen < 1 ||
839 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100840 /* TODO: get this in reg domain format */
841 pos = skb_put(skb, 2 * sband->n_channels + 2);
842 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
843 *pos++ = 2 * sband->n_channels;
844 for (i = 0; i < sband->n_channels; i++) {
845 *pos++ = ieee80211_frequency_to_channel(
846 sband->channels[i].center_freq);
847 *pos++ = 1; /* one channel in the subband*/
848 }
849 }
850
Sara Sharoncaf56332019-01-16 23:03:25 +0200851 /* Set MBSSID support for HE AP if needed */
852 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
Johannes Berg2ff69b02020-01-31 13:31:11 +0200853 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len &&
854 ext_capa && ext_capa->datalen >= 3)
855 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
Sara Sharoncaf56332019-01-16 23:03:25 +0200856
Johannes Berg66e67e42012-01-20 13:55:27 +0100857 /* if present, add any custom IEs that go before HT */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200858 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100859 static const u8 before_ht[] = {
860 WLAN_EID_SSID,
861 WLAN_EID_SUPP_RATES,
862 WLAN_EID_EXT_SUPP_RATES,
863 WLAN_EID_PWR_CAPABILITY,
864 WLAN_EID_SUPPORTED_CHANNELS,
865 WLAN_EID_RSN,
866 WLAN_EID_QOS_CAPA,
867 WLAN_EID_RRM_ENABLED_CAPABILITIES,
868 WLAN_EID_MOBILITY_DOMAIN,
Johannes Berg8ed28742014-10-27 12:03:19 +0100869 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
870 WLAN_EID_RIC_DATA, /* reassoc only */
Johannes Berg66e67e42012-01-20 13:55:27 +0100871 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
872 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100873 static const u8 after_ric[] = {
874 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
875 WLAN_EID_HT_CAPABILITY,
876 WLAN_EID_BSS_COEX_2040,
Johannes Berga7f26d82017-08-05 11:44:32 +0300877 /* luckily this is almost always there */
Johannes Berg8ed28742014-10-27 12:03:19 +0100878 WLAN_EID_EXT_CAPABILITY,
879 WLAN_EID_QOS_TRAFFIC_CAPA,
880 WLAN_EID_TIM_BCAST_REQ,
881 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300882 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg8ed28742014-10-27 12:03:19 +0100883 WLAN_EID_VHT_CAPABILITY,
884 WLAN_EID_OPMODE_NOTIF,
885 };
886
887 noffset = ieee80211_ie_split_ric(assoc_data->ie,
888 assoc_data->ie_len,
889 before_ht,
890 ARRAY_SIZE(before_ht),
891 after_ric,
892 ARRAY_SIZE(after_ric),
893 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800894 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100895 offset = noffset;
896 }
897
Johannes Bergf2d9d272012-11-22 14:11:39 +0100898 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
899 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
900 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
901
Johannes Berga8243b72012-11-22 14:32:09 +0100902 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200903 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200904 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100905
Johannes Berg3de38022014-02-04 09:54:07 +0100906 /* if present, add any custom IEs that go before VHT */
907 if (assoc_data->ie_len) {
908 static const u8 before_vht[] = {
Johannes Berga7f26d82017-08-05 11:44:32 +0300909 /*
910 * no need to list the ones split off before HT
911 * or generated here
912 */
Johannes Berg3de38022014-02-04 09:54:07 +0100913 WLAN_EID_BSS_COEX_2040,
914 WLAN_EID_EXT_CAPABILITY,
915 WLAN_EID_QOS_TRAFFIC_CAPA,
916 WLAN_EID_TIM_BCAST_REQ,
917 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300918 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg3de38022014-02-04 09:54:07 +0100919 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100920
921 /* RIC already taken above, so no need to handle here anymore */
Johannes Berg3de38022014-02-04 09:54:07 +0100922 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
923 before_vht, ARRAY_SIZE(before_vht),
924 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800925 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg3de38022014-02-04 09:54:07 +0100926 offset = noffset;
927 }
928
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300929 /* if present, add any custom IEs that go before HE */
930 if (assoc_data->ie_len) {
931 static const u8 before_he[] = {
932 /*
933 * no need to list the ones split off before VHT
934 * or generated here
935 */
936 WLAN_EID_OPMODE_NOTIF,
937 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
938 /* 11ai elements */
939 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
940 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
941 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
942 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
943 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
944 /* TODO: add 11ah/11aj/11ak elements */
945 };
946
947 /* RIC already taken above, so no need to handle here anymore */
948 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
949 before_he, ARRAY_SIZE(before_he),
950 offset);
951 pos = skb_put(skb, noffset - offset);
952 memcpy(pos, assoc_data->ie + offset, noffset - offset);
953 offset = noffset;
954 }
955
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000956 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100957 ieee80211_add_vht_ie(sdata, skb, sband,
958 &assoc_data->ap_vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000959
Shaul Triebitzdc7eb0f2018-12-15 11:03:20 +0200960 /*
961 * If AP doesn't support HT, mark HE as disabled.
962 * If on the 5GHz band, make sure it supports VHT.
963 */
964 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
965 (sband->band == NL80211_BAND_5GHZ &&
966 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
967 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
968
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300969 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
970 ieee80211_add_he_ie(sdata, skb, sband);
971
972 /* if present, add any custom non-vendor IEs that go after HE */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200973 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100974 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
975 assoc_data->ie_len,
976 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800977 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100978 offset = noffset;
979 }
980
Johannes Berg76f03032012-03-08 15:02:05 +0100981 if (assoc_data->wmm) {
982 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200983 qos_info = ifmgd->uapsd_queues;
984 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100985 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
986 } else {
987 qos_info = 0;
988 }
989
Arik Nemtsov40b861a2014-07-17 17:14:23 +0300990 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
Johannes Berg66e67e42012-01-20 13:55:27 +0100991 }
992
993 /* add any remaining custom (i.e. vendor specific here) IEs */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200994 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100995 noffset = assoc_data->ie_len;
yuan linyub952f4d2017-06-18 22:52:04 +0800996 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100997 }
998
Jouni Malinen39404fe2016-10-27 00:42:05 +0300999 if (assoc_data->fils_kek_len &&
1000 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
1001 dev_kfree_skb(skb);
1002 return;
1003 }
1004
Jouni Malinen4d9ec732019-02-15 02:14:33 +02001005 pos = skb_tail_pointer(skb);
1006 kfree(ifmgd->assoc_req_ies);
1007 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1008 ifmgd->assoc_req_ies_len = pos - ie_start;
1009
Ilan Peerd4e36e52018-04-20 13:49:25 +03001010 drv_mgd_prepare_tx(local, sdata, 0);
Johannes Berga1845fc2012-06-27 13:18:36 +02001011
Johannes Berg66e67e42012-01-20 13:55:27 +01001012 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Johannes Berg30686bf2015-06-02 21:39:54 +02001013 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +01001014 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1015 IEEE80211_TX_INTFL_MLME_CONN_TX;
Johannes Berg66e67e42012-01-20 13:55:27 +01001016 ieee80211_tx_skb(sdata, skb);
1017}
1018
Kalle Valo572e0012009-02-10 17:09:31 +02001019void ieee80211_send_pspoll(struct ieee80211_local *local,
1020 struct ieee80211_sub_if_data *sdata)
1021{
Kalle Valo572e0012009-02-10 17:09:31 +02001022 struct ieee80211_pspoll *pspoll;
1023 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +02001024
Kalle Valod8cd1892010-01-05 20:16:26 +02001025 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1026 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +02001027 return;
Kalle Valo572e0012009-02-10 17:09:31 +02001028
Kalle Valod8cd1892010-01-05 20:16:26 +02001029 pspoll = (struct ieee80211_pspoll *) skb->data;
1030 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +02001031
Johannes Berg62ae67b2009-11-18 18:42:05 +01001032 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1033 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +02001034}
1035
Johannes Berg965beda2009-04-16 13:17:24 +02001036void ieee80211_send_nullfunc(struct ieee80211_local *local,
1037 struct ieee80211_sub_if_data *sdata,
Johannes Berg076cdcb2015-09-24 16:14:55 +02001038 bool powersave)
Johannes Berg965beda2009-04-16 13:17:24 +02001039{
1040 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +02001041 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +05301042 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +02001043
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001044 /* Don't send NDPs when STA is connected HE */
1045 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1046 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
1047 return;
1048
Ben Caradoc-Davies7c181f42018-03-19 12:57:44 +13001049 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1050 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
Kalle Valod8cd1892010-01-05 20:16:26 +02001051 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +02001052 return;
1053
Kalle Valod8cd1892010-01-05 20:16:26 +02001054 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +02001055 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +02001056 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +02001057
Seth Forshee6c17b772013-02-11 11:21:07 -06001058 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1059 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Pontus Fuchsff40b422013-06-04 12:44:52 +02001060
Johannes Berg30686bf2015-06-02 21:39:54 +02001061 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Pontus Fuchsff40b422013-06-04 12:44:52 +02001062 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1063
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001064 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +05301065 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1066
Johannes Berg62ae67b2009-11-18 18:42:05 +01001067 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +02001068}
1069
Felix Fietkaud5242152010-01-08 18:06:26 +01001070static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1071 struct ieee80211_sub_if_data *sdata)
1072{
1073 struct sk_buff *skb;
1074 struct ieee80211_hdr *nullfunc;
1075 __le16 fc;
1076
1077 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1078 return;
1079
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001080 /* Don't send NDPs when connected HE */
1081 if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE))
1082 return;
1083
Felix Fietkaud5242152010-01-08 18:06:26 +01001084 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -07001085 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +01001086 return;
Joe Perchesd15b8452011-08-29 14:17:31 -07001087
Felix Fietkaud5242152010-01-08 18:06:26 +01001088 skb_reserve(skb, local->hw.extra_tx_headroom);
1089
Johannes Bergb080db52017-06-16 14:29:19 +02001090 nullfunc = skb_put_zero(skb, 30);
Felix Fietkaud5242152010-01-08 18:06:26 +01001091 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1092 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1093 nullfunc->frame_control = fc;
1094 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1095 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1096 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1097 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1098
1099 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1100 ieee80211_tx_skb(sdata, skb);
1101}
1102
Johannes Bergcc32abd2009-05-15 11:52:31 +02001103/* spectrum management related things */
1104static void ieee80211_chswitch_work(struct work_struct *work)
1105{
1106 struct ieee80211_sub_if_data *sdata =
1107 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Karl Beldan675a0b02013-03-25 16:26:57 +01001108 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001109 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001110 int ret;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001111
Johannes Berg9607e6b662009-12-23 13:15:31 +01001112 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +02001113 return;
1114
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001115 sdata_lock(sdata);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001116 mutex_lock(&local->mtx);
1117 mutex_lock(&local->chanctx_mtx);
1118
Johannes Berg77fdaa12009-07-07 03:45:17 +02001119 if (!ifmgd->associated)
1120 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001121
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001122 if (!sdata->vif.csa_active)
1123 goto out;
1124
1125 /*
1126 * using reservation isn't immediate as it may be deferred until later
1127 * with multi-vif. once reservation is complete it will re-schedule the
1128 * work with no reserved_chanctx so verify chandef to check if it
1129 * completed successfully
1130 */
1131
1132 if (sdata->reserved_chanctx) {
Ilan Peer0007e942018-08-31 11:31:10 +03001133 struct ieee80211_supported_band *sband = NULL;
1134 struct sta_info *mgd_sta = NULL;
1135 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
1136
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001137 /*
1138 * with multi-vif csa driver may call ieee80211_csa_finish()
1139 * many times while waiting for other interfaces to use their
1140 * reservations
1141 */
1142 if (sdata->reserved_ready)
1143 goto out;
1144
Ilan Peer0007e942018-08-31 11:31:10 +03001145 if (sdata->vif.bss_conf.chandef.width !=
1146 sdata->csa_chandef.width) {
1147 /*
1148 * For managed interface, we need to also update the AP
1149 * station bandwidth and align the rate scale algorithm
1150 * on the bandwidth change. Here we only consider the
1151 * bandwidth of the new channel definition (as channel
1152 * switch flow does not have the full HT/VHT/HE
1153 * information), assuming that if additional changes are
1154 * required they would be done as part of the processing
1155 * of the next beacon from the AP.
1156 */
1157 switch (sdata->csa_chandef.width) {
1158 case NL80211_CHAN_WIDTH_20_NOHT:
1159 case NL80211_CHAN_WIDTH_20:
1160 default:
1161 bw = IEEE80211_STA_RX_BW_20;
1162 break;
1163 case NL80211_CHAN_WIDTH_40:
1164 bw = IEEE80211_STA_RX_BW_40;
1165 break;
1166 case NL80211_CHAN_WIDTH_80:
1167 bw = IEEE80211_STA_RX_BW_80;
1168 break;
1169 case NL80211_CHAN_WIDTH_80P80:
1170 case NL80211_CHAN_WIDTH_160:
1171 bw = IEEE80211_STA_RX_BW_160;
1172 break;
1173 }
1174
1175 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1176 sband =
1177 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1178 }
1179
1180 if (sdata->vif.bss_conf.chandef.width >
1181 sdata->csa_chandef.width) {
1182 mgd_sta->sta.bandwidth = bw;
1183 rate_control_rate_update(local, sband, mgd_sta,
1184 IEEE80211_RC_BW_CHANGED);
1185 }
1186
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001187 ret = ieee80211_vif_use_reserved_context(sdata);
1188 if (ret) {
1189 sdata_info(sdata,
1190 "failed to use reserved channel context, disconnecting (err=%d)\n",
1191 ret);
1192 ieee80211_queue_work(&sdata->local->hw,
1193 &ifmgd->csa_connection_drop_work);
1194 goto out;
1195 }
1196
Ilan Peer0007e942018-08-31 11:31:10 +03001197 if (sdata->vif.bss_conf.chandef.width <
1198 sdata->csa_chandef.width) {
1199 mgd_sta->sta.bandwidth = bw;
1200 rate_control_rate_update(local, sband, mgd_sta,
1201 IEEE80211_RC_BW_CHANGED);
1202 }
1203
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001204 goto out;
1205 }
1206
1207 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1208 &sdata->csa_chandef)) {
Arik Nemtsov7578d572013-09-01 17:15:51 +03001209 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001210 "failed to finalize channel switch, disconnecting\n");
Arik Nemtsov7578d572013-09-01 17:15:51 +03001211 ieee80211_queue_work(&sdata->local->hw,
1212 &ifmgd->csa_connection_drop_work);
1213 goto out;
1214 }
Karl Beldan675a0b02013-03-25 16:26:57 +01001215
Luciano Coelho0c21e632014-10-08 09:48:39 +03001216 ifmgd->csa_waiting_bcn = true;
Luciano Coelhof1d65582014-10-08 09:48:38 +03001217
Michal Kaziore5593f52014-04-09 15:45:36 +02001218 ieee80211_sta_reset_beacon_monitor(sdata);
1219 ieee80211_sta_reset_conn_monitor(sdata);
1220
Michal Kazior59af6922014-04-09 15:10:59 +02001221out:
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001222 mutex_unlock(&local->chanctx_mtx);
1223 mutex_unlock(&local->mtx);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001224 sdata_unlock(sdata);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001225}
1226
Luciano Coelho0c21e632014-10-08 09:48:39 +03001227static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1228{
1229 struct ieee80211_local *local = sdata->local;
1230 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1231 int ret;
1232
1233 sdata_assert_lock(sdata);
1234
1235 WARN_ON(!sdata->vif.csa_active);
1236
1237 if (sdata->csa_block_tx) {
1238 ieee80211_wake_vif_queues(local, sdata,
1239 IEEE80211_QUEUE_STOP_REASON_CSA);
1240 sdata->csa_block_tx = false;
1241 }
1242
1243 sdata->vif.csa_active = false;
1244 ifmgd->csa_waiting_bcn = false;
1245
1246 ret = drv_post_channel_switch(sdata);
1247 if (ret) {
1248 sdata_info(sdata,
1249 "driver post channel switch failed, disconnecting\n");
1250 ieee80211_queue_work(&local->hw,
1251 &ifmgd->csa_connection_drop_work);
1252 return;
1253 }
Luciano Coelho688b1ec2014-12-16 16:01:39 +02001254
1255 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
Luciano Coelho0c21e632014-10-08 09:48:39 +03001256}
1257
Johannes Berg5ce6e432010-05-11 16:20:57 +02001258void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1259{
Johannes Berg55de9082012-07-26 17:24:39 +02001260 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1261 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001262
1263 trace_api_chswitch_done(sdata, success);
1264 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001265 sdata_info(sdata,
1266 "driver channel switch failed, disconnecting\n");
1267 ieee80211_queue_work(&sdata->local->hw,
1268 &ifmgd->csa_connection_drop_work);
1269 } else {
1270 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001271 }
Johannes Berg5ce6e432010-05-11 16:20:57 +02001272}
1273EXPORT_SYMBOL(ieee80211_chswitch_done);
1274
Kees Cook34f11cd2017-10-16 16:35:49 -07001275static void ieee80211_chswitch_timer(struct timer_list *t)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001276{
1277 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07001278 from_timer(sdata, t, u.mgd.chswitch_timer);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001279
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01001280 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001281}
1282
Johannes Berg37799e52013-03-26 14:02:26 +01001283static void
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001284ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata)
1285{
1286 struct ieee80211_local *local = sdata->local;
1287
1288 if (!local->ops->abort_channel_switch)
1289 return;
1290
1291 mutex_lock(&local->mtx);
1292
1293 mutex_lock(&local->chanctx_mtx);
1294 ieee80211_vif_unreserve_chanctx(sdata);
1295 mutex_unlock(&local->chanctx_mtx);
1296
1297 if (sdata->csa_block_tx)
1298 ieee80211_wake_vif_queues(local, sdata,
1299 IEEE80211_QUEUE_STOP_REASON_CSA);
1300
1301 sdata->csa_block_tx = false;
1302 sdata->vif.csa_active = false;
1303
1304 mutex_unlock(&local->mtx);
1305
1306 drv_abort_channel_switch(sdata);
1307}
1308
1309static void
Johannes Berg4a3cb702013-02-12 16:43:19 +01001310ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03001311 u64 timestamp, u32 device_timestamp,
1312 struct ieee802_11_elems *elems,
Johannes Berg04a161f2013-05-03 09:35:35 +02001313 bool beacon)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001314{
Johannes Bergb4f286a12013-03-26 14:13:58 +01001315 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001316 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg37799e52013-03-26 14:02:26 +01001317 struct cfg80211_bss *cbss = ifmgd->associated;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001318 struct ieee80211_chanctx_conf *conf;
Johannes Berg55de9082012-07-26 17:24:39 +02001319 struct ieee80211_chanctx *chanctx;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001320 enum nl80211_band current_band;
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001321 struct ieee80211_csa_ie csa_ie;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001322 struct ieee80211_channel_switch ch_switch;
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001323 int res;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001324
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001325 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001326
Johannes Berg37799e52013-03-26 14:02:26 +01001327 if (!cbss)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001328 return;
1329
Johannes Bergb4f286a12013-03-26 14:13:58 +01001330 if (local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001331 return;
1332
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001333 current_band = cbss->channel->band;
Luciano Coelho84469a42014-10-28 13:33:04 +02001334 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001335 ifmgd->flags,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001336 ifmgd->associated->bssid, &csa_ie);
Sara Sharonfafd2bc2019-02-06 13:17:15 +02001337
1338 if (!res) {
1339 ch_switch.timestamp = timestamp;
1340 ch_switch.device_timestamp = device_timestamp;
Sara Sharon7976b1e2019-02-06 13:17:17 +02001341 ch_switch.block_tx = beacon ? csa_ie.mode : 0;
Sara Sharonfafd2bc2019-02-06 13:17:15 +02001342 ch_switch.chandef = csa_ie.chandef;
1343 ch_switch.count = csa_ie.count;
1344 ch_switch.delay = csa_ie.max_switch_time;
1345 }
1346
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001347 if (res < 0) {
Johannes Bergb4f286a12013-03-26 14:13:58 +01001348 ieee80211_queue_work(&local->hw,
Johannes Berg882a7c62012-08-01 22:32:45 +02001349 &ifmgd->csa_connection_drop_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001350 return;
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001351 }
1352
Sara Sharonfafd2bc2019-02-06 13:17:15 +02001353 if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) {
1354 if (res)
1355 ieee80211_sta_abort_chanswitch(sdata);
1356 else
1357 drv_channel_switch_rx_beacon(sdata, &ch_switch);
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001358 return;
1359 } else if (sdata->vif.csa_active || res) {
1360 /* disregard subsequent announcements if already processing */
1361 return;
1362 }
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001363
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001364 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
Johannes Berg85220d72013-03-25 18:29:27 +01001365 IEEE80211_CHAN_DISABLED)) {
1366 sdata_info(sdata,
1367 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001368 ifmgd->associated->bssid,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001369 csa_ie.chandef.chan->center_freq,
1370 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1371 csa_ie.chandef.center_freq2);
Johannes Berg85220d72013-03-25 18:29:27 +01001372 ieee80211_queue_work(&local->hw,
1373 &ifmgd->csa_connection_drop_work);
1374 return;
1375 }
1376
Johannes Bergf84eaa12015-03-12 08:53:26 +02001377 if (cfg80211_chandef_identical(&csa_ie.chandef,
Sara Sharon97928752019-02-06 13:17:16 +02001378 &sdata->vif.bss_conf.chandef) &&
1379 (!csa_ie.mode || !beacon)) {
Johannes Bergf84eaa12015-03-12 08:53:26 +02001380 if (ifmgd->csa_ignored_same_chan)
1381 return;
1382 sdata_info(sdata,
1383 "AP %pM tries to chanswitch to same channel, ignore\n",
1384 ifmgd->associated->bssid);
1385 ifmgd->csa_ignored_same_chan = true;
1386 return;
1387 }
1388
Arik Nemtsovc5a71682015-05-19 14:36:48 +03001389 /*
1390 * Drop all TDLS peers - either we disconnect or move to a different
1391 * channel from this point on. There's no telling what our peer will do.
1392 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1393 * have an incompatible wider chandef.
1394 */
1395 ieee80211_teardown_tdls_peers(sdata);
1396
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001397 mutex_lock(&local->mtx);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001398 mutex_lock(&local->chanctx_mtx);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001399 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1400 lockdep_is_held(&local->chanctx_mtx));
1401 if (!conf) {
1402 sdata_info(sdata,
1403 "no channel context assigned to vif?, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001404 goto drop_connection;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001405 }
1406
1407 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1408
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001409 if (local->use_chanctx &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001410 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001411 sdata_info(sdata,
1412 "driver doesn't support chan-switch with channel contexts\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001413 goto drop_connection;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001414 }
1415
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001416 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1417 sdata_info(sdata,
1418 "preparing for channel switch failed, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001419 goto drop_connection;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001420 }
1421
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001422 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1423 chanctx->mode, false);
1424 if (res) {
Johannes Berg55de9082012-07-26 17:24:39 +02001425 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001426 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1427 res);
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001428 goto drop_connection;
Johannes Berg55de9082012-07-26 17:24:39 +02001429 }
Johannes Bergb4f286a12013-03-26 14:13:58 +01001430 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001431
Michal Kazior59af6922014-04-09 15:10:59 +02001432 sdata->vif.csa_active = true;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001433 sdata->csa_chandef = csa_ie.chandef;
Sara Sharon7976b1e2019-02-06 13:17:17 +02001434 sdata->csa_block_tx = ch_switch.block_tx;
Johannes Bergf84eaa12015-03-12 08:53:26 +02001435 ifmgd->csa_ignored_same_chan = false;
Michal Kazior59af6922014-04-09 15:10:59 +02001436
1437 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03001438 ieee80211_stop_vif_queues(local, sdata,
1439 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02001440 mutex_unlock(&local->mtx);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001441
Luciano Coelho2f457292014-11-07 14:31:36 +02001442 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1443 csa_ie.count);
1444
Johannes Bergb4f286a12013-03-26 14:13:58 +01001445 if (local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +02001446 /* use driver's channel switch callback */
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001447 drv_channel_switch(local, sdata, &ch_switch);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001448 return;
1449 }
1450
1451 /* channel switch handled in software */
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001452 if (csa_ie.count <= 1)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001453 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001454 else
Johannes Bergcc32abd2009-05-15 11:52:31 +02001455 mod_timer(&ifmgd->chswitch_timer,
Luciano Coelhoff1e4172014-10-28 13:33:05 +02001456 TU_TO_EXP_TIME((csa_ie.count - 1) *
1457 cbss->beacon_interval));
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001458 return;
1459 drop_connection:
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03001460 /*
1461 * This is just so that the disconnect flow will know that
1462 * we were trying to switch channel and failed. In case the
1463 * mode is 1 (we are not allowed to Tx), we will know not to
1464 * send a deauthentication frame. Those two fields will be
1465 * reset when the disconnection worker runs.
1466 */
1467 sdata->vif.csa_active = true;
Sara Sharon7976b1e2019-02-06 13:17:17 +02001468 sdata->csa_block_tx = ch_switch.block_tx;
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03001469
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001470 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1471 mutex_unlock(&local->chanctx_mtx);
1472 mutex_unlock(&local->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001473}
1474
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001475static bool
1476ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1477 struct ieee80211_channel *channel,
1478 const u8 *country_ie, u8 country_ie_len,
1479 const u8 *pwr_constr_elem,
1480 int *chan_pwr, int *pwr_reduction)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001481{
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001482 struct ieee80211_country_ie_triplet *triplet;
1483 int chan = ieee80211_frequency_to_channel(channel->center_freq);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001484 int i, chan_increment;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001485 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001486
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001487 /* Invalid IE */
1488 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001489 return false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001490
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001491 triplet = (void *)(country_ie + 3);
1492 country_ie_len -= 3;
1493
1494 switch (channel->band) {
1495 default:
1496 WARN_ON_ONCE(1);
1497 /* fall through */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001498 case NL80211_BAND_2GHZ:
1499 case NL80211_BAND_60GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001500 chan_increment = 1;
1501 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001502 case NL80211_BAND_5GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001503 chan_increment = 4;
1504 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001505 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001506
1507 /* find channel */
1508 while (country_ie_len >= 3) {
1509 u8 first_channel = triplet->chans.first_channel;
1510
1511 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1512 goto next;
1513
1514 for (i = 0; i < triplet->chans.num_channels; i++) {
1515 if (first_channel + i * chan_increment == chan) {
1516 have_chan_pwr = true;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001517 *chan_pwr = triplet->chans.max_power;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001518 break;
1519 }
1520 }
1521 if (have_chan_pwr)
1522 break;
1523
1524 next:
1525 triplet++;
1526 country_ie_len -= 3;
1527 }
1528
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001529 if (have_chan_pwr && pwr_constr_elem)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001530 *pwr_reduction = *pwr_constr_elem;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001531 else
1532 *pwr_reduction = 0;
1533
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001534 return have_chan_pwr;
1535}
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001536
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001537static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1538 struct ieee80211_channel *channel,
1539 const u8 *cisco_dtpc_ie,
1540 int *pwr_level)
1541{
1542 /* From practical testing, the first data byte of the DTPC element
1543 * seems to contain the requested dBm level, and the CLI on Cisco
1544 * APs clearly state the range is -127 to 127 dBm, which indicates
1545 * a signed byte, although it seemingly never actually goes negative.
1546 * The other byte seems to always be zero.
1547 */
1548 *pwr_level = (__s8)cisco_dtpc_ie[4];
1549}
1550
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001551static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1552 struct ieee80211_channel *channel,
1553 struct ieee80211_mgmt *mgmt,
1554 const u8 *country_ie, u8 country_ie_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001555 const u8 *pwr_constr_ie,
1556 const u8 *cisco_dtpc_ie)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001557{
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001558 bool has_80211h_pwr = false, has_cisco_pwr = false;
1559 int chan_pwr = 0, pwr_reduction_80211h = 0;
1560 int pwr_level_cisco, pwr_level_80211h;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001561 int new_ap_level;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001562 __le16 capab = mgmt->u.probe_resp.capab_info;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001563
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001564 if (country_ie &&
1565 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1566 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001567 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1568 sdata, channel, country_ie, country_ie_len,
1569 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001570 pwr_level_80211h =
1571 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001572 }
1573
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001574 if (cisco_dtpc_ie) {
1575 ieee80211_find_cisco_dtpc(
1576 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1577 has_cisco_pwr = true;
1578 }
1579
1580 if (!has_80211h_pwr && !has_cisco_pwr)
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001581 return 0;
1582
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001583 /* If we have both 802.11h and Cisco DTPC, apply both limits
1584 * by picking the smallest of the two power levels advertised.
1585 */
1586 if (has_80211h_pwr &&
1587 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
Johannes Berga87da0c2015-12-08 16:04:37 +02001588 new_ap_level = pwr_level_80211h;
1589
1590 if (sdata->ap_power_level == new_ap_level)
1591 return 0;
1592
John Linvillecef2fc12015-03-31 10:49:14 -04001593 sdata_dbg(sdata,
1594 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1595 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1596 sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001597 } else { /* has_cisco_pwr is always true here. */
Johannes Berga87da0c2015-12-08 16:04:37 +02001598 new_ap_level = pwr_level_cisco;
1599
1600 if (sdata->ap_power_level == new_ap_level)
1601 return 0;
1602
John Linvillecef2fc12015-03-31 10:49:14 -04001603 sdata_dbg(sdata,
1604 "Limiting TX power to %d dBm as advertised by %pM\n",
1605 pwr_level_cisco, sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001606 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001607
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001608 sdata->ap_power_level = new_ap_level;
1609 if (__ieee80211_recalc_txpower(sdata))
1610 return BSS_CHANGED_TXPOWER;
1611 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001612}
1613
Johannes Berg965beda2009-04-16 13:17:24 +02001614/* powersave */
1615static void ieee80211_enable_ps(struct ieee80211_local *local,
1616 struct ieee80211_sub_if_data *sdata)
1617{
1618 struct ieee80211_conf *conf = &local->hw.conf;
1619
Johannes Bergd5edaed2009-04-22 23:02:51 +02001620 /*
1621 * If we are scanning right now then the parameters will
1622 * take effect when scan finishes.
1623 */
Helmut Schaafbe9c4292009-07-23 12:14:04 +02001624 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +02001625 return;
1626
Johannes Berg965beda2009-04-16 13:17:24 +02001627 if (conf->dynamic_ps_timeout > 0 &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001628 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001629 mod_timer(&local->dynamic_ps_timer, jiffies +
1630 msecs_to_jiffies(conf->dynamic_ps_timeout));
1631 } else {
Johannes Berg30686bf2015-06-02 21:39:54 +02001632 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
Johannes Berg076cdcb2015-09-24 16:14:55 +02001633 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajan375177b2010-02-09 14:50:28 +05301634
Johannes Berg30686bf2015-06-02 21:39:54 +02001635 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1636 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001637 return;
1638
1639 conf->flags |= IEEE80211_CONF_PS;
1640 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +02001641 }
1642}
1643
1644static void ieee80211_change_ps(struct ieee80211_local *local)
1645{
1646 struct ieee80211_conf *conf = &local->hw.conf;
1647
1648 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +02001649 ieee80211_enable_ps(local, local->ps_sdata);
1650 } else if (conf->flags & IEEE80211_CONF_PS) {
1651 conf->flags &= ~IEEE80211_CONF_PS;
1652 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1653 del_timer_sync(&local->dynamic_ps_timer);
1654 cancel_work_sync(&local->dynamic_ps_enable_work);
1655 }
1656}
1657
Jason Young808118c2011-03-10 16:43:19 -08001658static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1659{
1660 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1661 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001662 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001663
1664 if (!mgd->powersave)
1665 return false;
1666
Johannes Berg05cb9102011-10-28 11:59:47 +02001667 if (mgd->broken_ap)
1668 return false;
1669
Jason Young808118c2011-03-10 16:43:19 -08001670 if (!mgd->associated)
1671 return false;
1672
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001673 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
Jason Young808118c2011-03-10 16:43:19 -08001674 return false;
1675
Alexander Bondar989c6502013-05-16 17:34:17 +03001676 if (!mgd->have_beacon)
Alexander Bondarce857882013-05-06 17:17:04 +03001677 return false;
1678
Jason Young808118c2011-03-10 16:43:19 -08001679 rcu_read_lock();
1680 sta = sta_info_get(sdata, mgd->bssid);
1681 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001682 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001683 rcu_read_unlock();
1684
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001685 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001686}
1687
Johannes Berg965beda2009-04-16 13:17:24 +02001688/* need to hold RTNL or interface lock */
Johannes Berg4a733ef2015-10-14 18:02:43 +02001689void ieee80211_recalc_ps(struct ieee80211_local *local)
Johannes Berg965beda2009-04-16 13:17:24 +02001690{
1691 struct ieee80211_sub_if_data *sdata, *found = NULL;
1692 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001693 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001694
Johannes Berg30686bf2015-06-02 21:39:54 +02001695 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001696 local->ps_sdata = NULL;
1697 return;
1698 }
1699
1700 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b662009-12-23 13:15:31 +01001701 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001702 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301703 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1704 /* If an AP vif is found, then disable PS
1705 * by setting the count to zero thereby setting
1706 * ps_sdata to NULL.
1707 */
1708 count = 0;
1709 break;
1710 }
Johannes Berg965beda2009-04-16 13:17:24 +02001711 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1712 continue;
1713 found = sdata;
1714 count++;
1715 }
1716
Jason Young808118c2011-03-10 16:43:19 -08001717 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg4a733ef2015-10-14 18:02:43 +02001718 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg10f644a2009-04-16 13:17:25 +02001719
Juuso Oikarinenff616382010-06-09 09:51:52 +03001720 timeout = local->dynamic_ps_forced_timeout;
Johannes Berg4a733ef2015-10-14 18:02:43 +02001721 if (timeout < 0)
1722 timeout = 100;
Johannes Berg09b85562013-02-06 23:07:41 +01001723 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001724
Johannes Berg4a733ef2015-10-14 18:02:43 +02001725 /* If the TIM IE is invalid, pretend the value is 1 */
1726 if (!dtimper)
1727 dtimper = 1;
Johannes Berg56007a02010-01-26 14:19:52 +01001728
Johannes Berg4a733ef2015-10-14 18:02:43 +02001729 local->hw.conf.ps_dtim_period = dtimper;
1730 local->ps_sdata = found;
Johannes Berg10f644a2009-04-16 13:17:25 +02001731 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001732 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001733 }
Johannes Berg965beda2009-04-16 13:17:24 +02001734
1735 ieee80211_change_ps(local);
1736}
1737
Eliad Pellerab095872012-07-27 12:33:22 +03001738void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1739{
1740 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1741
1742 if (sdata->vif.bss_conf.ps != ps_allowed) {
1743 sdata->vif.bss_conf.ps = ps_allowed;
1744 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1745 }
1746}
1747
Johannes Berg965beda2009-04-16 13:17:24 +02001748void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1749{
1750 struct ieee80211_local *local =
1751 container_of(work, struct ieee80211_local,
1752 dynamic_ps_disable_work);
1753
1754 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1755 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1756 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1757 }
1758
1759 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001760 IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +03001761 IEEE80211_QUEUE_STOP_REASON_PS,
1762 false);
Johannes Berg965beda2009-04-16 13:17:24 +02001763}
1764
1765void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1766{
1767 struct ieee80211_local *local =
1768 container_of(work, struct ieee80211_local,
1769 dynamic_ps_enable_work);
1770 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001771 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301772 unsigned long flags;
1773 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001774
1775 /* can only happen when PS was just disabled anyway */
1776 if (!sdata)
1777 return;
1778
Christian Lamparter5e340692011-06-30 21:08:43 +02001779 ifmgd = &sdata->u.mgd;
1780
Johannes Berg965beda2009-04-16 13:17:24 +02001781 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1782 return;
1783
Johannes Berg09b85562013-02-06 23:07:41 +01001784 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001785 /* don't enter PS if TX frames are pending */
1786 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301787 mod_timer(&local->dynamic_ps_timer, jiffies +
1788 msecs_to_jiffies(
1789 local->hw.conf.dynamic_ps_timeout));
1790 return;
1791 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001792
1793 /*
1794 * transmission can be stopped by others which leads to
1795 * dynamic_ps_timer expiry. Postpone the ps timer if it
1796 * is not the actual idle state.
1797 */
1798 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1799 for (q = 0; q < local->hw.queues; q++) {
1800 if (local->queue_stop_reasons[q]) {
1801 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1802 flags);
1803 mod_timer(&local->dynamic_ps_timer, jiffies +
1804 msecs_to_jiffies(
1805 local->hw.conf.dynamic_ps_timeout));
1806 return;
1807 }
1808 }
1809 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301810 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301811
Johannes Berg30686bf2015-06-02 21:39:54 +02001812 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301813 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Johannes Berga1598382013-03-26 22:02:42 +01001814 if (drv_tx_frames_pending(local)) {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301815 mod_timer(&local->dynamic_ps_timer, jiffies +
1816 msecs_to_jiffies(
1817 local->hw.conf.dynamic_ps_timeout));
Johannes Berga1598382013-03-26 22:02:42 +01001818 } else {
Johannes Berg076cdcb2015-09-24 16:14:55 +02001819 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301820 /* Flush to get the tx status of nullfunc frame */
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001821 ieee80211_flush_queues(local, sdata, false);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301822 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301823 }
1824
Johannes Berg30686bf2015-06-02 21:39:54 +02001825 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1826 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301827 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1828 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1829 local->hw.conf.flags |= IEEE80211_CONF_PS;
1830 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1831 }
Johannes Berg965beda2009-04-16 13:17:24 +02001832}
1833
Kees Cook34f11cd2017-10-16 16:35:49 -07001834void ieee80211_dynamic_ps_timer(struct timer_list *t)
Johannes Berg965beda2009-04-16 13:17:24 +02001835{
Kees Cook34f11cd2017-10-16 16:35:49 -07001836 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
Johannes Berg965beda2009-04-16 13:17:24 +02001837
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001838 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001839}
1840
Simon Wunderlich164eb022013-02-08 18:16:20 +01001841void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1842{
Geliang Tanga85a7e22016-01-01 23:48:52 +08001843 struct delayed_work *delayed_work = to_delayed_work(work);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001844 struct ieee80211_sub_if_data *sdata =
1845 container_of(delayed_work, struct ieee80211_sub_if_data,
1846 dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001847 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlich164eb022013-02-08 18:16:20 +01001848
Johannes Berg34a37402013-12-18 09:43:33 +01001849 mutex_lock(&sdata->local->mtx);
1850 if (sdata->wdev.cac_started) {
1851 ieee80211_vif_release_channel(sdata);
1852 cfg80211_cac_event(sdata->dev, &chandef,
1853 NL80211_RADAR_CAC_FINISHED,
1854 GFP_KERNEL);
1855 }
1856 mutex_unlock(&sdata->local->mtx);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001857}
1858
Johannes Berg02219b32014-10-07 10:38:50 +03001859static bool
1860__ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1861{
1862 struct ieee80211_local *local = sdata->local;
1863 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
John Linvillecc72f6e2015-01-06 14:39:33 -05001864 bool ret = false;
Johannes Berg02219b32014-10-07 10:38:50 +03001865 int ac;
1866
1867 if (local->hw.queues < IEEE80211_NUM_ACS)
1868 return false;
1869
1870 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1871 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1872 int non_acm_ac;
1873 unsigned long now = jiffies;
1874
1875 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1876 tx_tspec->admitted_time &&
1877 time_after(now, tx_tspec->time_slice_start + HZ)) {
1878 tx_tspec->consumed_tx_time = 0;
1879 tx_tspec->time_slice_start = now;
1880
1881 if (tx_tspec->downgraded)
1882 tx_tspec->action =
1883 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1884 }
1885
1886 switch (tx_tspec->action) {
1887 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1888 /* take the original parameters */
1889 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1890 sdata_err(sdata,
1891 "failed to set TX queue parameters for queue %d\n",
1892 ac);
1893 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1894 tx_tspec->downgraded = false;
1895 ret = true;
1896 break;
1897 case TX_TSPEC_ACTION_DOWNGRADE:
1898 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1899 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1900 ret = true;
1901 break;
1902 }
1903 /* downgrade next lower non-ACM AC */
1904 for (non_acm_ac = ac + 1;
1905 non_acm_ac < IEEE80211_NUM_ACS;
1906 non_acm_ac++)
1907 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1908 break;
Johannes Berg93db1d92016-09-14 09:23:51 +02001909 /* Usually the loop will result in using BK even if it
1910 * requires admission control, but such a configuration
1911 * makes no sense and we have to transmit somehow - the
1912 * AC selection does the same thing.
1913 * If we started out trying to downgrade from BK, then
1914 * the extra condition here might be needed.
Johannes Berg02219b32014-10-07 10:38:50 +03001915 */
Johannes Berg93db1d92016-09-14 09:23:51 +02001916 if (non_acm_ac >= IEEE80211_NUM_ACS)
1917 non_acm_ac = IEEE80211_AC_BK;
Johannes Berg02219b32014-10-07 10:38:50 +03001918 if (drv_conf_tx(local, sdata, ac,
1919 &sdata->tx_conf[non_acm_ac]))
1920 sdata_err(sdata,
1921 "failed to set TX queue parameters for queue %d\n",
1922 ac);
1923 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1924 ret = true;
1925 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1926 tx_tspec->time_slice_start + HZ - now + 1);
1927 break;
1928 case TX_TSPEC_ACTION_NONE:
1929 /* nothing now */
1930 break;
1931 }
1932 }
1933
1934 return ret;
1935}
1936
1937void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1938{
1939 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1940 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1941}
1942
1943static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1944{
1945 struct ieee80211_sub_if_data *sdata;
1946
1947 sdata = container_of(work, struct ieee80211_sub_if_data,
1948 u.mgd.tx_tspec_wk.work);
1949 ieee80211_sta_handle_tspec_ac_params(sdata);
1950}
1951
Johannes Berg60f8b392008-09-08 17:44:22 +02001952/* MLME */
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001953static bool
1954ieee80211_sta_wmm_params(struct ieee80211_local *local,
1955 struct ieee80211_sub_if_data *sdata,
1956 const u8 *wmm_param, size_t wmm_param_len,
1957 const struct ieee80211_mu_edca_param_set *mu_edca)
Jiri Bencf0706e82007-05-05 11:45:53 -07001958{
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001959 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
Johannes Berg4ced3f72010-07-19 16:39:04 +02001960 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001961 size_t left;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001962 int count, mu_edca_count, ac;
Johannes Berg4a3cb702013-02-12 16:43:19 +01001963 const u8 *pos;
1964 u8 uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001965
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001966 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001967 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001968
Johannes Berg32c50572012-03-28 11:04:29 +02001969 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001970 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001971
1972 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001973 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001974
Jiri Bencf0706e82007-05-05 11:45:53 -07001975 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001976 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001977
1978 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001979 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001980
Jiri Bencf0706e82007-05-05 11:45:53 -07001981 count = wmm_param[6] & 0x0f;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001982 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
1983 * if mu_edca was preset before and now it disappeared tell
1984 * the driver about it.
1985 */
1986 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
1987 if (count == ifmgd->wmm_last_param_set &&
1988 mu_edca_count == ifmgd->mu_edca_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001989 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001990 ifmgd->wmm_last_param_set = count;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001991 ifmgd->mu_edca_last_param_set = mu_edca_count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001992
1993 pos = wmm_param + 8;
1994 left = wmm_param_len - 8;
1995
1996 memset(&params, 0, sizeof(params));
1997
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001998 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001999 for (; left >= 4; left -= 4, pos += 4) {
2000 int aci = (pos[0] >> 5) & 0x03;
2001 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02002002 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002003
2004 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02002005 case 1: /* AC_BK */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002006 ac = IEEE80211_AC_BK;
Johannes Berg988c0f72008-04-17 19:21:22 +02002007 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03002008 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02002009 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2010 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03002011 params[ac].mu_edca = !!mu_edca;
2012 if (mu_edca)
2013 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
Jiri Bencf0706e82007-05-05 11:45:53 -07002014 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02002015 case 2: /* AC_VI */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002016 ac = IEEE80211_AC_VI;
Johannes Berg988c0f72008-04-17 19:21:22 +02002017 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03002018 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02002019 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2020 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03002021 params[ac].mu_edca = !!mu_edca;
2022 if (mu_edca)
2023 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
Jiri Bencf0706e82007-05-05 11:45:53 -07002024 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02002025 case 3: /* AC_VO */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002026 ac = IEEE80211_AC_VO;
Johannes Berg988c0f72008-04-17 19:21:22 +02002027 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03002028 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02002029 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2030 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03002031 params[ac].mu_edca = !!mu_edca;
2032 if (mu_edca)
2033 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
Jiri Bencf0706e82007-05-05 11:45:53 -07002034 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02002035 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07002036 default:
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002037 ac = IEEE80211_AC_BE;
Johannes Berg988c0f72008-04-17 19:21:22 +02002038 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03002039 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02002040 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2041 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03002042 params[ac].mu_edca = !!mu_edca;
2043 if (mu_edca)
2044 params[ac].mu_edca_param_rec = mu_edca->ac_be;
Jiri Bencf0706e82007-05-05 11:45:53 -07002045 break;
2046 }
2047
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002048 params[ac].aifs = pos[0] & 0x0f;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02002049
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002050 if (params[ac].aifs < 2) {
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02002051 sdata_info(sdata,
2052 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002053 params[ac].aifs, aci);
2054 params[ac].aifs = 2;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02002055 }
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002056 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2057 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2058 params[ac].txop = get_unaligned_le16(pos + 2);
2059 params[ac].acm = acm;
2060 params[ac].uapsd = uapsd;
Kalle Valoab133152010-01-12 10:42:31 +02002061
Ilan Peer911a2642018-04-03 11:35:22 +03002062 if (params[ac].cw_min == 0 ||
Emmanuel Grumbachc470bdc2018-03-26 16:21:04 +03002063 params[ac].cw_min > params[ac].cw_max) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002064 sdata_info(sdata,
2065 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2066 params[ac].cw_min, params[ac].cw_max, aci);
2067 return false;
2068 }
Haim Dreyfusse552af02018-03-28 13:24:10 +03002069 ieee80211_regulatory_limit_wmm_params(sdata, &params[ac], ac);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002070 }
2071
Brian Norris05aaa5c2019-07-26 15:47:58 -07002072 /* WMM specification requires all 4 ACIs. */
2073 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2074 if (params[ac].cw_min == 0) {
2075 sdata_info(sdata,
2076 "AP has invalid WMM params (missing AC %d), using defaults\n",
2077 ac);
2078 return false;
2079 }
2080 }
2081
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002082 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002083 mlme_dbg(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002084 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2085 ac, params[ac].acm,
2086 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2087 params[ac].txop, params[ac].uapsd,
2088 ifmgd->tx_tspec[ac].downgraded);
2089 sdata->tx_conf[ac] = params[ac];
2090 if (!ifmgd->tx_tspec[ac].downgraded &&
2091 drv_conf_tx(local, sdata, ac, &params[ac]))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002092 sdata_err(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002093 "failed to set TX queue parameters for AC %d\n",
2094 ac);
Jiri Bencf0706e82007-05-05 11:45:53 -07002095 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02002096
2097 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02002098 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02002099 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07002100}
2101
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002102static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2103{
2104 lockdep_assert_held(&sdata->local->mtx);
2105
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002106 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002107 ieee80211_run_deferred_scan(sdata->local);
2108}
2109
2110static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2111{
2112 mutex_lock(&sdata->local->mtx);
2113 __ieee80211_stop_poll(sdata);
2114 mutex_unlock(&sdata->local->mtx);
2115}
2116
Johannes Berg7a5158e2008-10-08 10:59:33 +02002117static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2118 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02002119{
Johannes Bergbda39332008-10-11 01:51:51 +02002120 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302121 struct ieee80211_supported_band *sband;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002122 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002123 bool use_protection;
2124 bool use_short_preamble;
2125 bool use_short_slot;
2126
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302127 sband = ieee80211_get_sband(sdata);
2128 if (!sband)
2129 return changed;
2130
Johannes Berg7a5158e2008-10-08 10:59:33 +02002131 if (erp_valid) {
2132 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2133 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2134 } else {
2135 use_protection = false;
2136 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2137 }
2138
2139 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302140 if (sband->band == NL80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01002141 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02002142
Johannes Berg471b3ef2007-12-28 14:32:58 +01002143 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01002144 bss_conf->use_cts_prot = use_protection;
2145 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02002146 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02002147
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002148 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002149 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002150 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02002151 }
Daniel Draked9430a32007-07-27 15:43:24 +02002152
Johannes Berg7a5158e2008-10-08 10:59:33 +02002153 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02002154 bss_conf->use_short_slot = use_short_slot;
2155 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04002156 }
2157
2158 return changed;
2159}
2160
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002161static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002162 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02002163 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07002164{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002165 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002166 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002167 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002168
Johannes Bergae5eb022008-10-14 16:58:37 +02002169 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002170 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03002171 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002172
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002173 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
Ben Greear59c1ec22013-03-19 14:19:56 -07002174 beacon_loss_count * bss_conf->beacon_int));
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002175
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002176 sdata->u.mgd.associated = cbss;
2177 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002178
Johannes Berge8e4f522017-03-08 11:12:10 +01002179 ieee80211_check_rate_mask(sdata);
2180
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002181 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2182
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01002183 if (sdata->vif.p2p ||
2184 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002185 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01002186
Johannes Berg9caf0362012-11-29 01:25:20 +01002187 rcu_read_lock();
2188 ies = rcu_dereference(cbss->ies);
2189 if (ies) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002190 int ret;
2191
2192 ret = cfg80211_get_p2p_attr(
2193 ies->data, ies->len,
2194 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002195 (u8 *) &bss_conf->p2p_noa_attr,
2196 sizeof(bss_conf->p2p_noa_attr));
Johannes Berg9caf0362012-11-29 01:25:20 +01002197 if (ret >= 2) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002198 sdata->u.mgd.p2p_noa_index =
2199 bss_conf->p2p_noa_attr.index;
Johannes Berg9caf0362012-11-29 01:25:20 +01002200 bss_info_changed |= BSS_CHANGED_P2P_PS;
Johannes Berg9caf0362012-11-29 01:25:20 +01002201 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01002202 }
Johannes Berg9caf0362012-11-29 01:25:20 +01002203 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01002204 }
2205
Johannes Bergb291ba12009-07-10 15:29:03 +02002206 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002207 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002208
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002209 ieee80211_led_assoc(local, 1);
2210
Alexander Bondar989c6502013-05-16 17:34:17 +03002211 if (sdata->u.mgd.have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02002212 /*
2213 * If the AP is buggy we may get here with no DTIM period
2214 * known, so assume it's 1 which is the only safe assumption
2215 * in that case, although if the TIM IE is broken powersave
2216 * probably just won't work at all.
2217 */
2218 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Alexander Bondar817cee72013-05-19 14:23:57 +03002219 bss_conf->beacon_rate = bss->beacon_rate;
Alexander Bondar989c6502013-05-16 17:34:17 +03002220 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
Johannes Berg826262c2012-12-10 16:38:14 +02002221 } else {
Alexander Bondar817cee72013-05-19 14:23:57 +03002222 bss_conf->beacon_rate = NULL;
Johannes Berge5b900d2010-07-29 16:08:55 +02002223 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02002224 }
Johannes Berge5b900d2010-07-29 16:08:55 +02002225
Juuso Oikarinen68542962010-06-09 13:43:26 +03002226 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02002227
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002228 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01002229 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03002230 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002231 bss_info_changed |= BSS_CHANGED_CQM;
2232
Juuso Oikarinen68542962010-06-09 13:43:26 +03002233 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002234 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002235 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002236
Johannes Bergae5eb022008-10-14 16:58:37 +02002237 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03002238
Johannes Berg056508d2009-07-30 21:43:55 +02002239 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002240 ieee80211_recalc_ps(local);
Johannes Berg056508d2009-07-30 21:43:55 +02002241 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02002242
Johannes Berg04ecd252012-09-11 14:34:12 +02002243 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03002244 ieee80211_recalc_ps_vif(sdata);
2245
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002246 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07002247}
2248
Jouni Malinene69e95d2010-03-29 23:29:31 -07002249static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01002250 u16 stype, u16 reason, bool tx,
2251 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03002252{
Johannes Berg46900292009-02-15 12:44:28 +01002253 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002254 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01002255 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002256
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002257 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002258
Johannes Berg37ad3882012-02-24 13:50:54 +01002259 if (WARN_ON_ONCE(tx && !frame_buf))
2260 return;
2261
Johannes Bergb291ba12009-07-10 15:29:03 +02002262 if (WARN_ON(!ifmgd->associated))
2263 return;
2264
David Spinadel79543d82012-06-12 09:59:45 +03002265 ieee80211_stop_poll(sdata);
2266
Johannes Berg77fdaa12009-07-07 03:45:17 +02002267 ifmgd->associated = NULL;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002268 netif_carrier_off(sdata->dev);
2269
Eliad Peller88bc40e2012-07-12 17:35:33 +03002270 /*
2271 * if we want to get out of ps before disassoc (why?) we have
2272 * to do it before sending disassoc, as otherwise the null-packet
2273 * won't be valid.
2274 */
2275 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2276 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2277 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2278 }
2279 local->ps_sdata = NULL;
2280
Eliad Pellerab095872012-07-27 12:33:22 +03002281 /* disable per-vif ps */
2282 ieee80211_recalc_ps_vif(sdata);
2283
Emmanuel Grumbach14f2ae82015-01-22 23:30:19 +02002284 /* make sure ongoing transmission finishes */
2285 synchronize_net();
2286
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002287 /*
2288 * drop any frame before deauth/disassoc, this can be data or
2289 * management frame. Since we are disconnecting, we should not
2290 * insist sending these frames which can take time and delay
2291 * the disconnection and possible the roaming.
2292 */
Eliad Pellerf8239812012-06-27 14:18:22 +03002293 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002294 ieee80211_flush_queues(local, sdata, true);
Eliad Pellerf8239812012-06-27 14:18:22 +03002295
Johannes Berg37ad3882012-02-24 13:50:54 +01002296 /* deauthenticate/disassociate now */
Ilan Peer94ba9272018-02-19 14:48:41 +02002297 if (tx || frame_buf) {
Ilan Peer94ba9272018-02-19 14:48:41 +02002298 /*
2299 * In multi channel scenarios guarantee that the virtual
2300 * interface is granted immediate airtime to transmit the
2301 * deauthentication frame by calling mgd_prepare_tx, if the
2302 * driver requested so.
2303 */
2304 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2305 !ifmgd->have_beacon)
Ilan Peerd4e36e52018-04-20 13:49:25 +03002306 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Ilan Peer94ba9272018-02-19 14:48:41 +02002307
Johannes Berg4b08d1b2019-08-30 14:24:51 +03002308 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid,
2309 ifmgd->bssid, stype, reason,
2310 tx, frame_buf);
Ilan Peer94ba9272018-02-19 14:48:41 +02002311 }
Johannes Berg37ad3882012-02-24 13:50:54 +01002312
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002313 /* flush out frame - make sure the deauth was actually sent */
Johannes Berg37ad3882012-02-24 13:50:54 +01002314 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002315 ieee80211_flush_queues(local, sdata, false);
Johannes Berg37ad3882012-02-24 13:50:54 +01002316
Eliad Peller88a9e312012-06-01 11:14:03 +03002317 /* clear bssid only after building the needed mgmt frames */
Joe Perchesc84a67a2015-03-02 19:54:57 -08002318 eth_zero_addr(ifmgd->bssid);
Eliad Peller88a9e312012-06-01 11:14:03 +03002319
Johannes Berg37ad3882012-02-24 13:50:54 +01002320 /* remove AP and TDLS peers */
Johannes Bergd34ba212013-12-04 22:46:11 +01002321 sta_info_flush(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01002322
2323 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002324 changed |= ieee80211_reset_erp_info(sdata);
2325
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002326 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02002327 changed |= BSS_CHANGED_ASSOC;
2328 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002329
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002330 ifmgd->p2p_noa_index = -1;
2331 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2332 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01002333
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002334 /* on the next assoc, re-program HT/VHT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08002335 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2336 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002337 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2338 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
Sara Sharon23a1f8d2015-12-08 16:04:31 +02002339
2340 /* reset MU-MIMO ownership and group data */
2341 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2342 sizeof(sdata->vif.bss_conf.mu_group.membership));
2343 memset(sdata->vif.bss_conf.mu_group.position, 0,
2344 sizeof(sdata->vif.bss_conf.mu_group.position));
2345 changed |= BSS_CHANGED_MU_GROUPS;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002346 sdata->vif.mu_mimo_owner = false;
Johannes Berg413ad502009-05-08 21:21:06 +02002347
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002348 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05302349
Kalle Valo520eb822008-12-18 23:35:27 +02002350 del_timer_sync(&local->dynamic_ps_timer);
2351 cancel_work_sync(&local->dynamic_ps_enable_work);
2352
Juuso Oikarinen68542962010-06-09 13:43:26 +03002353 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002354 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002355 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002356
Johannes Berg3abead52012-03-02 15:56:59 +01002357 sdata->vif.bss_conf.qos = false;
2358 changed |= BSS_CHANGED_QOS;
2359
Johannes Berg0aaffa92010-05-05 15:28:27 +02002360 /* The BSSID (not really interesting) and HT changed */
2361 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02002362 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02002363
Johannes Berg3abead52012-03-02 15:56:59 +01002364 /* disassociated - set to defaults now */
Johannes Bergcec66282015-10-22 17:46:04 +02002365 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg3abead52012-03-02 15:56:59 +01002366
Johannes Bergb9dcf712010-08-27 12:35:54 +02002367 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2368 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2369 del_timer_sync(&sdata->u.mgd.timer);
2370 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02002371
Johannes Berg826262c2012-12-10 16:38:14 +02002372 sdata->vif.bss_conf.dtim_period = 0;
Alexander Bondar817cee72013-05-19 14:23:57 +03002373 sdata->vif.bss_conf.beacon_rate = NULL;
2374
Alexander Bondar989c6502013-05-16 17:34:17 +03002375 ifmgd->have_beacon = false;
Johannes Berg826262c2012-12-10 16:38:14 +02002376
Johannes Berg028e8da02012-11-26 11:57:41 +01002377 ifmgd->flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002378 mutex_lock(&local->mtx);
Johannes Berg028e8da02012-11-26 11:57:41 +01002379 ieee80211_vif_release_channel(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002380
2381 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002382 ifmgd->csa_waiting_bcn = false;
Johannes Bergf84eaa12015-03-12 08:53:26 +02002383 ifmgd->csa_ignored_same_chan = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002384 if (sdata->csa_block_tx) {
2385 ieee80211_wake_vif_queues(local, sdata,
2386 IEEE80211_QUEUE_STOP_REASON_CSA);
2387 sdata->csa_block_tx = false;
2388 }
Johannes Berg34a37402013-12-18 09:43:33 +01002389 mutex_unlock(&local->mtx);
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002390
Johannes Berg02219b32014-10-07 10:38:50 +03002391 /* existing TX TSPEC sessions no longer exist */
2392 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2393 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2394
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002395 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002396}
Jiri Bencf0706e82007-05-05 11:45:53 -07002397
Kalle Valo3cf335d52009-03-22 21:57:06 +02002398void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2399 struct ieee80211_hdr *hdr)
2400{
2401 /*
2402 * We can postpone the mgd.timer whenever receiving unicast frames
2403 * from AP because we know that the connection is working both ways
2404 * at that time. But multicast frames (and hence also beacons) must
2405 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02002406 * data idle periods for sending the periodic probe request to the
2407 * AP we're connected to.
Kalle Valo3cf335d52009-03-22 21:57:06 +02002408 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002409 if (is_multicast_ether_addr(hdr->addr1))
2410 return;
2411
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04002412 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d52009-03-22 21:57:06 +02002413}
Jiri Bencf0706e82007-05-05 11:45:53 -07002414
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002415static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2416{
2417 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002418 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002419
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002420 mutex_lock(&local->mtx);
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002421 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2422 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002423
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002424 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002425
2426 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002427 ieee80211_recalc_ps(local);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002428 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002429
Johannes Berg30686bf2015-06-02 21:39:54 +02002430 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002431 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002432
2433 /*
2434 * We've received a probe response, but are not sure whether
2435 * we have or will be receiving any beacons or data, so let's
2436 * schedule the timers again, just in case.
2437 */
2438 ieee80211_sta_reset_beacon_monitor(sdata);
2439
2440 mod_timer(&ifmgd->conn_mon_timer,
2441 round_jiffies_up(jiffies +
2442 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002443out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002444 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002445}
2446
Johannes Berg02219b32014-10-07 10:38:50 +03002447static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2448 struct ieee80211_hdr *hdr,
2449 u16 tx_time)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002450{
Johannes Berg02219b32014-10-07 10:38:50 +03002451 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Sara Sharona1f2ba04c2018-02-19 14:48:40 +02002452 u16 tid = ieee80211_get_tid(hdr);
Johannes Berg02219b32014-10-07 10:38:50 +03002453 int ac = ieee80211_ac_from_tid(tid);
2454 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2455 unsigned long now = jiffies;
2456
2457 if (likely(!tx_tspec->admitted_time))
2458 return;
2459
2460 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2461 tx_tspec->consumed_tx_time = 0;
2462 tx_tspec->time_slice_start = now;
2463
2464 if (tx_tspec->downgraded) {
2465 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2466 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2467 }
2468 }
2469
2470 if (tx_tspec->downgraded)
2471 return;
2472
2473 tx_tspec->consumed_tx_time += tx_time;
2474
2475 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2476 tx_tspec->downgraded = true;
2477 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2478 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2479 }
2480}
2481
2482void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2483 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2484{
2485 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2486
Felix Fietkau75706d02010-12-02 21:01:07 +01002487 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002488 return;
2489
Thomas Pedersen30b2f0b2020-01-13 21:59:40 -08002490 if (ieee80211_is_any_nullfunc(hdr->frame_control) &&
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002491 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002492 if (ack)
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002493 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002494 else
2495 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002496 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002497 return;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002498 }
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002499
2500 if (ack)
2501 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002502}
2503
Johannes Berg45ad6832018-05-28 15:47:39 +02002504static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2505 const u8 *src, const u8 *dst,
2506 const u8 *ssid, size_t ssid_len,
2507 struct ieee80211_channel *channel)
2508{
2509 struct sk_buff *skb;
2510
2511 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2512 ssid, ssid_len, NULL, 0,
2513 IEEE80211_PROBE_FLAG_DIRECTED);
2514 if (skb)
2515 ieee80211_tx_skb(sdata, skb);
2516}
2517
Maxim Levitskya43abf22009-07-31 18:54:12 +03002518static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2519{
2520 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2521 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002522 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08002523 u8 unicast_limit = max(1, max_probe_tries - 3);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002524 struct sta_info *sta;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002525
2526 /*
2527 * Try sending broadcast probe requests for the last three
2528 * probe requests after the first ones failed since some
2529 * buggy APs only support broadcast probe requests.
2530 */
2531 if (ifmgd->probe_send_count >= unicast_limit)
2532 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002533
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002534 /*
2535 * When the hardware reports an accurate Tx ACK status, it's
2536 * better to send a nullfunc frame instead of a probe request,
2537 * as it will kick us off the AP quickly if we aren't associated
2538 * anymore. The timeout will be reset if the frame is ACKed by
2539 * the AP.
2540 */
Soumik Das992e68b2012-05-20 15:31:13 +05302541 ifmgd->probe_send_count++;
2542
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002543 if (dst) {
2544 mutex_lock(&sdata->local->sta_mtx);
2545 sta = sta_info_get(sdata, dst);
2546 if (!WARN_ON(!sta))
2547 ieee80211_check_fast_rx(sta);
2548 mutex_unlock(&sdata->local->sta_mtx);
2549 }
2550
Johannes Berg30686bf2015-06-02 21:39:54 +02002551 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002552 ifmgd->nullfunc_failed = false;
Shay Barf39b07f2019-07-03 16:18:48 +03002553 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
2554 ifmgd->probe_send_count--;
2555 else
2556 ieee80211_send_nullfunc(sdata->local, sdata, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002557 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002558 int ssid_len;
2559
Johannes Berg9caf0362012-11-29 01:25:20 +01002560 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002561 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002562 if (WARN_ON_ONCE(ssid == NULL))
2563 ssid_len = 0;
2564 else
2565 ssid_len = ssid[1];
2566
Johannes Berg45ad6832018-05-28 15:47:39 +02002567 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2568 ssid + 2, ssid_len,
2569 ifmgd->associated->channel);
Johannes Berg9caf0362012-11-29 01:25:20 +01002570 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002571 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03002572
Ben Greear180205b2011-02-04 15:30:24 -08002573 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002574 run_again(sdata, ifmgd->probe_timeout);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002575}
2576
Johannes Bergb291ba12009-07-10 15:29:03 +02002577static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2578 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02002579{
Kalle Valo04de8382009-03-22 21:57:35 +02002580 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002581 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02002582
Johannes Berg9607e6b662009-12-23 13:15:31 +01002583 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02002584 return;
2585
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002586 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002587
2588 if (!ifmgd->associated)
2589 goto out;
2590
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002591 mutex_lock(&sdata->local->mtx);
2592
2593 if (sdata->local->tmp_channel || sdata->local->scanning) {
2594 mutex_unlock(&sdata->local->mtx);
2595 goto out;
2596 }
2597
Ben Greeara13fbe52013-03-25 11:19:35 -07002598 if (beacon) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002599 mlme_dbg_ratelimited(sdata,
Ben Greear59c1ec22013-03-19 14:19:56 -07002600 "detected beacon loss from AP (missed %d beacons) - probing\n",
2601 beacon_loss_count);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002602
Johannes Berg98f03342014-11-26 12:42:02 +01002603 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
Ben Greeara13fbe52013-03-25 11:19:35 -07002604 }
Kalle Valo04de8382009-03-22 21:57:35 +02002605
Johannes Bergb291ba12009-07-10 15:29:03 +02002606 /*
2607 * The driver/our work has already reported this event or the
2608 * connection monitoring has kicked in and we have already sent
2609 * a probe request. Or maybe the AP died and the driver keeps
2610 * reporting until we disassociate...
2611 *
2612 * In either case we have to ignore the current call to this
2613 * function (except for setting the correct probe reason bit)
2614 * because otherwise we would reset the timer every time and
2615 * never check whether we received a probe response!
2616 */
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002617 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Johannes Bergb291ba12009-07-10 15:29:03 +02002618 already = true;
2619
Eliad Peller12b5f342013-11-18 19:06:46 +02002620 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2621
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002622 mutex_unlock(&sdata->local->mtx);
2623
Johannes Bergb291ba12009-07-10 15:29:03 +02002624 if (already)
2625 goto out;
2626
Johannes Berg4e751842009-06-10 15:16:52 +02002627 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002628 ieee80211_recalc_ps(sdata->local);
Johannes Berg4e751842009-06-10 15:16:52 +02002629 mutex_unlock(&sdata->local->iflist_mtx);
2630
Maxim Levitskya43abf22009-07-31 18:54:12 +03002631 ifmgd->probe_send_count = 0;
2632 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002633 out:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002634 sdata_unlock(sdata);
Kalle Valo04de8382009-03-22 21:57:35 +02002635}
2636
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002637struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2638 struct ieee80211_vif *vif)
2639{
2640 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2641 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002642 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002643 struct sk_buff *skb;
2644 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002645 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002646
2647 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2648 return NULL;
2649
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002650 sdata_assert_lock(sdata);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002651
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002652 if (ifmgd->associated)
2653 cbss = ifmgd->associated;
2654 else if (ifmgd->auth_data)
2655 cbss = ifmgd->auth_data->bss;
2656 else if (ifmgd->assoc_data)
2657 cbss = ifmgd->assoc_data->bss;
2658 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002659 return NULL;
2660
Johannes Berg9caf0362012-11-29 01:25:20 +01002661 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002662 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Will Deacon41525612019-10-04 10:51:31 +01002663 if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
2664 "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002665 ssid_len = 0;
2666 else
2667 ssid_len = ssid[1];
2668
Johannes Berga344d672014-06-12 22:24:31 +02002669 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02002670 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02002671 ssid + 2, ssid_len,
Johannes Berg00387f32018-05-28 15:47:38 +02002672 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
Johannes Berg9caf0362012-11-29 01:25:20 +01002673 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002674
2675 return skb;
2676}
2677EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2678
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002679static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2680 const u8 *buf, size_t len, bool tx,
2681 u16 reason)
2682{
2683 struct ieee80211_event event = {
2684 .type = MLME_EVENT,
2685 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2686 .u.mlme.reason = reason,
2687 };
2688
2689 if (tx)
2690 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2691 else
2692 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2693
2694 drv_event_callback(sdata->local, sdata, &event);
2695}
2696
Johannes Bergeef9e542013-01-29 13:09:34 +01002697static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002698{
Michal Kazior59af6922014-04-09 15:10:59 +02002699 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002700 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002701 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002702 bool tx;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002703
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002704 sdata_lock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002705 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002706 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002707 return;
2708 }
2709
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002710 tx = !sdata->csa_block_tx;
2711
David Spinadel20eb7ea2016-05-03 16:05:02 +03002712 /* AP is probably out of range (or not reachable for another reason) so
2713 * remove the bss struct for that AP.
2714 */
2715 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2716
Johannes Berg37ad3882012-02-24 13:50:54 +01002717 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2718 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002719 tx, frame_buf);
Michal Kazior59af6922014-04-09 15:10:59 +02002720 mutex_lock(&local->mtx);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002721 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002722 ifmgd->csa_waiting_bcn = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002723 if (sdata->csa_block_tx) {
2724 ieee80211_wake_vif_queues(local, sdata,
2725 IEEE80211_QUEUE_STOP_REASON_CSA);
2726 sdata->csa_block_tx = false;
2727 }
Michal Kazior59af6922014-04-09 15:10:59 +02002728 mutex_unlock(&local->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002729
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002730 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002731 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2732
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002733 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002734}
2735
Johannes Bergcc74c0c2012-08-01 16:49:34 +02002736static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02002737{
2738 struct ieee80211_sub_if_data *sdata =
2739 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002740 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002741 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Paul Stewarta85e1d52011-12-09 11:01:49 -08002742
Johannes Berg976bd9e2015-10-16 17:18:11 +02002743 if (ifmgd->associated)
2744 ifmgd->beacon_loss_count++;
Johannes Bergb291ba12009-07-10 15:29:03 +02002745
Johannes Berg682bd382013-01-29 13:13:50 +01002746 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02002747 sdata_info(sdata, "Connection to AP %pM lost\n",
2748 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01002749 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02002750 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002751 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02002752 }
2753}
2754
2755static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2756{
2757 struct ieee80211_sub_if_data *sdata =
2758 container_of(work, struct ieee80211_sub_if_data,
2759 u.mgd.csa_connection_drop_work);
2760
Johannes Bergeef9e542013-01-29 13:09:34 +01002761 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002762}
2763
Kalle Valo04de8382009-03-22 21:57:35 +02002764void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2765{
2766 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002767 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02002768
Johannes Bergb5878a22010-04-07 16:48:40 +02002769 trace_api_beacon_loss(sdata);
2770
Johannes Berg682bd382013-01-29 13:13:50 +01002771 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002772 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002773}
2774EXPORT_SYMBOL(ieee80211_beacon_loss);
2775
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002776void ieee80211_connection_loss(struct ieee80211_vif *vif)
2777{
2778 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2779 struct ieee80211_hw *hw = &sdata->local->hw;
2780
Johannes Bergb5878a22010-04-07 16:48:40 +02002781 trace_api_connection_loss(sdata);
2782
Johannes Berg682bd382013-01-29 13:13:50 +01002783 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002784 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2785}
2786EXPORT_SYMBOL(ieee80211_connection_loss);
2787
2788
Johannes Berg66e67e42012-01-20 13:55:27 +01002789static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2790 bool assoc)
2791{
2792 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2793
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002794 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002795
Johannes Berg66e67e42012-01-20 13:55:27 +01002796 if (!assoc) {
Emmanuel Grumbachc1e140b2015-01-19 16:53:06 +02002797 /*
2798 * we are not authenticated yet, the only timer that could be
2799 * running is the timeout for the authentication response which
2800 * which is not relevant anymore.
2801 */
2802 del_timer_sync(&sdata->u.mgd.timer);
Johannes Berg66e67e42012-01-20 13:55:27 +01002803 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2804
Joe Perchesc84a67a2015-03-02 19:54:57 -08002805 eth_zero_addr(sdata->u.mgd.bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002806 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002807 sdata->u.mgd.flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002808 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002809 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002810 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01002811 }
2812
Johannes Berg5b112d32013-02-01 01:49:58 +01002813 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002814 kfree(auth_data);
2815 sdata->u.mgd.auth_data = NULL;
2816}
2817
Johannes Bergc9c99f82015-06-01 14:10:09 +02002818static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
Johannes Berge6f462d2016-12-08 17:22:09 +01002819 bool assoc, bool abandon)
Johannes Bergc9c99f82015-06-01 14:10:09 +02002820{
2821 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2822
2823 sdata_assert_lock(sdata);
2824
2825 if (!assoc) {
2826 /*
2827 * we are not associated yet, the only timer that could be
2828 * running is the timeout for the association response which
2829 * which is not relevant anymore.
2830 */
2831 del_timer_sync(&sdata->u.mgd.timer);
2832 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2833
2834 eth_zero_addr(sdata->u.mgd.bssid);
2835 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2836 sdata->u.mgd.flags = 0;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002837 sdata->vif.mu_mimo_owner = false;
2838
Johannes Bergc9c99f82015-06-01 14:10:09 +02002839 mutex_lock(&sdata->local->mtx);
2840 ieee80211_vif_release_channel(sdata);
2841 mutex_unlock(&sdata->local->mtx);
Johannes Berge6f462d2016-12-08 17:22:09 +01002842
2843 if (abandon)
2844 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
Johannes Bergc9c99f82015-06-01 14:10:09 +02002845 }
2846
2847 kfree(assoc_data);
2848 sdata->u.mgd.assoc_data = NULL;
2849}
2850
Johannes Berg66e67e42012-01-20 13:55:27 +01002851static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2852 struct ieee80211_mgmt *mgmt, size_t len)
2853{
Johannes Berg1672c0e32013-01-29 15:02:27 +01002854 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01002855 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2856 u8 *pos;
2857 struct ieee802_11_elems elems;
Johannes Berg1672c0e32013-01-29 15:02:27 +01002858 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002859
2860 pos = mgmt->u.auth.variable;
Sara Sharon4abb52a2019-01-16 12:14:41 +02002861 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
2862 mgmt->bssid, auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002863 if (!elems.challenge)
2864 return;
2865 auth_data->expected_transaction = 4;
Ilan Peerd4e36e52018-04-20 13:49:25 +03002866 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg30686bf2015-06-02 21:39:54 +02002867 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +01002868 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2869 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03002870 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01002871 elems.challenge - 2, elems.challenge_len + 2,
2872 auth_data->bss->bssid, auth_data->bss->bssid,
2873 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002874 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002875}
2876
Jouni Malinenfc107a92018-10-11 00:21:19 +03002877static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2878 const u8 *bssid)
2879{
Jouni Malinenefb543e2018-10-11 00:21:21 +03002880 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002881 struct sta_info *sta;
Wei Yongjun33483a62018-10-16 02:35:30 +00002882 bool result = true;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002883
Jouni Malinenefb543e2018-10-11 00:21:21 +03002884 sdata_info(sdata, "authenticated\n");
2885 ifmgd->auth_data->done = true;
2886 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2887 ifmgd->auth_data->timeout_started = true;
2888 run_again(sdata, ifmgd->auth_data->timeout);
2889
Jouni Malinenfc107a92018-10-11 00:21:19 +03002890 /* move station state to auth */
2891 mutex_lock(&sdata->local->sta_mtx);
2892 sta = sta_info_get(sdata, bssid);
2893 if (!sta) {
2894 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
Wei Yongjun33483a62018-10-16 02:35:30 +00002895 result = false;
2896 goto out;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002897 }
2898 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2899 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Wei Yongjun33483a62018-10-16 02:35:30 +00002900 result = false;
2901 goto out;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002902 }
Jouni Malinenfc107a92018-10-11 00:21:19 +03002903
Wei Yongjun33483a62018-10-16 02:35:30 +00002904out:
2905 mutex_unlock(&sdata->local->sta_mtx);
2906 return result;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002907}
2908
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002909static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2910 struct ieee80211_mgmt *mgmt, size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002911{
2912 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2913 u8 bssid[ETH_ALEN];
2914 u16 auth_alg, auth_transaction, status_code;
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002915 struct ieee80211_event event = {
2916 .type = MLME_EVENT,
2917 .u.mlme.data = AUTH_EVENT,
2918 };
Johannes Berg66e67e42012-01-20 13:55:27 +01002919
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002920 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002921
2922 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002923 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002924
2925 if (!ifmgd->auth_data || ifmgd->auth_data->done)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002926 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002927
2928 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2929
Joe Perchesb203ca32012-05-08 18:56:52 +00002930 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002931 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002932
2933 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2934 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2935 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2936
2937 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinenefb543e2018-10-11 00:21:21 +03002938 (auth_alg != WLAN_AUTH_SAE &&
2939 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2940 (auth_alg == WLAN_AUTH_SAE &&
2941 (auth_transaction < ifmgd->auth_data->expected_transaction ||
2942 auth_transaction > 2))) {
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002943 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2944 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2945 auth_transaction,
2946 ifmgd->auth_data->expected_transaction);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002947 return;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002948 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002949
2950 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002951 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2952 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002953 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002954 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002955 event.u.mlme.status = MLME_DENIED;
2956 event.u.mlme.reason = status_code;
2957 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002958 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002959 }
2960
2961 switch (ifmgd->auth_data->algorithm) {
2962 case WLAN_AUTH_OPEN:
2963 case WLAN_AUTH_LEAP:
2964 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002965 case WLAN_AUTH_SAE:
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03002966 case WLAN_AUTH_FILS_SK:
2967 case WLAN_AUTH_FILS_SK_PFS:
2968 case WLAN_AUTH_FILS_PK:
Johannes Berg66e67e42012-01-20 13:55:27 +01002969 break;
2970 case WLAN_AUTH_SHARED_KEY:
2971 if (ifmgd->auth_data->expected_transaction != 4) {
2972 ieee80211_auth_challenge(sdata, mgmt, len);
2973 /* need another frame */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002974 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002975 }
2976 break;
2977 default:
2978 WARN_ONCE(1, "invalid auth alg %d",
2979 ifmgd->auth_data->algorithm);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002980 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002981 }
2982
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002983 event.u.mlme.status = MLME_SUCCESS;
2984 drv_event_callback(sdata->local, sdata, &event);
Jouni Malinenefb543e2018-10-11 00:21:21 +03002985 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
2986 (auth_transaction == 2 &&
2987 ifmgd->auth_data->expected_transaction == 2)) {
2988 if (!ieee80211_mark_sta_auth(sdata, bssid))
2989 goto out_err;
2990 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2991 auth_transaction == 2) {
2992 sdata_info(sdata, "SAE peer confirmed\n");
2993 ifmgd->auth_data->peer_confirmed = true;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002994 }
2995
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002996 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002997 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002998 out_err:
2999 mutex_unlock(&sdata->local->sta_mtx);
3000 /* ignore frame -- wait for timeout */
Johannes Berg66e67e42012-01-20 13:55:27 +01003001}
3002
Calvin Owensdfa1ad22014-02-11 12:36:24 -06003003#define case_WLAN(type) \
3004 case WLAN_REASON_##type: return #type
3005
Yu Wang79c92ca2019-05-10 17:04:52 +08003006const char *ieee80211_get_reason_code_string(u16 reason_code)
Calvin Owensdfa1ad22014-02-11 12:36:24 -06003007{
3008 switch (reason_code) {
3009 case_WLAN(UNSPECIFIED);
3010 case_WLAN(PREV_AUTH_NOT_VALID);
3011 case_WLAN(DEAUTH_LEAVING);
3012 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3013 case_WLAN(DISASSOC_AP_BUSY);
3014 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3015 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3016 case_WLAN(DISASSOC_STA_HAS_LEFT);
3017 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3018 case_WLAN(DISASSOC_BAD_POWER);
3019 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3020 case_WLAN(INVALID_IE);
3021 case_WLAN(MIC_FAILURE);
3022 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3023 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3024 case_WLAN(IE_DIFFERENT);
3025 case_WLAN(INVALID_GROUP_CIPHER);
3026 case_WLAN(INVALID_PAIRWISE_CIPHER);
3027 case_WLAN(INVALID_AKMP);
3028 case_WLAN(UNSUPP_RSN_VERSION);
3029 case_WLAN(INVALID_RSN_IE_CAP);
3030 case_WLAN(IEEE8021X_FAILED);
3031 case_WLAN(CIPHER_SUITE_REJECTED);
3032 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3033 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3034 case_WLAN(DISASSOC_LOW_ACK);
3035 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3036 case_WLAN(QSTA_LEAVE_QBSS);
3037 case_WLAN(QSTA_NOT_USE);
3038 case_WLAN(QSTA_REQUIRE_SETUP);
3039 case_WLAN(QSTA_TIMEOUT);
3040 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3041 case_WLAN(MESH_PEER_CANCELED);
3042 case_WLAN(MESH_MAX_PEERS);
3043 case_WLAN(MESH_CONFIG);
3044 case_WLAN(MESH_CLOSE);
3045 case_WLAN(MESH_MAX_RETRIES);
3046 case_WLAN(MESH_CONFIRM_TIMEOUT);
3047 case_WLAN(MESH_INVALID_GTK);
3048 case_WLAN(MESH_INCONSISTENT_PARAM);
3049 case_WLAN(MESH_INVALID_SECURITY);
3050 case_WLAN(MESH_PATH_ERROR);
3051 case_WLAN(MESH_PATH_NOFORWARD);
3052 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3053 case_WLAN(MAC_EXISTS_IN_MBSS);
3054 case_WLAN(MESH_CHAN_REGULATORY);
3055 case_WLAN(MESH_CHAN);
3056 default: return "<unknown>";
3057 }
3058}
Johannes Berg66e67e42012-01-20 13:55:27 +01003059
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003060static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3061 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003062{
Johannes Berg46900292009-02-15 12:44:28 +01003063 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergc9c99f82015-06-01 14:10:09 +02003064 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07003065
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003066 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003067
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003068 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003069 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003070
Yu Wang79c92ca2019-05-10 17:04:52 +08003071 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3072 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3073 return;
3074 }
3075
Johannes Bergc9c99f82015-06-01 14:10:09 +02003076 if (ifmgd->associated &&
3077 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3078 const u8 *bssid = ifmgd->associated->bssid;
3079
3080 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3081 bssid, reason_code,
3082 ieee80211_get_reason_code_string(reason_code));
3083
3084 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3085
3086 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3087 reason_code);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003088 return;
Johannes Bergc9c99f82015-06-01 14:10:09 +02003089 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003090
Johannes Bergc9c99f82015-06-01 14:10:09 +02003091 if (ifmgd->assoc_data &&
3092 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3093 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07003094
Johannes Bergc9c99f82015-06-01 14:10:09 +02003095 sdata_info(sdata,
3096 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3097 bssid, reason_code,
3098 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07003099
Johannes Berge6f462d2016-12-08 17:22:09 +01003100 ieee80211_destroy_assoc_data(sdata, false, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07003101
Johannes Bergc9c99f82015-06-01 14:10:09 +02003102 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3103 return;
3104 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003105}
3106
3107
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003108static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3109 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003110{
Johannes Berg46900292009-02-15 12:44:28 +01003111 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07003112 u16 reason_code;
3113
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003114 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003115
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003116 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003117 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003118
Johannes Berg66e67e42012-01-20 13:55:27 +01003119 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00003120 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003121 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003122
3123 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3124
Yu Wang79c92ca2019-05-10 17:04:52 +08003125 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3126 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3127 return;
3128 }
3129
Arkadiusz Miskiewicz68506e92017-02-15 14:21:27 +01003130 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3131 mgmt->sa, reason_code,
3132 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07003133
Johannes Berg37ad3882012-02-24 13:50:54 +01003134 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3135
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003136 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07003137}
3138
Christian Lamparterc74d0842011-10-15 00:14:49 +02003139static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3140 u8 *supp_rates, unsigned int supp_rates_len,
3141 u32 *rates, u32 *basic_rates,
3142 bool *have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003143 int *min_rate, int *min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03003144 int shift)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003145{
3146 int i, j;
3147
3148 for (i = 0; i < supp_rates_len; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003149 int rate = supp_rates[i] & 0x7f;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003150 bool is_basic = !!(supp_rates[i] & 0x80);
3151
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003152 if ((rate * 5 * (1 << shift)) > 110)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003153 *have_higher_than_11mbit = true;
3154
3155 /*
Johannes Berga6289d32017-03-06 22:59:04 +01003156 * Skip HT and VHT BSS membership selectors since they're not
3157 * rates.
Christian Lamparterc74d0842011-10-15 00:14:49 +02003158 *
Johannes Berga6289d32017-03-06 22:59:04 +01003159 * Note: Even though the membership selector and the basic
Christian Lamparterc74d0842011-10-15 00:14:49 +02003160 * rate flag share the same bit, they are not exactly
3161 * the same.
3162 */
Johannes Berga6289d32017-03-06 22:59:04 +01003163 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3164 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
Christian Lamparterc74d0842011-10-15 00:14:49 +02003165 continue;
3166
3167 for (j = 0; j < sband->n_bitrates; j++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003168 struct ieee80211_rate *br;
3169 int brate;
3170
3171 br = &sband->bitrates[j];
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003172
3173 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3174 if (brate == rate) {
Christian Lamparterc74d0842011-10-15 00:14:49 +02003175 *rates |= BIT(j);
3176 if (is_basic)
3177 *basic_rates |= BIT(j);
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003178 if ((rate * 5) < *min_rate) {
3179 *min_rate = rate * 5;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003180 *min_rate_index = j;
3181 }
3182 break;
3183 }
3184 }
3185 }
3186}
Jiri Bencf0706e82007-05-05 11:45:53 -07003187
Emmanuel Grumbach55ebd6e2018-12-15 11:03:04 +02003188static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3189 const struct ieee802_11_elems *elems)
3190{
3191 if (elems->ext_capab_len < 10)
3192 return false;
3193
3194 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3195 return false;
3196
3197 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3198 IEEE80211_HE_MAC_CAP0_TWT_RES;
3199}
3200
John Crispinc9d32452019-05-28 13:49:47 +02003201static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3202 struct sta_info *sta,
3203 struct ieee802_11_elems *elems)
3204{
3205 bool twt = ieee80211_twt_req_supported(sta, elems);
3206
3207 if (sdata->vif.bss_conf.twt_requester != twt) {
3208 sdata->vif.bss_conf.twt_requester = twt;
3209 return BSS_CHANGED_TWT;
3210 }
3211 return 0;
3212}
3213
Johannes Berg66e67e42012-01-20 13:55:27 +01003214static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3215 struct cfg80211_bss *cbss,
Johannes Bergf61d7882019-10-28 12:52:42 +01003216 struct ieee80211_mgmt *mgmt, size_t len,
3217 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07003218{
Johannes Berg46900292009-02-15 12:44:28 +01003219 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01003220 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01003221 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003222 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003223 u16 capab_info, aid;
Johannes Bergbda39332008-10-11 01:51:51 +02003224 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg35d865a2013-05-28 10:54:03 +02003225 const struct cfg80211_bss_ies *bss_ies = NULL;
3226 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
Johannes Bergae5eb022008-10-14 16:58:37 +02003227 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003228 int err;
Johannes Berg35d865a2013-05-28 10:54:03 +02003229 bool ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003230
Johannes Bergaf6b6372009-12-23 13:15:35 +01003231 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07003232
Jiri Bencf0706e82007-05-05 11:45:53 -07003233 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003234 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07003235
Johannes Bergc7c477b2017-12-01 13:50:51 +02003236 /*
3237 * The 5 MSB of the AID field are reserved
3238 * (802.11-2016 9.4.1.8 AID field)
3239 */
3240 aid &= 0x7ff;
Johannes Berg1dd84aa2007-10-10 12:03:41 +02003241
Johannes Berg05cb9102011-10-28 11:59:47 +02003242 ifmgd->broken_ap = false;
3243
3244 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003245 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3246 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02003247 aid = 0;
3248 ifmgd->broken_ap = true;
3249 }
3250
Johannes Bergf61d7882019-10-28 12:52:42 +01003251 if (!elems->supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003252 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01003253 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07003254 }
3255
Johannes Berg46900292009-02-15 12:44:28 +01003256 ifmgd->aid = aid;
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02003257 ifmgd->tdls_chan_switch_prohibited =
Johannes Bergf61d7882019-10-28 12:52:42 +01003258 elems->ext_capab && elems->ext_capab_len >= 5 &&
3259 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
Jiri Bencf0706e82007-05-05 11:45:53 -07003260
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003261 /*
Johannes Berg35d865a2013-05-28 10:54:03 +02003262 * Some APs are erroneously not including some information in their
3263 * (re)association response frames. Try to recover by using the data
3264 * from the beacon or probe response. This seems to afflict mobile
3265 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3266 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3267 */
Johannes Bergf61d7882019-10-28 12:52:42 +01003268 if ((assoc_data->wmm && !elems->wmm_param) ||
Johannes Berg35d865a2013-05-28 10:54:03 +02003269 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003270 (!elems->ht_cap_elem || !elems->ht_operation)) ||
Johannes Berg35d865a2013-05-28 10:54:03 +02003271 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003272 (!elems->vht_cap_elem || !elems->vht_operation))) {
Johannes Berg35d865a2013-05-28 10:54:03 +02003273 const struct cfg80211_bss_ies *ies;
3274 struct ieee802_11_elems bss_elems;
3275
3276 rcu_read_lock();
3277 ies = rcu_dereference(cbss->ies);
3278 if (ies)
3279 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3280 GFP_ATOMIC);
3281 rcu_read_unlock();
3282 if (!bss_ies)
3283 return false;
3284
3285 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003286 false, &bss_elems,
3287 mgmt->bssid,
3288 assoc_data->bss->bssid);
Johannes Berg35d865a2013-05-28 10:54:03 +02003289 if (assoc_data->wmm &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003290 !elems->wmm_param && bss_elems.wmm_param) {
3291 elems->wmm_param = bss_elems.wmm_param;
Johannes Berg35d865a2013-05-28 10:54:03 +02003292 sdata_info(sdata,
3293 "AP bug: WMM param missing from AssocResp\n");
3294 }
3295
3296 /*
3297 * Also check if we requested HT/VHT, otherwise the AP doesn't
3298 * have to include the IEs in the (re)association response.
3299 */
Johannes Bergf61d7882019-10-28 12:52:42 +01003300 if (!elems->ht_cap_elem && bss_elems.ht_cap_elem &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003301 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003302 elems->ht_cap_elem = bss_elems.ht_cap_elem;
Johannes Berg35d865a2013-05-28 10:54:03 +02003303 sdata_info(sdata,
3304 "AP bug: HT capability missing from AssocResp\n");
3305 }
Johannes Bergf61d7882019-10-28 12:52:42 +01003306 if (!elems->ht_operation && bss_elems.ht_operation &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003307 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003308 elems->ht_operation = bss_elems.ht_operation;
Johannes Berg35d865a2013-05-28 10:54:03 +02003309 sdata_info(sdata,
3310 "AP bug: HT operation missing from AssocResp\n");
3311 }
Johannes Bergf61d7882019-10-28 12:52:42 +01003312 if (!elems->vht_cap_elem && bss_elems.vht_cap_elem &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003313 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003314 elems->vht_cap_elem = bss_elems.vht_cap_elem;
Johannes Berg35d865a2013-05-28 10:54:03 +02003315 sdata_info(sdata,
3316 "AP bug: VHT capa missing from AssocResp\n");
3317 }
Johannes Bergf61d7882019-10-28 12:52:42 +01003318 if (!elems->vht_operation && bss_elems.vht_operation &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003319 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003320 elems->vht_operation = bss_elems.vht_operation;
Johannes Berg35d865a2013-05-28 10:54:03 +02003321 sdata_info(sdata,
3322 "AP bug: VHT operation missing from AssocResp\n");
3323 }
3324 }
3325
3326 /*
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003327 * We previously checked these in the beacon/probe response, so
3328 * they should be present here. This is just a safety net.
3329 */
3330 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003331 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003332 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003333 "HT AP is missing WMM params or HT capability/operation\n");
3334 ret = false;
3335 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003336 }
3337
3338 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003339 (!elems->vht_cap_elem || !elems->vht_operation)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003340 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003341 "VHT AP is missing VHT capability/operation\n");
3342 ret = false;
3343 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003344 }
3345
Guy Eilam2a33bee2011-08-17 15:18:15 +03003346 mutex_lock(&sdata->local->sta_mtx);
3347 /*
3348 * station info was already allocated and inserted before
3349 * the association and should be available to us
3350 */
Johannes Berg7852e362012-01-20 13:55:24 +01003351 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003352 if (WARN_ON(!sta)) {
3353 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003354 ret = false;
3355 goto out;
Jiri Bencf0706e82007-05-05 11:45:53 -07003356 }
3357
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05303358 sband = ieee80211_get_sband(sdata);
3359 if (!sband) {
3360 mutex_unlock(&sdata->local->sta_mtx);
3361 ret = false;
3362 goto out;
3363 }
Johannes Berg8318d782008-01-24 19:38:38 +01003364
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003365 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003366 (!elems->he_cap || !elems->he_operation)) {
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003367 mutex_unlock(&sdata->local->sta_mtx);
3368 sdata_info(sdata,
3369 "HE AP is missing HE capability/operation\n");
3370 ret = false;
3371 goto out;
3372 }
3373
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003374 /* Set up internal HT/VHT capabilities */
Johannes Bergf61d7882019-10-28 12:52:42 +01003375 if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08003376 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergf61d7882019-10-28 12:52:42 +01003377 elems->ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02003378
Johannes Bergf61d7882019-10-28 12:52:42 +01003379 if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Mahesh Palivela818255e2012-10-10 11:33:04 +00003380 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Bergf61d7882019-10-28 12:52:42 +01003381 elems->vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00003382
Johannes Bergf61d7882019-10-28 12:52:42 +01003383 if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3384 elems->he_cap) {
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003385 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
Johannes Bergf61d7882019-10-28 12:52:42 +01003386 elems->he_cap,
3387 elems->he_cap_len,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003388 sta);
3389
3390 bss_conf->he_support = sta->sta.he_cap.has_he;
Johannes Bergf61d7882019-10-28 12:52:42 +01003391 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003392 } else {
3393 bss_conf->he_support = false;
Emmanuel Grumbach55ebd6e2018-12-15 11:03:04 +02003394 bss_conf->twt_requester = false;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003395 }
3396
3397 if (bss_conf->he_support) {
John Crispindd56e902019-12-17 15:19:19 +01003398 bss_conf->he_bss_color.color =
Johannes Bergf61d7882019-10-28 12:52:42 +01003399 le32_get_bits(elems->he_operation->he_oper_params,
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003400 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
John Crispindd56e902019-12-17 15:19:19 +01003401 bss_conf->he_bss_color.partial =
3402 le32_get_bits(elems->he_operation->he_oper_params,
3403 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
3404 bss_conf->he_bss_color.disabled =
3405 le32_get_bits(elems->he_operation->he_oper_params,
3406 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
3407 changed |= BSS_CHANGED_HE_BSS_COLOR;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003408
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003409 bss_conf->htc_trig_based_pkt_ext =
Johannes Bergf61d7882019-10-28 12:52:42 +01003410 le32_get_bits(elems->he_operation->he_oper_params,
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003411 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003412 bss_conf->frame_time_rts_th =
Johannes Bergf61d7882019-10-28 12:52:42 +01003413 le32_get_bits(elems->he_operation->he_oper_params,
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003414 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003415
3416 bss_conf->multi_sta_back_32bit =
3417 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3418 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
3419
3420 bss_conf->ack_enabled =
3421 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3422 IEEE80211_HE_MAC_CAP2_ACK_EN;
3423
Johannes Bergf61d7882019-10-28 12:52:42 +01003424 bss_conf->uora_exists = !!elems->uora_element;
3425 if (elems->uora_element)
3426 bss_conf->uora_ocw_range = elems->uora_element[0];
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003427
Johannes Bergf61d7882019-10-28 12:52:42 +01003428 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3429 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003430 /* TODO: OPEN: what happens if BSS color disable is set? */
3431 }
3432
Sara Sharon78ac51f2019-01-16 18:22:56 +02003433 if (cbss->transmitted_bss) {
3434 bss_conf->nontransmitted = true;
3435 ether_addr_copy(bss_conf->transmitter_bssid,
3436 cbss->transmitted_bss->bssid);
3437 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3438 bss_conf->bssid_index = cbss->bssid_index;
3439 }
3440
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003441 /*
3442 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3443 * in their association response, so ignore that data for our own
3444 * configuration. If it changed since the last beacon, we'll get the
3445 * next beacon and update then.
3446 */
Johannes Berg11289582013-02-07 17:36:12 +01003447
Johannes Bergbee7f5862013-02-07 22:24:55 +01003448 /*
3449 * If an operating mode notification IE is present, override the
3450 * NSS calculation (that would be done in rate_control_rate_init())
3451 * and use the # of streams from that element.
3452 */
Johannes Bergf61d7882019-10-28 12:52:42 +01003453 if (elems->opmode_notif &&
3454 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
Johannes Bergbee7f5862013-02-07 22:24:55 +01003455 u8 nss;
3456
Johannes Bergf61d7882019-10-28 12:52:42 +01003457 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
Johannes Bergbee7f5862013-02-07 22:24:55 +01003458 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3459 nss += 1;
3460 sta->sta.rx_nss = nss;
3461 }
3462
Johannes Berg4b7679a2008-09-18 18:14:18 +02003463 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003464
Tamizh chelvam93f04902015-10-07 10:40:04 +05303465 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003466 set_sta_flag(sta, WLAN_STA_MFP);
Tamizh chelvam93f04902015-10-07 10:40:04 +05303467 sta->sta.mfp = true;
3468 } else {
3469 sta->sta.mfp = false;
3470 }
Jouni Malinen5394af42009-01-08 13:31:59 +02003471
Johannes Bergf61d7882019-10-28 12:52:42 +01003472 sta->sta.wme = elems->wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
Johannes Bergddf4ac52008-10-22 11:41:38 +02003473
Johannes Berg3e4d40f2013-02-07 17:19:08 +01003474 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01003475 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3476 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3477 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003478 sdata_info(sdata,
3479 "failed to move station %pM to desired state\n",
3480 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01003481 WARN_ON(__sta_info_destroy(sta));
3482 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003483 ret = false;
3484 goto out;
Johannes Bergc8987872012-01-20 13:55:17 +01003485 }
3486
Johannes Berg7852e362012-01-20 13:55:24 +01003487 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02003488
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003489 /*
3490 * Always handle WMM once after association regardless
3491 * of the first value the AP uses. Setting -1 here has
3492 * that effect because the AP values is an unsigned
3493 * 4-bit value.
3494 */
3495 ifmgd->wmm_last_param_set = -1;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02003496 ifmgd->mu_edca_last_param_set = -1;
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003497
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003498 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Bergcec66282015-10-22 17:46:04 +02003499 ieee80211_set_wmm_default(sdata, false, false);
Johannes Bergf61d7882019-10-28 12:52:42 +01003500 } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
3501 elems->wmm_param_len,
3502 elems->mu_edca_param_set)) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003503 /* still enable QoS since we might have HT/VHT */
3504 ieee80211_set_wmm_default(sdata, false, true);
3505 /* set the disable-WMM flag in this case to disable
3506 * tracking WMM parameter changes in the beacon if
3507 * the parameters weren't actually valid. Doing so
3508 * avoids changing parameters very strangely when
3509 * the AP is going back and forth between valid and
3510 * invalid parameters.
3511 */
3512 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3513 }
Johannes Berg3abead52012-03-02 15:56:59 +01003514 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07003515
Johannes Bergf61d7882019-10-28 12:52:42 +01003516 if (elems->max_idle_period_ie) {
Avraham Sterne38a0172017-04-26 10:58:47 +03003517 bss_conf->max_idle_period =
Johannes Bergf61d7882019-10-28 12:52:42 +01003518 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
Avraham Sterne38a0172017-04-26 10:58:47 +03003519 bss_conf->protected_keep_alive =
Johannes Bergf61d7882019-10-28 12:52:42 +01003520 !!(elems->max_idle_period_ie->idle_options &
Avraham Sterne38a0172017-04-26 10:58:47 +03003521 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3522 changed |= BSS_CHANGED_KEEP_ALIVE;
3523 } else {
3524 bss_conf->max_idle_period = 0;
3525 bss_conf->protected_keep_alive = false;
3526 }
3527
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003528 /* set AID and assoc capability,
3529 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01003530 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003531 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003532 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003533
Kalle Valo15b7b062009-03-22 21:57:14 +02003534 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01003535 * If we're using 4-addr mode, let the AP know that we're
3536 * doing so, so that it can create the STA VLAN on its side
3537 */
3538 if (ifmgd->use_4addr)
3539 ieee80211_send_4addr_nullfunc(local, sdata);
3540
3541 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02003542 * Start timer to probe the connection to the AP now.
3543 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02003544 */
Johannes Bergb291ba12009-07-10 15:29:03 +02003545 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003546 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02003547
Johannes Berg35d865a2013-05-28 10:54:03 +02003548 ret = true;
3549 out:
3550 kfree(bss_ies);
3551 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003552}
3553
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003554static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3555 struct ieee80211_mgmt *mgmt,
3556 size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01003557{
3558 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3559 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3560 u16 capab_info, status_code, aid;
3561 struct ieee802_11_elems elems;
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003562 int ac, uapsd_queues = -1;
Johannes Berg66e67e42012-01-20 13:55:27 +01003563 u8 *pos;
3564 bool reassoc;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003565 struct cfg80211_bss *bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003566 struct ieee80211_event event = {
3567 .type = MLME_EVENT,
3568 .u.mlme.data = ASSOC_EVENT,
3569 };
Jiri Bencf0706e82007-05-05 11:45:53 -07003570
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003571 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003572
3573 if (!assoc_data)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003574 return;
Joe Perchesb203ca32012-05-08 18:56:52 +00003575 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003576 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003577
3578 /*
3579 * AssocResp and ReassocResp have identical structure, so process both
3580 * of them in this function.
3581 */
3582
3583 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003584 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003585
Simon Dinkin7a7d3e42017-08-31 13:09:36 +03003586 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
Johannes Berg66e67e42012-01-20 13:55:27 +01003587 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3588 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3589 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3590
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003591 sdata_info(sdata,
3592 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3593 reassoc ? "Rea" : "A", mgmt->sa,
3594 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01003595
Jouni Malinen39404fe2016-10-27 00:42:05 +03003596 if (assoc_data->fils_kek_len &&
3597 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3598 return;
3599
Johannes Berg66e67e42012-01-20 13:55:27 +01003600 pos = mgmt->u.assoc_resp.variable;
Sara Sharon4abb52a2019-01-16 12:14:41 +02003601 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3602 mgmt->bssid, assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003603
3604 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01003605 elems.timeout_int &&
3606 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003607 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01003608 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01003609 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003610 sdata_info(sdata,
3611 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3612 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01003613 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01003614 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01003615 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003616 run_again(sdata, assoc_data->timeout);
3617 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003618 }
3619
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003620 bss = assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01003621
3622 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003623 sdata_info(sdata, "%pM denied association (code=%d)\n",
3624 mgmt->sa, status_code);
Johannes Berge6f462d2016-12-08 17:22:09 +01003625 ieee80211_destroy_assoc_data(sdata, false, false);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003626 event.u.mlme.status = MLME_DENIED;
3627 event.u.mlme.reason = status_code;
3628 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01003629 } else {
Johannes Bergf61d7882019-10-28 12:52:42 +01003630 if (!ieee80211_assoc_success(sdata, bss, mgmt, len, &elems)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003631 /* oops -- internal error -- send timeout for now */
Johannes Berge6f462d2016-12-08 17:22:09 +01003632 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02003633 cfg80211_assoc_timeout(sdata->dev, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003634 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003635 }
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003636 event.u.mlme.status = MLME_SUCCESS;
3637 drv_event_callback(sdata->local, sdata, &event);
John W. Linville635d9992012-07-09 16:34:34 -04003638 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01003639
3640 /*
3641 * destroy assoc_data afterwards, as otherwise an idle
3642 * recalc after assoc_data is NULL but before associated
3643 * is set can cause the interface to go idle
3644 */
Johannes Berge6f462d2016-12-08 17:22:09 +01003645 ieee80211_destroy_assoc_data(sdata, true, false);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003646
3647 /* get uapsd queues configuration */
3648 uapsd_queues = 0;
3649 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3650 if (sdata->tx_conf[ac].uapsd)
Emmanuel Grumbachf438ceb2016-10-18 23:12:12 +03003651 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
Johannes Berg66e67e42012-01-20 13:55:27 +01003652 }
3653
Jouni Malinen4d9ec732019-02-15 02:14:33 +02003654 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues,
3655 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003656}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003657
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003658static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003659 struct ieee80211_mgmt *mgmt, size_t len,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003660 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003661{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003662 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02003663 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01003664 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01003665
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003666 sdata_assert_lock(sdata);
Johannes Bergb4f286a12013-03-26 14:13:58 +01003667
Emmanuel Grumbach3afc2162014-03-04 16:50:13 +02003668 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3669 if (!channel)
Johannes Berg5bda6172008-09-08 11:05:10 +02003670 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003671
Sara Sharon4abb52a2019-01-16 12:14:41 +02003672 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
Alexander Bondar817cee72013-05-19 14:23:57 +03003673 if (bss) {
Alexander Bondar817cee72013-05-19 14:23:57 +03003674 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
Johannes Bergd2722f82014-03-04 11:43:28 +01003675 ieee80211_rx_bss_put(local, bss);
Alexander Bondar817cee72013-05-19 14:23:57 +03003676 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003677}
3678
3679
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003680static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003681 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003682{
Johannes Bergaf6b6372009-12-23 13:15:35 +01003683 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02003684 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003685 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3686 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03003687
Kalle Valo15b7b062009-03-22 21:57:14 +02003688 ifmgd = &sdata->u.mgd;
3689
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003690 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003691
Joe Perchesb203ca32012-05-08 18:56:52 +00003692 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03003693 return; /* ignore ProbeResp to foreign address */
3694
Ester Kummerae6a44e2008-06-27 18:54:48 +03003695 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3696 if (baselen > len)
3697 return;
3698
Sara Sharon4abb52a2019-01-16 12:14:41 +02003699 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03003700
Johannes Berg77fdaa12009-07-07 03:45:17 +02003701 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003702 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003703 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003704}
3705
Johannes Bergd91f36d2009-04-16 13:17:26 +02003706/*
3707 * This is the canonical list of information elements we care about,
3708 * the filter code also gives us all changes to the Microsoft OUI
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003709 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3710 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3711 * changes to requested client power.
Johannes Bergd91f36d2009-04-16 13:17:26 +02003712 *
3713 * We implement beacon filtering in software since that means we can
3714 * avoid processing the frame here and in cfg80211, and userspace
3715 * will not be able to tell whether the hardware supports it or not.
3716 *
3717 * XXX: This list needs to be dynamic -- userspace needs to be able to
3718 * add items it requires. It also needs to be able to tell us to
3719 * look out for other vendor IEs.
3720 */
3721static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02003722 (1ULL << WLAN_EID_COUNTRY) |
3723 (1ULL << WLAN_EID_ERP_INFO) |
3724 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3725 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3726 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg70a3fd62015-03-12 08:53:29 +02003727 (1ULL << WLAN_EID_HT_OPERATION) |
3728 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003729
Tosoni1ad22fb2018-03-14 16:58:34 +00003730static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3731 struct ieee80211_if_managed *ifmgd,
3732 struct ieee80211_bss_conf *bss_conf,
3733 struct ieee80211_local *local,
3734 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003735{
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003736 /* Track average RSSI from the Beacon frames of the current AP */
Tosoni1ad22fb2018-03-14 16:58:34 +00003737
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003738 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3739 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Johannes Berg338c17a2015-08-28 10:52:54 +02003740 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003741 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03003742 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003743 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003744 } else {
Jouni Malinen391a2002010-08-27 22:22:00 +03003745 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003746 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003747
Johannes Berg338c17a2015-08-28 10:52:54 +02003748 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3749
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003750 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3751 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003752 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003753 int last_sig = ifmgd->last_ave_beacon_signal;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003754 struct ieee80211_event event = {
3755 .type = RSSI_EVENT,
3756 };
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003757
3758 /*
3759 * if signal crosses either of the boundaries, invoke callback
3760 * with appropriate parameters
3761 */
3762 if (sig > ifmgd->rssi_max_thold &&
3763 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3764 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003765 event.u.rssi.data = RSSI_EVENT_HIGH;
3766 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003767 } else if (sig < ifmgd->rssi_min_thold &&
3768 (last_sig >= ifmgd->rssi_max_thold ||
3769 last_sig == 0)) {
3770 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003771 event.u.rssi.data = RSSI_EVENT_LOW;
3772 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003773 }
3774 }
3775
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003776 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03003777 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01003778 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003779 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003780 int last_event = ifmgd->last_cqm_event_signal;
3781 int thold = bss_conf->cqm_rssi_thold;
3782 int hyst = bss_conf->cqm_rssi_hyst;
Johannes Berg338c17a2015-08-28 10:52:54 +02003783
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003784 if (sig < thold &&
3785 (last_event == 0 || sig < last_event - hyst)) {
3786 ifmgd->last_cqm_event_signal = sig;
3787 ieee80211_cqm_rssi_notify(
3788 &sdata->vif,
3789 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003790 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003791 } else if (sig > thold &&
3792 (last_event == 0 || sig > last_event + hyst)) {
3793 ifmgd->last_cqm_event_signal = sig;
3794 ieee80211_cqm_rssi_notify(
3795 &sdata->vif,
3796 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003797 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003798 }
3799 }
3800
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003801 if (bss_conf->cqm_rssi_low &&
3802 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3803 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3804 int last_event = ifmgd->last_cqm_event_signal;
3805 int low = bss_conf->cqm_rssi_low;
3806 int high = bss_conf->cqm_rssi_high;
3807
3808 if (sig < low &&
3809 (last_event == 0 || last_event >= low)) {
3810 ifmgd->last_cqm_event_signal = sig;
3811 ieee80211_cqm_rssi_notify(
3812 &sdata->vif,
3813 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3814 sig, GFP_KERNEL);
3815 } else if (sig > high &&
3816 (last_event == 0 || last_event <= high)) {
3817 ifmgd->last_cqm_event_signal = sig;
3818 ieee80211_cqm_rssi_notify(
3819 &sdata->vif,
3820 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3821 sig, GFP_KERNEL);
3822 }
3823 }
Tosoni1ad22fb2018-03-14 16:58:34 +00003824}
3825
Sara Sharon78ac51f2019-01-16 18:22:56 +02003826static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
3827 struct cfg80211_bss *bss)
3828{
3829 if (ether_addr_equal(tx_bssid, bss->bssid))
3830 return true;
3831 if (!bss->transmitted_bss)
3832 return false;
3833 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
3834}
3835
Tosoni1ad22fb2018-03-14 16:58:34 +00003836static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3837 struct ieee80211_mgmt *mgmt, size_t len,
3838 struct ieee80211_rx_status *rx_status)
3839{
3840 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3841 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3842 size_t baselen;
3843 struct ieee802_11_elems elems;
3844 struct ieee80211_local *local = sdata->local;
3845 struct ieee80211_chanctx_conf *chanctx_conf;
3846 struct ieee80211_channel *chan;
3847 struct sta_info *sta;
3848 u32 changed = 0;
3849 bool erp_valid;
3850 u8 erp_value = 0;
3851 u32 ncrc;
3852 u8 *bssid;
3853 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3854
3855 sdata_assert_lock(sdata);
3856
3857 /* Process beacon from the current BSS */
3858 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3859 if (baselen > len)
3860 return;
3861
3862 rcu_read_lock();
3863 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3864 if (!chanctx_conf) {
3865 rcu_read_unlock();
3866 return;
3867 }
3868
3869 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3870 rcu_read_unlock();
3871 return;
3872 }
3873 chan = chanctx_conf->def.chan;
3874 rcu_read_unlock();
3875
3876 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
Sara Sharon78ac51f2019-01-16 18:22:56 +02003877 ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->assoc_data->bss)) {
Tosoni1ad22fb2018-03-14 16:58:34 +00003878 ieee802_11_parse_elems(mgmt->u.beacon.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003879 len - baselen, false, &elems,
3880 mgmt->bssid,
3881 ifmgd->assoc_data->bss->bssid);
Tosoni1ad22fb2018-03-14 16:58:34 +00003882
Sara Sharon4abb52a2019-01-16 12:14:41 +02003883 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Sara Sharon78ac51f2019-01-16 18:22:56 +02003884
3885 if (elems.dtim_period)
3886 ifmgd->dtim_period = elems.dtim_period;
Tosoni1ad22fb2018-03-14 16:58:34 +00003887 ifmgd->have_beacon = true;
3888 ifmgd->assoc_data->need_beacon = false;
3889 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3890 sdata->vif.bss_conf.sync_tsf =
3891 le64_to_cpu(mgmt->u.beacon.timestamp);
3892 sdata->vif.bss_conf.sync_device_ts =
3893 rx_status->device_timestamp;
Sara Sharon78ac51f2019-01-16 18:22:56 +02003894 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
Tosoni1ad22fb2018-03-14 16:58:34 +00003895 }
Sara Sharon78ac51f2019-01-16 18:22:56 +02003896
3897 if (elems.mbssid_config_ie)
3898 bss_conf->profile_periodicity =
3899 elems.mbssid_config_ie->profile_periodicity;
3900
3901 if (elems.ext_capab_len >= 11 &&
3902 (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
3903 bss_conf->ema_ap = true;
3904
Tosoni1ad22fb2018-03-14 16:58:34 +00003905 /* continue assoc process */
3906 ifmgd->assoc_data->timeout = jiffies;
3907 ifmgd->assoc_data->timeout_started = true;
3908 run_again(sdata, ifmgd->assoc_data->timeout);
3909 return;
3910 }
3911
3912 if (!ifmgd->associated ||
Sara Sharon78ac51f2019-01-16 18:22:56 +02003913 !ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->associated))
Tosoni1ad22fb2018-03-14 16:58:34 +00003914 return;
3915 bssid = ifmgd->associated->bssid;
3916
3917 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3918 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
3919 local, rx_status);
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003920
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003921 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003922 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01003923 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003924 ieee80211_reset_ap_probe(sdata);
Jouni Malinen92778182009-05-14 21:15:36 +03003925 }
3926
Johannes Bergb291ba12009-07-10 15:29:03 +02003927 /*
3928 * Push the beacon loss detection into the future since
3929 * we are processing a beacon from the AP just now.
3930 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003931 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003932
Johannes Bergd91f36d2009-04-16 13:17:26 +02003933 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3934 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003935 len - baselen, false, &elems,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003936 care_about_ies, ncrc,
3937 mgmt->bssid, bssid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003938
Johannes Berg90d13e82015-09-24 16:13:07 +02003939 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3940 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3941 if (local->hw.conf.dynamic_ps_timeout > 0) {
3942 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3943 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3944 ieee80211_hw_config(local,
3945 IEEE80211_CONF_CHANGE_PS);
Kalle Valo572e0012009-02-10 17:09:31 +02003946 }
Johannes Berg076cdcb2015-09-24 16:14:55 +02003947 ieee80211_send_nullfunc(local, sdata, false);
Johannes Berg90d13e82015-09-24 16:13:07 +02003948 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3949 local->pspolling = true;
3950
3951 /*
3952 * Here is assumed that the driver will be
3953 * able to send ps-poll frame and receive a
3954 * response even though power save mode is
3955 * enabled, but some drivers might require
3956 * to disable power save here. This needs
3957 * to be investigated.
3958 */
3959 ieee80211_send_pspoll(local, sdata);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003960 }
3961 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003962
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01003963 if (sdata->vif.p2p ||
3964 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003965 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003966 int ret;
3967
3968 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3969 len - baselen,
3970 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003971 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003972 if (ret >= 2) {
3973 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3974 /* valid noa_attr and index changed */
3975 sdata->u.mgd.p2p_noa_index = noa.index;
3976 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3977 changed |= BSS_CHANGED_P2P_PS;
3978 /*
3979 * make sure we update all information, the CRC
3980 * mechanism doesn't look at P2P attributes.
3981 */
3982 ifmgd->beacon_crc_valid = false;
3983 }
3984 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3985 /* noa_attr not found and we had valid noa_attr before */
3986 sdata->u.mgd.p2p_noa_index = -1;
3987 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003988 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003989 ifmgd->beacon_crc_valid = false;
3990 }
3991 }
3992
Luciano Coelho0c21e632014-10-08 09:48:39 +03003993 if (ifmgd->csa_waiting_bcn)
3994 ieee80211_chswitch_post_beacon(sdata);
3995
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003996 /*
3997 * Update beacon timing and dtim count on every beacon appearance. This
3998 * will allow the driver to use the most updated values. Do it before
3999 * comparing this one with last received beacon.
4000 * IMPORTANT: These parameters would possibly be out of sync by the time
4001 * the driver will use them. The synchronized view is currently
4002 * guaranteed only in certain callbacks.
4003 */
Johannes Berg30686bf2015-06-02 21:39:54 +02004004 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Alexander Bondar2ecc3902015-03-01 09:10:00 +02004005 sdata->vif.bss_conf.sync_tsf =
4006 le64_to_cpu(mgmt->u.beacon.timestamp);
4007 sdata->vif.bss_conf.sync_device_ts =
4008 rx_status->device_timestamp;
Sara Sharon78ac51f2019-01-16 18:22:56 +02004009 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
Alexander Bondar2ecc3902015-03-01 09:10:00 +02004010 }
4011
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03004012 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004013 return;
Jouni Malinen30196672009-05-19 17:01:43 +03004014 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03004015 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03004016
Sara Sharon4abb52a2019-01-16 12:14:41 +02004017 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Johannes Berg7d257452012-07-06 17:37:43 +02004018
Johannes Bergd70b7612013-08-23 15:48:48 +02004019 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
Luciano Coelho2ba45382014-10-08 09:48:35 +03004020 rx_status->device_timestamp,
Johannes Bergd70b7612013-08-23 15:48:48 +02004021 &elems, true);
4022
Johannes Berg095d81c2013-10-15 12:25:07 +02004023 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
4024 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004025 elems.wmm_param_len,
4026 elems.mu_edca_param_set))
Johannes Berg7d257452012-07-06 17:37:43 +02004027 changed |= BSS_CHANGED_QOS;
4028
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004029 /*
4030 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01004031 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004032 */
Alexander Bondar989c6502013-05-16 17:34:17 +03004033 if (!ifmgd->have_beacon) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004034 /* a few bogus AP send dtim_period = 0 or no TIM IE */
Sara Sharon78ac51f2019-01-16 18:22:56 +02004035 bss_conf->dtim_period = elems.dtim_period ?: 1;
Johannes Bergef429da2013-02-05 17:48:40 +01004036
Alexander Bondar989c6502013-05-16 17:34:17 +03004037 changed |= BSS_CHANGED_BEACON_INFO;
4038 ifmgd->have_beacon = true;
Alexander Bondar482a9c72013-06-03 17:29:33 +03004039
4040 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02004041 ieee80211_recalc_ps(local);
Alexander Bondar482a9c72013-06-03 17:29:33 +03004042 mutex_unlock(&local->iflist_mtx);
4043
Alexander Bondarce857882013-05-06 17:17:04 +03004044 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004045 }
4046
Johannes Berg1946bed2013-03-27 14:31:53 +01004047 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02004048 erp_valid = true;
4049 erp_value = elems.erp_info[0];
4050 } else {
4051 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04004052 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02004053 changed |= ieee80211_handle_bss_capability(sdata,
4054 le16_to_cpu(mgmt->u.beacon.capab_info),
4055 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07004056
Johannes Berg11289582013-02-07 17:36:12 +01004057 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f5862013-02-07 22:24:55 +01004058 sta = sta_info_get(sdata, bssid);
4059
John Crispinc9d32452019-05-28 13:49:47 +02004060 changed |= ieee80211_recalc_twt_req(sdata, sta, &elems);
4061
Eliad Peller53b954e2014-07-24 11:20:05 +03004062 if (ieee80211_config_bw(sdata, sta,
4063 elems.ht_cap_elem, elems.ht_operation,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004064 elems.vht_operation, elems.he_operation,
4065 bssid, &changed)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01004066 mutex_unlock(&local->sta_mtx);
Johannes Berg89f774e2016-01-25 15:46:36 +02004067 sdata_info(sdata,
4068 "failed to follow AP %pM bandwidth change, disconnect\n",
4069 bssid);
Johannes Berg30eb1dc2013-02-08 15:12:14 +01004070 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4071 WLAN_REASON_DEAUTH_LEAVING,
4072 true, deauth_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004073 ieee80211_report_disconnect(sdata, deauth_buf,
4074 sizeof(deauth_buf), true,
4075 WLAN_REASON_DEAUTH_LEAVING);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004076 return;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01004077 }
Johannes Bergbee7f5862013-02-07 22:24:55 +01004078
4079 if (sta && elems.opmode_notif)
4080 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
Eyal Shapiracf1e05c2015-12-08 16:04:36 +02004081 rx_status->band);
Johannes Berg11289582013-02-07 17:36:12 +01004082 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02004083
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07004084 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4085 elems.country_elem,
4086 elems.country_elem_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07004087 elems.pwr_constr_elem,
4088 elems.cisco_dtpc_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08004089
Johannes Berg471b3ef2007-12-28 14:32:58 +01004090 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07004091}
4092
Johannes Berg1fa57d02010-06-10 10:21:32 +02004093void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4094 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07004095{
4096 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07004097 struct ieee80211_mgmt *mgmt;
4098 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004099 struct ieee802_11_elems elems;
4100 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07004101
Jiri Bencf0706e82007-05-05 11:45:53 -07004102 rx_status = (struct ieee80211_rx_status *) skb->cb;
4103 mgmt = (struct ieee80211_mgmt *) skb->data;
4104 fc = le16_to_cpu(mgmt->frame_control);
4105
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004106 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004107
Johannes Berg66e67e42012-01-20 13:55:27 +01004108 switch (fc & IEEE80211_FCTL_STYPE) {
4109 case IEEE80211_STYPE_BEACON:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004110 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01004111 break;
4112 case IEEE80211_STYPE_PROBE_RESP:
4113 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4114 break;
4115 case IEEE80211_STYPE_AUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004116 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004117 break;
4118 case IEEE80211_STYPE_DEAUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004119 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004120 break;
4121 case IEEE80211_STYPE_DISASSOC:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004122 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004123 break;
4124 case IEEE80211_STYPE_ASSOC_RESP:
4125 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004126 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004127 break;
4128 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01004129 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004130 ies_len = skb->len -
4131 offsetof(struct ieee80211_mgmt,
4132 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01004133
4134 if (ies_len < 0)
4135 break;
4136
Sara Sharon4abb52a2019-01-16 12:14:41 +02004137 /* CSA IE cannot be overridden, no need for BSSID */
Johannes Berg37799e52013-03-26 14:02:26 +01004138 ieee802_11_parse_elems(
4139 mgmt->u.action.u.chan_switch.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02004140 ies_len, true, &elems, mgmt->bssid, NULL);
Johannes Berg37799e52013-03-26 14:02:26 +01004141
4142 if (elems.parse_error)
4143 break;
4144
Johannes Berg66e67e42012-01-20 13:55:27 +01004145 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03004146 rx_status->mactime,
4147 rx_status->device_timestamp,
4148 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004149 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4150 ies_len = skb->len -
4151 offsetof(struct ieee80211_mgmt,
4152 u.action.u.ext_chan_switch.variable);
4153
4154 if (ies_len < 0)
4155 break;
4156
Sara Sharon4abb52a2019-01-16 12:14:41 +02004157 /*
4158 * extended CSA IE can't be overridden, no need for
4159 * BSSID
4160 */
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004161 ieee802_11_parse_elems(
4162 mgmt->u.action.u.ext_chan_switch.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02004163 ies_len, true, &elems, mgmt->bssid, NULL);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004164
4165 if (elems.parse_error)
4166 break;
4167
4168 /* for the handling code pretend this was also an IE */
4169 elems.ext_chansw_ie =
4170 &mgmt->u.action.u.ext_chan_switch.data;
4171
4172 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03004173 rx_status->mactime,
4174 rx_status->device_timestamp,
4175 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004176 }
Johannes Berg37799e52013-03-26 14:02:26 +01004177 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004178 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004179 sdata_unlock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07004180}
4181
Kees Cook34f11cd2017-10-16 16:35:49 -07004182static void ieee80211_sta_timer(struct timer_list *t)
Jiri Bencf0706e82007-05-05 11:45:53 -07004183{
4184 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004185 from_timer(sdata, t, u.mgd.timer);
Jiri Bencf0706e82007-05-05 11:45:53 -07004186
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01004187 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07004188}
4189
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004190static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01004191 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004192{
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004193 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004194
Johannes Berg37ad3882012-02-24 13:50:54 +01004195 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01004196 tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01004197
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004198 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4199 reason);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004200}
4201
Johannes Berg46cad4b2015-08-15 22:39:54 +03004202static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg66e67e42012-01-20 13:55:27 +01004203{
4204 struct ieee80211_local *local = sdata->local;
4205 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4206 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004207 u32 tx_flags = 0;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004208 u16 trans = 1;
4209 u16 status = 0;
Ilan Peerd4e36e52018-04-20 13:49:25 +03004210 u16 prepare_tx_duration = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004211
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004212 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004213
4214 if (WARN_ON_ONCE(!auth_data))
4215 return -EINVAL;
4216
Johannes Berg66e67e42012-01-20 13:55:27 +01004217 auth_data->tries++;
4218
4219 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004220 sdata_info(sdata, "authentication with %pM timed out\n",
4221 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004222
4223 /*
4224 * Most likely AP is not in the range so remove the
4225 * bss struct for that AP.
4226 */
4227 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4228
4229 return -ETIMEDOUT;
4230 }
4231
Ilan Peerd4e36e52018-04-20 13:49:25 +03004232 if (auth_data->algorithm == WLAN_AUTH_SAE)
4233 prepare_tx_duration =
4234 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4235
4236 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
Johannes Berga1845fc2012-06-27 13:18:36 +02004237
Johannes Berg46cad4b2015-08-15 22:39:54 +03004238 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4239 auth_data->bss->bssid, auth_data->tries,
4240 IEEE80211_AUTH_MAX_TRIES);
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004241
Johannes Berg46cad4b2015-08-15 22:39:54 +03004242 auth_data->expected_transaction = 2;
Johannes Berg66e67e42012-01-20 13:55:27 +01004243
Johannes Berg46cad4b2015-08-15 22:39:54 +03004244 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4245 trans = auth_data->sae_trans;
4246 status = auth_data->sae_status;
4247 auth_data->expected_transaction = trans;
Johannes Berg66e67e42012-01-20 13:55:27 +01004248 }
4249
Johannes Berg46cad4b2015-08-15 22:39:54 +03004250 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4251 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4252 IEEE80211_TX_INTFL_MLME_CONN_TX;
4253
4254 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4255 auth_data->data, auth_data->data_len,
4256 auth_data->bss->bssid,
4257 auth_data->bss->bssid, NULL, 0, 0,
4258 tx_flags);
4259
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02004260 if (tx_flags == 0) {
Ilan Peer407879b2018-04-20 13:49:20 +03004261 if (auth_data->algorithm == WLAN_AUTH_SAE)
4262 auth_data->timeout = jiffies +
4263 IEEE80211_AUTH_TIMEOUT_SAE;
4264 else
4265 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004266 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004267 auth_data->timeout =
4268 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004269 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004270
Ilan Peer407879b2018-04-20 13:49:20 +03004271 auth_data->timeout_started = true;
4272 run_again(sdata, auth_data->timeout);
4273
Johannes Berg66e67e42012-01-20 13:55:27 +01004274 return 0;
4275}
4276
4277static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4278{
4279 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4280 struct ieee80211_local *local = sdata->local;
4281
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004282 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004283
Johannes Berg66e67e42012-01-20 13:55:27 +01004284 assoc_data->tries++;
4285 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004286 sdata_info(sdata, "association with %pM timed out\n",
4287 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004288
4289 /*
4290 * Most likely AP is not in the range so remove the
4291 * bss struct for that AP.
4292 */
4293 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4294
4295 return -ETIMEDOUT;
4296 }
4297
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004298 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4299 assoc_data->bss->bssid, assoc_data->tries,
4300 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01004301 ieee80211_send_assoc(sdata);
4302
Johannes Berg30686bf2015-06-02 21:39:54 +02004303 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004304 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004305 assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004306 run_again(sdata, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01004307 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004308 assoc_data->timeout =
4309 round_jiffies_up(jiffies +
4310 IEEE80211_ASSOC_TIMEOUT_LONG);
4311 assoc_data->timeout_started = true;
4312 run_again(sdata, assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004313 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004314
4315 return 0;
4316}
4317
Johannes Berg1672c0e32013-01-29 15:02:27 +01004318void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4319 __le16 fc, bool acked)
4320{
4321 struct ieee80211_local *local = sdata->local;
4322
4323 sdata->u.mgd.status_fc = fc;
4324 sdata->u.mgd.status_acked = acked;
4325 sdata->u.mgd.status_received = true;
4326
4327 ieee80211_queue_work(&local->hw, &sdata->work);
4328}
4329
Johannes Berg1fa57d02010-06-10 10:21:32 +02004330void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02004331{
Johannes Berg60f8b392008-09-08 17:44:22 +02004332 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02004333 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02004334
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004335 sdata_lock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02004336
Johannes Berg1672c0e32013-01-29 15:02:27 +01004337 if (ifmgd->status_received) {
4338 __le16 fc = ifmgd->status_fc;
4339 bool status_acked = ifmgd->status_acked;
4340
4341 ifmgd->status_received = false;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004342 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004343 if (status_acked) {
Ilan Peer407879b2018-04-20 13:49:20 +03004344 if (ifmgd->auth_data->algorithm ==
4345 WLAN_AUTH_SAE)
4346 ifmgd->auth_data->timeout =
4347 jiffies +
4348 IEEE80211_AUTH_TIMEOUT_SAE;
4349 else
4350 ifmgd->auth_data->timeout =
4351 jiffies +
4352 IEEE80211_AUTH_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004353 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004354 } else {
4355 ifmgd->auth_data->timeout = jiffies - 1;
4356 }
Johannes Berg89afe612013-02-13 15:39:57 +01004357 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004358 } else if (ifmgd->assoc_data &&
4359 (ieee80211_is_assoc_req(fc) ||
4360 ieee80211_is_reassoc_req(fc))) {
4361 if (status_acked) {
4362 ifmgd->assoc_data->timeout =
4363 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004364 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004365 } else {
4366 ifmgd->assoc_data->timeout = jiffies - 1;
4367 }
Johannes Berg89afe612013-02-13 15:39:57 +01004368 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004369 }
4370 }
4371
Johannes Berg89afe612013-02-13 15:39:57 +01004372 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004373 time_after(jiffies, ifmgd->auth_data->timeout)) {
4374 if (ifmgd->auth_data->done) {
4375 /*
4376 * ok ... we waited for assoc but userspace didn't,
4377 * so let's just kill the auth data
4378 */
4379 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg46cad4b2015-08-15 22:39:54 +03004380 } else if (ieee80211_auth(sdata)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004381 u8 bssid[ETH_ALEN];
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004382 struct ieee80211_event event = {
4383 .type = MLME_EVENT,
4384 .u.mlme.data = AUTH_EVENT,
4385 .u.mlme.status = MLME_TIMEOUT,
4386 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004387
4388 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4389
4390 ieee80211_destroy_auth_data(sdata, false);
4391
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004392 cfg80211_auth_timeout(sdata->dev, bssid);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004393 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004394 }
Johannes Berg89afe612013-02-13 15:39:57 +01004395 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004396 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004397
Johannes Berg89afe612013-02-13 15:39:57 +01004398 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004399 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Alexander Bondar989c6502013-05-16 17:34:17 +03004400 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01004401 ieee80211_do_assoc(sdata)) {
Johannes Berg959867f2013-06-19 13:05:42 +02004402 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004403 struct ieee80211_event event = {
4404 .type = MLME_EVENT,
4405 .u.mlme.data = ASSOC_EVENT,
4406 .u.mlme.status = MLME_TIMEOUT,
4407 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004408
Johannes Berge6f462d2016-12-08 17:22:09 +01004409 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02004410 cfg80211_assoc_timeout(sdata->dev, bss);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004411 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004412 }
Johannes Berg89afe612013-02-13 15:39:57 +01004413 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004414 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004415
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02004416 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
Johannes Bergb291ba12009-07-10 15:29:03 +02004417 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03004418 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004419 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03004420
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004421 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004422
Johannes Berg30686bf2015-06-02 21:39:54 +02004423 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Ben Greear180205b2011-02-04 15:30:24 -08004424 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004425 else
Ben Greear180205b2011-02-04 15:30:24 -08004426 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004427
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004428 /* ACK received for nullfunc probing frame */
4429 if (!ifmgd->probe_send_count)
4430 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004431 else if (ifmgd->nullfunc_failed) {
4432 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004433 mlme_dbg(sdata,
4434 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4435 bssid, ifmgd->probe_send_count,
4436 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004437 ieee80211_mgd_probe_ap_send(sdata);
4438 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004439 mlme_dbg(sdata,
4440 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4441 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02004442 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004443 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4444 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004445 }
4446 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004447 run_again(sdata, ifmgd->probe_timeout);
Johannes Berg30686bf2015-06-02 21:39:54 +02004448 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004449 mlme_dbg(sdata,
4450 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4451 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02004452 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004453 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004454 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004455 mlme_dbg(sdata,
4456 "No probe response from AP %pM after %dms, try %d/%i\n",
4457 bssid, probe_wait_ms,
4458 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03004459 ieee80211_mgd_probe_ap_send(sdata);
4460 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02004461 /*
4462 * We actually lost the connection ... or did we?
4463 * Let's make sure!
4464 */
Johannes Berg89f774e2016-01-25 15:46:36 +02004465 mlme_dbg(sdata,
4466 "No probe response from AP %pM after %dms, disconnecting.\n",
4467 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004468
Johannes Berg95acac62011-07-12 12:30:59 +02004469 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004470 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02004471 }
4472 }
4473
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004474 sdata_unlock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02004475}
Johannes Berg0a51b272008-09-08 17:44:25 +02004476
Kees Cook34f11cd2017-10-16 16:35:49 -07004477static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004478{
4479 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004480 from_timer(sdata, t, u.mgd.bcn_mon_timer);
Luciano Coelho0c21e632014-10-08 09:48:39 +03004481 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004482
Luciano Coelho0c21e632014-10-08 09:48:39 +03004483 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004484 return;
4485
Johannes Berg682bd382013-01-29 13:13:50 +01004486 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004487 ieee80211_queue_work(&sdata->local->hw,
4488 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004489}
4490
Kees Cook34f11cd2017-10-16 16:35:49 -07004491static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004492{
4493 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004494 from_timer(sdata, t, u.mgd.conn_mon_timer);
Johannes Bergb291ba12009-07-10 15:29:03 +02004495 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4496 struct ieee80211_local *local = sdata->local;
4497
Luciano Coelho0c21e632014-10-08 09:48:39 +03004498 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004499 return;
4500
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04004501 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004502}
4503
4504static void ieee80211_sta_monitor_work(struct work_struct *work)
4505{
4506 struct ieee80211_sub_if_data *sdata =
4507 container_of(work, struct ieee80211_sub_if_data,
4508 u.mgd.monitor_work);
4509
4510 ieee80211_mgd_probe_ap(sdata, false);
4511}
4512
Johannes Berga1678f82008-09-11 00:01:47 +02004513static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4514{
Kalle Vaload935682009-04-19 08:47:19 +03004515 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02004516 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03004517
Johannes Bergb291ba12009-07-10 15:29:03 +02004518 /* let's probe the connection once */
Johannes Berg30686bf2015-06-02 21:39:54 +02004519 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Eliad Peller494f1fe2012-02-19 15:26:09 +02004520 ieee80211_queue_work(&sdata->local->hw,
4521 &sdata->u.mgd.monitor_work);
Kalle Vaload935682009-04-19 08:47:19 +03004522 }
Johannes Berga1678f82008-09-11 00:01:47 +02004523}
4524
Johannes Bergb8360ab2013-04-29 14:57:44 +02004525#ifdef CONFIG_PM
Johannes Berg1a1cb742014-03-19 09:55:55 +01004526void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4527{
4528 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4529 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4530
4531 sdata_lock(sdata);
4532
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004533 if (ifmgd->auth_data || ifmgd->assoc_data) {
4534 const u8 *bssid = ifmgd->auth_data ?
4535 ifmgd->auth_data->bss->bssid :
4536 ifmgd->assoc_data->bss->bssid;
4537
Johannes Berg1a1cb742014-03-19 09:55:55 +01004538 /*
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004539 * If we are trying to authenticate / associate while suspending,
4540 * cfg80211 won't know and won't actually abort those attempts,
4541 * thus we need to do that ourselves.
Johannes Berg1a1cb742014-03-19 09:55:55 +01004542 */
Johannes Berg4b08d1b2019-08-30 14:24:51 +03004543 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
Johannes Berg1a1cb742014-03-19 09:55:55 +01004544 IEEE80211_STYPE_DEAUTH,
4545 WLAN_REASON_DEAUTH_LEAVING,
4546 false, frame_buf);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004547 if (ifmgd->assoc_data)
Johannes Berge6f462d2016-12-08 17:22:09 +01004548 ieee80211_destroy_assoc_data(sdata, false, true);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004549 if (ifmgd->auth_data)
4550 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg1a1cb742014-03-19 09:55:55 +01004551 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4552 IEEE80211_DEAUTH_FRAME_LEN);
4553 }
4554
Johannes Bergbe72afe2015-03-01 09:10:03 +02004555 /* This is a bit of a hack - we should find a better and more generic
4556 * solution to this. Normally when suspending, cfg80211 will in fact
4557 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4558 * auth (not so important) or assoc (this is the problem) process.
4559 *
4560 * As a consequence, it can happen that we are in the process of both
4561 * associating and suspending, and receive an association response
4562 * after cfg80211 has checked if it needs to disconnect, but before
4563 * we actually set the flag to drop incoming frames. This will then
4564 * cause the workqueue flush to process the association response in
4565 * the suspend, resulting in a successful association just before it
4566 * tries to remove the interface from the driver, which now though
4567 * has a channel context assigned ... this results in issues.
4568 *
4569 * To work around this (for now) simply deauth here again if we're
4570 * now connected.
4571 */
4572 if (ifmgd->associated && !sdata->local->wowlan) {
4573 u8 bssid[ETH_ALEN];
4574 struct cfg80211_deauth_request req = {
4575 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4576 .bssid = bssid,
4577 };
4578
4579 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4580 ieee80211_mgd_deauth(sdata, &req);
4581 }
4582
Johannes Berg1a1cb742014-03-19 09:55:55 +01004583 sdata_unlock(sdata);
4584}
4585
Johannes Bergb8360ab2013-04-29 14:57:44 +02004586void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4587{
4588 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4589
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004590 sdata_lock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004591 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004592 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004593 return;
4594 }
4595
4596 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4597 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4598 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4599 ieee80211_sta_connection_lost(sdata,
4600 ifmgd->associated->bssid,
4601 WLAN_REASON_UNSPECIFIED,
4602 true);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004603 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004604 return;
4605 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004606 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004607}
4608#endif
4609
Johannes Berg9c6bd792008-09-11 00:01:52 +02004610/* interface setup */
4611void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4612{
Johannes Berg46900292009-02-15 12:44:28 +01004613 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004614
Johannes Berg46900292009-02-15 12:44:28 +01004615 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004616 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01004617 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004618 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4619 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02004620 INIT_WORK(&ifmgd->csa_connection_drop_work,
4621 ieee80211_csa_connection_drop_work);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03004622 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03004623 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4624 ieee80211_tdls_peer_del_work);
Kees Cook34f11cd2017-10-16 16:35:49 -07004625 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4626 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4627 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4628 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
Johannes Berg02219b32014-10-07 10:38:50 +03004629 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4630 ieee80211_sta_handle_tspec_ac_params_wk);
Johannes Berg9c6bd792008-09-11 00:01:52 +02004631
Johannes Bergab1faea2009-07-01 21:41:17 +02004632 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05304633 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02004634 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4635 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01004636 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02004637
Eliad Peller0d8614b2014-09-10 14:07:36 +03004638 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
Johannes Berg0f782312009-12-01 13:37:02 +01004639 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4640 else
4641 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02004642
4643 /* Setup TDLS data */
4644 spin_lock_init(&ifmgd->teardown_lock);
4645 ifmgd->teardown_skb = NULL;
4646 ifmgd->orig_teardown_skb = NULL;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004647}
4648
4649/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02004650void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4651{
Johannes Berg31ee67a2012-07-06 21:18:24 +02004652 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02004653
4654 /* Restart STA timers */
4655 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07004656 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4657 if (ieee80211_sdata_running(sdata))
4658 ieee80211_restart_sta_timer(sdata);
4659 }
Johannes Berga1678f82008-09-11 00:01:47 +02004660 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02004661}
Johannes Berg10f644a2009-04-16 13:17:25 +02004662
Johannes Bergf2d9d272012-11-22 14:11:39 +01004663static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4664 struct cfg80211_bss *cbss)
4665{
4666 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4667 const u8 *ht_cap_ie, *vht_cap_ie;
4668 const struct ieee80211_ht_cap *ht_cap;
4669 const struct ieee80211_vht_cap *vht_cap;
4670 u8 chains = 1;
4671
4672 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4673 return chains;
4674
Johannes Berg9caf0362012-11-29 01:25:20 +01004675 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004676 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4677 ht_cap = (void *)(ht_cap_ie + 2);
4678 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4679 /*
4680 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4681 * "Tx Unequal Modulation Supported" fields.
4682 */
4683 }
4684
4685 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4686 return chains;
4687
Johannes Berg9caf0362012-11-29 01:25:20 +01004688 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004689 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4690 u8 nss;
4691 u16 tx_mcs_map;
4692
4693 vht_cap = (void *)(vht_cap_ie + 2);
4694 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4695 for (nss = 8; nss > 0; nss--) {
4696 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4697 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4698 break;
4699 }
4700 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4701 chains = max(chains, nss);
4702 }
4703
4704 return chains;
4705}
4706
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004707static bool
4708ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4709 const struct ieee80211_he_operation *he_op)
4710{
4711 const struct ieee80211_sta_he_cap *sta_he_cap =
4712 ieee80211_get_he_sta_cap(sband);
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004713 u16 ap_min_req_set;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004714 int i;
4715
4716 if (!sta_he_cap || !he_op)
4717 return false;
4718
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004719 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4720
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004721 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4722 for (i = 0; i < 3; i++) {
4723 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4724 &sta_he_cap->he_mcs_nss_supp;
4725 u16 sta_mcs_map_rx =
4726 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4727 u16 sta_mcs_map_tx =
4728 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4729 u8 nss;
4730 bool verified = true;
4731
4732 /*
4733 * For each band there is a maximum of 8 spatial streams
4734 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4735 * of 2 bits per NSS (1-8), with the values defined in enum
4736 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4737 * capabilities aren't less than the AP's minimum requirements
4738 * for this HE BSS per SS.
4739 * It is enough to find one such band that meets the reqs.
4740 */
4741 for (nss = 8; nss > 0; nss--) {
4742 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4743 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4744 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4745
4746 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4747 continue;
4748
4749 /*
4750 * Make sure the HE AP doesn't require MCSs that aren't
4751 * supported by the client
4752 */
4753 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4754 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4755 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4756 verified = false;
4757 break;
4758 }
4759 }
4760
4761 if (verified)
4762 return true;
4763 }
4764
4765 /* If here, STA doesn't meet AP's HE min requirements */
4766 return false;
4767}
4768
Johannes Bergb17166a2012-07-27 11:41:27 +02004769static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4770 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01004771{
4772 struct ieee80211_local *local = sdata->local;
4773 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Peller53b954e2014-07-24 11:20:05 +03004774 const struct ieee80211_ht_cap *ht_cap = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004775 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004776 const struct ieee80211_vht_operation *vht_oper = NULL;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004777 const struct ieee80211_he_operation *he_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004778 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01004779 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004780 int ret;
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004781 u32 i;
4782 bool have_80mhz;
Johannes Berga1cf7752012-03-08 15:02:07 +01004783
Johannes Berg24398e32012-03-28 10:58:36 +02004784 sband = local->hw.wiphy->bands[cbss->channel->band];
4785
Johannes Bergf2d9d272012-11-22 14:11:39 +01004786 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4787 IEEE80211_STA_DISABLE_80P80MHZ |
4788 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02004789
Johannes Berg75e296e2020-01-31 13:12:39 +02004790 /* disable HT/VHT/HE if we don't support them */
4791 if (!sband->ht_cap.ht_supported) {
4792 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4793 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4794 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4795 }
4796
4797 if (!sband->vht_cap.vht_supported)
4798 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4799
4800 if (!ieee80211_get_he_sta_cap(sband))
4801 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4802
Johannes Berg9caf0362012-11-29 01:25:20 +01004803 rcu_read_lock();
4804
Johannes Berg75e296e2020-01-31 13:12:39 +02004805 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Eliad Peller53b954e2014-07-24 11:20:05 +03004806 const u8 *ht_oper_ie, *ht_cap_ie;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004807
Johannes Berg9caf0362012-11-29 01:25:20 +01004808 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02004809 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4810 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6effa2013-02-07 23:33:32 +01004811
Eliad Peller53b954e2014-07-24 11:20:05 +03004812 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4813 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4814 ht_cap = (void *)(ht_cap_ie + 2);
4815
4816 if (!ht_cap) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004817 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4818 ht_oper = NULL;
4819 }
Johannes Berg24398e32012-03-28 10:58:36 +02004820 }
4821
Johannes Berg75e296e2020-01-31 13:12:39 +02004822 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004823 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004824
Johannes Berg9caf0362012-11-29 01:25:20 +01004825 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4826 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004827 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4828 vht_oper = (void *)(vht_oper_ie + 2);
4829 if (vht_oper && !ht_oper) {
4830 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004831 sdata_info(sdata,
Johannes Berg75e296e2020-01-31 13:12:39 +02004832 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
Johannes Bergcb145022013-02-07 20:41:50 +01004833 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4834 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg75e296e2020-01-31 13:12:39 +02004835 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Johannes Berg24398e32012-03-28 10:58:36 +02004836 }
Johannes Berg08e6effa2013-02-07 23:33:32 +01004837
4838 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4839 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4840 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4841 vht_oper = NULL;
4842 }
Johannes Berg24398e32012-03-28 10:58:36 +02004843 }
4844
Shaul Triebitz002245e2018-12-15 11:03:19 +02004845 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004846 const struct cfg80211_bss_ies *ies;
4847 const u8 *he_oper_ie;
4848
4849 ies = rcu_dereference(cbss->ies);
4850 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
4851 ies->data, ies->len);
4852 if (he_oper_ie &&
4853 he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
4854 he_oper = (void *)(he_oper_ie + 3);
4855 else
4856 he_oper = NULL;
4857
Johannes Bergf0c04072018-06-29 09:51:39 +02004858 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004859 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4860 }
4861
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004862 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4863 have_80mhz = false;
4864 for (i = 0; i < sband->n_channels; i++) {
4865 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4866 IEEE80211_CHAN_NO_80MHZ))
4867 continue;
4868
4869 have_80mhz = true;
4870 break;
4871 }
4872
4873 if (!have_80mhz)
4874 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4875
Johannes Bergf2d9d272012-11-22 14:11:39 +01004876 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4877 cbss->channel,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004878 ht_oper, vht_oper, he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +02004879 &chandef, false);
Johannes Berg04ecd252012-09-11 14:34:12 +02004880
Johannes Bergf2d9d272012-11-22 14:11:39 +01004881 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4882 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02004883
Johannes Berg9caf0362012-11-29 01:25:20 +01004884 rcu_read_unlock();
4885
Johannes Berg04ecd252012-09-11 14:34:12 +02004886 /* will change later if needed */
4887 sdata->smps_mode = IEEE80211_SMPS_OFF;
4888
Johannes Berg34a37402013-12-18 09:43:33 +01004889 mutex_lock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004890 /*
4891 * If this fails (possibly due to channel context sharing
4892 * on incompatible channels, e.g. 80+80 and 160 sharing the
4893 * same control channel) try to use a smaller bandwidth.
4894 */
4895 ret = ieee80211_vif_use_channel(sdata, &chandef,
4896 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich0418a442013-05-16 13:00:31 +02004897
4898 /* don't downgrade for 5 and 10 MHz channels, though. */
4899 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4900 chandef.width == NL80211_CHAN_WIDTH_10)
Johannes Berg34a37402013-12-18 09:43:33 +01004901 goto out;
Simon Wunderlich0418a442013-05-16 13:00:31 +02004902
Johannes Bergd601cd82013-02-07 20:54:51 +01004903 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02004904 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01004905 ret = ieee80211_vif_use_channel(sdata, &chandef,
4906 IEEE80211_CHANCTX_SHARED);
4907 }
Johannes Berg34a37402013-12-18 09:43:33 +01004908 out:
4909 mutex_unlock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004910 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02004911}
4912
Sara Sharon78ac51f2019-01-16 18:22:56 +02004913static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
4914 u8 *dtim_count, u8 *dtim_period)
4915{
4916 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
4917 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
4918 ies->len);
4919 const struct ieee80211_tim_ie *tim = NULL;
4920 const struct ieee80211_bssid_index *idx;
4921 bool valid = tim_ie && tim_ie[1] >= 2;
4922
4923 if (valid)
4924 tim = (void *)(tim_ie + 2);
4925
4926 if (dtim_count)
4927 *dtim_count = valid ? tim->dtim_count : 0;
4928
4929 if (dtim_period)
4930 *dtim_period = valid ? tim->dtim_period : 0;
4931
4932 /* Check if value is overridden by non-transmitted profile */
4933 if (!idx_ie || idx_ie[1] < 3)
4934 return valid;
4935
4936 idx = (void *)(idx_ie + 2);
4937
4938 if (dtim_count)
4939 *dtim_count = idx->dtim_count;
4940
4941 if (dtim_period)
4942 *dtim_period = idx->dtim_period;
4943
4944 return true;
4945}
4946
Johannes Bergb17166a2012-07-27 11:41:27 +02004947static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004948 struct cfg80211_bss *cbss, bool assoc,
4949 bool override)
Johannes Bergb17166a2012-07-27 11:41:27 +02004950{
4951 struct ieee80211_local *local = sdata->local;
4952 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4953 struct ieee80211_bss *bss = (void *)cbss->priv;
4954 struct sta_info *new_sta = NULL;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004955 struct ieee80211_supported_band *sband;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004956 bool have_sta = false;
Johannes Bergb17166a2012-07-27 11:41:27 +02004957 int err;
4958
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004959 sband = local->hw.wiphy->bands[cbss->channel->band];
4960
Johannes Bergb17166a2012-07-27 11:41:27 +02004961 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4962 return -EINVAL;
4963
Luca Coelhof8860ce2017-05-02 17:56:21 +03004964 /* If a reconfig is happening, bail out */
4965 if (local->in_reconfig)
4966 return -EBUSY;
4967
Johannes Bergb17166a2012-07-27 11:41:27 +02004968 if (assoc) {
4969 rcu_read_lock();
4970 have_sta = sta_info_get(sdata, cbss->bssid);
4971 rcu_read_unlock();
4972 }
4973
4974 if (!have_sta) {
4975 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4976 if (!new_sta)
4977 return -ENOMEM;
4978 }
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004979
Johannes Bergc87905b2017-06-10 13:52:43 +03004980 /*
4981 * Set up the information for the new channel before setting the
4982 * new channel. We can't - completely race-free - change the basic
4983 * rates bitmap and the channel (sband) that it refers to, but if
4984 * we set it up before we at least avoid calling into the driver's
4985 * bss_info_changed() method with invalid information (since we do
4986 * call that from changing the channel - only for IDLE and perhaps
4987 * some others, but ...).
4988 *
4989 * So to avoid that, just set up all the new information before the
4990 * channel, but tell the driver to apply it only afterwards, since
4991 * it might need the new channel for that.
4992 */
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004993 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004994 u32 rates = 0, basic_rates = 0;
4995 bool have_higher_than_11mbit;
4996 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004997 const struct cfg80211_bss_ies *ies;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004998 int shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004999
Johannes Berg5d6a1b02012-03-08 15:02:08 +01005000 ieee80211_get_rates(sband, bss->supp_rates,
5001 bss->supp_rates_len,
5002 &rates, &basic_rates,
5003 &have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02005004 &min_rate, &min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03005005 shift);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01005006
5007 /*
5008 * This used to be a workaround for basic rates missing
5009 * in the association response frame. Now that we no
5010 * longer use the basic rates from there, it probably
5011 * doesn't happen any more, but keep the workaround so
5012 * in case some *other* APs are buggy in different ways
5013 * we can connect -- with a warning.
5014 */
5015 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005016 sdata_info(sdata,
5017 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01005018 basic_rates = BIT(min_rate_index);
5019 }
5020
Johannes Bergbd718fc2019-05-29 15:25:35 +03005021 if (rates)
5022 new_sta->sta.supp_rates[cbss->channel->band] = rates;
5023 else
5024 sdata_info(sdata,
5025 "No rates found, keeping mandatory only\n");
5026
Johannes Berg5d6a1b02012-03-08 15:02:08 +01005027 sdata->vif.bss_conf.basic_rates = basic_rates;
5028
5029 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg57fbcce2016-04-12 15:56:15 +02005030 if (cbss->channel->band == NL80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01005031 have_higher_than_11mbit)
5032 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
5033 else
5034 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
5035
5036 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
5037
Johannes Berg8c358bc2012-05-22 22:13:05 +02005038 /* set timing information */
5039 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005040 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01005041 ies = rcu_dereference(cbss->beacon_ies);
5042 if (ies) {
Johannes Bergef429da2013-02-05 17:48:40 +01005043 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5044 sdata->vif.bss_conf.sync_device_ts =
5045 bss->device_ts_beacon;
Sara Sharon78ac51f2019-01-16 18:22:56 +02005046
5047 ieee80211_get_dtim(ies,
5048 &sdata->vif.bss_conf.sync_dtim_count,
5049 NULL);
Johannes Berg30686bf2015-06-02 21:39:54 +02005050 } else if (!ieee80211_hw_check(&sdata->local->hw,
5051 TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005052 ies = rcu_dereference(cbss->proberesp_ies);
5053 /* must be non-NULL since beacon IEs were NULL */
5054 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5055 sdata->vif.bss_conf.sync_device_ts =
5056 bss->device_ts_presp;
5057 sdata->vif.bss_conf.sync_dtim_count = 0;
5058 } else {
5059 sdata->vif.bss_conf.sync_tsf = 0;
5060 sdata->vif.bss_conf.sync_device_ts = 0;
5061 sdata->vif.bss_conf.sync_dtim_count = 0;
5062 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01005063 rcu_read_unlock();
Johannes Bergc87905b2017-06-10 13:52:43 +03005064 }
Johannes Berg8c358bc2012-05-22 22:13:05 +02005065
Johannes Bergc87905b2017-06-10 13:52:43 +03005066 if (new_sta || override) {
5067 err = ieee80211_prep_channel(sdata, cbss);
5068 if (err) {
5069 if (new_sta)
5070 sta_info_free(local, new_sta);
5071 return -EINVAL;
5072 }
5073 }
5074
5075 if (new_sta) {
5076 /*
5077 * tell driver about BSSID, basic rates and timing
5078 * this was set up above, before setting the channel
5079 */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01005080 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02005081 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5082 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01005083
5084 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02005085 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01005086
Johannes Berg13e0c8e2012-07-27 10:43:16 +02005087 err = sta_info_insert(new_sta);
5088 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01005089 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005090 sdata_info(sdata,
5091 "failed to insert STA entry for the AP (error %d)\n",
5092 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01005093 return err;
5094 }
5095 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00005096 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01005097
David Spinadel7d830a12015-03-17 19:58:38 +02005098 /* Cancel scan to ensure that nothing interferes with connection */
5099 if (local->scanning)
5100 ieee80211_scan_cancel(local);
5101
Johannes Berga1cf7752012-03-08 15:02:07 +01005102 return 0;
5103}
5104
Johannes Berg77fdaa12009-07-07 03:45:17 +02005105/* config hooks */
5106int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5107 struct cfg80211_auth_request *req)
5108{
Johannes Berg66e67e42012-01-20 13:55:27 +01005109 struct ieee80211_local *local = sdata->local;
5110 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5111 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005112 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01005113 int err;
Jouni Malinenefb543e2018-10-11 00:21:21 +03005114 bool cont_auth;
Johannes Berg66e67e42012-01-20 13:55:27 +01005115
5116 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02005117
5118 switch (req->auth_type) {
5119 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5120 auth_alg = WLAN_AUTH_OPEN;
5121 break;
5122 case NL80211_AUTHTYPE_SHARED_KEY:
Ard Biesheuvel5fdb3732019-06-12 18:19:54 +02005123 if (fips_enabled)
Johannes Berg9dca9c42010-07-21 10:09:25 +02005124 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005125 auth_alg = WLAN_AUTH_SHARED_KEY;
5126 break;
5127 case NL80211_AUTHTYPE_FT:
5128 auth_alg = WLAN_AUTH_FT;
5129 break;
5130 case NL80211_AUTHTYPE_NETWORK_EAP:
5131 auth_alg = WLAN_AUTH_LEAP;
5132 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005133 case NL80211_AUTHTYPE_SAE:
5134 auth_alg = WLAN_AUTH_SAE;
5135 break;
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03005136 case NL80211_AUTHTYPE_FILS_SK:
5137 auth_alg = WLAN_AUTH_FILS_SK;
5138 break;
5139 case NL80211_AUTHTYPE_FILS_SK_PFS:
5140 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5141 break;
5142 case NL80211_AUTHTYPE_FILS_PK:
5143 auth_alg = WLAN_AUTH_FILS_PK;
5144 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005145 default:
5146 return -EOPNOTSUPP;
5147 }
5148
Jouni Malinenefb543e2018-10-11 00:21:21 +03005149 if (ifmgd->assoc_data)
Jouni Malinen8d7432a2018-10-11 00:21:20 +03005150 return -EBUSY;
5151
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03005152 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005153 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01005154 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005155 return -ENOMEM;
5156
Johannes Berg66e67e42012-01-20 13:55:27 +01005157 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005158
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03005159 if (req->auth_data_len >= 4) {
Jouni Malinen6ec63612016-10-27 00:41:59 +03005160 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5161 __le16 *pos = (__le16 *) req->auth_data;
5162
5163 auth_data->sae_trans = le16_to_cpu(pos[0]);
5164 auth_data->sae_status = le16_to_cpu(pos[1]);
5165 }
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03005166 memcpy(auth_data->data, req->auth_data + 4,
5167 req->auth_data_len - 4);
5168 auth_data->data_len += req->auth_data_len - 4;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005169 }
5170
Jouni Malinenefb543e2018-10-11 00:21:21 +03005171 /* Check if continuing authentication or trying to authenticate with the
5172 * same BSS that we were in the process of authenticating with and avoid
5173 * removal and re-addition of the STA entry in
5174 * ieee80211_prep_connection().
5175 */
5176 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5177
Johannes Berg77fdaa12009-07-07 03:45:17 +02005178 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005179 memcpy(&auth_data->data[auth_data->data_len],
5180 req->ie, req->ie_len);
5181 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005182 }
5183
Johannes Bergfffd0932009-07-08 14:22:54 +02005184 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005185 auth_data->key_len = req->key_len;
5186 auth_data->key_idx = req->key_idx;
5187 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02005188 }
5189
Johannes Berg66e67e42012-01-20 13:55:27 +01005190 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005191
Johannes Berg66e67e42012-01-20 13:55:27 +01005192 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01005193
Jouni Malinenefb543e2018-10-11 00:21:21 +03005194 if (ifmgd->auth_data) {
5195 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5196 auth_data->peer_confirmed =
5197 ifmgd->auth_data->peer_confirmed;
5198 }
5199 ieee80211_destroy_auth_data(sdata, cont_auth);
5200 }
Guy Eilam2a33bee2011-08-17 15:18:15 +03005201
Johannes Berg66e67e42012-01-20 13:55:27 +01005202 /* prep auth_data so we don't go into idle on disassoc */
5203 ifmgd->auth_data = auth_data;
5204
Jouni Malinenefb543e2018-10-11 00:21:21 +03005205 /* If this is continuation of an ongoing SAE authentication exchange
5206 * (i.e., request to send SAE Confirm) and the peer has already
5207 * confirmed, mark authentication completed since we are about to send
5208 * out SAE Confirm.
5209 */
5210 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5211 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5212 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5213
Johannes Berg7b119dc2013-04-10 21:38:36 +02005214 if (ifmgd->associated) {
5215 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5216
Johannes Berg89f774e2016-01-25 15:46:36 +02005217 sdata_info(sdata,
5218 "disconnect from AP %pM for new auth to %pM\n",
5219 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005220 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5221 WLAN_REASON_UNSPECIFIED,
5222 false, frame_buf);
5223
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005224 ieee80211_report_disconnect(sdata, frame_buf,
5225 sizeof(frame_buf), true,
5226 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005227 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005228
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005229 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005230
Jouni Malinenefb543e2018-10-11 00:21:21 +03005231 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
Johannes Berga1cf7752012-03-08 15:02:07 +01005232 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01005233 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005234
Johannes Berg46cad4b2015-08-15 22:39:54 +03005235 err = ieee80211_auth(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01005236 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005237 sta_info_destroy_addr(sdata, req->bss->bssid);
5238 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005239 }
5240
Johannes Berg66e67e42012-01-20 13:55:27 +01005241 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01005242 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005243 return 0;
Johannes Berge5b900d2010-07-29 16:08:55 +02005244
Johannes Berg66e67e42012-01-20 13:55:27 +01005245 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005246 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005247 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005248 ifmgd->auth_data = NULL;
Michal Kaziord01f8582015-06-03 08:36:13 +02005249 mutex_lock(&sdata->local->mtx);
5250 ieee80211_vif_release_channel(sdata);
5251 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01005252 kfree(auth_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005253 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005254}
5255
Johannes Berg77fdaa12009-07-07 03:45:17 +02005256int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5257 struct cfg80211_assoc_request *req)
5258{
Johannes Berg66e67e42012-01-20 13:55:27 +01005259 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005260 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01005261 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01005262 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005263 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005264 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005265 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005266 int i, err;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005267 bool override = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005268
Johannes Berg66e67e42012-01-20 13:55:27 +01005269 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5270 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01005271 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005272
Johannes Berg9caf0362012-11-29 01:25:20 +01005273 rcu_read_lock();
5274 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Will Deacon41525612019-10-04 10:51:31 +01005275 if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
Johannes Berg9caf0362012-11-29 01:25:20 +01005276 rcu_read_unlock();
5277 kfree(assoc_data);
5278 return -EINVAL;
5279 }
5280 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5281 assoc_data->ssid_len = ssidie[1];
5282 rcu_read_unlock();
5283
Johannes Berg7b119dc2013-04-10 21:38:36 +02005284 if (ifmgd->associated) {
5285 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5286
Johannes Berg89f774e2016-01-25 15:46:36 +02005287 sdata_info(sdata,
5288 "disconnect from AP %pM for new assoc to %pM\n",
5289 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005290 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5291 WLAN_REASON_UNSPECIFIED,
5292 false, frame_buf);
5293
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005294 ieee80211_report_disconnect(sdata, frame_buf,
5295 sizeof(frame_buf), true,
5296 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005297 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005298
5299 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5300 err = -EBUSY;
5301 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005302 }
5303
Johannes Berg66e67e42012-01-20 13:55:27 +01005304 if (ifmgd->assoc_data) {
5305 err = -EBUSY;
5306 goto err_free;
5307 }
5308
5309 if (ifmgd->auth_data) {
5310 bool match;
5311
5312 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00005313 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005314 ieee80211_destroy_auth_data(sdata, match);
5315 }
5316
5317 /* prepare assoc data */
Johannes Berg095d81c2013-10-15 12:25:07 +02005318
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03005319 ifmgd->beacon_crc_valid = false;
5320
Johannes Berg095d81c2013-10-15 12:25:07 +02005321 assoc_data->wmm = bss->wmm_used &&
5322 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg095d81c2013-10-15 12:25:07 +02005323
Johannes Bergde5036a2012-03-08 15:02:03 +01005324 /*
5325 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5326 * We still associate in non-HT mode (11a/b/g) if any one of these
5327 * ciphers is configured as pairwise.
5328 * We can set this to true for non-11n hardware, that'll be checked
5329 * separately along with the peer capabilities.
5330 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02005331 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02005332 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5333 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02005334 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01005335 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005336 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005337 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Johannes Berg1c4cb922012-05-30 15:57:00 +02005338 netdev_info(sdata->dev,
Johannes Berg54626322019-08-30 14:24:46 +03005339 "disabling HT/VHT/HE due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005340 }
5341 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005342
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005343 sband = local->hw.wiphy->bands[req->bss->channel->band];
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005344
Johannes Berg75e296e2020-01-31 13:12:39 +02005345 /* also disable HT/VHT/HE if the AP doesn't use WMM */
5346 if (!bss->wmm_used) {
5347 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005348 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg75e296e2020-01-31 13:12:39 +02005349 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5350 netdev_info(sdata->dev,
5351 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005352 }
5353
Ben Greearef96a8422011-11-18 11:32:00 -08005354 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5355 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5356 sizeof(ifmgd->ht_capa_mask));
5357
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01005358 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5359 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5360 sizeof(ifmgd->vht_capa_mask));
5361
Johannes Berg77fdaa12009-07-07 03:45:17 +02005362 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005363 memcpy(assoc_data->ie, req->ie, req->ie_len);
5364 assoc_data->ie_len = req->ie_len;
5365 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005366
Jouni Malinen39404fe2016-10-27 00:42:05 +03005367 if (req->fils_kek) {
5368 /* should already be checked in cfg80211 - so warn */
5369 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5370 err = -EINVAL;
5371 goto err_free;
5372 }
5373 memcpy(assoc_data->fils_kek, req->fils_kek,
5374 req->fils_kek_len);
5375 assoc_data->fils_kek_len = req->fils_kek_len;
5376 }
5377
5378 if (req->fils_nonces)
5379 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5380 2 * FILS_NONCE_LEN);
5381
Johannes Berg66e67e42012-01-20 13:55:27 +01005382 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01005383
Johannes Bergaf6b6372009-12-23 13:15:35 +01005384 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5385 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02005386 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005387 else
Johannes Berg04ecd252012-09-11 14:34:12 +02005388 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005389 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02005390 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005391
Johannes Berg66e67e42012-01-20 13:55:27 +01005392 assoc_data->capability = req->bss->capability;
Johannes Berg66e67e42012-01-20 13:55:27 +01005393 assoc_data->supp_rates = bss->supp_rates;
5394 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02005395
Johannes Berg9caf0362012-11-29 01:25:20 +01005396 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02005397 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5398 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5399 assoc_data->ap_ht_param =
5400 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5401 else
Johannes Berga8243b72012-11-22 14:32:09 +01005402 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005403 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5404 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5405 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5406 sizeof(struct ieee80211_vht_cap));
5407 else
5408 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01005409 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01005410
Johannes Berg848955c2014-11-11 12:48:42 +01005411 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02005412 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
Johannes Berg848955c2014-11-11 12:48:42 +01005413 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5414 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5415
Kalle Valoab133152010-01-12 10:42:31 +02005416 if (bss->wmm_used && bss->uapsd_supported &&
Johannes Berg848955c2014-11-11 12:48:42 +01005417 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01005418 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02005419 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5420 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01005421 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02005422 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5423 }
5424
Johannes Berg77fdaa12009-07-07 03:45:17 +02005425 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01005426 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005427
5428 if (req->use_mfp) {
5429 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5430 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5431 } else {
5432 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5433 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5434 }
5435
Assaf Krausscd2f5dd2014-09-03 15:25:02 +03005436 if (req->flags & ASSOC_REQ_USE_RRM)
5437 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5438 else
5439 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5440
Johannes Berg77fdaa12009-07-07 03:45:17 +02005441 if (req->crypto.control_port)
5442 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5443 else
5444 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5445
Johannes Berga621fa42010-08-27 14:26:54 +03005446 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5447 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05005448 sdata->control_port_over_nl80211 =
5449 req->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02005450 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5451 sdata->vif.type);
Johannes Berga621fa42010-08-27 14:26:54 +03005452
Johannes Berg66e67e42012-01-20 13:55:27 +01005453 /* kick off associate process */
5454
5455 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02005456 ifmgd->dtim_period = 0;
Alexander Bondar989c6502013-05-16 17:34:17 +03005457 ifmgd->have_beacon = false;
Johannes Berg66e67e42012-01-20 13:55:27 +01005458
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005459 /* override HT/VHT configuration only if the AP and we support it */
5460 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5461 struct ieee80211_sta_ht_cap sta_ht_cap;
5462
5463 if (req->flags & ASSOC_REQ_DISABLE_HT)
5464 override = true;
5465
5466 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5467 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5468
5469 /* check for 40 MHz disable override */
5470 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5471 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5472 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5473 override = true;
5474
5475 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5476 req->flags & ASSOC_REQ_DISABLE_VHT)
5477 override = true;
5478 }
5479
5480 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5481 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5482 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg75e296e2020-01-31 13:12:39 +02005483 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005484 }
5485
5486 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5487 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5488
5489 err = ieee80211_prep_connection(sdata, req->bss, true, override);
Johannes Berga1cf7752012-03-08 15:02:07 +01005490 if (err)
5491 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01005492
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005493 rcu_read_lock();
5494 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02005495
Johannes Berg30686bf2015-06-02 21:39:54 +02005496 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005497 !beacon_ies) {
5498 /*
5499 * Wait up to one beacon interval ...
5500 * should this be more if we miss one?
5501 */
5502 sdata_info(sdata, "waiting for beacon from %pM\n",
5503 ifmgd->bssid);
5504 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01005505 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005506 assoc_data->need_beacon = true;
5507 } else if (beacon_ies) {
Sara Sharon78ac51f2019-01-16 18:22:56 +02005508 const u8 *ie;
Johannes Bergef429da2013-02-05 17:48:40 +01005509 u8 dtim_count = 0;
5510
Sara Sharon78ac51f2019-01-16 18:22:56 +02005511 ieee80211_get_dtim(beacon_ies, &dtim_count,
5512 &ifmgd->dtim_period);
5513
Alexander Bondar989c6502013-05-16 17:34:17 +03005514 ifmgd->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005515 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005516 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01005517
Johannes Berg30686bf2015-06-02 21:39:54 +02005518 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005519 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5520 sdata->vif.bss_conf.sync_device_ts =
5521 bss->device_ts_beacon;
5522 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5523 }
Sara Sharon78ac51f2019-01-16 18:22:56 +02005524
5525 ie = cfg80211_find_ext_ie(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5526 beacon_ies->data, beacon_ies->len);
5527 if (ie && ie[1] >= 3)
5528 sdata->vif.bss_conf.profile_periodicity = ie[4];
5529
5530 ie = cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY,
5531 beacon_ies->data, beacon_ies->len);
5532 if (ie && ie[1] >= 11 &&
5533 (ie[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5534 sdata->vif.bss_conf.ema_ap = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005535 } else {
5536 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005537 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005538 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005539 rcu_read_unlock();
5540
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005541 run_again(sdata, assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01005542
Paul Stewartfcff4f12012-02-23 17:59:53 -08005543 if (bss->corrupt_data) {
5544 char *corrupt_type = "data";
5545 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5546 if (bss->corrupt_data &
5547 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5548 corrupt_type = "beacon and probe response";
5549 else
5550 corrupt_type = "beacon";
5551 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5552 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005553 sdata_info(sdata, "associating with AP with corrupt %s\n",
5554 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08005555 }
5556
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005557 return 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01005558 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005559 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005560 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005561 ifmgd->assoc_data = NULL;
5562 err_free:
5563 kfree(assoc_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005564 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005565}
5566
5567int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005568 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005569{
5570 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005571 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005572 bool tx = !req->local_state_change;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005573
Johannes Bergc9c3a062014-03-19 09:11:19 +01005574 if (ifmgd->auth_data &&
5575 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5576 sdata_info(sdata,
5577 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5578 req->bssid, req->reason_code,
5579 ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005580
Ilan Peerd4e36e52018-04-20 13:49:25 +03005581 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg4b08d1b2019-08-30 14:24:51 +03005582 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
Johannes Berg37ad3882012-02-24 13:50:54 +01005583 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005584 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01005585 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01005586 ieee80211_destroy_auth_data(sdata, false);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005587 ieee80211_report_disconnect(sdata, frame_buf,
5588 sizeof(frame_buf), true,
5589 req->reason_code);
Johannes Berg86552012012-10-29 09:46:31 +01005590
Johannes Bergc9c3a062014-03-19 09:11:19 +01005591 return 0;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03005592 }
5593
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005594 if (ifmgd->assoc_data &&
5595 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5596 sdata_info(sdata,
5597 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5598 req->bssid, req->reason_code,
5599 ieee80211_get_reason_code_string(req->reason_code));
5600
Ilan Peerd4e36e52018-04-20 13:49:25 +03005601 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg4b08d1b2019-08-30 14:24:51 +03005602 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005603 IEEE80211_STYPE_DEAUTH,
5604 req->reason_code, tx,
5605 frame_buf);
Johannes Berge6f462d2016-12-08 17:22:09 +01005606 ieee80211_destroy_assoc_data(sdata, false, true);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005607 ieee80211_report_disconnect(sdata, frame_buf,
5608 sizeof(frame_buf), true,
5609 req->reason_code);
5610 return 0;
5611 }
5612
Johannes Berg86552012012-10-29 09:46:31 +01005613 if (ifmgd->associated &&
5614 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
Johannes Bergc9c3a062014-03-19 09:11:19 +01005615 sdata_info(sdata,
5616 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5617 req->bssid, req->reason_code,
5618 ieee80211_get_reason_code_string(req->reason_code));
5619
Johannes Berg86552012012-10-29 09:46:31 +01005620 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5621 req->reason_code, tx, frame_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005622 ieee80211_report_disconnect(sdata, frame_buf,
5623 sizeof(frame_buf), true,
5624 req->reason_code);
Johannes Bergc9c3a062014-03-19 09:11:19 +01005625 return 0;
5626 }
Johannes Berg86552012012-10-29 09:46:31 +01005627
Johannes Bergc9c3a062014-03-19 09:11:19 +01005628 return -ENOTCONN;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005629}
5630
5631int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005632 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005633{
5634 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07005635 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005636 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02005637
Johannes Berg8d8b2612009-07-25 11:58:36 +02005638 /*
5639 * cfg80211 should catch this ... but it's racy since
5640 * we can receive a disassoc frame, process it, hand it
5641 * to cfg80211 while that's in a locked section already
5642 * trying to tell us that the user wants to disconnect.
5643 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005644 if (ifmgd->associated != req->bss)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005645 return -ENOLINK;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005646
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005647 sdata_info(sdata,
Calvin Owensdfa1ad22014-02-11 12:36:24 -06005648 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5649 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005650
Jouni Malinene69e95d2010-03-29 23:29:31 -07005651 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01005652 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5653 req->reason_code, !req->local_state_change,
5654 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005655
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005656 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5657 req->reason_code);
Johannes Bergbc83b682009-11-29 12:19:06 +01005658
Johannes Berg77fdaa12009-07-07 03:45:17 +02005659 return 0;
5660}
Jouni Malinen026331c2010-02-15 12:53:10 +02005661
Eliad Pellerafa762f2012-04-23 14:45:15 +03005662void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005663{
5664 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5665
Ben Greear49921852013-02-20 09:41:09 -08005666 /*
5667 * Make sure some work items will not run after this,
5668 * they will not do anything but might not have been
5669 * cancelled when disconnecting.
5670 */
5671 cancel_work_sync(&ifmgd->monitor_work);
5672 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5673 cancel_work_sync(&ifmgd->request_smps_work);
5674 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5675 cancel_work_sync(&ifmgd->chswitch_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03005676 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
Ben Greear49921852013-02-20 09:41:09 -08005677
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005678 sdata_lock(sdata);
Johannes Berg959867f2013-06-19 13:05:42 +02005679 if (ifmgd->assoc_data) {
5680 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Johannes Berge6f462d2016-12-08 17:22:09 +01005681 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02005682 cfg80211_assoc_timeout(sdata->dev, bss);
5683 }
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005684 if (ifmgd->auth_data)
5685 ieee80211_destroy_auth_data(sdata, false);
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005686 spin_lock_bh(&ifmgd->teardown_lock);
5687 if (ifmgd->teardown_skb) {
5688 kfree_skb(ifmgd->teardown_skb);
5689 ifmgd->teardown_skb = NULL;
5690 ifmgd->orig_teardown_skb = NULL;
5691 }
Jouni Malinen4d9ec732019-02-15 02:14:33 +02005692 kfree(ifmgd->assoc_req_ies);
5693 ifmgd->assoc_req_ies = NULL;
5694 ifmgd->assoc_req_ies_len = 0;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005695 spin_unlock_bh(&ifmgd->teardown_lock);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005696 del_timer_sync(&ifmgd->timer);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005697 sdata_unlock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005698}
5699
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005700void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5701 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005702 s32 rssi_level,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005703 gfp_t gfp)
5704{
5705 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5706
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005707 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
Johannes Bergb5878a22010-04-07 16:48:40 +02005708
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01005709 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005710}
5711EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
Johannes Berg98f03342014-11-26 12:42:02 +01005712
5713void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5714{
5715 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5716
5717 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5718
5719 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5720}
5721EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);