blob: f076e73314a6484598ef114095e4ab0653cc56a6 [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 Berg60f8b39c2008-09-08 17:44:22 +020027
Jiri Bencf0706e82007-05-05 11:45:53 -070028#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020029#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040030#include "rate.h"
31#include "led.h"
Jouni Malinen39404fe2016-10-27 00:42:05 +030032#include "fils_aead.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070033
Johannes Berg1672c0e32013-01-29 15:02:27 +010034#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020035#define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010036#define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
Ilan Peer407879b2018-04-20 13:49:20 +030037#define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010038#define IEEE80211_AUTH_MAX_TRIES 3
39#define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
40#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020041#define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010042#define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
43#define IEEE80211_ASSOC_MAX_TRIES 3
Johannes Berg66e67e42012-01-20 13:55:27 +010044
Ben Greear180205b2011-02-04 15:30:24 -080045static int max_nullfunc_tries = 2;
46module_param(max_nullfunc_tries, int, 0644);
47MODULE_PARM_DESC(max_nullfunc_tries,
48 "Maximum nullfunc tx tries before disconnecting (reason 4).");
49
50static int max_probe_tries = 5;
51module_param(max_probe_tries, int, 0644);
52MODULE_PARM_DESC(max_probe_tries,
53 "Maximum probe tries before disconnecting (reason 4).");
Johannes Bergb291ba12009-07-10 15:29:03 +020054
55/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010056 * Beacon loss timeout is calculated as N frames times the
57 * advertised beacon interval. This may need to be somewhat
58 * higher than what hardware might detect to account for
59 * delays in the host processing frames. But since we also
60 * probe on beacon miss before declaring the connection lost
61 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020062 */
Ben Greear59c1ec22013-03-19 14:19:56 -070063static int beacon_loss_count = 7;
64module_param(beacon_loss_count, int, 0644);
65MODULE_PARM_DESC(beacon_loss_count,
66 "Number of beacon intervals before we decide beacon was lost.");
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010067
Johannes Bergb291ba12009-07-10 15:29:03 +020068/*
69 * Time the connection can be idle before we probe
70 * it to see if we can still talk to the AP.
71 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030072#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020073/*
74 * Time we wait for a probe response after sending
75 * a probe request because of beacon loss or for
76 * checking the connection still works.
77 */
Ben Greear180205b2011-02-04 15:30:24 -080078static int probe_wait_ms = 500;
79module_param(probe_wait_ms, int, 0644);
80MODULE_PARM_DESC(probe_wait_ms,
81 "Maximum time(ms) to wait for probe response"
82 " before disconnecting (reason 4).");
Jiri Bencf0706e82007-05-05 11:45:53 -070083
Jouni Malinen17e4ec12010-03-29 23:28:30 -070084/*
Jouni Malinen391a2002010-08-27 22:22:00 +030085 * How many Beacon frames need to have been used in average signal strength
86 * before starting to indicate signal change events.
87 */
88#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
89
Johannes Berg77fdaa12009-07-07 03:45:17 +020090/*
Johannes Bergca386f32009-07-10 02:39:48 +020091 * We can have multiple work items (and connection probing)
92 * scheduling this timer, but we need to take care to only
93 * reschedule it when it should fire _earlier_ than it was
94 * asked for before, or if it's not pending right now. This
95 * function ensures that. Note that it then is required to
96 * run this function for all timeouts after the first one
97 * has happened -- the work that runs from this timer will
98 * do that.
99 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200100static void run_again(struct ieee80211_sub_if_data *sdata,
101 unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200102{
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200103 sdata_assert_lock(sdata);
Johannes Bergca386f32009-07-10 02:39:48 +0200104
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200105 if (!timer_pending(&sdata->u.mgd.timer) ||
106 time_before(timeout, sdata->u.mgd.timer.expires))
107 mod_timer(&sdata->u.mgd.timer, timeout);
Johannes Bergca386f32009-07-10 02:39:48 +0200108}
109
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400110void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200111{
Johannes Bergc1288b12012-01-19 09:29:57 +0100112 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200113 return;
114
Johannes Berg30686bf2015-06-02 21:39:54 +0200115 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Johannes Berg7eeff742012-07-18 10:27:27 +0200116 return;
117
Johannes Bergb291ba12009-07-10 15:29:03 +0200118 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100119 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200120}
121
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400122void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
123{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400124 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
125
Johannes Bergb100e5d2016-03-17 15:41:37 +0200126 if (unlikely(!ifmgd->associated))
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100127 return;
128
Johannes Bergb100e5d2016-03-17 15:41:37 +0200129 if (ifmgd->probe_send_count)
130 ifmgd->probe_send_count = 0;
Eliad Peller448cd2e2014-02-11 12:30:18 +0200131
Johannes Berg30686bf2015-06-02 21:39:54 +0200132 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400133 return;
134
Johannes Bergb100e5d2016-03-17 15:41:37 +0200135 mod_timer(&ifmgd->conn_mon_timer,
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400136 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
137}
138
Johannes Berg5484e232008-09-08 17:44:27 +0200139static int ecw2cw(int ecw)
Johannes Berg60f8b39c2008-09-08 17:44:22 +0200140{
Johannes Berg5484e232008-09-08 17:44:27 +0200141 return (1 << ecw) - 1;
Johannes Berg60f8b39c2008-09-08 17:44:22 +0200142}
143
Johannes Berg6565ec92013-02-08 14:52:32 +0100144static u32
145ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
146 struct ieee80211_supported_band *sband,
147 struct ieee80211_channel *channel,
148 const struct ieee80211_ht_operation *ht_oper,
149 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300150 const struct ieee80211_he_operation *he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +0200151 struct cfg80211_chan_def *chandef, bool tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100152{
Johannes Berg5cdaed12013-07-31 11:23:06 +0200153 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg6565ec92013-02-08 14:52:32 +0100154 struct cfg80211_chan_def vht_chandef;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200155 struct ieee80211_sta_ht_cap sta_ht_cap;
Johannes Berg6565ec92013-02-08 14:52:32 +0100156 u32 ht_cfreq, ret;
157
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200158 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
159 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
160
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +0300161 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
Johannes Berg6565ec92013-02-08 14:52:32 +0100162 chandef->chan = channel;
163 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
164 chandef->center_freq1 = channel->center_freq;
Johannes Berg6565ec92013-02-08 14:52:32 +0100165
Johannes Bergb1b1ae22017-10-13 15:26:01 +0300166 if (!ht_oper || !sta_ht_cap.ht_supported) {
Johannes 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
Johannes Berg5cdaed12013-07-31 11:23:06 +0200316 if (chandef->width != vht_chandef.width && !tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100317 sdata_info(sdata,
318 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
319
320 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
321 return ret;
322}
323
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100324static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
325 struct sta_info *sta,
Eliad Peller53b954e2014-07-24 11:20:05 +0300326 const struct ieee80211_ht_cap *ht_cap,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100327 const struct ieee80211_ht_operation *ht_oper,
328 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300329 const struct ieee80211_he_operation *he_oper,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100330 const u8 *bssid, u32 *changed)
Johannes Bergd5522e02009-03-30 13:23:35 +0200331{
332 struct ieee80211_local *local = sdata->local;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100333 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300334 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
335 struct ieee80211_supported_band *sband =
336 local->hw.wiphy->bands[chan->band];
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100337 struct cfg80211_chan_def chandef;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200338 u16 ht_opmode;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100339 u32 flags;
340 enum ieee80211_sta_rx_bandwidth new_sta_bw;
341 int ret;
342
343 /* if HT was/is disabled, don't track any bandwidth changes */
344 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
345 return 0;
346
347 /* don't check VHT if we associated as non-VHT station */
348 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
349 vht_oper = NULL;
Johannes Bergd5522e02009-03-30 13:23:35 +0200350
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300351 /* don't check HE if we associated as non-HE station */
352 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
353 !ieee80211_get_he_sta_cap(sband))
354 he_oper = NULL;
355
Johannes Berg11289582013-02-07 17:36:12 +0100356 if (WARN_ON_ONCE(!sta))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100357 return -EINVAL;
Johannes Berg11289582013-02-07 17:36:12 +0100358
Avri Altman017b45b2013-11-18 19:06:48 +0200359 /*
360 * if bss configuration changed store the new one -
361 * this may be applicable even if channel is identical
362 */
363 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
364 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
365 *changed |= BSS_CHANGED_HT;
366 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
367 }
368
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300369 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
Eliad Peller53b954e2014-07-24 11:20:05 +0300370 flags = ieee80211_determine_chantype(sdata, sband, chan,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300371 ht_oper, vht_oper, he_oper,
Eliad Peller53b954e2014-07-24 11:20:05 +0300372 &chandef, true);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100373
374 /*
375 * Downgrade the new channel if we associated with restricted
376 * capabilities. For example, if we associated as a 20 MHz STA
377 * to a 40 MHz AP (due to regulatory, capabilities or config
378 * reasons) then switching to a 40 MHz channel now won't do us
379 * any good -- we couldn't use it with the AP.
380 */
381 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
382 chandef.width == NL80211_CHAN_WIDTH_80P80)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200383 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100384 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
385 chandef.width == NL80211_CHAN_WIDTH_160)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200386 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100387 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
388 chandef.width > NL80211_CHAN_WIDTH_20)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200389 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100390
391 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
392 return 0;
393
394 sdata_info(sdata,
395 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
396 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
397 chandef.center_freq1, chandef.center_freq2);
398
399 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
400 IEEE80211_STA_DISABLE_VHT |
Johannes Berg75e296e2020-01-31 13:12:39 +0200401 IEEE80211_STA_DISABLE_HE |
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100402 IEEE80211_STA_DISABLE_40MHZ |
403 IEEE80211_STA_DISABLE_80P80MHZ |
404 IEEE80211_STA_DISABLE_160MHZ)) ||
405 !cfg80211_chandef_valid(&chandef)) {
406 sdata_info(sdata,
407 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
408 ifmgd->bssid);
409 return -EINVAL;
Johannes Berg64f68e52012-03-28 10:58:37 +0200410 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200411
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100412 switch (chandef.width) {
413 case NL80211_CHAN_WIDTH_20_NOHT:
414 case NL80211_CHAN_WIDTH_20:
415 new_sta_bw = IEEE80211_STA_RX_BW_20;
416 break;
417 case NL80211_CHAN_WIDTH_40:
418 new_sta_bw = IEEE80211_STA_RX_BW_40;
419 break;
420 case NL80211_CHAN_WIDTH_80:
421 new_sta_bw = IEEE80211_STA_RX_BW_80;
422 break;
423 case NL80211_CHAN_WIDTH_80P80:
424 case NL80211_CHAN_WIDTH_160:
425 new_sta_bw = IEEE80211_STA_RX_BW_160;
426 break;
427 default:
428 return -EINVAL;
429 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200430
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100431 if (new_sta_bw > sta->cur_max_bandwidth)
432 new_sta_bw = sta->cur_max_bandwidth;
Johannes Berg64f68e52012-03-28 10:58:37 +0200433
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100434 if (new_sta_bw < sta->sta.bandwidth) {
435 sta->sta.bandwidth = new_sta_bw;
436 rate_control_rate_update(local, sband, sta,
437 IEEE80211_RC_BW_CHANGED);
438 }
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530439
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100440 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
441 if (ret) {
442 sdata_info(sdata,
443 "AP %pM changed bandwidth to incompatible one - disconnect\n",
444 ifmgd->bssid);
445 return ret;
446 }
447
448 if (new_sta_bw > sta->sta.bandwidth) {
449 sta->sta.bandwidth = new_sta_bw;
450 rate_control_rate_update(local, sband, sta,
451 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200452 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200453
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100454 return 0;
Johannes Bergd5522e02009-03-30 13:23:35 +0200455}
456
Johannes Berg9c6bd792008-09-11 00:01:52 +0200457/* frame sending functions */
458
Johannes Berg66e67e42012-01-20 13:55:27 +0100459static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200460 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100461 struct ieee80211_supported_band *sband,
462 struct ieee80211_channel *channel,
463 enum ieee80211_smps_mode smps)
464{
Johannes Berg66e67e42012-01-20 13:55:27 +0100465 u8 *pos;
466 u32 flags = channel->flags;
467 u16 cap;
468 struct ieee80211_sta_ht_cap ht_cap;
469
470 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
471
Johannes Berg66e67e42012-01-20 13:55:27 +0100472 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
473 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
474
Johannes Berg66e67e42012-01-20 13:55:27 +0100475 /* determine capability flags */
476 cap = ht_cap.cap;
477
Johannes Berg9dde6422012-05-16 23:43:19 +0200478 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100479 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
480 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
481 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
482 cap &= ~IEEE80211_HT_CAP_SGI_40;
483 }
484 break;
485 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
486 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
487 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
488 cap &= ~IEEE80211_HT_CAP_SGI_40;
489 }
490 break;
491 }
492
Johannes Berg24398e32012-03-28 10:58:36 +0200493 /*
494 * If 40 MHz was disabled associate as though we weren't
495 * capable of 40 MHz -- some broken APs will never fall
496 * back to trying to transmit in 20 MHz.
497 */
498 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
499 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
500 cap &= ~IEEE80211_HT_CAP_SGI_40;
501 }
502
Johannes Berg66e67e42012-01-20 13:55:27 +0100503 /* set SM PS mode properly */
504 cap &= ~IEEE80211_HT_CAP_SM_PS;
505 switch (smps) {
506 case IEEE80211_SMPS_AUTOMATIC:
507 case IEEE80211_SMPS_NUM_MODES:
508 WARN_ON(1);
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500509 /* fall through */
Johannes Berg66e67e42012-01-20 13:55:27 +0100510 case IEEE80211_SMPS_OFF:
511 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
512 IEEE80211_HT_CAP_SM_PS_SHIFT;
513 break;
514 case IEEE80211_SMPS_STATIC:
515 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
516 IEEE80211_HT_CAP_SM_PS_SHIFT;
517 break;
518 case IEEE80211_SMPS_DYNAMIC:
519 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
520 IEEE80211_HT_CAP_SM_PS_SHIFT;
521 break;
522 }
523
524 /* reserve and fill IE */
525 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
526 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
527}
528
Sara Sharon322cd402015-07-08 15:41:43 +0300529/* This function determines vht capability flags for the association
530 * and builds the IE.
531 * Note - the function may set the owner of the MU-MIMO capability
532 */
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000533static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
534 struct sk_buff *skb,
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100535 struct ieee80211_supported_band *sband,
536 struct ieee80211_vht_cap *ap_vht_cap)
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000537{
Sara Sharon322cd402015-07-08 15:41:43 +0300538 struct ieee80211_local *local = sdata->local;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000539 u8 *pos;
540 u32 cap;
541 struct ieee80211_sta_vht_cap vht_cap;
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200542 u32 mask, ap_bf_sts, our_bf_sts;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000543
544 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
545
546 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +0100547 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000548
549 /* determine capability flags */
550 cap = vht_cap.cap;
551
Johannes Bergf2d9d272012-11-22 14:11:39 +0100552 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
Johannes Berg575f0532014-11-24 16:51:33 +0100553 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
554
555 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
556 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
557 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
558 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100559 }
560
561 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
562 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
Johannes Berg575f0532014-11-24 16:51:33 +0100563 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100564 }
565
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100566 /*
567 * Some APs apparently get confused if our capabilities are better
568 * than theirs, so restrict what we advertise in the assoc request.
569 */
570 if (!(ap_vht_cap->vht_cap_info &
571 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
Sara Sharon322cd402015-07-08 15:41:43 +0300572 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
573 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
574 else if (!(ap_vht_cap->vht_cap_info &
575 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
576 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
577
578 /*
579 * If some other vif is using the MU-MIMO capablity we cannot associate
580 * using MU-MIMO - this will lead to contradictions in the group-id
581 * mechanism.
582 * Ownership is defined since association request, in order to avoid
583 * simultaneous associations with MU-MIMO.
584 */
585 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
586 bool disable_mu_mimo = false;
587 struct ieee80211_sub_if_data *other;
588
589 list_for_each_entry_rcu(other, &local->interfaces, list) {
Sara Sharonb5a33d52016-02-16 12:48:18 +0200590 if (other->vif.mu_mimo_owner) {
Sara Sharon322cd402015-07-08 15:41:43 +0300591 disable_mu_mimo = true;
592 break;
593 }
594 }
595 if (disable_mu_mimo)
596 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
597 else
Sara Sharonb5a33d52016-02-16 12:48:18 +0200598 sdata->vif.mu_mimo_owner = true;
Sara Sharon322cd402015-07-08 15:41:43 +0300599 }
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100600
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200601 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
602
603 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
604 our_bf_sts = cap & mask;
605
606 if (ap_bf_sts < our_bf_sts) {
607 cap &= ~mask;
608 cap |= ap_bf_sts;
609 }
610
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000611 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000612 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000613 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
614}
615
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300616/* This function determines HE capability flags for the association
617 * and builds the IE.
618 */
619static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
620 struct sk_buff *skb,
621 struct ieee80211_supported_band *sband)
622{
623 u8 *pos;
624 const struct ieee80211_sta_he_cap *he_cap = NULL;
625 u8 he_cap_size;
626
627 he_cap = ieee80211_get_he_sta_cap(sband);
628 if (!he_cap)
629 return;
630
631 /*
632 * TODO: the 1 added is because this temporarily is under the EXTENSION
633 * IE. Get rid of it when it moves.
634 */
635 he_cap_size =
636 2 + 1 + sizeof(he_cap->he_cap_elem) +
637 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
638 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
639 he_cap->he_cap_elem.phy_cap_info);
640 pos = skb_put(skb, he_cap_size);
641 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
642}
643
Johannes Berg66e67e42012-01-20 13:55:27 +0100644static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
645{
646 struct ieee80211_local *local = sdata->local;
647 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
648 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
649 struct sk_buff *skb;
650 struct ieee80211_mgmt *mgmt;
Jouni Malinen4d9ec732019-02-15 02:14:33 +0200651 u8 *pos, qos_info, *ie_start;
Johannes Berg66e67e42012-01-20 13:55:27 +0100652 size_t offset = 0, noffset;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200653 int i, count, rates_len, supp_rates_len, shift;
Johannes Berg66e67e42012-01-20 13:55:27 +0100654 u16 capab;
655 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200656 struct ieee80211_chanctx_conf *chanctx_conf;
657 struct ieee80211_channel *chan;
Johannes Berg44f6d422017-06-10 13:52:44 +0300658 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100659
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200660 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +0100661
Johannes Berg55de9082012-07-26 17:24:39 +0200662 rcu_read_lock();
663 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
664 if (WARN_ON(!chanctx_conf)) {
665 rcu_read_unlock();
666 return;
667 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100668 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200669 rcu_read_unlock();
670 sband = local->hw.wiphy->bands[chan->band];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200671 shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg66e67e42012-01-20 13:55:27 +0100672
673 if (assoc_data->supp_rates_len) {
674 /*
675 * Get all rates supported by the device and the AP as
676 * some APs don't like getting a superset of their rates
677 * in the association request (e.g. D-Link DAP 1353 in
678 * b-only mode)...
679 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200680 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
681 assoc_data->supp_rates,
682 assoc_data->supp_rates_len,
683 &rates);
Johannes Berg66e67e42012-01-20 13:55:27 +0100684 } else {
685 /*
686 * In case AP not provide any supported rates information
687 * before association, we send information element(s) with
688 * all rates that we support.
689 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200690 rates_len = 0;
691 for (i = 0; i < sband->n_bitrates; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200692 rates |= BIT(i);
693 rates_len++;
694 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100695 }
696
697 skb = alloc_skb(local->hw.extra_tx_headroom +
698 sizeof(*mgmt) + /* bit too much but doesn't matter */
699 2 + assoc_data->ssid_len + /* SSID */
700 4 + rates_len + /* (extended) rates */
701 4 + /* power capability */
702 2 + 2 * sband->n_channels + /* supported channels */
703 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000704 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300705 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
706 sizeof(struct ieee80211_he_mcs_nss_supp) +
707 IEEE80211_HE_PPE_THRES_MAX_LEN +
Johannes Berg66e67e42012-01-20 13:55:27 +0100708 assoc_data->ie_len + /* extra IEs */
Jouni Malinen39404fe2016-10-27 00:42:05 +0300709 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
Johannes Berg66e67e42012-01-20 13:55:27 +0100710 9, /* WMM */
711 GFP_KERNEL);
712 if (!skb)
713 return;
714
715 skb_reserve(skb, local->hw.extra_tx_headroom);
716
717 capab = WLAN_CAPABILITY_ESS;
718
Johannes Berg57fbcce2016-04-12 15:56:15 +0200719 if (sband->band == NL80211_BAND_2GHZ) {
Johannes Bergea1b2b452015-06-02 20:15:49 +0200720 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
721 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
Johannes Berg66e67e42012-01-20 13:55:27 +0100722 }
723
724 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
725 capab |= WLAN_CAPABILITY_PRIVACY;
726
727 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg30686bf2015-06-02 21:39:54 +0200728 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
Johannes Berg66e67e42012-01-20 13:55:27 +0100729 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
730
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300731 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
732 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
733
Johannes Bergb080db52017-06-16 14:29:19 +0200734 mgmt = skb_put_zero(skb, 24);
Johannes Berg66e67e42012-01-20 13:55:27 +0100735 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
736 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
737 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
738
739 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
740 skb_put(skb, 10);
741 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
742 IEEE80211_STYPE_REASSOC_REQ);
743 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
744 mgmt->u.reassoc_req.listen_interval =
745 cpu_to_le16(local->hw.conf.listen_interval);
746 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
747 ETH_ALEN);
748 } else {
749 skb_put(skb, 4);
750 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
751 IEEE80211_STYPE_ASSOC_REQ);
752 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
753 mgmt->u.assoc_req.listen_interval =
754 cpu_to_le16(local->hw.conf.listen_interval);
755 }
756
757 /* SSID */
758 pos = skb_put(skb, 2 + assoc_data->ssid_len);
Jouni Malinen4d9ec732019-02-15 02:14:33 +0200759 ie_start = pos;
Johannes Berg66e67e42012-01-20 13:55:27 +0100760 *pos++ = WLAN_EID_SSID;
761 *pos++ = assoc_data->ssid_len;
762 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
763
764 /* add all rates which were marked to be used above */
765 supp_rates_len = rates_len;
766 if (supp_rates_len > 8)
767 supp_rates_len = 8;
768
769 pos = skb_put(skb, supp_rates_len + 2);
770 *pos++ = WLAN_EID_SUPP_RATES;
771 *pos++ = supp_rates_len;
772
773 count = 0;
774 for (i = 0; i < sband->n_bitrates; i++) {
775 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200776 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
777 5 * (1 << shift));
778 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100779 if (++count == 8)
780 break;
781 }
782 }
783
784 if (rates_len > count) {
785 pos = skb_put(skb, rates_len - count + 2);
786 *pos++ = WLAN_EID_EXT_SUPP_RATES;
787 *pos++ = rates_len - count;
788
789 for (i++; i < sband->n_bitrates; i++) {
790 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200791 int rate;
792 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
793 5 * (1 << shift));
794 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100795 }
796 }
797 }
798
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300799 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
800 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100801 pos = skb_put(skb, 4);
802 *pos++ = WLAN_EID_PWR_CAPABILITY;
803 *pos++ = 2;
804 *pos++ = 0; /* min tx power */
Simon Wunderlich0430c882013-07-08 16:55:55 +0200805 /* max tx power */
806 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300807 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100808
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300809 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100810 /* TODO: get this in reg domain format */
811 pos = skb_put(skb, 2 * sband->n_channels + 2);
812 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
813 *pos++ = 2 * sband->n_channels;
814 for (i = 0; i < sband->n_channels; i++) {
815 *pos++ = ieee80211_frequency_to_channel(
816 sband->channels[i].center_freq);
817 *pos++ = 1; /* one channel in the subband*/
818 }
819 }
820
Sara Sharoncaf56332019-01-16 23:03:25 +0200821 /* Set MBSSID support for HE AP if needed */
822 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
823 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len) {
824 struct element *elem;
825
826 /* we know it's writable, cast away the const */
827 elem = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
828 assoc_data->ie,
829 assoc_data->ie_len);
830
831 /* We can probably assume both always true */
832 if (elem && elem->datalen >= 3)
833 elem->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
834 }
835
Johannes Berg66e67e42012-01-20 13:55:27 +0100836 /* if present, add any custom IEs that go before HT */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200837 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100838 static const u8 before_ht[] = {
839 WLAN_EID_SSID,
840 WLAN_EID_SUPP_RATES,
841 WLAN_EID_EXT_SUPP_RATES,
842 WLAN_EID_PWR_CAPABILITY,
843 WLAN_EID_SUPPORTED_CHANNELS,
844 WLAN_EID_RSN,
845 WLAN_EID_QOS_CAPA,
846 WLAN_EID_RRM_ENABLED_CAPABILITIES,
847 WLAN_EID_MOBILITY_DOMAIN,
Johannes Berg8ed28742014-10-27 12:03:19 +0100848 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
849 WLAN_EID_RIC_DATA, /* reassoc only */
Johannes Berg66e67e42012-01-20 13:55:27 +0100850 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
851 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100852 static const u8 after_ric[] = {
853 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
854 WLAN_EID_HT_CAPABILITY,
855 WLAN_EID_BSS_COEX_2040,
Johannes Berga7f26d82017-08-05 11:44:32 +0300856 /* luckily this is almost always there */
Johannes Berg8ed28742014-10-27 12:03:19 +0100857 WLAN_EID_EXT_CAPABILITY,
858 WLAN_EID_QOS_TRAFFIC_CAPA,
859 WLAN_EID_TIM_BCAST_REQ,
860 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300861 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg8ed28742014-10-27 12:03:19 +0100862 WLAN_EID_VHT_CAPABILITY,
863 WLAN_EID_OPMODE_NOTIF,
864 };
865
866 noffset = ieee80211_ie_split_ric(assoc_data->ie,
867 assoc_data->ie_len,
868 before_ht,
869 ARRAY_SIZE(before_ht),
870 after_ric,
871 ARRAY_SIZE(after_ric),
872 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800873 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100874 offset = noffset;
875 }
876
Johannes Bergf2d9d272012-11-22 14:11:39 +0100877 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
878 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
879 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
880
Johannes Berga8243b72012-11-22 14:32:09 +0100881 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200882 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200883 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100884
Johannes Berg3de38022014-02-04 09:54:07 +0100885 /* if present, add any custom IEs that go before VHT */
886 if (assoc_data->ie_len) {
887 static const u8 before_vht[] = {
Johannes Berga7f26d82017-08-05 11:44:32 +0300888 /*
889 * no need to list the ones split off before HT
890 * or generated here
891 */
Johannes Berg3de38022014-02-04 09:54:07 +0100892 WLAN_EID_BSS_COEX_2040,
893 WLAN_EID_EXT_CAPABILITY,
894 WLAN_EID_QOS_TRAFFIC_CAPA,
895 WLAN_EID_TIM_BCAST_REQ,
896 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300897 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg3de38022014-02-04 09:54:07 +0100898 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100899
900 /* RIC already taken above, so no need to handle here anymore */
Johannes Berg3de38022014-02-04 09:54:07 +0100901 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
902 before_vht, ARRAY_SIZE(before_vht),
903 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800904 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg3de38022014-02-04 09:54:07 +0100905 offset = noffset;
906 }
907
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300908 /* if present, add any custom IEs that go before HE */
909 if (assoc_data->ie_len) {
910 static const u8 before_he[] = {
911 /*
912 * no need to list the ones split off before VHT
913 * or generated here
914 */
915 WLAN_EID_OPMODE_NOTIF,
916 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
917 /* 11ai elements */
918 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
919 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
920 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
921 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
922 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
923 /* TODO: add 11ah/11aj/11ak elements */
924 };
925
926 /* RIC already taken above, so no need to handle here anymore */
927 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
928 before_he, ARRAY_SIZE(before_he),
929 offset);
930 pos = skb_put(skb, noffset - offset);
931 memcpy(pos, assoc_data->ie + offset, noffset - offset);
932 offset = noffset;
933 }
934
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000935 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100936 ieee80211_add_vht_ie(sdata, skb, sband,
937 &assoc_data->ap_vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000938
Shaul Triebitzdc7eb0f2018-12-15 11:03:20 +0200939 /*
940 * If AP doesn't support HT, mark HE as disabled.
941 * If on the 5GHz band, make sure it supports VHT.
942 */
943 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
944 (sband->band == NL80211_BAND_5GHZ &&
945 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
946 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
947
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300948 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
949 ieee80211_add_he_ie(sdata, skb, sband);
950
951 /* if present, add any custom non-vendor IEs that go after HE */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200952 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100953 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
954 assoc_data->ie_len,
955 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800956 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100957 offset = noffset;
958 }
959
Johannes Berg76f03032012-03-08 15:02:05 +0100960 if (assoc_data->wmm) {
961 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200962 qos_info = ifmgd->uapsd_queues;
963 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100964 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
965 } else {
966 qos_info = 0;
967 }
968
Arik Nemtsov40b861a2014-07-17 17:14:23 +0300969 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
Johannes Berg66e67e42012-01-20 13:55:27 +0100970 }
971
972 /* add any remaining custom (i.e. vendor specific here) IEs */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200973 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100974 noffset = assoc_data->ie_len;
yuan linyub952f4d2017-06-18 22:52:04 +0800975 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100976 }
977
Jouni Malinen39404fe2016-10-27 00:42:05 +0300978 if (assoc_data->fils_kek_len &&
979 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
980 dev_kfree_skb(skb);
981 return;
982 }
983
Jouni Malinen4d9ec732019-02-15 02:14:33 +0200984 pos = skb_tail_pointer(skb);
985 kfree(ifmgd->assoc_req_ies);
986 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
987 ifmgd->assoc_req_ies_len = pos - ie_start;
988
Ilan Peerd4e36e52018-04-20 13:49:25 +0300989 drv_mgd_prepare_tx(local, sdata, 0);
Johannes Berga1845fc2012-06-27 13:18:36 +0200990
Johannes Berg66e67e42012-01-20 13:55:27 +0100991 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Johannes Berg30686bf2015-06-02 21:39:54 +0200992 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +0100993 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
994 IEEE80211_TX_INTFL_MLME_CONN_TX;
Johannes Berg66e67e42012-01-20 13:55:27 +0100995 ieee80211_tx_skb(sdata, skb);
996}
997
Kalle Valo572e0012009-02-10 17:09:31 +0200998void ieee80211_send_pspoll(struct ieee80211_local *local,
999 struct ieee80211_sub_if_data *sdata)
1000{
Kalle Valo572e0012009-02-10 17:09:31 +02001001 struct ieee80211_pspoll *pspoll;
1002 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +02001003
Kalle Valod8cd1892010-01-05 20:16:26 +02001004 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1005 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +02001006 return;
Kalle Valo572e0012009-02-10 17:09:31 +02001007
Kalle Valod8cd1892010-01-05 20:16:26 +02001008 pspoll = (struct ieee80211_pspoll *) skb->data;
1009 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +02001010
Johannes Berg62ae67b2009-11-18 18:42:05 +01001011 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1012 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +02001013}
1014
Johannes Berg965beda2009-04-16 13:17:24 +02001015void ieee80211_send_nullfunc(struct ieee80211_local *local,
1016 struct ieee80211_sub_if_data *sdata,
Johannes Berg076cdcb2015-09-24 16:14:55 +02001017 bool powersave)
Johannes Berg965beda2009-04-16 13:17:24 +02001018{
1019 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +02001020 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +05301021 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +02001022
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001023 /* Don't send NDPs when STA is connected HE */
1024 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1025 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
1026 return;
1027
Ben Caradoc-Davies7c181f42018-03-19 12:57:44 +13001028 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1029 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
Kalle Valod8cd1892010-01-05 20:16:26 +02001030 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +02001031 return;
1032
Kalle Valod8cd1892010-01-05 20:16:26 +02001033 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +02001034 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +02001035 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +02001036
Seth Forshee6c17b772013-02-11 11:21:07 -06001037 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1038 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Pontus Fuchsff40b422013-06-04 12:44:52 +02001039
Johannes Berg30686bf2015-06-02 21:39:54 +02001040 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Pontus Fuchsff40b422013-06-04 12:44:52 +02001041 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1042
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001043 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +05301044 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1045
Johannes Berg62ae67b2009-11-18 18:42:05 +01001046 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +02001047}
1048
Felix Fietkaud5242152010-01-08 18:06:26 +01001049static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1050 struct ieee80211_sub_if_data *sdata)
1051{
1052 struct sk_buff *skb;
1053 struct ieee80211_hdr *nullfunc;
1054 __le16 fc;
1055
1056 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1057 return;
1058
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001059 /* Don't send NDPs when connected HE */
1060 if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE))
1061 return;
1062
Felix Fietkaud5242152010-01-08 18:06:26 +01001063 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -07001064 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +01001065 return;
Joe Perchesd15b8452011-08-29 14:17:31 -07001066
Felix Fietkaud5242152010-01-08 18:06:26 +01001067 skb_reserve(skb, local->hw.extra_tx_headroom);
1068
Johannes Bergb080db52017-06-16 14:29:19 +02001069 nullfunc = skb_put_zero(skb, 30);
Felix Fietkaud5242152010-01-08 18:06:26 +01001070 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1071 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1072 nullfunc->frame_control = fc;
1073 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1074 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1075 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1076 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1077
1078 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1079 ieee80211_tx_skb(sdata, skb);
1080}
1081
Johannes Bergcc32abd2009-05-15 11:52:31 +02001082/* spectrum management related things */
1083static void ieee80211_chswitch_work(struct work_struct *work)
1084{
1085 struct ieee80211_sub_if_data *sdata =
1086 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Karl Beldan675a0b02013-03-25 16:26:57 +01001087 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001088 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001089 int ret;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001090
Johannes Berg9607e6b662009-12-23 13:15:31 +01001091 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +02001092 return;
1093
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001094 sdata_lock(sdata);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001095 mutex_lock(&local->mtx);
1096 mutex_lock(&local->chanctx_mtx);
1097
Johannes Berg77fdaa12009-07-07 03:45:17 +02001098 if (!ifmgd->associated)
1099 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001100
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001101 if (!sdata->vif.csa_active)
1102 goto out;
1103
1104 /*
1105 * using reservation isn't immediate as it may be deferred until later
1106 * with multi-vif. once reservation is complete it will re-schedule the
1107 * work with no reserved_chanctx so verify chandef to check if it
1108 * completed successfully
1109 */
1110
1111 if (sdata->reserved_chanctx) {
Ilan Peer0007e942018-08-31 11:31:10 +03001112 struct ieee80211_supported_band *sband = NULL;
1113 struct sta_info *mgd_sta = NULL;
1114 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
1115
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001116 /*
1117 * with multi-vif csa driver may call ieee80211_csa_finish()
1118 * many times while waiting for other interfaces to use their
1119 * reservations
1120 */
1121 if (sdata->reserved_ready)
1122 goto out;
1123
Ilan Peer0007e942018-08-31 11:31:10 +03001124 if (sdata->vif.bss_conf.chandef.width !=
1125 sdata->csa_chandef.width) {
1126 /*
1127 * For managed interface, we need to also update the AP
1128 * station bandwidth and align the rate scale algorithm
1129 * on the bandwidth change. Here we only consider the
1130 * bandwidth of the new channel definition (as channel
1131 * switch flow does not have the full HT/VHT/HE
1132 * information), assuming that if additional changes are
1133 * required they would be done as part of the processing
1134 * of the next beacon from the AP.
1135 */
1136 switch (sdata->csa_chandef.width) {
1137 case NL80211_CHAN_WIDTH_20_NOHT:
1138 case NL80211_CHAN_WIDTH_20:
1139 default:
1140 bw = IEEE80211_STA_RX_BW_20;
1141 break;
1142 case NL80211_CHAN_WIDTH_40:
1143 bw = IEEE80211_STA_RX_BW_40;
1144 break;
1145 case NL80211_CHAN_WIDTH_80:
1146 bw = IEEE80211_STA_RX_BW_80;
1147 break;
1148 case NL80211_CHAN_WIDTH_80P80:
1149 case NL80211_CHAN_WIDTH_160:
1150 bw = IEEE80211_STA_RX_BW_160;
1151 break;
1152 }
1153
1154 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1155 sband =
1156 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1157 }
1158
1159 if (sdata->vif.bss_conf.chandef.width >
1160 sdata->csa_chandef.width) {
1161 mgd_sta->sta.bandwidth = bw;
1162 rate_control_rate_update(local, sband, mgd_sta,
1163 IEEE80211_RC_BW_CHANGED);
1164 }
1165
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001166 ret = ieee80211_vif_use_reserved_context(sdata);
1167 if (ret) {
1168 sdata_info(sdata,
1169 "failed to use reserved channel context, disconnecting (err=%d)\n",
1170 ret);
1171 ieee80211_queue_work(&sdata->local->hw,
1172 &ifmgd->csa_connection_drop_work);
1173 goto out;
1174 }
1175
Ilan Peer0007e942018-08-31 11:31:10 +03001176 if (sdata->vif.bss_conf.chandef.width <
1177 sdata->csa_chandef.width) {
1178 mgd_sta->sta.bandwidth = bw;
1179 rate_control_rate_update(local, sband, mgd_sta,
1180 IEEE80211_RC_BW_CHANGED);
1181 }
1182
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001183 goto out;
1184 }
1185
1186 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1187 &sdata->csa_chandef)) {
Arik Nemtsov7578d572013-09-01 17:15:51 +03001188 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001189 "failed to finalize channel switch, disconnecting\n");
Arik Nemtsov7578d572013-09-01 17:15:51 +03001190 ieee80211_queue_work(&sdata->local->hw,
1191 &ifmgd->csa_connection_drop_work);
1192 goto out;
1193 }
Karl Beldan675a0b02013-03-25 16:26:57 +01001194
Luciano Coelho0c21e632014-10-08 09:48:39 +03001195 ifmgd->csa_waiting_bcn = true;
Luciano Coelhof1d65582014-10-08 09:48:38 +03001196
Michal Kaziore5593f52014-04-09 15:45:36 +02001197 ieee80211_sta_reset_beacon_monitor(sdata);
1198 ieee80211_sta_reset_conn_monitor(sdata);
1199
Michal Kazior59af6922014-04-09 15:10:59 +02001200out:
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001201 mutex_unlock(&local->chanctx_mtx);
1202 mutex_unlock(&local->mtx);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001203 sdata_unlock(sdata);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001204}
1205
Luciano Coelho0c21e632014-10-08 09:48:39 +03001206static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1207{
1208 struct ieee80211_local *local = sdata->local;
1209 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1210 int ret;
1211
1212 sdata_assert_lock(sdata);
1213
1214 WARN_ON(!sdata->vif.csa_active);
1215
1216 if (sdata->csa_block_tx) {
1217 ieee80211_wake_vif_queues(local, sdata,
1218 IEEE80211_QUEUE_STOP_REASON_CSA);
1219 sdata->csa_block_tx = false;
1220 }
1221
1222 sdata->vif.csa_active = false;
1223 ifmgd->csa_waiting_bcn = false;
1224
1225 ret = drv_post_channel_switch(sdata);
1226 if (ret) {
1227 sdata_info(sdata,
1228 "driver post channel switch failed, disconnecting\n");
1229 ieee80211_queue_work(&local->hw,
1230 &ifmgd->csa_connection_drop_work);
1231 return;
1232 }
Luciano Coelho688b1ec2014-12-16 16:01:39 +02001233
1234 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
Luciano Coelho0c21e632014-10-08 09:48:39 +03001235}
1236
Johannes Berg5ce6e432010-05-11 16:20:57 +02001237void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1238{
Johannes Berg55de9082012-07-26 17:24:39 +02001239 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1240 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001241
1242 trace_api_chswitch_done(sdata, success);
1243 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001244 sdata_info(sdata,
1245 "driver channel switch failed, disconnecting\n");
1246 ieee80211_queue_work(&sdata->local->hw,
1247 &ifmgd->csa_connection_drop_work);
1248 } else {
1249 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001250 }
Johannes Berg5ce6e432010-05-11 16:20:57 +02001251}
1252EXPORT_SYMBOL(ieee80211_chswitch_done);
1253
Kees Cook34f11cd2017-10-16 16:35:49 -07001254static void ieee80211_chswitch_timer(struct timer_list *t)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001255{
1256 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07001257 from_timer(sdata, t, u.mgd.chswitch_timer);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001258
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01001259 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001260}
1261
Johannes Berg37799e52013-03-26 14:02:26 +01001262static void
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001263ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata)
1264{
1265 struct ieee80211_local *local = sdata->local;
1266
1267 if (!local->ops->abort_channel_switch)
1268 return;
1269
1270 mutex_lock(&local->mtx);
1271
1272 mutex_lock(&local->chanctx_mtx);
1273 ieee80211_vif_unreserve_chanctx(sdata);
1274 mutex_unlock(&local->chanctx_mtx);
1275
1276 if (sdata->csa_block_tx)
1277 ieee80211_wake_vif_queues(local, sdata,
1278 IEEE80211_QUEUE_STOP_REASON_CSA);
1279
1280 sdata->csa_block_tx = false;
1281 sdata->vif.csa_active = false;
1282
1283 mutex_unlock(&local->mtx);
1284
1285 drv_abort_channel_switch(sdata);
1286}
1287
1288static void
Johannes Berg4a3cb702013-02-12 16:43:19 +01001289ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03001290 u64 timestamp, u32 device_timestamp,
1291 struct ieee802_11_elems *elems,
Johannes Berg04a161f2013-05-03 09:35:35 +02001292 bool beacon)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001293{
Johannes Bergb4f286a12013-03-26 14:13:58 +01001294 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001295 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg37799e52013-03-26 14:02:26 +01001296 struct cfg80211_bss *cbss = ifmgd->associated;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001297 struct ieee80211_chanctx_conf *conf;
Johannes Berg55de9082012-07-26 17:24:39 +02001298 struct ieee80211_chanctx *chanctx;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001299 enum nl80211_band current_band;
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001300 struct ieee80211_csa_ie csa_ie;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001301 struct ieee80211_channel_switch ch_switch;
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001302 int res;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001303
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001304 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001305
Johannes Berg37799e52013-03-26 14:02:26 +01001306 if (!cbss)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001307 return;
1308
Johannes Bergb4f286a12013-03-26 14:13:58 +01001309 if (local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001310 return;
1311
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001312 current_band = cbss->channel->band;
Luciano Coelho84469a42014-10-28 13:33:04 +02001313 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001314 ifmgd->flags,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001315 ifmgd->associated->bssid, &csa_ie);
Sara Sharonfafd2bc2019-02-06 13:17:15 +02001316
1317 if (!res) {
1318 ch_switch.timestamp = timestamp;
1319 ch_switch.device_timestamp = device_timestamp;
Sara Sharon7976b1e2019-02-06 13:17:17 +02001320 ch_switch.block_tx = beacon ? csa_ie.mode : 0;
Sara Sharonfafd2bc2019-02-06 13:17:15 +02001321 ch_switch.chandef = csa_ie.chandef;
1322 ch_switch.count = csa_ie.count;
1323 ch_switch.delay = csa_ie.max_switch_time;
1324 }
1325
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001326 if (res < 0) {
Johannes Bergb4f286a12013-03-26 14:13:58 +01001327 ieee80211_queue_work(&local->hw,
Johannes Berg882a7c62012-08-01 22:32:45 +02001328 &ifmgd->csa_connection_drop_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001329 return;
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001330 }
1331
Sara Sharonfafd2bc2019-02-06 13:17:15 +02001332 if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) {
1333 if (res)
1334 ieee80211_sta_abort_chanswitch(sdata);
1335 else
1336 drv_channel_switch_rx_beacon(sdata, &ch_switch);
Sara Sharonb9cc81d2019-02-06 13:17:10 +02001337 return;
1338 } else if (sdata->vif.csa_active || res) {
1339 /* disregard subsequent announcements if already processing */
1340 return;
1341 }
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001342
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001343 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
Johannes Berg85220d72013-03-25 18:29:27 +01001344 IEEE80211_CHAN_DISABLED)) {
1345 sdata_info(sdata,
1346 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001347 ifmgd->associated->bssid,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001348 csa_ie.chandef.chan->center_freq,
1349 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1350 csa_ie.chandef.center_freq2);
Johannes Berg85220d72013-03-25 18:29:27 +01001351 ieee80211_queue_work(&local->hw,
1352 &ifmgd->csa_connection_drop_work);
1353 return;
1354 }
1355
Johannes Bergf84eaa12015-03-12 08:53:26 +02001356 if (cfg80211_chandef_identical(&csa_ie.chandef,
Sara Sharon97928752019-02-06 13:17:16 +02001357 &sdata->vif.bss_conf.chandef) &&
1358 (!csa_ie.mode || !beacon)) {
Johannes Bergf84eaa12015-03-12 08:53:26 +02001359 if (ifmgd->csa_ignored_same_chan)
1360 return;
1361 sdata_info(sdata,
1362 "AP %pM tries to chanswitch to same channel, ignore\n",
1363 ifmgd->associated->bssid);
1364 ifmgd->csa_ignored_same_chan = true;
1365 return;
1366 }
1367
Arik Nemtsovc5a71682015-05-19 14:36:48 +03001368 /*
1369 * Drop all TDLS peers - either we disconnect or move to a different
1370 * channel from this point on. There's no telling what our peer will do.
1371 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1372 * have an incompatible wider chandef.
1373 */
1374 ieee80211_teardown_tdls_peers(sdata);
1375
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001376 mutex_lock(&local->mtx);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001377 mutex_lock(&local->chanctx_mtx);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001378 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1379 lockdep_is_held(&local->chanctx_mtx));
1380 if (!conf) {
1381 sdata_info(sdata,
1382 "no channel context assigned to vif?, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001383 goto drop_connection;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001384 }
1385
1386 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1387
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001388 if (local->use_chanctx &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001389 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001390 sdata_info(sdata,
1391 "driver doesn't support chan-switch with channel contexts\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001392 goto drop_connection;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001393 }
1394
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001395 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1396 sdata_info(sdata,
1397 "preparing for channel switch failed, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001398 goto drop_connection;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001399 }
1400
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001401 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1402 chanctx->mode, false);
1403 if (res) {
Johannes Berg55de9082012-07-26 17:24:39 +02001404 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001405 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1406 res);
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001407 goto drop_connection;
Johannes Berg55de9082012-07-26 17:24:39 +02001408 }
Johannes Bergb4f286a12013-03-26 14:13:58 +01001409 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001410
Michal Kazior59af6922014-04-09 15:10:59 +02001411 sdata->vif.csa_active = true;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001412 sdata->csa_chandef = csa_ie.chandef;
Sara Sharon7976b1e2019-02-06 13:17:17 +02001413 sdata->csa_block_tx = ch_switch.block_tx;
Johannes Bergf84eaa12015-03-12 08:53:26 +02001414 ifmgd->csa_ignored_same_chan = false;
Michal Kazior59af6922014-04-09 15:10:59 +02001415
1416 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03001417 ieee80211_stop_vif_queues(local, sdata,
1418 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02001419 mutex_unlock(&local->mtx);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001420
Luciano Coelho2f457292014-11-07 14:31:36 +02001421 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1422 csa_ie.count);
1423
Johannes Bergb4f286a12013-03-26 14:13:58 +01001424 if (local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +02001425 /* use driver's channel switch callback */
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001426 drv_channel_switch(local, sdata, &ch_switch);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001427 return;
1428 }
1429
1430 /* channel switch handled in software */
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001431 if (csa_ie.count <= 1)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001432 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001433 else
Johannes Bergcc32abd2009-05-15 11:52:31 +02001434 mod_timer(&ifmgd->chswitch_timer,
Luciano Coelhoff1e4172014-10-28 13:33:05 +02001435 TU_TO_EXP_TIME((csa_ie.count - 1) *
1436 cbss->beacon_interval));
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001437 return;
1438 drop_connection:
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03001439 /*
1440 * This is just so that the disconnect flow will know that
1441 * we were trying to switch channel and failed. In case the
1442 * mode is 1 (we are not allowed to Tx), we will know not to
1443 * send a deauthentication frame. Those two fields will be
1444 * reset when the disconnection worker runs.
1445 */
1446 sdata->vif.csa_active = true;
Sara Sharon7976b1e2019-02-06 13:17:17 +02001447 sdata->csa_block_tx = ch_switch.block_tx;
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03001448
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001449 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1450 mutex_unlock(&local->chanctx_mtx);
1451 mutex_unlock(&local->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001452}
1453
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001454static bool
1455ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1456 struct ieee80211_channel *channel,
1457 const u8 *country_ie, u8 country_ie_len,
1458 const u8 *pwr_constr_elem,
1459 int *chan_pwr, int *pwr_reduction)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001460{
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001461 struct ieee80211_country_ie_triplet *triplet;
1462 int chan = ieee80211_frequency_to_channel(channel->center_freq);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001463 int i, chan_increment;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001464 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001465
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001466 /* Invalid IE */
1467 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001468 return false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001469
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001470 triplet = (void *)(country_ie + 3);
1471 country_ie_len -= 3;
1472
1473 switch (channel->band) {
1474 default:
1475 WARN_ON_ONCE(1);
1476 /* fall through */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001477 case NL80211_BAND_2GHZ:
1478 case NL80211_BAND_60GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001479 chan_increment = 1;
1480 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001481 case NL80211_BAND_5GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001482 chan_increment = 4;
1483 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001484 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001485
1486 /* find channel */
1487 while (country_ie_len >= 3) {
1488 u8 first_channel = triplet->chans.first_channel;
1489
1490 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1491 goto next;
1492
1493 for (i = 0; i < triplet->chans.num_channels; i++) {
1494 if (first_channel + i * chan_increment == chan) {
1495 have_chan_pwr = true;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001496 *chan_pwr = triplet->chans.max_power;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001497 break;
1498 }
1499 }
1500 if (have_chan_pwr)
1501 break;
1502
1503 next:
1504 triplet++;
1505 country_ie_len -= 3;
1506 }
1507
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001508 if (have_chan_pwr && pwr_constr_elem)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001509 *pwr_reduction = *pwr_constr_elem;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001510 else
1511 *pwr_reduction = 0;
1512
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001513 return have_chan_pwr;
1514}
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001515
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001516static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1517 struct ieee80211_channel *channel,
1518 const u8 *cisco_dtpc_ie,
1519 int *pwr_level)
1520{
1521 /* From practical testing, the first data byte of the DTPC element
1522 * seems to contain the requested dBm level, and the CLI on Cisco
1523 * APs clearly state the range is -127 to 127 dBm, which indicates
1524 * a signed byte, although it seemingly never actually goes negative.
1525 * The other byte seems to always be zero.
1526 */
1527 *pwr_level = (__s8)cisco_dtpc_ie[4];
1528}
1529
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001530static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1531 struct ieee80211_channel *channel,
1532 struct ieee80211_mgmt *mgmt,
1533 const u8 *country_ie, u8 country_ie_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001534 const u8 *pwr_constr_ie,
1535 const u8 *cisco_dtpc_ie)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001536{
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001537 bool has_80211h_pwr = false, has_cisco_pwr = false;
1538 int chan_pwr = 0, pwr_reduction_80211h = 0;
1539 int pwr_level_cisco, pwr_level_80211h;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001540 int new_ap_level;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001541 __le16 capab = mgmt->u.probe_resp.capab_info;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001542
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001543 if (country_ie &&
1544 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1545 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001546 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1547 sdata, channel, country_ie, country_ie_len,
1548 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001549 pwr_level_80211h =
1550 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001551 }
1552
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001553 if (cisco_dtpc_ie) {
1554 ieee80211_find_cisco_dtpc(
1555 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1556 has_cisco_pwr = true;
1557 }
1558
1559 if (!has_80211h_pwr && !has_cisco_pwr)
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001560 return 0;
1561
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001562 /* If we have both 802.11h and Cisco DTPC, apply both limits
1563 * by picking the smallest of the two power levels advertised.
1564 */
1565 if (has_80211h_pwr &&
1566 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
Johannes Berga87da0c2015-12-08 16:04:37 +02001567 new_ap_level = pwr_level_80211h;
1568
1569 if (sdata->ap_power_level == new_ap_level)
1570 return 0;
1571
John Linvillecef2fc12015-03-31 10:49:14 -04001572 sdata_dbg(sdata,
1573 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1574 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1575 sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001576 } else { /* has_cisco_pwr is always true here. */
Johannes Berga87da0c2015-12-08 16:04:37 +02001577 new_ap_level = pwr_level_cisco;
1578
1579 if (sdata->ap_power_level == new_ap_level)
1580 return 0;
1581
John Linvillecef2fc12015-03-31 10:49:14 -04001582 sdata_dbg(sdata,
1583 "Limiting TX power to %d dBm as advertised by %pM\n",
1584 pwr_level_cisco, sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001585 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001586
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001587 sdata->ap_power_level = new_ap_level;
1588 if (__ieee80211_recalc_txpower(sdata))
1589 return BSS_CHANGED_TXPOWER;
1590 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001591}
1592
Johannes Berg965beda2009-04-16 13:17:24 +02001593/* powersave */
1594static void ieee80211_enable_ps(struct ieee80211_local *local,
1595 struct ieee80211_sub_if_data *sdata)
1596{
1597 struct ieee80211_conf *conf = &local->hw.conf;
1598
Johannes Bergd5edaed2009-04-22 23:02:51 +02001599 /*
1600 * If we are scanning right now then the parameters will
1601 * take effect when scan finishes.
1602 */
Helmut Schaafbe9c4292009-07-23 12:14:04 +02001603 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +02001604 return;
1605
Johannes Berg965beda2009-04-16 13:17:24 +02001606 if (conf->dynamic_ps_timeout > 0 &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001607 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001608 mod_timer(&local->dynamic_ps_timer, jiffies +
1609 msecs_to_jiffies(conf->dynamic_ps_timeout));
1610 } else {
Johannes Berg30686bf2015-06-02 21:39:54 +02001611 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
Johannes Berg076cdcb2015-09-24 16:14:55 +02001612 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajan375177b2010-02-09 14:50:28 +05301613
Johannes Berg30686bf2015-06-02 21:39:54 +02001614 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1615 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001616 return;
1617
1618 conf->flags |= IEEE80211_CONF_PS;
1619 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +02001620 }
1621}
1622
1623static void ieee80211_change_ps(struct ieee80211_local *local)
1624{
1625 struct ieee80211_conf *conf = &local->hw.conf;
1626
1627 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +02001628 ieee80211_enable_ps(local, local->ps_sdata);
1629 } else if (conf->flags & IEEE80211_CONF_PS) {
1630 conf->flags &= ~IEEE80211_CONF_PS;
1631 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1632 del_timer_sync(&local->dynamic_ps_timer);
1633 cancel_work_sync(&local->dynamic_ps_enable_work);
1634 }
1635}
1636
Jason Young808118c2011-03-10 16:43:19 -08001637static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1638{
1639 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1640 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001641 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001642
1643 if (!mgd->powersave)
1644 return false;
1645
Johannes Berg05cb9102011-10-28 11:59:47 +02001646 if (mgd->broken_ap)
1647 return false;
1648
Jason Young808118c2011-03-10 16:43:19 -08001649 if (!mgd->associated)
1650 return false;
1651
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001652 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
Jason Young808118c2011-03-10 16:43:19 -08001653 return false;
1654
Alexander Bondar989c6502013-05-16 17:34:17 +03001655 if (!mgd->have_beacon)
Alexander Bondarce857882013-05-06 17:17:04 +03001656 return false;
1657
Jason Young808118c2011-03-10 16:43:19 -08001658 rcu_read_lock();
1659 sta = sta_info_get(sdata, mgd->bssid);
1660 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001661 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001662 rcu_read_unlock();
1663
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001664 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001665}
1666
Johannes Berg965beda2009-04-16 13:17:24 +02001667/* need to hold RTNL or interface lock */
Johannes Berg4a733ef2015-10-14 18:02:43 +02001668void ieee80211_recalc_ps(struct ieee80211_local *local)
Johannes Berg965beda2009-04-16 13:17:24 +02001669{
1670 struct ieee80211_sub_if_data *sdata, *found = NULL;
1671 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001672 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001673
Johannes Berg30686bf2015-06-02 21:39:54 +02001674 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001675 local->ps_sdata = NULL;
1676 return;
1677 }
1678
1679 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b662009-12-23 13:15:31 +01001680 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001681 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301682 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1683 /* If an AP vif is found, then disable PS
1684 * by setting the count to zero thereby setting
1685 * ps_sdata to NULL.
1686 */
1687 count = 0;
1688 break;
1689 }
Johannes Berg965beda2009-04-16 13:17:24 +02001690 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1691 continue;
1692 found = sdata;
1693 count++;
1694 }
1695
Jason Young808118c2011-03-10 16:43:19 -08001696 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg4a733ef2015-10-14 18:02:43 +02001697 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg10f644a2009-04-16 13:17:25 +02001698
Juuso Oikarinenff616382010-06-09 09:51:52 +03001699 timeout = local->dynamic_ps_forced_timeout;
Johannes Berg4a733ef2015-10-14 18:02:43 +02001700 if (timeout < 0)
1701 timeout = 100;
Johannes Berg09b85562013-02-06 23:07:41 +01001702 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001703
Johannes Berg4a733ef2015-10-14 18:02:43 +02001704 /* If the TIM IE is invalid, pretend the value is 1 */
1705 if (!dtimper)
1706 dtimper = 1;
Johannes Berg56007a02010-01-26 14:19:52 +01001707
Johannes Berg4a733ef2015-10-14 18:02:43 +02001708 local->hw.conf.ps_dtim_period = dtimper;
1709 local->ps_sdata = found;
Johannes Berg10f644a2009-04-16 13:17:25 +02001710 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001711 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001712 }
Johannes Berg965beda2009-04-16 13:17:24 +02001713
1714 ieee80211_change_ps(local);
1715}
1716
Eliad Pellerab095872012-07-27 12:33:22 +03001717void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1718{
1719 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1720
1721 if (sdata->vif.bss_conf.ps != ps_allowed) {
1722 sdata->vif.bss_conf.ps = ps_allowed;
1723 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1724 }
1725}
1726
Johannes Berg965beda2009-04-16 13:17:24 +02001727void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1728{
1729 struct ieee80211_local *local =
1730 container_of(work, struct ieee80211_local,
1731 dynamic_ps_disable_work);
1732
1733 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1734 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1735 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1736 }
1737
1738 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001739 IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +03001740 IEEE80211_QUEUE_STOP_REASON_PS,
1741 false);
Johannes Berg965beda2009-04-16 13:17:24 +02001742}
1743
1744void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1745{
1746 struct ieee80211_local *local =
1747 container_of(work, struct ieee80211_local,
1748 dynamic_ps_enable_work);
1749 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001750 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301751 unsigned long flags;
1752 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001753
1754 /* can only happen when PS was just disabled anyway */
1755 if (!sdata)
1756 return;
1757
Christian Lamparter5e340692011-06-30 21:08:43 +02001758 ifmgd = &sdata->u.mgd;
1759
Johannes Berg965beda2009-04-16 13:17:24 +02001760 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1761 return;
1762
Johannes Berg09b85562013-02-06 23:07:41 +01001763 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001764 /* don't enter PS if TX frames are pending */
1765 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301766 mod_timer(&local->dynamic_ps_timer, jiffies +
1767 msecs_to_jiffies(
1768 local->hw.conf.dynamic_ps_timeout));
1769 return;
1770 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001771
1772 /*
1773 * transmission can be stopped by others which leads to
1774 * dynamic_ps_timer expiry. Postpone the ps timer if it
1775 * is not the actual idle state.
1776 */
1777 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1778 for (q = 0; q < local->hw.queues; q++) {
1779 if (local->queue_stop_reasons[q]) {
1780 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1781 flags);
1782 mod_timer(&local->dynamic_ps_timer, jiffies +
1783 msecs_to_jiffies(
1784 local->hw.conf.dynamic_ps_timeout));
1785 return;
1786 }
1787 }
1788 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301789 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301790
Johannes Berg30686bf2015-06-02 21:39:54 +02001791 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301792 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Johannes Berga15983832013-03-26 22:02:42 +01001793 if (drv_tx_frames_pending(local)) {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301794 mod_timer(&local->dynamic_ps_timer, jiffies +
1795 msecs_to_jiffies(
1796 local->hw.conf.dynamic_ps_timeout));
Johannes Berga15983832013-03-26 22:02:42 +01001797 } else {
Johannes Berg076cdcb2015-09-24 16:14:55 +02001798 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301799 /* Flush to get the tx status of nullfunc frame */
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001800 ieee80211_flush_queues(local, sdata, false);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301801 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301802 }
1803
Johannes Berg30686bf2015-06-02 21:39:54 +02001804 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1805 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301806 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1807 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1808 local->hw.conf.flags |= IEEE80211_CONF_PS;
1809 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1810 }
Johannes Berg965beda2009-04-16 13:17:24 +02001811}
1812
Kees Cook34f11cd2017-10-16 16:35:49 -07001813void ieee80211_dynamic_ps_timer(struct timer_list *t)
Johannes Berg965beda2009-04-16 13:17:24 +02001814{
Kees Cook34f11cd2017-10-16 16:35:49 -07001815 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
Johannes Berg965beda2009-04-16 13:17:24 +02001816
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001817 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001818}
1819
Simon Wunderlich164eb022013-02-08 18:16:20 +01001820void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1821{
Geliang Tanga85a7e22016-01-01 23:48:52 +08001822 struct delayed_work *delayed_work = to_delayed_work(work);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001823 struct ieee80211_sub_if_data *sdata =
1824 container_of(delayed_work, struct ieee80211_sub_if_data,
1825 dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001826 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlich164eb022013-02-08 18:16:20 +01001827
Johannes Berg34a37402013-12-18 09:43:33 +01001828 mutex_lock(&sdata->local->mtx);
1829 if (sdata->wdev.cac_started) {
1830 ieee80211_vif_release_channel(sdata);
1831 cfg80211_cac_event(sdata->dev, &chandef,
1832 NL80211_RADAR_CAC_FINISHED,
1833 GFP_KERNEL);
1834 }
1835 mutex_unlock(&sdata->local->mtx);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001836}
1837
Johannes Berg02219b32014-10-07 10:38:50 +03001838static bool
1839__ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1840{
1841 struct ieee80211_local *local = sdata->local;
1842 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
John Linvillecc72f6e2015-01-06 14:39:33 -05001843 bool ret = false;
Johannes Berg02219b32014-10-07 10:38:50 +03001844 int ac;
1845
1846 if (local->hw.queues < IEEE80211_NUM_ACS)
1847 return false;
1848
1849 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1850 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1851 int non_acm_ac;
1852 unsigned long now = jiffies;
1853
1854 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1855 tx_tspec->admitted_time &&
1856 time_after(now, tx_tspec->time_slice_start + HZ)) {
1857 tx_tspec->consumed_tx_time = 0;
1858 tx_tspec->time_slice_start = now;
1859
1860 if (tx_tspec->downgraded)
1861 tx_tspec->action =
1862 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1863 }
1864
1865 switch (tx_tspec->action) {
1866 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1867 /* take the original parameters */
1868 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1869 sdata_err(sdata,
1870 "failed to set TX queue parameters for queue %d\n",
1871 ac);
1872 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1873 tx_tspec->downgraded = false;
1874 ret = true;
1875 break;
1876 case TX_TSPEC_ACTION_DOWNGRADE:
1877 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1878 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1879 ret = true;
1880 break;
1881 }
1882 /* downgrade next lower non-ACM AC */
1883 for (non_acm_ac = ac + 1;
1884 non_acm_ac < IEEE80211_NUM_ACS;
1885 non_acm_ac++)
1886 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1887 break;
Johannes Berg93db1d92016-09-14 09:23:51 +02001888 /* Usually the loop will result in using BK even if it
1889 * requires admission control, but such a configuration
1890 * makes no sense and we have to transmit somehow - the
1891 * AC selection does the same thing.
1892 * If we started out trying to downgrade from BK, then
1893 * the extra condition here might be needed.
Johannes Berg02219b32014-10-07 10:38:50 +03001894 */
Johannes Berg93db1d92016-09-14 09:23:51 +02001895 if (non_acm_ac >= IEEE80211_NUM_ACS)
1896 non_acm_ac = IEEE80211_AC_BK;
Johannes Berg02219b32014-10-07 10:38:50 +03001897 if (drv_conf_tx(local, sdata, ac,
1898 &sdata->tx_conf[non_acm_ac]))
1899 sdata_err(sdata,
1900 "failed to set TX queue parameters for queue %d\n",
1901 ac);
1902 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1903 ret = true;
1904 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1905 tx_tspec->time_slice_start + HZ - now + 1);
1906 break;
1907 case TX_TSPEC_ACTION_NONE:
1908 /* nothing now */
1909 break;
1910 }
1911 }
1912
1913 return ret;
1914}
1915
1916void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1917{
1918 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1919 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1920}
1921
1922static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1923{
1924 struct ieee80211_sub_if_data *sdata;
1925
1926 sdata = container_of(work, struct ieee80211_sub_if_data,
1927 u.mgd.tx_tspec_wk.work);
1928 ieee80211_sta_handle_tspec_ac_params(sdata);
1929}
1930
Johannes Berg60f8b39c2008-09-08 17:44:22 +02001931/* MLME */
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001932static bool
1933ieee80211_sta_wmm_params(struct ieee80211_local *local,
1934 struct ieee80211_sub_if_data *sdata,
1935 const u8 *wmm_param, size_t wmm_param_len,
1936 const struct ieee80211_mu_edca_param_set *mu_edca)
Jiri Bencf0706e82007-05-05 11:45:53 -07001937{
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001938 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
Johannes Berg4ced3f72010-07-19 16:39:04 +02001939 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001940 size_t left;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001941 int count, mu_edca_count, ac;
Johannes Berg4a3cb702013-02-12 16:43:19 +01001942 const u8 *pos;
1943 u8 uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001944
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001945 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001946 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001947
Johannes Berg32c50572012-03-28 11:04:29 +02001948 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001949 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001950
1951 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001952 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001953
Jiri Bencf0706e82007-05-05 11:45:53 -07001954 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001955 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001956
1957 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001958 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001959
Jiri Bencf0706e82007-05-05 11:45:53 -07001960 count = wmm_param[6] & 0x0f;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001961 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
1962 * if mu_edca was preset before and now it disappeared tell
1963 * the driver about it.
1964 */
1965 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
1966 if (count == ifmgd->wmm_last_param_set &&
1967 mu_edca_count == ifmgd->mu_edca_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001968 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001969 ifmgd->wmm_last_param_set = count;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001970 ifmgd->mu_edca_last_param_set = mu_edca_count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001971
1972 pos = wmm_param + 8;
1973 left = wmm_param_len - 8;
1974
1975 memset(&params, 0, sizeof(params));
1976
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001977 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001978 for (; left >= 4; left -= 4, pos += 4) {
1979 int aci = (pos[0] >> 5) & 0x03;
1980 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001981 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001982
1983 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001984 case 1: /* AC_BK */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001985 ac = IEEE80211_AC_BK;
Johannes Berg988c0f72008-04-17 19:21:22 +02001986 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001987 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001988 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1989 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001990 params[ac].mu_edca = !!mu_edca;
1991 if (mu_edca)
1992 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
Jiri Bencf0706e82007-05-05 11:45:53 -07001993 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001994 case 2: /* AC_VI */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001995 ac = IEEE80211_AC_VI;
Johannes Berg988c0f72008-04-17 19:21:22 +02001996 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001997 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001998 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1999 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03002000 params[ac].mu_edca = !!mu_edca;
2001 if (mu_edca)
2002 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
Jiri Bencf0706e82007-05-05 11:45:53 -07002003 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02002004 case 3: /* AC_VO */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002005 ac = IEEE80211_AC_VO;
Johannes Berg988c0f72008-04-17 19:21:22 +02002006 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03002007 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02002008 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2009 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03002010 params[ac].mu_edca = !!mu_edca;
2011 if (mu_edca)
2012 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
Jiri Bencf0706e82007-05-05 11:45:53 -07002013 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02002014 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07002015 default:
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002016 ac = IEEE80211_AC_BE;
Johannes Berg988c0f72008-04-17 19:21:22 +02002017 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03002018 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02002019 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
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_be;
Jiri Bencf0706e82007-05-05 11:45:53 -07002024 break;
2025 }
2026
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002027 params[ac].aifs = pos[0] & 0x0f;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02002028
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002029 if (params[ac].aifs < 2) {
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02002030 sdata_info(sdata,
2031 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002032 params[ac].aifs, aci);
2033 params[ac].aifs = 2;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02002034 }
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002035 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2036 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2037 params[ac].txop = get_unaligned_le16(pos + 2);
2038 params[ac].acm = acm;
2039 params[ac].uapsd = uapsd;
Kalle Valoab133152010-01-12 10:42:31 +02002040
Ilan Peer911a2642018-04-03 11:35:22 +03002041 if (params[ac].cw_min == 0 ||
Emmanuel Grumbachc470bdc2018-03-26 16:21:04 +03002042 params[ac].cw_min > params[ac].cw_max) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002043 sdata_info(sdata,
2044 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2045 params[ac].cw_min, params[ac].cw_max, aci);
2046 return false;
2047 }
Haim Dreyfusse552af02018-03-28 13:24:10 +03002048 ieee80211_regulatory_limit_wmm_params(sdata, &params[ac], ac);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002049 }
2050
Brian Norris05aaa5c2019-07-26 15:47:58 -07002051 /* WMM specification requires all 4 ACIs. */
2052 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2053 if (params[ac].cw_min == 0) {
2054 sdata_info(sdata,
2055 "AP has invalid WMM params (missing AC %d), using defaults\n",
2056 ac);
2057 return false;
2058 }
2059 }
2060
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002061 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002062 mlme_dbg(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002063 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2064 ac, params[ac].acm,
2065 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2066 params[ac].txop, params[ac].uapsd,
2067 ifmgd->tx_tspec[ac].downgraded);
2068 sdata->tx_conf[ac] = params[ac];
2069 if (!ifmgd->tx_tspec[ac].downgraded &&
2070 drv_conf_tx(local, sdata, ac, &params[ac]))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002071 sdata_err(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002072 "failed to set TX queue parameters for AC %d\n",
2073 ac);
Jiri Bencf0706e82007-05-05 11:45:53 -07002074 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02002075
2076 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02002077 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02002078 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07002079}
2080
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002081static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2082{
2083 lockdep_assert_held(&sdata->local->mtx);
2084
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002085 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002086 ieee80211_run_deferred_scan(sdata->local);
2087}
2088
2089static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2090{
2091 mutex_lock(&sdata->local->mtx);
2092 __ieee80211_stop_poll(sdata);
2093 mutex_unlock(&sdata->local->mtx);
2094}
2095
Johannes Berg7a5158e2008-10-08 10:59:33 +02002096static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2097 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02002098{
Johannes Bergbda39332008-10-11 01:51:51 +02002099 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302100 struct ieee80211_supported_band *sband;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002101 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002102 bool use_protection;
2103 bool use_short_preamble;
2104 bool use_short_slot;
2105
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302106 sband = ieee80211_get_sband(sdata);
2107 if (!sband)
2108 return changed;
2109
Johannes Berg7a5158e2008-10-08 10:59:33 +02002110 if (erp_valid) {
2111 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2112 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2113 } else {
2114 use_protection = false;
2115 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2116 }
2117
2118 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302119 if (sband->band == NL80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01002120 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02002121
Johannes Berg471b3ef2007-12-28 14:32:58 +01002122 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01002123 bss_conf->use_cts_prot = use_protection;
2124 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02002125 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02002126
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002127 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002128 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002129 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02002130 }
Daniel Draked9430a32007-07-27 15:43:24 +02002131
Johannes Berg7a5158e2008-10-08 10:59:33 +02002132 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02002133 bss_conf->use_short_slot = use_short_slot;
2134 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04002135 }
2136
2137 return changed;
2138}
2139
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002140static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002141 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02002142 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07002143{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002144 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002145 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002146 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002147
Johannes Bergae5eb022008-10-14 16:58:37 +02002148 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002149 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03002150 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002151
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002152 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
Ben Greear59c1ec22013-03-19 14:19:56 -07002153 beacon_loss_count * bss_conf->beacon_int));
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002154
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002155 sdata->u.mgd.associated = cbss;
2156 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002157
Johannes Berge8e4f522017-03-08 11:12:10 +01002158 ieee80211_check_rate_mask(sdata);
2159
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002160 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2161
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01002162 if (sdata->vif.p2p ||
2163 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002164 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01002165
Johannes Berg9caf0362012-11-29 01:25:20 +01002166 rcu_read_lock();
2167 ies = rcu_dereference(cbss->ies);
2168 if (ies) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002169 int ret;
2170
2171 ret = cfg80211_get_p2p_attr(
2172 ies->data, ies->len,
2173 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002174 (u8 *) &bss_conf->p2p_noa_attr,
2175 sizeof(bss_conf->p2p_noa_attr));
Johannes Berg9caf0362012-11-29 01:25:20 +01002176 if (ret >= 2) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002177 sdata->u.mgd.p2p_noa_index =
2178 bss_conf->p2p_noa_attr.index;
Johannes Berg9caf0362012-11-29 01:25:20 +01002179 bss_info_changed |= BSS_CHANGED_P2P_PS;
Johannes Berg9caf0362012-11-29 01:25:20 +01002180 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01002181 }
Johannes Berg9caf0362012-11-29 01:25:20 +01002182 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01002183 }
2184
Johannes Bergb291ba12009-07-10 15:29:03 +02002185 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002186 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002187
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002188 ieee80211_led_assoc(local, 1);
2189
Alexander Bondar989c6502013-05-16 17:34:17 +03002190 if (sdata->u.mgd.have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02002191 /*
2192 * If the AP is buggy we may get here with no DTIM period
2193 * known, so assume it's 1 which is the only safe assumption
2194 * in that case, although if the TIM IE is broken powersave
2195 * probably just won't work at all.
2196 */
2197 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Alexander Bondar817cee72013-05-19 14:23:57 +03002198 bss_conf->beacon_rate = bss->beacon_rate;
Alexander Bondar989c6502013-05-16 17:34:17 +03002199 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
Johannes Berg826262c2012-12-10 16:38:14 +02002200 } else {
Alexander Bondar817cee72013-05-19 14:23:57 +03002201 bss_conf->beacon_rate = NULL;
Johannes Berge5b900d2010-07-29 16:08:55 +02002202 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02002203 }
Johannes Berge5b900d2010-07-29 16:08:55 +02002204
Juuso Oikarinen68542962010-06-09 13:43:26 +03002205 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02002206
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002207 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01002208 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03002209 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002210 bss_info_changed |= BSS_CHANGED_CQM;
2211
Juuso Oikarinen68542962010-06-09 13:43:26 +03002212 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002213 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002214 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002215
Johannes Bergae5eb022008-10-14 16:58:37 +02002216 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03002217
Johannes Berg056508d2009-07-30 21:43:55 +02002218 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002219 ieee80211_recalc_ps(local);
Johannes Berg056508d2009-07-30 21:43:55 +02002220 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02002221
Johannes Berg04ecd252012-09-11 14:34:12 +02002222 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03002223 ieee80211_recalc_ps_vif(sdata);
2224
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002225 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07002226}
2227
Jouni Malinene69e95d2010-03-29 23:29:31 -07002228static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01002229 u16 stype, u16 reason, bool tx,
2230 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03002231{
Johannes Berg46900292009-02-15 12:44:28 +01002232 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002233 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01002234 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002235
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002236 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002237
Johannes Berg37ad3882012-02-24 13:50:54 +01002238 if (WARN_ON_ONCE(tx && !frame_buf))
2239 return;
2240
Johannes Bergb291ba12009-07-10 15:29:03 +02002241 if (WARN_ON(!ifmgd->associated))
2242 return;
2243
David Spinadel79543d82012-06-12 09:59:45 +03002244 ieee80211_stop_poll(sdata);
2245
Johannes Berg77fdaa12009-07-07 03:45:17 +02002246 ifmgd->associated = NULL;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002247 netif_carrier_off(sdata->dev);
2248
Eliad Peller88bc40e2012-07-12 17:35:33 +03002249 /*
2250 * if we want to get out of ps before disassoc (why?) we have
2251 * to do it before sending disassoc, as otherwise the null-packet
2252 * won't be valid.
2253 */
2254 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2255 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2256 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2257 }
2258 local->ps_sdata = NULL;
2259
Eliad Pellerab095872012-07-27 12:33:22 +03002260 /* disable per-vif ps */
2261 ieee80211_recalc_ps_vif(sdata);
2262
Emmanuel Grumbach14f2ae82015-01-22 23:30:19 +02002263 /* make sure ongoing transmission finishes */
2264 synchronize_net();
2265
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002266 /*
2267 * drop any frame before deauth/disassoc, this can be data or
2268 * management frame. Since we are disconnecting, we should not
2269 * insist sending these frames which can take time and delay
2270 * the disconnection and possible the roaming.
2271 */
Eliad Pellerf8239812012-06-27 14:18:22 +03002272 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002273 ieee80211_flush_queues(local, sdata, true);
Eliad Pellerf8239812012-06-27 14:18:22 +03002274
Johannes Berg37ad3882012-02-24 13:50:54 +01002275 /* deauthenticate/disassociate now */
Ilan Peer94ba9272018-02-19 14:48:41 +02002276 if (tx || frame_buf) {
Ilan Peer94ba9272018-02-19 14:48:41 +02002277 /*
2278 * In multi channel scenarios guarantee that the virtual
2279 * interface is granted immediate airtime to transmit the
2280 * deauthentication frame by calling mgd_prepare_tx, if the
2281 * driver requested so.
2282 */
2283 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2284 !ifmgd->have_beacon)
Ilan Peerd4e36e52018-04-20 13:49:25 +03002285 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Ilan Peer94ba9272018-02-19 14:48:41 +02002286
Johannes Berg4b08d1b2019-08-30 14:24:51 +03002287 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid,
2288 ifmgd->bssid, stype, reason,
2289 tx, frame_buf);
Ilan Peer94ba9272018-02-19 14:48:41 +02002290 }
Johannes Berg37ad3882012-02-24 13:50:54 +01002291
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002292 /* flush out frame - make sure the deauth was actually sent */
Johannes Berg37ad3882012-02-24 13:50:54 +01002293 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002294 ieee80211_flush_queues(local, sdata, false);
Johannes Berg37ad3882012-02-24 13:50:54 +01002295
Eliad Peller88a9e312012-06-01 11:14:03 +03002296 /* clear bssid only after building the needed mgmt frames */
Joe Perchesc84a67a2015-03-02 19:54:57 -08002297 eth_zero_addr(ifmgd->bssid);
Eliad Peller88a9e312012-06-01 11:14:03 +03002298
Johannes Berg37ad3882012-02-24 13:50:54 +01002299 /* remove AP and TDLS peers */
Johannes Bergd34ba212013-12-04 22:46:11 +01002300 sta_info_flush(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01002301
2302 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002303 changed |= ieee80211_reset_erp_info(sdata);
2304
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002305 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02002306 changed |= BSS_CHANGED_ASSOC;
2307 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002308
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002309 ifmgd->p2p_noa_index = -1;
2310 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2311 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01002312
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002313 /* on the next assoc, re-program HT/VHT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08002314 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2315 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002316 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2317 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
Sara Sharon23a1f8d2015-12-08 16:04:31 +02002318
2319 /* reset MU-MIMO ownership and group data */
2320 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2321 sizeof(sdata->vif.bss_conf.mu_group.membership));
2322 memset(sdata->vif.bss_conf.mu_group.position, 0,
2323 sizeof(sdata->vif.bss_conf.mu_group.position));
2324 changed |= BSS_CHANGED_MU_GROUPS;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002325 sdata->vif.mu_mimo_owner = false;
Johannes Berg413ad502009-05-08 21:21:06 +02002326
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002327 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05302328
Kalle Valo520eb822008-12-18 23:35:27 +02002329 del_timer_sync(&local->dynamic_ps_timer);
2330 cancel_work_sync(&local->dynamic_ps_enable_work);
2331
Juuso Oikarinen68542962010-06-09 13:43:26 +03002332 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002333 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002334 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002335
Johannes Berg3abead52012-03-02 15:56:59 +01002336 sdata->vif.bss_conf.qos = false;
2337 changed |= BSS_CHANGED_QOS;
2338
Johannes Berg0aaffa92010-05-05 15:28:27 +02002339 /* The BSSID (not really interesting) and HT changed */
2340 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02002341 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02002342
Johannes Berg3abead52012-03-02 15:56:59 +01002343 /* disassociated - set to defaults now */
Johannes Bergcec66282015-10-22 17:46:04 +02002344 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg3abead52012-03-02 15:56:59 +01002345
Johannes Bergb9dcf712010-08-27 12:35:54 +02002346 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2347 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2348 del_timer_sync(&sdata->u.mgd.timer);
2349 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02002350
Johannes Berg826262c2012-12-10 16:38:14 +02002351 sdata->vif.bss_conf.dtim_period = 0;
Alexander Bondar817cee72013-05-19 14:23:57 +03002352 sdata->vif.bss_conf.beacon_rate = NULL;
2353
Alexander Bondar989c6502013-05-16 17:34:17 +03002354 ifmgd->have_beacon = false;
Johannes Berg826262c2012-12-10 16:38:14 +02002355
Johannes Berg028e8da02012-11-26 11:57:41 +01002356 ifmgd->flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002357 mutex_lock(&local->mtx);
Johannes Berg028e8da02012-11-26 11:57:41 +01002358 ieee80211_vif_release_channel(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002359
2360 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002361 ifmgd->csa_waiting_bcn = false;
Johannes Bergf84eaa12015-03-12 08:53:26 +02002362 ifmgd->csa_ignored_same_chan = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002363 if (sdata->csa_block_tx) {
2364 ieee80211_wake_vif_queues(local, sdata,
2365 IEEE80211_QUEUE_STOP_REASON_CSA);
2366 sdata->csa_block_tx = false;
2367 }
Johannes Berg34a37402013-12-18 09:43:33 +01002368 mutex_unlock(&local->mtx);
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002369
Johannes Berg02219b32014-10-07 10:38:50 +03002370 /* existing TX TSPEC sessions no longer exist */
2371 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2372 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2373
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002374 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002375}
Jiri Bencf0706e82007-05-05 11:45:53 -07002376
Kalle Valo3cf335d52009-03-22 21:57:06 +02002377void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2378 struct ieee80211_hdr *hdr)
2379{
2380 /*
2381 * We can postpone the mgd.timer whenever receiving unicast frames
2382 * from AP because we know that the connection is working both ways
2383 * at that time. But multicast frames (and hence also beacons) must
2384 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02002385 * data idle periods for sending the periodic probe request to the
2386 * AP we're connected to.
Kalle Valo3cf335d52009-03-22 21:57:06 +02002387 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002388 if (is_multicast_ether_addr(hdr->addr1))
2389 return;
2390
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04002391 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d52009-03-22 21:57:06 +02002392}
Jiri Bencf0706e82007-05-05 11:45:53 -07002393
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002394static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2395{
2396 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002397 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002398
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002399 mutex_lock(&local->mtx);
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002400 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2401 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002402
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002403 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002404
2405 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002406 ieee80211_recalc_ps(local);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002407 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002408
Johannes Berg30686bf2015-06-02 21:39:54 +02002409 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002410 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002411
2412 /*
2413 * We've received a probe response, but are not sure whether
2414 * we have or will be receiving any beacons or data, so let's
2415 * schedule the timers again, just in case.
2416 */
2417 ieee80211_sta_reset_beacon_monitor(sdata);
2418
2419 mod_timer(&ifmgd->conn_mon_timer,
2420 round_jiffies_up(jiffies +
2421 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002422out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002423 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002424}
2425
Johannes Berg02219b32014-10-07 10:38:50 +03002426static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2427 struct ieee80211_hdr *hdr,
2428 u16 tx_time)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002429{
Johannes Berg02219b32014-10-07 10:38:50 +03002430 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Sara Sharona1f2ba04c2018-02-19 14:48:40 +02002431 u16 tid = ieee80211_get_tid(hdr);
Johannes Berg02219b32014-10-07 10:38:50 +03002432 int ac = ieee80211_ac_from_tid(tid);
2433 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2434 unsigned long now = jiffies;
2435
2436 if (likely(!tx_tspec->admitted_time))
2437 return;
2438
2439 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2440 tx_tspec->consumed_tx_time = 0;
2441 tx_tspec->time_slice_start = now;
2442
2443 if (tx_tspec->downgraded) {
2444 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2445 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2446 }
2447 }
2448
2449 if (tx_tspec->downgraded)
2450 return;
2451
2452 tx_tspec->consumed_tx_time += tx_time;
2453
2454 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2455 tx_tspec->downgraded = true;
2456 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2457 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2458 }
2459}
2460
2461void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2462 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2463{
2464 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2465
Felix Fietkau75706d02010-12-02 21:01:07 +01002466 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002467 return;
2468
Thomas Pedersen30b2f0b2020-01-13 21:59:40 -08002469 if (ieee80211_is_any_nullfunc(hdr->frame_control) &&
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002470 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002471 if (ack)
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002472 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002473 else
2474 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002475 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002476 return;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002477 }
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002478
2479 if (ack)
2480 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002481}
2482
Johannes Berg45ad6832018-05-28 15:47:39 +02002483static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2484 const u8 *src, const u8 *dst,
2485 const u8 *ssid, size_t ssid_len,
2486 struct ieee80211_channel *channel)
2487{
2488 struct sk_buff *skb;
2489
2490 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2491 ssid, ssid_len, NULL, 0,
2492 IEEE80211_PROBE_FLAG_DIRECTED);
2493 if (skb)
2494 ieee80211_tx_skb(sdata, skb);
2495}
2496
Maxim Levitskya43abf22009-07-31 18:54:12 +03002497static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2498{
2499 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2500 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002501 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08002502 u8 unicast_limit = max(1, max_probe_tries - 3);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002503 struct sta_info *sta;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002504
2505 /*
2506 * Try sending broadcast probe requests for the last three
2507 * probe requests after the first ones failed since some
2508 * buggy APs only support broadcast probe requests.
2509 */
2510 if (ifmgd->probe_send_count >= unicast_limit)
2511 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002512
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002513 /*
2514 * When the hardware reports an accurate Tx ACK status, it's
2515 * better to send a nullfunc frame instead of a probe request,
2516 * as it will kick us off the AP quickly if we aren't associated
2517 * anymore. The timeout will be reset if the frame is ACKed by
2518 * the AP.
2519 */
Soumik Das992e68b2012-05-20 15:31:13 +05302520 ifmgd->probe_send_count++;
2521
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002522 if (dst) {
2523 mutex_lock(&sdata->local->sta_mtx);
2524 sta = sta_info_get(sdata, dst);
2525 if (!WARN_ON(!sta))
2526 ieee80211_check_fast_rx(sta);
2527 mutex_unlock(&sdata->local->sta_mtx);
2528 }
2529
Johannes Berg30686bf2015-06-02 21:39:54 +02002530 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002531 ifmgd->nullfunc_failed = false;
Shay Barf39b07f2019-07-03 16:18:48 +03002532 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
2533 ifmgd->probe_send_count--;
2534 else
2535 ieee80211_send_nullfunc(sdata->local, sdata, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002536 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002537 int ssid_len;
2538
Johannes Berg9caf0362012-11-29 01:25:20 +01002539 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002540 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002541 if (WARN_ON_ONCE(ssid == NULL))
2542 ssid_len = 0;
2543 else
2544 ssid_len = ssid[1];
2545
Johannes Berg45ad6832018-05-28 15:47:39 +02002546 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2547 ssid + 2, ssid_len,
2548 ifmgd->associated->channel);
Johannes Berg9caf0362012-11-29 01:25:20 +01002549 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002550 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03002551
Ben Greear180205b2011-02-04 15:30:24 -08002552 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002553 run_again(sdata, ifmgd->probe_timeout);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002554}
2555
Johannes Bergb291ba12009-07-10 15:29:03 +02002556static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2557 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02002558{
Kalle Valo04de8382009-03-22 21:57:35 +02002559 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002560 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02002561
Johannes Berg9607e6b662009-12-23 13:15:31 +01002562 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02002563 return;
2564
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002565 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002566
2567 if (!ifmgd->associated)
2568 goto out;
2569
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002570 mutex_lock(&sdata->local->mtx);
2571
2572 if (sdata->local->tmp_channel || sdata->local->scanning) {
2573 mutex_unlock(&sdata->local->mtx);
2574 goto out;
2575 }
2576
Ben Greeara13fbe52013-03-25 11:19:35 -07002577 if (beacon) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002578 mlme_dbg_ratelimited(sdata,
Ben Greear59c1ec22013-03-19 14:19:56 -07002579 "detected beacon loss from AP (missed %d beacons) - probing\n",
2580 beacon_loss_count);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002581
Johannes Berg98f03342014-11-26 12:42:02 +01002582 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
Ben Greeara13fbe52013-03-25 11:19:35 -07002583 }
Kalle Valo04de8382009-03-22 21:57:35 +02002584
Johannes Bergb291ba12009-07-10 15:29:03 +02002585 /*
2586 * The driver/our work has already reported this event or the
2587 * connection monitoring has kicked in and we have already sent
2588 * a probe request. Or maybe the AP died and the driver keeps
2589 * reporting until we disassociate...
2590 *
2591 * In either case we have to ignore the current call to this
2592 * function (except for setting the correct probe reason bit)
2593 * because otherwise we would reset the timer every time and
2594 * never check whether we received a probe response!
2595 */
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002596 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Johannes Bergb291ba12009-07-10 15:29:03 +02002597 already = true;
2598
Eliad Peller12b5f342013-11-18 19:06:46 +02002599 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2600
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002601 mutex_unlock(&sdata->local->mtx);
2602
Johannes Bergb291ba12009-07-10 15:29:03 +02002603 if (already)
2604 goto out;
2605
Johannes Berg4e751842009-06-10 15:16:52 +02002606 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002607 ieee80211_recalc_ps(sdata->local);
Johannes Berg4e751842009-06-10 15:16:52 +02002608 mutex_unlock(&sdata->local->iflist_mtx);
2609
Maxim Levitskya43abf22009-07-31 18:54:12 +03002610 ifmgd->probe_send_count = 0;
2611 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002612 out:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002613 sdata_unlock(sdata);
Kalle Valo04de8382009-03-22 21:57:35 +02002614}
2615
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002616struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2617 struct ieee80211_vif *vif)
2618{
2619 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2620 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002621 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002622 struct sk_buff *skb;
2623 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002624 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002625
2626 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2627 return NULL;
2628
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002629 sdata_assert_lock(sdata);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002630
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002631 if (ifmgd->associated)
2632 cbss = ifmgd->associated;
2633 else if (ifmgd->auth_data)
2634 cbss = ifmgd->auth_data->bss;
2635 else if (ifmgd->assoc_data)
2636 cbss = ifmgd->assoc_data->bss;
2637 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002638 return NULL;
2639
Johannes Berg9caf0362012-11-29 01:25:20 +01002640 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002641 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Will Deacon41525612019-10-04 10:51:31 +01002642 if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
2643 "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002644 ssid_len = 0;
2645 else
2646 ssid_len = ssid[1];
2647
Johannes Berga344d672014-06-12 22:24:31 +02002648 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02002649 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02002650 ssid + 2, ssid_len,
Johannes Berg00387f32018-05-28 15:47:38 +02002651 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
Johannes Berg9caf0362012-11-29 01:25:20 +01002652 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002653
2654 return skb;
2655}
2656EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2657
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002658static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2659 const u8 *buf, size_t len, bool tx,
2660 u16 reason)
2661{
2662 struct ieee80211_event event = {
2663 .type = MLME_EVENT,
2664 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2665 .u.mlme.reason = reason,
2666 };
2667
2668 if (tx)
2669 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2670 else
2671 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2672
2673 drv_event_callback(sdata->local, sdata, &event);
2674}
2675
Johannes Bergeef9e542013-01-29 13:09:34 +01002676static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002677{
Michal Kazior59af6922014-04-09 15:10:59 +02002678 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002679 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002680 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002681 bool tx;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002682
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002683 sdata_lock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002684 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002685 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002686 return;
2687 }
2688
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002689 tx = !sdata->csa_block_tx;
2690
David Spinadel20eb7ea2016-05-03 16:05:02 +03002691 /* AP is probably out of range (or not reachable for another reason) so
2692 * remove the bss struct for that AP.
2693 */
2694 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2695
Johannes Berg37ad3882012-02-24 13:50:54 +01002696 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2697 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002698 tx, frame_buf);
Michal Kazior59af6922014-04-09 15:10:59 +02002699 mutex_lock(&local->mtx);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002700 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002701 ifmgd->csa_waiting_bcn = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002702 if (sdata->csa_block_tx) {
2703 ieee80211_wake_vif_queues(local, sdata,
2704 IEEE80211_QUEUE_STOP_REASON_CSA);
2705 sdata->csa_block_tx = false;
2706 }
Michal Kazior59af6922014-04-09 15:10:59 +02002707 mutex_unlock(&local->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002708
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002709 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002710 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2711
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002712 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002713}
2714
Johannes Bergcc74c0c2012-08-01 16:49:34 +02002715static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02002716{
2717 struct ieee80211_sub_if_data *sdata =
2718 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002719 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002720 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Paul Stewarta85e1d52011-12-09 11:01:49 -08002721
Johannes Berg976bd9e2015-10-16 17:18:11 +02002722 if (ifmgd->associated)
2723 ifmgd->beacon_loss_count++;
Johannes Bergb291ba12009-07-10 15:29:03 +02002724
Johannes Berg682bd382013-01-29 13:13:50 +01002725 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02002726 sdata_info(sdata, "Connection to AP %pM lost\n",
2727 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01002728 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02002729 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002730 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02002731 }
2732}
2733
2734static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2735{
2736 struct ieee80211_sub_if_data *sdata =
2737 container_of(work, struct ieee80211_sub_if_data,
2738 u.mgd.csa_connection_drop_work);
2739
Johannes Bergeef9e542013-01-29 13:09:34 +01002740 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002741}
2742
Kalle Valo04de8382009-03-22 21:57:35 +02002743void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2744{
2745 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002746 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02002747
Johannes Bergb5878a22010-04-07 16:48:40 +02002748 trace_api_beacon_loss(sdata);
2749
Johannes Berg682bd382013-01-29 13:13:50 +01002750 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002751 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002752}
2753EXPORT_SYMBOL(ieee80211_beacon_loss);
2754
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002755void ieee80211_connection_loss(struct ieee80211_vif *vif)
2756{
2757 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2758 struct ieee80211_hw *hw = &sdata->local->hw;
2759
Johannes Bergb5878a22010-04-07 16:48:40 +02002760 trace_api_connection_loss(sdata);
2761
Johannes Berg682bd382013-01-29 13:13:50 +01002762 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002763 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2764}
2765EXPORT_SYMBOL(ieee80211_connection_loss);
2766
2767
Johannes Berg66e67e42012-01-20 13:55:27 +01002768static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2769 bool assoc)
2770{
2771 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2772
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002773 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002774
Johannes Berg66e67e42012-01-20 13:55:27 +01002775 if (!assoc) {
Emmanuel Grumbachc1e140b2015-01-19 16:53:06 +02002776 /*
2777 * we are not authenticated yet, the only timer that could be
2778 * running is the timeout for the authentication response which
2779 * which is not relevant anymore.
2780 */
2781 del_timer_sync(&sdata->u.mgd.timer);
Johannes Berg66e67e42012-01-20 13:55:27 +01002782 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2783
Joe Perchesc84a67a2015-03-02 19:54:57 -08002784 eth_zero_addr(sdata->u.mgd.bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002785 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002786 sdata->u.mgd.flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002787 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002788 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002789 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01002790 }
2791
Johannes Berg5b112d32013-02-01 01:49:58 +01002792 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002793 kfree(auth_data);
2794 sdata->u.mgd.auth_data = NULL;
2795}
2796
Johannes Bergc9c99f82015-06-01 14:10:09 +02002797static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
Johannes Berge6f462d2016-12-08 17:22:09 +01002798 bool assoc, bool abandon)
Johannes Bergc9c99f82015-06-01 14:10:09 +02002799{
2800 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2801
2802 sdata_assert_lock(sdata);
2803
2804 if (!assoc) {
2805 /*
2806 * we are not associated yet, the only timer that could be
2807 * running is the timeout for the association response which
2808 * which is not relevant anymore.
2809 */
2810 del_timer_sync(&sdata->u.mgd.timer);
2811 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2812
2813 eth_zero_addr(sdata->u.mgd.bssid);
2814 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2815 sdata->u.mgd.flags = 0;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002816 sdata->vif.mu_mimo_owner = false;
2817
Johannes Bergc9c99f82015-06-01 14:10:09 +02002818 mutex_lock(&sdata->local->mtx);
2819 ieee80211_vif_release_channel(sdata);
2820 mutex_unlock(&sdata->local->mtx);
Johannes Berge6f462d2016-12-08 17:22:09 +01002821
2822 if (abandon)
2823 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
Johannes Bergc9c99f82015-06-01 14:10:09 +02002824 }
2825
2826 kfree(assoc_data);
2827 sdata->u.mgd.assoc_data = NULL;
2828}
2829
Johannes Berg66e67e42012-01-20 13:55:27 +01002830static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2831 struct ieee80211_mgmt *mgmt, size_t len)
2832{
Johannes Berg1672c0e32013-01-29 15:02:27 +01002833 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01002834 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2835 u8 *pos;
2836 struct ieee802_11_elems elems;
Johannes Berg1672c0e32013-01-29 15:02:27 +01002837 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002838
2839 pos = mgmt->u.auth.variable;
Sara Sharon4abb52a2019-01-16 12:14:41 +02002840 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
2841 mgmt->bssid, auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002842 if (!elems.challenge)
2843 return;
2844 auth_data->expected_transaction = 4;
Ilan Peerd4e36e52018-04-20 13:49:25 +03002845 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg30686bf2015-06-02 21:39:54 +02002846 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +01002847 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2848 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03002849 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01002850 elems.challenge - 2, elems.challenge_len + 2,
2851 auth_data->bss->bssid, auth_data->bss->bssid,
2852 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002853 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002854}
2855
Jouni Malinenfc107a92018-10-11 00:21:19 +03002856static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2857 const u8 *bssid)
2858{
Jouni Malinenefb543e2018-10-11 00:21:21 +03002859 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002860 struct sta_info *sta;
Wei Yongjun33483a62018-10-16 02:35:30 +00002861 bool result = true;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002862
Jouni Malinenefb543e2018-10-11 00:21:21 +03002863 sdata_info(sdata, "authenticated\n");
2864 ifmgd->auth_data->done = true;
2865 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2866 ifmgd->auth_data->timeout_started = true;
2867 run_again(sdata, ifmgd->auth_data->timeout);
2868
Jouni Malinenfc107a92018-10-11 00:21:19 +03002869 /* move station state to auth */
2870 mutex_lock(&sdata->local->sta_mtx);
2871 sta = sta_info_get(sdata, bssid);
2872 if (!sta) {
2873 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
Wei Yongjun33483a62018-10-16 02:35:30 +00002874 result = false;
2875 goto out;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002876 }
2877 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2878 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Wei Yongjun33483a62018-10-16 02:35:30 +00002879 result = false;
2880 goto out;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002881 }
Jouni Malinenfc107a92018-10-11 00:21:19 +03002882
Wei Yongjun33483a62018-10-16 02:35:30 +00002883out:
2884 mutex_unlock(&sdata->local->sta_mtx);
2885 return result;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002886}
2887
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002888static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2889 struct ieee80211_mgmt *mgmt, size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002890{
2891 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2892 u8 bssid[ETH_ALEN];
2893 u16 auth_alg, auth_transaction, status_code;
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002894 struct ieee80211_event event = {
2895 .type = MLME_EVENT,
2896 .u.mlme.data = AUTH_EVENT,
2897 };
Johannes Berg66e67e42012-01-20 13:55:27 +01002898
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002899 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002900
2901 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002902 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002903
2904 if (!ifmgd->auth_data || ifmgd->auth_data->done)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002905 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002906
2907 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2908
Joe Perchesb203ca32012-05-08 18:56:52 +00002909 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002910 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002911
2912 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2913 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2914 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2915
2916 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinenefb543e2018-10-11 00:21:21 +03002917 (auth_alg != WLAN_AUTH_SAE &&
2918 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2919 (auth_alg == WLAN_AUTH_SAE &&
2920 (auth_transaction < ifmgd->auth_data->expected_transaction ||
2921 auth_transaction > 2))) {
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002922 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2923 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2924 auth_transaction,
2925 ifmgd->auth_data->expected_transaction);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002926 return;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002927 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002928
2929 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002930 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2931 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002932 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002933 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002934 event.u.mlme.status = MLME_DENIED;
2935 event.u.mlme.reason = status_code;
2936 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002937 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002938 }
2939
2940 switch (ifmgd->auth_data->algorithm) {
2941 case WLAN_AUTH_OPEN:
2942 case WLAN_AUTH_LEAP:
2943 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002944 case WLAN_AUTH_SAE:
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03002945 case WLAN_AUTH_FILS_SK:
2946 case WLAN_AUTH_FILS_SK_PFS:
2947 case WLAN_AUTH_FILS_PK:
Johannes Berg66e67e42012-01-20 13:55:27 +01002948 break;
2949 case WLAN_AUTH_SHARED_KEY:
2950 if (ifmgd->auth_data->expected_transaction != 4) {
2951 ieee80211_auth_challenge(sdata, mgmt, len);
2952 /* need another frame */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002953 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002954 }
2955 break;
2956 default:
2957 WARN_ONCE(1, "invalid auth alg %d",
2958 ifmgd->auth_data->algorithm);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002959 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002960 }
2961
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002962 event.u.mlme.status = MLME_SUCCESS;
2963 drv_event_callback(sdata->local, sdata, &event);
Jouni Malinenefb543e2018-10-11 00:21:21 +03002964 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
2965 (auth_transaction == 2 &&
2966 ifmgd->auth_data->expected_transaction == 2)) {
2967 if (!ieee80211_mark_sta_auth(sdata, bssid))
2968 goto out_err;
2969 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2970 auth_transaction == 2) {
2971 sdata_info(sdata, "SAE peer confirmed\n");
2972 ifmgd->auth_data->peer_confirmed = true;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002973 }
2974
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002975 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002976 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002977 out_err:
2978 mutex_unlock(&sdata->local->sta_mtx);
2979 /* ignore frame -- wait for timeout */
Johannes Berg66e67e42012-01-20 13:55:27 +01002980}
2981
Calvin Owensdfa1ad22014-02-11 12:36:24 -06002982#define case_WLAN(type) \
2983 case WLAN_REASON_##type: return #type
2984
Yu Wang79c92ca2019-05-10 17:04:52 +08002985const char *ieee80211_get_reason_code_string(u16 reason_code)
Calvin Owensdfa1ad22014-02-11 12:36:24 -06002986{
2987 switch (reason_code) {
2988 case_WLAN(UNSPECIFIED);
2989 case_WLAN(PREV_AUTH_NOT_VALID);
2990 case_WLAN(DEAUTH_LEAVING);
2991 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2992 case_WLAN(DISASSOC_AP_BUSY);
2993 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2994 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2995 case_WLAN(DISASSOC_STA_HAS_LEFT);
2996 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2997 case_WLAN(DISASSOC_BAD_POWER);
2998 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2999 case_WLAN(INVALID_IE);
3000 case_WLAN(MIC_FAILURE);
3001 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3002 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3003 case_WLAN(IE_DIFFERENT);
3004 case_WLAN(INVALID_GROUP_CIPHER);
3005 case_WLAN(INVALID_PAIRWISE_CIPHER);
3006 case_WLAN(INVALID_AKMP);
3007 case_WLAN(UNSUPP_RSN_VERSION);
3008 case_WLAN(INVALID_RSN_IE_CAP);
3009 case_WLAN(IEEE8021X_FAILED);
3010 case_WLAN(CIPHER_SUITE_REJECTED);
3011 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3012 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3013 case_WLAN(DISASSOC_LOW_ACK);
3014 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3015 case_WLAN(QSTA_LEAVE_QBSS);
3016 case_WLAN(QSTA_NOT_USE);
3017 case_WLAN(QSTA_REQUIRE_SETUP);
3018 case_WLAN(QSTA_TIMEOUT);
3019 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3020 case_WLAN(MESH_PEER_CANCELED);
3021 case_WLAN(MESH_MAX_PEERS);
3022 case_WLAN(MESH_CONFIG);
3023 case_WLAN(MESH_CLOSE);
3024 case_WLAN(MESH_MAX_RETRIES);
3025 case_WLAN(MESH_CONFIRM_TIMEOUT);
3026 case_WLAN(MESH_INVALID_GTK);
3027 case_WLAN(MESH_INCONSISTENT_PARAM);
3028 case_WLAN(MESH_INVALID_SECURITY);
3029 case_WLAN(MESH_PATH_ERROR);
3030 case_WLAN(MESH_PATH_NOFORWARD);
3031 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3032 case_WLAN(MAC_EXISTS_IN_MBSS);
3033 case_WLAN(MESH_CHAN_REGULATORY);
3034 case_WLAN(MESH_CHAN);
3035 default: return "<unknown>";
3036 }
3037}
Johannes Berg66e67e42012-01-20 13:55:27 +01003038
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003039static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3040 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003041{
Johannes Berg46900292009-02-15 12:44:28 +01003042 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergc9c99f82015-06-01 14:10:09 +02003043 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07003044
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003045 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003046
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003047 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003048 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003049
Yu Wang79c92ca2019-05-10 17:04:52 +08003050 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3051 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3052 return;
3053 }
3054
Johannes Bergc9c99f82015-06-01 14:10:09 +02003055 if (ifmgd->associated &&
3056 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3057 const u8 *bssid = ifmgd->associated->bssid;
3058
3059 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3060 bssid, reason_code,
3061 ieee80211_get_reason_code_string(reason_code));
3062
3063 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3064
3065 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3066 reason_code);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003067 return;
Johannes Bergc9c99f82015-06-01 14:10:09 +02003068 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003069
Johannes Bergc9c99f82015-06-01 14:10:09 +02003070 if (ifmgd->assoc_data &&
3071 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3072 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07003073
Johannes Bergc9c99f82015-06-01 14:10:09 +02003074 sdata_info(sdata,
3075 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3076 bssid, reason_code,
3077 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07003078
Johannes Berge6f462d2016-12-08 17:22:09 +01003079 ieee80211_destroy_assoc_data(sdata, false, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07003080
Johannes Bergc9c99f82015-06-01 14:10:09 +02003081 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3082 return;
3083 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003084}
3085
3086
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003087static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3088 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003089{
Johannes Berg46900292009-02-15 12:44:28 +01003090 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07003091 u16 reason_code;
3092
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003093 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003094
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003095 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003096 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003097
Johannes Berg66e67e42012-01-20 13:55:27 +01003098 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00003099 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003100 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003101
3102 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3103
Yu Wang79c92ca2019-05-10 17:04:52 +08003104 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3105 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3106 return;
3107 }
3108
Arkadiusz Miskiewicz68506e92017-02-15 14:21:27 +01003109 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3110 mgmt->sa, reason_code,
3111 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07003112
Johannes Berg37ad3882012-02-24 13:50:54 +01003113 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3114
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003115 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07003116}
3117
Christian Lamparterc74d0842011-10-15 00:14:49 +02003118static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3119 u8 *supp_rates, unsigned int supp_rates_len,
3120 u32 *rates, u32 *basic_rates,
3121 bool *have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003122 int *min_rate, int *min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03003123 int shift)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003124{
3125 int i, j;
3126
3127 for (i = 0; i < supp_rates_len; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003128 int rate = supp_rates[i] & 0x7f;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003129 bool is_basic = !!(supp_rates[i] & 0x80);
3130
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003131 if ((rate * 5 * (1 << shift)) > 110)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003132 *have_higher_than_11mbit = true;
3133
3134 /*
Johannes Berga6289d32017-03-06 22:59:04 +01003135 * Skip HT and VHT BSS membership selectors since they're not
3136 * rates.
Christian Lamparterc74d0842011-10-15 00:14:49 +02003137 *
Johannes Berga6289d32017-03-06 22:59:04 +01003138 * Note: Even though the membership selector and the basic
Christian Lamparterc74d0842011-10-15 00:14:49 +02003139 * rate flag share the same bit, they are not exactly
3140 * the same.
3141 */
Johannes Berga6289d32017-03-06 22:59:04 +01003142 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3143 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
Christian Lamparterc74d0842011-10-15 00:14:49 +02003144 continue;
3145
3146 for (j = 0; j < sband->n_bitrates; j++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003147 struct ieee80211_rate *br;
3148 int brate;
3149
3150 br = &sband->bitrates[j];
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003151
3152 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3153 if (brate == rate) {
Christian Lamparterc74d0842011-10-15 00:14:49 +02003154 *rates |= BIT(j);
3155 if (is_basic)
3156 *basic_rates |= BIT(j);
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003157 if ((rate * 5) < *min_rate) {
3158 *min_rate = rate * 5;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003159 *min_rate_index = j;
3160 }
3161 break;
3162 }
3163 }
3164 }
3165}
Jiri Bencf0706e82007-05-05 11:45:53 -07003166
Emmanuel Grumbach55ebd6e2018-12-15 11:03:04 +02003167static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3168 const struct ieee802_11_elems *elems)
3169{
3170 if (elems->ext_capab_len < 10)
3171 return false;
3172
3173 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3174 return false;
3175
3176 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3177 IEEE80211_HE_MAC_CAP0_TWT_RES;
3178}
3179
John Crispinc9d32452019-05-28 13:49:47 +02003180static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3181 struct sta_info *sta,
3182 struct ieee802_11_elems *elems)
3183{
3184 bool twt = ieee80211_twt_req_supported(sta, elems);
3185
3186 if (sdata->vif.bss_conf.twt_requester != twt) {
3187 sdata->vif.bss_conf.twt_requester = twt;
3188 return BSS_CHANGED_TWT;
3189 }
3190 return 0;
3191}
3192
Johannes Berg66e67e42012-01-20 13:55:27 +01003193static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3194 struct cfg80211_bss *cbss,
Johannes Bergf61d7882019-10-28 12:52:42 +01003195 struct ieee80211_mgmt *mgmt, size_t len,
3196 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07003197{
Johannes Berg46900292009-02-15 12:44:28 +01003198 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01003199 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01003200 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003201 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003202 u16 capab_info, aid;
Johannes Bergbda39332008-10-11 01:51:51 +02003203 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg35d865a2013-05-28 10:54:03 +02003204 const struct cfg80211_bss_ies *bss_ies = NULL;
3205 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
Johannes Bergae5eb022008-10-14 16:58:37 +02003206 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003207 int err;
Johannes Berg35d865a2013-05-28 10:54:03 +02003208 bool ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003209
Johannes Bergaf6b6372009-12-23 13:15:35 +01003210 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07003211
Jiri Bencf0706e82007-05-05 11:45:53 -07003212 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003213 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07003214
Johannes Bergc7c477b2017-12-01 13:50:51 +02003215 /*
3216 * The 5 MSB of the AID field are reserved
3217 * (802.11-2016 9.4.1.8 AID field)
3218 */
3219 aid &= 0x7ff;
Johannes Berg1dd84aa2007-10-10 12:03:41 +02003220
Johannes Berg05cb9102011-10-28 11:59:47 +02003221 ifmgd->broken_ap = false;
3222
3223 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003224 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3225 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02003226 aid = 0;
3227 ifmgd->broken_ap = true;
3228 }
3229
Johannes Bergf61d7882019-10-28 12:52:42 +01003230 if (!elems->supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003231 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01003232 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07003233 }
3234
Johannes Berg46900292009-02-15 12:44:28 +01003235 ifmgd->aid = aid;
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02003236 ifmgd->tdls_chan_switch_prohibited =
Johannes Bergf61d7882019-10-28 12:52:42 +01003237 elems->ext_capab && elems->ext_capab_len >= 5 &&
3238 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
Jiri Bencf0706e82007-05-05 11:45:53 -07003239
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003240 /*
Johannes Berg35d865a2013-05-28 10:54:03 +02003241 * Some APs are erroneously not including some information in their
3242 * (re)association response frames. Try to recover by using the data
3243 * from the beacon or probe response. This seems to afflict mobile
3244 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3245 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3246 */
Johannes Bergf61d7882019-10-28 12:52:42 +01003247 if ((assoc_data->wmm && !elems->wmm_param) ||
Johannes Berg35d865a2013-05-28 10:54:03 +02003248 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003249 (!elems->ht_cap_elem || !elems->ht_operation)) ||
Johannes Berg35d865a2013-05-28 10:54:03 +02003250 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003251 (!elems->vht_cap_elem || !elems->vht_operation))) {
Johannes Berg35d865a2013-05-28 10:54:03 +02003252 const struct cfg80211_bss_ies *ies;
3253 struct ieee802_11_elems bss_elems;
3254
3255 rcu_read_lock();
3256 ies = rcu_dereference(cbss->ies);
3257 if (ies)
3258 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3259 GFP_ATOMIC);
3260 rcu_read_unlock();
3261 if (!bss_ies)
3262 return false;
3263
3264 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003265 false, &bss_elems,
3266 mgmt->bssid,
3267 assoc_data->bss->bssid);
Johannes Berg35d865a2013-05-28 10:54:03 +02003268 if (assoc_data->wmm &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003269 !elems->wmm_param && bss_elems.wmm_param) {
3270 elems->wmm_param = bss_elems.wmm_param;
Johannes Berg35d865a2013-05-28 10:54:03 +02003271 sdata_info(sdata,
3272 "AP bug: WMM param missing from AssocResp\n");
3273 }
3274
3275 /*
3276 * Also check if we requested HT/VHT, otherwise the AP doesn't
3277 * have to include the IEs in the (re)association response.
3278 */
Johannes Bergf61d7882019-10-28 12:52:42 +01003279 if (!elems->ht_cap_elem && bss_elems.ht_cap_elem &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003280 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003281 elems->ht_cap_elem = bss_elems.ht_cap_elem;
Johannes Berg35d865a2013-05-28 10:54:03 +02003282 sdata_info(sdata,
3283 "AP bug: HT capability missing from AssocResp\n");
3284 }
Johannes Bergf61d7882019-10-28 12:52:42 +01003285 if (!elems->ht_operation && bss_elems.ht_operation &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003286 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003287 elems->ht_operation = bss_elems.ht_operation;
Johannes Berg35d865a2013-05-28 10:54:03 +02003288 sdata_info(sdata,
3289 "AP bug: HT operation missing from AssocResp\n");
3290 }
Johannes Bergf61d7882019-10-28 12:52:42 +01003291 if (!elems->vht_cap_elem && bss_elems.vht_cap_elem &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003292 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003293 elems->vht_cap_elem = bss_elems.vht_cap_elem;
Johannes Berg35d865a2013-05-28 10:54:03 +02003294 sdata_info(sdata,
3295 "AP bug: VHT capa missing from AssocResp\n");
3296 }
Johannes Bergf61d7882019-10-28 12:52:42 +01003297 if (!elems->vht_operation && bss_elems.vht_operation &&
Johannes Berg35d865a2013-05-28 10:54:03 +02003298 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
Johannes Bergf61d7882019-10-28 12:52:42 +01003299 elems->vht_operation = bss_elems.vht_operation;
Johannes Berg35d865a2013-05-28 10:54:03 +02003300 sdata_info(sdata,
3301 "AP bug: VHT operation missing from AssocResp\n");
3302 }
3303 }
3304
3305 /*
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003306 * We previously checked these in the beacon/probe response, so
3307 * they should be present here. This is just a safety net.
3308 */
3309 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003310 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003311 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003312 "HT AP is missing WMM params or HT capability/operation\n");
3313 ret = false;
3314 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003315 }
3316
3317 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003318 (!elems->vht_cap_elem || !elems->vht_operation)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003319 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003320 "VHT AP is missing VHT capability/operation\n");
3321 ret = false;
3322 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003323 }
3324
Guy Eilam2a33bee2011-08-17 15:18:15 +03003325 mutex_lock(&sdata->local->sta_mtx);
3326 /*
3327 * station info was already allocated and inserted before
3328 * the association and should be available to us
3329 */
Johannes Berg7852e362012-01-20 13:55:24 +01003330 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003331 if (WARN_ON(!sta)) {
3332 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003333 ret = false;
3334 goto out;
Jiri Bencf0706e82007-05-05 11:45:53 -07003335 }
3336
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05303337 sband = ieee80211_get_sband(sdata);
3338 if (!sband) {
3339 mutex_unlock(&sdata->local->sta_mtx);
3340 ret = false;
3341 goto out;
3342 }
Johannes Berg8318d782008-01-24 19:38:38 +01003343
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003344 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
Johannes Bergf61d7882019-10-28 12:52:42 +01003345 (!elems->he_cap || !elems->he_operation)) {
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003346 mutex_unlock(&sdata->local->sta_mtx);
3347 sdata_info(sdata,
3348 "HE AP is missing HE capability/operation\n");
3349 ret = false;
3350 goto out;
3351 }
3352
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003353 /* Set up internal HT/VHT capabilities */
Johannes Bergf61d7882019-10-28 12:52:42 +01003354 if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08003355 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergf61d7882019-10-28 12:52:42 +01003356 elems->ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02003357
Johannes Bergf61d7882019-10-28 12:52:42 +01003358 if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Mahesh Palivela818255e2012-10-10 11:33:04 +00003359 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Bergf61d7882019-10-28 12:52:42 +01003360 elems->vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00003361
Johannes Bergf61d7882019-10-28 12:52:42 +01003362 if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3363 elems->he_cap) {
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003364 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
Johannes Bergf61d7882019-10-28 12:52:42 +01003365 elems->he_cap,
3366 elems->he_cap_len,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003367 sta);
3368
3369 bss_conf->he_support = sta->sta.he_cap.has_he;
Johannes Bergf61d7882019-10-28 12:52:42 +01003370 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003371 } else {
3372 bss_conf->he_support = false;
Emmanuel Grumbach55ebd6e2018-12-15 11:03:04 +02003373 bss_conf->twt_requester = false;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003374 }
3375
3376 if (bss_conf->he_support) {
John Crispindd56e902019-12-17 15:19:19 +01003377 bss_conf->he_bss_color.color =
Johannes Bergf61d7882019-10-28 12:52:42 +01003378 le32_get_bits(elems->he_operation->he_oper_params,
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003379 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
John Crispindd56e902019-12-17 15:19:19 +01003380 bss_conf->he_bss_color.partial =
3381 le32_get_bits(elems->he_operation->he_oper_params,
3382 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
3383 bss_conf->he_bss_color.disabled =
3384 le32_get_bits(elems->he_operation->he_oper_params,
3385 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
3386 changed |= BSS_CHANGED_HE_BSS_COLOR;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003387
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003388 bss_conf->htc_trig_based_pkt_ext =
Johannes Bergf61d7882019-10-28 12:52:42 +01003389 le32_get_bits(elems->he_operation->he_oper_params,
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003390 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003391 bss_conf->frame_time_rts_th =
Johannes Bergf61d7882019-10-28 12:52:42 +01003392 le32_get_bits(elems->he_operation->he_oper_params,
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003393 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003394
3395 bss_conf->multi_sta_back_32bit =
3396 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3397 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
3398
3399 bss_conf->ack_enabled =
3400 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3401 IEEE80211_HE_MAC_CAP2_ACK_EN;
3402
Johannes Bergf61d7882019-10-28 12:52:42 +01003403 bss_conf->uora_exists = !!elems->uora_element;
3404 if (elems->uora_element)
3405 bss_conf->uora_ocw_range = elems->uora_element[0];
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003406
Johannes Bergf61d7882019-10-28 12:52:42 +01003407 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3408 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003409 /* TODO: OPEN: what happens if BSS color disable is set? */
3410 }
3411
Sara Sharon78ac51f2019-01-16 18:22:56 +02003412 if (cbss->transmitted_bss) {
3413 bss_conf->nontransmitted = true;
3414 ether_addr_copy(bss_conf->transmitter_bssid,
3415 cbss->transmitted_bss->bssid);
3416 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3417 bss_conf->bssid_index = cbss->bssid_index;
3418 }
3419
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003420 /*
3421 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3422 * in their association response, so ignore that data for our own
3423 * configuration. If it changed since the last beacon, we'll get the
3424 * next beacon and update then.
3425 */
Johannes Berg11289582013-02-07 17:36:12 +01003426
Johannes Bergbee7f5862013-02-07 22:24:55 +01003427 /*
3428 * If an operating mode notification IE is present, override the
3429 * NSS calculation (that would be done in rate_control_rate_init())
3430 * and use the # of streams from that element.
3431 */
Johannes Bergf61d7882019-10-28 12:52:42 +01003432 if (elems->opmode_notif &&
3433 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
Johannes Bergbee7f5862013-02-07 22:24:55 +01003434 u8 nss;
3435
Johannes Bergf61d7882019-10-28 12:52:42 +01003436 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
Johannes Bergbee7f5862013-02-07 22:24:55 +01003437 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3438 nss += 1;
3439 sta->sta.rx_nss = nss;
3440 }
3441
Johannes Berg4b7679a2008-09-18 18:14:18 +02003442 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003443
Tamizh chelvam93f04902015-10-07 10:40:04 +05303444 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003445 set_sta_flag(sta, WLAN_STA_MFP);
Tamizh chelvam93f04902015-10-07 10:40:04 +05303446 sta->sta.mfp = true;
3447 } else {
3448 sta->sta.mfp = false;
3449 }
Jouni Malinen5394af42009-01-08 13:31:59 +02003450
Johannes Bergf61d7882019-10-28 12:52:42 +01003451 sta->sta.wme = elems->wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
Johannes Bergddf4ac52008-10-22 11:41:38 +02003452
Johannes Berg3e4d40f2013-02-07 17:19:08 +01003453 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01003454 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3455 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3456 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003457 sdata_info(sdata,
3458 "failed to move station %pM to desired state\n",
3459 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01003460 WARN_ON(__sta_info_destroy(sta));
3461 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003462 ret = false;
3463 goto out;
Johannes Bergc8987872012-01-20 13:55:17 +01003464 }
3465
Johannes Berg7852e362012-01-20 13:55:24 +01003466 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02003467
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003468 /*
3469 * Always handle WMM once after association regardless
3470 * of the first value the AP uses. Setting -1 here has
3471 * that effect because the AP values is an unsigned
3472 * 4-bit value.
3473 */
3474 ifmgd->wmm_last_param_set = -1;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02003475 ifmgd->mu_edca_last_param_set = -1;
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003476
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003477 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Bergcec66282015-10-22 17:46:04 +02003478 ieee80211_set_wmm_default(sdata, false, false);
Johannes Bergf61d7882019-10-28 12:52:42 +01003479 } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
3480 elems->wmm_param_len,
3481 elems->mu_edca_param_set)) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003482 /* still enable QoS since we might have HT/VHT */
3483 ieee80211_set_wmm_default(sdata, false, true);
3484 /* set the disable-WMM flag in this case to disable
3485 * tracking WMM parameter changes in the beacon if
3486 * the parameters weren't actually valid. Doing so
3487 * avoids changing parameters very strangely when
3488 * the AP is going back and forth between valid and
3489 * invalid parameters.
3490 */
3491 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3492 }
Johannes Berg3abead52012-03-02 15:56:59 +01003493 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07003494
Johannes Bergf61d7882019-10-28 12:52:42 +01003495 if (elems->max_idle_period_ie) {
Avraham Sterne38a0172017-04-26 10:58:47 +03003496 bss_conf->max_idle_period =
Johannes Bergf61d7882019-10-28 12:52:42 +01003497 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
Avraham Sterne38a0172017-04-26 10:58:47 +03003498 bss_conf->protected_keep_alive =
Johannes Bergf61d7882019-10-28 12:52:42 +01003499 !!(elems->max_idle_period_ie->idle_options &
Avraham Sterne38a0172017-04-26 10:58:47 +03003500 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3501 changed |= BSS_CHANGED_KEEP_ALIVE;
3502 } else {
3503 bss_conf->max_idle_period = 0;
3504 bss_conf->protected_keep_alive = false;
3505 }
3506
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003507 /* set AID and assoc capability,
3508 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01003509 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003510 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003511 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003512
Kalle Valo15b7b062009-03-22 21:57:14 +02003513 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01003514 * If we're using 4-addr mode, let the AP know that we're
3515 * doing so, so that it can create the STA VLAN on its side
3516 */
3517 if (ifmgd->use_4addr)
3518 ieee80211_send_4addr_nullfunc(local, sdata);
3519
3520 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02003521 * Start timer to probe the connection to the AP now.
3522 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02003523 */
Johannes Bergb291ba12009-07-10 15:29:03 +02003524 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003525 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02003526
Johannes Berg35d865a2013-05-28 10:54:03 +02003527 ret = true;
3528 out:
3529 kfree(bss_ies);
3530 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003531}
3532
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003533static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3534 struct ieee80211_mgmt *mgmt,
3535 size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01003536{
3537 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3538 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3539 u16 capab_info, status_code, aid;
3540 struct ieee802_11_elems elems;
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003541 int ac, uapsd_queues = -1;
Johannes Berg66e67e42012-01-20 13:55:27 +01003542 u8 *pos;
3543 bool reassoc;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003544 struct cfg80211_bss *bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003545 struct ieee80211_event event = {
3546 .type = MLME_EVENT,
3547 .u.mlme.data = ASSOC_EVENT,
3548 };
Jiri Bencf0706e82007-05-05 11:45:53 -07003549
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003550 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003551
3552 if (!assoc_data)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003553 return;
Joe Perchesb203ca32012-05-08 18:56:52 +00003554 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003555 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003556
3557 /*
3558 * AssocResp and ReassocResp have identical structure, so process both
3559 * of them in this function.
3560 */
3561
3562 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003563 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003564
Simon Dinkin7a7d3e42017-08-31 13:09:36 +03003565 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
Johannes Berg66e67e42012-01-20 13:55:27 +01003566 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3567 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3568 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3569
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003570 sdata_info(sdata,
3571 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3572 reassoc ? "Rea" : "A", mgmt->sa,
3573 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01003574
Jouni Malinen39404fe2016-10-27 00:42:05 +03003575 if (assoc_data->fils_kek_len &&
3576 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3577 return;
3578
Johannes Berg66e67e42012-01-20 13:55:27 +01003579 pos = mgmt->u.assoc_resp.variable;
Sara Sharon4abb52a2019-01-16 12:14:41 +02003580 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3581 mgmt->bssid, assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003582
3583 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01003584 elems.timeout_int &&
3585 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003586 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01003587 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01003588 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003589 sdata_info(sdata,
3590 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3591 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01003592 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01003593 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01003594 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003595 run_again(sdata, assoc_data->timeout);
3596 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003597 }
3598
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003599 bss = assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01003600
3601 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003602 sdata_info(sdata, "%pM denied association (code=%d)\n",
3603 mgmt->sa, status_code);
Johannes Berge6f462d2016-12-08 17:22:09 +01003604 ieee80211_destroy_assoc_data(sdata, false, false);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003605 event.u.mlme.status = MLME_DENIED;
3606 event.u.mlme.reason = status_code;
3607 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01003608 } else {
Johannes Bergf61d7882019-10-28 12:52:42 +01003609 if (!ieee80211_assoc_success(sdata, bss, mgmt, len, &elems)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003610 /* oops -- internal error -- send timeout for now */
Johannes Berge6f462d2016-12-08 17:22:09 +01003611 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02003612 cfg80211_assoc_timeout(sdata->dev, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003613 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003614 }
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003615 event.u.mlme.status = MLME_SUCCESS;
3616 drv_event_callback(sdata->local, sdata, &event);
John W. Linville635d9992012-07-09 16:34:34 -04003617 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01003618
3619 /*
3620 * destroy assoc_data afterwards, as otherwise an idle
3621 * recalc after assoc_data is NULL but before associated
3622 * is set can cause the interface to go idle
3623 */
Johannes Berge6f462d2016-12-08 17:22:09 +01003624 ieee80211_destroy_assoc_data(sdata, true, false);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003625
3626 /* get uapsd queues configuration */
3627 uapsd_queues = 0;
3628 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3629 if (sdata->tx_conf[ac].uapsd)
Emmanuel Grumbachf438ceb2016-10-18 23:12:12 +03003630 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
Johannes Berg66e67e42012-01-20 13:55:27 +01003631 }
3632
Jouni Malinen4d9ec732019-02-15 02:14:33 +02003633 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues,
3634 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003635}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003636
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003637static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003638 struct ieee80211_mgmt *mgmt, size_t len,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003639 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003640{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003641 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02003642 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01003643 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01003644
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003645 sdata_assert_lock(sdata);
Johannes Bergb4f286a12013-03-26 14:13:58 +01003646
Emmanuel Grumbach3afc2162014-03-04 16:50:13 +02003647 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3648 if (!channel)
Johannes Berg5bda6172008-09-08 11:05:10 +02003649 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003650
Sara Sharon4abb52a2019-01-16 12:14:41 +02003651 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
Alexander Bondar817cee72013-05-19 14:23:57 +03003652 if (bss) {
Alexander Bondar817cee72013-05-19 14:23:57 +03003653 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
Johannes Bergd2722f82014-03-04 11:43:28 +01003654 ieee80211_rx_bss_put(local, bss);
Alexander Bondar817cee72013-05-19 14:23:57 +03003655 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003656}
3657
3658
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003659static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003660 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003661{
Johannes Bergaf6b6372009-12-23 13:15:35 +01003662 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02003663 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003664 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3665 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03003666
Kalle Valo15b7b062009-03-22 21:57:14 +02003667 ifmgd = &sdata->u.mgd;
3668
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003669 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003670
Joe Perchesb203ca32012-05-08 18:56:52 +00003671 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03003672 return; /* ignore ProbeResp to foreign address */
3673
Ester Kummerae6a44e2008-06-27 18:54:48 +03003674 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3675 if (baselen > len)
3676 return;
3677
Sara Sharon4abb52a2019-01-16 12:14:41 +02003678 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03003679
Johannes Berg77fdaa12009-07-07 03:45:17 +02003680 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003681 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003682 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003683}
3684
Johannes Bergd91f36d2009-04-16 13:17:26 +02003685/*
3686 * This is the canonical list of information elements we care about,
3687 * the filter code also gives us all changes to the Microsoft OUI
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003688 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3689 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3690 * changes to requested client power.
Johannes Bergd91f36d2009-04-16 13:17:26 +02003691 *
3692 * We implement beacon filtering in software since that means we can
3693 * avoid processing the frame here and in cfg80211, and userspace
3694 * will not be able to tell whether the hardware supports it or not.
3695 *
3696 * XXX: This list needs to be dynamic -- userspace needs to be able to
3697 * add items it requires. It also needs to be able to tell us to
3698 * look out for other vendor IEs.
3699 */
3700static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02003701 (1ULL << WLAN_EID_COUNTRY) |
3702 (1ULL << WLAN_EID_ERP_INFO) |
3703 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3704 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3705 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg70a3fd62015-03-12 08:53:29 +02003706 (1ULL << WLAN_EID_HT_OPERATION) |
3707 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003708
Tosoni1ad22fb2018-03-14 16:58:34 +00003709static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3710 struct ieee80211_if_managed *ifmgd,
3711 struct ieee80211_bss_conf *bss_conf,
3712 struct ieee80211_local *local,
3713 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003714{
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003715 /* Track average RSSI from the Beacon frames of the current AP */
Tosoni1ad22fb2018-03-14 16:58:34 +00003716
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003717 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3718 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Johannes Berg338c17a2015-08-28 10:52:54 +02003719 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003720 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03003721 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003722 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003723 } else {
Jouni Malinen391a2002010-08-27 22:22:00 +03003724 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003725 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003726
Johannes Berg338c17a2015-08-28 10:52:54 +02003727 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3728
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003729 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3730 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003731 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003732 int last_sig = ifmgd->last_ave_beacon_signal;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003733 struct ieee80211_event event = {
3734 .type = RSSI_EVENT,
3735 };
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003736
3737 /*
3738 * if signal crosses either of the boundaries, invoke callback
3739 * with appropriate parameters
3740 */
3741 if (sig > ifmgd->rssi_max_thold &&
3742 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3743 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003744 event.u.rssi.data = RSSI_EVENT_HIGH;
3745 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003746 } else if (sig < ifmgd->rssi_min_thold &&
3747 (last_sig >= ifmgd->rssi_max_thold ||
3748 last_sig == 0)) {
3749 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003750 event.u.rssi.data = RSSI_EVENT_LOW;
3751 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003752 }
3753 }
3754
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003755 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03003756 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01003757 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003758 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003759 int last_event = ifmgd->last_cqm_event_signal;
3760 int thold = bss_conf->cqm_rssi_thold;
3761 int hyst = bss_conf->cqm_rssi_hyst;
Johannes Berg338c17a2015-08-28 10:52:54 +02003762
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003763 if (sig < thold &&
3764 (last_event == 0 || sig < last_event - hyst)) {
3765 ifmgd->last_cqm_event_signal = sig;
3766 ieee80211_cqm_rssi_notify(
3767 &sdata->vif,
3768 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003769 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003770 } else if (sig > thold &&
3771 (last_event == 0 || sig > last_event + hyst)) {
3772 ifmgd->last_cqm_event_signal = sig;
3773 ieee80211_cqm_rssi_notify(
3774 &sdata->vif,
3775 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003776 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003777 }
3778 }
3779
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003780 if (bss_conf->cqm_rssi_low &&
3781 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3782 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3783 int last_event = ifmgd->last_cqm_event_signal;
3784 int low = bss_conf->cqm_rssi_low;
3785 int high = bss_conf->cqm_rssi_high;
3786
3787 if (sig < low &&
3788 (last_event == 0 || last_event >= low)) {
3789 ifmgd->last_cqm_event_signal = sig;
3790 ieee80211_cqm_rssi_notify(
3791 &sdata->vif,
3792 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3793 sig, GFP_KERNEL);
3794 } else if (sig > high &&
3795 (last_event == 0 || last_event <= high)) {
3796 ifmgd->last_cqm_event_signal = sig;
3797 ieee80211_cqm_rssi_notify(
3798 &sdata->vif,
3799 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3800 sig, GFP_KERNEL);
3801 }
3802 }
Tosoni1ad22fb2018-03-14 16:58:34 +00003803}
3804
Sara Sharon78ac51f2019-01-16 18:22:56 +02003805static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
3806 struct cfg80211_bss *bss)
3807{
3808 if (ether_addr_equal(tx_bssid, bss->bssid))
3809 return true;
3810 if (!bss->transmitted_bss)
3811 return false;
3812 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
3813}
3814
Tosoni1ad22fb2018-03-14 16:58:34 +00003815static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3816 struct ieee80211_mgmt *mgmt, size_t len,
3817 struct ieee80211_rx_status *rx_status)
3818{
3819 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3820 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3821 size_t baselen;
3822 struct ieee802_11_elems elems;
3823 struct ieee80211_local *local = sdata->local;
3824 struct ieee80211_chanctx_conf *chanctx_conf;
3825 struct ieee80211_channel *chan;
3826 struct sta_info *sta;
3827 u32 changed = 0;
3828 bool erp_valid;
3829 u8 erp_value = 0;
3830 u32 ncrc;
3831 u8 *bssid;
3832 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3833
3834 sdata_assert_lock(sdata);
3835
3836 /* Process beacon from the current BSS */
3837 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3838 if (baselen > len)
3839 return;
3840
3841 rcu_read_lock();
3842 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3843 if (!chanctx_conf) {
3844 rcu_read_unlock();
3845 return;
3846 }
3847
3848 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3849 rcu_read_unlock();
3850 return;
3851 }
3852 chan = chanctx_conf->def.chan;
3853 rcu_read_unlock();
3854
3855 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
Sara Sharon78ac51f2019-01-16 18:22:56 +02003856 ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->assoc_data->bss)) {
Tosoni1ad22fb2018-03-14 16:58:34 +00003857 ieee802_11_parse_elems(mgmt->u.beacon.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003858 len - baselen, false, &elems,
3859 mgmt->bssid,
3860 ifmgd->assoc_data->bss->bssid);
Tosoni1ad22fb2018-03-14 16:58:34 +00003861
Sara Sharon4abb52a2019-01-16 12:14:41 +02003862 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Sara Sharon78ac51f2019-01-16 18:22:56 +02003863
3864 if (elems.dtim_period)
3865 ifmgd->dtim_period = elems.dtim_period;
Tosoni1ad22fb2018-03-14 16:58:34 +00003866 ifmgd->have_beacon = true;
3867 ifmgd->assoc_data->need_beacon = false;
3868 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3869 sdata->vif.bss_conf.sync_tsf =
3870 le64_to_cpu(mgmt->u.beacon.timestamp);
3871 sdata->vif.bss_conf.sync_device_ts =
3872 rx_status->device_timestamp;
Sara Sharon78ac51f2019-01-16 18:22:56 +02003873 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
Tosoni1ad22fb2018-03-14 16:58:34 +00003874 }
Sara Sharon78ac51f2019-01-16 18:22:56 +02003875
3876 if (elems.mbssid_config_ie)
3877 bss_conf->profile_periodicity =
3878 elems.mbssid_config_ie->profile_periodicity;
3879
3880 if (elems.ext_capab_len >= 11 &&
3881 (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
3882 bss_conf->ema_ap = true;
3883
Tosoni1ad22fb2018-03-14 16:58:34 +00003884 /* continue assoc process */
3885 ifmgd->assoc_data->timeout = jiffies;
3886 ifmgd->assoc_data->timeout_started = true;
3887 run_again(sdata, ifmgd->assoc_data->timeout);
3888 return;
3889 }
3890
3891 if (!ifmgd->associated ||
Sara Sharon78ac51f2019-01-16 18:22:56 +02003892 !ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->associated))
Tosoni1ad22fb2018-03-14 16:58:34 +00003893 return;
3894 bssid = ifmgd->associated->bssid;
3895
3896 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3897 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
3898 local, rx_status);
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003899
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003900 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003901 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01003902 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003903 ieee80211_reset_ap_probe(sdata);
Jouni Malinen92778182009-05-14 21:15:36 +03003904 }
3905
Johannes Bergb291ba12009-07-10 15:29:03 +02003906 /*
3907 * Push the beacon loss detection into the future since
3908 * we are processing a beacon from the AP just now.
3909 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003910 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003911
Johannes Bergd91f36d2009-04-16 13:17:26 +02003912 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3913 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003914 len - baselen, false, &elems,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003915 care_about_ies, ncrc,
3916 mgmt->bssid, bssid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003917
Johannes Berg90d13e82015-09-24 16:13:07 +02003918 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3919 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3920 if (local->hw.conf.dynamic_ps_timeout > 0) {
3921 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3922 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3923 ieee80211_hw_config(local,
3924 IEEE80211_CONF_CHANGE_PS);
Kalle Valo572e0012009-02-10 17:09:31 +02003925 }
Johannes Berg076cdcb2015-09-24 16:14:55 +02003926 ieee80211_send_nullfunc(local, sdata, false);
Johannes Berg90d13e82015-09-24 16:13:07 +02003927 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3928 local->pspolling = true;
3929
3930 /*
3931 * Here is assumed that the driver will be
3932 * able to send ps-poll frame and receive a
3933 * response even though power save mode is
3934 * enabled, but some drivers might require
3935 * to disable power save here. This needs
3936 * to be investigated.
3937 */
3938 ieee80211_send_pspoll(local, sdata);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003939 }
3940 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003941
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01003942 if (sdata->vif.p2p ||
3943 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003944 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003945 int ret;
3946
3947 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3948 len - baselen,
3949 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003950 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003951 if (ret >= 2) {
3952 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3953 /* valid noa_attr and index changed */
3954 sdata->u.mgd.p2p_noa_index = noa.index;
3955 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3956 changed |= BSS_CHANGED_P2P_PS;
3957 /*
3958 * make sure we update all information, the CRC
3959 * mechanism doesn't look at P2P attributes.
3960 */
3961 ifmgd->beacon_crc_valid = false;
3962 }
3963 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3964 /* noa_attr not found and we had valid noa_attr before */
3965 sdata->u.mgd.p2p_noa_index = -1;
3966 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003967 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003968 ifmgd->beacon_crc_valid = false;
3969 }
3970 }
3971
Luciano Coelho0c21e632014-10-08 09:48:39 +03003972 if (ifmgd->csa_waiting_bcn)
3973 ieee80211_chswitch_post_beacon(sdata);
3974
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003975 /*
3976 * Update beacon timing and dtim count on every beacon appearance. This
3977 * will allow the driver to use the most updated values. Do it before
3978 * comparing this one with last received beacon.
3979 * IMPORTANT: These parameters would possibly be out of sync by the time
3980 * the driver will use them. The synchronized view is currently
3981 * guaranteed only in certain callbacks.
3982 */
Johannes Berg30686bf2015-06-02 21:39:54 +02003983 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003984 sdata->vif.bss_conf.sync_tsf =
3985 le64_to_cpu(mgmt->u.beacon.timestamp);
3986 sdata->vif.bss_conf.sync_device_ts =
3987 rx_status->device_timestamp;
Sara Sharon78ac51f2019-01-16 18:22:56 +02003988 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003989 }
3990
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003991 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003992 return;
Jouni Malinen30196672009-05-19 17:01:43 +03003993 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003994 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03003995
Sara Sharon4abb52a2019-01-16 12:14:41 +02003996 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Johannes Berg7d257452012-07-06 17:37:43 +02003997
Johannes Bergd70b7612013-08-23 15:48:48 +02003998 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003999 rx_status->device_timestamp,
Johannes Bergd70b7612013-08-23 15:48:48 +02004000 &elems, true);
4001
Johannes Berg095d81c2013-10-15 12:25:07 +02004002 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
4003 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004004 elems.wmm_param_len,
4005 elems.mu_edca_param_set))
Johannes Berg7d257452012-07-06 17:37:43 +02004006 changed |= BSS_CHANGED_QOS;
4007
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004008 /*
4009 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01004010 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004011 */
Alexander Bondar989c6502013-05-16 17:34:17 +03004012 if (!ifmgd->have_beacon) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004013 /* a few bogus AP send dtim_period = 0 or no TIM IE */
Sara Sharon78ac51f2019-01-16 18:22:56 +02004014 bss_conf->dtim_period = elems.dtim_period ?: 1;
Johannes Bergef429da2013-02-05 17:48:40 +01004015
Alexander Bondar989c6502013-05-16 17:34:17 +03004016 changed |= BSS_CHANGED_BEACON_INFO;
4017 ifmgd->have_beacon = true;
Alexander Bondar482a9c72013-06-03 17:29:33 +03004018
4019 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02004020 ieee80211_recalc_ps(local);
Alexander Bondar482a9c72013-06-03 17:29:33 +03004021 mutex_unlock(&local->iflist_mtx);
4022
Alexander Bondarce857882013-05-06 17:17:04 +03004023 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004024 }
4025
Johannes Berg1946bed2013-03-27 14:31:53 +01004026 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02004027 erp_valid = true;
4028 erp_value = elems.erp_info[0];
4029 } else {
4030 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04004031 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02004032 changed |= ieee80211_handle_bss_capability(sdata,
4033 le16_to_cpu(mgmt->u.beacon.capab_info),
4034 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07004035
Johannes Berg11289582013-02-07 17:36:12 +01004036 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f5862013-02-07 22:24:55 +01004037 sta = sta_info_get(sdata, bssid);
4038
John Crispinc9d32452019-05-28 13:49:47 +02004039 changed |= ieee80211_recalc_twt_req(sdata, sta, &elems);
4040
Eliad Peller53b954e2014-07-24 11:20:05 +03004041 if (ieee80211_config_bw(sdata, sta,
4042 elems.ht_cap_elem, elems.ht_operation,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004043 elems.vht_operation, elems.he_operation,
4044 bssid, &changed)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01004045 mutex_unlock(&local->sta_mtx);
Johannes Berg89f774e2016-01-25 15:46:36 +02004046 sdata_info(sdata,
4047 "failed to follow AP %pM bandwidth change, disconnect\n",
4048 bssid);
Johannes Berg30eb1dc2013-02-08 15:12:14 +01004049 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4050 WLAN_REASON_DEAUTH_LEAVING,
4051 true, deauth_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004052 ieee80211_report_disconnect(sdata, deauth_buf,
4053 sizeof(deauth_buf), true,
4054 WLAN_REASON_DEAUTH_LEAVING);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004055 return;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01004056 }
Johannes Bergbee7f5862013-02-07 22:24:55 +01004057
4058 if (sta && elems.opmode_notif)
4059 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
Eyal Shapiracf1e05c2015-12-08 16:04:36 +02004060 rx_status->band);
Johannes Berg11289582013-02-07 17:36:12 +01004061 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02004062
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07004063 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4064 elems.country_elem,
4065 elems.country_elem_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07004066 elems.pwr_constr_elem,
4067 elems.cisco_dtpc_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08004068
Johannes Berg471b3ef2007-12-28 14:32:58 +01004069 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07004070}
4071
Johannes Berg1fa57d02010-06-10 10:21:32 +02004072void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4073 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07004074{
4075 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07004076 struct ieee80211_mgmt *mgmt;
4077 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004078 struct ieee802_11_elems elems;
4079 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07004080
Jiri Bencf0706e82007-05-05 11:45:53 -07004081 rx_status = (struct ieee80211_rx_status *) skb->cb;
4082 mgmt = (struct ieee80211_mgmt *) skb->data;
4083 fc = le16_to_cpu(mgmt->frame_control);
4084
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004085 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004086
Johannes Berg66e67e42012-01-20 13:55:27 +01004087 switch (fc & IEEE80211_FCTL_STYPE) {
4088 case IEEE80211_STYPE_BEACON:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004089 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01004090 break;
4091 case IEEE80211_STYPE_PROBE_RESP:
4092 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4093 break;
4094 case IEEE80211_STYPE_AUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004095 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004096 break;
4097 case IEEE80211_STYPE_DEAUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004098 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004099 break;
4100 case IEEE80211_STYPE_DISASSOC:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004101 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004102 break;
4103 case IEEE80211_STYPE_ASSOC_RESP:
4104 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004105 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01004106 break;
4107 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01004108 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004109 ies_len = skb->len -
4110 offsetof(struct ieee80211_mgmt,
4111 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01004112
4113 if (ies_len < 0)
4114 break;
4115
Sara Sharon4abb52a2019-01-16 12:14:41 +02004116 /* CSA IE cannot be overridden, no need for BSSID */
Johannes Berg37799e52013-03-26 14:02:26 +01004117 ieee802_11_parse_elems(
4118 mgmt->u.action.u.chan_switch.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02004119 ies_len, true, &elems, mgmt->bssid, NULL);
Johannes Berg37799e52013-03-26 14:02:26 +01004120
4121 if (elems.parse_error)
4122 break;
4123
Johannes Berg66e67e42012-01-20 13:55:27 +01004124 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03004125 rx_status->mactime,
4126 rx_status->device_timestamp,
4127 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004128 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4129 ies_len = skb->len -
4130 offsetof(struct ieee80211_mgmt,
4131 u.action.u.ext_chan_switch.variable);
4132
4133 if (ies_len < 0)
4134 break;
4135
Sara Sharon4abb52a2019-01-16 12:14:41 +02004136 /*
4137 * extended CSA IE can't be overridden, no need for
4138 * BSSID
4139 */
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004140 ieee802_11_parse_elems(
4141 mgmt->u.action.u.ext_chan_switch.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02004142 ies_len, true, &elems, mgmt->bssid, NULL);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004143
4144 if (elems.parse_error)
4145 break;
4146
4147 /* for the handling code pretend this was also an IE */
4148 elems.ext_chansw_ie =
4149 &mgmt->u.action.u.ext_chan_switch.data;
4150
4151 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03004152 rx_status->mactime,
4153 rx_status->device_timestamp,
4154 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004155 }
Johannes Berg37799e52013-03-26 14:02:26 +01004156 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004157 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004158 sdata_unlock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07004159}
4160
Kees Cook34f11cd2017-10-16 16:35:49 -07004161static void ieee80211_sta_timer(struct timer_list *t)
Jiri Bencf0706e82007-05-05 11:45:53 -07004162{
4163 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004164 from_timer(sdata, t, u.mgd.timer);
Jiri Bencf0706e82007-05-05 11:45:53 -07004165
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01004166 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07004167}
4168
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004169static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01004170 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004171{
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004172 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004173
Johannes Berg37ad3882012-02-24 13:50:54 +01004174 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01004175 tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01004176
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004177 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4178 reason);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004179}
4180
Johannes Berg46cad4b2015-08-15 22:39:54 +03004181static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg66e67e42012-01-20 13:55:27 +01004182{
4183 struct ieee80211_local *local = sdata->local;
4184 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4185 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004186 u32 tx_flags = 0;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004187 u16 trans = 1;
4188 u16 status = 0;
Ilan Peerd4e36e52018-04-20 13:49:25 +03004189 u16 prepare_tx_duration = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004190
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004191 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004192
4193 if (WARN_ON_ONCE(!auth_data))
4194 return -EINVAL;
4195
Johannes Berg66e67e42012-01-20 13:55:27 +01004196 auth_data->tries++;
4197
4198 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004199 sdata_info(sdata, "authentication with %pM timed out\n",
4200 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004201
4202 /*
4203 * Most likely AP is not in the range so remove the
4204 * bss struct for that AP.
4205 */
4206 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4207
4208 return -ETIMEDOUT;
4209 }
4210
Ilan Peerd4e36e52018-04-20 13:49:25 +03004211 if (auth_data->algorithm == WLAN_AUTH_SAE)
4212 prepare_tx_duration =
4213 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4214
4215 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
Johannes Berga1845fc2012-06-27 13:18:36 +02004216
Johannes Berg46cad4b2015-08-15 22:39:54 +03004217 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4218 auth_data->bss->bssid, auth_data->tries,
4219 IEEE80211_AUTH_MAX_TRIES);
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004220
Johannes Berg46cad4b2015-08-15 22:39:54 +03004221 auth_data->expected_transaction = 2;
Johannes Berg66e67e42012-01-20 13:55:27 +01004222
Johannes Berg46cad4b2015-08-15 22:39:54 +03004223 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4224 trans = auth_data->sae_trans;
4225 status = auth_data->sae_status;
4226 auth_data->expected_transaction = trans;
Johannes Berg66e67e42012-01-20 13:55:27 +01004227 }
4228
Johannes Berg46cad4b2015-08-15 22:39:54 +03004229 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4230 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4231 IEEE80211_TX_INTFL_MLME_CONN_TX;
4232
4233 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4234 auth_data->data, auth_data->data_len,
4235 auth_data->bss->bssid,
4236 auth_data->bss->bssid, NULL, 0, 0,
4237 tx_flags);
4238
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02004239 if (tx_flags == 0) {
Ilan Peer407879b2018-04-20 13:49:20 +03004240 if (auth_data->algorithm == WLAN_AUTH_SAE)
4241 auth_data->timeout = jiffies +
4242 IEEE80211_AUTH_TIMEOUT_SAE;
4243 else
4244 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004245 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004246 auth_data->timeout =
4247 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004248 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004249
Ilan Peer407879b2018-04-20 13:49:20 +03004250 auth_data->timeout_started = true;
4251 run_again(sdata, auth_data->timeout);
4252
Johannes Berg66e67e42012-01-20 13:55:27 +01004253 return 0;
4254}
4255
4256static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4257{
4258 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4259 struct ieee80211_local *local = sdata->local;
4260
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004261 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004262
Johannes Berg66e67e42012-01-20 13:55:27 +01004263 assoc_data->tries++;
4264 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004265 sdata_info(sdata, "association with %pM timed out\n",
4266 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004267
4268 /*
4269 * Most likely AP is not in the range so remove the
4270 * bss struct for that AP.
4271 */
4272 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4273
4274 return -ETIMEDOUT;
4275 }
4276
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004277 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4278 assoc_data->bss->bssid, assoc_data->tries,
4279 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01004280 ieee80211_send_assoc(sdata);
4281
Johannes Berg30686bf2015-06-02 21:39:54 +02004282 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004283 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004284 assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004285 run_again(sdata, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01004286 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004287 assoc_data->timeout =
4288 round_jiffies_up(jiffies +
4289 IEEE80211_ASSOC_TIMEOUT_LONG);
4290 assoc_data->timeout_started = true;
4291 run_again(sdata, assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004292 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004293
4294 return 0;
4295}
4296
Johannes Berg1672c0e32013-01-29 15:02:27 +01004297void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4298 __le16 fc, bool acked)
4299{
4300 struct ieee80211_local *local = sdata->local;
4301
4302 sdata->u.mgd.status_fc = fc;
4303 sdata->u.mgd.status_acked = acked;
4304 sdata->u.mgd.status_received = true;
4305
4306 ieee80211_queue_work(&local->hw, &sdata->work);
4307}
4308
Johannes Berg1fa57d02010-06-10 10:21:32 +02004309void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004310{
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004311 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02004312 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004313
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004314 sdata_lock(sdata);
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004315
Johannes Berg1672c0e32013-01-29 15:02:27 +01004316 if (ifmgd->status_received) {
4317 __le16 fc = ifmgd->status_fc;
4318 bool status_acked = ifmgd->status_acked;
4319
4320 ifmgd->status_received = false;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004321 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004322 if (status_acked) {
Ilan Peer407879b2018-04-20 13:49:20 +03004323 if (ifmgd->auth_data->algorithm ==
4324 WLAN_AUTH_SAE)
4325 ifmgd->auth_data->timeout =
4326 jiffies +
4327 IEEE80211_AUTH_TIMEOUT_SAE;
4328 else
4329 ifmgd->auth_data->timeout =
4330 jiffies +
4331 IEEE80211_AUTH_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004332 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004333 } else {
4334 ifmgd->auth_data->timeout = jiffies - 1;
4335 }
Johannes Berg89afe612013-02-13 15:39:57 +01004336 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004337 } else if (ifmgd->assoc_data &&
4338 (ieee80211_is_assoc_req(fc) ||
4339 ieee80211_is_reassoc_req(fc))) {
4340 if (status_acked) {
4341 ifmgd->assoc_data->timeout =
4342 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004343 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004344 } else {
4345 ifmgd->assoc_data->timeout = jiffies - 1;
4346 }
Johannes Berg89afe612013-02-13 15:39:57 +01004347 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004348 }
4349 }
4350
Johannes Berg89afe612013-02-13 15:39:57 +01004351 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004352 time_after(jiffies, ifmgd->auth_data->timeout)) {
4353 if (ifmgd->auth_data->done) {
4354 /*
4355 * ok ... we waited for assoc but userspace didn't,
4356 * so let's just kill the auth data
4357 */
4358 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg46cad4b2015-08-15 22:39:54 +03004359 } else if (ieee80211_auth(sdata)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004360 u8 bssid[ETH_ALEN];
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004361 struct ieee80211_event event = {
4362 .type = MLME_EVENT,
4363 .u.mlme.data = AUTH_EVENT,
4364 .u.mlme.status = MLME_TIMEOUT,
4365 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004366
4367 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4368
4369 ieee80211_destroy_auth_data(sdata, false);
4370
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004371 cfg80211_auth_timeout(sdata->dev, bssid);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004372 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004373 }
Johannes Berg89afe612013-02-13 15:39:57 +01004374 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004375 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004376
Johannes Berg89afe612013-02-13 15:39:57 +01004377 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004378 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Alexander Bondar989c6502013-05-16 17:34:17 +03004379 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01004380 ieee80211_do_assoc(sdata)) {
Johannes Berg959867f2013-06-19 13:05:42 +02004381 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004382 struct ieee80211_event event = {
4383 .type = MLME_EVENT,
4384 .u.mlme.data = ASSOC_EVENT,
4385 .u.mlme.status = MLME_TIMEOUT,
4386 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004387
Johannes Berge6f462d2016-12-08 17:22:09 +01004388 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02004389 cfg80211_assoc_timeout(sdata->dev, bss);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004390 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004391 }
Johannes Berg89afe612013-02-13 15:39:57 +01004392 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004393 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004394
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02004395 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
Johannes Bergb291ba12009-07-10 15:29:03 +02004396 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03004397 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004398 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03004399
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004400 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004401
Johannes Berg30686bf2015-06-02 21:39:54 +02004402 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Ben Greear180205b2011-02-04 15:30:24 -08004403 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004404 else
Ben Greear180205b2011-02-04 15:30:24 -08004405 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004406
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004407 /* ACK received for nullfunc probing frame */
4408 if (!ifmgd->probe_send_count)
4409 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004410 else if (ifmgd->nullfunc_failed) {
4411 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004412 mlme_dbg(sdata,
4413 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4414 bssid, ifmgd->probe_send_count,
4415 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004416 ieee80211_mgd_probe_ap_send(sdata);
4417 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004418 mlme_dbg(sdata,
4419 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4420 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02004421 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004422 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4423 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004424 }
4425 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004426 run_again(sdata, ifmgd->probe_timeout);
Johannes Berg30686bf2015-06-02 21:39:54 +02004427 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004428 mlme_dbg(sdata,
4429 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4430 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02004431 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004432 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004433 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004434 mlme_dbg(sdata,
4435 "No probe response from AP %pM after %dms, try %d/%i\n",
4436 bssid, probe_wait_ms,
4437 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03004438 ieee80211_mgd_probe_ap_send(sdata);
4439 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02004440 /*
4441 * We actually lost the connection ... or did we?
4442 * Let's make sure!
4443 */
Johannes Berg89f774e2016-01-25 15:46:36 +02004444 mlme_dbg(sdata,
4445 "No probe response from AP %pM after %dms, disconnecting.\n",
4446 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004447
Johannes Berg95acac62011-07-12 12:30:59 +02004448 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004449 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02004450 }
4451 }
4452
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004453 sdata_unlock(sdata);
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004454}
Johannes Berg0a51b272008-09-08 17:44:25 +02004455
Kees Cook34f11cd2017-10-16 16:35:49 -07004456static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004457{
4458 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004459 from_timer(sdata, t, u.mgd.bcn_mon_timer);
Luciano Coelho0c21e632014-10-08 09:48:39 +03004460 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004461
Luciano Coelho0c21e632014-10-08 09:48:39 +03004462 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004463 return;
4464
Johannes Berg682bd382013-01-29 13:13:50 +01004465 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004466 ieee80211_queue_work(&sdata->local->hw,
4467 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004468}
4469
Kees Cook34f11cd2017-10-16 16:35:49 -07004470static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004471{
4472 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004473 from_timer(sdata, t, u.mgd.conn_mon_timer);
Johannes Bergb291ba12009-07-10 15:29:03 +02004474 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4475 struct ieee80211_local *local = sdata->local;
4476
Luciano Coelho0c21e632014-10-08 09:48:39 +03004477 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004478 return;
4479
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04004480 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004481}
4482
4483static void ieee80211_sta_monitor_work(struct work_struct *work)
4484{
4485 struct ieee80211_sub_if_data *sdata =
4486 container_of(work, struct ieee80211_sub_if_data,
4487 u.mgd.monitor_work);
4488
4489 ieee80211_mgd_probe_ap(sdata, false);
4490}
4491
Johannes Berga1678f82008-09-11 00:01:47 +02004492static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4493{
Kalle Vaload935682009-04-19 08:47:19 +03004494 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02004495 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03004496
Johannes Bergb291ba12009-07-10 15:29:03 +02004497 /* let's probe the connection once */
Johannes Berg30686bf2015-06-02 21:39:54 +02004498 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Eliad Peller494f1fe2012-02-19 15:26:09 +02004499 ieee80211_queue_work(&sdata->local->hw,
4500 &sdata->u.mgd.monitor_work);
Kalle Vaload935682009-04-19 08:47:19 +03004501 }
Johannes Berga1678f82008-09-11 00:01:47 +02004502}
4503
Johannes Bergb8360ab2013-04-29 14:57:44 +02004504#ifdef CONFIG_PM
Johannes Berg1a1cb742014-03-19 09:55:55 +01004505void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4506{
4507 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4508 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4509
4510 sdata_lock(sdata);
4511
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004512 if (ifmgd->auth_data || ifmgd->assoc_data) {
4513 const u8 *bssid = ifmgd->auth_data ?
4514 ifmgd->auth_data->bss->bssid :
4515 ifmgd->assoc_data->bss->bssid;
4516
Johannes Berg1a1cb742014-03-19 09:55:55 +01004517 /*
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004518 * If we are trying to authenticate / associate while suspending,
4519 * cfg80211 won't know and won't actually abort those attempts,
4520 * thus we need to do that ourselves.
Johannes Berg1a1cb742014-03-19 09:55:55 +01004521 */
Johannes Berg4b08d1b2019-08-30 14:24:51 +03004522 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
Johannes Berg1a1cb742014-03-19 09:55:55 +01004523 IEEE80211_STYPE_DEAUTH,
4524 WLAN_REASON_DEAUTH_LEAVING,
4525 false, frame_buf);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004526 if (ifmgd->assoc_data)
Johannes Berge6f462d2016-12-08 17:22:09 +01004527 ieee80211_destroy_assoc_data(sdata, false, true);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004528 if (ifmgd->auth_data)
4529 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg1a1cb742014-03-19 09:55:55 +01004530 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4531 IEEE80211_DEAUTH_FRAME_LEN);
4532 }
4533
Johannes Bergbe72afe2015-03-01 09:10:03 +02004534 /* This is a bit of a hack - we should find a better and more generic
4535 * solution to this. Normally when suspending, cfg80211 will in fact
4536 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4537 * auth (not so important) or assoc (this is the problem) process.
4538 *
4539 * As a consequence, it can happen that we are in the process of both
4540 * associating and suspending, and receive an association response
4541 * after cfg80211 has checked if it needs to disconnect, but before
4542 * we actually set the flag to drop incoming frames. This will then
4543 * cause the workqueue flush to process the association response in
4544 * the suspend, resulting in a successful association just before it
4545 * tries to remove the interface from the driver, which now though
4546 * has a channel context assigned ... this results in issues.
4547 *
4548 * To work around this (for now) simply deauth here again if we're
4549 * now connected.
4550 */
4551 if (ifmgd->associated && !sdata->local->wowlan) {
4552 u8 bssid[ETH_ALEN];
4553 struct cfg80211_deauth_request req = {
4554 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4555 .bssid = bssid,
4556 };
4557
4558 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4559 ieee80211_mgd_deauth(sdata, &req);
4560 }
4561
Johannes Berg1a1cb742014-03-19 09:55:55 +01004562 sdata_unlock(sdata);
4563}
4564
Johannes Bergb8360ab2013-04-29 14:57:44 +02004565void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4566{
4567 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4568
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004569 sdata_lock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004570 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004571 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004572 return;
4573 }
4574
4575 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4576 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4577 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4578 ieee80211_sta_connection_lost(sdata,
4579 ifmgd->associated->bssid,
4580 WLAN_REASON_UNSPECIFIED,
4581 true);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004582 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004583 return;
4584 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004585 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004586}
4587#endif
4588
Johannes Berg9c6bd792008-09-11 00:01:52 +02004589/* interface setup */
4590void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4591{
Johannes Berg46900292009-02-15 12:44:28 +01004592 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004593
Johannes Berg46900292009-02-15 12:44:28 +01004594 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004595 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01004596 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004597 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4598 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02004599 INIT_WORK(&ifmgd->csa_connection_drop_work,
4600 ieee80211_csa_connection_drop_work);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03004601 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03004602 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4603 ieee80211_tdls_peer_del_work);
Kees Cook34f11cd2017-10-16 16:35:49 -07004604 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4605 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4606 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4607 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
Johannes Berg02219b32014-10-07 10:38:50 +03004608 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4609 ieee80211_sta_handle_tspec_ac_params_wk);
Johannes Berg9c6bd792008-09-11 00:01:52 +02004610
Johannes Bergab1faea2009-07-01 21:41:17 +02004611 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05304612 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02004613 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4614 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01004615 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02004616
Eliad Peller0d8614b2014-09-10 14:07:36 +03004617 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
Johannes Berg0f782312009-12-01 13:37:02 +01004618 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4619 else
4620 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02004621
4622 /* Setup TDLS data */
4623 spin_lock_init(&ifmgd->teardown_lock);
4624 ifmgd->teardown_skb = NULL;
4625 ifmgd->orig_teardown_skb = NULL;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004626}
4627
4628/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02004629void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4630{
Johannes Berg31ee67a2012-07-06 21:18:24 +02004631 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02004632
4633 /* Restart STA timers */
4634 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07004635 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4636 if (ieee80211_sdata_running(sdata))
4637 ieee80211_restart_sta_timer(sdata);
4638 }
Johannes Berga1678f82008-09-11 00:01:47 +02004639 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02004640}
Johannes Berg10f644a2009-04-16 13:17:25 +02004641
Johannes Bergf2d9d272012-11-22 14:11:39 +01004642static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4643 struct cfg80211_bss *cbss)
4644{
4645 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4646 const u8 *ht_cap_ie, *vht_cap_ie;
4647 const struct ieee80211_ht_cap *ht_cap;
4648 const struct ieee80211_vht_cap *vht_cap;
4649 u8 chains = 1;
4650
4651 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4652 return chains;
4653
Johannes Berg9caf0362012-11-29 01:25:20 +01004654 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004655 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4656 ht_cap = (void *)(ht_cap_ie + 2);
4657 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4658 /*
4659 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4660 * "Tx Unequal Modulation Supported" fields.
4661 */
4662 }
4663
4664 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4665 return chains;
4666
Johannes Berg9caf0362012-11-29 01:25:20 +01004667 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004668 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4669 u8 nss;
4670 u16 tx_mcs_map;
4671
4672 vht_cap = (void *)(vht_cap_ie + 2);
4673 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4674 for (nss = 8; nss > 0; nss--) {
4675 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4676 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4677 break;
4678 }
4679 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4680 chains = max(chains, nss);
4681 }
4682
4683 return chains;
4684}
4685
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004686static bool
4687ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4688 const struct ieee80211_he_operation *he_op)
4689{
4690 const struct ieee80211_sta_he_cap *sta_he_cap =
4691 ieee80211_get_he_sta_cap(sband);
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004692 u16 ap_min_req_set;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004693 int i;
4694
4695 if (!sta_he_cap || !he_op)
4696 return false;
4697
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004698 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4699
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004700 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4701 for (i = 0; i < 3; i++) {
4702 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4703 &sta_he_cap->he_mcs_nss_supp;
4704 u16 sta_mcs_map_rx =
4705 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4706 u16 sta_mcs_map_tx =
4707 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4708 u8 nss;
4709 bool verified = true;
4710
4711 /*
4712 * For each band there is a maximum of 8 spatial streams
4713 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4714 * of 2 bits per NSS (1-8), with the values defined in enum
4715 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4716 * capabilities aren't less than the AP's minimum requirements
4717 * for this HE BSS per SS.
4718 * It is enough to find one such band that meets the reqs.
4719 */
4720 for (nss = 8; nss > 0; nss--) {
4721 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4722 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4723 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4724
4725 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4726 continue;
4727
4728 /*
4729 * Make sure the HE AP doesn't require MCSs that aren't
4730 * supported by the client
4731 */
4732 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4733 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4734 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4735 verified = false;
4736 break;
4737 }
4738 }
4739
4740 if (verified)
4741 return true;
4742 }
4743
4744 /* If here, STA doesn't meet AP's HE min requirements */
4745 return false;
4746}
4747
Johannes Bergb17166a2012-07-27 11:41:27 +02004748static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4749 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01004750{
4751 struct ieee80211_local *local = sdata->local;
4752 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Peller53b954e2014-07-24 11:20:05 +03004753 const struct ieee80211_ht_cap *ht_cap = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004754 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004755 const struct ieee80211_vht_operation *vht_oper = NULL;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004756 const struct ieee80211_he_operation *he_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004757 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01004758 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004759 int ret;
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004760 u32 i;
4761 bool have_80mhz;
Johannes Berga1cf7752012-03-08 15:02:07 +01004762
Johannes Berg24398e32012-03-28 10:58:36 +02004763 sband = local->hw.wiphy->bands[cbss->channel->band];
4764
Johannes Bergf2d9d272012-11-22 14:11:39 +01004765 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4766 IEEE80211_STA_DISABLE_80P80MHZ |
4767 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02004768
Johannes Berg75e296e2020-01-31 13:12:39 +02004769 /* disable HT/VHT/HE if we don't support them */
4770 if (!sband->ht_cap.ht_supported) {
4771 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4772 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4773 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4774 }
4775
4776 if (!sband->vht_cap.vht_supported)
4777 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4778
4779 if (!ieee80211_get_he_sta_cap(sband))
4780 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4781
Johannes Berg9caf0362012-11-29 01:25:20 +01004782 rcu_read_lock();
4783
Johannes Berg75e296e2020-01-31 13:12:39 +02004784 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Eliad Peller53b954e2014-07-24 11:20:05 +03004785 const u8 *ht_oper_ie, *ht_cap_ie;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004786
Johannes Berg9caf0362012-11-29 01:25:20 +01004787 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02004788 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4789 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6effa2013-02-07 23:33:32 +01004790
Eliad Peller53b954e2014-07-24 11:20:05 +03004791 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4792 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4793 ht_cap = (void *)(ht_cap_ie + 2);
4794
4795 if (!ht_cap) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004796 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4797 ht_oper = NULL;
4798 }
Johannes Berg24398e32012-03-28 10:58:36 +02004799 }
4800
Johannes Berg75e296e2020-01-31 13:12:39 +02004801 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004802 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004803
Johannes Berg9caf0362012-11-29 01:25:20 +01004804 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4805 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004806 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4807 vht_oper = (void *)(vht_oper_ie + 2);
4808 if (vht_oper && !ht_oper) {
4809 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004810 sdata_info(sdata,
Johannes Berg75e296e2020-01-31 13:12:39 +02004811 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
Johannes Bergcb145022013-02-07 20:41:50 +01004812 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4813 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg75e296e2020-01-31 13:12:39 +02004814 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Johannes Berg24398e32012-03-28 10:58:36 +02004815 }
Johannes Berg08e6effa2013-02-07 23:33:32 +01004816
4817 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4818 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4819 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4820 vht_oper = NULL;
4821 }
Johannes Berg24398e32012-03-28 10:58:36 +02004822 }
4823
Shaul Triebitz002245e2018-12-15 11:03:19 +02004824 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004825 const struct cfg80211_bss_ies *ies;
4826 const u8 *he_oper_ie;
4827
4828 ies = rcu_dereference(cbss->ies);
4829 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
4830 ies->data, ies->len);
4831 if (he_oper_ie &&
4832 he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
4833 he_oper = (void *)(he_oper_ie + 3);
4834 else
4835 he_oper = NULL;
4836
Johannes Bergf0c04072018-06-29 09:51:39 +02004837 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004838 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4839 }
4840
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004841 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4842 have_80mhz = false;
4843 for (i = 0; i < sband->n_channels; i++) {
4844 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4845 IEEE80211_CHAN_NO_80MHZ))
4846 continue;
4847
4848 have_80mhz = true;
4849 break;
4850 }
4851
4852 if (!have_80mhz)
4853 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4854
Johannes Bergf2d9d272012-11-22 14:11:39 +01004855 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4856 cbss->channel,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004857 ht_oper, vht_oper, he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +02004858 &chandef, false);
Johannes Berg04ecd252012-09-11 14:34:12 +02004859
Johannes Bergf2d9d272012-11-22 14:11:39 +01004860 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4861 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02004862
Johannes Berg9caf0362012-11-29 01:25:20 +01004863 rcu_read_unlock();
4864
Johannes Berg04ecd252012-09-11 14:34:12 +02004865 /* will change later if needed */
4866 sdata->smps_mode = IEEE80211_SMPS_OFF;
4867
Johannes Berg34a37402013-12-18 09:43:33 +01004868 mutex_lock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004869 /*
4870 * If this fails (possibly due to channel context sharing
4871 * on incompatible channels, e.g. 80+80 and 160 sharing the
4872 * same control channel) try to use a smaller bandwidth.
4873 */
4874 ret = ieee80211_vif_use_channel(sdata, &chandef,
4875 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich0418a442013-05-16 13:00:31 +02004876
4877 /* don't downgrade for 5 and 10 MHz channels, though. */
4878 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4879 chandef.width == NL80211_CHAN_WIDTH_10)
Johannes Berg34a37402013-12-18 09:43:33 +01004880 goto out;
Simon Wunderlich0418a442013-05-16 13:00:31 +02004881
Johannes Bergd601cd82013-02-07 20:54:51 +01004882 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02004883 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01004884 ret = ieee80211_vif_use_channel(sdata, &chandef,
4885 IEEE80211_CHANCTX_SHARED);
4886 }
Johannes Berg34a37402013-12-18 09:43:33 +01004887 out:
4888 mutex_unlock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004889 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02004890}
4891
Sara Sharon78ac51f2019-01-16 18:22:56 +02004892static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
4893 u8 *dtim_count, u8 *dtim_period)
4894{
4895 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
4896 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
4897 ies->len);
4898 const struct ieee80211_tim_ie *tim = NULL;
4899 const struct ieee80211_bssid_index *idx;
4900 bool valid = tim_ie && tim_ie[1] >= 2;
4901
4902 if (valid)
4903 tim = (void *)(tim_ie + 2);
4904
4905 if (dtim_count)
4906 *dtim_count = valid ? tim->dtim_count : 0;
4907
4908 if (dtim_period)
4909 *dtim_period = valid ? tim->dtim_period : 0;
4910
4911 /* Check if value is overridden by non-transmitted profile */
4912 if (!idx_ie || idx_ie[1] < 3)
4913 return valid;
4914
4915 idx = (void *)(idx_ie + 2);
4916
4917 if (dtim_count)
4918 *dtim_count = idx->dtim_count;
4919
4920 if (dtim_period)
4921 *dtim_period = idx->dtim_period;
4922
4923 return true;
4924}
4925
Johannes Bergb17166a2012-07-27 11:41:27 +02004926static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004927 struct cfg80211_bss *cbss, bool assoc,
4928 bool override)
Johannes Bergb17166a2012-07-27 11:41:27 +02004929{
4930 struct ieee80211_local *local = sdata->local;
4931 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4932 struct ieee80211_bss *bss = (void *)cbss->priv;
4933 struct sta_info *new_sta = NULL;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004934 struct ieee80211_supported_band *sband;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004935 bool have_sta = false;
Johannes Bergb17166a2012-07-27 11:41:27 +02004936 int err;
4937
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004938 sband = local->hw.wiphy->bands[cbss->channel->band];
4939
Johannes Bergb17166a2012-07-27 11:41:27 +02004940 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4941 return -EINVAL;
4942
Luca Coelhof8860ce2017-05-02 17:56:21 +03004943 /* If a reconfig is happening, bail out */
4944 if (local->in_reconfig)
4945 return -EBUSY;
4946
Johannes Bergb17166a2012-07-27 11:41:27 +02004947 if (assoc) {
4948 rcu_read_lock();
4949 have_sta = sta_info_get(sdata, cbss->bssid);
4950 rcu_read_unlock();
4951 }
4952
4953 if (!have_sta) {
4954 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4955 if (!new_sta)
4956 return -ENOMEM;
4957 }
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004958
Johannes Bergc87905b2017-06-10 13:52:43 +03004959 /*
4960 * Set up the information for the new channel before setting the
4961 * new channel. We can't - completely race-free - change the basic
4962 * rates bitmap and the channel (sband) that it refers to, but if
4963 * we set it up before we at least avoid calling into the driver's
4964 * bss_info_changed() method with invalid information (since we do
4965 * call that from changing the channel - only for IDLE and perhaps
4966 * some others, but ...).
4967 *
4968 * So to avoid that, just set up all the new information before the
4969 * channel, but tell the driver to apply it only afterwards, since
4970 * it might need the new channel for that.
4971 */
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004972 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004973 u32 rates = 0, basic_rates = 0;
4974 bool have_higher_than_11mbit;
4975 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004976 const struct cfg80211_bss_ies *ies;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004977 int shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004978
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004979 ieee80211_get_rates(sband, bss->supp_rates,
4980 bss->supp_rates_len,
4981 &rates, &basic_rates,
4982 &have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02004983 &min_rate, &min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03004984 shift);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004985
4986 /*
4987 * This used to be a workaround for basic rates missing
4988 * in the association response frame. Now that we no
4989 * longer use the basic rates from there, it probably
4990 * doesn't happen any more, but keep the workaround so
4991 * in case some *other* APs are buggy in different ways
4992 * we can connect -- with a warning.
4993 */
4994 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004995 sdata_info(sdata,
4996 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004997 basic_rates = BIT(min_rate_index);
4998 }
4999
Johannes Bergbd718fc2019-05-29 15:25:35 +03005000 if (rates)
5001 new_sta->sta.supp_rates[cbss->channel->band] = rates;
5002 else
5003 sdata_info(sdata,
5004 "No rates found, keeping mandatory only\n");
5005
Johannes Berg5d6a1b02012-03-08 15:02:08 +01005006 sdata->vif.bss_conf.basic_rates = basic_rates;
5007
5008 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg57fbcce2016-04-12 15:56:15 +02005009 if (cbss->channel->band == NL80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01005010 have_higher_than_11mbit)
5011 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
5012 else
5013 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
5014
5015 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
5016
Johannes Berg8c358bc2012-05-22 22:13:05 +02005017 /* set timing information */
5018 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005019 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01005020 ies = rcu_dereference(cbss->beacon_ies);
5021 if (ies) {
Johannes Bergef429da2013-02-05 17:48:40 +01005022 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5023 sdata->vif.bss_conf.sync_device_ts =
5024 bss->device_ts_beacon;
Sara Sharon78ac51f2019-01-16 18:22:56 +02005025
5026 ieee80211_get_dtim(ies,
5027 &sdata->vif.bss_conf.sync_dtim_count,
5028 NULL);
Johannes Berg30686bf2015-06-02 21:39:54 +02005029 } else if (!ieee80211_hw_check(&sdata->local->hw,
5030 TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005031 ies = rcu_dereference(cbss->proberesp_ies);
5032 /* must be non-NULL since beacon IEs were NULL */
5033 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5034 sdata->vif.bss_conf.sync_device_ts =
5035 bss->device_ts_presp;
5036 sdata->vif.bss_conf.sync_dtim_count = 0;
5037 } else {
5038 sdata->vif.bss_conf.sync_tsf = 0;
5039 sdata->vif.bss_conf.sync_device_ts = 0;
5040 sdata->vif.bss_conf.sync_dtim_count = 0;
5041 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01005042 rcu_read_unlock();
Johannes Bergc87905b2017-06-10 13:52:43 +03005043 }
Johannes Berg8c358bc2012-05-22 22:13:05 +02005044
Johannes Bergc87905b2017-06-10 13:52:43 +03005045 if (new_sta || override) {
5046 err = ieee80211_prep_channel(sdata, cbss);
5047 if (err) {
5048 if (new_sta)
5049 sta_info_free(local, new_sta);
5050 return -EINVAL;
5051 }
5052 }
5053
5054 if (new_sta) {
5055 /*
5056 * tell driver about BSSID, basic rates and timing
5057 * this was set up above, before setting the channel
5058 */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01005059 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02005060 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5061 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01005062
5063 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02005064 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01005065
Johannes Berg13e0c8e2012-07-27 10:43:16 +02005066 err = sta_info_insert(new_sta);
5067 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01005068 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005069 sdata_info(sdata,
5070 "failed to insert STA entry for the AP (error %d)\n",
5071 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01005072 return err;
5073 }
5074 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00005075 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01005076
David Spinadel7d830a12015-03-17 19:58:38 +02005077 /* Cancel scan to ensure that nothing interferes with connection */
5078 if (local->scanning)
5079 ieee80211_scan_cancel(local);
5080
Johannes Berga1cf7752012-03-08 15:02:07 +01005081 return 0;
5082}
5083
Johannes Berg77fdaa12009-07-07 03:45:17 +02005084/* config hooks */
5085int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5086 struct cfg80211_auth_request *req)
5087{
Johannes Berg66e67e42012-01-20 13:55:27 +01005088 struct ieee80211_local *local = sdata->local;
5089 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5090 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005091 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01005092 int err;
Jouni Malinenefb543e2018-10-11 00:21:21 +03005093 bool cont_auth;
Johannes Berg66e67e42012-01-20 13:55:27 +01005094
5095 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02005096
5097 switch (req->auth_type) {
5098 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5099 auth_alg = WLAN_AUTH_OPEN;
5100 break;
5101 case NL80211_AUTHTYPE_SHARED_KEY:
Ard Biesheuvel5fdb3732019-06-12 18:19:54 +02005102 if (fips_enabled)
Johannes Berg9dca9c42010-07-21 10:09:25 +02005103 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005104 auth_alg = WLAN_AUTH_SHARED_KEY;
5105 break;
5106 case NL80211_AUTHTYPE_FT:
5107 auth_alg = WLAN_AUTH_FT;
5108 break;
5109 case NL80211_AUTHTYPE_NETWORK_EAP:
5110 auth_alg = WLAN_AUTH_LEAP;
5111 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005112 case NL80211_AUTHTYPE_SAE:
5113 auth_alg = WLAN_AUTH_SAE;
5114 break;
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03005115 case NL80211_AUTHTYPE_FILS_SK:
5116 auth_alg = WLAN_AUTH_FILS_SK;
5117 break;
5118 case NL80211_AUTHTYPE_FILS_SK_PFS:
5119 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5120 break;
5121 case NL80211_AUTHTYPE_FILS_PK:
5122 auth_alg = WLAN_AUTH_FILS_PK;
5123 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005124 default:
5125 return -EOPNOTSUPP;
5126 }
5127
Jouni Malinenefb543e2018-10-11 00:21:21 +03005128 if (ifmgd->assoc_data)
Jouni Malinen8d7432a2018-10-11 00:21:20 +03005129 return -EBUSY;
5130
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03005131 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005132 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01005133 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005134 return -ENOMEM;
5135
Johannes Berg66e67e42012-01-20 13:55:27 +01005136 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005137
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03005138 if (req->auth_data_len >= 4) {
Jouni Malinen6ec63612016-10-27 00:41:59 +03005139 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5140 __le16 *pos = (__le16 *) req->auth_data;
5141
5142 auth_data->sae_trans = le16_to_cpu(pos[0]);
5143 auth_data->sae_status = le16_to_cpu(pos[1]);
5144 }
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03005145 memcpy(auth_data->data, req->auth_data + 4,
5146 req->auth_data_len - 4);
5147 auth_data->data_len += req->auth_data_len - 4;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005148 }
5149
Jouni Malinenefb543e2018-10-11 00:21:21 +03005150 /* Check if continuing authentication or trying to authenticate with the
5151 * same BSS that we were in the process of authenticating with and avoid
5152 * removal and re-addition of the STA entry in
5153 * ieee80211_prep_connection().
5154 */
5155 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5156
Johannes Berg77fdaa12009-07-07 03:45:17 +02005157 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03005158 memcpy(&auth_data->data[auth_data->data_len],
5159 req->ie, req->ie_len);
5160 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005161 }
5162
Johannes Bergfffd0932009-07-08 14:22:54 +02005163 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005164 auth_data->key_len = req->key_len;
5165 auth_data->key_idx = req->key_idx;
5166 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02005167 }
5168
Johannes Berg66e67e42012-01-20 13:55:27 +01005169 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005170
Johannes Berg66e67e42012-01-20 13:55:27 +01005171 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01005172
Jouni Malinenefb543e2018-10-11 00:21:21 +03005173 if (ifmgd->auth_data) {
5174 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5175 auth_data->peer_confirmed =
5176 ifmgd->auth_data->peer_confirmed;
5177 }
5178 ieee80211_destroy_auth_data(sdata, cont_auth);
5179 }
Guy Eilam2a33bee2011-08-17 15:18:15 +03005180
Johannes Berg66e67e42012-01-20 13:55:27 +01005181 /* prep auth_data so we don't go into idle on disassoc */
5182 ifmgd->auth_data = auth_data;
5183
Jouni Malinenefb543e2018-10-11 00:21:21 +03005184 /* If this is continuation of an ongoing SAE authentication exchange
5185 * (i.e., request to send SAE Confirm) and the peer has already
5186 * confirmed, mark authentication completed since we are about to send
5187 * out SAE Confirm.
5188 */
5189 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5190 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5191 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5192
Johannes Berg7b119dc2013-04-10 21:38:36 +02005193 if (ifmgd->associated) {
5194 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5195
Johannes Berg89f774e2016-01-25 15:46:36 +02005196 sdata_info(sdata,
5197 "disconnect from AP %pM for new auth to %pM\n",
5198 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005199 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5200 WLAN_REASON_UNSPECIFIED,
5201 false, frame_buf);
5202
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005203 ieee80211_report_disconnect(sdata, frame_buf,
5204 sizeof(frame_buf), true,
5205 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005206 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005207
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005208 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005209
Jouni Malinenefb543e2018-10-11 00:21:21 +03005210 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
Johannes Berga1cf7752012-03-08 15:02:07 +01005211 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01005212 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005213
Johannes Berg46cad4b2015-08-15 22:39:54 +03005214 err = ieee80211_auth(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01005215 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005216 sta_info_destroy_addr(sdata, req->bss->bssid);
5217 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005218 }
5219
Johannes Berg66e67e42012-01-20 13:55:27 +01005220 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01005221 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005222 return 0;
Johannes Berge5b900d2010-07-29 16:08:55 +02005223
Johannes Berg66e67e42012-01-20 13:55:27 +01005224 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005225 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005226 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005227 ifmgd->auth_data = NULL;
Michal Kaziord01f8582015-06-03 08:36:13 +02005228 mutex_lock(&sdata->local->mtx);
5229 ieee80211_vif_release_channel(sdata);
5230 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01005231 kfree(auth_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005232 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005233}
5234
Johannes Berg77fdaa12009-07-07 03:45:17 +02005235int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5236 struct cfg80211_assoc_request *req)
5237{
Johannes Berg66e67e42012-01-20 13:55:27 +01005238 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005239 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01005240 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01005241 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005242 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005243 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005244 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005245 int i, err;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005246 bool override = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005247
Johannes Berg66e67e42012-01-20 13:55:27 +01005248 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5249 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01005250 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005251
Johannes Berg9caf0362012-11-29 01:25:20 +01005252 rcu_read_lock();
5253 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Will Deacon41525612019-10-04 10:51:31 +01005254 if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
Johannes Berg9caf0362012-11-29 01:25:20 +01005255 rcu_read_unlock();
5256 kfree(assoc_data);
5257 return -EINVAL;
5258 }
5259 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5260 assoc_data->ssid_len = ssidie[1];
5261 rcu_read_unlock();
5262
Johannes Berg7b119dc2013-04-10 21:38:36 +02005263 if (ifmgd->associated) {
5264 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5265
Johannes Berg89f774e2016-01-25 15:46:36 +02005266 sdata_info(sdata,
5267 "disconnect from AP %pM for new assoc to %pM\n",
5268 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005269 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5270 WLAN_REASON_UNSPECIFIED,
5271 false, frame_buf);
5272
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005273 ieee80211_report_disconnect(sdata, frame_buf,
5274 sizeof(frame_buf), true,
5275 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005276 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005277
5278 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5279 err = -EBUSY;
5280 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005281 }
5282
Johannes Berg66e67e42012-01-20 13:55:27 +01005283 if (ifmgd->assoc_data) {
5284 err = -EBUSY;
5285 goto err_free;
5286 }
5287
5288 if (ifmgd->auth_data) {
5289 bool match;
5290
5291 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00005292 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005293 ieee80211_destroy_auth_data(sdata, match);
5294 }
5295
5296 /* prepare assoc data */
Johannes Berg095d81c2013-10-15 12:25:07 +02005297
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03005298 ifmgd->beacon_crc_valid = false;
5299
Johannes Berg095d81c2013-10-15 12:25:07 +02005300 assoc_data->wmm = bss->wmm_used &&
5301 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg095d81c2013-10-15 12:25:07 +02005302
Johannes Bergde5036a2012-03-08 15:02:03 +01005303 /*
5304 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5305 * We still associate in non-HT mode (11a/b/g) if any one of these
5306 * ciphers is configured as pairwise.
5307 * We can set this to true for non-11n hardware, that'll be checked
5308 * separately along with the peer capabilities.
5309 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02005310 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02005311 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5312 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02005313 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01005314 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005315 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005316 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Johannes Berg1c4cb922012-05-30 15:57:00 +02005317 netdev_info(sdata->dev,
Johannes Berg54626322019-08-30 14:24:46 +03005318 "disabling HT/VHT/HE due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005319 }
5320 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005321
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005322 sband = local->hw.wiphy->bands[req->bss->channel->band];
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005323
Johannes Berg75e296e2020-01-31 13:12:39 +02005324 /* also disable HT/VHT/HE if the AP doesn't use WMM */
5325 if (!bss->wmm_used) {
5326 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005327 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg75e296e2020-01-31 13:12:39 +02005328 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5329 netdev_info(sdata->dev,
5330 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005331 }
5332
Ben Greearef96a8422011-11-18 11:32:00 -08005333 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5334 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5335 sizeof(ifmgd->ht_capa_mask));
5336
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01005337 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5338 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5339 sizeof(ifmgd->vht_capa_mask));
5340
Johannes Berg77fdaa12009-07-07 03:45:17 +02005341 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005342 memcpy(assoc_data->ie, req->ie, req->ie_len);
5343 assoc_data->ie_len = req->ie_len;
5344 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005345
Jouni Malinen39404fe2016-10-27 00:42:05 +03005346 if (req->fils_kek) {
5347 /* should already be checked in cfg80211 - so warn */
5348 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5349 err = -EINVAL;
5350 goto err_free;
5351 }
5352 memcpy(assoc_data->fils_kek, req->fils_kek,
5353 req->fils_kek_len);
5354 assoc_data->fils_kek_len = req->fils_kek_len;
5355 }
5356
5357 if (req->fils_nonces)
5358 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5359 2 * FILS_NONCE_LEN);
5360
Johannes Berg66e67e42012-01-20 13:55:27 +01005361 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01005362
Johannes Bergaf6b6372009-12-23 13:15:35 +01005363 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5364 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02005365 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005366 else
Johannes Berg04ecd252012-09-11 14:34:12 +02005367 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005368 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02005369 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005370
Johannes Berg66e67e42012-01-20 13:55:27 +01005371 assoc_data->capability = req->bss->capability;
Johannes Berg66e67e42012-01-20 13:55:27 +01005372 assoc_data->supp_rates = bss->supp_rates;
5373 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02005374
Johannes Berg9caf0362012-11-29 01:25:20 +01005375 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02005376 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5377 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5378 assoc_data->ap_ht_param =
5379 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5380 else
Johannes Berga8243b72012-11-22 14:32:09 +01005381 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005382 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5383 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5384 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5385 sizeof(struct ieee80211_vht_cap));
5386 else
5387 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01005388 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01005389
Johannes Berg848955c2014-11-11 12:48:42 +01005390 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02005391 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
Johannes Berg848955c2014-11-11 12:48:42 +01005392 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5393 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5394
Kalle Valoab133152010-01-12 10:42:31 +02005395 if (bss->wmm_used && bss->uapsd_supported &&
Johannes Berg848955c2014-11-11 12:48:42 +01005396 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01005397 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02005398 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5399 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01005400 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02005401 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5402 }
5403
Johannes Berg77fdaa12009-07-07 03:45:17 +02005404 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01005405 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005406
5407 if (req->use_mfp) {
5408 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5409 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5410 } else {
5411 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5412 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5413 }
5414
Assaf Krausscd2f5dd2014-09-03 15:25:02 +03005415 if (req->flags & ASSOC_REQ_USE_RRM)
5416 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5417 else
5418 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5419
Johannes Berg77fdaa12009-07-07 03:45:17 +02005420 if (req->crypto.control_port)
5421 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5422 else
5423 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5424
Johannes Berga621fa42010-08-27 14:26:54 +03005425 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5426 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05005427 sdata->control_port_over_nl80211 =
5428 req->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02005429 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5430 sdata->vif.type);
Johannes Berga621fa42010-08-27 14:26:54 +03005431
Johannes Berg66e67e42012-01-20 13:55:27 +01005432 /* kick off associate process */
5433
5434 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02005435 ifmgd->dtim_period = 0;
Alexander Bondar989c6502013-05-16 17:34:17 +03005436 ifmgd->have_beacon = false;
Johannes Berg66e67e42012-01-20 13:55:27 +01005437
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005438 /* override HT/VHT configuration only if the AP and we support it */
5439 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5440 struct ieee80211_sta_ht_cap sta_ht_cap;
5441
5442 if (req->flags & ASSOC_REQ_DISABLE_HT)
5443 override = true;
5444
5445 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5446 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5447
5448 /* check for 40 MHz disable override */
5449 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5450 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5451 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5452 override = true;
5453
5454 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5455 req->flags & ASSOC_REQ_DISABLE_VHT)
5456 override = true;
5457 }
5458
5459 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5460 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5461 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg75e296e2020-01-31 13:12:39 +02005462 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005463 }
5464
5465 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5466 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5467
5468 err = ieee80211_prep_connection(sdata, req->bss, true, override);
Johannes Berga1cf7752012-03-08 15:02:07 +01005469 if (err)
5470 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01005471
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005472 rcu_read_lock();
5473 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02005474
Johannes Berg30686bf2015-06-02 21:39:54 +02005475 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005476 !beacon_ies) {
5477 /*
5478 * Wait up to one beacon interval ...
5479 * should this be more if we miss one?
5480 */
5481 sdata_info(sdata, "waiting for beacon from %pM\n",
5482 ifmgd->bssid);
5483 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01005484 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005485 assoc_data->need_beacon = true;
5486 } else if (beacon_ies) {
Sara Sharon78ac51f2019-01-16 18:22:56 +02005487 const u8 *ie;
Johannes Bergef429da2013-02-05 17:48:40 +01005488 u8 dtim_count = 0;
5489
Sara Sharon78ac51f2019-01-16 18:22:56 +02005490 ieee80211_get_dtim(beacon_ies, &dtim_count,
5491 &ifmgd->dtim_period);
5492
Alexander Bondar989c6502013-05-16 17:34:17 +03005493 ifmgd->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005494 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005495 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01005496
Johannes Berg30686bf2015-06-02 21:39:54 +02005497 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005498 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5499 sdata->vif.bss_conf.sync_device_ts =
5500 bss->device_ts_beacon;
5501 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5502 }
Sara Sharon78ac51f2019-01-16 18:22:56 +02005503
5504 ie = cfg80211_find_ext_ie(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5505 beacon_ies->data, beacon_ies->len);
5506 if (ie && ie[1] >= 3)
5507 sdata->vif.bss_conf.profile_periodicity = ie[4];
5508
5509 ie = cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY,
5510 beacon_ies->data, beacon_ies->len);
5511 if (ie && ie[1] >= 11 &&
5512 (ie[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5513 sdata->vif.bss_conf.ema_ap = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005514 } else {
5515 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005516 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005517 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005518 rcu_read_unlock();
5519
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005520 run_again(sdata, assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01005521
Paul Stewartfcff4f12012-02-23 17:59:53 -08005522 if (bss->corrupt_data) {
5523 char *corrupt_type = "data";
5524 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5525 if (bss->corrupt_data &
5526 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5527 corrupt_type = "beacon and probe response";
5528 else
5529 corrupt_type = "beacon";
5530 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5531 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005532 sdata_info(sdata, "associating with AP with corrupt %s\n",
5533 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08005534 }
5535
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005536 return 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01005537 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005538 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005539 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005540 ifmgd->assoc_data = NULL;
5541 err_free:
5542 kfree(assoc_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005543 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005544}
5545
5546int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005547 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005548{
5549 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005550 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005551 bool tx = !req->local_state_change;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005552
Johannes Bergc9c3a062014-03-19 09:11:19 +01005553 if (ifmgd->auth_data &&
5554 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5555 sdata_info(sdata,
5556 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5557 req->bssid, req->reason_code,
5558 ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005559
Ilan Peerd4e36e52018-04-20 13:49:25 +03005560 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg4b08d1b2019-08-30 14:24:51 +03005561 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
Johannes Berg37ad3882012-02-24 13:50:54 +01005562 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005563 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01005564 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01005565 ieee80211_destroy_auth_data(sdata, false);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005566 ieee80211_report_disconnect(sdata, frame_buf,
5567 sizeof(frame_buf), true,
5568 req->reason_code);
Johannes Berg86552012012-10-29 09:46:31 +01005569
Johannes Bergc9c3a062014-03-19 09:11:19 +01005570 return 0;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03005571 }
5572
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005573 if (ifmgd->assoc_data &&
5574 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5575 sdata_info(sdata,
5576 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5577 req->bssid, req->reason_code,
5578 ieee80211_get_reason_code_string(req->reason_code));
5579
Ilan Peerd4e36e52018-04-20 13:49:25 +03005580 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg4b08d1b2019-08-30 14:24:51 +03005581 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005582 IEEE80211_STYPE_DEAUTH,
5583 req->reason_code, tx,
5584 frame_buf);
Johannes Berge6f462d2016-12-08 17:22:09 +01005585 ieee80211_destroy_assoc_data(sdata, false, true);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005586 ieee80211_report_disconnect(sdata, frame_buf,
5587 sizeof(frame_buf), true,
5588 req->reason_code);
5589 return 0;
5590 }
5591
Johannes Berg86552012012-10-29 09:46:31 +01005592 if (ifmgd->associated &&
5593 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
Johannes Bergc9c3a062014-03-19 09:11:19 +01005594 sdata_info(sdata,
5595 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5596 req->bssid, req->reason_code,
5597 ieee80211_get_reason_code_string(req->reason_code));
5598
Johannes Berg86552012012-10-29 09:46:31 +01005599 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5600 req->reason_code, tx, frame_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005601 ieee80211_report_disconnect(sdata, frame_buf,
5602 sizeof(frame_buf), true,
5603 req->reason_code);
Johannes Bergc9c3a062014-03-19 09:11:19 +01005604 return 0;
5605 }
Johannes Berg86552012012-10-29 09:46:31 +01005606
Johannes Bergc9c3a062014-03-19 09:11:19 +01005607 return -ENOTCONN;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005608}
5609
5610int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005611 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005612{
5613 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07005614 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005615 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02005616
Johannes Berg8d8b2612009-07-25 11:58:36 +02005617 /*
5618 * cfg80211 should catch this ... but it's racy since
5619 * we can receive a disassoc frame, process it, hand it
5620 * to cfg80211 while that's in a locked section already
5621 * trying to tell us that the user wants to disconnect.
5622 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005623 if (ifmgd->associated != req->bss)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005624 return -ENOLINK;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005625
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005626 sdata_info(sdata,
Calvin Owensdfa1ad22014-02-11 12:36:24 -06005627 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5628 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005629
Jouni Malinene69e95d2010-03-29 23:29:31 -07005630 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01005631 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5632 req->reason_code, !req->local_state_change,
5633 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005634
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005635 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5636 req->reason_code);
Johannes Bergbc83b682009-11-29 12:19:06 +01005637
Johannes Berg77fdaa12009-07-07 03:45:17 +02005638 return 0;
5639}
Jouni Malinen026331c2010-02-15 12:53:10 +02005640
Eliad Pellerafa762f2012-04-23 14:45:15 +03005641void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005642{
5643 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5644
Ben Greear49921852013-02-20 09:41:09 -08005645 /*
5646 * Make sure some work items will not run after this,
5647 * they will not do anything but might not have been
5648 * cancelled when disconnecting.
5649 */
5650 cancel_work_sync(&ifmgd->monitor_work);
5651 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5652 cancel_work_sync(&ifmgd->request_smps_work);
5653 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5654 cancel_work_sync(&ifmgd->chswitch_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03005655 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
Ben Greear49921852013-02-20 09:41:09 -08005656
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005657 sdata_lock(sdata);
Johannes Berg959867f2013-06-19 13:05:42 +02005658 if (ifmgd->assoc_data) {
5659 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Johannes Berge6f462d2016-12-08 17:22:09 +01005660 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02005661 cfg80211_assoc_timeout(sdata->dev, bss);
5662 }
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005663 if (ifmgd->auth_data)
5664 ieee80211_destroy_auth_data(sdata, false);
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005665 spin_lock_bh(&ifmgd->teardown_lock);
5666 if (ifmgd->teardown_skb) {
5667 kfree_skb(ifmgd->teardown_skb);
5668 ifmgd->teardown_skb = NULL;
5669 ifmgd->orig_teardown_skb = NULL;
5670 }
Jouni Malinen4d9ec732019-02-15 02:14:33 +02005671 kfree(ifmgd->assoc_req_ies);
5672 ifmgd->assoc_req_ies = NULL;
5673 ifmgd->assoc_req_ies_len = 0;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005674 spin_unlock_bh(&ifmgd->teardown_lock);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005675 del_timer_sync(&ifmgd->timer);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005676 sdata_unlock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005677}
5678
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005679void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5680 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005681 s32 rssi_level,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005682 gfp_t gfp)
5683{
5684 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5685
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005686 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
Johannes Bergb5878a22010-04-07 16:48:40 +02005687
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01005688 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005689}
5690EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
Johannes Berg98f03342014-11-26 12:42:02 +01005691
5692void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5693{
5694 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5695
5696 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5697
5698 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5699}
5700EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);