blob: 1f41f760bd22acfd0590fcb788da7b9ab395cb85 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * BSS client mode implementation
Jouni Malinen5394af42009-01-08 13:31:59 +02003 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
Jiri Bencf0706e82007-05-05 11:45:53 -07004 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
Johannes Bergd98ad832014-09-03 15:24:57 +03008 * Copyright 2013-2014 Intel Mobile Communications GmbH
Avraham Sterne38a0172017-04-26 10:58:47 +03009 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
Ilan Peer94ba9272018-02-19 14:48:41 +020010 * Copyright (C) 2018 Intel Corporation
Jiri Bencf0706e82007-05-05 11:45:53 -070011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070017#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018#include <linux/if_ether.h>
19#include <linux/skbuff.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070020#include <linux/if_arp.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070021#include <linux/etherdevice.h>
Paul Gortmakerd9b93842011-09-18 13:21:27 -040022#include <linux/moduleparam.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010023#include <linux/rtnetlink.h>
Johannes Bergd91f36d2009-04-16 13:17:26 +020024#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040026#include <linux/export.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070027#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020028#include <asm/unaligned.h>
Johannes Berg60f8b39c2008-09-08 17:44:22 +020029
Jiri Bencf0706e82007-05-05 11:45:53 -070030#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020031#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040032#include "rate.h"
33#include "led.h"
Jouni Malinen39404fe2016-10-27 00:42:05 +030034#include "fils_aead.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070035
Johannes Berg1672c0e32013-01-29 15:02:27 +010036#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020037#define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010038#define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
Ilan Peer407879b2018-04-20 13:49:20 +030039#define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010040#define IEEE80211_AUTH_MAX_TRIES 3
41#define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
42#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020043#define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010044#define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
45#define IEEE80211_ASSOC_MAX_TRIES 3
Johannes Berg66e67e42012-01-20 13:55:27 +010046
Ben Greear180205b2011-02-04 15:30:24 -080047static int max_nullfunc_tries = 2;
48module_param(max_nullfunc_tries, int, 0644);
49MODULE_PARM_DESC(max_nullfunc_tries,
50 "Maximum nullfunc tx tries before disconnecting (reason 4).");
51
52static int max_probe_tries = 5;
53module_param(max_probe_tries, int, 0644);
54MODULE_PARM_DESC(max_probe_tries,
55 "Maximum probe tries before disconnecting (reason 4).");
Johannes Bergb291ba12009-07-10 15:29:03 +020056
57/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010058 * Beacon loss timeout is calculated as N frames times the
59 * advertised beacon interval. This may need to be somewhat
60 * higher than what hardware might detect to account for
61 * delays in the host processing frames. But since we also
62 * probe on beacon miss before declaring the connection lost
63 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020064 */
Ben Greear59c1ec22013-03-19 14:19:56 -070065static int beacon_loss_count = 7;
66module_param(beacon_loss_count, int, 0644);
67MODULE_PARM_DESC(beacon_loss_count,
68 "Number of beacon intervals before we decide beacon was lost.");
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010069
Johannes Bergb291ba12009-07-10 15:29:03 +020070/*
71 * Time the connection can be idle before we probe
72 * it to see if we can still talk to the AP.
73 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030074#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020075/*
76 * Time we wait for a probe response after sending
77 * a probe request because of beacon loss or for
78 * checking the connection still works.
79 */
Ben Greear180205b2011-02-04 15:30:24 -080080static int probe_wait_ms = 500;
81module_param(probe_wait_ms, int, 0644);
82MODULE_PARM_DESC(probe_wait_ms,
83 "Maximum time(ms) to wait for probe response"
84 " before disconnecting (reason 4).");
Jiri Bencf0706e82007-05-05 11:45:53 -070085
Jouni Malinen17e4ec12010-03-29 23:28:30 -070086/*
Jouni Malinen391a2002010-08-27 22:22:00 +030087 * How many Beacon frames need to have been used in average signal strength
88 * before starting to indicate signal change events.
89 */
90#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
91
Johannes Berg77fdaa12009-07-07 03:45:17 +020092/*
Johannes Bergca386f32009-07-10 02:39:48 +020093 * We can have multiple work items (and connection probing)
94 * scheduling this timer, but we need to take care to only
95 * reschedule it when it should fire _earlier_ than it was
96 * asked for before, or if it's not pending right now. This
97 * function ensures that. Note that it then is required to
98 * run this function for all timeouts after the first one
99 * has happened -- the work that runs from this timer will
100 * do that.
101 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200102static void run_again(struct ieee80211_sub_if_data *sdata,
103 unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200104{
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200105 sdata_assert_lock(sdata);
Johannes Bergca386f32009-07-10 02:39:48 +0200106
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200107 if (!timer_pending(&sdata->u.mgd.timer) ||
108 time_before(timeout, sdata->u.mgd.timer.expires))
109 mod_timer(&sdata->u.mgd.timer, timeout);
Johannes Bergca386f32009-07-10 02:39:48 +0200110}
111
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400112void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200113{
Johannes Bergc1288b12012-01-19 09:29:57 +0100114 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200115 return;
116
Johannes Berg30686bf2015-06-02 21:39:54 +0200117 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Johannes Berg7eeff742012-07-18 10:27:27 +0200118 return;
119
Johannes Bergb291ba12009-07-10 15:29:03 +0200120 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100121 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200122}
123
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400124void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
125{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400126 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
127
Johannes Bergb100e5d2016-03-17 15:41:37 +0200128 if (unlikely(!ifmgd->associated))
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100129 return;
130
Johannes Bergb100e5d2016-03-17 15:41:37 +0200131 if (ifmgd->probe_send_count)
132 ifmgd->probe_send_count = 0;
Eliad Peller448cd2e2014-02-11 12:30:18 +0200133
Johannes Berg30686bf2015-06-02 21:39:54 +0200134 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400135 return;
136
Johannes Bergb100e5d2016-03-17 15:41:37 +0200137 mod_timer(&ifmgd->conn_mon_timer,
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400138 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
139}
140
Johannes Berg5484e232008-09-08 17:44:27 +0200141static int ecw2cw(int ecw)
Johannes Berg60f8b39c2008-09-08 17:44:22 +0200142{
Johannes Berg5484e232008-09-08 17:44:27 +0200143 return (1 << ecw) - 1;
Johannes Berg60f8b39c2008-09-08 17:44:22 +0200144}
145
Johannes Berg6565ec92013-02-08 14:52:32 +0100146static u32
147ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
148 struct ieee80211_supported_band *sband,
149 struct ieee80211_channel *channel,
150 const struct ieee80211_ht_operation *ht_oper,
151 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300152 const struct ieee80211_he_operation *he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +0200153 struct cfg80211_chan_def *chandef, bool tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100154{
Johannes Berg5cdaed12013-07-31 11:23:06 +0200155 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg6565ec92013-02-08 14:52:32 +0100156 struct cfg80211_chan_def vht_chandef;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200157 struct ieee80211_sta_ht_cap sta_ht_cap;
Johannes Berg6565ec92013-02-08 14:52:32 +0100158 u32 ht_cfreq, ret;
159
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200160 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
161 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
162
Johannes Berg6565ec92013-02-08 14:52:32 +0100163 chandef->chan = channel;
164 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
165 chandef->center_freq1 = channel->center_freq;
166 chandef->center_freq2 = 0;
167
Johannes Bergb1b1ae22017-10-13 15:26:01 +0300168 if (!ht_oper || !sta_ht_cap.ht_supported) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100169 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
170 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 Berg6565ec92013-02-08 14:52:32 +0100190 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
191 goto out;
192 }
193
194 /* check 40 MHz support, if we have it */
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200195 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100196 ieee80211_chandef_ht_oper(ht_oper, chandef);
Johannes Berg6565ec92013-02-08 14:52:32 +0100197 } else {
198 /* 40 MHz (and 80 MHz) must be supported for VHT */
199 ret = IEEE80211_STA_DISABLE_VHT;
Johannes Berg85220d72013-03-25 18:29:27 +0100200 /* also mark 40 MHz disabled */
201 ret |= IEEE80211_STA_DISABLE_40MHZ;
Johannes Berg6565ec92013-02-08 14:52:32 +0100202 goto out;
203 }
204
205 if (!vht_oper || !sband->vht_cap.vht_supported) {
206 ret = IEEE80211_STA_DISABLE_VHT;
207 goto out;
208 }
209
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100210 vht_chandef = *chandef;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300211 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
212 (le32_to_cpu(he_oper->he_oper_params) &
213 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
214 struct ieee80211_vht_operation he_oper_vht_cap;
215
216 /*
217 * Set only first 3 bytes (other 2 aren't used in
218 * ieee80211_chandef_vht_oper() anyway)
219 */
220 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
221 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
222
Johannes Berg7eb26df2018-08-31 11:31:18 +0300223 if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
224 &he_oper_vht_cap, ht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300225 &vht_chandef)) {
226 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
227 sdata_info(sdata,
228 "HE AP VHT information is invalid, disable HE\n");
229 ret = IEEE80211_STA_DISABLE_HE;
230 goto out;
231 }
Johannes Berg7eb26df2018-08-31 11:31:18 +0300232 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_oper,
233 ht_oper, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200234 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100235 sdata_info(sdata,
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100236 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100237 ret = IEEE80211_STA_DISABLE_VHT;
238 goto out;
239 }
240
241 if (!cfg80211_chandef_valid(&vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200242 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100243 sdata_info(sdata,
244 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100245 ret = IEEE80211_STA_DISABLE_VHT;
246 goto out;
247 }
248
249 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
250 ret = 0;
251 goto out;
252 }
253
254 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200255 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100256 sdata_info(sdata,
257 "AP VHT information doesn't match HT, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100258 ret = IEEE80211_STA_DISABLE_VHT;
259 goto out;
260 }
261
262 *chandef = vht_chandef;
263
264 ret = 0;
265
266out:
Johannes Berg963a18522014-02-21 20:34:34 +0100267 /*
268 * When tracking the current AP, don't do any further checks if the
269 * new chandef is identical to the one we're currently using for the
270 * connection. This keeps us from playing ping-pong with regulatory,
271 * without it the following can happen (for example):
272 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
273 * - AP advertises regdom US
274 * - CRDA loads regdom US with 80 MHz prohibited (old database)
275 * - the code below detects an unsupported channel, downgrades, and
276 * we disconnect from the AP in the caller
277 * - disconnect causes CRDA to reload world regdomain and the game
278 * starts anew.
279 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
280 *
281 * It seems possible that there are still scenarios with CSA or real
282 * bandwidth changes where a this could happen, but those cases are
283 * less common and wouldn't completely prevent using the AP.
284 */
285 if (tracking &&
286 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
287 return ret;
288
Johannes Berg586e01e2013-02-14 12:13:53 +0100289 /* don't print the message below for VHT mismatch if VHT is disabled */
290 if (ret & IEEE80211_STA_DISABLE_VHT)
291 vht_chandef = *chandef;
292
Johannes Bergddfe49b2013-07-31 20:52:03 +0200293 /*
294 * Ignore the DISABLED flag when we're already connected and only
295 * tracking the APs beacon for bandwidth changes - otherwise we
296 * might get disconnected here if we connect to an AP, update our
297 * regulatory information based on the AP's country IE and the
298 * information we have is wrong/outdated and disables the channel
299 * that we're actually using for the connection to the AP.
300 */
Johannes Berg6565ec92013-02-08 14:52:32 +0100301 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
Johannes Bergddfe49b2013-07-31 20:52:03 +0200302 tracking ? 0 :
303 IEEE80211_CHAN_DISABLED)) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100304 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
305 ret = IEEE80211_STA_DISABLE_HT |
306 IEEE80211_STA_DISABLE_VHT;
Chris Wrightb56e4b82013-07-31 12:12:24 -0700307 break;
Johannes Berg6565ec92013-02-08 14:52:32 +0100308 }
309
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200310 ret |= ieee80211_chandef_downgrade(chandef);
Johannes Berg6565ec92013-02-08 14:52:32 +0100311 }
312
Johannes Berg5cdaed12013-07-31 11:23:06 +0200313 if (chandef->width != vht_chandef.width && !tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100314 sdata_info(sdata,
315 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
316
317 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
318 return ret;
319}
320
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100321static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
322 struct sta_info *sta,
Eliad Peller53b954e2014-07-24 11:20:05 +0300323 const struct ieee80211_ht_cap *ht_cap,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100324 const struct ieee80211_ht_operation *ht_oper,
325 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300326 const struct ieee80211_he_operation *he_oper,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100327 const u8 *bssid, u32 *changed)
Johannes Bergd5522e02009-03-30 13:23:35 +0200328{
329 struct ieee80211_local *local = sdata->local;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100330 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300331 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
332 struct ieee80211_supported_band *sband =
333 local->hw.wiphy->bands[chan->band];
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100334 struct cfg80211_chan_def chandef;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200335 u16 ht_opmode;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100336 u32 flags;
337 enum ieee80211_sta_rx_bandwidth new_sta_bw;
338 int ret;
339
340 /* if HT was/is disabled, don't track any bandwidth changes */
341 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
342 return 0;
343
344 /* don't check VHT if we associated as non-VHT station */
345 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
346 vht_oper = NULL;
Johannes Bergd5522e02009-03-30 13:23:35 +0200347
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300348 /* don't check HE if we associated as non-HE station */
349 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
350 !ieee80211_get_he_sta_cap(sband))
351 he_oper = NULL;
352
Johannes Berg11289582013-02-07 17:36:12 +0100353 if (WARN_ON_ONCE(!sta))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100354 return -EINVAL;
Johannes Berg11289582013-02-07 17:36:12 +0100355
Avri Altman017b45b2013-11-18 19:06:48 +0200356 /*
357 * if bss configuration changed store the new one -
358 * this may be applicable even if channel is identical
359 */
360 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
361 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
362 *changed |= BSS_CHANGED_HT;
363 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
364 }
365
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300366 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
Eliad Peller53b954e2014-07-24 11:20:05 +0300367 flags = ieee80211_determine_chantype(sdata, sband, chan,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300368 ht_oper, vht_oper, he_oper,
Eliad Peller53b954e2014-07-24 11:20:05 +0300369 &chandef, true);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100370
371 /*
372 * Downgrade the new channel if we associated with restricted
373 * capabilities. For example, if we associated as a 20 MHz STA
374 * to a 40 MHz AP (due to regulatory, capabilities or config
375 * reasons) then switching to a 40 MHz channel now won't do us
376 * any good -- we couldn't use it with the AP.
377 */
378 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
379 chandef.width == NL80211_CHAN_WIDTH_80P80)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200380 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100381 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
382 chandef.width == NL80211_CHAN_WIDTH_160)
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_40MHZ &&
385 chandef.width > NL80211_CHAN_WIDTH_20)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200386 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100387
388 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
389 return 0;
390
391 sdata_info(sdata,
392 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
393 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
394 chandef.center_freq1, chandef.center_freq2);
395
396 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
397 IEEE80211_STA_DISABLE_VHT |
398 IEEE80211_STA_DISABLE_40MHZ |
399 IEEE80211_STA_DISABLE_80P80MHZ |
400 IEEE80211_STA_DISABLE_160MHZ)) ||
401 !cfg80211_chandef_valid(&chandef)) {
402 sdata_info(sdata,
403 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
404 ifmgd->bssid);
405 return -EINVAL;
Johannes Berg64f68e52012-03-28 10:58:37 +0200406 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200407
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100408 switch (chandef.width) {
409 case NL80211_CHAN_WIDTH_20_NOHT:
410 case NL80211_CHAN_WIDTH_20:
411 new_sta_bw = IEEE80211_STA_RX_BW_20;
412 break;
413 case NL80211_CHAN_WIDTH_40:
414 new_sta_bw = IEEE80211_STA_RX_BW_40;
415 break;
416 case NL80211_CHAN_WIDTH_80:
417 new_sta_bw = IEEE80211_STA_RX_BW_80;
418 break;
419 case NL80211_CHAN_WIDTH_80P80:
420 case NL80211_CHAN_WIDTH_160:
421 new_sta_bw = IEEE80211_STA_RX_BW_160;
422 break;
423 default:
424 return -EINVAL;
425 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200426
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100427 if (new_sta_bw > sta->cur_max_bandwidth)
428 new_sta_bw = sta->cur_max_bandwidth;
Johannes Berg64f68e52012-03-28 10:58:37 +0200429
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100430 if (new_sta_bw < sta->sta.bandwidth) {
431 sta->sta.bandwidth = new_sta_bw;
432 rate_control_rate_update(local, sband, sta,
433 IEEE80211_RC_BW_CHANGED);
434 }
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530435
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100436 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
437 if (ret) {
438 sdata_info(sdata,
439 "AP %pM changed bandwidth to incompatible one - disconnect\n",
440 ifmgd->bssid);
441 return ret;
442 }
443
444 if (new_sta_bw > sta->sta.bandwidth) {
445 sta->sta.bandwidth = new_sta_bw;
446 rate_control_rate_update(local, sband, sta,
447 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200448 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200449
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100450 return 0;
Johannes Bergd5522e02009-03-30 13:23:35 +0200451}
452
Johannes Berg9c6bd792008-09-11 00:01:52 +0200453/* frame sending functions */
454
Johannes Berg66e67e42012-01-20 13:55:27 +0100455static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200456 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100457 struct ieee80211_supported_band *sband,
458 struct ieee80211_channel *channel,
459 enum ieee80211_smps_mode smps)
460{
Johannes Berg66e67e42012-01-20 13:55:27 +0100461 u8 *pos;
462 u32 flags = channel->flags;
463 u16 cap;
464 struct ieee80211_sta_ht_cap ht_cap;
465
466 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
467
Johannes Berg66e67e42012-01-20 13:55:27 +0100468 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
469 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
470
Johannes Berg66e67e42012-01-20 13:55:27 +0100471 /* determine capability flags */
472 cap = ht_cap.cap;
473
Johannes Berg9dde6422012-05-16 23:43:19 +0200474 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100475 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
476 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
477 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
478 cap &= ~IEEE80211_HT_CAP_SGI_40;
479 }
480 break;
481 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
482 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
483 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
484 cap &= ~IEEE80211_HT_CAP_SGI_40;
485 }
486 break;
487 }
488
Johannes Berg24398e32012-03-28 10:58:36 +0200489 /*
490 * If 40 MHz was disabled associate as though we weren't
491 * capable of 40 MHz -- some broken APs will never fall
492 * back to trying to transmit in 20 MHz.
493 */
494 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
495 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
496 cap &= ~IEEE80211_HT_CAP_SGI_40;
497 }
498
Johannes Berg66e67e42012-01-20 13:55:27 +0100499 /* set SM PS mode properly */
500 cap &= ~IEEE80211_HT_CAP_SM_PS;
501 switch (smps) {
502 case IEEE80211_SMPS_AUTOMATIC:
503 case IEEE80211_SMPS_NUM_MODES:
504 WARN_ON(1);
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500505 /* fall through */
Johannes Berg66e67e42012-01-20 13:55:27 +0100506 case IEEE80211_SMPS_OFF:
507 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
508 IEEE80211_HT_CAP_SM_PS_SHIFT;
509 break;
510 case IEEE80211_SMPS_STATIC:
511 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
512 IEEE80211_HT_CAP_SM_PS_SHIFT;
513 break;
514 case IEEE80211_SMPS_DYNAMIC:
515 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
516 IEEE80211_HT_CAP_SM_PS_SHIFT;
517 break;
518 }
519
520 /* reserve and fill IE */
521 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
522 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
523}
524
Sara Sharon322cd402015-07-08 15:41:43 +0300525/* This function determines vht capability flags for the association
526 * and builds the IE.
527 * Note - the function may set the owner of the MU-MIMO capability
528 */
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000529static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
530 struct sk_buff *skb,
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100531 struct ieee80211_supported_band *sband,
532 struct ieee80211_vht_cap *ap_vht_cap)
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000533{
Sara Sharon322cd402015-07-08 15:41:43 +0300534 struct ieee80211_local *local = sdata->local;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000535 u8 *pos;
536 u32 cap;
537 struct ieee80211_sta_vht_cap vht_cap;
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200538 u32 mask, ap_bf_sts, our_bf_sts;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000539
540 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
541
542 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +0100543 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000544
545 /* determine capability flags */
546 cap = vht_cap.cap;
547
Johannes Bergf2d9d272012-11-22 14:11:39 +0100548 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
Johannes Berg575f0532014-11-24 16:51:33 +0100549 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
550
551 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
552 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
553 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
554 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100555 }
556
557 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
558 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
Johannes Berg575f0532014-11-24 16:51:33 +0100559 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100560 }
561
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100562 /*
563 * Some APs apparently get confused if our capabilities are better
564 * than theirs, so restrict what we advertise in the assoc request.
565 */
566 if (!(ap_vht_cap->vht_cap_info &
567 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
Sara Sharon322cd402015-07-08 15:41:43 +0300568 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
569 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
570 else if (!(ap_vht_cap->vht_cap_info &
571 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
572 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
573
574 /*
575 * If some other vif is using the MU-MIMO capablity we cannot associate
576 * using MU-MIMO - this will lead to contradictions in the group-id
577 * mechanism.
578 * Ownership is defined since association request, in order to avoid
579 * simultaneous associations with MU-MIMO.
580 */
581 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
582 bool disable_mu_mimo = false;
583 struct ieee80211_sub_if_data *other;
584
585 list_for_each_entry_rcu(other, &local->interfaces, list) {
Sara Sharonb5a33d52016-02-16 12:48:18 +0200586 if (other->vif.mu_mimo_owner) {
Sara Sharon322cd402015-07-08 15:41:43 +0300587 disable_mu_mimo = true;
588 break;
589 }
590 }
591 if (disable_mu_mimo)
592 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
593 else
Sara Sharonb5a33d52016-02-16 12:48:18 +0200594 sdata->vif.mu_mimo_owner = true;
Sara Sharon322cd402015-07-08 15:41:43 +0300595 }
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100596
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200597 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
598
599 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
600 our_bf_sts = cap & mask;
601
602 if (ap_bf_sts < our_bf_sts) {
603 cap &= ~mask;
604 cap |= ap_bf_sts;
605 }
606
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000607 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000608 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000609 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
610}
611
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300612/* This function determines HE capability flags for the association
613 * and builds the IE.
614 */
615static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
616 struct sk_buff *skb,
617 struct ieee80211_supported_band *sband)
618{
619 u8 *pos;
620 const struct ieee80211_sta_he_cap *he_cap = NULL;
621 u8 he_cap_size;
622
623 he_cap = ieee80211_get_he_sta_cap(sband);
624 if (!he_cap)
625 return;
626
627 /*
628 * TODO: the 1 added is because this temporarily is under the EXTENSION
629 * IE. Get rid of it when it moves.
630 */
631 he_cap_size =
632 2 + 1 + sizeof(he_cap->he_cap_elem) +
633 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
634 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
635 he_cap->he_cap_elem.phy_cap_info);
636 pos = skb_put(skb, he_cap_size);
637 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
638}
639
Johannes Berg66e67e42012-01-20 13:55:27 +0100640static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
641{
642 struct ieee80211_local *local = sdata->local;
643 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
644 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
645 struct sk_buff *skb;
646 struct ieee80211_mgmt *mgmt;
647 u8 *pos, qos_info;
648 size_t offset = 0, noffset;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200649 int i, count, rates_len, supp_rates_len, shift;
Johannes Berg66e67e42012-01-20 13:55:27 +0100650 u16 capab;
651 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200652 struct ieee80211_chanctx_conf *chanctx_conf;
653 struct ieee80211_channel *chan;
Johannes Berg44f6d422017-06-10 13:52:44 +0300654 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100655
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200656 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +0100657
Johannes Berg55de9082012-07-26 17:24:39 +0200658 rcu_read_lock();
659 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
660 if (WARN_ON(!chanctx_conf)) {
661 rcu_read_unlock();
662 return;
663 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100664 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200665 rcu_read_unlock();
666 sband = local->hw.wiphy->bands[chan->band];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200667 shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg66e67e42012-01-20 13:55:27 +0100668
669 if (assoc_data->supp_rates_len) {
670 /*
671 * Get all rates supported by the device and the AP as
672 * some APs don't like getting a superset of their rates
673 * in the association request (e.g. D-Link DAP 1353 in
674 * b-only mode)...
675 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200676 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
677 assoc_data->supp_rates,
678 assoc_data->supp_rates_len,
679 &rates);
Johannes Berg66e67e42012-01-20 13:55:27 +0100680 } else {
681 /*
682 * In case AP not provide any supported rates information
683 * before association, we send information element(s) with
684 * all rates that we support.
685 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200686 rates_len = 0;
687 for (i = 0; i < sband->n_bitrates; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200688 rates |= BIT(i);
689 rates_len++;
690 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100691 }
692
693 skb = alloc_skb(local->hw.extra_tx_headroom +
694 sizeof(*mgmt) + /* bit too much but doesn't matter */
695 2 + assoc_data->ssid_len + /* SSID */
696 4 + rates_len + /* (extended) rates */
697 4 + /* power capability */
698 2 + 2 * sband->n_channels + /* supported channels */
699 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000700 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300701 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
702 sizeof(struct ieee80211_he_mcs_nss_supp) +
703 IEEE80211_HE_PPE_THRES_MAX_LEN +
Johannes Berg66e67e42012-01-20 13:55:27 +0100704 assoc_data->ie_len + /* extra IEs */
Jouni Malinen39404fe2016-10-27 00:42:05 +0300705 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
Johannes Berg66e67e42012-01-20 13:55:27 +0100706 9, /* WMM */
707 GFP_KERNEL);
708 if (!skb)
709 return;
710
711 skb_reserve(skb, local->hw.extra_tx_headroom);
712
713 capab = WLAN_CAPABILITY_ESS;
714
Johannes Berg57fbcce2016-04-12 15:56:15 +0200715 if (sband->band == NL80211_BAND_2GHZ) {
Johannes Bergea1b2b452015-06-02 20:15:49 +0200716 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
717 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
Johannes Berg66e67e42012-01-20 13:55:27 +0100718 }
719
720 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
721 capab |= WLAN_CAPABILITY_PRIVACY;
722
723 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg30686bf2015-06-02 21:39:54 +0200724 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
Johannes Berg66e67e42012-01-20 13:55:27 +0100725 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
726
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300727 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
728 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
729
Johannes Bergb080db52017-06-16 14:29:19 +0200730 mgmt = skb_put_zero(skb, 24);
Johannes Berg66e67e42012-01-20 13:55:27 +0100731 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
732 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
733 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
734
735 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
736 skb_put(skb, 10);
737 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
738 IEEE80211_STYPE_REASSOC_REQ);
739 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
740 mgmt->u.reassoc_req.listen_interval =
741 cpu_to_le16(local->hw.conf.listen_interval);
742 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
743 ETH_ALEN);
744 } else {
745 skb_put(skb, 4);
746 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
747 IEEE80211_STYPE_ASSOC_REQ);
748 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
749 mgmt->u.assoc_req.listen_interval =
750 cpu_to_le16(local->hw.conf.listen_interval);
751 }
752
753 /* SSID */
754 pos = skb_put(skb, 2 + assoc_data->ssid_len);
755 *pos++ = WLAN_EID_SSID;
756 *pos++ = assoc_data->ssid_len;
757 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
758
759 /* add all rates which were marked to be used above */
760 supp_rates_len = rates_len;
761 if (supp_rates_len > 8)
762 supp_rates_len = 8;
763
764 pos = skb_put(skb, supp_rates_len + 2);
765 *pos++ = WLAN_EID_SUPP_RATES;
766 *pos++ = supp_rates_len;
767
768 count = 0;
769 for (i = 0; i < sband->n_bitrates; i++) {
770 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200771 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
772 5 * (1 << shift));
773 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100774 if (++count == 8)
775 break;
776 }
777 }
778
779 if (rates_len > count) {
780 pos = skb_put(skb, rates_len - count + 2);
781 *pos++ = WLAN_EID_EXT_SUPP_RATES;
782 *pos++ = rates_len - count;
783
784 for (i++; i < sband->n_bitrates; i++) {
785 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200786 int rate;
787 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
788 5 * (1 << shift));
789 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100790 }
791 }
792 }
793
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300794 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
795 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100796 pos = skb_put(skb, 4);
797 *pos++ = WLAN_EID_PWR_CAPABILITY;
798 *pos++ = 2;
799 *pos++ = 0; /* min tx power */
Simon Wunderlich0430c882013-07-08 16:55:55 +0200800 /* max tx power */
801 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300802 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100803
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300804 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100805 /* TODO: get this in reg domain format */
806 pos = skb_put(skb, 2 * sband->n_channels + 2);
807 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
808 *pos++ = 2 * sband->n_channels;
809 for (i = 0; i < sband->n_channels; i++) {
810 *pos++ = ieee80211_frequency_to_channel(
811 sband->channels[i].center_freq);
812 *pos++ = 1; /* one channel in the subband*/
813 }
814 }
815
816 /* if present, add any custom IEs that go before HT */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200817 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100818 static const u8 before_ht[] = {
819 WLAN_EID_SSID,
820 WLAN_EID_SUPP_RATES,
821 WLAN_EID_EXT_SUPP_RATES,
822 WLAN_EID_PWR_CAPABILITY,
823 WLAN_EID_SUPPORTED_CHANNELS,
824 WLAN_EID_RSN,
825 WLAN_EID_QOS_CAPA,
826 WLAN_EID_RRM_ENABLED_CAPABILITIES,
827 WLAN_EID_MOBILITY_DOMAIN,
Johannes Berg8ed28742014-10-27 12:03:19 +0100828 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
829 WLAN_EID_RIC_DATA, /* reassoc only */
Johannes Berg66e67e42012-01-20 13:55:27 +0100830 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
831 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100832 static const u8 after_ric[] = {
833 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
834 WLAN_EID_HT_CAPABILITY,
835 WLAN_EID_BSS_COEX_2040,
Johannes Berga7f26d82017-08-05 11:44:32 +0300836 /* luckily this is almost always there */
Johannes Berg8ed28742014-10-27 12:03:19 +0100837 WLAN_EID_EXT_CAPABILITY,
838 WLAN_EID_QOS_TRAFFIC_CAPA,
839 WLAN_EID_TIM_BCAST_REQ,
840 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300841 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg8ed28742014-10-27 12:03:19 +0100842 WLAN_EID_VHT_CAPABILITY,
843 WLAN_EID_OPMODE_NOTIF,
844 };
845
846 noffset = ieee80211_ie_split_ric(assoc_data->ie,
847 assoc_data->ie_len,
848 before_ht,
849 ARRAY_SIZE(before_ht),
850 after_ric,
851 ARRAY_SIZE(after_ric),
852 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800853 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100854 offset = noffset;
855 }
856
Johannes Bergf2d9d272012-11-22 14:11:39 +0100857 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
858 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
859 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
860
Johannes Berga8243b72012-11-22 14:32:09 +0100861 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200862 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200863 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100864
Johannes Berg3de38022014-02-04 09:54:07 +0100865 /* if present, add any custom IEs that go before VHT */
866 if (assoc_data->ie_len) {
867 static const u8 before_vht[] = {
Johannes Berga7f26d82017-08-05 11:44:32 +0300868 /*
869 * no need to list the ones split off before HT
870 * or generated here
871 */
Johannes Berg3de38022014-02-04 09:54:07 +0100872 WLAN_EID_BSS_COEX_2040,
873 WLAN_EID_EXT_CAPABILITY,
874 WLAN_EID_QOS_TRAFFIC_CAPA,
875 WLAN_EID_TIM_BCAST_REQ,
876 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300877 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg3de38022014-02-04 09:54:07 +0100878 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100879
880 /* RIC already taken above, so no need to handle here anymore */
Johannes Berg3de38022014-02-04 09:54:07 +0100881 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
882 before_vht, ARRAY_SIZE(before_vht),
883 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800884 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg3de38022014-02-04 09:54:07 +0100885 offset = noffset;
886 }
887
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300888 /* if present, add any custom IEs that go before HE */
889 if (assoc_data->ie_len) {
890 static const u8 before_he[] = {
891 /*
892 * no need to list the ones split off before VHT
893 * or generated here
894 */
895 WLAN_EID_OPMODE_NOTIF,
896 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
897 /* 11ai elements */
898 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
899 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
900 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
901 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
902 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
903 /* TODO: add 11ah/11aj/11ak elements */
904 };
905
906 /* RIC already taken above, so no need to handle here anymore */
907 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
908 before_he, ARRAY_SIZE(before_he),
909 offset);
910 pos = skb_put(skb, noffset - offset);
911 memcpy(pos, assoc_data->ie + offset, noffset - offset);
912 offset = noffset;
913 }
914
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000915 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100916 ieee80211_add_vht_ie(sdata, skb, sband,
917 &assoc_data->ap_vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000918
Shaul Triebitzdc7eb0f2018-12-15 11:03:20 +0200919 /*
920 * If AP doesn't support HT, mark HE as disabled.
921 * If on the 5GHz band, make sure it supports VHT.
922 */
923 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
924 (sband->band == NL80211_BAND_5GHZ &&
925 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
926 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
927
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300928 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
929 ieee80211_add_he_ie(sdata, skb, sband);
930
931 /* if present, add any custom non-vendor IEs that go after HE */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200932 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100933 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
934 assoc_data->ie_len,
935 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800936 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100937 offset = noffset;
938 }
939
Johannes Berg76f03032012-03-08 15:02:05 +0100940 if (assoc_data->wmm) {
941 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200942 qos_info = ifmgd->uapsd_queues;
943 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100944 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
945 } else {
946 qos_info = 0;
947 }
948
Arik Nemtsov40b861a2014-07-17 17:14:23 +0300949 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
Johannes Berg66e67e42012-01-20 13:55:27 +0100950 }
951
952 /* add any remaining custom (i.e. vendor specific here) IEs */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200953 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100954 noffset = assoc_data->ie_len;
yuan linyub952f4d2017-06-18 22:52:04 +0800955 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100956 }
957
Jouni Malinen39404fe2016-10-27 00:42:05 +0300958 if (assoc_data->fils_kek_len &&
959 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
960 dev_kfree_skb(skb);
961 return;
962 }
963
Ilan Peerd4e36e52018-04-20 13:49:25 +0300964 drv_mgd_prepare_tx(local, sdata, 0);
Johannes Berga1845fc2012-06-27 13:18:36 +0200965
Johannes Berg66e67e42012-01-20 13:55:27 +0100966 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Johannes Berg30686bf2015-06-02 21:39:54 +0200967 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +0100968 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
969 IEEE80211_TX_INTFL_MLME_CONN_TX;
Johannes Berg66e67e42012-01-20 13:55:27 +0100970 ieee80211_tx_skb(sdata, skb);
971}
972
Kalle Valo572e0012009-02-10 17:09:31 +0200973void ieee80211_send_pspoll(struct ieee80211_local *local,
974 struct ieee80211_sub_if_data *sdata)
975{
Kalle Valo572e0012009-02-10 17:09:31 +0200976 struct ieee80211_pspoll *pspoll;
977 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200978
Kalle Valod8cd1892010-01-05 20:16:26 +0200979 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
980 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200981 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200982
Kalle Valod8cd1892010-01-05 20:16:26 +0200983 pspoll = (struct ieee80211_pspoll *) skb->data;
984 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200985
Johannes Berg62ae67b2009-11-18 18:42:05 +0100986 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
987 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200988}
989
Johannes Berg965beda2009-04-16 13:17:24 +0200990void ieee80211_send_nullfunc(struct ieee80211_local *local,
991 struct ieee80211_sub_if_data *sdata,
Johannes Berg076cdcb2015-09-24 16:14:55 +0200992 bool powersave)
Johannes Berg965beda2009-04-16 13:17:24 +0200993{
994 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200995 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530996 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200997
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300998 /* Don't send NDPs when STA is connected HE */
999 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1000 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
1001 return;
1002
Ben Caradoc-Davies7c181f42018-03-19 12:57:44 +13001003 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1004 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
Kalle Valod8cd1892010-01-05 20:16:26 +02001005 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +02001006 return;
1007
Kalle Valod8cd1892010-01-05 20:16:26 +02001008 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +02001009 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +02001010 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +02001011
Seth Forshee6c17b772013-02-11 11:21:07 -06001012 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1013 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Pontus Fuchsff40b422013-06-04 12:44:52 +02001014
Johannes Berg30686bf2015-06-02 21:39:54 +02001015 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Pontus Fuchsff40b422013-06-04 12:44:52 +02001016 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1017
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001018 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +05301019 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1020
Johannes Berg62ae67b2009-11-18 18:42:05 +01001021 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +02001022}
1023
Felix Fietkaud5242152010-01-08 18:06:26 +01001024static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1025 struct ieee80211_sub_if_data *sdata)
1026{
1027 struct sk_buff *skb;
1028 struct ieee80211_hdr *nullfunc;
1029 __le16 fc;
1030
1031 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1032 return;
1033
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001034 /* Don't send NDPs when connected HE */
1035 if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE))
1036 return;
1037
Felix Fietkaud5242152010-01-08 18:06:26 +01001038 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -07001039 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +01001040 return;
Joe Perchesd15b8452011-08-29 14:17:31 -07001041
Felix Fietkaud5242152010-01-08 18:06:26 +01001042 skb_reserve(skb, local->hw.extra_tx_headroom);
1043
Johannes Bergb080db52017-06-16 14:29:19 +02001044 nullfunc = skb_put_zero(skb, 30);
Felix Fietkaud5242152010-01-08 18:06:26 +01001045 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1046 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1047 nullfunc->frame_control = fc;
1048 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1049 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1050 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1051 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1052
1053 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1054 ieee80211_tx_skb(sdata, skb);
1055}
1056
Johannes Bergcc32abd2009-05-15 11:52:31 +02001057/* spectrum management related things */
1058static void ieee80211_chswitch_work(struct work_struct *work)
1059{
1060 struct ieee80211_sub_if_data *sdata =
1061 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Karl Beldan675a0b02013-03-25 16:26:57 +01001062 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001063 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001064 int ret;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001065
Johannes Berg9607e6b662009-12-23 13:15:31 +01001066 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +02001067 return;
1068
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001069 sdata_lock(sdata);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001070 mutex_lock(&local->mtx);
1071 mutex_lock(&local->chanctx_mtx);
1072
Johannes Berg77fdaa12009-07-07 03:45:17 +02001073 if (!ifmgd->associated)
1074 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001075
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001076 if (!sdata->vif.csa_active)
1077 goto out;
1078
1079 /*
1080 * using reservation isn't immediate as it may be deferred until later
1081 * with multi-vif. once reservation is complete it will re-schedule the
1082 * work with no reserved_chanctx so verify chandef to check if it
1083 * completed successfully
1084 */
1085
1086 if (sdata->reserved_chanctx) {
Ilan Peer0007e942018-08-31 11:31:10 +03001087 struct ieee80211_supported_band *sband = NULL;
1088 struct sta_info *mgd_sta = NULL;
1089 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
1090
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001091 /*
1092 * with multi-vif csa driver may call ieee80211_csa_finish()
1093 * many times while waiting for other interfaces to use their
1094 * reservations
1095 */
1096 if (sdata->reserved_ready)
1097 goto out;
1098
Ilan Peer0007e942018-08-31 11:31:10 +03001099 if (sdata->vif.bss_conf.chandef.width !=
1100 sdata->csa_chandef.width) {
1101 /*
1102 * For managed interface, we need to also update the AP
1103 * station bandwidth and align the rate scale algorithm
1104 * on the bandwidth change. Here we only consider the
1105 * bandwidth of the new channel definition (as channel
1106 * switch flow does not have the full HT/VHT/HE
1107 * information), assuming that if additional changes are
1108 * required they would be done as part of the processing
1109 * of the next beacon from the AP.
1110 */
1111 switch (sdata->csa_chandef.width) {
1112 case NL80211_CHAN_WIDTH_20_NOHT:
1113 case NL80211_CHAN_WIDTH_20:
1114 default:
1115 bw = IEEE80211_STA_RX_BW_20;
1116 break;
1117 case NL80211_CHAN_WIDTH_40:
1118 bw = IEEE80211_STA_RX_BW_40;
1119 break;
1120 case NL80211_CHAN_WIDTH_80:
1121 bw = IEEE80211_STA_RX_BW_80;
1122 break;
1123 case NL80211_CHAN_WIDTH_80P80:
1124 case NL80211_CHAN_WIDTH_160:
1125 bw = IEEE80211_STA_RX_BW_160;
1126 break;
1127 }
1128
1129 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1130 sband =
1131 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1132 }
1133
1134 if (sdata->vif.bss_conf.chandef.width >
1135 sdata->csa_chandef.width) {
1136 mgd_sta->sta.bandwidth = bw;
1137 rate_control_rate_update(local, sband, mgd_sta,
1138 IEEE80211_RC_BW_CHANGED);
1139 }
1140
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001141 ret = ieee80211_vif_use_reserved_context(sdata);
1142 if (ret) {
1143 sdata_info(sdata,
1144 "failed to use reserved channel context, disconnecting (err=%d)\n",
1145 ret);
1146 ieee80211_queue_work(&sdata->local->hw,
1147 &ifmgd->csa_connection_drop_work);
1148 goto out;
1149 }
1150
Ilan Peer0007e942018-08-31 11:31:10 +03001151 if (sdata->vif.bss_conf.chandef.width <
1152 sdata->csa_chandef.width) {
1153 mgd_sta->sta.bandwidth = bw;
1154 rate_control_rate_update(local, sband, mgd_sta,
1155 IEEE80211_RC_BW_CHANGED);
1156 }
1157
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001158 goto out;
1159 }
1160
1161 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1162 &sdata->csa_chandef)) {
Arik Nemtsov7578d572013-09-01 17:15:51 +03001163 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001164 "failed to finalize channel switch, disconnecting\n");
Arik Nemtsov7578d572013-09-01 17:15:51 +03001165 ieee80211_queue_work(&sdata->local->hw,
1166 &ifmgd->csa_connection_drop_work);
1167 goto out;
1168 }
Karl Beldan675a0b02013-03-25 16:26:57 +01001169
Johannes Berg77fdaa12009-07-07 03:45:17 +02001170 /* XXX: shouldn't really modify cfg80211-owned data! */
Luciano Coelho33787fc2013-11-11 20:34:54 +02001171 ifmgd->associated->channel = sdata->csa_chandef.chan;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001172
Luciano Coelho0c21e632014-10-08 09:48:39 +03001173 ifmgd->csa_waiting_bcn = true;
Luciano Coelhof1d65582014-10-08 09:48:38 +03001174
Michal Kaziore5593f52014-04-09 15:45:36 +02001175 ieee80211_sta_reset_beacon_monitor(sdata);
1176 ieee80211_sta_reset_conn_monitor(sdata);
1177
Michal Kazior59af6922014-04-09 15:10:59 +02001178out:
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001179 mutex_unlock(&local->chanctx_mtx);
1180 mutex_unlock(&local->mtx);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001181 sdata_unlock(sdata);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001182}
1183
Luciano Coelho0c21e632014-10-08 09:48:39 +03001184static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1185{
1186 struct ieee80211_local *local = sdata->local;
1187 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1188 int ret;
1189
1190 sdata_assert_lock(sdata);
1191
1192 WARN_ON(!sdata->vif.csa_active);
1193
1194 if (sdata->csa_block_tx) {
1195 ieee80211_wake_vif_queues(local, sdata,
1196 IEEE80211_QUEUE_STOP_REASON_CSA);
1197 sdata->csa_block_tx = false;
1198 }
1199
1200 sdata->vif.csa_active = false;
1201 ifmgd->csa_waiting_bcn = false;
1202
1203 ret = drv_post_channel_switch(sdata);
1204 if (ret) {
1205 sdata_info(sdata,
1206 "driver post channel switch failed, disconnecting\n");
1207 ieee80211_queue_work(&local->hw,
1208 &ifmgd->csa_connection_drop_work);
1209 return;
1210 }
Luciano Coelho688b1ec2014-12-16 16:01:39 +02001211
1212 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
Luciano Coelho0c21e632014-10-08 09:48:39 +03001213}
1214
Johannes Berg5ce6e432010-05-11 16:20:57 +02001215void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1216{
Johannes Berg55de9082012-07-26 17:24:39 +02001217 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1218 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001219
1220 trace_api_chswitch_done(sdata, success);
1221 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001222 sdata_info(sdata,
1223 "driver channel switch failed, disconnecting\n");
1224 ieee80211_queue_work(&sdata->local->hw,
1225 &ifmgd->csa_connection_drop_work);
1226 } else {
1227 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001228 }
Johannes Berg5ce6e432010-05-11 16:20:57 +02001229}
1230EXPORT_SYMBOL(ieee80211_chswitch_done);
1231
Kees Cook34f11cd2017-10-16 16:35:49 -07001232static void ieee80211_chswitch_timer(struct timer_list *t)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001233{
1234 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07001235 from_timer(sdata, t, u.mgd.chswitch_timer);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001236
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01001237 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001238}
1239
Johannes Berg37799e52013-03-26 14:02:26 +01001240static void
Johannes Berg4a3cb702013-02-12 16:43:19 +01001241ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03001242 u64 timestamp, u32 device_timestamp,
1243 struct ieee802_11_elems *elems,
Johannes Berg04a161f2013-05-03 09:35:35 +02001244 bool beacon)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001245{
Johannes Bergb4f286a12013-03-26 14:13:58 +01001246 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001247 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg37799e52013-03-26 14:02:26 +01001248 struct cfg80211_bss *cbss = ifmgd->associated;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001249 struct ieee80211_chanctx_conf *conf;
Johannes Berg55de9082012-07-26 17:24:39 +02001250 struct ieee80211_chanctx *chanctx;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001251 enum nl80211_band current_band;
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001252 struct ieee80211_csa_ie csa_ie;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001253 struct ieee80211_channel_switch ch_switch;
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001254 int res;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001255
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001256 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001257
Johannes Berg37799e52013-03-26 14:02:26 +01001258 if (!cbss)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001259 return;
1260
Johannes Bergb4f286a12013-03-26 14:13:58 +01001261 if (local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001262 return;
1263
Johannes Berg37799e52013-03-26 14:02:26 +01001264 /* disregard subsequent announcements if we are already processing */
Luciano Coelho3e2a0222014-07-05 11:43:01 +03001265 if (sdata->vif.csa_active)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001266 return;
1267
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001268 current_band = cbss->channel->band;
Luciano Coelho84469a42014-10-28 13:33:04 +02001269 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001270 ifmgd->flags,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001271 ifmgd->associated->bssid, &csa_ie);
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001272 if (res < 0)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001273 ieee80211_queue_work(&local->hw,
Johannes Berg882a7c62012-08-01 22:32:45 +02001274 &ifmgd->csa_connection_drop_work);
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001275 if (res)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001276 return;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001277
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001278 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
Johannes Berg85220d72013-03-25 18:29:27 +01001279 IEEE80211_CHAN_DISABLED)) {
1280 sdata_info(sdata,
1281 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001282 ifmgd->associated->bssid,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001283 csa_ie.chandef.chan->center_freq,
1284 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1285 csa_ie.chandef.center_freq2);
Johannes Berg85220d72013-03-25 18:29:27 +01001286 ieee80211_queue_work(&local->hw,
1287 &ifmgd->csa_connection_drop_work);
1288 return;
1289 }
1290
Johannes Bergf84eaa12015-03-12 08:53:26 +02001291 if (cfg80211_chandef_identical(&csa_ie.chandef,
1292 &sdata->vif.bss_conf.chandef)) {
1293 if (ifmgd->csa_ignored_same_chan)
1294 return;
1295 sdata_info(sdata,
1296 "AP %pM tries to chanswitch to same channel, ignore\n",
1297 ifmgd->associated->bssid);
1298 ifmgd->csa_ignored_same_chan = true;
1299 return;
1300 }
1301
Arik Nemtsovc5a71682015-05-19 14:36:48 +03001302 /*
1303 * Drop all TDLS peers - either we disconnect or move to a different
1304 * channel from this point on. There's no telling what our peer will do.
1305 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1306 * have an incompatible wider chandef.
1307 */
1308 ieee80211_teardown_tdls_peers(sdata);
1309
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001310 mutex_lock(&local->mtx);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001311 mutex_lock(&local->chanctx_mtx);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001312 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1313 lockdep_is_held(&local->chanctx_mtx));
1314 if (!conf) {
1315 sdata_info(sdata,
1316 "no channel context assigned to vif?, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001317 goto drop_connection;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001318 }
1319
1320 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1321
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001322 if (local->use_chanctx &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001323 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001324 sdata_info(sdata,
1325 "driver doesn't support chan-switch with channel contexts\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001326 goto drop_connection;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001327 }
1328
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001329 ch_switch.timestamp = timestamp;
1330 ch_switch.device_timestamp = device_timestamp;
1331 ch_switch.block_tx = csa_ie.mode;
1332 ch_switch.chandef = csa_ie.chandef;
1333 ch_switch.count = csa_ie.count;
1334
1335 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1336 sdata_info(sdata,
1337 "preparing for channel switch failed, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001338 goto drop_connection;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001339 }
1340
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001341 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1342 chanctx->mode, false);
1343 if (res) {
Johannes Berg55de9082012-07-26 17:24:39 +02001344 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001345 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1346 res);
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001347 goto drop_connection;
Johannes Berg55de9082012-07-26 17:24:39 +02001348 }
Johannes Bergb4f286a12013-03-26 14:13:58 +01001349 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001350
Michal Kazior59af6922014-04-09 15:10:59 +02001351 sdata->vif.csa_active = true;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001352 sdata->csa_chandef = csa_ie.chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02001353 sdata->csa_block_tx = csa_ie.mode;
Johannes Bergf84eaa12015-03-12 08:53:26 +02001354 ifmgd->csa_ignored_same_chan = false;
Michal Kazior59af6922014-04-09 15:10:59 +02001355
1356 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03001357 ieee80211_stop_vif_queues(local, sdata,
1358 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02001359 mutex_unlock(&local->mtx);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001360
Luciano Coelho2f457292014-11-07 14:31:36 +02001361 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1362 csa_ie.count);
1363
Johannes Bergb4f286a12013-03-26 14:13:58 +01001364 if (local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +02001365 /* use driver's channel switch callback */
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001366 drv_channel_switch(local, sdata, &ch_switch);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001367 return;
1368 }
1369
1370 /* channel switch handled in software */
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001371 if (csa_ie.count <= 1)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001372 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001373 else
Johannes Bergcc32abd2009-05-15 11:52:31 +02001374 mod_timer(&ifmgd->chswitch_timer,
Luciano Coelhoff1e4172014-10-28 13:33:05 +02001375 TU_TO_EXP_TIME((csa_ie.count - 1) *
1376 cbss->beacon_interval));
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001377 return;
1378 drop_connection:
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03001379 /*
1380 * This is just so that the disconnect flow will know that
1381 * we were trying to switch channel and failed. In case the
1382 * mode is 1 (we are not allowed to Tx), we will know not to
1383 * send a deauthentication frame. Those two fields will be
1384 * reset when the disconnection worker runs.
1385 */
1386 sdata->vif.csa_active = true;
1387 sdata->csa_block_tx = csa_ie.mode;
1388
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001389 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1390 mutex_unlock(&local->chanctx_mtx);
1391 mutex_unlock(&local->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001392}
1393
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001394static bool
1395ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1396 struct ieee80211_channel *channel,
1397 const u8 *country_ie, u8 country_ie_len,
1398 const u8 *pwr_constr_elem,
1399 int *chan_pwr, int *pwr_reduction)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001400{
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001401 struct ieee80211_country_ie_triplet *triplet;
1402 int chan = ieee80211_frequency_to_channel(channel->center_freq);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001403 int i, chan_increment;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001404 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001405
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001406 /* Invalid IE */
1407 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001408 return false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001409
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001410 triplet = (void *)(country_ie + 3);
1411 country_ie_len -= 3;
1412
1413 switch (channel->band) {
1414 default:
1415 WARN_ON_ONCE(1);
1416 /* fall through */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001417 case NL80211_BAND_2GHZ:
1418 case NL80211_BAND_60GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001419 chan_increment = 1;
1420 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001421 case NL80211_BAND_5GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001422 chan_increment = 4;
1423 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001424 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001425
1426 /* find channel */
1427 while (country_ie_len >= 3) {
1428 u8 first_channel = triplet->chans.first_channel;
1429
1430 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1431 goto next;
1432
1433 for (i = 0; i < triplet->chans.num_channels; i++) {
1434 if (first_channel + i * chan_increment == chan) {
1435 have_chan_pwr = true;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001436 *chan_pwr = triplet->chans.max_power;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001437 break;
1438 }
1439 }
1440 if (have_chan_pwr)
1441 break;
1442
1443 next:
1444 triplet++;
1445 country_ie_len -= 3;
1446 }
1447
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001448 if (have_chan_pwr && pwr_constr_elem)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001449 *pwr_reduction = *pwr_constr_elem;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001450 else
1451 *pwr_reduction = 0;
1452
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001453 return have_chan_pwr;
1454}
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001455
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001456static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1457 struct ieee80211_channel *channel,
1458 const u8 *cisco_dtpc_ie,
1459 int *pwr_level)
1460{
1461 /* From practical testing, the first data byte of the DTPC element
1462 * seems to contain the requested dBm level, and the CLI on Cisco
1463 * APs clearly state the range is -127 to 127 dBm, which indicates
1464 * a signed byte, although it seemingly never actually goes negative.
1465 * The other byte seems to always be zero.
1466 */
1467 *pwr_level = (__s8)cisco_dtpc_ie[4];
1468}
1469
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001470static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1471 struct ieee80211_channel *channel,
1472 struct ieee80211_mgmt *mgmt,
1473 const u8 *country_ie, u8 country_ie_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001474 const u8 *pwr_constr_ie,
1475 const u8 *cisco_dtpc_ie)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001476{
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001477 bool has_80211h_pwr = false, has_cisco_pwr = false;
1478 int chan_pwr = 0, pwr_reduction_80211h = 0;
1479 int pwr_level_cisco, pwr_level_80211h;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001480 int new_ap_level;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001481 __le16 capab = mgmt->u.probe_resp.capab_info;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001482
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001483 if (country_ie &&
1484 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1485 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001486 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1487 sdata, channel, country_ie, country_ie_len,
1488 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001489 pwr_level_80211h =
1490 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001491 }
1492
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001493 if (cisco_dtpc_ie) {
1494 ieee80211_find_cisco_dtpc(
1495 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1496 has_cisco_pwr = true;
1497 }
1498
1499 if (!has_80211h_pwr && !has_cisco_pwr)
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001500 return 0;
1501
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001502 /* If we have both 802.11h and Cisco DTPC, apply both limits
1503 * by picking the smallest of the two power levels advertised.
1504 */
1505 if (has_80211h_pwr &&
1506 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
Johannes Berga87da0c2015-12-08 16:04:37 +02001507 new_ap_level = pwr_level_80211h;
1508
1509 if (sdata->ap_power_level == new_ap_level)
1510 return 0;
1511
John Linvillecef2fc12015-03-31 10:49:14 -04001512 sdata_dbg(sdata,
1513 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1514 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1515 sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001516 } else { /* has_cisco_pwr is always true here. */
Johannes Berga87da0c2015-12-08 16:04:37 +02001517 new_ap_level = pwr_level_cisco;
1518
1519 if (sdata->ap_power_level == new_ap_level)
1520 return 0;
1521
John Linvillecef2fc12015-03-31 10:49:14 -04001522 sdata_dbg(sdata,
1523 "Limiting TX power to %d dBm as advertised by %pM\n",
1524 pwr_level_cisco, sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001525 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001526
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001527 sdata->ap_power_level = new_ap_level;
1528 if (__ieee80211_recalc_txpower(sdata))
1529 return BSS_CHANGED_TXPOWER;
1530 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001531}
1532
Johannes Berg965beda2009-04-16 13:17:24 +02001533/* powersave */
1534static void ieee80211_enable_ps(struct ieee80211_local *local,
1535 struct ieee80211_sub_if_data *sdata)
1536{
1537 struct ieee80211_conf *conf = &local->hw.conf;
1538
Johannes Bergd5edaed2009-04-22 23:02:51 +02001539 /*
1540 * If we are scanning right now then the parameters will
1541 * take effect when scan finishes.
1542 */
Helmut Schaafbe9c4292009-07-23 12:14:04 +02001543 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +02001544 return;
1545
Johannes Berg965beda2009-04-16 13:17:24 +02001546 if (conf->dynamic_ps_timeout > 0 &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001547 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001548 mod_timer(&local->dynamic_ps_timer, jiffies +
1549 msecs_to_jiffies(conf->dynamic_ps_timeout));
1550 } else {
Johannes Berg30686bf2015-06-02 21:39:54 +02001551 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
Johannes Berg076cdcb2015-09-24 16:14:55 +02001552 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajan375177b2010-02-09 14:50:28 +05301553
Johannes Berg30686bf2015-06-02 21:39:54 +02001554 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1555 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001556 return;
1557
1558 conf->flags |= IEEE80211_CONF_PS;
1559 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +02001560 }
1561}
1562
1563static void ieee80211_change_ps(struct ieee80211_local *local)
1564{
1565 struct ieee80211_conf *conf = &local->hw.conf;
1566
1567 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +02001568 ieee80211_enable_ps(local, local->ps_sdata);
1569 } else if (conf->flags & IEEE80211_CONF_PS) {
1570 conf->flags &= ~IEEE80211_CONF_PS;
1571 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1572 del_timer_sync(&local->dynamic_ps_timer);
1573 cancel_work_sync(&local->dynamic_ps_enable_work);
1574 }
1575}
1576
Jason Young808118c2011-03-10 16:43:19 -08001577static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1578{
1579 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1580 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001581 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001582
1583 if (!mgd->powersave)
1584 return false;
1585
Johannes Berg05cb9102011-10-28 11:59:47 +02001586 if (mgd->broken_ap)
1587 return false;
1588
Jason Young808118c2011-03-10 16:43:19 -08001589 if (!mgd->associated)
1590 return false;
1591
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001592 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
Jason Young808118c2011-03-10 16:43:19 -08001593 return false;
1594
Alexander Bondar989c6502013-05-16 17:34:17 +03001595 if (!mgd->have_beacon)
Alexander Bondarce857882013-05-06 17:17:04 +03001596 return false;
1597
Jason Young808118c2011-03-10 16:43:19 -08001598 rcu_read_lock();
1599 sta = sta_info_get(sdata, mgd->bssid);
1600 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001601 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001602 rcu_read_unlock();
1603
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001604 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001605}
1606
Johannes Berg965beda2009-04-16 13:17:24 +02001607/* need to hold RTNL or interface lock */
Johannes Berg4a733ef2015-10-14 18:02:43 +02001608void ieee80211_recalc_ps(struct ieee80211_local *local)
Johannes Berg965beda2009-04-16 13:17:24 +02001609{
1610 struct ieee80211_sub_if_data *sdata, *found = NULL;
1611 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001612 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001613
Johannes Berg30686bf2015-06-02 21:39:54 +02001614 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001615 local->ps_sdata = NULL;
1616 return;
1617 }
1618
1619 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b662009-12-23 13:15:31 +01001620 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001621 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301622 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1623 /* If an AP vif is found, then disable PS
1624 * by setting the count to zero thereby setting
1625 * ps_sdata to NULL.
1626 */
1627 count = 0;
1628 break;
1629 }
Johannes Berg965beda2009-04-16 13:17:24 +02001630 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1631 continue;
1632 found = sdata;
1633 count++;
1634 }
1635
Jason Young808118c2011-03-10 16:43:19 -08001636 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg4a733ef2015-10-14 18:02:43 +02001637 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg10f644a2009-04-16 13:17:25 +02001638
Juuso Oikarinenff616382010-06-09 09:51:52 +03001639 timeout = local->dynamic_ps_forced_timeout;
Johannes Berg4a733ef2015-10-14 18:02:43 +02001640 if (timeout < 0)
1641 timeout = 100;
Johannes Berg09b85562013-02-06 23:07:41 +01001642 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001643
Johannes Berg4a733ef2015-10-14 18:02:43 +02001644 /* If the TIM IE is invalid, pretend the value is 1 */
1645 if (!dtimper)
1646 dtimper = 1;
Johannes Berg56007a02010-01-26 14:19:52 +01001647
Johannes Berg4a733ef2015-10-14 18:02:43 +02001648 local->hw.conf.ps_dtim_period = dtimper;
1649 local->ps_sdata = found;
Johannes Berg10f644a2009-04-16 13:17:25 +02001650 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001651 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001652 }
Johannes Berg965beda2009-04-16 13:17:24 +02001653
1654 ieee80211_change_ps(local);
1655}
1656
Eliad Pellerab095872012-07-27 12:33:22 +03001657void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1658{
1659 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1660
1661 if (sdata->vif.bss_conf.ps != ps_allowed) {
1662 sdata->vif.bss_conf.ps = ps_allowed;
1663 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1664 }
1665}
1666
Johannes Berg965beda2009-04-16 13:17:24 +02001667void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1668{
1669 struct ieee80211_local *local =
1670 container_of(work, struct ieee80211_local,
1671 dynamic_ps_disable_work);
1672
1673 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1674 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1675 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1676 }
1677
1678 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001679 IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +03001680 IEEE80211_QUEUE_STOP_REASON_PS,
1681 false);
Johannes Berg965beda2009-04-16 13:17:24 +02001682}
1683
1684void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1685{
1686 struct ieee80211_local *local =
1687 container_of(work, struct ieee80211_local,
1688 dynamic_ps_enable_work);
1689 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001690 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301691 unsigned long flags;
1692 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001693
1694 /* can only happen when PS was just disabled anyway */
1695 if (!sdata)
1696 return;
1697
Christian Lamparter5e340692011-06-30 21:08:43 +02001698 ifmgd = &sdata->u.mgd;
1699
Johannes Berg965beda2009-04-16 13:17:24 +02001700 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1701 return;
1702
Johannes Berg09b85562013-02-06 23:07:41 +01001703 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001704 /* don't enter PS if TX frames are pending */
1705 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301706 mod_timer(&local->dynamic_ps_timer, jiffies +
1707 msecs_to_jiffies(
1708 local->hw.conf.dynamic_ps_timeout));
1709 return;
1710 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001711
1712 /*
1713 * transmission can be stopped by others which leads to
1714 * dynamic_ps_timer expiry. Postpone the ps timer if it
1715 * is not the actual idle state.
1716 */
1717 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1718 for (q = 0; q < local->hw.queues; q++) {
1719 if (local->queue_stop_reasons[q]) {
1720 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1721 flags);
1722 mod_timer(&local->dynamic_ps_timer, jiffies +
1723 msecs_to_jiffies(
1724 local->hw.conf.dynamic_ps_timeout));
1725 return;
1726 }
1727 }
1728 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301729 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301730
Johannes Berg30686bf2015-06-02 21:39:54 +02001731 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301732 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Johannes Berga15983832013-03-26 22:02:42 +01001733 if (drv_tx_frames_pending(local)) {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301734 mod_timer(&local->dynamic_ps_timer, jiffies +
1735 msecs_to_jiffies(
1736 local->hw.conf.dynamic_ps_timeout));
Johannes Berga15983832013-03-26 22:02:42 +01001737 } else {
Johannes Berg076cdcb2015-09-24 16:14:55 +02001738 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301739 /* Flush to get the tx status of nullfunc frame */
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001740 ieee80211_flush_queues(local, sdata, false);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301741 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301742 }
1743
Johannes Berg30686bf2015-06-02 21:39:54 +02001744 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1745 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301746 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1747 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1748 local->hw.conf.flags |= IEEE80211_CONF_PS;
1749 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1750 }
Johannes Berg965beda2009-04-16 13:17:24 +02001751}
1752
Kees Cook34f11cd2017-10-16 16:35:49 -07001753void ieee80211_dynamic_ps_timer(struct timer_list *t)
Johannes Berg965beda2009-04-16 13:17:24 +02001754{
Kees Cook34f11cd2017-10-16 16:35:49 -07001755 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
Johannes Berg965beda2009-04-16 13:17:24 +02001756
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001757 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001758}
1759
Simon Wunderlich164eb022013-02-08 18:16:20 +01001760void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1761{
Geliang Tanga85a7e22016-01-01 23:48:52 +08001762 struct delayed_work *delayed_work = to_delayed_work(work);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001763 struct ieee80211_sub_if_data *sdata =
1764 container_of(delayed_work, struct ieee80211_sub_if_data,
1765 dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001766 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlich164eb022013-02-08 18:16:20 +01001767
Johannes Berg34a37402013-12-18 09:43:33 +01001768 mutex_lock(&sdata->local->mtx);
1769 if (sdata->wdev.cac_started) {
1770 ieee80211_vif_release_channel(sdata);
1771 cfg80211_cac_event(sdata->dev, &chandef,
1772 NL80211_RADAR_CAC_FINISHED,
1773 GFP_KERNEL);
1774 }
1775 mutex_unlock(&sdata->local->mtx);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001776}
1777
Johannes Berg02219b32014-10-07 10:38:50 +03001778static bool
1779__ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1780{
1781 struct ieee80211_local *local = sdata->local;
1782 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
John Linvillecc72f6e2015-01-06 14:39:33 -05001783 bool ret = false;
Johannes Berg02219b32014-10-07 10:38:50 +03001784 int ac;
1785
1786 if (local->hw.queues < IEEE80211_NUM_ACS)
1787 return false;
1788
1789 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1790 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1791 int non_acm_ac;
1792 unsigned long now = jiffies;
1793
1794 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1795 tx_tspec->admitted_time &&
1796 time_after(now, tx_tspec->time_slice_start + HZ)) {
1797 tx_tspec->consumed_tx_time = 0;
1798 tx_tspec->time_slice_start = now;
1799
1800 if (tx_tspec->downgraded)
1801 tx_tspec->action =
1802 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1803 }
1804
1805 switch (tx_tspec->action) {
1806 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1807 /* take the original parameters */
1808 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1809 sdata_err(sdata,
1810 "failed to set TX queue parameters for queue %d\n",
1811 ac);
1812 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1813 tx_tspec->downgraded = false;
1814 ret = true;
1815 break;
1816 case TX_TSPEC_ACTION_DOWNGRADE:
1817 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1818 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1819 ret = true;
1820 break;
1821 }
1822 /* downgrade next lower non-ACM AC */
1823 for (non_acm_ac = ac + 1;
1824 non_acm_ac < IEEE80211_NUM_ACS;
1825 non_acm_ac++)
1826 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1827 break;
Johannes Berg93db1d92016-09-14 09:23:51 +02001828 /* Usually the loop will result in using BK even if it
1829 * requires admission control, but such a configuration
1830 * makes no sense and we have to transmit somehow - the
1831 * AC selection does the same thing.
1832 * If we started out trying to downgrade from BK, then
1833 * the extra condition here might be needed.
Johannes Berg02219b32014-10-07 10:38:50 +03001834 */
Johannes Berg93db1d92016-09-14 09:23:51 +02001835 if (non_acm_ac >= IEEE80211_NUM_ACS)
1836 non_acm_ac = IEEE80211_AC_BK;
Johannes Berg02219b32014-10-07 10:38:50 +03001837 if (drv_conf_tx(local, sdata, ac,
1838 &sdata->tx_conf[non_acm_ac]))
1839 sdata_err(sdata,
1840 "failed to set TX queue parameters for queue %d\n",
1841 ac);
1842 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1843 ret = true;
1844 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1845 tx_tspec->time_slice_start + HZ - now + 1);
1846 break;
1847 case TX_TSPEC_ACTION_NONE:
1848 /* nothing now */
1849 break;
1850 }
1851 }
1852
1853 return ret;
1854}
1855
1856void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1857{
1858 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1859 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1860}
1861
1862static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1863{
1864 struct ieee80211_sub_if_data *sdata;
1865
1866 sdata = container_of(work, struct ieee80211_sub_if_data,
1867 u.mgd.tx_tspec_wk.work);
1868 ieee80211_sta_handle_tspec_ac_params(sdata);
1869}
1870
Johannes Berg60f8b39c2008-09-08 17:44:22 +02001871/* MLME */
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001872static bool
1873ieee80211_sta_wmm_params(struct ieee80211_local *local,
1874 struct ieee80211_sub_if_data *sdata,
1875 const u8 *wmm_param, size_t wmm_param_len,
1876 const struct ieee80211_mu_edca_param_set *mu_edca)
Jiri Bencf0706e82007-05-05 11:45:53 -07001877{
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001878 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
Johannes Berg4ced3f72010-07-19 16:39:04 +02001879 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001880 size_t left;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001881 int count, mu_edca_count, ac;
Johannes Berg4a3cb702013-02-12 16:43:19 +01001882 const u8 *pos;
1883 u8 uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001884
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001885 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001886 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001887
Johannes Berg32c50572012-03-28 11:04:29 +02001888 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001889 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001890
1891 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001892 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001893
Jiri Bencf0706e82007-05-05 11:45:53 -07001894 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001895 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001896
1897 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001898 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001899
Jiri Bencf0706e82007-05-05 11:45:53 -07001900 count = wmm_param[6] & 0x0f;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001901 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
1902 * if mu_edca was preset before and now it disappeared tell
1903 * the driver about it.
1904 */
1905 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
1906 if (count == ifmgd->wmm_last_param_set &&
1907 mu_edca_count == ifmgd->mu_edca_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001908 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001909 ifmgd->wmm_last_param_set = count;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02001910 ifmgd->mu_edca_last_param_set = mu_edca_count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001911
1912 pos = wmm_param + 8;
1913 left = wmm_param_len - 8;
1914
1915 memset(&params, 0, sizeof(params));
1916
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001917 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001918 for (; left >= 4; left -= 4, pos += 4) {
1919 int aci = (pos[0] >> 5) & 0x03;
1920 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001921 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001922
1923 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001924 case 1: /* AC_BK */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001925 ac = IEEE80211_AC_BK;
Johannes Berg988c0f72008-04-17 19:21:22 +02001926 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001927 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001928 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1929 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001930 params[ac].mu_edca = !!mu_edca;
1931 if (mu_edca)
1932 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
Jiri Bencf0706e82007-05-05 11:45:53 -07001933 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001934 case 2: /* AC_VI */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001935 ac = IEEE80211_AC_VI;
Johannes Berg988c0f72008-04-17 19:21:22 +02001936 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001937 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001938 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1939 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001940 params[ac].mu_edca = !!mu_edca;
1941 if (mu_edca)
1942 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
Jiri Bencf0706e82007-05-05 11:45:53 -07001943 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001944 case 3: /* AC_VO */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001945 ac = IEEE80211_AC_VO;
Johannes Berg988c0f72008-04-17 19:21:22 +02001946 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001947 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02001948 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1949 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001950 params[ac].mu_edca = !!mu_edca;
1951 if (mu_edca)
1952 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
Jiri Bencf0706e82007-05-05 11:45:53 -07001953 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001954 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001955 default:
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001956 ac = IEEE80211_AC_BE;
Johannes Berg988c0f72008-04-17 19:21:22 +02001957 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001958 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02001959 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1960 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001961 params[ac].mu_edca = !!mu_edca;
1962 if (mu_edca)
1963 params[ac].mu_edca_param_rec = mu_edca->ac_be;
Jiri Bencf0706e82007-05-05 11:45:53 -07001964 break;
1965 }
1966
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001967 params[ac].aifs = pos[0] & 0x0f;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001968
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001969 if (params[ac].aifs < 2) {
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001970 sdata_info(sdata,
1971 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001972 params[ac].aifs, aci);
1973 params[ac].aifs = 2;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001974 }
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001975 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1976 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
1977 params[ac].txop = get_unaligned_le16(pos + 2);
1978 params[ac].acm = acm;
1979 params[ac].uapsd = uapsd;
Kalle Valoab133152010-01-12 10:42:31 +02001980
Ilan Peer911a2642018-04-03 11:35:22 +03001981 if (params[ac].cw_min == 0 ||
Emmanuel Grumbachc470bdc2018-03-26 16:21:04 +03001982 params[ac].cw_min > params[ac].cw_max) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001983 sdata_info(sdata,
1984 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
1985 params[ac].cw_min, params[ac].cw_max, aci);
1986 return false;
1987 }
Haim Dreyfusse552af02018-03-28 13:24:10 +03001988 ieee80211_regulatory_limit_wmm_params(sdata, &params[ac], ac);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001989 }
1990
1991 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001992 mlme_dbg(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001993 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
1994 ac, params[ac].acm,
1995 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
1996 params[ac].txop, params[ac].uapsd,
1997 ifmgd->tx_tspec[ac].downgraded);
1998 sdata->tx_conf[ac] = params[ac];
1999 if (!ifmgd->tx_tspec[ac].downgraded &&
2000 drv_conf_tx(local, sdata, ac, &params[ac]))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002001 sdata_err(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02002002 "failed to set TX queue parameters for AC %d\n",
2003 ac);
Jiri Bencf0706e82007-05-05 11:45:53 -07002004 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02002005
2006 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02002007 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02002008 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07002009}
2010
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002011static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2012{
2013 lockdep_assert_held(&sdata->local->mtx);
2014
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002015 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002016 ieee80211_run_deferred_scan(sdata->local);
2017}
2018
2019static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2020{
2021 mutex_lock(&sdata->local->mtx);
2022 __ieee80211_stop_poll(sdata);
2023 mutex_unlock(&sdata->local->mtx);
2024}
2025
Johannes Berg7a5158e2008-10-08 10:59:33 +02002026static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2027 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02002028{
Johannes Bergbda39332008-10-11 01:51:51 +02002029 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302030 struct ieee80211_supported_band *sband;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002031 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002032 bool use_protection;
2033 bool use_short_preamble;
2034 bool use_short_slot;
2035
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302036 sband = ieee80211_get_sband(sdata);
2037 if (!sband)
2038 return changed;
2039
Johannes Berg7a5158e2008-10-08 10:59:33 +02002040 if (erp_valid) {
2041 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2042 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2043 } else {
2044 use_protection = false;
2045 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2046 }
2047
2048 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302049 if (sband->band == NL80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01002050 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02002051
Johannes Berg471b3ef2007-12-28 14:32:58 +01002052 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01002053 bss_conf->use_cts_prot = use_protection;
2054 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02002055 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02002056
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002057 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002058 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002059 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02002060 }
Daniel Draked9430a32007-07-27 15:43:24 +02002061
Johannes Berg7a5158e2008-10-08 10:59:33 +02002062 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02002063 bss_conf->use_short_slot = use_short_slot;
2064 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04002065 }
2066
2067 return changed;
2068}
2069
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002070static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002071 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02002072 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07002073{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002074 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002075 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002076 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002077
Johannes Bergae5eb022008-10-14 16:58:37 +02002078 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002079 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03002080 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002081
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002082 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
Ben Greear59c1ec22013-03-19 14:19:56 -07002083 beacon_loss_count * bss_conf->beacon_int));
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002084
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002085 sdata->u.mgd.associated = cbss;
2086 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002087
Johannes Berge8e4f522017-03-08 11:12:10 +01002088 ieee80211_check_rate_mask(sdata);
2089
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002090 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2091
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01002092 if (sdata->vif.p2p ||
2093 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002094 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01002095
Johannes Berg9caf0362012-11-29 01:25:20 +01002096 rcu_read_lock();
2097 ies = rcu_dereference(cbss->ies);
2098 if (ies) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002099 int ret;
2100
2101 ret = cfg80211_get_p2p_attr(
2102 ies->data, ies->len,
2103 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002104 (u8 *) &bss_conf->p2p_noa_attr,
2105 sizeof(bss_conf->p2p_noa_attr));
Johannes Berg9caf0362012-11-29 01:25:20 +01002106 if (ret >= 2) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002107 sdata->u.mgd.p2p_noa_index =
2108 bss_conf->p2p_noa_attr.index;
Johannes Berg9caf0362012-11-29 01:25:20 +01002109 bss_info_changed |= BSS_CHANGED_P2P_PS;
Johannes Berg9caf0362012-11-29 01:25:20 +01002110 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01002111 }
Johannes Berg9caf0362012-11-29 01:25:20 +01002112 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01002113 }
2114
Johannes Bergb291ba12009-07-10 15:29:03 +02002115 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002116 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002117
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002118 ieee80211_led_assoc(local, 1);
2119
Alexander Bondar989c6502013-05-16 17:34:17 +03002120 if (sdata->u.mgd.have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02002121 /*
2122 * If the AP is buggy we may get here with no DTIM period
2123 * known, so assume it's 1 which is the only safe assumption
2124 * in that case, although if the TIM IE is broken powersave
2125 * probably just won't work at all.
2126 */
2127 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Alexander Bondar817cee72013-05-19 14:23:57 +03002128 bss_conf->beacon_rate = bss->beacon_rate;
Alexander Bondar989c6502013-05-16 17:34:17 +03002129 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
Johannes Berg826262c2012-12-10 16:38:14 +02002130 } else {
Alexander Bondar817cee72013-05-19 14:23:57 +03002131 bss_conf->beacon_rate = NULL;
Johannes Berge5b900d2010-07-29 16:08:55 +02002132 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02002133 }
Johannes Berge5b900d2010-07-29 16:08:55 +02002134
Juuso Oikarinen68542962010-06-09 13:43:26 +03002135 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02002136
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002137 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01002138 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03002139 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002140 bss_info_changed |= BSS_CHANGED_CQM;
2141
Juuso Oikarinen68542962010-06-09 13:43:26 +03002142 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002143 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002144 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002145
Johannes Bergae5eb022008-10-14 16:58:37 +02002146 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03002147
Johannes Berg056508d2009-07-30 21:43:55 +02002148 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002149 ieee80211_recalc_ps(local);
Johannes Berg056508d2009-07-30 21:43:55 +02002150 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02002151
Johannes Berg04ecd252012-09-11 14:34:12 +02002152 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03002153 ieee80211_recalc_ps_vif(sdata);
2154
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002155 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07002156}
2157
Jouni Malinene69e95d2010-03-29 23:29:31 -07002158static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01002159 u16 stype, u16 reason, bool tx,
2160 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03002161{
Johannes Berg46900292009-02-15 12:44:28 +01002162 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002163 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01002164 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002165
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002166 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002167
Johannes Berg37ad3882012-02-24 13:50:54 +01002168 if (WARN_ON_ONCE(tx && !frame_buf))
2169 return;
2170
Johannes Bergb291ba12009-07-10 15:29:03 +02002171 if (WARN_ON(!ifmgd->associated))
2172 return;
2173
David Spinadel79543d82012-06-12 09:59:45 +03002174 ieee80211_stop_poll(sdata);
2175
Johannes Berg77fdaa12009-07-07 03:45:17 +02002176 ifmgd->associated = NULL;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002177 netif_carrier_off(sdata->dev);
2178
Eliad Peller88bc40e2012-07-12 17:35:33 +03002179 /*
2180 * if we want to get out of ps before disassoc (why?) we have
2181 * to do it before sending disassoc, as otherwise the null-packet
2182 * won't be valid.
2183 */
2184 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2185 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2186 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2187 }
2188 local->ps_sdata = NULL;
2189
Eliad Pellerab095872012-07-27 12:33:22 +03002190 /* disable per-vif ps */
2191 ieee80211_recalc_ps_vif(sdata);
2192
Emmanuel Grumbach14f2ae82015-01-22 23:30:19 +02002193 /* make sure ongoing transmission finishes */
2194 synchronize_net();
2195
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002196 /*
2197 * drop any frame before deauth/disassoc, this can be data or
2198 * management frame. Since we are disconnecting, we should not
2199 * insist sending these frames which can take time and delay
2200 * the disconnection and possible the roaming.
2201 */
Eliad Pellerf8239812012-06-27 14:18:22 +03002202 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002203 ieee80211_flush_queues(local, sdata, true);
Eliad Pellerf8239812012-06-27 14:18:22 +03002204
Johannes Berg37ad3882012-02-24 13:50:54 +01002205 /* deauthenticate/disassociate now */
Ilan Peer94ba9272018-02-19 14:48:41 +02002206 if (tx || frame_buf) {
Ilan Peer94ba9272018-02-19 14:48:41 +02002207 /*
2208 * In multi channel scenarios guarantee that the virtual
2209 * interface is granted immediate airtime to transmit the
2210 * deauthentication frame by calling mgd_prepare_tx, if the
2211 * driver requested so.
2212 */
2213 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2214 !ifmgd->have_beacon)
Ilan Peerd4e36e52018-04-20 13:49:25 +03002215 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Ilan Peer94ba9272018-02-19 14:48:41 +02002216
Eliad Peller88a9e312012-06-01 11:14:03 +03002217 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
2218 reason, tx, frame_buf);
Ilan Peer94ba9272018-02-19 14:48:41 +02002219 }
Johannes Berg37ad3882012-02-24 13:50:54 +01002220
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002221 /* flush out frame - make sure the deauth was actually sent */
Johannes Berg37ad3882012-02-24 13:50:54 +01002222 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002223 ieee80211_flush_queues(local, sdata, false);
Johannes Berg37ad3882012-02-24 13:50:54 +01002224
Eliad Peller88a9e312012-06-01 11:14:03 +03002225 /* clear bssid only after building the needed mgmt frames */
Joe Perchesc84a67a2015-03-02 19:54:57 -08002226 eth_zero_addr(ifmgd->bssid);
Eliad Peller88a9e312012-06-01 11:14:03 +03002227
Johannes Berg37ad3882012-02-24 13:50:54 +01002228 /* remove AP and TDLS peers */
Johannes Bergd34ba212013-12-04 22:46:11 +01002229 sta_info_flush(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01002230
2231 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002232 changed |= ieee80211_reset_erp_info(sdata);
2233
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002234 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02002235 changed |= BSS_CHANGED_ASSOC;
2236 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002237
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002238 ifmgd->p2p_noa_index = -1;
2239 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2240 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01002241
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002242 /* on the next assoc, re-program HT/VHT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08002243 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2244 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002245 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2246 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
Sara Sharon23a1f8d2015-12-08 16:04:31 +02002247
2248 /* reset MU-MIMO ownership and group data */
2249 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2250 sizeof(sdata->vif.bss_conf.mu_group.membership));
2251 memset(sdata->vif.bss_conf.mu_group.position, 0,
2252 sizeof(sdata->vif.bss_conf.mu_group.position));
2253 changed |= BSS_CHANGED_MU_GROUPS;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002254 sdata->vif.mu_mimo_owner = false;
Johannes Berg413ad502009-05-08 21:21:06 +02002255
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002256 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05302257
Kalle Valo520eb822008-12-18 23:35:27 +02002258 del_timer_sync(&local->dynamic_ps_timer);
2259 cancel_work_sync(&local->dynamic_ps_enable_work);
2260
Juuso Oikarinen68542962010-06-09 13:43:26 +03002261 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002262 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002263 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002264
Johannes Berg3abead52012-03-02 15:56:59 +01002265 sdata->vif.bss_conf.qos = false;
2266 changed |= BSS_CHANGED_QOS;
2267
Johannes Berg0aaffa92010-05-05 15:28:27 +02002268 /* The BSSID (not really interesting) and HT changed */
2269 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02002270 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02002271
Johannes Berg3abead52012-03-02 15:56:59 +01002272 /* disassociated - set to defaults now */
Johannes Bergcec66282015-10-22 17:46:04 +02002273 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg3abead52012-03-02 15:56:59 +01002274
Johannes Bergb9dcf712010-08-27 12:35:54 +02002275 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2276 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2277 del_timer_sync(&sdata->u.mgd.timer);
2278 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02002279
Johannes Berg826262c2012-12-10 16:38:14 +02002280 sdata->vif.bss_conf.dtim_period = 0;
Alexander Bondar817cee72013-05-19 14:23:57 +03002281 sdata->vif.bss_conf.beacon_rate = NULL;
2282
Alexander Bondar989c6502013-05-16 17:34:17 +03002283 ifmgd->have_beacon = false;
Johannes Berg826262c2012-12-10 16:38:14 +02002284
Johannes Berg028e8da02012-11-26 11:57:41 +01002285 ifmgd->flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002286 mutex_lock(&local->mtx);
Johannes Berg028e8da02012-11-26 11:57:41 +01002287 ieee80211_vif_release_channel(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002288
2289 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002290 ifmgd->csa_waiting_bcn = false;
Johannes Bergf84eaa12015-03-12 08:53:26 +02002291 ifmgd->csa_ignored_same_chan = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002292 if (sdata->csa_block_tx) {
2293 ieee80211_wake_vif_queues(local, sdata,
2294 IEEE80211_QUEUE_STOP_REASON_CSA);
2295 sdata->csa_block_tx = false;
2296 }
Johannes Berg34a37402013-12-18 09:43:33 +01002297 mutex_unlock(&local->mtx);
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002298
Johannes Berg02219b32014-10-07 10:38:50 +03002299 /* existing TX TSPEC sessions no longer exist */
2300 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2301 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2302
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002303 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002304}
Jiri Bencf0706e82007-05-05 11:45:53 -07002305
Kalle Valo3cf335d52009-03-22 21:57:06 +02002306void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2307 struct ieee80211_hdr *hdr)
2308{
2309 /*
2310 * We can postpone the mgd.timer whenever receiving unicast frames
2311 * from AP because we know that the connection is working both ways
2312 * at that time. But multicast frames (and hence also beacons) must
2313 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02002314 * data idle periods for sending the periodic probe request to the
2315 * AP we're connected to.
Kalle Valo3cf335d52009-03-22 21:57:06 +02002316 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002317 if (is_multicast_ether_addr(hdr->addr1))
2318 return;
2319
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04002320 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d52009-03-22 21:57:06 +02002321}
Jiri Bencf0706e82007-05-05 11:45:53 -07002322
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002323static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2324{
2325 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002326 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002327
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002328 mutex_lock(&local->mtx);
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002329 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2330 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002331
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002332 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002333
2334 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002335 ieee80211_recalc_ps(local);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002336 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002337
Johannes Berg30686bf2015-06-02 21:39:54 +02002338 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002339 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002340
2341 /*
2342 * We've received a probe response, but are not sure whether
2343 * we have or will be receiving any beacons or data, so let's
2344 * schedule the timers again, just in case.
2345 */
2346 ieee80211_sta_reset_beacon_monitor(sdata);
2347
2348 mod_timer(&ifmgd->conn_mon_timer,
2349 round_jiffies_up(jiffies +
2350 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002351out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002352 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002353}
2354
Johannes Berg02219b32014-10-07 10:38:50 +03002355static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2356 struct ieee80211_hdr *hdr,
2357 u16 tx_time)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002358{
Johannes Berg02219b32014-10-07 10:38:50 +03002359 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Sara Sharona1f2ba04c2018-02-19 14:48:40 +02002360 u16 tid = ieee80211_get_tid(hdr);
Johannes Berg02219b32014-10-07 10:38:50 +03002361 int ac = ieee80211_ac_from_tid(tid);
2362 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2363 unsigned long now = jiffies;
2364
2365 if (likely(!tx_tspec->admitted_time))
2366 return;
2367
2368 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2369 tx_tspec->consumed_tx_time = 0;
2370 tx_tspec->time_slice_start = now;
2371
2372 if (tx_tspec->downgraded) {
2373 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2374 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2375 }
2376 }
2377
2378 if (tx_tspec->downgraded)
2379 return;
2380
2381 tx_tspec->consumed_tx_time += tx_time;
2382
2383 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2384 tx_tspec->downgraded = true;
2385 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2386 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2387 }
2388}
2389
2390void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2391 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2392{
2393 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2394
Felix Fietkau75706d02010-12-02 21:01:07 +01002395 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002396 return;
2397
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002398 if (ieee80211_is_nullfunc(hdr->frame_control) &&
2399 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002400 if (ack)
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002401 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002402 else
2403 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002404 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002405 return;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002406 }
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002407
2408 if (ack)
2409 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002410}
2411
Johannes Berg45ad6832018-05-28 15:47:39 +02002412static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2413 const u8 *src, const u8 *dst,
2414 const u8 *ssid, size_t ssid_len,
2415 struct ieee80211_channel *channel)
2416{
2417 struct sk_buff *skb;
2418
2419 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2420 ssid, ssid_len, NULL, 0,
2421 IEEE80211_PROBE_FLAG_DIRECTED);
2422 if (skb)
2423 ieee80211_tx_skb(sdata, skb);
2424}
2425
Maxim Levitskya43abf22009-07-31 18:54:12 +03002426static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2427{
2428 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2429 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002430 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08002431 u8 unicast_limit = max(1, max_probe_tries - 3);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002432 struct sta_info *sta;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002433
2434 /*
2435 * Try sending broadcast probe requests for the last three
2436 * probe requests after the first ones failed since some
2437 * buggy APs only support broadcast probe requests.
2438 */
2439 if (ifmgd->probe_send_count >= unicast_limit)
2440 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002441
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002442 /*
2443 * When the hardware reports an accurate Tx ACK status, it's
2444 * better to send a nullfunc frame instead of a probe request,
2445 * as it will kick us off the AP quickly if we aren't associated
2446 * anymore. The timeout will be reset if the frame is ACKed by
2447 * the AP.
2448 */
Soumik Das992e68b2012-05-20 15:31:13 +05302449 ifmgd->probe_send_count++;
2450
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002451 if (dst) {
2452 mutex_lock(&sdata->local->sta_mtx);
2453 sta = sta_info_get(sdata, dst);
2454 if (!WARN_ON(!sta))
2455 ieee80211_check_fast_rx(sta);
2456 mutex_unlock(&sdata->local->sta_mtx);
2457 }
2458
Johannes Berg30686bf2015-06-02 21:39:54 +02002459 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002460 ifmgd->nullfunc_failed = false;
Johannes Berg076cdcb2015-09-24 16:14:55 +02002461 ieee80211_send_nullfunc(sdata->local, sdata, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002462 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002463 int ssid_len;
2464
Johannes Berg9caf0362012-11-29 01:25:20 +01002465 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002466 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002467 if (WARN_ON_ONCE(ssid == NULL))
2468 ssid_len = 0;
2469 else
2470 ssid_len = ssid[1];
2471
Johannes Berg45ad6832018-05-28 15:47:39 +02002472 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2473 ssid + 2, ssid_len,
2474 ifmgd->associated->channel);
Johannes Berg9caf0362012-11-29 01:25:20 +01002475 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002476 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03002477
Ben Greear180205b2011-02-04 15:30:24 -08002478 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002479 run_again(sdata, ifmgd->probe_timeout);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002480}
2481
Johannes Bergb291ba12009-07-10 15:29:03 +02002482static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2483 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02002484{
Kalle Valo04de8382009-03-22 21:57:35 +02002485 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002486 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02002487
Johannes Berg9607e6b662009-12-23 13:15:31 +01002488 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02002489 return;
2490
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002491 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002492
2493 if (!ifmgd->associated)
2494 goto out;
2495
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002496 mutex_lock(&sdata->local->mtx);
2497
2498 if (sdata->local->tmp_channel || sdata->local->scanning) {
2499 mutex_unlock(&sdata->local->mtx);
2500 goto out;
2501 }
2502
Ben Greeara13fbe52013-03-25 11:19:35 -07002503 if (beacon) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002504 mlme_dbg_ratelimited(sdata,
Ben Greear59c1ec22013-03-19 14:19:56 -07002505 "detected beacon loss from AP (missed %d beacons) - probing\n",
2506 beacon_loss_count);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002507
Johannes Berg98f03342014-11-26 12:42:02 +01002508 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
Ben Greeara13fbe52013-03-25 11:19:35 -07002509 }
Kalle Valo04de8382009-03-22 21:57:35 +02002510
Johannes Bergb291ba12009-07-10 15:29:03 +02002511 /*
2512 * The driver/our work has already reported this event or the
2513 * connection monitoring has kicked in and we have already sent
2514 * a probe request. Or maybe the AP died and the driver keeps
2515 * reporting until we disassociate...
2516 *
2517 * In either case we have to ignore the current call to this
2518 * function (except for setting the correct probe reason bit)
2519 * because otherwise we would reset the timer every time and
2520 * never check whether we received a probe response!
2521 */
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002522 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Johannes Bergb291ba12009-07-10 15:29:03 +02002523 already = true;
2524
Eliad Peller12b5f342013-11-18 19:06:46 +02002525 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2526
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002527 mutex_unlock(&sdata->local->mtx);
2528
Johannes Bergb291ba12009-07-10 15:29:03 +02002529 if (already)
2530 goto out;
2531
Johannes Berg4e751842009-06-10 15:16:52 +02002532 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002533 ieee80211_recalc_ps(sdata->local);
Johannes Berg4e751842009-06-10 15:16:52 +02002534 mutex_unlock(&sdata->local->iflist_mtx);
2535
Maxim Levitskya43abf22009-07-31 18:54:12 +03002536 ifmgd->probe_send_count = 0;
2537 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002538 out:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002539 sdata_unlock(sdata);
Kalle Valo04de8382009-03-22 21:57:35 +02002540}
2541
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002542struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2543 struct ieee80211_vif *vif)
2544{
2545 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2546 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002547 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002548 struct sk_buff *skb;
2549 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002550 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002551
2552 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2553 return NULL;
2554
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002555 sdata_assert_lock(sdata);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002556
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002557 if (ifmgd->associated)
2558 cbss = ifmgd->associated;
2559 else if (ifmgd->auth_data)
2560 cbss = ifmgd->auth_data->bss;
2561 else if (ifmgd->assoc_data)
2562 cbss = ifmgd->assoc_data->bss;
2563 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002564 return NULL;
2565
Johannes Berg9caf0362012-11-29 01:25:20 +01002566 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002567 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002568 if (WARN_ON_ONCE(ssid == NULL))
2569 ssid_len = 0;
2570 else
2571 ssid_len = ssid[1];
2572
Johannes Berga344d672014-06-12 22:24:31 +02002573 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02002574 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02002575 ssid + 2, ssid_len,
Johannes Berg00387f32018-05-28 15:47:38 +02002576 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
Johannes Berg9caf0362012-11-29 01:25:20 +01002577 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002578
2579 return skb;
2580}
2581EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2582
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002583static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2584 const u8 *buf, size_t len, bool tx,
2585 u16 reason)
2586{
2587 struct ieee80211_event event = {
2588 .type = MLME_EVENT,
2589 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2590 .u.mlme.reason = reason,
2591 };
2592
2593 if (tx)
2594 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2595 else
2596 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2597
2598 drv_event_callback(sdata->local, sdata, &event);
2599}
2600
Johannes Bergeef9e542013-01-29 13:09:34 +01002601static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002602{
Michal Kazior59af6922014-04-09 15:10:59 +02002603 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002604 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002605 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002606 bool tx;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002607
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002608 sdata_lock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002609 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002610 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002611 return;
2612 }
2613
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002614 tx = !sdata->csa_block_tx;
2615
David Spinadel20eb7ea2016-05-03 16:05:02 +03002616 /* AP is probably out of range (or not reachable for another reason) so
2617 * remove the bss struct for that AP.
2618 */
2619 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2620
Johannes Berg37ad3882012-02-24 13:50:54 +01002621 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2622 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002623 tx, frame_buf);
Michal Kazior59af6922014-04-09 15:10:59 +02002624 mutex_lock(&local->mtx);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002625 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002626 ifmgd->csa_waiting_bcn = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002627 if (sdata->csa_block_tx) {
2628 ieee80211_wake_vif_queues(local, sdata,
2629 IEEE80211_QUEUE_STOP_REASON_CSA);
2630 sdata->csa_block_tx = false;
2631 }
Michal Kazior59af6922014-04-09 15:10:59 +02002632 mutex_unlock(&local->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002633
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002634 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002635 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2636
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002637 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002638}
2639
Johannes Bergcc74c0c2012-08-01 16:49:34 +02002640static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02002641{
2642 struct ieee80211_sub_if_data *sdata =
2643 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002644 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002645 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Paul Stewarta85e1d52011-12-09 11:01:49 -08002646
Johannes Berg976bd9e2015-10-16 17:18:11 +02002647 if (ifmgd->associated)
2648 ifmgd->beacon_loss_count++;
Johannes Bergb291ba12009-07-10 15:29:03 +02002649
Johannes Berg682bd382013-01-29 13:13:50 +01002650 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02002651 sdata_info(sdata, "Connection to AP %pM lost\n",
2652 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01002653 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02002654 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002655 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02002656 }
2657}
2658
2659static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2660{
2661 struct ieee80211_sub_if_data *sdata =
2662 container_of(work, struct ieee80211_sub_if_data,
2663 u.mgd.csa_connection_drop_work);
2664
Johannes Bergeef9e542013-01-29 13:09:34 +01002665 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002666}
2667
Kalle Valo04de8382009-03-22 21:57:35 +02002668void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2669{
2670 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002671 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02002672
Johannes Bergb5878a22010-04-07 16:48:40 +02002673 trace_api_beacon_loss(sdata);
2674
Johannes Berg682bd382013-01-29 13:13:50 +01002675 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002676 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002677}
2678EXPORT_SYMBOL(ieee80211_beacon_loss);
2679
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002680void ieee80211_connection_loss(struct ieee80211_vif *vif)
2681{
2682 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2683 struct ieee80211_hw *hw = &sdata->local->hw;
2684
Johannes Bergb5878a22010-04-07 16:48:40 +02002685 trace_api_connection_loss(sdata);
2686
Johannes Berg682bd382013-01-29 13:13:50 +01002687 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002688 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2689}
2690EXPORT_SYMBOL(ieee80211_connection_loss);
2691
2692
Johannes Berg66e67e42012-01-20 13:55:27 +01002693static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2694 bool assoc)
2695{
2696 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2697
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002698 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002699
Johannes Berg66e67e42012-01-20 13:55:27 +01002700 if (!assoc) {
Emmanuel Grumbachc1e140b2015-01-19 16:53:06 +02002701 /*
2702 * we are not authenticated yet, the only timer that could be
2703 * running is the timeout for the authentication response which
2704 * which is not relevant anymore.
2705 */
2706 del_timer_sync(&sdata->u.mgd.timer);
Johannes Berg66e67e42012-01-20 13:55:27 +01002707 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2708
Joe Perchesc84a67a2015-03-02 19:54:57 -08002709 eth_zero_addr(sdata->u.mgd.bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002710 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002711 sdata->u.mgd.flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002712 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002713 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002714 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01002715 }
2716
Johannes Berg5b112d32013-02-01 01:49:58 +01002717 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002718 kfree(auth_data);
2719 sdata->u.mgd.auth_data = NULL;
2720}
2721
Johannes Bergc9c99f82015-06-01 14:10:09 +02002722static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
Johannes Berge6f462d2016-12-08 17:22:09 +01002723 bool assoc, bool abandon)
Johannes Bergc9c99f82015-06-01 14:10:09 +02002724{
2725 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2726
2727 sdata_assert_lock(sdata);
2728
2729 if (!assoc) {
2730 /*
2731 * we are not associated yet, the only timer that could be
2732 * running is the timeout for the association response which
2733 * which is not relevant anymore.
2734 */
2735 del_timer_sync(&sdata->u.mgd.timer);
2736 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2737
2738 eth_zero_addr(sdata->u.mgd.bssid);
2739 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2740 sdata->u.mgd.flags = 0;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002741 sdata->vif.mu_mimo_owner = false;
2742
Johannes Bergc9c99f82015-06-01 14:10:09 +02002743 mutex_lock(&sdata->local->mtx);
2744 ieee80211_vif_release_channel(sdata);
2745 mutex_unlock(&sdata->local->mtx);
Johannes Berge6f462d2016-12-08 17:22:09 +01002746
2747 if (abandon)
2748 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
Johannes Bergc9c99f82015-06-01 14:10:09 +02002749 }
2750
2751 kfree(assoc_data);
2752 sdata->u.mgd.assoc_data = NULL;
2753}
2754
Johannes Berg66e67e42012-01-20 13:55:27 +01002755static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2756 struct ieee80211_mgmt *mgmt, size_t len)
2757{
Johannes Berg1672c0e32013-01-29 15:02:27 +01002758 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01002759 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2760 u8 *pos;
2761 struct ieee802_11_elems elems;
Johannes Berg1672c0e32013-01-29 15:02:27 +01002762 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002763
2764 pos = mgmt->u.auth.variable;
Sara Sharon4abb52a2019-01-16 12:14:41 +02002765 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
2766 mgmt->bssid, auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002767 if (!elems.challenge)
2768 return;
2769 auth_data->expected_transaction = 4;
Ilan Peerd4e36e52018-04-20 13:49:25 +03002770 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg30686bf2015-06-02 21:39:54 +02002771 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +01002772 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2773 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03002774 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01002775 elems.challenge - 2, elems.challenge_len + 2,
2776 auth_data->bss->bssid, auth_data->bss->bssid,
2777 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002778 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002779}
2780
Jouni Malinenfc107a92018-10-11 00:21:19 +03002781static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2782 const u8 *bssid)
2783{
Jouni Malinenefb543e2018-10-11 00:21:21 +03002784 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002785 struct sta_info *sta;
Wei Yongjun33483a62018-10-16 02:35:30 +00002786 bool result = true;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002787
Jouni Malinenefb543e2018-10-11 00:21:21 +03002788 sdata_info(sdata, "authenticated\n");
2789 ifmgd->auth_data->done = true;
2790 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2791 ifmgd->auth_data->timeout_started = true;
2792 run_again(sdata, ifmgd->auth_data->timeout);
2793
Jouni Malinenfc107a92018-10-11 00:21:19 +03002794 /* move station state to auth */
2795 mutex_lock(&sdata->local->sta_mtx);
2796 sta = sta_info_get(sdata, bssid);
2797 if (!sta) {
2798 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
Wei Yongjun33483a62018-10-16 02:35:30 +00002799 result = false;
2800 goto out;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002801 }
2802 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2803 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Wei Yongjun33483a62018-10-16 02:35:30 +00002804 result = false;
2805 goto out;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002806 }
Jouni Malinenfc107a92018-10-11 00:21:19 +03002807
Wei Yongjun33483a62018-10-16 02:35:30 +00002808out:
2809 mutex_unlock(&sdata->local->sta_mtx);
2810 return result;
Jouni Malinenfc107a92018-10-11 00:21:19 +03002811}
2812
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002813static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2814 struct ieee80211_mgmt *mgmt, size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002815{
2816 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2817 u8 bssid[ETH_ALEN];
2818 u16 auth_alg, auth_transaction, status_code;
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002819 struct ieee80211_event event = {
2820 .type = MLME_EVENT,
2821 .u.mlme.data = AUTH_EVENT,
2822 };
Johannes Berg66e67e42012-01-20 13:55:27 +01002823
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002824 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002825
2826 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002827 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002828
2829 if (!ifmgd->auth_data || ifmgd->auth_data->done)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002830 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002831
2832 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2833
Joe Perchesb203ca32012-05-08 18:56:52 +00002834 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002835 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002836
2837 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2838 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2839 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2840
2841 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinenefb543e2018-10-11 00:21:21 +03002842 (auth_alg != WLAN_AUTH_SAE &&
2843 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2844 (auth_alg == WLAN_AUTH_SAE &&
2845 (auth_transaction < ifmgd->auth_data->expected_transaction ||
2846 auth_transaction > 2))) {
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002847 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2848 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2849 auth_transaction,
2850 ifmgd->auth_data->expected_transaction);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002851 return;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002852 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002853
2854 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002855 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2856 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002857 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002858 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002859 event.u.mlme.status = MLME_DENIED;
2860 event.u.mlme.reason = status_code;
2861 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002862 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002863 }
2864
2865 switch (ifmgd->auth_data->algorithm) {
2866 case WLAN_AUTH_OPEN:
2867 case WLAN_AUTH_LEAP:
2868 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002869 case WLAN_AUTH_SAE:
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03002870 case WLAN_AUTH_FILS_SK:
2871 case WLAN_AUTH_FILS_SK_PFS:
2872 case WLAN_AUTH_FILS_PK:
Johannes Berg66e67e42012-01-20 13:55:27 +01002873 break;
2874 case WLAN_AUTH_SHARED_KEY:
2875 if (ifmgd->auth_data->expected_transaction != 4) {
2876 ieee80211_auth_challenge(sdata, mgmt, len);
2877 /* need another frame */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002878 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002879 }
2880 break;
2881 default:
2882 WARN_ONCE(1, "invalid auth alg %d",
2883 ifmgd->auth_data->algorithm);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002884 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002885 }
2886
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002887 event.u.mlme.status = MLME_SUCCESS;
2888 drv_event_callback(sdata->local, sdata, &event);
Jouni Malinenefb543e2018-10-11 00:21:21 +03002889 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
2890 (auth_transaction == 2 &&
2891 ifmgd->auth_data->expected_transaction == 2)) {
2892 if (!ieee80211_mark_sta_auth(sdata, bssid))
2893 goto out_err;
2894 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2895 auth_transaction == 2) {
2896 sdata_info(sdata, "SAE peer confirmed\n");
2897 ifmgd->auth_data->peer_confirmed = true;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002898 }
2899
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002900 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002901 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002902 out_err:
2903 mutex_unlock(&sdata->local->sta_mtx);
2904 /* ignore frame -- wait for timeout */
Johannes Berg66e67e42012-01-20 13:55:27 +01002905}
2906
Calvin Owensdfa1ad22014-02-11 12:36:24 -06002907#define case_WLAN(type) \
2908 case WLAN_REASON_##type: return #type
2909
2910static const char *ieee80211_get_reason_code_string(u16 reason_code)
2911{
2912 switch (reason_code) {
2913 case_WLAN(UNSPECIFIED);
2914 case_WLAN(PREV_AUTH_NOT_VALID);
2915 case_WLAN(DEAUTH_LEAVING);
2916 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2917 case_WLAN(DISASSOC_AP_BUSY);
2918 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2919 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2920 case_WLAN(DISASSOC_STA_HAS_LEFT);
2921 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2922 case_WLAN(DISASSOC_BAD_POWER);
2923 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2924 case_WLAN(INVALID_IE);
2925 case_WLAN(MIC_FAILURE);
2926 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
2927 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
2928 case_WLAN(IE_DIFFERENT);
2929 case_WLAN(INVALID_GROUP_CIPHER);
2930 case_WLAN(INVALID_PAIRWISE_CIPHER);
2931 case_WLAN(INVALID_AKMP);
2932 case_WLAN(UNSUPP_RSN_VERSION);
2933 case_WLAN(INVALID_RSN_IE_CAP);
2934 case_WLAN(IEEE8021X_FAILED);
2935 case_WLAN(CIPHER_SUITE_REJECTED);
2936 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
2937 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
2938 case_WLAN(DISASSOC_LOW_ACK);
2939 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
2940 case_WLAN(QSTA_LEAVE_QBSS);
2941 case_WLAN(QSTA_NOT_USE);
2942 case_WLAN(QSTA_REQUIRE_SETUP);
2943 case_WLAN(QSTA_TIMEOUT);
2944 case_WLAN(QSTA_CIPHER_NOT_SUPP);
2945 case_WLAN(MESH_PEER_CANCELED);
2946 case_WLAN(MESH_MAX_PEERS);
2947 case_WLAN(MESH_CONFIG);
2948 case_WLAN(MESH_CLOSE);
2949 case_WLAN(MESH_MAX_RETRIES);
2950 case_WLAN(MESH_CONFIRM_TIMEOUT);
2951 case_WLAN(MESH_INVALID_GTK);
2952 case_WLAN(MESH_INCONSISTENT_PARAM);
2953 case_WLAN(MESH_INVALID_SECURITY);
2954 case_WLAN(MESH_PATH_ERROR);
2955 case_WLAN(MESH_PATH_NOFORWARD);
2956 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
2957 case_WLAN(MAC_EXISTS_IN_MBSS);
2958 case_WLAN(MESH_CHAN_REGULATORY);
2959 case_WLAN(MESH_CHAN);
2960 default: return "<unknown>";
2961 }
2962}
Johannes Berg66e67e42012-01-20 13:55:27 +01002963
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002964static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2965 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002966{
Johannes Berg46900292009-02-15 12:44:28 +01002967 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergc9c99f82015-06-01 14:10:09 +02002968 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002969
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002970 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002971
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002972 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002973 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002974
Johannes Bergc9c99f82015-06-01 14:10:09 +02002975 if (ifmgd->associated &&
2976 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
2977 const u8 *bssid = ifmgd->associated->bssid;
2978
2979 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
2980 bssid, reason_code,
2981 ieee80211_get_reason_code_string(reason_code));
2982
2983 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2984
2985 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
2986 reason_code);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002987 return;
Johannes Bergc9c99f82015-06-01 14:10:09 +02002988 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002989
Johannes Bergc9c99f82015-06-01 14:10:09 +02002990 if (ifmgd->assoc_data &&
2991 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2992 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002993
Johannes Bergc9c99f82015-06-01 14:10:09 +02002994 sdata_info(sdata,
2995 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
2996 bssid, reason_code,
2997 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07002998
Johannes Berge6f462d2016-12-08 17:22:09 +01002999 ieee80211_destroy_assoc_data(sdata, false, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07003000
Johannes Bergc9c99f82015-06-01 14:10:09 +02003001 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3002 return;
3003 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003004}
3005
3006
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003007static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3008 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003009{
Johannes Berg46900292009-02-15 12:44:28 +01003010 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07003011 u16 reason_code;
3012
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003013 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003014
Johannes Bergf4ea83d2008-06-30 15:10:46 +02003015 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003016 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003017
Johannes Berg66e67e42012-01-20 13:55:27 +01003018 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00003019 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003020 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003021
3022 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3023
Arkadiusz Miskiewicz68506e92017-02-15 14:21:27 +01003024 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3025 mgmt->sa, reason_code,
3026 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07003027
Johannes Berg37ad3882012-02-24 13:50:54 +01003028 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3029
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003030 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07003031}
3032
Christian Lamparterc74d0842011-10-15 00:14:49 +02003033static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3034 u8 *supp_rates, unsigned int supp_rates_len,
3035 u32 *rates, u32 *basic_rates,
3036 bool *have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003037 int *min_rate, int *min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03003038 int shift)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003039{
3040 int i, j;
3041
3042 for (i = 0; i < supp_rates_len; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003043 int rate = supp_rates[i] & 0x7f;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003044 bool is_basic = !!(supp_rates[i] & 0x80);
3045
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003046 if ((rate * 5 * (1 << shift)) > 110)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003047 *have_higher_than_11mbit = true;
3048
3049 /*
Johannes Berga6289d32017-03-06 22:59:04 +01003050 * Skip HT and VHT BSS membership selectors since they're not
3051 * rates.
Christian Lamparterc74d0842011-10-15 00:14:49 +02003052 *
Johannes Berga6289d32017-03-06 22:59:04 +01003053 * Note: Even though the membership selector and the basic
Christian Lamparterc74d0842011-10-15 00:14:49 +02003054 * rate flag share the same bit, they are not exactly
3055 * the same.
3056 */
Johannes Berga6289d32017-03-06 22:59:04 +01003057 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3058 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
Christian Lamparterc74d0842011-10-15 00:14:49 +02003059 continue;
3060
3061 for (j = 0; j < sband->n_bitrates; j++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003062 struct ieee80211_rate *br;
3063 int brate;
3064
3065 br = &sband->bitrates[j];
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003066
3067 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3068 if (brate == rate) {
Christian Lamparterc74d0842011-10-15 00:14:49 +02003069 *rates |= BIT(j);
3070 if (is_basic)
3071 *basic_rates |= BIT(j);
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003072 if ((rate * 5) < *min_rate) {
3073 *min_rate = rate * 5;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003074 *min_rate_index = j;
3075 }
3076 break;
3077 }
3078 }
3079 }
3080}
Jiri Bencf0706e82007-05-05 11:45:53 -07003081
Emmanuel Grumbach55ebd6e2018-12-15 11:03:04 +02003082static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3083 const struct ieee802_11_elems *elems)
3084{
3085 if (elems->ext_capab_len < 10)
3086 return false;
3087
3088 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3089 return false;
3090
3091 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3092 IEEE80211_HE_MAC_CAP0_TWT_RES;
3093}
3094
Johannes Berg66e67e42012-01-20 13:55:27 +01003095static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3096 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003097 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003098{
Johannes Berg46900292009-02-15 12:44:28 +01003099 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01003100 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01003101 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003102 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003103 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003104 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07003105 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02003106 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg35d865a2013-05-28 10:54:03 +02003107 const struct cfg80211_bss_ies *bss_ies = NULL;
3108 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
Johannes Bergae5eb022008-10-14 16:58:37 +02003109 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003110 int err;
Johannes Berg35d865a2013-05-28 10:54:03 +02003111 bool ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003112
Johannes Bergaf6b6372009-12-23 13:15:35 +01003113 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07003114
Jiri Bencf0706e82007-05-05 11:45:53 -07003115 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003116 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07003117
Johannes Bergc7c477b2017-12-01 13:50:51 +02003118 /*
3119 * The 5 MSB of the AID field are reserved
3120 * (802.11-2016 9.4.1.8 AID field)
3121 */
3122 aid &= 0x7ff;
Johannes Berg1dd84aa2007-10-10 12:03:41 +02003123
Johannes Berg05cb9102011-10-28 11:59:47 +02003124 ifmgd->broken_ap = false;
3125
3126 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003127 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3128 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02003129 aid = 0;
3130 ifmgd->broken_ap = true;
3131 }
3132
Johannes Bergaf6b6372009-12-23 13:15:35 +01003133 pos = mgmt->u.assoc_resp.variable;
Sara Sharon4abb52a2019-01-16 12:14:41 +02003134 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3135 mgmt->bssid, assoc_data->bss->bssid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003136
Jiri Bencf0706e82007-05-05 11:45:53 -07003137 if (!elems.supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003138 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01003139 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07003140 }
3141
Johannes Berg46900292009-02-15 12:44:28 +01003142 ifmgd->aid = aid;
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02003143 ifmgd->tdls_chan_switch_prohibited =
3144 elems.ext_capab && elems.ext_capab_len >= 5 &&
3145 (elems.ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
Jiri Bencf0706e82007-05-05 11:45:53 -07003146
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003147 /*
Johannes Berg35d865a2013-05-28 10:54:03 +02003148 * Some APs are erroneously not including some information in their
3149 * (re)association response frames. Try to recover by using the data
3150 * from the beacon or probe response. This seems to afflict mobile
3151 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3152 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3153 */
3154 if ((assoc_data->wmm && !elems.wmm_param) ||
3155 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3156 (!elems.ht_cap_elem || !elems.ht_operation)) ||
3157 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3158 (!elems.vht_cap_elem || !elems.vht_operation))) {
3159 const struct cfg80211_bss_ies *ies;
3160 struct ieee802_11_elems bss_elems;
3161
3162 rcu_read_lock();
3163 ies = rcu_dereference(cbss->ies);
3164 if (ies)
3165 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3166 GFP_ATOMIC);
3167 rcu_read_unlock();
3168 if (!bss_ies)
3169 return false;
3170
3171 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003172 false, &bss_elems,
3173 mgmt->bssid,
3174 assoc_data->bss->bssid);
Johannes Berg35d865a2013-05-28 10:54:03 +02003175 if (assoc_data->wmm &&
3176 !elems.wmm_param && bss_elems.wmm_param) {
3177 elems.wmm_param = bss_elems.wmm_param;
3178 sdata_info(sdata,
3179 "AP bug: WMM param missing from AssocResp\n");
3180 }
3181
3182 /*
3183 * Also check if we requested HT/VHT, otherwise the AP doesn't
3184 * have to include the IEs in the (re)association response.
3185 */
3186 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
3187 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3188 elems.ht_cap_elem = bss_elems.ht_cap_elem;
3189 sdata_info(sdata,
3190 "AP bug: HT capability missing from AssocResp\n");
3191 }
3192 if (!elems.ht_operation && bss_elems.ht_operation &&
3193 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3194 elems.ht_operation = bss_elems.ht_operation;
3195 sdata_info(sdata,
3196 "AP bug: HT operation missing from AssocResp\n");
3197 }
3198 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
3199 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3200 elems.vht_cap_elem = bss_elems.vht_cap_elem;
3201 sdata_info(sdata,
3202 "AP bug: VHT capa missing from AssocResp\n");
3203 }
3204 if (!elems.vht_operation && bss_elems.vht_operation &&
3205 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3206 elems.vht_operation = bss_elems.vht_operation;
3207 sdata_info(sdata,
3208 "AP bug: VHT operation missing from AssocResp\n");
3209 }
3210 }
3211
3212 /*
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003213 * We previously checked these in the beacon/probe response, so
3214 * they should be present here. This is just a safety net.
3215 */
3216 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3217 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
3218 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003219 "HT AP is missing WMM params or HT capability/operation\n");
3220 ret = false;
3221 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003222 }
3223
3224 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3225 (!elems.vht_cap_elem || !elems.vht_operation)) {
3226 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003227 "VHT AP is missing VHT capability/operation\n");
3228 ret = false;
3229 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003230 }
3231
Guy Eilam2a33bee2011-08-17 15:18:15 +03003232 mutex_lock(&sdata->local->sta_mtx);
3233 /*
3234 * station info was already allocated and inserted before
3235 * the association and should be available to us
3236 */
Johannes Berg7852e362012-01-20 13:55:24 +01003237 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003238 if (WARN_ON(!sta)) {
3239 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003240 ret = false;
3241 goto out;
Jiri Bencf0706e82007-05-05 11:45:53 -07003242 }
3243
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05303244 sband = ieee80211_get_sband(sdata);
3245 if (!sband) {
3246 mutex_unlock(&sdata->local->sta_mtx);
3247 ret = false;
3248 goto out;
3249 }
Johannes Berg8318d782008-01-24 19:38:38 +01003250
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003251 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3252 (!elems.he_cap || !elems.he_operation)) {
3253 mutex_unlock(&sdata->local->sta_mtx);
3254 sdata_info(sdata,
3255 "HE AP is missing HE capability/operation\n");
3256 ret = false;
3257 goto out;
3258 }
3259
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003260 /* Set up internal HT/VHT capabilities */
Johannes Berga8243b72012-11-22 14:32:09 +01003261 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08003262 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01003263 elems.ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02003264
Mahesh Palivela818255e2012-10-10 11:33:04 +00003265 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3266 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01003267 elems.vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00003268
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003269 if (elems.he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3270 elems.he_cap) {
3271 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3272 elems.he_cap,
3273 elems.he_cap_len,
3274 sta);
3275
3276 bss_conf->he_support = sta->sta.he_cap.has_he;
Emmanuel Grumbach55ebd6e2018-12-15 11:03:04 +02003277 bss_conf->twt_requester =
3278 ieee80211_twt_req_supported(sta, &elems);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003279 } else {
3280 bss_conf->he_support = false;
Emmanuel Grumbach55ebd6e2018-12-15 11:03:04 +02003281 bss_conf->twt_requester = false;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003282 }
3283
3284 if (bss_conf->he_support) {
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003285 bss_conf->bss_color =
3286 le32_get_bits(elems.he_operation->he_oper_params,
3287 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003288
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003289 bss_conf->htc_trig_based_pkt_ext =
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003290 le32_get_bits(elems.he_operation->he_oper_params,
3291 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003292 bss_conf->frame_time_rts_th =
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003293 le32_get_bits(elems.he_operation->he_oper_params,
3294 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003295
3296 bss_conf->multi_sta_back_32bit =
3297 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3298 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
3299
3300 bss_conf->ack_enabled =
3301 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3302 IEEE80211_HE_MAC_CAP2_ACK_EN;
3303
3304 bss_conf->uora_exists = !!elems.uora_element;
3305 if (elems.uora_element)
3306 bss_conf->uora_ocw_range = elems.uora_element[0];
3307
3308 /* TODO: OPEN: what happens if BSS color disable is set? */
3309 }
3310
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003311 /*
3312 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3313 * in their association response, so ignore that data for our own
3314 * configuration. If it changed since the last beacon, we'll get the
3315 * next beacon and update then.
3316 */
Johannes Berg11289582013-02-07 17:36:12 +01003317
Johannes Bergbee7f5862013-02-07 22:24:55 +01003318 /*
3319 * If an operating mode notification IE is present, override the
3320 * NSS calculation (that would be done in rate_control_rate_init())
3321 * and use the # of streams from that element.
3322 */
3323 if (elems.opmode_notif &&
3324 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3325 u8 nss;
3326
3327 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3328 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3329 nss += 1;
3330 sta->sta.rx_nss = nss;
3331 }
3332
Johannes Berg4b7679a2008-09-18 18:14:18 +02003333 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003334
Tamizh chelvam93f04902015-10-07 10:40:04 +05303335 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003336 set_sta_flag(sta, WLAN_STA_MFP);
Tamizh chelvam93f04902015-10-07 10:40:04 +05303337 sta->sta.mfp = true;
3338 } else {
3339 sta->sta.mfp = false;
3340 }
Jouni Malinen5394af42009-01-08 13:31:59 +02003341
Johannes Berg527871d2015-03-21 08:09:55 +01003342 sta->sta.wme = elems.wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
Johannes Bergddf4ac52008-10-22 11:41:38 +02003343
Johannes Berg3e4d40f2013-02-07 17:19:08 +01003344 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01003345 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3346 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3347 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003348 sdata_info(sdata,
3349 "failed to move station %pM to desired state\n",
3350 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01003351 WARN_ON(__sta_info_destroy(sta));
3352 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003353 ret = false;
3354 goto out;
Johannes Bergc8987872012-01-20 13:55:17 +01003355 }
3356
Johannes Berg7852e362012-01-20 13:55:24 +01003357 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02003358
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003359 /*
3360 * Always handle WMM once after association regardless
3361 * of the first value the AP uses. Setting -1 here has
3362 * that effect because the AP values is an unsigned
3363 * 4-bit value.
3364 */
3365 ifmgd->wmm_last_param_set = -1;
Shaul Triebitz2e249fc2018-12-15 11:03:15 +02003366 ifmgd->mu_edca_last_param_set = -1;
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003367
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003368 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Bergcec66282015-10-22 17:46:04 +02003369 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003370 } else if (!ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003371 elems.wmm_param_len,
3372 elems.mu_edca_param_set)) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003373 /* still enable QoS since we might have HT/VHT */
3374 ieee80211_set_wmm_default(sdata, false, true);
3375 /* set the disable-WMM flag in this case to disable
3376 * tracking WMM parameter changes in the beacon if
3377 * the parameters weren't actually valid. Doing so
3378 * avoids changing parameters very strangely when
3379 * the AP is going back and forth between valid and
3380 * invalid parameters.
3381 */
3382 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3383 }
Johannes Berg3abead52012-03-02 15:56:59 +01003384 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07003385
Avraham Sterne38a0172017-04-26 10:58:47 +03003386 if (elems.max_idle_period_ie) {
3387 bss_conf->max_idle_period =
3388 le16_to_cpu(elems.max_idle_period_ie->max_idle_period);
3389 bss_conf->protected_keep_alive =
3390 !!(elems.max_idle_period_ie->idle_options &
3391 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3392 changed |= BSS_CHANGED_KEEP_ALIVE;
3393 } else {
3394 bss_conf->max_idle_period = 0;
3395 bss_conf->protected_keep_alive = false;
3396 }
3397
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003398 /* set AID and assoc capability,
3399 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01003400 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003401 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003402 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003403
Kalle Valo15b7b062009-03-22 21:57:14 +02003404 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01003405 * If we're using 4-addr mode, let the AP know that we're
3406 * doing so, so that it can create the STA VLAN on its side
3407 */
3408 if (ifmgd->use_4addr)
3409 ieee80211_send_4addr_nullfunc(local, sdata);
3410
3411 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02003412 * Start timer to probe the connection to the AP now.
3413 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02003414 */
Johannes Bergb291ba12009-07-10 15:29:03 +02003415 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003416 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02003417
Johannes Berg35d865a2013-05-28 10:54:03 +02003418 ret = true;
3419 out:
3420 kfree(bss_ies);
3421 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003422}
3423
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003424static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3425 struct ieee80211_mgmt *mgmt,
3426 size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01003427{
3428 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3429 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3430 u16 capab_info, status_code, aid;
3431 struct ieee802_11_elems elems;
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003432 int ac, uapsd_queues = -1;
Johannes Berg66e67e42012-01-20 13:55:27 +01003433 u8 *pos;
3434 bool reassoc;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003435 struct cfg80211_bss *bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003436 struct ieee80211_event event = {
3437 .type = MLME_EVENT,
3438 .u.mlme.data = ASSOC_EVENT,
3439 };
Jiri Bencf0706e82007-05-05 11:45:53 -07003440
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003441 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003442
3443 if (!assoc_data)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003444 return;
Joe Perchesb203ca32012-05-08 18:56:52 +00003445 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003446 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003447
3448 /*
3449 * AssocResp and ReassocResp have identical structure, so process both
3450 * of them in this function.
3451 */
3452
3453 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003454 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003455
Simon Dinkin7a7d3e42017-08-31 13:09:36 +03003456 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
Johannes Berg66e67e42012-01-20 13:55:27 +01003457 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3458 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3459 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3460
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003461 sdata_info(sdata,
3462 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3463 reassoc ? "Rea" : "A", mgmt->sa,
3464 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01003465
Jouni Malinen39404fe2016-10-27 00:42:05 +03003466 if (assoc_data->fils_kek_len &&
3467 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3468 return;
3469
Johannes Berg66e67e42012-01-20 13:55:27 +01003470 pos = mgmt->u.assoc_resp.variable;
Sara Sharon4abb52a2019-01-16 12:14:41 +02003471 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3472 mgmt->bssid, assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003473
3474 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01003475 elems.timeout_int &&
3476 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003477 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01003478 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01003479 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003480 sdata_info(sdata,
3481 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3482 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01003483 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01003484 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01003485 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003486 run_again(sdata, assoc_data->timeout);
3487 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003488 }
3489
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003490 bss = assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01003491
3492 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003493 sdata_info(sdata, "%pM denied association (code=%d)\n",
3494 mgmt->sa, status_code);
Johannes Berge6f462d2016-12-08 17:22:09 +01003495 ieee80211_destroy_assoc_data(sdata, false, false);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003496 event.u.mlme.status = MLME_DENIED;
3497 event.u.mlme.reason = status_code;
3498 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01003499 } else {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003500 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003501 /* oops -- internal error -- send timeout for now */
Johannes Berge6f462d2016-12-08 17:22:09 +01003502 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02003503 cfg80211_assoc_timeout(sdata->dev, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003504 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003505 }
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003506 event.u.mlme.status = MLME_SUCCESS;
3507 drv_event_callback(sdata->local, sdata, &event);
John W. Linville635d9992012-07-09 16:34:34 -04003508 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01003509
3510 /*
3511 * destroy assoc_data afterwards, as otherwise an idle
3512 * recalc after assoc_data is NULL but before associated
3513 * is set can cause the interface to go idle
3514 */
Johannes Berge6f462d2016-12-08 17:22:09 +01003515 ieee80211_destroy_assoc_data(sdata, true, false);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003516
3517 /* get uapsd queues configuration */
3518 uapsd_queues = 0;
3519 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3520 if (sdata->tx_conf[ac].uapsd)
Emmanuel Grumbachf438ceb2016-10-18 23:12:12 +03003521 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
Johannes Berg66e67e42012-01-20 13:55:27 +01003522 }
3523
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003524 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues);
Johannes Berg66e67e42012-01-20 13:55:27 +01003525}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003526
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003527static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003528 struct ieee80211_mgmt *mgmt, size_t len,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003529 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003530{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003531 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02003532 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01003533 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01003534
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003535 sdata_assert_lock(sdata);
Johannes Bergb4f286a12013-03-26 14:13:58 +01003536
Emmanuel Grumbach3afc2162014-03-04 16:50:13 +02003537 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3538 if (!channel)
Johannes Berg5bda6172008-09-08 11:05:10 +02003539 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003540
Sara Sharon4abb52a2019-01-16 12:14:41 +02003541 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
Alexander Bondar817cee72013-05-19 14:23:57 +03003542 if (bss) {
Alexander Bondar817cee72013-05-19 14:23:57 +03003543 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
Johannes Bergd2722f82014-03-04 11:43:28 +01003544 ieee80211_rx_bss_put(local, bss);
Alexander Bondar817cee72013-05-19 14:23:57 +03003545 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003546}
3547
3548
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003549static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003550 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003551{
Johannes Bergaf6b6372009-12-23 13:15:35 +01003552 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02003553 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003554 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3555 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03003556
Kalle Valo15b7b062009-03-22 21:57:14 +02003557 ifmgd = &sdata->u.mgd;
3558
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003559 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003560
Joe Perchesb203ca32012-05-08 18:56:52 +00003561 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03003562 return; /* ignore ProbeResp to foreign address */
3563
Ester Kummerae6a44e2008-06-27 18:54:48 +03003564 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3565 if (baselen > len)
3566 return;
3567
Sara Sharon4abb52a2019-01-16 12:14:41 +02003568 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03003569
Johannes Berg77fdaa12009-07-07 03:45:17 +02003570 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003571 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003572 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003573}
3574
Johannes Bergd91f36d2009-04-16 13:17:26 +02003575/*
3576 * This is the canonical list of information elements we care about,
3577 * the filter code also gives us all changes to the Microsoft OUI
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003578 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3579 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3580 * changes to requested client power.
Johannes Bergd91f36d2009-04-16 13:17:26 +02003581 *
3582 * We implement beacon filtering in software since that means we can
3583 * avoid processing the frame here and in cfg80211, and userspace
3584 * will not be able to tell whether the hardware supports it or not.
3585 *
3586 * XXX: This list needs to be dynamic -- userspace needs to be able to
3587 * add items it requires. It also needs to be able to tell us to
3588 * look out for other vendor IEs.
3589 */
3590static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02003591 (1ULL << WLAN_EID_COUNTRY) |
3592 (1ULL << WLAN_EID_ERP_INFO) |
3593 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3594 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3595 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg70a3fd62015-03-12 08:53:29 +02003596 (1ULL << WLAN_EID_HT_OPERATION) |
3597 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003598
Tosoni1ad22fb2018-03-14 16:58:34 +00003599static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3600 struct ieee80211_if_managed *ifmgd,
3601 struct ieee80211_bss_conf *bss_conf,
3602 struct ieee80211_local *local,
3603 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003604{
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003605 /* Track average RSSI from the Beacon frames of the current AP */
Tosoni1ad22fb2018-03-14 16:58:34 +00003606
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003607 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3608 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Johannes Berg338c17a2015-08-28 10:52:54 +02003609 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003610 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03003611 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003612 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003613 } else {
Jouni Malinen391a2002010-08-27 22:22:00 +03003614 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003615 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003616
Johannes Berg338c17a2015-08-28 10:52:54 +02003617 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3618
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003619 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3620 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003621 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003622 int last_sig = ifmgd->last_ave_beacon_signal;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003623 struct ieee80211_event event = {
3624 .type = RSSI_EVENT,
3625 };
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003626
3627 /*
3628 * if signal crosses either of the boundaries, invoke callback
3629 * with appropriate parameters
3630 */
3631 if (sig > ifmgd->rssi_max_thold &&
3632 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3633 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003634 event.u.rssi.data = RSSI_EVENT_HIGH;
3635 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003636 } else if (sig < ifmgd->rssi_min_thold &&
3637 (last_sig >= ifmgd->rssi_max_thold ||
3638 last_sig == 0)) {
3639 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003640 event.u.rssi.data = RSSI_EVENT_LOW;
3641 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003642 }
3643 }
3644
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003645 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03003646 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01003647 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003648 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003649 int last_event = ifmgd->last_cqm_event_signal;
3650 int thold = bss_conf->cqm_rssi_thold;
3651 int hyst = bss_conf->cqm_rssi_hyst;
Johannes Berg338c17a2015-08-28 10:52:54 +02003652
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003653 if (sig < thold &&
3654 (last_event == 0 || sig < last_event - hyst)) {
3655 ifmgd->last_cqm_event_signal = sig;
3656 ieee80211_cqm_rssi_notify(
3657 &sdata->vif,
3658 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003659 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003660 } else if (sig > thold &&
3661 (last_event == 0 || sig > last_event + hyst)) {
3662 ifmgd->last_cqm_event_signal = sig;
3663 ieee80211_cqm_rssi_notify(
3664 &sdata->vif,
3665 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003666 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003667 }
3668 }
3669
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003670 if (bss_conf->cqm_rssi_low &&
3671 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3672 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3673 int last_event = ifmgd->last_cqm_event_signal;
3674 int low = bss_conf->cqm_rssi_low;
3675 int high = bss_conf->cqm_rssi_high;
3676
3677 if (sig < low &&
3678 (last_event == 0 || last_event >= low)) {
3679 ifmgd->last_cqm_event_signal = sig;
3680 ieee80211_cqm_rssi_notify(
3681 &sdata->vif,
3682 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3683 sig, GFP_KERNEL);
3684 } else if (sig > high &&
3685 (last_event == 0 || last_event <= high)) {
3686 ifmgd->last_cqm_event_signal = sig;
3687 ieee80211_cqm_rssi_notify(
3688 &sdata->vif,
3689 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3690 sig, GFP_KERNEL);
3691 }
3692 }
Tosoni1ad22fb2018-03-14 16:58:34 +00003693}
3694
3695static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3696 struct ieee80211_mgmt *mgmt, size_t len,
3697 struct ieee80211_rx_status *rx_status)
3698{
3699 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3700 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3701 size_t baselen;
3702 struct ieee802_11_elems elems;
3703 struct ieee80211_local *local = sdata->local;
3704 struct ieee80211_chanctx_conf *chanctx_conf;
3705 struct ieee80211_channel *chan;
3706 struct sta_info *sta;
3707 u32 changed = 0;
3708 bool erp_valid;
3709 u8 erp_value = 0;
3710 u32 ncrc;
3711 u8 *bssid;
3712 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3713
3714 sdata_assert_lock(sdata);
3715
3716 /* Process beacon from the current BSS */
3717 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3718 if (baselen > len)
3719 return;
3720
3721 rcu_read_lock();
3722 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3723 if (!chanctx_conf) {
3724 rcu_read_unlock();
3725 return;
3726 }
3727
3728 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3729 rcu_read_unlock();
3730 return;
3731 }
3732 chan = chanctx_conf->def.chan;
3733 rcu_read_unlock();
3734
3735 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
3736 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3737 ieee802_11_parse_elems(mgmt->u.beacon.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003738 len - baselen, false, &elems,
3739 mgmt->bssid,
3740 ifmgd->assoc_data->bss->bssid);
Tosoni1ad22fb2018-03-14 16:58:34 +00003741
Sara Sharon4abb52a2019-01-16 12:14:41 +02003742 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Tosoni1ad22fb2018-03-14 16:58:34 +00003743 if (elems.tim && !elems.parse_error) {
3744 const struct ieee80211_tim_ie *tim_ie = elems.tim;
3745 ifmgd->dtim_period = tim_ie->dtim_period;
3746 }
3747 ifmgd->have_beacon = true;
3748 ifmgd->assoc_data->need_beacon = false;
3749 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3750 sdata->vif.bss_conf.sync_tsf =
3751 le64_to_cpu(mgmt->u.beacon.timestamp);
3752 sdata->vif.bss_conf.sync_device_ts =
3753 rx_status->device_timestamp;
3754 if (elems.tim)
3755 sdata->vif.bss_conf.sync_dtim_count =
3756 elems.tim->dtim_count;
3757 else
3758 sdata->vif.bss_conf.sync_dtim_count = 0;
3759 }
3760 /* continue assoc process */
3761 ifmgd->assoc_data->timeout = jiffies;
3762 ifmgd->assoc_data->timeout_started = true;
3763 run_again(sdata, ifmgd->assoc_data->timeout);
3764 return;
3765 }
3766
3767 if (!ifmgd->associated ||
3768 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3769 return;
3770 bssid = ifmgd->associated->bssid;
3771
3772 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3773 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
3774 local, rx_status);
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003775
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003776 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003777 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01003778 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003779 ieee80211_reset_ap_probe(sdata);
Jouni Malinen92778182009-05-14 21:15:36 +03003780 }
3781
Johannes Bergb291ba12009-07-10 15:29:03 +02003782 /*
3783 * Push the beacon loss detection into the future since
3784 * we are processing a beacon from the AP just now.
3785 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003786 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003787
Johannes Bergd91f36d2009-04-16 13:17:26 +02003788 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3789 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003790 len - baselen, false, &elems,
Sara Sharon4abb52a2019-01-16 12:14:41 +02003791 care_about_ies, ncrc,
3792 mgmt->bssid, bssid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003793
Johannes Berg90d13e82015-09-24 16:13:07 +02003794 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3795 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3796 if (local->hw.conf.dynamic_ps_timeout > 0) {
3797 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3798 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3799 ieee80211_hw_config(local,
3800 IEEE80211_CONF_CHANGE_PS);
Kalle Valo572e0012009-02-10 17:09:31 +02003801 }
Johannes Berg076cdcb2015-09-24 16:14:55 +02003802 ieee80211_send_nullfunc(local, sdata, false);
Johannes Berg90d13e82015-09-24 16:13:07 +02003803 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3804 local->pspolling = true;
3805
3806 /*
3807 * Here is assumed that the driver will be
3808 * able to send ps-poll frame and receive a
3809 * response even though power save mode is
3810 * enabled, but some drivers might require
3811 * to disable power save here. This needs
3812 * to be investigated.
3813 */
3814 ieee80211_send_pspoll(local, sdata);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003815 }
3816 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003817
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01003818 if (sdata->vif.p2p ||
3819 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003820 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003821 int ret;
3822
3823 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3824 len - baselen,
3825 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003826 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003827 if (ret >= 2) {
3828 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3829 /* valid noa_attr and index changed */
3830 sdata->u.mgd.p2p_noa_index = noa.index;
3831 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3832 changed |= BSS_CHANGED_P2P_PS;
3833 /*
3834 * make sure we update all information, the CRC
3835 * mechanism doesn't look at P2P attributes.
3836 */
3837 ifmgd->beacon_crc_valid = false;
3838 }
3839 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3840 /* noa_attr not found and we had valid noa_attr before */
3841 sdata->u.mgd.p2p_noa_index = -1;
3842 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003843 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003844 ifmgd->beacon_crc_valid = false;
3845 }
3846 }
3847
Luciano Coelho0c21e632014-10-08 09:48:39 +03003848 if (ifmgd->csa_waiting_bcn)
3849 ieee80211_chswitch_post_beacon(sdata);
3850
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003851 /*
3852 * Update beacon timing and dtim count on every beacon appearance. This
3853 * will allow the driver to use the most updated values. Do it before
3854 * comparing this one with last received beacon.
3855 * IMPORTANT: These parameters would possibly be out of sync by the time
3856 * the driver will use them. The synchronized view is currently
3857 * guaranteed only in certain callbacks.
3858 */
Johannes Berg30686bf2015-06-02 21:39:54 +02003859 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003860 sdata->vif.bss_conf.sync_tsf =
3861 le64_to_cpu(mgmt->u.beacon.timestamp);
3862 sdata->vif.bss_conf.sync_device_ts =
3863 rx_status->device_timestamp;
3864 if (elems.tim)
3865 sdata->vif.bss_conf.sync_dtim_count =
3866 elems.tim->dtim_count;
3867 else
3868 sdata->vif.bss_conf.sync_dtim_count = 0;
3869 }
3870
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003871 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003872 return;
Jouni Malinen30196672009-05-19 17:01:43 +03003873 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003874 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03003875
Sara Sharon4abb52a2019-01-16 12:14:41 +02003876 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
Johannes Berg7d257452012-07-06 17:37:43 +02003877
Johannes Bergd70b7612013-08-23 15:48:48 +02003878 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003879 rx_status->device_timestamp,
Johannes Bergd70b7612013-08-23 15:48:48 +02003880 &elems, true);
3881
Johannes Berg095d81c2013-10-15 12:25:07 +02003882 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
3883 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003884 elems.wmm_param_len,
3885 elems.mu_edca_param_set))
Johannes Berg7d257452012-07-06 17:37:43 +02003886 changed |= BSS_CHANGED_QOS;
3887
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003888 /*
3889 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01003890 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003891 */
Alexander Bondar989c6502013-05-16 17:34:17 +03003892 if (!ifmgd->have_beacon) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003893 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3894 if (elems.tim)
3895 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3896 else
3897 bss_conf->dtim_period = 1;
Johannes Bergef429da2013-02-05 17:48:40 +01003898
Alexander Bondar989c6502013-05-16 17:34:17 +03003899 changed |= BSS_CHANGED_BEACON_INFO;
3900 ifmgd->have_beacon = true;
Alexander Bondar482a9c72013-06-03 17:29:33 +03003901
3902 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02003903 ieee80211_recalc_ps(local);
Alexander Bondar482a9c72013-06-03 17:29:33 +03003904 mutex_unlock(&local->iflist_mtx);
3905
Alexander Bondarce857882013-05-06 17:17:04 +03003906 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003907 }
3908
Johannes Berg1946bed2013-03-27 14:31:53 +01003909 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02003910 erp_valid = true;
3911 erp_value = elems.erp_info[0];
3912 } else {
3913 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04003914 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003915 changed |= ieee80211_handle_bss_capability(sdata,
3916 le16_to_cpu(mgmt->u.beacon.capab_info),
3917 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07003918
Johannes Berg11289582013-02-07 17:36:12 +01003919 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f5862013-02-07 22:24:55 +01003920 sta = sta_info_get(sdata, bssid);
3921
Eliad Peller53b954e2014-07-24 11:20:05 +03003922 if (ieee80211_config_bw(sdata, sta,
3923 elems.ht_cap_elem, elems.ht_operation,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003924 elems.vht_operation, elems.he_operation,
3925 bssid, &changed)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003926 mutex_unlock(&local->sta_mtx);
Johannes Berg89f774e2016-01-25 15:46:36 +02003927 sdata_info(sdata,
3928 "failed to follow AP %pM bandwidth change, disconnect\n",
3929 bssid);
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003930 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3931 WLAN_REASON_DEAUTH_LEAVING,
3932 true, deauth_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003933 ieee80211_report_disconnect(sdata, deauth_buf,
3934 sizeof(deauth_buf), true,
3935 WLAN_REASON_DEAUTH_LEAVING);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003936 return;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003937 }
Johannes Bergbee7f5862013-02-07 22:24:55 +01003938
3939 if (sta && elems.opmode_notif)
3940 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
Eyal Shapiracf1e05c2015-12-08 16:04:36 +02003941 rx_status->band);
Johannes Berg11289582013-02-07 17:36:12 +01003942 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003943
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07003944 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
3945 elems.country_elem,
3946 elems.country_elem_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003947 elems.pwr_constr_elem,
3948 elems.cisco_dtpc_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08003949
Johannes Berg471b3ef2007-12-28 14:32:58 +01003950 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003951}
3952
Johannes Berg1fa57d02010-06-10 10:21:32 +02003953void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3954 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003955{
3956 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07003957 struct ieee80211_mgmt *mgmt;
3958 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003959 struct ieee802_11_elems elems;
3960 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07003961
Jiri Bencf0706e82007-05-05 11:45:53 -07003962 rx_status = (struct ieee80211_rx_status *) skb->cb;
3963 mgmt = (struct ieee80211_mgmt *) skb->data;
3964 fc = le16_to_cpu(mgmt->frame_control);
3965
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003966 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003967
Johannes Berg66e67e42012-01-20 13:55:27 +01003968 switch (fc & IEEE80211_FCTL_STYPE) {
3969 case IEEE80211_STYPE_BEACON:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003970 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01003971 break;
3972 case IEEE80211_STYPE_PROBE_RESP:
3973 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3974 break;
3975 case IEEE80211_STYPE_AUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003976 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003977 break;
3978 case IEEE80211_STYPE_DEAUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003979 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003980 break;
3981 case IEEE80211_STYPE_DISASSOC:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003982 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003983 break;
3984 case IEEE80211_STYPE_ASSOC_RESP:
3985 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003986 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003987 break;
3988 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01003989 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003990 ies_len = skb->len -
3991 offsetof(struct ieee80211_mgmt,
3992 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01003993
3994 if (ies_len < 0)
3995 break;
3996
Sara Sharon4abb52a2019-01-16 12:14:41 +02003997 /* CSA IE cannot be overridden, no need for BSSID */
Johannes Berg37799e52013-03-26 14:02:26 +01003998 ieee802_11_parse_elems(
3999 mgmt->u.action.u.chan_switch.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02004000 ies_len, true, &elems, mgmt->bssid, NULL);
Johannes Berg37799e52013-03-26 14:02:26 +01004001
4002 if (elems.parse_error)
4003 break;
4004
Johannes Berg66e67e42012-01-20 13:55:27 +01004005 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03004006 rx_status->mactime,
4007 rx_status->device_timestamp,
4008 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004009 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4010 ies_len = skb->len -
4011 offsetof(struct ieee80211_mgmt,
4012 u.action.u.ext_chan_switch.variable);
4013
4014 if (ies_len < 0)
4015 break;
4016
Sara Sharon4abb52a2019-01-16 12:14:41 +02004017 /*
4018 * extended CSA IE can't be overridden, no need for
4019 * BSSID
4020 */
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004021 ieee802_11_parse_elems(
4022 mgmt->u.action.u.ext_chan_switch.variable,
Sara Sharon4abb52a2019-01-16 12:14:41 +02004023 ies_len, true, &elems, mgmt->bssid, NULL);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01004024
4025 if (elems.parse_error)
4026 break;
4027
4028 /* for the handling code pretend this was also an IE */
4029 elems.ext_chansw_ie =
4030 &mgmt->u.action.u.ext_chan_switch.data;
4031
4032 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03004033 rx_status->mactime,
4034 rx_status->device_timestamp,
4035 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004036 }
Johannes Berg37799e52013-03-26 14:02:26 +01004037 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004038 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004039 sdata_unlock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07004040}
4041
Kees Cook34f11cd2017-10-16 16:35:49 -07004042static void ieee80211_sta_timer(struct timer_list *t)
Jiri Bencf0706e82007-05-05 11:45:53 -07004043{
4044 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004045 from_timer(sdata, t, u.mgd.timer);
Jiri Bencf0706e82007-05-05 11:45:53 -07004046
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01004047 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07004048}
4049
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004050static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01004051 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004052{
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004053 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004054
Johannes Berg37ad3882012-02-24 13:50:54 +01004055 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01004056 tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01004057
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004058 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4059 reason);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004060}
4061
Johannes Berg46cad4b2015-08-15 22:39:54 +03004062static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg66e67e42012-01-20 13:55:27 +01004063{
4064 struct ieee80211_local *local = sdata->local;
4065 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4066 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004067 u32 tx_flags = 0;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004068 u16 trans = 1;
4069 u16 status = 0;
Ilan Peerd4e36e52018-04-20 13:49:25 +03004070 u16 prepare_tx_duration = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004071
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004072 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004073
4074 if (WARN_ON_ONCE(!auth_data))
4075 return -EINVAL;
4076
Johannes Berg66e67e42012-01-20 13:55:27 +01004077 auth_data->tries++;
4078
4079 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004080 sdata_info(sdata, "authentication with %pM timed out\n",
4081 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004082
4083 /*
4084 * Most likely AP is not in the range so remove the
4085 * bss struct for that AP.
4086 */
4087 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4088
4089 return -ETIMEDOUT;
4090 }
4091
Ilan Peerd4e36e52018-04-20 13:49:25 +03004092 if (auth_data->algorithm == WLAN_AUTH_SAE)
4093 prepare_tx_duration =
4094 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4095
4096 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
Johannes Berga1845fc2012-06-27 13:18:36 +02004097
Johannes Berg46cad4b2015-08-15 22:39:54 +03004098 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4099 auth_data->bss->bssid, auth_data->tries,
4100 IEEE80211_AUTH_MAX_TRIES);
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004101
Johannes Berg46cad4b2015-08-15 22:39:54 +03004102 auth_data->expected_transaction = 2;
Johannes Berg66e67e42012-01-20 13:55:27 +01004103
Johannes Berg46cad4b2015-08-15 22:39:54 +03004104 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4105 trans = auth_data->sae_trans;
4106 status = auth_data->sae_status;
4107 auth_data->expected_transaction = trans;
Johannes Berg66e67e42012-01-20 13:55:27 +01004108 }
4109
Johannes Berg46cad4b2015-08-15 22:39:54 +03004110 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4111 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4112 IEEE80211_TX_INTFL_MLME_CONN_TX;
4113
4114 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4115 auth_data->data, auth_data->data_len,
4116 auth_data->bss->bssid,
4117 auth_data->bss->bssid, NULL, 0, 0,
4118 tx_flags);
4119
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02004120 if (tx_flags == 0) {
Ilan Peer407879b2018-04-20 13:49:20 +03004121 if (auth_data->algorithm == WLAN_AUTH_SAE)
4122 auth_data->timeout = jiffies +
4123 IEEE80211_AUTH_TIMEOUT_SAE;
4124 else
4125 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004126 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004127 auth_data->timeout =
4128 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004129 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004130
Ilan Peer407879b2018-04-20 13:49:20 +03004131 auth_data->timeout_started = true;
4132 run_again(sdata, auth_data->timeout);
4133
Johannes Berg66e67e42012-01-20 13:55:27 +01004134 return 0;
4135}
4136
4137static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4138{
4139 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4140 struct ieee80211_local *local = sdata->local;
4141
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004142 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004143
Johannes Berg66e67e42012-01-20 13:55:27 +01004144 assoc_data->tries++;
4145 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004146 sdata_info(sdata, "association with %pM timed out\n",
4147 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004148
4149 /*
4150 * Most likely AP is not in the range so remove the
4151 * bss struct for that AP.
4152 */
4153 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4154
4155 return -ETIMEDOUT;
4156 }
4157
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004158 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4159 assoc_data->bss->bssid, assoc_data->tries,
4160 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01004161 ieee80211_send_assoc(sdata);
4162
Johannes Berg30686bf2015-06-02 21:39:54 +02004163 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004164 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004165 assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004166 run_again(sdata, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01004167 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004168 assoc_data->timeout =
4169 round_jiffies_up(jiffies +
4170 IEEE80211_ASSOC_TIMEOUT_LONG);
4171 assoc_data->timeout_started = true;
4172 run_again(sdata, assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004173 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004174
4175 return 0;
4176}
4177
Johannes Berg1672c0e32013-01-29 15:02:27 +01004178void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4179 __le16 fc, bool acked)
4180{
4181 struct ieee80211_local *local = sdata->local;
4182
4183 sdata->u.mgd.status_fc = fc;
4184 sdata->u.mgd.status_acked = acked;
4185 sdata->u.mgd.status_received = true;
4186
4187 ieee80211_queue_work(&local->hw, &sdata->work);
4188}
4189
Johannes Berg1fa57d02010-06-10 10:21:32 +02004190void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004191{
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004192 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02004193 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004194
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004195 sdata_lock(sdata);
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004196
Johannes Berg1672c0e32013-01-29 15:02:27 +01004197 if (ifmgd->status_received) {
4198 __le16 fc = ifmgd->status_fc;
4199 bool status_acked = ifmgd->status_acked;
4200
4201 ifmgd->status_received = false;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004202 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004203 if (status_acked) {
Ilan Peer407879b2018-04-20 13:49:20 +03004204 if (ifmgd->auth_data->algorithm ==
4205 WLAN_AUTH_SAE)
4206 ifmgd->auth_data->timeout =
4207 jiffies +
4208 IEEE80211_AUTH_TIMEOUT_SAE;
4209 else
4210 ifmgd->auth_data->timeout =
4211 jiffies +
4212 IEEE80211_AUTH_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004213 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004214 } else {
4215 ifmgd->auth_data->timeout = jiffies - 1;
4216 }
Johannes Berg89afe612013-02-13 15:39:57 +01004217 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004218 } else if (ifmgd->assoc_data &&
4219 (ieee80211_is_assoc_req(fc) ||
4220 ieee80211_is_reassoc_req(fc))) {
4221 if (status_acked) {
4222 ifmgd->assoc_data->timeout =
4223 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004224 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004225 } else {
4226 ifmgd->assoc_data->timeout = jiffies - 1;
4227 }
Johannes Berg89afe612013-02-13 15:39:57 +01004228 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004229 }
4230 }
4231
Johannes Berg89afe612013-02-13 15:39:57 +01004232 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004233 time_after(jiffies, ifmgd->auth_data->timeout)) {
4234 if (ifmgd->auth_data->done) {
4235 /*
4236 * ok ... we waited for assoc but userspace didn't,
4237 * so let's just kill the auth data
4238 */
4239 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg46cad4b2015-08-15 22:39:54 +03004240 } else if (ieee80211_auth(sdata)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004241 u8 bssid[ETH_ALEN];
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004242 struct ieee80211_event event = {
4243 .type = MLME_EVENT,
4244 .u.mlme.data = AUTH_EVENT,
4245 .u.mlme.status = MLME_TIMEOUT,
4246 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004247
4248 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4249
4250 ieee80211_destroy_auth_data(sdata, false);
4251
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004252 cfg80211_auth_timeout(sdata->dev, bssid);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004253 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004254 }
Johannes Berg89afe612013-02-13 15:39:57 +01004255 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004256 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004257
Johannes Berg89afe612013-02-13 15:39:57 +01004258 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004259 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Alexander Bondar989c6502013-05-16 17:34:17 +03004260 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01004261 ieee80211_do_assoc(sdata)) {
Johannes Berg959867f2013-06-19 13:05:42 +02004262 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004263 struct ieee80211_event event = {
4264 .type = MLME_EVENT,
4265 .u.mlme.data = ASSOC_EVENT,
4266 .u.mlme.status = MLME_TIMEOUT,
4267 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004268
Johannes Berge6f462d2016-12-08 17:22:09 +01004269 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02004270 cfg80211_assoc_timeout(sdata->dev, bss);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004271 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004272 }
Johannes Berg89afe612013-02-13 15:39:57 +01004273 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004274 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004275
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02004276 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
Johannes Bergb291ba12009-07-10 15:29:03 +02004277 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03004278 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004279 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03004280
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004281 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004282
Johannes Berg30686bf2015-06-02 21:39:54 +02004283 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Ben Greear180205b2011-02-04 15:30:24 -08004284 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004285 else
Ben Greear180205b2011-02-04 15:30:24 -08004286 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004287
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004288 /* ACK received for nullfunc probing frame */
4289 if (!ifmgd->probe_send_count)
4290 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004291 else if (ifmgd->nullfunc_failed) {
4292 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004293 mlme_dbg(sdata,
4294 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4295 bssid, ifmgd->probe_send_count,
4296 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004297 ieee80211_mgd_probe_ap_send(sdata);
4298 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004299 mlme_dbg(sdata,
4300 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4301 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02004302 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004303 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4304 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004305 }
4306 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004307 run_again(sdata, ifmgd->probe_timeout);
Johannes Berg30686bf2015-06-02 21:39:54 +02004308 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004309 mlme_dbg(sdata,
4310 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4311 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02004312 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004313 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004314 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004315 mlme_dbg(sdata,
4316 "No probe response from AP %pM after %dms, try %d/%i\n",
4317 bssid, probe_wait_ms,
4318 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03004319 ieee80211_mgd_probe_ap_send(sdata);
4320 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02004321 /*
4322 * We actually lost the connection ... or did we?
4323 * Let's make sure!
4324 */
Johannes Berg89f774e2016-01-25 15:46:36 +02004325 mlme_dbg(sdata,
4326 "No probe response from AP %pM after %dms, disconnecting.\n",
4327 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004328
Johannes Berg95acac62011-07-12 12:30:59 +02004329 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004330 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02004331 }
4332 }
4333
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004334 sdata_unlock(sdata);
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004335}
Johannes Berg0a51b272008-09-08 17:44:25 +02004336
Kees Cook34f11cd2017-10-16 16:35:49 -07004337static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004338{
4339 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004340 from_timer(sdata, t, u.mgd.bcn_mon_timer);
Luciano Coelho0c21e632014-10-08 09:48:39 +03004341 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004342
Luciano Coelho0c21e632014-10-08 09:48:39 +03004343 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004344 return;
4345
Johannes Berg682bd382013-01-29 13:13:50 +01004346 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004347 ieee80211_queue_work(&sdata->local->hw,
4348 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004349}
4350
Kees Cook34f11cd2017-10-16 16:35:49 -07004351static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004352{
4353 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004354 from_timer(sdata, t, u.mgd.conn_mon_timer);
Johannes Bergb291ba12009-07-10 15:29:03 +02004355 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4356 struct ieee80211_local *local = sdata->local;
4357
Luciano Coelho0c21e632014-10-08 09:48:39 +03004358 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004359 return;
4360
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04004361 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004362}
4363
4364static void ieee80211_sta_monitor_work(struct work_struct *work)
4365{
4366 struct ieee80211_sub_if_data *sdata =
4367 container_of(work, struct ieee80211_sub_if_data,
4368 u.mgd.monitor_work);
4369
4370 ieee80211_mgd_probe_ap(sdata, false);
4371}
4372
Johannes Berga1678f82008-09-11 00:01:47 +02004373static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4374{
Kalle Vaload935682009-04-19 08:47:19 +03004375 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02004376 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03004377
Johannes Bergb291ba12009-07-10 15:29:03 +02004378 /* let's probe the connection once */
Johannes Berg30686bf2015-06-02 21:39:54 +02004379 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Eliad Peller494f1fe2012-02-19 15:26:09 +02004380 ieee80211_queue_work(&sdata->local->hw,
4381 &sdata->u.mgd.monitor_work);
Kalle Vaload935682009-04-19 08:47:19 +03004382 }
Johannes Berga1678f82008-09-11 00:01:47 +02004383}
4384
Johannes Bergb8360ab2013-04-29 14:57:44 +02004385#ifdef CONFIG_PM
Johannes Berg1a1cb742014-03-19 09:55:55 +01004386void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4387{
4388 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4389 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4390
4391 sdata_lock(sdata);
4392
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004393 if (ifmgd->auth_data || ifmgd->assoc_data) {
4394 const u8 *bssid = ifmgd->auth_data ?
4395 ifmgd->auth_data->bss->bssid :
4396 ifmgd->assoc_data->bss->bssid;
4397
Johannes Berg1a1cb742014-03-19 09:55:55 +01004398 /*
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004399 * If we are trying to authenticate / associate while suspending,
4400 * cfg80211 won't know and won't actually abort those attempts,
4401 * thus we need to do that ourselves.
Johannes Berg1a1cb742014-03-19 09:55:55 +01004402 */
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004403 ieee80211_send_deauth_disassoc(sdata, bssid,
Johannes Berg1a1cb742014-03-19 09:55:55 +01004404 IEEE80211_STYPE_DEAUTH,
4405 WLAN_REASON_DEAUTH_LEAVING,
4406 false, frame_buf);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004407 if (ifmgd->assoc_data)
Johannes Berge6f462d2016-12-08 17:22:09 +01004408 ieee80211_destroy_assoc_data(sdata, false, true);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004409 if (ifmgd->auth_data)
4410 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg1a1cb742014-03-19 09:55:55 +01004411 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4412 IEEE80211_DEAUTH_FRAME_LEN);
4413 }
4414
Johannes Bergbe72afe2015-03-01 09:10:03 +02004415 /* This is a bit of a hack - we should find a better and more generic
4416 * solution to this. Normally when suspending, cfg80211 will in fact
4417 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4418 * auth (not so important) or assoc (this is the problem) process.
4419 *
4420 * As a consequence, it can happen that we are in the process of both
4421 * associating and suspending, and receive an association response
4422 * after cfg80211 has checked if it needs to disconnect, but before
4423 * we actually set the flag to drop incoming frames. This will then
4424 * cause the workqueue flush to process the association response in
4425 * the suspend, resulting in a successful association just before it
4426 * tries to remove the interface from the driver, which now though
4427 * has a channel context assigned ... this results in issues.
4428 *
4429 * To work around this (for now) simply deauth here again if we're
4430 * now connected.
4431 */
4432 if (ifmgd->associated && !sdata->local->wowlan) {
4433 u8 bssid[ETH_ALEN];
4434 struct cfg80211_deauth_request req = {
4435 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4436 .bssid = bssid,
4437 };
4438
4439 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4440 ieee80211_mgd_deauth(sdata, &req);
4441 }
4442
Johannes Berg1a1cb742014-03-19 09:55:55 +01004443 sdata_unlock(sdata);
4444}
4445
Johannes Bergb8360ab2013-04-29 14:57:44 +02004446void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4447{
4448 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4449
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004450 sdata_lock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004451 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004452 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004453 return;
4454 }
4455
4456 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4457 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4458 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4459 ieee80211_sta_connection_lost(sdata,
4460 ifmgd->associated->bssid,
4461 WLAN_REASON_UNSPECIFIED,
4462 true);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004463 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004464 return;
4465 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004466 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004467}
4468#endif
4469
Johannes Berg9c6bd792008-09-11 00:01:52 +02004470/* interface setup */
4471void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4472{
Johannes Berg46900292009-02-15 12:44:28 +01004473 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004474
Johannes Berg46900292009-02-15 12:44:28 +01004475 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004476 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01004477 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004478 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4479 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02004480 INIT_WORK(&ifmgd->csa_connection_drop_work,
4481 ieee80211_csa_connection_drop_work);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03004482 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03004483 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4484 ieee80211_tdls_peer_del_work);
Kees Cook34f11cd2017-10-16 16:35:49 -07004485 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4486 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4487 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4488 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
Johannes Berg02219b32014-10-07 10:38:50 +03004489 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4490 ieee80211_sta_handle_tspec_ac_params_wk);
Johannes Berg9c6bd792008-09-11 00:01:52 +02004491
Johannes Bergab1faea2009-07-01 21:41:17 +02004492 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05304493 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02004494 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4495 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01004496 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02004497
Eliad Peller0d8614b2014-09-10 14:07:36 +03004498 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
Johannes Berg0f782312009-12-01 13:37:02 +01004499 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4500 else
4501 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02004502
4503 /* Setup TDLS data */
4504 spin_lock_init(&ifmgd->teardown_lock);
4505 ifmgd->teardown_skb = NULL;
4506 ifmgd->orig_teardown_skb = NULL;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004507}
4508
4509/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02004510void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4511{
Johannes Berg31ee67a2012-07-06 21:18:24 +02004512 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02004513
4514 /* Restart STA timers */
4515 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07004516 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4517 if (ieee80211_sdata_running(sdata))
4518 ieee80211_restart_sta_timer(sdata);
4519 }
Johannes Berga1678f82008-09-11 00:01:47 +02004520 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02004521}
Johannes Berg10f644a2009-04-16 13:17:25 +02004522
Johannes Bergf2d9d272012-11-22 14:11:39 +01004523static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4524 struct cfg80211_bss *cbss)
4525{
4526 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4527 const u8 *ht_cap_ie, *vht_cap_ie;
4528 const struct ieee80211_ht_cap *ht_cap;
4529 const struct ieee80211_vht_cap *vht_cap;
4530 u8 chains = 1;
4531
4532 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4533 return chains;
4534
Johannes Berg9caf0362012-11-29 01:25:20 +01004535 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004536 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4537 ht_cap = (void *)(ht_cap_ie + 2);
4538 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4539 /*
4540 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4541 * "Tx Unequal Modulation Supported" fields.
4542 */
4543 }
4544
4545 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4546 return chains;
4547
Johannes Berg9caf0362012-11-29 01:25:20 +01004548 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004549 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4550 u8 nss;
4551 u16 tx_mcs_map;
4552
4553 vht_cap = (void *)(vht_cap_ie + 2);
4554 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4555 for (nss = 8; nss > 0; nss--) {
4556 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4557 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4558 break;
4559 }
4560 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4561 chains = max(chains, nss);
4562 }
4563
4564 return chains;
4565}
4566
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004567static bool
4568ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4569 const struct ieee80211_he_operation *he_op)
4570{
4571 const struct ieee80211_sta_he_cap *sta_he_cap =
4572 ieee80211_get_he_sta_cap(sband);
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004573 u16 ap_min_req_set;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004574 int i;
4575
4576 if (!sta_he_cap || !he_op)
4577 return false;
4578
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004579 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4580
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004581 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4582 for (i = 0; i < 3; i++) {
4583 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4584 &sta_he_cap->he_mcs_nss_supp;
4585 u16 sta_mcs_map_rx =
4586 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4587 u16 sta_mcs_map_tx =
4588 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4589 u8 nss;
4590 bool verified = true;
4591
4592 /*
4593 * For each band there is a maximum of 8 spatial streams
4594 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4595 * of 2 bits per NSS (1-8), with the values defined in enum
4596 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4597 * capabilities aren't less than the AP's minimum requirements
4598 * for this HE BSS per SS.
4599 * It is enough to find one such band that meets the reqs.
4600 */
4601 for (nss = 8; nss > 0; nss--) {
4602 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4603 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4604 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4605
4606 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4607 continue;
4608
4609 /*
4610 * Make sure the HE AP doesn't require MCSs that aren't
4611 * supported by the client
4612 */
4613 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4614 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4615 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4616 verified = false;
4617 break;
4618 }
4619 }
4620
4621 if (verified)
4622 return true;
4623 }
4624
4625 /* If here, STA doesn't meet AP's HE min requirements */
4626 return false;
4627}
4628
Johannes Bergb17166a2012-07-27 11:41:27 +02004629static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4630 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01004631{
4632 struct ieee80211_local *local = sdata->local;
4633 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Peller53b954e2014-07-24 11:20:05 +03004634 const struct ieee80211_ht_cap *ht_cap = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004635 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004636 const struct ieee80211_vht_operation *vht_oper = NULL;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004637 const struct ieee80211_he_operation *he_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004638 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01004639 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004640 int ret;
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004641 u32 i;
4642 bool have_80mhz;
Johannes Berga1cf7752012-03-08 15:02:07 +01004643
Johannes Berg24398e32012-03-28 10:58:36 +02004644 sband = local->hw.wiphy->bands[cbss->channel->band];
4645
Johannes Bergf2d9d272012-11-22 14:11:39 +01004646 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4647 IEEE80211_STA_DISABLE_80P80MHZ |
4648 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02004649
Johannes Berg9caf0362012-11-29 01:25:20 +01004650 rcu_read_lock();
4651
Johannes Bergf2d9d272012-11-22 14:11:39 +01004652 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
4653 sband->ht_cap.ht_supported) {
Eliad Peller53b954e2014-07-24 11:20:05 +03004654 const u8 *ht_oper_ie, *ht_cap_ie;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004655
Johannes Berg9caf0362012-11-29 01:25:20 +01004656 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02004657 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4658 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6effa2013-02-07 23:33:32 +01004659
Eliad Peller53b954e2014-07-24 11:20:05 +03004660 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4661 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4662 ht_cap = (void *)(ht_cap_ie + 2);
4663
4664 if (!ht_cap) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004665 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4666 ht_oper = NULL;
4667 }
Johannes Berg24398e32012-03-28 10:58:36 +02004668 }
4669
Johannes Bergf2d9d272012-11-22 14:11:39 +01004670 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4671 sband->vht_cap.vht_supported) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004672 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004673
Johannes Berg9caf0362012-11-29 01:25:20 +01004674 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4675 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004676 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4677 vht_oper = (void *)(vht_oper_ie + 2);
4678 if (vht_oper && !ht_oper) {
4679 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004680 sdata_info(sdata,
Johannes Bergf2d9d272012-11-22 14:11:39 +01004681 "AP advertised VHT without HT, disabling both\n");
Johannes Bergcb145022013-02-07 20:41:50 +01004682 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4683 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg24398e32012-03-28 10:58:36 +02004684 }
Johannes Berg08e6effa2013-02-07 23:33:32 +01004685
4686 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4687 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4688 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4689 vht_oper = NULL;
4690 }
Johannes Berg24398e32012-03-28 10:58:36 +02004691 }
4692
Shaul Triebitz002245e2018-12-15 11:03:19 +02004693 if (!ieee80211_get_he_sta_cap(sband))
4694 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4695
4696 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004697 const struct cfg80211_bss_ies *ies;
4698 const u8 *he_oper_ie;
4699
4700 ies = rcu_dereference(cbss->ies);
4701 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
4702 ies->data, ies->len);
4703 if (he_oper_ie &&
4704 he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
4705 he_oper = (void *)(he_oper_ie + 3);
4706 else
4707 he_oper = NULL;
4708
Johannes Bergf0c04072018-06-29 09:51:39 +02004709 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004710 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4711 }
4712
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004713 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4714 have_80mhz = false;
4715 for (i = 0; i < sband->n_channels; i++) {
4716 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4717 IEEE80211_CHAN_NO_80MHZ))
4718 continue;
4719
4720 have_80mhz = true;
4721 break;
4722 }
4723
4724 if (!have_80mhz)
4725 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4726
Johannes Bergf2d9d272012-11-22 14:11:39 +01004727 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4728 cbss->channel,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004729 ht_oper, vht_oper, he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +02004730 &chandef, false);
Johannes Berg04ecd252012-09-11 14:34:12 +02004731
Johannes Bergf2d9d272012-11-22 14:11:39 +01004732 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4733 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02004734
Johannes Berg9caf0362012-11-29 01:25:20 +01004735 rcu_read_unlock();
4736
Johannes Berg04ecd252012-09-11 14:34:12 +02004737 /* will change later if needed */
4738 sdata->smps_mode = IEEE80211_SMPS_OFF;
4739
Johannes Berg34a37402013-12-18 09:43:33 +01004740 mutex_lock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004741 /*
4742 * If this fails (possibly due to channel context sharing
4743 * on incompatible channels, e.g. 80+80 and 160 sharing the
4744 * same control channel) try to use a smaller bandwidth.
4745 */
4746 ret = ieee80211_vif_use_channel(sdata, &chandef,
4747 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich0418a442013-05-16 13:00:31 +02004748
4749 /* don't downgrade for 5 and 10 MHz channels, though. */
4750 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4751 chandef.width == NL80211_CHAN_WIDTH_10)
Johannes Berg34a37402013-12-18 09:43:33 +01004752 goto out;
Simon Wunderlich0418a442013-05-16 13:00:31 +02004753
Johannes Bergd601cd82013-02-07 20:54:51 +01004754 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02004755 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01004756 ret = ieee80211_vif_use_channel(sdata, &chandef,
4757 IEEE80211_CHANCTX_SHARED);
4758 }
Johannes Berg34a37402013-12-18 09:43:33 +01004759 out:
4760 mutex_unlock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004761 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02004762}
4763
4764static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004765 struct cfg80211_bss *cbss, bool assoc,
4766 bool override)
Johannes Bergb17166a2012-07-27 11:41:27 +02004767{
4768 struct ieee80211_local *local = sdata->local;
4769 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4770 struct ieee80211_bss *bss = (void *)cbss->priv;
4771 struct sta_info *new_sta = NULL;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004772 struct ieee80211_supported_band *sband;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004773 bool have_sta = false;
Johannes Bergb17166a2012-07-27 11:41:27 +02004774 int err;
4775
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004776 sband = local->hw.wiphy->bands[cbss->channel->band];
4777
Johannes Bergb17166a2012-07-27 11:41:27 +02004778 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4779 return -EINVAL;
4780
Luca Coelhof8860ce2017-05-02 17:56:21 +03004781 /* If a reconfig is happening, bail out */
4782 if (local->in_reconfig)
4783 return -EBUSY;
4784
Johannes Bergb17166a2012-07-27 11:41:27 +02004785 if (assoc) {
4786 rcu_read_lock();
4787 have_sta = sta_info_get(sdata, cbss->bssid);
4788 rcu_read_unlock();
4789 }
4790
4791 if (!have_sta) {
4792 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4793 if (!new_sta)
4794 return -ENOMEM;
4795 }
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004796
Johannes Bergc87905b2017-06-10 13:52:43 +03004797 /*
4798 * Set up the information for the new channel before setting the
4799 * new channel. We can't - completely race-free - change the basic
4800 * rates bitmap and the channel (sband) that it refers to, but if
4801 * we set it up before we at least avoid calling into the driver's
4802 * bss_info_changed() method with invalid information (since we do
4803 * call that from changing the channel - only for IDLE and perhaps
4804 * some others, but ...).
4805 *
4806 * So to avoid that, just set up all the new information before the
4807 * channel, but tell the driver to apply it only afterwards, since
4808 * it might need the new channel for that.
4809 */
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004810 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004811 u32 rates = 0, basic_rates = 0;
4812 bool have_higher_than_11mbit;
4813 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004814 const struct cfg80211_bss_ies *ies;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004815 int shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004816
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004817 ieee80211_get_rates(sband, bss->supp_rates,
4818 bss->supp_rates_len,
4819 &rates, &basic_rates,
4820 &have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02004821 &min_rate, &min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03004822 shift);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004823
4824 /*
4825 * This used to be a workaround for basic rates missing
4826 * in the association response frame. Now that we no
4827 * longer use the basic rates from there, it probably
4828 * doesn't happen any more, but keep the workaround so
4829 * in case some *other* APs are buggy in different ways
4830 * we can connect -- with a warning.
4831 */
4832 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004833 sdata_info(sdata,
4834 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004835 basic_rates = BIT(min_rate_index);
4836 }
4837
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004838 new_sta->sta.supp_rates[cbss->channel->band] = rates;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004839 sdata->vif.bss_conf.basic_rates = basic_rates;
4840
4841 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg57fbcce2016-04-12 15:56:15 +02004842 if (cbss->channel->band == NL80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004843 have_higher_than_11mbit)
4844 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
4845 else
4846 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
4847
4848 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
4849
Johannes Berg8c358bc2012-05-22 22:13:05 +02004850 /* set timing information */
4851 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004852 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01004853 ies = rcu_dereference(cbss->beacon_ies);
4854 if (ies) {
4855 const u8 *tim_ie;
4856
4857 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4858 sdata->vif.bss_conf.sync_device_ts =
4859 bss->device_ts_beacon;
4860 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4861 ies->data, ies->len);
4862 if (tim_ie && tim_ie[1] >= 2)
4863 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
4864 else
4865 sdata->vif.bss_conf.sync_dtim_count = 0;
Johannes Berg30686bf2015-06-02 21:39:54 +02004866 } else if (!ieee80211_hw_check(&sdata->local->hw,
4867 TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01004868 ies = rcu_dereference(cbss->proberesp_ies);
4869 /* must be non-NULL since beacon IEs were NULL */
4870 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4871 sdata->vif.bss_conf.sync_device_ts =
4872 bss->device_ts_presp;
4873 sdata->vif.bss_conf.sync_dtim_count = 0;
4874 } else {
4875 sdata->vif.bss_conf.sync_tsf = 0;
4876 sdata->vif.bss_conf.sync_device_ts = 0;
4877 sdata->vif.bss_conf.sync_dtim_count = 0;
4878 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01004879 rcu_read_unlock();
Johannes Bergc87905b2017-06-10 13:52:43 +03004880 }
Johannes Berg8c358bc2012-05-22 22:13:05 +02004881
Johannes Bergc87905b2017-06-10 13:52:43 +03004882 if (new_sta || override) {
4883 err = ieee80211_prep_channel(sdata, cbss);
4884 if (err) {
4885 if (new_sta)
4886 sta_info_free(local, new_sta);
4887 return -EINVAL;
4888 }
4889 }
4890
4891 if (new_sta) {
4892 /*
4893 * tell driver about BSSID, basic rates and timing
4894 * this was set up above, before setting the channel
4895 */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004896 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02004897 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
4898 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01004899
4900 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004901 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01004902
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004903 err = sta_info_insert(new_sta);
4904 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01004905 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004906 sdata_info(sdata,
4907 "failed to insert STA entry for the AP (error %d)\n",
4908 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01004909 return err;
4910 }
4911 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00004912 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01004913
David Spinadel7d830a12015-03-17 19:58:38 +02004914 /* Cancel scan to ensure that nothing interferes with connection */
4915 if (local->scanning)
4916 ieee80211_scan_cancel(local);
4917
Johannes Berga1cf7752012-03-08 15:02:07 +01004918 return 0;
4919}
4920
Johannes Berg77fdaa12009-07-07 03:45:17 +02004921/* config hooks */
4922int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
4923 struct cfg80211_auth_request *req)
4924{
Johannes Berg66e67e42012-01-20 13:55:27 +01004925 struct ieee80211_local *local = sdata->local;
4926 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4927 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004928 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01004929 int err;
Jouni Malinenefb543e2018-10-11 00:21:21 +03004930 bool cont_auth;
Johannes Berg66e67e42012-01-20 13:55:27 +01004931
4932 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02004933
4934 switch (req->auth_type) {
4935 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4936 auth_alg = WLAN_AUTH_OPEN;
4937 break;
4938 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01004939 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02004940 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004941 auth_alg = WLAN_AUTH_SHARED_KEY;
4942 break;
4943 case NL80211_AUTHTYPE_FT:
4944 auth_alg = WLAN_AUTH_FT;
4945 break;
4946 case NL80211_AUTHTYPE_NETWORK_EAP:
4947 auth_alg = WLAN_AUTH_LEAP;
4948 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004949 case NL80211_AUTHTYPE_SAE:
4950 auth_alg = WLAN_AUTH_SAE;
4951 break;
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03004952 case NL80211_AUTHTYPE_FILS_SK:
4953 auth_alg = WLAN_AUTH_FILS_SK;
4954 break;
4955 case NL80211_AUTHTYPE_FILS_SK_PFS:
4956 auth_alg = WLAN_AUTH_FILS_SK_PFS;
4957 break;
4958 case NL80211_AUTHTYPE_FILS_PK:
4959 auth_alg = WLAN_AUTH_FILS_PK;
4960 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004961 default:
4962 return -EOPNOTSUPP;
4963 }
4964
Jouni Malinenefb543e2018-10-11 00:21:21 +03004965 if (ifmgd->assoc_data)
Jouni Malinen8d7432a2018-10-11 00:21:20 +03004966 return -EBUSY;
4967
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004968 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004969 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01004970 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004971 return -ENOMEM;
4972
Johannes Berg66e67e42012-01-20 13:55:27 +01004973 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004974
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004975 if (req->auth_data_len >= 4) {
Jouni Malinen6ec63612016-10-27 00:41:59 +03004976 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
4977 __le16 *pos = (__le16 *) req->auth_data;
4978
4979 auth_data->sae_trans = le16_to_cpu(pos[0]);
4980 auth_data->sae_status = le16_to_cpu(pos[1]);
4981 }
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004982 memcpy(auth_data->data, req->auth_data + 4,
4983 req->auth_data_len - 4);
4984 auth_data->data_len += req->auth_data_len - 4;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004985 }
4986
Jouni Malinenefb543e2018-10-11 00:21:21 +03004987 /* Check if continuing authentication or trying to authenticate with the
4988 * same BSS that we were in the process of authenticating with and avoid
4989 * removal and re-addition of the STA entry in
4990 * ieee80211_prep_connection().
4991 */
4992 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
4993
Johannes Berg77fdaa12009-07-07 03:45:17 +02004994 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004995 memcpy(&auth_data->data[auth_data->data_len],
4996 req->ie, req->ie_len);
4997 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004998 }
4999
Johannes Bergfffd0932009-07-08 14:22:54 +02005000 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005001 auth_data->key_len = req->key_len;
5002 auth_data->key_idx = req->key_idx;
5003 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02005004 }
5005
Johannes Berg66e67e42012-01-20 13:55:27 +01005006 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005007
Johannes Berg66e67e42012-01-20 13:55:27 +01005008 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01005009
Jouni Malinenefb543e2018-10-11 00:21:21 +03005010 if (ifmgd->auth_data) {
5011 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5012 auth_data->peer_confirmed =
5013 ifmgd->auth_data->peer_confirmed;
5014 }
5015 ieee80211_destroy_auth_data(sdata, cont_auth);
5016 }
Guy Eilam2a33bee2011-08-17 15:18:15 +03005017
Johannes Berg66e67e42012-01-20 13:55:27 +01005018 /* prep auth_data so we don't go into idle on disassoc */
5019 ifmgd->auth_data = auth_data;
5020
Jouni Malinenefb543e2018-10-11 00:21:21 +03005021 /* If this is continuation of an ongoing SAE authentication exchange
5022 * (i.e., request to send SAE Confirm) and the peer has already
5023 * confirmed, mark authentication completed since we are about to send
5024 * out SAE Confirm.
5025 */
5026 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5027 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5028 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5029
Johannes Berg7b119dc2013-04-10 21:38:36 +02005030 if (ifmgd->associated) {
5031 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5032
Johannes Berg89f774e2016-01-25 15:46:36 +02005033 sdata_info(sdata,
5034 "disconnect from AP %pM for new auth to %pM\n",
5035 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005036 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5037 WLAN_REASON_UNSPECIFIED,
5038 false, frame_buf);
5039
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005040 ieee80211_report_disconnect(sdata, frame_buf,
5041 sizeof(frame_buf), true,
5042 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005043 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005044
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005045 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005046
Jouni Malinenefb543e2018-10-11 00:21:21 +03005047 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
Johannes Berga1cf7752012-03-08 15:02:07 +01005048 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01005049 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005050
Johannes Berg46cad4b2015-08-15 22:39:54 +03005051 err = ieee80211_auth(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01005052 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005053 sta_info_destroy_addr(sdata, req->bss->bssid);
5054 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005055 }
5056
Johannes Berg66e67e42012-01-20 13:55:27 +01005057 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01005058 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005059 return 0;
Johannes Berge5b900d2010-07-29 16:08:55 +02005060
Johannes Berg66e67e42012-01-20 13:55:27 +01005061 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005062 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005063 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005064 ifmgd->auth_data = NULL;
Michal Kaziord01f8582015-06-03 08:36:13 +02005065 mutex_lock(&sdata->local->mtx);
5066 ieee80211_vif_release_channel(sdata);
5067 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01005068 kfree(auth_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005069 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005070}
5071
Johannes Berg77fdaa12009-07-07 03:45:17 +02005072int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5073 struct cfg80211_assoc_request *req)
5074{
Johannes Berg66e67e42012-01-20 13:55:27 +01005075 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005076 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01005077 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01005078 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005079 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005080 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005081 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005082 int i, err;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005083 bool override = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005084
Johannes Berg66e67e42012-01-20 13:55:27 +01005085 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5086 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01005087 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005088
Johannes Berg9caf0362012-11-29 01:25:20 +01005089 rcu_read_lock();
5090 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
5091 if (!ssidie) {
5092 rcu_read_unlock();
5093 kfree(assoc_data);
5094 return -EINVAL;
5095 }
5096 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5097 assoc_data->ssid_len = ssidie[1];
5098 rcu_read_unlock();
5099
Johannes Berg7b119dc2013-04-10 21:38:36 +02005100 if (ifmgd->associated) {
5101 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5102
Johannes Berg89f774e2016-01-25 15:46:36 +02005103 sdata_info(sdata,
5104 "disconnect from AP %pM for new assoc to %pM\n",
5105 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005106 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5107 WLAN_REASON_UNSPECIFIED,
5108 false, frame_buf);
5109
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005110 ieee80211_report_disconnect(sdata, frame_buf,
5111 sizeof(frame_buf), true,
5112 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005113 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005114
5115 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5116 err = -EBUSY;
5117 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005118 }
5119
Johannes Berg66e67e42012-01-20 13:55:27 +01005120 if (ifmgd->assoc_data) {
5121 err = -EBUSY;
5122 goto err_free;
5123 }
5124
5125 if (ifmgd->auth_data) {
5126 bool match;
5127
5128 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00005129 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005130 ieee80211_destroy_auth_data(sdata, match);
5131 }
5132
5133 /* prepare assoc data */
Johannes Berg095d81c2013-10-15 12:25:07 +02005134
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03005135 ifmgd->beacon_crc_valid = false;
5136
Johannes Berg095d81c2013-10-15 12:25:07 +02005137 assoc_data->wmm = bss->wmm_used &&
5138 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg095d81c2013-10-15 12:25:07 +02005139
Johannes Bergde5036a2012-03-08 15:02:03 +01005140 /*
5141 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5142 * We still associate in non-HT mode (11a/b/g) if any one of these
5143 * ciphers is configured as pairwise.
5144 * We can set this to true for non-11n hardware, that'll be checked
5145 * separately along with the peer capabilities.
5146 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02005147 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02005148 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5149 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02005150 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01005151 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005152 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005153 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Johannes Berg1c4cb922012-05-30 15:57:00 +02005154 netdev_info(sdata->dev,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005155 "disabling HE/HT/VHT due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005156 }
5157 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005158
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005159 /* Also disable HT if we don't support it or the AP doesn't use WMM */
5160 sband = local->hw.wiphy->bands[req->bss->channel->band];
5161 if (!sband->ht_cap.ht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005162 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5163 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Berga8243b72012-11-22 14:32:09 +01005164 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005165 if (!bss->wmm_used &&
5166 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005167 netdev_info(sdata->dev,
5168 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005169 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005170
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005171 /* disable VHT if we don't support it or the AP doesn't use WMM */
5172 if (!sband->vht_cap.vht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005173 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5174 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005175 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005176 if (!bss->wmm_used &&
5177 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005178 netdev_info(sdata->dev,
5179 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005180 }
5181
Ben Greearef96a8422011-11-18 11:32:00 -08005182 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5183 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5184 sizeof(ifmgd->ht_capa_mask));
5185
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01005186 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5187 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5188 sizeof(ifmgd->vht_capa_mask));
5189
Johannes Berg77fdaa12009-07-07 03:45:17 +02005190 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005191 memcpy(assoc_data->ie, req->ie, req->ie_len);
5192 assoc_data->ie_len = req->ie_len;
5193 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005194
Jouni Malinen39404fe2016-10-27 00:42:05 +03005195 if (req->fils_kek) {
5196 /* should already be checked in cfg80211 - so warn */
5197 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5198 err = -EINVAL;
5199 goto err_free;
5200 }
5201 memcpy(assoc_data->fils_kek, req->fils_kek,
5202 req->fils_kek_len);
5203 assoc_data->fils_kek_len = req->fils_kek_len;
5204 }
5205
5206 if (req->fils_nonces)
5207 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5208 2 * FILS_NONCE_LEN);
5209
Johannes Berg66e67e42012-01-20 13:55:27 +01005210 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01005211
Johannes Bergaf6b6372009-12-23 13:15:35 +01005212 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5213 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02005214 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005215 else
Johannes Berg04ecd252012-09-11 14:34:12 +02005216 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005217 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02005218 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005219
Johannes Berg66e67e42012-01-20 13:55:27 +01005220 assoc_data->capability = req->bss->capability;
Johannes Berg66e67e42012-01-20 13:55:27 +01005221 assoc_data->supp_rates = bss->supp_rates;
5222 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02005223
Johannes Berg9caf0362012-11-29 01:25:20 +01005224 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02005225 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5226 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5227 assoc_data->ap_ht_param =
5228 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5229 else
Johannes Berga8243b72012-11-22 14:32:09 +01005230 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005231 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5232 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5233 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5234 sizeof(struct ieee80211_vht_cap));
5235 else
5236 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01005237 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01005238
Johannes Berg848955c2014-11-11 12:48:42 +01005239 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02005240 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
Johannes Berg848955c2014-11-11 12:48:42 +01005241 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5242 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5243
Kalle Valoab133152010-01-12 10:42:31 +02005244 if (bss->wmm_used && bss->uapsd_supported &&
Johannes Berg848955c2014-11-11 12:48:42 +01005245 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01005246 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02005247 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5248 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01005249 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02005250 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5251 }
5252
Johannes Berg77fdaa12009-07-07 03:45:17 +02005253 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01005254 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005255
5256 if (req->use_mfp) {
5257 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5258 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5259 } else {
5260 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5261 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5262 }
5263
Assaf Krausscd2f5dd2014-09-03 15:25:02 +03005264 if (req->flags & ASSOC_REQ_USE_RRM)
5265 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5266 else
5267 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5268
Johannes Berg77fdaa12009-07-07 03:45:17 +02005269 if (req->crypto.control_port)
5270 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5271 else
5272 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5273
Johannes Berga621fa42010-08-27 14:26:54 +03005274 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5275 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05005276 sdata->control_port_over_nl80211 =
5277 req->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02005278 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5279 sdata->vif.type);
Johannes Berga621fa42010-08-27 14:26:54 +03005280
Johannes Berg66e67e42012-01-20 13:55:27 +01005281 /* kick off associate process */
5282
5283 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02005284 ifmgd->dtim_period = 0;
Alexander Bondar989c6502013-05-16 17:34:17 +03005285 ifmgd->have_beacon = false;
Johannes Berg66e67e42012-01-20 13:55:27 +01005286
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005287 /* override HT/VHT configuration only if the AP and we support it */
5288 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5289 struct ieee80211_sta_ht_cap sta_ht_cap;
5290
5291 if (req->flags & ASSOC_REQ_DISABLE_HT)
5292 override = true;
5293
5294 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5295 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5296
5297 /* check for 40 MHz disable override */
5298 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5299 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5300 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5301 override = true;
5302
5303 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5304 req->flags & ASSOC_REQ_DISABLE_VHT)
5305 override = true;
5306 }
5307
5308 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5309 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5310 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5311 }
5312
5313 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5314 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5315
5316 err = ieee80211_prep_connection(sdata, req->bss, true, override);
Johannes Berga1cf7752012-03-08 15:02:07 +01005317 if (err)
5318 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01005319
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005320 rcu_read_lock();
5321 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02005322
Johannes Berg30686bf2015-06-02 21:39:54 +02005323 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005324 !beacon_ies) {
5325 /*
5326 * Wait up to one beacon interval ...
5327 * should this be more if we miss one?
5328 */
5329 sdata_info(sdata, "waiting for beacon from %pM\n",
5330 ifmgd->bssid);
5331 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01005332 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005333 assoc_data->need_beacon = true;
5334 } else if (beacon_ies) {
5335 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
5336 beacon_ies->data,
5337 beacon_ies->len);
Johannes Bergef429da2013-02-05 17:48:40 +01005338 u8 dtim_count = 0;
5339
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005340 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
5341 const struct ieee80211_tim_ie *tim;
5342 tim = (void *)(tim_ie + 2);
5343 ifmgd->dtim_period = tim->dtim_period;
Johannes Bergef429da2013-02-05 17:48:40 +01005344 dtim_count = tim->dtim_count;
Johannes Berg826262c2012-12-10 16:38:14 +02005345 }
Alexander Bondar989c6502013-05-16 17:34:17 +03005346 ifmgd->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005347 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005348 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01005349
Johannes Berg30686bf2015-06-02 21:39:54 +02005350 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005351 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5352 sdata->vif.bss_conf.sync_device_ts =
5353 bss->device_ts_beacon;
5354 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5355 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005356 } else {
5357 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005358 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005359 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005360 rcu_read_unlock();
5361
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005362 run_again(sdata, assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01005363
Paul Stewartfcff4f12012-02-23 17:59:53 -08005364 if (bss->corrupt_data) {
5365 char *corrupt_type = "data";
5366 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5367 if (bss->corrupt_data &
5368 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5369 corrupt_type = "beacon and probe response";
5370 else
5371 corrupt_type = "beacon";
5372 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5373 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005374 sdata_info(sdata, "associating with AP with corrupt %s\n",
5375 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08005376 }
5377
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005378 return 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01005379 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005380 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005381 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005382 ifmgd->assoc_data = NULL;
5383 err_free:
5384 kfree(assoc_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005385 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005386}
5387
5388int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005389 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005390{
5391 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005392 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005393 bool tx = !req->local_state_change;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005394
Johannes Bergc9c3a062014-03-19 09:11:19 +01005395 if (ifmgd->auth_data &&
5396 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5397 sdata_info(sdata,
5398 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5399 req->bssid, req->reason_code,
5400 ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005401
Ilan Peerd4e36e52018-04-20 13:49:25 +03005402 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg37ad3882012-02-24 13:50:54 +01005403 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5404 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005405 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01005406 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01005407 ieee80211_destroy_auth_data(sdata, false);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005408 ieee80211_report_disconnect(sdata, frame_buf,
5409 sizeof(frame_buf), true,
5410 req->reason_code);
Johannes Berg86552012012-10-29 09:46:31 +01005411
Johannes Bergc9c3a062014-03-19 09:11:19 +01005412 return 0;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03005413 }
5414
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005415 if (ifmgd->assoc_data &&
5416 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5417 sdata_info(sdata,
5418 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5419 req->bssid, req->reason_code,
5420 ieee80211_get_reason_code_string(req->reason_code));
5421
Ilan Peerd4e36e52018-04-20 13:49:25 +03005422 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005423 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5424 IEEE80211_STYPE_DEAUTH,
5425 req->reason_code, tx,
5426 frame_buf);
Johannes Berge6f462d2016-12-08 17:22:09 +01005427 ieee80211_destroy_assoc_data(sdata, false, true);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005428 ieee80211_report_disconnect(sdata, frame_buf,
5429 sizeof(frame_buf), true,
5430 req->reason_code);
5431 return 0;
5432 }
5433
Johannes Berg86552012012-10-29 09:46:31 +01005434 if (ifmgd->associated &&
5435 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
Johannes Bergc9c3a062014-03-19 09:11:19 +01005436 sdata_info(sdata,
5437 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5438 req->bssid, req->reason_code,
5439 ieee80211_get_reason_code_string(req->reason_code));
5440
Johannes Berg86552012012-10-29 09:46:31 +01005441 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5442 req->reason_code, tx, frame_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005443 ieee80211_report_disconnect(sdata, frame_buf,
5444 sizeof(frame_buf), true,
5445 req->reason_code);
Johannes Bergc9c3a062014-03-19 09:11:19 +01005446 return 0;
5447 }
Johannes Berg86552012012-10-29 09:46:31 +01005448
Johannes Bergc9c3a062014-03-19 09:11:19 +01005449 return -ENOTCONN;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005450}
5451
5452int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005453 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005454{
5455 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07005456 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005457 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02005458
Johannes Berg8d8b2612009-07-25 11:58:36 +02005459 /*
5460 * cfg80211 should catch this ... but it's racy since
5461 * we can receive a disassoc frame, process it, hand it
5462 * to cfg80211 while that's in a locked section already
5463 * trying to tell us that the user wants to disconnect.
5464 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005465 if (ifmgd->associated != req->bss)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005466 return -ENOLINK;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005467
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005468 sdata_info(sdata,
Calvin Owensdfa1ad22014-02-11 12:36:24 -06005469 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5470 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005471
Jouni Malinene69e95d2010-03-29 23:29:31 -07005472 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01005473 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5474 req->reason_code, !req->local_state_change,
5475 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005476
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005477 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5478 req->reason_code);
Johannes Bergbc83b682009-11-29 12:19:06 +01005479
Johannes Berg77fdaa12009-07-07 03:45:17 +02005480 return 0;
5481}
Jouni Malinen026331c2010-02-15 12:53:10 +02005482
Eliad Pellerafa762f2012-04-23 14:45:15 +03005483void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005484{
5485 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5486
Ben Greear49921852013-02-20 09:41:09 -08005487 /*
5488 * Make sure some work items will not run after this,
5489 * they will not do anything but might not have been
5490 * cancelled when disconnecting.
5491 */
5492 cancel_work_sync(&ifmgd->monitor_work);
5493 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5494 cancel_work_sync(&ifmgd->request_smps_work);
5495 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5496 cancel_work_sync(&ifmgd->chswitch_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03005497 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
Ben Greear49921852013-02-20 09:41:09 -08005498
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005499 sdata_lock(sdata);
Johannes Berg959867f2013-06-19 13:05:42 +02005500 if (ifmgd->assoc_data) {
5501 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Johannes Berge6f462d2016-12-08 17:22:09 +01005502 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02005503 cfg80211_assoc_timeout(sdata->dev, bss);
5504 }
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005505 if (ifmgd->auth_data)
5506 ieee80211_destroy_auth_data(sdata, false);
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005507 spin_lock_bh(&ifmgd->teardown_lock);
5508 if (ifmgd->teardown_skb) {
5509 kfree_skb(ifmgd->teardown_skb);
5510 ifmgd->teardown_skb = NULL;
5511 ifmgd->orig_teardown_skb = NULL;
5512 }
5513 spin_unlock_bh(&ifmgd->teardown_lock);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005514 del_timer_sync(&ifmgd->timer);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005515 sdata_unlock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005516}
5517
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005518void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5519 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005520 s32 rssi_level,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005521 gfp_t gfp)
5522{
5523 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5524
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005525 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
Johannes Bergb5878a22010-04-07 16:48:40 +02005526
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01005527 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005528}
5529EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
Johannes Berg98f03342014-11-26 12:42:02 +01005530
5531void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5532{
5533 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5534
5535 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5536
5537 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5538}
5539EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);