blob: 3dbecae4be73cb1aae05752807b717a329b80980 [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) {
Ilan Peer0007e942018-08-31 11:31:10 +03001076 struct ieee80211_supported_band *sband = NULL;
1077 struct sta_info *mgd_sta = NULL;
1078 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
1079
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001080 /*
1081 * with multi-vif csa driver may call ieee80211_csa_finish()
1082 * many times while waiting for other interfaces to use their
1083 * reservations
1084 */
1085 if (sdata->reserved_ready)
1086 goto out;
1087
Ilan Peer0007e942018-08-31 11:31:10 +03001088 if (sdata->vif.bss_conf.chandef.width !=
1089 sdata->csa_chandef.width) {
1090 /*
1091 * For managed interface, we need to also update the AP
1092 * station bandwidth and align the rate scale algorithm
1093 * on the bandwidth change. Here we only consider the
1094 * bandwidth of the new channel definition (as channel
1095 * switch flow does not have the full HT/VHT/HE
1096 * information), assuming that if additional changes are
1097 * required they would be done as part of the processing
1098 * of the next beacon from the AP.
1099 */
1100 switch (sdata->csa_chandef.width) {
1101 case NL80211_CHAN_WIDTH_20_NOHT:
1102 case NL80211_CHAN_WIDTH_20:
1103 default:
1104 bw = IEEE80211_STA_RX_BW_20;
1105 break;
1106 case NL80211_CHAN_WIDTH_40:
1107 bw = IEEE80211_STA_RX_BW_40;
1108 break;
1109 case NL80211_CHAN_WIDTH_80:
1110 bw = IEEE80211_STA_RX_BW_80;
1111 break;
1112 case NL80211_CHAN_WIDTH_80P80:
1113 case NL80211_CHAN_WIDTH_160:
1114 bw = IEEE80211_STA_RX_BW_160;
1115 break;
1116 }
1117
1118 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1119 sband =
1120 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1121 }
1122
1123 if (sdata->vif.bss_conf.chandef.width >
1124 sdata->csa_chandef.width) {
1125 mgd_sta->sta.bandwidth = bw;
1126 rate_control_rate_update(local, sband, mgd_sta,
1127 IEEE80211_RC_BW_CHANGED);
1128 }
1129
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001130 ret = ieee80211_vif_use_reserved_context(sdata);
1131 if (ret) {
1132 sdata_info(sdata,
1133 "failed to use reserved channel context, disconnecting (err=%d)\n",
1134 ret);
1135 ieee80211_queue_work(&sdata->local->hw,
1136 &ifmgd->csa_connection_drop_work);
1137 goto out;
1138 }
1139
Ilan Peer0007e942018-08-31 11:31:10 +03001140 if (sdata->vif.bss_conf.chandef.width <
1141 sdata->csa_chandef.width) {
1142 mgd_sta->sta.bandwidth = bw;
1143 rate_control_rate_update(local, sband, mgd_sta,
1144 IEEE80211_RC_BW_CHANGED);
1145 }
1146
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001147 goto out;
1148 }
1149
1150 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1151 &sdata->csa_chandef)) {
Arik Nemtsov7578d572013-09-01 17:15:51 +03001152 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001153 "failed to finalize channel switch, disconnecting\n");
Arik Nemtsov7578d572013-09-01 17:15:51 +03001154 ieee80211_queue_work(&sdata->local->hw,
1155 &ifmgd->csa_connection_drop_work);
1156 goto out;
1157 }
Karl Beldan675a0b02013-03-25 16:26:57 +01001158
Johannes Berg77fdaa12009-07-07 03:45:17 +02001159 /* XXX: shouldn't really modify cfg80211-owned data! */
Luciano Coelho33787fc2013-11-11 20:34:54 +02001160 ifmgd->associated->channel = sdata->csa_chandef.chan;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001161
Luciano Coelho0c21e632014-10-08 09:48:39 +03001162 ifmgd->csa_waiting_bcn = true;
Luciano Coelhof1d65582014-10-08 09:48:38 +03001163
Michal Kaziore5593f52014-04-09 15:45:36 +02001164 ieee80211_sta_reset_beacon_monitor(sdata);
1165 ieee80211_sta_reset_conn_monitor(sdata);
1166
Michal Kazior59af6922014-04-09 15:10:59 +02001167out:
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001168 mutex_unlock(&local->chanctx_mtx);
1169 mutex_unlock(&local->mtx);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001170 sdata_unlock(sdata);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001171}
1172
Luciano Coelho0c21e632014-10-08 09:48:39 +03001173static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1174{
1175 struct ieee80211_local *local = sdata->local;
1176 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1177 int ret;
1178
1179 sdata_assert_lock(sdata);
1180
1181 WARN_ON(!sdata->vif.csa_active);
1182
1183 if (sdata->csa_block_tx) {
1184 ieee80211_wake_vif_queues(local, sdata,
1185 IEEE80211_QUEUE_STOP_REASON_CSA);
1186 sdata->csa_block_tx = false;
1187 }
1188
1189 sdata->vif.csa_active = false;
1190 ifmgd->csa_waiting_bcn = false;
1191
1192 ret = drv_post_channel_switch(sdata);
1193 if (ret) {
1194 sdata_info(sdata,
1195 "driver post channel switch failed, disconnecting\n");
1196 ieee80211_queue_work(&local->hw,
1197 &ifmgd->csa_connection_drop_work);
1198 return;
1199 }
Luciano Coelho688b1ec2014-12-16 16:01:39 +02001200
1201 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
Luciano Coelho0c21e632014-10-08 09:48:39 +03001202}
1203
Johannes Berg5ce6e432010-05-11 16:20:57 +02001204void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1205{
Johannes Berg55de9082012-07-26 17:24:39 +02001206 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1207 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001208
1209 trace_api_chswitch_done(sdata, success);
1210 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001211 sdata_info(sdata,
1212 "driver channel switch failed, disconnecting\n");
1213 ieee80211_queue_work(&sdata->local->hw,
1214 &ifmgd->csa_connection_drop_work);
1215 } else {
1216 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001217 }
Johannes Berg5ce6e432010-05-11 16:20:57 +02001218}
1219EXPORT_SYMBOL(ieee80211_chswitch_done);
1220
Kees Cook34f11cd2017-10-16 16:35:49 -07001221static void ieee80211_chswitch_timer(struct timer_list *t)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001222{
1223 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07001224 from_timer(sdata, t, u.mgd.chswitch_timer);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001225
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01001226 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001227}
1228
Johannes Berg37799e52013-03-26 14:02:26 +01001229static void
Johannes Berg4a3cb702013-02-12 16:43:19 +01001230ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03001231 u64 timestamp, u32 device_timestamp,
1232 struct ieee802_11_elems *elems,
Johannes Berg04a161f2013-05-03 09:35:35 +02001233 bool beacon)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001234{
Johannes Bergb4f286a12013-03-26 14:13:58 +01001235 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001236 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg37799e52013-03-26 14:02:26 +01001237 struct cfg80211_bss *cbss = ifmgd->associated;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001238 struct ieee80211_chanctx_conf *conf;
Johannes Berg55de9082012-07-26 17:24:39 +02001239 struct ieee80211_chanctx *chanctx;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001240 enum nl80211_band current_band;
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001241 struct ieee80211_csa_ie csa_ie;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001242 struct ieee80211_channel_switch ch_switch;
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001243 int res;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001244
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001245 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001246
Johannes Berg37799e52013-03-26 14:02:26 +01001247 if (!cbss)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001248 return;
1249
Johannes Bergb4f286a12013-03-26 14:13:58 +01001250 if (local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001251 return;
1252
Johannes Berg37799e52013-03-26 14:02:26 +01001253 /* disregard subsequent announcements if we are already processing */
Luciano Coelho3e2a0222014-07-05 11:43:01 +03001254 if (sdata->vif.csa_active)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001255 return;
1256
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001257 current_band = cbss->channel->band;
Luciano Coelho84469a42014-10-28 13:33:04 +02001258 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001259 ifmgd->flags,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001260 ifmgd->associated->bssid, &csa_ie);
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001261 if (res < 0)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001262 ieee80211_queue_work(&local->hw,
Johannes Berg882a7c62012-08-01 22:32:45 +02001263 &ifmgd->csa_connection_drop_work);
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001264 if (res)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001265 return;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001266
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001267 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
Johannes Berg85220d72013-03-25 18:29:27 +01001268 IEEE80211_CHAN_DISABLED)) {
1269 sdata_info(sdata,
1270 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02001271 ifmgd->associated->bssid,
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001272 csa_ie.chandef.chan->center_freq,
1273 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1274 csa_ie.chandef.center_freq2);
Johannes Berg85220d72013-03-25 18:29:27 +01001275 ieee80211_queue_work(&local->hw,
1276 &ifmgd->csa_connection_drop_work);
1277 return;
1278 }
1279
Johannes Bergf84eaa12015-03-12 08:53:26 +02001280 if (cfg80211_chandef_identical(&csa_ie.chandef,
1281 &sdata->vif.bss_conf.chandef)) {
1282 if (ifmgd->csa_ignored_same_chan)
1283 return;
1284 sdata_info(sdata,
1285 "AP %pM tries to chanswitch to same channel, ignore\n",
1286 ifmgd->associated->bssid);
1287 ifmgd->csa_ignored_same_chan = true;
1288 return;
1289 }
1290
Arik Nemtsovc5a71682015-05-19 14:36:48 +03001291 /*
1292 * Drop all TDLS peers - either we disconnect or move to a different
1293 * channel from this point on. There's no telling what our peer will do.
1294 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1295 * have an incompatible wider chandef.
1296 */
1297 ieee80211_teardown_tdls_peers(sdata);
1298
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001299 mutex_lock(&local->mtx);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001300 mutex_lock(&local->chanctx_mtx);
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001301 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1302 lockdep_is_held(&local->chanctx_mtx));
1303 if (!conf) {
1304 sdata_info(sdata,
1305 "no channel context assigned to vif?, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001306 goto drop_connection;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001307 }
1308
1309 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1310
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001311 if (local->use_chanctx &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001312 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001313 sdata_info(sdata,
1314 "driver doesn't support chan-switch with channel contexts\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001315 goto drop_connection;
Arik Nemtsov7578d572013-09-01 17:15:51 +03001316 }
1317
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001318 ch_switch.timestamp = timestamp;
1319 ch_switch.device_timestamp = device_timestamp;
1320 ch_switch.block_tx = csa_ie.mode;
1321 ch_switch.chandef = csa_ie.chandef;
1322 ch_switch.count = csa_ie.count;
1323
1324 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1325 sdata_info(sdata,
1326 "preparing for channel switch failed, disconnecting\n");
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001327 goto drop_connection;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03001328 }
1329
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001330 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1331 chanctx->mode, false);
1332 if (res) {
Johannes Berg55de9082012-07-26 17:24:39 +02001333 sdata_info(sdata,
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001334 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1335 res);
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001336 goto drop_connection;
Johannes Berg55de9082012-07-26 17:24:39 +02001337 }
Johannes Bergb4f286a12013-03-26 14:13:58 +01001338 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001339
Michal Kazior59af6922014-04-09 15:10:59 +02001340 sdata->vif.csa_active = true;
Michal Kazior4c3ebc52014-06-25 12:35:09 +02001341 sdata->csa_chandef = csa_ie.chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02001342 sdata->csa_block_tx = csa_ie.mode;
Johannes Bergf84eaa12015-03-12 08:53:26 +02001343 ifmgd->csa_ignored_same_chan = false;
Michal Kazior59af6922014-04-09 15:10:59 +02001344
1345 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03001346 ieee80211_stop_vif_queues(local, sdata,
1347 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02001348 mutex_unlock(&local->mtx);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001349
Luciano Coelho2f457292014-11-07 14:31:36 +02001350 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1351 csa_ie.count);
1352
Johannes Bergb4f286a12013-03-26 14:13:58 +01001353 if (local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +02001354 /* use driver's channel switch callback */
Luciano Coelho0f791eb42014-10-08 09:48:40 +03001355 drv_channel_switch(local, sdata, &ch_switch);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001356 return;
1357 }
1358
1359 /* channel switch handled in software */
Chun-Yeow Yeohc0f17eb2013-10-14 19:08:29 -07001360 if (csa_ie.count <= 1)
Johannes Bergb4f286a12013-03-26 14:13:58 +01001361 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001362 else
Johannes Bergcc32abd2009-05-15 11:52:31 +02001363 mod_timer(&ifmgd->chswitch_timer,
Luciano Coelhoff1e4172014-10-28 13:33:05 +02001364 TU_TO_EXP_TIME((csa_ie.count - 1) *
1365 cbss->beacon_interval));
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001366 return;
1367 drop_connection:
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03001368 /*
1369 * This is just so that the disconnect flow will know that
1370 * we were trying to switch channel and failed. In case the
1371 * mode is 1 (we are not allowed to Tx), we will know not to
1372 * send a deauthentication frame. Those two fields will be
1373 * reset when the disconnection worker runs.
1374 */
1375 sdata->vif.csa_active = true;
1376 sdata->csa_block_tx = csa_ie.mode;
1377
Johannes Bergf3b0bbb2015-03-12 08:53:25 +02001378 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1379 mutex_unlock(&local->chanctx_mtx);
1380 mutex_unlock(&local->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001381}
1382
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001383static bool
1384ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1385 struct ieee80211_channel *channel,
1386 const u8 *country_ie, u8 country_ie_len,
1387 const u8 *pwr_constr_elem,
1388 int *chan_pwr, int *pwr_reduction)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001389{
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001390 struct ieee80211_country_ie_triplet *triplet;
1391 int chan = ieee80211_frequency_to_channel(channel->center_freq);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001392 int i, chan_increment;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001393 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001394
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001395 /* Invalid IE */
1396 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001397 return false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001398
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001399 triplet = (void *)(country_ie + 3);
1400 country_ie_len -= 3;
1401
1402 switch (channel->band) {
1403 default:
1404 WARN_ON_ONCE(1);
1405 /* fall through */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001406 case NL80211_BAND_2GHZ:
1407 case NL80211_BAND_60GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001408 chan_increment = 1;
1409 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001410 case NL80211_BAND_5GHZ:
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001411 chan_increment = 4;
1412 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001413 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001414
1415 /* find channel */
1416 while (country_ie_len >= 3) {
1417 u8 first_channel = triplet->chans.first_channel;
1418
1419 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1420 goto next;
1421
1422 for (i = 0; i < triplet->chans.num_channels; i++) {
1423 if (first_channel + i * chan_increment == chan) {
1424 have_chan_pwr = true;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001425 *chan_pwr = triplet->chans.max_power;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001426 break;
1427 }
1428 }
1429 if (have_chan_pwr)
1430 break;
1431
1432 next:
1433 triplet++;
1434 country_ie_len -= 3;
1435 }
1436
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001437 if (have_chan_pwr && pwr_constr_elem)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001438 *pwr_reduction = *pwr_constr_elem;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001439 else
1440 *pwr_reduction = 0;
1441
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001442 return have_chan_pwr;
1443}
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001444
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001445static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1446 struct ieee80211_channel *channel,
1447 const u8 *cisco_dtpc_ie,
1448 int *pwr_level)
1449{
1450 /* From practical testing, the first data byte of the DTPC element
1451 * seems to contain the requested dBm level, and the CLI on Cisco
1452 * APs clearly state the range is -127 to 127 dBm, which indicates
1453 * a signed byte, although it seemingly never actually goes negative.
1454 * The other byte seems to always be zero.
1455 */
1456 *pwr_level = (__s8)cisco_dtpc_ie[4];
1457}
1458
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001459static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1460 struct ieee80211_channel *channel,
1461 struct ieee80211_mgmt *mgmt,
1462 const u8 *country_ie, u8 country_ie_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001463 const u8 *pwr_constr_ie,
1464 const u8 *cisco_dtpc_ie)
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001465{
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001466 bool has_80211h_pwr = false, has_cisco_pwr = false;
1467 int chan_pwr = 0, pwr_reduction_80211h = 0;
1468 int pwr_level_cisco, pwr_level_80211h;
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001469 int new_ap_level;
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001470 __le16 capab = mgmt->u.probe_resp.capab_info;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001471
Moshe Benjia5fee9c2014-12-14 11:05:50 +02001472 if (country_ie &&
1473 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1474 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001475 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1476 sdata, channel, country_ie, country_ie_len,
1477 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001478 pwr_level_80211h =
1479 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07001480 }
1481
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001482 if (cisco_dtpc_ie) {
1483 ieee80211_find_cisco_dtpc(
1484 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1485 has_cisco_pwr = true;
1486 }
1487
1488 if (!has_80211h_pwr && !has_cisco_pwr)
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001489 return 0;
1490
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001491 /* If we have both 802.11h and Cisco DTPC, apply both limits
1492 * by picking the smallest of the two power levels advertised.
1493 */
1494 if (has_80211h_pwr &&
1495 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
Johannes Berga87da0c2015-12-08 16:04:37 +02001496 new_ap_level = pwr_level_80211h;
1497
1498 if (sdata->ap_power_level == new_ap_level)
1499 return 0;
1500
John Linvillecef2fc12015-03-31 10:49:14 -04001501 sdata_dbg(sdata,
1502 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1503 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1504 sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001505 } else { /* has_cisco_pwr is always true here. */
Johannes Berga87da0c2015-12-08 16:04:37 +02001506 new_ap_level = pwr_level_cisco;
1507
1508 if (sdata->ap_power_level == new_ap_level)
1509 return 0;
1510
John Linvillecef2fc12015-03-31 10:49:14 -04001511 sdata_dbg(sdata,
1512 "Limiting TX power to %d dBm as advertised by %pM\n",
1513 pwr_level_cisco, sdata->u.mgd.bssid);
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07001514 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001515
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001516 sdata->ap_power_level = new_ap_level;
1517 if (__ieee80211_recalc_txpower(sdata))
1518 return BSS_CHANGED_TXPOWER;
1519 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001520}
1521
Johannes Berg965beda2009-04-16 13:17:24 +02001522/* powersave */
1523static void ieee80211_enable_ps(struct ieee80211_local *local,
1524 struct ieee80211_sub_if_data *sdata)
1525{
1526 struct ieee80211_conf *conf = &local->hw.conf;
1527
Johannes Bergd5edaed2009-04-22 23:02:51 +02001528 /*
1529 * If we are scanning right now then the parameters will
1530 * take effect when scan finishes.
1531 */
Helmut Schaafbe9c422009-07-23 12:14:04 +02001532 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +02001533 return;
1534
Johannes Berg965beda2009-04-16 13:17:24 +02001535 if (conf->dynamic_ps_timeout > 0 &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001536 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001537 mod_timer(&local->dynamic_ps_timer, jiffies +
1538 msecs_to_jiffies(conf->dynamic_ps_timeout));
1539 } else {
Johannes Berg30686bf2015-06-02 21:39:54 +02001540 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
Johannes Berg076cdcb2015-09-24 16:14:55 +02001541 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajan375177b2010-02-09 14:50:28 +05301542
Johannes Berg30686bf2015-06-02 21:39:54 +02001543 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1544 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001545 return;
1546
1547 conf->flags |= IEEE80211_CONF_PS;
1548 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +02001549 }
1550}
1551
1552static void ieee80211_change_ps(struct ieee80211_local *local)
1553{
1554 struct ieee80211_conf *conf = &local->hw.conf;
1555
1556 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +02001557 ieee80211_enable_ps(local, local->ps_sdata);
1558 } else if (conf->flags & IEEE80211_CONF_PS) {
1559 conf->flags &= ~IEEE80211_CONF_PS;
1560 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1561 del_timer_sync(&local->dynamic_ps_timer);
1562 cancel_work_sync(&local->dynamic_ps_enable_work);
1563 }
1564}
1565
Jason Young808118c2011-03-10 16:43:19 -08001566static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1567{
1568 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1569 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001570 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001571
1572 if (!mgd->powersave)
1573 return false;
1574
Johannes Berg05cb9102011-10-28 11:59:47 +02001575 if (mgd->broken_ap)
1576 return false;
1577
Jason Young808118c2011-03-10 16:43:19 -08001578 if (!mgd->associated)
1579 return false;
1580
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001581 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
Jason Young808118c2011-03-10 16:43:19 -08001582 return false;
1583
Alexander Bondar989c6502013-05-16 17:34:17 +03001584 if (!mgd->have_beacon)
Alexander Bondarce857882013-05-06 17:17:04 +03001585 return false;
1586
Jason Young808118c2011-03-10 16:43:19 -08001587 rcu_read_lock();
1588 sta = sta_info_get(sdata, mgd->bssid);
1589 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001590 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001591 rcu_read_unlock();
1592
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001593 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001594}
1595
Johannes Berg965beda2009-04-16 13:17:24 +02001596/* need to hold RTNL or interface lock */
Johannes Berg4a733ef2015-10-14 18:02:43 +02001597void ieee80211_recalc_ps(struct ieee80211_local *local)
Johannes Berg965beda2009-04-16 13:17:24 +02001598{
1599 struct ieee80211_sub_if_data *sdata, *found = NULL;
1600 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001601 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001602
Johannes Berg30686bf2015-06-02 21:39:54 +02001603 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
Johannes Berg965beda2009-04-16 13:17:24 +02001604 local->ps_sdata = NULL;
1605 return;
1606 }
1607
1608 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01001609 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001610 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301611 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1612 /* If an AP vif is found, then disable PS
1613 * by setting the count to zero thereby setting
1614 * ps_sdata to NULL.
1615 */
1616 count = 0;
1617 break;
1618 }
Johannes Berg965beda2009-04-16 13:17:24 +02001619 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1620 continue;
1621 found = sdata;
1622 count++;
1623 }
1624
Jason Young808118c2011-03-10 16:43:19 -08001625 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg4a733ef2015-10-14 18:02:43 +02001626 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg10f644a2009-04-16 13:17:25 +02001627
Juuso Oikarinenff616382010-06-09 09:51:52 +03001628 timeout = local->dynamic_ps_forced_timeout;
Johannes Berg4a733ef2015-10-14 18:02:43 +02001629 if (timeout < 0)
1630 timeout = 100;
Johannes Berg09b85562013-02-06 23:07:41 +01001631 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001632
Johannes Berg4a733ef2015-10-14 18:02:43 +02001633 /* If the TIM IE is invalid, pretend the value is 1 */
1634 if (!dtimper)
1635 dtimper = 1;
Johannes Berg56007a02010-01-26 14:19:52 +01001636
Johannes Berg4a733ef2015-10-14 18:02:43 +02001637 local->hw.conf.ps_dtim_period = dtimper;
1638 local->ps_sdata = found;
Johannes Berg10f644a2009-04-16 13:17:25 +02001639 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001640 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001641 }
Johannes Berg965beda2009-04-16 13:17:24 +02001642
1643 ieee80211_change_ps(local);
1644}
1645
Eliad Pellerab095872012-07-27 12:33:22 +03001646void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1647{
1648 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1649
1650 if (sdata->vif.bss_conf.ps != ps_allowed) {
1651 sdata->vif.bss_conf.ps = ps_allowed;
1652 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1653 }
1654}
1655
Johannes Berg965beda2009-04-16 13:17:24 +02001656void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1657{
1658 struct ieee80211_local *local =
1659 container_of(work, struct ieee80211_local,
1660 dynamic_ps_disable_work);
1661
1662 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1663 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1664 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1665 }
1666
1667 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001668 IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +03001669 IEEE80211_QUEUE_STOP_REASON_PS,
1670 false);
Johannes Berg965beda2009-04-16 13:17:24 +02001671}
1672
1673void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1674{
1675 struct ieee80211_local *local =
1676 container_of(work, struct ieee80211_local,
1677 dynamic_ps_enable_work);
1678 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001679 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301680 unsigned long flags;
1681 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001682
1683 /* can only happen when PS was just disabled anyway */
1684 if (!sdata)
1685 return;
1686
Christian Lamparter5e340692011-06-30 21:08:43 +02001687 ifmgd = &sdata->u.mgd;
1688
Johannes Berg965beda2009-04-16 13:17:24 +02001689 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1690 return;
1691
Johannes Berg09b85562013-02-06 23:07:41 +01001692 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001693 /* don't enter PS if TX frames are pending */
1694 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301695 mod_timer(&local->dynamic_ps_timer, jiffies +
1696 msecs_to_jiffies(
1697 local->hw.conf.dynamic_ps_timeout));
1698 return;
1699 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001700
1701 /*
1702 * transmission can be stopped by others which leads to
1703 * dynamic_ps_timer expiry. Postpone the ps timer if it
1704 * is not the actual idle state.
1705 */
1706 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1707 for (q = 0; q < local->hw.queues; q++) {
1708 if (local->queue_stop_reasons[q]) {
1709 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1710 flags);
1711 mod_timer(&local->dynamic_ps_timer, jiffies +
1712 msecs_to_jiffies(
1713 local->hw.conf.dynamic_ps_timeout));
1714 return;
1715 }
1716 }
1717 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301718 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301719
Johannes Berg30686bf2015-06-02 21:39:54 +02001720 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301721 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Johannes Berga1598382013-03-26 22:02:42 +01001722 if (drv_tx_frames_pending(local)) {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301723 mod_timer(&local->dynamic_ps_timer, jiffies +
1724 msecs_to_jiffies(
1725 local->hw.conf.dynamic_ps_timeout));
Johannes Berga1598382013-03-26 22:02:42 +01001726 } else {
Johannes Berg076cdcb2015-09-24 16:14:55 +02001727 ieee80211_send_nullfunc(local, sdata, true);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301728 /* Flush to get the tx status of nullfunc frame */
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02001729 ieee80211_flush_queues(local, sdata, false);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301730 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301731 }
1732
Johannes Berg30686bf2015-06-02 21:39:54 +02001733 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1734 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301735 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1736 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1737 local->hw.conf.flags |= IEEE80211_CONF_PS;
1738 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1739 }
Johannes Berg965beda2009-04-16 13:17:24 +02001740}
1741
Kees Cook34f11cd2017-10-16 16:35:49 -07001742void ieee80211_dynamic_ps_timer(struct timer_list *t)
Johannes Berg965beda2009-04-16 13:17:24 +02001743{
Kees Cook34f11cd2017-10-16 16:35:49 -07001744 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
Johannes Berg965beda2009-04-16 13:17:24 +02001745
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001746 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001747}
1748
Simon Wunderlich164eb022013-02-08 18:16:20 +01001749void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1750{
Geliang Tanga85a7e22016-01-01 23:48:52 +08001751 struct delayed_work *delayed_work = to_delayed_work(work);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001752 struct ieee80211_sub_if_data *sdata =
1753 container_of(delayed_work, struct ieee80211_sub_if_data,
1754 dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001755 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlich164eb022013-02-08 18:16:20 +01001756
Johannes Berg34a37402013-12-18 09:43:33 +01001757 mutex_lock(&sdata->local->mtx);
1758 if (sdata->wdev.cac_started) {
1759 ieee80211_vif_release_channel(sdata);
1760 cfg80211_cac_event(sdata->dev, &chandef,
1761 NL80211_RADAR_CAC_FINISHED,
1762 GFP_KERNEL);
1763 }
1764 mutex_unlock(&sdata->local->mtx);
Simon Wunderlich164eb022013-02-08 18:16:20 +01001765}
1766
Johannes Berg02219b32014-10-07 10:38:50 +03001767static bool
1768__ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1769{
1770 struct ieee80211_local *local = sdata->local;
1771 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
John Linvillecc72f6e2015-01-06 14:39:33 -05001772 bool ret = false;
Johannes Berg02219b32014-10-07 10:38:50 +03001773 int ac;
1774
1775 if (local->hw.queues < IEEE80211_NUM_ACS)
1776 return false;
1777
1778 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1779 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1780 int non_acm_ac;
1781 unsigned long now = jiffies;
1782
1783 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1784 tx_tspec->admitted_time &&
1785 time_after(now, tx_tspec->time_slice_start + HZ)) {
1786 tx_tspec->consumed_tx_time = 0;
1787 tx_tspec->time_slice_start = now;
1788
1789 if (tx_tspec->downgraded)
1790 tx_tspec->action =
1791 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1792 }
1793
1794 switch (tx_tspec->action) {
1795 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1796 /* take the original parameters */
1797 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1798 sdata_err(sdata,
1799 "failed to set TX queue parameters for queue %d\n",
1800 ac);
1801 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1802 tx_tspec->downgraded = false;
1803 ret = true;
1804 break;
1805 case TX_TSPEC_ACTION_DOWNGRADE:
1806 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1807 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1808 ret = true;
1809 break;
1810 }
1811 /* downgrade next lower non-ACM AC */
1812 for (non_acm_ac = ac + 1;
1813 non_acm_ac < IEEE80211_NUM_ACS;
1814 non_acm_ac++)
1815 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1816 break;
Johannes Berg93db1d92016-09-14 09:23:51 +02001817 /* Usually the loop will result in using BK even if it
1818 * requires admission control, but such a configuration
1819 * makes no sense and we have to transmit somehow - the
1820 * AC selection does the same thing.
1821 * If we started out trying to downgrade from BK, then
1822 * the extra condition here might be needed.
Johannes Berg02219b32014-10-07 10:38:50 +03001823 */
Johannes Berg93db1d92016-09-14 09:23:51 +02001824 if (non_acm_ac >= IEEE80211_NUM_ACS)
1825 non_acm_ac = IEEE80211_AC_BK;
Johannes Berg02219b32014-10-07 10:38:50 +03001826 if (drv_conf_tx(local, sdata, ac,
1827 &sdata->tx_conf[non_acm_ac]))
1828 sdata_err(sdata,
1829 "failed to set TX queue parameters for queue %d\n",
1830 ac);
1831 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1832 ret = true;
1833 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1834 tx_tspec->time_slice_start + HZ - now + 1);
1835 break;
1836 case TX_TSPEC_ACTION_NONE:
1837 /* nothing now */
1838 break;
1839 }
1840 }
1841
1842 return ret;
1843}
1844
1845void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1846{
1847 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1848 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1849}
1850
1851static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1852{
1853 struct ieee80211_sub_if_data *sdata;
1854
1855 sdata = container_of(work, struct ieee80211_sub_if_data,
1856 u.mgd.tx_tspec_wk.work);
1857 ieee80211_sta_handle_tspec_ac_params(sdata);
1858}
1859
Johannes Berg60f8b392008-09-08 17:44:22 +02001860/* MLME */
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001861static bool
1862ieee80211_sta_wmm_params(struct ieee80211_local *local,
1863 struct ieee80211_sub_if_data *sdata,
1864 const u8 *wmm_param, size_t wmm_param_len,
1865 const struct ieee80211_mu_edca_param_set *mu_edca)
Jiri Bencf0706e82007-05-05 11:45:53 -07001866{
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001867 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
Johannes Berg4ced3f72010-07-19 16:39:04 +02001868 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001869 size_t left;
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001870 int count, ac;
Johannes Berg4a3cb702013-02-12 16:43:19 +01001871 const u8 *pos;
1872 u8 uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001873
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001874 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001875 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001876
Johannes Berg32c50572012-03-28 11:04:29 +02001877 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001878 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001879
1880 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001881 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001882
Jiri Bencf0706e82007-05-05 11:45:53 -07001883 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001884 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001885
1886 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001887 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001888
Jiri Bencf0706e82007-05-05 11:45:53 -07001889 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +01001890 if (count == ifmgd->wmm_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001891 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001892 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001893
1894 pos = wmm_param + 8;
1895 left = wmm_param_len - 8;
1896
1897 memset(&params, 0, sizeof(params));
1898
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001899 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001900 for (; left >= 4; left -= 4, pos += 4) {
1901 int aci = (pos[0] >> 5) & 0x03;
1902 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001903 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001904
1905 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001906 case 1: /* AC_BK */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001907 ac = IEEE80211_AC_BK;
Johannes Berg988c0f72008-04-17 19:21:22 +02001908 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001909 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001910 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1911 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001912 params[ac].mu_edca = !!mu_edca;
1913 if (mu_edca)
1914 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
Jiri Bencf0706e82007-05-05 11:45:53 -07001915 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001916 case 2: /* AC_VI */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001917 ac = IEEE80211_AC_VI;
Johannes Berg988c0f72008-04-17 19:21:22 +02001918 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001919 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001920 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1921 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001922 params[ac].mu_edca = !!mu_edca;
1923 if (mu_edca)
1924 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
Jiri Bencf0706e82007-05-05 11:45:53 -07001925 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001926 case 3: /* AC_VO */
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001927 ac = IEEE80211_AC_VO;
Johannes Berg988c0f72008-04-17 19:21:22 +02001928 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001929 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02001930 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1931 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001932 params[ac].mu_edca = !!mu_edca;
1933 if (mu_edca)
1934 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
Jiri Bencf0706e82007-05-05 11:45:53 -07001935 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001936 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001937 default:
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001938 ac = IEEE80211_AC_BE;
Johannes Berg988c0f72008-04-17 19:21:22 +02001939 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001940 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02001941 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1942 uapsd = true;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001943 params[ac].mu_edca = !!mu_edca;
1944 if (mu_edca)
1945 params[ac].mu_edca_param_rec = mu_edca->ac_be;
Jiri Bencf0706e82007-05-05 11:45:53 -07001946 break;
1947 }
1948
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001949 params[ac].aifs = pos[0] & 0x0f;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001950
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001951 if (params[ac].aifs < 2) {
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001952 sdata_info(sdata,
1953 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001954 params[ac].aifs, aci);
1955 params[ac].aifs = 2;
Emmanuel Grumbach730a75502015-10-22 17:46:05 +02001956 }
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001957 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1958 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
1959 params[ac].txop = get_unaligned_le16(pos + 2);
1960 params[ac].acm = acm;
1961 params[ac].uapsd = uapsd;
Kalle Valoab133152010-01-12 10:42:31 +02001962
Ilan Peer911a2642018-04-03 11:35:22 +03001963 if (params[ac].cw_min == 0 ||
Emmanuel Grumbachc470bdc2018-03-26 16:21:04 +03001964 params[ac].cw_min > params[ac].cw_max) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001965 sdata_info(sdata,
1966 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
1967 params[ac].cw_min, params[ac].cw_max, aci);
1968 return false;
1969 }
Haim Dreyfusse552af02018-03-28 13:24:10 +03001970 ieee80211_regulatory_limit_wmm_params(sdata, &params[ac], ac);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001971 }
1972
1973 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001974 mlme_dbg(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001975 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
1976 ac, params[ac].acm,
1977 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
1978 params[ac].txop, params[ac].uapsd,
1979 ifmgd->tx_tspec[ac].downgraded);
1980 sdata->tx_conf[ac] = params[ac];
1981 if (!ifmgd->tx_tspec[ac].downgraded &&
1982 drv_conf_tx(local, sdata, ac, &params[ac]))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001983 sdata_err(sdata,
Johannes Berg2ed77ea2015-10-22 17:46:06 +02001984 "failed to set TX queue parameters for AC %d\n",
1985 ac);
Jiri Bencf0706e82007-05-05 11:45:53 -07001986 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001987
1988 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02001989 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02001990 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001991}
1992
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001993static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1994{
1995 lockdep_assert_held(&sdata->local->mtx);
1996
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02001997 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001998 ieee80211_run_deferred_scan(sdata->local);
1999}
2000
2001static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2002{
2003 mutex_lock(&sdata->local->mtx);
2004 __ieee80211_stop_poll(sdata);
2005 mutex_unlock(&sdata->local->mtx);
2006}
2007
Johannes Berg7a5158e2008-10-08 10:59:33 +02002008static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2009 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02002010{
Johannes Bergbda39332008-10-11 01:51:51 +02002011 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302012 struct ieee80211_supported_band *sband;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002013 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002014 bool use_protection;
2015 bool use_short_preamble;
2016 bool use_short_slot;
2017
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302018 sband = ieee80211_get_sband(sdata);
2019 if (!sband)
2020 return changed;
2021
Johannes Berg7a5158e2008-10-08 10:59:33 +02002022 if (erp_valid) {
2023 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2024 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2025 } else {
2026 use_protection = false;
2027 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2028 }
2029
2030 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302031 if (sband->band == NL80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01002032 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02002033
Johannes Berg471b3ef2007-12-28 14:32:58 +01002034 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01002035 bss_conf->use_cts_prot = use_protection;
2036 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02002037 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02002038
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002039 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02002040 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002041 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02002042 }
Daniel Draked9430a32007-07-27 15:43:24 +02002043
Johannes Berg7a5158e2008-10-08 10:59:33 +02002044 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02002045 bss_conf->use_short_slot = use_short_slot;
2046 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04002047 }
2048
2049 return changed;
2050}
2051
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002052static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002053 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02002054 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07002055{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002056 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002057 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002058 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04002059
Johannes Bergae5eb022008-10-14 16:58:37 +02002060 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002061 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03002062 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002063
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002064 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
Ben Greear59c1ec22013-03-19 14:19:56 -07002065 beacon_loss_count * bss_conf->beacon_int));
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01002066
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002067 sdata->u.mgd.associated = cbss;
2068 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002069
Johannes Berge8e4f522017-03-08 11:12:10 +01002070 ieee80211_check_rate_mask(sdata);
2071
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002072 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2073
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01002074 if (sdata->vif.p2p ||
2075 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002076 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01002077
Johannes Berg9caf0362012-11-29 01:25:20 +01002078 rcu_read_lock();
2079 ies = rcu_dereference(cbss->ies);
2080 if (ies) {
Johannes Berg9caf0362012-11-29 01:25:20 +01002081 int ret;
2082
2083 ret = cfg80211_get_p2p_attr(
2084 ies->data, ies->len,
2085 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002086 (u8 *) &bss_conf->p2p_noa_attr,
2087 sizeof(bss_conf->p2p_noa_attr));
Johannes Berg9caf0362012-11-29 01:25:20 +01002088 if (ret >= 2) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002089 sdata->u.mgd.p2p_noa_index =
2090 bss_conf->p2p_noa_attr.index;
Johannes Berg9caf0362012-11-29 01:25:20 +01002091 bss_info_changed |= BSS_CHANGED_P2P_PS;
Johannes Berg9caf0362012-11-29 01:25:20 +01002092 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01002093 }
Johannes Berg9caf0362012-11-29 01:25:20 +01002094 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01002095 }
2096
Johannes Bergb291ba12009-07-10 15:29:03 +02002097 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002098 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002099
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002100 ieee80211_led_assoc(local, 1);
2101
Alexander Bondar989c6502013-05-16 17:34:17 +03002102 if (sdata->u.mgd.have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02002103 /*
2104 * If the AP is buggy we may get here with no DTIM period
2105 * known, so assume it's 1 which is the only safe assumption
2106 * in that case, although if the TIM IE is broken powersave
2107 * probably just won't work at all.
2108 */
2109 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Alexander Bondar817cee72013-05-19 14:23:57 +03002110 bss_conf->beacon_rate = bss->beacon_rate;
Alexander Bondar989c6502013-05-16 17:34:17 +03002111 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
Johannes Berg826262c2012-12-10 16:38:14 +02002112 } else {
Alexander Bondar817cee72013-05-19 14:23:57 +03002113 bss_conf->beacon_rate = NULL;
Johannes Berge5b900d2010-07-29 16:08:55 +02002114 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02002115 }
Johannes Berge5b900d2010-07-29 16:08:55 +02002116
Juuso Oikarinen68542962010-06-09 13:43:26 +03002117 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02002118
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002119 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01002120 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03002121 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002122 bss_info_changed |= BSS_CHANGED_CQM;
2123
Juuso Oikarinen68542962010-06-09 13:43:26 +03002124 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002125 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002126 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002127
Johannes Bergae5eb022008-10-14 16:58:37 +02002128 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03002129
Johannes Berg056508d2009-07-30 21:43:55 +02002130 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002131 ieee80211_recalc_ps(local);
Johannes Berg056508d2009-07-30 21:43:55 +02002132 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02002133
Johannes Berg04ecd252012-09-11 14:34:12 +02002134 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03002135 ieee80211_recalc_ps_vif(sdata);
2136
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002137 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07002138}
2139
Jouni Malinene69e95d2010-03-29 23:29:31 -07002140static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01002141 u16 stype, u16 reason, bool tx,
2142 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03002143{
Johannes Berg46900292009-02-15 12:44:28 +01002144 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002145 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01002146 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002147
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002148 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002149
Johannes Berg37ad3882012-02-24 13:50:54 +01002150 if (WARN_ON_ONCE(tx && !frame_buf))
2151 return;
2152
Johannes Bergb291ba12009-07-10 15:29:03 +02002153 if (WARN_ON(!ifmgd->associated))
2154 return;
2155
David Spinadel79543d82012-06-12 09:59:45 +03002156 ieee80211_stop_poll(sdata);
2157
Johannes Berg77fdaa12009-07-07 03:45:17 +02002158 ifmgd->associated = NULL;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002159 netif_carrier_off(sdata->dev);
2160
Eliad Peller88bc40e2012-07-12 17:35:33 +03002161 /*
2162 * if we want to get out of ps before disassoc (why?) we have
2163 * to do it before sending disassoc, as otherwise the null-packet
2164 * won't be valid.
2165 */
2166 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2167 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2168 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2169 }
2170 local->ps_sdata = NULL;
2171
Eliad Pellerab095872012-07-27 12:33:22 +03002172 /* disable per-vif ps */
2173 ieee80211_recalc_ps_vif(sdata);
2174
Emmanuel Grumbach14f2ae82015-01-22 23:30:19 +02002175 /* make sure ongoing transmission finishes */
2176 synchronize_net();
2177
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002178 /*
2179 * drop any frame before deauth/disassoc, this can be data or
2180 * management frame. Since we are disconnecting, we should not
2181 * insist sending these frames which can take time and delay
2182 * the disconnection and possible the roaming.
2183 */
Eliad Pellerf8239812012-06-27 14:18:22 +03002184 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002185 ieee80211_flush_queues(local, sdata, true);
Eliad Pellerf8239812012-06-27 14:18:22 +03002186
Johannes Berg37ad3882012-02-24 13:50:54 +01002187 /* deauthenticate/disassociate now */
Ilan Peer94ba9272018-02-19 14:48:41 +02002188 if (tx || frame_buf) {
Ilan Peer94ba9272018-02-19 14:48:41 +02002189 /*
2190 * In multi channel scenarios guarantee that the virtual
2191 * interface is granted immediate airtime to transmit the
2192 * deauthentication frame by calling mgd_prepare_tx, if the
2193 * driver requested so.
2194 */
2195 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2196 !ifmgd->have_beacon)
Ilan Peerd4e36e52018-04-20 13:49:25 +03002197 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Ilan Peer94ba9272018-02-19 14:48:41 +02002198
Eliad Peller88a9e312012-06-01 11:14:03 +03002199 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
2200 reason, tx, frame_buf);
Ilan Peer94ba9272018-02-19 14:48:41 +02002201 }
Johannes Berg37ad3882012-02-24 13:50:54 +01002202
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002203 /* flush out frame - make sure the deauth was actually sent */
Johannes Berg37ad3882012-02-24 13:50:54 +01002204 if (tx)
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02002205 ieee80211_flush_queues(local, sdata, false);
Johannes Berg37ad3882012-02-24 13:50:54 +01002206
Eliad Peller88a9e312012-06-01 11:14:03 +03002207 /* clear bssid only after building the needed mgmt frames */
Joe Perchesc84a67a2015-03-02 19:54:57 -08002208 eth_zero_addr(ifmgd->bssid);
Eliad Peller88a9e312012-06-01 11:14:03 +03002209
Johannes Berg37ad3882012-02-24 13:50:54 +01002210 /* remove AP and TDLS peers */
Johannes Bergd34ba212013-12-04 22:46:11 +01002211 sta_info_flush(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01002212
2213 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002214 changed |= ieee80211_reset_erp_info(sdata);
2215
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002216 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02002217 changed |= BSS_CHANGED_ASSOC;
2218 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02002219
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002220 ifmgd->p2p_noa_index = -1;
2221 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2222 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01002223
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002224 /* on the next assoc, re-program HT/VHT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08002225 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2226 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01002227 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2228 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
Sara Sharon23a1f8d2015-12-08 16:04:31 +02002229
2230 /* reset MU-MIMO ownership and group data */
2231 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2232 sizeof(sdata->vif.bss_conf.mu_group.membership));
2233 memset(sdata->vif.bss_conf.mu_group.position, 0,
2234 sizeof(sdata->vif.bss_conf.mu_group.position));
2235 changed |= BSS_CHANGED_MU_GROUPS;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002236 sdata->vif.mu_mimo_owner = false;
Johannes Berg413ad502009-05-08 21:21:06 +02002237
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002238 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05302239
Kalle Valo520eb822008-12-18 23:35:27 +02002240 del_timer_sync(&local->dynamic_ps_timer);
2241 cancel_work_sync(&local->dynamic_ps_enable_work);
2242
Juuso Oikarinen68542962010-06-09 13:43:26 +03002243 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01002244 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03002245 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03002246
Johannes Berg3abead52012-03-02 15:56:59 +01002247 sdata->vif.bss_conf.qos = false;
2248 changed |= BSS_CHANGED_QOS;
2249
Johannes Berg0aaffa92010-05-05 15:28:27 +02002250 /* The BSSID (not really interesting) and HT changed */
2251 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02002252 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02002253
Johannes Berg3abead52012-03-02 15:56:59 +01002254 /* disassociated - set to defaults now */
Johannes Bergcec66282015-10-22 17:46:04 +02002255 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg3abead52012-03-02 15:56:59 +01002256
Johannes Bergb9dcf712010-08-27 12:35:54 +02002257 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2258 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2259 del_timer_sync(&sdata->u.mgd.timer);
2260 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02002261
Johannes Berg826262c2012-12-10 16:38:14 +02002262 sdata->vif.bss_conf.dtim_period = 0;
Alexander Bondar817cee72013-05-19 14:23:57 +03002263 sdata->vif.bss_conf.beacon_rate = NULL;
2264
Alexander Bondar989c6502013-05-16 17:34:17 +03002265 ifmgd->have_beacon = false;
Johannes Berg826262c2012-12-10 16:38:14 +02002266
Johannes Berg028e8da02012-11-26 11:57:41 +01002267 ifmgd->flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002268 mutex_lock(&local->mtx);
Johannes Berg028e8da02012-11-26 11:57:41 +01002269 ieee80211_vif_release_channel(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002270
2271 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002272 ifmgd->csa_waiting_bcn = false;
Johannes Bergf84eaa12015-03-12 08:53:26 +02002273 ifmgd->csa_ignored_same_chan = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002274 if (sdata->csa_block_tx) {
2275 ieee80211_wake_vif_queues(local, sdata,
2276 IEEE80211_QUEUE_STOP_REASON_CSA);
2277 sdata->csa_block_tx = false;
2278 }
Johannes Berg34a37402013-12-18 09:43:33 +01002279 mutex_unlock(&local->mtx);
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002280
Johannes Berg02219b32014-10-07 10:38:50 +03002281 /* existing TX TSPEC sessions no longer exist */
2282 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2283 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2284
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002285 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
Tomas Winkleraa458d12008-09-09 00:32:12 +03002286}
Jiri Bencf0706e82007-05-05 11:45:53 -07002287
Kalle Valo3cf335d2009-03-22 21:57:06 +02002288void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
2289 struct ieee80211_hdr *hdr)
2290{
2291 /*
2292 * We can postpone the mgd.timer whenever receiving unicast frames
2293 * from AP because we know that the connection is working both ways
2294 * at that time. But multicast frames (and hence also beacons) must
2295 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02002296 * data idle periods for sending the periodic probe request to the
2297 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02002298 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002299 if (is_multicast_ether_addr(hdr->addr1))
2300 return;
2301
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04002302 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02002303}
Jiri Bencf0706e82007-05-05 11:45:53 -07002304
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002305static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2306{
2307 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002308 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002309
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002310 mutex_lock(&local->mtx);
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002311 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2312 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002313
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002314 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002315
2316 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002317 ieee80211_recalc_ps(local);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002318 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002319
Johannes Berg30686bf2015-06-02 21:39:54 +02002320 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002321 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002322
2323 /*
2324 * We've received a probe response, but are not sure whether
2325 * we have or will be receiving any beacons or data, so let's
2326 * schedule the timers again, just in case.
2327 */
2328 ieee80211_sta_reset_beacon_monitor(sdata);
2329
2330 mod_timer(&ifmgd->conn_mon_timer,
2331 round_jiffies_up(jiffies +
2332 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002333out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002334 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002335}
2336
Johannes Berg02219b32014-10-07 10:38:50 +03002337static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2338 struct ieee80211_hdr *hdr,
2339 u16 tx_time)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002340{
Johannes Berg02219b32014-10-07 10:38:50 +03002341 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Sara Sharona1f2ba04c2018-02-19 14:48:40 +02002342 u16 tid = ieee80211_get_tid(hdr);
Johannes Berg02219b32014-10-07 10:38:50 +03002343 int ac = ieee80211_ac_from_tid(tid);
2344 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2345 unsigned long now = jiffies;
2346
2347 if (likely(!tx_tspec->admitted_time))
2348 return;
2349
2350 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2351 tx_tspec->consumed_tx_time = 0;
2352 tx_tspec->time_slice_start = now;
2353
2354 if (tx_tspec->downgraded) {
2355 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2356 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2357 }
2358 }
2359
2360 if (tx_tspec->downgraded)
2361 return;
2362
2363 tx_tspec->consumed_tx_time += tx_time;
2364
2365 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2366 tx_tspec->downgraded = true;
2367 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2368 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2369 }
2370}
2371
2372void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2373 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2374{
2375 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2376
Felix Fietkau75706d02010-12-02 21:01:07 +01002377 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002378 return;
2379
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002380 if (ieee80211_is_nullfunc(hdr->frame_control) &&
2381 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002382 if (ack)
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002383 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002384 else
2385 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002386 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002387 return;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002388 }
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002389
2390 if (ack)
2391 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002392}
2393
Johannes Berg45ad6832018-05-28 15:47:39 +02002394static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2395 const u8 *src, const u8 *dst,
2396 const u8 *ssid, size_t ssid_len,
2397 struct ieee80211_channel *channel)
2398{
2399 struct sk_buff *skb;
2400
2401 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2402 ssid, ssid_len, NULL, 0,
2403 IEEE80211_PROBE_FLAG_DIRECTED);
2404 if (skb)
2405 ieee80211_tx_skb(sdata, skb);
2406}
2407
Maxim Levitskya43abf22009-07-31 18:54:12 +03002408static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2409{
2410 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2411 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002412 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08002413 u8 unicast_limit = max(1, max_probe_tries - 3);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002414 struct sta_info *sta;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002415
2416 /*
2417 * Try sending broadcast probe requests for the last three
2418 * probe requests after the first ones failed since some
2419 * buggy APs only support broadcast probe requests.
2420 */
2421 if (ifmgd->probe_send_count >= unicast_limit)
2422 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002423
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002424 /*
2425 * When the hardware reports an accurate Tx ACK status, it's
2426 * better to send a nullfunc frame instead of a probe request,
2427 * as it will kick us off the AP quickly if we aren't associated
2428 * anymore. The timeout will be reset if the frame is ACKed by
2429 * the AP.
2430 */
Soumik Das992e68b2012-05-20 15:31:13 +05302431 ifmgd->probe_send_count++;
2432
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002433 if (dst) {
2434 mutex_lock(&sdata->local->sta_mtx);
2435 sta = sta_info_get(sdata, dst);
2436 if (!WARN_ON(!sta))
2437 ieee80211_check_fast_rx(sta);
2438 mutex_unlock(&sdata->local->sta_mtx);
2439 }
2440
Johannes Berg30686bf2015-06-02 21:39:54 +02002441 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002442 ifmgd->nullfunc_failed = false;
Johannes Berg076cdcb2015-09-24 16:14:55 +02002443 ieee80211_send_nullfunc(sdata->local, sdata, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002444 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002445 int ssid_len;
2446
Johannes Berg9caf0362012-11-29 01:25:20 +01002447 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002448 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002449 if (WARN_ON_ONCE(ssid == NULL))
2450 ssid_len = 0;
2451 else
2452 ssid_len = ssid[1];
2453
Johannes Berg45ad6832018-05-28 15:47:39 +02002454 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2455 ssid + 2, ssid_len,
2456 ifmgd->associated->channel);
Johannes Berg9caf0362012-11-29 01:25:20 +01002457 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002458 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03002459
Ben Greear180205b2011-02-04 15:30:24 -08002460 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002461 run_again(sdata, ifmgd->probe_timeout);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002462}
2463
Johannes Bergb291ba12009-07-10 15:29:03 +02002464static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2465 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02002466{
Kalle Valo04de8382009-03-22 21:57:35 +02002467 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002468 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02002469
Johannes Berg9607e6b2009-12-23 13:15:31 +01002470 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02002471 return;
2472
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002473 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002474
2475 if (!ifmgd->associated)
2476 goto out;
2477
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002478 mutex_lock(&sdata->local->mtx);
2479
2480 if (sdata->local->tmp_channel || sdata->local->scanning) {
2481 mutex_unlock(&sdata->local->mtx);
2482 goto out;
2483 }
2484
Ben Greeara13fbe52013-03-25 11:19:35 -07002485 if (beacon) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002486 mlme_dbg_ratelimited(sdata,
Ben Greear59c1ec22013-03-19 14:19:56 -07002487 "detected beacon loss from AP (missed %d beacons) - probing\n",
2488 beacon_loss_count);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002489
Johannes Berg98f03342014-11-26 12:42:02 +01002490 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
Ben Greeara13fbe52013-03-25 11:19:35 -07002491 }
Kalle Valo04de8382009-03-22 21:57:35 +02002492
Johannes Bergb291ba12009-07-10 15:29:03 +02002493 /*
2494 * The driver/our work has already reported this event or the
2495 * connection monitoring has kicked in and we have already sent
2496 * a probe request. Or maybe the AP died and the driver keeps
2497 * reporting until we disassociate...
2498 *
2499 * In either case we have to ignore the current call to this
2500 * function (except for setting the correct probe reason bit)
2501 * because otherwise we would reset the timer every time and
2502 * never check whether we received a probe response!
2503 */
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02002504 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
Johannes Bergb291ba12009-07-10 15:29:03 +02002505 already = true;
2506
Eliad Peller12b5f342013-11-18 19:06:46 +02002507 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2508
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002509 mutex_unlock(&sdata->local->mtx);
2510
Johannes Bergb291ba12009-07-10 15:29:03 +02002511 if (already)
2512 goto out;
2513
Johannes Berg4e751842009-06-10 15:16:52 +02002514 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02002515 ieee80211_recalc_ps(sdata->local);
Johannes Berg4e751842009-06-10 15:16:52 +02002516 mutex_unlock(&sdata->local->iflist_mtx);
2517
Maxim Levitskya43abf22009-07-31 18:54:12 +03002518 ifmgd->probe_send_count = 0;
2519 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002520 out:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002521 sdata_unlock(sdata);
Kalle Valo04de8382009-03-22 21:57:35 +02002522}
2523
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002524struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2525 struct ieee80211_vif *vif)
2526{
2527 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2528 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002529 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002530 struct sk_buff *skb;
2531 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002532 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002533
2534 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2535 return NULL;
2536
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002537 sdata_assert_lock(sdata);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002538
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002539 if (ifmgd->associated)
2540 cbss = ifmgd->associated;
2541 else if (ifmgd->auth_data)
2542 cbss = ifmgd->auth_data->bss;
2543 else if (ifmgd->assoc_data)
2544 cbss = ifmgd->assoc_data->bss;
2545 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002546 return NULL;
2547
Johannes Berg9caf0362012-11-29 01:25:20 +01002548 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002549 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002550 if (WARN_ON_ONCE(ssid == NULL))
2551 ssid_len = 0;
2552 else
2553 ssid_len = ssid[1];
2554
Johannes Berga344d672014-06-12 22:24:31 +02002555 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02002556 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02002557 ssid + 2, ssid_len,
Johannes Berg00387f32018-05-28 15:47:38 +02002558 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
Johannes Berg9caf0362012-11-29 01:25:20 +01002559 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002560
2561 return skb;
2562}
2563EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2564
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002565static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2566 const u8 *buf, size_t len, bool tx,
2567 u16 reason)
2568{
2569 struct ieee80211_event event = {
2570 .type = MLME_EVENT,
2571 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2572 .u.mlme.reason = reason,
2573 };
2574
2575 if (tx)
2576 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2577 else
2578 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2579
2580 drv_event_callback(sdata->local, sdata, &event);
2581}
2582
Johannes Bergeef9e542013-01-29 13:09:34 +01002583static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002584{
Michal Kazior59af6922014-04-09 15:10:59 +02002585 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002586 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002587 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002588 bool tx;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002589
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002590 sdata_lock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002591 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002592 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002593 return;
2594 }
2595
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002596 tx = !sdata->csa_block_tx;
2597
David Spinadel20eb7ea2016-05-03 16:05:02 +03002598 /* AP is probably out of range (or not reachable for another reason) so
2599 * remove the bss struct for that AP.
2600 */
2601 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2602
Johannes Berg37ad3882012-02-24 13:50:54 +01002603 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2604 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002605 tx, frame_buf);
Michal Kazior59af6922014-04-09 15:10:59 +02002606 mutex_lock(&local->mtx);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002607 sdata->vif.csa_active = false;
Luciano Coelho0c21e632014-10-08 09:48:39 +03002608 ifmgd->csa_waiting_bcn = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002609 if (sdata->csa_block_tx) {
2610 ieee80211_wake_vif_queues(local, sdata,
2611 IEEE80211_QUEUE_STOP_REASON_CSA);
2612 sdata->csa_block_tx = false;
2613 }
Michal Kazior59af6922014-04-09 15:10:59 +02002614 mutex_unlock(&local->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002615
Emmanuel Grumbach6c18b272018-08-31 11:31:12 +03002616 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002617 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
2618
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002619 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002620}
2621
Johannes Bergcc74c0c2012-08-01 16:49:34 +02002622static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02002623{
2624 struct ieee80211_sub_if_data *sdata =
2625 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002626 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002627 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Paul Stewarta85e1d52011-12-09 11:01:49 -08002628
Johannes Berg976bd9e2015-10-16 17:18:11 +02002629 if (ifmgd->associated)
2630 ifmgd->beacon_loss_count++;
Johannes Bergb291ba12009-07-10 15:29:03 +02002631
Johannes Berg682bd382013-01-29 13:13:50 +01002632 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02002633 sdata_info(sdata, "Connection to AP %pM lost\n",
2634 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01002635 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02002636 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002637 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02002638 }
2639}
2640
2641static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2642{
2643 struct ieee80211_sub_if_data *sdata =
2644 container_of(work, struct ieee80211_sub_if_data,
2645 u.mgd.csa_connection_drop_work);
2646
Johannes Bergeef9e542013-01-29 13:09:34 +01002647 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002648}
2649
Kalle Valo04de8382009-03-22 21:57:35 +02002650void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2651{
2652 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002653 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02002654
Johannes Bergb5878a22010-04-07 16:48:40 +02002655 trace_api_beacon_loss(sdata);
2656
Johannes Berg682bd382013-01-29 13:13:50 +01002657 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002658 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002659}
2660EXPORT_SYMBOL(ieee80211_beacon_loss);
2661
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002662void ieee80211_connection_loss(struct ieee80211_vif *vif)
2663{
2664 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2665 struct ieee80211_hw *hw = &sdata->local->hw;
2666
Johannes Bergb5878a22010-04-07 16:48:40 +02002667 trace_api_connection_loss(sdata);
2668
Johannes Berg682bd382013-01-29 13:13:50 +01002669 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002670 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2671}
2672EXPORT_SYMBOL(ieee80211_connection_loss);
2673
2674
Johannes Berg66e67e42012-01-20 13:55:27 +01002675static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2676 bool assoc)
2677{
2678 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2679
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002680 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002681
Johannes Berg66e67e42012-01-20 13:55:27 +01002682 if (!assoc) {
Emmanuel Grumbachc1e140b2015-01-19 16:53:06 +02002683 /*
2684 * we are not authenticated yet, the only timer that could be
2685 * running is the timeout for the authentication response which
2686 * which is not relevant anymore.
2687 */
2688 del_timer_sync(&sdata->u.mgd.timer);
Johannes Berg66e67e42012-01-20 13:55:27 +01002689 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2690
Joe Perchesc84a67a2015-03-02 19:54:57 -08002691 eth_zero_addr(sdata->u.mgd.bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002692 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002693 sdata->u.mgd.flags = 0;
Johannes Berg34a37402013-12-18 09:43:33 +01002694 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002695 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002696 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01002697 }
2698
Johannes Berg5b112d32013-02-01 01:49:58 +01002699 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002700 kfree(auth_data);
2701 sdata->u.mgd.auth_data = NULL;
2702}
2703
Johannes Bergc9c99f82015-06-01 14:10:09 +02002704static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
Johannes Berge6f462d2016-12-08 17:22:09 +01002705 bool assoc, bool abandon)
Johannes Bergc9c99f82015-06-01 14:10:09 +02002706{
2707 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2708
2709 sdata_assert_lock(sdata);
2710
2711 if (!assoc) {
2712 /*
2713 * we are not associated yet, the only timer that could be
2714 * running is the timeout for the association response which
2715 * which is not relevant anymore.
2716 */
2717 del_timer_sync(&sdata->u.mgd.timer);
2718 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2719
2720 eth_zero_addr(sdata->u.mgd.bssid);
2721 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2722 sdata->u.mgd.flags = 0;
Sara Sharonb5a33d52016-02-16 12:48:18 +02002723 sdata->vif.mu_mimo_owner = false;
2724
Johannes Bergc9c99f82015-06-01 14:10:09 +02002725 mutex_lock(&sdata->local->mtx);
2726 ieee80211_vif_release_channel(sdata);
2727 mutex_unlock(&sdata->local->mtx);
Johannes Berge6f462d2016-12-08 17:22:09 +01002728
2729 if (abandon)
2730 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
Johannes Bergc9c99f82015-06-01 14:10:09 +02002731 }
2732
2733 kfree(assoc_data);
2734 sdata->u.mgd.assoc_data = NULL;
2735}
2736
Johannes Berg66e67e42012-01-20 13:55:27 +01002737static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2738 struct ieee80211_mgmt *mgmt, size_t len)
2739{
Johannes Berg1672c0e32013-01-29 15:02:27 +01002740 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01002741 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2742 u8 *pos;
2743 struct ieee802_11_elems elems;
Johannes Berg1672c0e32013-01-29 15:02:27 +01002744 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002745
2746 pos = mgmt->u.auth.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002747 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002748 if (!elems.challenge)
2749 return;
2750 auth_data->expected_transaction = 4;
Ilan Peerd4e36e52018-04-20 13:49:25 +03002751 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg30686bf2015-06-02 21:39:54 +02002752 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Johannes Berg1672c0e32013-01-29 15:02:27 +01002753 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2754 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03002755 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01002756 elems.challenge - 2, elems.challenge_len + 2,
2757 auth_data->bss->bssid, auth_data->bss->bssid,
2758 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002759 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002760}
2761
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002762static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2763 struct ieee80211_mgmt *mgmt, size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002764{
2765 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2766 u8 bssid[ETH_ALEN];
2767 u16 auth_alg, auth_transaction, status_code;
2768 struct sta_info *sta;
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002769 struct ieee80211_event event = {
2770 .type = MLME_EVENT,
2771 .u.mlme.data = AUTH_EVENT,
2772 };
Johannes Berg66e67e42012-01-20 13:55:27 +01002773
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002774 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002775
2776 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002777 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002778
2779 if (!ifmgd->auth_data || ifmgd->auth_data->done)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002780 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002781
2782 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2783
Joe Perchesb203ca32012-05-08 18:56:52 +00002784 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002785 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002786
2787 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2788 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2789 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2790
2791 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002792 auth_transaction != ifmgd->auth_data->expected_transaction) {
2793 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2794 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2795 auth_transaction,
2796 ifmgd->auth_data->expected_transaction);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002797 return;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002798 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002799
2800 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002801 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2802 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002803 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002804 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002805 event.u.mlme.status = MLME_DENIED;
2806 event.u.mlme.reason = status_code;
2807 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002808 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002809 }
2810
2811 switch (ifmgd->auth_data->algorithm) {
2812 case WLAN_AUTH_OPEN:
2813 case WLAN_AUTH_LEAP:
2814 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002815 case WLAN_AUTH_SAE:
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03002816 case WLAN_AUTH_FILS_SK:
2817 case WLAN_AUTH_FILS_SK_PFS:
2818 case WLAN_AUTH_FILS_PK:
Johannes Berg66e67e42012-01-20 13:55:27 +01002819 break;
2820 case WLAN_AUTH_SHARED_KEY:
2821 if (ifmgd->auth_data->expected_transaction != 4) {
2822 ieee80211_auth_challenge(sdata, mgmt, len);
2823 /* need another frame */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002824 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002825 }
2826 break;
2827 default:
2828 WARN_ONCE(1, "invalid auth alg %d",
2829 ifmgd->auth_data->algorithm);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002830 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002831 }
2832
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02002833 event.u.mlme.status = MLME_SUCCESS;
2834 drv_event_callback(sdata->local, sdata, &event);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002835 sdata_info(sdata, "authenticated\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002836 ifmgd->auth_data->done = true;
2837 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
Johannes Berg89afe612013-02-13 15:39:57 +01002838 ifmgd->auth_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002839 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01002840
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002841 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2842 ifmgd->auth_data->expected_transaction != 2) {
2843 /*
2844 * Report auth frame to user space for processing since another
2845 * round of Authentication frames is still needed.
2846 */
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002847 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002848 return;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002849 }
2850
Johannes Berg66e67e42012-01-20 13:55:27 +01002851 /* move station state to auth */
2852 mutex_lock(&sdata->local->sta_mtx);
2853 sta = sta_info_get(sdata, bssid);
2854 if (!sta) {
2855 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2856 goto out_err;
2857 }
2858 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002859 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002860 goto out_err;
2861 }
2862 mutex_unlock(&sdata->local->sta_mtx);
2863
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002864 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002865 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002866 out_err:
2867 mutex_unlock(&sdata->local->sta_mtx);
2868 /* ignore frame -- wait for timeout */
Johannes Berg66e67e42012-01-20 13:55:27 +01002869}
2870
Calvin Owensdfa1ad22014-02-11 12:36:24 -06002871#define case_WLAN(type) \
2872 case WLAN_REASON_##type: return #type
2873
2874static const char *ieee80211_get_reason_code_string(u16 reason_code)
2875{
2876 switch (reason_code) {
2877 case_WLAN(UNSPECIFIED);
2878 case_WLAN(PREV_AUTH_NOT_VALID);
2879 case_WLAN(DEAUTH_LEAVING);
2880 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
2881 case_WLAN(DISASSOC_AP_BUSY);
2882 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
2883 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
2884 case_WLAN(DISASSOC_STA_HAS_LEFT);
2885 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
2886 case_WLAN(DISASSOC_BAD_POWER);
2887 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
2888 case_WLAN(INVALID_IE);
2889 case_WLAN(MIC_FAILURE);
2890 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
2891 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
2892 case_WLAN(IE_DIFFERENT);
2893 case_WLAN(INVALID_GROUP_CIPHER);
2894 case_WLAN(INVALID_PAIRWISE_CIPHER);
2895 case_WLAN(INVALID_AKMP);
2896 case_WLAN(UNSUPP_RSN_VERSION);
2897 case_WLAN(INVALID_RSN_IE_CAP);
2898 case_WLAN(IEEE8021X_FAILED);
2899 case_WLAN(CIPHER_SUITE_REJECTED);
2900 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
2901 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
2902 case_WLAN(DISASSOC_LOW_ACK);
2903 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
2904 case_WLAN(QSTA_LEAVE_QBSS);
2905 case_WLAN(QSTA_NOT_USE);
2906 case_WLAN(QSTA_REQUIRE_SETUP);
2907 case_WLAN(QSTA_TIMEOUT);
2908 case_WLAN(QSTA_CIPHER_NOT_SUPP);
2909 case_WLAN(MESH_PEER_CANCELED);
2910 case_WLAN(MESH_MAX_PEERS);
2911 case_WLAN(MESH_CONFIG);
2912 case_WLAN(MESH_CLOSE);
2913 case_WLAN(MESH_MAX_RETRIES);
2914 case_WLAN(MESH_CONFIRM_TIMEOUT);
2915 case_WLAN(MESH_INVALID_GTK);
2916 case_WLAN(MESH_INCONSISTENT_PARAM);
2917 case_WLAN(MESH_INVALID_SECURITY);
2918 case_WLAN(MESH_PATH_ERROR);
2919 case_WLAN(MESH_PATH_NOFORWARD);
2920 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
2921 case_WLAN(MAC_EXISTS_IN_MBSS);
2922 case_WLAN(MESH_CHAN_REGULATORY);
2923 case_WLAN(MESH_CHAN);
2924 default: return "<unknown>";
2925 }
2926}
Johannes Berg66e67e42012-01-20 13:55:27 +01002927
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002928static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2929 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002930{
Johannes Berg46900292009-02-15 12:44:28 +01002931 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergc9c99f82015-06-01 14:10:09 +02002932 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002933
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002934 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002935
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002936 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002937 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002938
Johannes Bergc9c99f82015-06-01 14:10:09 +02002939 if (ifmgd->associated &&
2940 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
2941 const u8 *bssid = ifmgd->associated->bssid;
2942
2943 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
2944 bssid, reason_code,
2945 ieee80211_get_reason_code_string(reason_code));
2946
2947 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2948
2949 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
2950 reason_code);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002951 return;
Johannes Bergc9c99f82015-06-01 14:10:09 +02002952 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002953
Johannes Bergc9c99f82015-06-01 14:10:09 +02002954 if (ifmgd->assoc_data &&
2955 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2956 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002957
Johannes Bergc9c99f82015-06-01 14:10:09 +02002958 sdata_info(sdata,
2959 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
2960 bssid, reason_code,
2961 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07002962
Johannes Berge6f462d2016-12-08 17:22:09 +01002963 ieee80211_destroy_assoc_data(sdata, false, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07002964
Johannes Bergc9c99f82015-06-01 14:10:09 +02002965 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2966 return;
2967 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002968}
2969
2970
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002971static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2972 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002973{
Johannes Berg46900292009-02-15 12:44:28 +01002974 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002975 u16 reason_code;
2976
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002977 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002978
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002979 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002980 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002981
Johannes Berg66e67e42012-01-20 13:55:27 +01002982 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002983 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002984 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002985
2986 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2987
Arkadiusz Miskiewicz68506e92017-02-15 14:21:27 +01002988 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
2989 mgmt->sa, reason_code,
2990 ieee80211_get_reason_code_string(reason_code));
Jiri Bencf0706e82007-05-05 11:45:53 -07002991
Johannes Berg37ad3882012-02-24 13:50:54 +01002992 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2993
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02002994 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002995}
2996
Christian Lamparterc74d0842011-10-15 00:14:49 +02002997static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2998 u8 *supp_rates, unsigned int supp_rates_len,
2999 u32 *rates, u32 *basic_rates,
3000 bool *have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003001 int *min_rate, int *min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03003002 int shift)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003003{
3004 int i, j;
3005
3006 for (i = 0; i < supp_rates_len; i++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003007 int rate = supp_rates[i] & 0x7f;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003008 bool is_basic = !!(supp_rates[i] & 0x80);
3009
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003010 if ((rate * 5 * (1 << shift)) > 110)
Christian Lamparterc74d0842011-10-15 00:14:49 +02003011 *have_higher_than_11mbit = true;
3012
3013 /*
Johannes Berga6289d32017-03-06 22:59:04 +01003014 * Skip HT and VHT BSS membership selectors since they're not
3015 * rates.
Christian Lamparterc74d0842011-10-15 00:14:49 +02003016 *
Johannes Berga6289d32017-03-06 22:59:04 +01003017 * Note: Even though the membership selector and the basic
Christian Lamparterc74d0842011-10-15 00:14:49 +02003018 * rate flag share the same bit, they are not exactly
3019 * the same.
3020 */
Johannes Berga6289d32017-03-06 22:59:04 +01003021 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3022 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
Christian Lamparterc74d0842011-10-15 00:14:49 +02003023 continue;
3024
3025 for (j = 0; j < sband->n_bitrates; j++) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003026 struct ieee80211_rate *br;
3027 int brate;
3028
3029 br = &sband->bitrates[j];
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003030
3031 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3032 if (brate == rate) {
Christian Lamparterc74d0842011-10-15 00:14:49 +02003033 *rates |= BIT(j);
3034 if (is_basic)
3035 *basic_rates |= BIT(j);
Simon Wunderlich2103dec2013-07-08 16:55:53 +02003036 if ((rate * 5) < *min_rate) {
3037 *min_rate = rate * 5;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003038 *min_rate_index = j;
3039 }
3040 break;
3041 }
3042 }
3043 }
3044}
Jiri Bencf0706e82007-05-05 11:45:53 -07003045
Johannes Berg66e67e42012-01-20 13:55:27 +01003046static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3047 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003048 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07003049{
Johannes Berg46900292009-02-15 12:44:28 +01003050 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01003051 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01003052 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07003053 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003054 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003055 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07003056 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02003057 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg35d865a2013-05-28 10:54:03 +02003058 const struct cfg80211_bss_ies *bss_ies = NULL;
3059 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
Johannes Bergae5eb022008-10-14 16:58:37 +02003060 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02003061 int err;
Johannes Berg35d865a2013-05-28 10:54:03 +02003062 bool ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003063
Johannes Bergaf6b6372009-12-23 13:15:35 +01003064 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07003065
Jiri Bencf0706e82007-05-05 11:45:53 -07003066 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003067 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07003068
Johannes Bergc7c477b2017-12-01 13:50:51 +02003069 /*
3070 * The 5 MSB of the AID field are reserved
3071 * (802.11-2016 9.4.1.8 AID field)
3072 */
3073 aid &= 0x7ff;
Johannes Berg1dd84aa2007-10-10 12:03:41 +02003074
Johannes Berg05cb9102011-10-28 11:59:47 +02003075 ifmgd->broken_ap = false;
3076
3077 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003078 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3079 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02003080 aid = 0;
3081 ifmgd->broken_ap = true;
3082 }
3083
Johannes Bergaf6b6372009-12-23 13:15:35 +01003084 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01003085 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003086
Jiri Bencf0706e82007-05-05 11:45:53 -07003087 if (!elems.supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003088 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01003089 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07003090 }
3091
Johannes Berg46900292009-02-15 12:44:28 +01003092 ifmgd->aid = aid;
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02003093 ifmgd->tdls_chan_switch_prohibited =
3094 elems.ext_capab && elems.ext_capab_len >= 5 &&
3095 (elems.ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
Jiri Bencf0706e82007-05-05 11:45:53 -07003096
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003097 /*
Johannes Berg35d865a2013-05-28 10:54:03 +02003098 * Some APs are erroneously not including some information in their
3099 * (re)association response frames. Try to recover by using the data
3100 * from the beacon or probe response. This seems to afflict mobile
3101 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3102 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3103 */
3104 if ((assoc_data->wmm && !elems.wmm_param) ||
3105 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3106 (!elems.ht_cap_elem || !elems.ht_operation)) ||
3107 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3108 (!elems.vht_cap_elem || !elems.vht_operation))) {
3109 const struct cfg80211_bss_ies *ies;
3110 struct ieee802_11_elems bss_elems;
3111
3112 rcu_read_lock();
3113 ies = rcu_dereference(cbss->ies);
3114 if (ies)
3115 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3116 GFP_ATOMIC);
3117 rcu_read_unlock();
3118 if (!bss_ies)
3119 return false;
3120
3121 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3122 false, &bss_elems);
3123 if (assoc_data->wmm &&
3124 !elems.wmm_param && bss_elems.wmm_param) {
3125 elems.wmm_param = bss_elems.wmm_param;
3126 sdata_info(sdata,
3127 "AP bug: WMM param missing from AssocResp\n");
3128 }
3129
3130 /*
3131 * Also check if we requested HT/VHT, otherwise the AP doesn't
3132 * have to include the IEs in the (re)association response.
3133 */
3134 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
3135 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3136 elems.ht_cap_elem = bss_elems.ht_cap_elem;
3137 sdata_info(sdata,
3138 "AP bug: HT capability missing from AssocResp\n");
3139 }
3140 if (!elems.ht_operation && bss_elems.ht_operation &&
3141 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3142 elems.ht_operation = bss_elems.ht_operation;
3143 sdata_info(sdata,
3144 "AP bug: HT operation missing from AssocResp\n");
3145 }
3146 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
3147 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3148 elems.vht_cap_elem = bss_elems.vht_cap_elem;
3149 sdata_info(sdata,
3150 "AP bug: VHT capa missing from AssocResp\n");
3151 }
3152 if (!elems.vht_operation && bss_elems.vht_operation &&
3153 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3154 elems.vht_operation = bss_elems.vht_operation;
3155 sdata_info(sdata,
3156 "AP bug: VHT operation missing from AssocResp\n");
3157 }
3158 }
3159
3160 /*
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003161 * We previously checked these in the beacon/probe response, so
3162 * they should be present here. This is just a safety net.
3163 */
3164 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3165 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
3166 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003167 "HT AP is missing WMM params or HT capability/operation\n");
3168 ret = false;
3169 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003170 }
3171
3172 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3173 (!elems.vht_cap_elem || !elems.vht_operation)) {
3174 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02003175 "VHT AP is missing VHT capability/operation\n");
3176 ret = false;
3177 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003178 }
3179
Guy Eilam2a33bee2011-08-17 15:18:15 +03003180 mutex_lock(&sdata->local->sta_mtx);
3181 /*
3182 * station info was already allocated and inserted before
3183 * the association and should be available to us
3184 */
Johannes Berg7852e362012-01-20 13:55:24 +01003185 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003186 if (WARN_ON(!sta)) {
3187 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003188 ret = false;
3189 goto out;
Jiri Bencf0706e82007-05-05 11:45:53 -07003190 }
3191
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05303192 sband = ieee80211_get_sband(sdata);
3193 if (!sband) {
3194 mutex_unlock(&sdata->local->sta_mtx);
3195 ret = false;
3196 goto out;
3197 }
Johannes Berg8318d782008-01-24 19:38:38 +01003198
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003199 /*
3200 * If AP doesn't support HT, or it doesn't have HE mandatory IEs, mark
3201 * HE as disabled. If on the 5GHz band, make sure it supports VHT.
3202 */
3203 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
3204 (sband->band == NL80211_BAND_5GHZ &&
3205 ifmgd->flags & IEEE80211_STA_DISABLE_VHT) ||
3206 (!elems.he_cap && !elems.he_operation))
3207 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
3208
3209 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3210 (!elems.he_cap || !elems.he_operation)) {
3211 mutex_unlock(&sdata->local->sta_mtx);
3212 sdata_info(sdata,
3213 "HE AP is missing HE capability/operation\n");
3214 ret = false;
3215 goto out;
3216 }
3217
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003218 /* Set up internal HT/VHT capabilities */
Johannes Berga8243b72012-11-22 14:32:09 +01003219 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08003220 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01003221 elems.ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02003222
Mahesh Palivela818255e2012-10-10 11:33:04 +00003223 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3224 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01003225 elems.vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00003226
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003227 if (elems.he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3228 elems.he_cap) {
3229 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3230 elems.he_cap,
3231 elems.he_cap_len,
3232 sta);
3233
3234 bss_conf->he_support = sta->sta.he_cap.has_he;
3235 } else {
3236 bss_conf->he_support = false;
3237 }
3238
3239 if (bss_conf->he_support) {
3240 u32 he_oper_params =
3241 le32_to_cpu(elems.he_operation->he_oper_params);
3242
3243 bss_conf->bss_color = he_oper_params &
3244 IEEE80211_HE_OPERATION_BSS_COLOR_MASK;
3245 bss_conf->htc_trig_based_pkt_ext =
3246 (he_oper_params &
3247 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK) <<
3248 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_OFFSET;
3249 bss_conf->frame_time_rts_th =
3250 (he_oper_params &
3251 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK) <<
3252 IEEE80211_HE_OPERATION_RTS_THRESHOLD_OFFSET;
3253
3254 bss_conf->multi_sta_back_32bit =
3255 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3256 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
3257
3258 bss_conf->ack_enabled =
3259 sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3260 IEEE80211_HE_MAC_CAP2_ACK_EN;
3261
3262 bss_conf->uora_exists = !!elems.uora_element;
3263 if (elems.uora_element)
3264 bss_conf->uora_ocw_range = elems.uora_element[0];
3265
3266 /* TODO: OPEN: what happens if BSS color disable is set? */
3267 }
3268
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003269 /*
3270 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3271 * in their association response, so ignore that data for our own
3272 * configuration. If it changed since the last beacon, we'll get the
3273 * next beacon and update then.
3274 */
Johannes Berg11289582013-02-07 17:36:12 +01003275
Johannes Bergbee7f582013-02-07 22:24:55 +01003276 /*
3277 * If an operating mode notification IE is present, override the
3278 * NSS calculation (that would be done in rate_control_rate_init())
3279 * and use the # of streams from that element.
3280 */
3281 if (elems.opmode_notif &&
3282 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3283 u8 nss;
3284
3285 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3286 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3287 nss += 1;
3288 sta->sta.rx_nss = nss;
3289 }
3290
Johannes Berg4b7679a2008-09-18 18:14:18 +02003291 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07003292
Tamizh chelvam93f04902015-10-07 10:40:04 +05303293 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003294 set_sta_flag(sta, WLAN_STA_MFP);
Tamizh chelvam93f04902015-10-07 10:40:04 +05303295 sta->sta.mfp = true;
3296 } else {
3297 sta->sta.mfp = false;
3298 }
Jouni Malinen5394af42009-01-08 13:31:59 +02003299
Johannes Berg527871d2015-03-21 08:09:55 +01003300 sta->sta.wme = elems.wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
Johannes Bergddf4ac52008-10-22 11:41:38 +02003301
Johannes Berg3e4d40f2013-02-07 17:19:08 +01003302 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01003303 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3304 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3305 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003306 sdata_info(sdata,
3307 "failed to move station %pM to desired state\n",
3308 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01003309 WARN_ON(__sta_info_destroy(sta));
3310 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02003311 ret = false;
3312 goto out;
Johannes Bergc8987872012-01-20 13:55:17 +01003313 }
3314
Johannes Berg7852e362012-01-20 13:55:24 +01003315 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02003316
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03003317 /*
3318 * Always handle WMM once after association regardless
3319 * of the first value the AP uses. Setting -1 here has
3320 * that effect because the AP values is an unsigned
3321 * 4-bit value.
3322 */
3323 ifmgd->wmm_last_param_set = -1;
3324
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003325 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Bergcec66282015-10-22 17:46:04 +02003326 ieee80211_set_wmm_default(sdata, false, false);
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003327 } else if (!ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003328 elems.wmm_param_len,
3329 elems.mu_edca_param_set)) {
Johannes Berg2ed77ea2015-10-22 17:46:06 +02003330 /* still enable QoS since we might have HT/VHT */
3331 ieee80211_set_wmm_default(sdata, false, true);
3332 /* set the disable-WMM flag in this case to disable
3333 * tracking WMM parameter changes in the beacon if
3334 * the parameters weren't actually valid. Doing so
3335 * avoids changing parameters very strangely when
3336 * the AP is going back and forth between valid and
3337 * invalid parameters.
3338 */
3339 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3340 }
Johannes Berg3abead52012-03-02 15:56:59 +01003341 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07003342
Avraham Sterne38a0172017-04-26 10:58:47 +03003343 if (elems.max_idle_period_ie) {
3344 bss_conf->max_idle_period =
3345 le16_to_cpu(elems.max_idle_period_ie->max_idle_period);
3346 bss_conf->protected_keep_alive =
3347 !!(elems.max_idle_period_ie->idle_options &
3348 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3349 changed |= BSS_CHANGED_KEEP_ALIVE;
3350 } else {
3351 bss_conf->max_idle_period = 0;
3352 bss_conf->protected_keep_alive = false;
3353 }
3354
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003355 /* set AID and assoc capability,
3356 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01003357 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07003358 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003359 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003360
Kalle Valo15b7b062009-03-22 21:57:14 +02003361 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01003362 * If we're using 4-addr mode, let the AP know that we're
3363 * doing so, so that it can create the STA VLAN on its side
3364 */
3365 if (ifmgd->use_4addr)
3366 ieee80211_send_4addr_nullfunc(local, sdata);
3367
3368 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02003369 * Start timer to probe the connection to the AP now.
3370 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02003371 */
Johannes Bergb291ba12009-07-10 15:29:03 +02003372 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003373 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02003374
Johannes Berg35d865a2013-05-28 10:54:03 +02003375 ret = true;
3376 out:
3377 kfree(bss_ies);
3378 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07003379}
3380
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003381static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3382 struct ieee80211_mgmt *mgmt,
3383 size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01003384{
3385 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3386 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3387 u16 capab_info, status_code, aid;
3388 struct ieee802_11_elems elems;
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003389 int ac, uapsd_queues = -1;
Johannes Berg66e67e42012-01-20 13:55:27 +01003390 u8 *pos;
3391 bool reassoc;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003392 struct cfg80211_bss *bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003393 struct ieee80211_event event = {
3394 .type = MLME_EVENT,
3395 .u.mlme.data = ASSOC_EVENT,
3396 };
Jiri Bencf0706e82007-05-05 11:45:53 -07003397
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003398 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003399
3400 if (!assoc_data)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003401 return;
Joe Perchesb203ca32012-05-08 18:56:52 +00003402 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003403 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003404
3405 /*
3406 * AssocResp and ReassocResp have identical structure, so process both
3407 * of them in this function.
3408 */
3409
3410 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003411 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003412
Simon Dinkin7a7d3e42017-08-31 13:09:36 +03003413 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
Johannes Berg66e67e42012-01-20 13:55:27 +01003414 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3415 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3416 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3417
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003418 sdata_info(sdata,
3419 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3420 reassoc ? "Rea" : "A", mgmt->sa,
3421 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01003422
Jouni Malinen39404fe2016-10-27 00:42:05 +03003423 if (assoc_data->fils_kek_len &&
3424 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3425 return;
3426
Johannes Berg66e67e42012-01-20 13:55:27 +01003427 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01003428 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01003429
3430 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01003431 elems.timeout_int &&
3432 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003433 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01003434 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01003435 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003436 sdata_info(sdata,
3437 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3438 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01003439 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01003440 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01003441 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003442 run_again(sdata, assoc_data->timeout);
3443 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003444 }
3445
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003446 bss = assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01003447
3448 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003449 sdata_info(sdata, "%pM denied association (code=%d)\n",
3450 mgmt->sa, status_code);
Johannes Berge6f462d2016-12-08 17:22:09 +01003451 ieee80211_destroy_assoc_data(sdata, false, false);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003452 event.u.mlme.status = MLME_DENIED;
3453 event.u.mlme.reason = status_code;
3454 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01003455 } else {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003456 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003457 /* oops -- internal error -- send timeout for now */
Johannes Berge6f462d2016-12-08 17:22:09 +01003458 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02003459 cfg80211_assoc_timeout(sdata->dev, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003460 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01003461 }
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02003462 event.u.mlme.status = MLME_SUCCESS;
3463 drv_event_callback(sdata->local, sdata, &event);
John W. Linville635d9992012-07-09 16:34:34 -04003464 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01003465
3466 /*
3467 * destroy assoc_data afterwards, as otherwise an idle
3468 * recalc after assoc_data is NULL but before associated
3469 * is set can cause the interface to go idle
3470 */
Johannes Berge6f462d2016-12-08 17:22:09 +01003471 ieee80211_destroy_assoc_data(sdata, true, false);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003472
3473 /* get uapsd queues configuration */
3474 uapsd_queues = 0;
3475 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3476 if (sdata->tx_conf[ac].uapsd)
Emmanuel Grumbachf438ceb2016-10-18 23:12:12 +03003477 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
Johannes Berg66e67e42012-01-20 13:55:27 +01003478 }
3479
Eliad Pellerb0b6aa22014-09-09 17:09:45 +03003480 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues);
Johannes Berg66e67e42012-01-20 13:55:27 +01003481}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003482
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003483static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01003484 struct ieee80211_mgmt *mgmt, size_t len,
Jiri Bencf0706e82007-05-05 11:45:53 -07003485 struct ieee80211_rx_status *rx_status,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003486 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07003487{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003488 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02003489 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01003490 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01003491
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003492 sdata_assert_lock(sdata);
Johannes Bergb4f286a12013-03-26 14:13:58 +01003493
Emmanuel Grumbach3afc2162014-03-04 16:50:13 +02003494 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3495 if (!channel)
Johannes Berg5bda6172008-09-08 11:05:10 +02003496 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07003497
Johannes Berg98c8fcc2008-09-08 17:44:26 +02003498 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003499 channel);
Alexander Bondar817cee72013-05-19 14:23:57 +03003500 if (bss) {
Alexander Bondar817cee72013-05-19 14:23:57 +03003501 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
Johannes Bergd2722f82014-03-04 11:43:28 +01003502 ieee80211_rx_bss_put(local, bss);
Alexander Bondar817cee72013-05-19 14:23:57 +03003503 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003504}
3505
3506
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12003507static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01003508 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003509{
Johannes Bergaf6b6372009-12-23 13:15:35 +01003510 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02003511 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003512 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3513 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03003514 struct ieee802_11_elems elems;
3515
Kalle Valo15b7b062009-03-22 21:57:14 +02003516 ifmgd = &sdata->u.mgd;
3517
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003518 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003519
Joe Perchesb203ca32012-05-08 18:56:52 +00003520 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03003521 return; /* ignore ProbeResp to foreign address */
3522
Ester Kummerae6a44e2008-06-27 18:54:48 +03003523 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3524 if (baselen > len)
3525 return;
3526
3527 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003528 false, &elems);
Ester Kummerae6a44e2008-06-27 18:54:48 +03003529
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003530 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03003531
Johannes Berg77fdaa12009-07-07 03:45:17 +02003532 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00003533 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003534 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003535}
3536
Johannes Bergd91f36d2009-04-16 13:17:26 +02003537/*
3538 * This is the canonical list of information elements we care about,
3539 * the filter code also gives us all changes to the Microsoft OUI
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003540 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3541 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3542 * changes to requested client power.
Johannes Bergd91f36d2009-04-16 13:17:26 +02003543 *
3544 * We implement beacon filtering in software since that means we can
3545 * avoid processing the frame here and in cfg80211, and userspace
3546 * will not be able to tell whether the hardware supports it or not.
3547 *
3548 * XXX: This list needs to be dynamic -- userspace needs to be able to
3549 * add items it requires. It also needs to be able to tell us to
3550 * look out for other vendor IEs.
3551 */
3552static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02003553 (1ULL << WLAN_EID_COUNTRY) |
3554 (1ULL << WLAN_EID_ERP_INFO) |
3555 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3556 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3557 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg70a3fd62015-03-12 08:53:29 +02003558 (1ULL << WLAN_EID_HT_OPERATION) |
3559 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
Johannes Bergd91f36d2009-04-16 13:17:26 +02003560
Tosoni1ad22fb2018-03-14 16:58:34 +00003561static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3562 struct ieee80211_if_managed *ifmgd,
3563 struct ieee80211_bss_conf *bss_conf,
3564 struct ieee80211_local *local,
3565 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07003566{
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003567 /* Track average RSSI from the Beacon frames of the current AP */
Tosoni1ad22fb2018-03-14 16:58:34 +00003568
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003569 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3570 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Johannes Berg338c17a2015-08-28 10:52:54 +02003571 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003572 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03003573 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003574 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003575 } else {
Jouni Malinen391a2002010-08-27 22:22:00 +03003576 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003577 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003578
Johannes Berg338c17a2015-08-28 10:52:54 +02003579 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3580
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003581 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3582 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003583 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003584 int last_sig = ifmgd->last_ave_beacon_signal;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003585 struct ieee80211_event event = {
3586 .type = RSSI_EVENT,
3587 };
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003588
3589 /*
3590 * if signal crosses either of the boundaries, invoke callback
3591 * with appropriate parameters
3592 */
3593 if (sig > ifmgd->rssi_max_thold &&
3594 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3595 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003596 event.u.rssi.data = RSSI_EVENT_HIGH;
3597 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003598 } else if (sig < ifmgd->rssi_min_thold &&
3599 (last_sig >= ifmgd->rssi_max_thold ||
3600 last_sig == 0)) {
3601 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbacha8182922015-03-16 23:23:34 +02003602 event.u.rssi.data = RSSI_EVENT_LOW;
3603 drv_event_callback(local, sdata, &event);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003604 }
3605 }
3606
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003607 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03003608 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01003609 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Johannes Berg338c17a2015-08-28 10:52:54 +02003610 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003611 int last_event = ifmgd->last_cqm_event_signal;
3612 int thold = bss_conf->cqm_rssi_thold;
3613 int hyst = bss_conf->cqm_rssi_hyst;
Johannes Berg338c17a2015-08-28 10:52:54 +02003614
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003615 if (sig < thold &&
3616 (last_event == 0 || sig < last_event - hyst)) {
3617 ifmgd->last_cqm_event_signal = sig;
3618 ieee80211_cqm_rssi_notify(
3619 &sdata->vif,
3620 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003621 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003622 } else if (sig > thold &&
3623 (last_event == 0 || sig > last_event + hyst)) {
3624 ifmgd->last_cqm_event_signal = sig;
3625 ieee80211_cqm_rssi_notify(
3626 &sdata->vif,
3627 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01003628 sig, GFP_KERNEL);
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003629 }
3630 }
3631
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003632 if (bss_conf->cqm_rssi_low &&
3633 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3634 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3635 int last_event = ifmgd->last_cqm_event_signal;
3636 int low = bss_conf->cqm_rssi_low;
3637 int high = bss_conf->cqm_rssi_high;
3638
3639 if (sig < low &&
3640 (last_event == 0 || last_event >= low)) {
3641 ifmgd->last_cqm_event_signal = sig;
3642 ieee80211_cqm_rssi_notify(
3643 &sdata->vif,
3644 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3645 sig, GFP_KERNEL);
3646 } else if (sig > high &&
3647 (last_event == 0 || last_event <= high)) {
3648 ifmgd->last_cqm_event_signal = sig;
3649 ieee80211_cqm_rssi_notify(
3650 &sdata->vif,
3651 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3652 sig, GFP_KERNEL);
3653 }
3654 }
Tosoni1ad22fb2018-03-14 16:58:34 +00003655}
3656
3657static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3658 struct ieee80211_mgmt *mgmt, size_t len,
3659 struct ieee80211_rx_status *rx_status)
3660{
3661 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3662 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3663 size_t baselen;
3664 struct ieee802_11_elems elems;
3665 struct ieee80211_local *local = sdata->local;
3666 struct ieee80211_chanctx_conf *chanctx_conf;
3667 struct ieee80211_channel *chan;
3668 struct sta_info *sta;
3669 u32 changed = 0;
3670 bool erp_valid;
3671 u8 erp_value = 0;
3672 u32 ncrc;
3673 u8 *bssid;
3674 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3675
3676 sdata_assert_lock(sdata);
3677
3678 /* Process beacon from the current BSS */
3679 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
3680 if (baselen > len)
3681 return;
3682
3683 rcu_read_lock();
3684 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3685 if (!chanctx_conf) {
3686 rcu_read_unlock();
3687 return;
3688 }
3689
3690 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
3691 rcu_read_unlock();
3692 return;
3693 }
3694 chan = chanctx_conf->def.chan;
3695 rcu_read_unlock();
3696
3697 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
3698 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3699 ieee802_11_parse_elems(mgmt->u.beacon.variable,
3700 len - baselen, false, &elems);
3701
3702 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
3703 if (elems.tim && !elems.parse_error) {
3704 const struct ieee80211_tim_ie *tim_ie = elems.tim;
3705 ifmgd->dtim_period = tim_ie->dtim_period;
3706 }
3707 ifmgd->have_beacon = true;
3708 ifmgd->assoc_data->need_beacon = false;
3709 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
3710 sdata->vif.bss_conf.sync_tsf =
3711 le64_to_cpu(mgmt->u.beacon.timestamp);
3712 sdata->vif.bss_conf.sync_device_ts =
3713 rx_status->device_timestamp;
3714 if (elems.tim)
3715 sdata->vif.bss_conf.sync_dtim_count =
3716 elems.tim->dtim_count;
3717 else
3718 sdata->vif.bss_conf.sync_dtim_count = 0;
3719 }
3720 /* continue assoc process */
3721 ifmgd->assoc_data->timeout = jiffies;
3722 ifmgd->assoc_data->timeout_started = true;
3723 run_again(sdata, ifmgd->assoc_data->timeout);
3724 return;
3725 }
3726
3727 if (!ifmgd->associated ||
3728 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3729 return;
3730 bssid = ifmgd->associated->bssid;
3731
3732 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
3733 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
3734 local, rx_status);
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003735
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003736 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003737 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01003738 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02003739 ieee80211_reset_ap_probe(sdata);
Jouni Malinen92778182009-05-14 21:15:36 +03003740 }
3741
Johannes Bergb291ba12009-07-10 15:29:03 +02003742 /*
3743 * Push the beacon loss detection into the future since
3744 * we are processing a beacon from the AP just now.
3745 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003746 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003747
Johannes Bergd91f36d2009-04-16 13:17:26 +02003748 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3749 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003750 len - baselen, false, &elems,
Johannes Bergd91f36d2009-04-16 13:17:26 +02003751 care_about_ies, ncrc);
3752
Johannes Berg90d13e82015-09-24 16:13:07 +02003753 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
3754 ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
3755 if (local->hw.conf.dynamic_ps_timeout > 0) {
3756 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3757 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3758 ieee80211_hw_config(local,
3759 IEEE80211_CONF_CHANGE_PS);
Kalle Valo572e0012009-02-10 17:09:31 +02003760 }
Johannes Berg076cdcb2015-09-24 16:14:55 +02003761 ieee80211_send_nullfunc(local, sdata, false);
Johannes Berg90d13e82015-09-24 16:13:07 +02003762 } else if (!local->pspolling && sdata->u.mgd.powersave) {
3763 local->pspolling = true;
3764
3765 /*
3766 * Here is assumed that the driver will be
3767 * able to send ps-poll frame and receive a
3768 * response even though power save mode is
3769 * enabled, but some drivers might require
3770 * to disable power save here. This needs
3771 * to be investigated.
3772 */
3773 ieee80211_send_pspoll(local, sdata);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003774 }
3775 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003776
Janusz.Dziedzic@tieto.comb115b972015-10-27 08:38:40 +01003777 if (sdata->vif.p2p ||
3778 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003779 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003780 int ret;
3781
3782 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3783 len - baselen,
3784 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003785 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003786 if (ret >= 2) {
3787 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3788 /* valid noa_attr and index changed */
3789 sdata->u.mgd.p2p_noa_index = noa.index;
3790 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3791 changed |= BSS_CHANGED_P2P_PS;
3792 /*
3793 * make sure we update all information, the CRC
3794 * mechanism doesn't look at P2P attributes.
3795 */
3796 ifmgd->beacon_crc_valid = false;
3797 }
3798 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3799 /* noa_attr not found and we had valid noa_attr before */
3800 sdata->u.mgd.p2p_noa_index = -1;
3801 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003802 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003803 ifmgd->beacon_crc_valid = false;
3804 }
3805 }
3806
Luciano Coelho0c21e632014-10-08 09:48:39 +03003807 if (ifmgd->csa_waiting_bcn)
3808 ieee80211_chswitch_post_beacon(sdata);
3809
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003810 /*
3811 * Update beacon timing and dtim count on every beacon appearance. This
3812 * will allow the driver to use the most updated values. Do it before
3813 * comparing this one with last received beacon.
3814 * IMPORTANT: These parameters would possibly be out of sync by the time
3815 * the driver will use them. The synchronized view is currently
3816 * guaranteed only in certain callbacks.
3817 */
Johannes Berg30686bf2015-06-02 21:39:54 +02003818 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Alexander Bondar2ecc3902015-03-01 09:10:00 +02003819 sdata->vif.bss_conf.sync_tsf =
3820 le64_to_cpu(mgmt->u.beacon.timestamp);
3821 sdata->vif.bss_conf.sync_device_ts =
3822 rx_status->device_timestamp;
3823 if (elems.tim)
3824 sdata->vif.bss_conf.sync_dtim_count =
3825 elems.tim->dtim_count;
3826 else
3827 sdata->vif.bss_conf.sync_dtim_count = 0;
3828 }
3829
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003830 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003831 return;
Jouni Malinen30196672009-05-19 17:01:43 +03003832 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003833 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03003834
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003835 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg7d257452012-07-06 17:37:43 +02003836
Johannes Bergd70b7612013-08-23 15:48:48 +02003837 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003838 rx_status->device_timestamp,
Johannes Bergd70b7612013-08-23 15:48:48 +02003839 &elems, true);
3840
Johannes Berg095d81c2013-10-15 12:25:07 +02003841 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
3842 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003843 elems.wmm_param_len,
3844 elems.mu_edca_param_set))
Johannes Berg7d257452012-07-06 17:37:43 +02003845 changed |= BSS_CHANGED_QOS;
3846
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003847 /*
3848 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01003849 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003850 */
Alexander Bondar989c6502013-05-16 17:34:17 +03003851 if (!ifmgd->have_beacon) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003852 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3853 if (elems.tim)
3854 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3855 else
3856 bss_conf->dtim_period = 1;
Johannes Bergef429da2013-02-05 17:48:40 +01003857
Alexander Bondar989c6502013-05-16 17:34:17 +03003858 changed |= BSS_CHANGED_BEACON_INFO;
3859 ifmgd->have_beacon = true;
Alexander Bondar482a9c72013-06-03 17:29:33 +03003860
3861 mutex_lock(&local->iflist_mtx);
Johannes Berg4a733ef2015-10-14 18:02:43 +02003862 ieee80211_recalc_ps(local);
Alexander Bondar482a9c72013-06-03 17:29:33 +03003863 mutex_unlock(&local->iflist_mtx);
3864
Alexander Bondarce857882013-05-06 17:17:04 +03003865 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003866 }
3867
Johannes Berg1946bed2013-03-27 14:31:53 +01003868 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02003869 erp_valid = true;
3870 erp_value = elems.erp_info[0];
3871 } else {
3872 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04003873 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003874 changed |= ieee80211_handle_bss_capability(sdata,
3875 le16_to_cpu(mgmt->u.beacon.capab_info),
3876 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07003877
Johannes Berg11289582013-02-07 17:36:12 +01003878 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f582013-02-07 22:24:55 +01003879 sta = sta_info_get(sdata, bssid);
3880
Eliad Peller53b954e2014-07-24 11:20:05 +03003881 if (ieee80211_config_bw(sdata, sta,
3882 elems.ht_cap_elem, elems.ht_operation,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03003883 elems.vht_operation, elems.he_operation,
3884 bssid, &changed)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003885 mutex_unlock(&local->sta_mtx);
Johannes Berg89f774e2016-01-25 15:46:36 +02003886 sdata_info(sdata,
3887 "failed to follow AP %pM bandwidth change, disconnect\n",
3888 bssid);
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003889 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3890 WLAN_REASON_DEAUTH_LEAVING,
3891 true, deauth_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02003892 ieee80211_report_disconnect(sdata, deauth_buf,
3893 sizeof(deauth_buf), true,
3894 WLAN_REASON_DEAUTH_LEAVING);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003895 return;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003896 }
Johannes Bergbee7f582013-02-07 22:24:55 +01003897
3898 if (sta && elems.opmode_notif)
3899 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
Eyal Shapiracf1e05c2015-12-08 16:04:36 +02003900 rx_status->band);
Johannes Berg11289582013-02-07 17:36:12 +01003901 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003902
Steinar H. Gunderson24a4e402014-09-03 06:22:10 -07003903 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
3904 elems.country_elem,
3905 elems.country_elem_len,
Steinar H. Gundersonc8d65912014-09-03 06:48:37 -07003906 elems.pwr_constr_elem,
3907 elems.cisco_dtpc_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08003908
Johannes Berg471b3ef2007-12-28 14:32:58 +01003909 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003910}
3911
Johannes Berg1fa57d02010-06-10 10:21:32 +02003912void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3913 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003914{
3915 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07003916 struct ieee80211_mgmt *mgmt;
3917 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003918 struct ieee802_11_elems elems;
3919 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07003920
Jiri Bencf0706e82007-05-05 11:45:53 -07003921 rx_status = (struct ieee80211_rx_status *) skb->cb;
3922 mgmt = (struct ieee80211_mgmt *) skb->data;
3923 fc = le16_to_cpu(mgmt->frame_control);
3924
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003925 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003926
Johannes Berg66e67e42012-01-20 13:55:27 +01003927 switch (fc & IEEE80211_FCTL_STYPE) {
3928 case IEEE80211_STYPE_BEACON:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003929 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01003930 break;
3931 case IEEE80211_STYPE_PROBE_RESP:
3932 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3933 break;
3934 case IEEE80211_STYPE_AUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003935 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003936 break;
3937 case IEEE80211_STYPE_DEAUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003938 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003939 break;
3940 case IEEE80211_STYPE_DISASSOC:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003941 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003942 break;
3943 case IEEE80211_STYPE_ASSOC_RESP:
3944 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003945 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003946 break;
3947 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01003948 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003949 ies_len = skb->len -
3950 offsetof(struct ieee80211_mgmt,
3951 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01003952
3953 if (ies_len < 0)
3954 break;
3955
3956 ieee802_11_parse_elems(
3957 mgmt->u.action.u.chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003958 ies_len, true, &elems);
Johannes Berg37799e52013-03-26 14:02:26 +01003959
3960 if (elems.parse_error)
3961 break;
3962
Johannes Berg66e67e42012-01-20 13:55:27 +01003963 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003964 rx_status->mactime,
3965 rx_status->device_timestamp,
3966 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003967 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3968 ies_len = skb->len -
3969 offsetof(struct ieee80211_mgmt,
3970 u.action.u.ext_chan_switch.variable);
3971
3972 if (ies_len < 0)
3973 break;
3974
3975 ieee802_11_parse_elems(
3976 mgmt->u.action.u.ext_chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003977 ies_len, true, &elems);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003978
3979 if (elems.parse_error)
3980 break;
3981
3982 /* for the handling code pretend this was also an IE */
3983 elems.ext_chansw_ie =
3984 &mgmt->u.action.u.ext_chan_switch.data;
3985
3986 ieee80211_sta_process_chanswitch(sdata,
Luciano Coelho2ba45382014-10-08 09:48:35 +03003987 rx_status->mactime,
3988 rx_status->device_timestamp,
3989 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003990 }
Johannes Berg37799e52013-03-26 14:02:26 +01003991 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003992 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003993 sdata_unlock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003994}
3995
Kees Cook34f11cd2017-10-16 16:35:49 -07003996static void ieee80211_sta_timer(struct timer_list *t)
Jiri Bencf0706e82007-05-05 11:45:53 -07003997{
3998 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07003999 from_timer(sdata, t, u.mgd.timer);
Jiri Bencf0706e82007-05-05 11:45:53 -07004000
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01004001 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07004002}
4003
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004004static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01004005 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004006{
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004007 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004008
Johannes Berg37ad3882012-02-24 13:50:54 +01004009 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01004010 tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01004011
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004012 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4013 reason);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004014}
4015
Johannes Berg46cad4b2015-08-15 22:39:54 +03004016static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg66e67e42012-01-20 13:55:27 +01004017{
4018 struct ieee80211_local *local = sdata->local;
4019 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4020 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004021 u32 tx_flags = 0;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004022 u16 trans = 1;
4023 u16 status = 0;
Ilan Peerd4e36e52018-04-20 13:49:25 +03004024 u16 prepare_tx_duration = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004025
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004026 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004027
4028 if (WARN_ON_ONCE(!auth_data))
4029 return -EINVAL;
4030
Johannes Berg66e67e42012-01-20 13:55:27 +01004031 auth_data->tries++;
4032
4033 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004034 sdata_info(sdata, "authentication with %pM timed out\n",
4035 auth_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, auth_data->bss);
4042
4043 return -ETIMEDOUT;
4044 }
4045
Ilan Peerd4e36e52018-04-20 13:49:25 +03004046 if (auth_data->algorithm == WLAN_AUTH_SAE)
4047 prepare_tx_duration =
4048 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4049
4050 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
Johannes Berga1845fc2012-06-27 13:18:36 +02004051
Johannes Berg46cad4b2015-08-15 22:39:54 +03004052 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4053 auth_data->bss->bssid, auth_data->tries,
4054 IEEE80211_AUTH_MAX_TRIES);
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004055
Johannes Berg46cad4b2015-08-15 22:39:54 +03004056 auth_data->expected_transaction = 2;
Johannes Berg66e67e42012-01-20 13:55:27 +01004057
Johannes Berg46cad4b2015-08-15 22:39:54 +03004058 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4059 trans = auth_data->sae_trans;
4060 status = auth_data->sae_status;
4061 auth_data->expected_transaction = trans;
Johannes Berg66e67e42012-01-20 13:55:27 +01004062 }
4063
Johannes Berg46cad4b2015-08-15 22:39:54 +03004064 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4065 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4066 IEEE80211_TX_INTFL_MLME_CONN_TX;
4067
4068 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4069 auth_data->data, auth_data->data_len,
4070 auth_data->bss->bssid,
4071 auth_data->bss->bssid, NULL, 0, 0,
4072 tx_flags);
4073
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02004074 if (tx_flags == 0) {
Ilan Peer407879b2018-04-20 13:49:20 +03004075 if (auth_data->algorithm == WLAN_AUTH_SAE)
4076 auth_data->timeout = jiffies +
4077 IEEE80211_AUTH_TIMEOUT_SAE;
4078 else
4079 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004080 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004081 auth_data->timeout =
4082 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004083 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004084
Ilan Peer407879b2018-04-20 13:49:20 +03004085 auth_data->timeout_started = true;
4086 run_again(sdata, auth_data->timeout);
4087
Johannes Berg66e67e42012-01-20 13:55:27 +01004088 return 0;
4089}
4090
4091static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4092{
4093 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4094 struct ieee80211_local *local = sdata->local;
4095
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004096 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004097
Johannes Berg66e67e42012-01-20 13:55:27 +01004098 assoc_data->tries++;
4099 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004100 sdata_info(sdata, "association with %pM timed out\n",
4101 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004102
4103 /*
4104 * Most likely AP is not in the range so remove the
4105 * bss struct for that AP.
4106 */
4107 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4108
4109 return -ETIMEDOUT;
4110 }
4111
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004112 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4113 assoc_data->bss->bssid, assoc_data->tries,
4114 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01004115 ieee80211_send_assoc(sdata);
4116
Johannes Berg30686bf2015-06-02 21:39:54 +02004117 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004118 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01004119 assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004120 run_again(sdata, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01004121 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02004122 assoc_data->timeout =
4123 round_jiffies_up(jiffies +
4124 IEEE80211_ASSOC_TIMEOUT_LONG);
4125 assoc_data->timeout_started = true;
4126 run_again(sdata, assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004127 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004128
4129 return 0;
4130}
4131
Johannes Berg1672c0e32013-01-29 15:02:27 +01004132void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4133 __le16 fc, bool acked)
4134{
4135 struct ieee80211_local *local = sdata->local;
4136
4137 sdata->u.mgd.status_fc = fc;
4138 sdata->u.mgd.status_acked = acked;
4139 sdata->u.mgd.status_received = true;
4140
4141 ieee80211_queue_work(&local->hw, &sdata->work);
4142}
4143
Johannes Berg1fa57d02010-06-10 10:21:32 +02004144void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02004145{
Johannes Berg60f8b392008-09-08 17:44:22 +02004146 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02004147 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02004148
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004149 sdata_lock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02004150
Johannes Berg1672c0e32013-01-29 15:02:27 +01004151 if (ifmgd->status_received) {
4152 __le16 fc = ifmgd->status_fc;
4153 bool status_acked = ifmgd->status_acked;
4154
4155 ifmgd->status_received = false;
Johannes Berg46cad4b2015-08-15 22:39:54 +03004156 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01004157 if (status_acked) {
Ilan Peer407879b2018-04-20 13:49:20 +03004158 if (ifmgd->auth_data->algorithm ==
4159 WLAN_AUTH_SAE)
4160 ifmgd->auth_data->timeout =
4161 jiffies +
4162 IEEE80211_AUTH_TIMEOUT_SAE;
4163 else
4164 ifmgd->auth_data->timeout =
4165 jiffies +
4166 IEEE80211_AUTH_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004167 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004168 } else {
4169 ifmgd->auth_data->timeout = jiffies - 1;
4170 }
Johannes Berg89afe612013-02-13 15:39:57 +01004171 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004172 } else if (ifmgd->assoc_data &&
4173 (ieee80211_is_assoc_req(fc) ||
4174 ieee80211_is_reassoc_req(fc))) {
4175 if (status_acked) {
4176 ifmgd->assoc_data->timeout =
4177 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004178 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01004179 } else {
4180 ifmgd->assoc_data->timeout = jiffies - 1;
4181 }
Johannes Berg89afe612013-02-13 15:39:57 +01004182 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01004183 }
4184 }
4185
Johannes Berg89afe612013-02-13 15:39:57 +01004186 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004187 time_after(jiffies, ifmgd->auth_data->timeout)) {
4188 if (ifmgd->auth_data->done) {
4189 /*
4190 * ok ... we waited for assoc but userspace didn't,
4191 * so let's just kill the auth data
4192 */
4193 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg46cad4b2015-08-15 22:39:54 +03004194 } else if (ieee80211_auth(sdata)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004195 u8 bssid[ETH_ALEN];
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004196 struct ieee80211_event event = {
4197 .type = MLME_EVENT,
4198 .u.mlme.data = AUTH_EVENT,
4199 .u.mlme.status = MLME_TIMEOUT,
4200 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004201
4202 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4203
4204 ieee80211_destroy_auth_data(sdata, false);
4205
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004206 cfg80211_auth_timeout(sdata->dev, bssid);
Emmanuel Grumbacha9409092015-03-16 23:23:35 +02004207 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004208 }
Johannes Berg89afe612013-02-13 15:39:57 +01004209 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004210 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004211
Johannes Berg89afe612013-02-13 15:39:57 +01004212 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01004213 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Alexander Bondar989c6502013-05-16 17:34:17 +03004214 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01004215 ieee80211_do_assoc(sdata)) {
Johannes Berg959867f2013-06-19 13:05:42 +02004216 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004217 struct ieee80211_event event = {
4218 .type = MLME_EVENT,
4219 .u.mlme.data = ASSOC_EVENT,
4220 .u.mlme.status = MLME_TIMEOUT,
4221 };
Johannes Berg66e67e42012-01-20 13:55:27 +01004222
Johannes Berge6f462d2016-12-08 17:22:09 +01004223 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02004224 cfg80211_assoc_timeout(sdata->dev, bss);
Emmanuel Grumbachd0d1a122015-03-16 23:23:36 +02004225 drv_event_callback(sdata->local, sdata, &event);
Johannes Berg66e67e42012-01-20 13:55:27 +01004226 }
Johannes Berg89afe612013-02-13 15:39:57 +01004227 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004228 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004229
Stanislaw Gruszka392b9ff2013-08-27 11:36:35 +02004230 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
Johannes Bergb291ba12009-07-10 15:29:03 +02004231 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03004232 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004233 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03004234
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004235 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004236
Johannes Berg30686bf2015-06-02 21:39:54 +02004237 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
Ben Greear180205b2011-02-04 15:30:24 -08004238 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004239 else
Ben Greear180205b2011-02-04 15:30:24 -08004240 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01004241
Felix Fietkau4e5ff372010-11-23 03:10:31 +01004242 /* ACK received for nullfunc probing frame */
4243 if (!ifmgd->probe_send_count)
4244 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004245 else if (ifmgd->nullfunc_failed) {
4246 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004247 mlme_dbg(sdata,
4248 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4249 bssid, ifmgd->probe_send_count,
4250 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004251 ieee80211_mgd_probe_ap_send(sdata);
4252 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004253 mlme_dbg(sdata,
4254 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4255 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02004256 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004257 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4258 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004259 }
4260 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004261 run_again(sdata, ifmgd->probe_timeout);
Johannes Berg30686bf2015-06-02 21:39:54 +02004262 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004263 mlme_dbg(sdata,
4264 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4265 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02004266 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004267 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004268 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004269 mlme_dbg(sdata,
4270 "No probe response from AP %pM after %dms, try %d/%i\n",
4271 bssid, probe_wait_ms,
4272 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03004273 ieee80211_mgd_probe_ap_send(sdata);
4274 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02004275 /*
4276 * We actually lost the connection ... or did we?
4277 * Let's make sure!
4278 */
Johannes Berg89f774e2016-01-25 15:46:36 +02004279 mlme_dbg(sdata,
4280 "No probe response from AP %pM after %dms, disconnecting.\n",
4281 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01004282
Johannes Berg95acac62011-07-12 12:30:59 +02004283 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01004284 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02004285 }
4286 }
4287
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004288 sdata_unlock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02004289}
Johannes Berg0a51b272008-09-08 17:44:25 +02004290
Kees Cook34f11cd2017-10-16 16:35:49 -07004291static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004292{
4293 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004294 from_timer(sdata, t, u.mgd.bcn_mon_timer);
Luciano Coelho0c21e632014-10-08 09:48:39 +03004295 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004296
Luciano Coelho0c21e632014-10-08 09:48:39 +03004297 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004298 return;
4299
Johannes Berg682bd382013-01-29 13:13:50 +01004300 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004301 ieee80211_queue_work(&sdata->local->hw,
4302 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004303}
4304
Kees Cook34f11cd2017-10-16 16:35:49 -07004305static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
Johannes Bergb291ba12009-07-10 15:29:03 +02004306{
4307 struct ieee80211_sub_if_data *sdata =
Kees Cook34f11cd2017-10-16 16:35:49 -07004308 from_timer(sdata, t, u.mgd.conn_mon_timer);
Johannes Bergb291ba12009-07-10 15:29:03 +02004309 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4310 struct ieee80211_local *local = sdata->local;
4311
Luciano Coelho0c21e632014-10-08 09:48:39 +03004312 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
Michal Kaziore5593f52014-04-09 15:45:36 +02004313 return;
4314
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04004315 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02004316}
4317
4318static void ieee80211_sta_monitor_work(struct work_struct *work)
4319{
4320 struct ieee80211_sub_if_data *sdata =
4321 container_of(work, struct ieee80211_sub_if_data,
4322 u.mgd.monitor_work);
4323
4324 ieee80211_mgd_probe_ap(sdata, false);
4325}
4326
Johannes Berga1678f82008-09-11 00:01:47 +02004327static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4328{
Kalle Vaload935682009-04-19 08:47:19 +03004329 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02004330 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03004331
Johannes Bergb291ba12009-07-10 15:29:03 +02004332 /* let's probe the connection once */
Johannes Berg30686bf2015-06-02 21:39:54 +02004333 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
Eliad Peller494f1fe2012-02-19 15:26:09 +02004334 ieee80211_queue_work(&sdata->local->hw,
4335 &sdata->u.mgd.monitor_work);
Kalle Vaload935682009-04-19 08:47:19 +03004336 }
Johannes Berga1678f82008-09-11 00:01:47 +02004337}
4338
Johannes Bergb8360ab2013-04-29 14:57:44 +02004339#ifdef CONFIG_PM
Johannes Berg1a1cb742014-03-19 09:55:55 +01004340void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4341{
4342 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4343 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4344
4345 sdata_lock(sdata);
4346
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004347 if (ifmgd->auth_data || ifmgd->assoc_data) {
4348 const u8 *bssid = ifmgd->auth_data ?
4349 ifmgd->auth_data->bss->bssid :
4350 ifmgd->assoc_data->bss->bssid;
4351
Johannes Berg1a1cb742014-03-19 09:55:55 +01004352 /*
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004353 * If we are trying to authenticate / associate while suspending,
4354 * cfg80211 won't know and won't actually abort those attempts,
4355 * thus we need to do that ourselves.
Johannes Berg1a1cb742014-03-19 09:55:55 +01004356 */
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004357 ieee80211_send_deauth_disassoc(sdata, bssid,
Johannes Berg1a1cb742014-03-19 09:55:55 +01004358 IEEE80211_STYPE_DEAUTH,
4359 WLAN_REASON_DEAUTH_LEAVING,
4360 false, frame_buf);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004361 if (ifmgd->assoc_data)
Johannes Berge6f462d2016-12-08 17:22:09 +01004362 ieee80211_destroy_assoc_data(sdata, false, true);
Emmanuel Grumbachc52666a2014-05-13 12:54:09 +03004363 if (ifmgd->auth_data)
4364 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg1a1cb742014-03-19 09:55:55 +01004365 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4366 IEEE80211_DEAUTH_FRAME_LEN);
4367 }
4368
Johannes Bergbe72afe2015-03-01 09:10:03 +02004369 /* This is a bit of a hack - we should find a better and more generic
4370 * solution to this. Normally when suspending, cfg80211 will in fact
4371 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4372 * auth (not so important) or assoc (this is the problem) process.
4373 *
4374 * As a consequence, it can happen that we are in the process of both
4375 * associating and suspending, and receive an association response
4376 * after cfg80211 has checked if it needs to disconnect, but before
4377 * we actually set the flag to drop incoming frames. This will then
4378 * cause the workqueue flush to process the association response in
4379 * the suspend, resulting in a successful association just before it
4380 * tries to remove the interface from the driver, which now though
4381 * has a channel context assigned ... this results in issues.
4382 *
4383 * To work around this (for now) simply deauth here again if we're
4384 * now connected.
4385 */
4386 if (ifmgd->associated && !sdata->local->wowlan) {
4387 u8 bssid[ETH_ALEN];
4388 struct cfg80211_deauth_request req = {
4389 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4390 .bssid = bssid,
4391 };
4392
4393 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4394 ieee80211_mgd_deauth(sdata, &req);
4395 }
4396
Johannes Berg1a1cb742014-03-19 09:55:55 +01004397 sdata_unlock(sdata);
4398}
4399
Johannes Bergb8360ab2013-04-29 14:57:44 +02004400void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4401{
4402 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4403
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004404 sdata_lock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004405 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004406 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004407 return;
4408 }
4409
4410 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4411 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4412 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4413 ieee80211_sta_connection_lost(sdata,
4414 ifmgd->associated->bssid,
4415 WLAN_REASON_UNSPECIFIED,
4416 true);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004417 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004418 return;
4419 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004420 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02004421}
4422#endif
4423
Johannes Berg9c6bd792008-09-11 00:01:52 +02004424/* interface setup */
4425void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4426{
Johannes Berg46900292009-02-15 12:44:28 +01004427 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004428
Johannes Berg46900292009-02-15 12:44:28 +01004429 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02004430 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01004431 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02004432 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4433 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02004434 INIT_WORK(&ifmgd->csa_connection_drop_work,
4435 ieee80211_csa_connection_drop_work);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03004436 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03004437 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4438 ieee80211_tdls_peer_del_work);
Kees Cook34f11cd2017-10-16 16:35:49 -07004439 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4440 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4441 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4442 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
Johannes Berg02219b32014-10-07 10:38:50 +03004443 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4444 ieee80211_sta_handle_tspec_ac_params_wk);
Johannes Berg9c6bd792008-09-11 00:01:52 +02004445
Johannes Bergab1faea2009-07-01 21:41:17 +02004446 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05304447 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02004448 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4449 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01004450 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02004451
Eliad Peller0d8614b2014-09-10 14:07:36 +03004452 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
Johannes Berg0f782312009-12-01 13:37:02 +01004453 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4454 else
4455 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Liad Kaufman1277b4a2014-11-09 18:50:08 +02004456
4457 /* Setup TDLS data */
4458 spin_lock_init(&ifmgd->teardown_lock);
4459 ifmgd->teardown_skb = NULL;
4460 ifmgd->orig_teardown_skb = NULL;
Johannes Berg9c6bd792008-09-11 00:01:52 +02004461}
4462
4463/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02004464void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4465{
Johannes Berg31ee67a2012-07-06 21:18:24 +02004466 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02004467
4468 /* Restart STA timers */
4469 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07004470 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4471 if (ieee80211_sdata_running(sdata))
4472 ieee80211_restart_sta_timer(sdata);
4473 }
Johannes Berga1678f82008-09-11 00:01:47 +02004474 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02004475}
Johannes Berg10f644a2009-04-16 13:17:25 +02004476
Johannes Bergf2d9d272012-11-22 14:11:39 +01004477static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4478 struct cfg80211_bss *cbss)
4479{
4480 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4481 const u8 *ht_cap_ie, *vht_cap_ie;
4482 const struct ieee80211_ht_cap *ht_cap;
4483 const struct ieee80211_vht_cap *vht_cap;
4484 u8 chains = 1;
4485
4486 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4487 return chains;
4488
Johannes Berg9caf0362012-11-29 01:25:20 +01004489 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004490 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4491 ht_cap = (void *)(ht_cap_ie + 2);
4492 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4493 /*
4494 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4495 * "Tx Unequal Modulation Supported" fields.
4496 */
4497 }
4498
4499 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4500 return chains;
4501
Johannes Berg9caf0362012-11-29 01:25:20 +01004502 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004503 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4504 u8 nss;
4505 u16 tx_mcs_map;
4506
4507 vht_cap = (void *)(vht_cap_ie + 2);
4508 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4509 for (nss = 8; nss > 0; nss--) {
4510 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4511 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4512 break;
4513 }
4514 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4515 chains = max(chains, nss);
4516 }
4517
4518 return chains;
4519}
4520
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004521static bool
4522ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4523 const struct ieee80211_he_operation *he_op)
4524{
4525 const struct ieee80211_sta_he_cap *sta_he_cap =
4526 ieee80211_get_he_sta_cap(sband);
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004527 u16 ap_min_req_set;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004528 int i;
4529
4530 if (!sta_he_cap || !he_op)
4531 return false;
4532
Gustavo A. R. Silva47aa7862018-06-18 07:41:34 -05004533 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4534
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004535 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4536 for (i = 0; i < 3; i++) {
4537 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4538 &sta_he_cap->he_mcs_nss_supp;
4539 u16 sta_mcs_map_rx =
4540 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4541 u16 sta_mcs_map_tx =
4542 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4543 u8 nss;
4544 bool verified = true;
4545
4546 /*
4547 * For each band there is a maximum of 8 spatial streams
4548 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4549 * of 2 bits per NSS (1-8), with the values defined in enum
4550 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4551 * capabilities aren't less than the AP's minimum requirements
4552 * for this HE BSS per SS.
4553 * It is enough to find one such band that meets the reqs.
4554 */
4555 for (nss = 8; nss > 0; nss--) {
4556 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4557 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4558 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4559
4560 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4561 continue;
4562
4563 /*
4564 * Make sure the HE AP doesn't require MCSs that aren't
4565 * supported by the client
4566 */
4567 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4568 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4569 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4570 verified = false;
4571 break;
4572 }
4573 }
4574
4575 if (verified)
4576 return true;
4577 }
4578
4579 /* If here, STA doesn't meet AP's HE min requirements */
4580 return false;
4581}
4582
Johannes Bergb17166a2012-07-27 11:41:27 +02004583static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4584 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01004585{
4586 struct ieee80211_local *local = sdata->local;
4587 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Peller53b954e2014-07-24 11:20:05 +03004588 const struct ieee80211_ht_cap *ht_cap = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004589 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004590 const struct ieee80211_vht_operation *vht_oper = NULL;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004591 const struct ieee80211_he_operation *he_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02004592 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01004593 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004594 int ret;
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004595 u32 i;
4596 bool have_80mhz;
Johannes Berga1cf7752012-03-08 15:02:07 +01004597
Johannes Berg24398e32012-03-28 10:58:36 +02004598 sband = local->hw.wiphy->bands[cbss->channel->band];
4599
Johannes Bergf2d9d272012-11-22 14:11:39 +01004600 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4601 IEEE80211_STA_DISABLE_80P80MHZ |
4602 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02004603
Johannes Berg9caf0362012-11-29 01:25:20 +01004604 rcu_read_lock();
4605
Johannes Bergf2d9d272012-11-22 14:11:39 +01004606 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
4607 sband->ht_cap.ht_supported) {
Eliad Peller53b954e2014-07-24 11:20:05 +03004608 const u8 *ht_oper_ie, *ht_cap_ie;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004609
Johannes Berg9caf0362012-11-29 01:25:20 +01004610 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02004611 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
4612 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6eff2013-02-07 23:33:32 +01004613
Eliad Peller53b954e2014-07-24 11:20:05 +03004614 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4615 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
4616 ht_cap = (void *)(ht_cap_ie + 2);
4617
4618 if (!ht_cap) {
Johannes Berg08e6eff2013-02-07 23:33:32 +01004619 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4620 ht_oper = NULL;
4621 }
Johannes Berg24398e32012-03-28 10:58:36 +02004622 }
4623
Johannes Bergf2d9d272012-11-22 14:11:39 +01004624 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
4625 sband->vht_cap.vht_supported) {
Johannes Berg08e6eff2013-02-07 23:33:32 +01004626 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01004627
Johannes Berg9caf0362012-11-29 01:25:20 +01004628 vht_oper_ie = ieee80211_bss_get_ie(cbss,
4629 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004630 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
4631 vht_oper = (void *)(vht_oper_ie + 2);
4632 if (vht_oper && !ht_oper) {
4633 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004634 sdata_info(sdata,
Johannes Bergf2d9d272012-11-22 14:11:39 +01004635 "AP advertised VHT without HT, disabling both\n");
Johannes Bergcb145022013-02-07 20:41:50 +01004636 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4637 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg24398e32012-03-28 10:58:36 +02004638 }
Johannes Berg08e6eff2013-02-07 23:33:32 +01004639
4640 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4641 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
4642 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4643 vht_oper = NULL;
4644 }
Johannes Berg24398e32012-03-28 10:58:36 +02004645 }
4646
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004647 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
4648 ieee80211_get_he_sta_cap(sband)) {
4649 const struct cfg80211_bss_ies *ies;
4650 const u8 *he_oper_ie;
4651
4652 ies = rcu_dereference(cbss->ies);
4653 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
4654 ies->data, ies->len);
4655 if (he_oper_ie &&
4656 he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
4657 he_oper = (void *)(he_oper_ie + 3);
4658 else
4659 he_oper = NULL;
4660
Johannes Bergf0c04072018-06-29 09:51:39 +02004661 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004662 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4663 }
4664
Arik Nemtsov52a45f32015-08-15 22:39:53 +03004665 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4666 have_80mhz = false;
4667 for (i = 0; i < sband->n_channels; i++) {
4668 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4669 IEEE80211_CHAN_NO_80MHZ))
4670 continue;
4671
4672 have_80mhz = true;
4673 break;
4674 }
4675
4676 if (!have_80mhz)
4677 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4678
Johannes Bergf2d9d272012-11-22 14:11:39 +01004679 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
4680 cbss->channel,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03004681 ht_oper, vht_oper, he_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +02004682 &chandef, false);
Johannes Berg04ecd252012-09-11 14:34:12 +02004683
Johannes Bergf2d9d272012-11-22 14:11:39 +01004684 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
4685 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02004686
Johannes Berg9caf0362012-11-29 01:25:20 +01004687 rcu_read_unlock();
4688
Johannes Berg04ecd252012-09-11 14:34:12 +02004689 /* will change later if needed */
4690 sdata->smps_mode = IEEE80211_SMPS_OFF;
4691
Johannes Berg34a37402013-12-18 09:43:33 +01004692 mutex_lock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004693 /*
4694 * If this fails (possibly due to channel context sharing
4695 * on incompatible channels, e.g. 80+80 and 160 sharing the
4696 * same control channel) try to use a smaller bandwidth.
4697 */
4698 ret = ieee80211_vif_use_channel(sdata, &chandef,
4699 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich0418a442013-05-16 13:00:31 +02004700
4701 /* don't downgrade for 5 and 10 MHz channels, though. */
4702 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4703 chandef.width == NL80211_CHAN_WIDTH_10)
Johannes Berg34a37402013-12-18 09:43:33 +01004704 goto out;
Simon Wunderlich0418a442013-05-16 13:00:31 +02004705
Johannes Bergd601cd82013-02-07 20:54:51 +01004706 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Simon Wunderliche6b7cde2013-08-28 13:41:29 +02004707 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01004708 ret = ieee80211_vif_use_channel(sdata, &chandef,
4709 IEEE80211_CHANCTX_SHARED);
4710 }
Johannes Berg34a37402013-12-18 09:43:33 +01004711 out:
4712 mutex_unlock(&local->mtx);
Johannes Bergf2d9d272012-11-22 14:11:39 +01004713 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02004714}
4715
4716static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004717 struct cfg80211_bss *cbss, bool assoc,
4718 bool override)
Johannes Bergb17166a2012-07-27 11:41:27 +02004719{
4720 struct ieee80211_local *local = sdata->local;
4721 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4722 struct ieee80211_bss *bss = (void *)cbss->priv;
4723 struct sta_info *new_sta = NULL;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004724 struct ieee80211_supported_band *sband;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004725 bool have_sta = false;
Johannes Bergb17166a2012-07-27 11:41:27 +02004726 int err;
4727
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004728 sband = local->hw.wiphy->bands[cbss->channel->band];
4729
Johannes Bergb17166a2012-07-27 11:41:27 +02004730 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
4731 return -EINVAL;
4732
Luca Coelhof8860ce2017-05-02 17:56:21 +03004733 /* If a reconfig is happening, bail out */
4734 if (local->in_reconfig)
4735 return -EBUSY;
4736
Johannes Bergb17166a2012-07-27 11:41:27 +02004737 if (assoc) {
4738 rcu_read_lock();
4739 have_sta = sta_info_get(sdata, cbss->bssid);
4740 rcu_read_unlock();
4741 }
4742
4743 if (!have_sta) {
4744 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
4745 if (!new_sta)
4746 return -ENOMEM;
4747 }
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004748
Johannes Bergc87905b2017-06-10 13:52:43 +03004749 /*
4750 * Set up the information for the new channel before setting the
4751 * new channel. We can't - completely race-free - change the basic
4752 * rates bitmap and the channel (sband) that it refers to, but if
4753 * we set it up before we at least avoid calling into the driver's
4754 * bss_info_changed() method with invalid information (since we do
4755 * call that from changing the channel - only for IDLE and perhaps
4756 * some others, but ...).
4757 *
4758 * So to avoid that, just set up all the new information before the
4759 * channel, but tell the driver to apply it only afterwards, since
4760 * it might need the new channel for that.
4761 */
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004762 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004763 u32 rates = 0, basic_rates = 0;
4764 bool have_higher_than_11mbit;
4765 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004766 const struct cfg80211_bss_ies *ies;
Chaya Rachel Ivgi179b8fc2014-12-14 10:38:59 +02004767 int shift = ieee80211_vif_get_shift(&sdata->vif);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004768
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004769 ieee80211_get_rates(sband, bss->supp_rates,
4770 bss->supp_rates_len,
4771 &rates, &basic_rates,
4772 &have_higher_than_11mbit,
Simon Wunderlich2103dec2013-07-08 16:55:53 +02004773 &min_rate, &min_rate_index,
Johannes Berg44f6d422017-06-10 13:52:44 +03004774 shift);
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004775
4776 /*
4777 * This used to be a workaround for basic rates missing
4778 * in the association response frame. Now that we no
4779 * longer use the basic rates from there, it probably
4780 * doesn't happen any more, but keep the workaround so
4781 * in case some *other* APs are buggy in different ways
4782 * we can connect -- with a warning.
4783 */
4784 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004785 sdata_info(sdata,
4786 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004787 basic_rates = BIT(min_rate_index);
4788 }
4789
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004790 new_sta->sta.supp_rates[cbss->channel->band] = rates;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004791 sdata->vif.bss_conf.basic_rates = basic_rates;
4792
4793 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg57fbcce2016-04-12 15:56:15 +02004794 if (cbss->channel->band == NL80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004795 have_higher_than_11mbit)
4796 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
4797 else
4798 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
4799
4800 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
4801
Johannes Berg8c358bc2012-05-22 22:13:05 +02004802 /* set timing information */
4803 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01004804 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01004805 ies = rcu_dereference(cbss->beacon_ies);
4806 if (ies) {
4807 const u8 *tim_ie;
4808
4809 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4810 sdata->vif.bss_conf.sync_device_ts =
4811 bss->device_ts_beacon;
4812 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4813 ies->data, ies->len);
4814 if (tim_ie && tim_ie[1] >= 2)
4815 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
4816 else
4817 sdata->vif.bss_conf.sync_dtim_count = 0;
Johannes Berg30686bf2015-06-02 21:39:54 +02004818 } else if (!ieee80211_hw_check(&sdata->local->hw,
4819 TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01004820 ies = rcu_dereference(cbss->proberesp_ies);
4821 /* must be non-NULL since beacon IEs were NULL */
4822 sdata->vif.bss_conf.sync_tsf = ies->tsf;
4823 sdata->vif.bss_conf.sync_device_ts =
4824 bss->device_ts_presp;
4825 sdata->vif.bss_conf.sync_dtim_count = 0;
4826 } else {
4827 sdata->vif.bss_conf.sync_tsf = 0;
4828 sdata->vif.bss_conf.sync_device_ts = 0;
4829 sdata->vif.bss_conf.sync_dtim_count = 0;
4830 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01004831 rcu_read_unlock();
Johannes Bergc87905b2017-06-10 13:52:43 +03004832 }
Johannes Berg8c358bc2012-05-22 22:13:05 +02004833
Johannes Bergc87905b2017-06-10 13:52:43 +03004834 if (new_sta || override) {
4835 err = ieee80211_prep_channel(sdata, cbss);
4836 if (err) {
4837 if (new_sta)
4838 sta_info_free(local, new_sta);
4839 return -EINVAL;
4840 }
4841 }
4842
4843 if (new_sta) {
4844 /*
4845 * tell driver about BSSID, basic rates and timing
4846 * this was set up above, before setting the channel
4847 */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01004848 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02004849 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
4850 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01004851
4852 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004853 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01004854
Johannes Berg13e0c8e2012-07-27 10:43:16 +02004855 err = sta_info_insert(new_sta);
4856 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01004857 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004858 sdata_info(sdata,
4859 "failed to insert STA entry for the AP (error %d)\n",
4860 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01004861 return err;
4862 }
4863 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00004864 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01004865
David Spinadel7d830a12015-03-17 19:58:38 +02004866 /* Cancel scan to ensure that nothing interferes with connection */
4867 if (local->scanning)
4868 ieee80211_scan_cancel(local);
4869
Johannes Berga1cf7752012-03-08 15:02:07 +01004870 return 0;
4871}
4872
Johannes Berg77fdaa12009-07-07 03:45:17 +02004873/* config hooks */
4874int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
4875 struct cfg80211_auth_request *req)
4876{
Johannes Berg66e67e42012-01-20 13:55:27 +01004877 struct ieee80211_local *local = sdata->local;
4878 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4879 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004880 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01004881 int err;
4882
4883 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02004884
4885 switch (req->auth_type) {
4886 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4887 auth_alg = WLAN_AUTH_OPEN;
4888 break;
4889 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01004890 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02004891 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004892 auth_alg = WLAN_AUTH_SHARED_KEY;
4893 break;
4894 case NL80211_AUTHTYPE_FT:
4895 auth_alg = WLAN_AUTH_FT;
4896 break;
4897 case NL80211_AUTHTYPE_NETWORK_EAP:
4898 auth_alg = WLAN_AUTH_LEAP;
4899 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004900 case NL80211_AUTHTYPE_SAE:
4901 auth_alg = WLAN_AUTH_SAE;
4902 break;
Jouni Malinendbc0c2c2016-10-27 00:42:04 +03004903 case NL80211_AUTHTYPE_FILS_SK:
4904 auth_alg = WLAN_AUTH_FILS_SK;
4905 break;
4906 case NL80211_AUTHTYPE_FILS_SK_PFS:
4907 auth_alg = WLAN_AUTH_FILS_SK_PFS;
4908 break;
4909 case NL80211_AUTHTYPE_FILS_PK:
4910 auth_alg = WLAN_AUTH_FILS_PK;
4911 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004912 default:
4913 return -EOPNOTSUPP;
4914 }
4915
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004916 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004917 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01004918 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004919 return -ENOMEM;
4920
Johannes Berg66e67e42012-01-20 13:55:27 +01004921 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004922
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004923 if (req->auth_data_len >= 4) {
Jouni Malinen6ec63612016-10-27 00:41:59 +03004924 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
4925 __le16 *pos = (__le16 *) req->auth_data;
4926
4927 auth_data->sae_trans = le16_to_cpu(pos[0]);
4928 auth_data->sae_status = le16_to_cpu(pos[1]);
4929 }
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03004930 memcpy(auth_data->data, req->auth_data + 4,
4931 req->auth_data_len - 4);
4932 auth_data->data_len += req->auth_data_len - 4;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004933 }
4934
Johannes Berg77fdaa12009-07-07 03:45:17 +02004935 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004936 memcpy(&auth_data->data[auth_data->data_len],
4937 req->ie, req->ie_len);
4938 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004939 }
4940
Johannes Bergfffd0932009-07-08 14:22:54 +02004941 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004942 auth_data->key_len = req->key_len;
4943 auth_data->key_idx = req->key_idx;
4944 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02004945 }
4946
Johannes Berg66e67e42012-01-20 13:55:27 +01004947 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004948
Johannes Berg66e67e42012-01-20 13:55:27 +01004949 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01004950
Johannes Berg66e67e42012-01-20 13:55:27 +01004951 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
4952 ifmgd->assoc_data) {
4953 err = -EBUSY;
4954 goto err_free;
4955 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004956
Johannes Berg66e67e42012-01-20 13:55:27 +01004957 if (ifmgd->auth_data)
4958 ieee80211_destroy_auth_data(sdata, false);
Guy Eilam2a33bee2011-08-17 15:18:15 +03004959
Johannes Berg66e67e42012-01-20 13:55:27 +01004960 /* prep auth_data so we don't go into idle on disassoc */
4961 ifmgd->auth_data = auth_data;
4962
Johannes Berg7b119dc2013-04-10 21:38:36 +02004963 if (ifmgd->associated) {
4964 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4965
Johannes Berg89f774e2016-01-25 15:46:36 +02004966 sdata_info(sdata,
4967 "disconnect from AP %pM for new auth to %pM\n",
4968 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02004969 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4970 WLAN_REASON_UNSPECIFIED,
4971 false, frame_buf);
4972
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02004973 ieee80211_report_disconnect(sdata, frame_buf,
4974 sizeof(frame_buf), true,
4975 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02004976 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004977
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004978 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004979
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03004980 err = ieee80211_prep_connection(sdata, req->bss, false, false);
Johannes Berga1cf7752012-03-08 15:02:07 +01004981 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01004982 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004983
Johannes Berg46cad4b2015-08-15 22:39:54 +03004984 err = ieee80211_auth(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01004985 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004986 sta_info_destroy_addr(sdata, req->bss->bssid);
4987 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004988 }
4989
Johannes Berg66e67e42012-01-20 13:55:27 +01004990 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01004991 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004992 return 0;
Johannes Berge5b900d2010-07-29 16:08:55 +02004993
Johannes Berg66e67e42012-01-20 13:55:27 +01004994 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08004995 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03004996 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01004997 ifmgd->auth_data = NULL;
Michal Kaziord01f8582015-06-03 08:36:13 +02004998 mutex_lock(&sdata->local->mtx);
4999 ieee80211_vif_release_channel(sdata);
5000 mutex_unlock(&sdata->local->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01005001 err_free:
5002 kfree(auth_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005003 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005004}
5005
Johannes Berg77fdaa12009-07-07 03:45:17 +02005006int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5007 struct cfg80211_assoc_request *req)
5008{
Johannes Berg66e67e42012-01-20 13:55:27 +01005009 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005010 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01005011 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01005012 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005013 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005014 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005015 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005016 int i, err;
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005017 bool override = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005018
Johannes Berg66e67e42012-01-20 13:55:27 +01005019 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5020 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01005021 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005022
Johannes Berg9caf0362012-11-29 01:25:20 +01005023 rcu_read_lock();
5024 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
5025 if (!ssidie) {
5026 rcu_read_unlock();
5027 kfree(assoc_data);
5028 return -EINVAL;
5029 }
5030 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5031 assoc_data->ssid_len = ssidie[1];
5032 rcu_read_unlock();
5033
Johannes Berg7b119dc2013-04-10 21:38:36 +02005034 if (ifmgd->associated) {
5035 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5036
Johannes Berg89f774e2016-01-25 15:46:36 +02005037 sdata_info(sdata,
5038 "disconnect from AP %pM for new assoc to %pM\n",
5039 ifmgd->associated->bssid, req->bss->bssid);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005040 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5041 WLAN_REASON_UNSPECIFIED,
5042 false, frame_buf);
5043
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005044 ieee80211_report_disconnect(sdata, frame_buf,
5045 sizeof(frame_buf), true,
5046 WLAN_REASON_UNSPECIFIED);
Johannes Berg7b119dc2013-04-10 21:38:36 +02005047 }
Johannes Berg66e67e42012-01-20 13:55:27 +01005048
5049 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5050 err = -EBUSY;
5051 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03005052 }
5053
Johannes Berg66e67e42012-01-20 13:55:27 +01005054 if (ifmgd->assoc_data) {
5055 err = -EBUSY;
5056 goto err_free;
5057 }
5058
5059 if (ifmgd->auth_data) {
5060 bool match;
5061
5062 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00005063 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01005064 ieee80211_destroy_auth_data(sdata, match);
5065 }
5066
5067 /* prepare assoc data */
Johannes Berg095d81c2013-10-15 12:25:07 +02005068
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03005069 ifmgd->beacon_crc_valid = false;
5070
Johannes Berg095d81c2013-10-15 12:25:07 +02005071 assoc_data->wmm = bss->wmm_used &&
5072 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg095d81c2013-10-15 12:25:07 +02005073
Johannes Bergde5036a2012-03-08 15:02:03 +01005074 /*
5075 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5076 * We still associate in non-HT mode (11a/b/g) if any one of these
5077 * ciphers is configured as pairwise.
5078 * We can set this to true for non-11n hardware, that'll be checked
5079 * separately along with the peer capabilities.
5080 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02005081 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02005082 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5083 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02005084 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01005085 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005086 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005087 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
Johannes Berg1c4cb922012-05-30 15:57:00 +02005088 netdev_info(sdata->dev,
Luca Coelho41cbb0f2018-06-09 09:14:44 +03005089 "disabling HE/HT/VHT due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005090 }
5091 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005092
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005093 /* Also disable HT if we don't support it or the AP doesn't use WMM */
5094 sband = local->hw.wiphy->bands[req->bss->channel->band];
5095 if (!sband->ht_cap.ht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005096 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5097 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Johannes Berga8243b72012-11-22 14:32:09 +01005098 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005099 if (!bss->wmm_used &&
5100 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005101 netdev_info(sdata->dev,
5102 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02005103 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01005104
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005105 /* disable VHT if we don't support it or the AP doesn't use WMM */
5106 if (!sband->vht_cap.vht_supported ||
Johannes Berg095d81c2013-10-15 12:25:07 +02005107 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
5108 ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005109 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg095d81c2013-10-15 12:25:07 +02005110 if (!bss->wmm_used &&
5111 !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
Johannes Berg1b49de22012-07-27 10:29:14 +02005112 netdev_info(sdata->dev,
5113 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00005114 }
5115
Ben Greearef96a8422011-11-18 11:32:00 -08005116 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5117 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5118 sizeof(ifmgd->ht_capa_mask));
5119
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01005120 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5121 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5122 sizeof(ifmgd->vht_capa_mask));
5123
Johannes Berg77fdaa12009-07-07 03:45:17 +02005124 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01005125 memcpy(assoc_data->ie, req->ie, req->ie_len);
5126 assoc_data->ie_len = req->ie_len;
5127 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02005128
Jouni Malinen39404fe2016-10-27 00:42:05 +03005129 if (req->fils_kek) {
5130 /* should already be checked in cfg80211 - so warn */
5131 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5132 err = -EINVAL;
5133 goto err_free;
5134 }
5135 memcpy(assoc_data->fils_kek, req->fils_kek,
5136 req->fils_kek_len);
5137 assoc_data->fils_kek_len = req->fils_kek_len;
5138 }
5139
5140 if (req->fils_nonces)
5141 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5142 2 * FILS_NONCE_LEN);
5143
Johannes Berg66e67e42012-01-20 13:55:27 +01005144 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01005145
Johannes Bergaf6b6372009-12-23 13:15:35 +01005146 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5147 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02005148 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005149 else
Johannes Berg04ecd252012-09-11 14:34:12 +02005150 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005151 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02005152 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01005153
Johannes Berg66e67e42012-01-20 13:55:27 +01005154 assoc_data->capability = req->bss->capability;
Johannes Berg66e67e42012-01-20 13:55:27 +01005155 assoc_data->supp_rates = bss->supp_rates;
5156 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02005157
Johannes Berg9caf0362012-11-29 01:25:20 +01005158 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02005159 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5160 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5161 assoc_data->ap_ht_param =
5162 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5163 else
Johannes Berga8243b72012-11-22 14:32:09 +01005164 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01005165 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5166 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5167 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5168 sizeof(struct ieee80211_vht_cap));
5169 else
5170 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01005171 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01005172
Johannes Berg848955c2014-11-11 12:48:42 +01005173 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02005174 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
Johannes Berg848955c2014-11-11 12:48:42 +01005175 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5176 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5177
Kalle Valoab133152010-01-12 10:42:31 +02005178 if (bss->wmm_used && bss->uapsd_supported &&
Johannes Berg848955c2014-11-11 12:48:42 +01005179 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01005180 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02005181 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5182 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01005183 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02005184 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5185 }
5186
Johannes Berg77fdaa12009-07-07 03:45:17 +02005187 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01005188 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005189
5190 if (req->use_mfp) {
5191 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5192 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5193 } else {
5194 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5195 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5196 }
5197
Assaf Krausscd2f5dd2014-09-03 15:25:02 +03005198 if (req->flags & ASSOC_REQ_USE_RRM)
5199 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5200 else
5201 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5202
Johannes Berg77fdaa12009-07-07 03:45:17 +02005203 if (req->crypto.control_port)
5204 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5205 else
5206 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5207
Johannes Berga621fa42010-08-27 14:26:54 +03005208 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5209 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05005210 sdata->control_port_over_nl80211 =
5211 req->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02005212 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5213 sdata->vif.type);
Johannes Berga621fa42010-08-27 14:26:54 +03005214
Johannes Berg66e67e42012-01-20 13:55:27 +01005215 /* kick off associate process */
5216
5217 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02005218 ifmgd->dtim_period = 0;
Alexander Bondar989c6502013-05-16 17:34:17 +03005219 ifmgd->have_beacon = false;
Johannes Berg66e67e42012-01-20 13:55:27 +01005220
Chaya Rachel Ivgic1041f12015-04-20 22:51:46 +03005221 /* override HT/VHT configuration only if the AP and we support it */
5222 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5223 struct ieee80211_sta_ht_cap sta_ht_cap;
5224
5225 if (req->flags & ASSOC_REQ_DISABLE_HT)
5226 override = true;
5227
5228 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5229 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5230
5231 /* check for 40 MHz disable override */
5232 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5233 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5234 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5235 override = true;
5236
5237 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5238 req->flags & ASSOC_REQ_DISABLE_VHT)
5239 override = true;
5240 }
5241
5242 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5243 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5244 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5245 }
5246
5247 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5248 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5249
5250 err = ieee80211_prep_connection(sdata, req->bss, true, override);
Johannes Berga1cf7752012-03-08 15:02:07 +01005251 if (err)
5252 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01005253
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005254 rcu_read_lock();
5255 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02005256
Johannes Berg30686bf2015-06-02 21:39:54 +02005257 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005258 !beacon_ies) {
5259 /*
5260 * Wait up to one beacon interval ...
5261 * should this be more if we miss one?
5262 */
5263 sdata_info(sdata, "waiting for beacon from %pM\n",
5264 ifmgd->bssid);
5265 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01005266 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005267 assoc_data->need_beacon = true;
5268 } else if (beacon_ies) {
5269 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
5270 beacon_ies->data,
5271 beacon_ies->len);
Johannes Bergef429da2013-02-05 17:48:40 +01005272 u8 dtim_count = 0;
5273
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005274 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
5275 const struct ieee80211_tim_ie *tim;
5276 tim = (void *)(tim_ie + 2);
5277 ifmgd->dtim_period = tim->dtim_period;
Johannes Bergef429da2013-02-05 17:48:40 +01005278 dtim_count = tim->dtim_count;
Johannes Berg826262c2012-12-10 16:38:14 +02005279 }
Alexander Bondar989c6502013-05-16 17:34:17 +03005280 ifmgd->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005281 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005282 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01005283
Johannes Berg30686bf2015-06-02 21:39:54 +02005284 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
Johannes Bergef429da2013-02-05 17:48:40 +01005285 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5286 sdata->vif.bss_conf.sync_device_ts =
5287 bss->device_ts_beacon;
5288 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5289 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005290 } else {
5291 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01005292 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01005293 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02005294 rcu_read_unlock();
5295
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005296 run_again(sdata, assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01005297
Paul Stewartfcff4f12012-02-23 17:59:53 -08005298 if (bss->corrupt_data) {
5299 char *corrupt_type = "data";
5300 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5301 if (bss->corrupt_data &
5302 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5303 corrupt_type = "beacon and probe response";
5304 else
5305 corrupt_type = "beacon";
5306 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5307 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005308 sdata_info(sdata, "associating with AP with corrupt %s\n",
5309 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08005310 }
5311
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005312 return 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01005313 err_clear:
Joe Perchesc84a67a2015-03-02 19:54:57 -08005314 eth_zero_addr(ifmgd->bssid);
Eliad Peller3d2abdf2012-09-04 17:44:45 +03005315 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01005316 ifmgd->assoc_data = NULL;
5317 err_free:
5318 kfree(assoc_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01005319 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005320}
5321
5322int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005323 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005324{
5325 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005326 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005327 bool tx = !req->local_state_change;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005328
Johannes Bergc9c3a062014-03-19 09:11:19 +01005329 if (ifmgd->auth_data &&
5330 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5331 sdata_info(sdata,
5332 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5333 req->bssid, req->reason_code,
5334 ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005335
Ilan Peerd4e36e52018-04-20 13:49:25 +03005336 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Johannes Berg37ad3882012-02-24 13:50:54 +01005337 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5338 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02005339 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01005340 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01005341 ieee80211_destroy_auth_data(sdata, false);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005342 ieee80211_report_disconnect(sdata, frame_buf,
5343 sizeof(frame_buf), true,
5344 req->reason_code);
Johannes Berg86552012012-10-29 09:46:31 +01005345
Johannes Bergc9c3a062014-03-19 09:11:19 +01005346 return 0;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03005347 }
5348
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005349 if (ifmgd->assoc_data &&
5350 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5351 sdata_info(sdata,
5352 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5353 req->bssid, req->reason_code,
5354 ieee80211_get_reason_code_string(req->reason_code));
5355
Ilan Peerd4e36e52018-04-20 13:49:25 +03005356 drv_mgd_prepare_tx(sdata->local, sdata, 0);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005357 ieee80211_send_deauth_disassoc(sdata, req->bssid,
5358 IEEE80211_STYPE_DEAUTH,
5359 req->reason_code, tx,
5360 frame_buf);
Johannes Berge6f462d2016-12-08 17:22:09 +01005361 ieee80211_destroy_assoc_data(sdata, false, true);
Andrei Otcheretianskia64cba32015-10-25 10:59:38 +02005362 ieee80211_report_disconnect(sdata, frame_buf,
5363 sizeof(frame_buf), true,
5364 req->reason_code);
5365 return 0;
5366 }
5367
Johannes Berg86552012012-10-29 09:46:31 +01005368 if (ifmgd->associated &&
5369 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
Johannes Bergc9c3a062014-03-19 09:11:19 +01005370 sdata_info(sdata,
5371 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5372 req->bssid, req->reason_code,
5373 ieee80211_get_reason_code_string(req->reason_code));
5374
Johannes Berg86552012012-10-29 09:46:31 +01005375 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5376 req->reason_code, tx, frame_buf);
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005377 ieee80211_report_disconnect(sdata, frame_buf,
5378 sizeof(frame_buf), true,
5379 req->reason_code);
Johannes Bergc9c3a062014-03-19 09:11:19 +01005380 return 0;
5381 }
Johannes Berg86552012012-10-29 09:46:31 +01005382
Johannes Bergc9c3a062014-03-19 09:11:19 +01005383 return -ENOTCONN;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005384}
5385
5386int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01005387 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005388{
5389 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07005390 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02005391 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02005392
Johannes Berg8d8b2612009-07-25 11:58:36 +02005393 /*
5394 * cfg80211 should catch this ... but it's racy since
5395 * we can receive a disassoc frame, process it, hand it
5396 * to cfg80211 while that's in a locked section already
5397 * trying to tell us that the user wants to disconnect.
5398 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005399 if (ifmgd->associated != req->bss)
Johannes Berg77fdaa12009-07-07 03:45:17 +02005400 return -ENOLINK;
Johannes Berg77fdaa12009-07-07 03:45:17 +02005401
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02005402 sdata_info(sdata,
Calvin Owensdfa1ad22014-02-11 12:36:24 -06005403 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5404 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
Johannes Berg0ff71612009-09-26 14:45:41 +02005405
Jouni Malinene69e95d2010-03-29 23:29:31 -07005406 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01005407 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5408 req->reason_code, !req->local_state_change,
5409 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02005410
Emmanuel Grumbacha90faa92015-03-16 23:23:37 +02005411 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5412 req->reason_code);
Johannes Bergbc83b682009-11-29 12:19:06 +01005413
Johannes Berg77fdaa12009-07-07 03:45:17 +02005414 return 0;
5415}
Jouni Malinen026331c2010-02-15 12:53:10 +02005416
Eliad Pellerafa762f2012-04-23 14:45:15 +03005417void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005418{
5419 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5420
Ben Greear49921852013-02-20 09:41:09 -08005421 /*
5422 * Make sure some work items will not run after this,
5423 * they will not do anything but might not have been
5424 * cancelled when disconnecting.
5425 */
5426 cancel_work_sync(&ifmgd->monitor_work);
5427 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5428 cancel_work_sync(&ifmgd->request_smps_work);
5429 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5430 cancel_work_sync(&ifmgd->chswitch_work);
Arik Nemtsov81dd2b82014-07-17 17:14:25 +03005431 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
Ben Greear49921852013-02-20 09:41:09 -08005432
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005433 sdata_lock(sdata);
Johannes Berg959867f2013-06-19 13:05:42 +02005434 if (ifmgd->assoc_data) {
5435 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Johannes Berge6f462d2016-12-08 17:22:09 +01005436 ieee80211_destroy_assoc_data(sdata, false, false);
Johannes Berg959867f2013-06-19 13:05:42 +02005437 cfg80211_assoc_timeout(sdata->dev, bss);
5438 }
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005439 if (ifmgd->auth_data)
5440 ieee80211_destroy_auth_data(sdata, false);
Liad Kaufman1277b4a2014-11-09 18:50:08 +02005441 spin_lock_bh(&ifmgd->teardown_lock);
5442 if (ifmgd->teardown_skb) {
5443 kfree_skb(ifmgd->teardown_skb);
5444 ifmgd->teardown_skb = NULL;
5445 ifmgd->orig_teardown_skb = NULL;
5446 }
5447 spin_unlock_bh(&ifmgd->teardown_lock);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005448 del_timer_sync(&ifmgd->timer);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02005449 sdata_unlock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01005450}
5451
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005452void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5453 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005454 s32 rssi_level,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005455 gfp_t gfp)
5456{
5457 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5458
Andrzej Zaborowski769f07d2017-01-25 12:43:40 +01005459 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
Johannes Bergb5878a22010-04-07 16:48:40 +02005460
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +01005461 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02005462}
5463EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
Johannes Berg98f03342014-11-26 12:42:02 +01005464
5465void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5466{
5467 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5468
5469 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5470
5471 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5472}
5473EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);