blob: 7a98d524fc8118b3f58654a56c940ba48ab3e641 [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>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070014#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070015#include <linux/if_ether.h>
16#include <linux/skbuff.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070017#include <linux/if_arp.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018#include <linux/etherdevice.h>
Paul Gortmakerd9b93842011-09-18 13:21:27 -040019#include <linux/moduleparam.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010020#include <linux/rtnetlink.h>
Jean Pihete8db0be2011-08-25 15:35:03 +020021#include <linux/pm_qos.h>
Johannes Bergd91f36d2009-04-16 13:17:26 +020022#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040024#include <linux/export.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070025#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020026#include <asm/unaligned.h>
Johannes Berg60f8b392008-09-08 17:44:22 +020027
Jiri Bencf0706e82007-05-05 11:45:53 -070028#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020029#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040030#include "rate.h"
31#include "led.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070032
Johannes Berg1672c0e2013-01-29 15:02:27 +010033#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020034#define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e2013-01-29 15:02:27 +010035#define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
36#define IEEE80211_AUTH_MAX_TRIES 3
37#define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
38#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
Johannes Bergcb236d22013-07-29 23:07:43 +020039#define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
Johannes Berg1672c0e2013-01-29 15:02:27 +010040#define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
41#define IEEE80211_ASSOC_MAX_TRIES 3
Johannes Berg66e67e42012-01-20 13:55:27 +010042
Ben Greear180205b2011-02-04 15:30:24 -080043static int max_nullfunc_tries = 2;
44module_param(max_nullfunc_tries, int, 0644);
45MODULE_PARM_DESC(max_nullfunc_tries,
46 "Maximum nullfunc tx tries before disconnecting (reason 4).");
47
48static int max_probe_tries = 5;
49module_param(max_probe_tries, int, 0644);
50MODULE_PARM_DESC(max_probe_tries,
51 "Maximum probe tries before disconnecting (reason 4).");
Johannes Bergb291ba12009-07-10 15:29:03 +020052
53/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010054 * Beacon loss timeout is calculated as N frames times the
55 * advertised beacon interval. This may need to be somewhat
56 * higher than what hardware might detect to account for
57 * delays in the host processing frames. But since we also
58 * probe on beacon miss before declaring the connection lost
59 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020060 */
Ben Greear59c1ec22013-03-19 14:19:56 -070061static int beacon_loss_count = 7;
62module_param(beacon_loss_count, int, 0644);
63MODULE_PARM_DESC(beacon_loss_count,
64 "Number of beacon intervals before we decide beacon was lost.");
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010065
Johannes Bergb291ba12009-07-10 15:29:03 +020066/*
67 * Time the connection can be idle before we probe
68 * it to see if we can still talk to the AP.
69 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030070#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020071/*
72 * Time we wait for a probe response after sending
73 * a probe request because of beacon loss or for
74 * checking the connection still works.
75 */
Ben Greear180205b2011-02-04 15:30:24 -080076static int probe_wait_ms = 500;
77module_param(probe_wait_ms, int, 0644);
78MODULE_PARM_DESC(probe_wait_ms,
79 "Maximum time(ms) to wait for probe response"
80 " before disconnecting (reason 4).");
Jiri Bencf0706e82007-05-05 11:45:53 -070081
Jouni Malinen17e4ec12010-03-29 23:28:30 -070082/*
83 * Weight given to the latest Beacon frame when calculating average signal
84 * strength for Beacon frames received in the current BSS. This must be
85 * between 1 and 15.
86 */
87#define IEEE80211_SIGNAL_AVE_WEIGHT 3
88
Jouni Malinen391a2002010-08-27 22:22:00 +030089/*
90 * How many Beacon frames need to have been used in average signal strength
91 * before starting to indicate signal change events.
92 */
93#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
94
Johannes Berg77fdaa12009-07-07 03:45:17 +020095/*
Johannes Bergca386f32009-07-10 02:39:48 +020096 * We can have multiple work items (and connection probing)
97 * scheduling this timer, but we need to take care to only
98 * reschedule it when it should fire _earlier_ than it was
99 * asked for before, or if it's not pending right now. This
100 * function ensures that. Note that it then is required to
101 * run this function for all timeouts after the first one
102 * has happened -- the work that runs from this timer will
103 * do that.
104 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200105static void run_again(struct ieee80211_sub_if_data *sdata,
106 unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200107{
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200108 sdata_assert_lock(sdata);
Johannes Bergca386f32009-07-10 02:39:48 +0200109
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200110 if (!timer_pending(&sdata->u.mgd.timer) ||
111 time_before(timeout, sdata->u.mgd.timer.expires))
112 mod_timer(&sdata->u.mgd.timer, timeout);
Johannes Bergca386f32009-07-10 02:39:48 +0200113}
114
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400115void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200116{
Johannes Bergc1288b12012-01-19 09:29:57 +0100117 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200118 return;
119
Johannes Berg7eeff742012-07-18 10:27:27 +0200120 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
121 return;
122
Johannes Bergb291ba12009-07-10 15:29:03 +0200123 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100124 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200125}
126
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400127void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
128{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400129 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
130
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100131 if (unlikely(!sdata->u.mgd.associated))
132 return;
133
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400134 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
135 return;
136
137 mod_timer(&sdata->u.mgd.conn_mon_timer,
138 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400139
140 ifmgd->probe_send_count = 0;
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400141}
142
Johannes Berg5484e232008-09-08 17:44:27 +0200143static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200144{
Johannes Berg5484e232008-09-08 17:44:27 +0200145 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200146}
147
Johannes Berg6565ec92013-02-08 14:52:32 +0100148static u32 chandef_downgrade(struct cfg80211_chan_def *c)
149{
150 u32 ret;
151 int tmp;
152
153 switch (c->width) {
154 case NL80211_CHAN_WIDTH_20:
155 c->width = NL80211_CHAN_WIDTH_20_NOHT;
156 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
157 break;
158 case NL80211_CHAN_WIDTH_40:
159 c->width = NL80211_CHAN_WIDTH_20;
160 c->center_freq1 = c->chan->center_freq;
161 ret = IEEE80211_STA_DISABLE_40MHZ |
162 IEEE80211_STA_DISABLE_VHT;
163 break;
164 case NL80211_CHAN_WIDTH_80:
165 tmp = (30 + c->chan->center_freq - c->center_freq1)/20;
166 /* n_P40 */
167 tmp /= 2;
168 /* freq_P40 */
169 c->center_freq1 = c->center_freq1 - 20 + 40 * tmp;
170 c->width = NL80211_CHAN_WIDTH_40;
171 ret = IEEE80211_STA_DISABLE_VHT;
172 break;
173 case NL80211_CHAN_WIDTH_80P80:
174 c->center_freq2 = 0;
175 c->width = NL80211_CHAN_WIDTH_80;
176 ret = IEEE80211_STA_DISABLE_80P80MHZ |
177 IEEE80211_STA_DISABLE_160MHZ;
178 break;
179 case NL80211_CHAN_WIDTH_160:
180 /* n_P20 */
181 tmp = (70 + c->chan->center_freq - c->center_freq1)/20;
182 /* n_P80 */
183 tmp /= 4;
184 c->center_freq1 = c->center_freq1 - 40 + 80 * tmp;
185 c->width = NL80211_CHAN_WIDTH_80;
186 ret = IEEE80211_STA_DISABLE_80P80MHZ |
187 IEEE80211_STA_DISABLE_160MHZ;
188 break;
189 default:
190 case NL80211_CHAN_WIDTH_20_NOHT:
191 WARN_ON_ONCE(1);
192 c->width = NL80211_CHAN_WIDTH_20_NOHT;
193 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
194 break;
Simon Wunderlich0418a442013-05-16 13:00:31 +0200195 case NL80211_CHAN_WIDTH_5:
196 case NL80211_CHAN_WIDTH_10:
197 WARN_ON_ONCE(1);
198 /* keep c->width */
199 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
200 break;
Johannes Berg6565ec92013-02-08 14:52:32 +0100201 }
202
203 WARN_ON_ONCE(!cfg80211_chandef_valid(c));
204
205 return ret;
206}
207
208static u32
209ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
210 struct ieee80211_supported_band *sband,
211 struct ieee80211_channel *channel,
212 const struct ieee80211_ht_operation *ht_oper,
213 const struct ieee80211_vht_operation *vht_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +0200214 struct cfg80211_chan_def *chandef, bool tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100215{
Johannes Berg5cdaed12013-07-31 11:23:06 +0200216 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg6565ec92013-02-08 14:52:32 +0100217 struct cfg80211_chan_def vht_chandef;
218 u32 ht_cfreq, ret;
219
220 chandef->chan = channel;
221 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
222 chandef->center_freq1 = channel->center_freq;
223 chandef->center_freq2 = 0;
224
225 if (!ht_oper || !sband->ht_cap.ht_supported) {
226 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
227 goto out;
228 }
229
230 chandef->width = NL80211_CHAN_WIDTH_20;
231
232 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
233 channel->band);
234 /* check that channel matches the right operating channel */
Johannes Berg5cdaed12013-07-31 11:23:06 +0200235 if (!tracking && channel->center_freq != ht_cfreq) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100236 /*
237 * It's possible that some APs are confused here;
238 * Netgear WNDR3700 sometimes reports 4 higher than
239 * the actual channel in association responses, but
240 * since we look at probe response/beacon data here
241 * it should be OK.
242 */
Johannes Berg5cdaed12013-07-31 11:23:06 +0200243 sdata_info(sdata,
244 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
245 channel->center_freq, ht_cfreq,
246 ht_oper->primary_chan, channel->band);
Johannes Berg6565ec92013-02-08 14:52:32 +0100247 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
248 goto out;
249 }
250
251 /* check 40 MHz support, if we have it */
252 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
253 switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
254 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
255 chandef->width = NL80211_CHAN_WIDTH_40;
256 chandef->center_freq1 += 10;
257 break;
258 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
259 chandef->width = NL80211_CHAN_WIDTH_40;
260 chandef->center_freq1 -= 10;
261 break;
262 }
263 } else {
264 /* 40 MHz (and 80 MHz) must be supported for VHT */
265 ret = IEEE80211_STA_DISABLE_VHT;
Johannes Berg85220d72013-03-25 18:29:27 +0100266 /* also mark 40 MHz disabled */
267 ret |= IEEE80211_STA_DISABLE_40MHZ;
Johannes Berg6565ec92013-02-08 14:52:32 +0100268 goto out;
269 }
270
271 if (!vht_oper || !sband->vht_cap.vht_supported) {
272 ret = IEEE80211_STA_DISABLE_VHT;
273 goto out;
274 }
275
276 vht_chandef.chan = channel;
277 vht_chandef.center_freq1 =
278 ieee80211_channel_to_frequency(vht_oper->center_freq_seg1_idx,
279 channel->band);
280 vht_chandef.center_freq2 = 0;
281
Johannes Berg6565ec92013-02-08 14:52:32 +0100282 switch (vht_oper->chan_width) {
283 case IEEE80211_VHT_CHANWIDTH_USE_HT:
284 vht_chandef.width = chandef->width;
285 break;
286 case IEEE80211_VHT_CHANWIDTH_80MHZ:
287 vht_chandef.width = NL80211_CHAN_WIDTH_80;
288 break;
289 case IEEE80211_VHT_CHANWIDTH_160MHZ:
290 vht_chandef.width = NL80211_CHAN_WIDTH_160;
291 break;
292 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
293 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
Johannes Berg6553bf02013-03-28 10:26:17 +0100294 vht_chandef.center_freq2 =
295 ieee80211_channel_to_frequency(
296 vht_oper->center_freq_seg2_idx,
297 channel->band);
Johannes Berg6565ec92013-02-08 14:52:32 +0100298 break;
299 default:
Johannes Berg5cdaed12013-07-31 11:23:06 +0200300 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100301 sdata_info(sdata,
302 "AP VHT operation IE has invalid channel width (%d), disable VHT\n",
303 vht_oper->chan_width);
Johannes Berg6565ec92013-02-08 14:52:32 +0100304 ret = IEEE80211_STA_DISABLE_VHT;
305 goto out;
306 }
307
308 if (!cfg80211_chandef_valid(&vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200309 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100310 sdata_info(sdata,
311 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100312 ret = IEEE80211_STA_DISABLE_VHT;
313 goto out;
314 }
315
316 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
317 ret = 0;
318 goto out;
319 }
320
321 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
Johannes Berg5cdaed12013-07-31 11:23:06 +0200322 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100323 sdata_info(sdata,
324 "AP VHT information doesn't match HT, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100325 ret = IEEE80211_STA_DISABLE_VHT;
326 goto out;
327 }
328
329 *chandef = vht_chandef;
330
331 ret = 0;
332
333out:
Johannes Berg586e01e2013-02-14 12:13:53 +0100334 /* don't print the message below for VHT mismatch if VHT is disabled */
335 if (ret & IEEE80211_STA_DISABLE_VHT)
336 vht_chandef = *chandef;
337
Johannes Bergddfe49b2013-07-31 20:52:03 +0200338 /*
339 * Ignore the DISABLED flag when we're already connected and only
340 * tracking the APs beacon for bandwidth changes - otherwise we
341 * might get disconnected here if we connect to an AP, update our
342 * regulatory information based on the AP's country IE and the
343 * information we have is wrong/outdated and disables the channel
344 * that we're actually using for the connection to the AP.
345 */
Johannes Berg6565ec92013-02-08 14:52:32 +0100346 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
Johannes Bergddfe49b2013-07-31 20:52:03 +0200347 tracking ? 0 :
348 IEEE80211_CHAN_DISABLED)) {
Johannes Berg6565ec92013-02-08 14:52:32 +0100349 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
350 ret = IEEE80211_STA_DISABLE_HT |
351 IEEE80211_STA_DISABLE_VHT;
Chris Wrightb56e4b82013-07-31 12:12:24 -0700352 break;
Johannes Berg6565ec92013-02-08 14:52:32 +0100353 }
354
355 ret |= chandef_downgrade(chandef);
356 }
357
Johannes Berg5cdaed12013-07-31 11:23:06 +0200358 if (chandef->width != vht_chandef.width && !tracking)
Johannes Berg6565ec92013-02-08 14:52:32 +0100359 sdata_info(sdata,
360 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
361
362 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
363 return ret;
364}
365
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100366static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
367 struct sta_info *sta,
368 const struct ieee80211_ht_operation *ht_oper,
369 const struct ieee80211_vht_operation *vht_oper,
370 const u8 *bssid, u32 *changed)
Johannes Bergd5522e02009-03-30 13:23:35 +0200371{
372 struct ieee80211_local *local = sdata->local;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100373 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergd5522e02009-03-30 13:23:35 +0200374 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200375 struct ieee80211_channel *chan;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100376 struct cfg80211_chan_def chandef;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200377 u16 ht_opmode;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100378 u32 flags;
379 enum ieee80211_sta_rx_bandwidth new_sta_bw;
380 int ret;
381
382 /* if HT was/is disabled, don't track any bandwidth changes */
383 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
384 return 0;
385
386 /* don't check VHT if we associated as non-VHT station */
387 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
388 vht_oper = NULL;
Johannes Bergd5522e02009-03-30 13:23:35 +0200389
Johannes Berg11289582013-02-07 17:36:12 +0100390 if (WARN_ON_ONCE(!sta))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100391 return -EINVAL;
Johannes Berg11289582013-02-07 17:36:12 +0100392
Johannes Bergf2d93302013-02-08 13:15:55 +0100393 chan = sdata->vif.bss_conf.chandef.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200394 sband = local->hw.wiphy->bands[chan->band];
Johannes Berg0aaffa92010-05-05 15:28:27 +0200395
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100396 /* calculate new channel (type) based on HT/VHT operation IEs */
397 flags = ieee80211_determine_chantype(sdata, sband, chan, ht_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +0200398 vht_oper, &chandef, true);
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100399
400 /*
401 * Downgrade the new channel if we associated with restricted
402 * capabilities. For example, if we associated as a 20 MHz STA
403 * to a 40 MHz AP (due to regulatory, capabilities or config
404 * reasons) then switching to a 40 MHz channel now won't do us
405 * any good -- we couldn't use it with the AP.
406 */
407 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
408 chandef.width == NL80211_CHAN_WIDTH_80P80)
409 flags |= chandef_downgrade(&chandef);
410 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
411 chandef.width == NL80211_CHAN_WIDTH_160)
412 flags |= chandef_downgrade(&chandef);
413 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
414 chandef.width > NL80211_CHAN_WIDTH_20)
415 flags |= chandef_downgrade(&chandef);
416
417 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
418 return 0;
419
420 sdata_info(sdata,
421 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
422 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
423 chandef.center_freq1, chandef.center_freq2);
424
425 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
426 IEEE80211_STA_DISABLE_VHT |
427 IEEE80211_STA_DISABLE_40MHZ |
428 IEEE80211_STA_DISABLE_80P80MHZ |
429 IEEE80211_STA_DISABLE_160MHZ)) ||
430 !cfg80211_chandef_valid(&chandef)) {
431 sdata_info(sdata,
432 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
433 ifmgd->bssid);
434 return -EINVAL;
Johannes Berg64f68e52012-03-28 10:58:37 +0200435 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200436
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100437 switch (chandef.width) {
438 case NL80211_CHAN_WIDTH_20_NOHT:
439 case NL80211_CHAN_WIDTH_20:
440 new_sta_bw = IEEE80211_STA_RX_BW_20;
441 break;
442 case NL80211_CHAN_WIDTH_40:
443 new_sta_bw = IEEE80211_STA_RX_BW_40;
444 break;
445 case NL80211_CHAN_WIDTH_80:
446 new_sta_bw = IEEE80211_STA_RX_BW_80;
447 break;
448 case NL80211_CHAN_WIDTH_80P80:
449 case NL80211_CHAN_WIDTH_160:
450 new_sta_bw = IEEE80211_STA_RX_BW_160;
451 break;
452 default:
453 return -EINVAL;
454 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200455
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100456 if (new_sta_bw > sta->cur_max_bandwidth)
457 new_sta_bw = sta->cur_max_bandwidth;
Johannes Berg64f68e52012-03-28 10:58:37 +0200458
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100459 if (new_sta_bw < sta->sta.bandwidth) {
460 sta->sta.bandwidth = new_sta_bw;
461 rate_control_rate_update(local, sband, sta,
462 IEEE80211_RC_BW_CHANGED);
463 }
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530464
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100465 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
466 if (ret) {
467 sdata_info(sdata,
468 "AP %pM changed bandwidth to incompatible one - disconnect\n",
469 ifmgd->bssid);
470 return ret;
471 }
472
473 if (new_sta_bw > sta->sta.bandwidth) {
474 sta->sta.bandwidth = new_sta_bw;
475 rate_control_rate_update(local, sband, sta,
476 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200477 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200478
Johannes Berg074d46d2012-03-15 19:45:16 +0100479 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200480
481 /* if bss configuration changed store the new one */
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100482 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
483 *changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200484 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Bergd5522e02009-03-30 13:23:35 +0200485 }
486
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100487 return 0;
Johannes Bergd5522e02009-03-30 13:23:35 +0200488}
489
Johannes Berg9c6bd792008-09-11 00:01:52 +0200490/* frame sending functions */
491
Johannes Berg66e67e42012-01-20 13:55:27 +0100492static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
493 struct ieee80211_supported_band *sband,
494 u32 *rates)
495{
496 int i, j, count;
497 *rates = 0;
498 count = 0;
499 for (i = 0; i < supp_rates_len; i++) {
500 int rate = (supp_rates[i] & 0x7F) * 5;
501
502 for (j = 0; j < sband->n_bitrates; j++)
503 if (sband->bitrates[j].bitrate == rate) {
504 *rates |= BIT(j);
505 count++;
506 break;
507 }
508 }
509
510 return count;
511}
512
513static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200514 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100515 struct ieee80211_supported_band *sband,
516 struct ieee80211_channel *channel,
517 enum ieee80211_smps_mode smps)
518{
Johannes Berg66e67e42012-01-20 13:55:27 +0100519 u8 *pos;
520 u32 flags = channel->flags;
521 u16 cap;
522 struct ieee80211_sta_ht_cap ht_cap;
523
524 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
525
Johannes Berg66e67e42012-01-20 13:55:27 +0100526 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
527 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
528
Johannes Berg66e67e42012-01-20 13:55:27 +0100529 /* determine capability flags */
530 cap = ht_cap.cap;
531
Johannes Berg9dde6422012-05-16 23:43:19 +0200532 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100533 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
534 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
535 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
536 cap &= ~IEEE80211_HT_CAP_SGI_40;
537 }
538 break;
539 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
540 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
541 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
542 cap &= ~IEEE80211_HT_CAP_SGI_40;
543 }
544 break;
545 }
546
Johannes Berg24398e32012-03-28 10:58:36 +0200547 /*
548 * If 40 MHz was disabled associate as though we weren't
549 * capable of 40 MHz -- some broken APs will never fall
550 * back to trying to transmit in 20 MHz.
551 */
552 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
553 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
554 cap &= ~IEEE80211_HT_CAP_SGI_40;
555 }
556
Johannes Berg66e67e42012-01-20 13:55:27 +0100557 /* set SM PS mode properly */
558 cap &= ~IEEE80211_HT_CAP_SM_PS;
559 switch (smps) {
560 case IEEE80211_SMPS_AUTOMATIC:
561 case IEEE80211_SMPS_NUM_MODES:
562 WARN_ON(1);
563 case IEEE80211_SMPS_OFF:
564 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
565 IEEE80211_HT_CAP_SM_PS_SHIFT;
566 break;
567 case IEEE80211_SMPS_STATIC:
568 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
569 IEEE80211_HT_CAP_SM_PS_SHIFT;
570 break;
571 case IEEE80211_SMPS_DYNAMIC:
572 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
573 IEEE80211_HT_CAP_SM_PS_SHIFT;
574 break;
575 }
576
577 /* reserve and fill IE */
578 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
579 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
580}
581
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000582static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
583 struct sk_buff *skb,
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100584 struct ieee80211_supported_band *sband,
585 struct ieee80211_vht_cap *ap_vht_cap)
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000586{
587 u8 *pos;
588 u32 cap;
589 struct ieee80211_sta_vht_cap vht_cap;
590
591 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
592
593 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +0100594 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000595
596 /* determine capability flags */
597 cap = vht_cap.cap;
598
Johannes Bergf2d9d272012-11-22 14:11:39 +0100599 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
600 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
601 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
602 }
603
604 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
605 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
606 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
607 }
608
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100609 /*
610 * Some APs apparently get confused if our capabilities are better
611 * than theirs, so restrict what we advertise in the assoc request.
612 */
613 if (!(ap_vht_cap->vht_cap_info &
614 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
615 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
616
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000617 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000618 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000619 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
620}
621
Johannes Berg66e67e42012-01-20 13:55:27 +0100622static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
623{
624 struct ieee80211_local *local = sdata->local;
625 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
626 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
627 struct sk_buff *skb;
628 struct ieee80211_mgmt *mgmt;
629 u8 *pos, qos_info;
630 size_t offset = 0, noffset;
631 int i, count, rates_len, supp_rates_len;
632 u16 capab;
633 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200634 struct ieee80211_chanctx_conf *chanctx_conf;
635 struct ieee80211_channel *chan;
Johannes Berg66e67e42012-01-20 13:55:27 +0100636 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100637
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200638 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +0100639
Johannes Berg55de9082012-07-26 17:24:39 +0200640 rcu_read_lock();
641 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
642 if (WARN_ON(!chanctx_conf)) {
643 rcu_read_unlock();
644 return;
645 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100646 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200647 rcu_read_unlock();
648 sband = local->hw.wiphy->bands[chan->band];
Johannes Berg66e67e42012-01-20 13:55:27 +0100649
650 if (assoc_data->supp_rates_len) {
651 /*
652 * Get all rates supported by the device and the AP as
653 * some APs don't like getting a superset of their rates
654 * in the association request (e.g. D-Link DAP 1353 in
655 * b-only mode)...
656 */
657 rates_len = ieee80211_compatible_rates(assoc_data->supp_rates,
658 assoc_data->supp_rates_len,
659 sband, &rates);
660 } else {
661 /*
662 * In case AP not provide any supported rates information
663 * before association, we send information element(s) with
664 * all rates that we support.
665 */
666 rates = ~0;
667 rates_len = sband->n_bitrates;
668 }
669
670 skb = alloc_skb(local->hw.extra_tx_headroom +
671 sizeof(*mgmt) + /* bit too much but doesn't matter */
672 2 + assoc_data->ssid_len + /* SSID */
673 4 + rates_len + /* (extended) rates */
674 4 + /* power capability */
675 2 + 2 * sband->n_channels + /* supported channels */
676 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000677 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Johannes Berg66e67e42012-01-20 13:55:27 +0100678 assoc_data->ie_len + /* extra IEs */
679 9, /* WMM */
680 GFP_KERNEL);
681 if (!skb)
682 return;
683
684 skb_reserve(skb, local->hw.extra_tx_headroom);
685
686 capab = WLAN_CAPABILITY_ESS;
687
688 if (sband->band == IEEE80211_BAND_2GHZ) {
689 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
690 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
691 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
692 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
693 }
694
695 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
696 capab |= WLAN_CAPABILITY_PRIVACY;
697
698 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
699 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
700 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
701
702 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
703 memset(mgmt, 0, 24);
704 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
705 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
706 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
707
708 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
709 skb_put(skb, 10);
710 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
711 IEEE80211_STYPE_REASSOC_REQ);
712 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
713 mgmt->u.reassoc_req.listen_interval =
714 cpu_to_le16(local->hw.conf.listen_interval);
715 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
716 ETH_ALEN);
717 } else {
718 skb_put(skb, 4);
719 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
720 IEEE80211_STYPE_ASSOC_REQ);
721 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
722 mgmt->u.assoc_req.listen_interval =
723 cpu_to_le16(local->hw.conf.listen_interval);
724 }
725
726 /* SSID */
727 pos = skb_put(skb, 2 + assoc_data->ssid_len);
728 *pos++ = WLAN_EID_SSID;
729 *pos++ = assoc_data->ssid_len;
730 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
731
732 /* add all rates which were marked to be used above */
733 supp_rates_len = rates_len;
734 if (supp_rates_len > 8)
735 supp_rates_len = 8;
736
737 pos = skb_put(skb, supp_rates_len + 2);
738 *pos++ = WLAN_EID_SUPP_RATES;
739 *pos++ = supp_rates_len;
740
741 count = 0;
742 for (i = 0; i < sband->n_bitrates; i++) {
743 if (BIT(i) & rates) {
744 int rate = sband->bitrates[i].bitrate;
745 *pos++ = (u8) (rate / 5);
746 if (++count == 8)
747 break;
748 }
749 }
750
751 if (rates_len > count) {
752 pos = skb_put(skb, rates_len - count + 2);
753 *pos++ = WLAN_EID_EXT_SUPP_RATES;
754 *pos++ = rates_len - count;
755
756 for (i++; i < sband->n_bitrates; i++) {
757 if (BIT(i) & rates) {
758 int rate = sband->bitrates[i].bitrate;
759 *pos++ = (u8) (rate / 5);
760 }
761 }
762 }
763
764 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
765 /* 1. power capabilities */
766 pos = skb_put(skb, 4);
767 *pos++ = WLAN_EID_PWR_CAPABILITY;
768 *pos++ = 2;
769 *pos++ = 0; /* min tx power */
Johannes Berg55de9082012-07-26 17:24:39 +0200770 *pos++ = chan->max_power; /* max tx power */
Johannes Berg66e67e42012-01-20 13:55:27 +0100771
772 /* 2. supported channels */
773 /* TODO: get this in reg domain format */
774 pos = skb_put(skb, 2 * sband->n_channels + 2);
775 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
776 *pos++ = 2 * sband->n_channels;
777 for (i = 0; i < sband->n_channels; i++) {
778 *pos++ = ieee80211_frequency_to_channel(
779 sband->channels[i].center_freq);
780 *pos++ = 1; /* one channel in the subband*/
781 }
782 }
783
784 /* if present, add any custom IEs that go before HT */
785 if (assoc_data->ie_len && assoc_data->ie) {
786 static const u8 before_ht[] = {
787 WLAN_EID_SSID,
788 WLAN_EID_SUPP_RATES,
789 WLAN_EID_EXT_SUPP_RATES,
790 WLAN_EID_PWR_CAPABILITY,
791 WLAN_EID_SUPPORTED_CHANNELS,
792 WLAN_EID_RSN,
793 WLAN_EID_QOS_CAPA,
794 WLAN_EID_RRM_ENABLED_CAPABILITIES,
795 WLAN_EID_MOBILITY_DOMAIN,
796 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
797 };
798 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
799 before_ht, ARRAY_SIZE(before_ht),
800 offset);
801 pos = skb_put(skb, noffset - offset);
802 memcpy(pos, assoc_data->ie + offset, noffset - offset);
803 offset = noffset;
804 }
805
Johannes Bergf2d9d272012-11-22 14:11:39 +0100806 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
807 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
808 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
809
Johannes Berga8243b72012-11-22 14:32:09 +0100810 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200811 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200812 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100813
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000814 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100815 ieee80211_add_vht_ie(sdata, skb, sband,
816 &assoc_data->ap_vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000817
Johannes Berg66e67e42012-01-20 13:55:27 +0100818 /* if present, add any custom non-vendor IEs that go after HT */
819 if (assoc_data->ie_len && assoc_data->ie) {
820 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
821 assoc_data->ie_len,
822 offset);
823 pos = skb_put(skb, noffset - offset);
824 memcpy(pos, assoc_data->ie + offset, noffset - offset);
825 offset = noffset;
826 }
827
Johannes Berg76f03032012-03-08 15:02:05 +0100828 if (assoc_data->wmm) {
829 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200830 qos_info = ifmgd->uapsd_queues;
831 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100832 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
833 } else {
834 qos_info = 0;
835 }
836
837 pos = skb_put(skb, 9);
838 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
839 *pos++ = 7; /* len */
840 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
841 *pos++ = 0x50;
842 *pos++ = 0xf2;
843 *pos++ = 2; /* WME */
844 *pos++ = 0; /* WME info */
845 *pos++ = 1; /* WME ver */
846 *pos++ = qos_info;
847 }
848
849 /* add any remaining custom (i.e. vendor specific here) IEs */
850 if (assoc_data->ie_len && assoc_data->ie) {
851 noffset = assoc_data->ie_len;
852 pos = skb_put(skb, noffset - offset);
853 memcpy(pos, assoc_data->ie + offset, noffset - offset);
854 }
855
Johannes Berga1845fc2012-06-27 13:18:36 +0200856 drv_mgd_prepare_tx(local, sdata);
857
Johannes Berg66e67e42012-01-20 13:55:27 +0100858 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Johannes Berg1672c0e2013-01-29 15:02:27 +0100859 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
860 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
861 IEEE80211_TX_INTFL_MLME_CONN_TX;
Johannes Berg66e67e42012-01-20 13:55:27 +0100862 ieee80211_tx_skb(sdata, skb);
863}
864
Kalle Valo572e0012009-02-10 17:09:31 +0200865void ieee80211_send_pspoll(struct ieee80211_local *local,
866 struct ieee80211_sub_if_data *sdata)
867{
Kalle Valo572e0012009-02-10 17:09:31 +0200868 struct ieee80211_pspoll *pspoll;
869 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200870
Kalle Valod8cd1892010-01-05 20:16:26 +0200871 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
872 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200873 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200874
Kalle Valod8cd1892010-01-05 20:16:26 +0200875 pspoll = (struct ieee80211_pspoll *) skb->data;
876 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200877
Johannes Berg62ae67b2009-11-18 18:42:05 +0100878 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
879 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200880}
881
Johannes Berg965beda2009-04-16 13:17:24 +0200882void ieee80211_send_nullfunc(struct ieee80211_local *local,
883 struct ieee80211_sub_if_data *sdata,
884 int powersave)
885{
886 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200887 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530888 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200889
Kalle Valod8cd1892010-01-05 20:16:26 +0200890 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
891 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200892 return;
893
Kalle Valod8cd1892010-01-05 20:16:26 +0200894 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200895 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200896 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200897
Seth Forshee6c17b772013-02-11 11:21:07 -0600898 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
899 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Pontus Fuchsff40b422013-06-04 12:44:52 +0200900
901 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
902 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
903
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530904 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
905 IEEE80211_STA_CONNECTION_POLL))
906 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
907
Johannes Berg62ae67b2009-11-18 18:42:05 +0100908 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200909}
910
Felix Fietkaud5242152010-01-08 18:06:26 +0100911static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
912 struct ieee80211_sub_if_data *sdata)
913{
914 struct sk_buff *skb;
915 struct ieee80211_hdr *nullfunc;
916 __le16 fc;
917
918 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
919 return;
920
921 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -0700922 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +0100923 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700924
Felix Fietkaud5242152010-01-08 18:06:26 +0100925 skb_reserve(skb, local->hw.extra_tx_headroom);
926
927 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
928 memset(nullfunc, 0, 30);
929 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
930 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
931 nullfunc->frame_control = fc;
932 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
933 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
934 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
935 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
936
937 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
938 ieee80211_tx_skb(sdata, skb);
939}
940
Johannes Bergcc32abd2009-05-15 11:52:31 +0200941/* spectrum management related things */
942static void ieee80211_chswitch_work(struct work_struct *work)
943{
944 struct ieee80211_sub_if_data *sdata =
945 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Karl Beldan675a0b02013-03-25 16:26:57 +0100946 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200947 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
948
Johannes Berg9607e6b2009-12-23 13:15:31 +0100949 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200950 return;
951
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200952 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200953 if (!ifmgd->associated)
954 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200955
Johannes Berg85220d72013-03-25 18:29:27 +0100956 local->_oper_chandef = local->csa_chandef;
Karl Beldan675a0b02013-03-25 16:26:57 +0100957
958 if (!local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +0200959 /* call "hw_config" only if doing sw channel switch */
Karl Beldan675a0b02013-03-25 16:26:57 +0100960 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
Shahar Levi1ea57b12011-09-08 08:44:05 +0300961 } else {
962 /* update the device channel directly */
Karl Beldan675a0b02013-03-25 16:26:57 +0100963 local->hw.conf.chandef = local->_oper_chandef;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200964 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200965
Johannes Berg77fdaa12009-07-07 03:45:17 +0200966 /* XXX: shouldn't really modify cfg80211-owned data! */
Karl Beldan675a0b02013-03-25 16:26:57 +0100967 ifmgd->associated->channel = local->_oper_chandef.chan;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200968
Johannes Berg57eebdf2012-08-01 15:50:46 +0200969 /* XXX: wait for a beacon first? */
Karl Beldan675a0b02013-03-25 16:26:57 +0100970 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +0100971 IEEE80211_MAX_QUEUE_MAP,
Johannes Bergcc32abd2009-05-15 11:52:31 +0200972 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200973 out:
974 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200975 sdata_unlock(sdata);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200976}
977
Johannes Berg5ce6e432010-05-11 16:20:57 +0200978void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
979{
Johannes Berg55de9082012-07-26 17:24:39 +0200980 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
981 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200982
983 trace_api_chswitch_done(sdata, success);
984 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +0200985 sdata_info(sdata,
986 "driver channel switch failed, disconnecting\n");
987 ieee80211_queue_work(&sdata->local->hw,
988 &ifmgd->csa_connection_drop_work);
989 } else {
990 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +0200991 }
Johannes Berg5ce6e432010-05-11 16:20:57 +0200992}
993EXPORT_SYMBOL(ieee80211_chswitch_done);
994
Johannes Bergcc32abd2009-05-15 11:52:31 +0200995static void ieee80211_chswitch_timer(unsigned long data)
996{
997 struct ieee80211_sub_if_data *sdata =
998 (struct ieee80211_sub_if_data *) data;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200999
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01001000 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001001}
1002
Johannes Berg37799e52013-03-26 14:02:26 +01001003static void
Johannes Berg4a3cb702013-02-12 16:43:19 +01001004ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
Johannes Berg04a161f2013-05-03 09:35:35 +02001005 u64 timestamp, struct ieee802_11_elems *elems,
1006 bool beacon)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001007{
Johannes Bergb4f286a2013-03-26 14:13:58 +01001008 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001009 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg37799e52013-03-26 14:02:26 +01001010 struct cfg80211_bss *cbss = ifmgd->associated;
1011 struct ieee80211_bss *bss;
Johannes Berg55de9082012-07-26 17:24:39 +02001012 struct ieee80211_chanctx *chanctx;
Johannes Bergb4f286a2013-03-26 14:13:58 +01001013 enum ieee80211_band new_band;
1014 int new_freq;
1015 u8 new_chan_no;
1016 u8 count;
1017 u8 mode;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001018 struct ieee80211_channel *new_chan;
Johannes Berg85220d72013-03-25 18:29:27 +01001019 struct cfg80211_chan_def new_chandef = {};
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001020 struct cfg80211_chan_def new_vht_chandef = {};
1021 const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1022 const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
Johannes Berg04a161f2013-05-03 09:35:35 +02001023 const struct ieee80211_ht_operation *ht_oper;
Johannes Berg85220d72013-03-25 18:29:27 +01001024 int secondary_channel_offset = -1;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001025
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001026 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001027
Johannes Berg37799e52013-03-26 14:02:26 +01001028 if (!cbss)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001029 return;
1030
Johannes Bergb4f286a2013-03-26 14:13:58 +01001031 if (local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001032 return;
1033
Johannes Berg37799e52013-03-26 14:02:26 +01001034 /* disregard subsequent announcements if we are already processing */
Johannes Bergcc32abd2009-05-15 11:52:31 +02001035 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1036 return;
1037
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001038 sec_chan_offs = elems->sec_chan_offs;
1039 wide_bw_chansw_ie = elems->wide_bw_chansw_ie;
Johannes Berg04a161f2013-05-03 09:35:35 +02001040 ht_oper = elems->ht_operation;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001041
1042 if (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
1043 IEEE80211_STA_DISABLE_40MHZ)) {
1044 sec_chan_offs = NULL;
1045 wide_bw_chansw_ie = NULL;
Johannes Berg04a161f2013-05-03 09:35:35 +02001046 /* only used for bandwidth here */
1047 ht_oper = NULL;
Johannes Berg85220d72013-03-25 18:29:27 +01001048 }
1049
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001050 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
1051 wide_bw_chansw_ie = NULL;
Johannes Berg85220d72013-03-25 18:29:27 +01001052
Johannes Bergb4f286a2013-03-26 14:13:58 +01001053 if (elems->ext_chansw_ie) {
1054 if (!ieee80211_operating_class_to_band(
1055 elems->ext_chansw_ie->new_operating_class,
1056 &new_band)) {
1057 sdata_info(sdata,
1058 "cannot understand ECSA IE operating class %d, disconnecting\n",
1059 elems->ext_chansw_ie->new_operating_class);
1060 ieee80211_queue_work(&local->hw,
1061 &ifmgd->csa_connection_drop_work);
1062 }
1063 new_chan_no = elems->ext_chansw_ie->new_ch_num;
1064 count = elems->ext_chansw_ie->count;
1065 mode = elems->ext_chansw_ie->mode;
1066 } else if (elems->ch_switch_ie) {
1067 new_band = cbss->channel->band;
1068 new_chan_no = elems->ch_switch_ie->new_ch_num;
1069 count = elems->ch_switch_ie->count;
1070 mode = elems->ch_switch_ie->mode;
1071 } else {
1072 /* nothing here we understand */
Johannes Berg37799e52013-03-26 14:02:26 +01001073 return;
Johannes Bergb4f286a2013-03-26 14:13:58 +01001074 }
Johannes Berg37799e52013-03-26 14:02:26 +01001075
1076 bss = (void *)cbss->priv;
1077
Johannes Bergb4f286a2013-03-26 14:13:58 +01001078 new_freq = ieee80211_channel_to_frequency(new_chan_no, new_band);
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001079 new_chan = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1080 if (!new_chan || new_chan->flags & IEEE80211_CHAN_DISABLED) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001081 sdata_info(sdata,
1082 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
1083 ifmgd->associated->bssid, new_freq);
Johannes Bergb4f286a2013-03-26 14:13:58 +01001084 ieee80211_queue_work(&local->hw,
Johannes Berg882a7c62012-08-01 22:32:45 +02001085 &ifmgd->csa_connection_drop_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001086 return;
Johannes Berg882a7c62012-08-01 22:32:45 +02001087 }
Johannes Bergcc32abd2009-05-15 11:52:31 +02001088
Johannes Berg04a161f2013-05-03 09:35:35 +02001089 if (!beacon && sec_chan_offs) {
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001090 secondary_channel_offset = sec_chan_offs->sec_chan_offs;
Johannes Berg04a161f2013-05-03 09:35:35 +02001091 } else if (beacon && ht_oper) {
1092 secondary_channel_offset =
1093 ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001094 } else if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Johannes Berg04a161f2013-05-03 09:35:35 +02001095 /*
1096 * If it's not a beacon, HT is enabled and the IE not present,
1097 * it's 20 MHz, 802.11-2012 8.5.2.6:
1098 * This element [the Secondary Channel Offset Element] is
1099 * present when switching to a 40 MHz channel. It may be
1100 * present when switching to a 20 MHz channel (in which
1101 * case the secondary channel offset is set to SCN).
1102 */
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001103 secondary_channel_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1104 }
1105
Johannes Berg85220d72013-03-25 18:29:27 +01001106 switch (secondary_channel_offset) {
1107 default:
1108 /* secondary_channel_offset was present but is invalid */
1109 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001110 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001111 NL80211_CHAN_HT20);
1112 break;
1113 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001114 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001115 NL80211_CHAN_HT40PLUS);
1116 break;
1117 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001118 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001119 NL80211_CHAN_HT40MINUS);
1120 break;
1121 case -1:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001122 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001123 NL80211_CHAN_NO_HT);
1124 break;
1125 }
1126
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001127 if (wide_bw_chansw_ie) {
1128 new_vht_chandef.chan = new_chan;
1129 new_vht_chandef.center_freq1 =
1130 ieee80211_channel_to_frequency(
1131 wide_bw_chansw_ie->new_center_freq_seg0,
1132 new_band);
1133
1134 switch (wide_bw_chansw_ie->new_channel_width) {
1135 default:
1136 /* hmmm, ignore VHT and use HT if present */
1137 case IEEE80211_VHT_CHANWIDTH_USE_HT:
1138 new_vht_chandef.chan = NULL;
1139 break;
1140 case IEEE80211_VHT_CHANWIDTH_80MHZ:
1141 new_vht_chandef.width = NL80211_CHAN_WIDTH_80;
1142 break;
1143 case IEEE80211_VHT_CHANWIDTH_160MHZ:
1144 new_vht_chandef.width = NL80211_CHAN_WIDTH_160;
1145 break;
1146 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1147 /* field is otherwise reserved */
1148 new_vht_chandef.center_freq2 =
1149 ieee80211_channel_to_frequency(
1150 wide_bw_chansw_ie->new_center_freq_seg1,
1151 new_band);
1152 new_vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1153 break;
1154 }
1155 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
1156 new_vht_chandef.width == NL80211_CHAN_WIDTH_80P80)
1157 chandef_downgrade(&new_vht_chandef);
1158 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
1159 new_vht_chandef.width == NL80211_CHAN_WIDTH_160)
1160 chandef_downgrade(&new_vht_chandef);
1161 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
1162 new_vht_chandef.width > NL80211_CHAN_WIDTH_20)
1163 chandef_downgrade(&new_vht_chandef);
1164 }
1165
1166 /* if VHT data is there validate & use it */
1167 if (new_vht_chandef.chan) {
1168 if (!cfg80211_chandef_compatible(&new_vht_chandef,
1169 &new_chandef)) {
1170 sdata_info(sdata,
1171 "AP %pM CSA has inconsistent channel data, disconnecting\n",
1172 ifmgd->associated->bssid);
1173 ieee80211_queue_work(&local->hw,
1174 &ifmgd->csa_connection_drop_work);
1175 return;
1176 }
1177 new_chandef = new_vht_chandef;
1178 }
1179
Johannes Berg85220d72013-03-25 18:29:27 +01001180 if (!cfg80211_chandef_usable(local->hw.wiphy, &new_chandef,
1181 IEEE80211_CHAN_DISABLED)) {
1182 sdata_info(sdata,
1183 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1184 ifmgd->associated->bssid, new_freq,
1185 new_chandef.width, new_chandef.center_freq1,
1186 new_chandef.center_freq2);
1187 ieee80211_queue_work(&local->hw,
1188 &ifmgd->csa_connection_drop_work);
1189 return;
1190 }
1191
Johannes Berg57eebdf2012-08-01 15:50:46 +02001192 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
1193
Johannes Bergb4f286a2013-03-26 14:13:58 +01001194 if (local->use_chanctx) {
Johannes Berg55de9082012-07-26 17:24:39 +02001195 sdata_info(sdata,
1196 "not handling channel switch with channel contexts\n");
Johannes Bergb4f286a2013-03-26 14:13:58 +01001197 ieee80211_queue_work(&local->hw,
Johannes Berg55de9082012-07-26 17:24:39 +02001198 &ifmgd->csa_connection_drop_work);
Simon Wunderlich246dc3f2012-11-30 19:17:27 +01001199 return;
Johannes Berg55de9082012-07-26 17:24:39 +02001200 }
1201
Johannes Bergb4f286a2013-03-26 14:13:58 +01001202 mutex_lock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001203 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
Johannes Bergb4f286a2013-03-26 14:13:58 +01001204 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001205 return;
1206 }
1207 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
1208 struct ieee80211_chanctx, conf);
1209 if (chanctx->refcount > 1) {
1210 sdata_info(sdata,
1211 "channel switch with multiple interfaces on the same channel, disconnecting\n");
Johannes Bergb4f286a2013-03-26 14:13:58 +01001212 ieee80211_queue_work(&local->hw,
Johannes Berg55de9082012-07-26 17:24:39 +02001213 &ifmgd->csa_connection_drop_work);
Johannes Bergb4f286a2013-03-26 14:13:58 +01001214 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001215 return;
1216 }
Johannes Bergb4f286a2013-03-26 14:13:58 +01001217 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001218
Johannes Berg85220d72013-03-25 18:29:27 +01001219 local->csa_chandef = new_chandef;
Johannes Berg55de9082012-07-26 17:24:39 +02001220
Johannes Bergb4f286a2013-03-26 14:13:58 +01001221 if (mode)
1222 ieee80211_stop_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001223 IEEE80211_MAX_QUEUE_MAP,
Johannes Berg57eebdf2012-08-01 15:50:46 +02001224 IEEE80211_QUEUE_STOP_REASON_CSA);
1225
Johannes Bergb4f286a2013-03-26 14:13:58 +01001226 if (local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +02001227 /* use driver's channel switch callback */
Johannes Berg57eebdf2012-08-01 15:50:46 +02001228 struct ieee80211_channel_switch ch_switch = {
1229 .timestamp = timestamp,
Johannes Bergb4f286a2013-03-26 14:13:58 +01001230 .block_tx = mode,
Johannes Berg85220d72013-03-25 18:29:27 +01001231 .chandef = new_chandef,
Johannes Bergb4f286a2013-03-26 14:13:58 +01001232 .count = count,
Johannes Berg57eebdf2012-08-01 15:50:46 +02001233 };
1234
Johannes Bergb4f286a2013-03-26 14:13:58 +01001235 drv_channel_switch(local, &ch_switch);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001236 return;
1237 }
1238
1239 /* channel switch handled in software */
Johannes Bergb4f286a2013-03-26 14:13:58 +01001240 if (count <= 1)
1241 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001242 else
Johannes Bergcc32abd2009-05-15 11:52:31 +02001243 mod_timer(&ifmgd->chswitch_timer,
Johannes Bergb4f286a2013-03-26 14:13:58 +01001244 TU_TO_EXP_TIME(count * cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +02001245}
1246
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001247static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1248 struct ieee80211_channel *channel,
1249 const u8 *country_ie, u8 country_ie_len,
1250 const u8 *pwr_constr_elem)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001251{
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001252 struct ieee80211_country_ie_triplet *triplet;
1253 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1254 int i, chan_pwr, chan_increment, new_ap_level;
1255 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001256
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001257 /* Invalid IE */
1258 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001259 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001260
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001261 triplet = (void *)(country_ie + 3);
1262 country_ie_len -= 3;
1263
1264 switch (channel->band) {
1265 default:
1266 WARN_ON_ONCE(1);
1267 /* fall through */
1268 case IEEE80211_BAND_2GHZ:
1269 case IEEE80211_BAND_60GHZ:
1270 chan_increment = 1;
1271 break;
1272 case IEEE80211_BAND_5GHZ:
1273 chan_increment = 4;
1274 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001275 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001276
1277 /* find channel */
1278 while (country_ie_len >= 3) {
1279 u8 first_channel = triplet->chans.first_channel;
1280
1281 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1282 goto next;
1283
1284 for (i = 0; i < triplet->chans.num_channels; i++) {
1285 if (first_channel + i * chan_increment == chan) {
1286 have_chan_pwr = true;
1287 chan_pwr = triplet->chans.max_power;
1288 break;
1289 }
1290 }
1291 if (have_chan_pwr)
1292 break;
1293
1294 next:
1295 triplet++;
1296 country_ie_len -= 3;
1297 }
1298
1299 if (!have_chan_pwr)
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001300 return 0;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001301
1302 new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
1303
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001304 if (sdata->ap_power_level == new_ap_level)
1305 return 0;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001306
1307 sdata_info(sdata,
1308 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1309 new_ap_level, chan_pwr, *pwr_constr_elem,
1310 sdata->u.mgd.bssid);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001311 sdata->ap_power_level = new_ap_level;
1312 if (__ieee80211_recalc_txpower(sdata))
1313 return BSS_CHANGED_TXPOWER;
1314 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001315}
1316
Johannes Berg965beda2009-04-16 13:17:24 +02001317/* powersave */
1318static void ieee80211_enable_ps(struct ieee80211_local *local,
1319 struct ieee80211_sub_if_data *sdata)
1320{
1321 struct ieee80211_conf *conf = &local->hw.conf;
1322
Johannes Bergd5edaed2009-04-22 23:02:51 +02001323 /*
1324 * If we are scanning right now then the parameters will
1325 * take effect when scan finishes.
1326 */
Helmut Schaafbe9c422009-07-23 12:14:04 +02001327 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +02001328 return;
1329
Johannes Berg965beda2009-04-16 13:17:24 +02001330 if (conf->dynamic_ps_timeout > 0 &&
1331 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
1332 mod_timer(&local->dynamic_ps_timer, jiffies +
1333 msecs_to_jiffies(conf->dynamic_ps_timeout));
1334 } else {
1335 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1336 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +05301337
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001338 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
1339 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
1340 return;
1341
1342 conf->flags |= IEEE80211_CONF_PS;
1343 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +02001344 }
1345}
1346
1347static void ieee80211_change_ps(struct ieee80211_local *local)
1348{
1349 struct ieee80211_conf *conf = &local->hw.conf;
1350
1351 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +02001352 ieee80211_enable_ps(local, local->ps_sdata);
1353 } else if (conf->flags & IEEE80211_CONF_PS) {
1354 conf->flags &= ~IEEE80211_CONF_PS;
1355 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1356 del_timer_sync(&local->dynamic_ps_timer);
1357 cancel_work_sync(&local->dynamic_ps_enable_work);
1358 }
1359}
1360
Jason Young808118c2011-03-10 16:43:19 -08001361static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1362{
1363 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1364 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001365 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001366
1367 if (!mgd->powersave)
1368 return false;
1369
Johannes Berg05cb9102011-10-28 11:59:47 +02001370 if (mgd->broken_ap)
1371 return false;
1372
Jason Young808118c2011-03-10 16:43:19 -08001373 if (!mgd->associated)
1374 return false;
1375
Jason Young808118c2011-03-10 16:43:19 -08001376 if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
1377 IEEE80211_STA_CONNECTION_POLL))
1378 return false;
1379
Alexander Bondar989c6502013-05-16 17:34:17 +03001380 if (!mgd->have_beacon)
Alexander Bondarce857882013-05-06 17:17:04 +03001381 return false;
1382
Jason Young808118c2011-03-10 16:43:19 -08001383 rcu_read_lock();
1384 sta = sta_info_get(sdata, mgd->bssid);
1385 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001386 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001387 rcu_read_unlock();
1388
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001389 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001390}
1391
Johannes Berg965beda2009-04-16 13:17:24 +02001392/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +02001393void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +02001394{
1395 struct ieee80211_sub_if_data *sdata, *found = NULL;
1396 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001397 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001398
1399 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
1400 local->ps_sdata = NULL;
1401 return;
1402 }
1403
1404 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01001405 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001406 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301407 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1408 /* If an AP vif is found, then disable PS
1409 * by setting the count to zero thereby setting
1410 * ps_sdata to NULL.
1411 */
1412 count = 0;
1413 break;
1414 }
Johannes Berg965beda2009-04-16 13:17:24 +02001415 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1416 continue;
1417 found = sdata;
1418 count++;
1419 }
1420
Jason Young808118c2011-03-10 16:43:19 -08001421 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg10f644a2009-04-16 13:17:25 +02001422 s32 beaconint_us;
1423
1424 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +02001425 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +02001426
1427 beaconint_us = ieee80211_tu_to_usec(
1428 found->vif.bss_conf.beacon_int);
1429
Juuso Oikarinenff616382010-06-09 09:51:52 +03001430 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001431 if (timeout < 0) {
1432 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +03001433 * Go to full PSM if the user configures a very low
1434 * latency requirement.
Eliad Peller0ab82b02010-12-03 02:16:23 +02001435 * The 2000 second value is there for compatibility
1436 * until the PM_QOS_NETWORK_LATENCY is configured
1437 * with real values.
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001438 */
Eliad Peller0ab82b02010-12-03 02:16:23 +02001439 if (latency > (1900 * USEC_PER_MSEC) &&
1440 latency != (2000 * USEC_PER_SEC))
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001441 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001442 else
1443 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001444 }
Johannes Berg09b85562013-02-06 23:07:41 +01001445 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001446
Johannes Berg04fe2032009-04-22 18:44:37 +02001447 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +02001448 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +02001449 } else {
Johannes Berg04fe2032009-04-22 18:44:37 +02001450 int maxslp = 1;
Johannes Berg826262c2012-12-10 16:38:14 +02001451 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg56007a02010-01-26 14:19:52 +01001452
1453 /* If the TIM IE is invalid, pretend the value is 1 */
1454 if (!dtimper)
1455 dtimper = 1;
1456 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +02001457 maxslp = min_t(int, dtimper,
1458 latency / beaconint_us);
1459
Johannes Berg9ccebe62009-04-23 10:32:36 +02001460 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +01001461 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +02001462 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +02001463 }
Johannes Berg10f644a2009-04-16 13:17:25 +02001464 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001465 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001466 }
Johannes Berg965beda2009-04-16 13:17:24 +02001467
1468 ieee80211_change_ps(local);
1469}
1470
Eliad Pellerab095872012-07-27 12:33:22 +03001471void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1472{
1473 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1474
1475 if (sdata->vif.bss_conf.ps != ps_allowed) {
1476 sdata->vif.bss_conf.ps = ps_allowed;
1477 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1478 }
1479}
1480
Johannes Berg965beda2009-04-16 13:17:24 +02001481void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1482{
1483 struct ieee80211_local *local =
1484 container_of(work, struct ieee80211_local,
1485 dynamic_ps_disable_work);
1486
1487 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1488 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1489 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1490 }
1491
1492 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001493 IEEE80211_MAX_QUEUE_MAP,
Johannes Berg965beda2009-04-16 13:17:24 +02001494 IEEE80211_QUEUE_STOP_REASON_PS);
1495}
1496
1497void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1498{
1499 struct ieee80211_local *local =
1500 container_of(work, struct ieee80211_local,
1501 dynamic_ps_enable_work);
1502 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001503 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301504 unsigned long flags;
1505 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001506
1507 /* can only happen when PS was just disabled anyway */
1508 if (!sdata)
1509 return;
1510
Christian Lamparter5e340692011-06-30 21:08:43 +02001511 ifmgd = &sdata->u.mgd;
1512
Johannes Berg965beda2009-04-16 13:17:24 +02001513 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1514 return;
1515
Johannes Berg09b85562013-02-06 23:07:41 +01001516 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001517 /* don't enter PS if TX frames are pending */
1518 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301519 mod_timer(&local->dynamic_ps_timer, jiffies +
1520 msecs_to_jiffies(
1521 local->hw.conf.dynamic_ps_timeout));
1522 return;
1523 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001524
1525 /*
1526 * transmission can be stopped by others which leads to
1527 * dynamic_ps_timer expiry. Postpone the ps timer if it
1528 * is not the actual idle state.
1529 */
1530 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1531 for (q = 0; q < local->hw.queues; q++) {
1532 if (local->queue_stop_reasons[q]) {
1533 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1534 flags);
1535 mod_timer(&local->dynamic_ps_timer, jiffies +
1536 msecs_to_jiffies(
1537 local->hw.conf.dynamic_ps_timeout));
1538 return;
1539 }
1540 }
1541 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301542 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301543
Vivek Natarajan375177b2010-02-09 14:50:28 +05301544 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301545 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Johannes Berga1598382013-03-26 22:02:42 +01001546 if (drv_tx_frames_pending(local)) {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301547 mod_timer(&local->dynamic_ps_timer, jiffies +
1548 msecs_to_jiffies(
1549 local->hw.conf.dynamic_ps_timeout));
Johannes Berga1598382013-03-26 22:02:42 +01001550 } else {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301551 ieee80211_send_nullfunc(local, sdata, 1);
1552 /* Flush to get the tx status of nullfunc frame */
Johannes Berg39ecc012013-02-13 12:11:00 +01001553 ieee80211_flush_queues(local, sdata);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301554 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301555 }
1556
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001557 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
1558 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301559 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1560 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1561 local->hw.conf.flags |= IEEE80211_CONF_PS;
1562 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1563 }
Johannes Berg965beda2009-04-16 13:17:24 +02001564}
1565
1566void ieee80211_dynamic_ps_timer(unsigned long data)
1567{
1568 struct ieee80211_local *local = (void *) data;
1569
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -07001570 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +02001571 return;
1572
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001573 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001574}
1575
Simon Wunderlich164eb022013-02-08 18:16:20 +01001576void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1577{
1578 struct delayed_work *delayed_work =
1579 container_of(work, struct delayed_work, work);
1580 struct ieee80211_sub_if_data *sdata =
1581 container_of(delayed_work, struct ieee80211_sub_if_data,
1582 dfs_cac_timer_work);
1583
1584 ieee80211_vif_release_channel(sdata);
1585
1586 cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
1587}
1588
Johannes Berg60f8b392008-09-08 17:44:22 +02001589/* MLME */
Johannes Berg7d257452012-07-06 17:37:43 +02001590static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +02001591 struct ieee80211_sub_if_data *sdata,
Johannes Berg4a3cb702013-02-12 16:43:19 +01001592 const u8 *wmm_param, size_t wmm_param_len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001593{
Jiri Bencf0706e82007-05-05 11:45:53 -07001594 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +02001595 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001596 size_t left;
1597 int count;
Johannes Berg4a3cb702013-02-12 16:43:19 +01001598 const u8 *pos;
1599 u8 uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001600
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001601 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001602 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001603
Johannes Berg32c5057b2012-03-28 11:04:29 +02001604 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001605 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001606
1607 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001608 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001609
Jiri Bencf0706e82007-05-05 11:45:53 -07001610 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001611 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001612
1613 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001614 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001615
Jiri Bencf0706e82007-05-05 11:45:53 -07001616 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +01001617 if (count == ifmgd->wmm_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001618 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001619 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001620
1621 pos = wmm_param + 8;
1622 left = wmm_param_len - 8;
1623
1624 memset(&params, 0, sizeof(params));
1625
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001626 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001627 for (; left >= 4; left -= 4, pos += 4) {
1628 int aci = (pos[0] >> 5) & 0x03;
1629 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001630 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001631 int queue;
1632
1633 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001634 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +02001635 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +02001636 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001637 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001638 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1639 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001640 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001641 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +02001642 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +02001643 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001644 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001645 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1646 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001647 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001648 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +02001649 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +02001650 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001651 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02001652 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1653 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001654 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001655 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001656 default:
Johannes Berge100bb62008-04-30 18:51:21 +02001657 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +02001658 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001659 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02001660 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1661 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001662 break;
1663 }
1664
1665 params.aifs = pos[0] & 0x0f;
1666 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1667 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +02001668 params.txop = get_unaligned_le16(pos + 2);
Alexander Bondar908f8d02013-04-07 09:53:30 +03001669 params.acm = acm;
Kalle Valoab133152010-01-12 10:42:31 +02001670 params.uapsd = uapsd;
1671
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001672 mlme_dbg(sdata,
1673 "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
1674 queue, aci, acm,
1675 params.aifs, params.cw_min, params.cw_max,
1676 params.txop, params.uapsd);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001677 sdata->tx_conf[queue] = params;
1678 if (drv_conf_tx(local, sdata, queue, &params))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001679 sdata_err(sdata,
1680 "failed to set TX queue parameters for queue %d\n",
1681 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -07001682 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001683
1684 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02001685 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02001686 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001687}
1688
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001689static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1690{
1691 lockdep_assert_held(&sdata->local->mtx);
1692
1693 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1694 IEEE80211_STA_BEACON_POLL);
1695 ieee80211_run_deferred_scan(sdata->local);
1696}
1697
1698static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1699{
1700 mutex_lock(&sdata->local->mtx);
1701 __ieee80211_stop_poll(sdata);
1702 mutex_unlock(&sdata->local->mtx);
1703}
1704
Johannes Berg7a5158e2008-10-08 10:59:33 +02001705static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1706 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02001707{
Johannes Bergbda39332008-10-11 01:51:51 +02001708 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001709 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001710 bool use_protection;
1711 bool use_short_preamble;
1712 bool use_short_slot;
1713
1714 if (erp_valid) {
1715 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1716 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1717 } else {
1718 use_protection = false;
1719 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1720 }
1721
1722 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Johannes Berg55de9082012-07-26 17:24:39 +02001723 if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01001724 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02001725
Johannes Berg471b3ef2007-12-28 14:32:58 +01001726 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01001727 bss_conf->use_cts_prot = use_protection;
1728 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02001729 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02001730
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001731 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001732 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001733 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02001734 }
Daniel Draked9430a32007-07-27 15:43:24 +02001735
Johannes Berg7a5158e2008-10-08 10:59:33 +02001736 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02001737 bss_conf->use_short_slot = use_short_slot;
1738 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04001739 }
1740
1741 return changed;
1742}
1743
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001744static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001745 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02001746 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07001747{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001748 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001749 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001750 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001751
Johannes Bergae5eb022008-10-14 16:58:37 +02001752 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001753 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03001754 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001755
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01001756 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
Ben Greear59c1ec22013-03-19 14:19:56 -07001757 beacon_loss_count * bss_conf->beacon_int));
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01001758
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001759 sdata->u.mgd.associated = cbss;
1760 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01001761
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001762 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1763
Johannes Berg488dd7b2012-10-29 20:08:01 +01001764 if (sdata->vif.p2p) {
Johannes Berg9caf0362012-11-29 01:25:20 +01001765 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01001766
Johannes Berg9caf0362012-11-29 01:25:20 +01001767 rcu_read_lock();
1768 ies = rcu_dereference(cbss->ies);
1769 if (ies) {
Johannes Berg9caf0362012-11-29 01:25:20 +01001770 int ret;
1771
1772 ret = cfg80211_get_p2p_attr(
1773 ies->data, ies->len,
1774 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001775 (u8 *) &bss_conf->p2p_noa_attr,
1776 sizeof(bss_conf->p2p_noa_attr));
Johannes Berg9caf0362012-11-29 01:25:20 +01001777 if (ret >= 2) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001778 sdata->u.mgd.p2p_noa_index =
1779 bss_conf->p2p_noa_attr.index;
Johannes Berg9caf0362012-11-29 01:25:20 +01001780 bss_info_changed |= BSS_CHANGED_P2P_PS;
Johannes Berg9caf0362012-11-29 01:25:20 +01001781 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01001782 }
Johannes Berg9caf0362012-11-29 01:25:20 +01001783 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01001784 }
1785
Johannes Bergb291ba12009-07-10 15:29:03 +02001786 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001787 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001788
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001789 ieee80211_led_assoc(local, 1);
1790
Alexander Bondar989c6502013-05-16 17:34:17 +03001791 if (sdata->u.mgd.have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02001792 /*
1793 * If the AP is buggy we may get here with no DTIM period
1794 * known, so assume it's 1 which is the only safe assumption
1795 * in that case, although if the TIM IE is broken powersave
1796 * probably just won't work at all.
1797 */
1798 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Alexander Bondar817cee72013-05-19 14:23:57 +03001799 bss_conf->beacon_rate = bss->beacon_rate;
Alexander Bondar989c6502013-05-16 17:34:17 +03001800 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
Johannes Berg826262c2012-12-10 16:38:14 +02001801 } else {
Alexander Bondar817cee72013-05-19 14:23:57 +03001802 bss_conf->beacon_rate = NULL;
Johannes Berge5b900d2010-07-29 16:08:55 +02001803 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02001804 }
Johannes Berge5b900d2010-07-29 16:08:55 +02001805
Juuso Oikarinen68542962010-06-09 13:43:26 +03001806 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02001807
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001808 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01001809 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03001810 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001811 bss_info_changed |= BSS_CHANGED_CQM;
1812
Juuso Oikarinen68542962010-06-09 13:43:26 +03001813 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01001814 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03001815 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001816
Johannes Bergae5eb022008-10-14 16:58:37 +02001817 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03001818
Johannes Berg056508d2009-07-30 21:43:55 +02001819 mutex_lock(&local->iflist_mtx);
1820 ieee80211_recalc_ps(local, -1);
1821 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02001822
Johannes Berg04ecd252012-09-11 14:34:12 +02001823 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03001824 ieee80211_recalc_ps_vif(sdata);
1825
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001826 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001827}
1828
Jouni Malinene69e95d2010-03-29 23:29:31 -07001829static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01001830 u16 stype, u16 reason, bool tx,
1831 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03001832{
Johannes Berg46900292009-02-15 12:44:28 +01001833 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001834 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01001835 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001836
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001837 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001838
Johannes Berg37ad3882012-02-24 13:50:54 +01001839 if (WARN_ON_ONCE(tx && !frame_buf))
1840 return;
1841
Johannes Bergb291ba12009-07-10 15:29:03 +02001842 if (WARN_ON(!ifmgd->associated))
1843 return;
1844
David Spinadel79543d82012-06-12 09:59:45 +03001845 ieee80211_stop_poll(sdata);
1846
Johannes Berg77fdaa12009-07-07 03:45:17 +02001847 ifmgd->associated = NULL;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001848 netif_carrier_off(sdata->dev);
1849
Eliad Peller88bc40e2012-07-12 17:35:33 +03001850 /*
1851 * if we want to get out of ps before disassoc (why?) we have
1852 * to do it before sending disassoc, as otherwise the null-packet
1853 * won't be valid.
1854 */
1855 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1856 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1857 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1858 }
1859 local->ps_sdata = NULL;
1860
Eliad Pellerab095872012-07-27 12:33:22 +03001861 /* disable per-vif ps */
1862 ieee80211_recalc_ps_vif(sdata);
1863
Eliad Pellerf8239812012-06-27 14:18:22 +03001864 /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
1865 if (tx)
Johannes Berg39ecc012013-02-13 12:11:00 +01001866 ieee80211_flush_queues(local, sdata);
Eliad Pellerf8239812012-06-27 14:18:22 +03001867
Johannes Berg37ad3882012-02-24 13:50:54 +01001868 /* deauthenticate/disassociate now */
1869 if (tx || frame_buf)
Eliad Peller88a9e312012-06-01 11:14:03 +03001870 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
1871 reason, tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01001872
1873 /* flush out frame */
1874 if (tx)
Johannes Berg39ecc012013-02-13 12:11:00 +01001875 ieee80211_flush_queues(local, sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01001876
Eliad Peller88a9e312012-06-01 11:14:03 +03001877 /* clear bssid only after building the needed mgmt frames */
1878 memset(ifmgd->bssid, 0, ETH_ALEN);
1879
Johannes Berg37ad3882012-02-24 13:50:54 +01001880 /* remove AP and TDLS peers */
Johannes Berg051007d2012-12-13 23:49:02 +01001881 sta_info_flush_defer(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01001882
1883 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001884 changed |= ieee80211_reset_erp_info(sdata);
1885
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001886 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001887 changed |= BSS_CHANGED_ASSOC;
1888 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001889
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001890 ifmgd->p2p_noa_index = -1;
1891 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1892 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01001893
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01001894 /* on the next assoc, re-program HT/VHT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08001895 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
1896 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01001897 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
1898 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
Johannes Berg413ad502009-05-08 21:21:06 +02001899
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001900 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301901
Kalle Valo520eb822008-12-18 23:35:27 +02001902 del_timer_sync(&local->dynamic_ps_timer);
1903 cancel_work_sync(&local->dynamic_ps_enable_work);
1904
Juuso Oikarinen68542962010-06-09 13:43:26 +03001905 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01001906 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03001907 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001908
Johannes Berg3abead52012-03-02 15:56:59 +01001909 sdata->vif.bss_conf.qos = false;
1910 changed |= BSS_CHANGED_QOS;
1911
Johannes Berg0aaffa92010-05-05 15:28:27 +02001912 /* The BSSID (not really interesting) and HT changed */
1913 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001914 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001915
Johannes Berg3abead52012-03-02 15:56:59 +01001916 /* disassociated - set to defaults now */
1917 ieee80211_set_wmm_default(sdata, false);
1918
Johannes Bergb9dcf712010-08-27 12:35:54 +02001919 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1920 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1921 del_timer_sync(&sdata->u.mgd.timer);
1922 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02001923
Johannes Berg826262c2012-12-10 16:38:14 +02001924 sdata->vif.bss_conf.dtim_period = 0;
Alexander Bondar817cee72013-05-19 14:23:57 +03001925 sdata->vif.bss_conf.beacon_rate = NULL;
1926
Alexander Bondar989c6502013-05-16 17:34:17 +03001927 ifmgd->have_beacon = false;
Johannes Berg826262c2012-12-10 16:38:14 +02001928
Johannes Berg028e8da02012-11-26 11:57:41 +01001929 ifmgd->flags = 0;
1930 ieee80211_vif_release_channel(sdata);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001931}
Jiri Bencf0706e82007-05-05 11:45:53 -07001932
Kalle Valo3cf335d2009-03-22 21:57:06 +02001933void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1934 struct ieee80211_hdr *hdr)
1935{
1936 /*
1937 * We can postpone the mgd.timer whenever receiving unicast frames
1938 * from AP because we know that the connection is working both ways
1939 * at that time. But multicast frames (and hence also beacons) must
1940 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001941 * data idle periods for sending the periodic probe request to the
1942 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001943 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001944 if (is_multicast_ether_addr(hdr->addr1))
1945 return;
1946
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001947 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02001948}
Jiri Bencf0706e82007-05-05 11:45:53 -07001949
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001950static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1951{
1952 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001953 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001954
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001955 mutex_lock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001956 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001957 IEEE80211_STA_CONNECTION_POLL))) {
1958 mutex_unlock(&local->mtx);
1959 return;
1960 }
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001961
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001962 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001963
1964 mutex_lock(&local->iflist_mtx);
1965 ieee80211_recalc_ps(local, -1);
1966 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001967
1968 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001969 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001970
1971 /*
1972 * We've received a probe response, but are not sure whether
1973 * we have or will be receiving any beacons or data, so let's
1974 * schedule the timers again, just in case.
1975 */
1976 ieee80211_sta_reset_beacon_monitor(sdata);
1977
1978 mod_timer(&ifmgd->conn_mon_timer,
1979 round_jiffies_up(jiffies +
1980 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001981out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001982 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001983}
1984
1985void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001986 struct ieee80211_hdr *hdr, bool ack)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001987{
Felix Fietkau75706d02010-12-02 21:01:07 +01001988 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001989 return;
1990
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001991 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1992 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001993 if (ack)
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01001994 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001995 else
1996 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001997 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01001998 return;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001999 }
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002000
2001 if (ack)
2002 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002003}
2004
Maxim Levitskya43abf22009-07-31 18:54:12 +03002005static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2006{
2007 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2008 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002009 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08002010 u8 unicast_limit = max(1, max_probe_tries - 3);
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002011
2012 /*
2013 * Try sending broadcast probe requests for the last three
2014 * probe requests after the first ones failed since some
2015 * buggy APs only support broadcast probe requests.
2016 */
2017 if (ifmgd->probe_send_count >= unicast_limit)
2018 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002019
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002020 /*
2021 * When the hardware reports an accurate Tx ACK status, it's
2022 * better to send a nullfunc frame instead of a probe request,
2023 * as it will kick us off the AP quickly if we aren't associated
2024 * anymore. The timeout will be reset if the frame is ACKed by
2025 * the AP.
2026 */
Soumik Das992e68b2012-05-20 15:31:13 +05302027 ifmgd->probe_send_count++;
2028
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002029 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
2030 ifmgd->nullfunc_failed = false;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002031 ieee80211_send_nullfunc(sdata->local, sdata, 0);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002032 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002033 int ssid_len;
2034
Johannes Berg9caf0362012-11-29 01:25:20 +01002035 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002036 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002037 if (WARN_ON_ONCE(ssid == NULL))
2038 ssid_len = 0;
2039 else
2040 ssid_len = ssid[1];
2041
2042 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL,
Johannes Berg1672c0e2013-01-29 15:02:27 +01002043 0, (u32) -1, true, 0,
Johannes Berg55de9082012-07-26 17:24:39 +02002044 ifmgd->associated->channel, false);
Johannes Berg9caf0362012-11-29 01:25:20 +01002045 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002046 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03002047
Ben Greear180205b2011-02-04 15:30:24 -08002048 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002049 run_again(sdata, ifmgd->probe_timeout);
Rajkumar Manoharanf69b9c72012-03-15 06:15:26 +05302050 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Johannes Berg39ecc012013-02-13 12:11:00 +01002051 ieee80211_flush_queues(sdata->local, sdata);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002052}
2053
Johannes Bergb291ba12009-07-10 15:29:03 +02002054static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2055 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02002056{
Kalle Valo04de8382009-03-22 21:57:35 +02002057 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002058 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02002059
Johannes Berg9607e6b2009-12-23 13:15:31 +01002060 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02002061 return;
2062
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002063 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002064
2065 if (!ifmgd->associated)
2066 goto out;
2067
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002068 mutex_lock(&sdata->local->mtx);
2069
2070 if (sdata->local->tmp_channel || sdata->local->scanning) {
2071 mutex_unlock(&sdata->local->mtx);
2072 goto out;
2073 }
2074
Ben Greeara13fbe52013-03-25 11:19:35 -07002075 if (beacon) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002076 mlme_dbg_ratelimited(sdata,
Ben Greear59c1ec22013-03-19 14:19:56 -07002077 "detected beacon loss from AP (missed %d beacons) - probing\n",
2078 beacon_loss_count);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002079
Ben Greeara13fbe52013-03-25 11:19:35 -07002080 ieee80211_cqm_rssi_notify(&sdata->vif,
2081 NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
2082 GFP_KERNEL);
2083 }
Kalle Valo04de8382009-03-22 21:57:35 +02002084
Johannes Bergb291ba12009-07-10 15:29:03 +02002085 /*
2086 * The driver/our work has already reported this event or the
2087 * connection monitoring has kicked in and we have already sent
2088 * a probe request. Or maybe the AP died and the driver keeps
2089 * reporting until we disassociate...
2090 *
2091 * In either case we have to ignore the current call to this
2092 * function (except for setting the correct probe reason bit)
2093 * because otherwise we would reset the timer every time and
2094 * never check whether we received a probe response!
2095 */
2096 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
2097 IEEE80211_STA_CONNECTION_POLL))
2098 already = true;
2099
2100 if (beacon)
2101 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
2102 else
2103 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2104
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002105 mutex_unlock(&sdata->local->mtx);
2106
Johannes Bergb291ba12009-07-10 15:29:03 +02002107 if (already)
2108 goto out;
2109
Johannes Berg4e751842009-06-10 15:16:52 +02002110 mutex_lock(&sdata->local->iflist_mtx);
2111 ieee80211_recalc_ps(sdata->local, -1);
2112 mutex_unlock(&sdata->local->iflist_mtx);
2113
Maxim Levitskya43abf22009-07-31 18:54:12 +03002114 ifmgd->probe_send_count = 0;
2115 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002116 out:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002117 sdata_unlock(sdata);
Kalle Valo04de8382009-03-22 21:57:35 +02002118}
2119
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002120struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2121 struct ieee80211_vif *vif)
2122{
2123 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2124 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002125 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002126 struct sk_buff *skb;
2127 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002128 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002129
2130 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2131 return NULL;
2132
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002133 sdata_assert_lock(sdata);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002134
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002135 if (ifmgd->associated)
2136 cbss = ifmgd->associated;
2137 else if (ifmgd->auth_data)
2138 cbss = ifmgd->auth_data->bss;
2139 else if (ifmgd->assoc_data)
2140 cbss = ifmgd->assoc_data->bss;
2141 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002142 return NULL;
2143
Johannes Berg9caf0362012-11-29 01:25:20 +01002144 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002145 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002146 if (WARN_ON_ONCE(ssid == NULL))
2147 ssid_len = 0;
2148 else
2149 ssid_len = ssid[1];
2150
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002151 skb = ieee80211_build_probe_req(sdata, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02002152 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02002153 ssid + 2, ssid_len,
Johannes Berg85a237f2011-07-18 18:08:36 +02002154 NULL, 0, true);
Johannes Berg9caf0362012-11-29 01:25:20 +01002155 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002156
2157 return skb;
2158}
2159EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2160
Johannes Bergeef9e542013-01-29 13:09:34 +01002161static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002162{
2163 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002164 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002165
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002166 sdata_lock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002167 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002168 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002169 return;
2170 }
2171
Johannes Berg37ad3882012-02-24 13:50:54 +01002172 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2173 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Johannes Bergeef9e542013-01-29 13:09:34 +01002174 true, frame_buf);
Johannes Berg882a7c62012-08-01 22:32:45 +02002175 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
Johannes Berg5b36ebd2013-02-13 14:21:45 +01002176 ieee80211_wake_queues_by_reason(&sdata->local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01002177 IEEE80211_MAX_QUEUE_MAP,
Johannes Berg5b36ebd2013-02-13 14:21:45 +01002178 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002179
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002180 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
2181 IEEE80211_DEAUTH_FRAME_LEN);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002182 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002183}
2184
Johannes Bergcc74c0c2012-08-01 16:49:34 +02002185static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02002186{
2187 struct ieee80211_sub_if_data *sdata =
2188 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002189 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002190 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2191 struct sta_info *sta;
2192
2193 if (ifmgd->associated) {
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05302194 rcu_read_lock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08002195 sta = sta_info_get(sdata, ifmgd->bssid);
2196 if (sta)
2197 sta->beacon_loss_count++;
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05302198 rcu_read_unlock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08002199 }
Johannes Bergb291ba12009-07-10 15:29:03 +02002200
Johannes Berg682bd382013-01-29 13:13:50 +01002201 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02002202 sdata_info(sdata, "Connection to AP %pM lost\n",
2203 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01002204 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02002205 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002206 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02002207 }
2208}
2209
2210static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2211{
2212 struct ieee80211_sub_if_data *sdata =
2213 container_of(work, struct ieee80211_sub_if_data,
2214 u.mgd.csa_connection_drop_work);
2215
Johannes Bergeef9e542013-01-29 13:09:34 +01002216 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002217}
2218
Kalle Valo04de8382009-03-22 21:57:35 +02002219void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2220{
2221 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002222 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02002223
Johannes Bergb5878a22010-04-07 16:48:40 +02002224 trace_api_beacon_loss(sdata);
2225
Johannes Berg682bd382013-01-29 13:13:50 +01002226 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002227 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002228}
2229EXPORT_SYMBOL(ieee80211_beacon_loss);
2230
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002231void ieee80211_connection_loss(struct ieee80211_vif *vif)
2232{
2233 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2234 struct ieee80211_hw *hw = &sdata->local->hw;
2235
Johannes Bergb5878a22010-04-07 16:48:40 +02002236 trace_api_connection_loss(sdata);
2237
Johannes Berg682bd382013-01-29 13:13:50 +01002238 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002239 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2240}
2241EXPORT_SYMBOL(ieee80211_connection_loss);
2242
2243
Johannes Berg66e67e42012-01-20 13:55:27 +01002244static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2245 bool assoc)
2246{
2247 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2248
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002249 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002250
Johannes Berg66e67e42012-01-20 13:55:27 +01002251 if (!assoc) {
2252 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2253
2254 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2255 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002256 sdata->u.mgd.flags = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002257 ieee80211_vif_release_channel(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002258 }
2259
Johannes Berg5b112d32013-02-01 01:49:58 +01002260 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002261 kfree(auth_data);
2262 sdata->u.mgd.auth_data = NULL;
2263}
2264
2265static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2266 struct ieee80211_mgmt *mgmt, size_t len)
2267{
Johannes Berg1672c0e2013-01-29 15:02:27 +01002268 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01002269 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2270 u8 *pos;
2271 struct ieee802_11_elems elems;
Johannes Berg1672c0e2013-01-29 15:02:27 +01002272 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002273
2274 pos = mgmt->u.auth.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002275 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002276 if (!elems.challenge)
2277 return;
2278 auth_data->expected_transaction = 4;
Johannes Berga1845fc2012-06-27 13:18:36 +02002279 drv_mgd_prepare_tx(sdata->local, sdata);
Johannes Berg1672c0e2013-01-29 15:02:27 +01002280 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
2281 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2282 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03002283 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01002284 elems.challenge - 2, elems.challenge_len + 2,
2285 auth_data->bss->bssid, auth_data->bss->bssid,
2286 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e2013-01-29 15:02:27 +01002287 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002288}
2289
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002290static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2291 struct ieee80211_mgmt *mgmt, size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002292{
2293 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2294 u8 bssid[ETH_ALEN];
2295 u16 auth_alg, auth_transaction, status_code;
2296 struct sta_info *sta;
2297
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002298 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002299
2300 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002301 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002302
2303 if (!ifmgd->auth_data || ifmgd->auth_data->done)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002304 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002305
2306 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2307
Joe Perchesb203ca32012-05-08 18:56:52 +00002308 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002309 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002310
2311 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2312 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2313 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2314
2315 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002316 auth_transaction != ifmgd->auth_data->expected_transaction) {
2317 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2318 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2319 auth_transaction,
2320 ifmgd->auth_data->expected_transaction);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002321 return;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002322 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002323
2324 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002325 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2326 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002327 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002328 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002329 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002330 }
2331
2332 switch (ifmgd->auth_data->algorithm) {
2333 case WLAN_AUTH_OPEN:
2334 case WLAN_AUTH_LEAP:
2335 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002336 case WLAN_AUTH_SAE:
Johannes Berg66e67e42012-01-20 13:55:27 +01002337 break;
2338 case WLAN_AUTH_SHARED_KEY:
2339 if (ifmgd->auth_data->expected_transaction != 4) {
2340 ieee80211_auth_challenge(sdata, mgmt, len);
2341 /* need another frame */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002342 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002343 }
2344 break;
2345 default:
2346 WARN_ONCE(1, "invalid auth alg %d",
2347 ifmgd->auth_data->algorithm);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002348 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002349 }
2350
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002351 sdata_info(sdata, "authenticated\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002352 ifmgd->auth_data->done = true;
2353 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
Johannes Berg89afe612013-02-13 15:39:57 +01002354 ifmgd->auth_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002355 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01002356
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002357 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2358 ifmgd->auth_data->expected_transaction != 2) {
2359 /*
2360 * Report auth frame to user space for processing since another
2361 * round of Authentication frames is still needed.
2362 */
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002363 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002364 return;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002365 }
2366
Johannes Berg66e67e42012-01-20 13:55:27 +01002367 /* move station state to auth */
2368 mutex_lock(&sdata->local->sta_mtx);
2369 sta = sta_info_get(sdata, bssid);
2370 if (!sta) {
2371 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2372 goto out_err;
2373 }
2374 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002375 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002376 goto out_err;
2377 }
2378 mutex_unlock(&sdata->local->sta_mtx);
2379
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002380 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002381 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002382 out_err:
2383 mutex_unlock(&sdata->local->sta_mtx);
2384 /* ignore frame -- wait for timeout */
Johannes Berg66e67e42012-01-20 13:55:27 +01002385}
2386
2387
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002388static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2389 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002390{
Johannes Berg46900292009-02-15 12:44:28 +01002391 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002392 const u8 *bssid = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07002393 u16 reason_code;
2394
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002395 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002396
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002397 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002398 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002399
Johannes Berg66e67e42012-01-20 13:55:27 +01002400 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002401 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002402 return;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002403
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002404 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002405
2406 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
2407
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002408 sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n",
2409 bssid, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002410
Johannes Berg37ad3882012-02-24 13:50:54 +01002411 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2412
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002413 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07002414}
2415
2416
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002417static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2418 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002419{
Johannes Berg46900292009-02-15 12:44:28 +01002420 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002421 u16 reason_code;
2422
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002423 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002424
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002425 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002426 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002427
Johannes Berg66e67e42012-01-20 13:55:27 +01002428 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002429 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002430 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002431
2432 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2433
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002434 sdata_info(sdata, "disassociated from %pM (Reason: %u)\n",
2435 mgmt->sa, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002436
Johannes Berg37ad3882012-02-24 13:50:54 +01002437 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2438
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002439 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07002440}
2441
Christian Lamparterc74d0842011-10-15 00:14:49 +02002442static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2443 u8 *supp_rates, unsigned int supp_rates_len,
2444 u32 *rates, u32 *basic_rates,
2445 bool *have_higher_than_11mbit,
2446 int *min_rate, int *min_rate_index)
2447{
2448 int i, j;
2449
2450 for (i = 0; i < supp_rates_len; i++) {
2451 int rate = (supp_rates[i] & 0x7f) * 5;
2452 bool is_basic = !!(supp_rates[i] & 0x80);
2453
2454 if (rate > 110)
2455 *have_higher_than_11mbit = true;
2456
2457 /*
2458 * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
2459 * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
2460 *
2461 * Note: Even through the membership selector and the basic
2462 * rate flag share the same bit, they are not exactly
2463 * the same.
2464 */
2465 if (!!(supp_rates[i] & 0x80) &&
2466 (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
2467 continue;
2468
2469 for (j = 0; j < sband->n_bitrates; j++) {
2470 if (sband->bitrates[j].bitrate == rate) {
2471 *rates |= BIT(j);
2472 if (is_basic)
2473 *basic_rates |= BIT(j);
2474 if (rate < *min_rate) {
2475 *min_rate = rate;
2476 *min_rate_index = j;
2477 }
2478 break;
2479 }
2480 }
2481 }
2482}
Jiri Bencf0706e82007-05-05 11:45:53 -07002483
Johannes Berg66e67e42012-01-20 13:55:27 +01002484static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2485 bool assoc)
2486{
2487 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2488
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002489 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002490
Johannes Berg66e67e42012-01-20 13:55:27 +01002491 if (!assoc) {
2492 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2493
2494 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2495 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002496 sdata->u.mgd.flags = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002497 ieee80211_vif_release_channel(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002498 }
2499
2500 kfree(assoc_data);
2501 sdata->u.mgd.assoc_data = NULL;
2502}
2503
2504static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2505 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002506 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002507{
Johannes Berg46900292009-02-15 12:44:28 +01002508 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002509 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01002510 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07002511 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002512 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002513 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002514 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02002515 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg35d865a2013-05-28 10:54:03 +02002516 const struct cfg80211_bss_ies *bss_ies = NULL;
2517 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
Johannes Bergae5eb022008-10-14 16:58:37 +02002518 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02002519 int err;
Johannes Berg35d865a2013-05-28 10:54:03 +02002520 bool ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07002521
Johannes Bergaf6b6372009-12-23 13:15:35 +01002522 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07002523
Jiri Bencf0706e82007-05-05 11:45:53 -07002524 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002525 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07002526
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002527 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002528 sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
2529 aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002530 aid &= ~(BIT(15) | BIT(14));
2531
Johannes Berg05cb9102011-10-28 11:59:47 +02002532 ifmgd->broken_ap = false;
2533
2534 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002535 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
2536 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02002537 aid = 0;
2538 ifmgd->broken_ap = true;
2539 }
2540
Johannes Bergaf6b6372009-12-23 13:15:35 +01002541 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002542 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002543
Jiri Bencf0706e82007-05-05 11:45:53 -07002544 if (!elems.supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002545 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01002546 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002547 }
2548
Johannes Berg46900292009-02-15 12:44:28 +01002549 ifmgd->aid = aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002550
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002551 /*
Johannes Berg35d865a2013-05-28 10:54:03 +02002552 * Some APs are erroneously not including some information in their
2553 * (re)association response frames. Try to recover by using the data
2554 * from the beacon or probe response. This seems to afflict mobile
2555 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
2556 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
2557 */
2558 if ((assoc_data->wmm && !elems.wmm_param) ||
2559 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
2560 (!elems.ht_cap_elem || !elems.ht_operation)) ||
2561 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
2562 (!elems.vht_cap_elem || !elems.vht_operation))) {
2563 const struct cfg80211_bss_ies *ies;
2564 struct ieee802_11_elems bss_elems;
2565
2566 rcu_read_lock();
2567 ies = rcu_dereference(cbss->ies);
2568 if (ies)
2569 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
2570 GFP_ATOMIC);
2571 rcu_read_unlock();
2572 if (!bss_ies)
2573 return false;
2574
2575 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
2576 false, &bss_elems);
2577 if (assoc_data->wmm &&
2578 !elems.wmm_param && bss_elems.wmm_param) {
2579 elems.wmm_param = bss_elems.wmm_param;
2580 sdata_info(sdata,
2581 "AP bug: WMM param missing from AssocResp\n");
2582 }
2583
2584 /*
2585 * Also check if we requested HT/VHT, otherwise the AP doesn't
2586 * have to include the IEs in the (re)association response.
2587 */
2588 if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
2589 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
2590 elems.ht_cap_elem = bss_elems.ht_cap_elem;
2591 sdata_info(sdata,
2592 "AP bug: HT capability missing from AssocResp\n");
2593 }
2594 if (!elems.ht_operation && bss_elems.ht_operation &&
2595 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
2596 elems.ht_operation = bss_elems.ht_operation;
2597 sdata_info(sdata,
2598 "AP bug: HT operation missing from AssocResp\n");
2599 }
2600 if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
2601 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
2602 elems.vht_cap_elem = bss_elems.vht_cap_elem;
2603 sdata_info(sdata,
2604 "AP bug: VHT capa missing from AssocResp\n");
2605 }
2606 if (!elems.vht_operation && bss_elems.vht_operation &&
2607 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
2608 elems.vht_operation = bss_elems.vht_operation;
2609 sdata_info(sdata,
2610 "AP bug: VHT operation missing from AssocResp\n");
2611 }
2612 }
2613
2614 /*
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002615 * We previously checked these in the beacon/probe response, so
2616 * they should be present here. This is just a safety net.
2617 */
2618 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
2619 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
2620 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02002621 "HT AP is missing WMM params or HT capability/operation\n");
2622 ret = false;
2623 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002624 }
2625
2626 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
2627 (!elems.vht_cap_elem || !elems.vht_operation)) {
2628 sdata_info(sdata,
Johannes Berg35d865a2013-05-28 10:54:03 +02002629 "VHT AP is missing VHT capability/operation\n");
2630 ret = false;
2631 goto out;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002632 }
2633
Guy Eilam2a33bee2011-08-17 15:18:15 +03002634 mutex_lock(&sdata->local->sta_mtx);
2635 /*
2636 * station info was already allocated and inserted before
2637 * the association and should be available to us
2638 */
Johannes Berg7852e362012-01-20 13:55:24 +01002639 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03002640 if (WARN_ON(!sta)) {
2641 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02002642 ret = false;
2643 goto out;
Jiri Bencf0706e82007-05-05 11:45:53 -07002644 }
2645
Johannes Berg55de9082012-07-26 17:24:39 +02002646 sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
Johannes Berg8318d782008-01-24 19:38:38 +01002647
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002648 /* Set up internal HT/VHT capabilities */
Johannes Berga8243b72012-11-22 14:32:09 +01002649 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08002650 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01002651 elems.ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02002652
Mahesh Palivela818255e2012-10-10 11:33:04 +00002653 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2654 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01002655 elems.vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00002656
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002657 /*
2658 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
2659 * in their association response, so ignore that data for our own
2660 * configuration. If it changed since the last beacon, we'll get the
2661 * next beacon and update then.
2662 */
Johannes Berg11289582013-02-07 17:36:12 +01002663
Johannes Bergbee7f582013-02-07 22:24:55 +01002664 /*
2665 * If an operating mode notification IE is present, override the
2666 * NSS calculation (that would be done in rate_control_rate_init())
2667 * and use the # of streams from that element.
2668 */
2669 if (elems.opmode_notif &&
2670 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
2671 u8 nss;
2672
2673 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
2674 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
2675 nss += 1;
2676 sta->sta.rx_nss = nss;
2677 }
2678
Johannes Berg4b7679a2008-09-18 18:14:18 +02002679 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07002680
Johannes Berg46900292009-02-15 12:44:28 +01002681 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002682 set_sta_flag(sta, WLAN_STA_MFP);
Jouni Malinen5394af42009-01-08 13:31:59 +02002683
Johannes Bergddf4ac52008-10-22 11:41:38 +02002684 if (elems.wmm_param)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002685 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002686
Johannes Berg3e4d40f2013-02-07 17:19:08 +01002687 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01002688 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
2689 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
2690 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002691 sdata_info(sdata,
2692 "failed to move station %pM to desired state\n",
2693 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01002694 WARN_ON(__sta_info_destroy(sta));
2695 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg35d865a2013-05-28 10:54:03 +02002696 ret = false;
2697 goto out;
Johannes Bergc8987872012-01-20 13:55:17 +01002698 }
2699
Johannes Berg7852e362012-01-20 13:55:24 +01002700 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002701
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03002702 /*
2703 * Always handle WMM once after association regardless
2704 * of the first value the AP uses. Setting -1 here has
2705 * that effect because the AP values is an unsigned
2706 * 4-bit value.
2707 */
2708 ifmgd->wmm_last_param_set = -1;
2709
Johannes Bergddf4ac52008-10-22 11:41:38 +02002710 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02002711 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07002712 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02002713 else
Johannes Berg3abead52012-03-02 15:56:59 +01002714 ieee80211_set_wmm_default(sdata, false);
2715 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07002716
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002717 /* set AID and assoc capability,
2718 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01002719 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002720 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002721 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07002722
Kalle Valo15b7b062009-03-22 21:57:14 +02002723 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01002724 * If we're using 4-addr mode, let the AP know that we're
2725 * doing so, so that it can create the STA VLAN on its side
2726 */
2727 if (ifmgd->use_4addr)
2728 ieee80211_send_4addr_nullfunc(local, sdata);
2729
2730 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02002731 * Start timer to probe the connection to the AP now.
2732 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02002733 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002734 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04002735 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02002736
Johannes Berg35d865a2013-05-28 10:54:03 +02002737 ret = true;
2738 out:
2739 kfree(bss_ies);
2740 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07002741}
2742
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002743static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2744 struct ieee80211_mgmt *mgmt,
2745 size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002746{
2747 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2748 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
2749 u16 capab_info, status_code, aid;
2750 struct ieee802_11_elems elems;
2751 u8 *pos;
2752 bool reassoc;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002753 struct cfg80211_bss *bss;
Jiri Bencf0706e82007-05-05 11:45:53 -07002754
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002755 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002756
2757 if (!assoc_data)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002758 return;
Joe Perchesb203ca32012-05-08 18:56:52 +00002759 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002760 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002761
2762 /*
2763 * AssocResp and ReassocResp have identical structure, so process both
2764 * of them in this function.
2765 */
2766
2767 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002768 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002769
2770 reassoc = ieee80211_is_reassoc_req(mgmt->frame_control);
2771 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2772 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2773 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2774
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002775 sdata_info(sdata,
2776 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
2777 reassoc ? "Rea" : "A", mgmt->sa,
2778 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01002779
2780 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002781 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002782
2783 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01002784 elems.timeout_int &&
2785 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002786 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01002787 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01002788 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002789 sdata_info(sdata,
2790 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
2791 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01002792 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01002793 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01002794 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002795 run_again(sdata, assoc_data->timeout);
2796 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002797 }
2798
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002799 bss = assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01002800
2801 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002802 sdata_info(sdata, "%pM denied association (code=%d)\n",
2803 mgmt->sa, status_code);
Johannes Berg66e67e42012-01-20 13:55:27 +01002804 ieee80211_destroy_assoc_data(sdata, false);
2805 } else {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002806 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002807 /* oops -- internal error -- send timeout for now */
Eliad Peller10a91092012-07-02 14:42:03 +03002808 ieee80211_destroy_assoc_data(sdata, false);
Johannes Berg959867f2013-06-19 13:05:42 +02002809 cfg80211_assoc_timeout(sdata->dev, bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002810 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002811 }
John W. Linville635d9992012-07-09 16:34:34 -04002812 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01002813
2814 /*
2815 * destroy assoc_data afterwards, as otherwise an idle
2816 * recalc after assoc_data is NULL but before associated
2817 * is set can cause the interface to go idle
2818 */
2819 ieee80211_destroy_assoc_data(sdata, true);
Johannes Berg66e67e42012-01-20 13:55:27 +01002820 }
2821
Johannes Berg6ff57cf2013-05-16 00:55:00 +02002822 cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len);
Johannes Berg66e67e42012-01-20 13:55:27 +01002823}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01002824
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002825static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01002826 struct ieee80211_mgmt *mgmt, size_t len,
Jiri Bencf0706e82007-05-05 11:45:53 -07002827 struct ieee80211_rx_status *rx_status,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002828 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07002829{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002830 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002831 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02002832 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002833 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01002834
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002835 sdata_assert_lock(sdata);
Johannes Bergb4f286a2013-03-26 14:13:58 +01002836
Johannes Berg1cd8e882013-03-27 14:30:12 +01002837 if (elems->ds_params)
Bruno Randolf59eb21a2011-01-17 13:37:28 +09002838 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
2839 rx_status->band);
Johannes Berg5bda6172008-09-08 11:05:10 +02002840 else
2841 freq = rx_status->freq;
2842
2843 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2844
2845 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2846 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002847
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002848 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002849 channel);
Alexander Bondar817cee72013-05-19 14:23:57 +03002850 if (bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002851 ieee80211_rx_bss_put(local, bss);
Alexander Bondar817cee72013-05-19 14:23:57 +03002852 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
2853 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002854}
2855
2856
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002857static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002858 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07002859{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002860 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02002861 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002862 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
2863 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002864 struct ieee802_11_elems elems;
2865
Kalle Valo15b7b062009-03-22 21:57:14 +02002866 ifmgd = &sdata->u.mgd;
2867
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002868 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002869
Joe Perchesb203ca32012-05-08 18:56:52 +00002870 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03002871 return; /* ignore ProbeResp to foreign address */
2872
Ester Kummerae6a44e2008-06-27 18:54:48 +03002873 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
2874 if (baselen > len)
2875 return;
2876
2877 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
Johannes Bergb2e506b2013-03-26 14:54:16 +01002878 false, &elems);
Ester Kummerae6a44e2008-06-27 18:54:48 +03002879
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002880 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03002881
Johannes Berg77fdaa12009-07-07 03:45:17 +02002882 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002883 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002884 ieee80211_reset_ap_probe(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002885
2886 if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002887 ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002888 /* got probe response, continue with auth */
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002889 sdata_info(sdata, "direct probe responded\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002890 ifmgd->auth_data->tries = 0;
2891 ifmgd->auth_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01002892 ifmgd->auth_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002893 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01002894 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002895}
2896
Johannes Bergd91f36d2009-04-16 13:17:26 +02002897/*
2898 * This is the canonical list of information elements we care about,
2899 * the filter code also gives us all changes to the Microsoft OUI
2900 * (00:50:F2) vendor IE which is used for WMM which we need to track.
2901 *
2902 * We implement beacon filtering in software since that means we can
2903 * avoid processing the frame here and in cfg80211, and userspace
2904 * will not be able to tell whether the hardware supports it or not.
2905 *
2906 * XXX: This list needs to be dynamic -- userspace needs to be able to
2907 * add items it requires. It also needs to be able to tell us to
2908 * look out for other vendor IEs.
2909 */
2910static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02002911 (1ULL << WLAN_EID_COUNTRY) |
2912 (1ULL << WLAN_EID_ERP_INFO) |
2913 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
2914 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
2915 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg074d46d2012-03-15 19:45:16 +01002916 (1ULL << WLAN_EID_HT_OPERATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02002917
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002918static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2919 struct ieee80211_mgmt *mgmt, size_t len,
2920 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07002921{
Johannes Bergd91f36d2009-04-16 13:17:26 +02002922 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002923 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07002924 size_t baselen;
2925 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002926 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +02002927 struct ieee80211_chanctx_conf *chanctx_conf;
2928 struct ieee80211_channel *chan;
Johannes Bergbee7f582013-02-07 22:24:55 +01002929 struct sta_info *sta;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002930 u32 changed = 0;
Rami Rosenf87ad632012-10-25 10:16:23 +02002931 bool erp_valid;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002932 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02002933 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002934 u8 *bssid;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002935 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002936
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002937 sdata_assert_lock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07002938
Ester Kummerae6a44e2008-06-27 18:54:48 +03002939 /* Process beacon from the current BSS */
2940 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2941 if (baselen > len)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002942 return;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002943
Johannes Berg55de9082012-07-26 17:24:39 +02002944 rcu_read_lock();
2945 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2946 if (!chanctx_conf) {
2947 rcu_read_unlock();
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002948 return;
Johannes Berg55de9082012-07-26 17:24:39 +02002949 }
2950
Johannes Berg4bf88532012-11-09 11:39:59 +01002951 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
Johannes Berg55de9082012-07-26 17:24:39 +02002952 rcu_read_unlock();
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002953 return;
Johannes Berg55de9082012-07-26 17:24:39 +02002954 }
Johannes Berg4bf88532012-11-09 11:39:59 +01002955 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +02002956 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002957
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002958 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002959 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002960 ieee802_11_parse_elems(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01002961 len - baselen, false, &elems);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002962
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002963 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Alexander Bondar482a9c72013-06-03 17:29:33 +03002964 if (elems.tim && !elems.parse_error) {
2965 const struct ieee80211_tim_ie *tim_ie = elems.tim;
2966 ifmgd->dtim_period = tim_ie->dtim_period;
2967 }
Alexander Bondar989c6502013-05-16 17:34:17 +03002968 ifmgd->have_beacon = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002969 ifmgd->assoc_data->need_beacon = false;
Johannes Bergef429da2013-02-05 17:48:40 +01002970 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
2971 sdata->vif.bss_conf.sync_tsf =
2972 le64_to_cpu(mgmt->u.beacon.timestamp);
2973 sdata->vif.bss_conf.sync_device_ts =
2974 rx_status->device_timestamp;
2975 if (elems.tim)
2976 sdata->vif.bss_conf.sync_dtim_count =
2977 elems.tim->dtim_count;
2978 else
2979 sdata->vif.bss_conf.sync_dtim_count = 0;
2980 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002981 /* continue assoc process */
2982 ifmgd->assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01002983 ifmgd->assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002984 run_again(sdata, ifmgd->assoc_data->timeout);
2985 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002986 }
2987
2988 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002989 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002990 return;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002991 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002992
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002993 /* Track average RSSI from the Beacon frames of the current AP */
2994 ifmgd->last_beacon_signal = rx_status->signal;
2995 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
2996 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03002997 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002998 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03002999 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003000 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003001 } else {
3002 ifmgd->ave_beacon_signal =
3003 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
3004 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
3005 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03003006 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003007 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003008
3009 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3010 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3011 int sig = ifmgd->ave_beacon_signal;
3012 int last_sig = ifmgd->last_ave_beacon_signal;
3013
3014 /*
3015 * if signal crosses either of the boundaries, invoke callback
3016 * with appropriate parameters
3017 */
3018 if (sig > ifmgd->rssi_max_thold &&
3019 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3020 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbach887da912013-01-20 17:32:41 +02003021 drv_rssi_callback(local, sdata, RSSI_EVENT_HIGH);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003022 } else if (sig < ifmgd->rssi_min_thold &&
3023 (last_sig >= ifmgd->rssi_max_thold ||
3024 last_sig == 0)) {
3025 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbach887da912013-01-20 17:32:41 +02003026 drv_rssi_callback(local, sdata, RSSI_EVENT_LOW);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07003027 }
3028 }
3029
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003030 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03003031 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01003032 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Jouni Malinen17e4ec12010-03-29 23:28:30 -07003033 int sig = ifmgd->ave_beacon_signal / 16;
3034 int last_event = ifmgd->last_cqm_event_signal;
3035 int thold = bss_conf->cqm_rssi_thold;
3036 int hyst = bss_conf->cqm_rssi_hyst;
3037 if (sig < thold &&
3038 (last_event == 0 || sig < last_event - hyst)) {
3039 ifmgd->last_cqm_event_signal = sig;
3040 ieee80211_cqm_rssi_notify(
3041 &sdata->vif,
3042 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3043 GFP_KERNEL);
3044 } else if (sig > thold &&
3045 (last_event == 0 || sig > last_event + hyst)) {
3046 ifmgd->last_cqm_event_signal = sig;
3047 ieee80211_cqm_rssi_notify(
3048 &sdata->vif,
3049 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3050 GFP_KERNEL);
3051 }
3052 }
3053
Johannes Bergb291ba12009-07-10 15:29:03 +02003054 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003055 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01003056 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003057 mutex_lock(&local->mtx);
Johannes Bergb291ba12009-07-10 15:29:03 +02003058 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003059 ieee80211_run_deferred_scan(local);
3060 mutex_unlock(&local->mtx);
3061
Johannes Berg4e751842009-06-10 15:16:52 +02003062 mutex_lock(&local->iflist_mtx);
3063 ieee80211_recalc_ps(local, -1);
3064 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03003065 }
3066
Johannes Bergb291ba12009-07-10 15:29:03 +02003067 /*
3068 * Push the beacon loss detection into the future since
3069 * we are processing a beacon from the AP just now.
3070 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003071 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003072
Johannes Bergd91f36d2009-04-16 13:17:26 +02003073 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3074 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003075 len - baselen, false, &elems,
Johannes Bergd91f36d2009-04-16 13:17:26 +02003076 care_about_ies, ncrc);
3077
Vivek Natarajan25c9c872009-03-02 20:20:30 +05303078 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Rami Rosenf87ad632012-10-25 10:16:23 +02003079 bool directed_tim = ieee80211_check_tim(elems.tim,
3080 elems.tim_len,
3081 ifmgd->aid);
Kalle Valo1fb36062009-02-10 17:09:24 +02003082 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02003083 if (local->hw.conf.dynamic_ps_timeout > 0) {
Ronald Wahl70b12f22012-03-19 14:37:20 +01003084 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3085 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3086 ieee80211_hw_config(local,
3087 IEEE80211_CONF_CHANGE_PS);
3088 }
Kalle Valo572e0012009-02-10 17:09:31 +02003089 ieee80211_send_nullfunc(local, sdata, 0);
Rajkumar Manoharan6f0756a2012-03-15 05:50:36 +05303090 } else if (!local->pspolling && sdata->u.mgd.powersave) {
Kalle Valo572e0012009-02-10 17:09:31 +02003091 local->pspolling = true;
3092
3093 /*
3094 * Here is assumed that the driver will be
3095 * able to send ps-poll frame and receive a
3096 * response even though power save mode is
3097 * enabled, but some drivers might require
3098 * to disable power save here. This needs
3099 * to be investigated.
3100 */
3101 ieee80211_send_pspoll(local, sdata);
3102 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003103 }
3104 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003105
Johannes Berg488dd7b2012-10-29 20:08:01 +01003106 if (sdata->vif.p2p) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003107 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003108 int ret;
3109
3110 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3111 len - baselen,
3112 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003113 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003114 if (ret >= 2) {
3115 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3116 /* valid noa_attr and index changed */
3117 sdata->u.mgd.p2p_noa_index = noa.index;
3118 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3119 changed |= BSS_CHANGED_P2P_PS;
3120 /*
3121 * make sure we update all information, the CRC
3122 * mechanism doesn't look at P2P attributes.
3123 */
3124 ifmgd->beacon_crc_valid = false;
3125 }
3126 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3127 /* noa_attr not found and we had valid noa_attr before */
3128 sdata->u.mgd.p2p_noa_index = -1;
3129 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003130 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003131 ifmgd->beacon_crc_valid = false;
3132 }
3133 }
3134
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003135 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003136 return;
Jouni Malinen30196672009-05-19 17:01:43 +03003137 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003138 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03003139
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003140 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg7d257452012-07-06 17:37:43 +02003141
Johannes Bergd70b7612013-08-23 15:48:48 +02003142 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
3143 &elems, true);
3144
Johannes Berg7d257452012-07-06 17:37:43 +02003145 if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3146 elems.wmm_param_len))
3147 changed |= BSS_CHANGED_QOS;
3148
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003149 /*
3150 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01003151 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003152 */
Alexander Bondar989c6502013-05-16 17:34:17 +03003153 if (!ifmgd->have_beacon) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003154 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3155 if (elems.tim)
3156 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3157 else
3158 bss_conf->dtim_period = 1;
Johannes Bergef429da2013-02-05 17:48:40 +01003159
3160 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
3161 sdata->vif.bss_conf.sync_tsf =
3162 le64_to_cpu(mgmt->u.beacon.timestamp);
3163 sdata->vif.bss_conf.sync_device_ts =
3164 rx_status->device_timestamp;
3165 if (elems.tim)
3166 sdata->vif.bss_conf.sync_dtim_count =
3167 elems.tim->dtim_count;
3168 else
3169 sdata->vif.bss_conf.sync_dtim_count = 0;
3170 }
3171
Alexander Bondar989c6502013-05-16 17:34:17 +03003172 changed |= BSS_CHANGED_BEACON_INFO;
3173 ifmgd->have_beacon = true;
Alexander Bondar482a9c72013-06-03 17:29:33 +03003174
3175 mutex_lock(&local->iflist_mtx);
3176 ieee80211_recalc_ps(local, -1);
3177 mutex_unlock(&local->iflist_mtx);
3178
Alexander Bondarce857882013-05-06 17:17:04 +03003179 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003180 }
3181
Johannes Berg1946bed2013-03-27 14:31:53 +01003182 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02003183 erp_valid = true;
3184 erp_value = elems.erp_info[0];
3185 } else {
3186 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04003187 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003188 changed |= ieee80211_handle_bss_capability(sdata,
3189 le16_to_cpu(mgmt->u.beacon.capab_info),
3190 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07003191
Johannes Berg11289582013-02-07 17:36:12 +01003192 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f582013-02-07 22:24:55 +01003193 sta = sta_info_get(sdata, bssid);
3194
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003195 if (ieee80211_config_bw(sdata, sta, elems.ht_operation,
3196 elems.vht_operation, bssid, &changed)) {
3197 mutex_unlock(&local->sta_mtx);
3198 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3199 WLAN_REASON_DEAUTH_LEAVING,
3200 true, deauth_buf);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02003201 cfg80211_tx_mlme_mgmt(sdata->dev, deauth_buf,
3202 sizeof(deauth_buf));
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003203 return;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003204 }
Johannes Bergbee7f582013-02-07 22:24:55 +01003205
3206 if (sta && elems.opmode_notif)
3207 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
3208 rx_status->band, true);
Johannes Berg11289582013-02-07 17:36:12 +01003209 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003210
Johannes Berg04b7b2f2012-09-05 13:41:37 +02003211 if (elems.country_elem && elems.pwr_constr_elem &&
3212 mgmt->u.probe_resp.capab_info &
3213 cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02003214 changed |= ieee80211_handle_pwr_constr(sdata, chan,
3215 elems.country_elem,
3216 elems.country_elem_len,
3217 elems.pwr_constr_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08003218
Johannes Berg471b3ef2007-12-28 14:32:58 +01003219 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003220}
3221
Johannes Berg1fa57d02010-06-10 10:21:32 +02003222void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3223 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003224{
3225 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07003226 struct ieee80211_mgmt *mgmt;
3227 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003228 struct ieee802_11_elems elems;
3229 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07003230
Jiri Bencf0706e82007-05-05 11:45:53 -07003231 rx_status = (struct ieee80211_rx_status *) skb->cb;
3232 mgmt = (struct ieee80211_mgmt *) skb->data;
3233 fc = le16_to_cpu(mgmt->frame_control);
3234
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003235 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003236
Johannes Berg66e67e42012-01-20 13:55:27 +01003237 switch (fc & IEEE80211_FCTL_STYPE) {
3238 case IEEE80211_STYPE_BEACON:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003239 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01003240 break;
3241 case IEEE80211_STYPE_PROBE_RESP:
3242 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3243 break;
3244 case IEEE80211_STYPE_AUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003245 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003246 break;
3247 case IEEE80211_STYPE_DEAUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003248 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003249 break;
3250 case IEEE80211_STYPE_DISASSOC:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003251 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003252 break;
3253 case IEEE80211_STYPE_ASSOC_RESP:
3254 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003255 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003256 break;
3257 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01003258 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003259 ies_len = skb->len -
3260 offsetof(struct ieee80211_mgmt,
3261 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01003262
3263 if (ies_len < 0)
3264 break;
3265
3266 ieee802_11_parse_elems(
3267 mgmt->u.action.u.chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003268 ies_len, true, &elems);
Johannes Berg37799e52013-03-26 14:02:26 +01003269
3270 if (elems.parse_error)
3271 break;
3272
Johannes Berg66e67e42012-01-20 13:55:27 +01003273 ieee80211_sta_process_chanswitch(sdata,
Johannes Berg37799e52013-03-26 14:02:26 +01003274 rx_status->mactime,
Johannes Berg04a161f2013-05-03 09:35:35 +02003275 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003276 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3277 ies_len = skb->len -
3278 offsetof(struct ieee80211_mgmt,
3279 u.action.u.ext_chan_switch.variable);
3280
3281 if (ies_len < 0)
3282 break;
3283
3284 ieee802_11_parse_elems(
3285 mgmt->u.action.u.ext_chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003286 ies_len, true, &elems);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003287
3288 if (elems.parse_error)
3289 break;
3290
3291 /* for the handling code pretend this was also an IE */
3292 elems.ext_chansw_ie =
3293 &mgmt->u.action.u.ext_chan_switch.data;
3294
3295 ieee80211_sta_process_chanswitch(sdata,
3296 rx_status->mactime,
Johannes Berg04a161f2013-05-03 09:35:35 +02003297 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003298 }
Johannes Berg37799e52013-03-26 14:02:26 +01003299 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003300 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003301 sdata_unlock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003302}
3303
Johannes Berg9c6bd792008-09-11 00:01:52 +02003304static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07003305{
3306 struct ieee80211_sub_if_data *sdata =
3307 (struct ieee80211_sub_if_data *) data;
Jiri Bencf0706e82007-05-05 11:45:53 -07003308
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01003309 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07003310}
3311
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003312static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01003313 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003314{
Antonio Quartulli6ae16772012-09-07 13:28:52 +02003315 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003316
Johannes Berg37ad3882012-02-24 13:50:54 +01003317 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01003318 tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01003319
Johannes Berg6ff57cf2013-05-16 00:55:00 +02003320 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
3321 IEEE80211_DEAUTH_FRAME_LEN);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003322}
3323
Johannes Berg66e67e42012-01-20 13:55:27 +01003324static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
3325{
3326 struct ieee80211_local *local = sdata->local;
3327 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3328 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e2013-01-29 15:02:27 +01003329 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01003330
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003331 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003332
3333 if (WARN_ON_ONCE(!auth_data))
3334 return -EINVAL;
3335
Johannes Berg66e67e42012-01-20 13:55:27 +01003336 auth_data->tries++;
3337
3338 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003339 sdata_info(sdata, "authentication with %pM timed out\n",
3340 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003341
3342 /*
3343 * Most likely AP is not in the range so remove the
3344 * bss struct for that AP.
3345 */
3346 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
3347
3348 return -ETIMEDOUT;
3349 }
3350
Johannes Berga1845fc2012-06-27 13:18:36 +02003351 drv_mgd_prepare_tx(local, sdata);
3352
Johannes Berg66e67e42012-01-20 13:55:27 +01003353 if (auth_data->bss->proberesp_ies) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003354 u16 trans = 1;
3355 u16 status = 0;
3356
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003357 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
3358 auth_data->bss->bssid, auth_data->tries,
3359 IEEE80211_AUTH_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01003360
3361 auth_data->expected_transaction = 2;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003362
3363 if (auth_data->algorithm == WLAN_AUTH_SAE) {
3364 trans = auth_data->sae_trans;
3365 status = auth_data->sae_status;
3366 auth_data->expected_transaction = trans;
3367 }
3368
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02003369 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
3370 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3371 IEEE80211_TX_INTFL_MLME_CONN_TX;
3372
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003373 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
3374 auth_data->data, auth_data->data_len,
Johannes Berg66e67e42012-01-20 13:55:27 +01003375 auth_data->bss->bssid,
Johannes Berg1672c0e2013-01-29 15:02:27 +01003376 auth_data->bss->bssid, NULL, 0, 0,
3377 tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01003378 } else {
3379 const u8 *ssidie;
3380
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003381 sdata_info(sdata, "direct probe to %pM (try %d/%i)\n",
3382 auth_data->bss->bssid, auth_data->tries,
3383 IEEE80211_AUTH_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01003384
Johannes Berg9caf0362012-11-29 01:25:20 +01003385 rcu_read_lock();
Johannes Berg66e67e42012-01-20 13:55:27 +01003386 ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
Johannes Berg9caf0362012-11-29 01:25:20 +01003387 if (!ssidie) {
3388 rcu_read_unlock();
Johannes Berg66e67e42012-01-20 13:55:27 +01003389 return -EINVAL;
Johannes Berg9caf0362012-11-29 01:25:20 +01003390 }
Johannes Berg66e67e42012-01-20 13:55:27 +01003391 /*
3392 * Direct probe is sent to broadcast address as some APs
3393 * will not answer to direct packet in unassociated state.
3394 */
3395 ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02003396 NULL, 0, (u32) -1, true, 0,
Johannes Berg55de9082012-07-26 17:24:39 +02003397 auth_data->bss->channel, false);
Johannes Berg9caf0362012-11-29 01:25:20 +01003398 rcu_read_unlock();
Johannes Berg66e67e42012-01-20 13:55:27 +01003399 }
3400
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02003401 if (tx_flags == 0) {
Johannes Berg1672c0e2013-01-29 15:02:27 +01003402 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Bergcb236d22013-07-29 23:07:43 +02003403 auth_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003404 run_again(sdata, auth_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01003405 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02003406 auth_data->timeout =
3407 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
3408 auth_data->timeout_started = true;
3409 run_again(sdata, auth_data->timeout);
Johannes Berg1672c0e2013-01-29 15:02:27 +01003410 }
Johannes Berg66e67e42012-01-20 13:55:27 +01003411
3412 return 0;
3413}
3414
3415static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
3416{
3417 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3418 struct ieee80211_local *local = sdata->local;
3419
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003420 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003421
Johannes Berg66e67e42012-01-20 13:55:27 +01003422 assoc_data->tries++;
3423 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003424 sdata_info(sdata, "association with %pM timed out\n",
3425 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003426
3427 /*
3428 * Most likely AP is not in the range so remove the
3429 * bss struct for that AP.
3430 */
3431 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
3432
3433 return -ETIMEDOUT;
3434 }
3435
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003436 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
3437 assoc_data->bss->bssid, assoc_data->tries,
3438 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01003439 ieee80211_send_assoc(sdata);
3440
Johannes Berg1672c0e2013-01-29 15:02:27 +01003441 if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
3442 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01003443 assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003444 run_again(sdata, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01003445 } else {
Johannes Bergcb236d22013-07-29 23:07:43 +02003446 assoc_data->timeout =
3447 round_jiffies_up(jiffies +
3448 IEEE80211_ASSOC_TIMEOUT_LONG);
3449 assoc_data->timeout_started = true;
3450 run_again(sdata, assoc_data->timeout);
Johannes Berg1672c0e2013-01-29 15:02:27 +01003451 }
Johannes Berg66e67e42012-01-20 13:55:27 +01003452
3453 return 0;
3454}
3455
Johannes Berg1672c0e2013-01-29 15:02:27 +01003456void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
3457 __le16 fc, bool acked)
3458{
3459 struct ieee80211_local *local = sdata->local;
3460
3461 sdata->u.mgd.status_fc = fc;
3462 sdata->u.mgd.status_acked = acked;
3463 sdata->u.mgd.status_received = true;
3464
3465 ieee80211_queue_work(&local->hw, &sdata->work);
3466}
3467
Johannes Berg1fa57d02010-06-10 10:21:32 +02003468void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02003469{
Johannes Berg60f8b392008-09-08 17:44:22 +02003470 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02003471 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02003472
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003473 sdata_lock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02003474
Johannes Berg1672c0e2013-01-29 15:02:27 +01003475 if (ifmgd->status_received) {
3476 __le16 fc = ifmgd->status_fc;
3477 bool status_acked = ifmgd->status_acked;
3478
3479 ifmgd->status_received = false;
3480 if (ifmgd->auth_data &&
3481 (ieee80211_is_probe_req(fc) || ieee80211_is_auth(fc))) {
3482 if (status_acked) {
3483 ifmgd->auth_data->timeout =
3484 jiffies + IEEE80211_AUTH_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003485 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg1672c0e2013-01-29 15:02:27 +01003486 } else {
3487 ifmgd->auth_data->timeout = jiffies - 1;
3488 }
Johannes Berg89afe612013-02-13 15:39:57 +01003489 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e2013-01-29 15:02:27 +01003490 } else if (ifmgd->assoc_data &&
3491 (ieee80211_is_assoc_req(fc) ||
3492 ieee80211_is_reassoc_req(fc))) {
3493 if (status_acked) {
3494 ifmgd->assoc_data->timeout =
3495 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003496 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg1672c0e2013-01-29 15:02:27 +01003497 } else {
3498 ifmgd->assoc_data->timeout = jiffies - 1;
3499 }
Johannes Berg89afe612013-02-13 15:39:57 +01003500 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e2013-01-29 15:02:27 +01003501 }
3502 }
3503
Johannes Berg89afe612013-02-13 15:39:57 +01003504 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01003505 time_after(jiffies, ifmgd->auth_data->timeout)) {
3506 if (ifmgd->auth_data->done) {
3507 /*
3508 * ok ... we waited for assoc but userspace didn't,
3509 * so let's just kill the auth data
3510 */
3511 ieee80211_destroy_auth_data(sdata, false);
3512 } else if (ieee80211_probe_auth(sdata)) {
3513 u8 bssid[ETH_ALEN];
3514
3515 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
3516
3517 ieee80211_destroy_auth_data(sdata, false);
3518
Johannes Berg6ff57cf2013-05-16 00:55:00 +02003519 cfg80211_auth_timeout(sdata->dev, bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003520 }
Johannes Berg89afe612013-02-13 15:39:57 +01003521 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003522 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01003523
Johannes Berg89afe612013-02-13 15:39:57 +01003524 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01003525 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Alexander Bondar989c6502013-05-16 17:34:17 +03003526 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01003527 ieee80211_do_assoc(sdata)) {
Johannes Berg959867f2013-06-19 13:05:42 +02003528 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01003529
3530 ieee80211_destroy_assoc_data(sdata, false);
Johannes Berg959867f2013-06-19 13:05:42 +02003531 cfg80211_assoc_timeout(sdata->dev, bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01003532 }
Johannes Berg89afe612013-02-13 15:39:57 +01003533 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003534 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01003535
Johannes Bergb291ba12009-07-10 15:29:03 +02003536 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
3537 IEEE80211_STA_CONNECTION_POLL) &&
3538 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03003539 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003540 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03003541
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003542 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003543
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003544 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Ben Greear180205b2011-02-04 15:30:24 -08003545 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003546 else
Ben Greear180205b2011-02-04 15:30:24 -08003547 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003548
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003549 /* ACK received for nullfunc probing frame */
3550 if (!ifmgd->probe_send_count)
3551 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003552 else if (ifmgd->nullfunc_failed) {
3553 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003554 mlme_dbg(sdata,
3555 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
3556 bssid, ifmgd->probe_send_count,
3557 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003558 ieee80211_mgd_probe_ap_send(sdata);
3559 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003560 mlme_dbg(sdata,
3561 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
3562 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02003563 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003564 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3565 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003566 }
3567 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003568 run_again(sdata, ifmgd->probe_timeout);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003569 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003570 mlme_dbg(sdata,
3571 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
3572 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02003573 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003574 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003575 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003576 mlme_dbg(sdata,
3577 "No probe response from AP %pM after %dms, try %d/%i\n",
3578 bssid, probe_wait_ms,
3579 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03003580 ieee80211_mgd_probe_ap_send(sdata);
3581 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02003582 /*
3583 * We actually lost the connection ... or did we?
3584 * Let's make sure!
3585 */
Ben Greearb38afa82010-10-07 16:12:06 -07003586 wiphy_debug(local->hw.wiphy,
3587 "%s: No probe response from AP %pM"
3588 " after %dms, disconnecting.\n",
3589 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08003590 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003591
Johannes Berg95acac62011-07-12 12:30:59 +02003592 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003593 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02003594 }
3595 }
3596
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003597 sdata_unlock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02003598}
Johannes Berg0a51b272008-09-08 17:44:25 +02003599
Johannes Bergb291ba12009-07-10 15:29:03 +02003600static void ieee80211_sta_bcn_mon_timer(unsigned long data)
3601{
3602 struct ieee80211_sub_if_data *sdata =
3603 (struct ieee80211_sub_if_data *) data;
3604 struct ieee80211_local *local = sdata->local;
3605
3606 if (local->quiescing)
3607 return;
3608
Johannes Berg682bd382013-01-29 13:13:50 +01003609 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003610 ieee80211_queue_work(&sdata->local->hw,
3611 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003612}
3613
3614static void ieee80211_sta_conn_mon_timer(unsigned long data)
3615{
3616 struct ieee80211_sub_if_data *sdata =
3617 (struct ieee80211_sub_if_data *) data;
3618 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3619 struct ieee80211_local *local = sdata->local;
3620
3621 if (local->quiescing)
3622 return;
3623
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04003624 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003625}
3626
3627static void ieee80211_sta_monitor_work(struct work_struct *work)
3628{
3629 struct ieee80211_sub_if_data *sdata =
3630 container_of(work, struct ieee80211_sub_if_data,
3631 u.mgd.monitor_work);
3632
3633 ieee80211_mgd_probe_ap(sdata, false);
3634}
3635
Johannes Berga1678f82008-09-11 00:01:47 +02003636static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3637{
Eliad Peller494f1fe2012-02-19 15:26:09 +02003638 u32 flags;
3639
Kalle Vaload935682009-04-19 08:47:19 +03003640 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003641 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03003642
Johannes Bergb291ba12009-07-10 15:29:03 +02003643 /* let's probe the connection once */
Eliad Peller494f1fe2012-02-19 15:26:09 +02003644 flags = sdata->local->hw.flags;
3645 if (!(flags & IEEE80211_HW_CONNECTION_MONITOR))
3646 ieee80211_queue_work(&sdata->local->hw,
3647 &sdata->u.mgd.monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003648 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02003649 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03003650 }
Johannes Berga1678f82008-09-11 00:01:47 +02003651}
3652
Johannes Bergb8360ab2013-04-29 14:57:44 +02003653#ifdef CONFIG_PM
3654void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
3655{
3656 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3657
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003658 sdata_lock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02003659 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003660 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02003661 return;
3662 }
3663
3664 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
3665 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
3666 mlme_dbg(sdata, "driver requested disconnect after resume\n");
3667 ieee80211_sta_connection_lost(sdata,
3668 ifmgd->associated->bssid,
3669 WLAN_REASON_UNSPECIFIED,
3670 true);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003671 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02003672 return;
3673 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003674 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02003675}
3676#endif
3677
Johannes Berg9c6bd792008-09-11 00:01:52 +02003678/* interface setup */
3679void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
3680{
Johannes Berg46900292009-02-15 12:44:28 +01003681 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003682
Johannes Berg46900292009-02-15 12:44:28 +01003683 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02003684 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01003685 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003686 INIT_WORK(&ifmgd->beacon_connection_loss_work,
3687 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02003688 INIT_WORK(&ifmgd->csa_connection_drop_work,
3689 ieee80211_csa_connection_drop_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02003690 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01003691 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02003692 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003693 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
3694 (unsigned long) sdata);
3695 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
3696 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01003697 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05303698 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02003699
Johannes Bergab1faea2009-07-01 21:41:17 +02003700 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05303701 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02003702 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
3703 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003704 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02003705
Johannes Berg0f782312009-12-01 13:37:02 +01003706 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
3707 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
3708 else
3709 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003710}
3711
3712/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02003713void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
3714{
Johannes Berg31ee67a2012-07-06 21:18:24 +02003715 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02003716
3717 /* Restart STA timers */
3718 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07003719 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3720 if (ieee80211_sdata_running(sdata))
3721 ieee80211_restart_sta_timer(sdata);
3722 }
Johannes Berga1678f82008-09-11 00:01:47 +02003723 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02003724}
Johannes Berg10f644a2009-04-16 13:17:25 +02003725
3726int ieee80211_max_network_latency(struct notifier_block *nb,
3727 unsigned long data, void *dummy)
3728{
3729 s32 latency_usec = (s32) data;
3730 struct ieee80211_local *local =
3731 container_of(nb, struct ieee80211_local,
3732 network_latency_notifier);
3733
3734 mutex_lock(&local->iflist_mtx);
3735 ieee80211_recalc_ps(local, latency_usec);
3736 mutex_unlock(&local->iflist_mtx);
3737
3738 return 0;
3739}
Johannes Berg77fdaa12009-07-07 03:45:17 +02003740
Johannes Bergf2d9d272012-11-22 14:11:39 +01003741static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
3742 struct cfg80211_bss *cbss)
3743{
3744 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3745 const u8 *ht_cap_ie, *vht_cap_ie;
3746 const struct ieee80211_ht_cap *ht_cap;
3747 const struct ieee80211_vht_cap *vht_cap;
3748 u8 chains = 1;
3749
3750 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
3751 return chains;
3752
Johannes Berg9caf0362012-11-29 01:25:20 +01003753 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003754 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
3755 ht_cap = (void *)(ht_cap_ie + 2);
3756 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
3757 /*
3758 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
3759 * "Tx Unequal Modulation Supported" fields.
3760 */
3761 }
3762
3763 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
3764 return chains;
3765
Johannes Berg9caf0362012-11-29 01:25:20 +01003766 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003767 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
3768 u8 nss;
3769 u16 tx_mcs_map;
3770
3771 vht_cap = (void *)(vht_cap_ie + 2);
3772 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
3773 for (nss = 8; nss > 0; nss--) {
3774 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
3775 IEEE80211_VHT_MCS_NOT_SUPPORTED)
3776 break;
3777 }
3778 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
3779 chains = max(chains, nss);
3780 }
3781
3782 return chains;
3783}
3784
Johannes Bergb17166a2012-07-27 11:41:27 +02003785static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
3786 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01003787{
3788 struct ieee80211_local *local = sdata->local;
3789 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg24398e32012-03-28 10:58:36 +02003790 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003791 const struct ieee80211_vht_operation *vht_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02003792 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01003793 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003794 int ret;
Johannes Berga1cf7752012-03-08 15:02:07 +01003795
Johannes Berg24398e32012-03-28 10:58:36 +02003796 sband = local->hw.wiphy->bands[cbss->channel->band];
3797
Johannes Bergf2d9d272012-11-22 14:11:39 +01003798 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
3799 IEEE80211_STA_DISABLE_80P80MHZ |
3800 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02003801
Johannes Berg9caf0362012-11-29 01:25:20 +01003802 rcu_read_lock();
3803
Johannes Bergf2d9d272012-11-22 14:11:39 +01003804 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3805 sband->ht_cap.ht_supported) {
Johannes Berg08e6eff2013-02-07 23:33:32 +01003806 const u8 *ht_oper_ie, *ht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003807
Johannes Berg9caf0362012-11-29 01:25:20 +01003808 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02003809 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
3810 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6eff2013-02-07 23:33:32 +01003811
3812 ht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
3813 if (!ht_cap || ht_cap[1] < sizeof(struct ieee80211_ht_cap)) {
3814 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3815 ht_oper = NULL;
3816 }
Johannes Berg24398e32012-03-28 10:58:36 +02003817 }
3818
Johannes Bergf2d9d272012-11-22 14:11:39 +01003819 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3820 sband->vht_cap.vht_supported) {
Johannes Berg08e6eff2013-02-07 23:33:32 +01003821 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003822
Johannes Berg9caf0362012-11-29 01:25:20 +01003823 vht_oper_ie = ieee80211_bss_get_ie(cbss,
3824 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003825 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
3826 vht_oper = (void *)(vht_oper_ie + 2);
3827 if (vht_oper && !ht_oper) {
3828 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003829 sdata_info(sdata,
Johannes Bergf2d9d272012-11-22 14:11:39 +01003830 "AP advertised VHT without HT, disabling both\n");
Johannes Bergcb145022013-02-07 20:41:50 +01003831 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3832 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg24398e32012-03-28 10:58:36 +02003833 }
Johannes Berg08e6eff2013-02-07 23:33:32 +01003834
3835 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
3836 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
3837 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3838 vht_oper = NULL;
3839 }
Johannes Berg24398e32012-03-28 10:58:36 +02003840 }
3841
Johannes Bergf2d9d272012-11-22 14:11:39 +01003842 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
3843 cbss->channel,
3844 ht_oper, vht_oper,
Johannes Berg5cdaed12013-07-31 11:23:06 +02003845 &chandef, false);
Johannes Berg04ecd252012-09-11 14:34:12 +02003846
Johannes Bergf2d9d272012-11-22 14:11:39 +01003847 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
3848 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02003849
Johannes Berg9caf0362012-11-29 01:25:20 +01003850 rcu_read_unlock();
3851
Johannes Berg04ecd252012-09-11 14:34:12 +02003852 /* will change later if needed */
3853 sdata->smps_mode = IEEE80211_SMPS_OFF;
3854
Johannes Bergf2d9d272012-11-22 14:11:39 +01003855 /*
3856 * If this fails (possibly due to channel context sharing
3857 * on incompatible channels, e.g. 80+80 and 160 sharing the
3858 * same control channel) try to use a smaller bandwidth.
3859 */
3860 ret = ieee80211_vif_use_channel(sdata, &chandef,
3861 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich0418a442013-05-16 13:00:31 +02003862
3863 /* don't downgrade for 5 and 10 MHz channels, though. */
3864 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
3865 chandef.width == NL80211_CHAN_WIDTH_10)
3866 return ret;
3867
Johannes Bergd601cd82013-02-07 20:54:51 +01003868 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Johannes Bergf2d9d272012-11-22 14:11:39 +01003869 ifmgd->flags |= chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01003870 ret = ieee80211_vif_use_channel(sdata, &chandef,
3871 IEEE80211_CHANCTX_SHARED);
3872 }
Johannes Bergf2d9d272012-11-22 14:11:39 +01003873 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02003874}
3875
3876static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3877 struct cfg80211_bss *cbss, bool assoc)
3878{
3879 struct ieee80211_local *local = sdata->local;
3880 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3881 struct ieee80211_bss *bss = (void *)cbss->priv;
3882 struct sta_info *new_sta = NULL;
3883 bool have_sta = false;
3884 int err;
3885
3886 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
3887 return -EINVAL;
3888
3889 if (assoc) {
3890 rcu_read_lock();
3891 have_sta = sta_info_get(sdata, cbss->bssid);
3892 rcu_read_unlock();
3893 }
3894
3895 if (!have_sta) {
3896 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
3897 if (!new_sta)
3898 return -ENOMEM;
3899 }
3900
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003901 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003902 u32 rates = 0, basic_rates = 0;
3903 bool have_higher_than_11mbit;
3904 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Bergb17166a2012-07-27 11:41:27 +02003905 struct ieee80211_supported_band *sband;
Johannes Berg8cef2c92013-02-05 16:54:31 +01003906 const struct cfg80211_bss_ies *ies;
Johannes Bergb17166a2012-07-27 11:41:27 +02003907
3908 sband = local->hw.wiphy->bands[cbss->channel->band];
3909
3910 err = ieee80211_prep_channel(sdata, cbss);
3911 if (err) {
3912 sta_info_free(local, new_sta);
3913 return err;
3914 }
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003915
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003916 ieee80211_get_rates(sband, bss->supp_rates,
3917 bss->supp_rates_len,
3918 &rates, &basic_rates,
3919 &have_higher_than_11mbit,
3920 &min_rate, &min_rate_index);
3921
3922 /*
3923 * This used to be a workaround for basic rates missing
3924 * in the association response frame. Now that we no
3925 * longer use the basic rates from there, it probably
3926 * doesn't happen any more, but keep the workaround so
3927 * in case some *other* APs are buggy in different ways
3928 * we can connect -- with a warning.
3929 */
3930 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003931 sdata_info(sdata,
3932 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003933 basic_rates = BIT(min_rate_index);
3934 }
3935
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003936 new_sta->sta.supp_rates[cbss->channel->band] = rates;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003937 sdata->vif.bss_conf.basic_rates = basic_rates;
3938
3939 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg55de9082012-07-26 17:24:39 +02003940 if (cbss->channel->band == IEEE80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003941 have_higher_than_11mbit)
3942 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
3943 else
3944 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
3945
3946 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
3947
Johannes Berg8c358bc2012-05-22 22:13:05 +02003948 /* set timing information */
3949 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01003950 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01003951 ies = rcu_dereference(cbss->beacon_ies);
3952 if (ies) {
3953 const u8 *tim_ie;
3954
3955 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3956 sdata->vif.bss_conf.sync_device_ts =
3957 bss->device_ts_beacon;
3958 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
3959 ies->data, ies->len);
3960 if (tim_ie && tim_ie[1] >= 2)
3961 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
3962 else
3963 sdata->vif.bss_conf.sync_dtim_count = 0;
3964 } else if (!(local->hw.flags &
3965 IEEE80211_HW_TIMING_BEACON_ONLY)) {
3966 ies = rcu_dereference(cbss->proberesp_ies);
3967 /* must be non-NULL since beacon IEs were NULL */
3968 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3969 sdata->vif.bss_conf.sync_device_ts =
3970 bss->device_ts_presp;
3971 sdata->vif.bss_conf.sync_dtim_count = 0;
3972 } else {
3973 sdata->vif.bss_conf.sync_tsf = 0;
3974 sdata->vif.bss_conf.sync_device_ts = 0;
3975 sdata->vif.bss_conf.sync_dtim_count = 0;
3976 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01003977 rcu_read_unlock();
Johannes Berg8c358bc2012-05-22 22:13:05 +02003978
3979 /* tell driver about BSSID, basic rates and timing */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003980 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02003981 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
3982 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01003983
3984 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003985 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01003986
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003987 err = sta_info_insert(new_sta);
3988 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01003989 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003990 sdata_info(sdata,
3991 "failed to insert STA entry for the AP (error %d)\n",
3992 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01003993 return err;
3994 }
3995 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00003996 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01003997
3998 return 0;
3999}
4000
Johannes Berg77fdaa12009-07-07 03:45:17 +02004001/* config hooks */
4002int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
4003 struct cfg80211_auth_request *req)
4004{
Johannes Berg66e67e42012-01-20 13:55:27 +01004005 struct ieee80211_local *local = sdata->local;
4006 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4007 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004008 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01004009 int err;
4010
4011 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02004012
4013 switch (req->auth_type) {
4014 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4015 auth_alg = WLAN_AUTH_OPEN;
4016 break;
4017 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01004018 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02004019 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004020 auth_alg = WLAN_AUTH_SHARED_KEY;
4021 break;
4022 case NL80211_AUTHTYPE_FT:
4023 auth_alg = WLAN_AUTH_FT;
4024 break;
4025 case NL80211_AUTHTYPE_NETWORK_EAP:
4026 auth_alg = WLAN_AUTH_LEAP;
4027 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004028 case NL80211_AUTHTYPE_SAE:
4029 auth_alg = WLAN_AUTH_SAE;
4030 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004031 default:
4032 return -EOPNOTSUPP;
4033 }
4034
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004035 auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len +
4036 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01004037 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004038 return -ENOMEM;
4039
Johannes Berg66e67e42012-01-20 13:55:27 +01004040 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004041
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004042 if (req->sae_data_len >= 4) {
4043 __le16 *pos = (__le16 *) req->sae_data;
4044 auth_data->sae_trans = le16_to_cpu(pos[0]);
4045 auth_data->sae_status = le16_to_cpu(pos[1]);
4046 memcpy(auth_data->data, req->sae_data + 4,
4047 req->sae_data_len - 4);
4048 auth_data->data_len += req->sae_data_len - 4;
4049 }
4050
Johannes Berg77fdaa12009-07-07 03:45:17 +02004051 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004052 memcpy(&auth_data->data[auth_data->data_len],
4053 req->ie, req->ie_len);
4054 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004055 }
4056
Johannes Bergfffd0932009-07-08 14:22:54 +02004057 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004058 auth_data->key_len = req->key_len;
4059 auth_data->key_idx = req->key_idx;
4060 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02004061 }
4062
Johannes Berg66e67e42012-01-20 13:55:27 +01004063 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004064
Johannes Berg66e67e42012-01-20 13:55:27 +01004065 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01004066
Johannes Berg66e67e42012-01-20 13:55:27 +01004067 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
4068 ifmgd->assoc_data) {
4069 err = -EBUSY;
4070 goto err_free;
4071 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004072
Johannes Berg66e67e42012-01-20 13:55:27 +01004073 if (ifmgd->auth_data)
4074 ieee80211_destroy_auth_data(sdata, false);
Guy Eilam2a33bee2011-08-17 15:18:15 +03004075
Johannes Berg66e67e42012-01-20 13:55:27 +01004076 /* prep auth_data so we don't go into idle on disassoc */
4077 ifmgd->auth_data = auth_data;
4078
Johannes Berg7b119dc2013-04-10 21:38:36 +02004079 if (ifmgd->associated) {
4080 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4081
4082 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4083 WLAN_REASON_UNSPECIFIED,
4084 false, frame_buf);
4085
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004086 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4087 sizeof(frame_buf));
Johannes Berg7b119dc2013-04-10 21:38:36 +02004088 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004089
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004090 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004091
Johannes Berga1cf7752012-03-08 15:02:07 +01004092 err = ieee80211_prep_connection(sdata, req->bss, false);
4093 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01004094 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004095
Johannes Berg66e67e42012-01-20 13:55:27 +01004096 err = ieee80211_probe_auth(sdata);
4097 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004098 sta_info_destroy_addr(sdata, req->bss->bssid);
4099 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004100 }
4101
Johannes Berg66e67e42012-01-20 13:55:27 +01004102 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01004103 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004104 return 0;
Johannes Berge5b900d2010-07-29 16:08:55 +02004105
Johannes Berg66e67e42012-01-20 13:55:27 +01004106 err_clear:
Eliad Peller3d2abdf2012-09-04 17:44:45 +03004107 memset(ifmgd->bssid, 0, ETH_ALEN);
4108 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01004109 ifmgd->auth_data = NULL;
4110 err_free:
4111 kfree(auth_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01004112 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004113}
4114
Johannes Berg77fdaa12009-07-07 03:45:17 +02004115int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
4116 struct cfg80211_assoc_request *req)
4117{
Johannes Berg66e67e42012-01-20 13:55:27 +01004118 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004119 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004120 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01004121 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004122 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01004123 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01004124 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004125 int i, err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004126
Johannes Berg66e67e42012-01-20 13:55:27 +01004127 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
4128 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01004129 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004130
Johannes Berg9caf0362012-11-29 01:25:20 +01004131 rcu_read_lock();
4132 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
4133 if (!ssidie) {
4134 rcu_read_unlock();
4135 kfree(assoc_data);
4136 return -EINVAL;
4137 }
4138 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
4139 assoc_data->ssid_len = ssidie[1];
4140 rcu_read_unlock();
4141
Johannes Berg7b119dc2013-04-10 21:38:36 +02004142 if (ifmgd->associated) {
4143 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4144
4145 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4146 WLAN_REASON_UNSPECIFIED,
4147 false, frame_buf);
4148
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004149 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4150 sizeof(frame_buf));
Johannes Berg7b119dc2013-04-10 21:38:36 +02004151 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004152
4153 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
4154 err = -EBUSY;
4155 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004156 }
4157
Johannes Berg66e67e42012-01-20 13:55:27 +01004158 if (ifmgd->assoc_data) {
4159 err = -EBUSY;
4160 goto err_free;
4161 }
4162
4163 if (ifmgd->auth_data) {
4164 bool match;
4165
4166 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00004167 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004168 ieee80211_destroy_auth_data(sdata, match);
4169 }
4170
4171 /* prepare assoc data */
Johannes Berg19c3b832012-08-01 20:13:36 +02004172
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03004173 ifmgd->beacon_crc_valid = false;
4174
Johannes Bergde5036a2012-03-08 15:02:03 +01004175 /*
4176 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
4177 * We still associate in non-HT mode (11a/b/g) if any one of these
4178 * ciphers is configured as pairwise.
4179 * We can set this to true for non-11n hardware, that'll be checked
4180 * separately along with the peer capabilities.
4181 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02004182 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02004183 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
4184 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02004185 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01004186 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004187 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg1c4cb922012-05-30 15:57:00 +02004188 netdev_info(sdata->dev,
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004189 "disabling HT/VHT due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02004190 }
4191 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004192
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004193 if (req->flags & ASSOC_REQ_DISABLE_HT) {
Johannes Berga8243b72012-11-22 14:32:09 +01004194 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004195 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4196 }
Ben Greearef96a8422011-11-18 11:32:00 -08004197
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01004198 if (req->flags & ASSOC_REQ_DISABLE_VHT)
4199 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4200
Johannes Berg4e74bfd2012-03-08 15:02:04 +01004201 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4202 sband = local->hw.wiphy->bands[req->bss->channel->band];
4203 if (!sband->ht_cap.ht_supported ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02004204 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
Johannes Berga8243b72012-11-22 14:32:09 +01004205 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg1b49de22012-07-27 10:29:14 +02004206 if (!bss->wmm_used)
4207 netdev_info(sdata->dev,
4208 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02004209 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01004210
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004211 /* disable VHT if we don't support it or the AP doesn't use WMM */
4212 if (!sband->vht_cap.vht_supported ||
4213 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
4214 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg1b49de22012-07-27 10:29:14 +02004215 if (!bss->wmm_used)
4216 netdev_info(sdata->dev,
4217 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004218 }
4219
Ben Greearef96a8422011-11-18 11:32:00 -08004220 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
4221 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
4222 sizeof(ifmgd->ht_capa_mask));
4223
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01004224 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
4225 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
4226 sizeof(ifmgd->vht_capa_mask));
4227
Johannes Berg77fdaa12009-07-07 03:45:17 +02004228 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004229 memcpy(assoc_data->ie, req->ie, req->ie_len);
4230 assoc_data->ie_len = req->ie_len;
4231 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004232
Johannes Berg66e67e42012-01-20 13:55:27 +01004233 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01004234
Johannes Bergaf6b6372009-12-23 13:15:35 +01004235 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
4236 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02004237 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004238 else
Johannes Berg04ecd252012-09-11 14:34:12 +02004239 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004240 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02004241 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004242
Johannes Berg66e67e42012-01-20 13:55:27 +01004243 assoc_data->capability = req->bss->capability;
Johannes Berg32c5057b2012-03-28 11:04:29 +02004244 assoc_data->wmm = bss->wmm_used &&
4245 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg66e67e42012-01-20 13:55:27 +01004246 assoc_data->supp_rates = bss->supp_rates;
4247 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02004248
Johannes Berg9caf0362012-11-29 01:25:20 +01004249 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02004250 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
4251 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
4252 assoc_data->ap_ht_param =
4253 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
4254 else
Johannes Berga8243b72012-11-22 14:32:09 +01004255 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01004256 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
4257 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
4258 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
4259 sizeof(struct ieee80211_vht_cap));
4260 else
4261 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01004262 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01004263
Kalle Valoab133152010-01-12 10:42:31 +02004264 if (bss->wmm_used && bss->uapsd_supported &&
Alexander Bondar24aa11a2013-04-02 15:30:14 +03004265 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) &&
4266 sdata->wmm_acm != 0xff) {
Johannes Berg76f03032012-03-08 15:02:05 +01004267 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02004268 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
4269 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01004270 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02004271 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
4272 }
4273
Johannes Berg77fdaa12009-07-07 03:45:17 +02004274 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01004275 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004276
4277 if (req->use_mfp) {
4278 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
4279 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
4280 } else {
4281 ifmgd->mfp = IEEE80211_MFP_DISABLED;
4282 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
4283 }
4284
4285 if (req->crypto.control_port)
4286 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
4287 else
4288 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
4289
Johannes Berga621fa42010-08-27 14:26:54 +03004290 sdata->control_port_protocol = req->crypto.control_port_ethertype;
4291 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
4292
Johannes Berg66e67e42012-01-20 13:55:27 +01004293 /* kick off associate process */
4294
4295 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02004296 ifmgd->dtim_period = 0;
Alexander Bondar989c6502013-05-16 17:34:17 +03004297 ifmgd->have_beacon = false;
Johannes Berg66e67e42012-01-20 13:55:27 +01004298
Johannes Berga1cf7752012-03-08 15:02:07 +01004299 err = ieee80211_prep_connection(sdata, req->bss, true);
4300 if (err)
4301 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01004302
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004303 rcu_read_lock();
4304 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02004305
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004306 if (sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC &&
4307 !beacon_ies) {
4308 /*
4309 * Wait up to one beacon interval ...
4310 * should this be more if we miss one?
4311 */
4312 sdata_info(sdata, "waiting for beacon from %pM\n",
4313 ifmgd->bssid);
4314 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01004315 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004316 assoc_data->need_beacon = true;
4317 } else if (beacon_ies) {
4318 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4319 beacon_ies->data,
4320 beacon_ies->len);
Johannes Bergef429da2013-02-05 17:48:40 +01004321 u8 dtim_count = 0;
4322
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004323 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
4324 const struct ieee80211_tim_ie *tim;
4325 tim = (void *)(tim_ie + 2);
4326 ifmgd->dtim_period = tim->dtim_period;
Johannes Bergef429da2013-02-05 17:48:40 +01004327 dtim_count = tim->dtim_count;
Johannes Berg826262c2012-12-10 16:38:14 +02004328 }
Alexander Bondar989c6502013-05-16 17:34:17 +03004329 ifmgd->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01004330 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01004331 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01004332
4333 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
4334 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
4335 sdata->vif.bss_conf.sync_device_ts =
4336 bss->device_ts_beacon;
4337 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
4338 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004339 } else {
4340 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01004341 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01004342 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004343 rcu_read_unlock();
4344
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004345 run_again(sdata, assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004346
Paul Stewartfcff4f12012-02-23 17:59:53 -08004347 if (bss->corrupt_data) {
4348 char *corrupt_type = "data";
4349 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
4350 if (bss->corrupt_data &
4351 IEEE80211_BSS_CORRUPT_PROBE_RESP)
4352 corrupt_type = "beacon and probe response";
4353 else
4354 corrupt_type = "beacon";
4355 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
4356 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004357 sdata_info(sdata, "associating with AP with corrupt %s\n",
4358 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08004359 }
4360
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004361 return 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004362 err_clear:
Eliad Peller3d2abdf2012-09-04 17:44:45 +03004363 memset(ifmgd->bssid, 0, ETH_ALEN);
4364 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01004365 ifmgd->assoc_data = NULL;
4366 err_free:
4367 kfree(assoc_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01004368 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004369}
4370
4371int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01004372 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004373{
4374 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004375 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02004376 bool tx = !req->local_state_change;
Johannes Bergde3d43a2013-05-14 09:39:02 +02004377 bool report_frame = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004378
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004379 sdata_info(sdata,
4380 "deauthenticating from %pM by local choice (reason=%d)\n",
4381 req->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02004382
Johannes Berg86552012012-10-29 09:46:31 +01004383 if (ifmgd->auth_data) {
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03004384 drv_mgd_prepare_tx(sdata->local, sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01004385 ieee80211_send_deauth_disassoc(sdata, req->bssid,
4386 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02004387 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01004388 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01004389 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg86552012012-10-29 09:46:31 +01004390
Johannes Bergde3d43a2013-05-14 09:39:02 +02004391 report_frame = true;
Johannes Berg86552012012-10-29 09:46:31 +01004392 goto out;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03004393 }
4394
Johannes Berg86552012012-10-29 09:46:31 +01004395 if (ifmgd->associated &&
4396 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
4397 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4398 req->reason_code, tx, frame_buf);
Johannes Bergde3d43a2013-05-14 09:39:02 +02004399 report_frame = true;
Johannes Berg86552012012-10-29 09:46:31 +01004400 }
Johannes Berg37ad3882012-02-24 13:50:54 +01004401
Johannes Berg86552012012-10-29 09:46:31 +01004402 out:
Johannes Bergde3d43a2013-05-14 09:39:02 +02004403 if (report_frame)
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004404 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4405 IEEE80211_DEAUTH_FRAME_LEN);
Johannes Berg86552012012-10-29 09:46:31 +01004406
Johannes Berg77fdaa12009-07-07 03:45:17 +02004407 return 0;
4408}
4409
4410int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01004411 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004412{
4413 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07004414 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004415 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02004416
Johannes Berg8d8b2612009-07-25 11:58:36 +02004417 /*
4418 * cfg80211 should catch this ... but it's racy since
4419 * we can receive a disassoc frame, process it, hand it
4420 * to cfg80211 while that's in a locked section already
4421 * trying to tell us that the user wants to disconnect.
4422 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004423 if (ifmgd->associated != req->bss)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004424 return -ENOLINK;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004425
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004426 sdata_info(sdata,
4427 "disassociating from %pM by local choice (reason=%d)\n",
4428 req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02004429
Jouni Malinene69e95d2010-03-29 23:29:31 -07004430 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01004431 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
4432 req->reason_code, !req->local_state_change,
4433 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004434
Johannes Berg6ff57cf2013-05-16 00:55:00 +02004435 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4436 IEEE80211_DEAUTH_FRAME_LEN);
Johannes Bergbc83b682009-11-29 12:19:06 +01004437
Johannes Berg77fdaa12009-07-07 03:45:17 +02004438 return 0;
4439}
Jouni Malinen026331c2010-02-15 12:53:10 +02004440
Eliad Pellerafa762f2012-04-23 14:45:15 +03004441void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01004442{
4443 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4444
Ben Greear49921852013-02-20 09:41:09 -08004445 /*
4446 * Make sure some work items will not run after this,
4447 * they will not do anything but might not have been
4448 * cancelled when disconnecting.
4449 */
4450 cancel_work_sync(&ifmgd->monitor_work);
4451 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
4452 cancel_work_sync(&ifmgd->request_smps_work);
4453 cancel_work_sync(&ifmgd->csa_connection_drop_work);
4454 cancel_work_sync(&ifmgd->chswitch_work);
4455
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004456 sdata_lock(sdata);
Johannes Berg959867f2013-06-19 13:05:42 +02004457 if (ifmgd->assoc_data) {
4458 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
Johannes Berg54e4ffb2012-02-25 21:48:08 +01004459 ieee80211_destroy_assoc_data(sdata, false);
Johannes Berg959867f2013-06-19 13:05:42 +02004460 cfg80211_assoc_timeout(sdata->dev, bss);
4461 }
Johannes Berg54e4ffb2012-02-25 21:48:08 +01004462 if (ifmgd->auth_data)
4463 ieee80211_destroy_auth_data(sdata, false);
4464 del_timer_sync(&ifmgd->timer);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004465 sdata_unlock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01004466}
4467
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02004468void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
4469 enum nl80211_cqm_rssi_threshold_event rssi_event,
4470 gfp_t gfp)
4471{
4472 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4473
Johannes Bergb5878a22010-04-07 16:48:40 +02004474 trace_api_cqm_rssi_notify(sdata, rssi_event);
4475
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02004476 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
4477}
4478EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);