blob: 7fb9957359a3c1be557e577ba5b76cc4c1177105 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * BSS client mode implementation
Jouni Malinen5394af42009-01-08 13:31:59 +02003 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
Jiri Bencf0706e82007-05-05 11:45:53 -07004 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
Johannes Bergd98ad832014-09-03 15:24:57 +03008 * Copyright 2013-2014 Intel Mobile Communications GmbH
Avraham Sterne38a0172017-04-26 10:58:47 +03009 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
Ilan Peer94ba9272018-02-19 14:48:41 +020010 * Copyright (C) 2018 Intel Corporation
Jiri Bencf0706e82007-05-05 11:45:53 -070011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070017#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018#include <linux/if_ether.h>
19#include <linux/skbuff.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070020#include <linux/if_arp.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070021#include <linux/etherdevice.h>
Paul Gortmakerd9b93842011-09-18 13:21:27 -040022#include <linux/moduleparam.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010023#include <linux/rtnetlink.h>
Johannes Bergd91f36d2009-04-16 13:17:26 +020024#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040026#include <linux/export.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070027#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020028#include <asm/unaligned.h>
Johannes Berg60f8b392008-09-08 17:44:22 +020029
Jiri Bencf0706e82007-05-05 11:45:53 -070030#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020031#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040032#include "rate.h"
33#include "led.h"
Jouni Malinen39404fe2016-10-27 00:42:05 +030034#include "fils_aead.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070035
Johannes Berg1672c0e32013-01-29 15:02:27 +010036#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020037#define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010038#define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
Ilan Peer407879b2018-04-20 13:49:20 +030039#define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010040#define IEEE80211_AUTH_MAX_TRIES 3
41#define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
42#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020043#define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e32013-01-29 15:02:27 +010044#define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
45#define IEEE80211_ASSOC_MAX_TRIES 3
Johannes Berg66e67e42012-01-20 13:55:27 +010046
Ben Greear180205b2011-02-04 15:30:24 -080047static int max_nullfunc_tries = 2;
48module_param(max_nullfunc_tries, int, 0644);
49MODULE_PARM_DESC(max_nullfunc_tries,
50 "Maximum nullfunc tx tries before disconnecting (reason 4).");
51
52static int max_probe_tries = 5;
53module_param(max_probe_tries, int, 0644);
54MODULE_PARM_DESC(max_probe_tries,
55 "Maximum probe tries before disconnecting (reason 4).");
Johannes Bergb291ba12009-07-10 15:29:03 +020056
57/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010058 * Beacon loss timeout is calculated as N frames times the
59 * advertised beacon interval. This may need to be somewhat
60 * higher than what hardware might detect to account for
61 * delays in the host processing frames. But since we also
62 * probe on beacon miss before declaring the connection lost
63 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020064 */
Ben Greear59c1ec22013-03-19 14:19:56 -070065static int beacon_loss_count = 7;
66module_param(beacon_loss_count, int, 0644);
67MODULE_PARM_DESC(beacon_loss_count,
68 "Number of beacon intervals before we decide beacon was lost.");
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010069
Johannes Bergb291ba12009-07-10 15:29:03 +020070/*
71 * Time the connection can be idle before we probe
72 * it to see if we can still talk to the AP.
73 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030074#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020075/*
76 * Time we wait for a probe response after sending
77 * a probe request because of beacon loss or for
78 * checking the connection still works.
79 */
Ben Greear180205b2011-02-04 15:30:24 -080080static int probe_wait_ms = 500;
81module_param(probe_wait_ms, int, 0644);
82MODULE_PARM_DESC(probe_wait_ms,
83 "Maximum time(ms) to wait for probe response"
84 " before disconnecting (reason 4).");
Jiri Bencf0706e82007-05-05 11:45:53 -070085
Jouni Malinen17e4ec12010-03-29 23:28:30 -070086/*
Jouni Malinen391a2002010-08-27 22:22:00 +030087 * How many Beacon frames need to have been used in average signal strength
88 * before starting to indicate signal change events.
89 */
90#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
91
Johannes Berg77fdaa12009-07-07 03:45:17 +020092/*
Johannes Bergca386f32009-07-10 02:39:48 +020093 * We can have multiple work items (and connection probing)
94 * scheduling this timer, but we need to take care to only
95 * reschedule it when it should fire _earlier_ than it was
96 * asked for before, or if it's not pending right now. This
97 * function ensures that. Note that it then is required to
98 * run this function for all timeouts after the first one
99 * has happened -- the work that runs from this timer will
100 * do that.
101 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200102static void run_again(struct ieee80211_sub_if_data *sdata,
103 unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200104{
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200105 sdata_assert_lock(sdata);
Johannes Bergca386f32009-07-10 02:39:48 +0200106
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200107 if (!timer_pending(&sdata->u.mgd.timer) ||
108 time_before(timeout, sdata->u.mgd.timer.expires))
109 mod_timer(&sdata->u.mgd.timer, timeout);
Johannes Bergca386f32009-07-10 02:39:48 +0200110}
111
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400112void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200113{
Johannes Bergc1288b12012-01-19 09:29:57 +0100114 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200115 return;
116
Johannes Berg30686bf2015-06-02 21:39:54 +0200117 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Johannes Berg7eeff742012-07-18 10:27:27 +0200118 return;
119
Johannes Bergb291ba12009-07-10 15:29:03 +0200120 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100121 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200122}
123
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400124void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
125{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400126 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
127
Johannes Bergb100e5d2016-03-17 15:41:37 +0200128 if (unlikely(!ifmgd->associated))
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100129 return;
130
Johannes Bergb100e5d2016-03-17 15:41:37 +0200131 if (ifmgd->probe_send_count)
132 ifmgd->probe_send_count = 0;
Eliad Peller448cd2e2014-02-11 12:30:18 +0200133
Johannes Berg30686bf2015-06-02 21:39:54 +0200134 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400135 return;
136
Johannes Bergb100e5d2016-03-17 15:41:37 +0200137 mod_timer(&ifmgd->conn_mon_timer,
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400138 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
139}
140
Johannes Berg5484e232008-09-08 17:44:27 +0200141static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200142{
Johannes Berg5484e232008-09-08 17:44:27 +0200143 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200144}
145
Johannes Berg6565ec92013-02-08 14:52:32 +0100146static u32
147ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
148 struct ieee80211_supported_band *sband,
149 struct ieee80211_channel *channel,
150 const struct ieee80211_ht_operation *ht_oper,
151 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300152 const struct ieee80211_he_operation *he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +0200153 struct cfg80211_chan_def *chandef, bool tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100154{
Johannes Berg5cdaed12013-07-31 11:23:06 +0200155 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg6565ec92013-02-08 14:52:32 +0100156 struct cfg80211_chan_def vht_chandef;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200157 struct ieee80211_sta_ht_cap sta_ht_cap;
Johannes Berg6565ec92013-02-08 14:52:32 +0100158 u32 ht_cfreq, ret;
159
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200160 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
161 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
162
Johannes Berg6565ec92013-02-08 14:52:32 +0100163 chandef->chan = channel;
164 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
165 chandef->center_freq1 = channel->center_freq;
166 chandef->center_freq2 = 0;
167
Johannes Bergb1b1ae22017-10-13 15:26:01 +0300168 if (!ht_oper || !sta_ht_cap.ht_supported) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100169 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
170 goto out;
171 }
172
173 chandef->width = NL80211_CHAN_WIDTH_20;
174
175 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
176 channel->band);
177 /* check that channel matches the right operating channel */
Johannes Berg5cdaed12013-07-31 11:23:06 +0200178 if (!tracking && channel->center_freq != ht_cfreq) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100179 /*
180 * It's possible that some APs are confused here;
181 * Netgear WNDR3700 sometimes reports 4 higher than
182 * the actual channel in association responses, but
183 * since we look at probe response/beacon data here
184 * it should be OK.
185 */
Johannes Berg5cdaed12013-07-31 11:23:06 +0200186 sdata_info(sdata,
187 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
188 channel->center_freq, ht_cfreq,
189 ht_oper->primary_chan, channel->band);
Johannes Berg6565ec92013-02-08 14:52:32 +0100190 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
191 goto out;
192 }
193
194 /* check 40 MHz support, if we have it */
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +0200195 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100196 ieee80211_chandef_ht_oper(ht_oper, chandef);
Johannes Berg6565ec92013-02-08 14:52:32 +0100197 } else {
198 /* 40 MHz (and 80 MHz) must be supported for VHT */
199 ret = IEEE80211_STA_DISABLE_VHT;
Johannes Berg85220d72013-03-25 18:29:27 +0100200 /* also mark 40 MHz disabled */
201 ret |= IEEE80211_STA_DISABLE_40MHZ;
Johannes Berg6565ec92013-02-08 14:52:32 +0100202 goto out;
203 }
204
205 if (!vht_oper || !sband->vht_cap.vht_supported) {
206 ret = IEEE80211_STA_DISABLE_VHT;
207 goto out;
208 }
209
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100210 vht_chandef = *chandef;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300211 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
212 (le32_to_cpu(he_oper->he_oper_params) &
213 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
214 struct ieee80211_vht_operation he_oper_vht_cap;
215
216 /*
217 * Set only first 3 bytes (other 2 aren't used in
218 * ieee80211_chandef_vht_oper() anyway)
219 */
220 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
221 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
222
223 if (!ieee80211_chandef_vht_oper(&he_oper_vht_cap,
224 &vht_chandef)) {
225 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
226 sdata_info(sdata,
227 "HE AP VHT information is invalid, disable HE\n");
228 ret = IEEE80211_STA_DISABLE_HE;
229 goto out;
230 }
231 } else if (!ieee80211_chandef_vht_oper(vht_oper, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200232 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100233 sdata_info(sdata,
Johannes Berg8ac3c7042015-12-18 15:08:34 +0100234 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100235 ret = IEEE80211_STA_DISABLE_VHT;
236 goto out;
237 }
238
239 if (!cfg80211_chandef_valid(&vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200240 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100241 sdata_info(sdata,
242 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100243 ret = IEEE80211_STA_DISABLE_VHT;
244 goto out;
245 }
246
247 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
248 ret = 0;
249 goto out;
250 }
251
252 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200253 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100254 sdata_info(sdata,
255 "AP VHT information doesn't match HT, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100256 ret = IEEE80211_STA_DISABLE_VHT;
257 goto out;
258 }
259
260 *chandef = vht_chandef;
261
262 ret = 0;
263
264out:
Johannes Berg963a18522014-02-21 20:34:34 +0100265 /*
266 * When tracking the current AP, don't do any further checks if the
267 * new chandef is identical to the one we're currently using for the
268 * connection. This keeps us from playing ping-pong with regulatory,
269 * without it the following can happen (for example):
270 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
271 * - AP advertises regdom US
272 * - CRDA loads regdom US with 80 MHz prohibited (old database)
273 * - the code below detects an unsupported channel, downgrades, and
274 * we disconnect from the AP in the caller
275 * - disconnect causes CRDA to reload world regdomain and the game
276 * starts anew.
277 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
278 *
279 * It seems possible that there are still scenarios with CSA or real
280 * bandwidth changes where a this could happen, but those cases are
281 * less common and wouldn't completely prevent using the AP.
282 */
283 if (tracking &&
284 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
285 return ret;
286
Johannes Berg586e01e2013-02-14 12:13:53 +0100287 /* don't print the message below for VHT mismatch if VHT is disabled */
288 if (ret & IEEE80211_STA_DISABLE_VHT)
289 vht_chandef = *chandef;
290
Johannes Bergddfe49b2013-07-31 20:52:03 +0200291 /*
292 * Ignore the DISABLED flag when we're already connected and only
293 * tracking the APs beacon for bandwidth changes - otherwise we
294 * might get disconnected here if we connect to an AP, update our
295 * regulatory information based on the AP's country IE and the
296 * information we have is wrong/outdated and disables the channel
297 * that we're actually using for the connection to the AP.
298 */
Johannes Berg6565ec92013-02-08 14:52:32 +0100299 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
Johannes Bergddfe49b2013-07-31 20:52:03 +0200300 tracking ? 0 :
301 IEEE80211_CHAN_DISABLED)) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100302 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
303 ret = IEEE80211_STA_DISABLE_HT |
304 IEEE80211_STA_DISABLE_VHT;
Chris Wrightb56e4b82013-07-31 12:12:24 -0700305 break;
Johannes Berg6565ec92013-02-08 14:52:32 +0100306 }
307
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200308 ret |= ieee80211_chandef_downgrade(chandef);
Johannes Berg6565ec92013-02-08 14:52:32 +0100309 }
310
Johannes Berg5cdaed12013-07-31 11:23:06 +0200311 if (chandef->width != vht_chandef.width && !tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100312 sdata_info(sdata,
313 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
314
315 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
316 return ret;
317}
318
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100319static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
320 struct sta_info *sta,
Eliad Peller53b954e2014-07-24 11:20:05 +0300321 const struct ieee80211_ht_cap *ht_cap,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100322 const struct ieee80211_ht_operation *ht_oper,
323 const struct ieee80211_vht_operation *vht_oper,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300324 const struct ieee80211_he_operation *he_oper,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100325 const u8 *bssid, u32 *changed)
Johannes Bergd5522e02009-03-30 13:23:35 +0200326{
327 struct ieee80211_local *local = sdata->local;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100328 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300329 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
330 struct ieee80211_supported_band *sband =
331 local->hw.wiphy->bands[chan->band];
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100332 struct cfg80211_chan_def chandef;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200333 u16 ht_opmode;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100334 u32 flags;
335 enum ieee80211_sta_rx_bandwidth new_sta_bw;
336 int ret;
337
338 /* if HT was/is disabled, don't track any bandwidth changes */
339 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
340 return 0;
341
342 /* don't check VHT if we associated as non-VHT station */
343 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
344 vht_oper = NULL;
Johannes Bergd5522e02009-03-30 13:23:35 +0200345
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300346 /* don't check HE if we associated as non-HE station */
347 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
348 !ieee80211_get_he_sta_cap(sband))
349 he_oper = NULL;
350
Johannes Berg11289582013-02-07 17:36:12 +0100351 if (WARN_ON_ONCE(!sta))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100352 return -EINVAL;
Johannes Berg11289582013-02-07 17:36:12 +0100353
Avri Altman017b45b2013-11-18 19:06:48 +0200354 /*
355 * if bss configuration changed store the new one -
356 * this may be applicable even if channel is identical
357 */
358 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
359 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
360 *changed |= BSS_CHANGED_HT;
361 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
362 }
363
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300364 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
Eliad Peller53b954e2014-07-24 11:20:05 +0300365 flags = ieee80211_determine_chantype(sdata, sband, chan,
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300366 ht_oper, vht_oper, he_oper,
Eliad Peller53b954e2014-07-24 11:20:05 +0300367 &chandef, true);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100368
369 /*
370 * Downgrade the new channel if we associated with restricted
371 * capabilities. For example, if we associated as a 20 MHz STA
372 * to a 40 MHz AP (due to regulatory, capabilities or config
373 * reasons) then switching to a 40 MHz channel now won't do us
374 * any good -- we couldn't use it with the AP.
375 */
376 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
377 chandef.width == NL80211_CHAN_WIDTH_80P80)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200378 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100379 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
380 chandef.width == NL80211_CHAN_WIDTH_160)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200381 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100382 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
383 chandef.width > NL80211_CHAN_WIDTH_20)
Simon Wunderliche6b7cde2013-08-28 13:41:29 +0200384 flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100385
386 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
387 return 0;
388
389 sdata_info(sdata,
390 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
391 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
392 chandef.center_freq1, chandef.center_freq2);
393
394 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
395 IEEE80211_STA_DISABLE_VHT |
396 IEEE80211_STA_DISABLE_40MHZ |
397 IEEE80211_STA_DISABLE_80P80MHZ |
398 IEEE80211_STA_DISABLE_160MHZ)) ||
399 !cfg80211_chandef_valid(&chandef)) {
400 sdata_info(sdata,
401 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
402 ifmgd->bssid);
403 return -EINVAL;
Johannes Berg64f68e52012-03-28 10:58:37 +0200404 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200405
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100406 switch (chandef.width) {
407 case NL80211_CHAN_WIDTH_20_NOHT:
408 case NL80211_CHAN_WIDTH_20:
409 new_sta_bw = IEEE80211_STA_RX_BW_20;
410 break;
411 case NL80211_CHAN_WIDTH_40:
412 new_sta_bw = IEEE80211_STA_RX_BW_40;
413 break;
414 case NL80211_CHAN_WIDTH_80:
415 new_sta_bw = IEEE80211_STA_RX_BW_80;
416 break;
417 case NL80211_CHAN_WIDTH_80P80:
418 case NL80211_CHAN_WIDTH_160:
419 new_sta_bw = IEEE80211_STA_RX_BW_160;
420 break;
421 default:
422 return -EINVAL;
423 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200424
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100425 if (new_sta_bw > sta->cur_max_bandwidth)
426 new_sta_bw = sta->cur_max_bandwidth;
Johannes Berg64f68e52012-03-28 10:58:37 +0200427
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100428 if (new_sta_bw < sta->sta.bandwidth) {
429 sta->sta.bandwidth = new_sta_bw;
430 rate_control_rate_update(local, sband, sta,
431 IEEE80211_RC_BW_CHANGED);
432 }
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530433
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100434 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
435 if (ret) {
436 sdata_info(sdata,
437 "AP %pM changed bandwidth to incompatible one - disconnect\n",
438 ifmgd->bssid);
439 return ret;
440 }
441
442 if (new_sta_bw > sta->sta.bandwidth) {
443 sta->sta.bandwidth = new_sta_bw;
444 rate_control_rate_update(local, sband, sta,
445 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200446 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200447
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100448 return 0;
Johannes Bergd5522e02009-03-30 13:23:35 +0200449}
450
Johannes Berg9c6bd792008-09-11 00:01:52 +0200451/* frame sending functions */
452
Johannes Berg66e67e42012-01-20 13:55:27 +0100453static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200454 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100455 struct ieee80211_supported_band *sband,
456 struct ieee80211_channel *channel,
457 enum ieee80211_smps_mode smps)
458{
Johannes Berg66e67e42012-01-20 13:55:27 +0100459 u8 *pos;
460 u32 flags = channel->flags;
461 u16 cap;
462 struct ieee80211_sta_ht_cap ht_cap;
463
464 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
465
Johannes Berg66e67e42012-01-20 13:55:27 +0100466 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
467 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
468
Johannes Berg66e67e42012-01-20 13:55:27 +0100469 /* determine capability flags */
470 cap = ht_cap.cap;
471
Johannes Berg9dde6422012-05-16 23:43:19 +0200472 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100473 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
474 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
475 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
476 cap &= ~IEEE80211_HT_CAP_SGI_40;
477 }
478 break;
479 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
480 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
481 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
482 cap &= ~IEEE80211_HT_CAP_SGI_40;
483 }
484 break;
485 }
486
Johannes Berg24398e32012-03-28 10:58:36 +0200487 /*
488 * If 40 MHz was disabled associate as though we weren't
489 * capable of 40 MHz -- some broken APs will never fall
490 * back to trying to transmit in 20 MHz.
491 */
492 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
493 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
494 cap &= ~IEEE80211_HT_CAP_SGI_40;
495 }
496
Johannes Berg66e67e42012-01-20 13:55:27 +0100497 /* set SM PS mode properly */
498 cap &= ~IEEE80211_HT_CAP_SM_PS;
499 switch (smps) {
500 case IEEE80211_SMPS_AUTOMATIC:
501 case IEEE80211_SMPS_NUM_MODES:
502 WARN_ON(1);
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500503 /* fall through */
Johannes Berg66e67e42012-01-20 13:55:27 +0100504 case IEEE80211_SMPS_OFF:
505 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
506 IEEE80211_HT_CAP_SM_PS_SHIFT;
507 break;
508 case IEEE80211_SMPS_STATIC:
509 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
510 IEEE80211_HT_CAP_SM_PS_SHIFT;
511 break;
512 case IEEE80211_SMPS_DYNAMIC:
513 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
514 IEEE80211_HT_CAP_SM_PS_SHIFT;
515 break;
516 }
517
518 /* reserve and fill IE */
519 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
520 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
521}
522
Sara Sharon322cd402015-07-08 15:41:43 +0300523/* This function determines vht capability flags for the association
524 * and builds the IE.
525 * Note - the function may set the owner of the MU-MIMO capability
526 */
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000527static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
528 struct sk_buff *skb,
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100529 struct ieee80211_supported_band *sband,
530 struct ieee80211_vht_cap *ap_vht_cap)
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000531{
Sara Sharon322cd402015-07-08 15:41:43 +0300532 struct ieee80211_local *local = sdata->local;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000533 u8 *pos;
534 u32 cap;
535 struct ieee80211_sta_vht_cap vht_cap;
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200536 u32 mask, ap_bf_sts, our_bf_sts;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000537
538 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
539
540 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +0100541 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000542
543 /* determine capability flags */
544 cap = vht_cap.cap;
545
Johannes Bergf2d9d272012-11-22 14:11:39 +0100546 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
Johannes Berg575f0532014-11-24 16:51:33 +0100547 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
548
549 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
550 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
551 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
552 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100553 }
554
555 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
556 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
Johannes Berg575f0532014-11-24 16:51:33 +0100557 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Johannes Bergf2d9d272012-11-22 14:11:39 +0100558 }
559
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100560 /*
561 * Some APs apparently get confused if our capabilities are better
562 * than theirs, so restrict what we advertise in the assoc request.
563 */
564 if (!(ap_vht_cap->vht_cap_info &
565 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
Sara Sharon322cd402015-07-08 15:41:43 +0300566 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
567 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
568 else if (!(ap_vht_cap->vht_cap_info &
569 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
570 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
571
572 /*
573 * If some other vif is using the MU-MIMO capablity we cannot associate
574 * using MU-MIMO - this will lead to contradictions in the group-id
575 * mechanism.
576 * Ownership is defined since association request, in order to avoid
577 * simultaneous associations with MU-MIMO.
578 */
579 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
580 bool disable_mu_mimo = false;
581 struct ieee80211_sub_if_data *other;
582
583 list_for_each_entry_rcu(other, &local->interfaces, list) {
Sara Sharonb5a33d52016-02-16 12:48:18 +0200584 if (other->vif.mu_mimo_owner) {
Sara Sharon322cd402015-07-08 15:41:43 +0300585 disable_mu_mimo = true;
586 break;
587 }
588 }
589 if (disable_mu_mimo)
590 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
591 else
Sara Sharonb5a33d52016-02-16 12:48:18 +0200592 sdata->vif.mu_mimo_owner = true;
Sara Sharon322cd402015-07-08 15:41:43 +0300593 }
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100594
Eyal Shapirac1cf6d42014-01-08 15:49:08 +0200595 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
596
597 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
598 our_bf_sts = cap & mask;
599
600 if (ap_bf_sts < our_bf_sts) {
601 cap &= ~mask;
602 cap |= ap_bf_sts;
603 }
604
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000605 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000606 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000607 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
608}
609
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300610/* This function determines HE capability flags for the association
611 * and builds the IE.
612 */
613static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
614 struct sk_buff *skb,
615 struct ieee80211_supported_band *sband)
616{
617 u8 *pos;
618 const struct ieee80211_sta_he_cap *he_cap = NULL;
619 u8 he_cap_size;
620
621 he_cap = ieee80211_get_he_sta_cap(sband);
622 if (!he_cap)
623 return;
624
625 /*
626 * TODO: the 1 added is because this temporarily is under the EXTENSION
627 * IE. Get rid of it when it moves.
628 */
629 he_cap_size =
630 2 + 1 + sizeof(he_cap->he_cap_elem) +
631 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
632 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
633 he_cap->he_cap_elem.phy_cap_info);
634 pos = skb_put(skb, he_cap_size);
635 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
636}
637
Johannes Berg66e67e42012-01-20 13:55:27 +0100638static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
639{
640 struct ieee80211_local *local = sdata->local;
641 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
642 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
643 struct sk_buff *skb;
644 struct ieee80211_mgmt *mgmt;
645 u8 *pos, qos_info;
646 size_t offset = 0, noffset;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200647 int i, count, rates_len, supp_rates_len, shift;
Johannes Berg66e67e42012-01-20 13:55:27 +0100648 u16 capab;
649 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200650 struct ieee80211_chanctx_conf *chanctx_conf;
651 struct ieee80211_channel *chan;
Johannes Berg44f6d422017-06-10 13:52:44 +0300652 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100653
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200654 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +0100655
Johannes Berg55de9082012-07-26 17:24:39 +0200656 rcu_read_lock();
657 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
658 if (WARN_ON(!chanctx_conf)) {
659 rcu_read_unlock();
660 return;
661 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100662 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200663 rcu_read_unlock();
664 sband = local->hw.wiphy->bands[chan->band];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200665 shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg66e67e42012-01-20 13:55:27 +0100666
667 if (assoc_data->supp_rates_len) {
668 /*
669 * Get all rates supported by the device and the AP as
670 * some APs don't like getting a superset of their rates
671 * in the association request (e.g. D-Link DAP 1353 in
672 * b-only mode)...
673 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200674 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
675 assoc_data->supp_rates,
676 assoc_data->supp_rates_len,
677 &rates);
Johannes Berg66e67e42012-01-20 13:55:27 +0100678 } else {
679 /*
680 * In case AP not provide any supported rates information
681 * before association, we send information element(s) with
682 * all rates that we support.
683 */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200684 rates_len = 0;
685 for (i = 0; i < sband->n_bitrates; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200686 rates |= BIT(i);
687 rates_len++;
688 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100689 }
690
691 skb = alloc_skb(local->hw.extra_tx_headroom +
692 sizeof(*mgmt) + /* bit too much but doesn't matter */
693 2 + assoc_data->ssid_len + /* SSID */
694 4 + rates_len + /* (extended) rates */
695 4 + /* power capability */
696 2 + 2 * sband->n_channels + /* supported channels */
697 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000698 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300699 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
700 sizeof(struct ieee80211_he_mcs_nss_supp) +
701 IEEE80211_HE_PPE_THRES_MAX_LEN +
Johannes Berg66e67e42012-01-20 13:55:27 +0100702 assoc_data->ie_len + /* extra IEs */
Jouni Malinen39404fe2016-10-27 00:42:05 +0300703 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
Johannes Berg66e67e42012-01-20 13:55:27 +0100704 9, /* WMM */
705 GFP_KERNEL);
706 if (!skb)
707 return;
708
709 skb_reserve(skb, local->hw.extra_tx_headroom);
710
711 capab = WLAN_CAPABILITY_ESS;
712
Johannes Berg57fbcce2016-04-12 15:56:15 +0200713 if (sband->band == NL80211_BAND_2GHZ) {
Johannes Bergea1b2b452015-06-02 20:15:49 +0200714 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
715 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
Johannes Berg66e67e42012-01-20 13:55:27 +0100716 }
717
718 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
719 capab |= WLAN_CAPABILITY_PRIVACY;
720
721 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg30686bf2015-06-02 21:39:54 +0200722 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
Johannes Berg66e67e42012-01-20 13:55:27 +0100723 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
724
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300725 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
726 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
727
Johannes Bergb080db52017-06-16 14:29:19 +0200728 mgmt = skb_put_zero(skb, 24);
Johannes Berg66e67e42012-01-20 13:55:27 +0100729 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
730 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
731 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
732
733 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
734 skb_put(skb, 10);
735 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
736 IEEE80211_STYPE_REASSOC_REQ);
737 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
738 mgmt->u.reassoc_req.listen_interval =
739 cpu_to_le16(local->hw.conf.listen_interval);
740 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
741 ETH_ALEN);
742 } else {
743 skb_put(skb, 4);
744 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
745 IEEE80211_STYPE_ASSOC_REQ);
746 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
747 mgmt->u.assoc_req.listen_interval =
748 cpu_to_le16(local->hw.conf.listen_interval);
749 }
750
751 /* SSID */
752 pos = skb_put(skb, 2 + assoc_data->ssid_len);
753 *pos++ = WLAN_EID_SSID;
754 *pos++ = assoc_data->ssid_len;
755 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
756
757 /* add all rates which were marked to be used above */
758 supp_rates_len = rates_len;
759 if (supp_rates_len > 8)
760 supp_rates_len = 8;
761
762 pos = skb_put(skb, supp_rates_len + 2);
763 *pos++ = WLAN_EID_SUPP_RATES;
764 *pos++ = supp_rates_len;
765
766 count = 0;
767 for (i = 0; i < sband->n_bitrates; i++) {
768 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200769 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
770 5 * (1 << shift));
771 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100772 if (++count == 8)
773 break;
774 }
775 }
776
777 if (rates_len > count) {
778 pos = skb_put(skb, rates_len - count + 2);
779 *pos++ = WLAN_EID_EXT_SUPP_RATES;
780 *pos++ = rates_len - count;
781
782 for (i++; i < sband->n_bitrates; i++) {
783 if (BIT(i) & rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200784 int rate;
785 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
786 5 * (1 << shift));
787 *pos++ = (u8) rate;
Johannes Berg66e67e42012-01-20 13:55:27 +0100788 }
789 }
790 }
791
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300792 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
793 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100794 pos = skb_put(skb, 4);
795 *pos++ = WLAN_EID_PWR_CAPABILITY;
796 *pos++ = 2;
797 *pos++ = 0; /* min tx power */
Simon Wunderlich0430c882013-07-08 16:55:55 +0200798 /* max tx power */
799 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300800 }
Johannes Berg66e67e42012-01-20 13:55:27 +0100801
Assaf Krausscd2f5dd2014-09-03 15:25:02 +0300802 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100803 /* TODO: get this in reg domain format */
804 pos = skb_put(skb, 2 * sband->n_channels + 2);
805 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
806 *pos++ = 2 * sband->n_channels;
807 for (i = 0; i < sband->n_channels; i++) {
808 *pos++ = ieee80211_frequency_to_channel(
809 sband->channels[i].center_freq);
810 *pos++ = 1; /* one channel in the subband*/
811 }
812 }
813
814 /* if present, add any custom IEs that go before HT */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200815 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100816 static const u8 before_ht[] = {
817 WLAN_EID_SSID,
818 WLAN_EID_SUPP_RATES,
819 WLAN_EID_EXT_SUPP_RATES,
820 WLAN_EID_PWR_CAPABILITY,
821 WLAN_EID_SUPPORTED_CHANNELS,
822 WLAN_EID_RSN,
823 WLAN_EID_QOS_CAPA,
824 WLAN_EID_RRM_ENABLED_CAPABILITIES,
825 WLAN_EID_MOBILITY_DOMAIN,
Johannes Berg8ed28742014-10-27 12:03:19 +0100826 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
827 WLAN_EID_RIC_DATA, /* reassoc only */
Johannes Berg66e67e42012-01-20 13:55:27 +0100828 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
829 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100830 static const u8 after_ric[] = {
831 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
832 WLAN_EID_HT_CAPABILITY,
833 WLAN_EID_BSS_COEX_2040,
Johannes Berga7f26d82017-08-05 11:44:32 +0300834 /* luckily this is almost always there */
Johannes Berg8ed28742014-10-27 12:03:19 +0100835 WLAN_EID_EXT_CAPABILITY,
836 WLAN_EID_QOS_TRAFFIC_CAPA,
837 WLAN_EID_TIM_BCAST_REQ,
838 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300839 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg8ed28742014-10-27 12:03:19 +0100840 WLAN_EID_VHT_CAPABILITY,
841 WLAN_EID_OPMODE_NOTIF,
842 };
843
844 noffset = ieee80211_ie_split_ric(assoc_data->ie,
845 assoc_data->ie_len,
846 before_ht,
847 ARRAY_SIZE(before_ht),
848 after_ric,
849 ARRAY_SIZE(after_ric),
850 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800851 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100852 offset = noffset;
853 }
854
Johannes Bergf2d9d272012-11-22 14:11:39 +0100855 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
856 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
857 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
858
Johannes Berga8243b72012-11-22 14:32:09 +0100859 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200860 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200861 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100862
Johannes Berg3de38022014-02-04 09:54:07 +0100863 /* if present, add any custom IEs that go before VHT */
864 if (assoc_data->ie_len) {
865 static const u8 before_vht[] = {
Johannes Berga7f26d82017-08-05 11:44:32 +0300866 /*
867 * no need to list the ones split off before HT
868 * or generated here
869 */
Johannes Berg3de38022014-02-04 09:54:07 +0100870 WLAN_EID_BSS_COEX_2040,
871 WLAN_EID_EXT_CAPABILITY,
872 WLAN_EID_QOS_TRAFFIC_CAPA,
873 WLAN_EID_TIM_BCAST_REQ,
874 WLAN_EID_INTERWORKING,
Johannes Berga7f26d82017-08-05 11:44:32 +0300875 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
Johannes Berg3de38022014-02-04 09:54:07 +0100876 };
Johannes Berg8ed28742014-10-27 12:03:19 +0100877
878 /* RIC already taken above, so no need to handle here anymore */
Johannes Berg3de38022014-02-04 09:54:07 +0100879 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
880 before_vht, ARRAY_SIZE(before_vht),
881 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800882 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg3de38022014-02-04 09:54:07 +0100883 offset = noffset;
884 }
885
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300886 /* if present, add any custom IEs that go before HE */
887 if (assoc_data->ie_len) {
888 static const u8 before_he[] = {
889 /*
890 * no need to list the ones split off before VHT
891 * or generated here
892 */
893 WLAN_EID_OPMODE_NOTIF,
894 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
895 /* 11ai elements */
896 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
897 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
898 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
899 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
900 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
901 /* TODO: add 11ah/11aj/11ak elements */
902 };
903
904 /* RIC already taken above, so no need to handle here anymore */
905 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
906 before_he, ARRAY_SIZE(before_he),
907 offset);
908 pos = skb_put(skb, noffset - offset);
909 memcpy(pos, assoc_data->ie + offset, noffset - offset);
910 offset = noffset;
911 }
912
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000913 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100914 ieee80211_add_vht_ie(sdata, skb, sband,
915 &assoc_data->ap_vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000916
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300917 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
918 ieee80211_add_he_ie(sdata, skb, sband);
919
920 /* if present, add any custom non-vendor IEs that go after HE */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200921 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100922 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
923 assoc_data->ie_len,
924 offset);
yuan linyub952f4d2017-06-18 22:52:04 +0800925 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100926 offset = noffset;
927 }
928
Johannes Berg76f03032012-03-08 15:02:05 +0100929 if (assoc_data->wmm) {
930 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200931 qos_info = ifmgd->uapsd_queues;
932 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100933 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
934 } else {
935 qos_info = 0;
936 }
937
Arik Nemtsov40b861a2014-07-17 17:14:23 +0300938 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
Johannes Berg66e67e42012-01-20 13:55:27 +0100939 }
940
941 /* add any remaining custom (i.e. vendor specific here) IEs */
Johannes Bergb3f51e92013-10-25 11:31:42 +0200942 if (assoc_data->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100943 noffset = assoc_data->ie_len;
yuan linyub952f4d2017-06-18 22:52:04 +0800944 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
Johannes Berg66e67e42012-01-20 13:55:27 +0100945 }
946
Jouni Malinen39404fe2016-10-27 00:42:05 +0300947 if (assoc_data->fils_kek_len &&
948 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
949 dev_kfree_skb(skb);
950 return;
951 }
952
Ilan Peerd4e36e52018-04-20 13:49:25 +0300953 drv_mgd_prepare_tx(local, sdata, 0);
Johannes Berga1845fc2012-06-27 13:18:36 +0200954
Johannes Berg66e67e42012-01-20 13:55:27 +0100955 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Johannes Berg30686bf2015-06-02 21:39:54 +0200956 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +0100957 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
958 IEEE80211_TX_INTFL_MLME_CONN_TX;
Johannes Berg66e67e42012-01-20 13:55:27 +0100959 ieee80211_tx_skb(sdata, skb);
960}
961
Kalle Valo572e0012009-02-10 17:09:31 +0200962void ieee80211_send_pspoll(struct ieee80211_local *local,
963 struct ieee80211_sub_if_data *sdata)
964{
Kalle Valo572e0012009-02-10 17:09:31 +0200965 struct ieee80211_pspoll *pspoll;
966 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200967
Kalle Valod8cd1892010-01-05 20:16:26 +0200968 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
969 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200970 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200971
Kalle Valod8cd1892010-01-05 20:16:26 +0200972 pspoll = (struct ieee80211_pspoll *) skb->data;
973 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200974
Johannes Berg62ae67b2009-11-18 18:42:05 +0100975 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
976 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200977}
978
Johannes Berg965beda2009-04-16 13:17:24 +0200979void ieee80211_send_nullfunc(struct ieee80211_local *local,
980 struct ieee80211_sub_if_data *sdata,
Johannes Berg076cdcb2015-09-24 16:14:55 +0200981 bool powersave)
Johannes Berg965beda2009-04-16 13:17:24 +0200982{
983 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200984 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530985 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200986
Luca Coelho41cbb0f2018-06-09 09:14:44 +0300987 /* Don't send NDPs when STA is connected HE */
988 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
989 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
990 return;
991
Ben Caradoc-Davies7c181f42018-03-19 12:57:44 +1300992 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
993 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
Kalle Valod8cd1892010-01-05 20:16:26 +0200994 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200995 return;
996
Kalle Valod8cd1892010-01-05 20:16:26 +0200997 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200998 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200999 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +02001000
Seth Forshee6c17b772013-02-11 11:21:07 -06001001 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1002 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Pontus Fuchsff40b422013-06-04 12:44:52 +02001003
Johannes Berg30686bf2015-06-02 21:39:54 +02001004 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Pontus Fuchsff40b422013-06-04 12:44:52 +02001005 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1006
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001007 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +05301008 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1009
Johannes Berg62ae67b2009-11-18 18:42:05 +01001010 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +02001011}
1012
Felix Fietkaud5242152010-01-08 18:06:26 +01001013static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1014 struct ieee80211_sub_if_data *sdata)
1015{
1016 struct sk_buff *skb;
1017 struct ieee80211_hdr *nullfunc;
1018 __le16 fc;
1019
1020 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1021 return;
1022
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001023 /* Don't send NDPs when connected HE */
1024 if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE))
1025 return;
1026
Felix Fietkaud5242152010-01-08 18:06:26 +01001027 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -07001028 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +01001029 return;
Joe Perchesd15b8452011-08-29 14:17:31 -07001030
Felix Fietkaud5242152010-01-08 18:06:26 +01001031 skb_reserve(skb, local->hw.extra_tx_headroom);
1032
Johannes Bergb080db52017-06-16 14:29:19 +02001033 nullfunc = skb_put_zero(skb, 30);
Felix Fietkaud5242152010-01-08 18:06:26 +01001034 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1035 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1036 nullfunc->frame_control = fc;
1037 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1038 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1039 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1040 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1041
1042 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1043 ieee80211_tx_skb(sdata, skb);
1044}
1045
Johannes Bergcc32abd2009-05-15 11:52:31 +02001046/* spectrum management related things */
1047static void ieee80211_chswitch_work(struct work_struct *work)
1048{
1049 struct ieee80211_sub_if_data *sdata =
1050 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Karl Beldan675a0b02013-03-25 16:26:57 +01001051 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001052 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001053 int ret;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001054
Johannes Berg9607e6b2009-12-23 13:15:31 +01001055 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +02001056 return;
1057
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001058 sdata_lock(sdata);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001059 mutex_lock(&local->mtx);
1060 mutex_lock(&local->chanctx_mtx);
1061
Johannes Berg77fdaa12009-07-07 03:45:17 +02001062 if (!ifmgd->associated)
1063 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001064
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001065 if (!sdata->vif.csa_active)
1066 goto out;
1067
1068 /*
1069 * using reservation isn't immediate as it may be deferred until later
1070 * with multi-vif. once reservation is complete it will re-schedule the
1071 * work with no reserved_chanctx so verify chandef to check if it
1072 * completed successfully
1073 */
1074
1075 if (sdata->reserved_chanctx) {
1076 /*
1077 * with multi-vif csa driver may call ieee80211_csa_finish()
1078 * many times while waiting for other interfaces to use their
1079 * reservations
1080 */
1081 if (sdata->reserved_ready)
1082 goto out;
1083
1084 ret = ieee80211_vif_use_reserved_context(sdata);
1085 if (ret) {
1086 sdata_info(sdata,
1087 "failed to use reserved channel context, disconnecting (err=%d)\n",
1088 ret);
1089 ieee80211_queue_work(&sdata->local->hw,
1090 &ifmgd->csa_connection_drop_work);
1091 goto out;
1092 }
1093
1094 goto out;
1095 }
1096
1097 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1098 &sdata->csa_chandef)) {
Arik Nemtsov7578d572013-09-01 17:15:51 +03001099 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001100 "failed to finalize channel switch, disconnecting\n");
Arik Nemtsov7578d572013-09-01 17:15:51 +03001101 ieee80211_queue_work(&sdata->local->hw,
1102 &ifmgd->csa_connection_drop_work);
1103 goto out;
1104 }
Karl Beldan675a0b02013-03-25 16:26:57 +01001105
Johannes Berg77fdaa12009-07-07 03:45:17 +02001106 /* XXX: shouldn't really modify cfg80211-owned data! */
Luciano Coelho33787fc2013-11-11 20:34:54 +02001107 ifmgd->associated->channel = sdata->csa_chandef.chan;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001108
Luciano Coelho0c21e632014-10-08 09:48:39 +03001109 ifmgd->csa_waiting_bcn = true;
Luciano Coelhof1d65582014-10-08 09:48:38 +03001110
Michal Kaziore5593f52014-04-09 15:45:36 +02001111 ieee80211_sta_reset_beacon_monitor(sdata);
1112 ieee80211_sta_reset_conn_monitor(sdata);
1113
Michal Kazior59af6922014-04-09 15:10:59 +02001114out:
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001115 mutex_unlock(&local->chanctx_mtx);
1116 mutex_unlock(&local->mtx);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001117 sdata_unlock(sdata);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001118}
1119
Luciano Coelho0c21e632014-10-08 09:48:39 +03001120static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1121{
1122 struct ieee80211_local *local = sdata->local;
1123 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1124 int ret;
1125
1126 sdata_assert_lock(sdata);
1127
1128 WARN_ON(!sdata->vif.csa_active);
1129
1130 if (sdata->csa_block_tx) {
1131 ieee80211_wake_vif_queues(local, sdata,
1132 IEEE80211_QUEUE_STOP_REASON_CSA);
1133 sdata->csa_block_tx = false;
1134 }
1135
1136 sdata->vif.csa_active = false;
1137 ifmgd->csa_waiting_bcn = false;
1138
1139 ret = drv_post_channel_switch(sdata);
1140 if (ret) {
1141 sdata_info(sdata,
1142 "driver post channel switch failed, disconnecting\n");
1143 ieee80211_queue_work(&local->hw,
1144 &ifmgd->csa_connection_drop_work);
1145 return;
1146 }
Luciano Coelho688b1ec2014-12-16 16:01:39 +02001147
1148 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
Luciano Coelho0c21e632014-10-08 09:48:39 +03001149}
1150
Johannes Berg5ce6e432010-05-11 16:20:57 +02001151void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1152{
Johannes Berg55de9082012-07-26 17:24:39 +02001153 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1154 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001155
1156 trace_api_chswitch_done(sdata, success);
1157 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001158 sdata_info(sdata,
1159 "driver channel switch failed, disconnecting\n");
1160 ieee80211_queue_work(&sdata->local->hw,
1161 &ifmgd->csa_connection_drop_work);
1162 } else {
1163 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001164 }
Johannes Berg5ce6e432010-05-11 16:20:57 +02001165}
1166EXPORT_SYMBOL(ieee80211_chswitch_done);
1167
Kees Cook34f11cd2017-10-16 16:35:49 -07001168static void ieee80211_chswitch_timer(struct timer_list *t)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001169{
1170 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07001171 from_timer(sdata, t, u.mgd.chswitch_timer);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001172
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01001173 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001174}
1175
Johannes Berg37799e52013-03-26 14:02:26 +01001176static void
Johannes Berg4a3cb702013-02-12 16:43:19 +01001177ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03001178 u64 timestamp, u32 device_timestamp,
1179 struct ieee802_11_elems *elems,
Johannes Berg04a161f2013-05-03 09:35:35 +02001180 bool beacon)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001181{
Johannes Bergb4f286a12013-03-26 14:13:58 +01001182 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001183 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg37799e52013-03-26 14:02:26 +01001184 struct cfg80211_bss *cbss = ifmgd->associated;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001185 struct ieee80211_chanctx_conf *conf;
Johannes Berg55de9082012-07-26 17:24:39 +02001186 struct ieee80211_chanctx *chanctx;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001187 enum nl80211_band current_band;
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001188 struct ieee80211_csa_ie csa_ie;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001189 struct ieee80211_channel_switch ch_switch;
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001190 int res;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001191
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001192 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001193
Johannes Berg37799e52013-03-26 14:02:26 +01001194 if (!cbss)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001195 return;
1196
Johannes Bergb4f286a12013-03-26 14:13:58 +01001197 if (local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001198 return;
1199
Johannes Berg37799e52013-03-26 14:02:26 +01001200 /* disregard subsequent announcements if we are already processing */
Luciano Coelho3e2a0222014-07-05 11:43:01 +03001201 if (sdata->vif.csa_active)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001202 return;
1203
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001204 current_band = cbss->channel->band;
Luciano Coelho84469a42014-10-28 13:33:04 +02001205 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001206 ifmgd->flags,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001207 ifmgd->associated->bssid, &csa_ie);
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001208 if (res < 0)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001209 ieee80211_queue_work(&local->hw,
Johannes Berg882a7c62012-08-01 22:32:45 +02001210 &ifmgd->csa_connection_drop_work);
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001211 if (res)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001212 return;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001213
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001214 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
Johannes Berg85220d72013-03-25 18:29:27 +01001215 IEEE80211_CHAN_DISABLED)) {
1216 sdata_info(sdata,
1217 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001218 ifmgd->associated->bssid,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001219 csa_ie.chandef.chan->center_freq,
1220 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1221 csa_ie.chandef.center_freq2);
Johannes Berg85220d72013-03-25 18:29:27 +01001222 ieee80211_queue_work(&local->hw,
1223 &ifmgd->csa_connection_drop_work);
1224 return;
1225 }
1226
Johannes Bergf84eaa12015-03-12 08:53:26 +02001227 if (cfg80211_chandef_identical(&csa_ie.chandef,
1228 &sdata->vif.bss_conf.chandef)) {
1229 if (ifmgd->csa_ignored_same_chan)
1230 return;
1231 sdata_info(sdata,
1232 "AP %pM tries to chanswitch to same channel, ignore\n",
1233 ifmgd->associated->bssid);
1234 ifmgd->csa_ignored_same_chan = true;
1235 return;
1236 }
1237
Arik Nemtsovc5a71682015-05-19 14:36:48 +03001238 /*
1239 * Drop all TDLS peers - either we disconnect or move to a different
1240 * channel from this point on. There's no telling what our peer will do.
1241 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1242 * have an incompatible wider chandef.
1243 */
1244 ieee80211_teardown_tdls_peers(sdata);
1245
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001246 mutex_lock(&local->mtx);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001247 mutex_lock(&local->chanctx_mtx);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001248 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1249 lockdep_is_held(&local->chanctx_mtx));
1250 if (!conf) {
1251 sdata_info(sdata,
1252 "no channel context assigned to vif?, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001253 goto drop_connection;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001254 }
1255
1256 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1257
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001258 if (local->use_chanctx &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001259 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001260 sdata_info(sdata,
1261 "driver doesn't support chan-switch with channel contexts\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001262 goto drop_connection;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001263 }
1264
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001265 ch_switch.timestamp = timestamp;
1266 ch_switch.device_timestamp = device_timestamp;
1267 ch_switch.block_tx = csa_ie.mode;
1268 ch_switch.chandef = csa_ie.chandef;
1269 ch_switch.count = csa_ie.count;
1270
1271 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1272 sdata_info(sdata,
1273 "preparing for channel switch failed, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001274 goto drop_connection;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001275 }
1276
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001277 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1278 chanctx->mode, false);
1279 if (res) {
Johannes Berg55de9082012-07-26 17:24:39 +02001280 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001281 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1282 res);
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001283 goto drop_connection;
Johannes Berg55de9082012-07-26 17:24:39 +02001284 }
Johannes Bergb4f286a12013-03-26 14:13:58 +01001285 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001286
Michal Kazior59af6922014-04-09 15:10:59 +02001287 sdata->vif.csa_active = true;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001288 sdata->csa_chandef = csa_ie.chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02001289 sdata->csa_block_tx = csa_ie.mode;
Johannes Bergf84eaa12015-03-12 08:53:26 +02001290 ifmgd->csa_ignored_same_chan = false;
Michal Kazior59af6922014-04-09 15:10:59 +02001291
1292 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03001293 ieee80211_stop_vif_queues(local, sdata,
1294 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02001295 mutex_unlock(&local->mtx);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001296
Luciano Coelho2f457292014-11-07 14:31:36 +02001297 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1298 csa_ie.count);
1299
Johannes Bergb4f286a12013-03-26 14:13:58 +01001300 if (local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +02001301 /* use driver's channel switch callback */
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001302 drv_channel_switch(local, sdata, &ch_switch);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001303 return;
1304 }
1305
1306 /* channel switch handled in software */
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001307 if (csa_ie.count <= 1)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001308 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001309 else
Johannes Bergcc32abd2009-05-15 11:52:31 +02001310 mod_timer(&ifmgd->chswitch_timer,
Luciano Coelhoff1e4172014-10-28 13:33:05 +02001311 TU_TO_EXP_TIME((csa_ie.count - 1) *
1312 cbss->beacon_interval));
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001313 return;
1314 drop_connection:
1315 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1316 mutex_unlock(&local->chanctx_mtx);
1317 mutex_unlock(&local->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001318}
1319
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001320static bool
1321ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1322 struct ieee80211_channel *channel,
1323 const u8 *country_ie, u8 country_ie_len,
1324 const u8 *pwr_constr_elem,
1325 int *chan_pwr, int *pwr_reduction)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001326{
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001327 struct ieee80211_country_ie_triplet *triplet;
1328 int chan = ieee80211_frequency_to_channel(channel->center_freq);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001329 int i, chan_increment;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001330 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001331
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001332 /* Invalid IE */
1333 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001334 return false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001335
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001336 triplet = (void *)(country_ie + 3);
1337 country_ie_len -= 3;
1338
1339 switch (channel->band) {
1340 default:
1341 WARN_ON_ONCE(1);
1342 /* fall through */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001343 case NL80211_BAND_2GHZ:
1344 case NL80211_BAND_60GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001345 chan_increment = 1;
1346 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001347 case NL80211_BAND_5GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001348 chan_increment = 4;
1349 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001350 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001351
1352 /* find channel */
1353 while (country_ie_len >= 3) {
1354 u8 first_channel = triplet->chans.first_channel;
1355
1356 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1357 goto next;
1358
1359 for (i = 0; i < triplet->chans.num_channels; i++) {
1360 if (first_channel + i * chan_increment == chan) {
1361 have_chan_pwr = true;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001362 *chan_pwr = triplet->chans.max_power;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001363 break;
1364 }
1365 }
1366 if (have_chan_pwr)
1367 break;
1368
1369 next:
1370 triplet++;
1371 country_ie_len -= 3;
1372 }
1373
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001374 if (have_chan_pwr && pwr_constr_elem)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001375 *pwr_reduction = *pwr_constr_elem;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001376 else
1377 *pwr_reduction = 0;
1378
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001379 return have_chan_pwr;
1380}
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001381
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001382static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1383 struct ieee80211_channel *channel,
1384 const u8 *cisco_dtpc_ie,
1385 int *pwr_level)
1386{
1387 /* From practical testing, the first data byte of the DTPC element
1388 * seems to contain the requested dBm level, and the CLI on Cisco
1389 * APs clearly state the range is -127 to 127 dBm, which indicates
1390 * a signed byte, although it seemingly never actually goes negative.
1391 * The other byte seems to always be zero.
1392 */
1393 *pwr_level = (__s8)cisco_dtpc_ie[4];
1394}
1395
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001396static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1397 struct ieee80211_channel *channel,
1398 struct ieee80211_mgmt *mgmt,
1399 const u8 *country_ie, u8 country_ie_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001400 const u8 *pwr_constr_ie,
1401 const u8 *cisco_dtpc_ie)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001402{
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001403 bool has_80211h_pwr = false, has_cisco_pwr = false;
1404 int chan_pwr = 0, pwr_reduction_80211h = 0;
1405 int pwr_level_cisco, pwr_level_80211h;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001406 int new_ap_level;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001407 __le16 capab = mgmt->u.probe_resp.capab_info;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001408
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001409 if (country_ie &&
1410 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1411 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001412 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1413 sdata, channel, country_ie, country_ie_len,
1414 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001415 pwr_level_80211h =
1416 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001417 }
1418
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001419 if (cisco_dtpc_ie) {
1420 ieee80211_find_cisco_dtpc(
1421 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1422 has_cisco_pwr = true;
1423 }
1424
1425 if (!has_80211h_pwr && !has_cisco_pwr)
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001426 return 0;
1427
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001428 /* If we have both 802.11h and Cisco DTPC, apply both limits
1429 * by picking the smallest of the two power levels advertised.
1430 */
1431 if (has_80211h_pwr &&
1432 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
Johannes Berga87da0c2015-12-08 16:04:37 +02001433 new_ap_level = pwr_level_80211h;
1434
1435 if (sdata->ap_power_level == new_ap_level)
1436 return 0;
1437
John Linvillecef2fc12015-03-31 10:49:14 -04001438 sdata_dbg(sdata,
1439 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1440 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1441 sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001442 } else { /* has_cisco_pwr is always true here. */
Johannes Berga87da0c2015-12-08 16:04:37 +02001443 new_ap_level = pwr_level_cisco;
1444
1445 if (sdata->ap_power_level == new_ap_level)
1446 return 0;
1447
John Linvillecef2fc12015-03-31 10:49:14 -04001448 sdata_dbg(sdata,
1449 "Limiting TX power to %d dBm as advertised by %pM\n",
1450 pwr_level_cisco, sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001451 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001452
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001453 sdata->ap_power_level = new_ap_level;
1454 if (__ieee80211_recalc_txpower(sdata))
1455 return BSS_CHANGED_TXPOWER;
1456 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001457}
1458
Johannes Berg965beda2009-04-16 13:17:24 +02001459/* powersave */
1460static void ieee80211_enable_ps(struct ieee80211_local *local,
1461 struct ieee80211_sub_if_data *sdata)
1462{
1463 struct ieee80211_conf *conf = &local->hw.conf;
1464
Johannes Bergd5edaed2009-04-22 23:02:51 +02001465 /*
1466 * If we are scanning right now then the parameters will
1467 * take effect when scan finishes.
1468 */
Helmut Schaafbe9c422009-07-23 12:14:04 +02001469 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +02001470 return;
1471
Johannes Berg965beda2009-04-16 13:17:24 +02001472 if (conf->dynamic_ps_timeout > 0 &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001473 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001474 mod_timer(&local->dynamic_ps_timer, jiffies +
1475 msecs_to_jiffies(conf->dynamic_ps_timeout));
1476 } else {
Johannes Berg30686bf2015-06-02 21:39:54 +02001477 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
Johannes Berg076cdcb2015-09-24 16:14:55 +02001478 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajan375177b2010-02-09 14:50:28 +05301479
Johannes Berg30686bf2015-06-02 21:39:54 +02001480 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1481 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001482 return;
1483
1484 conf->flags |= IEEE80211_CONF_PS;
1485 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +02001486 }
1487}
1488
1489static void ieee80211_change_ps(struct ieee80211_local *local)
1490{
1491 struct ieee80211_conf *conf = &local->hw.conf;
1492
1493 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +02001494 ieee80211_enable_ps(local, local->ps_sdata);
1495 } else if (conf->flags & IEEE80211_CONF_PS) {
1496 conf->flags &= ~IEEE80211_CONF_PS;
1497 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1498 del_timer_sync(&local->dynamic_ps_timer);
1499 cancel_work_sync(&local->dynamic_ps_enable_work);
1500 }
1501}
1502
Jason Young808118c2011-03-10 16:43:19 -08001503static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1504{
1505 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1506 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001507 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001508
1509 if (!mgd->powersave)
1510 return false;
1511
Johannes Berg05cb9102011-10-28 11:59:47 +02001512 if (mgd->broken_ap)
1513 return false;
1514
Jason Young808118c2011-03-10 16:43:19 -08001515 if (!mgd->associated)
1516 return false;
1517
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001518 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
Jason Young808118c2011-03-10 16:43:19 -08001519 return false;
1520
Alexander Bondar989c6502013-05-16 17:34:17 +03001521 if (!mgd->have_beacon)
Alexander Bondarce857882013-05-06 17:17:04 +03001522 return false;
1523
Jason Young808118c2011-03-10 16:43:19 -08001524 rcu_read_lock();
1525 sta = sta_info_get(sdata, mgd->bssid);
1526 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001527 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001528 rcu_read_unlock();
1529
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001530 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001531}
1532
Johannes Berg965beda2009-04-16 13:17:24 +02001533/* need to hold RTNL or interface lock */
Johannes Berg4a733ef2015-10-14 18:02:43 +02001534void ieee80211_recalc_ps(struct ieee80211_local *local)
Johannes Berg965beda2009-04-16 13:17:24 +02001535{
1536 struct ieee80211_sub_if_data *sdata, *found = NULL;
1537 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001538 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001539
Johannes Berg30686bf2015-06-02 21:39:54 +02001540 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001541 local->ps_sdata = NULL;
1542 return;
1543 }
1544
1545 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01001546 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001547 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301548 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1549 /* If an AP vif is found, then disable PS
1550 * by setting the count to zero thereby setting
1551 * ps_sdata to NULL.
1552 */
1553 count = 0;
1554 break;
1555 }
Johannes Berg965beda2009-04-16 13:17:24 +02001556 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1557 continue;
1558 found = sdata;
1559 count++;
1560 }
1561
Jason Young808118c2011-03-10 16:43:19 -08001562 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg4a733ef2015-10-14 18:02:43 +02001563 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg10f644a2009-04-16 13:17:25 +02001564
Juuso Oikarinenff616382010-06-09 09:51:52 +03001565 timeout = local->dynamic_ps_forced_timeout;
Johannes Berg4a733ef2015-10-14 18:02:43 +02001566 if (timeout < 0)
1567 timeout = 100;
Johannes Berg09b85562013-02-06 23:07:41 +01001568 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001569
Johannes Berg4a733ef2015-10-14 18:02:43 +02001570 /* If the TIM IE is invalid, pretend the value is 1 */
1571 if (!dtimper)
1572 dtimper = 1;
Johannes Berg56007a02010-01-26 14:19:52 +01001573
Johannes Berg4a733ef2015-10-14 18:02:43 +02001574 local->hw.conf.ps_dtim_period = dtimper;
1575 local->ps_sdata = found;
Johannes Berg10f644a2009-04-16 13:17:25 +02001576 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001577 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001578 }
Johannes Berg965beda2009-04-16 13:17:24 +02001579
1580 ieee80211_change_ps(local);
1581}
1582
Eliad Pellerab095872012-07-27 12:33:22 +03001583void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1584{
1585 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1586
1587 if (sdata->vif.bss_conf.ps != ps_allowed) {
1588 sdata->vif.bss_conf.ps = ps_allowed;
1589 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1590 }
1591}
1592
Johannes Berg965beda2009-04-16 13:17:24 +02001593void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1594{
1595 struct ieee80211_local *local =
1596 container_of(work, struct ieee80211_local,
1597 dynamic_ps_disable_work);
1598
1599 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1600 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1601 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1602 }
1603
1604 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001605 IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +03001606 IEEE80211_QUEUE_STOP_REASON_PS,
1607 false);
Johannes Berg965beda2009-04-16 13:17:24 +02001608}
1609
1610void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1611{
1612 struct ieee80211_local *local =
1613 container_of(work, struct ieee80211_local,
1614 dynamic_ps_enable_work);
1615 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001616 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301617 unsigned long flags;
1618 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001619
1620 /* can only happen when PS was just disabled anyway */
1621 if (!sdata)
1622 return;
1623
Christian Lamparter5e340692011-06-30 21:08:43 +02001624 ifmgd = &sdata->u.mgd;
1625
Johannes Berg965beda2009-04-16 13:17:24 +02001626 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1627 return;
1628
Johannes Berg09b85562013-02-06 23:07:41 +01001629 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001630 /* don't enter PS if TX frames are pending */
1631 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301632 mod_timer(&local->dynamic_ps_timer, jiffies +
1633 msecs_to_jiffies(
1634 local->hw.conf.dynamic_ps_timeout));
1635 return;
1636 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001637
1638 /*
1639 * transmission can be stopped by others which leads to
1640 * dynamic_ps_timer expiry. Postpone the ps timer if it
1641 * is not the actual idle state.
1642 */
1643 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1644 for (q = 0; q < local->hw.queues; q++) {
1645 if (local->queue_stop_reasons[q]) {
1646 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1647 flags);
1648 mod_timer(&local->dynamic_ps_timer, jiffies +
1649 msecs_to_jiffies(
1650 local->hw.conf.dynamic_ps_timeout));
1651 return;
1652 }
1653 }
1654 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301655 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301656
Johannes Berg30686bf2015-06-02 21:39:54 +02001657 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301658 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Johannes Berga1598382013-03-26 22:02:42 +01001659 if (drv_tx_frames_pending(local)) {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301660 mod_timer(&local->dynamic_ps_timer, jiffies +
1661 msecs_to_jiffies(
1662 local->hw.conf.dynamic_ps_timeout));
Johannes Berga1598382013-03-26 22:02:42 +01001663 } else {
Johannes Berg076cdcb2015-09-24 16:14:55 +02001664 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301665 /* Flush to get the tx status of nullfunc frame */
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001666 ieee80211_flush_queues(local, sdata, false);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301667 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301668 }
1669
Johannes Berg30686bf2015-06-02 21:39:54 +02001670 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1671 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301672 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1673 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1674 local->hw.conf.flags |= IEEE80211_CONF_PS;
1675 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1676 }
Johannes Berg965beda2009-04-16 13:17:24 +02001677}
1678
Kees Cook34f11cd2017-10-16 16:35:49 -07001679void ieee80211_dynamic_ps_timer(struct timer_list *t)
Johannes Berg965beda2009-04-16 13:17:24 +02001680{
Kees Cook34f11cd2017-10-16 16:35:49 -07001681 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
Johannes Berg965beda2009-04-16 13:17:24 +02001682
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001683 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001684}
1685
Simon Wunderlich164eb022013-02-08 18:16:20 +01001686void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1687{
Geliang Tanga85a7e22016-01-01 23:48:52 +08001688 struct delayed_work *delayed_work = to_delayed_work(work);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001689 struct ieee80211_sub_if_data *sdata =
1690 container_of(delayed_work, struct ieee80211_sub_if_data,
1691 dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001692 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlich164eb022013-02-08 18:16:20 +01001693
Johannes Berg34a37402013-12-18 09:43:33 +01001694 mutex_lock(&sdata->local->mtx);
1695 if (sdata->wdev.cac_started) {
1696 ieee80211_vif_release_channel(sdata);
1697 cfg80211_cac_event(sdata->dev, &chandef,
1698 NL80211_RADAR_CAC_FINISHED,
1699 GFP_KERNEL);
1700 }
1701 mutex_unlock(&sdata->local->mtx);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001702}
1703
Johannes Berg02219b32014-10-07 10:38:50 +03001704static bool
1705__ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1706{
1707 struct ieee80211_local *local = sdata->local;
1708 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
John Linvillecc72f6e2015-01-06 14:39:33 -05001709 bool ret = false;
Johannes Berg02219b32014-10-07 10:38:50 +03001710 int ac;
1711
1712 if (local->hw.queues < IEEE80211_NUM_ACS)
1713 return false;
1714
1715 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1716 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1717 int non_acm_ac;
1718 unsigned long now = jiffies;
1719
1720 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1721 tx_tspec->admitted_time &&
1722 time_after(now, tx_tspec->time_slice_start + HZ)) {
1723 tx_tspec->consumed_tx_time = 0;
1724 tx_tspec->time_slice_start = now;
1725
1726 if (tx_tspec->downgraded)
1727 tx_tspec->action =
1728 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1729 }
1730
1731 switch (tx_tspec->action) {
1732 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1733 /* take the original parameters */
1734 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1735 sdata_err(sdata,
1736 "failed to set TX queue parameters for queue %d\n",
1737 ac);
1738 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1739 tx_tspec->downgraded = false;
1740 ret = true;
1741 break;
1742 case TX_TSPEC_ACTION_DOWNGRADE:
1743 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1744 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1745 ret = true;
1746 break;
1747 }
1748 /* downgrade next lower non-ACM AC */
1749 for (non_acm_ac = ac + 1;
1750 non_acm_ac < IEEE80211_NUM_ACS;
1751 non_acm_ac++)
1752 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1753 break;
Johannes Berg93db1d92016-09-14 09:23:51 +02001754 /* Usually the loop will result in using BK even if it
1755 * requires admission control, but such a configuration
1756 * makes no sense and we have to transmit somehow - the
1757 * AC selection does the same thing.
1758 * If we started out trying to downgrade from BK, then
1759 * the extra condition here might be needed.
Johannes Berg02219b32014-10-07 10:38:50 +03001760 */
Johannes Berg93db1d92016-09-14 09:23:51 +02001761 if (non_acm_ac >= IEEE80211_NUM_ACS)
1762 non_acm_ac = IEEE80211_AC_BK;
Johannes Berg02219b32014-10-07 10:38:50 +03001763 if (drv_conf_tx(local, sdata, ac,
1764 &sdata->tx_conf[non_acm_ac]))
1765 sdata_err(sdata,
1766 "failed to set TX queue parameters for queue %d\n",
1767 ac);
1768 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1769 ret = true;
1770 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1771 tx_tspec->time_slice_start + HZ - now + 1);
1772 break;
1773 case TX_TSPEC_ACTION_NONE:
1774 /* nothing now */
1775 break;
1776 }
1777 }
1778
1779 return ret;
1780}
1781
1782void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1783{
1784 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1785 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1786}
1787
1788static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1789{
1790 struct ieee80211_sub_if_data *sdata;
1791
1792 sdata = container_of(work, struct ieee80211_sub_if_data,
1793 u.mgd.tx_tspec_wk.work);
1794 ieee80211_sta_handle_tspec_ac_params(sdata);
1795}
1796
Johannes Berg60f8b392008-09-08 17:44:22 +02001797/* MLME */
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001798static bool
1799ieee80211_sta_wmm_params(struct ieee80211_local *local,
1800 struct ieee80211_sub_if_data *sdata,
1801 const u8 *wmm_param, size_t wmm_param_len,
1802 const struct ieee80211_mu_edca_param_set *mu_edca)
Jiri Bencf0706e82007-05-05 11:45:53 -07001803{
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001804 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
Johannes Berg4ced3f72010-07-19 16:39:04 +02001805 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001806 size_t left;
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001807 int count, ac;
Johannes Berg4a3cb702013-02-12 16:43:19 +01001808 const u8 *pos;
1809 u8 uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001810
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001811 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001812 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001813
Johannes Berg32c50572012-03-28 11:04:29 +02001814 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001815 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001816
1817 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001818 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001819
Jiri Bencf0706e82007-05-05 11:45:53 -07001820 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001821 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001822
1823 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001824 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001825
Jiri Bencf0706e82007-05-05 11:45:53 -07001826 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +01001827 if (count == ifmgd->wmm_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001828 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001829 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001830
1831 pos = wmm_param + 8;
1832 left = wmm_param_len - 8;
1833
1834 memset(&params, 0, sizeof(params));
1835
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001836 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001837 for (; left >= 4; left -= 4, pos += 4) {
1838 int aci = (pos[0] >> 5) & 0x03;
1839 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001840 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001841
1842 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001843 case 1: /* AC_BK */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001844 ac = IEEE80211_AC_BK;
Johannes Berg988c0f72008-04-17 19:21:22 +02001845 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001846 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001847 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1848 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001849 params[ac].mu_edca = !!mu_edca;
1850 if (mu_edca)
1851 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
Jiri Bencf0706e82007-05-05 11:45:53 -07001852 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001853 case 2: /* AC_VI */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001854 ac = IEEE80211_AC_VI;
Johannes Berg988c0f72008-04-17 19:21:22 +02001855 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001856 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001857 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1858 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001859 params[ac].mu_edca = !!mu_edca;
1860 if (mu_edca)
1861 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
Jiri Bencf0706e82007-05-05 11:45:53 -07001862 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001863 case 3: /* AC_VO */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001864 ac = IEEE80211_AC_VO;
Johannes Berg988c0f72008-04-17 19:21:22 +02001865 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001866 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02001867 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1868 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001869 params[ac].mu_edca = !!mu_edca;
1870 if (mu_edca)
1871 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
Jiri Bencf0706e82007-05-05 11:45:53 -07001872 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001873 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001874 default:
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001875 ac = IEEE80211_AC_BE;
Johannes Berg988c0f72008-04-17 19:21:22 +02001876 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001877 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02001878 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1879 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001880 params[ac].mu_edca = !!mu_edca;
1881 if (mu_edca)
1882 params[ac].mu_edca_param_rec = mu_edca->ac_be;
Jiri Bencf0706e82007-05-05 11:45:53 -07001883 break;
1884 }
1885
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001886 params[ac].aifs = pos[0] & 0x0f;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001887
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001888 if (params[ac].aifs < 2) {
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001889 sdata_info(sdata,
1890 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001891 params[ac].aifs, aci);
1892 params[ac].aifs = 2;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001893 }
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001894 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1895 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
1896 params[ac].txop = get_unaligned_le16(pos + 2);
1897 params[ac].acm = acm;
1898 params[ac].uapsd = uapsd;
Kalle Valoab133152010-01-12 10:42:31 +02001899
Ilan Peer911a2642018-04-03 11:35:22 +03001900 if (params[ac].cw_min == 0 ||
Emmanuel Grumbachc470bdc2018-03-26 16:21:04 +03001901 params[ac].cw_min > params[ac].cw_max) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001902 sdata_info(sdata,
1903 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
1904 params[ac].cw_min, params[ac].cw_max, aci);
1905 return false;
1906 }
Haim Dreyfusse552af02018-03-28 13:24:10 +03001907 ieee80211_regulatory_limit_wmm_params(sdata, &params[ac], ac);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001908 }
1909
1910 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001911 mlme_dbg(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001912 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
1913 ac, params[ac].acm,
1914 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
1915 params[ac].txop, params[ac].uapsd,
1916 ifmgd->tx_tspec[ac].downgraded);
1917 sdata->tx_conf[ac] = params[ac];
1918 if (!ifmgd->tx_tspec[ac].downgraded &&
1919 drv_conf_tx(local, sdata, ac, &params[ac]))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001920 sdata_err(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001921 "failed to set TX queue parameters for AC %d\n",
1922 ac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001923 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001924
1925 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02001926 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02001927 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001928}
1929
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001930static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1931{
1932 lockdep_assert_held(&sdata->local->mtx);
1933
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001934 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001935 ieee80211_run_deferred_scan(sdata->local);
1936}
1937
1938static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1939{
1940 mutex_lock(&sdata->local->mtx);
1941 __ieee80211_stop_poll(sdata);
1942 mutex_unlock(&sdata->local->mtx);
1943}
1944
Johannes Berg7a5158e2008-10-08 10:59:33 +02001945static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1946 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02001947{
Johannes Bergbda39332008-10-11 01:51:51 +02001948 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301949 struct ieee80211_supported_band *sband;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001950 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001951 bool use_protection;
1952 bool use_short_preamble;
1953 bool use_short_slot;
1954
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301955 sband = ieee80211_get_sband(sdata);
1956 if (!sband)
1957 return changed;
1958
Johannes Berg7a5158e2008-10-08 10:59:33 +02001959 if (erp_valid) {
1960 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1961 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1962 } else {
1963 use_protection = false;
1964 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1965 }
1966
1967 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301968 if (sband->band == NL80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01001969 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02001970
Johannes Berg471b3ef2007-12-28 14:32:58 +01001971 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01001972 bss_conf->use_cts_prot = use_protection;
1973 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02001974 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02001975
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001976 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001977 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001978 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02001979 }
Daniel Draked9430a32007-07-27 15:43:24 +02001980
Johannes Berg7a5158e2008-10-08 10:59:33 +02001981 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02001982 bss_conf->use_short_slot = use_short_slot;
1983 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04001984 }
1985
1986 return changed;
1987}
1988
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001989static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001990 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02001991 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07001992{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001993 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001994 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001995 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001996
Johannes Bergae5eb022008-10-14 16:58:37 +02001997 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001998 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03001999 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002000
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002001 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
Ben Greear59c1ec22013-03-19 14:19:56 -07002002 beacon_loss_count * bss_conf->beacon_int));
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002003
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002004 sdata->u.mgd.associated = cbss;
2005 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002006
Johannes Berge8e4f522017-03-08 11:12:10 +01002007 ieee80211_check_rate_mask(sdata);
2008
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002009 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2010
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01002011 if (sdata->vif.p2p ||
2012 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002013 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01002014
Johannes Berg9caf0362012-11-29 01:25:20 +01002015 rcu_read_lock();
2016 ies = rcu_dereference(cbss->ies);
2017 if (ies) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002018 int ret;
2019
2020 ret = cfg80211_get_p2p_attr(
2021 ies->data, ies->len,
2022 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002023 (u8 *) &bss_conf->p2p_noa_attr,
2024 sizeof(bss_conf->p2p_noa_attr));
Johannes Berg9caf0362012-11-29 01:25:20 +01002025 if (ret >= 2) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002026 sdata->u.mgd.p2p_noa_index =
2027 bss_conf->p2p_noa_attr.index;
Johannes Berg9caf0362012-11-29 01:25:20 +01002028 bss_info_changed |= BSS_CHANGED_P2P_PS;
Johannes Berg9caf0362012-11-29 01:25:20 +01002029 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01002030 }
Johannes Berg9caf0362012-11-29 01:25:20 +01002031 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01002032 }
2033
Johannes Bergb291ba12009-07-10 15:29:03 +02002034 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002035 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002036
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002037 ieee80211_led_assoc(local, 1);
2038
Alexander Bondar989c6502013-05-16 17:34:17 +03002039 if (sdata->u.mgd.have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02002040 /*
2041 * If the AP is buggy we may get here with no DTIM period
2042 * known, so assume it's 1 which is the only safe assumption
2043 * in that case, although if the TIM IE is broken powersave
2044 * probably just won't work at all.
2045 */
2046 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Alexander Bondar817cee72013-05-19 14:23:57 +03002047 bss_conf->beacon_rate = bss->beacon_rate;
Alexander Bondar989c6502013-05-16 17:34:17 +03002048 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
Johannes Berg826262c2012-12-10 16:38:14 +02002049 } else {
Alexander Bondar817cee72013-05-19 14:23:57 +03002050 bss_conf->beacon_rate = NULL;
Johannes Berge5b900d2010-07-29 16:08:55 +02002051 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02002052 }
Johannes Berge5b900d2010-07-29 16:08:55 +02002053
Juuso Oikarinen68542962010-06-09 13:43:26 +03002054 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02002055
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002056 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01002057 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03002058 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002059 bss_info_changed |= BSS_CHANGED_CQM;
2060
Juuso Oikarinen68542962010-06-09 13:43:26 +03002061 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002062 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002063 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002064
Johannes Bergae5eb022008-10-14 16:58:37 +02002065 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03002066
Johannes Berg056508d2009-07-30 21:43:55 +02002067 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002068 ieee80211_recalc_ps(local);
Johannes Berg056508d2009-07-30 21:43:55 +02002069 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02002070
Johannes Berg04ecd252012-09-11 14:34:12 +02002071 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03002072 ieee80211_recalc_ps_vif(sdata);
2073
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002074 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07002075}
2076
Jouni Malinene69e95d2010-03-29 23:29:31 -07002077static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01002078 u16 stype, u16 reason, bool tx,
2079 u8 *frame_buf)
Tomas Winkleraa458d172008-09-09 00:32:12 +03002080{
Johannes Berg46900292009-02-15 12:44:28 +01002081 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d172008-09-09 00:32:12 +03002082 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01002083 u32 changed = 0;
Tomas Winkleraa458d172008-09-09 00:32:12 +03002084
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002085 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002086
Johannes Berg37ad3882012-02-24 13:50:54 +01002087 if (WARN_ON_ONCE(tx && !frame_buf))
2088 return;
2089
Johannes Bergb291ba12009-07-10 15:29:03 +02002090 if (WARN_ON(!ifmgd->associated))
2091 return;
2092
David Spinadel79543d82012-06-12 09:59:45 +03002093 ieee80211_stop_poll(sdata);
2094
Johannes Berg77fdaa12009-07-07 03:45:17 +02002095 ifmgd->associated = NULL;
Tomas Winkleraa458d172008-09-09 00:32:12 +03002096 netif_carrier_off(sdata->dev);
2097
Eliad Peller88bc40e2012-07-12 17:35:33 +03002098 /*
2099 * if we want to get out of ps before disassoc (why?) we have
2100 * to do it before sending disassoc, as otherwise the null-packet
2101 * won't be valid.
2102 */
2103 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2104 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2105 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2106 }
2107 local->ps_sdata = NULL;
2108
Eliad Pellerab095872012-07-27 12:33:22 +03002109 /* disable per-vif ps */
2110 ieee80211_recalc_ps_vif(sdata);
2111
Emmanuel Grumbach14f2ae82015-01-22 23:30:19 +02002112 /* make sure ongoing transmission finishes */
2113 synchronize_net();
2114
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002115 /*
2116 * drop any frame before deauth/disassoc, this can be data or
2117 * management frame. Since we are disconnecting, we should not
2118 * insist sending these frames which can take time and delay
2119 * the disconnection and possible the roaming.
2120 */
Eliad Pellerf8239812012-06-27 14:18:22 +03002121 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002122 ieee80211_flush_queues(local, sdata, true);
Eliad Pellerf8239812012-06-27 14:18:22 +03002123
Johannes Berg37ad3882012-02-24 13:50:54 +01002124 /* deauthenticate/disassociate now */
Ilan Peer94ba9272018-02-19 14:48:41 +02002125 if (tx || frame_buf) {
Ilan Peer94ba9272018-02-19 14:48:41 +02002126 /*
2127 * In multi channel scenarios guarantee that the virtual
2128 * interface is granted immediate airtime to transmit the
2129 * deauthentication frame by calling mgd_prepare_tx, if the
2130 * driver requested so.
2131 */
2132 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2133 !ifmgd->have_beacon)
Ilan Peerd4e36e52018-04-20 13:49:25 +03002134 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Ilan Peer94ba9272018-02-19 14:48:41 +02002135
Eliad Peller88a9e312012-06-01 11:14:03 +03002136 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
2137 reason, tx, frame_buf);
Ilan Peer94ba9272018-02-19 14:48:41 +02002138 }
Johannes Berg37ad3882012-02-24 13:50:54 +01002139
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002140 /* flush out frame - make sure the deauth was actually sent */
Johannes Berg37ad3882012-02-24 13:50:54 +01002141 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002142 ieee80211_flush_queues(local, sdata, false);
Johannes Berg37ad3882012-02-24 13:50:54 +01002143
Eliad Peller88a9e312012-06-01 11:14:03 +03002144 /* clear bssid only after building the needed mgmt frames */
Joe Perchesc84a67a2015-03-02 19:54:57 -08002145 eth_zero_addr(ifmgd->bssid);
Eliad Peller88a9e312012-06-01 11:14:03 +03002146
Johannes Berg37ad3882012-02-24 13:50:54 +01002147 /* remove AP and TDLS peers */
Johannes Bergd34ba212013-12-04 22:46:11 +01002148 sta_info_flush(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01002149
2150 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002151 changed |= ieee80211_reset_erp_info(sdata);
2152
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002153 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02002154 changed |= BSS_CHANGED_ASSOC;
2155 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002156
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002157 ifmgd->p2p_noa_index = -1;
2158 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2159 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01002160
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002161 /* on the next assoc, re-program HT/VHT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08002162 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2163 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002164 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2165 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
Sara Sharon23a1f8d2015-12-08 16:04:31 +02002166
2167 /* reset MU-MIMO ownership and group data */
2168 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2169 sizeof(sdata->vif.bss_conf.mu_group.membership));
2170 memset(sdata->vif.bss_conf.mu_group.position, 0,
2171 sizeof(sdata->vif.bss_conf.mu_group.position));
2172 changed |= BSS_CHANGED_MU_GROUPS;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002173 sdata->vif.mu_mimo_owner = false;
Johannes Berg413ad502009-05-08 21:21:06 +02002174
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002175 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05302176
Kalle Valo520eb822008-12-18 23:35:27 +02002177 del_timer_sync(&local->dynamic_ps_timer);
2178 cancel_work_sync(&local->dynamic_ps_enable_work);
2179
Juuso Oikarinen68542962010-06-09 13:43:26 +03002180 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002181 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002182 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002183
Johannes Berg3abead52012-03-02 15:56:59 +01002184 sdata->vif.bss_conf.qos = false;
2185 changed |= BSS_CHANGED_QOS;
2186
Johannes Berg0aaffa92010-05-05 15:28:27 +02002187 /* The BSSID (not really interesting) and HT changed */
2188 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02002189 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02002190
Johannes Berg3abead52012-03-02 15:56:59 +01002191 /* disassociated - set to defaults now */
Johannes Bergcec66282015-10-22 17:46:04 +02002192 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg3abead52012-03-02 15:56:59 +01002193
Johannes Bergb9dcf712010-08-27 12:35:54 +02002194 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2195 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2196 del_timer_sync(&sdata->u.mgd.timer);
2197 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02002198
Johannes Berg826262c2012-12-10 16:38:14 +02002199 sdata->vif.bss_conf.dtim_period = 0;
Alexander Bondar817cee72013-05-19 14:23:57 +03002200 sdata->vif.bss_conf.beacon_rate = NULL;
2201
Alexander Bondar989c6502013-05-16 17:34:17 +03002202 ifmgd->have_beacon = false;
Johannes Berg826262c2012-12-10 16:38:14 +02002203
Johannes Berg028e8da02012-11-26 11:57:41 +01002204 ifmgd->flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002205 mutex_lock(&local->mtx);
Johannes Berg028e8da02012-11-26 11:57:41 +01002206 ieee80211_vif_release_channel(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002207
2208 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002209 ifmgd->csa_waiting_bcn = false;
Johannes Bergf84eaa12015-03-12 08:53:26 +02002210 ifmgd->csa_ignored_same_chan = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002211 if (sdata->csa_block_tx) {
2212 ieee80211_wake_vif_queues(local, sdata,
2213 IEEE80211_QUEUE_STOP_REASON_CSA);
2214 sdata->csa_block_tx = false;
2215 }
Johannes Berg34a37402013-12-18 09:43:33 +01002216 mutex_unlock(&local->mtx);
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002217
Johannes Berg02219b32014-10-07 10:38:50 +03002218 /* existing TX TSPEC sessions no longer exist */
2219 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2220 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2221
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002222 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
Tomas Winkleraa458d172008-09-09 00:32:12 +03002223}
Jiri Bencf0706e82007-05-05 11:45:53 -07002224
Kalle Valo3cf335d2009-03-22 21:57:06 +02002225void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2226 struct ieee80211_hdr *hdr)
2227{
2228 /*
2229 * We can postpone the mgd.timer whenever receiving unicast frames
2230 * from AP because we know that the connection is working both ways
2231 * at that time. But multicast frames (and hence also beacons) must
2232 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02002233 * data idle periods for sending the periodic probe request to the
2234 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02002235 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002236 if (is_multicast_ether_addr(hdr->addr1))
2237 return;
2238
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04002239 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02002240}
Jiri Bencf0706e82007-05-05 11:45:53 -07002241
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002242static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2243{
2244 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002245 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002246
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002247 mutex_lock(&local->mtx);
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002248 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2249 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002250
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002251 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002252
2253 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002254 ieee80211_recalc_ps(local);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002255 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002256
Johannes Berg30686bf2015-06-02 21:39:54 +02002257 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002258 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002259
2260 /*
2261 * We've received a probe response, but are not sure whether
2262 * we have or will be receiving any beacons or data, so let's
2263 * schedule the timers again, just in case.
2264 */
2265 ieee80211_sta_reset_beacon_monitor(sdata);
2266
2267 mod_timer(&ifmgd->conn_mon_timer,
2268 round_jiffies_up(jiffies +
2269 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002270out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002271 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002272}
2273
Johannes Berg02219b32014-10-07 10:38:50 +03002274static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2275 struct ieee80211_hdr *hdr,
2276 u16 tx_time)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002277{
Johannes Berg02219b32014-10-07 10:38:50 +03002278 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Sara Sharona1f2ba04c2018-02-19 14:48:40 +02002279 u16 tid = ieee80211_get_tid(hdr);
Johannes Berg02219b32014-10-07 10:38:50 +03002280 int ac = ieee80211_ac_from_tid(tid);
2281 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2282 unsigned long now = jiffies;
2283
2284 if (likely(!tx_tspec->admitted_time))
2285 return;
2286
2287 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2288 tx_tspec->consumed_tx_time = 0;
2289 tx_tspec->time_slice_start = now;
2290
2291 if (tx_tspec->downgraded) {
2292 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2293 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2294 }
2295 }
2296
2297 if (tx_tspec->downgraded)
2298 return;
2299
2300 tx_tspec->consumed_tx_time += tx_time;
2301
2302 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2303 tx_tspec->downgraded = true;
2304 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2305 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2306 }
2307}
2308
2309void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2310 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2311{
2312 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2313
Felix Fietkau75706d02010-12-02 21:01:07 +01002314 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002315 return;
2316
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002317 if (ieee80211_is_nullfunc(hdr->frame_control) &&
2318 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002319 if (ack)
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002320 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002321 else
2322 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002323 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002324 return;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002325 }
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002326
2327 if (ack)
2328 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002329}
2330
Johannes Berg45ad6832018-05-28 15:47:39 +02002331static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2332 const u8 *src, const u8 *dst,
2333 const u8 *ssid, size_t ssid_len,
2334 struct ieee80211_channel *channel)
2335{
2336 struct sk_buff *skb;
2337
2338 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2339 ssid, ssid_len, NULL, 0,
2340 IEEE80211_PROBE_FLAG_DIRECTED);
2341 if (skb)
2342 ieee80211_tx_skb(sdata, skb);
2343}
2344
Maxim Levitskya43abf22009-07-31 18:54:12 +03002345static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2346{
2347 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2348 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002349 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08002350 u8 unicast_limit = max(1, max_probe_tries - 3);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002351 struct sta_info *sta;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002352
2353 /*
2354 * Try sending broadcast probe requests for the last three
2355 * probe requests after the first ones failed since some
2356 * buggy APs only support broadcast probe requests.
2357 */
2358 if (ifmgd->probe_send_count >= unicast_limit)
2359 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002360
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002361 /*
2362 * When the hardware reports an accurate Tx ACK status, it's
2363 * better to send a nullfunc frame instead of a probe request,
2364 * as it will kick us off the AP quickly if we aren't associated
2365 * anymore. The timeout will be reset if the frame is ACKed by
2366 * the AP.
2367 */
Soumik Das992e68b2012-05-20 15:31:13 +05302368 ifmgd->probe_send_count++;
2369
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002370 if (dst) {
2371 mutex_lock(&sdata->local->sta_mtx);
2372 sta = sta_info_get(sdata, dst);
2373 if (!WARN_ON(!sta))
2374 ieee80211_check_fast_rx(sta);
2375 mutex_unlock(&sdata->local->sta_mtx);
2376 }
2377
Johannes Berg30686bf2015-06-02 21:39:54 +02002378 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002379 ifmgd->nullfunc_failed = false;
Johannes Berg076cdcb2015-09-24 16:14:55 +02002380 ieee80211_send_nullfunc(sdata->local, sdata, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002381 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002382 int ssid_len;
2383
Johannes Berg9caf0362012-11-29 01:25:20 +01002384 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002385 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002386 if (WARN_ON_ONCE(ssid == NULL))
2387 ssid_len = 0;
2388 else
2389 ssid_len = ssid[1];
2390
Johannes Berg45ad6832018-05-28 15:47:39 +02002391 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2392 ssid + 2, ssid_len,
2393 ifmgd->associated->channel);
Johannes Berg9caf0362012-11-29 01:25:20 +01002394 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002395 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03002396
Ben Greear180205b2011-02-04 15:30:24 -08002397 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002398 run_again(sdata, ifmgd->probe_timeout);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002399}
2400
Johannes Bergb291ba12009-07-10 15:29:03 +02002401static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2402 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02002403{
Kalle Valo04de8382009-03-22 21:57:35 +02002404 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002405 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02002406
Johannes Berg9607e6b2009-12-23 13:15:31 +01002407 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02002408 return;
2409
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002410 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002411
2412 if (!ifmgd->associated)
2413 goto out;
2414
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002415 mutex_lock(&sdata->local->mtx);
2416
2417 if (sdata->local->tmp_channel || sdata->local->scanning) {
2418 mutex_unlock(&sdata->local->mtx);
2419 goto out;
2420 }
2421
Ben Greeara13fbe52013-03-25 11:19:35 -07002422 if (beacon) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002423 mlme_dbg_ratelimited(sdata,
Ben Greear59c1ec22013-03-19 14:19:56 -07002424 "detected beacon loss from AP (missed %d beacons) - probing\n",
2425 beacon_loss_count);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002426
Johannes Berg98f03342014-11-26 12:42:02 +01002427 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
Ben Greeara13fbe52013-03-25 11:19:35 -07002428 }
Kalle Valo04de8382009-03-22 21:57:35 +02002429
Johannes Bergb291ba12009-07-10 15:29:03 +02002430 /*
2431 * The driver/our work has already reported this event or the
2432 * connection monitoring has kicked in and we have already sent
2433 * a probe request. Or maybe the AP died and the driver keeps
2434 * reporting until we disassociate...
2435 *
2436 * In either case we have to ignore the current call to this
2437 * function (except for setting the correct probe reason bit)
2438 * because otherwise we would reset the timer every time and
2439 * never check whether we received a probe response!
2440 */
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002441 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Johannes Bergb291ba12009-07-10 15:29:03 +02002442 already = true;
2443
Eliad Peller12b5f342013-11-18 19:06:46 +02002444 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2445
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002446 mutex_unlock(&sdata->local->mtx);
2447
Johannes Bergb291ba12009-07-10 15:29:03 +02002448 if (already)
2449 goto out;
2450
Johannes Berg4e751842009-06-10 15:16:52 +02002451 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002452 ieee80211_recalc_ps(sdata->local);
Johannes Berg4e751842009-06-10 15:16:52 +02002453 mutex_unlock(&sdata->local->iflist_mtx);
2454
Maxim Levitskya43abf22009-07-31 18:54:12 +03002455 ifmgd->probe_send_count = 0;
2456 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002457 out:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002458 sdata_unlock(sdata);
Kalle Valo04de8382009-03-22 21:57:35 +02002459}
2460
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002461struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2462 struct ieee80211_vif *vif)
2463{
2464 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2465 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002466 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002467 struct sk_buff *skb;
2468 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002469 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002470
2471 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2472 return NULL;
2473
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002474 sdata_assert_lock(sdata);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002475
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002476 if (ifmgd->associated)
2477 cbss = ifmgd->associated;
2478 else if (ifmgd->auth_data)
2479 cbss = ifmgd->auth_data->bss;
2480 else if (ifmgd->assoc_data)
2481 cbss = ifmgd->assoc_data->bss;
2482 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002483 return NULL;
2484
Johannes Berg9caf0362012-11-29 01:25:20 +01002485 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002486 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002487 if (WARN_ON_ONCE(ssid == NULL))
2488 ssid_len = 0;
2489 else
2490 ssid_len = ssid[1];
2491
Johannes Berga344d672014-06-12 22:24:31 +02002492 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02002493 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02002494 ssid + 2, ssid_len,
Johannes Berg00387f32018-05-28 15:47:38 +02002495 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
Johannes Berg9caf0362012-11-29 01:25:20 +01002496 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002497
2498 return skb;
2499}
2500EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2501
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002502static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2503 const u8 *buf, size_t len, bool tx,
2504 u16 reason)
2505{
2506 struct ieee80211_event event = {
2507 .type = MLME_EVENT,
2508 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2509 .u.mlme.reason = reason,
2510 };
2511
2512 if (tx)
2513 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2514 else
2515 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2516
2517 drv_event_callback(sdata->local, sdata, &event);
2518}
2519
Johannes Bergeef9e542013-01-29 13:09:34 +01002520static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002521{
Michal Kazior59af6922014-04-09 15:10:59 +02002522 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002523 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002524 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002525
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002526 sdata_lock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002527 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002528 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002529 return;
2530 }
2531
David Spinadel20eb7ea2016-05-03 16:05:02 +03002532 /* AP is probably out of range (or not reachable for another reason) so
2533 * remove the bss struct for that AP.
2534 */
2535 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2536
Johannes Berg37ad3882012-02-24 13:50:54 +01002537 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2538 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Johannes Bergeef9e542013-01-29 13:09:34 +01002539 true, frame_buf);
Michal Kazior59af6922014-04-09 15:10:59 +02002540 mutex_lock(&local->mtx);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002541 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002542 ifmgd->csa_waiting_bcn = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002543 if (sdata->csa_block_tx) {
2544 ieee80211_wake_vif_queues(local, sdata,
2545 IEEE80211_QUEUE_STOP_REASON_CSA);
2546 sdata->csa_block_tx = false;
2547 }
Michal Kazior59af6922014-04-09 15:10:59 +02002548 mutex_unlock(&local->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002549
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002550 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
2551 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2552
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002553 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002554}
2555
Johannes Bergcc74c0c2012-08-01 16:49:34 +02002556static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02002557{
2558 struct ieee80211_sub_if_data *sdata =
2559 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002560 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002561 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Paul Stewarta85e1d52011-12-09 11:01:49 -08002562
Johannes Berg976bd9e2015-10-16 17:18:11 +02002563 if (ifmgd->associated)
2564 ifmgd->beacon_loss_count++;
Johannes Bergb291ba12009-07-10 15:29:03 +02002565
Johannes Berg682bd382013-01-29 13:13:50 +01002566 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02002567 sdata_info(sdata, "Connection to AP %pM lost\n",
2568 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01002569 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02002570 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002571 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02002572 }
2573}
2574
2575static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2576{
2577 struct ieee80211_sub_if_data *sdata =
2578 container_of(work, struct ieee80211_sub_if_data,
2579 u.mgd.csa_connection_drop_work);
2580
Johannes Bergeef9e542013-01-29 13:09:34 +01002581 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002582}
2583
Kalle Valo04de8382009-03-22 21:57:35 +02002584void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2585{
2586 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002587 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02002588
Johannes Bergb5878a22010-04-07 16:48:40 +02002589 trace_api_beacon_loss(sdata);
2590
Johannes Berg682bd382013-01-29 13:13:50 +01002591 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002592 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002593}
2594EXPORT_SYMBOL(ieee80211_beacon_loss);
2595
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002596void ieee80211_connection_loss(struct ieee80211_vif *vif)
2597{
2598 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2599 struct ieee80211_hw *hw = &sdata->local->hw;
2600
Johannes Bergb5878a22010-04-07 16:48:40 +02002601 trace_api_connection_loss(sdata);
2602
Johannes Berg682bd382013-01-29 13:13:50 +01002603 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002604 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2605}
2606EXPORT_SYMBOL(ieee80211_connection_loss);
2607
2608
Johannes Berg66e67e42012-01-20 13:55:27 +01002609static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2610 bool assoc)
2611{
2612 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2613
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002614 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002615
Johannes Berg66e67e42012-01-20 13:55:27 +01002616 if (!assoc) {
Emmanuel Grumbachc1e140b2015-01-19 16:53:06 +02002617 /*
2618 * we are not authenticated yet, the only timer that could be
2619 * running is the timeout for the authentication response which
2620 * which is not relevant anymore.
2621 */
2622 del_timer_sync(&sdata->u.mgd.timer);
Johannes Berg66e67e42012-01-20 13:55:27 +01002623 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2624
Joe Perchesc84a67a2015-03-02 19:54:57 -08002625 eth_zero_addr(sdata->u.mgd.bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002626 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002627 sdata->u.mgd.flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002628 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002629 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002630 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01002631 }
2632
Johannes Berg5b112d32013-02-01 01:49:58 +01002633 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002634 kfree(auth_data);
2635 sdata->u.mgd.auth_data = NULL;
2636}
2637
Johannes Bergc9c99f82015-06-01 14:10:09 +02002638static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
Johannes Berge6f462d2016-12-08 17:22:09 +01002639 bool assoc, bool abandon)
Johannes Bergc9c99f82015-06-01 14:10:09 +02002640{
2641 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2642
2643 sdata_assert_lock(sdata);
2644
2645 if (!assoc) {
2646 /*
2647 * we are not associated yet, the only timer that could be
2648 * running is the timeout for the association response which
2649 * which is not relevant anymore.
2650 */
2651 del_timer_sync(&sdata->u.mgd.timer);
2652 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2653
2654 eth_zero_addr(sdata->u.mgd.bssid);
2655 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2656 sdata->u.mgd.flags = 0;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002657 sdata->vif.mu_mimo_owner = false;
2658
Johannes Bergc9c99f82015-06-01 14:10:09 +02002659 mutex_lock(&sdata->local->mtx);
2660 ieee80211_vif_release_channel(sdata);
2661 mutex_unlock(&sdata->local->mtx);
Johannes Berge6f462d2016-12-08 17:22:09 +01002662
2663 if (abandon)
2664 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
Johannes Bergc9c99f82015-06-01 14:10:09 +02002665 }
2666
2667 kfree(assoc_data);
2668 sdata->u.mgd.assoc_data = NULL;
2669}
2670
Johannes Berg66e67e42012-01-20 13:55:27 +01002671static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2672 struct ieee80211_mgmt *mgmt, size_t len)
2673{
Johannes Berg1672c0e32013-01-29 15:02:27 +01002674 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01002675 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2676 u8 *pos;
2677 struct ieee802_11_elems elems;
Johannes Berg1672c0e32013-01-29 15:02:27 +01002678 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002679
2680 pos = mgmt->u.auth.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002681 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002682 if (!elems.challenge)
2683 return;
2684 auth_data->expected_transaction = 4;
Ilan Peerd4e36e52018-04-20 13:49:25 +03002685 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg30686bf2015-06-02 21:39:54 +02002686 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +01002687 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2688 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03002689 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01002690 elems.challenge - 2, elems.challenge_len + 2,
2691 auth_data->bss->bssid, auth_data->bss->bssid,
2692 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002693 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002694}
2695
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002696static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2697 struct ieee80211_mgmt *mgmt, size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002698{
2699 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2700 u8 bssid[ETH_ALEN];
2701 u16 auth_alg, auth_transaction, status_code;
2702 struct sta_info *sta;
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002703 struct ieee80211_event event = {
2704 .type = MLME_EVENT,
2705 .u.mlme.data = AUTH_EVENT,
2706 };
Johannes Berg66e67e42012-01-20 13:55:27 +01002707
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002708 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002709
2710 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002711 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002712
2713 if (!ifmgd->auth_data || ifmgd->auth_data->done)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002714 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002715
2716 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2717
Joe Perchesb203ca32012-05-08 18:56:52 +00002718 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002719 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002720
2721 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2722 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2723 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2724
2725 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002726 auth_transaction != ifmgd->auth_data->expected_transaction) {
2727 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2728 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2729 auth_transaction,
2730 ifmgd->auth_data->expected_transaction);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002731 return;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002732 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002733
2734 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002735 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2736 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002737 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002738 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002739 event.u.mlme.status = MLME_DENIED;
2740 event.u.mlme.reason = status_code;
2741 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002742 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002743 }
2744
2745 switch (ifmgd->auth_data->algorithm) {
2746 case WLAN_AUTH_OPEN:
2747 case WLAN_AUTH_LEAP:
2748 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002749 case WLAN_AUTH_SAE:
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03002750 case WLAN_AUTH_FILS_SK:
2751 case WLAN_AUTH_FILS_SK_PFS:
2752 case WLAN_AUTH_FILS_PK:
Johannes Berg66e67e42012-01-20 13:55:27 +01002753 break;
2754 case WLAN_AUTH_SHARED_KEY:
2755 if (ifmgd->auth_data->expected_transaction != 4) {
2756 ieee80211_auth_challenge(sdata, mgmt, len);
2757 /* need another frame */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002758 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002759 }
2760 break;
2761 default:
2762 WARN_ONCE(1, "invalid auth alg %d",
2763 ifmgd->auth_data->algorithm);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002764 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002765 }
2766
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002767 event.u.mlme.status = MLME_SUCCESS;
2768 drv_event_callback(sdata->local, sdata, &event);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002769 sdata_info(sdata, "authenticated\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002770 ifmgd->auth_data->done = true;
2771 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
Johannes Berg89afe612013-02-13 15:39:57 +01002772 ifmgd->auth_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002773 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01002774
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002775 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2776 ifmgd->auth_data->expected_transaction != 2) {
2777 /*
2778 * Report auth frame to user space for processing since another
2779 * round of Authentication frames is still needed.
2780 */
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002781 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002782 return;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002783 }
2784
Johannes Berg66e67e42012-01-20 13:55:27 +01002785 /* move station state to auth */
2786 mutex_lock(&sdata->local->sta_mtx);
2787 sta = sta_info_get(sdata, bssid);
2788 if (!sta) {
2789 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2790 goto out_err;
2791 }
2792 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002793 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002794 goto out_err;
2795 }
2796 mutex_unlock(&sdata->local->sta_mtx);
2797
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002798 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002799 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002800 out_err:
2801 mutex_unlock(&sdata->local->sta_mtx);
2802 /* ignore frame -- wait for timeout */
Johannes Berg66e67e42012-01-20 13:55:27 +01002803}
2804
Calvin Owensdfa1ad22014-02-11 12:36:24 -06002805#define case_WLAN(type) \
2806 case WLAN_REASON_##type: return #type
2807
2808static const char *ieee80211_get_reason_code_string(u16 reason_code)
2809{
2810 switch (reason_code) {
2811 case_WLAN(UNSPECIFIED);
2812 case_WLAN(PREV_AUTH_NOT_VALID);
2813 case_WLAN(DEAUTH_LEAVING);
2814 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2815 case_WLAN(DISASSOC_AP_BUSY);
2816 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2817 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2818 case_WLAN(DISASSOC_STA_HAS_LEFT);
2819 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2820 case_WLAN(DISASSOC_BAD_POWER);
2821 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2822 case_WLAN(INVALID_IE);
2823 case_WLAN(MIC_FAILURE);
2824 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
2825 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
2826 case_WLAN(IE_DIFFERENT);
2827 case_WLAN(INVALID_GROUP_CIPHER);
2828 case_WLAN(INVALID_PAIRWISE_CIPHER);
2829 case_WLAN(INVALID_AKMP);
2830 case_WLAN(UNSUPP_RSN_VERSION);
2831 case_WLAN(INVALID_RSN_IE_CAP);
2832 case_WLAN(IEEE8021X_FAILED);
2833 case_WLAN(CIPHER_SUITE_REJECTED);
2834 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
2835 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
2836 case_WLAN(DISASSOC_LOW_ACK);
2837 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
2838 case_WLAN(QSTA_LEAVE_QBSS);
2839 case_WLAN(QSTA_NOT_USE);
2840 case_WLAN(QSTA_REQUIRE_SETUP);
2841 case_WLAN(QSTA_TIMEOUT);
2842 case_WLAN(QSTA_CIPHER_NOT_SUPP);
2843 case_WLAN(MESH_PEER_CANCELED);
2844 case_WLAN(MESH_MAX_PEERS);
2845 case_WLAN(MESH_CONFIG);
2846 case_WLAN(MESH_CLOSE);
2847 case_WLAN(MESH_MAX_RETRIES);
2848 case_WLAN(MESH_CONFIRM_TIMEOUT);
2849 case_WLAN(MESH_INVALID_GTK);
2850 case_WLAN(MESH_INCONSISTENT_PARAM);
2851 case_WLAN(MESH_INVALID_SECURITY);
2852 case_WLAN(MESH_PATH_ERROR);
2853 case_WLAN(MESH_PATH_NOFORWARD);
2854 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
2855 case_WLAN(MAC_EXISTS_IN_MBSS);
2856 case_WLAN(MESH_CHAN_REGULATORY);
2857 case_WLAN(MESH_CHAN);
2858 default: return "<unknown>";
2859 }
2860}
Johannes Berg66e67e42012-01-20 13:55:27 +01002861
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002862static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2863 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002864{
Johannes Berg46900292009-02-15 12:44:28 +01002865 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergc9c99f82015-06-01 14:10:09 +02002866 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002867
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002868 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002869
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002870 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002871 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002872
Johannes Bergc9c99f82015-06-01 14:10:09 +02002873 if (ifmgd->associated &&
2874 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
2875 const u8 *bssid = ifmgd->associated->bssid;
2876
2877 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
2878 bssid, reason_code,
2879 ieee80211_get_reason_code_string(reason_code));
2880
2881 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2882
2883 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
2884 reason_code);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002885 return;
Johannes Bergc9c99f82015-06-01 14:10:09 +02002886 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002887
Johannes Bergc9c99f82015-06-01 14:10:09 +02002888 if (ifmgd->assoc_data &&
2889 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2890 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002891
Johannes Bergc9c99f82015-06-01 14:10:09 +02002892 sdata_info(sdata,
2893 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
2894 bssid, reason_code,
2895 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07002896
Johannes Berge6f462d2016-12-08 17:22:09 +01002897 ieee80211_destroy_assoc_data(sdata, false, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07002898
Johannes Bergc9c99f82015-06-01 14:10:09 +02002899 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2900 return;
2901 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002902}
2903
2904
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002905static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2906 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002907{
Johannes Berg46900292009-02-15 12:44:28 +01002908 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002909 u16 reason_code;
2910
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002911 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002912
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002913 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002914 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002915
Johannes Berg66e67e42012-01-20 13:55:27 +01002916 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002917 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002918 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002919
2920 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2921
Arkadiusz Miskiewicz68506e92017-02-15 14:21:27 +01002922 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
2923 mgmt->sa, reason_code,
2924 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07002925
Johannes Berg37ad3882012-02-24 13:50:54 +01002926 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2927
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002928 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002929}
2930
Christian Lamparterc74d0842011-10-15 00:14:49 +02002931static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2932 u8 *supp_rates, unsigned int supp_rates_len,
2933 u32 *rates, u32 *basic_rates,
2934 bool *have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002935 int *min_rate, int *min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03002936 int shift)
Christian Lamparterc74d0842011-10-15 00:14:49 +02002937{
2938 int i, j;
2939
2940 for (i = 0; i < supp_rates_len; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002941 int rate = supp_rates[i] & 0x7f;
Christian Lamparterc74d0842011-10-15 00:14:49 +02002942 bool is_basic = !!(supp_rates[i] & 0x80);
2943
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002944 if ((rate * 5 * (1 << shift)) > 110)
Christian Lamparterc74d0842011-10-15 00:14:49 +02002945 *have_higher_than_11mbit = true;
2946
2947 /*
Johannes Berga6289d32017-03-06 22:59:04 +01002948 * Skip HT and VHT BSS membership selectors since they're not
2949 * rates.
Christian Lamparterc74d0842011-10-15 00:14:49 +02002950 *
Johannes Berga6289d32017-03-06 22:59:04 +01002951 * Note: Even though the membership selector and the basic
Christian Lamparterc74d0842011-10-15 00:14:49 +02002952 * rate flag share the same bit, they are not exactly
2953 * the same.
2954 */
Johannes Berga6289d32017-03-06 22:59:04 +01002955 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
2956 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
Christian Lamparterc74d0842011-10-15 00:14:49 +02002957 continue;
2958
2959 for (j = 0; j < sband->n_bitrates; j++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002960 struct ieee80211_rate *br;
2961 int brate;
2962
2963 br = &sband->bitrates[j];
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002964
2965 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
2966 if (brate == rate) {
Christian Lamparterc74d0842011-10-15 00:14:49 +02002967 *rates |= BIT(j);
2968 if (is_basic)
2969 *basic_rates |= BIT(j);
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002970 if ((rate * 5) < *min_rate) {
2971 *min_rate = rate * 5;
Christian Lamparterc74d0842011-10-15 00:14:49 +02002972 *min_rate_index = j;
2973 }
2974 break;
2975 }
2976 }
2977 }
2978}
Jiri Bencf0706e82007-05-05 11:45:53 -07002979
Johannes Berg66e67e42012-01-20 13:55:27 +01002980static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2981 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002982 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002983{
Johannes Berg46900292009-02-15 12:44:28 +01002984 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002985 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01002986 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07002987 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002988 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002989 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002990 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02002991 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg35d865a2013-05-28 10:54:03 +02002992 const struct cfg80211_bss_ies *bss_ies = NULL;
2993 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
Johannes Bergae5eb022008-10-14 16:58:37 +02002994 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02002995 int err;
Johannes Berg35d865a2013-05-28 10:54:03 +02002996 bool ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07002997
Johannes Bergaf6b6372009-12-23 13:15:35 +01002998 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07002999
Jiri Bencf0706e82007-05-05 11:45:53 -07003000 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003001 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07003002
Johannes Bergc7c477b2017-12-01 13:50:51 +02003003 /*
3004 * The 5 MSB of the AID field are reserved
3005 * (802.11-2016 9.4.1.8 AID field)
3006 */
3007 aid &= 0x7ff;
Johannes Berg1dd84aa2007-10-10 12:03:41 +02003008
Johannes Berg05cb9102011-10-28 11:59:47 +02003009 ifmgd->broken_ap = false;
3010
3011 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003012 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3013 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02003014 aid = 0;
3015 ifmgd->broken_ap = true;
3016 }
3017
Johannes Bergaf6b6372009-12-23 13:15:35 +01003018 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01003019 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003020
Jiri Bencf0706e82007-05-05 11:45:53 -07003021 if (!elems.supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003022 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01003023 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07003024 }
3025
Johannes Berg46900292009-02-15 12:44:28 +01003026 ifmgd->aid = aid;
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02003027 ifmgd->tdls_chan_switch_prohibited =
3028 elems.ext_capab && elems.ext_capab_len >= 5 &&
3029 (elems.ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
Jiri Bencf0706e82007-05-05 11:45:53 -07003030
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003031 /*
Johannes Berg35d865a2013-05-28 10:54:03 +02003032 * Some APs are erroneously not including some information in their
3033 * (re)association response frames. Try to recover by using the data
3034 * from the beacon or probe response. This seems to afflict mobile
3035 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3036 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3037 */
3038 if ((assoc_data->wmm && !elems.wmm_param) ||
3039 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3040 (!elems.ht_cap_elem || !elems.ht_operation)) ||
3041 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3042 (!elems.vht_cap_elem || !elems.vht_operation))) {
3043 const struct cfg80211_bss_ies *ies;
3044 struct ieee802_11_elems bss_elems;
3045
3046 rcu_read_lock();
3047 ies = rcu_dereference(cbss->ies);
3048 if (ies)
3049 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3050 GFP_ATOMIC);
3051 rcu_read_unlock();
3052 if (!bss_ies)
3053 return false;
3054
3055 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3056 false, &bss_elems);
3057 if (assoc_data->wmm &&
3058 !elems.wmm_param && bss_elems.wmm_param) {
3059 elems.wmm_param = bss_elems.wmm_param;
3060 sdata_info(sdata,
3061 "AP bug: WMM param missing from AssocResp\n");
3062 }
3063
3064 /*
3065 * Also check if we requested HT/VHT, otherwise the AP doesn't
3066 * have to include the IEs in the (re)association response.
3067 */
3068 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
3069 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3070 elems.ht_cap_elem = bss_elems.ht_cap_elem;
3071 sdata_info(sdata,
3072 "AP bug: HT capability missing from AssocResp\n");
3073 }
3074 if (!elems.ht_operation && bss_elems.ht_operation &&
3075 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3076 elems.ht_operation = bss_elems.ht_operation;
3077 sdata_info(sdata,
3078 "AP bug: HT operation missing from AssocResp\n");
3079 }
3080 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
3081 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3082 elems.vht_cap_elem = bss_elems.vht_cap_elem;
3083 sdata_info(sdata,
3084 "AP bug: VHT capa missing from AssocResp\n");
3085 }
3086 if (!elems.vht_operation && bss_elems.vht_operation &&
3087 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3088 elems.vht_operation = bss_elems.vht_operation;
3089 sdata_info(sdata,
3090 "AP bug: VHT operation missing from AssocResp\n");
3091 }
3092 }
3093
3094 /*
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003095 * We previously checked these in the beacon/probe response, so
3096 * they should be present here. This is just a safety net.
3097 */
3098 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3099 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
3100 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003101 "HT AP is missing WMM params or HT capability/operation\n");
3102 ret = false;
3103 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003104 }
3105
3106 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3107 (!elems.vht_cap_elem || !elems.vht_operation)) {
3108 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003109 "VHT AP is missing VHT capability/operation\n");
3110 ret = false;
3111 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003112 }
3113
Guy Eilam2a33bee2011-08-17 15:18:15 +03003114 mutex_lock(&sdata->local->sta_mtx);
3115 /*
3116 * station info was already allocated and inserted before
3117 * the association and should be available to us
3118 */
Johannes Berg7852e362012-01-20 13:55:24 +01003119 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003120 if (WARN_ON(!sta)) {
3121 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003122 ret = false;
3123 goto out;
Jiri Bencf0706e82007-05-05 11:45:53 -07003124 }
3125
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05303126 sband = ieee80211_get_sband(sdata);
3127 if (!sband) {
3128 mutex_unlock(&sdata->local->sta_mtx);
3129 ret = false;
3130 goto out;
3131 }
Johannes Berg8318d782008-01-24 19:38:38 +01003132
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003133 /*
3134 * If AP doesn't support HT, or it doesn't have HE mandatory IEs, mark
3135 * HE as disabled. If on the 5GHz band, make sure it supports VHT.
3136 */
3137 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
3138 (sband->band == NL80211_BAND_5GHZ &&
3139 ifmgd->flags & IEEE80211_STA_DISABLE_VHT) ||
3140 (!elems.he_cap && !elems.he_operation))
3141 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
3142
3143 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3144 (!elems.he_cap || !elems.he_operation)) {
3145 mutex_unlock(&sdata->local->sta_mtx);
3146 sdata_info(sdata,
3147 "HE AP is missing HE capability/operation\n");
3148 ret = false;
3149 goto out;
3150 }
3151
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003152 /* Set up internal HT/VHT capabilities */
Johannes Berga8243b72012-11-22 14:32:09 +01003153 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08003154 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01003155 elems.ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02003156
Mahesh Palivela818255e2012-10-10 11:33:04 +00003157 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3158 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01003159 elems.vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00003160
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003161 if (elems.he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3162 elems.he_cap) {
3163 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3164 elems.he_cap,
3165 elems.he_cap_len,
3166 sta);
3167
3168 bss_conf->he_support = sta->sta.he_cap.has_he;
3169 } else {
3170 bss_conf->he_support = false;
3171 }
3172
3173 if (bss_conf->he_support) {
3174 u32 he_oper_params =
3175 le32_to_cpu(elems.he_operation->he_oper_params);
3176
3177 bss_conf->bss_color = he_oper_params &
3178 IEEE80211_HE_OPERATION_BSS_COLOR_MASK;
3179 bss_conf->htc_trig_based_pkt_ext =
3180 (he_oper_params &
3181 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK) <<
3182 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_OFFSET;
3183 bss_conf->frame_time_rts_th =
3184 (he_oper_params &
3185 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK) <<
3186 IEEE80211_HE_OPERATION_RTS_THRESHOLD_OFFSET;
3187
3188 bss_conf->multi_sta_back_32bit =
3189 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3190 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
3191
3192 bss_conf->ack_enabled =
3193 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3194 IEEE80211_HE_MAC_CAP2_ACK_EN;
3195
3196 bss_conf->uora_exists = !!elems.uora_element;
3197 if (elems.uora_element)
3198 bss_conf->uora_ocw_range = elems.uora_element[0];
3199
3200 /* TODO: OPEN: what happens if BSS color disable is set? */
3201 }
3202
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003203 /*
3204 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3205 * in their association response, so ignore that data for our own
3206 * configuration. If it changed since the last beacon, we'll get the
3207 * next beacon and update then.
3208 */
Johannes Berg11289582013-02-07 17:36:12 +01003209
Johannes Bergbee7f582013-02-07 22:24:55 +01003210 /*
3211 * If an operating mode notification IE is present, override the
3212 * NSS calculation (that would be done in rate_control_rate_init())
3213 * and use the # of streams from that element.
3214 */
3215 if (elems.opmode_notif &&
3216 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3217 u8 nss;
3218
3219 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3220 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3221 nss += 1;
3222 sta->sta.rx_nss = nss;
3223 }
3224
Johannes Berg4b7679a2008-09-18 18:14:18 +02003225 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003226
Tamizh chelvam93f04902015-10-07 10:40:04 +05303227 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003228 set_sta_flag(sta, WLAN_STA_MFP);
Tamizh chelvam93f04902015-10-07 10:40:04 +05303229 sta->sta.mfp = true;
3230 } else {
3231 sta->sta.mfp = false;
3232 }
Jouni Malinen5394af42009-01-08 13:31:59 +02003233
Johannes Berg527871d2015-03-21 08:09:55 +01003234 sta->sta.wme = elems.wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
Johannes Bergddf4ac52008-10-22 11:41:38 +02003235
Johannes Berg3e4d40f2013-02-07 17:19:08 +01003236 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01003237 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3238 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3239 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003240 sdata_info(sdata,
3241 "failed to move station %pM to desired state\n",
3242 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01003243 WARN_ON(__sta_info_destroy(sta));
3244 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003245 ret = false;
3246 goto out;
Johannes Bergc8987872012-01-20 13:55:17 +01003247 }
3248
Johannes Berg7852e362012-01-20 13:55:24 +01003249 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02003250
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003251 /*
3252 * Always handle WMM once after association regardless
3253 * of the first value the AP uses. Setting -1 here has
3254 * that effect because the AP values is an unsigned
3255 * 4-bit value.
3256 */
3257 ifmgd->wmm_last_param_set = -1;
3258
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003259 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Bergcec66282015-10-22 17:46:04 +02003260 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003261 } else if (!ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003262 elems.wmm_param_len,
3263 elems.mu_edca_param_set)) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003264 /* still enable QoS since we might have HT/VHT */
3265 ieee80211_set_wmm_default(sdata, false, true);
3266 /* set the disable-WMM flag in this case to disable
3267 * tracking WMM parameter changes in the beacon if
3268 * the parameters weren't actually valid. Doing so
3269 * avoids changing parameters very strangely when
3270 * the AP is going back and forth between valid and
3271 * invalid parameters.
3272 */
3273 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3274 }
Johannes Berg3abead52012-03-02 15:56:59 +01003275 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07003276
Avraham Sterne38a0172017-04-26 10:58:47 +03003277 if (elems.max_idle_period_ie) {
3278 bss_conf->max_idle_period =
3279 le16_to_cpu(elems.max_idle_period_ie->max_idle_period);
3280 bss_conf->protected_keep_alive =
3281 !!(elems.max_idle_period_ie->idle_options &
3282 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3283 changed |= BSS_CHANGED_KEEP_ALIVE;
3284 } else {
3285 bss_conf->max_idle_period = 0;
3286 bss_conf->protected_keep_alive = false;
3287 }
3288
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003289 /* set AID and assoc capability,
3290 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01003291 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003292 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003293 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003294
Kalle Valo15b7b062009-03-22 21:57:14 +02003295 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01003296 * If we're using 4-addr mode, let the AP know that we're
3297 * doing so, so that it can create the STA VLAN on its side
3298 */
3299 if (ifmgd->use_4addr)
3300 ieee80211_send_4addr_nullfunc(local, sdata);
3301
3302 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02003303 * Start timer to probe the connection to the AP now.
3304 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02003305 */
Johannes Bergb291ba12009-07-10 15:29:03 +02003306 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003307 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02003308
Johannes Berg35d865a2013-05-28 10:54:03 +02003309 ret = true;
3310 out:
3311 kfree(bss_ies);
3312 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003313}
3314
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003315static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3316 struct ieee80211_mgmt *mgmt,
3317 size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01003318{
3319 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3320 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3321 u16 capab_info, status_code, aid;
3322 struct ieee802_11_elems elems;
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003323 int ac, uapsd_queues = -1;
Johannes Berg66e67e42012-01-20 13:55:27 +01003324 u8 *pos;
3325 bool reassoc;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003326 struct cfg80211_bss *bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003327 struct ieee80211_event event = {
3328 .type = MLME_EVENT,
3329 .u.mlme.data = ASSOC_EVENT,
3330 };
Jiri Bencf0706e82007-05-05 11:45:53 -07003331
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003332 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003333
3334 if (!assoc_data)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003335 return;
Joe Perchesb203ca32012-05-08 18:56:52 +00003336 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003337 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003338
3339 /*
3340 * AssocResp and ReassocResp have identical structure, so process both
3341 * of them in this function.
3342 */
3343
3344 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003345 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003346
Simon Dinkin7a7d3e42017-08-31 13:09:36 +03003347 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
Johannes Berg66e67e42012-01-20 13:55:27 +01003348 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3349 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3350 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3351
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003352 sdata_info(sdata,
3353 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3354 reassoc ? "Rea" : "A", mgmt->sa,
3355 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01003356
Jouni Malinen39404fe2016-10-27 00:42:05 +03003357 if (assoc_data->fils_kek_len &&
3358 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3359 return;
3360
Johannes Berg66e67e42012-01-20 13:55:27 +01003361 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01003362 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01003363
3364 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01003365 elems.timeout_int &&
3366 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003367 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01003368 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01003369 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003370 sdata_info(sdata,
3371 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3372 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01003373 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01003374 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01003375 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003376 run_again(sdata, assoc_data->timeout);
3377 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003378 }
3379
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003380 bss = assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01003381
3382 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003383 sdata_info(sdata, "%pM denied association (code=%d)\n",
3384 mgmt->sa, status_code);
Johannes Berge6f462d2016-12-08 17:22:09 +01003385 ieee80211_destroy_assoc_data(sdata, false, false);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003386 event.u.mlme.status = MLME_DENIED;
3387 event.u.mlme.reason = status_code;
3388 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01003389 } else {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003390 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003391 /* oops -- internal error -- send timeout for now */
Johannes Berge6f462d2016-12-08 17:22:09 +01003392 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02003393 cfg80211_assoc_timeout(sdata->dev, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003394 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003395 }
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003396 event.u.mlme.status = MLME_SUCCESS;
3397 drv_event_callback(sdata->local, sdata, &event);
John W. Linville635d9992012-07-09 16:34:34 -04003398 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01003399
3400 /*
3401 * destroy assoc_data afterwards, as otherwise an idle
3402 * recalc after assoc_data is NULL but before associated
3403 * is set can cause the interface to go idle
3404 */
Johannes Berge6f462d2016-12-08 17:22:09 +01003405 ieee80211_destroy_assoc_data(sdata, true, false);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003406
3407 /* get uapsd queues configuration */
3408 uapsd_queues = 0;
3409 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3410 if (sdata->tx_conf[ac].uapsd)
Emmanuel Grumbachf438ceb2016-10-18 23:12:12 +03003411 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
Johannes Berg66e67e42012-01-20 13:55:27 +01003412 }
3413
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003414 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues);
Johannes Berg66e67e42012-01-20 13:55:27 +01003415}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003416
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003417static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003418 struct ieee80211_mgmt *mgmt, size_t len,
Jiri Bencf0706e82007-05-05 11:45:53 -07003419 struct ieee80211_rx_status *rx_status,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003420 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07003421{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003422 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02003423 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01003424 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01003425
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003426 sdata_assert_lock(sdata);
Johannes Bergb4f286a12013-03-26 14:13:58 +01003427
Emmanuel Grumbach3afc2162014-03-04 16:50:13 +02003428 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3429 if (!channel)
Johannes Berg5bda6172008-09-08 11:05:10 +02003430 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003431
Johannes Berg98c8fcc2008-09-08 17:44:26 +02003432 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003433 channel);
Alexander Bondar817cee72013-05-19 14:23:57 +03003434 if (bss) {
Alexander Bondar817cee72013-05-19 14:23:57 +03003435 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
Johannes Bergd2722f82014-03-04 11:43:28 +01003436 ieee80211_rx_bss_put(local, bss);
Alexander Bondar817cee72013-05-19 14:23:57 +03003437 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003438}
3439
3440
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003441static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003442 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003443{
Johannes Bergaf6b6372009-12-23 13:15:35 +01003444 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02003445 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003446 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3447 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03003448 struct ieee802_11_elems elems;
3449
Kalle Valo15b7b062009-03-22 21:57:14 +02003450 ifmgd = &sdata->u.mgd;
3451
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003452 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003453
Joe Perchesb203ca32012-05-08 18:56:52 +00003454 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03003455 return; /* ignore ProbeResp to foreign address */
3456
Ester Kummerae6a44e2008-06-27 18:54:48 +03003457 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3458 if (baselen > len)
3459 return;
3460
3461 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003462 false, &elems);
Ester Kummerae6a44e2008-06-27 18:54:48 +03003463
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003464 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03003465
Johannes Berg77fdaa12009-07-07 03:45:17 +02003466 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003467 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003468 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003469}
3470
Johannes Bergd91f36d2009-04-16 13:17:26 +02003471/*
3472 * This is the canonical list of information elements we care about,
3473 * the filter code also gives us all changes to the Microsoft OUI
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003474 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3475 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3476 * changes to requested client power.
Johannes Bergd91f36d2009-04-16 13:17:26 +02003477 *
3478 * We implement beacon filtering in software since that means we can
3479 * avoid processing the frame here and in cfg80211, and userspace
3480 * will not be able to tell whether the hardware supports it or not.
3481 *
3482 * XXX: This list needs to be dynamic -- userspace needs to be able to
3483 * add items it requires. It also needs to be able to tell us to
3484 * look out for other vendor IEs.
3485 */
3486static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02003487 (1ULL << WLAN_EID_COUNTRY) |
3488 (1ULL << WLAN_EID_ERP_INFO) |
3489 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3490 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3491 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg70a3fd62015-03-12 08:53:29 +02003492 (1ULL << WLAN_EID_HT_OPERATION) |
3493 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003494
Tosoni1ad22fb2018-03-14 16:58:34 +00003495static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3496 struct ieee80211_if_managed *ifmgd,
3497 struct ieee80211_bss_conf *bss_conf,
3498 struct ieee80211_local *local,
3499 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003500{
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003501 /* Track average RSSI from the Beacon frames of the current AP */
Tosoni1ad22fb2018-03-14 16:58:34 +00003502
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003503 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3504 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Johannes Berg338c17a2015-08-28 10:52:54 +02003505 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003506 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03003507 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003508 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003509 } else {
Jouni Malinen391a2002010-08-27 22:22:00 +03003510 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003511 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003512
Johannes Berg338c17a2015-08-28 10:52:54 +02003513 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3514
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003515 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3516 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003517 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003518 int last_sig = ifmgd->last_ave_beacon_signal;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003519 struct ieee80211_event event = {
3520 .type = RSSI_EVENT,
3521 };
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003522
3523 /*
3524 * if signal crosses either of the boundaries, invoke callback
3525 * with appropriate parameters
3526 */
3527 if (sig > ifmgd->rssi_max_thold &&
3528 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3529 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003530 event.u.rssi.data = RSSI_EVENT_HIGH;
3531 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003532 } else if (sig < ifmgd->rssi_min_thold &&
3533 (last_sig >= ifmgd->rssi_max_thold ||
3534 last_sig == 0)) {
3535 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003536 event.u.rssi.data = RSSI_EVENT_LOW;
3537 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003538 }
3539 }
3540
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003541 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03003542 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01003543 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003544 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003545 int last_event = ifmgd->last_cqm_event_signal;
3546 int thold = bss_conf->cqm_rssi_thold;
3547 int hyst = bss_conf->cqm_rssi_hyst;
Johannes Berg338c17a2015-08-28 10:52:54 +02003548
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003549 if (sig < thold &&
3550 (last_event == 0 || sig < last_event - hyst)) {
3551 ifmgd->last_cqm_event_signal = sig;
3552 ieee80211_cqm_rssi_notify(
3553 &sdata->vif,
3554 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003555 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003556 } else if (sig > thold &&
3557 (last_event == 0 || sig > last_event + hyst)) {
3558 ifmgd->last_cqm_event_signal = sig;
3559 ieee80211_cqm_rssi_notify(
3560 &sdata->vif,
3561 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003562 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003563 }
3564 }
3565
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003566 if (bss_conf->cqm_rssi_low &&
3567 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3568 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3569 int last_event = ifmgd->last_cqm_event_signal;
3570 int low = bss_conf->cqm_rssi_low;
3571 int high = bss_conf->cqm_rssi_high;
3572
3573 if (sig < low &&
3574 (last_event == 0 || last_event >= low)) {
3575 ifmgd->last_cqm_event_signal = sig;
3576 ieee80211_cqm_rssi_notify(
3577 &sdata->vif,
3578 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3579 sig, GFP_KERNEL);
3580 } else if (sig > high &&
3581 (last_event == 0 || last_event <= high)) {
3582 ifmgd->last_cqm_event_signal = sig;
3583 ieee80211_cqm_rssi_notify(
3584 &sdata->vif,
3585 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3586 sig, GFP_KERNEL);
3587 }
3588 }
Tosoni1ad22fb2018-03-14 16:58:34 +00003589}
3590
3591static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3592 struct ieee80211_mgmt *mgmt, size_t len,
3593 struct ieee80211_rx_status *rx_status)
3594{
3595 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3596 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3597 size_t baselen;
3598 struct ieee802_11_elems elems;
3599 struct ieee80211_local *local = sdata->local;
3600 struct ieee80211_chanctx_conf *chanctx_conf;
3601 struct ieee80211_channel *chan;
3602 struct sta_info *sta;
3603 u32 changed = 0;
3604 bool erp_valid;
3605 u8 erp_value = 0;
3606 u32 ncrc;
3607 u8 *bssid;
3608 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3609
3610 sdata_assert_lock(sdata);
3611
3612 /* Process beacon from the current BSS */
3613 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3614 if (baselen > len)
3615 return;
3616
3617 rcu_read_lock();
3618 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3619 if (!chanctx_conf) {
3620 rcu_read_unlock();
3621 return;
3622 }
3623
3624 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3625 rcu_read_unlock();
3626 return;
3627 }
3628 chan = chanctx_conf->def.chan;
3629 rcu_read_unlock();
3630
3631 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
3632 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3633 ieee802_11_parse_elems(mgmt->u.beacon.variable,
3634 len - baselen, false, &elems);
3635
3636 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3637 if (elems.tim && !elems.parse_error) {
3638 const struct ieee80211_tim_ie *tim_ie = elems.tim;
3639 ifmgd->dtim_period = tim_ie->dtim_period;
3640 }
3641 ifmgd->have_beacon = true;
3642 ifmgd->assoc_data->need_beacon = false;
3643 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3644 sdata->vif.bss_conf.sync_tsf =
3645 le64_to_cpu(mgmt->u.beacon.timestamp);
3646 sdata->vif.bss_conf.sync_device_ts =
3647 rx_status->device_timestamp;
3648 if (elems.tim)
3649 sdata->vif.bss_conf.sync_dtim_count =
3650 elems.tim->dtim_count;
3651 else
3652 sdata->vif.bss_conf.sync_dtim_count = 0;
3653 }
3654 /* continue assoc process */
3655 ifmgd->assoc_data->timeout = jiffies;
3656 ifmgd->assoc_data->timeout_started = true;
3657 run_again(sdata, ifmgd->assoc_data->timeout);
3658 return;
3659 }
3660
3661 if (!ifmgd->associated ||
3662 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3663 return;
3664 bssid = ifmgd->associated->bssid;
3665
3666 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3667 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
3668 local, rx_status);
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003669
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003670 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003671 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01003672 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003673 ieee80211_reset_ap_probe(sdata);
Jouni Malinen92778182009-05-14 21:15:36 +03003674 }
3675
Johannes Bergb291ba12009-07-10 15:29:03 +02003676 /*
3677 * Push the beacon loss detection into the future since
3678 * we are processing a beacon from the AP just now.
3679 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003680 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003681
Johannes Bergd91f36d2009-04-16 13:17:26 +02003682 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3683 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003684 len - baselen, false, &elems,
Johannes Bergd91f36d2009-04-16 13:17:26 +02003685 care_about_ies, ncrc);
3686
Johannes Berg90d13e82015-09-24 16:13:07 +02003687 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3688 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3689 if (local->hw.conf.dynamic_ps_timeout > 0) {
3690 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3691 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3692 ieee80211_hw_config(local,
3693 IEEE80211_CONF_CHANGE_PS);
Kalle Valo572e0012009-02-10 17:09:31 +02003694 }
Johannes Berg076cdcb2015-09-24 16:14:55 +02003695 ieee80211_send_nullfunc(local, sdata, false);
Johannes Berg90d13e82015-09-24 16:13:07 +02003696 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3697 local->pspolling = true;
3698
3699 /*
3700 * Here is assumed that the driver will be
3701 * able to send ps-poll frame and receive a
3702 * response even though power save mode is
3703 * enabled, but some drivers might require
3704 * to disable power save here. This needs
3705 * to be investigated.
3706 */
3707 ieee80211_send_pspoll(local, sdata);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003708 }
3709 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003710
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01003711 if (sdata->vif.p2p ||
3712 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003713 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003714 int ret;
3715
3716 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3717 len - baselen,
3718 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003719 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003720 if (ret >= 2) {
3721 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3722 /* valid noa_attr and index changed */
3723 sdata->u.mgd.p2p_noa_index = noa.index;
3724 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3725 changed |= BSS_CHANGED_P2P_PS;
3726 /*
3727 * make sure we update all information, the CRC
3728 * mechanism doesn't look at P2P attributes.
3729 */
3730 ifmgd->beacon_crc_valid = false;
3731 }
3732 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3733 /* noa_attr not found and we had valid noa_attr before */
3734 sdata->u.mgd.p2p_noa_index = -1;
3735 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003736 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003737 ifmgd->beacon_crc_valid = false;
3738 }
3739 }
3740
Luciano Coelho0c21e632014-10-08 09:48:39 +03003741 if (ifmgd->csa_waiting_bcn)
3742 ieee80211_chswitch_post_beacon(sdata);
3743
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003744 /*
3745 * Update beacon timing and dtim count on every beacon appearance. This
3746 * will allow the driver to use the most updated values. Do it before
3747 * comparing this one with last received beacon.
3748 * IMPORTANT: These parameters would possibly be out of sync by the time
3749 * the driver will use them. The synchronized view is currently
3750 * guaranteed only in certain callbacks.
3751 */
Johannes Berg30686bf2015-06-02 21:39:54 +02003752 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003753 sdata->vif.bss_conf.sync_tsf =
3754 le64_to_cpu(mgmt->u.beacon.timestamp);
3755 sdata->vif.bss_conf.sync_device_ts =
3756 rx_status->device_timestamp;
3757 if (elems.tim)
3758 sdata->vif.bss_conf.sync_dtim_count =
3759 elems.tim->dtim_count;
3760 else
3761 sdata->vif.bss_conf.sync_dtim_count = 0;
3762 }
3763
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003764 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003765 return;
Jouni Malinen30196672009-05-19 17:01:43 +03003766 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003767 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03003768
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003769 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg7d257452012-07-06 17:37:43 +02003770
Johannes Bergd70b7612013-08-23 15:48:48 +02003771 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003772 rx_status->device_timestamp,
Johannes Bergd70b7612013-08-23 15:48:48 +02003773 &elems, true);
3774
Johannes Berg095d81c2013-10-15 12:25:07 +02003775 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
3776 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003777 elems.wmm_param_len,
3778 elems.mu_edca_param_set))
Johannes Berg7d257452012-07-06 17:37:43 +02003779 changed |= BSS_CHANGED_QOS;
3780
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003781 /*
3782 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01003783 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003784 */
Alexander Bondar989c6502013-05-16 17:34:17 +03003785 if (!ifmgd->have_beacon) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003786 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3787 if (elems.tim)
3788 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3789 else
3790 bss_conf->dtim_period = 1;
Johannes Bergef429da2013-02-05 17:48:40 +01003791
Alexander Bondar989c6502013-05-16 17:34:17 +03003792 changed |= BSS_CHANGED_BEACON_INFO;
3793 ifmgd->have_beacon = true;
Alexander Bondar482a9c72013-06-03 17:29:33 +03003794
3795 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02003796 ieee80211_recalc_ps(local);
Alexander Bondar482a9c72013-06-03 17:29:33 +03003797 mutex_unlock(&local->iflist_mtx);
3798
Alexander Bondarce857882013-05-06 17:17:04 +03003799 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003800 }
3801
Johannes Berg1946bed2013-03-27 14:31:53 +01003802 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02003803 erp_valid = true;
3804 erp_value = elems.erp_info[0];
3805 } else {
3806 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04003807 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003808 changed |= ieee80211_handle_bss_capability(sdata,
3809 le16_to_cpu(mgmt->u.beacon.capab_info),
3810 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07003811
Johannes Berg11289582013-02-07 17:36:12 +01003812 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f582013-02-07 22:24:55 +01003813 sta = sta_info_get(sdata, bssid);
3814
Eliad Peller53b954e2014-07-24 11:20:05 +03003815 if (ieee80211_config_bw(sdata, sta,
3816 elems.ht_cap_elem, elems.ht_operation,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003817 elems.vht_operation, elems.he_operation,
3818 bssid, &changed)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003819 mutex_unlock(&local->sta_mtx);
Johannes Berg89f774e2016-01-25 15:46:36 +02003820 sdata_info(sdata,
3821 "failed to follow AP %pM bandwidth change, disconnect\n",
3822 bssid);
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003823 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3824 WLAN_REASON_DEAUTH_LEAVING,
3825 true, deauth_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003826 ieee80211_report_disconnect(sdata, deauth_buf,
3827 sizeof(deauth_buf), true,
3828 WLAN_REASON_DEAUTH_LEAVING);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003829 return;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003830 }
Johannes Bergbee7f582013-02-07 22:24:55 +01003831
3832 if (sta && elems.opmode_notif)
3833 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
Eyal Shapiracf1e05c2015-12-08 16:04:36 +02003834 rx_status->band);
Johannes Berg11289582013-02-07 17:36:12 +01003835 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003836
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07003837 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
3838 elems.country_elem,
3839 elems.country_elem_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003840 elems.pwr_constr_elem,
3841 elems.cisco_dtpc_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08003842
Johannes Berg471b3ef2007-12-28 14:32:58 +01003843 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003844}
3845
Johannes Berg1fa57d02010-06-10 10:21:32 +02003846void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3847 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003848{
3849 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07003850 struct ieee80211_mgmt *mgmt;
3851 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003852 struct ieee802_11_elems elems;
3853 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07003854
Jiri Bencf0706e82007-05-05 11:45:53 -07003855 rx_status = (struct ieee80211_rx_status *) skb->cb;
3856 mgmt = (struct ieee80211_mgmt *) skb->data;
3857 fc = le16_to_cpu(mgmt->frame_control);
3858
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003859 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003860
Johannes Berg66e67e42012-01-20 13:55:27 +01003861 switch (fc & IEEE80211_FCTL_STYPE) {
3862 case IEEE80211_STYPE_BEACON:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003863 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01003864 break;
3865 case IEEE80211_STYPE_PROBE_RESP:
3866 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3867 break;
3868 case IEEE80211_STYPE_AUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003869 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003870 break;
3871 case IEEE80211_STYPE_DEAUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003872 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003873 break;
3874 case IEEE80211_STYPE_DISASSOC:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003875 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003876 break;
3877 case IEEE80211_STYPE_ASSOC_RESP:
3878 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003879 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003880 break;
3881 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01003882 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003883 ies_len = skb->len -
3884 offsetof(struct ieee80211_mgmt,
3885 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01003886
3887 if (ies_len < 0)
3888 break;
3889
3890 ieee802_11_parse_elems(
3891 mgmt->u.action.u.chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003892 ies_len, true, &elems);
Johannes Berg37799e52013-03-26 14:02:26 +01003893
3894 if (elems.parse_error)
3895 break;
3896
Johannes Berg66e67e42012-01-20 13:55:27 +01003897 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003898 rx_status->mactime,
3899 rx_status->device_timestamp,
3900 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003901 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3902 ies_len = skb->len -
3903 offsetof(struct ieee80211_mgmt,
3904 u.action.u.ext_chan_switch.variable);
3905
3906 if (ies_len < 0)
3907 break;
3908
3909 ieee802_11_parse_elems(
3910 mgmt->u.action.u.ext_chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003911 ies_len, true, &elems);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003912
3913 if (elems.parse_error)
3914 break;
3915
3916 /* for the handling code pretend this was also an IE */
3917 elems.ext_chansw_ie =
3918 &mgmt->u.action.u.ext_chan_switch.data;
3919
3920 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003921 rx_status->mactime,
3922 rx_status->device_timestamp,
3923 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003924 }
Johannes Berg37799e52013-03-26 14:02:26 +01003925 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003926 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003927 sdata_unlock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003928}
3929
Kees Cook34f11cd2017-10-16 16:35:49 -07003930static void ieee80211_sta_timer(struct timer_list *t)
Jiri Bencf0706e82007-05-05 11:45:53 -07003931{
3932 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07003933 from_timer(sdata, t, u.mgd.timer);
Jiri Bencf0706e82007-05-05 11:45:53 -07003934
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01003935 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07003936}
3937
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003938static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01003939 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003940{
Antonio Quartulli6ae16772012-09-07 13:28:52 +02003941 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003942
Johannes Berg37ad3882012-02-24 13:50:54 +01003943 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01003944 tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01003945
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003946 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
3947 reason);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003948}
3949
Johannes Berg46cad4b2015-08-15 22:39:54 +03003950static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg66e67e42012-01-20 13:55:27 +01003951{
3952 struct ieee80211_local *local = sdata->local;
3953 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3954 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003955 u32 tx_flags = 0;
Johannes Berg46cad4b2015-08-15 22:39:54 +03003956 u16 trans = 1;
3957 u16 status = 0;
Ilan Peerd4e36e52018-04-20 13:49:25 +03003958 u16 prepare_tx_duration = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01003959
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003960 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003961
3962 if (WARN_ON_ONCE(!auth_data))
3963 return -EINVAL;
3964
Johannes Berg66e67e42012-01-20 13:55:27 +01003965 auth_data->tries++;
3966
3967 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003968 sdata_info(sdata, "authentication with %pM timed out\n",
3969 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003970
3971 /*
3972 * Most likely AP is not in the range so remove the
3973 * bss struct for that AP.
3974 */
3975 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
3976
3977 return -ETIMEDOUT;
3978 }
3979
Ilan Peerd4e36e52018-04-20 13:49:25 +03003980 if (auth_data->algorithm == WLAN_AUTH_SAE)
3981 prepare_tx_duration =
3982 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
3983
3984 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
Johannes Berga1845fc2012-06-27 13:18:36 +02003985
Johannes Berg46cad4b2015-08-15 22:39:54 +03003986 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
3987 auth_data->bss->bssid, auth_data->tries,
3988 IEEE80211_AUTH_MAX_TRIES);
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003989
Johannes Berg46cad4b2015-08-15 22:39:54 +03003990 auth_data->expected_transaction = 2;
Johannes Berg66e67e42012-01-20 13:55:27 +01003991
Johannes Berg46cad4b2015-08-15 22:39:54 +03003992 if (auth_data->algorithm == WLAN_AUTH_SAE) {
3993 trans = auth_data->sae_trans;
3994 status = auth_data->sae_status;
3995 auth_data->expected_transaction = trans;
Johannes Berg66e67e42012-01-20 13:55:27 +01003996 }
3997
Johannes Berg46cad4b2015-08-15 22:39:54 +03003998 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3999 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4000 IEEE80211_TX_INTFL_MLME_CONN_TX;
4001
4002 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4003 auth_data->data, auth_data->data_len,
4004 auth_data->bss->bssid,
4005 auth_data->bss->bssid, NULL, 0, 0,
4006 tx_flags);
4007
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02004008 if (tx_flags == 0) {
Ilan Peer407879b2018-04-20 13:49:20 +03004009 if (auth_data->algorithm == WLAN_AUTH_SAE)
4010 auth_data->timeout = jiffies +
4011 IEEE80211_AUTH_TIMEOUT_SAE;
4012 else
4013 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004014 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004015 auth_data->timeout =
4016 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004017 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004018
Ilan Peer407879b2018-04-20 13:49:20 +03004019 auth_data->timeout_started = true;
4020 run_again(sdata, auth_data->timeout);
4021
Johannes Berg66e67e42012-01-20 13:55:27 +01004022 return 0;
4023}
4024
4025static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4026{
4027 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4028 struct ieee80211_local *local = sdata->local;
4029
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004030 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004031
Johannes Berg66e67e42012-01-20 13:55:27 +01004032 assoc_data->tries++;
4033 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004034 sdata_info(sdata, "association with %pM timed out\n",
4035 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004036
4037 /*
4038 * Most likely AP is not in the range so remove the
4039 * bss struct for that AP.
4040 */
4041 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4042
4043 return -ETIMEDOUT;
4044 }
4045
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004046 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4047 assoc_data->bss->bssid, assoc_data->tries,
4048 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01004049 ieee80211_send_assoc(sdata);
4050
Johannes Berg30686bf2015-06-02 21:39:54 +02004051 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004052 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004053 assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004054 run_again(sdata, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01004055 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004056 assoc_data->timeout =
4057 round_jiffies_up(jiffies +
4058 IEEE80211_ASSOC_TIMEOUT_LONG);
4059 assoc_data->timeout_started = true;
4060 run_again(sdata, assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004061 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004062
4063 return 0;
4064}
4065
Johannes Berg1672c0e32013-01-29 15:02:27 +01004066void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4067 __le16 fc, bool acked)
4068{
4069 struct ieee80211_local *local = sdata->local;
4070
4071 sdata->u.mgd.status_fc = fc;
4072 sdata->u.mgd.status_acked = acked;
4073 sdata->u.mgd.status_received = true;
4074
4075 ieee80211_queue_work(&local->hw, &sdata->work);
4076}
4077
Johannes Berg1fa57d02010-06-10 10:21:32 +02004078void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02004079{
Johannes Berg60f8b392008-09-08 17:44:22 +02004080 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02004081 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02004082
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004083 sdata_lock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02004084
Johannes Berg1672c0e32013-01-29 15:02:27 +01004085 if (ifmgd->status_received) {
4086 __le16 fc = ifmgd->status_fc;
4087 bool status_acked = ifmgd->status_acked;
4088
4089 ifmgd->status_received = false;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004090 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004091 if (status_acked) {
Ilan Peer407879b2018-04-20 13:49:20 +03004092 if (ifmgd->auth_data->algorithm ==
4093 WLAN_AUTH_SAE)
4094 ifmgd->auth_data->timeout =
4095 jiffies +
4096 IEEE80211_AUTH_TIMEOUT_SAE;
4097 else
4098 ifmgd->auth_data->timeout =
4099 jiffies +
4100 IEEE80211_AUTH_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004101 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004102 } else {
4103 ifmgd->auth_data->timeout = jiffies - 1;
4104 }
Johannes Berg89afe612013-02-13 15:39:57 +01004105 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004106 } else if (ifmgd->assoc_data &&
4107 (ieee80211_is_assoc_req(fc) ||
4108 ieee80211_is_reassoc_req(fc))) {
4109 if (status_acked) {
4110 ifmgd->assoc_data->timeout =
4111 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004112 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004113 } else {
4114 ifmgd->assoc_data->timeout = jiffies - 1;
4115 }
Johannes Berg89afe612013-02-13 15:39:57 +01004116 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004117 }
4118 }
4119
Johannes Berg89afe612013-02-13 15:39:57 +01004120 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004121 time_after(jiffies, ifmgd->auth_data->timeout)) {
4122 if (ifmgd->auth_data->done) {
4123 /*
4124 * ok ... we waited for assoc but userspace didn't,
4125 * so let's just kill the auth data
4126 */
4127 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg46cad4b2015-08-15 22:39:54 +03004128 } else if (ieee80211_auth(sdata)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004129 u8 bssid[ETH_ALEN];
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004130 struct ieee80211_event event = {
4131 .type = MLME_EVENT,
4132 .u.mlme.data = AUTH_EVENT,
4133 .u.mlme.status = MLME_TIMEOUT,
4134 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004135
4136 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4137
4138 ieee80211_destroy_auth_data(sdata, false);
4139
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004140 cfg80211_auth_timeout(sdata->dev, bssid);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004141 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004142 }
Johannes Berg89afe612013-02-13 15:39:57 +01004143 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004144 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004145
Johannes Berg89afe612013-02-13 15:39:57 +01004146 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004147 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Alexander Bondar989c6502013-05-16 17:34:17 +03004148 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01004149 ieee80211_do_assoc(sdata)) {
Johannes Berg959867f2013-06-19 13:05:42 +02004150 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004151 struct ieee80211_event event = {
4152 .type = MLME_EVENT,
4153 .u.mlme.data = ASSOC_EVENT,
4154 .u.mlme.status = MLME_TIMEOUT,
4155 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004156
Johannes Berge6f462d2016-12-08 17:22:09 +01004157 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02004158 cfg80211_assoc_timeout(sdata->dev, bss);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004159 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004160 }
Johannes Berg89afe612013-02-13 15:39:57 +01004161 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004162 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004163
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02004164 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
Johannes Bergb291ba12009-07-10 15:29:03 +02004165 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03004166 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004167 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03004168
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004169 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004170
Johannes Berg30686bf2015-06-02 21:39:54 +02004171 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Ben Greear180205b2011-02-04 15:30:24 -08004172 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004173 else
Ben Greear180205b2011-02-04 15:30:24 -08004174 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004175
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004176 /* ACK received for nullfunc probing frame */
4177 if (!ifmgd->probe_send_count)
4178 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004179 else if (ifmgd->nullfunc_failed) {
4180 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004181 mlme_dbg(sdata,
4182 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4183 bssid, ifmgd->probe_send_count,
4184 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004185 ieee80211_mgd_probe_ap_send(sdata);
4186 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004187 mlme_dbg(sdata,
4188 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4189 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02004190 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004191 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4192 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004193 }
4194 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004195 run_again(sdata, ifmgd->probe_timeout);
Johannes Berg30686bf2015-06-02 21:39:54 +02004196 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004197 mlme_dbg(sdata,
4198 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4199 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02004200 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004201 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004202 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004203 mlme_dbg(sdata,
4204 "No probe response from AP %pM after %dms, try %d/%i\n",
4205 bssid, probe_wait_ms,
4206 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03004207 ieee80211_mgd_probe_ap_send(sdata);
4208 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02004209 /*
4210 * We actually lost the connection ... or did we?
4211 * Let's make sure!
4212 */
Johannes Berg89f774e2016-01-25 15:46:36 +02004213 mlme_dbg(sdata,
4214 "No probe response from AP %pM after %dms, disconnecting.\n",
4215 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004216
Johannes Berg95acac62011-07-12 12:30:59 +02004217 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004218 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02004219 }
4220 }
4221
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004222 sdata_unlock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02004223}
Johannes Berg0a51b272008-09-08 17:44:25 +02004224
Kees Cook34f11cd2017-10-16 16:35:49 -07004225static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004226{
4227 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004228 from_timer(sdata, t, u.mgd.bcn_mon_timer);
Luciano Coelho0c21e632014-10-08 09:48:39 +03004229 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004230
Luciano Coelho0c21e632014-10-08 09:48:39 +03004231 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004232 return;
4233
Johannes Berg682bd382013-01-29 13:13:50 +01004234 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004235 ieee80211_queue_work(&sdata->local->hw,
4236 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004237}
4238
Kees Cook34f11cd2017-10-16 16:35:49 -07004239static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004240{
4241 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004242 from_timer(sdata, t, u.mgd.conn_mon_timer);
Johannes Bergb291ba12009-07-10 15:29:03 +02004243 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4244 struct ieee80211_local *local = sdata->local;
4245
Luciano Coelho0c21e632014-10-08 09:48:39 +03004246 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004247 return;
4248
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04004249 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004250}
4251
4252static void ieee80211_sta_monitor_work(struct work_struct *work)
4253{
4254 struct ieee80211_sub_if_data *sdata =
4255 container_of(work, struct ieee80211_sub_if_data,
4256 u.mgd.monitor_work);
4257
4258 ieee80211_mgd_probe_ap(sdata, false);
4259}
4260
Johannes Berga1678f82008-09-11 00:01:47 +02004261static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4262{
Kalle Vaload935682009-04-19 08:47:19 +03004263 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02004264 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03004265
Johannes Bergb291ba12009-07-10 15:29:03 +02004266 /* let's probe the connection once */
Johannes Berg30686bf2015-06-02 21:39:54 +02004267 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Eliad Peller494f1fe2012-02-19 15:26:09 +02004268 ieee80211_queue_work(&sdata->local->hw,
4269 &sdata->u.mgd.monitor_work);
Kalle Vaload935682009-04-19 08:47:19 +03004270 }
Johannes Berga1678f82008-09-11 00:01:47 +02004271}
4272
Johannes Bergb8360ab2013-04-29 14:57:44 +02004273#ifdef CONFIG_PM
Johannes Berg1a1cb742014-03-19 09:55:55 +01004274void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4275{
4276 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4277 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4278
4279 sdata_lock(sdata);
4280
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004281 if (ifmgd->auth_data || ifmgd->assoc_data) {
4282 const u8 *bssid = ifmgd->auth_data ?
4283 ifmgd->auth_data->bss->bssid :
4284 ifmgd->assoc_data->bss->bssid;
4285
Johannes Berg1a1cb742014-03-19 09:55:55 +01004286 /*
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004287 * If we are trying to authenticate / associate while suspending,
4288 * cfg80211 won't know and won't actually abort those attempts,
4289 * thus we need to do that ourselves.
Johannes Berg1a1cb742014-03-19 09:55:55 +01004290 */
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004291 ieee80211_send_deauth_disassoc(sdata, bssid,
Johannes Berg1a1cb742014-03-19 09:55:55 +01004292 IEEE80211_STYPE_DEAUTH,
4293 WLAN_REASON_DEAUTH_LEAVING,
4294 false, frame_buf);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004295 if (ifmgd->assoc_data)
Johannes Berge6f462d2016-12-08 17:22:09 +01004296 ieee80211_destroy_assoc_data(sdata, false, true);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004297 if (ifmgd->auth_data)
4298 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg1a1cb742014-03-19 09:55:55 +01004299 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4300 IEEE80211_DEAUTH_FRAME_LEN);
4301 }
4302
Johannes Bergbe72afe2015-03-01 09:10:03 +02004303 /* This is a bit of a hack - we should find a better and more generic
4304 * solution to this. Normally when suspending, cfg80211 will in fact
4305 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4306 * auth (not so important) or assoc (this is the problem) process.
4307 *
4308 * As a consequence, it can happen that we are in the process of both
4309 * associating and suspending, and receive an association response
4310 * after cfg80211 has checked if it needs to disconnect, but before
4311 * we actually set the flag to drop incoming frames. This will then
4312 * cause the workqueue flush to process the association response in
4313 * the suspend, resulting in a successful association just before it
4314 * tries to remove the interface from the driver, which now though
4315 * has a channel context assigned ... this results in issues.
4316 *
4317 * To work around this (for now) simply deauth here again if we're
4318 * now connected.
4319 */
4320 if (ifmgd->associated && !sdata->local->wowlan) {
4321 u8 bssid[ETH_ALEN];
4322 struct cfg80211_deauth_request req = {
4323 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4324 .bssid = bssid,
4325 };
4326
4327 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4328 ieee80211_mgd_deauth(sdata, &req);
4329 }
4330
Johannes Berg1a1cb742014-03-19 09:55:55 +01004331 sdata_unlock(sdata);
4332}
4333
Johannes Bergb8360ab2013-04-29 14:57:44 +02004334void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4335{
4336 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4337
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004338 sdata_lock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004339 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004340 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004341 return;
4342 }
4343
4344 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4345 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4346 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4347 ieee80211_sta_connection_lost(sdata,
4348 ifmgd->associated->bssid,
4349 WLAN_REASON_UNSPECIFIED,
4350 true);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004351 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004352 return;
4353 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004354 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004355}
4356#endif
4357
Johannes Berg9c6bd792008-09-11 00:01:52 +02004358/* interface setup */
4359void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4360{
Johannes Berg46900292009-02-15 12:44:28 +01004361 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004362
Johannes Berg46900292009-02-15 12:44:28 +01004363 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004364 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01004365 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004366 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4367 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02004368 INIT_WORK(&ifmgd->csa_connection_drop_work,
4369 ieee80211_csa_connection_drop_work);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03004370 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03004371 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4372 ieee80211_tdls_peer_del_work);
Kees Cook34f11cd2017-10-16 16:35:49 -07004373 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4374 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4375 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4376 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
Johannes Berg02219b32014-10-07 10:38:50 +03004377 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4378 ieee80211_sta_handle_tspec_ac_params_wk);
Johannes Berg9c6bd792008-09-11 00:01:52 +02004379
Johannes Bergab1faea2009-07-01 21:41:17 +02004380 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05304381 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02004382 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4383 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01004384 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02004385
Eliad Peller0d8614b2014-09-10 14:07:36 +03004386 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
Johannes Berg0f782312009-12-01 13:37:02 +01004387 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4388 else
4389 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02004390
4391 /* Setup TDLS data */
4392 spin_lock_init(&ifmgd->teardown_lock);
4393 ifmgd->teardown_skb = NULL;
4394 ifmgd->orig_teardown_skb = NULL;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004395}
4396
4397/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02004398void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4399{
Johannes Berg31ee67a2012-07-06 21:18:24 +02004400 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02004401
4402 /* Restart STA timers */
4403 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07004404 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4405 if (ieee80211_sdata_running(sdata))
4406 ieee80211_restart_sta_timer(sdata);
4407 }
Johannes Berga1678f82008-09-11 00:01:47 +02004408 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02004409}
Johannes Berg10f644a2009-04-16 13:17:25 +02004410
Johannes Bergf2d9d272012-11-22 14:11:39 +01004411static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4412 struct cfg80211_bss *cbss)
4413{
4414 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4415 const u8 *ht_cap_ie, *vht_cap_ie;
4416 const struct ieee80211_ht_cap *ht_cap;
4417 const struct ieee80211_vht_cap *vht_cap;
4418 u8 chains = 1;
4419
4420 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4421 return chains;
4422
Johannes Berg9caf0362012-11-29 01:25:20 +01004423 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004424 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4425 ht_cap = (void *)(ht_cap_ie + 2);
4426 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4427 /*
4428 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4429 * "Tx Unequal Modulation Supported" fields.
4430 */
4431 }
4432
4433 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4434 return chains;
4435
Johannes Berg9caf0362012-11-29 01:25:20 +01004436 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004437 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4438 u8 nss;
4439 u16 tx_mcs_map;
4440
4441 vht_cap = (void *)(vht_cap_ie + 2);
4442 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4443 for (nss = 8; nss > 0; nss--) {
4444 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4445 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4446 break;
4447 }
4448 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4449 chains = max(chains, nss);
4450 }
4451
4452 return chains;
4453}
4454
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004455static bool
4456ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4457 const struct ieee80211_he_operation *he_op)
4458{
4459 const struct ieee80211_sta_he_cap *sta_he_cap =
4460 ieee80211_get_he_sta_cap(sband);
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004461 u16 ap_min_req_set;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004462 int i;
4463
4464 if (!sta_he_cap || !he_op)
4465 return false;
4466
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004467 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4468
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004469 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4470 for (i = 0; i < 3; i++) {
4471 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4472 &sta_he_cap->he_mcs_nss_supp;
4473 u16 sta_mcs_map_rx =
4474 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4475 u16 sta_mcs_map_tx =
4476 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4477 u8 nss;
4478 bool verified = true;
4479
4480 /*
4481 * For each band there is a maximum of 8 spatial streams
4482 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4483 * of 2 bits per NSS (1-8), with the values defined in enum
4484 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4485 * capabilities aren't less than the AP's minimum requirements
4486 * for this HE BSS per SS.
4487 * It is enough to find one such band that meets the reqs.
4488 */
4489 for (nss = 8; nss > 0; nss--) {
4490 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4491 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4492 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4493
4494 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4495 continue;
4496
4497 /*
4498 * Make sure the HE AP doesn't require MCSs that aren't
4499 * supported by the client
4500 */
4501 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4502 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4503 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4504 verified = false;
4505 break;
4506 }
4507 }
4508
4509 if (verified)
4510 return true;
4511 }
4512
4513 /* If here, STA doesn't meet AP's HE min requirements */
4514 return false;
4515}
4516
Johannes Bergb17166a2012-07-27 11:41:27 +02004517static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4518 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01004519{
4520 struct ieee80211_local *local = sdata->local;
4521 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Peller53b954e2014-07-24 11:20:05 +03004522 const struct ieee80211_ht_cap *ht_cap = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004523 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004524 const struct ieee80211_vht_operation *vht_oper = NULL;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004525 const struct ieee80211_he_operation *he_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004526 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01004527 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004528 int ret;
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004529 u32 i;
4530 bool have_80mhz;
Johannes Berga1cf7752012-03-08 15:02:07 +01004531
Johannes Berg24398e32012-03-28 10:58:36 +02004532 sband = local->hw.wiphy->bands[cbss->channel->band];
4533
Johannes Bergf2d9d272012-11-22 14:11:39 +01004534 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4535 IEEE80211_STA_DISABLE_80P80MHZ |
4536 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02004537
Johannes Berg9caf0362012-11-29 01:25:20 +01004538 rcu_read_lock();
4539
Johannes Bergf2d9d272012-11-22 14:11:39 +01004540 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
4541 sband->ht_cap.ht_supported) {
Eliad Peller53b954e2014-07-24 11:20:05 +03004542 const u8 *ht_oper_ie, *ht_cap_ie;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004543
Johannes Berg9caf0362012-11-29 01:25:20 +01004544 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02004545 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4546 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6eff2013-02-07 23:33:32 +01004547
Eliad Peller53b954e2014-07-24 11:20:05 +03004548 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4549 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4550 ht_cap = (void *)(ht_cap_ie + 2);
4551
4552 if (!ht_cap) {
Johannes Berg08e6eff2013-02-07 23:33:32 +01004553 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4554 ht_oper = NULL;
4555 }
Johannes Berg24398e32012-03-28 10:58:36 +02004556 }
4557
Johannes Bergf2d9d272012-11-22 14:11:39 +01004558 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4559 sband->vht_cap.vht_supported) {
Johannes Berg08e6eff2013-02-07 23:33:32 +01004560 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004561
Johannes Berg9caf0362012-11-29 01:25:20 +01004562 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4563 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004564 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4565 vht_oper = (void *)(vht_oper_ie + 2);
4566 if (vht_oper && !ht_oper) {
4567 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004568 sdata_info(sdata,
Johannes Bergf2d9d272012-11-22 14:11:39 +01004569 "AP advertised VHT without HT, disabling both\n");
Johannes Bergcb145022013-02-07 20:41:50 +01004570 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4571 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg24398e32012-03-28 10:58:36 +02004572 }
Johannes Berg08e6eff2013-02-07 23:33:32 +01004573
4574 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4575 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4576 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4577 vht_oper = NULL;
4578 }
Johannes Berg24398e32012-03-28 10:58:36 +02004579 }
4580
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004581 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
4582 ieee80211_get_he_sta_cap(sband)) {
4583 const struct cfg80211_bss_ies *ies;
4584 const u8 *he_oper_ie;
4585
4586 ies = rcu_dereference(cbss->ies);
4587 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
4588 ies->data, ies->len);
4589 if (he_oper_ie &&
4590 he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
4591 he_oper = (void *)(he_oper_ie + 3);
4592 else
4593 he_oper = NULL;
4594
Johannes Bergf0c04072018-06-29 09:51:39 +02004595 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004596 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4597 }
4598
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004599 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4600 have_80mhz = false;
4601 for (i = 0; i < sband->n_channels; i++) {
4602 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4603 IEEE80211_CHAN_NO_80MHZ))
4604 continue;
4605
4606 have_80mhz = true;
4607 break;
4608 }
4609
4610 if (!have_80mhz)
4611 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4612
Johannes Bergf2d9d272012-11-22 14:11:39 +01004613 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4614 cbss->channel,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004615 ht_oper, vht_oper, he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +02004616 &chandef, false);
Johannes Berg04ecd252012-09-11 14:34:12 +02004617
Johannes Bergf2d9d272012-11-22 14:11:39 +01004618 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4619 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02004620
Johannes Berg9caf0362012-11-29 01:25:20 +01004621 rcu_read_unlock();
4622
Johannes Berg04ecd252012-09-11 14:34:12 +02004623 /* will change later if needed */
4624 sdata->smps_mode = IEEE80211_SMPS_OFF;
4625
Johannes Berg34a37402013-12-18 09:43:33 +01004626 mutex_lock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004627 /*
4628 * If this fails (possibly due to channel context sharing
4629 * on incompatible channels, e.g. 80+80 and 160 sharing the
4630 * same control channel) try to use a smaller bandwidth.
4631 */
4632 ret = ieee80211_vif_use_channel(sdata, &chandef,
4633 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich0418a442013-05-16 13:00:31 +02004634
4635 /* don't downgrade for 5 and 10 MHz channels, though. */
4636 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4637 chandef.width == NL80211_CHAN_WIDTH_10)
Johannes Berg34a37402013-12-18 09:43:33 +01004638 goto out;
Simon Wunderlich0418a442013-05-16 13:00:31 +02004639
Johannes Bergd601cd82013-02-07 20:54:51 +01004640 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02004641 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01004642 ret = ieee80211_vif_use_channel(sdata, &chandef,
4643 IEEE80211_CHANCTX_SHARED);
4644 }
Johannes Berg34a37402013-12-18 09:43:33 +01004645 out:
4646 mutex_unlock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004647 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02004648}
4649
4650static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004651 struct cfg80211_bss *cbss, bool assoc,
4652 bool override)
Johannes Bergb17166a2012-07-27 11:41:27 +02004653{
4654 struct ieee80211_local *local = sdata->local;
4655 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4656 struct ieee80211_bss *bss = (void *)cbss->priv;
4657 struct sta_info *new_sta = NULL;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004658 struct ieee80211_supported_band *sband;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004659 bool have_sta = false;
Johannes Bergb17166a2012-07-27 11:41:27 +02004660 int err;
4661
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004662 sband = local->hw.wiphy->bands[cbss->channel->band];
4663
Johannes Bergb17166a2012-07-27 11:41:27 +02004664 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4665 return -EINVAL;
4666
Luca Coelhof8860ce2017-05-02 17:56:21 +03004667 /* If a reconfig is happening, bail out */
4668 if (local->in_reconfig)
4669 return -EBUSY;
4670
Johannes Bergb17166a2012-07-27 11:41:27 +02004671 if (assoc) {
4672 rcu_read_lock();
4673 have_sta = sta_info_get(sdata, cbss->bssid);
4674 rcu_read_unlock();
4675 }
4676
4677 if (!have_sta) {
4678 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4679 if (!new_sta)
4680 return -ENOMEM;
4681 }
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004682
Johannes Bergc87905b2017-06-10 13:52:43 +03004683 /*
4684 * Set up the information for the new channel before setting the
4685 * new channel. We can't - completely race-free - change the basic
4686 * rates bitmap and the channel (sband) that it refers to, but if
4687 * we set it up before we at least avoid calling into the driver's
4688 * bss_info_changed() method with invalid information (since we do
4689 * call that from changing the channel - only for IDLE and perhaps
4690 * some others, but ...).
4691 *
4692 * So to avoid that, just set up all the new information before the
4693 * channel, but tell the driver to apply it only afterwards, since
4694 * it might need the new channel for that.
4695 */
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004696 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004697 u32 rates = 0, basic_rates = 0;
4698 bool have_higher_than_11mbit;
4699 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004700 const struct cfg80211_bss_ies *ies;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004701 int shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004702
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004703 ieee80211_get_rates(sband, bss->supp_rates,
4704 bss->supp_rates_len,
4705 &rates, &basic_rates,
4706 &have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02004707 &min_rate, &min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03004708 shift);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004709
4710 /*
4711 * This used to be a workaround for basic rates missing
4712 * in the association response frame. Now that we no
4713 * longer use the basic rates from there, it probably
4714 * doesn't happen any more, but keep the workaround so
4715 * in case some *other* APs are buggy in different ways
4716 * we can connect -- with a warning.
4717 */
4718 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004719 sdata_info(sdata,
4720 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004721 basic_rates = BIT(min_rate_index);
4722 }
4723
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004724 new_sta->sta.supp_rates[cbss->channel->band] = rates;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004725 sdata->vif.bss_conf.basic_rates = basic_rates;
4726
4727 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg57fbcce2016-04-12 15:56:15 +02004728 if (cbss->channel->band == NL80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004729 have_higher_than_11mbit)
4730 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
4731 else
4732 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
4733
4734 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
4735
Johannes Berg8c358bc2012-05-22 22:13:05 +02004736 /* set timing information */
4737 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004738 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01004739 ies = rcu_dereference(cbss->beacon_ies);
4740 if (ies) {
4741 const u8 *tim_ie;
4742
4743 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4744 sdata->vif.bss_conf.sync_device_ts =
4745 bss->device_ts_beacon;
4746 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4747 ies->data, ies->len);
4748 if (tim_ie && tim_ie[1] >= 2)
4749 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
4750 else
4751 sdata->vif.bss_conf.sync_dtim_count = 0;
Johannes Berg30686bf2015-06-02 21:39:54 +02004752 } else if (!ieee80211_hw_check(&sdata->local->hw,
4753 TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01004754 ies = rcu_dereference(cbss->proberesp_ies);
4755 /* must be non-NULL since beacon IEs were NULL */
4756 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4757 sdata->vif.bss_conf.sync_device_ts =
4758 bss->device_ts_presp;
4759 sdata->vif.bss_conf.sync_dtim_count = 0;
4760 } else {
4761 sdata->vif.bss_conf.sync_tsf = 0;
4762 sdata->vif.bss_conf.sync_device_ts = 0;
4763 sdata->vif.bss_conf.sync_dtim_count = 0;
4764 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01004765 rcu_read_unlock();
Johannes Bergc87905b2017-06-10 13:52:43 +03004766 }
Johannes Berg8c358bc2012-05-22 22:13:05 +02004767
Johannes Bergc87905b2017-06-10 13:52:43 +03004768 if (new_sta || override) {
4769 err = ieee80211_prep_channel(sdata, cbss);
4770 if (err) {
4771 if (new_sta)
4772 sta_info_free(local, new_sta);
4773 return -EINVAL;
4774 }
4775 }
4776
4777 if (new_sta) {
4778 /*
4779 * tell driver about BSSID, basic rates and timing
4780 * this was set up above, before setting the channel
4781 */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004782 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02004783 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
4784 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01004785
4786 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004787 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01004788
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004789 err = sta_info_insert(new_sta);
4790 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01004791 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004792 sdata_info(sdata,
4793 "failed to insert STA entry for the AP (error %d)\n",
4794 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01004795 return err;
4796 }
4797 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00004798 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01004799
David Spinadel7d830a12015-03-17 19:58:38 +02004800 /* Cancel scan to ensure that nothing interferes with connection */
4801 if (local->scanning)
4802 ieee80211_scan_cancel(local);
4803
Johannes Berga1cf7752012-03-08 15:02:07 +01004804 return 0;
4805}
4806
Johannes Berg77fdaa12009-07-07 03:45:17 +02004807/* config hooks */
4808int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
4809 struct cfg80211_auth_request *req)
4810{
Johannes Berg66e67e42012-01-20 13:55:27 +01004811 struct ieee80211_local *local = sdata->local;
4812 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4813 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004814 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01004815 int err;
4816
4817 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02004818
4819 switch (req->auth_type) {
4820 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4821 auth_alg = WLAN_AUTH_OPEN;
4822 break;
4823 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01004824 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02004825 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004826 auth_alg = WLAN_AUTH_SHARED_KEY;
4827 break;
4828 case NL80211_AUTHTYPE_FT:
4829 auth_alg = WLAN_AUTH_FT;
4830 break;
4831 case NL80211_AUTHTYPE_NETWORK_EAP:
4832 auth_alg = WLAN_AUTH_LEAP;
4833 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004834 case NL80211_AUTHTYPE_SAE:
4835 auth_alg = WLAN_AUTH_SAE;
4836 break;
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03004837 case NL80211_AUTHTYPE_FILS_SK:
4838 auth_alg = WLAN_AUTH_FILS_SK;
4839 break;
4840 case NL80211_AUTHTYPE_FILS_SK_PFS:
4841 auth_alg = WLAN_AUTH_FILS_SK_PFS;
4842 break;
4843 case NL80211_AUTHTYPE_FILS_PK:
4844 auth_alg = WLAN_AUTH_FILS_PK;
4845 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004846 default:
4847 return -EOPNOTSUPP;
4848 }
4849
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004850 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004851 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01004852 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004853 return -ENOMEM;
4854
Johannes Berg66e67e42012-01-20 13:55:27 +01004855 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004856
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004857 if (req->auth_data_len >= 4) {
Jouni Malinen6ec63612016-10-27 00:41:59 +03004858 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
4859 __le16 *pos = (__le16 *) req->auth_data;
4860
4861 auth_data->sae_trans = le16_to_cpu(pos[0]);
4862 auth_data->sae_status = le16_to_cpu(pos[1]);
4863 }
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004864 memcpy(auth_data->data, req->auth_data + 4,
4865 req->auth_data_len - 4);
4866 auth_data->data_len += req->auth_data_len - 4;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004867 }
4868
Johannes Berg77fdaa12009-07-07 03:45:17 +02004869 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004870 memcpy(&auth_data->data[auth_data->data_len],
4871 req->ie, req->ie_len);
4872 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004873 }
4874
Johannes Bergfffd0932009-07-08 14:22:54 +02004875 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004876 auth_data->key_len = req->key_len;
4877 auth_data->key_idx = req->key_idx;
4878 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02004879 }
4880
Johannes Berg66e67e42012-01-20 13:55:27 +01004881 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004882
Johannes Berg66e67e42012-01-20 13:55:27 +01004883 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01004884
Johannes Berg66e67e42012-01-20 13:55:27 +01004885 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
4886 ifmgd->assoc_data) {
4887 err = -EBUSY;
4888 goto err_free;
4889 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004890
Johannes Berg66e67e42012-01-20 13:55:27 +01004891 if (ifmgd->auth_data)
4892 ieee80211_destroy_auth_data(sdata, false);
Guy Eilam2a33bee2011-08-17 15:18:15 +03004893
Johannes Berg66e67e42012-01-20 13:55:27 +01004894 /* prep auth_data so we don't go into idle on disassoc */
4895 ifmgd->auth_data = auth_data;
4896
Johannes Berg7b119dc2013-04-10 21:38:36 +02004897 if (ifmgd->associated) {
4898 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4899
Johannes Berg89f774e2016-01-25 15:46:36 +02004900 sdata_info(sdata,
4901 "disconnect from AP %pM for new auth to %pM\n",
4902 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02004903 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4904 WLAN_REASON_UNSPECIFIED,
4905 false, frame_buf);
4906
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004907 ieee80211_report_disconnect(sdata, frame_buf,
4908 sizeof(frame_buf), true,
4909 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02004910 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004911
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004912 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004913
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004914 err = ieee80211_prep_connection(sdata, req->bss, false, false);
Johannes Berga1cf7752012-03-08 15:02:07 +01004915 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01004916 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004917
Johannes Berg46cad4b2015-08-15 22:39:54 +03004918 err = ieee80211_auth(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004919 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004920 sta_info_destroy_addr(sdata, req->bss->bssid);
4921 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004922 }
4923
Johannes Berg66e67e42012-01-20 13:55:27 +01004924 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01004925 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004926 return 0;
Johannes Berge5b900d2010-07-29 16:08:55 +02004927
Johannes Berg66e67e42012-01-20 13:55:27 +01004928 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08004929 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03004930 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01004931 ifmgd->auth_data = NULL;
Michal Kaziord01f8582015-06-03 08:36:13 +02004932 mutex_lock(&sdata->local->mtx);
4933 ieee80211_vif_release_channel(sdata);
4934 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01004935 err_free:
4936 kfree(auth_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01004937 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004938}
4939
Johannes Berg77fdaa12009-07-07 03:45:17 +02004940int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
4941 struct cfg80211_assoc_request *req)
4942{
Johannes Berg66e67e42012-01-20 13:55:27 +01004943 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004944 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004945 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01004946 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004947 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01004948 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01004949 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004950 int i, err;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004951 bool override = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004952
Johannes Berg66e67e42012-01-20 13:55:27 +01004953 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
4954 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01004955 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004956
Johannes Berg9caf0362012-11-29 01:25:20 +01004957 rcu_read_lock();
4958 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
4959 if (!ssidie) {
4960 rcu_read_unlock();
4961 kfree(assoc_data);
4962 return -EINVAL;
4963 }
4964 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
4965 assoc_data->ssid_len = ssidie[1];
4966 rcu_read_unlock();
4967
Johannes Berg7b119dc2013-04-10 21:38:36 +02004968 if (ifmgd->associated) {
4969 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4970
Johannes Berg89f774e2016-01-25 15:46:36 +02004971 sdata_info(sdata,
4972 "disconnect from AP %pM for new assoc to %pM\n",
4973 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02004974 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4975 WLAN_REASON_UNSPECIFIED,
4976 false, frame_buf);
4977
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004978 ieee80211_report_disconnect(sdata, frame_buf,
4979 sizeof(frame_buf), true,
4980 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02004981 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004982
4983 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
4984 err = -EBUSY;
4985 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004986 }
4987
Johannes Berg66e67e42012-01-20 13:55:27 +01004988 if (ifmgd->assoc_data) {
4989 err = -EBUSY;
4990 goto err_free;
4991 }
4992
4993 if (ifmgd->auth_data) {
4994 bool match;
4995
4996 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00004997 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004998 ieee80211_destroy_auth_data(sdata, match);
4999 }
5000
5001 /* prepare assoc data */
Johannes Berg095d81c2013-10-15 12:25:07 +02005002
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03005003 ifmgd->beacon_crc_valid = false;
5004
Johannes Berg095d81c2013-10-15 12:25:07 +02005005 assoc_data->wmm = bss->wmm_used &&
5006 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg095d81c2013-10-15 12:25:07 +02005007
Johannes Bergde5036a2012-03-08 15:02:03 +01005008 /*
5009 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5010 * We still associate in non-HT mode (11a/b/g) if any one of these
5011 * ciphers is configured as pairwise.
5012 * We can set this to true for non-11n hardware, that'll be checked
5013 * separately along with the peer capabilities.
5014 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02005015 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02005016 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5017 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02005018 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01005019 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005020 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005021 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Johannes Berg1c4cb922012-05-30 15:57:00 +02005022 netdev_info(sdata->dev,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005023 "disabling HE/HT/VHT due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005024 }
5025 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005026
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005027 /* Also disable HT if we don't support it or the AP doesn't use WMM */
5028 sband = local->hw.wiphy->bands[req->bss->channel->band];
5029 if (!sband->ht_cap.ht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005030 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5031 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Berga8243b72012-11-22 14:32:09 +01005032 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005033 if (!bss->wmm_used &&
5034 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005035 netdev_info(sdata->dev,
5036 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005037 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005038
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005039 /* disable VHT if we don't support it or the AP doesn't use WMM */
5040 if (!sband->vht_cap.vht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005041 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5042 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005043 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005044 if (!bss->wmm_used &&
5045 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005046 netdev_info(sdata->dev,
5047 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005048 }
5049
Ben Greearef96a8422011-11-18 11:32:00 -08005050 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5051 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5052 sizeof(ifmgd->ht_capa_mask));
5053
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01005054 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5055 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5056 sizeof(ifmgd->vht_capa_mask));
5057
Johannes Berg77fdaa12009-07-07 03:45:17 +02005058 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005059 memcpy(assoc_data->ie, req->ie, req->ie_len);
5060 assoc_data->ie_len = req->ie_len;
5061 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005062
Jouni Malinen39404fe2016-10-27 00:42:05 +03005063 if (req->fils_kek) {
5064 /* should already be checked in cfg80211 - so warn */
5065 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5066 err = -EINVAL;
5067 goto err_free;
5068 }
5069 memcpy(assoc_data->fils_kek, req->fils_kek,
5070 req->fils_kek_len);
5071 assoc_data->fils_kek_len = req->fils_kek_len;
5072 }
5073
5074 if (req->fils_nonces)
5075 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5076 2 * FILS_NONCE_LEN);
5077
Johannes Berg66e67e42012-01-20 13:55:27 +01005078 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01005079
Johannes Bergaf6b6372009-12-23 13:15:35 +01005080 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5081 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02005082 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005083 else
Johannes Berg04ecd252012-09-11 14:34:12 +02005084 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005085 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02005086 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005087
Johannes Berg66e67e42012-01-20 13:55:27 +01005088 assoc_data->capability = req->bss->capability;
Johannes Berg66e67e42012-01-20 13:55:27 +01005089 assoc_data->supp_rates = bss->supp_rates;
5090 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02005091
Johannes Berg9caf0362012-11-29 01:25:20 +01005092 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02005093 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5094 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5095 assoc_data->ap_ht_param =
5096 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5097 else
Johannes Berga8243b72012-11-22 14:32:09 +01005098 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005099 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5100 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5101 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5102 sizeof(struct ieee80211_vht_cap));
5103 else
5104 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01005105 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01005106
Johannes Berg848955c2014-11-11 12:48:42 +01005107 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02005108 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
Johannes Berg848955c2014-11-11 12:48:42 +01005109 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5110 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5111
Kalle Valoab133152010-01-12 10:42:31 +02005112 if (bss->wmm_used && bss->uapsd_supported &&
Johannes Berg848955c2014-11-11 12:48:42 +01005113 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01005114 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02005115 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5116 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01005117 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02005118 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5119 }
5120
Johannes Berg77fdaa12009-07-07 03:45:17 +02005121 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01005122 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005123
5124 if (req->use_mfp) {
5125 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5126 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5127 } else {
5128 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5129 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5130 }
5131
Assaf Krausscd2f5dd2014-09-03 15:25:02 +03005132 if (req->flags & ASSOC_REQ_USE_RRM)
5133 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5134 else
5135 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5136
Johannes Berg77fdaa12009-07-07 03:45:17 +02005137 if (req->crypto.control_port)
5138 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5139 else
5140 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5141
Johannes Berga621fa42010-08-27 14:26:54 +03005142 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5143 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05005144 sdata->control_port_over_nl80211 =
5145 req->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02005146 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5147 sdata->vif.type);
Johannes Berga621fa42010-08-27 14:26:54 +03005148
Johannes Berg66e67e42012-01-20 13:55:27 +01005149 /* kick off associate process */
5150
5151 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02005152 ifmgd->dtim_period = 0;
Alexander Bondar989c6502013-05-16 17:34:17 +03005153 ifmgd->have_beacon = false;
Johannes Berg66e67e42012-01-20 13:55:27 +01005154
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005155 /* override HT/VHT configuration only if the AP and we support it */
5156 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5157 struct ieee80211_sta_ht_cap sta_ht_cap;
5158
5159 if (req->flags & ASSOC_REQ_DISABLE_HT)
5160 override = true;
5161
5162 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5163 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5164
5165 /* check for 40 MHz disable override */
5166 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5167 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5168 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5169 override = true;
5170
5171 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5172 req->flags & ASSOC_REQ_DISABLE_VHT)
5173 override = true;
5174 }
5175
5176 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5177 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5178 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5179 }
5180
5181 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5182 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5183
5184 err = ieee80211_prep_connection(sdata, req->bss, true, override);
Johannes Berga1cf7752012-03-08 15:02:07 +01005185 if (err)
5186 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01005187
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005188 rcu_read_lock();
5189 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02005190
Johannes Berg30686bf2015-06-02 21:39:54 +02005191 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005192 !beacon_ies) {
5193 /*
5194 * Wait up to one beacon interval ...
5195 * should this be more if we miss one?
5196 */
5197 sdata_info(sdata, "waiting for beacon from %pM\n",
5198 ifmgd->bssid);
5199 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01005200 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005201 assoc_data->need_beacon = true;
5202 } else if (beacon_ies) {
5203 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
5204 beacon_ies->data,
5205 beacon_ies->len);
Johannes Bergef429da2013-02-05 17:48:40 +01005206 u8 dtim_count = 0;
5207
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005208 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
5209 const struct ieee80211_tim_ie *tim;
5210 tim = (void *)(tim_ie + 2);
5211 ifmgd->dtim_period = tim->dtim_period;
Johannes Bergef429da2013-02-05 17:48:40 +01005212 dtim_count = tim->dtim_count;
Johannes Berg826262c2012-12-10 16:38:14 +02005213 }
Alexander Bondar989c6502013-05-16 17:34:17 +03005214 ifmgd->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005215 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005216 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01005217
Johannes Berg30686bf2015-06-02 21:39:54 +02005218 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005219 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5220 sdata->vif.bss_conf.sync_device_ts =
5221 bss->device_ts_beacon;
5222 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5223 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005224 } else {
5225 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005226 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005227 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005228 rcu_read_unlock();
5229
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005230 run_again(sdata, assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01005231
Paul Stewartfcff4f12012-02-23 17:59:53 -08005232 if (bss->corrupt_data) {
5233 char *corrupt_type = "data";
5234 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5235 if (bss->corrupt_data &
5236 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5237 corrupt_type = "beacon and probe response";
5238 else
5239 corrupt_type = "beacon";
5240 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5241 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005242 sdata_info(sdata, "associating with AP with corrupt %s\n",
5243 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08005244 }
5245
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005246 return 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01005247 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005248 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005249 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005250 ifmgd->assoc_data = NULL;
5251 err_free:
5252 kfree(assoc_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005253 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005254}
5255
5256int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005257 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005258{
5259 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005260 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005261 bool tx = !req->local_state_change;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005262
Johannes Bergc9c3a062014-03-19 09:11:19 +01005263 if (ifmgd->auth_data &&
5264 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5265 sdata_info(sdata,
5266 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5267 req->bssid, req->reason_code,
5268 ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005269
Ilan Peerd4e36e52018-04-20 13:49:25 +03005270 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg37ad3882012-02-24 13:50:54 +01005271 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5272 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005273 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01005274 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01005275 ieee80211_destroy_auth_data(sdata, false);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005276 ieee80211_report_disconnect(sdata, frame_buf,
5277 sizeof(frame_buf), true,
5278 req->reason_code);
Johannes Berg86552012012-10-29 09:46:31 +01005279
Johannes Bergc9c3a062014-03-19 09:11:19 +01005280 return 0;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03005281 }
5282
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005283 if (ifmgd->assoc_data &&
5284 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5285 sdata_info(sdata,
5286 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5287 req->bssid, req->reason_code,
5288 ieee80211_get_reason_code_string(req->reason_code));
5289
Ilan Peerd4e36e52018-04-20 13:49:25 +03005290 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005291 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5292 IEEE80211_STYPE_DEAUTH,
5293 req->reason_code, tx,
5294 frame_buf);
Johannes Berge6f462d2016-12-08 17:22:09 +01005295 ieee80211_destroy_assoc_data(sdata, false, true);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005296 ieee80211_report_disconnect(sdata, frame_buf,
5297 sizeof(frame_buf), true,
5298 req->reason_code);
5299 return 0;
5300 }
5301
Johannes Berg86552012012-10-29 09:46:31 +01005302 if (ifmgd->associated &&
5303 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
Johannes Bergc9c3a062014-03-19 09:11:19 +01005304 sdata_info(sdata,
5305 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5306 req->bssid, req->reason_code,
5307 ieee80211_get_reason_code_string(req->reason_code));
5308
Johannes Berg86552012012-10-29 09:46:31 +01005309 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5310 req->reason_code, tx, frame_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005311 ieee80211_report_disconnect(sdata, frame_buf,
5312 sizeof(frame_buf), true,
5313 req->reason_code);
Johannes Bergc9c3a062014-03-19 09:11:19 +01005314 return 0;
5315 }
Johannes Berg86552012012-10-29 09:46:31 +01005316
Johannes Bergc9c3a062014-03-19 09:11:19 +01005317 return -ENOTCONN;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005318}
5319
5320int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005321 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005322{
5323 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07005324 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005325 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02005326
Johannes Berg8d8b2612009-07-25 11:58:36 +02005327 /*
5328 * cfg80211 should catch this ... but it's racy since
5329 * we can receive a disassoc frame, process it, hand it
5330 * to cfg80211 while that's in a locked section already
5331 * trying to tell us that the user wants to disconnect.
5332 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005333 if (ifmgd->associated != req->bss)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005334 return -ENOLINK;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005335
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005336 sdata_info(sdata,
Calvin Owensdfa1ad22014-02-11 12:36:24 -06005337 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5338 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005339
Jouni Malinene69e95d2010-03-29 23:29:31 -07005340 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01005341 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5342 req->reason_code, !req->local_state_change,
5343 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005344
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005345 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5346 req->reason_code);
Johannes Bergbc83b682009-11-29 12:19:06 +01005347
Johannes Berg77fdaa12009-07-07 03:45:17 +02005348 return 0;
5349}
Jouni Malinen026331c2010-02-15 12:53:10 +02005350
Eliad Pellerafa762f2012-04-23 14:45:15 +03005351void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005352{
5353 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5354
Ben Greear49921852013-02-20 09:41:09 -08005355 /*
5356 * Make sure some work items will not run after this,
5357 * they will not do anything but might not have been
5358 * cancelled when disconnecting.
5359 */
5360 cancel_work_sync(&ifmgd->monitor_work);
5361 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5362 cancel_work_sync(&ifmgd->request_smps_work);
5363 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5364 cancel_work_sync(&ifmgd->chswitch_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03005365 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
Ben Greear49921852013-02-20 09:41:09 -08005366
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005367 sdata_lock(sdata);
Johannes Berg959867f2013-06-19 13:05:42 +02005368 if (ifmgd->assoc_data) {
5369 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Johannes Berge6f462d2016-12-08 17:22:09 +01005370 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02005371 cfg80211_assoc_timeout(sdata->dev, bss);
5372 }
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005373 if (ifmgd->auth_data)
5374 ieee80211_destroy_auth_data(sdata, false);
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005375 spin_lock_bh(&ifmgd->teardown_lock);
5376 if (ifmgd->teardown_skb) {
5377 kfree_skb(ifmgd->teardown_skb);
5378 ifmgd->teardown_skb = NULL;
5379 ifmgd->orig_teardown_skb = NULL;
5380 }
5381 spin_unlock_bh(&ifmgd->teardown_lock);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005382 del_timer_sync(&ifmgd->timer);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005383 sdata_unlock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005384}
5385
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005386void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5387 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005388 s32 rssi_level,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005389 gfp_t gfp)
5390{
5391 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5392
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005393 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
Johannes Bergb5878a22010-04-07 16:48:40 +02005394
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01005395 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005396}
5397EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
Johannes Berg98f03342014-11-26 12:42:02 +01005398
5399void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5400{
5401 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5402
5403 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5404
5405 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5406}
5407EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);