blob: 1818dbc5622d65872bb67a152d05821e63c3c6b7 [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 Berg60f8b392008-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 Berg60f8b392008-09-08 17:44:22 +0200142{
Johannes Berg5484e232008-09-08 17:44:27 +0200143 return (1 << ecw) - 1;
Johannes Berg60f8b392008-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
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300919 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
920 ieee80211_add_he_ie(sdata, skb, sband);
921
922 /* if present, add any custom non-vendor IEs that go after HE */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200923 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100924 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
925 assoc_data->ie_len,
926 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800927 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100928 offset = noffset;
929 }
930
Johannes Berg76f03032012-03-08 15:02:05 +0100931 if (assoc_data->wmm) {
932 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200933 qos_info = ifmgd->uapsd_queues;
934 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100935 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
936 } else {
937 qos_info = 0;
938 }
939
Arik Nemtsov40b861a2014-07-17 17:14:23 +0300940 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
Johannes Berg66e67e42012-01-20 13:55:27 +0100941 }
942
943 /* add any remaining custom (i.e. vendor specific here) IEs */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200944 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100945 noffset = assoc_data->ie_len;
yuan linyub952f4d2017-06-18 22:52:04 +0800946 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100947 }
948
Jouni Malinen39404fe2016-10-27 00:42:05 +0300949 if (assoc_data->fils_kek_len &&
950 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
951 dev_kfree_skb(skb);
952 return;
953 }
954
Ilan Peerd4e36e52018-04-20 13:49:25 +0300955 drv_mgd_prepare_tx(local, sdata, 0);
Johannes Berga1845fc2012-06-27 13:18:36 +0200956
Johannes Berg66e67e42012-01-20 13:55:27 +0100957 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Johannes Berg30686bf2015-06-02 21:39:54 +0200958 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +0100959 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
960 IEEE80211_TX_INTFL_MLME_CONN_TX;
Johannes Berg66e67e42012-01-20 13:55:27 +0100961 ieee80211_tx_skb(sdata, skb);
962}
963
Kalle Valo572e0012009-02-10 17:09:31 +0200964void ieee80211_send_pspoll(struct ieee80211_local *local,
965 struct ieee80211_sub_if_data *sdata)
966{
Kalle Valo572e0012009-02-10 17:09:31 +0200967 struct ieee80211_pspoll *pspoll;
968 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200969
Kalle Valod8cd1892010-01-05 20:16:26 +0200970 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
971 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200972 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200973
Kalle Valod8cd1892010-01-05 20:16:26 +0200974 pspoll = (struct ieee80211_pspoll *) skb->data;
975 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200976
Johannes Berg62ae67b2009-11-18 18:42:05 +0100977 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
978 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200979}
980
Johannes Berg965beda2009-04-16 13:17:24 +0200981void ieee80211_send_nullfunc(struct ieee80211_local *local,
982 struct ieee80211_sub_if_data *sdata,
Johannes Berg076cdcb2015-09-24 16:14:55 +0200983 bool powersave)
Johannes Berg965beda2009-04-16 13:17:24 +0200984{
985 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200986 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530987 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200988
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300989 /* Don't send NDPs when STA is connected HE */
990 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
991 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
992 return;
993
Ben Caradoc-Davies7c181f42018-03-19 12:57:44 +1300994 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
995 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
Kalle Valod8cd1892010-01-05 20:16:26 +0200996 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200997 return;
998
Kalle Valod8cd1892010-01-05 20:16:26 +0200999 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +02001000 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +02001001 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +02001002
Seth Forshee6c17b772013-02-11 11:21:07 -06001003 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1004 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Pontus Fuchsff40b422013-06-04 12:44:52 +02001005
Johannes Berg30686bf2015-06-02 21:39:54 +02001006 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Pontus Fuchsff40b422013-06-04 12:44:52 +02001007 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1008
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001009 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +05301010 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1011
Johannes Berg62ae67b2009-11-18 18:42:05 +01001012 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +02001013}
1014
Felix Fietkaud5242152010-01-08 18:06:26 +01001015static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1016 struct ieee80211_sub_if_data *sdata)
1017{
1018 struct sk_buff *skb;
1019 struct ieee80211_hdr *nullfunc;
1020 __le16 fc;
1021
1022 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1023 return;
1024
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001025 /* Don't send NDPs when connected HE */
1026 if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE))
1027 return;
1028
Felix Fietkaud5242152010-01-08 18:06:26 +01001029 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -07001030 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +01001031 return;
Joe Perchesd15b8452011-08-29 14:17:31 -07001032
Felix Fietkaud5242152010-01-08 18:06:26 +01001033 skb_reserve(skb, local->hw.extra_tx_headroom);
1034
Johannes Bergb080db52017-06-16 14:29:19 +02001035 nullfunc = skb_put_zero(skb, 30);
Felix Fietkaud5242152010-01-08 18:06:26 +01001036 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1037 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1038 nullfunc->frame_control = fc;
1039 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1040 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1041 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1042 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1043
1044 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1045 ieee80211_tx_skb(sdata, skb);
1046}
1047
Johannes Bergcc32abd2009-05-15 11:52:31 +02001048/* spectrum management related things */
1049static void ieee80211_chswitch_work(struct work_struct *work)
1050{
1051 struct ieee80211_sub_if_data *sdata =
1052 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Karl Beldan675a0b02013-03-25 16:26:57 +01001053 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001054 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001055 int ret;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001056
Johannes Berg9607e6b662009-12-23 13:15:31 +01001057 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +02001058 return;
1059
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001060 sdata_lock(sdata);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001061 mutex_lock(&local->mtx);
1062 mutex_lock(&local->chanctx_mtx);
1063
Johannes Berg77fdaa12009-07-07 03:45:17 +02001064 if (!ifmgd->associated)
1065 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001066
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001067 if (!sdata->vif.csa_active)
1068 goto out;
1069
1070 /*
1071 * using reservation isn't immediate as it may be deferred until later
1072 * with multi-vif. once reservation is complete it will re-schedule the
1073 * work with no reserved_chanctx so verify chandef to check if it
1074 * completed successfully
1075 */
1076
1077 if (sdata->reserved_chanctx) {
Ilan Peer0007e942018-08-31 11:31:10 +03001078 struct ieee80211_supported_band *sband = NULL;
1079 struct sta_info *mgd_sta = NULL;
1080 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
1081
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001082 /*
1083 * with multi-vif csa driver may call ieee80211_csa_finish()
1084 * many times while waiting for other interfaces to use their
1085 * reservations
1086 */
1087 if (sdata->reserved_ready)
1088 goto out;
1089
Ilan Peer0007e942018-08-31 11:31:10 +03001090 if (sdata->vif.bss_conf.chandef.width !=
1091 sdata->csa_chandef.width) {
1092 /*
1093 * For managed interface, we need to also update the AP
1094 * station bandwidth and align the rate scale algorithm
1095 * on the bandwidth change. Here we only consider the
1096 * bandwidth of the new channel definition (as channel
1097 * switch flow does not have the full HT/VHT/HE
1098 * information), assuming that if additional changes are
1099 * required they would be done as part of the processing
1100 * of the next beacon from the AP.
1101 */
1102 switch (sdata->csa_chandef.width) {
1103 case NL80211_CHAN_WIDTH_20_NOHT:
1104 case NL80211_CHAN_WIDTH_20:
1105 default:
1106 bw = IEEE80211_STA_RX_BW_20;
1107 break;
1108 case NL80211_CHAN_WIDTH_40:
1109 bw = IEEE80211_STA_RX_BW_40;
1110 break;
1111 case NL80211_CHAN_WIDTH_80:
1112 bw = IEEE80211_STA_RX_BW_80;
1113 break;
1114 case NL80211_CHAN_WIDTH_80P80:
1115 case NL80211_CHAN_WIDTH_160:
1116 bw = IEEE80211_STA_RX_BW_160;
1117 break;
1118 }
1119
1120 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1121 sband =
1122 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1123 }
1124
1125 if (sdata->vif.bss_conf.chandef.width >
1126 sdata->csa_chandef.width) {
1127 mgd_sta->sta.bandwidth = bw;
1128 rate_control_rate_update(local, sband, mgd_sta,
1129 IEEE80211_RC_BW_CHANGED);
1130 }
1131
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001132 ret = ieee80211_vif_use_reserved_context(sdata);
1133 if (ret) {
1134 sdata_info(sdata,
1135 "failed to use reserved channel context, disconnecting (err=%d)\n",
1136 ret);
1137 ieee80211_queue_work(&sdata->local->hw,
1138 &ifmgd->csa_connection_drop_work);
1139 goto out;
1140 }
1141
Ilan Peer0007e942018-08-31 11:31:10 +03001142 if (sdata->vif.bss_conf.chandef.width <
1143 sdata->csa_chandef.width) {
1144 mgd_sta->sta.bandwidth = bw;
1145 rate_control_rate_update(local, sband, mgd_sta,
1146 IEEE80211_RC_BW_CHANGED);
1147 }
1148
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001149 goto out;
1150 }
1151
1152 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1153 &sdata->csa_chandef)) {
Arik Nemtsov7578d572013-09-01 17:15:51 +03001154 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001155 "failed to finalize channel switch, disconnecting\n");
Arik Nemtsov7578d572013-09-01 17:15:51 +03001156 ieee80211_queue_work(&sdata->local->hw,
1157 &ifmgd->csa_connection_drop_work);
1158 goto out;
1159 }
Karl Beldan675a0b02013-03-25 16:26:57 +01001160
Johannes Berg77fdaa12009-07-07 03:45:17 +02001161 /* XXX: shouldn't really modify cfg80211-owned data! */
Luciano Coelho33787fc2013-11-11 20:34:54 +02001162 ifmgd->associated->channel = sdata->csa_chandef.chan;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001163
Luciano Coelho0c21e632014-10-08 09:48:39 +03001164 ifmgd->csa_waiting_bcn = true;
Luciano Coelhof1d65582014-10-08 09:48:38 +03001165
Michal Kaziore5593f52014-04-09 15:45:36 +02001166 ieee80211_sta_reset_beacon_monitor(sdata);
1167 ieee80211_sta_reset_conn_monitor(sdata);
1168
Michal Kazior59af6922014-04-09 15:10:59 +02001169out:
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001170 mutex_unlock(&local->chanctx_mtx);
1171 mutex_unlock(&local->mtx);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001172 sdata_unlock(sdata);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001173}
1174
Luciano Coelho0c21e632014-10-08 09:48:39 +03001175static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1176{
1177 struct ieee80211_local *local = sdata->local;
1178 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1179 int ret;
1180
1181 sdata_assert_lock(sdata);
1182
1183 WARN_ON(!sdata->vif.csa_active);
1184
1185 if (sdata->csa_block_tx) {
1186 ieee80211_wake_vif_queues(local, sdata,
1187 IEEE80211_QUEUE_STOP_REASON_CSA);
1188 sdata->csa_block_tx = false;
1189 }
1190
1191 sdata->vif.csa_active = false;
1192 ifmgd->csa_waiting_bcn = false;
1193
1194 ret = drv_post_channel_switch(sdata);
1195 if (ret) {
1196 sdata_info(sdata,
1197 "driver post channel switch failed, disconnecting\n");
1198 ieee80211_queue_work(&local->hw,
1199 &ifmgd->csa_connection_drop_work);
1200 return;
1201 }
Luciano Coelho688b1ec2014-12-16 16:01:39 +02001202
1203 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
Luciano Coelho0c21e632014-10-08 09:48:39 +03001204}
1205
Johannes Berg5ce6e432010-05-11 16:20:57 +02001206void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1207{
Johannes Berg55de9082012-07-26 17:24:39 +02001208 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1209 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001210
1211 trace_api_chswitch_done(sdata, success);
1212 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001213 sdata_info(sdata,
1214 "driver channel switch failed, disconnecting\n");
1215 ieee80211_queue_work(&sdata->local->hw,
1216 &ifmgd->csa_connection_drop_work);
1217 } else {
1218 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001219 }
Johannes Berg5ce6e432010-05-11 16:20:57 +02001220}
1221EXPORT_SYMBOL(ieee80211_chswitch_done);
1222
Kees Cook34f11cd2017-10-16 16:35:49 -07001223static void ieee80211_chswitch_timer(struct timer_list *t)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001224{
1225 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07001226 from_timer(sdata, t, u.mgd.chswitch_timer);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001227
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01001228 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001229}
1230
Johannes Berg37799e52013-03-26 14:02:26 +01001231static void
Johannes Berg4a3cb702013-02-12 16:43:19 +01001232ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03001233 u64 timestamp, u32 device_timestamp,
1234 struct ieee802_11_elems *elems,
Johannes Berg04a161f2013-05-03 09:35:35 +02001235 bool beacon)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001236{
Johannes Bergb4f286a12013-03-26 14:13:58 +01001237 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001238 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg37799e52013-03-26 14:02:26 +01001239 struct cfg80211_bss *cbss = ifmgd->associated;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001240 struct ieee80211_chanctx_conf *conf;
Johannes Berg55de9082012-07-26 17:24:39 +02001241 struct ieee80211_chanctx *chanctx;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001242 enum nl80211_band current_band;
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001243 struct ieee80211_csa_ie csa_ie;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001244 struct ieee80211_channel_switch ch_switch;
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001245 int res;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001246
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001247 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001248
Johannes Berg37799e52013-03-26 14:02:26 +01001249 if (!cbss)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001250 return;
1251
Johannes Bergb4f286a12013-03-26 14:13:58 +01001252 if (local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001253 return;
1254
Johannes Berg37799e52013-03-26 14:02:26 +01001255 /* disregard subsequent announcements if we are already processing */
Luciano Coelho3e2a0222014-07-05 11:43:01 +03001256 if (sdata->vif.csa_active)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001257 return;
1258
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001259 current_band = cbss->channel->band;
Luciano Coelho84469a42014-10-28 13:33:04 +02001260 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001261 ifmgd->flags,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001262 ifmgd->associated->bssid, &csa_ie);
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001263 if (res < 0)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001264 ieee80211_queue_work(&local->hw,
Johannes Berg882a7c62012-08-01 22:32:45 +02001265 &ifmgd->csa_connection_drop_work);
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001266 if (res)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001267 return;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001268
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001269 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
Johannes Berg85220d72013-03-25 18:29:27 +01001270 IEEE80211_CHAN_DISABLED)) {
1271 sdata_info(sdata,
1272 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001273 ifmgd->associated->bssid,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001274 csa_ie.chandef.chan->center_freq,
1275 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1276 csa_ie.chandef.center_freq2);
Johannes Berg85220d72013-03-25 18:29:27 +01001277 ieee80211_queue_work(&local->hw,
1278 &ifmgd->csa_connection_drop_work);
1279 return;
1280 }
1281
Johannes Bergf84eaa12015-03-12 08:53:26 +02001282 if (cfg80211_chandef_identical(&csa_ie.chandef,
1283 &sdata->vif.bss_conf.chandef)) {
1284 if (ifmgd->csa_ignored_same_chan)
1285 return;
1286 sdata_info(sdata,
1287 "AP %pM tries to chanswitch to same channel, ignore\n",
1288 ifmgd->associated->bssid);
1289 ifmgd->csa_ignored_same_chan = true;
1290 return;
1291 }
1292
Arik Nemtsovc5a71682015-05-19 14:36:48 +03001293 /*
1294 * Drop all TDLS peers - either we disconnect or move to a different
1295 * channel from this point on. There's no telling what our peer will do.
1296 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1297 * have an incompatible wider chandef.
1298 */
1299 ieee80211_teardown_tdls_peers(sdata);
1300
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001301 mutex_lock(&local->mtx);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001302 mutex_lock(&local->chanctx_mtx);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001303 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1304 lockdep_is_held(&local->chanctx_mtx));
1305 if (!conf) {
1306 sdata_info(sdata,
1307 "no channel context assigned to vif?, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001308 goto drop_connection;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001309 }
1310
1311 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1312
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001313 if (local->use_chanctx &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001314 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001315 sdata_info(sdata,
1316 "driver doesn't support chan-switch with channel contexts\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001317 goto drop_connection;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001318 }
1319
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001320 ch_switch.timestamp = timestamp;
1321 ch_switch.device_timestamp = device_timestamp;
1322 ch_switch.block_tx = csa_ie.mode;
1323 ch_switch.chandef = csa_ie.chandef;
1324 ch_switch.count = csa_ie.count;
1325
1326 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1327 sdata_info(sdata,
1328 "preparing for channel switch failed, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001329 goto drop_connection;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001330 }
1331
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001332 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1333 chanctx->mode, false);
1334 if (res) {
Johannes Berg55de9082012-07-26 17:24:39 +02001335 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001336 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1337 res);
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001338 goto drop_connection;
Johannes Berg55de9082012-07-26 17:24:39 +02001339 }
Johannes Bergb4f286a12013-03-26 14:13:58 +01001340 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001341
Michal Kazior59af6922014-04-09 15:10:59 +02001342 sdata->vif.csa_active = true;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001343 sdata->csa_chandef = csa_ie.chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02001344 sdata->csa_block_tx = csa_ie.mode;
Johannes Bergf84eaa12015-03-12 08:53:26 +02001345 ifmgd->csa_ignored_same_chan = false;
Michal Kazior59af6922014-04-09 15:10:59 +02001346
1347 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03001348 ieee80211_stop_vif_queues(local, sdata,
1349 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02001350 mutex_unlock(&local->mtx);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001351
Luciano Coelho2f457292014-11-07 14:31:36 +02001352 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1353 csa_ie.count);
1354
Johannes Bergb4f286a12013-03-26 14:13:58 +01001355 if (local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +02001356 /* use driver's channel switch callback */
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001357 drv_channel_switch(local, sdata, &ch_switch);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001358 return;
1359 }
1360
1361 /* channel switch handled in software */
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001362 if (csa_ie.count <= 1)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001363 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001364 else
Johannes Bergcc32abd2009-05-15 11:52:31 +02001365 mod_timer(&ifmgd->chswitch_timer,
Luciano Coelhoff1e4172014-10-28 13:33:05 +02001366 TU_TO_EXP_TIME((csa_ie.count - 1) *
1367 cbss->beacon_interval));
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001368 return;
1369 drop_connection:
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03001370 /*
1371 * This is just so that the disconnect flow will know that
1372 * we were trying to switch channel and failed. In case the
1373 * mode is 1 (we are not allowed to Tx), we will know not to
1374 * send a deauthentication frame. Those two fields will be
1375 * reset when the disconnection worker runs.
1376 */
1377 sdata->vif.csa_active = true;
1378 sdata->csa_block_tx = csa_ie.mode;
1379
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001380 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1381 mutex_unlock(&local->chanctx_mtx);
1382 mutex_unlock(&local->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001383}
1384
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001385static bool
1386ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1387 struct ieee80211_channel *channel,
1388 const u8 *country_ie, u8 country_ie_len,
1389 const u8 *pwr_constr_elem,
1390 int *chan_pwr, int *pwr_reduction)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001391{
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001392 struct ieee80211_country_ie_triplet *triplet;
1393 int chan = ieee80211_frequency_to_channel(channel->center_freq);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001394 int i, chan_increment;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001395 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001396
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001397 /* Invalid IE */
1398 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001399 return false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001400
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001401 triplet = (void *)(country_ie + 3);
1402 country_ie_len -= 3;
1403
1404 switch (channel->band) {
1405 default:
1406 WARN_ON_ONCE(1);
1407 /* fall through */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001408 case NL80211_BAND_2GHZ:
1409 case NL80211_BAND_60GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001410 chan_increment = 1;
1411 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001412 case NL80211_BAND_5GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001413 chan_increment = 4;
1414 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001415 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001416
1417 /* find channel */
1418 while (country_ie_len >= 3) {
1419 u8 first_channel = triplet->chans.first_channel;
1420
1421 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1422 goto next;
1423
1424 for (i = 0; i < triplet->chans.num_channels; i++) {
1425 if (first_channel + i * chan_increment == chan) {
1426 have_chan_pwr = true;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001427 *chan_pwr = triplet->chans.max_power;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001428 break;
1429 }
1430 }
1431 if (have_chan_pwr)
1432 break;
1433
1434 next:
1435 triplet++;
1436 country_ie_len -= 3;
1437 }
1438
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001439 if (have_chan_pwr && pwr_constr_elem)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001440 *pwr_reduction = *pwr_constr_elem;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001441 else
1442 *pwr_reduction = 0;
1443
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001444 return have_chan_pwr;
1445}
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001446
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001447static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1448 struct ieee80211_channel *channel,
1449 const u8 *cisco_dtpc_ie,
1450 int *pwr_level)
1451{
1452 /* From practical testing, the first data byte of the DTPC element
1453 * seems to contain the requested dBm level, and the CLI on Cisco
1454 * APs clearly state the range is -127 to 127 dBm, which indicates
1455 * a signed byte, although it seemingly never actually goes negative.
1456 * The other byte seems to always be zero.
1457 */
1458 *pwr_level = (__s8)cisco_dtpc_ie[4];
1459}
1460
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001461static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1462 struct ieee80211_channel *channel,
1463 struct ieee80211_mgmt *mgmt,
1464 const u8 *country_ie, u8 country_ie_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001465 const u8 *pwr_constr_ie,
1466 const u8 *cisco_dtpc_ie)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001467{
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001468 bool has_80211h_pwr = false, has_cisco_pwr = false;
1469 int chan_pwr = 0, pwr_reduction_80211h = 0;
1470 int pwr_level_cisco, pwr_level_80211h;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001471 int new_ap_level;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001472 __le16 capab = mgmt->u.probe_resp.capab_info;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001473
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001474 if (country_ie &&
1475 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1476 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001477 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1478 sdata, channel, country_ie, country_ie_len,
1479 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001480 pwr_level_80211h =
1481 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001482 }
1483
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001484 if (cisco_dtpc_ie) {
1485 ieee80211_find_cisco_dtpc(
1486 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1487 has_cisco_pwr = true;
1488 }
1489
1490 if (!has_80211h_pwr && !has_cisco_pwr)
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001491 return 0;
1492
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001493 /* If we have both 802.11h and Cisco DTPC, apply both limits
1494 * by picking the smallest of the two power levels advertised.
1495 */
1496 if (has_80211h_pwr &&
1497 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
Johannes Berga87da0c2015-12-08 16:04:37 +02001498 new_ap_level = pwr_level_80211h;
1499
1500 if (sdata->ap_power_level == new_ap_level)
1501 return 0;
1502
John Linvillecef2fc12015-03-31 10:49:14 -04001503 sdata_dbg(sdata,
1504 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1505 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1506 sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001507 } else { /* has_cisco_pwr is always true here. */
Johannes Berga87da0c2015-12-08 16:04:37 +02001508 new_ap_level = pwr_level_cisco;
1509
1510 if (sdata->ap_power_level == new_ap_level)
1511 return 0;
1512
John Linvillecef2fc12015-03-31 10:49:14 -04001513 sdata_dbg(sdata,
1514 "Limiting TX power to %d dBm as advertised by %pM\n",
1515 pwr_level_cisco, sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001516 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001517
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001518 sdata->ap_power_level = new_ap_level;
1519 if (__ieee80211_recalc_txpower(sdata))
1520 return BSS_CHANGED_TXPOWER;
1521 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001522}
1523
Johannes Berg965beda2009-04-16 13:17:24 +02001524/* powersave */
1525static void ieee80211_enable_ps(struct ieee80211_local *local,
1526 struct ieee80211_sub_if_data *sdata)
1527{
1528 struct ieee80211_conf *conf = &local->hw.conf;
1529
Johannes Bergd5edaed2009-04-22 23:02:51 +02001530 /*
1531 * If we are scanning right now then the parameters will
1532 * take effect when scan finishes.
1533 */
Helmut Schaafbe9c4292009-07-23 12:14:04 +02001534 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +02001535 return;
1536
Johannes Berg965beda2009-04-16 13:17:24 +02001537 if (conf->dynamic_ps_timeout > 0 &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001538 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001539 mod_timer(&local->dynamic_ps_timer, jiffies +
1540 msecs_to_jiffies(conf->dynamic_ps_timeout));
1541 } else {
Johannes Berg30686bf2015-06-02 21:39:54 +02001542 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
Johannes Berg076cdcb2015-09-24 16:14:55 +02001543 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajan375177b2010-02-09 14:50:28 +05301544
Johannes Berg30686bf2015-06-02 21:39:54 +02001545 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1546 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001547 return;
1548
1549 conf->flags |= IEEE80211_CONF_PS;
1550 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +02001551 }
1552}
1553
1554static void ieee80211_change_ps(struct ieee80211_local *local)
1555{
1556 struct ieee80211_conf *conf = &local->hw.conf;
1557
1558 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +02001559 ieee80211_enable_ps(local, local->ps_sdata);
1560 } else if (conf->flags & IEEE80211_CONF_PS) {
1561 conf->flags &= ~IEEE80211_CONF_PS;
1562 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1563 del_timer_sync(&local->dynamic_ps_timer);
1564 cancel_work_sync(&local->dynamic_ps_enable_work);
1565 }
1566}
1567
Jason Young808118c2011-03-10 16:43:19 -08001568static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1569{
1570 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1571 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001572 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001573
1574 if (!mgd->powersave)
1575 return false;
1576
Johannes Berg05cb9102011-10-28 11:59:47 +02001577 if (mgd->broken_ap)
1578 return false;
1579
Jason Young808118c2011-03-10 16:43:19 -08001580 if (!mgd->associated)
1581 return false;
1582
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001583 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
Jason Young808118c2011-03-10 16:43:19 -08001584 return false;
1585
Alexander Bondar989c6502013-05-16 17:34:17 +03001586 if (!mgd->have_beacon)
Alexander Bondarce857882013-05-06 17:17:04 +03001587 return false;
1588
Jason Young808118c2011-03-10 16:43:19 -08001589 rcu_read_lock();
1590 sta = sta_info_get(sdata, mgd->bssid);
1591 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001592 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001593 rcu_read_unlock();
1594
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001595 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001596}
1597
Johannes Berg965beda2009-04-16 13:17:24 +02001598/* need to hold RTNL or interface lock */
Johannes Berg4a733ef2015-10-14 18:02:43 +02001599void ieee80211_recalc_ps(struct ieee80211_local *local)
Johannes Berg965beda2009-04-16 13:17:24 +02001600{
1601 struct ieee80211_sub_if_data *sdata, *found = NULL;
1602 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001603 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001604
Johannes Berg30686bf2015-06-02 21:39:54 +02001605 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001606 local->ps_sdata = NULL;
1607 return;
1608 }
1609
1610 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b662009-12-23 13:15:31 +01001611 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001612 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301613 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1614 /* If an AP vif is found, then disable PS
1615 * by setting the count to zero thereby setting
1616 * ps_sdata to NULL.
1617 */
1618 count = 0;
1619 break;
1620 }
Johannes Berg965beda2009-04-16 13:17:24 +02001621 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1622 continue;
1623 found = sdata;
1624 count++;
1625 }
1626
Jason Young808118c2011-03-10 16:43:19 -08001627 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg4a733ef2015-10-14 18:02:43 +02001628 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg10f644a2009-04-16 13:17:25 +02001629
Juuso Oikarinenff616382010-06-09 09:51:52 +03001630 timeout = local->dynamic_ps_forced_timeout;
Johannes Berg4a733ef2015-10-14 18:02:43 +02001631 if (timeout < 0)
1632 timeout = 100;
Johannes Berg09b85562013-02-06 23:07:41 +01001633 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001634
Johannes Berg4a733ef2015-10-14 18:02:43 +02001635 /* If the TIM IE is invalid, pretend the value is 1 */
1636 if (!dtimper)
1637 dtimper = 1;
Johannes Berg56007a02010-01-26 14:19:52 +01001638
Johannes Berg4a733ef2015-10-14 18:02:43 +02001639 local->hw.conf.ps_dtim_period = dtimper;
1640 local->ps_sdata = found;
Johannes Berg10f644a2009-04-16 13:17:25 +02001641 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001642 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001643 }
Johannes Berg965beda2009-04-16 13:17:24 +02001644
1645 ieee80211_change_ps(local);
1646}
1647
Eliad Pellerab095872012-07-27 12:33:22 +03001648void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1649{
1650 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1651
1652 if (sdata->vif.bss_conf.ps != ps_allowed) {
1653 sdata->vif.bss_conf.ps = ps_allowed;
1654 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1655 }
1656}
1657
Johannes Berg965beda2009-04-16 13:17:24 +02001658void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1659{
1660 struct ieee80211_local *local =
1661 container_of(work, struct ieee80211_local,
1662 dynamic_ps_disable_work);
1663
1664 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1665 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1666 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1667 }
1668
1669 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001670 IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +03001671 IEEE80211_QUEUE_STOP_REASON_PS,
1672 false);
Johannes Berg965beda2009-04-16 13:17:24 +02001673}
1674
1675void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1676{
1677 struct ieee80211_local *local =
1678 container_of(work, struct ieee80211_local,
1679 dynamic_ps_enable_work);
1680 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001681 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301682 unsigned long flags;
1683 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001684
1685 /* can only happen when PS was just disabled anyway */
1686 if (!sdata)
1687 return;
1688
Christian Lamparter5e340692011-06-30 21:08:43 +02001689 ifmgd = &sdata->u.mgd;
1690
Johannes Berg965beda2009-04-16 13:17:24 +02001691 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1692 return;
1693
Johannes Berg09b85562013-02-06 23:07:41 +01001694 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001695 /* don't enter PS if TX frames are pending */
1696 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301697 mod_timer(&local->dynamic_ps_timer, jiffies +
1698 msecs_to_jiffies(
1699 local->hw.conf.dynamic_ps_timeout));
1700 return;
1701 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001702
1703 /*
1704 * transmission can be stopped by others which leads to
1705 * dynamic_ps_timer expiry. Postpone the ps timer if it
1706 * is not the actual idle state.
1707 */
1708 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1709 for (q = 0; q < local->hw.queues; q++) {
1710 if (local->queue_stop_reasons[q]) {
1711 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1712 flags);
1713 mod_timer(&local->dynamic_ps_timer, jiffies +
1714 msecs_to_jiffies(
1715 local->hw.conf.dynamic_ps_timeout));
1716 return;
1717 }
1718 }
1719 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301720 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301721
Johannes Berg30686bf2015-06-02 21:39:54 +02001722 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301723 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Johannes Berga1598382013-03-26 22:02:42 +01001724 if (drv_tx_frames_pending(local)) {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301725 mod_timer(&local->dynamic_ps_timer, jiffies +
1726 msecs_to_jiffies(
1727 local->hw.conf.dynamic_ps_timeout));
Johannes Berga1598382013-03-26 22:02:42 +01001728 } else {
Johannes Berg076cdcb2015-09-24 16:14:55 +02001729 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301730 /* Flush to get the tx status of nullfunc frame */
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001731 ieee80211_flush_queues(local, sdata, false);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301732 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301733 }
1734
Johannes Berg30686bf2015-06-02 21:39:54 +02001735 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1736 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301737 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1738 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1739 local->hw.conf.flags |= IEEE80211_CONF_PS;
1740 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1741 }
Johannes Berg965beda2009-04-16 13:17:24 +02001742}
1743
Kees Cook34f11cd2017-10-16 16:35:49 -07001744void ieee80211_dynamic_ps_timer(struct timer_list *t)
Johannes Berg965beda2009-04-16 13:17:24 +02001745{
Kees Cook34f11cd2017-10-16 16:35:49 -07001746 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
Johannes Berg965beda2009-04-16 13:17:24 +02001747
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001748 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001749}
1750
Simon Wunderlich164eb022013-02-08 18:16:20 +01001751void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1752{
Geliang Tanga85a7e22016-01-01 23:48:52 +08001753 struct delayed_work *delayed_work = to_delayed_work(work);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001754 struct ieee80211_sub_if_data *sdata =
1755 container_of(delayed_work, struct ieee80211_sub_if_data,
1756 dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001757 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlich164eb022013-02-08 18:16:20 +01001758
Johannes Berg34a37402013-12-18 09:43:33 +01001759 mutex_lock(&sdata->local->mtx);
1760 if (sdata->wdev.cac_started) {
1761 ieee80211_vif_release_channel(sdata);
1762 cfg80211_cac_event(sdata->dev, &chandef,
1763 NL80211_RADAR_CAC_FINISHED,
1764 GFP_KERNEL);
1765 }
1766 mutex_unlock(&sdata->local->mtx);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001767}
1768
Johannes Berg02219b32014-10-07 10:38:50 +03001769static bool
1770__ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1771{
1772 struct ieee80211_local *local = sdata->local;
1773 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
John Linvillecc72f6e2015-01-06 14:39:33 -05001774 bool ret = false;
Johannes Berg02219b32014-10-07 10:38:50 +03001775 int ac;
1776
1777 if (local->hw.queues < IEEE80211_NUM_ACS)
1778 return false;
1779
1780 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1781 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1782 int non_acm_ac;
1783 unsigned long now = jiffies;
1784
1785 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1786 tx_tspec->admitted_time &&
1787 time_after(now, tx_tspec->time_slice_start + HZ)) {
1788 tx_tspec->consumed_tx_time = 0;
1789 tx_tspec->time_slice_start = now;
1790
1791 if (tx_tspec->downgraded)
1792 tx_tspec->action =
1793 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1794 }
1795
1796 switch (tx_tspec->action) {
1797 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1798 /* take the original parameters */
1799 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1800 sdata_err(sdata,
1801 "failed to set TX queue parameters for queue %d\n",
1802 ac);
1803 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1804 tx_tspec->downgraded = false;
1805 ret = true;
1806 break;
1807 case TX_TSPEC_ACTION_DOWNGRADE:
1808 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1809 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1810 ret = true;
1811 break;
1812 }
1813 /* downgrade next lower non-ACM AC */
1814 for (non_acm_ac = ac + 1;
1815 non_acm_ac < IEEE80211_NUM_ACS;
1816 non_acm_ac++)
1817 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1818 break;
Johannes Berg93db1d92016-09-14 09:23:51 +02001819 /* Usually the loop will result in using BK even if it
1820 * requires admission control, but such a configuration
1821 * makes no sense and we have to transmit somehow - the
1822 * AC selection does the same thing.
1823 * If we started out trying to downgrade from BK, then
1824 * the extra condition here might be needed.
Johannes Berg02219b32014-10-07 10:38:50 +03001825 */
Johannes Berg93db1d92016-09-14 09:23:51 +02001826 if (non_acm_ac >= IEEE80211_NUM_ACS)
1827 non_acm_ac = IEEE80211_AC_BK;
Johannes Berg02219b32014-10-07 10:38:50 +03001828 if (drv_conf_tx(local, sdata, ac,
1829 &sdata->tx_conf[non_acm_ac]))
1830 sdata_err(sdata,
1831 "failed to set TX queue parameters for queue %d\n",
1832 ac);
1833 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1834 ret = true;
1835 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1836 tx_tspec->time_slice_start + HZ - now + 1);
1837 break;
1838 case TX_TSPEC_ACTION_NONE:
1839 /* nothing now */
1840 break;
1841 }
1842 }
1843
1844 return ret;
1845}
1846
1847void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1848{
1849 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1850 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1851}
1852
1853static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1854{
1855 struct ieee80211_sub_if_data *sdata;
1856
1857 sdata = container_of(work, struct ieee80211_sub_if_data,
1858 u.mgd.tx_tspec_wk.work);
1859 ieee80211_sta_handle_tspec_ac_params(sdata);
1860}
1861
Johannes Berg60f8b392008-09-08 17:44:22 +02001862/* MLME */
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001863static bool
1864ieee80211_sta_wmm_params(struct ieee80211_local *local,
1865 struct ieee80211_sub_if_data *sdata,
1866 const u8 *wmm_param, size_t wmm_param_len,
1867 const struct ieee80211_mu_edca_param_set *mu_edca)
Jiri Bencf0706e82007-05-05 11:45:53 -07001868{
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001869 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
Johannes Berg4ced3f72010-07-19 16:39:04 +02001870 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001871 size_t left;
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001872 int count, ac;
Johannes Berg4a3cb702013-02-12 16:43:19 +01001873 const u8 *pos;
1874 u8 uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001875
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001876 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001877 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001878
Johannes Berg32c50572012-03-28 11:04:29 +02001879 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001880 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001881
1882 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001883 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001884
Jiri Bencf0706e82007-05-05 11:45:53 -07001885 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001886 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001887
1888 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001889 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001890
Jiri Bencf0706e82007-05-05 11:45:53 -07001891 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +01001892 if (count == ifmgd->wmm_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001893 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001894 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001895
1896 pos = wmm_param + 8;
1897 left = wmm_param_len - 8;
1898
1899 memset(&params, 0, sizeof(params));
1900
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001901 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001902 for (; left >= 4; left -= 4, pos += 4) {
1903 int aci = (pos[0] >> 5) & 0x03;
1904 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001905 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001906
1907 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001908 case 1: /* AC_BK */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001909 ac = IEEE80211_AC_BK;
Johannes Berg988c0f72008-04-17 19:21:22 +02001910 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001911 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001912 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1913 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001914 params[ac].mu_edca = !!mu_edca;
1915 if (mu_edca)
1916 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
Jiri Bencf0706e82007-05-05 11:45:53 -07001917 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001918 case 2: /* AC_VI */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001919 ac = IEEE80211_AC_VI;
Johannes Berg988c0f72008-04-17 19:21:22 +02001920 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001921 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001922 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1923 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001924 params[ac].mu_edca = !!mu_edca;
1925 if (mu_edca)
1926 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
Jiri Bencf0706e82007-05-05 11:45:53 -07001927 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001928 case 3: /* AC_VO */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001929 ac = IEEE80211_AC_VO;
Johannes Berg988c0f72008-04-17 19:21:22 +02001930 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001931 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02001932 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1933 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001934 params[ac].mu_edca = !!mu_edca;
1935 if (mu_edca)
1936 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
Jiri Bencf0706e82007-05-05 11:45:53 -07001937 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001938 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001939 default:
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001940 ac = IEEE80211_AC_BE;
Johannes Berg988c0f72008-04-17 19:21:22 +02001941 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001942 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02001943 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1944 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001945 params[ac].mu_edca = !!mu_edca;
1946 if (mu_edca)
1947 params[ac].mu_edca_param_rec = mu_edca->ac_be;
Jiri Bencf0706e82007-05-05 11:45:53 -07001948 break;
1949 }
1950
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001951 params[ac].aifs = pos[0] & 0x0f;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001952
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001953 if (params[ac].aifs < 2) {
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001954 sdata_info(sdata,
1955 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001956 params[ac].aifs, aci);
1957 params[ac].aifs = 2;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001958 }
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001959 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1960 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
1961 params[ac].txop = get_unaligned_le16(pos + 2);
1962 params[ac].acm = acm;
1963 params[ac].uapsd = uapsd;
Kalle Valoab133152010-01-12 10:42:31 +02001964
Ilan Peer911a2642018-04-03 11:35:22 +03001965 if (params[ac].cw_min == 0 ||
Emmanuel Grumbachc470bdc2018-03-26 16:21:04 +03001966 params[ac].cw_min > params[ac].cw_max) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001967 sdata_info(sdata,
1968 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
1969 params[ac].cw_min, params[ac].cw_max, aci);
1970 return false;
1971 }
Haim Dreyfusse552af02018-03-28 13:24:10 +03001972 ieee80211_regulatory_limit_wmm_params(sdata, &params[ac], ac);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001973 }
1974
1975 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001976 mlme_dbg(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001977 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
1978 ac, params[ac].acm,
1979 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
1980 params[ac].txop, params[ac].uapsd,
1981 ifmgd->tx_tspec[ac].downgraded);
1982 sdata->tx_conf[ac] = params[ac];
1983 if (!ifmgd->tx_tspec[ac].downgraded &&
1984 drv_conf_tx(local, sdata, ac, &params[ac]))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001985 sdata_err(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001986 "failed to set TX queue parameters for AC %d\n",
1987 ac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001988 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001989
1990 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02001991 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02001992 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001993}
1994
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001995static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1996{
1997 lockdep_assert_held(&sdata->local->mtx);
1998
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001999 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002000 ieee80211_run_deferred_scan(sdata->local);
2001}
2002
2003static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2004{
2005 mutex_lock(&sdata->local->mtx);
2006 __ieee80211_stop_poll(sdata);
2007 mutex_unlock(&sdata->local->mtx);
2008}
2009
Johannes Berg7a5158e2008-10-08 10:59:33 +02002010static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2011 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02002012{
Johannes Bergbda39332008-10-11 01:51:51 +02002013 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302014 struct ieee80211_supported_band *sband;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002015 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002016 bool use_protection;
2017 bool use_short_preamble;
2018 bool use_short_slot;
2019
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302020 sband = ieee80211_get_sband(sdata);
2021 if (!sband)
2022 return changed;
2023
Johannes Berg7a5158e2008-10-08 10:59:33 +02002024 if (erp_valid) {
2025 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2026 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2027 } else {
2028 use_protection = false;
2029 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2030 }
2031
2032 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302033 if (sband->band == NL80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01002034 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02002035
Johannes Berg471b3ef2007-12-28 14:32:58 +01002036 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01002037 bss_conf->use_cts_prot = use_protection;
2038 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02002039 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02002040
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002041 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002042 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002043 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02002044 }
Daniel Draked9430a32007-07-27 15:43:24 +02002045
Johannes Berg7a5158e2008-10-08 10:59:33 +02002046 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02002047 bss_conf->use_short_slot = use_short_slot;
2048 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04002049 }
2050
2051 return changed;
2052}
2053
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002054static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002055 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02002056 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07002057{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002058 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002059 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002060 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002061
Johannes Bergae5eb022008-10-14 16:58:37 +02002062 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002063 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03002064 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002065
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002066 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
Ben Greear59c1ec22013-03-19 14:19:56 -07002067 beacon_loss_count * bss_conf->beacon_int));
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002068
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002069 sdata->u.mgd.associated = cbss;
2070 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002071
Johannes Berge8e4f522017-03-08 11:12:10 +01002072 ieee80211_check_rate_mask(sdata);
2073
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002074 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2075
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01002076 if (sdata->vif.p2p ||
2077 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002078 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01002079
Johannes Berg9caf0362012-11-29 01:25:20 +01002080 rcu_read_lock();
2081 ies = rcu_dereference(cbss->ies);
2082 if (ies) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002083 int ret;
2084
2085 ret = cfg80211_get_p2p_attr(
2086 ies->data, ies->len,
2087 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002088 (u8 *) &bss_conf->p2p_noa_attr,
2089 sizeof(bss_conf->p2p_noa_attr));
Johannes Berg9caf0362012-11-29 01:25:20 +01002090 if (ret >= 2) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002091 sdata->u.mgd.p2p_noa_index =
2092 bss_conf->p2p_noa_attr.index;
Johannes Berg9caf0362012-11-29 01:25:20 +01002093 bss_info_changed |= BSS_CHANGED_P2P_PS;
Johannes Berg9caf0362012-11-29 01:25:20 +01002094 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01002095 }
Johannes Berg9caf0362012-11-29 01:25:20 +01002096 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01002097 }
2098
Johannes Bergb291ba12009-07-10 15:29:03 +02002099 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002100 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002101
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002102 ieee80211_led_assoc(local, 1);
2103
Alexander Bondar989c6502013-05-16 17:34:17 +03002104 if (sdata->u.mgd.have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02002105 /*
2106 * If the AP is buggy we may get here with no DTIM period
2107 * known, so assume it's 1 which is the only safe assumption
2108 * in that case, although if the TIM IE is broken powersave
2109 * probably just won't work at all.
2110 */
2111 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Alexander Bondar817cee72013-05-19 14:23:57 +03002112 bss_conf->beacon_rate = bss->beacon_rate;
Alexander Bondar989c6502013-05-16 17:34:17 +03002113 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
Johannes Berg826262c2012-12-10 16:38:14 +02002114 } else {
Alexander Bondar817cee72013-05-19 14:23:57 +03002115 bss_conf->beacon_rate = NULL;
Johannes Berge5b900d2010-07-29 16:08:55 +02002116 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02002117 }
Johannes Berge5b900d2010-07-29 16:08:55 +02002118
Juuso Oikarinen68542962010-06-09 13:43:26 +03002119 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02002120
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002121 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01002122 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03002123 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002124 bss_info_changed |= BSS_CHANGED_CQM;
2125
Juuso Oikarinen68542962010-06-09 13:43:26 +03002126 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002127 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002128 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002129
Johannes Bergae5eb022008-10-14 16:58:37 +02002130 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03002131
Johannes Berg056508d2009-07-30 21:43:55 +02002132 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002133 ieee80211_recalc_ps(local);
Johannes Berg056508d2009-07-30 21:43:55 +02002134 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02002135
Johannes Berg04ecd252012-09-11 14:34:12 +02002136 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03002137 ieee80211_recalc_ps_vif(sdata);
2138
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002139 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07002140}
2141
Jouni Malinene69e95d2010-03-29 23:29:31 -07002142static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01002143 u16 stype, u16 reason, bool tx,
2144 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03002145{
Johannes Berg46900292009-02-15 12:44:28 +01002146 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002147 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01002148 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002149
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002150 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002151
Johannes Berg37ad3882012-02-24 13:50:54 +01002152 if (WARN_ON_ONCE(tx && !frame_buf))
2153 return;
2154
Johannes Bergb291ba12009-07-10 15:29:03 +02002155 if (WARN_ON(!ifmgd->associated))
2156 return;
2157
David Spinadel79543d82012-06-12 09:59:45 +03002158 ieee80211_stop_poll(sdata);
2159
Johannes Berg77fdaa12009-07-07 03:45:17 +02002160 ifmgd->associated = NULL;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002161 netif_carrier_off(sdata->dev);
2162
Eliad Peller88bc40e2012-07-12 17:35:33 +03002163 /*
2164 * if we want to get out of ps before disassoc (why?) we have
2165 * to do it before sending disassoc, as otherwise the null-packet
2166 * won't be valid.
2167 */
2168 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2169 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2170 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2171 }
2172 local->ps_sdata = NULL;
2173
Eliad Pellerab095872012-07-27 12:33:22 +03002174 /* disable per-vif ps */
2175 ieee80211_recalc_ps_vif(sdata);
2176
Emmanuel Grumbach14f2ae82015-01-22 23:30:19 +02002177 /* make sure ongoing transmission finishes */
2178 synchronize_net();
2179
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002180 /*
2181 * drop any frame before deauth/disassoc, this can be data or
2182 * management frame. Since we are disconnecting, we should not
2183 * insist sending these frames which can take time and delay
2184 * the disconnection and possible the roaming.
2185 */
Eliad Pellerf8239812012-06-27 14:18:22 +03002186 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002187 ieee80211_flush_queues(local, sdata, true);
Eliad Pellerf8239812012-06-27 14:18:22 +03002188
Johannes Berg37ad3882012-02-24 13:50:54 +01002189 /* deauthenticate/disassociate now */
Ilan Peer94ba9272018-02-19 14:48:41 +02002190 if (tx || frame_buf) {
Ilan Peer94ba9272018-02-19 14:48:41 +02002191 /*
2192 * In multi channel scenarios guarantee that the virtual
2193 * interface is granted immediate airtime to transmit the
2194 * deauthentication frame by calling mgd_prepare_tx, if the
2195 * driver requested so.
2196 */
2197 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2198 !ifmgd->have_beacon)
Ilan Peerd4e36e52018-04-20 13:49:25 +03002199 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Ilan Peer94ba9272018-02-19 14:48:41 +02002200
Eliad Peller88a9e312012-06-01 11:14:03 +03002201 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
2202 reason, tx, frame_buf);
Ilan Peer94ba9272018-02-19 14:48:41 +02002203 }
Johannes Berg37ad3882012-02-24 13:50:54 +01002204
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002205 /* flush out frame - make sure the deauth was actually sent */
Johannes Berg37ad3882012-02-24 13:50:54 +01002206 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002207 ieee80211_flush_queues(local, sdata, false);
Johannes Berg37ad3882012-02-24 13:50:54 +01002208
Eliad Peller88a9e312012-06-01 11:14:03 +03002209 /* clear bssid only after building the needed mgmt frames */
Joe Perchesc84a67a2015-03-02 19:54:57 -08002210 eth_zero_addr(ifmgd->bssid);
Eliad Peller88a9e312012-06-01 11:14:03 +03002211
Johannes Berg37ad3882012-02-24 13:50:54 +01002212 /* remove AP and TDLS peers */
Johannes Bergd34ba212013-12-04 22:46:11 +01002213 sta_info_flush(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01002214
2215 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002216 changed |= ieee80211_reset_erp_info(sdata);
2217
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002218 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02002219 changed |= BSS_CHANGED_ASSOC;
2220 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002221
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002222 ifmgd->p2p_noa_index = -1;
2223 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2224 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01002225
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002226 /* on the next assoc, re-program HT/VHT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08002227 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2228 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002229 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2230 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
Sara Sharon23a1f8d2015-12-08 16:04:31 +02002231
2232 /* reset MU-MIMO ownership and group data */
2233 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2234 sizeof(sdata->vif.bss_conf.mu_group.membership));
2235 memset(sdata->vif.bss_conf.mu_group.position, 0,
2236 sizeof(sdata->vif.bss_conf.mu_group.position));
2237 changed |= BSS_CHANGED_MU_GROUPS;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002238 sdata->vif.mu_mimo_owner = false;
Johannes Berg413ad502009-05-08 21:21:06 +02002239
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002240 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05302241
Kalle Valo520eb822008-12-18 23:35:27 +02002242 del_timer_sync(&local->dynamic_ps_timer);
2243 cancel_work_sync(&local->dynamic_ps_enable_work);
2244
Juuso Oikarinen68542962010-06-09 13:43:26 +03002245 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002246 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002247 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002248
Johannes Berg3abead52012-03-02 15:56:59 +01002249 sdata->vif.bss_conf.qos = false;
2250 changed |= BSS_CHANGED_QOS;
2251
Johannes Berg0aaffa92010-05-05 15:28:27 +02002252 /* The BSSID (not really interesting) and HT changed */
2253 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02002254 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02002255
Johannes Berg3abead52012-03-02 15:56:59 +01002256 /* disassociated - set to defaults now */
Johannes Bergcec66282015-10-22 17:46:04 +02002257 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg3abead52012-03-02 15:56:59 +01002258
Johannes Bergb9dcf712010-08-27 12:35:54 +02002259 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2260 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2261 del_timer_sync(&sdata->u.mgd.timer);
2262 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02002263
Johannes Berg826262c2012-12-10 16:38:14 +02002264 sdata->vif.bss_conf.dtim_period = 0;
Alexander Bondar817cee72013-05-19 14:23:57 +03002265 sdata->vif.bss_conf.beacon_rate = NULL;
2266
Alexander Bondar989c6502013-05-16 17:34:17 +03002267 ifmgd->have_beacon = false;
Johannes Berg826262c2012-12-10 16:38:14 +02002268
Johannes Berg028e8da02012-11-26 11:57:41 +01002269 ifmgd->flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002270 mutex_lock(&local->mtx);
Johannes Berg028e8da02012-11-26 11:57:41 +01002271 ieee80211_vif_release_channel(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002272
2273 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002274 ifmgd->csa_waiting_bcn = false;
Johannes Bergf84eaa12015-03-12 08:53:26 +02002275 ifmgd->csa_ignored_same_chan = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002276 if (sdata->csa_block_tx) {
2277 ieee80211_wake_vif_queues(local, sdata,
2278 IEEE80211_QUEUE_STOP_REASON_CSA);
2279 sdata->csa_block_tx = false;
2280 }
Johannes Berg34a37402013-12-18 09:43:33 +01002281 mutex_unlock(&local->mtx);
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002282
Johannes Berg02219b32014-10-07 10:38:50 +03002283 /* existing TX TSPEC sessions no longer exist */
2284 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2285 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2286
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002287 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002288}
Jiri Bencf0706e82007-05-05 11:45:53 -07002289
Kalle Valo3cf335d52009-03-22 21:57:06 +02002290void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2291 struct ieee80211_hdr *hdr)
2292{
2293 /*
2294 * We can postpone the mgd.timer whenever receiving unicast frames
2295 * from AP because we know that the connection is working both ways
2296 * at that time. But multicast frames (and hence also beacons) must
2297 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02002298 * data idle periods for sending the periodic probe request to the
2299 * AP we're connected to.
Kalle Valo3cf335d52009-03-22 21:57:06 +02002300 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002301 if (is_multicast_ether_addr(hdr->addr1))
2302 return;
2303
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04002304 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d52009-03-22 21:57:06 +02002305}
Jiri Bencf0706e82007-05-05 11:45:53 -07002306
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002307static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2308{
2309 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002310 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002311
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002312 mutex_lock(&local->mtx);
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002313 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2314 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002315
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002316 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002317
2318 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002319 ieee80211_recalc_ps(local);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002320 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002321
Johannes Berg30686bf2015-06-02 21:39:54 +02002322 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002323 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002324
2325 /*
2326 * We've received a probe response, but are not sure whether
2327 * we have or will be receiving any beacons or data, so let's
2328 * schedule the timers again, just in case.
2329 */
2330 ieee80211_sta_reset_beacon_monitor(sdata);
2331
2332 mod_timer(&ifmgd->conn_mon_timer,
2333 round_jiffies_up(jiffies +
2334 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002335out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002336 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002337}
2338
Johannes Berg02219b32014-10-07 10:38:50 +03002339static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2340 struct ieee80211_hdr *hdr,
2341 u16 tx_time)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002342{
Johannes Berg02219b32014-10-07 10:38:50 +03002343 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Sara Sharona1f2ba04c2018-02-19 14:48:40 +02002344 u16 tid = ieee80211_get_tid(hdr);
Johannes Berg02219b32014-10-07 10:38:50 +03002345 int ac = ieee80211_ac_from_tid(tid);
2346 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2347 unsigned long now = jiffies;
2348
2349 if (likely(!tx_tspec->admitted_time))
2350 return;
2351
2352 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2353 tx_tspec->consumed_tx_time = 0;
2354 tx_tspec->time_slice_start = now;
2355
2356 if (tx_tspec->downgraded) {
2357 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2358 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2359 }
2360 }
2361
2362 if (tx_tspec->downgraded)
2363 return;
2364
2365 tx_tspec->consumed_tx_time += tx_time;
2366
2367 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2368 tx_tspec->downgraded = true;
2369 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2370 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2371 }
2372}
2373
2374void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2375 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2376{
2377 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2378
Felix Fietkau75706d02010-12-02 21:01:07 +01002379 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002380 return;
2381
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002382 if (ieee80211_is_nullfunc(hdr->frame_control) &&
2383 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002384 if (ack)
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002385 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002386 else
2387 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002388 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002389 return;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002390 }
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002391
2392 if (ack)
2393 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002394}
2395
Johannes Berg45ad6832018-05-28 15:47:39 +02002396static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2397 const u8 *src, const u8 *dst,
2398 const u8 *ssid, size_t ssid_len,
2399 struct ieee80211_channel *channel)
2400{
2401 struct sk_buff *skb;
2402
2403 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2404 ssid, ssid_len, NULL, 0,
2405 IEEE80211_PROBE_FLAG_DIRECTED);
2406 if (skb)
2407 ieee80211_tx_skb(sdata, skb);
2408}
2409
Maxim Levitskya43abf22009-07-31 18:54:12 +03002410static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2411{
2412 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2413 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002414 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08002415 u8 unicast_limit = max(1, max_probe_tries - 3);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002416 struct sta_info *sta;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002417
2418 /*
2419 * Try sending broadcast probe requests for the last three
2420 * probe requests after the first ones failed since some
2421 * buggy APs only support broadcast probe requests.
2422 */
2423 if (ifmgd->probe_send_count >= unicast_limit)
2424 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002425
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002426 /*
2427 * When the hardware reports an accurate Tx ACK status, it's
2428 * better to send a nullfunc frame instead of a probe request,
2429 * as it will kick us off the AP quickly if we aren't associated
2430 * anymore. The timeout will be reset if the frame is ACKed by
2431 * the AP.
2432 */
Soumik Das992e68b2012-05-20 15:31:13 +05302433 ifmgd->probe_send_count++;
2434
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002435 if (dst) {
2436 mutex_lock(&sdata->local->sta_mtx);
2437 sta = sta_info_get(sdata, dst);
2438 if (!WARN_ON(!sta))
2439 ieee80211_check_fast_rx(sta);
2440 mutex_unlock(&sdata->local->sta_mtx);
2441 }
2442
Johannes Berg30686bf2015-06-02 21:39:54 +02002443 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002444 ifmgd->nullfunc_failed = false;
Johannes Berg076cdcb2015-09-24 16:14:55 +02002445 ieee80211_send_nullfunc(sdata->local, sdata, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002446 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002447 int ssid_len;
2448
Johannes Berg9caf0362012-11-29 01:25:20 +01002449 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002450 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002451 if (WARN_ON_ONCE(ssid == NULL))
2452 ssid_len = 0;
2453 else
2454 ssid_len = ssid[1];
2455
Johannes Berg45ad6832018-05-28 15:47:39 +02002456 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2457 ssid + 2, ssid_len,
2458 ifmgd->associated->channel);
Johannes Berg9caf0362012-11-29 01:25:20 +01002459 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002460 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03002461
Ben Greear180205b2011-02-04 15:30:24 -08002462 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002463 run_again(sdata, ifmgd->probe_timeout);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002464}
2465
Johannes Bergb291ba12009-07-10 15:29:03 +02002466static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2467 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02002468{
Kalle Valo04de8382009-03-22 21:57:35 +02002469 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002470 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02002471
Johannes Berg9607e6b662009-12-23 13:15:31 +01002472 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02002473 return;
2474
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002475 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002476
2477 if (!ifmgd->associated)
2478 goto out;
2479
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002480 mutex_lock(&sdata->local->mtx);
2481
2482 if (sdata->local->tmp_channel || sdata->local->scanning) {
2483 mutex_unlock(&sdata->local->mtx);
2484 goto out;
2485 }
2486
Ben Greeara13fbe52013-03-25 11:19:35 -07002487 if (beacon) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002488 mlme_dbg_ratelimited(sdata,
Ben Greear59c1ec22013-03-19 14:19:56 -07002489 "detected beacon loss from AP (missed %d beacons) - probing\n",
2490 beacon_loss_count);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002491
Johannes Berg98f03342014-11-26 12:42:02 +01002492 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
Ben Greeara13fbe52013-03-25 11:19:35 -07002493 }
Kalle Valo04de8382009-03-22 21:57:35 +02002494
Johannes Bergb291ba12009-07-10 15:29:03 +02002495 /*
2496 * The driver/our work has already reported this event or the
2497 * connection monitoring has kicked in and we have already sent
2498 * a probe request. Or maybe the AP died and the driver keeps
2499 * reporting until we disassociate...
2500 *
2501 * In either case we have to ignore the current call to this
2502 * function (except for setting the correct probe reason bit)
2503 * because otherwise we would reset the timer every time and
2504 * never check whether we received a probe response!
2505 */
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002506 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Johannes Bergb291ba12009-07-10 15:29:03 +02002507 already = true;
2508
Eliad Peller12b5f342013-11-18 19:06:46 +02002509 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2510
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002511 mutex_unlock(&sdata->local->mtx);
2512
Johannes Bergb291ba12009-07-10 15:29:03 +02002513 if (already)
2514 goto out;
2515
Johannes Berg4e751842009-06-10 15:16:52 +02002516 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002517 ieee80211_recalc_ps(sdata->local);
Johannes Berg4e751842009-06-10 15:16:52 +02002518 mutex_unlock(&sdata->local->iflist_mtx);
2519
Maxim Levitskya43abf22009-07-31 18:54:12 +03002520 ifmgd->probe_send_count = 0;
2521 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002522 out:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002523 sdata_unlock(sdata);
Kalle Valo04de8382009-03-22 21:57:35 +02002524}
2525
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002526struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2527 struct ieee80211_vif *vif)
2528{
2529 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2530 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002531 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002532 struct sk_buff *skb;
2533 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002534 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002535
2536 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2537 return NULL;
2538
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002539 sdata_assert_lock(sdata);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002540
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002541 if (ifmgd->associated)
2542 cbss = ifmgd->associated;
2543 else if (ifmgd->auth_data)
2544 cbss = ifmgd->auth_data->bss;
2545 else if (ifmgd->assoc_data)
2546 cbss = ifmgd->assoc_data->bss;
2547 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002548 return NULL;
2549
Johannes Berg9caf0362012-11-29 01:25:20 +01002550 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002551 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002552 if (WARN_ON_ONCE(ssid == NULL))
2553 ssid_len = 0;
2554 else
2555 ssid_len = ssid[1];
2556
Johannes Berga344d672014-06-12 22:24:31 +02002557 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02002558 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02002559 ssid + 2, ssid_len,
Johannes Berg00387f32018-05-28 15:47:38 +02002560 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
Johannes Berg9caf0362012-11-29 01:25:20 +01002561 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002562
2563 return skb;
2564}
2565EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2566
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002567static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2568 const u8 *buf, size_t len, bool tx,
2569 u16 reason)
2570{
2571 struct ieee80211_event event = {
2572 .type = MLME_EVENT,
2573 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2574 .u.mlme.reason = reason,
2575 };
2576
2577 if (tx)
2578 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2579 else
2580 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2581
2582 drv_event_callback(sdata->local, sdata, &event);
2583}
2584
Johannes Bergeef9e542013-01-29 13:09:34 +01002585static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002586{
Michal Kazior59af6922014-04-09 15:10:59 +02002587 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002588 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002589 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002590 bool tx;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002591
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002592 sdata_lock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002593 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002594 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002595 return;
2596 }
2597
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002598 tx = !sdata->csa_block_tx;
2599
David Spinadel20eb7ea2016-05-03 16:05:02 +03002600 /* AP is probably out of range (or not reachable for another reason) so
2601 * remove the bss struct for that AP.
2602 */
2603 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2604
Johannes Berg37ad3882012-02-24 13:50:54 +01002605 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2606 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002607 tx, frame_buf);
Michal Kazior59af6922014-04-09 15:10:59 +02002608 mutex_lock(&local->mtx);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002609 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002610 ifmgd->csa_waiting_bcn = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002611 if (sdata->csa_block_tx) {
2612 ieee80211_wake_vif_queues(local, sdata,
2613 IEEE80211_QUEUE_STOP_REASON_CSA);
2614 sdata->csa_block_tx = false;
2615 }
Michal Kazior59af6922014-04-09 15:10:59 +02002616 mutex_unlock(&local->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002617
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002618 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002619 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2620
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002621 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002622}
2623
Johannes Bergcc74c0c2012-08-01 16:49:34 +02002624static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02002625{
2626 struct ieee80211_sub_if_data *sdata =
2627 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002628 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002629 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Paul Stewarta85e1d52011-12-09 11:01:49 -08002630
Johannes Berg976bd9e2015-10-16 17:18:11 +02002631 if (ifmgd->associated)
2632 ifmgd->beacon_loss_count++;
Johannes Bergb291ba12009-07-10 15:29:03 +02002633
Johannes Berg682bd382013-01-29 13:13:50 +01002634 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02002635 sdata_info(sdata, "Connection to AP %pM lost\n",
2636 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01002637 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02002638 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002639 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02002640 }
2641}
2642
2643static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2644{
2645 struct ieee80211_sub_if_data *sdata =
2646 container_of(work, struct ieee80211_sub_if_data,
2647 u.mgd.csa_connection_drop_work);
2648
Johannes Bergeef9e542013-01-29 13:09:34 +01002649 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002650}
2651
Kalle Valo04de8382009-03-22 21:57:35 +02002652void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2653{
2654 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002655 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02002656
Johannes Bergb5878a22010-04-07 16:48:40 +02002657 trace_api_beacon_loss(sdata);
2658
Johannes Berg682bd382013-01-29 13:13:50 +01002659 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002660 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002661}
2662EXPORT_SYMBOL(ieee80211_beacon_loss);
2663
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002664void ieee80211_connection_loss(struct ieee80211_vif *vif)
2665{
2666 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2667 struct ieee80211_hw *hw = &sdata->local->hw;
2668
Johannes Bergb5878a22010-04-07 16:48:40 +02002669 trace_api_connection_loss(sdata);
2670
Johannes Berg682bd382013-01-29 13:13:50 +01002671 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002672 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2673}
2674EXPORT_SYMBOL(ieee80211_connection_loss);
2675
2676
Johannes Berg66e67e42012-01-20 13:55:27 +01002677static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2678 bool assoc)
2679{
2680 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2681
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002682 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002683
Johannes Berg66e67e42012-01-20 13:55:27 +01002684 if (!assoc) {
Emmanuel Grumbachc1e140b2015-01-19 16:53:06 +02002685 /*
2686 * we are not authenticated yet, the only timer that could be
2687 * running is the timeout for the authentication response which
2688 * which is not relevant anymore.
2689 */
2690 del_timer_sync(&sdata->u.mgd.timer);
Johannes Berg66e67e42012-01-20 13:55:27 +01002691 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2692
Joe Perchesc84a67a2015-03-02 19:54:57 -08002693 eth_zero_addr(sdata->u.mgd.bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002694 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002695 sdata->u.mgd.flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002696 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002697 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002698 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01002699 }
2700
Johannes Berg5b112d32013-02-01 01:49:58 +01002701 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002702 kfree(auth_data);
2703 sdata->u.mgd.auth_data = NULL;
2704}
2705
Johannes Bergc9c99f82015-06-01 14:10:09 +02002706static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
Johannes Berge6f462d2016-12-08 17:22:09 +01002707 bool assoc, bool abandon)
Johannes Bergc9c99f82015-06-01 14:10:09 +02002708{
2709 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2710
2711 sdata_assert_lock(sdata);
2712
2713 if (!assoc) {
2714 /*
2715 * we are not associated yet, the only timer that could be
2716 * running is the timeout for the association response which
2717 * which is not relevant anymore.
2718 */
2719 del_timer_sync(&sdata->u.mgd.timer);
2720 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2721
2722 eth_zero_addr(sdata->u.mgd.bssid);
2723 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2724 sdata->u.mgd.flags = 0;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002725 sdata->vif.mu_mimo_owner = false;
2726
Johannes Bergc9c99f82015-06-01 14:10:09 +02002727 mutex_lock(&sdata->local->mtx);
2728 ieee80211_vif_release_channel(sdata);
2729 mutex_unlock(&sdata->local->mtx);
Johannes Berge6f462d2016-12-08 17:22:09 +01002730
2731 if (abandon)
2732 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
Johannes Bergc9c99f82015-06-01 14:10:09 +02002733 }
2734
2735 kfree(assoc_data);
2736 sdata->u.mgd.assoc_data = NULL;
2737}
2738
Johannes Berg66e67e42012-01-20 13:55:27 +01002739static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2740 struct ieee80211_mgmt *mgmt, size_t len)
2741{
Johannes Berg1672c0e32013-01-29 15:02:27 +01002742 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01002743 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2744 u8 *pos;
2745 struct ieee802_11_elems elems;
Johannes Berg1672c0e32013-01-29 15:02:27 +01002746 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002747
2748 pos = mgmt->u.auth.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002749 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002750 if (!elems.challenge)
2751 return;
2752 auth_data->expected_transaction = 4;
Ilan Peerd4e36e52018-04-20 13:49:25 +03002753 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg30686bf2015-06-02 21:39:54 +02002754 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +01002755 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2756 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03002757 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01002758 elems.challenge - 2, elems.challenge_len + 2,
2759 auth_data->bss->bssid, auth_data->bss->bssid,
2760 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002761 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002762}
2763
Jouni Malinenfc107a92018-10-11 00:21:19 +03002764static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2765 const u8 *bssid)
2766{
2767 struct sta_info *sta;
2768
2769 /* move station state to auth */
2770 mutex_lock(&sdata->local->sta_mtx);
2771 sta = sta_info_get(sdata, bssid);
2772 if (!sta) {
2773 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2774 return false;
2775 }
2776 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2777 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2778 return false;
2779 }
2780 mutex_unlock(&sdata->local->sta_mtx);
2781
2782 return true;
2783}
2784
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002785static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2786 struct ieee80211_mgmt *mgmt, size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002787{
2788 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2789 u8 bssid[ETH_ALEN];
2790 u16 auth_alg, auth_transaction, status_code;
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002791 struct ieee80211_event event = {
2792 .type = MLME_EVENT,
2793 .u.mlme.data = AUTH_EVENT,
2794 };
Johannes Berg66e67e42012-01-20 13:55:27 +01002795
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002796 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002797
2798 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002799 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002800
2801 if (!ifmgd->auth_data || ifmgd->auth_data->done)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002802 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002803
2804 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2805
Joe Perchesb203ca32012-05-08 18:56:52 +00002806 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002807 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002808
2809 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2810 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2811 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2812
2813 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002814 auth_transaction != ifmgd->auth_data->expected_transaction) {
2815 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2816 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2817 auth_transaction,
2818 ifmgd->auth_data->expected_transaction);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002819 return;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002820 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002821
2822 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002823 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2824 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002825 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002826 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002827 event.u.mlme.status = MLME_DENIED;
2828 event.u.mlme.reason = status_code;
2829 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002830 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002831 }
2832
2833 switch (ifmgd->auth_data->algorithm) {
2834 case WLAN_AUTH_OPEN:
2835 case WLAN_AUTH_LEAP:
2836 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002837 case WLAN_AUTH_SAE:
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03002838 case WLAN_AUTH_FILS_SK:
2839 case WLAN_AUTH_FILS_SK_PFS:
2840 case WLAN_AUTH_FILS_PK:
Johannes Berg66e67e42012-01-20 13:55:27 +01002841 break;
2842 case WLAN_AUTH_SHARED_KEY:
2843 if (ifmgd->auth_data->expected_transaction != 4) {
2844 ieee80211_auth_challenge(sdata, mgmt, len);
2845 /* need another frame */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002846 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002847 }
2848 break;
2849 default:
2850 WARN_ONCE(1, "invalid auth alg %d",
2851 ifmgd->auth_data->algorithm);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002852 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002853 }
2854
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002855 event.u.mlme.status = MLME_SUCCESS;
2856 drv_event_callback(sdata->local, sdata, &event);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002857 sdata_info(sdata, "authenticated\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002858 ifmgd->auth_data->done = true;
2859 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
Johannes Berg89afe612013-02-13 15:39:57 +01002860 ifmgd->auth_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002861 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01002862
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002863 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2864 ifmgd->auth_data->expected_transaction != 2) {
2865 /*
2866 * Report auth frame to user space for processing since another
2867 * round of Authentication frames is still needed.
2868 */
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002869 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002870 return;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002871 }
2872
Jouni Malinenfc107a92018-10-11 00:21:19 +03002873 if (!ieee80211_mark_sta_auth(sdata, bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002874 goto out_err;
Johannes Berg66e67e42012-01-20 13:55:27 +01002875
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002876 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002877 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002878 out_err:
2879 mutex_unlock(&sdata->local->sta_mtx);
2880 /* ignore frame -- wait for timeout */
Johannes Berg66e67e42012-01-20 13:55:27 +01002881}
2882
Calvin Owensdfa1ad22014-02-11 12:36:24 -06002883#define case_WLAN(type) \
2884 case WLAN_REASON_##type: return #type
2885
2886static const char *ieee80211_get_reason_code_string(u16 reason_code)
2887{
2888 switch (reason_code) {
2889 case_WLAN(UNSPECIFIED);
2890 case_WLAN(PREV_AUTH_NOT_VALID);
2891 case_WLAN(DEAUTH_LEAVING);
2892 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2893 case_WLAN(DISASSOC_AP_BUSY);
2894 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2895 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2896 case_WLAN(DISASSOC_STA_HAS_LEFT);
2897 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2898 case_WLAN(DISASSOC_BAD_POWER);
2899 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2900 case_WLAN(INVALID_IE);
2901 case_WLAN(MIC_FAILURE);
2902 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
2903 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
2904 case_WLAN(IE_DIFFERENT);
2905 case_WLAN(INVALID_GROUP_CIPHER);
2906 case_WLAN(INVALID_PAIRWISE_CIPHER);
2907 case_WLAN(INVALID_AKMP);
2908 case_WLAN(UNSUPP_RSN_VERSION);
2909 case_WLAN(INVALID_RSN_IE_CAP);
2910 case_WLAN(IEEE8021X_FAILED);
2911 case_WLAN(CIPHER_SUITE_REJECTED);
2912 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
2913 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
2914 case_WLAN(DISASSOC_LOW_ACK);
2915 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
2916 case_WLAN(QSTA_LEAVE_QBSS);
2917 case_WLAN(QSTA_NOT_USE);
2918 case_WLAN(QSTA_REQUIRE_SETUP);
2919 case_WLAN(QSTA_TIMEOUT);
2920 case_WLAN(QSTA_CIPHER_NOT_SUPP);
2921 case_WLAN(MESH_PEER_CANCELED);
2922 case_WLAN(MESH_MAX_PEERS);
2923 case_WLAN(MESH_CONFIG);
2924 case_WLAN(MESH_CLOSE);
2925 case_WLAN(MESH_MAX_RETRIES);
2926 case_WLAN(MESH_CONFIRM_TIMEOUT);
2927 case_WLAN(MESH_INVALID_GTK);
2928 case_WLAN(MESH_INCONSISTENT_PARAM);
2929 case_WLAN(MESH_INVALID_SECURITY);
2930 case_WLAN(MESH_PATH_ERROR);
2931 case_WLAN(MESH_PATH_NOFORWARD);
2932 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
2933 case_WLAN(MAC_EXISTS_IN_MBSS);
2934 case_WLAN(MESH_CHAN_REGULATORY);
2935 case_WLAN(MESH_CHAN);
2936 default: return "<unknown>";
2937 }
2938}
Johannes Berg66e67e42012-01-20 13:55:27 +01002939
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002940static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2941 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002942{
Johannes Berg46900292009-02-15 12:44:28 +01002943 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergc9c99f82015-06-01 14:10:09 +02002944 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002945
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002946 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002947
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002948 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002949 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002950
Johannes Bergc9c99f82015-06-01 14:10:09 +02002951 if (ifmgd->associated &&
2952 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
2953 const u8 *bssid = ifmgd->associated->bssid;
2954
2955 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
2956 bssid, reason_code,
2957 ieee80211_get_reason_code_string(reason_code));
2958
2959 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2960
2961 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
2962 reason_code);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002963 return;
Johannes Bergc9c99f82015-06-01 14:10:09 +02002964 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002965
Johannes Bergc9c99f82015-06-01 14:10:09 +02002966 if (ifmgd->assoc_data &&
2967 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2968 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002969
Johannes Bergc9c99f82015-06-01 14:10:09 +02002970 sdata_info(sdata,
2971 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
2972 bssid, reason_code,
2973 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07002974
Johannes Berge6f462d2016-12-08 17:22:09 +01002975 ieee80211_destroy_assoc_data(sdata, false, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07002976
Johannes Bergc9c99f82015-06-01 14:10:09 +02002977 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2978 return;
2979 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002980}
2981
2982
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002983static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2984 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002985{
Johannes Berg46900292009-02-15 12:44:28 +01002986 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002987 u16 reason_code;
2988
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002989 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002990
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002991 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002992 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002993
Johannes Berg66e67e42012-01-20 13:55:27 +01002994 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002995 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002996 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002997
2998 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2999
Arkadiusz Miskiewicz68506e92017-02-15 14:21:27 +01003000 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3001 mgmt->sa, reason_code,
3002 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07003003
Johannes Berg37ad3882012-02-24 13:50:54 +01003004 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3005
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003006 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07003007}
3008
Christian Lamparterc74d0842011-10-15 00:14:49 +02003009static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3010 u8 *supp_rates, unsigned int supp_rates_len,
3011 u32 *rates, u32 *basic_rates,
3012 bool *have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003013 int *min_rate, int *min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03003014 int shift)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003015{
3016 int i, j;
3017
3018 for (i = 0; i < supp_rates_len; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003019 int rate = supp_rates[i] & 0x7f;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003020 bool is_basic = !!(supp_rates[i] & 0x80);
3021
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003022 if ((rate * 5 * (1 << shift)) > 110)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003023 *have_higher_than_11mbit = true;
3024
3025 /*
Johannes Berga6289d32017-03-06 22:59:04 +01003026 * Skip HT and VHT BSS membership selectors since they're not
3027 * rates.
Christian Lamparterc74d0842011-10-15 00:14:49 +02003028 *
Johannes Berga6289d32017-03-06 22:59:04 +01003029 * Note: Even though the membership selector and the basic
Christian Lamparterc74d0842011-10-15 00:14:49 +02003030 * rate flag share the same bit, they are not exactly
3031 * the same.
3032 */
Johannes Berga6289d32017-03-06 22:59:04 +01003033 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3034 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
Christian Lamparterc74d0842011-10-15 00:14:49 +02003035 continue;
3036
3037 for (j = 0; j < sband->n_bitrates; j++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003038 struct ieee80211_rate *br;
3039 int brate;
3040
3041 br = &sband->bitrates[j];
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003042
3043 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3044 if (brate == rate) {
Christian Lamparterc74d0842011-10-15 00:14:49 +02003045 *rates |= BIT(j);
3046 if (is_basic)
3047 *basic_rates |= BIT(j);
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003048 if ((rate * 5) < *min_rate) {
3049 *min_rate = rate * 5;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003050 *min_rate_index = j;
3051 }
3052 break;
3053 }
3054 }
3055 }
3056}
Jiri Bencf0706e82007-05-05 11:45:53 -07003057
Johannes Berg66e67e42012-01-20 13:55:27 +01003058static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3059 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003060 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003061{
Johannes Berg46900292009-02-15 12:44:28 +01003062 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01003063 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01003064 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003065 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003066 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003067 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07003068 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02003069 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg35d865a2013-05-28 10:54:03 +02003070 const struct cfg80211_bss_ies *bss_ies = NULL;
3071 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
Johannes Bergae5eb022008-10-14 16:58:37 +02003072 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003073 int err;
Johannes Berg35d865a2013-05-28 10:54:03 +02003074 bool ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003075
Johannes Bergaf6b6372009-12-23 13:15:35 +01003076 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07003077
Jiri Bencf0706e82007-05-05 11:45:53 -07003078 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003079 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07003080
Johannes Bergc7c477b2017-12-01 13:50:51 +02003081 /*
3082 * The 5 MSB of the AID field are reserved
3083 * (802.11-2016 9.4.1.8 AID field)
3084 */
3085 aid &= 0x7ff;
Johannes Berg1dd84aa2007-10-10 12:03:41 +02003086
Johannes Berg05cb9102011-10-28 11:59:47 +02003087 ifmgd->broken_ap = false;
3088
3089 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003090 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3091 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02003092 aid = 0;
3093 ifmgd->broken_ap = true;
3094 }
3095
Johannes Bergaf6b6372009-12-23 13:15:35 +01003096 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01003097 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003098
Jiri Bencf0706e82007-05-05 11:45:53 -07003099 if (!elems.supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003100 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01003101 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07003102 }
3103
Johannes Berg46900292009-02-15 12:44:28 +01003104 ifmgd->aid = aid;
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02003105 ifmgd->tdls_chan_switch_prohibited =
3106 elems.ext_capab && elems.ext_capab_len >= 5 &&
3107 (elems.ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
Jiri Bencf0706e82007-05-05 11:45:53 -07003108
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003109 /*
Johannes Berg35d865a2013-05-28 10:54:03 +02003110 * Some APs are erroneously not including some information in their
3111 * (re)association response frames. Try to recover by using the data
3112 * from the beacon or probe response. This seems to afflict mobile
3113 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3114 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3115 */
3116 if ((assoc_data->wmm && !elems.wmm_param) ||
3117 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3118 (!elems.ht_cap_elem || !elems.ht_operation)) ||
3119 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3120 (!elems.vht_cap_elem || !elems.vht_operation))) {
3121 const struct cfg80211_bss_ies *ies;
3122 struct ieee802_11_elems bss_elems;
3123
3124 rcu_read_lock();
3125 ies = rcu_dereference(cbss->ies);
3126 if (ies)
3127 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3128 GFP_ATOMIC);
3129 rcu_read_unlock();
3130 if (!bss_ies)
3131 return false;
3132
3133 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3134 false, &bss_elems);
3135 if (assoc_data->wmm &&
3136 !elems.wmm_param && bss_elems.wmm_param) {
3137 elems.wmm_param = bss_elems.wmm_param;
3138 sdata_info(sdata,
3139 "AP bug: WMM param missing from AssocResp\n");
3140 }
3141
3142 /*
3143 * Also check if we requested HT/VHT, otherwise the AP doesn't
3144 * have to include the IEs in the (re)association response.
3145 */
3146 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
3147 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3148 elems.ht_cap_elem = bss_elems.ht_cap_elem;
3149 sdata_info(sdata,
3150 "AP bug: HT capability missing from AssocResp\n");
3151 }
3152 if (!elems.ht_operation && bss_elems.ht_operation &&
3153 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3154 elems.ht_operation = bss_elems.ht_operation;
3155 sdata_info(sdata,
3156 "AP bug: HT operation missing from AssocResp\n");
3157 }
3158 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
3159 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3160 elems.vht_cap_elem = bss_elems.vht_cap_elem;
3161 sdata_info(sdata,
3162 "AP bug: VHT capa missing from AssocResp\n");
3163 }
3164 if (!elems.vht_operation && bss_elems.vht_operation &&
3165 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3166 elems.vht_operation = bss_elems.vht_operation;
3167 sdata_info(sdata,
3168 "AP bug: VHT operation missing from AssocResp\n");
3169 }
3170 }
3171
3172 /*
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003173 * We previously checked these in the beacon/probe response, so
3174 * they should be present here. This is just a safety net.
3175 */
3176 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3177 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
3178 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003179 "HT AP is missing WMM params or HT capability/operation\n");
3180 ret = false;
3181 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003182 }
3183
3184 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3185 (!elems.vht_cap_elem || !elems.vht_operation)) {
3186 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003187 "VHT AP is missing VHT capability/operation\n");
3188 ret = false;
3189 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003190 }
3191
Guy Eilam2a33bee2011-08-17 15:18:15 +03003192 mutex_lock(&sdata->local->sta_mtx);
3193 /*
3194 * station info was already allocated and inserted before
3195 * the association and should be available to us
3196 */
Johannes Berg7852e362012-01-20 13:55:24 +01003197 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003198 if (WARN_ON(!sta)) {
3199 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003200 ret = false;
3201 goto out;
Jiri Bencf0706e82007-05-05 11:45:53 -07003202 }
3203
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05303204 sband = ieee80211_get_sband(sdata);
3205 if (!sband) {
3206 mutex_unlock(&sdata->local->sta_mtx);
3207 ret = false;
3208 goto out;
3209 }
Johannes Berg8318d782008-01-24 19:38:38 +01003210
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003211 /*
3212 * If AP doesn't support HT, or it doesn't have HE mandatory IEs, mark
3213 * HE as disabled. If on the 5GHz band, make sure it supports VHT.
3214 */
3215 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
3216 (sband->band == NL80211_BAND_5GHZ &&
3217 ifmgd->flags & IEEE80211_STA_DISABLE_VHT) ||
3218 (!elems.he_cap && !elems.he_operation))
3219 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
3220
3221 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3222 (!elems.he_cap || !elems.he_operation)) {
3223 mutex_unlock(&sdata->local->sta_mtx);
3224 sdata_info(sdata,
3225 "HE AP is missing HE capability/operation\n");
3226 ret = false;
3227 goto out;
3228 }
3229
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003230 /* Set up internal HT/VHT capabilities */
Johannes Berga8243b72012-11-22 14:32:09 +01003231 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08003232 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01003233 elems.ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02003234
Mahesh Palivela818255e2012-10-10 11:33:04 +00003235 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3236 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01003237 elems.vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00003238
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003239 if (elems.he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3240 elems.he_cap) {
3241 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3242 elems.he_cap,
3243 elems.he_cap_len,
3244 sta);
3245
3246 bss_conf->he_support = sta->sta.he_cap.has_he;
3247 } else {
3248 bss_conf->he_support = false;
3249 }
3250
3251 if (bss_conf->he_support) {
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003252 bss_conf->bss_color =
3253 le32_get_bits(elems.he_operation->he_oper_params,
3254 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003255
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003256 bss_conf->htc_trig_based_pkt_ext =
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003257 le32_get_bits(elems.he_operation->he_oper_params,
3258 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003259 bss_conf->frame_time_rts_th =
Naftali Goldstein77cbbc32018-09-05 08:06:07 +03003260 le32_get_bits(elems.he_operation->he_oper_params,
3261 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003262
3263 bss_conf->multi_sta_back_32bit =
3264 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3265 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
3266
3267 bss_conf->ack_enabled =
3268 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3269 IEEE80211_HE_MAC_CAP2_ACK_EN;
3270
3271 bss_conf->uora_exists = !!elems.uora_element;
3272 if (elems.uora_element)
3273 bss_conf->uora_ocw_range = elems.uora_element[0];
3274
3275 /* TODO: OPEN: what happens if BSS color disable is set? */
3276 }
3277
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003278 /*
3279 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3280 * in their association response, so ignore that data for our own
3281 * configuration. If it changed since the last beacon, we'll get the
3282 * next beacon and update then.
3283 */
Johannes Berg11289582013-02-07 17:36:12 +01003284
Johannes Bergbee7f5862013-02-07 22:24:55 +01003285 /*
3286 * If an operating mode notification IE is present, override the
3287 * NSS calculation (that would be done in rate_control_rate_init())
3288 * and use the # of streams from that element.
3289 */
3290 if (elems.opmode_notif &&
3291 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3292 u8 nss;
3293
3294 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3295 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3296 nss += 1;
3297 sta->sta.rx_nss = nss;
3298 }
3299
Johannes Berg4b7679a2008-09-18 18:14:18 +02003300 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003301
Tamizh chelvam93f04902015-10-07 10:40:04 +05303302 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003303 set_sta_flag(sta, WLAN_STA_MFP);
Tamizh chelvam93f04902015-10-07 10:40:04 +05303304 sta->sta.mfp = true;
3305 } else {
3306 sta->sta.mfp = false;
3307 }
Jouni Malinen5394af42009-01-08 13:31:59 +02003308
Johannes Berg527871d2015-03-21 08:09:55 +01003309 sta->sta.wme = elems.wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
Johannes Bergddf4ac52008-10-22 11:41:38 +02003310
Johannes Berg3e4d40f2013-02-07 17:19:08 +01003311 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01003312 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3313 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3314 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003315 sdata_info(sdata,
3316 "failed to move station %pM to desired state\n",
3317 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01003318 WARN_ON(__sta_info_destroy(sta));
3319 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003320 ret = false;
3321 goto out;
Johannes Bergc8987872012-01-20 13:55:17 +01003322 }
3323
Johannes Berg7852e362012-01-20 13:55:24 +01003324 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02003325
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003326 /*
3327 * Always handle WMM once after association regardless
3328 * of the first value the AP uses. Setting -1 here has
3329 * that effect because the AP values is an unsigned
3330 * 4-bit value.
3331 */
3332 ifmgd->wmm_last_param_set = -1;
3333
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003334 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Bergcec66282015-10-22 17:46:04 +02003335 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003336 } else if (!ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003337 elems.wmm_param_len,
3338 elems.mu_edca_param_set)) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003339 /* still enable QoS since we might have HT/VHT */
3340 ieee80211_set_wmm_default(sdata, false, true);
3341 /* set the disable-WMM flag in this case to disable
3342 * tracking WMM parameter changes in the beacon if
3343 * the parameters weren't actually valid. Doing so
3344 * avoids changing parameters very strangely when
3345 * the AP is going back and forth between valid and
3346 * invalid parameters.
3347 */
3348 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3349 }
Johannes Berg3abead52012-03-02 15:56:59 +01003350 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07003351
Avraham Sterne38a0172017-04-26 10:58:47 +03003352 if (elems.max_idle_period_ie) {
3353 bss_conf->max_idle_period =
3354 le16_to_cpu(elems.max_idle_period_ie->max_idle_period);
3355 bss_conf->protected_keep_alive =
3356 !!(elems.max_idle_period_ie->idle_options &
3357 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3358 changed |= BSS_CHANGED_KEEP_ALIVE;
3359 } else {
3360 bss_conf->max_idle_period = 0;
3361 bss_conf->protected_keep_alive = false;
3362 }
3363
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003364 /* set AID and assoc capability,
3365 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01003366 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003367 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003368 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003369
Kalle Valo15b7b062009-03-22 21:57:14 +02003370 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01003371 * If we're using 4-addr mode, let the AP know that we're
3372 * doing so, so that it can create the STA VLAN on its side
3373 */
3374 if (ifmgd->use_4addr)
3375 ieee80211_send_4addr_nullfunc(local, sdata);
3376
3377 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02003378 * Start timer to probe the connection to the AP now.
3379 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02003380 */
Johannes Bergb291ba12009-07-10 15:29:03 +02003381 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003382 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02003383
Johannes Berg35d865a2013-05-28 10:54:03 +02003384 ret = true;
3385 out:
3386 kfree(bss_ies);
3387 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003388}
3389
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003390static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3391 struct ieee80211_mgmt *mgmt,
3392 size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01003393{
3394 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3395 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3396 u16 capab_info, status_code, aid;
3397 struct ieee802_11_elems elems;
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003398 int ac, uapsd_queues = -1;
Johannes Berg66e67e42012-01-20 13:55:27 +01003399 u8 *pos;
3400 bool reassoc;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003401 struct cfg80211_bss *bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003402 struct ieee80211_event event = {
3403 .type = MLME_EVENT,
3404 .u.mlme.data = ASSOC_EVENT,
3405 };
Jiri Bencf0706e82007-05-05 11:45:53 -07003406
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003407 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003408
3409 if (!assoc_data)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003410 return;
Joe Perchesb203ca32012-05-08 18:56:52 +00003411 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003412 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003413
3414 /*
3415 * AssocResp and ReassocResp have identical structure, so process both
3416 * of them in this function.
3417 */
3418
3419 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003420 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003421
Simon Dinkin7a7d3e42017-08-31 13:09:36 +03003422 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
Johannes Berg66e67e42012-01-20 13:55:27 +01003423 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3424 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3425 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3426
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003427 sdata_info(sdata,
3428 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3429 reassoc ? "Rea" : "A", mgmt->sa,
3430 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01003431
Jouni Malinen39404fe2016-10-27 00:42:05 +03003432 if (assoc_data->fils_kek_len &&
3433 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3434 return;
3435
Johannes Berg66e67e42012-01-20 13:55:27 +01003436 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01003437 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01003438
3439 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01003440 elems.timeout_int &&
3441 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003442 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01003443 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01003444 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003445 sdata_info(sdata,
3446 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3447 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01003448 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01003449 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01003450 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003451 run_again(sdata, assoc_data->timeout);
3452 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003453 }
3454
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003455 bss = assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01003456
3457 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003458 sdata_info(sdata, "%pM denied association (code=%d)\n",
3459 mgmt->sa, status_code);
Johannes Berge6f462d2016-12-08 17:22:09 +01003460 ieee80211_destroy_assoc_data(sdata, false, false);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003461 event.u.mlme.status = MLME_DENIED;
3462 event.u.mlme.reason = status_code;
3463 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01003464 } else {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003465 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003466 /* oops -- internal error -- send timeout for now */
Johannes Berge6f462d2016-12-08 17:22:09 +01003467 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02003468 cfg80211_assoc_timeout(sdata->dev, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003469 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003470 }
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003471 event.u.mlme.status = MLME_SUCCESS;
3472 drv_event_callback(sdata->local, sdata, &event);
John W. Linville635d9992012-07-09 16:34:34 -04003473 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01003474
3475 /*
3476 * destroy assoc_data afterwards, as otherwise an idle
3477 * recalc after assoc_data is NULL but before associated
3478 * is set can cause the interface to go idle
3479 */
Johannes Berge6f462d2016-12-08 17:22:09 +01003480 ieee80211_destroy_assoc_data(sdata, true, false);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003481
3482 /* get uapsd queues configuration */
3483 uapsd_queues = 0;
3484 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3485 if (sdata->tx_conf[ac].uapsd)
Emmanuel Grumbachf438ceb2016-10-18 23:12:12 +03003486 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
Johannes Berg66e67e42012-01-20 13:55:27 +01003487 }
3488
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003489 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues);
Johannes Berg66e67e42012-01-20 13:55:27 +01003490}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003491
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003492static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003493 struct ieee80211_mgmt *mgmt, size_t len,
Jiri Bencf0706e82007-05-05 11:45:53 -07003494 struct ieee80211_rx_status *rx_status,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003495 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07003496{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003497 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02003498 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01003499 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01003500
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003501 sdata_assert_lock(sdata);
Johannes Bergb4f286a12013-03-26 14:13:58 +01003502
Emmanuel Grumbach3afc2162014-03-04 16:50:13 +02003503 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3504 if (!channel)
Johannes Berg5bda6172008-09-08 11:05:10 +02003505 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003506
Johannes Berg98c8fcc2008-09-08 17:44:26 +02003507 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003508 channel);
Alexander Bondar817cee72013-05-19 14:23:57 +03003509 if (bss) {
Alexander Bondar817cee72013-05-19 14:23:57 +03003510 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
Johannes Bergd2722f82014-03-04 11:43:28 +01003511 ieee80211_rx_bss_put(local, bss);
Alexander Bondar817cee72013-05-19 14:23:57 +03003512 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003513}
3514
3515
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003516static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003517 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003518{
Johannes Bergaf6b6372009-12-23 13:15:35 +01003519 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02003520 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003521 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3522 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03003523 struct ieee802_11_elems elems;
3524
Kalle Valo15b7b062009-03-22 21:57:14 +02003525 ifmgd = &sdata->u.mgd;
3526
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003527 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003528
Joe Perchesb203ca32012-05-08 18:56:52 +00003529 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03003530 return; /* ignore ProbeResp to foreign address */
3531
Ester Kummerae6a44e2008-06-27 18:54:48 +03003532 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3533 if (baselen > len)
3534 return;
3535
3536 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003537 false, &elems);
Ester Kummerae6a44e2008-06-27 18:54:48 +03003538
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003539 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03003540
Johannes Berg77fdaa12009-07-07 03:45:17 +02003541 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003542 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003543 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003544}
3545
Johannes Bergd91f36d2009-04-16 13:17:26 +02003546/*
3547 * This is the canonical list of information elements we care about,
3548 * the filter code also gives us all changes to the Microsoft OUI
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003549 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3550 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3551 * changes to requested client power.
Johannes Bergd91f36d2009-04-16 13:17:26 +02003552 *
3553 * We implement beacon filtering in software since that means we can
3554 * avoid processing the frame here and in cfg80211, and userspace
3555 * will not be able to tell whether the hardware supports it or not.
3556 *
3557 * XXX: This list needs to be dynamic -- userspace needs to be able to
3558 * add items it requires. It also needs to be able to tell us to
3559 * look out for other vendor IEs.
3560 */
3561static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02003562 (1ULL << WLAN_EID_COUNTRY) |
3563 (1ULL << WLAN_EID_ERP_INFO) |
3564 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3565 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3566 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg70a3fd62015-03-12 08:53:29 +02003567 (1ULL << WLAN_EID_HT_OPERATION) |
3568 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003569
Tosoni1ad22fb2018-03-14 16:58:34 +00003570static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3571 struct ieee80211_if_managed *ifmgd,
3572 struct ieee80211_bss_conf *bss_conf,
3573 struct ieee80211_local *local,
3574 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003575{
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003576 /* Track average RSSI from the Beacon frames of the current AP */
Tosoni1ad22fb2018-03-14 16:58:34 +00003577
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003578 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3579 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Johannes Berg338c17a2015-08-28 10:52:54 +02003580 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003581 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03003582 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003583 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003584 } else {
Jouni Malinen391a2002010-08-27 22:22:00 +03003585 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003586 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003587
Johannes Berg338c17a2015-08-28 10:52:54 +02003588 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3589
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003590 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3591 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003592 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003593 int last_sig = ifmgd->last_ave_beacon_signal;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003594 struct ieee80211_event event = {
3595 .type = RSSI_EVENT,
3596 };
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003597
3598 /*
3599 * if signal crosses either of the boundaries, invoke callback
3600 * with appropriate parameters
3601 */
3602 if (sig > ifmgd->rssi_max_thold &&
3603 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3604 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003605 event.u.rssi.data = RSSI_EVENT_HIGH;
3606 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003607 } else if (sig < ifmgd->rssi_min_thold &&
3608 (last_sig >= ifmgd->rssi_max_thold ||
3609 last_sig == 0)) {
3610 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003611 event.u.rssi.data = RSSI_EVENT_LOW;
3612 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003613 }
3614 }
3615
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003616 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03003617 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01003618 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003619 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003620 int last_event = ifmgd->last_cqm_event_signal;
3621 int thold = bss_conf->cqm_rssi_thold;
3622 int hyst = bss_conf->cqm_rssi_hyst;
Johannes Berg338c17a2015-08-28 10:52:54 +02003623
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003624 if (sig < thold &&
3625 (last_event == 0 || sig < last_event - hyst)) {
3626 ifmgd->last_cqm_event_signal = sig;
3627 ieee80211_cqm_rssi_notify(
3628 &sdata->vif,
3629 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003630 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003631 } else if (sig > thold &&
3632 (last_event == 0 || sig > last_event + hyst)) {
3633 ifmgd->last_cqm_event_signal = sig;
3634 ieee80211_cqm_rssi_notify(
3635 &sdata->vif,
3636 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003637 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003638 }
3639 }
3640
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003641 if (bss_conf->cqm_rssi_low &&
3642 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3643 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3644 int last_event = ifmgd->last_cqm_event_signal;
3645 int low = bss_conf->cqm_rssi_low;
3646 int high = bss_conf->cqm_rssi_high;
3647
3648 if (sig < low &&
3649 (last_event == 0 || last_event >= low)) {
3650 ifmgd->last_cqm_event_signal = sig;
3651 ieee80211_cqm_rssi_notify(
3652 &sdata->vif,
3653 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3654 sig, GFP_KERNEL);
3655 } else if (sig > high &&
3656 (last_event == 0 || last_event <= high)) {
3657 ifmgd->last_cqm_event_signal = sig;
3658 ieee80211_cqm_rssi_notify(
3659 &sdata->vif,
3660 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3661 sig, GFP_KERNEL);
3662 }
3663 }
Tosoni1ad22fb2018-03-14 16:58:34 +00003664}
3665
3666static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3667 struct ieee80211_mgmt *mgmt, size_t len,
3668 struct ieee80211_rx_status *rx_status)
3669{
3670 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3671 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3672 size_t baselen;
3673 struct ieee802_11_elems elems;
3674 struct ieee80211_local *local = sdata->local;
3675 struct ieee80211_chanctx_conf *chanctx_conf;
3676 struct ieee80211_channel *chan;
3677 struct sta_info *sta;
3678 u32 changed = 0;
3679 bool erp_valid;
3680 u8 erp_value = 0;
3681 u32 ncrc;
3682 u8 *bssid;
3683 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3684
3685 sdata_assert_lock(sdata);
3686
3687 /* Process beacon from the current BSS */
3688 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3689 if (baselen > len)
3690 return;
3691
3692 rcu_read_lock();
3693 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3694 if (!chanctx_conf) {
3695 rcu_read_unlock();
3696 return;
3697 }
3698
3699 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3700 rcu_read_unlock();
3701 return;
3702 }
3703 chan = chanctx_conf->def.chan;
3704 rcu_read_unlock();
3705
3706 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
3707 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3708 ieee802_11_parse_elems(mgmt->u.beacon.variable,
3709 len - baselen, false, &elems);
3710
3711 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3712 if (elems.tim && !elems.parse_error) {
3713 const struct ieee80211_tim_ie *tim_ie = elems.tim;
3714 ifmgd->dtim_period = tim_ie->dtim_period;
3715 }
3716 ifmgd->have_beacon = true;
3717 ifmgd->assoc_data->need_beacon = false;
3718 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3719 sdata->vif.bss_conf.sync_tsf =
3720 le64_to_cpu(mgmt->u.beacon.timestamp);
3721 sdata->vif.bss_conf.sync_device_ts =
3722 rx_status->device_timestamp;
3723 if (elems.tim)
3724 sdata->vif.bss_conf.sync_dtim_count =
3725 elems.tim->dtim_count;
3726 else
3727 sdata->vif.bss_conf.sync_dtim_count = 0;
3728 }
3729 /* continue assoc process */
3730 ifmgd->assoc_data->timeout = jiffies;
3731 ifmgd->assoc_data->timeout_started = true;
3732 run_again(sdata, ifmgd->assoc_data->timeout);
3733 return;
3734 }
3735
3736 if (!ifmgd->associated ||
3737 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3738 return;
3739 bssid = ifmgd->associated->bssid;
3740
3741 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3742 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
3743 local, rx_status);
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003744
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003745 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003746 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01003747 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003748 ieee80211_reset_ap_probe(sdata);
Jouni Malinen92778182009-05-14 21:15:36 +03003749 }
3750
Johannes Bergb291ba12009-07-10 15:29:03 +02003751 /*
3752 * Push the beacon loss detection into the future since
3753 * we are processing a beacon from the AP just now.
3754 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003755 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003756
Johannes Bergd91f36d2009-04-16 13:17:26 +02003757 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3758 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003759 len - baselen, false, &elems,
Johannes Bergd91f36d2009-04-16 13:17:26 +02003760 care_about_ies, ncrc);
3761
Johannes Berg90d13e82015-09-24 16:13:07 +02003762 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3763 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3764 if (local->hw.conf.dynamic_ps_timeout > 0) {
3765 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3766 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3767 ieee80211_hw_config(local,
3768 IEEE80211_CONF_CHANGE_PS);
Kalle Valo572e0012009-02-10 17:09:31 +02003769 }
Johannes Berg076cdcb2015-09-24 16:14:55 +02003770 ieee80211_send_nullfunc(local, sdata, false);
Johannes Berg90d13e82015-09-24 16:13:07 +02003771 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3772 local->pspolling = true;
3773
3774 /*
3775 * Here is assumed that the driver will be
3776 * able to send ps-poll frame and receive a
3777 * response even though power save mode is
3778 * enabled, but some drivers might require
3779 * to disable power save here. This needs
3780 * to be investigated.
3781 */
3782 ieee80211_send_pspoll(local, sdata);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003783 }
3784 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003785
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01003786 if (sdata->vif.p2p ||
3787 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003788 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003789 int ret;
3790
3791 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3792 len - baselen,
3793 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003794 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003795 if (ret >= 2) {
3796 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3797 /* valid noa_attr and index changed */
3798 sdata->u.mgd.p2p_noa_index = noa.index;
3799 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3800 changed |= BSS_CHANGED_P2P_PS;
3801 /*
3802 * make sure we update all information, the CRC
3803 * mechanism doesn't look at P2P attributes.
3804 */
3805 ifmgd->beacon_crc_valid = false;
3806 }
3807 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3808 /* noa_attr not found and we had valid noa_attr before */
3809 sdata->u.mgd.p2p_noa_index = -1;
3810 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003811 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003812 ifmgd->beacon_crc_valid = false;
3813 }
3814 }
3815
Luciano Coelho0c21e632014-10-08 09:48:39 +03003816 if (ifmgd->csa_waiting_bcn)
3817 ieee80211_chswitch_post_beacon(sdata);
3818
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003819 /*
3820 * Update beacon timing and dtim count on every beacon appearance. This
3821 * will allow the driver to use the most updated values. Do it before
3822 * comparing this one with last received beacon.
3823 * IMPORTANT: These parameters would possibly be out of sync by the time
3824 * the driver will use them. The synchronized view is currently
3825 * guaranteed only in certain callbacks.
3826 */
Johannes Berg30686bf2015-06-02 21:39:54 +02003827 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003828 sdata->vif.bss_conf.sync_tsf =
3829 le64_to_cpu(mgmt->u.beacon.timestamp);
3830 sdata->vif.bss_conf.sync_device_ts =
3831 rx_status->device_timestamp;
3832 if (elems.tim)
3833 sdata->vif.bss_conf.sync_dtim_count =
3834 elems.tim->dtim_count;
3835 else
3836 sdata->vif.bss_conf.sync_dtim_count = 0;
3837 }
3838
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003839 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003840 return;
Jouni Malinen30196672009-05-19 17:01:43 +03003841 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003842 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03003843
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003844 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg7d257452012-07-06 17:37:43 +02003845
Johannes Bergd70b7612013-08-23 15:48:48 +02003846 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003847 rx_status->device_timestamp,
Johannes Bergd70b7612013-08-23 15:48:48 +02003848 &elems, true);
3849
Johannes Berg095d81c2013-10-15 12:25:07 +02003850 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
3851 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003852 elems.wmm_param_len,
3853 elems.mu_edca_param_set))
Johannes Berg7d257452012-07-06 17:37:43 +02003854 changed |= BSS_CHANGED_QOS;
3855
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003856 /*
3857 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01003858 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003859 */
Alexander Bondar989c6502013-05-16 17:34:17 +03003860 if (!ifmgd->have_beacon) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003861 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3862 if (elems.tim)
3863 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3864 else
3865 bss_conf->dtim_period = 1;
Johannes Bergef429da2013-02-05 17:48:40 +01003866
Alexander Bondar989c6502013-05-16 17:34:17 +03003867 changed |= BSS_CHANGED_BEACON_INFO;
3868 ifmgd->have_beacon = true;
Alexander Bondar482a9c72013-06-03 17:29:33 +03003869
3870 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02003871 ieee80211_recalc_ps(local);
Alexander Bondar482a9c72013-06-03 17:29:33 +03003872 mutex_unlock(&local->iflist_mtx);
3873
Alexander Bondarce857882013-05-06 17:17:04 +03003874 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003875 }
3876
Johannes Berg1946bed2013-03-27 14:31:53 +01003877 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02003878 erp_valid = true;
3879 erp_value = elems.erp_info[0];
3880 } else {
3881 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04003882 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003883 changed |= ieee80211_handle_bss_capability(sdata,
3884 le16_to_cpu(mgmt->u.beacon.capab_info),
3885 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07003886
Johannes Berg11289582013-02-07 17:36:12 +01003887 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f5862013-02-07 22:24:55 +01003888 sta = sta_info_get(sdata, bssid);
3889
Eliad Peller53b954e2014-07-24 11:20:05 +03003890 if (ieee80211_config_bw(sdata, sta,
3891 elems.ht_cap_elem, elems.ht_operation,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003892 elems.vht_operation, elems.he_operation,
3893 bssid, &changed)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003894 mutex_unlock(&local->sta_mtx);
Johannes Berg89f774e2016-01-25 15:46:36 +02003895 sdata_info(sdata,
3896 "failed to follow AP %pM bandwidth change, disconnect\n",
3897 bssid);
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003898 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3899 WLAN_REASON_DEAUTH_LEAVING,
3900 true, deauth_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003901 ieee80211_report_disconnect(sdata, deauth_buf,
3902 sizeof(deauth_buf), true,
3903 WLAN_REASON_DEAUTH_LEAVING);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003904 return;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003905 }
Johannes Bergbee7f5862013-02-07 22:24:55 +01003906
3907 if (sta && elems.opmode_notif)
3908 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
Eyal Shapiracf1e05c2015-12-08 16:04:36 +02003909 rx_status->band);
Johannes Berg11289582013-02-07 17:36:12 +01003910 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003911
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07003912 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
3913 elems.country_elem,
3914 elems.country_elem_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003915 elems.pwr_constr_elem,
3916 elems.cisco_dtpc_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08003917
Johannes Berg471b3ef2007-12-28 14:32:58 +01003918 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003919}
3920
Johannes Berg1fa57d02010-06-10 10:21:32 +02003921void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3922 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003923{
3924 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07003925 struct ieee80211_mgmt *mgmt;
3926 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003927 struct ieee802_11_elems elems;
3928 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07003929
Jiri Bencf0706e82007-05-05 11:45:53 -07003930 rx_status = (struct ieee80211_rx_status *) skb->cb;
3931 mgmt = (struct ieee80211_mgmt *) skb->data;
3932 fc = le16_to_cpu(mgmt->frame_control);
3933
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003934 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003935
Johannes Berg66e67e42012-01-20 13:55:27 +01003936 switch (fc & IEEE80211_FCTL_STYPE) {
3937 case IEEE80211_STYPE_BEACON:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003938 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01003939 break;
3940 case IEEE80211_STYPE_PROBE_RESP:
3941 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3942 break;
3943 case IEEE80211_STYPE_AUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003944 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003945 break;
3946 case IEEE80211_STYPE_DEAUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003947 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003948 break;
3949 case IEEE80211_STYPE_DISASSOC:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003950 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003951 break;
3952 case IEEE80211_STYPE_ASSOC_RESP:
3953 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003954 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003955 break;
3956 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01003957 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003958 ies_len = skb->len -
3959 offsetof(struct ieee80211_mgmt,
3960 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01003961
3962 if (ies_len < 0)
3963 break;
3964
3965 ieee802_11_parse_elems(
3966 mgmt->u.action.u.chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003967 ies_len, true, &elems);
Johannes Berg37799e52013-03-26 14:02:26 +01003968
3969 if (elems.parse_error)
3970 break;
3971
Johannes Berg66e67e42012-01-20 13:55:27 +01003972 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003973 rx_status->mactime,
3974 rx_status->device_timestamp,
3975 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003976 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3977 ies_len = skb->len -
3978 offsetof(struct ieee80211_mgmt,
3979 u.action.u.ext_chan_switch.variable);
3980
3981 if (ies_len < 0)
3982 break;
3983
3984 ieee802_11_parse_elems(
3985 mgmt->u.action.u.ext_chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003986 ies_len, true, &elems);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003987
3988 if (elems.parse_error)
3989 break;
3990
3991 /* for the handling code pretend this was also an IE */
3992 elems.ext_chansw_ie =
3993 &mgmt->u.action.u.ext_chan_switch.data;
3994
3995 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003996 rx_status->mactime,
3997 rx_status->device_timestamp,
3998 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003999 }
Johannes Berg37799e52013-03-26 14:02:26 +01004000 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004001 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004002 sdata_unlock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07004003}
4004
Kees Cook34f11cd2017-10-16 16:35:49 -07004005static void ieee80211_sta_timer(struct timer_list *t)
Jiri Bencf0706e82007-05-05 11:45:53 -07004006{
4007 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004008 from_timer(sdata, t, u.mgd.timer);
Jiri Bencf0706e82007-05-05 11:45:53 -07004009
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01004010 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07004011}
4012
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004013static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01004014 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004015{
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004016 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004017
Johannes Berg37ad3882012-02-24 13:50:54 +01004018 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01004019 tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01004020
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004021 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4022 reason);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004023}
4024
Johannes Berg46cad4b2015-08-15 22:39:54 +03004025static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg66e67e42012-01-20 13:55:27 +01004026{
4027 struct ieee80211_local *local = sdata->local;
4028 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4029 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004030 u32 tx_flags = 0;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004031 u16 trans = 1;
4032 u16 status = 0;
Ilan Peerd4e36e52018-04-20 13:49:25 +03004033 u16 prepare_tx_duration = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004034
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004035 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004036
4037 if (WARN_ON_ONCE(!auth_data))
4038 return -EINVAL;
4039
Johannes Berg66e67e42012-01-20 13:55:27 +01004040 auth_data->tries++;
4041
4042 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004043 sdata_info(sdata, "authentication with %pM timed out\n",
4044 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004045
4046 /*
4047 * Most likely AP is not in the range so remove the
4048 * bss struct for that AP.
4049 */
4050 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4051
4052 return -ETIMEDOUT;
4053 }
4054
Ilan Peerd4e36e52018-04-20 13:49:25 +03004055 if (auth_data->algorithm == WLAN_AUTH_SAE)
4056 prepare_tx_duration =
4057 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4058
4059 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
Johannes Berga1845fc2012-06-27 13:18:36 +02004060
Johannes Berg46cad4b2015-08-15 22:39:54 +03004061 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4062 auth_data->bss->bssid, auth_data->tries,
4063 IEEE80211_AUTH_MAX_TRIES);
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004064
Johannes Berg46cad4b2015-08-15 22:39:54 +03004065 auth_data->expected_transaction = 2;
Johannes Berg66e67e42012-01-20 13:55:27 +01004066
Johannes Berg46cad4b2015-08-15 22:39:54 +03004067 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4068 trans = auth_data->sae_trans;
4069 status = auth_data->sae_status;
4070 auth_data->expected_transaction = trans;
Johannes Berg66e67e42012-01-20 13:55:27 +01004071 }
4072
Johannes Berg46cad4b2015-08-15 22:39:54 +03004073 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4074 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4075 IEEE80211_TX_INTFL_MLME_CONN_TX;
4076
4077 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4078 auth_data->data, auth_data->data_len,
4079 auth_data->bss->bssid,
4080 auth_data->bss->bssid, NULL, 0, 0,
4081 tx_flags);
4082
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02004083 if (tx_flags == 0) {
Ilan Peer407879b2018-04-20 13:49:20 +03004084 if (auth_data->algorithm == WLAN_AUTH_SAE)
4085 auth_data->timeout = jiffies +
4086 IEEE80211_AUTH_TIMEOUT_SAE;
4087 else
4088 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004089 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004090 auth_data->timeout =
4091 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004092 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004093
Ilan Peer407879b2018-04-20 13:49:20 +03004094 auth_data->timeout_started = true;
4095 run_again(sdata, auth_data->timeout);
4096
Johannes Berg66e67e42012-01-20 13:55:27 +01004097 return 0;
4098}
4099
4100static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4101{
4102 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4103 struct ieee80211_local *local = sdata->local;
4104
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004105 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004106
Johannes Berg66e67e42012-01-20 13:55:27 +01004107 assoc_data->tries++;
4108 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004109 sdata_info(sdata, "association with %pM timed out\n",
4110 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004111
4112 /*
4113 * Most likely AP is not in the range so remove the
4114 * bss struct for that AP.
4115 */
4116 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4117
4118 return -ETIMEDOUT;
4119 }
4120
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004121 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4122 assoc_data->bss->bssid, assoc_data->tries,
4123 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01004124 ieee80211_send_assoc(sdata);
4125
Johannes Berg30686bf2015-06-02 21:39:54 +02004126 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004127 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004128 assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004129 run_again(sdata, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01004130 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004131 assoc_data->timeout =
4132 round_jiffies_up(jiffies +
4133 IEEE80211_ASSOC_TIMEOUT_LONG);
4134 assoc_data->timeout_started = true;
4135 run_again(sdata, assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004136 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004137
4138 return 0;
4139}
4140
Johannes Berg1672c0e32013-01-29 15:02:27 +01004141void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4142 __le16 fc, bool acked)
4143{
4144 struct ieee80211_local *local = sdata->local;
4145
4146 sdata->u.mgd.status_fc = fc;
4147 sdata->u.mgd.status_acked = acked;
4148 sdata->u.mgd.status_received = true;
4149
4150 ieee80211_queue_work(&local->hw, &sdata->work);
4151}
4152
Johannes Berg1fa57d02010-06-10 10:21:32 +02004153void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02004154{
Johannes Berg60f8b392008-09-08 17:44:22 +02004155 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02004156 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02004157
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004158 sdata_lock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02004159
Johannes Berg1672c0e32013-01-29 15:02:27 +01004160 if (ifmgd->status_received) {
4161 __le16 fc = ifmgd->status_fc;
4162 bool status_acked = ifmgd->status_acked;
4163
4164 ifmgd->status_received = false;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004165 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004166 if (status_acked) {
Ilan Peer407879b2018-04-20 13:49:20 +03004167 if (ifmgd->auth_data->algorithm ==
4168 WLAN_AUTH_SAE)
4169 ifmgd->auth_data->timeout =
4170 jiffies +
4171 IEEE80211_AUTH_TIMEOUT_SAE;
4172 else
4173 ifmgd->auth_data->timeout =
4174 jiffies +
4175 IEEE80211_AUTH_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004176 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004177 } else {
4178 ifmgd->auth_data->timeout = jiffies - 1;
4179 }
Johannes Berg89afe612013-02-13 15:39:57 +01004180 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004181 } else if (ifmgd->assoc_data &&
4182 (ieee80211_is_assoc_req(fc) ||
4183 ieee80211_is_reassoc_req(fc))) {
4184 if (status_acked) {
4185 ifmgd->assoc_data->timeout =
4186 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004187 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004188 } else {
4189 ifmgd->assoc_data->timeout = jiffies - 1;
4190 }
Johannes Berg89afe612013-02-13 15:39:57 +01004191 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004192 }
4193 }
4194
Johannes Berg89afe612013-02-13 15:39:57 +01004195 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004196 time_after(jiffies, ifmgd->auth_data->timeout)) {
4197 if (ifmgd->auth_data->done) {
4198 /*
4199 * ok ... we waited for assoc but userspace didn't,
4200 * so let's just kill the auth data
4201 */
4202 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg46cad4b2015-08-15 22:39:54 +03004203 } else if (ieee80211_auth(sdata)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004204 u8 bssid[ETH_ALEN];
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004205 struct ieee80211_event event = {
4206 .type = MLME_EVENT,
4207 .u.mlme.data = AUTH_EVENT,
4208 .u.mlme.status = MLME_TIMEOUT,
4209 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004210
4211 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4212
4213 ieee80211_destroy_auth_data(sdata, false);
4214
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004215 cfg80211_auth_timeout(sdata->dev, bssid);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004216 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004217 }
Johannes Berg89afe612013-02-13 15:39:57 +01004218 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004219 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004220
Johannes Berg89afe612013-02-13 15:39:57 +01004221 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004222 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Alexander Bondar989c6502013-05-16 17:34:17 +03004223 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01004224 ieee80211_do_assoc(sdata)) {
Johannes Berg959867f2013-06-19 13:05:42 +02004225 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004226 struct ieee80211_event event = {
4227 .type = MLME_EVENT,
4228 .u.mlme.data = ASSOC_EVENT,
4229 .u.mlme.status = MLME_TIMEOUT,
4230 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004231
Johannes Berge6f462d2016-12-08 17:22:09 +01004232 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02004233 cfg80211_assoc_timeout(sdata->dev, bss);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004234 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004235 }
Johannes Berg89afe612013-02-13 15:39:57 +01004236 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004237 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004238
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02004239 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
Johannes Bergb291ba12009-07-10 15:29:03 +02004240 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03004241 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004242 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03004243
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004244 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004245
Johannes Berg30686bf2015-06-02 21:39:54 +02004246 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Ben Greear180205b2011-02-04 15:30:24 -08004247 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004248 else
Ben Greear180205b2011-02-04 15:30:24 -08004249 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004250
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004251 /* ACK received for nullfunc probing frame */
4252 if (!ifmgd->probe_send_count)
4253 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004254 else if (ifmgd->nullfunc_failed) {
4255 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004256 mlme_dbg(sdata,
4257 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4258 bssid, ifmgd->probe_send_count,
4259 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004260 ieee80211_mgd_probe_ap_send(sdata);
4261 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004262 mlme_dbg(sdata,
4263 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4264 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02004265 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004266 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4267 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004268 }
4269 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004270 run_again(sdata, ifmgd->probe_timeout);
Johannes Berg30686bf2015-06-02 21:39:54 +02004271 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004272 mlme_dbg(sdata,
4273 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4274 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02004275 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004276 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004277 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004278 mlme_dbg(sdata,
4279 "No probe response from AP %pM after %dms, try %d/%i\n",
4280 bssid, probe_wait_ms,
4281 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03004282 ieee80211_mgd_probe_ap_send(sdata);
4283 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02004284 /*
4285 * We actually lost the connection ... or did we?
4286 * Let's make sure!
4287 */
Johannes Berg89f774e2016-01-25 15:46:36 +02004288 mlme_dbg(sdata,
4289 "No probe response from AP %pM after %dms, disconnecting.\n",
4290 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004291
Johannes Berg95acac62011-07-12 12:30:59 +02004292 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004293 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02004294 }
4295 }
4296
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004297 sdata_unlock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02004298}
Johannes Berg0a51b272008-09-08 17:44:25 +02004299
Kees Cook34f11cd2017-10-16 16:35:49 -07004300static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004301{
4302 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004303 from_timer(sdata, t, u.mgd.bcn_mon_timer);
Luciano Coelho0c21e632014-10-08 09:48:39 +03004304 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004305
Luciano Coelho0c21e632014-10-08 09:48:39 +03004306 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004307 return;
4308
Johannes Berg682bd382013-01-29 13:13:50 +01004309 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004310 ieee80211_queue_work(&sdata->local->hw,
4311 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004312}
4313
Kees Cook34f11cd2017-10-16 16:35:49 -07004314static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004315{
4316 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004317 from_timer(sdata, t, u.mgd.conn_mon_timer);
Johannes Bergb291ba12009-07-10 15:29:03 +02004318 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4319 struct ieee80211_local *local = sdata->local;
4320
Luciano Coelho0c21e632014-10-08 09:48:39 +03004321 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004322 return;
4323
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04004324 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004325}
4326
4327static void ieee80211_sta_monitor_work(struct work_struct *work)
4328{
4329 struct ieee80211_sub_if_data *sdata =
4330 container_of(work, struct ieee80211_sub_if_data,
4331 u.mgd.monitor_work);
4332
4333 ieee80211_mgd_probe_ap(sdata, false);
4334}
4335
Johannes Berga1678f82008-09-11 00:01:47 +02004336static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4337{
Kalle Vaload935682009-04-19 08:47:19 +03004338 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02004339 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03004340
Johannes Bergb291ba12009-07-10 15:29:03 +02004341 /* let's probe the connection once */
Johannes Berg30686bf2015-06-02 21:39:54 +02004342 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Eliad Peller494f1fe2012-02-19 15:26:09 +02004343 ieee80211_queue_work(&sdata->local->hw,
4344 &sdata->u.mgd.monitor_work);
Kalle Vaload935682009-04-19 08:47:19 +03004345 }
Johannes Berga1678f82008-09-11 00:01:47 +02004346}
4347
Johannes Bergb8360ab2013-04-29 14:57:44 +02004348#ifdef CONFIG_PM
Johannes Berg1a1cb742014-03-19 09:55:55 +01004349void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4350{
4351 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4352 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4353
4354 sdata_lock(sdata);
4355
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004356 if (ifmgd->auth_data || ifmgd->assoc_data) {
4357 const u8 *bssid = ifmgd->auth_data ?
4358 ifmgd->auth_data->bss->bssid :
4359 ifmgd->assoc_data->bss->bssid;
4360
Johannes Berg1a1cb742014-03-19 09:55:55 +01004361 /*
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004362 * If we are trying to authenticate / associate while suspending,
4363 * cfg80211 won't know and won't actually abort those attempts,
4364 * thus we need to do that ourselves.
Johannes Berg1a1cb742014-03-19 09:55:55 +01004365 */
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004366 ieee80211_send_deauth_disassoc(sdata, bssid,
Johannes Berg1a1cb742014-03-19 09:55:55 +01004367 IEEE80211_STYPE_DEAUTH,
4368 WLAN_REASON_DEAUTH_LEAVING,
4369 false, frame_buf);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004370 if (ifmgd->assoc_data)
Johannes Berge6f462d2016-12-08 17:22:09 +01004371 ieee80211_destroy_assoc_data(sdata, false, true);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004372 if (ifmgd->auth_data)
4373 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg1a1cb742014-03-19 09:55:55 +01004374 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4375 IEEE80211_DEAUTH_FRAME_LEN);
4376 }
4377
Johannes Bergbe72afe2015-03-01 09:10:03 +02004378 /* This is a bit of a hack - we should find a better and more generic
4379 * solution to this. Normally when suspending, cfg80211 will in fact
4380 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4381 * auth (not so important) or assoc (this is the problem) process.
4382 *
4383 * As a consequence, it can happen that we are in the process of both
4384 * associating and suspending, and receive an association response
4385 * after cfg80211 has checked if it needs to disconnect, but before
4386 * we actually set the flag to drop incoming frames. This will then
4387 * cause the workqueue flush to process the association response in
4388 * the suspend, resulting in a successful association just before it
4389 * tries to remove the interface from the driver, which now though
4390 * has a channel context assigned ... this results in issues.
4391 *
4392 * To work around this (for now) simply deauth here again if we're
4393 * now connected.
4394 */
4395 if (ifmgd->associated && !sdata->local->wowlan) {
4396 u8 bssid[ETH_ALEN];
4397 struct cfg80211_deauth_request req = {
4398 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4399 .bssid = bssid,
4400 };
4401
4402 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4403 ieee80211_mgd_deauth(sdata, &req);
4404 }
4405
Johannes Berg1a1cb742014-03-19 09:55:55 +01004406 sdata_unlock(sdata);
4407}
4408
Johannes Bergb8360ab2013-04-29 14:57:44 +02004409void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4410{
4411 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4412
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004413 sdata_lock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004414 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004415 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004416 return;
4417 }
4418
4419 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4420 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4421 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4422 ieee80211_sta_connection_lost(sdata,
4423 ifmgd->associated->bssid,
4424 WLAN_REASON_UNSPECIFIED,
4425 true);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004426 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004427 return;
4428 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004429 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004430}
4431#endif
4432
Johannes Berg9c6bd792008-09-11 00:01:52 +02004433/* interface setup */
4434void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4435{
Johannes Berg46900292009-02-15 12:44:28 +01004436 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004437
Johannes Berg46900292009-02-15 12:44:28 +01004438 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004439 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01004440 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004441 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4442 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02004443 INIT_WORK(&ifmgd->csa_connection_drop_work,
4444 ieee80211_csa_connection_drop_work);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03004445 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03004446 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4447 ieee80211_tdls_peer_del_work);
Kees Cook34f11cd2017-10-16 16:35:49 -07004448 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4449 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4450 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4451 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
Johannes Berg02219b32014-10-07 10:38:50 +03004452 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4453 ieee80211_sta_handle_tspec_ac_params_wk);
Johannes Berg9c6bd792008-09-11 00:01:52 +02004454
Johannes Bergab1faea2009-07-01 21:41:17 +02004455 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05304456 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02004457 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4458 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01004459 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02004460
Eliad Peller0d8614b2014-09-10 14:07:36 +03004461 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
Johannes Berg0f782312009-12-01 13:37:02 +01004462 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4463 else
4464 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02004465
4466 /* Setup TDLS data */
4467 spin_lock_init(&ifmgd->teardown_lock);
4468 ifmgd->teardown_skb = NULL;
4469 ifmgd->orig_teardown_skb = NULL;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004470}
4471
4472/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02004473void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4474{
Johannes Berg31ee67a2012-07-06 21:18:24 +02004475 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02004476
4477 /* Restart STA timers */
4478 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07004479 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4480 if (ieee80211_sdata_running(sdata))
4481 ieee80211_restart_sta_timer(sdata);
4482 }
Johannes Berga1678f82008-09-11 00:01:47 +02004483 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02004484}
Johannes Berg10f644a2009-04-16 13:17:25 +02004485
Johannes Bergf2d9d272012-11-22 14:11:39 +01004486static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4487 struct cfg80211_bss *cbss)
4488{
4489 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4490 const u8 *ht_cap_ie, *vht_cap_ie;
4491 const struct ieee80211_ht_cap *ht_cap;
4492 const struct ieee80211_vht_cap *vht_cap;
4493 u8 chains = 1;
4494
4495 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4496 return chains;
4497
Johannes Berg9caf0362012-11-29 01:25:20 +01004498 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004499 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4500 ht_cap = (void *)(ht_cap_ie + 2);
4501 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4502 /*
4503 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4504 * "Tx Unequal Modulation Supported" fields.
4505 */
4506 }
4507
4508 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4509 return chains;
4510
Johannes Berg9caf0362012-11-29 01:25:20 +01004511 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004512 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4513 u8 nss;
4514 u16 tx_mcs_map;
4515
4516 vht_cap = (void *)(vht_cap_ie + 2);
4517 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4518 for (nss = 8; nss > 0; nss--) {
4519 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4520 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4521 break;
4522 }
4523 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4524 chains = max(chains, nss);
4525 }
4526
4527 return chains;
4528}
4529
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004530static bool
4531ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4532 const struct ieee80211_he_operation *he_op)
4533{
4534 const struct ieee80211_sta_he_cap *sta_he_cap =
4535 ieee80211_get_he_sta_cap(sband);
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004536 u16 ap_min_req_set;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004537 int i;
4538
4539 if (!sta_he_cap || !he_op)
4540 return false;
4541
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004542 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4543
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004544 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4545 for (i = 0; i < 3; i++) {
4546 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4547 &sta_he_cap->he_mcs_nss_supp;
4548 u16 sta_mcs_map_rx =
4549 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4550 u16 sta_mcs_map_tx =
4551 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4552 u8 nss;
4553 bool verified = true;
4554
4555 /*
4556 * For each band there is a maximum of 8 spatial streams
4557 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4558 * of 2 bits per NSS (1-8), with the values defined in enum
4559 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4560 * capabilities aren't less than the AP's minimum requirements
4561 * for this HE BSS per SS.
4562 * It is enough to find one such band that meets the reqs.
4563 */
4564 for (nss = 8; nss > 0; nss--) {
4565 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4566 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4567 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4568
4569 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4570 continue;
4571
4572 /*
4573 * Make sure the HE AP doesn't require MCSs that aren't
4574 * supported by the client
4575 */
4576 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4577 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4578 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4579 verified = false;
4580 break;
4581 }
4582 }
4583
4584 if (verified)
4585 return true;
4586 }
4587
4588 /* If here, STA doesn't meet AP's HE min requirements */
4589 return false;
4590}
4591
Johannes Bergb17166a2012-07-27 11:41:27 +02004592static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4593 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01004594{
4595 struct ieee80211_local *local = sdata->local;
4596 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Peller53b954e2014-07-24 11:20:05 +03004597 const struct ieee80211_ht_cap *ht_cap = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004598 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004599 const struct ieee80211_vht_operation *vht_oper = NULL;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004600 const struct ieee80211_he_operation *he_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004601 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01004602 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004603 int ret;
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004604 u32 i;
4605 bool have_80mhz;
Johannes Berga1cf7752012-03-08 15:02:07 +01004606
Johannes Berg24398e32012-03-28 10:58:36 +02004607 sband = local->hw.wiphy->bands[cbss->channel->band];
4608
Johannes Bergf2d9d272012-11-22 14:11:39 +01004609 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4610 IEEE80211_STA_DISABLE_80P80MHZ |
4611 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02004612
Johannes Berg9caf0362012-11-29 01:25:20 +01004613 rcu_read_lock();
4614
Johannes Bergf2d9d272012-11-22 14:11:39 +01004615 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
4616 sband->ht_cap.ht_supported) {
Eliad Peller53b954e2014-07-24 11:20:05 +03004617 const u8 *ht_oper_ie, *ht_cap_ie;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004618
Johannes Berg9caf0362012-11-29 01:25:20 +01004619 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02004620 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4621 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6effa2013-02-07 23:33:32 +01004622
Eliad Peller53b954e2014-07-24 11:20:05 +03004623 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4624 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4625 ht_cap = (void *)(ht_cap_ie + 2);
4626
4627 if (!ht_cap) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004628 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4629 ht_oper = NULL;
4630 }
Johannes Berg24398e32012-03-28 10:58:36 +02004631 }
4632
Johannes Bergf2d9d272012-11-22 14:11:39 +01004633 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4634 sband->vht_cap.vht_supported) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004635 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004636
Johannes Berg9caf0362012-11-29 01:25:20 +01004637 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4638 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004639 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4640 vht_oper = (void *)(vht_oper_ie + 2);
4641 if (vht_oper && !ht_oper) {
4642 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004643 sdata_info(sdata,
Johannes Bergf2d9d272012-11-22 14:11:39 +01004644 "AP advertised VHT without HT, disabling both\n");
Johannes Bergcb145022013-02-07 20:41:50 +01004645 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4646 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg24398e32012-03-28 10:58:36 +02004647 }
Johannes Berg08e6effa2013-02-07 23:33:32 +01004648
4649 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4650 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4651 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4652 vht_oper = NULL;
4653 }
Johannes Berg24398e32012-03-28 10:58:36 +02004654 }
4655
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004656 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
4657 ieee80211_get_he_sta_cap(sband)) {
4658 const struct cfg80211_bss_ies *ies;
4659 const u8 *he_oper_ie;
4660
4661 ies = rcu_dereference(cbss->ies);
4662 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
4663 ies->data, ies->len);
4664 if (he_oper_ie &&
4665 he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
4666 he_oper = (void *)(he_oper_ie + 3);
4667 else
4668 he_oper = NULL;
4669
Johannes Bergf0c04072018-06-29 09:51:39 +02004670 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004671 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4672 }
4673
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004674 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4675 have_80mhz = false;
4676 for (i = 0; i < sband->n_channels; i++) {
4677 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4678 IEEE80211_CHAN_NO_80MHZ))
4679 continue;
4680
4681 have_80mhz = true;
4682 break;
4683 }
4684
4685 if (!have_80mhz)
4686 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4687
Johannes Bergf2d9d272012-11-22 14:11:39 +01004688 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4689 cbss->channel,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004690 ht_oper, vht_oper, he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +02004691 &chandef, false);
Johannes Berg04ecd252012-09-11 14:34:12 +02004692
Johannes Bergf2d9d272012-11-22 14:11:39 +01004693 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4694 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02004695
Johannes Berg9caf0362012-11-29 01:25:20 +01004696 rcu_read_unlock();
4697
Johannes Berg04ecd252012-09-11 14:34:12 +02004698 /* will change later if needed */
4699 sdata->smps_mode = IEEE80211_SMPS_OFF;
4700
Johannes Berg34a37402013-12-18 09:43:33 +01004701 mutex_lock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004702 /*
4703 * If this fails (possibly due to channel context sharing
4704 * on incompatible channels, e.g. 80+80 and 160 sharing the
4705 * same control channel) try to use a smaller bandwidth.
4706 */
4707 ret = ieee80211_vif_use_channel(sdata, &chandef,
4708 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich0418a442013-05-16 13:00:31 +02004709
4710 /* don't downgrade for 5 and 10 MHz channels, though. */
4711 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4712 chandef.width == NL80211_CHAN_WIDTH_10)
Johannes Berg34a37402013-12-18 09:43:33 +01004713 goto out;
Simon Wunderlich0418a442013-05-16 13:00:31 +02004714
Johannes Bergd601cd82013-02-07 20:54:51 +01004715 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02004716 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01004717 ret = ieee80211_vif_use_channel(sdata, &chandef,
4718 IEEE80211_CHANCTX_SHARED);
4719 }
Johannes Berg34a37402013-12-18 09:43:33 +01004720 out:
4721 mutex_unlock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004722 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02004723}
4724
4725static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004726 struct cfg80211_bss *cbss, bool assoc,
4727 bool override)
Johannes Bergb17166a2012-07-27 11:41:27 +02004728{
4729 struct ieee80211_local *local = sdata->local;
4730 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4731 struct ieee80211_bss *bss = (void *)cbss->priv;
4732 struct sta_info *new_sta = NULL;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004733 struct ieee80211_supported_band *sband;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004734 bool have_sta = false;
Johannes Bergb17166a2012-07-27 11:41:27 +02004735 int err;
4736
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004737 sband = local->hw.wiphy->bands[cbss->channel->band];
4738
Johannes Bergb17166a2012-07-27 11:41:27 +02004739 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4740 return -EINVAL;
4741
Luca Coelhof8860ce2017-05-02 17:56:21 +03004742 /* If a reconfig is happening, bail out */
4743 if (local->in_reconfig)
4744 return -EBUSY;
4745
Johannes Bergb17166a2012-07-27 11:41:27 +02004746 if (assoc) {
4747 rcu_read_lock();
4748 have_sta = sta_info_get(sdata, cbss->bssid);
4749 rcu_read_unlock();
4750 }
4751
4752 if (!have_sta) {
4753 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4754 if (!new_sta)
4755 return -ENOMEM;
4756 }
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004757
Johannes Bergc87905b2017-06-10 13:52:43 +03004758 /*
4759 * Set up the information for the new channel before setting the
4760 * new channel. We can't - completely race-free - change the basic
4761 * rates bitmap and the channel (sband) that it refers to, but if
4762 * we set it up before we at least avoid calling into the driver's
4763 * bss_info_changed() method with invalid information (since we do
4764 * call that from changing the channel - only for IDLE and perhaps
4765 * some others, but ...).
4766 *
4767 * So to avoid that, just set up all the new information before the
4768 * channel, but tell the driver to apply it only afterwards, since
4769 * it might need the new channel for that.
4770 */
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004771 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004772 u32 rates = 0, basic_rates = 0;
4773 bool have_higher_than_11mbit;
4774 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004775 const struct cfg80211_bss_ies *ies;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004776 int shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004777
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004778 ieee80211_get_rates(sband, bss->supp_rates,
4779 bss->supp_rates_len,
4780 &rates, &basic_rates,
4781 &have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02004782 &min_rate, &min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03004783 shift);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004784
4785 /*
4786 * This used to be a workaround for basic rates missing
4787 * in the association response frame. Now that we no
4788 * longer use the basic rates from there, it probably
4789 * doesn't happen any more, but keep the workaround so
4790 * in case some *other* APs are buggy in different ways
4791 * we can connect -- with a warning.
4792 */
4793 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004794 sdata_info(sdata,
4795 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004796 basic_rates = BIT(min_rate_index);
4797 }
4798
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004799 new_sta->sta.supp_rates[cbss->channel->band] = rates;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004800 sdata->vif.bss_conf.basic_rates = basic_rates;
4801
4802 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg57fbcce2016-04-12 15:56:15 +02004803 if (cbss->channel->band == NL80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004804 have_higher_than_11mbit)
4805 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
4806 else
4807 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
4808
4809 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
4810
Johannes Berg8c358bc2012-05-22 22:13:05 +02004811 /* set timing information */
4812 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004813 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01004814 ies = rcu_dereference(cbss->beacon_ies);
4815 if (ies) {
4816 const u8 *tim_ie;
4817
4818 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4819 sdata->vif.bss_conf.sync_device_ts =
4820 bss->device_ts_beacon;
4821 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4822 ies->data, ies->len);
4823 if (tim_ie && tim_ie[1] >= 2)
4824 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
4825 else
4826 sdata->vif.bss_conf.sync_dtim_count = 0;
Johannes Berg30686bf2015-06-02 21:39:54 +02004827 } else if (!ieee80211_hw_check(&sdata->local->hw,
4828 TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01004829 ies = rcu_dereference(cbss->proberesp_ies);
4830 /* must be non-NULL since beacon IEs were NULL */
4831 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4832 sdata->vif.bss_conf.sync_device_ts =
4833 bss->device_ts_presp;
4834 sdata->vif.bss_conf.sync_dtim_count = 0;
4835 } else {
4836 sdata->vif.bss_conf.sync_tsf = 0;
4837 sdata->vif.bss_conf.sync_device_ts = 0;
4838 sdata->vif.bss_conf.sync_dtim_count = 0;
4839 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01004840 rcu_read_unlock();
Johannes Bergc87905b2017-06-10 13:52:43 +03004841 }
Johannes Berg8c358bc2012-05-22 22:13:05 +02004842
Johannes Bergc87905b2017-06-10 13:52:43 +03004843 if (new_sta || override) {
4844 err = ieee80211_prep_channel(sdata, cbss);
4845 if (err) {
4846 if (new_sta)
4847 sta_info_free(local, new_sta);
4848 return -EINVAL;
4849 }
4850 }
4851
4852 if (new_sta) {
4853 /*
4854 * tell driver about BSSID, basic rates and timing
4855 * this was set up above, before setting the channel
4856 */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004857 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02004858 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
4859 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01004860
4861 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004862 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01004863
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004864 err = sta_info_insert(new_sta);
4865 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01004866 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004867 sdata_info(sdata,
4868 "failed to insert STA entry for the AP (error %d)\n",
4869 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01004870 return err;
4871 }
4872 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00004873 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01004874
David Spinadel7d830a12015-03-17 19:58:38 +02004875 /* Cancel scan to ensure that nothing interferes with connection */
4876 if (local->scanning)
4877 ieee80211_scan_cancel(local);
4878
Johannes Berga1cf7752012-03-08 15:02:07 +01004879 return 0;
4880}
4881
Johannes Berg77fdaa12009-07-07 03:45:17 +02004882/* config hooks */
4883int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
4884 struct cfg80211_auth_request *req)
4885{
Johannes Berg66e67e42012-01-20 13:55:27 +01004886 struct ieee80211_local *local = sdata->local;
4887 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4888 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004889 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01004890 int err;
4891
4892 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02004893
4894 switch (req->auth_type) {
4895 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4896 auth_alg = WLAN_AUTH_OPEN;
4897 break;
4898 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01004899 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02004900 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004901 auth_alg = WLAN_AUTH_SHARED_KEY;
4902 break;
4903 case NL80211_AUTHTYPE_FT:
4904 auth_alg = WLAN_AUTH_FT;
4905 break;
4906 case NL80211_AUTHTYPE_NETWORK_EAP:
4907 auth_alg = WLAN_AUTH_LEAP;
4908 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004909 case NL80211_AUTHTYPE_SAE:
4910 auth_alg = WLAN_AUTH_SAE;
4911 break;
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03004912 case NL80211_AUTHTYPE_FILS_SK:
4913 auth_alg = WLAN_AUTH_FILS_SK;
4914 break;
4915 case NL80211_AUTHTYPE_FILS_SK_PFS:
4916 auth_alg = WLAN_AUTH_FILS_SK_PFS;
4917 break;
4918 case NL80211_AUTHTYPE_FILS_PK:
4919 auth_alg = WLAN_AUTH_FILS_PK;
4920 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004921 default:
4922 return -EOPNOTSUPP;
4923 }
4924
Jouni Malinen8d7432a2018-10-11 00:21:20 +03004925 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
4926 ifmgd->assoc_data)
4927 return -EBUSY;
4928
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004929 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004930 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01004931 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004932 return -ENOMEM;
4933
Johannes Berg66e67e42012-01-20 13:55:27 +01004934 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004935
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004936 if (req->auth_data_len >= 4) {
Jouni Malinen6ec63612016-10-27 00:41:59 +03004937 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
4938 __le16 *pos = (__le16 *) req->auth_data;
4939
4940 auth_data->sae_trans = le16_to_cpu(pos[0]);
4941 auth_data->sae_status = le16_to_cpu(pos[1]);
4942 }
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004943 memcpy(auth_data->data, req->auth_data + 4,
4944 req->auth_data_len - 4);
4945 auth_data->data_len += req->auth_data_len - 4;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004946 }
4947
Johannes Berg77fdaa12009-07-07 03:45:17 +02004948 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004949 memcpy(&auth_data->data[auth_data->data_len],
4950 req->ie, req->ie_len);
4951 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004952 }
4953
Johannes Bergfffd0932009-07-08 14:22:54 +02004954 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004955 auth_data->key_len = req->key_len;
4956 auth_data->key_idx = req->key_idx;
4957 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02004958 }
4959
Johannes Berg66e67e42012-01-20 13:55:27 +01004960 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004961
Johannes Berg66e67e42012-01-20 13:55:27 +01004962 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01004963
Johannes Berg66e67e42012-01-20 13:55:27 +01004964 if (ifmgd->auth_data)
4965 ieee80211_destroy_auth_data(sdata, false);
Guy Eilam2a33bee2011-08-17 15:18:15 +03004966
Johannes Berg66e67e42012-01-20 13:55:27 +01004967 /* prep auth_data so we don't go into idle on disassoc */
4968 ifmgd->auth_data = auth_data;
4969
Johannes Berg7b119dc2013-04-10 21:38:36 +02004970 if (ifmgd->associated) {
4971 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4972
Johannes Berg89f774e2016-01-25 15:46:36 +02004973 sdata_info(sdata,
4974 "disconnect from AP %pM for new auth to %pM\n",
4975 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02004976 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4977 WLAN_REASON_UNSPECIFIED,
4978 false, frame_buf);
4979
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004980 ieee80211_report_disconnect(sdata, frame_buf,
4981 sizeof(frame_buf), true,
4982 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02004983 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004984
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004985 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004986
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004987 err = ieee80211_prep_connection(sdata, req->bss, false, false);
Johannes Berga1cf7752012-03-08 15:02:07 +01004988 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01004989 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004990
Johannes Berg46cad4b2015-08-15 22:39:54 +03004991 err = ieee80211_auth(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004992 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004993 sta_info_destroy_addr(sdata, req->bss->bssid);
4994 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004995 }
4996
Johannes Berg66e67e42012-01-20 13:55:27 +01004997 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01004998 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004999 return 0;
Johannes Berge5b900d2010-07-29 16:08:55 +02005000
Johannes Berg66e67e42012-01-20 13:55:27 +01005001 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005002 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005003 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005004 ifmgd->auth_data = NULL;
Michal Kaziord01f8582015-06-03 08:36:13 +02005005 mutex_lock(&sdata->local->mtx);
5006 ieee80211_vif_release_channel(sdata);
5007 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01005008 kfree(auth_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005009 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005010}
5011
Johannes Berg77fdaa12009-07-07 03:45:17 +02005012int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5013 struct cfg80211_assoc_request *req)
5014{
Johannes Berg66e67e42012-01-20 13:55:27 +01005015 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005016 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01005017 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01005018 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005019 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005020 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005021 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005022 int i, err;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005023 bool override = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005024
Johannes Berg66e67e42012-01-20 13:55:27 +01005025 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5026 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01005027 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005028
Johannes Berg9caf0362012-11-29 01:25:20 +01005029 rcu_read_lock();
5030 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
5031 if (!ssidie) {
5032 rcu_read_unlock();
5033 kfree(assoc_data);
5034 return -EINVAL;
5035 }
5036 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5037 assoc_data->ssid_len = ssidie[1];
5038 rcu_read_unlock();
5039
Johannes Berg7b119dc2013-04-10 21:38:36 +02005040 if (ifmgd->associated) {
5041 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5042
Johannes Berg89f774e2016-01-25 15:46:36 +02005043 sdata_info(sdata,
5044 "disconnect from AP %pM for new assoc to %pM\n",
5045 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005046 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5047 WLAN_REASON_UNSPECIFIED,
5048 false, frame_buf);
5049
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005050 ieee80211_report_disconnect(sdata, frame_buf,
5051 sizeof(frame_buf), true,
5052 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005053 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005054
5055 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5056 err = -EBUSY;
5057 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005058 }
5059
Johannes Berg66e67e42012-01-20 13:55:27 +01005060 if (ifmgd->assoc_data) {
5061 err = -EBUSY;
5062 goto err_free;
5063 }
5064
5065 if (ifmgd->auth_data) {
5066 bool match;
5067
5068 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00005069 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005070 ieee80211_destroy_auth_data(sdata, match);
5071 }
5072
5073 /* prepare assoc data */
Johannes Berg095d81c2013-10-15 12:25:07 +02005074
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03005075 ifmgd->beacon_crc_valid = false;
5076
Johannes Berg095d81c2013-10-15 12:25:07 +02005077 assoc_data->wmm = bss->wmm_used &&
5078 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg095d81c2013-10-15 12:25:07 +02005079
Johannes Bergde5036a2012-03-08 15:02:03 +01005080 /*
5081 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5082 * We still associate in non-HT mode (11a/b/g) if any one of these
5083 * ciphers is configured as pairwise.
5084 * We can set this to true for non-11n hardware, that'll be checked
5085 * separately along with the peer capabilities.
5086 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02005087 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02005088 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5089 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02005090 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01005091 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005092 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005093 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Johannes Berg1c4cb922012-05-30 15:57:00 +02005094 netdev_info(sdata->dev,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005095 "disabling HE/HT/VHT due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005096 }
5097 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005098
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005099 /* Also disable HT if we don't support it or the AP doesn't use WMM */
5100 sband = local->hw.wiphy->bands[req->bss->channel->band];
5101 if (!sband->ht_cap.ht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005102 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5103 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Berga8243b72012-11-22 14:32:09 +01005104 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005105 if (!bss->wmm_used &&
5106 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005107 netdev_info(sdata->dev,
5108 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005109 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005110
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005111 /* disable VHT if we don't support it or the AP doesn't use WMM */
5112 if (!sband->vht_cap.vht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005113 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5114 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005115 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005116 if (!bss->wmm_used &&
5117 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005118 netdev_info(sdata->dev,
5119 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005120 }
5121
Ben Greearef96a8422011-11-18 11:32:00 -08005122 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5123 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5124 sizeof(ifmgd->ht_capa_mask));
5125
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01005126 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5127 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5128 sizeof(ifmgd->vht_capa_mask));
5129
Johannes Berg77fdaa12009-07-07 03:45:17 +02005130 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005131 memcpy(assoc_data->ie, req->ie, req->ie_len);
5132 assoc_data->ie_len = req->ie_len;
5133 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005134
Jouni Malinen39404fe2016-10-27 00:42:05 +03005135 if (req->fils_kek) {
5136 /* should already be checked in cfg80211 - so warn */
5137 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5138 err = -EINVAL;
5139 goto err_free;
5140 }
5141 memcpy(assoc_data->fils_kek, req->fils_kek,
5142 req->fils_kek_len);
5143 assoc_data->fils_kek_len = req->fils_kek_len;
5144 }
5145
5146 if (req->fils_nonces)
5147 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5148 2 * FILS_NONCE_LEN);
5149
Johannes Berg66e67e42012-01-20 13:55:27 +01005150 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01005151
Johannes Bergaf6b6372009-12-23 13:15:35 +01005152 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5153 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02005154 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005155 else
Johannes Berg04ecd252012-09-11 14:34:12 +02005156 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005157 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02005158 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005159
Johannes Berg66e67e42012-01-20 13:55:27 +01005160 assoc_data->capability = req->bss->capability;
Johannes Berg66e67e42012-01-20 13:55:27 +01005161 assoc_data->supp_rates = bss->supp_rates;
5162 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02005163
Johannes Berg9caf0362012-11-29 01:25:20 +01005164 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02005165 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5166 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5167 assoc_data->ap_ht_param =
5168 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5169 else
Johannes Berga8243b72012-11-22 14:32:09 +01005170 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005171 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5172 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5173 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5174 sizeof(struct ieee80211_vht_cap));
5175 else
5176 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01005177 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01005178
Johannes Berg848955c2014-11-11 12:48:42 +01005179 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02005180 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
Johannes Berg848955c2014-11-11 12:48:42 +01005181 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5182 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5183
Kalle Valoab133152010-01-12 10:42:31 +02005184 if (bss->wmm_used && bss->uapsd_supported &&
Johannes Berg848955c2014-11-11 12:48:42 +01005185 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01005186 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02005187 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5188 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01005189 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02005190 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5191 }
5192
Johannes Berg77fdaa12009-07-07 03:45:17 +02005193 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01005194 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005195
5196 if (req->use_mfp) {
5197 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5198 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5199 } else {
5200 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5201 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5202 }
5203
Assaf Krausscd2f5dd2014-09-03 15:25:02 +03005204 if (req->flags & ASSOC_REQ_USE_RRM)
5205 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5206 else
5207 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5208
Johannes Berg77fdaa12009-07-07 03:45:17 +02005209 if (req->crypto.control_port)
5210 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5211 else
5212 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5213
Johannes Berga621fa42010-08-27 14:26:54 +03005214 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5215 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05005216 sdata->control_port_over_nl80211 =
5217 req->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02005218 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5219 sdata->vif.type);
Johannes Berga621fa42010-08-27 14:26:54 +03005220
Johannes Berg66e67e42012-01-20 13:55:27 +01005221 /* kick off associate process */
5222
5223 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02005224 ifmgd->dtim_period = 0;
Alexander Bondar989c6502013-05-16 17:34:17 +03005225 ifmgd->have_beacon = false;
Johannes Berg66e67e42012-01-20 13:55:27 +01005226
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005227 /* override HT/VHT configuration only if the AP and we support it */
5228 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5229 struct ieee80211_sta_ht_cap sta_ht_cap;
5230
5231 if (req->flags & ASSOC_REQ_DISABLE_HT)
5232 override = true;
5233
5234 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5235 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5236
5237 /* check for 40 MHz disable override */
5238 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5239 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5240 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5241 override = true;
5242
5243 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5244 req->flags & ASSOC_REQ_DISABLE_VHT)
5245 override = true;
5246 }
5247
5248 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5249 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5250 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5251 }
5252
5253 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5254 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5255
5256 err = ieee80211_prep_connection(sdata, req->bss, true, override);
Johannes Berga1cf7752012-03-08 15:02:07 +01005257 if (err)
5258 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01005259
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005260 rcu_read_lock();
5261 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02005262
Johannes Berg30686bf2015-06-02 21:39:54 +02005263 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005264 !beacon_ies) {
5265 /*
5266 * Wait up to one beacon interval ...
5267 * should this be more if we miss one?
5268 */
5269 sdata_info(sdata, "waiting for beacon from %pM\n",
5270 ifmgd->bssid);
5271 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01005272 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005273 assoc_data->need_beacon = true;
5274 } else if (beacon_ies) {
5275 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
5276 beacon_ies->data,
5277 beacon_ies->len);
Johannes Bergef429da2013-02-05 17:48:40 +01005278 u8 dtim_count = 0;
5279
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005280 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
5281 const struct ieee80211_tim_ie *tim;
5282 tim = (void *)(tim_ie + 2);
5283 ifmgd->dtim_period = tim->dtim_period;
Johannes Bergef429da2013-02-05 17:48:40 +01005284 dtim_count = tim->dtim_count;
Johannes Berg826262c2012-12-10 16:38:14 +02005285 }
Alexander Bondar989c6502013-05-16 17:34:17 +03005286 ifmgd->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005287 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005288 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01005289
Johannes Berg30686bf2015-06-02 21:39:54 +02005290 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005291 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5292 sdata->vif.bss_conf.sync_device_ts =
5293 bss->device_ts_beacon;
5294 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5295 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005296 } else {
5297 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005298 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005299 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005300 rcu_read_unlock();
5301
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005302 run_again(sdata, assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01005303
Paul Stewartfcff4f12012-02-23 17:59:53 -08005304 if (bss->corrupt_data) {
5305 char *corrupt_type = "data";
5306 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5307 if (bss->corrupt_data &
5308 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5309 corrupt_type = "beacon and probe response";
5310 else
5311 corrupt_type = "beacon";
5312 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5313 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005314 sdata_info(sdata, "associating with AP with corrupt %s\n",
5315 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08005316 }
5317
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005318 return 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01005319 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005320 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005321 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005322 ifmgd->assoc_data = NULL;
5323 err_free:
5324 kfree(assoc_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005325 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005326}
5327
5328int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005329 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005330{
5331 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005332 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005333 bool tx = !req->local_state_change;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005334
Johannes Bergc9c3a062014-03-19 09:11:19 +01005335 if (ifmgd->auth_data &&
5336 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5337 sdata_info(sdata,
5338 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5339 req->bssid, req->reason_code,
5340 ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005341
Ilan Peerd4e36e52018-04-20 13:49:25 +03005342 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg37ad3882012-02-24 13:50:54 +01005343 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5344 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005345 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01005346 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01005347 ieee80211_destroy_auth_data(sdata, false);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005348 ieee80211_report_disconnect(sdata, frame_buf,
5349 sizeof(frame_buf), true,
5350 req->reason_code);
Johannes Berg86552012012-10-29 09:46:31 +01005351
Johannes Bergc9c3a062014-03-19 09:11:19 +01005352 return 0;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03005353 }
5354
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005355 if (ifmgd->assoc_data &&
5356 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5357 sdata_info(sdata,
5358 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5359 req->bssid, req->reason_code,
5360 ieee80211_get_reason_code_string(req->reason_code));
5361
Ilan Peerd4e36e52018-04-20 13:49:25 +03005362 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005363 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5364 IEEE80211_STYPE_DEAUTH,
5365 req->reason_code, tx,
5366 frame_buf);
Johannes Berge6f462d2016-12-08 17:22:09 +01005367 ieee80211_destroy_assoc_data(sdata, false, true);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005368 ieee80211_report_disconnect(sdata, frame_buf,
5369 sizeof(frame_buf), true,
5370 req->reason_code);
5371 return 0;
5372 }
5373
Johannes Berg86552012012-10-29 09:46:31 +01005374 if (ifmgd->associated &&
5375 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
Johannes Bergc9c3a062014-03-19 09:11:19 +01005376 sdata_info(sdata,
5377 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5378 req->bssid, req->reason_code,
5379 ieee80211_get_reason_code_string(req->reason_code));
5380
Johannes Berg86552012012-10-29 09:46:31 +01005381 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5382 req->reason_code, tx, frame_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005383 ieee80211_report_disconnect(sdata, frame_buf,
5384 sizeof(frame_buf), true,
5385 req->reason_code);
Johannes Bergc9c3a062014-03-19 09:11:19 +01005386 return 0;
5387 }
Johannes Berg86552012012-10-29 09:46:31 +01005388
Johannes Bergc9c3a062014-03-19 09:11:19 +01005389 return -ENOTCONN;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005390}
5391
5392int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005393 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005394{
5395 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07005396 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005397 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02005398
Johannes Berg8d8b2612009-07-25 11:58:36 +02005399 /*
5400 * cfg80211 should catch this ... but it's racy since
5401 * we can receive a disassoc frame, process it, hand it
5402 * to cfg80211 while that's in a locked section already
5403 * trying to tell us that the user wants to disconnect.
5404 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005405 if (ifmgd->associated != req->bss)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005406 return -ENOLINK;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005407
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005408 sdata_info(sdata,
Calvin Owensdfa1ad22014-02-11 12:36:24 -06005409 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5410 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005411
Jouni Malinene69e95d2010-03-29 23:29:31 -07005412 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01005413 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5414 req->reason_code, !req->local_state_change,
5415 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005416
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005417 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5418 req->reason_code);
Johannes Bergbc83b682009-11-29 12:19:06 +01005419
Johannes Berg77fdaa12009-07-07 03:45:17 +02005420 return 0;
5421}
Jouni Malinen026331c2010-02-15 12:53:10 +02005422
Eliad Pellerafa762f2012-04-23 14:45:15 +03005423void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005424{
5425 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5426
Ben Greear49921852013-02-20 09:41:09 -08005427 /*
5428 * Make sure some work items will not run after this,
5429 * they will not do anything but might not have been
5430 * cancelled when disconnecting.
5431 */
5432 cancel_work_sync(&ifmgd->monitor_work);
5433 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5434 cancel_work_sync(&ifmgd->request_smps_work);
5435 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5436 cancel_work_sync(&ifmgd->chswitch_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03005437 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
Ben Greear49921852013-02-20 09:41:09 -08005438
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005439 sdata_lock(sdata);
Johannes Berg959867f2013-06-19 13:05:42 +02005440 if (ifmgd->assoc_data) {
5441 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Johannes Berge6f462d2016-12-08 17:22:09 +01005442 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02005443 cfg80211_assoc_timeout(sdata->dev, bss);
5444 }
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005445 if (ifmgd->auth_data)
5446 ieee80211_destroy_auth_data(sdata, false);
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005447 spin_lock_bh(&ifmgd->teardown_lock);
5448 if (ifmgd->teardown_skb) {
5449 kfree_skb(ifmgd->teardown_skb);
5450 ifmgd->teardown_skb = NULL;
5451 ifmgd->orig_teardown_skb = NULL;
5452 }
5453 spin_unlock_bh(&ifmgd->teardown_lock);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005454 del_timer_sync(&ifmgd->timer);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005455 sdata_unlock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005456}
5457
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005458void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5459 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005460 s32 rssi_level,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005461 gfp_t gfp)
5462{
5463 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5464
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005465 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
Johannes Bergb5878a22010-04-07 16:48:40 +02005466
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01005467 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005468}
5469EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
Johannes Berg98f03342014-11-26 12:42:02 +01005470
5471void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5472{
5473 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5474
5475 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5476
5477 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5478}
5479EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);