blob: 764a0f8e1dd16674762dffacb321458fa6ff6eaf [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * BSS client mode implementation
Jouni Malinen5394af42009-01-08 13:31:59 +02003 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
Jiri Bencf0706e82007-05-05 11:45:53 -07004 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
Johannes Bergd98ad832014-09-03 15:24:57 +03008 * Copyright 2013-2014 Intel Mobile Communications GmbH
Avraham Sterne38a0172017-04-26 10:58:47 +03009 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
Ilan Peer94ba9272018-02-19 14:48:41 +020010 * Copyright (C) 2018 Intel Corporation
Jiri Bencf0706e82007-05-05 11:45:53 -070011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070017#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018#include <linux/if_ether.h>
19#include <linux/skbuff.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070020#include <linux/if_arp.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070021#include <linux/etherdevice.h>
Paul Gortmakerd9b93842011-09-18 13:21:27 -040022#include <linux/moduleparam.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010023#include <linux/rtnetlink.h>
Johannes Bergd91f36d2009-04-16 13:17:26 +020024#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040026#include <linux/export.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070027#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020028#include <asm/unaligned.h>
Johannes Berg60f8b39c2008-09-08 17:44:22 +020029
Jiri Bencf0706e82007-05-05 11:45:53 -070030#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020031#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040032#include "rate.h"
33#include "led.h"
Jouni Malinen39404fe2016-10-27 00:42:05 +030034#include "fils_aead.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070035
Johannes Berg1672c0e32013-01-29 15:02:27 +010036#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020037#define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010038#define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
Ilan Peer407879b2018-04-20 13:49:20 +030039#define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010040#define IEEE80211_AUTH_MAX_TRIES 3
41#define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
42#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020043#define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010044#define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
45#define IEEE80211_ASSOC_MAX_TRIES 3
Johannes Berg66e67e42012-01-20 13:55:27 +010046
Ben Greear180205b2011-02-04 15:30:24 -080047static int max_nullfunc_tries = 2;
48module_param(max_nullfunc_tries, int, 0644);
49MODULE_PARM_DESC(max_nullfunc_tries,
50 "Maximum nullfunc tx tries before disconnecting (reason 4).");
51
52static int max_probe_tries = 5;
53module_param(max_probe_tries, int, 0644);
54MODULE_PARM_DESC(max_probe_tries,
55 "Maximum probe tries before disconnecting (reason 4).");
Johannes Bergb291ba12009-07-10 15:29:03 +020056
57/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010058 * Beacon loss timeout is calculated as N frames times the
59 * advertised beacon interval. This may need to be somewhat
60 * higher than what hardware might detect to account for
61 * delays in the host processing frames. But since we also
62 * probe on beacon miss before declaring the connection lost
63 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020064 */
Ben Greear59c1ec22013-03-19 14:19:56 -070065static int beacon_loss_count = 7;
66module_param(beacon_loss_count, int, 0644);
67MODULE_PARM_DESC(beacon_loss_count,
68 "Number of beacon intervals before we decide beacon was lost.");
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010069
Johannes Bergb291ba12009-07-10 15:29:03 +020070/*
71 * Time the connection can be idle before we probe
72 * it to see if we can still talk to the AP.
73 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030074#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020075/*
76 * Time we wait for a probe response after sending
77 * a probe request because of beacon loss or for
78 * checking the connection still works.
79 */
Ben Greear180205b2011-02-04 15:30:24 -080080static int probe_wait_ms = 500;
81module_param(probe_wait_ms, int, 0644);
82MODULE_PARM_DESC(probe_wait_ms,
83 "Maximum time(ms) to wait for probe response"
84 " before disconnecting (reason 4).");
Jiri Bencf0706e82007-05-05 11:45:53 -070085
Jouni Malinen17e4ec12010-03-29 23:28:30 -070086/*
Jouni Malinen391a2002010-08-27 22:22:00 +030087 * How many Beacon frames need to have been used in average signal strength
88 * before starting to indicate signal change events.
89 */
90#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
91
Johannes Berg77fdaa12009-07-07 03:45:17 +020092/*
Johannes Bergca386f32009-07-10 02:39:48 +020093 * We can have multiple work items (and connection probing)
94 * scheduling this timer, but we need to take care to only
95 * reschedule it when it should fire _earlier_ than it was
96 * asked for before, or if it's not pending right now. This
97 * function ensures that. Note that it then is required to
98 * run this function for all timeouts after the first one
99 * has happened -- the work that runs from this timer will
100 * do that.
101 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200102static void run_again(struct ieee80211_sub_if_data *sdata,
103 unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200104{
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200105 sdata_assert_lock(sdata);
Johannes Bergca386f32009-07-10 02:39:48 +0200106
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200107 if (!timer_pending(&sdata->u.mgd.timer) ||
108 time_before(timeout, sdata->u.mgd.timer.expires))
109 mod_timer(&sdata->u.mgd.timer, timeout);
Johannes Bergca386f32009-07-10 02:39:48 +0200110}
111
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400112void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200113{
Johannes Bergc1288b12012-01-19 09:29:57 +0100114 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200115 return;
116
Johannes Berg30686bf2015-06-02 21:39:54 +0200117 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Johannes Berg7eeff742012-07-18 10:27:27 +0200118 return;
119
Johannes Bergb291ba12009-07-10 15:29:03 +0200120 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100121 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200122}
123
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400124void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
125{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400126 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
127
Johannes Bergb100e5d2016-03-17 15:41:37 +0200128 if (unlikely(!ifmgd->associated))
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100129 return;
130
Johannes Bergb100e5d2016-03-17 15:41:37 +0200131 if (ifmgd->probe_send_count)
132 ifmgd->probe_send_count = 0;
Eliad Peller448cd2e2014-02-11 12:30:18 +0200133
Johannes Berg30686bf2015-06-02 21:39:54 +0200134 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400135 return;
136
Johannes Bergb100e5d2016-03-17 15:41:37 +0200137 mod_timer(&ifmgd->conn_mon_timer,
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400138 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
139}
140
Johannes Berg5484e232008-09-08 17:44:27 +0200141static int ecw2cw(int ecw)
Johannes Berg60f8b39c2008-09-08 17:44:22 +0200142{
Johannes Berg5484e232008-09-08 17:44:27 +0200143 return (1 << ecw) - 1;
Johannes Berg60f8b39c2008-09-08 17:44:22 +0200144}
145
Johannes Berg6565ec92013-02-08 14:52:32 +0100146static u32
147ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
148 struct ieee80211_supported_band *sband,
149 struct ieee80211_channel *channel,
150 const struct ieee80211_ht_operation *ht_oper,
151 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300152 const struct ieee80211_he_operation *he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +0200153 struct cfg80211_chan_def *chandef, bool tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100154{
Johannes Berg5cdaed12013-07-31 11:23:06 +0200155 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg6565ec92013-02-08 14:52:32 +0100156 struct cfg80211_chan_def vht_chandef;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200157 struct ieee80211_sta_ht_cap sta_ht_cap;
Johannes Berg6565ec92013-02-08 14:52:32 +0100158 u32 ht_cfreq, ret;
159
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200160 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
161 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
162
Johannes Berg6565ec92013-02-08 14:52:32 +0100163 chandef->chan = channel;
164 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
165 chandef->center_freq1 = channel->center_freq;
166 chandef->center_freq2 = 0;
167
Johannes Bergb1b1ae22017-10-13 15:26:01 +0300168 if (!ht_oper || !sta_ht_cap.ht_supported) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100169 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
170 goto out;
171 }
172
173 chandef->width = NL80211_CHAN_WIDTH_20;
174
175 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
176 channel->band);
177 /* check that channel matches the right operating channel */
Johannes Berg5cdaed12013-07-31 11:23:06 +0200178 if (!tracking && channel->center_freq != ht_cfreq) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100179 /*
180 * It's possible that some APs are confused here;
181 * Netgear WNDR3700 sometimes reports 4 higher than
182 * the actual channel in association responses, but
183 * since we look at probe response/beacon data here
184 * it should be OK.
185 */
Johannes Berg5cdaed12013-07-31 11:23:06 +0200186 sdata_info(sdata,
187 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
188 channel->center_freq, ht_cfreq,
189 ht_oper->primary_chan, channel->band);
Johannes Berg6565ec92013-02-08 14:52:32 +0100190 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
191 goto out;
192 }
193
194 /* check 40 MHz support, if we have it */
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200195 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100196 ieee80211_chandef_ht_oper(ht_oper, chandef);
Johannes Berg6565ec92013-02-08 14:52:32 +0100197 } else {
198 /* 40 MHz (and 80 MHz) must be supported for VHT */
199 ret = IEEE80211_STA_DISABLE_VHT;
Johannes Berg85220d72013-03-25 18:29:27 +0100200 /* also mark 40 MHz disabled */
201 ret |= IEEE80211_STA_DISABLE_40MHZ;
Johannes Berg6565ec92013-02-08 14:52:32 +0100202 goto out;
203 }
204
205 if (!vht_oper || !sband->vht_cap.vht_supported) {
206 ret = IEEE80211_STA_DISABLE_VHT;
207 goto out;
208 }
209
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100210 vht_chandef = *chandef;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300211 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
212 (le32_to_cpu(he_oper->he_oper_params) &
213 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
214 struct ieee80211_vht_operation he_oper_vht_cap;
215
216 /*
217 * Set only first 3 bytes (other 2 aren't used in
218 * ieee80211_chandef_vht_oper() anyway)
219 */
220 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
221 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
222
Johannes Berg7eb26df2018-08-31 11:31:18 +0300223 if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
224 &he_oper_vht_cap, ht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300225 &vht_chandef)) {
226 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
227 sdata_info(sdata,
228 "HE AP VHT information is invalid, disable HE\n");
229 ret = IEEE80211_STA_DISABLE_HE;
230 goto out;
231 }
Johannes Berg7eb26df2018-08-31 11:31:18 +0300232 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_oper,
233 ht_oper, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200234 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100235 sdata_info(sdata,
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100236 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100237 ret = IEEE80211_STA_DISABLE_VHT;
238 goto out;
239 }
240
241 if (!cfg80211_chandef_valid(&vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200242 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100243 sdata_info(sdata,
244 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100245 ret = IEEE80211_STA_DISABLE_VHT;
246 goto out;
247 }
248
249 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
250 ret = 0;
251 goto out;
252 }
253
254 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200255 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100256 sdata_info(sdata,
257 "AP VHT information doesn't match HT, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100258 ret = IEEE80211_STA_DISABLE_VHT;
259 goto out;
260 }
261
262 *chandef = vht_chandef;
263
264 ret = 0;
265
266out:
Johannes Berg963a18522014-02-21 20:34:34 +0100267 /*
268 * When tracking the current AP, don't do any further checks if the
269 * new chandef is identical to the one we're currently using for the
270 * connection. This keeps us from playing ping-pong with regulatory,
271 * without it the following can happen (for example):
272 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
273 * - AP advertises regdom US
274 * - CRDA loads regdom US with 80 MHz prohibited (old database)
275 * - the code below detects an unsupported channel, downgrades, and
276 * we disconnect from the AP in the caller
277 * - disconnect causes CRDA to reload world regdomain and the game
278 * starts anew.
279 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
280 *
281 * It seems possible that there are still scenarios with CSA or real
282 * bandwidth changes where a this could happen, but those cases are
283 * less common and wouldn't completely prevent using the AP.
284 */
285 if (tracking &&
286 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
287 return ret;
288
Johannes Berg586e01e2013-02-14 12:13:53 +0100289 /* don't print the message below for VHT mismatch if VHT is disabled */
290 if (ret & IEEE80211_STA_DISABLE_VHT)
291 vht_chandef = *chandef;
292
Johannes Bergddfe49b2013-07-31 20:52:03 +0200293 /*
294 * Ignore the DISABLED flag when we're already connected and only
295 * tracking the APs beacon for bandwidth changes - otherwise we
296 * might get disconnected here if we connect to an AP, update our
297 * regulatory information based on the AP's country IE and the
298 * information we have is wrong/outdated and disables the channel
299 * that we're actually using for the connection to the AP.
300 */
Johannes Berg6565ec92013-02-08 14:52:32 +0100301 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
Johannes Bergddfe49b2013-07-31 20:52:03 +0200302 tracking ? 0 :
303 IEEE80211_CHAN_DISABLED)) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100304 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
305 ret = IEEE80211_STA_DISABLE_HT |
306 IEEE80211_STA_DISABLE_VHT;
Chris Wrightb56e4b82013-07-31 12:12:24 -0700307 break;
Johannes Berg6565ec92013-02-08 14:52:32 +0100308 }
309
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200310 ret |= ieee80211_chandef_downgrade(chandef);
Johannes Berg6565ec92013-02-08 14:52:32 +0100311 }
312
Johannes Berg5cdaed12013-07-31 11:23:06 +0200313 if (chandef->width != vht_chandef.width && !tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100314 sdata_info(sdata,
315 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
316
317 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
318 return ret;
319}
320
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100321static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
322 struct sta_info *sta,
Eliad Peller53b954e2014-07-24 11:20:05 +0300323 const struct ieee80211_ht_cap *ht_cap,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100324 const struct ieee80211_ht_operation *ht_oper,
325 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300326 const struct ieee80211_he_operation *he_oper,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100327 const u8 *bssid, u32 *changed)
Johannes Bergd5522e02009-03-30 13:23:35 +0200328{
329 struct ieee80211_local *local = sdata->local;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100330 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300331 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
332 struct ieee80211_supported_band *sband =
333 local->hw.wiphy->bands[chan->band];
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100334 struct cfg80211_chan_def chandef;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200335 u16 ht_opmode;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100336 u32 flags;
337 enum ieee80211_sta_rx_bandwidth new_sta_bw;
338 int ret;
339
340 /* if HT was/is disabled, don't track any bandwidth changes */
341 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
342 return 0;
343
344 /* don't check VHT if we associated as non-VHT station */
345 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
346 vht_oper = NULL;
Johannes Bergd5522e02009-03-30 13:23:35 +0200347
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300348 /* don't check HE if we associated as non-HE station */
349 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
350 !ieee80211_get_he_sta_cap(sband))
351 he_oper = NULL;
352
Johannes Berg11289582013-02-07 17:36:12 +0100353 if (WARN_ON_ONCE(!sta))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100354 return -EINVAL;
Johannes Berg11289582013-02-07 17:36:12 +0100355
Avri Altman017b45b2013-11-18 19:06:48 +0200356 /*
357 * if bss configuration changed store the new one -
358 * this may be applicable even if channel is identical
359 */
360 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
361 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
362 *changed |= BSS_CHANGED_HT;
363 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
364 }
365
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300366 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
Eliad Peller53b954e2014-07-24 11:20:05 +0300367 flags = ieee80211_determine_chantype(sdata, sband, chan,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300368 ht_oper, vht_oper, he_oper,
Eliad Peller53b954e2014-07-24 11:20:05 +0300369 &chandef, true);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100370
371 /*
372 * Downgrade the new channel if we associated with restricted
373 * capabilities. For example, if we associated as a 20 MHz STA
374 * to a 40 MHz AP (due to regulatory, capabilities or config
375 * reasons) then switching to a 40 MHz channel now won't do us
376 * any good -- we couldn't use it with the AP.
377 */
378 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
379 chandef.width == NL80211_CHAN_WIDTH_80P80)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200380 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100381 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
382 chandef.width == NL80211_CHAN_WIDTH_160)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200383 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100384 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
385 chandef.width > NL80211_CHAN_WIDTH_20)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200386 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100387
388 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
389 return 0;
390
391 sdata_info(sdata,
392 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
393 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
394 chandef.center_freq1, chandef.center_freq2);
395
396 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
397 IEEE80211_STA_DISABLE_VHT |
398 IEEE80211_STA_DISABLE_40MHZ |
399 IEEE80211_STA_DISABLE_80P80MHZ |
400 IEEE80211_STA_DISABLE_160MHZ)) ||
401 !cfg80211_chandef_valid(&chandef)) {
402 sdata_info(sdata,
403 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
404 ifmgd->bssid);
405 return -EINVAL;
Johannes Berg64f68e52012-03-28 10:58:37 +0200406 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200407
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100408 switch (chandef.width) {
409 case NL80211_CHAN_WIDTH_20_NOHT:
410 case NL80211_CHAN_WIDTH_20:
411 new_sta_bw = IEEE80211_STA_RX_BW_20;
412 break;
413 case NL80211_CHAN_WIDTH_40:
414 new_sta_bw = IEEE80211_STA_RX_BW_40;
415 break;
416 case NL80211_CHAN_WIDTH_80:
417 new_sta_bw = IEEE80211_STA_RX_BW_80;
418 break;
419 case NL80211_CHAN_WIDTH_80P80:
420 case NL80211_CHAN_WIDTH_160:
421 new_sta_bw = IEEE80211_STA_RX_BW_160;
422 break;
423 default:
424 return -EINVAL;
425 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200426
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100427 if (new_sta_bw > sta->cur_max_bandwidth)
428 new_sta_bw = sta->cur_max_bandwidth;
Johannes Berg64f68e52012-03-28 10:58:37 +0200429
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100430 if (new_sta_bw < sta->sta.bandwidth) {
431 sta->sta.bandwidth = new_sta_bw;
432 rate_control_rate_update(local, sband, sta,
433 IEEE80211_RC_BW_CHANGED);
434 }
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530435
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100436 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
437 if (ret) {
438 sdata_info(sdata,
439 "AP %pM changed bandwidth to incompatible one - disconnect\n",
440 ifmgd->bssid);
441 return ret;
442 }
443
444 if (new_sta_bw > sta->sta.bandwidth) {
445 sta->sta.bandwidth = new_sta_bw;
446 rate_control_rate_update(local, sband, sta,
447 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200448 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200449
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100450 return 0;
Johannes Bergd5522e02009-03-30 13:23:35 +0200451}
452
Johannes Berg9c6bd792008-09-11 00:01:52 +0200453/* frame sending functions */
454
Johannes Berg66e67e42012-01-20 13:55:27 +0100455static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200456 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100457 struct ieee80211_supported_band *sband,
458 struct ieee80211_channel *channel,
459 enum ieee80211_smps_mode smps)
460{
Johannes Berg66e67e42012-01-20 13:55:27 +0100461 u8 *pos;
462 u32 flags = channel->flags;
463 u16 cap;
464 struct ieee80211_sta_ht_cap ht_cap;
465
466 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
467
Johannes Berg66e67e42012-01-20 13:55:27 +0100468 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
469 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
470
Johannes Berg66e67e42012-01-20 13:55:27 +0100471 /* determine capability flags */
472 cap = ht_cap.cap;
473
Johannes Berg9dde6422012-05-16 23:43:19 +0200474 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100475 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
476 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
477 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
478 cap &= ~IEEE80211_HT_CAP_SGI_40;
479 }
480 break;
481 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
482 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
483 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
484 cap &= ~IEEE80211_HT_CAP_SGI_40;
485 }
486 break;
487 }
488
Johannes Berg24398e32012-03-28 10:58:36 +0200489 /*
490 * If 40 MHz was disabled associate as though we weren't
491 * capable of 40 MHz -- some broken APs will never fall
492 * back to trying to transmit in 20 MHz.
493 */
494 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
495 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
496 cap &= ~IEEE80211_HT_CAP_SGI_40;
497 }
498
Johannes Berg66e67e42012-01-20 13:55:27 +0100499 /* set SM PS mode properly */
500 cap &= ~IEEE80211_HT_CAP_SM_PS;
501 switch (smps) {
502 case IEEE80211_SMPS_AUTOMATIC:
503 case IEEE80211_SMPS_NUM_MODES:
504 WARN_ON(1);
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500505 /* fall through */
Johannes Berg66e67e42012-01-20 13:55:27 +0100506 case IEEE80211_SMPS_OFF:
507 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
508 IEEE80211_HT_CAP_SM_PS_SHIFT;
509 break;
510 case IEEE80211_SMPS_STATIC:
511 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
512 IEEE80211_HT_CAP_SM_PS_SHIFT;
513 break;
514 case IEEE80211_SMPS_DYNAMIC:
515 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
516 IEEE80211_HT_CAP_SM_PS_SHIFT;
517 break;
518 }
519
520 /* reserve and fill IE */
521 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
522 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
523}
524
Sara Sharon322cd402015-07-08 15:41:43 +0300525/* This function determines vht capability flags for the association
526 * and builds the IE.
527 * Note - the function may set the owner of the MU-MIMO capability
528 */
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000529static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
530 struct sk_buff *skb,
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100531 struct ieee80211_supported_band *sband,
532 struct ieee80211_vht_cap *ap_vht_cap)
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000533{
Sara Sharon322cd402015-07-08 15:41:43 +0300534 struct ieee80211_local *local = sdata->local;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000535 u8 *pos;
536 u32 cap;
537 struct ieee80211_sta_vht_cap vht_cap;
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200538 u32 mask, ap_bf_sts, our_bf_sts;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000539
540 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
541
542 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +0100543 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000544
545 /* determine capability flags */
546 cap = vht_cap.cap;
547
Johannes Bergf2d9d272012-11-22 14:11:39 +0100548 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
Johannes Berg575f0532014-11-24 16:51:33 +0100549 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
550
551 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
552 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
553 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
554 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100555 }
556
557 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
558 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
Johannes Berg575f0532014-11-24 16:51:33 +0100559 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100560 }
561
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100562 /*
563 * Some APs apparently get confused if our capabilities are better
564 * than theirs, so restrict what we advertise in the assoc request.
565 */
566 if (!(ap_vht_cap->vht_cap_info &
567 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
Sara Sharon322cd402015-07-08 15:41:43 +0300568 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
569 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
570 else if (!(ap_vht_cap->vht_cap_info &
571 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
572 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
573
574 /*
575 * If some other vif is using the MU-MIMO capablity we cannot associate
576 * using MU-MIMO - this will lead to contradictions in the group-id
577 * mechanism.
578 * Ownership is defined since association request, in order to avoid
579 * simultaneous associations with MU-MIMO.
580 */
581 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
582 bool disable_mu_mimo = false;
583 struct ieee80211_sub_if_data *other;
584
585 list_for_each_entry_rcu(other, &local->interfaces, list) {
Sara Sharonb5a33d52016-02-16 12:48:18 +0200586 if (other->vif.mu_mimo_owner) {
Sara Sharon322cd402015-07-08 15:41:43 +0300587 disable_mu_mimo = true;
588 break;
589 }
590 }
591 if (disable_mu_mimo)
592 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
593 else
Sara Sharonb5a33d52016-02-16 12:48:18 +0200594 sdata->vif.mu_mimo_owner = true;
Sara Sharon322cd402015-07-08 15:41:43 +0300595 }
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100596
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200597 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
598
599 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
600 our_bf_sts = cap & mask;
601
602 if (ap_bf_sts < our_bf_sts) {
603 cap &= ~mask;
604 cap |= ap_bf_sts;
605 }
606
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000607 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000608 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000609 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
610}
611
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300612/* This function determines HE capability flags for the association
613 * and builds the IE.
614 */
615static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
616 struct sk_buff *skb,
617 struct ieee80211_supported_band *sband)
618{
619 u8 *pos;
620 const struct ieee80211_sta_he_cap *he_cap = NULL;
621 u8 he_cap_size;
622
623 he_cap = ieee80211_get_he_sta_cap(sband);
624 if (!he_cap)
625 return;
626
627 /*
628 * TODO: the 1 added is because this temporarily is under the EXTENSION
629 * IE. Get rid of it when it moves.
630 */
631 he_cap_size =
632 2 + 1 + sizeof(he_cap->he_cap_elem) +
633 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
634 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
635 he_cap->he_cap_elem.phy_cap_info);
636 pos = skb_put(skb, he_cap_size);
637 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
638}
639
Johannes Berg66e67e42012-01-20 13:55:27 +0100640static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
641{
642 struct ieee80211_local *local = sdata->local;
643 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
644 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
645 struct sk_buff *skb;
646 struct ieee80211_mgmt *mgmt;
647 u8 *pos, qos_info;
648 size_t offset = 0, noffset;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200649 int i, count, rates_len, supp_rates_len, shift;
Johannes Berg66e67e42012-01-20 13:55:27 +0100650 u16 capab;
651 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200652 struct ieee80211_chanctx_conf *chanctx_conf;
653 struct ieee80211_channel *chan;
Johannes Berg44f6d422017-06-10 13:52:44 +0300654 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100655
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200656 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +0100657
Johannes Berg55de9082012-07-26 17:24:39 +0200658 rcu_read_lock();
659 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
660 if (WARN_ON(!chanctx_conf)) {
661 rcu_read_unlock();
662 return;
663 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100664 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200665 rcu_read_unlock();
666 sband = local->hw.wiphy->bands[chan->band];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200667 shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg66e67e42012-01-20 13:55:27 +0100668
669 if (assoc_data->supp_rates_len) {
670 /*
671 * Get all rates supported by the device and the AP as
672 * some APs don't like getting a superset of their rates
673 * in the association request (e.g. D-Link DAP 1353 in
674 * b-only mode)...
675 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200676 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
677 assoc_data->supp_rates,
678 assoc_data->supp_rates_len,
679 &rates);
Johannes Berg66e67e42012-01-20 13:55:27 +0100680 } else {
681 /*
682 * In case AP not provide any supported rates information
683 * before association, we send information element(s) with
684 * all rates that we support.
685 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200686 rates_len = 0;
687 for (i = 0; i < sband->n_bitrates; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200688 rates |= BIT(i);
689 rates_len++;
690 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100691 }
692
693 skb = alloc_skb(local->hw.extra_tx_headroom +
694 sizeof(*mgmt) + /* bit too much but doesn't matter */
695 2 + assoc_data->ssid_len + /* SSID */
696 4 + rates_len + /* (extended) rates */
697 4 + /* power capability */
698 2 + 2 * sband->n_channels + /* supported channels */
699 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000700 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300701 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
702 sizeof(struct ieee80211_he_mcs_nss_supp) +
703 IEEE80211_HE_PPE_THRES_MAX_LEN +
Johannes Berg66e67e42012-01-20 13:55:27 +0100704 assoc_data->ie_len + /* extra IEs */
Jouni Malinen39404fe2016-10-27 00:42:05 +0300705 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
Johannes Berg66e67e42012-01-20 13:55:27 +0100706 9, /* WMM */
707 GFP_KERNEL);
708 if (!skb)
709 return;
710
711 skb_reserve(skb, local->hw.extra_tx_headroom);
712
713 capab = WLAN_CAPABILITY_ESS;
714
Johannes Berg57fbcce2016-04-12 15:56:15 +0200715 if (sband->band == NL80211_BAND_2GHZ) {
Johannes Bergea1b2b452015-06-02 20:15:49 +0200716 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
717 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
Johannes Berg66e67e42012-01-20 13:55:27 +0100718 }
719
720 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
721 capab |= WLAN_CAPABILITY_PRIVACY;
722
723 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg30686bf2015-06-02 21:39:54 +0200724 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
Johannes Berg66e67e42012-01-20 13:55:27 +0100725 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
726
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300727 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
728 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
729
Johannes Bergb080db52017-06-16 14:29:19 +0200730 mgmt = skb_put_zero(skb, 24);
Johannes Berg66e67e42012-01-20 13:55:27 +0100731 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
732 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
733 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
734
735 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
736 skb_put(skb, 10);
737 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
738 IEEE80211_STYPE_REASSOC_REQ);
739 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
740 mgmt->u.reassoc_req.listen_interval =
741 cpu_to_le16(local->hw.conf.listen_interval);
742 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
743 ETH_ALEN);
744 } else {
745 skb_put(skb, 4);
746 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
747 IEEE80211_STYPE_ASSOC_REQ);
748 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
749 mgmt->u.assoc_req.listen_interval =
750 cpu_to_le16(local->hw.conf.listen_interval);
751 }
752
753 /* SSID */
754 pos = skb_put(skb, 2 + assoc_data->ssid_len);
755 *pos++ = WLAN_EID_SSID;
756 *pos++ = assoc_data->ssid_len;
757 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
758
759 /* add all rates which were marked to be used above */
760 supp_rates_len = rates_len;
761 if (supp_rates_len > 8)
762 supp_rates_len = 8;
763
764 pos = skb_put(skb, supp_rates_len + 2);
765 *pos++ = WLAN_EID_SUPP_RATES;
766 *pos++ = supp_rates_len;
767
768 count = 0;
769 for (i = 0; i < sband->n_bitrates; i++) {
770 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200771 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
772 5 * (1 << shift));
773 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100774 if (++count == 8)
775 break;
776 }
777 }
778
779 if (rates_len > count) {
780 pos = skb_put(skb, rates_len - count + 2);
781 *pos++ = WLAN_EID_EXT_SUPP_RATES;
782 *pos++ = rates_len - count;
783
784 for (i++; i < sband->n_bitrates; i++) {
785 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200786 int rate;
787 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
788 5 * (1 << shift));
789 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100790 }
791 }
792 }
793
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300794 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
795 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100796 pos = skb_put(skb, 4);
797 *pos++ = WLAN_EID_PWR_CAPABILITY;
798 *pos++ = 2;
799 *pos++ = 0; /* min tx power */
Simon Wunderlich0430c882013-07-08 16:55:55 +0200800 /* max tx power */
801 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300802 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100803
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300804 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100805 /* TODO: get this in reg domain format */
806 pos = skb_put(skb, 2 * sband->n_channels + 2);
807 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
808 *pos++ = 2 * sband->n_channels;
809 for (i = 0; i < sband->n_channels; i++) {
810 *pos++ = ieee80211_frequency_to_channel(
811 sband->channels[i].center_freq);
812 *pos++ = 1; /* one channel in the subband*/
813 }
814 }
815
816 /* if present, add any custom IEs that go before HT */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200817 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100818 static const u8 before_ht[] = {
819 WLAN_EID_SSID,
820 WLAN_EID_SUPP_RATES,
821 WLAN_EID_EXT_SUPP_RATES,
822 WLAN_EID_PWR_CAPABILITY,
823 WLAN_EID_SUPPORTED_CHANNELS,
824 WLAN_EID_RSN,
825 WLAN_EID_QOS_CAPA,
826 WLAN_EID_RRM_ENABLED_CAPABILITIES,
827 WLAN_EID_MOBILITY_DOMAIN,
Johannes Berg8ed28742014-10-27 12:03:19 +0100828 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
829 WLAN_EID_RIC_DATA, /* reassoc only */
Johannes Berg66e67e42012-01-20 13:55:27 +0100830 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
831 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100832 static const u8 after_ric[] = {
833 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
834 WLAN_EID_HT_CAPABILITY,
835 WLAN_EID_BSS_COEX_2040,
Johannes Berga7f26d82017-08-05 11:44:32 +0300836 /* luckily this is almost always there */
Johannes Berg8ed28742014-10-27 12:03:19 +0100837 WLAN_EID_EXT_CAPABILITY,
838 WLAN_EID_QOS_TRAFFIC_CAPA,
839 WLAN_EID_TIM_BCAST_REQ,
840 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300841 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg8ed28742014-10-27 12:03:19 +0100842 WLAN_EID_VHT_CAPABILITY,
843 WLAN_EID_OPMODE_NOTIF,
844 };
845
846 noffset = ieee80211_ie_split_ric(assoc_data->ie,
847 assoc_data->ie_len,
848 before_ht,
849 ARRAY_SIZE(before_ht),
850 after_ric,
851 ARRAY_SIZE(after_ric),
852 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800853 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100854 offset = noffset;
855 }
856
Johannes Bergf2d9d272012-11-22 14:11:39 +0100857 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
858 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
859 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
860
Johannes Berga8243b72012-11-22 14:32:09 +0100861 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200862 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200863 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100864
Johannes Berg3de38022014-02-04 09:54:07 +0100865 /* if present, add any custom IEs that go before VHT */
866 if (assoc_data->ie_len) {
867 static const u8 before_vht[] = {
Johannes Berga7f26d82017-08-05 11:44:32 +0300868 /*
869 * no need to list the ones split off before HT
870 * or generated here
871 */
Johannes Berg3de38022014-02-04 09:54:07 +0100872 WLAN_EID_BSS_COEX_2040,
873 WLAN_EID_EXT_CAPABILITY,
874 WLAN_EID_QOS_TRAFFIC_CAPA,
875 WLAN_EID_TIM_BCAST_REQ,
876 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300877 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg3de38022014-02-04 09:54:07 +0100878 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100879
880 /* RIC already taken above, so no need to handle here anymore */
Johannes Berg3de38022014-02-04 09:54:07 +0100881 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
882 before_vht, ARRAY_SIZE(before_vht),
883 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800884 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg3de38022014-02-04 09:54:07 +0100885 offset = noffset;
886 }
887
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300888 /* if present, add any custom IEs that go before HE */
889 if (assoc_data->ie_len) {
890 static const u8 before_he[] = {
891 /*
892 * no need to list the ones split off before VHT
893 * or generated here
894 */
895 WLAN_EID_OPMODE_NOTIF,
896 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
897 /* 11ai elements */
898 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
899 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
900 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
901 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
902 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
903 /* TODO: add 11ah/11aj/11ak elements */
904 };
905
906 /* RIC already taken above, so no need to handle here anymore */
907 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
908 before_he, ARRAY_SIZE(before_he),
909 offset);
910 pos = skb_put(skb, noffset - offset);
911 memcpy(pos, assoc_data->ie + offset, noffset - offset);
912 offset = noffset;
913 }
914
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000915 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100916 ieee80211_add_vht_ie(sdata, skb, sband,
917 &assoc_data->ap_vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000918
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 Berg60f8b39c2008-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
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002764static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2765 struct ieee80211_mgmt *mgmt, size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002766{
2767 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2768 u8 bssid[ETH_ALEN];
2769 u16 auth_alg, auth_transaction, status_code;
2770 struct sta_info *sta;
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002771 struct ieee80211_event event = {
2772 .type = MLME_EVENT,
2773 .u.mlme.data = AUTH_EVENT,
2774 };
Johannes Berg66e67e42012-01-20 13:55:27 +01002775
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002776 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002777
2778 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002779 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002780
2781 if (!ifmgd->auth_data || ifmgd->auth_data->done)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002782 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002783
2784 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2785
Joe Perchesb203ca32012-05-08 18:56:52 +00002786 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002787 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002788
2789 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2790 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2791 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2792
2793 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002794 auth_transaction != ifmgd->auth_data->expected_transaction) {
2795 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2796 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2797 auth_transaction,
2798 ifmgd->auth_data->expected_transaction);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002799 return;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002800 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002801
2802 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002803 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2804 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002805 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002806 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002807 event.u.mlme.status = MLME_DENIED;
2808 event.u.mlme.reason = status_code;
2809 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002810 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002811 }
2812
2813 switch (ifmgd->auth_data->algorithm) {
2814 case WLAN_AUTH_OPEN:
2815 case WLAN_AUTH_LEAP:
2816 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002817 case WLAN_AUTH_SAE:
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03002818 case WLAN_AUTH_FILS_SK:
2819 case WLAN_AUTH_FILS_SK_PFS:
2820 case WLAN_AUTH_FILS_PK:
Johannes Berg66e67e42012-01-20 13:55:27 +01002821 break;
2822 case WLAN_AUTH_SHARED_KEY:
2823 if (ifmgd->auth_data->expected_transaction != 4) {
2824 ieee80211_auth_challenge(sdata, mgmt, len);
2825 /* need another frame */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002826 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002827 }
2828 break;
2829 default:
2830 WARN_ONCE(1, "invalid auth alg %d",
2831 ifmgd->auth_data->algorithm);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002832 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002833 }
2834
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002835 event.u.mlme.status = MLME_SUCCESS;
2836 drv_event_callback(sdata->local, sdata, &event);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002837 sdata_info(sdata, "authenticated\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002838 ifmgd->auth_data->done = true;
2839 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
Johannes Berg89afe612013-02-13 15:39:57 +01002840 ifmgd->auth_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002841 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01002842
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002843 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2844 ifmgd->auth_data->expected_transaction != 2) {
2845 /*
2846 * Report auth frame to user space for processing since another
2847 * round of Authentication frames is still needed.
2848 */
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002849 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002850 return;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002851 }
2852
Johannes Berg66e67e42012-01-20 13:55:27 +01002853 /* move station state to auth */
2854 mutex_lock(&sdata->local->sta_mtx);
2855 sta = sta_info_get(sdata, bssid);
2856 if (!sta) {
2857 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2858 goto out_err;
2859 }
2860 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002861 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002862 goto out_err;
2863 }
2864 mutex_unlock(&sdata->local->sta_mtx);
2865
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002866 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002867 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002868 out_err:
2869 mutex_unlock(&sdata->local->sta_mtx);
2870 /* ignore frame -- wait for timeout */
Johannes Berg66e67e42012-01-20 13:55:27 +01002871}
2872
Calvin Owensdfa1ad22014-02-11 12:36:24 -06002873#define case_WLAN(type) \
2874 case WLAN_REASON_##type: return #type
2875
2876static const char *ieee80211_get_reason_code_string(u16 reason_code)
2877{
2878 switch (reason_code) {
2879 case_WLAN(UNSPECIFIED);
2880 case_WLAN(PREV_AUTH_NOT_VALID);
2881 case_WLAN(DEAUTH_LEAVING);
2882 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2883 case_WLAN(DISASSOC_AP_BUSY);
2884 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2885 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2886 case_WLAN(DISASSOC_STA_HAS_LEFT);
2887 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2888 case_WLAN(DISASSOC_BAD_POWER);
2889 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2890 case_WLAN(INVALID_IE);
2891 case_WLAN(MIC_FAILURE);
2892 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
2893 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
2894 case_WLAN(IE_DIFFERENT);
2895 case_WLAN(INVALID_GROUP_CIPHER);
2896 case_WLAN(INVALID_PAIRWISE_CIPHER);
2897 case_WLAN(INVALID_AKMP);
2898 case_WLAN(UNSUPP_RSN_VERSION);
2899 case_WLAN(INVALID_RSN_IE_CAP);
2900 case_WLAN(IEEE8021X_FAILED);
2901 case_WLAN(CIPHER_SUITE_REJECTED);
2902 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
2903 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
2904 case_WLAN(DISASSOC_LOW_ACK);
2905 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
2906 case_WLAN(QSTA_LEAVE_QBSS);
2907 case_WLAN(QSTA_NOT_USE);
2908 case_WLAN(QSTA_REQUIRE_SETUP);
2909 case_WLAN(QSTA_TIMEOUT);
2910 case_WLAN(QSTA_CIPHER_NOT_SUPP);
2911 case_WLAN(MESH_PEER_CANCELED);
2912 case_WLAN(MESH_MAX_PEERS);
2913 case_WLAN(MESH_CONFIG);
2914 case_WLAN(MESH_CLOSE);
2915 case_WLAN(MESH_MAX_RETRIES);
2916 case_WLAN(MESH_CONFIRM_TIMEOUT);
2917 case_WLAN(MESH_INVALID_GTK);
2918 case_WLAN(MESH_INCONSISTENT_PARAM);
2919 case_WLAN(MESH_INVALID_SECURITY);
2920 case_WLAN(MESH_PATH_ERROR);
2921 case_WLAN(MESH_PATH_NOFORWARD);
2922 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
2923 case_WLAN(MAC_EXISTS_IN_MBSS);
2924 case_WLAN(MESH_CHAN_REGULATORY);
2925 case_WLAN(MESH_CHAN);
2926 default: return "<unknown>";
2927 }
2928}
Johannes Berg66e67e42012-01-20 13:55:27 +01002929
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002930static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2931 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002932{
Johannes Berg46900292009-02-15 12:44:28 +01002933 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergc9c99f82015-06-01 14:10:09 +02002934 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002935
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002936 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002937
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002938 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002939 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002940
Johannes Bergc9c99f82015-06-01 14:10:09 +02002941 if (ifmgd->associated &&
2942 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
2943 const u8 *bssid = ifmgd->associated->bssid;
2944
2945 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
2946 bssid, reason_code,
2947 ieee80211_get_reason_code_string(reason_code));
2948
2949 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2950
2951 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
2952 reason_code);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002953 return;
Johannes Bergc9c99f82015-06-01 14:10:09 +02002954 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002955
Johannes Bergc9c99f82015-06-01 14:10:09 +02002956 if (ifmgd->assoc_data &&
2957 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2958 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002959
Johannes Bergc9c99f82015-06-01 14:10:09 +02002960 sdata_info(sdata,
2961 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
2962 bssid, reason_code,
2963 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07002964
Johannes Berge6f462d2016-12-08 17:22:09 +01002965 ieee80211_destroy_assoc_data(sdata, false, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07002966
Johannes Bergc9c99f82015-06-01 14:10:09 +02002967 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2968 return;
2969 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002970}
2971
2972
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002973static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2974 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002975{
Johannes Berg46900292009-02-15 12:44:28 +01002976 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002977 u16 reason_code;
2978
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002979 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002980
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002981 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002982 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002983
Johannes Berg66e67e42012-01-20 13:55:27 +01002984 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002985 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002986 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002987
2988 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2989
Arkadiusz Miskiewicz68506e92017-02-15 14:21:27 +01002990 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
2991 mgmt->sa, reason_code,
2992 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07002993
Johannes Berg37ad3882012-02-24 13:50:54 +01002994 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2995
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002996 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002997}
2998
Christian Lamparterc74d0842011-10-15 00:14:49 +02002999static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3000 u8 *supp_rates, unsigned int supp_rates_len,
3001 u32 *rates, u32 *basic_rates,
3002 bool *have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003003 int *min_rate, int *min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03003004 int shift)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003005{
3006 int i, j;
3007
3008 for (i = 0; i < supp_rates_len; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003009 int rate = supp_rates[i] & 0x7f;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003010 bool is_basic = !!(supp_rates[i] & 0x80);
3011
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003012 if ((rate * 5 * (1 << shift)) > 110)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003013 *have_higher_than_11mbit = true;
3014
3015 /*
Johannes Berga6289d32017-03-06 22:59:04 +01003016 * Skip HT and VHT BSS membership selectors since they're not
3017 * rates.
Christian Lamparterc74d0842011-10-15 00:14:49 +02003018 *
Johannes Berga6289d32017-03-06 22:59:04 +01003019 * Note: Even though the membership selector and the basic
Christian Lamparterc74d0842011-10-15 00:14:49 +02003020 * rate flag share the same bit, they are not exactly
3021 * the same.
3022 */
Johannes Berga6289d32017-03-06 22:59:04 +01003023 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3024 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
Christian Lamparterc74d0842011-10-15 00:14:49 +02003025 continue;
3026
3027 for (j = 0; j < sband->n_bitrates; j++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003028 struct ieee80211_rate *br;
3029 int brate;
3030
3031 br = &sband->bitrates[j];
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003032
3033 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3034 if (brate == rate) {
Christian Lamparterc74d0842011-10-15 00:14:49 +02003035 *rates |= BIT(j);
3036 if (is_basic)
3037 *basic_rates |= BIT(j);
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003038 if ((rate * 5) < *min_rate) {
3039 *min_rate = rate * 5;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003040 *min_rate_index = j;
3041 }
3042 break;
3043 }
3044 }
3045 }
3046}
Jiri Bencf0706e82007-05-05 11:45:53 -07003047
Johannes Berg66e67e42012-01-20 13:55:27 +01003048static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3049 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003050 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003051{
Johannes Berg46900292009-02-15 12:44:28 +01003052 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01003053 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01003054 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003055 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003056 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003057 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07003058 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02003059 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg35d865a2013-05-28 10:54:03 +02003060 const struct cfg80211_bss_ies *bss_ies = NULL;
3061 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
Johannes Bergae5eb022008-10-14 16:58:37 +02003062 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003063 int err;
Johannes Berg35d865a2013-05-28 10:54:03 +02003064 bool ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003065
Johannes Bergaf6b6372009-12-23 13:15:35 +01003066 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07003067
Jiri Bencf0706e82007-05-05 11:45:53 -07003068 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003069 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07003070
Johannes Bergc7c477b2017-12-01 13:50:51 +02003071 /*
3072 * The 5 MSB of the AID field are reserved
3073 * (802.11-2016 9.4.1.8 AID field)
3074 */
3075 aid &= 0x7ff;
Johannes Berg1dd84aa2007-10-10 12:03:41 +02003076
Johannes Berg05cb9102011-10-28 11:59:47 +02003077 ifmgd->broken_ap = false;
3078
3079 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003080 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3081 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02003082 aid = 0;
3083 ifmgd->broken_ap = true;
3084 }
3085
Johannes Bergaf6b6372009-12-23 13:15:35 +01003086 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01003087 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003088
Jiri Bencf0706e82007-05-05 11:45:53 -07003089 if (!elems.supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003090 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01003091 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07003092 }
3093
Johannes Berg46900292009-02-15 12:44:28 +01003094 ifmgd->aid = aid;
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02003095 ifmgd->tdls_chan_switch_prohibited =
3096 elems.ext_capab && elems.ext_capab_len >= 5 &&
3097 (elems.ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
Jiri Bencf0706e82007-05-05 11:45:53 -07003098
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003099 /*
Johannes Berg35d865a2013-05-28 10:54:03 +02003100 * Some APs are erroneously not including some information in their
3101 * (re)association response frames. Try to recover by using the data
3102 * from the beacon or probe response. This seems to afflict mobile
3103 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3104 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3105 */
3106 if ((assoc_data->wmm && !elems.wmm_param) ||
3107 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3108 (!elems.ht_cap_elem || !elems.ht_operation)) ||
3109 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3110 (!elems.vht_cap_elem || !elems.vht_operation))) {
3111 const struct cfg80211_bss_ies *ies;
3112 struct ieee802_11_elems bss_elems;
3113
3114 rcu_read_lock();
3115 ies = rcu_dereference(cbss->ies);
3116 if (ies)
3117 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3118 GFP_ATOMIC);
3119 rcu_read_unlock();
3120 if (!bss_ies)
3121 return false;
3122
3123 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3124 false, &bss_elems);
3125 if (assoc_data->wmm &&
3126 !elems.wmm_param && bss_elems.wmm_param) {
3127 elems.wmm_param = bss_elems.wmm_param;
3128 sdata_info(sdata,
3129 "AP bug: WMM param missing from AssocResp\n");
3130 }
3131
3132 /*
3133 * Also check if we requested HT/VHT, otherwise the AP doesn't
3134 * have to include the IEs in the (re)association response.
3135 */
3136 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
3137 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3138 elems.ht_cap_elem = bss_elems.ht_cap_elem;
3139 sdata_info(sdata,
3140 "AP bug: HT capability missing from AssocResp\n");
3141 }
3142 if (!elems.ht_operation && bss_elems.ht_operation &&
3143 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3144 elems.ht_operation = bss_elems.ht_operation;
3145 sdata_info(sdata,
3146 "AP bug: HT operation missing from AssocResp\n");
3147 }
3148 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
3149 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3150 elems.vht_cap_elem = bss_elems.vht_cap_elem;
3151 sdata_info(sdata,
3152 "AP bug: VHT capa missing from AssocResp\n");
3153 }
3154 if (!elems.vht_operation && bss_elems.vht_operation &&
3155 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3156 elems.vht_operation = bss_elems.vht_operation;
3157 sdata_info(sdata,
3158 "AP bug: VHT operation missing from AssocResp\n");
3159 }
3160 }
3161
3162 /*
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003163 * We previously checked these in the beacon/probe response, so
3164 * they should be present here. This is just a safety net.
3165 */
3166 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3167 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
3168 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003169 "HT AP is missing WMM params or HT capability/operation\n");
3170 ret = false;
3171 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003172 }
3173
3174 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3175 (!elems.vht_cap_elem || !elems.vht_operation)) {
3176 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003177 "VHT AP is missing VHT capability/operation\n");
3178 ret = false;
3179 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003180 }
3181
Guy Eilam2a33bee2011-08-17 15:18:15 +03003182 mutex_lock(&sdata->local->sta_mtx);
3183 /*
3184 * station info was already allocated and inserted before
3185 * the association and should be available to us
3186 */
Johannes Berg7852e362012-01-20 13:55:24 +01003187 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003188 if (WARN_ON(!sta)) {
3189 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003190 ret = false;
3191 goto out;
Jiri Bencf0706e82007-05-05 11:45:53 -07003192 }
3193
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05303194 sband = ieee80211_get_sband(sdata);
3195 if (!sband) {
3196 mutex_unlock(&sdata->local->sta_mtx);
3197 ret = false;
3198 goto out;
3199 }
Johannes Berg8318d782008-01-24 19:38:38 +01003200
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003201 /*
3202 * If AP doesn't support HT, or it doesn't have HE mandatory IEs, mark
3203 * HE as disabled. If on the 5GHz band, make sure it supports VHT.
3204 */
3205 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
3206 (sband->band == NL80211_BAND_5GHZ &&
3207 ifmgd->flags & IEEE80211_STA_DISABLE_VHT) ||
3208 (!elems.he_cap && !elems.he_operation))
3209 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
3210
3211 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3212 (!elems.he_cap || !elems.he_operation)) {
3213 mutex_unlock(&sdata->local->sta_mtx);
3214 sdata_info(sdata,
3215 "HE AP is missing HE capability/operation\n");
3216 ret = false;
3217 goto out;
3218 }
3219
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003220 /* Set up internal HT/VHT capabilities */
Johannes Berga8243b72012-11-22 14:32:09 +01003221 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08003222 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01003223 elems.ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02003224
Mahesh Palivela818255e2012-10-10 11:33:04 +00003225 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3226 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01003227 elems.vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00003228
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003229 if (elems.he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3230 elems.he_cap) {
3231 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3232 elems.he_cap,
3233 elems.he_cap_len,
3234 sta);
3235
3236 bss_conf->he_support = sta->sta.he_cap.has_he;
3237 } else {
3238 bss_conf->he_support = false;
3239 }
3240
3241 if (bss_conf->he_support) {
3242 u32 he_oper_params =
3243 le32_to_cpu(elems.he_operation->he_oper_params);
3244
3245 bss_conf->bss_color = he_oper_params &
3246 IEEE80211_HE_OPERATION_BSS_COLOR_MASK;
3247 bss_conf->htc_trig_based_pkt_ext =
3248 (he_oper_params &
3249 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK) <<
3250 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_OFFSET;
3251 bss_conf->frame_time_rts_th =
3252 (he_oper_params &
3253 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK) <<
3254 IEEE80211_HE_OPERATION_RTS_THRESHOLD_OFFSET;
3255
3256 bss_conf->multi_sta_back_32bit =
3257 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3258 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
3259
3260 bss_conf->ack_enabled =
3261 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3262 IEEE80211_HE_MAC_CAP2_ACK_EN;
3263
3264 bss_conf->uora_exists = !!elems.uora_element;
3265 if (elems.uora_element)
3266 bss_conf->uora_ocw_range = elems.uora_element[0];
3267
3268 /* TODO: OPEN: what happens if BSS color disable is set? */
3269 }
3270
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003271 /*
3272 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3273 * in their association response, so ignore that data for our own
3274 * configuration. If it changed since the last beacon, we'll get the
3275 * next beacon and update then.
3276 */
Johannes Berg11289582013-02-07 17:36:12 +01003277
Johannes Bergbee7f5862013-02-07 22:24:55 +01003278 /*
3279 * If an operating mode notification IE is present, override the
3280 * NSS calculation (that would be done in rate_control_rate_init())
3281 * and use the # of streams from that element.
3282 */
3283 if (elems.opmode_notif &&
3284 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3285 u8 nss;
3286
3287 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3288 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3289 nss += 1;
3290 sta->sta.rx_nss = nss;
3291 }
3292
Johannes Berg4b7679a2008-09-18 18:14:18 +02003293 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003294
Tamizh chelvam93f04902015-10-07 10:40:04 +05303295 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003296 set_sta_flag(sta, WLAN_STA_MFP);
Tamizh chelvam93f04902015-10-07 10:40:04 +05303297 sta->sta.mfp = true;
3298 } else {
3299 sta->sta.mfp = false;
3300 }
Jouni Malinen5394af42009-01-08 13:31:59 +02003301
Johannes Berg527871d2015-03-21 08:09:55 +01003302 sta->sta.wme = elems.wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
Johannes Bergddf4ac52008-10-22 11:41:38 +02003303
Johannes Berg3e4d40f2013-02-07 17:19:08 +01003304 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01003305 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3306 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3307 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003308 sdata_info(sdata,
3309 "failed to move station %pM to desired state\n",
3310 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01003311 WARN_ON(__sta_info_destroy(sta));
3312 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003313 ret = false;
3314 goto out;
Johannes Bergc8987872012-01-20 13:55:17 +01003315 }
3316
Johannes Berg7852e362012-01-20 13:55:24 +01003317 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02003318
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003319 /*
3320 * Always handle WMM once after association regardless
3321 * of the first value the AP uses. Setting -1 here has
3322 * that effect because the AP values is an unsigned
3323 * 4-bit value.
3324 */
3325 ifmgd->wmm_last_param_set = -1;
3326
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003327 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Bergcec66282015-10-22 17:46:04 +02003328 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003329 } else if (!ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003330 elems.wmm_param_len,
3331 elems.mu_edca_param_set)) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003332 /* still enable QoS since we might have HT/VHT */
3333 ieee80211_set_wmm_default(sdata, false, true);
3334 /* set the disable-WMM flag in this case to disable
3335 * tracking WMM parameter changes in the beacon if
3336 * the parameters weren't actually valid. Doing so
3337 * avoids changing parameters very strangely when
3338 * the AP is going back and forth between valid and
3339 * invalid parameters.
3340 */
3341 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3342 }
Johannes Berg3abead52012-03-02 15:56:59 +01003343 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07003344
Avraham Sterne38a0172017-04-26 10:58:47 +03003345 if (elems.max_idle_period_ie) {
3346 bss_conf->max_idle_period =
3347 le16_to_cpu(elems.max_idle_period_ie->max_idle_period);
3348 bss_conf->protected_keep_alive =
3349 !!(elems.max_idle_period_ie->idle_options &
3350 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3351 changed |= BSS_CHANGED_KEEP_ALIVE;
3352 } else {
3353 bss_conf->max_idle_period = 0;
3354 bss_conf->protected_keep_alive = false;
3355 }
3356
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003357 /* set AID and assoc capability,
3358 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01003359 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003360 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003361 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003362
Kalle Valo15b7b062009-03-22 21:57:14 +02003363 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01003364 * If we're using 4-addr mode, let the AP know that we're
3365 * doing so, so that it can create the STA VLAN on its side
3366 */
3367 if (ifmgd->use_4addr)
3368 ieee80211_send_4addr_nullfunc(local, sdata);
3369
3370 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02003371 * Start timer to probe the connection to the AP now.
3372 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02003373 */
Johannes Bergb291ba12009-07-10 15:29:03 +02003374 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003375 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02003376
Johannes Berg35d865a2013-05-28 10:54:03 +02003377 ret = true;
3378 out:
3379 kfree(bss_ies);
3380 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003381}
3382
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003383static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3384 struct ieee80211_mgmt *mgmt,
3385 size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01003386{
3387 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3388 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3389 u16 capab_info, status_code, aid;
3390 struct ieee802_11_elems elems;
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003391 int ac, uapsd_queues = -1;
Johannes Berg66e67e42012-01-20 13:55:27 +01003392 u8 *pos;
3393 bool reassoc;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003394 struct cfg80211_bss *bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003395 struct ieee80211_event event = {
3396 .type = MLME_EVENT,
3397 .u.mlme.data = ASSOC_EVENT,
3398 };
Jiri Bencf0706e82007-05-05 11:45:53 -07003399
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003400 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003401
3402 if (!assoc_data)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003403 return;
Joe Perchesb203ca32012-05-08 18:56:52 +00003404 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003405 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003406
3407 /*
3408 * AssocResp and ReassocResp have identical structure, so process both
3409 * of them in this function.
3410 */
3411
3412 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003413 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003414
Simon Dinkin7a7d3e42017-08-31 13:09:36 +03003415 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
Johannes Berg66e67e42012-01-20 13:55:27 +01003416 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3417 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3418 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3419
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003420 sdata_info(sdata,
3421 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3422 reassoc ? "Rea" : "A", mgmt->sa,
3423 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01003424
Jouni Malinen39404fe2016-10-27 00:42:05 +03003425 if (assoc_data->fils_kek_len &&
3426 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3427 return;
3428
Johannes Berg66e67e42012-01-20 13:55:27 +01003429 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01003430 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01003431
3432 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01003433 elems.timeout_int &&
3434 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003435 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01003436 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01003437 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003438 sdata_info(sdata,
3439 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3440 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01003441 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01003442 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01003443 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003444 run_again(sdata, assoc_data->timeout);
3445 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003446 }
3447
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003448 bss = assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01003449
3450 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003451 sdata_info(sdata, "%pM denied association (code=%d)\n",
3452 mgmt->sa, status_code);
Johannes Berge6f462d2016-12-08 17:22:09 +01003453 ieee80211_destroy_assoc_data(sdata, false, false);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003454 event.u.mlme.status = MLME_DENIED;
3455 event.u.mlme.reason = status_code;
3456 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01003457 } else {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003458 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003459 /* oops -- internal error -- send timeout for now */
Johannes Berge6f462d2016-12-08 17:22:09 +01003460 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02003461 cfg80211_assoc_timeout(sdata->dev, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003462 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003463 }
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003464 event.u.mlme.status = MLME_SUCCESS;
3465 drv_event_callback(sdata->local, sdata, &event);
John W. Linville635d9992012-07-09 16:34:34 -04003466 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01003467
3468 /*
3469 * destroy assoc_data afterwards, as otherwise an idle
3470 * recalc after assoc_data is NULL but before associated
3471 * is set can cause the interface to go idle
3472 */
Johannes Berge6f462d2016-12-08 17:22:09 +01003473 ieee80211_destroy_assoc_data(sdata, true, false);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003474
3475 /* get uapsd queues configuration */
3476 uapsd_queues = 0;
3477 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3478 if (sdata->tx_conf[ac].uapsd)
Emmanuel Grumbachf438ceb2016-10-18 23:12:12 +03003479 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
Johannes Berg66e67e42012-01-20 13:55:27 +01003480 }
3481
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003482 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues);
Johannes Berg66e67e42012-01-20 13:55:27 +01003483}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003484
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003485static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003486 struct ieee80211_mgmt *mgmt, size_t len,
Jiri Bencf0706e82007-05-05 11:45:53 -07003487 struct ieee80211_rx_status *rx_status,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003488 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07003489{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003490 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02003491 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01003492 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01003493
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003494 sdata_assert_lock(sdata);
Johannes Bergb4f286a12013-03-26 14:13:58 +01003495
Emmanuel Grumbach3afc2162014-03-04 16:50:13 +02003496 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3497 if (!channel)
Johannes Berg5bda6172008-09-08 11:05:10 +02003498 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003499
Johannes Berg98c8fcc2008-09-08 17:44:26 +02003500 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003501 channel);
Alexander Bondar817cee72013-05-19 14:23:57 +03003502 if (bss) {
Alexander Bondar817cee72013-05-19 14:23:57 +03003503 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
Johannes Bergd2722f82014-03-04 11:43:28 +01003504 ieee80211_rx_bss_put(local, bss);
Alexander Bondar817cee72013-05-19 14:23:57 +03003505 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003506}
3507
3508
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003509static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003510 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003511{
Johannes Bergaf6b6372009-12-23 13:15:35 +01003512 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02003513 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003514 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3515 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03003516 struct ieee802_11_elems elems;
3517
Kalle Valo15b7b062009-03-22 21:57:14 +02003518 ifmgd = &sdata->u.mgd;
3519
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003520 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003521
Joe Perchesb203ca32012-05-08 18:56:52 +00003522 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03003523 return; /* ignore ProbeResp to foreign address */
3524
Ester Kummerae6a44e2008-06-27 18:54:48 +03003525 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3526 if (baselen > len)
3527 return;
3528
3529 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003530 false, &elems);
Ester Kummerae6a44e2008-06-27 18:54:48 +03003531
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003532 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03003533
Johannes Berg77fdaa12009-07-07 03:45:17 +02003534 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003535 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003536 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003537}
3538
Johannes Bergd91f36d2009-04-16 13:17:26 +02003539/*
3540 * This is the canonical list of information elements we care about,
3541 * the filter code also gives us all changes to the Microsoft OUI
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003542 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3543 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3544 * changes to requested client power.
Johannes Bergd91f36d2009-04-16 13:17:26 +02003545 *
3546 * We implement beacon filtering in software since that means we can
3547 * avoid processing the frame here and in cfg80211, and userspace
3548 * will not be able to tell whether the hardware supports it or not.
3549 *
3550 * XXX: This list needs to be dynamic -- userspace needs to be able to
3551 * add items it requires. It also needs to be able to tell us to
3552 * look out for other vendor IEs.
3553 */
3554static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02003555 (1ULL << WLAN_EID_COUNTRY) |
3556 (1ULL << WLAN_EID_ERP_INFO) |
3557 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3558 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3559 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg70a3fd62015-03-12 08:53:29 +02003560 (1ULL << WLAN_EID_HT_OPERATION) |
3561 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003562
Tosoni1ad22fb2018-03-14 16:58:34 +00003563static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3564 struct ieee80211_if_managed *ifmgd,
3565 struct ieee80211_bss_conf *bss_conf,
3566 struct ieee80211_local *local,
3567 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003568{
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003569 /* Track average RSSI from the Beacon frames of the current AP */
Tosoni1ad22fb2018-03-14 16:58:34 +00003570
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003571 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3572 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Johannes Berg338c17a2015-08-28 10:52:54 +02003573 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003574 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03003575 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003576 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003577 } else {
Jouni Malinen391a2002010-08-27 22:22:00 +03003578 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003579 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003580
Johannes Berg338c17a2015-08-28 10:52:54 +02003581 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3582
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003583 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3584 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003585 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003586 int last_sig = ifmgd->last_ave_beacon_signal;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003587 struct ieee80211_event event = {
3588 .type = RSSI_EVENT,
3589 };
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003590
3591 /*
3592 * if signal crosses either of the boundaries, invoke callback
3593 * with appropriate parameters
3594 */
3595 if (sig > ifmgd->rssi_max_thold &&
3596 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3597 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003598 event.u.rssi.data = RSSI_EVENT_HIGH;
3599 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003600 } else if (sig < ifmgd->rssi_min_thold &&
3601 (last_sig >= ifmgd->rssi_max_thold ||
3602 last_sig == 0)) {
3603 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003604 event.u.rssi.data = RSSI_EVENT_LOW;
3605 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003606 }
3607 }
3608
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003609 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03003610 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01003611 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003612 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003613 int last_event = ifmgd->last_cqm_event_signal;
3614 int thold = bss_conf->cqm_rssi_thold;
3615 int hyst = bss_conf->cqm_rssi_hyst;
Johannes Berg338c17a2015-08-28 10:52:54 +02003616
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003617 if (sig < thold &&
3618 (last_event == 0 || sig < last_event - hyst)) {
3619 ifmgd->last_cqm_event_signal = sig;
3620 ieee80211_cqm_rssi_notify(
3621 &sdata->vif,
3622 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003623 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003624 } else 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_HIGH,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003630 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003631 }
3632 }
3633
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003634 if (bss_conf->cqm_rssi_low &&
3635 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3636 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3637 int last_event = ifmgd->last_cqm_event_signal;
3638 int low = bss_conf->cqm_rssi_low;
3639 int high = bss_conf->cqm_rssi_high;
3640
3641 if (sig < low &&
3642 (last_event == 0 || last_event >= low)) {
3643 ifmgd->last_cqm_event_signal = sig;
3644 ieee80211_cqm_rssi_notify(
3645 &sdata->vif,
3646 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3647 sig, GFP_KERNEL);
3648 } else if (sig > high &&
3649 (last_event == 0 || last_event <= high)) {
3650 ifmgd->last_cqm_event_signal = sig;
3651 ieee80211_cqm_rssi_notify(
3652 &sdata->vif,
3653 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3654 sig, GFP_KERNEL);
3655 }
3656 }
Tosoni1ad22fb2018-03-14 16:58:34 +00003657}
3658
3659static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3660 struct ieee80211_mgmt *mgmt, size_t len,
3661 struct ieee80211_rx_status *rx_status)
3662{
3663 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3664 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3665 size_t baselen;
3666 struct ieee802_11_elems elems;
3667 struct ieee80211_local *local = sdata->local;
3668 struct ieee80211_chanctx_conf *chanctx_conf;
3669 struct ieee80211_channel *chan;
3670 struct sta_info *sta;
3671 u32 changed = 0;
3672 bool erp_valid;
3673 u8 erp_value = 0;
3674 u32 ncrc;
3675 u8 *bssid;
3676 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3677
3678 sdata_assert_lock(sdata);
3679
3680 /* Process beacon from the current BSS */
3681 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3682 if (baselen > len)
3683 return;
3684
3685 rcu_read_lock();
3686 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3687 if (!chanctx_conf) {
3688 rcu_read_unlock();
3689 return;
3690 }
3691
3692 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3693 rcu_read_unlock();
3694 return;
3695 }
3696 chan = chanctx_conf->def.chan;
3697 rcu_read_unlock();
3698
3699 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
3700 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3701 ieee802_11_parse_elems(mgmt->u.beacon.variable,
3702 len - baselen, false, &elems);
3703
3704 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3705 if (elems.tim && !elems.parse_error) {
3706 const struct ieee80211_tim_ie *tim_ie = elems.tim;
3707 ifmgd->dtim_period = tim_ie->dtim_period;
3708 }
3709 ifmgd->have_beacon = true;
3710 ifmgd->assoc_data->need_beacon = false;
3711 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3712 sdata->vif.bss_conf.sync_tsf =
3713 le64_to_cpu(mgmt->u.beacon.timestamp);
3714 sdata->vif.bss_conf.sync_device_ts =
3715 rx_status->device_timestamp;
3716 if (elems.tim)
3717 sdata->vif.bss_conf.sync_dtim_count =
3718 elems.tim->dtim_count;
3719 else
3720 sdata->vif.bss_conf.sync_dtim_count = 0;
3721 }
3722 /* continue assoc process */
3723 ifmgd->assoc_data->timeout = jiffies;
3724 ifmgd->assoc_data->timeout_started = true;
3725 run_again(sdata, ifmgd->assoc_data->timeout);
3726 return;
3727 }
3728
3729 if (!ifmgd->associated ||
3730 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3731 return;
3732 bssid = ifmgd->associated->bssid;
3733
3734 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3735 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
3736 local, rx_status);
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003737
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003738 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003739 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01003740 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003741 ieee80211_reset_ap_probe(sdata);
Jouni Malinen92778182009-05-14 21:15:36 +03003742 }
3743
Johannes Bergb291ba12009-07-10 15:29:03 +02003744 /*
3745 * Push the beacon loss detection into the future since
3746 * we are processing a beacon from the AP just now.
3747 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003748 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003749
Johannes Bergd91f36d2009-04-16 13:17:26 +02003750 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3751 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003752 len - baselen, false, &elems,
Johannes Bergd91f36d2009-04-16 13:17:26 +02003753 care_about_ies, ncrc);
3754
Johannes Berg90d13e82015-09-24 16:13:07 +02003755 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3756 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3757 if (local->hw.conf.dynamic_ps_timeout > 0) {
3758 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3759 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3760 ieee80211_hw_config(local,
3761 IEEE80211_CONF_CHANGE_PS);
Kalle Valo572e0012009-02-10 17:09:31 +02003762 }
Johannes Berg076cdcb2015-09-24 16:14:55 +02003763 ieee80211_send_nullfunc(local, sdata, false);
Johannes Berg90d13e82015-09-24 16:13:07 +02003764 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3765 local->pspolling = true;
3766
3767 /*
3768 * Here is assumed that the driver will be
3769 * able to send ps-poll frame and receive a
3770 * response even though power save mode is
3771 * enabled, but some drivers might require
3772 * to disable power save here. This needs
3773 * to be investigated.
3774 */
3775 ieee80211_send_pspoll(local, sdata);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003776 }
3777 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003778
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01003779 if (sdata->vif.p2p ||
3780 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003781 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003782 int ret;
3783
3784 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3785 len - baselen,
3786 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003787 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003788 if (ret >= 2) {
3789 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3790 /* valid noa_attr and index changed */
3791 sdata->u.mgd.p2p_noa_index = noa.index;
3792 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3793 changed |= BSS_CHANGED_P2P_PS;
3794 /*
3795 * make sure we update all information, the CRC
3796 * mechanism doesn't look at P2P attributes.
3797 */
3798 ifmgd->beacon_crc_valid = false;
3799 }
3800 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3801 /* noa_attr not found and we had valid noa_attr before */
3802 sdata->u.mgd.p2p_noa_index = -1;
3803 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003804 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003805 ifmgd->beacon_crc_valid = false;
3806 }
3807 }
3808
Luciano Coelho0c21e632014-10-08 09:48:39 +03003809 if (ifmgd->csa_waiting_bcn)
3810 ieee80211_chswitch_post_beacon(sdata);
3811
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003812 /*
3813 * Update beacon timing and dtim count on every beacon appearance. This
3814 * will allow the driver to use the most updated values. Do it before
3815 * comparing this one with last received beacon.
3816 * IMPORTANT: These parameters would possibly be out of sync by the time
3817 * the driver will use them. The synchronized view is currently
3818 * guaranteed only in certain callbacks.
3819 */
Johannes Berg30686bf2015-06-02 21:39:54 +02003820 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003821 sdata->vif.bss_conf.sync_tsf =
3822 le64_to_cpu(mgmt->u.beacon.timestamp);
3823 sdata->vif.bss_conf.sync_device_ts =
3824 rx_status->device_timestamp;
3825 if (elems.tim)
3826 sdata->vif.bss_conf.sync_dtim_count =
3827 elems.tim->dtim_count;
3828 else
3829 sdata->vif.bss_conf.sync_dtim_count = 0;
3830 }
3831
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003832 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003833 return;
Jouni Malinen30196672009-05-19 17:01:43 +03003834 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003835 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03003836
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003837 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg7d257452012-07-06 17:37:43 +02003838
Johannes Bergd70b7612013-08-23 15:48:48 +02003839 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003840 rx_status->device_timestamp,
Johannes Bergd70b7612013-08-23 15:48:48 +02003841 &elems, true);
3842
Johannes Berg095d81c2013-10-15 12:25:07 +02003843 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
3844 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003845 elems.wmm_param_len,
3846 elems.mu_edca_param_set))
Johannes Berg7d257452012-07-06 17:37:43 +02003847 changed |= BSS_CHANGED_QOS;
3848
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003849 /*
3850 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01003851 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003852 */
Alexander Bondar989c6502013-05-16 17:34:17 +03003853 if (!ifmgd->have_beacon) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003854 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3855 if (elems.tim)
3856 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3857 else
3858 bss_conf->dtim_period = 1;
Johannes Bergef429da2013-02-05 17:48:40 +01003859
Alexander Bondar989c6502013-05-16 17:34:17 +03003860 changed |= BSS_CHANGED_BEACON_INFO;
3861 ifmgd->have_beacon = true;
Alexander Bondar482a9c72013-06-03 17:29:33 +03003862
3863 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02003864 ieee80211_recalc_ps(local);
Alexander Bondar482a9c72013-06-03 17:29:33 +03003865 mutex_unlock(&local->iflist_mtx);
3866
Alexander Bondarce857882013-05-06 17:17:04 +03003867 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003868 }
3869
Johannes Berg1946bed2013-03-27 14:31:53 +01003870 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02003871 erp_valid = true;
3872 erp_value = elems.erp_info[0];
3873 } else {
3874 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04003875 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003876 changed |= ieee80211_handle_bss_capability(sdata,
3877 le16_to_cpu(mgmt->u.beacon.capab_info),
3878 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07003879
Johannes Berg11289582013-02-07 17:36:12 +01003880 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f5862013-02-07 22:24:55 +01003881 sta = sta_info_get(sdata, bssid);
3882
Eliad Peller53b954e2014-07-24 11:20:05 +03003883 if (ieee80211_config_bw(sdata, sta,
3884 elems.ht_cap_elem, elems.ht_operation,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003885 elems.vht_operation, elems.he_operation,
3886 bssid, &changed)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003887 mutex_unlock(&local->sta_mtx);
Johannes Berg89f774e2016-01-25 15:46:36 +02003888 sdata_info(sdata,
3889 "failed to follow AP %pM bandwidth change, disconnect\n",
3890 bssid);
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003891 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3892 WLAN_REASON_DEAUTH_LEAVING,
3893 true, deauth_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003894 ieee80211_report_disconnect(sdata, deauth_buf,
3895 sizeof(deauth_buf), true,
3896 WLAN_REASON_DEAUTH_LEAVING);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003897 return;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003898 }
Johannes Bergbee7f5862013-02-07 22:24:55 +01003899
3900 if (sta && elems.opmode_notif)
3901 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
Eyal Shapiracf1e05c2015-12-08 16:04:36 +02003902 rx_status->band);
Johannes Berg11289582013-02-07 17:36:12 +01003903 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003904
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07003905 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
3906 elems.country_elem,
3907 elems.country_elem_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003908 elems.pwr_constr_elem,
3909 elems.cisco_dtpc_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08003910
Johannes Berg471b3ef2007-12-28 14:32:58 +01003911 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003912}
3913
Johannes Berg1fa57d02010-06-10 10:21:32 +02003914void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3915 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003916{
3917 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07003918 struct ieee80211_mgmt *mgmt;
3919 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003920 struct ieee802_11_elems elems;
3921 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07003922
Jiri Bencf0706e82007-05-05 11:45:53 -07003923 rx_status = (struct ieee80211_rx_status *) skb->cb;
3924 mgmt = (struct ieee80211_mgmt *) skb->data;
3925 fc = le16_to_cpu(mgmt->frame_control);
3926
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003927 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003928
Johannes Berg66e67e42012-01-20 13:55:27 +01003929 switch (fc & IEEE80211_FCTL_STYPE) {
3930 case IEEE80211_STYPE_BEACON:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003931 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01003932 break;
3933 case IEEE80211_STYPE_PROBE_RESP:
3934 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3935 break;
3936 case IEEE80211_STYPE_AUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003937 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003938 break;
3939 case IEEE80211_STYPE_DEAUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003940 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003941 break;
3942 case IEEE80211_STYPE_DISASSOC:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003943 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003944 break;
3945 case IEEE80211_STYPE_ASSOC_RESP:
3946 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003947 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003948 break;
3949 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01003950 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003951 ies_len = skb->len -
3952 offsetof(struct ieee80211_mgmt,
3953 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01003954
3955 if (ies_len < 0)
3956 break;
3957
3958 ieee802_11_parse_elems(
3959 mgmt->u.action.u.chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003960 ies_len, true, &elems);
Johannes Berg37799e52013-03-26 14:02:26 +01003961
3962 if (elems.parse_error)
3963 break;
3964
Johannes Berg66e67e42012-01-20 13:55:27 +01003965 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003966 rx_status->mactime,
3967 rx_status->device_timestamp,
3968 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003969 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3970 ies_len = skb->len -
3971 offsetof(struct ieee80211_mgmt,
3972 u.action.u.ext_chan_switch.variable);
3973
3974 if (ies_len < 0)
3975 break;
3976
3977 ieee802_11_parse_elems(
3978 mgmt->u.action.u.ext_chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003979 ies_len, true, &elems);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003980
3981 if (elems.parse_error)
3982 break;
3983
3984 /* for the handling code pretend this was also an IE */
3985 elems.ext_chansw_ie =
3986 &mgmt->u.action.u.ext_chan_switch.data;
3987
3988 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003989 rx_status->mactime,
3990 rx_status->device_timestamp,
3991 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003992 }
Johannes Berg37799e52013-03-26 14:02:26 +01003993 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003994 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003995 sdata_unlock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003996}
3997
Kees Cook34f11cd2017-10-16 16:35:49 -07003998static void ieee80211_sta_timer(struct timer_list *t)
Jiri Bencf0706e82007-05-05 11:45:53 -07003999{
4000 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004001 from_timer(sdata, t, u.mgd.timer);
Jiri Bencf0706e82007-05-05 11:45:53 -07004002
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01004003 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07004004}
4005
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004006static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01004007 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004008{
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004009 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004010
Johannes Berg37ad3882012-02-24 13:50:54 +01004011 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01004012 tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01004013
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004014 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4015 reason);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004016}
4017
Johannes Berg46cad4b2015-08-15 22:39:54 +03004018static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg66e67e42012-01-20 13:55:27 +01004019{
4020 struct ieee80211_local *local = sdata->local;
4021 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4022 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004023 u32 tx_flags = 0;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004024 u16 trans = 1;
4025 u16 status = 0;
Ilan Peerd4e36e52018-04-20 13:49:25 +03004026 u16 prepare_tx_duration = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004027
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004028 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004029
4030 if (WARN_ON_ONCE(!auth_data))
4031 return -EINVAL;
4032
Johannes Berg66e67e42012-01-20 13:55:27 +01004033 auth_data->tries++;
4034
4035 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004036 sdata_info(sdata, "authentication with %pM timed out\n",
4037 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004038
4039 /*
4040 * Most likely AP is not in the range so remove the
4041 * bss struct for that AP.
4042 */
4043 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4044
4045 return -ETIMEDOUT;
4046 }
4047
Ilan Peerd4e36e52018-04-20 13:49:25 +03004048 if (auth_data->algorithm == WLAN_AUTH_SAE)
4049 prepare_tx_duration =
4050 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4051
4052 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
Johannes Berga1845fc2012-06-27 13:18:36 +02004053
Johannes Berg46cad4b2015-08-15 22:39:54 +03004054 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4055 auth_data->bss->bssid, auth_data->tries,
4056 IEEE80211_AUTH_MAX_TRIES);
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004057
Johannes Berg46cad4b2015-08-15 22:39:54 +03004058 auth_data->expected_transaction = 2;
Johannes Berg66e67e42012-01-20 13:55:27 +01004059
Johannes Berg46cad4b2015-08-15 22:39:54 +03004060 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4061 trans = auth_data->sae_trans;
4062 status = auth_data->sae_status;
4063 auth_data->expected_transaction = trans;
Johannes Berg66e67e42012-01-20 13:55:27 +01004064 }
4065
Johannes Berg46cad4b2015-08-15 22:39:54 +03004066 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4067 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4068 IEEE80211_TX_INTFL_MLME_CONN_TX;
4069
4070 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4071 auth_data->data, auth_data->data_len,
4072 auth_data->bss->bssid,
4073 auth_data->bss->bssid, NULL, 0, 0,
4074 tx_flags);
4075
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02004076 if (tx_flags == 0) {
Ilan Peer407879b2018-04-20 13:49:20 +03004077 if (auth_data->algorithm == WLAN_AUTH_SAE)
4078 auth_data->timeout = jiffies +
4079 IEEE80211_AUTH_TIMEOUT_SAE;
4080 else
4081 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004082 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004083 auth_data->timeout =
4084 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004085 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004086
Ilan Peer407879b2018-04-20 13:49:20 +03004087 auth_data->timeout_started = true;
4088 run_again(sdata, auth_data->timeout);
4089
Johannes Berg66e67e42012-01-20 13:55:27 +01004090 return 0;
4091}
4092
4093static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4094{
4095 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4096 struct ieee80211_local *local = sdata->local;
4097
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004098 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004099
Johannes Berg66e67e42012-01-20 13:55:27 +01004100 assoc_data->tries++;
4101 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004102 sdata_info(sdata, "association with %pM timed out\n",
4103 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004104
4105 /*
4106 * Most likely AP is not in the range so remove the
4107 * bss struct for that AP.
4108 */
4109 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4110
4111 return -ETIMEDOUT;
4112 }
4113
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004114 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4115 assoc_data->bss->bssid, assoc_data->tries,
4116 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01004117 ieee80211_send_assoc(sdata);
4118
Johannes Berg30686bf2015-06-02 21:39:54 +02004119 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004120 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004121 assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004122 run_again(sdata, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01004123 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004124 assoc_data->timeout =
4125 round_jiffies_up(jiffies +
4126 IEEE80211_ASSOC_TIMEOUT_LONG);
4127 assoc_data->timeout_started = true;
4128 run_again(sdata, assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004129 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004130
4131 return 0;
4132}
4133
Johannes Berg1672c0e32013-01-29 15:02:27 +01004134void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4135 __le16 fc, bool acked)
4136{
4137 struct ieee80211_local *local = sdata->local;
4138
4139 sdata->u.mgd.status_fc = fc;
4140 sdata->u.mgd.status_acked = acked;
4141 sdata->u.mgd.status_received = true;
4142
4143 ieee80211_queue_work(&local->hw, &sdata->work);
4144}
4145
Johannes Berg1fa57d02010-06-10 10:21:32 +02004146void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004147{
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004148 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02004149 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004150
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004151 sdata_lock(sdata);
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004152
Johannes Berg1672c0e32013-01-29 15:02:27 +01004153 if (ifmgd->status_received) {
4154 __le16 fc = ifmgd->status_fc;
4155 bool status_acked = ifmgd->status_acked;
4156
4157 ifmgd->status_received = false;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004158 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004159 if (status_acked) {
Ilan Peer407879b2018-04-20 13:49:20 +03004160 if (ifmgd->auth_data->algorithm ==
4161 WLAN_AUTH_SAE)
4162 ifmgd->auth_data->timeout =
4163 jiffies +
4164 IEEE80211_AUTH_TIMEOUT_SAE;
4165 else
4166 ifmgd->auth_data->timeout =
4167 jiffies +
4168 IEEE80211_AUTH_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004169 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004170 } else {
4171 ifmgd->auth_data->timeout = jiffies - 1;
4172 }
Johannes Berg89afe612013-02-13 15:39:57 +01004173 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004174 } else if (ifmgd->assoc_data &&
4175 (ieee80211_is_assoc_req(fc) ||
4176 ieee80211_is_reassoc_req(fc))) {
4177 if (status_acked) {
4178 ifmgd->assoc_data->timeout =
4179 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004180 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004181 } else {
4182 ifmgd->assoc_data->timeout = jiffies - 1;
4183 }
Johannes Berg89afe612013-02-13 15:39:57 +01004184 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004185 }
4186 }
4187
Johannes Berg89afe612013-02-13 15:39:57 +01004188 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004189 time_after(jiffies, ifmgd->auth_data->timeout)) {
4190 if (ifmgd->auth_data->done) {
4191 /*
4192 * ok ... we waited for assoc but userspace didn't,
4193 * so let's just kill the auth data
4194 */
4195 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg46cad4b2015-08-15 22:39:54 +03004196 } else if (ieee80211_auth(sdata)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004197 u8 bssid[ETH_ALEN];
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004198 struct ieee80211_event event = {
4199 .type = MLME_EVENT,
4200 .u.mlme.data = AUTH_EVENT,
4201 .u.mlme.status = MLME_TIMEOUT,
4202 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004203
4204 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4205
4206 ieee80211_destroy_auth_data(sdata, false);
4207
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004208 cfg80211_auth_timeout(sdata->dev, bssid);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004209 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004210 }
Johannes Berg89afe612013-02-13 15:39:57 +01004211 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004212 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004213
Johannes Berg89afe612013-02-13 15:39:57 +01004214 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004215 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Alexander Bondar989c6502013-05-16 17:34:17 +03004216 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01004217 ieee80211_do_assoc(sdata)) {
Johannes Berg959867f2013-06-19 13:05:42 +02004218 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004219 struct ieee80211_event event = {
4220 .type = MLME_EVENT,
4221 .u.mlme.data = ASSOC_EVENT,
4222 .u.mlme.status = MLME_TIMEOUT,
4223 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004224
Johannes Berge6f462d2016-12-08 17:22:09 +01004225 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02004226 cfg80211_assoc_timeout(sdata->dev, bss);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004227 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004228 }
Johannes Berg89afe612013-02-13 15:39:57 +01004229 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004230 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004231
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02004232 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
Johannes Bergb291ba12009-07-10 15:29:03 +02004233 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03004234 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004235 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03004236
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004237 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004238
Johannes Berg30686bf2015-06-02 21:39:54 +02004239 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Ben Greear180205b2011-02-04 15:30:24 -08004240 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004241 else
Ben Greear180205b2011-02-04 15:30:24 -08004242 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004243
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004244 /* ACK received for nullfunc probing frame */
4245 if (!ifmgd->probe_send_count)
4246 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004247 else if (ifmgd->nullfunc_failed) {
4248 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004249 mlme_dbg(sdata,
4250 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4251 bssid, ifmgd->probe_send_count,
4252 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004253 ieee80211_mgd_probe_ap_send(sdata);
4254 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004255 mlme_dbg(sdata,
4256 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4257 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02004258 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004259 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4260 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004261 }
4262 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004263 run_again(sdata, ifmgd->probe_timeout);
Johannes Berg30686bf2015-06-02 21:39:54 +02004264 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004265 mlme_dbg(sdata,
4266 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4267 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02004268 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004269 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004270 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004271 mlme_dbg(sdata,
4272 "No probe response from AP %pM after %dms, try %d/%i\n",
4273 bssid, probe_wait_ms,
4274 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03004275 ieee80211_mgd_probe_ap_send(sdata);
4276 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02004277 /*
4278 * We actually lost the connection ... or did we?
4279 * Let's make sure!
4280 */
Johannes Berg89f774e2016-01-25 15:46:36 +02004281 mlme_dbg(sdata,
4282 "No probe response from AP %pM after %dms, disconnecting.\n",
4283 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004284
Johannes Berg95acac62011-07-12 12:30:59 +02004285 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004286 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02004287 }
4288 }
4289
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004290 sdata_unlock(sdata);
Johannes Berg60f8b39c2008-09-08 17:44:22 +02004291}
Johannes Berg0a51b272008-09-08 17:44:25 +02004292
Kees Cook34f11cd2017-10-16 16:35:49 -07004293static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004294{
4295 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004296 from_timer(sdata, t, u.mgd.bcn_mon_timer);
Luciano Coelho0c21e632014-10-08 09:48:39 +03004297 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004298
Luciano Coelho0c21e632014-10-08 09:48:39 +03004299 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004300 return;
4301
Johannes Berg682bd382013-01-29 13:13:50 +01004302 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004303 ieee80211_queue_work(&sdata->local->hw,
4304 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004305}
4306
Kees Cook34f11cd2017-10-16 16:35:49 -07004307static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004308{
4309 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004310 from_timer(sdata, t, u.mgd.conn_mon_timer);
Johannes Bergb291ba12009-07-10 15:29:03 +02004311 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4312 struct ieee80211_local *local = sdata->local;
4313
Luciano Coelho0c21e632014-10-08 09:48:39 +03004314 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004315 return;
4316
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04004317 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004318}
4319
4320static void ieee80211_sta_monitor_work(struct work_struct *work)
4321{
4322 struct ieee80211_sub_if_data *sdata =
4323 container_of(work, struct ieee80211_sub_if_data,
4324 u.mgd.monitor_work);
4325
4326 ieee80211_mgd_probe_ap(sdata, false);
4327}
4328
Johannes Berga1678f82008-09-11 00:01:47 +02004329static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4330{
Kalle Vaload935682009-04-19 08:47:19 +03004331 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02004332 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03004333
Johannes Bergb291ba12009-07-10 15:29:03 +02004334 /* let's probe the connection once */
Johannes Berg30686bf2015-06-02 21:39:54 +02004335 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Eliad Peller494f1fe2012-02-19 15:26:09 +02004336 ieee80211_queue_work(&sdata->local->hw,
4337 &sdata->u.mgd.monitor_work);
Kalle Vaload935682009-04-19 08:47:19 +03004338 }
Johannes Berga1678f82008-09-11 00:01:47 +02004339}
4340
Johannes Bergb8360ab2013-04-29 14:57:44 +02004341#ifdef CONFIG_PM
Johannes Berg1a1cb742014-03-19 09:55:55 +01004342void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4343{
4344 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4345 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4346
4347 sdata_lock(sdata);
4348
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004349 if (ifmgd->auth_data || ifmgd->assoc_data) {
4350 const u8 *bssid = ifmgd->auth_data ?
4351 ifmgd->auth_data->bss->bssid :
4352 ifmgd->assoc_data->bss->bssid;
4353
Johannes Berg1a1cb742014-03-19 09:55:55 +01004354 /*
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004355 * If we are trying to authenticate / associate while suspending,
4356 * cfg80211 won't know and won't actually abort those attempts,
4357 * thus we need to do that ourselves.
Johannes Berg1a1cb742014-03-19 09:55:55 +01004358 */
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004359 ieee80211_send_deauth_disassoc(sdata, bssid,
Johannes Berg1a1cb742014-03-19 09:55:55 +01004360 IEEE80211_STYPE_DEAUTH,
4361 WLAN_REASON_DEAUTH_LEAVING,
4362 false, frame_buf);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004363 if (ifmgd->assoc_data)
Johannes Berge6f462d2016-12-08 17:22:09 +01004364 ieee80211_destroy_assoc_data(sdata, false, true);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004365 if (ifmgd->auth_data)
4366 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg1a1cb742014-03-19 09:55:55 +01004367 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4368 IEEE80211_DEAUTH_FRAME_LEN);
4369 }
4370
Johannes Bergbe72afe2015-03-01 09:10:03 +02004371 /* This is a bit of a hack - we should find a better and more generic
4372 * solution to this. Normally when suspending, cfg80211 will in fact
4373 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4374 * auth (not so important) or assoc (this is the problem) process.
4375 *
4376 * As a consequence, it can happen that we are in the process of both
4377 * associating and suspending, and receive an association response
4378 * after cfg80211 has checked if it needs to disconnect, but before
4379 * we actually set the flag to drop incoming frames. This will then
4380 * cause the workqueue flush to process the association response in
4381 * the suspend, resulting in a successful association just before it
4382 * tries to remove the interface from the driver, which now though
4383 * has a channel context assigned ... this results in issues.
4384 *
4385 * To work around this (for now) simply deauth here again if we're
4386 * now connected.
4387 */
4388 if (ifmgd->associated && !sdata->local->wowlan) {
4389 u8 bssid[ETH_ALEN];
4390 struct cfg80211_deauth_request req = {
4391 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4392 .bssid = bssid,
4393 };
4394
4395 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4396 ieee80211_mgd_deauth(sdata, &req);
4397 }
4398
Johannes Berg1a1cb742014-03-19 09:55:55 +01004399 sdata_unlock(sdata);
4400}
4401
Johannes Bergb8360ab2013-04-29 14:57:44 +02004402void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4403{
4404 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4405
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004406 sdata_lock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004407 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004408 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004409 return;
4410 }
4411
4412 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4413 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4414 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4415 ieee80211_sta_connection_lost(sdata,
4416 ifmgd->associated->bssid,
4417 WLAN_REASON_UNSPECIFIED,
4418 true);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004419 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004420 return;
4421 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004422 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004423}
4424#endif
4425
Johannes Berg9c6bd792008-09-11 00:01:52 +02004426/* interface setup */
4427void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4428{
Johannes Berg46900292009-02-15 12:44:28 +01004429 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004430
Johannes Berg46900292009-02-15 12:44:28 +01004431 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004432 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01004433 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004434 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4435 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02004436 INIT_WORK(&ifmgd->csa_connection_drop_work,
4437 ieee80211_csa_connection_drop_work);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03004438 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03004439 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4440 ieee80211_tdls_peer_del_work);
Kees Cook34f11cd2017-10-16 16:35:49 -07004441 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4442 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4443 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4444 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
Johannes Berg02219b32014-10-07 10:38:50 +03004445 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4446 ieee80211_sta_handle_tspec_ac_params_wk);
Johannes Berg9c6bd792008-09-11 00:01:52 +02004447
Johannes Bergab1faea2009-07-01 21:41:17 +02004448 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05304449 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02004450 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4451 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01004452 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02004453
Eliad Peller0d8614b2014-09-10 14:07:36 +03004454 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
Johannes Berg0f782312009-12-01 13:37:02 +01004455 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4456 else
4457 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02004458
4459 /* Setup TDLS data */
4460 spin_lock_init(&ifmgd->teardown_lock);
4461 ifmgd->teardown_skb = NULL;
4462 ifmgd->orig_teardown_skb = NULL;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004463}
4464
4465/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02004466void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4467{
Johannes Berg31ee67a2012-07-06 21:18:24 +02004468 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02004469
4470 /* Restart STA timers */
4471 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07004472 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4473 if (ieee80211_sdata_running(sdata))
4474 ieee80211_restart_sta_timer(sdata);
4475 }
Johannes Berga1678f82008-09-11 00:01:47 +02004476 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02004477}
Johannes Berg10f644a2009-04-16 13:17:25 +02004478
Johannes Bergf2d9d272012-11-22 14:11:39 +01004479static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4480 struct cfg80211_bss *cbss)
4481{
4482 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4483 const u8 *ht_cap_ie, *vht_cap_ie;
4484 const struct ieee80211_ht_cap *ht_cap;
4485 const struct ieee80211_vht_cap *vht_cap;
4486 u8 chains = 1;
4487
4488 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4489 return chains;
4490
Johannes Berg9caf0362012-11-29 01:25:20 +01004491 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004492 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4493 ht_cap = (void *)(ht_cap_ie + 2);
4494 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4495 /*
4496 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4497 * "Tx Unequal Modulation Supported" fields.
4498 */
4499 }
4500
4501 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4502 return chains;
4503
Johannes Berg9caf0362012-11-29 01:25:20 +01004504 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004505 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4506 u8 nss;
4507 u16 tx_mcs_map;
4508
4509 vht_cap = (void *)(vht_cap_ie + 2);
4510 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4511 for (nss = 8; nss > 0; nss--) {
4512 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4513 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4514 break;
4515 }
4516 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4517 chains = max(chains, nss);
4518 }
4519
4520 return chains;
4521}
4522
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004523static bool
4524ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4525 const struct ieee80211_he_operation *he_op)
4526{
4527 const struct ieee80211_sta_he_cap *sta_he_cap =
4528 ieee80211_get_he_sta_cap(sband);
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004529 u16 ap_min_req_set;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004530 int i;
4531
4532 if (!sta_he_cap || !he_op)
4533 return false;
4534
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004535 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4536
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004537 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4538 for (i = 0; i < 3; i++) {
4539 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4540 &sta_he_cap->he_mcs_nss_supp;
4541 u16 sta_mcs_map_rx =
4542 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4543 u16 sta_mcs_map_tx =
4544 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4545 u8 nss;
4546 bool verified = true;
4547
4548 /*
4549 * For each band there is a maximum of 8 spatial streams
4550 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4551 * of 2 bits per NSS (1-8), with the values defined in enum
4552 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4553 * capabilities aren't less than the AP's minimum requirements
4554 * for this HE BSS per SS.
4555 * It is enough to find one such band that meets the reqs.
4556 */
4557 for (nss = 8; nss > 0; nss--) {
4558 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4559 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4560 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4561
4562 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4563 continue;
4564
4565 /*
4566 * Make sure the HE AP doesn't require MCSs that aren't
4567 * supported by the client
4568 */
4569 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4570 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4571 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4572 verified = false;
4573 break;
4574 }
4575 }
4576
4577 if (verified)
4578 return true;
4579 }
4580
4581 /* If here, STA doesn't meet AP's HE min requirements */
4582 return false;
4583}
4584
Johannes Bergb17166a2012-07-27 11:41:27 +02004585static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4586 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01004587{
4588 struct ieee80211_local *local = sdata->local;
4589 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Peller53b954e2014-07-24 11:20:05 +03004590 const struct ieee80211_ht_cap *ht_cap = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004591 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004592 const struct ieee80211_vht_operation *vht_oper = NULL;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004593 const struct ieee80211_he_operation *he_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004594 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01004595 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004596 int ret;
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004597 u32 i;
4598 bool have_80mhz;
Johannes Berga1cf7752012-03-08 15:02:07 +01004599
Johannes Berg24398e32012-03-28 10:58:36 +02004600 sband = local->hw.wiphy->bands[cbss->channel->band];
4601
Johannes Bergf2d9d272012-11-22 14:11:39 +01004602 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4603 IEEE80211_STA_DISABLE_80P80MHZ |
4604 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02004605
Johannes Berg9caf0362012-11-29 01:25:20 +01004606 rcu_read_lock();
4607
Johannes Bergf2d9d272012-11-22 14:11:39 +01004608 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
4609 sband->ht_cap.ht_supported) {
Eliad Peller53b954e2014-07-24 11:20:05 +03004610 const u8 *ht_oper_ie, *ht_cap_ie;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004611
Johannes Berg9caf0362012-11-29 01:25:20 +01004612 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02004613 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4614 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6effa2013-02-07 23:33:32 +01004615
Eliad Peller53b954e2014-07-24 11:20:05 +03004616 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4617 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4618 ht_cap = (void *)(ht_cap_ie + 2);
4619
4620 if (!ht_cap) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004621 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4622 ht_oper = NULL;
4623 }
Johannes Berg24398e32012-03-28 10:58:36 +02004624 }
4625
Johannes Bergf2d9d272012-11-22 14:11:39 +01004626 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4627 sband->vht_cap.vht_supported) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01004628 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004629
Johannes Berg9caf0362012-11-29 01:25:20 +01004630 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4631 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004632 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4633 vht_oper = (void *)(vht_oper_ie + 2);
4634 if (vht_oper && !ht_oper) {
4635 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004636 sdata_info(sdata,
Johannes Bergf2d9d272012-11-22 14:11:39 +01004637 "AP advertised VHT without HT, disabling both\n");
Johannes Bergcb145022013-02-07 20:41:50 +01004638 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4639 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg24398e32012-03-28 10:58:36 +02004640 }
Johannes Berg08e6effa2013-02-07 23:33:32 +01004641
4642 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4643 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4644 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4645 vht_oper = NULL;
4646 }
Johannes Berg24398e32012-03-28 10:58:36 +02004647 }
4648
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004649 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
4650 ieee80211_get_he_sta_cap(sband)) {
4651 const struct cfg80211_bss_ies *ies;
4652 const u8 *he_oper_ie;
4653
4654 ies = rcu_dereference(cbss->ies);
4655 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
4656 ies->data, ies->len);
4657 if (he_oper_ie &&
4658 he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
4659 he_oper = (void *)(he_oper_ie + 3);
4660 else
4661 he_oper = NULL;
4662
Johannes Bergf0c04072018-06-29 09:51:39 +02004663 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004664 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4665 }
4666
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004667 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4668 have_80mhz = false;
4669 for (i = 0; i < sband->n_channels; i++) {
4670 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4671 IEEE80211_CHAN_NO_80MHZ))
4672 continue;
4673
4674 have_80mhz = true;
4675 break;
4676 }
4677
4678 if (!have_80mhz)
4679 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4680
Johannes Bergf2d9d272012-11-22 14:11:39 +01004681 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4682 cbss->channel,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004683 ht_oper, vht_oper, he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +02004684 &chandef, false);
Johannes Berg04ecd252012-09-11 14:34:12 +02004685
Johannes Bergf2d9d272012-11-22 14:11:39 +01004686 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4687 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02004688
Johannes Berg9caf0362012-11-29 01:25:20 +01004689 rcu_read_unlock();
4690
Johannes Berg04ecd252012-09-11 14:34:12 +02004691 /* will change later if needed */
4692 sdata->smps_mode = IEEE80211_SMPS_OFF;
4693
Johannes Berg34a37402013-12-18 09:43:33 +01004694 mutex_lock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004695 /*
4696 * If this fails (possibly due to channel context sharing
4697 * on incompatible channels, e.g. 80+80 and 160 sharing the
4698 * same control channel) try to use a smaller bandwidth.
4699 */
4700 ret = ieee80211_vif_use_channel(sdata, &chandef,
4701 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich0418a442013-05-16 13:00:31 +02004702
4703 /* don't downgrade for 5 and 10 MHz channels, though. */
4704 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4705 chandef.width == NL80211_CHAN_WIDTH_10)
Johannes Berg34a37402013-12-18 09:43:33 +01004706 goto out;
Simon Wunderlich0418a442013-05-16 13:00:31 +02004707
Johannes Bergd601cd82013-02-07 20:54:51 +01004708 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02004709 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01004710 ret = ieee80211_vif_use_channel(sdata, &chandef,
4711 IEEE80211_CHANCTX_SHARED);
4712 }
Johannes Berg34a37402013-12-18 09:43:33 +01004713 out:
4714 mutex_unlock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004715 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02004716}
4717
4718static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004719 struct cfg80211_bss *cbss, bool assoc,
4720 bool override)
Johannes Bergb17166a2012-07-27 11:41:27 +02004721{
4722 struct ieee80211_local *local = sdata->local;
4723 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4724 struct ieee80211_bss *bss = (void *)cbss->priv;
4725 struct sta_info *new_sta = NULL;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004726 struct ieee80211_supported_band *sband;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004727 bool have_sta = false;
Johannes Bergb17166a2012-07-27 11:41:27 +02004728 int err;
4729
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004730 sband = local->hw.wiphy->bands[cbss->channel->band];
4731
Johannes Bergb17166a2012-07-27 11:41:27 +02004732 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4733 return -EINVAL;
4734
Luca Coelhof8860ce2017-05-02 17:56:21 +03004735 /* If a reconfig is happening, bail out */
4736 if (local->in_reconfig)
4737 return -EBUSY;
4738
Johannes Bergb17166a2012-07-27 11:41:27 +02004739 if (assoc) {
4740 rcu_read_lock();
4741 have_sta = sta_info_get(sdata, cbss->bssid);
4742 rcu_read_unlock();
4743 }
4744
4745 if (!have_sta) {
4746 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4747 if (!new_sta)
4748 return -ENOMEM;
4749 }
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004750
Johannes Bergc87905b2017-06-10 13:52:43 +03004751 /*
4752 * Set up the information for the new channel before setting the
4753 * new channel. We can't - completely race-free - change the basic
4754 * rates bitmap and the channel (sband) that it refers to, but if
4755 * we set it up before we at least avoid calling into the driver's
4756 * bss_info_changed() method with invalid information (since we do
4757 * call that from changing the channel - only for IDLE and perhaps
4758 * some others, but ...).
4759 *
4760 * So to avoid that, just set up all the new information before the
4761 * channel, but tell the driver to apply it only afterwards, since
4762 * it might need the new channel for that.
4763 */
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004764 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004765 u32 rates = 0, basic_rates = 0;
4766 bool have_higher_than_11mbit;
4767 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004768 const struct cfg80211_bss_ies *ies;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004769 int shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004770
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004771 ieee80211_get_rates(sband, bss->supp_rates,
4772 bss->supp_rates_len,
4773 &rates, &basic_rates,
4774 &have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02004775 &min_rate, &min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03004776 shift);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004777
4778 /*
4779 * This used to be a workaround for basic rates missing
4780 * in the association response frame. Now that we no
4781 * longer use the basic rates from there, it probably
4782 * doesn't happen any more, but keep the workaround so
4783 * in case some *other* APs are buggy in different ways
4784 * we can connect -- with a warning.
4785 */
4786 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004787 sdata_info(sdata,
4788 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004789 basic_rates = BIT(min_rate_index);
4790 }
4791
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004792 new_sta->sta.supp_rates[cbss->channel->band] = rates;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004793 sdata->vif.bss_conf.basic_rates = basic_rates;
4794
4795 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg57fbcce2016-04-12 15:56:15 +02004796 if (cbss->channel->band == NL80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004797 have_higher_than_11mbit)
4798 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
4799 else
4800 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
4801
4802 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
4803
Johannes Berg8c358bc2012-05-22 22:13:05 +02004804 /* set timing information */
4805 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004806 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01004807 ies = rcu_dereference(cbss->beacon_ies);
4808 if (ies) {
4809 const u8 *tim_ie;
4810
4811 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4812 sdata->vif.bss_conf.sync_device_ts =
4813 bss->device_ts_beacon;
4814 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4815 ies->data, ies->len);
4816 if (tim_ie && tim_ie[1] >= 2)
4817 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
4818 else
4819 sdata->vif.bss_conf.sync_dtim_count = 0;
Johannes Berg30686bf2015-06-02 21:39:54 +02004820 } else if (!ieee80211_hw_check(&sdata->local->hw,
4821 TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01004822 ies = rcu_dereference(cbss->proberesp_ies);
4823 /* must be non-NULL since beacon IEs were NULL */
4824 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4825 sdata->vif.bss_conf.sync_device_ts =
4826 bss->device_ts_presp;
4827 sdata->vif.bss_conf.sync_dtim_count = 0;
4828 } else {
4829 sdata->vif.bss_conf.sync_tsf = 0;
4830 sdata->vif.bss_conf.sync_device_ts = 0;
4831 sdata->vif.bss_conf.sync_dtim_count = 0;
4832 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01004833 rcu_read_unlock();
Johannes Bergc87905b2017-06-10 13:52:43 +03004834 }
Johannes Berg8c358bc2012-05-22 22:13:05 +02004835
Johannes Bergc87905b2017-06-10 13:52:43 +03004836 if (new_sta || override) {
4837 err = ieee80211_prep_channel(sdata, cbss);
4838 if (err) {
4839 if (new_sta)
4840 sta_info_free(local, new_sta);
4841 return -EINVAL;
4842 }
4843 }
4844
4845 if (new_sta) {
4846 /*
4847 * tell driver about BSSID, basic rates and timing
4848 * this was set up above, before setting the channel
4849 */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004850 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02004851 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
4852 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01004853
4854 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004855 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01004856
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004857 err = sta_info_insert(new_sta);
4858 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01004859 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004860 sdata_info(sdata,
4861 "failed to insert STA entry for the AP (error %d)\n",
4862 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01004863 return err;
4864 }
4865 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00004866 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01004867
David Spinadel7d830a12015-03-17 19:58:38 +02004868 /* Cancel scan to ensure that nothing interferes with connection */
4869 if (local->scanning)
4870 ieee80211_scan_cancel(local);
4871
Johannes Berga1cf7752012-03-08 15:02:07 +01004872 return 0;
4873}
4874
Johannes Berg77fdaa12009-07-07 03:45:17 +02004875/* config hooks */
4876int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
4877 struct cfg80211_auth_request *req)
4878{
Johannes Berg66e67e42012-01-20 13:55:27 +01004879 struct ieee80211_local *local = sdata->local;
4880 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4881 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004882 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01004883 int err;
4884
4885 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02004886
4887 switch (req->auth_type) {
4888 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4889 auth_alg = WLAN_AUTH_OPEN;
4890 break;
4891 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01004892 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02004893 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004894 auth_alg = WLAN_AUTH_SHARED_KEY;
4895 break;
4896 case NL80211_AUTHTYPE_FT:
4897 auth_alg = WLAN_AUTH_FT;
4898 break;
4899 case NL80211_AUTHTYPE_NETWORK_EAP:
4900 auth_alg = WLAN_AUTH_LEAP;
4901 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004902 case NL80211_AUTHTYPE_SAE:
4903 auth_alg = WLAN_AUTH_SAE;
4904 break;
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03004905 case NL80211_AUTHTYPE_FILS_SK:
4906 auth_alg = WLAN_AUTH_FILS_SK;
4907 break;
4908 case NL80211_AUTHTYPE_FILS_SK_PFS:
4909 auth_alg = WLAN_AUTH_FILS_SK_PFS;
4910 break;
4911 case NL80211_AUTHTYPE_FILS_PK:
4912 auth_alg = WLAN_AUTH_FILS_PK;
4913 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004914 default:
4915 return -EOPNOTSUPP;
4916 }
4917
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004918 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004919 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01004920 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004921 return -ENOMEM;
4922
Johannes Berg66e67e42012-01-20 13:55:27 +01004923 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004924
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004925 if (req->auth_data_len >= 4) {
Jouni Malinen6ec63612016-10-27 00:41:59 +03004926 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
4927 __le16 *pos = (__le16 *) req->auth_data;
4928
4929 auth_data->sae_trans = le16_to_cpu(pos[0]);
4930 auth_data->sae_status = le16_to_cpu(pos[1]);
4931 }
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004932 memcpy(auth_data->data, req->auth_data + 4,
4933 req->auth_data_len - 4);
4934 auth_data->data_len += req->auth_data_len - 4;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004935 }
4936
Johannes Berg77fdaa12009-07-07 03:45:17 +02004937 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004938 memcpy(&auth_data->data[auth_data->data_len],
4939 req->ie, req->ie_len);
4940 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004941 }
4942
Johannes Bergfffd0932009-07-08 14:22:54 +02004943 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004944 auth_data->key_len = req->key_len;
4945 auth_data->key_idx = req->key_idx;
4946 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02004947 }
4948
Johannes Berg66e67e42012-01-20 13:55:27 +01004949 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004950
Johannes Berg66e67e42012-01-20 13:55:27 +01004951 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01004952
Johannes Berg66e67e42012-01-20 13:55:27 +01004953 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
4954 ifmgd->assoc_data) {
4955 err = -EBUSY;
4956 goto err_free;
4957 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004958
Johannes Berg66e67e42012-01-20 13:55:27 +01004959 if (ifmgd->auth_data)
4960 ieee80211_destroy_auth_data(sdata, false);
Guy Eilam2a33bee2011-08-17 15:18:15 +03004961
Johannes Berg66e67e42012-01-20 13:55:27 +01004962 /* prep auth_data so we don't go into idle on disassoc */
4963 ifmgd->auth_data = auth_data;
4964
Johannes Berg7b119dc2013-04-10 21:38:36 +02004965 if (ifmgd->associated) {
4966 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4967
Johannes Berg89f774e2016-01-25 15:46:36 +02004968 sdata_info(sdata,
4969 "disconnect from AP %pM for new auth to %pM\n",
4970 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02004971 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4972 WLAN_REASON_UNSPECIFIED,
4973 false, frame_buf);
4974
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004975 ieee80211_report_disconnect(sdata, frame_buf,
4976 sizeof(frame_buf), true,
4977 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02004978 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004979
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004980 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004981
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004982 err = ieee80211_prep_connection(sdata, req->bss, false, false);
Johannes Berga1cf7752012-03-08 15:02:07 +01004983 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01004984 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004985
Johannes Berg46cad4b2015-08-15 22:39:54 +03004986 err = ieee80211_auth(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004987 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004988 sta_info_destroy_addr(sdata, req->bss->bssid);
4989 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004990 }
4991
Johannes Berg66e67e42012-01-20 13:55:27 +01004992 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01004993 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004994 return 0;
Johannes Berge5b900d2010-07-29 16:08:55 +02004995
Johannes Berg66e67e42012-01-20 13:55:27 +01004996 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08004997 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03004998 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01004999 ifmgd->auth_data = NULL;
Michal Kaziord01f8582015-06-03 08:36:13 +02005000 mutex_lock(&sdata->local->mtx);
5001 ieee80211_vif_release_channel(sdata);
5002 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01005003 err_free:
5004 kfree(auth_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005005 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005006}
5007
Johannes Berg77fdaa12009-07-07 03:45:17 +02005008int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5009 struct cfg80211_assoc_request *req)
5010{
Johannes Berg66e67e42012-01-20 13:55:27 +01005011 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005012 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01005013 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01005014 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005015 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005016 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005017 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005018 int i, err;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005019 bool override = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005020
Johannes Berg66e67e42012-01-20 13:55:27 +01005021 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5022 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01005023 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005024
Johannes Berg9caf0362012-11-29 01:25:20 +01005025 rcu_read_lock();
5026 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
5027 if (!ssidie) {
5028 rcu_read_unlock();
5029 kfree(assoc_data);
5030 return -EINVAL;
5031 }
5032 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5033 assoc_data->ssid_len = ssidie[1];
5034 rcu_read_unlock();
5035
Johannes Berg7b119dc2013-04-10 21:38:36 +02005036 if (ifmgd->associated) {
5037 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5038
Johannes Berg89f774e2016-01-25 15:46:36 +02005039 sdata_info(sdata,
5040 "disconnect from AP %pM for new assoc to %pM\n",
5041 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005042 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5043 WLAN_REASON_UNSPECIFIED,
5044 false, frame_buf);
5045
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005046 ieee80211_report_disconnect(sdata, frame_buf,
5047 sizeof(frame_buf), true,
5048 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005049 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005050
5051 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5052 err = -EBUSY;
5053 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005054 }
5055
Johannes Berg66e67e42012-01-20 13:55:27 +01005056 if (ifmgd->assoc_data) {
5057 err = -EBUSY;
5058 goto err_free;
5059 }
5060
5061 if (ifmgd->auth_data) {
5062 bool match;
5063
5064 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00005065 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005066 ieee80211_destroy_auth_data(sdata, match);
5067 }
5068
5069 /* prepare assoc data */
Johannes Berg095d81c2013-10-15 12:25:07 +02005070
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03005071 ifmgd->beacon_crc_valid = false;
5072
Johannes Berg095d81c2013-10-15 12:25:07 +02005073 assoc_data->wmm = bss->wmm_used &&
5074 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg095d81c2013-10-15 12:25:07 +02005075
Johannes Bergde5036a2012-03-08 15:02:03 +01005076 /*
5077 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5078 * We still associate in non-HT mode (11a/b/g) if any one of these
5079 * ciphers is configured as pairwise.
5080 * We can set this to true for non-11n hardware, that'll be checked
5081 * separately along with the peer capabilities.
5082 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02005083 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02005084 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5085 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02005086 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01005087 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005088 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005089 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Johannes Berg1c4cb922012-05-30 15:57:00 +02005090 netdev_info(sdata->dev,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005091 "disabling HE/HT/VHT due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005092 }
5093 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005094
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005095 /* Also disable HT if we don't support it or the AP doesn't use WMM */
5096 sband = local->hw.wiphy->bands[req->bss->channel->band];
5097 if (!sband->ht_cap.ht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005098 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5099 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Berga8243b72012-11-22 14:32:09 +01005100 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005101 if (!bss->wmm_used &&
5102 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005103 netdev_info(sdata->dev,
5104 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005105 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005106
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005107 /* disable VHT if we don't support it or the AP doesn't use WMM */
5108 if (!sband->vht_cap.vht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005109 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5110 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005111 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005112 if (!bss->wmm_used &&
5113 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005114 netdev_info(sdata->dev,
5115 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005116 }
5117
Ben Greearef96a8422011-11-18 11:32:00 -08005118 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5119 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5120 sizeof(ifmgd->ht_capa_mask));
5121
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01005122 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5123 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5124 sizeof(ifmgd->vht_capa_mask));
5125
Johannes Berg77fdaa12009-07-07 03:45:17 +02005126 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005127 memcpy(assoc_data->ie, req->ie, req->ie_len);
5128 assoc_data->ie_len = req->ie_len;
5129 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005130
Jouni Malinen39404fe2016-10-27 00:42:05 +03005131 if (req->fils_kek) {
5132 /* should already be checked in cfg80211 - so warn */
5133 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5134 err = -EINVAL;
5135 goto err_free;
5136 }
5137 memcpy(assoc_data->fils_kek, req->fils_kek,
5138 req->fils_kek_len);
5139 assoc_data->fils_kek_len = req->fils_kek_len;
5140 }
5141
5142 if (req->fils_nonces)
5143 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5144 2 * FILS_NONCE_LEN);
5145
Johannes Berg66e67e42012-01-20 13:55:27 +01005146 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01005147
Johannes Bergaf6b6372009-12-23 13:15:35 +01005148 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5149 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02005150 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005151 else
Johannes Berg04ecd252012-09-11 14:34:12 +02005152 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005153 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02005154 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005155
Johannes Berg66e67e42012-01-20 13:55:27 +01005156 assoc_data->capability = req->bss->capability;
Johannes Berg66e67e42012-01-20 13:55:27 +01005157 assoc_data->supp_rates = bss->supp_rates;
5158 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02005159
Johannes Berg9caf0362012-11-29 01:25:20 +01005160 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02005161 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5162 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5163 assoc_data->ap_ht_param =
5164 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5165 else
Johannes Berga8243b72012-11-22 14:32:09 +01005166 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005167 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5168 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5169 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5170 sizeof(struct ieee80211_vht_cap));
5171 else
5172 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01005173 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01005174
Johannes Berg848955c2014-11-11 12:48:42 +01005175 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02005176 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
Johannes Berg848955c2014-11-11 12:48:42 +01005177 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5178 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5179
Kalle Valoab133152010-01-12 10:42:31 +02005180 if (bss->wmm_used && bss->uapsd_supported &&
Johannes Berg848955c2014-11-11 12:48:42 +01005181 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01005182 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02005183 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5184 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01005185 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02005186 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5187 }
5188
Johannes Berg77fdaa12009-07-07 03:45:17 +02005189 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01005190 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005191
5192 if (req->use_mfp) {
5193 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5194 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5195 } else {
5196 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5197 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5198 }
5199
Assaf Krausscd2f5dd2014-09-03 15:25:02 +03005200 if (req->flags & ASSOC_REQ_USE_RRM)
5201 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5202 else
5203 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5204
Johannes Berg77fdaa12009-07-07 03:45:17 +02005205 if (req->crypto.control_port)
5206 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5207 else
5208 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5209
Johannes Berga621fa42010-08-27 14:26:54 +03005210 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5211 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05005212 sdata->control_port_over_nl80211 =
5213 req->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02005214 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5215 sdata->vif.type);
Johannes Berga621fa42010-08-27 14:26:54 +03005216
Johannes Berg66e67e42012-01-20 13:55:27 +01005217 /* kick off associate process */
5218
5219 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02005220 ifmgd->dtim_period = 0;
Alexander Bondar989c6502013-05-16 17:34:17 +03005221 ifmgd->have_beacon = false;
Johannes Berg66e67e42012-01-20 13:55:27 +01005222
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005223 /* override HT/VHT configuration only if the AP and we support it */
5224 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5225 struct ieee80211_sta_ht_cap sta_ht_cap;
5226
5227 if (req->flags & ASSOC_REQ_DISABLE_HT)
5228 override = true;
5229
5230 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5231 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5232
5233 /* check for 40 MHz disable override */
5234 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5235 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5236 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5237 override = true;
5238
5239 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5240 req->flags & ASSOC_REQ_DISABLE_VHT)
5241 override = true;
5242 }
5243
5244 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5245 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5246 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5247 }
5248
5249 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5250 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5251
5252 err = ieee80211_prep_connection(sdata, req->bss, true, override);
Johannes Berga1cf7752012-03-08 15:02:07 +01005253 if (err)
5254 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01005255
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005256 rcu_read_lock();
5257 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02005258
Johannes Berg30686bf2015-06-02 21:39:54 +02005259 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005260 !beacon_ies) {
5261 /*
5262 * Wait up to one beacon interval ...
5263 * should this be more if we miss one?
5264 */
5265 sdata_info(sdata, "waiting for beacon from %pM\n",
5266 ifmgd->bssid);
5267 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01005268 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005269 assoc_data->need_beacon = true;
5270 } else if (beacon_ies) {
5271 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
5272 beacon_ies->data,
5273 beacon_ies->len);
Johannes Bergef429da2013-02-05 17:48:40 +01005274 u8 dtim_count = 0;
5275
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005276 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
5277 const struct ieee80211_tim_ie *tim;
5278 tim = (void *)(tim_ie + 2);
5279 ifmgd->dtim_period = tim->dtim_period;
Johannes Bergef429da2013-02-05 17:48:40 +01005280 dtim_count = tim->dtim_count;
Johannes Berg826262c2012-12-10 16:38:14 +02005281 }
Alexander Bondar989c6502013-05-16 17:34:17 +03005282 ifmgd->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005283 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005284 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01005285
Johannes Berg30686bf2015-06-02 21:39:54 +02005286 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005287 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5288 sdata->vif.bss_conf.sync_device_ts =
5289 bss->device_ts_beacon;
5290 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5291 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005292 } else {
5293 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005294 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005295 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005296 rcu_read_unlock();
5297
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005298 run_again(sdata, assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01005299
Paul Stewartfcff4f12012-02-23 17:59:53 -08005300 if (bss->corrupt_data) {
5301 char *corrupt_type = "data";
5302 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5303 if (bss->corrupt_data &
5304 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5305 corrupt_type = "beacon and probe response";
5306 else
5307 corrupt_type = "beacon";
5308 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5309 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005310 sdata_info(sdata, "associating with AP with corrupt %s\n",
5311 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08005312 }
5313
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005314 return 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01005315 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005316 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005317 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005318 ifmgd->assoc_data = NULL;
5319 err_free:
5320 kfree(assoc_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005321 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005322}
5323
5324int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005325 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005326{
5327 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005328 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005329 bool tx = !req->local_state_change;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005330
Johannes Bergc9c3a062014-03-19 09:11:19 +01005331 if (ifmgd->auth_data &&
5332 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5333 sdata_info(sdata,
5334 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5335 req->bssid, req->reason_code,
5336 ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005337
Ilan Peerd4e36e52018-04-20 13:49:25 +03005338 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg37ad3882012-02-24 13:50:54 +01005339 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5340 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005341 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01005342 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01005343 ieee80211_destroy_auth_data(sdata, false);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005344 ieee80211_report_disconnect(sdata, frame_buf,
5345 sizeof(frame_buf), true,
5346 req->reason_code);
Johannes Berg86552012012-10-29 09:46:31 +01005347
Johannes Bergc9c3a062014-03-19 09:11:19 +01005348 return 0;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03005349 }
5350
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005351 if (ifmgd->assoc_data &&
5352 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5353 sdata_info(sdata,
5354 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5355 req->bssid, req->reason_code,
5356 ieee80211_get_reason_code_string(req->reason_code));
5357
Ilan Peerd4e36e52018-04-20 13:49:25 +03005358 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005359 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5360 IEEE80211_STYPE_DEAUTH,
5361 req->reason_code, tx,
5362 frame_buf);
Johannes Berge6f462d2016-12-08 17:22:09 +01005363 ieee80211_destroy_assoc_data(sdata, false, true);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005364 ieee80211_report_disconnect(sdata, frame_buf,
5365 sizeof(frame_buf), true,
5366 req->reason_code);
5367 return 0;
5368 }
5369
Johannes Berg86552012012-10-29 09:46:31 +01005370 if (ifmgd->associated &&
5371 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
Johannes Bergc9c3a062014-03-19 09:11:19 +01005372 sdata_info(sdata,
5373 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5374 req->bssid, req->reason_code,
5375 ieee80211_get_reason_code_string(req->reason_code));
5376
Johannes Berg86552012012-10-29 09:46:31 +01005377 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5378 req->reason_code, tx, frame_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005379 ieee80211_report_disconnect(sdata, frame_buf,
5380 sizeof(frame_buf), true,
5381 req->reason_code);
Johannes Bergc9c3a062014-03-19 09:11:19 +01005382 return 0;
5383 }
Johannes Berg86552012012-10-29 09:46:31 +01005384
Johannes Bergc9c3a062014-03-19 09:11:19 +01005385 return -ENOTCONN;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005386}
5387
5388int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005389 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005390{
5391 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07005392 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005393 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02005394
Johannes Berg8d8b2612009-07-25 11:58:36 +02005395 /*
5396 * cfg80211 should catch this ... but it's racy since
5397 * we can receive a disassoc frame, process it, hand it
5398 * to cfg80211 while that's in a locked section already
5399 * trying to tell us that the user wants to disconnect.
5400 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005401 if (ifmgd->associated != req->bss)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005402 return -ENOLINK;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005403
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005404 sdata_info(sdata,
Calvin Owensdfa1ad22014-02-11 12:36:24 -06005405 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5406 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005407
Jouni Malinene69e95d2010-03-29 23:29:31 -07005408 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01005409 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5410 req->reason_code, !req->local_state_change,
5411 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005412
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005413 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5414 req->reason_code);
Johannes Bergbc83b682009-11-29 12:19:06 +01005415
Johannes Berg77fdaa12009-07-07 03:45:17 +02005416 return 0;
5417}
Jouni Malinen026331c2010-02-15 12:53:10 +02005418
Eliad Pellerafa762f2012-04-23 14:45:15 +03005419void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005420{
5421 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5422
Ben Greear49921852013-02-20 09:41:09 -08005423 /*
5424 * Make sure some work items will not run after this,
5425 * they will not do anything but might not have been
5426 * cancelled when disconnecting.
5427 */
5428 cancel_work_sync(&ifmgd->monitor_work);
5429 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5430 cancel_work_sync(&ifmgd->request_smps_work);
5431 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5432 cancel_work_sync(&ifmgd->chswitch_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03005433 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
Ben Greear49921852013-02-20 09:41:09 -08005434
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005435 sdata_lock(sdata);
Johannes Berg959867f2013-06-19 13:05:42 +02005436 if (ifmgd->assoc_data) {
5437 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Johannes Berge6f462d2016-12-08 17:22:09 +01005438 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02005439 cfg80211_assoc_timeout(sdata->dev, bss);
5440 }
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005441 if (ifmgd->auth_data)
5442 ieee80211_destroy_auth_data(sdata, false);
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005443 spin_lock_bh(&ifmgd->teardown_lock);
5444 if (ifmgd->teardown_skb) {
5445 kfree_skb(ifmgd->teardown_skb);
5446 ifmgd->teardown_skb = NULL;
5447 ifmgd->orig_teardown_skb = NULL;
5448 }
5449 spin_unlock_bh(&ifmgd->teardown_lock);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005450 del_timer_sync(&ifmgd->timer);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005451 sdata_unlock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005452}
5453
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005454void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5455 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005456 s32 rssi_level,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005457 gfp_t gfp)
5458{
5459 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5460
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005461 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
Johannes Bergb5878a22010-04-07 16:48:40 +02005462
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01005463 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005464}
5465EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
Johannes Berg98f03342014-11-26 12:42:02 +01005466
5467void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5468{
5469 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5470
5471 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5472
5473 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5474}
5475EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);