blob: 9950e13f641b2a5c950a28732c9cea8227ab6e00 [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 Berg1672c0e32013-01-29 15:02:27 +010033#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
34#define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
35#define IEEE80211_AUTH_MAX_TRIES 3
36#define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
37#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
38#define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
39#define IEEE80211_ASSOC_MAX_TRIES 3
Johannes Berg66e67e42012-01-20 13:55:27 +010040
Ben Greear180205b2011-02-04 15:30:24 -080041static int max_nullfunc_tries = 2;
42module_param(max_nullfunc_tries, int, 0644);
43MODULE_PARM_DESC(max_nullfunc_tries,
44 "Maximum nullfunc tx tries before disconnecting (reason 4).");
45
46static int max_probe_tries = 5;
47module_param(max_probe_tries, int, 0644);
48MODULE_PARM_DESC(max_probe_tries,
49 "Maximum probe tries before disconnecting (reason 4).");
Johannes Bergb291ba12009-07-10 15:29:03 +020050
51/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010052 * Beacon loss timeout is calculated as N frames times the
53 * advertised beacon interval. This may need to be somewhat
54 * higher than what hardware might detect to account for
55 * delays in the host processing frames. But since we also
56 * probe on beacon miss before declaring the connection lost
57 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020058 */
Ben Greear59c1ec22013-03-19 14:19:56 -070059static int beacon_loss_count = 7;
60module_param(beacon_loss_count, int, 0644);
61MODULE_PARM_DESC(beacon_loss_count,
62 "Number of beacon intervals before we decide beacon was lost.");
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010063
Johannes Bergb291ba12009-07-10 15:29:03 +020064/*
65 * Time the connection can be idle before we probe
66 * it to see if we can still talk to the AP.
67 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030068#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020069/*
70 * Time we wait for a probe response after sending
71 * a probe request because of beacon loss or for
72 * checking the connection still works.
73 */
Ben Greear180205b2011-02-04 15:30:24 -080074static int probe_wait_ms = 500;
75module_param(probe_wait_ms, int, 0644);
76MODULE_PARM_DESC(probe_wait_ms,
77 "Maximum time(ms) to wait for probe response"
78 " before disconnecting (reason 4).");
Jiri Bencf0706e82007-05-05 11:45:53 -070079
Jouni Malinen17e4ec12010-03-29 23:28:30 -070080/*
81 * Weight given to the latest Beacon frame when calculating average signal
82 * strength for Beacon frames received in the current BSS. This must be
83 * between 1 and 15.
84 */
85#define IEEE80211_SIGNAL_AVE_WEIGHT 3
86
Jouni Malinen391a2002010-08-27 22:22:00 +030087/*
88 * How many Beacon frames need to have been used in average signal strength
89 * before starting to indicate signal change events.
90 */
91#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
92
Johannes Berg77fdaa12009-07-07 03:45:17 +020093/*
Johannes Bergca386f32009-07-10 02:39:48 +020094 * We can have multiple work items (and connection probing)
95 * scheduling this timer, but we need to take care to only
96 * reschedule it when it should fire _earlier_ than it was
97 * asked for before, or if it's not pending right now. This
98 * function ensures that. Note that it then is required to
99 * run this function for all timeouts after the first one
100 * has happened -- the work that runs from this timer will
101 * do that.
102 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200103static void run_again(struct ieee80211_sub_if_data *sdata,
104 unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200105{
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200106 sdata_assert_lock(sdata);
Johannes Bergca386f32009-07-10 02:39:48 +0200107
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200108 if (!timer_pending(&sdata->u.mgd.timer) ||
109 time_before(timeout, sdata->u.mgd.timer.expires))
110 mod_timer(&sdata->u.mgd.timer, timeout);
Johannes Bergca386f32009-07-10 02:39:48 +0200111}
112
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400113void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200114{
Johannes Bergc1288b12012-01-19 09:29:57 +0100115 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200116 return;
117
Johannes Berg7eeff742012-07-18 10:27:27 +0200118 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
119 return;
120
Johannes Bergb291ba12009-07-10 15:29:03 +0200121 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100122 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200123}
124
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400125void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
126{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400127 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
128
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100129 if (unlikely(!sdata->u.mgd.associated))
130 return;
131
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400132 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
133 return;
134
135 mod_timer(&sdata->u.mgd.conn_mon_timer,
136 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400137
138 ifmgd->probe_send_count = 0;
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400139}
140
Johannes Berg5484e232008-09-08 17:44:27 +0200141static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200142{
Johannes Berg5484e232008-09-08 17:44:27 +0200143 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200144}
145
Johannes Berg6565ec92013-02-08 14:52:32 +0100146static u32 chandef_downgrade(struct cfg80211_chan_def *c)
147{
148 u32 ret;
149 int tmp;
150
151 switch (c->width) {
152 case NL80211_CHAN_WIDTH_20:
153 c->width = NL80211_CHAN_WIDTH_20_NOHT;
154 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
155 break;
156 case NL80211_CHAN_WIDTH_40:
157 c->width = NL80211_CHAN_WIDTH_20;
158 c->center_freq1 = c->chan->center_freq;
159 ret = IEEE80211_STA_DISABLE_40MHZ |
160 IEEE80211_STA_DISABLE_VHT;
161 break;
162 case NL80211_CHAN_WIDTH_80:
163 tmp = (30 + c->chan->center_freq - c->center_freq1)/20;
164 /* n_P40 */
165 tmp /= 2;
166 /* freq_P40 */
167 c->center_freq1 = c->center_freq1 - 20 + 40 * tmp;
168 c->width = NL80211_CHAN_WIDTH_40;
169 ret = IEEE80211_STA_DISABLE_VHT;
170 break;
171 case NL80211_CHAN_WIDTH_80P80:
172 c->center_freq2 = 0;
173 c->width = NL80211_CHAN_WIDTH_80;
174 ret = IEEE80211_STA_DISABLE_80P80MHZ |
175 IEEE80211_STA_DISABLE_160MHZ;
176 break;
177 case NL80211_CHAN_WIDTH_160:
178 /* n_P20 */
179 tmp = (70 + c->chan->center_freq - c->center_freq1)/20;
180 /* n_P80 */
181 tmp /= 4;
182 c->center_freq1 = c->center_freq1 - 40 + 80 * tmp;
183 c->width = NL80211_CHAN_WIDTH_80;
184 ret = IEEE80211_STA_DISABLE_80P80MHZ |
185 IEEE80211_STA_DISABLE_160MHZ;
186 break;
187 default:
188 case NL80211_CHAN_WIDTH_20_NOHT:
189 WARN_ON_ONCE(1);
190 c->width = NL80211_CHAN_WIDTH_20_NOHT;
191 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
192 break;
193 }
194
195 WARN_ON_ONCE(!cfg80211_chandef_valid(c));
196
197 return ret;
198}
199
200static u32
201ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
202 struct ieee80211_supported_band *sband,
203 struct ieee80211_channel *channel,
204 const struct ieee80211_ht_operation *ht_oper,
205 const struct ieee80211_vht_operation *vht_oper,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100206 struct cfg80211_chan_def *chandef, bool verbose)
Johannes Berg6565ec92013-02-08 14:52:32 +0100207{
208 struct cfg80211_chan_def vht_chandef;
209 u32 ht_cfreq, ret;
210
211 chandef->chan = channel;
212 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
213 chandef->center_freq1 = channel->center_freq;
214 chandef->center_freq2 = 0;
215
216 if (!ht_oper || !sband->ht_cap.ht_supported) {
217 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
218 goto out;
219 }
220
221 chandef->width = NL80211_CHAN_WIDTH_20;
222
223 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
224 channel->band);
225 /* check that channel matches the right operating channel */
226 if (channel->center_freq != ht_cfreq) {
227 /*
228 * It's possible that some APs are confused here;
229 * Netgear WNDR3700 sometimes reports 4 higher than
230 * the actual channel in association responses, but
231 * since we look at probe response/beacon data here
232 * it should be OK.
233 */
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100234 if (verbose)
235 sdata_info(sdata,
236 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
237 channel->center_freq, ht_cfreq,
238 ht_oper->primary_chan, channel->band);
Johannes Berg6565ec92013-02-08 14:52:32 +0100239 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
240 goto out;
241 }
242
243 /* check 40 MHz support, if we have it */
244 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
245 switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
246 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
247 chandef->width = NL80211_CHAN_WIDTH_40;
248 chandef->center_freq1 += 10;
249 break;
250 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
251 chandef->width = NL80211_CHAN_WIDTH_40;
252 chandef->center_freq1 -= 10;
253 break;
254 }
255 } else {
256 /* 40 MHz (and 80 MHz) must be supported for VHT */
257 ret = IEEE80211_STA_DISABLE_VHT;
Johannes Berg85220d72013-03-25 18:29:27 +0100258 /* also mark 40 MHz disabled */
259 ret |= IEEE80211_STA_DISABLE_40MHZ;
Johannes Berg6565ec92013-02-08 14:52:32 +0100260 goto out;
261 }
262
263 if (!vht_oper || !sband->vht_cap.vht_supported) {
264 ret = IEEE80211_STA_DISABLE_VHT;
265 goto out;
266 }
267
268 vht_chandef.chan = channel;
269 vht_chandef.center_freq1 =
270 ieee80211_channel_to_frequency(vht_oper->center_freq_seg1_idx,
271 channel->band);
272 vht_chandef.center_freq2 = 0;
273
Johannes Berg6565ec92013-02-08 14:52:32 +0100274 switch (vht_oper->chan_width) {
275 case IEEE80211_VHT_CHANWIDTH_USE_HT:
276 vht_chandef.width = chandef->width;
277 break;
278 case IEEE80211_VHT_CHANWIDTH_80MHZ:
279 vht_chandef.width = NL80211_CHAN_WIDTH_80;
280 break;
281 case IEEE80211_VHT_CHANWIDTH_160MHZ:
282 vht_chandef.width = NL80211_CHAN_WIDTH_160;
283 break;
284 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
285 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
Johannes Berg6553bf042013-03-28 10:26:17 +0100286 vht_chandef.center_freq2 =
287 ieee80211_channel_to_frequency(
288 vht_oper->center_freq_seg2_idx,
289 channel->band);
Johannes Berg6565ec92013-02-08 14:52:32 +0100290 break;
291 default:
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100292 if (verbose)
293 sdata_info(sdata,
294 "AP VHT operation IE has invalid channel width (%d), disable VHT\n",
295 vht_oper->chan_width);
Johannes Berg6565ec92013-02-08 14:52:32 +0100296 ret = IEEE80211_STA_DISABLE_VHT;
297 goto out;
298 }
299
300 if (!cfg80211_chandef_valid(&vht_chandef)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100301 if (verbose)
302 sdata_info(sdata,
303 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100304 ret = IEEE80211_STA_DISABLE_VHT;
305 goto out;
306 }
307
308 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
309 ret = 0;
310 goto out;
311 }
312
313 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100314 if (verbose)
315 sdata_info(sdata,
316 "AP VHT information doesn't match HT, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100317 ret = IEEE80211_STA_DISABLE_VHT;
318 goto out;
319 }
320
321 *chandef = vht_chandef;
322
323 ret = 0;
324
325out:
Johannes Berg586e01e2013-02-14 12:13:53 +0100326 /* don't print the message below for VHT mismatch if VHT is disabled */
327 if (ret & IEEE80211_STA_DISABLE_VHT)
328 vht_chandef = *chandef;
329
Johannes Berg6565ec92013-02-08 14:52:32 +0100330 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
331 IEEE80211_CHAN_DISABLED)) {
332 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
333 ret = IEEE80211_STA_DISABLE_HT |
334 IEEE80211_STA_DISABLE_VHT;
335 goto out;
336 }
337
338 ret |= chandef_downgrade(chandef);
339 }
340
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100341 if (chandef->width != vht_chandef.width && verbose)
Johannes Berg6565ec92013-02-08 14:52:32 +0100342 sdata_info(sdata,
343 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
344
345 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
346 return ret;
347}
348
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100349static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
350 struct sta_info *sta,
351 const struct ieee80211_ht_operation *ht_oper,
352 const struct ieee80211_vht_operation *vht_oper,
353 const u8 *bssid, u32 *changed)
Johannes Bergd5522e02009-03-30 13:23:35 +0200354{
355 struct ieee80211_local *local = sdata->local;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100356 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergd5522e02009-03-30 13:23:35 +0200357 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200358 struct ieee80211_channel *chan;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100359 struct cfg80211_chan_def chandef;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200360 u16 ht_opmode;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100361 u32 flags;
362 enum ieee80211_sta_rx_bandwidth new_sta_bw;
363 int ret;
364
365 /* if HT was/is disabled, don't track any bandwidth changes */
366 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
367 return 0;
368
369 /* don't check VHT if we associated as non-VHT station */
370 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
371 vht_oper = NULL;
Johannes Bergd5522e02009-03-30 13:23:35 +0200372
Johannes Berg11289582013-02-07 17:36:12 +0100373 if (WARN_ON_ONCE(!sta))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100374 return -EINVAL;
Johannes Berg11289582013-02-07 17:36:12 +0100375
Johannes Bergf2d93302013-02-08 13:15:55 +0100376 chan = sdata->vif.bss_conf.chandef.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200377 sband = local->hw.wiphy->bands[chan->band];
Johannes Berg0aaffa92010-05-05 15:28:27 +0200378
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100379 /* calculate new channel (type) based on HT/VHT operation IEs */
380 flags = ieee80211_determine_chantype(sdata, sband, chan, ht_oper,
381 vht_oper, &chandef, false);
382
383 /*
384 * Downgrade the new channel if we associated with restricted
385 * capabilities. For example, if we associated as a 20 MHz STA
386 * to a 40 MHz AP (due to regulatory, capabilities or config
387 * reasons) then switching to a 40 MHz channel now won't do us
388 * any good -- we couldn't use it with the AP.
389 */
390 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
391 chandef.width == NL80211_CHAN_WIDTH_80P80)
392 flags |= chandef_downgrade(&chandef);
393 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
394 chandef.width == NL80211_CHAN_WIDTH_160)
395 flags |= chandef_downgrade(&chandef);
396 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
397 chandef.width > NL80211_CHAN_WIDTH_20)
398 flags |= chandef_downgrade(&chandef);
399
400 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
401 return 0;
402
403 sdata_info(sdata,
404 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
405 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
406 chandef.center_freq1, chandef.center_freq2);
407
408 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
409 IEEE80211_STA_DISABLE_VHT |
410 IEEE80211_STA_DISABLE_40MHZ |
411 IEEE80211_STA_DISABLE_80P80MHZ |
412 IEEE80211_STA_DISABLE_160MHZ)) ||
413 !cfg80211_chandef_valid(&chandef)) {
414 sdata_info(sdata,
415 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
416 ifmgd->bssid);
417 return -EINVAL;
Johannes Berg64f68e52012-03-28 10:58:37 +0200418 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200419
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100420 switch (chandef.width) {
421 case NL80211_CHAN_WIDTH_20_NOHT:
422 case NL80211_CHAN_WIDTH_20:
423 new_sta_bw = IEEE80211_STA_RX_BW_20;
424 break;
425 case NL80211_CHAN_WIDTH_40:
426 new_sta_bw = IEEE80211_STA_RX_BW_40;
427 break;
428 case NL80211_CHAN_WIDTH_80:
429 new_sta_bw = IEEE80211_STA_RX_BW_80;
430 break;
431 case NL80211_CHAN_WIDTH_80P80:
432 case NL80211_CHAN_WIDTH_160:
433 new_sta_bw = IEEE80211_STA_RX_BW_160;
434 break;
435 default:
436 return -EINVAL;
437 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200438
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100439 if (new_sta_bw > sta->cur_max_bandwidth)
440 new_sta_bw = sta->cur_max_bandwidth;
Johannes Berg64f68e52012-03-28 10:58:37 +0200441
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100442 if (new_sta_bw < sta->sta.bandwidth) {
443 sta->sta.bandwidth = new_sta_bw;
444 rate_control_rate_update(local, sband, sta,
445 IEEE80211_RC_BW_CHANGED);
446 }
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530447
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100448 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
449 if (ret) {
450 sdata_info(sdata,
451 "AP %pM changed bandwidth to incompatible one - disconnect\n",
452 ifmgd->bssid);
453 return ret;
454 }
455
456 if (new_sta_bw > sta->sta.bandwidth) {
457 sta->sta.bandwidth = new_sta_bw;
458 rate_control_rate_update(local, sband, sta,
459 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200460 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200461
Johannes Berg074d46d2012-03-15 19:45:16 +0100462 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200463
464 /* if bss configuration changed store the new one */
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100465 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
466 *changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200467 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Bergd5522e02009-03-30 13:23:35 +0200468 }
469
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100470 return 0;
Johannes Bergd5522e02009-03-30 13:23:35 +0200471}
472
Johannes Berg9c6bd792008-09-11 00:01:52 +0200473/* frame sending functions */
474
Johannes Berg66e67e42012-01-20 13:55:27 +0100475static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
476 struct ieee80211_supported_band *sband,
477 u32 *rates)
478{
479 int i, j, count;
480 *rates = 0;
481 count = 0;
482 for (i = 0; i < supp_rates_len; i++) {
483 int rate = (supp_rates[i] & 0x7F) * 5;
484
485 for (j = 0; j < sband->n_bitrates; j++)
486 if (sband->bitrates[j].bitrate == rate) {
487 *rates |= BIT(j);
488 count++;
489 break;
490 }
491 }
492
493 return count;
494}
495
496static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200497 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100498 struct ieee80211_supported_band *sband,
499 struct ieee80211_channel *channel,
500 enum ieee80211_smps_mode smps)
501{
Johannes Berg66e67e42012-01-20 13:55:27 +0100502 u8 *pos;
503 u32 flags = channel->flags;
504 u16 cap;
505 struct ieee80211_sta_ht_cap ht_cap;
506
507 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
508
Johannes Berg66e67e42012-01-20 13:55:27 +0100509 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
510 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
511
Johannes Berg66e67e42012-01-20 13:55:27 +0100512 /* determine capability flags */
513 cap = ht_cap.cap;
514
Johannes Berg9dde6422012-05-16 23:43:19 +0200515 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100516 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
517 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
518 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
519 cap &= ~IEEE80211_HT_CAP_SGI_40;
520 }
521 break;
522 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
523 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
524 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
525 cap &= ~IEEE80211_HT_CAP_SGI_40;
526 }
527 break;
528 }
529
Johannes Berg24398e32012-03-28 10:58:36 +0200530 /*
531 * If 40 MHz was disabled associate as though we weren't
532 * capable of 40 MHz -- some broken APs will never fall
533 * back to trying to transmit in 20 MHz.
534 */
535 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
536 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
537 cap &= ~IEEE80211_HT_CAP_SGI_40;
538 }
539
Johannes Berg66e67e42012-01-20 13:55:27 +0100540 /* set SM PS mode properly */
541 cap &= ~IEEE80211_HT_CAP_SM_PS;
542 switch (smps) {
543 case IEEE80211_SMPS_AUTOMATIC:
544 case IEEE80211_SMPS_NUM_MODES:
545 WARN_ON(1);
546 case IEEE80211_SMPS_OFF:
547 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
548 IEEE80211_HT_CAP_SM_PS_SHIFT;
549 break;
550 case IEEE80211_SMPS_STATIC:
551 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
552 IEEE80211_HT_CAP_SM_PS_SHIFT;
553 break;
554 case IEEE80211_SMPS_DYNAMIC:
555 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
556 IEEE80211_HT_CAP_SM_PS_SHIFT;
557 break;
558 }
559
560 /* reserve and fill IE */
561 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
562 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
563}
564
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000565static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
566 struct sk_buff *skb,
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100567 struct ieee80211_supported_band *sband,
568 struct ieee80211_vht_cap *ap_vht_cap)
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000569{
570 u8 *pos;
571 u32 cap;
572 struct ieee80211_sta_vht_cap vht_cap;
573
574 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
575
576 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +0100577 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000578
579 /* determine capability flags */
580 cap = vht_cap.cap;
581
Johannes Bergf2d9d272012-11-22 14:11:39 +0100582 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
583 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
584 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
585 }
586
587 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
588 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
589 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
590 }
591
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100592 /*
593 * Some APs apparently get confused if our capabilities are better
594 * than theirs, so restrict what we advertise in the assoc request.
595 */
596 if (!(ap_vht_cap->vht_cap_info &
597 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
598 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
599
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000600 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000601 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000602 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
603}
604
Johannes Berg66e67e42012-01-20 13:55:27 +0100605static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
606{
607 struct ieee80211_local *local = sdata->local;
608 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
609 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
610 struct sk_buff *skb;
611 struct ieee80211_mgmt *mgmt;
612 u8 *pos, qos_info;
613 size_t offset = 0, noffset;
614 int i, count, rates_len, supp_rates_len;
615 u16 capab;
616 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200617 struct ieee80211_chanctx_conf *chanctx_conf;
618 struct ieee80211_channel *chan;
Johannes Berg66e67e42012-01-20 13:55:27 +0100619 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100620
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200621 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +0100622
Johannes Berg55de9082012-07-26 17:24:39 +0200623 rcu_read_lock();
624 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
625 if (WARN_ON(!chanctx_conf)) {
626 rcu_read_unlock();
627 return;
628 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100629 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200630 rcu_read_unlock();
631 sband = local->hw.wiphy->bands[chan->band];
Johannes Berg66e67e42012-01-20 13:55:27 +0100632
633 if (assoc_data->supp_rates_len) {
634 /*
635 * Get all rates supported by the device and the AP as
636 * some APs don't like getting a superset of their rates
637 * in the association request (e.g. D-Link DAP 1353 in
638 * b-only mode)...
639 */
640 rates_len = ieee80211_compatible_rates(assoc_data->supp_rates,
641 assoc_data->supp_rates_len,
642 sband, &rates);
643 } else {
644 /*
645 * In case AP not provide any supported rates information
646 * before association, we send information element(s) with
647 * all rates that we support.
648 */
649 rates = ~0;
650 rates_len = sband->n_bitrates;
651 }
652
653 skb = alloc_skb(local->hw.extra_tx_headroom +
654 sizeof(*mgmt) + /* bit too much but doesn't matter */
655 2 + assoc_data->ssid_len + /* SSID */
656 4 + rates_len + /* (extended) rates */
657 4 + /* power capability */
658 2 + 2 * sband->n_channels + /* supported channels */
659 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000660 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Johannes Berg66e67e42012-01-20 13:55:27 +0100661 assoc_data->ie_len + /* extra IEs */
662 9, /* WMM */
663 GFP_KERNEL);
664 if (!skb)
665 return;
666
667 skb_reserve(skb, local->hw.extra_tx_headroom);
668
669 capab = WLAN_CAPABILITY_ESS;
670
671 if (sband->band == IEEE80211_BAND_2GHZ) {
672 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
673 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
674 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
675 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
676 }
677
678 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
679 capab |= WLAN_CAPABILITY_PRIVACY;
680
681 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
682 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
683 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
684
685 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
686 memset(mgmt, 0, 24);
687 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
688 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
689 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
690
691 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
692 skb_put(skb, 10);
693 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
694 IEEE80211_STYPE_REASSOC_REQ);
695 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
696 mgmt->u.reassoc_req.listen_interval =
697 cpu_to_le16(local->hw.conf.listen_interval);
698 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
699 ETH_ALEN);
700 } else {
701 skb_put(skb, 4);
702 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
703 IEEE80211_STYPE_ASSOC_REQ);
704 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
705 mgmt->u.assoc_req.listen_interval =
706 cpu_to_le16(local->hw.conf.listen_interval);
707 }
708
709 /* SSID */
710 pos = skb_put(skb, 2 + assoc_data->ssid_len);
711 *pos++ = WLAN_EID_SSID;
712 *pos++ = assoc_data->ssid_len;
713 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
714
715 /* add all rates which were marked to be used above */
716 supp_rates_len = rates_len;
717 if (supp_rates_len > 8)
718 supp_rates_len = 8;
719
720 pos = skb_put(skb, supp_rates_len + 2);
721 *pos++ = WLAN_EID_SUPP_RATES;
722 *pos++ = supp_rates_len;
723
724 count = 0;
725 for (i = 0; i < sband->n_bitrates; i++) {
726 if (BIT(i) & rates) {
727 int rate = sband->bitrates[i].bitrate;
728 *pos++ = (u8) (rate / 5);
729 if (++count == 8)
730 break;
731 }
732 }
733
734 if (rates_len > count) {
735 pos = skb_put(skb, rates_len - count + 2);
736 *pos++ = WLAN_EID_EXT_SUPP_RATES;
737 *pos++ = rates_len - count;
738
739 for (i++; i < sband->n_bitrates; i++) {
740 if (BIT(i) & rates) {
741 int rate = sband->bitrates[i].bitrate;
742 *pos++ = (u8) (rate / 5);
743 }
744 }
745 }
746
747 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
748 /* 1. power capabilities */
749 pos = skb_put(skb, 4);
750 *pos++ = WLAN_EID_PWR_CAPABILITY;
751 *pos++ = 2;
752 *pos++ = 0; /* min tx power */
Johannes Berg55de9082012-07-26 17:24:39 +0200753 *pos++ = chan->max_power; /* max tx power */
Johannes Berg66e67e42012-01-20 13:55:27 +0100754
755 /* 2. supported channels */
756 /* TODO: get this in reg domain format */
757 pos = skb_put(skb, 2 * sband->n_channels + 2);
758 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
759 *pos++ = 2 * sband->n_channels;
760 for (i = 0; i < sband->n_channels; i++) {
761 *pos++ = ieee80211_frequency_to_channel(
762 sband->channels[i].center_freq);
763 *pos++ = 1; /* one channel in the subband*/
764 }
765 }
766
767 /* if present, add any custom IEs that go before HT */
768 if (assoc_data->ie_len && assoc_data->ie) {
769 static const u8 before_ht[] = {
770 WLAN_EID_SSID,
771 WLAN_EID_SUPP_RATES,
772 WLAN_EID_EXT_SUPP_RATES,
773 WLAN_EID_PWR_CAPABILITY,
774 WLAN_EID_SUPPORTED_CHANNELS,
775 WLAN_EID_RSN,
776 WLAN_EID_QOS_CAPA,
777 WLAN_EID_RRM_ENABLED_CAPABILITIES,
778 WLAN_EID_MOBILITY_DOMAIN,
779 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
780 };
781 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
782 before_ht, ARRAY_SIZE(before_ht),
783 offset);
784 pos = skb_put(skb, noffset - offset);
785 memcpy(pos, assoc_data->ie + offset, noffset - offset);
786 offset = noffset;
787 }
788
Johannes Bergf2d9d272012-11-22 14:11:39 +0100789 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
790 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
791 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
792
Johannes Berga8243b72012-11-22 14:32:09 +0100793 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200794 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200795 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100796
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000797 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100798 ieee80211_add_vht_ie(sdata, skb, sband,
799 &assoc_data->ap_vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000800
Johannes Berg66e67e42012-01-20 13:55:27 +0100801 /* if present, add any custom non-vendor IEs that go after HT */
802 if (assoc_data->ie_len && assoc_data->ie) {
803 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
804 assoc_data->ie_len,
805 offset);
806 pos = skb_put(skb, noffset - offset);
807 memcpy(pos, assoc_data->ie + offset, noffset - offset);
808 offset = noffset;
809 }
810
Johannes Berg76f03032012-03-08 15:02:05 +0100811 if (assoc_data->wmm) {
812 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200813 qos_info = ifmgd->uapsd_queues;
814 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100815 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
816 } else {
817 qos_info = 0;
818 }
819
820 pos = skb_put(skb, 9);
821 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
822 *pos++ = 7; /* len */
823 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
824 *pos++ = 0x50;
825 *pos++ = 0xf2;
826 *pos++ = 2; /* WME */
827 *pos++ = 0; /* WME info */
828 *pos++ = 1; /* WME ver */
829 *pos++ = qos_info;
830 }
831
832 /* add any remaining custom (i.e. vendor specific here) IEs */
833 if (assoc_data->ie_len && assoc_data->ie) {
834 noffset = assoc_data->ie_len;
835 pos = skb_put(skb, noffset - offset);
836 memcpy(pos, assoc_data->ie + offset, noffset - offset);
837 }
838
Johannes Berga1845fc2012-06-27 13:18:36 +0200839 drv_mgd_prepare_tx(local, sdata);
840
Johannes Berg66e67e42012-01-20 13:55:27 +0100841 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Johannes Berg1672c0e32013-01-29 15:02:27 +0100842 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
843 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
844 IEEE80211_TX_INTFL_MLME_CONN_TX;
Johannes Berg66e67e42012-01-20 13:55:27 +0100845 ieee80211_tx_skb(sdata, skb);
846}
847
Kalle Valo572e0012009-02-10 17:09:31 +0200848void ieee80211_send_pspoll(struct ieee80211_local *local,
849 struct ieee80211_sub_if_data *sdata)
850{
Kalle Valo572e0012009-02-10 17:09:31 +0200851 struct ieee80211_pspoll *pspoll;
852 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200853
Kalle Valod8cd1892010-01-05 20:16:26 +0200854 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
855 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200856 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200857
Kalle Valod8cd1892010-01-05 20:16:26 +0200858 pspoll = (struct ieee80211_pspoll *) skb->data;
859 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200860
Johannes Berg62ae67b2009-11-18 18:42:05 +0100861 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
862 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200863}
864
Johannes Berg965beda2009-04-16 13:17:24 +0200865void ieee80211_send_nullfunc(struct ieee80211_local *local,
866 struct ieee80211_sub_if_data *sdata,
867 int powersave)
868{
869 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200870 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530871 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200872
Kalle Valod8cd1892010-01-05 20:16:26 +0200873 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
874 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200875 return;
876
Kalle Valod8cd1892010-01-05 20:16:26 +0200877 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200878 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200879 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200880
Seth Forshee6c17b772013-02-11 11:21:07 -0600881 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
882 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Pontus Fuchsff40b422013-06-04 12:44:52 +0200883
884 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
885 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
886
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530887 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
888 IEEE80211_STA_CONNECTION_POLL))
889 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
890
Johannes Berg62ae67b2009-11-18 18:42:05 +0100891 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200892}
893
Felix Fietkaud5242152010-01-08 18:06:26 +0100894static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
895 struct ieee80211_sub_if_data *sdata)
896{
897 struct sk_buff *skb;
898 struct ieee80211_hdr *nullfunc;
899 __le16 fc;
900
901 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
902 return;
903
904 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -0700905 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +0100906 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700907
Felix Fietkaud5242152010-01-08 18:06:26 +0100908 skb_reserve(skb, local->hw.extra_tx_headroom);
909
910 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
911 memset(nullfunc, 0, 30);
912 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
913 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
914 nullfunc->frame_control = fc;
915 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
916 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
917 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
918 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
919
920 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
921 ieee80211_tx_skb(sdata, skb);
922}
923
Johannes Bergcc32abd2009-05-15 11:52:31 +0200924/* spectrum management related things */
925static void ieee80211_chswitch_work(struct work_struct *work)
926{
927 struct ieee80211_sub_if_data *sdata =
928 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Karl Beldan675a0b02013-03-25 16:26:57 +0100929 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200930 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
931
Johannes Berg9607e6b2009-12-23 13:15:31 +0100932 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200933 return;
934
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200935 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200936 if (!ifmgd->associated)
937 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200938
Johannes Berg85220d72013-03-25 18:29:27 +0100939 local->_oper_chandef = local->csa_chandef;
Karl Beldan675a0b02013-03-25 16:26:57 +0100940
941 if (!local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +0200942 /* call "hw_config" only if doing sw channel switch */
Karl Beldan675a0b02013-03-25 16:26:57 +0100943 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
Shahar Levi1ea57b12011-09-08 08:44:05 +0300944 } else {
945 /* update the device channel directly */
Karl Beldan675a0b02013-03-25 16:26:57 +0100946 local->hw.conf.chandef = local->_oper_chandef;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200947 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200948
Johannes Berg77fdaa12009-07-07 03:45:17 +0200949 /* XXX: shouldn't really modify cfg80211-owned data! */
Karl Beldan675a0b02013-03-25 16:26:57 +0100950 ifmgd->associated->channel = local->_oper_chandef.chan;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200951
Johannes Berg57eebdf2012-08-01 15:50:46 +0200952 /* XXX: wait for a beacon first? */
Karl Beldan675a0b02013-03-25 16:26:57 +0100953 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +0100954 IEEE80211_MAX_QUEUE_MAP,
Johannes Bergcc32abd2009-05-15 11:52:31 +0200955 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200956 out:
957 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200958 sdata_unlock(sdata);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200959}
960
Johannes Berg5ce6e432010-05-11 16:20:57 +0200961void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
962{
Johannes Berg55de9082012-07-26 17:24:39 +0200963 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
964 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200965
966 trace_api_chswitch_done(sdata, success);
967 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +0200968 sdata_info(sdata,
969 "driver channel switch failed, disconnecting\n");
970 ieee80211_queue_work(&sdata->local->hw,
971 &ifmgd->csa_connection_drop_work);
972 } else {
973 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +0200974 }
Johannes Berg5ce6e432010-05-11 16:20:57 +0200975}
976EXPORT_SYMBOL(ieee80211_chswitch_done);
977
Johannes Bergcc32abd2009-05-15 11:52:31 +0200978static void ieee80211_chswitch_timer(unsigned long data)
979{
980 struct ieee80211_sub_if_data *sdata =
981 (struct ieee80211_sub_if_data *) data;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200982
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +0100983 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200984}
985
Johannes Berg37799e52013-03-26 14:02:26 +0100986static void
Johannes Berg4a3cb702013-02-12 16:43:19 +0100987ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
Johannes Berg04a161f2013-05-03 09:35:35 +0200988 u64 timestamp, struct ieee802_11_elems *elems,
989 bool beacon)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200990{
Johannes Bergb4f286a12013-03-26 14:13:58 +0100991 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200992 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg37799e52013-03-26 14:02:26 +0100993 struct cfg80211_bss *cbss = ifmgd->associated;
994 struct ieee80211_bss *bss;
Johannes Berg55de9082012-07-26 17:24:39 +0200995 struct ieee80211_chanctx *chanctx;
Johannes Bergb4f286a12013-03-26 14:13:58 +0100996 enum ieee80211_band new_band;
997 int new_freq;
998 u8 new_chan_no;
999 u8 count;
1000 u8 mode;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001001 struct ieee80211_channel *new_chan;
Johannes Berg85220d72013-03-25 18:29:27 +01001002 struct cfg80211_chan_def new_chandef = {};
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001003 struct cfg80211_chan_def new_vht_chandef = {};
1004 const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1005 const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
Johannes Berg04a161f2013-05-03 09:35:35 +02001006 const struct ieee80211_ht_operation *ht_oper;
Johannes Berg85220d72013-03-25 18:29:27 +01001007 int secondary_channel_offset = -1;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001008
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001009 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001010
Johannes Berg37799e52013-03-26 14:02:26 +01001011 if (!cbss)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001012 return;
1013
Johannes Bergb4f286a12013-03-26 14:13:58 +01001014 if (local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001015 return;
1016
Johannes Berg37799e52013-03-26 14:02:26 +01001017 /* disregard subsequent announcements if we are already processing */
Johannes Bergcc32abd2009-05-15 11:52:31 +02001018 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1019 return;
1020
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001021 sec_chan_offs = elems->sec_chan_offs;
1022 wide_bw_chansw_ie = elems->wide_bw_chansw_ie;
Johannes Berg04a161f2013-05-03 09:35:35 +02001023 ht_oper = elems->ht_operation;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001024
1025 if (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
1026 IEEE80211_STA_DISABLE_40MHZ)) {
1027 sec_chan_offs = NULL;
1028 wide_bw_chansw_ie = NULL;
Johannes Berg04a161f2013-05-03 09:35:35 +02001029 /* only used for bandwidth here */
1030 ht_oper = NULL;
Johannes Berg85220d72013-03-25 18:29:27 +01001031 }
1032
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001033 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
1034 wide_bw_chansw_ie = NULL;
Johannes Berg85220d72013-03-25 18:29:27 +01001035
Johannes Bergb4f286a12013-03-26 14:13:58 +01001036 if (elems->ext_chansw_ie) {
1037 if (!ieee80211_operating_class_to_band(
1038 elems->ext_chansw_ie->new_operating_class,
1039 &new_band)) {
1040 sdata_info(sdata,
1041 "cannot understand ECSA IE operating class %d, disconnecting\n",
1042 elems->ext_chansw_ie->new_operating_class);
1043 ieee80211_queue_work(&local->hw,
1044 &ifmgd->csa_connection_drop_work);
1045 }
1046 new_chan_no = elems->ext_chansw_ie->new_ch_num;
1047 count = elems->ext_chansw_ie->count;
1048 mode = elems->ext_chansw_ie->mode;
1049 } else if (elems->ch_switch_ie) {
1050 new_band = cbss->channel->band;
1051 new_chan_no = elems->ch_switch_ie->new_ch_num;
1052 count = elems->ch_switch_ie->count;
1053 mode = elems->ch_switch_ie->mode;
1054 } else {
1055 /* nothing here we understand */
Johannes Berg37799e52013-03-26 14:02:26 +01001056 return;
Johannes Bergb4f286a12013-03-26 14:13:58 +01001057 }
Johannes Berg37799e52013-03-26 14:02:26 +01001058
1059 bss = (void *)cbss->priv;
1060
Johannes Bergb4f286a12013-03-26 14:13:58 +01001061 new_freq = ieee80211_channel_to_frequency(new_chan_no, new_band);
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001062 new_chan = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1063 if (!new_chan || new_chan->flags & IEEE80211_CHAN_DISABLED) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001064 sdata_info(sdata,
1065 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
1066 ifmgd->associated->bssid, new_freq);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001067 ieee80211_queue_work(&local->hw,
Johannes Berg882a7c62012-08-01 22:32:45 +02001068 &ifmgd->csa_connection_drop_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001069 return;
Johannes Berg882a7c62012-08-01 22:32:45 +02001070 }
Johannes Bergcc32abd2009-05-15 11:52:31 +02001071
Johannes Berg04a161f2013-05-03 09:35:35 +02001072 if (!beacon && sec_chan_offs) {
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001073 secondary_channel_offset = sec_chan_offs->sec_chan_offs;
Johannes Berg04a161f2013-05-03 09:35:35 +02001074 } else if (beacon && ht_oper) {
1075 secondary_channel_offset =
1076 ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001077 } else if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Johannes Berg04a161f2013-05-03 09:35:35 +02001078 /*
1079 * If it's not a beacon, HT is enabled and the IE not present,
1080 * it's 20 MHz, 802.11-2012 8.5.2.6:
1081 * This element [the Secondary Channel Offset Element] is
1082 * present when switching to a 40 MHz channel. It may be
1083 * present when switching to a 20 MHz channel (in which
1084 * case the secondary channel offset is set to SCN).
1085 */
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001086 secondary_channel_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1087 }
1088
Johannes Berg85220d72013-03-25 18:29:27 +01001089 switch (secondary_channel_offset) {
1090 default:
1091 /* secondary_channel_offset was present but is invalid */
1092 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001093 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001094 NL80211_CHAN_HT20);
1095 break;
1096 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001097 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001098 NL80211_CHAN_HT40PLUS);
1099 break;
1100 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001101 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001102 NL80211_CHAN_HT40MINUS);
1103 break;
1104 case -1:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001105 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001106 NL80211_CHAN_NO_HT);
1107 break;
1108 }
1109
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001110 if (wide_bw_chansw_ie) {
1111 new_vht_chandef.chan = new_chan;
1112 new_vht_chandef.center_freq1 =
1113 ieee80211_channel_to_frequency(
1114 wide_bw_chansw_ie->new_center_freq_seg0,
1115 new_band);
1116
1117 switch (wide_bw_chansw_ie->new_channel_width) {
1118 default:
1119 /* hmmm, ignore VHT and use HT if present */
1120 case IEEE80211_VHT_CHANWIDTH_USE_HT:
1121 new_vht_chandef.chan = NULL;
1122 break;
1123 case IEEE80211_VHT_CHANWIDTH_80MHZ:
1124 new_vht_chandef.width = NL80211_CHAN_WIDTH_80;
1125 break;
1126 case IEEE80211_VHT_CHANWIDTH_160MHZ:
1127 new_vht_chandef.width = NL80211_CHAN_WIDTH_160;
1128 break;
1129 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1130 /* field is otherwise reserved */
1131 new_vht_chandef.center_freq2 =
1132 ieee80211_channel_to_frequency(
1133 wide_bw_chansw_ie->new_center_freq_seg1,
1134 new_band);
1135 new_vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1136 break;
1137 }
1138 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
1139 new_vht_chandef.width == NL80211_CHAN_WIDTH_80P80)
1140 chandef_downgrade(&new_vht_chandef);
1141 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
1142 new_vht_chandef.width == NL80211_CHAN_WIDTH_160)
1143 chandef_downgrade(&new_vht_chandef);
1144 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
1145 new_vht_chandef.width > NL80211_CHAN_WIDTH_20)
1146 chandef_downgrade(&new_vht_chandef);
1147 }
1148
1149 /* if VHT data is there validate & use it */
1150 if (new_vht_chandef.chan) {
1151 if (!cfg80211_chandef_compatible(&new_vht_chandef,
1152 &new_chandef)) {
1153 sdata_info(sdata,
1154 "AP %pM CSA has inconsistent channel data, disconnecting\n",
1155 ifmgd->associated->bssid);
1156 ieee80211_queue_work(&local->hw,
1157 &ifmgd->csa_connection_drop_work);
1158 return;
1159 }
1160 new_chandef = new_vht_chandef;
1161 }
1162
Johannes Berg85220d72013-03-25 18:29:27 +01001163 if (!cfg80211_chandef_usable(local->hw.wiphy, &new_chandef,
1164 IEEE80211_CHAN_DISABLED)) {
1165 sdata_info(sdata,
1166 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1167 ifmgd->associated->bssid, new_freq,
1168 new_chandef.width, new_chandef.center_freq1,
1169 new_chandef.center_freq2);
1170 ieee80211_queue_work(&local->hw,
1171 &ifmgd->csa_connection_drop_work);
1172 return;
1173 }
1174
Johannes Berg57eebdf2012-08-01 15:50:46 +02001175 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
1176
Johannes Bergb4f286a12013-03-26 14:13:58 +01001177 if (local->use_chanctx) {
Johannes Berg55de9082012-07-26 17:24:39 +02001178 sdata_info(sdata,
1179 "not handling channel switch with channel contexts\n");
Johannes Bergb4f286a12013-03-26 14:13:58 +01001180 ieee80211_queue_work(&local->hw,
Johannes Berg55de9082012-07-26 17:24:39 +02001181 &ifmgd->csa_connection_drop_work);
Simon Wunderlich246dc3f2012-11-30 19:17:27 +01001182 return;
Johannes Berg55de9082012-07-26 17:24:39 +02001183 }
1184
Johannes Bergb4f286a12013-03-26 14:13:58 +01001185 mutex_lock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001186 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
Johannes Bergb4f286a12013-03-26 14:13:58 +01001187 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001188 return;
1189 }
1190 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
1191 struct ieee80211_chanctx, conf);
1192 if (chanctx->refcount > 1) {
1193 sdata_info(sdata,
1194 "channel switch with multiple interfaces on the same channel, disconnecting\n");
Johannes Bergb4f286a12013-03-26 14:13:58 +01001195 ieee80211_queue_work(&local->hw,
Johannes Berg55de9082012-07-26 17:24:39 +02001196 &ifmgd->csa_connection_drop_work);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001197 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001198 return;
1199 }
Johannes Bergb4f286a12013-03-26 14:13:58 +01001200 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001201
Johannes Berg85220d72013-03-25 18:29:27 +01001202 local->csa_chandef = new_chandef;
Johannes Berg55de9082012-07-26 17:24:39 +02001203
Johannes Bergb4f286a12013-03-26 14:13:58 +01001204 if (mode)
1205 ieee80211_stop_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001206 IEEE80211_MAX_QUEUE_MAP,
Johannes Berg57eebdf2012-08-01 15:50:46 +02001207 IEEE80211_QUEUE_STOP_REASON_CSA);
1208
Johannes Bergb4f286a12013-03-26 14:13:58 +01001209 if (local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +02001210 /* use driver's channel switch callback */
Johannes Berg57eebdf2012-08-01 15:50:46 +02001211 struct ieee80211_channel_switch ch_switch = {
1212 .timestamp = timestamp,
Johannes Bergb4f286a12013-03-26 14:13:58 +01001213 .block_tx = mode,
Johannes Berg85220d72013-03-25 18:29:27 +01001214 .chandef = new_chandef,
Johannes Bergb4f286a12013-03-26 14:13:58 +01001215 .count = count,
Johannes Berg57eebdf2012-08-01 15:50:46 +02001216 };
1217
Johannes Bergb4f286a12013-03-26 14:13:58 +01001218 drv_channel_switch(local, &ch_switch);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001219 return;
1220 }
1221
1222 /* channel switch handled in software */
Johannes Bergb4f286a12013-03-26 14:13:58 +01001223 if (count <= 1)
1224 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001225 else
Johannes Bergcc32abd2009-05-15 11:52:31 +02001226 mod_timer(&ifmgd->chswitch_timer,
Johannes Bergb4f286a12013-03-26 14:13:58 +01001227 TU_TO_EXP_TIME(count * cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +02001228}
1229
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001230static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1231 struct ieee80211_channel *channel,
1232 const u8 *country_ie, u8 country_ie_len,
1233 const u8 *pwr_constr_elem)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001234{
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001235 struct ieee80211_country_ie_triplet *triplet;
1236 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1237 int i, chan_pwr, chan_increment, new_ap_level;
1238 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001239
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001240 /* Invalid IE */
1241 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001242 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001243
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001244 triplet = (void *)(country_ie + 3);
1245 country_ie_len -= 3;
1246
1247 switch (channel->band) {
1248 default:
1249 WARN_ON_ONCE(1);
1250 /* fall through */
1251 case IEEE80211_BAND_2GHZ:
1252 case IEEE80211_BAND_60GHZ:
1253 chan_increment = 1;
1254 break;
1255 case IEEE80211_BAND_5GHZ:
1256 chan_increment = 4;
1257 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001258 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001259
1260 /* find channel */
1261 while (country_ie_len >= 3) {
1262 u8 first_channel = triplet->chans.first_channel;
1263
1264 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1265 goto next;
1266
1267 for (i = 0; i < triplet->chans.num_channels; i++) {
1268 if (first_channel + i * chan_increment == chan) {
1269 have_chan_pwr = true;
1270 chan_pwr = triplet->chans.max_power;
1271 break;
1272 }
1273 }
1274 if (have_chan_pwr)
1275 break;
1276
1277 next:
1278 triplet++;
1279 country_ie_len -= 3;
1280 }
1281
1282 if (!have_chan_pwr)
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001283 return 0;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001284
1285 new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
1286
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001287 if (sdata->ap_power_level == new_ap_level)
1288 return 0;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001289
1290 sdata_info(sdata,
1291 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1292 new_ap_level, chan_pwr, *pwr_constr_elem,
1293 sdata->u.mgd.bssid);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001294 sdata->ap_power_level = new_ap_level;
1295 if (__ieee80211_recalc_txpower(sdata))
1296 return BSS_CHANGED_TXPOWER;
1297 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001298}
1299
Johannes Berg965beda2009-04-16 13:17:24 +02001300/* powersave */
1301static void ieee80211_enable_ps(struct ieee80211_local *local,
1302 struct ieee80211_sub_if_data *sdata)
1303{
1304 struct ieee80211_conf *conf = &local->hw.conf;
1305
Johannes Bergd5edaed2009-04-22 23:02:51 +02001306 /*
1307 * If we are scanning right now then the parameters will
1308 * take effect when scan finishes.
1309 */
Helmut Schaafbe9c422009-07-23 12:14:04 +02001310 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +02001311 return;
1312
Johannes Berg965beda2009-04-16 13:17:24 +02001313 if (conf->dynamic_ps_timeout > 0 &&
1314 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
1315 mod_timer(&local->dynamic_ps_timer, jiffies +
1316 msecs_to_jiffies(conf->dynamic_ps_timeout));
1317 } else {
1318 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1319 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +05301320
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001321 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
1322 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
1323 return;
1324
1325 conf->flags |= IEEE80211_CONF_PS;
1326 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +02001327 }
1328}
1329
1330static void ieee80211_change_ps(struct ieee80211_local *local)
1331{
1332 struct ieee80211_conf *conf = &local->hw.conf;
1333
1334 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +02001335 ieee80211_enable_ps(local, local->ps_sdata);
1336 } else if (conf->flags & IEEE80211_CONF_PS) {
1337 conf->flags &= ~IEEE80211_CONF_PS;
1338 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1339 del_timer_sync(&local->dynamic_ps_timer);
1340 cancel_work_sync(&local->dynamic_ps_enable_work);
1341 }
1342}
1343
Jason Young808118c2011-03-10 16:43:19 -08001344static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1345{
1346 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1347 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001348 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001349
1350 if (!mgd->powersave)
1351 return false;
1352
Johannes Berg05cb9102011-10-28 11:59:47 +02001353 if (mgd->broken_ap)
1354 return false;
1355
Jason Young808118c2011-03-10 16:43:19 -08001356 if (!mgd->associated)
1357 return false;
1358
Jason Young808118c2011-03-10 16:43:19 -08001359 if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
1360 IEEE80211_STA_CONNECTION_POLL))
1361 return false;
1362
Alexander Bondarce857882013-05-06 17:17:04 +03001363 if (!sdata->vif.bss_conf.dtim_period)
1364 return false;
1365
Jason Young808118c2011-03-10 16:43:19 -08001366 rcu_read_lock();
1367 sta = sta_info_get(sdata, mgd->bssid);
1368 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001369 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001370 rcu_read_unlock();
1371
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001372 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001373}
1374
Johannes Berg965beda2009-04-16 13:17:24 +02001375/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +02001376void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +02001377{
1378 struct ieee80211_sub_if_data *sdata, *found = NULL;
1379 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001380 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001381
1382 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
1383 local->ps_sdata = NULL;
1384 return;
1385 }
1386
1387 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01001388 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001389 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301390 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1391 /* If an AP vif is found, then disable PS
1392 * by setting the count to zero thereby setting
1393 * ps_sdata to NULL.
1394 */
1395 count = 0;
1396 break;
1397 }
Johannes Berg965beda2009-04-16 13:17:24 +02001398 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1399 continue;
1400 found = sdata;
1401 count++;
1402 }
1403
Jason Young808118c2011-03-10 16:43:19 -08001404 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg10f644a2009-04-16 13:17:25 +02001405 s32 beaconint_us;
1406
1407 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +02001408 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +02001409
1410 beaconint_us = ieee80211_tu_to_usec(
1411 found->vif.bss_conf.beacon_int);
1412
Juuso Oikarinenff616382010-06-09 09:51:52 +03001413 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001414 if (timeout < 0) {
1415 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +03001416 * Go to full PSM if the user configures a very low
1417 * latency requirement.
Eliad Peller0ab82b02010-12-03 02:16:23 +02001418 * The 2000 second value is there for compatibility
1419 * until the PM_QOS_NETWORK_LATENCY is configured
1420 * with real values.
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001421 */
Eliad Peller0ab82b02010-12-03 02:16:23 +02001422 if (latency > (1900 * USEC_PER_MSEC) &&
1423 latency != (2000 * USEC_PER_SEC))
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001424 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001425 else
1426 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001427 }
Johannes Berg09b85562013-02-06 23:07:41 +01001428 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001429
Johannes Berg04fe2032009-04-22 18:44:37 +02001430 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +02001431 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +02001432 } else {
Johannes Berg04fe2032009-04-22 18:44:37 +02001433 int maxslp = 1;
Johannes Berg826262c2012-12-10 16:38:14 +02001434 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg56007a02010-01-26 14:19:52 +01001435
1436 /* If the TIM IE is invalid, pretend the value is 1 */
1437 if (!dtimper)
1438 dtimper = 1;
1439 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +02001440 maxslp = min_t(int, dtimper,
1441 latency / beaconint_us);
1442
Johannes Berg9ccebe62009-04-23 10:32:36 +02001443 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +01001444 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +02001445 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +02001446 }
Johannes Berg10f644a2009-04-16 13:17:25 +02001447 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001448 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001449 }
Johannes Berg965beda2009-04-16 13:17:24 +02001450
1451 ieee80211_change_ps(local);
1452}
1453
Eliad Pellerab095872012-07-27 12:33:22 +03001454void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1455{
1456 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1457
1458 if (sdata->vif.bss_conf.ps != ps_allowed) {
1459 sdata->vif.bss_conf.ps = ps_allowed;
1460 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1461 }
1462}
1463
Johannes Berg965beda2009-04-16 13:17:24 +02001464void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1465{
1466 struct ieee80211_local *local =
1467 container_of(work, struct ieee80211_local,
1468 dynamic_ps_disable_work);
1469
1470 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1471 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1472 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1473 }
1474
1475 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001476 IEEE80211_MAX_QUEUE_MAP,
Johannes Berg965beda2009-04-16 13:17:24 +02001477 IEEE80211_QUEUE_STOP_REASON_PS);
1478}
1479
1480void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1481{
1482 struct ieee80211_local *local =
1483 container_of(work, struct ieee80211_local,
1484 dynamic_ps_enable_work);
1485 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001486 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301487 unsigned long flags;
1488 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001489
1490 /* can only happen when PS was just disabled anyway */
1491 if (!sdata)
1492 return;
1493
Christian Lamparter5e340692011-06-30 21:08:43 +02001494 ifmgd = &sdata->u.mgd;
1495
Johannes Berg965beda2009-04-16 13:17:24 +02001496 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1497 return;
1498
Johannes Berg09b85562013-02-06 23:07:41 +01001499 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001500 /* don't enter PS if TX frames are pending */
1501 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301502 mod_timer(&local->dynamic_ps_timer, jiffies +
1503 msecs_to_jiffies(
1504 local->hw.conf.dynamic_ps_timeout));
1505 return;
1506 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001507
1508 /*
1509 * transmission can be stopped by others which leads to
1510 * dynamic_ps_timer expiry. Postpone the ps timer if it
1511 * is not the actual idle state.
1512 */
1513 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1514 for (q = 0; q < local->hw.queues; q++) {
1515 if (local->queue_stop_reasons[q]) {
1516 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1517 flags);
1518 mod_timer(&local->dynamic_ps_timer, jiffies +
1519 msecs_to_jiffies(
1520 local->hw.conf.dynamic_ps_timeout));
1521 return;
1522 }
1523 }
1524 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301525 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301526
Vivek Natarajan375177b2010-02-09 14:50:28 +05301527 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301528 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Johannes Berga1598382013-03-26 22:02:42 +01001529 if (drv_tx_frames_pending(local)) {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301530 mod_timer(&local->dynamic_ps_timer, jiffies +
1531 msecs_to_jiffies(
1532 local->hw.conf.dynamic_ps_timeout));
Johannes Berga1598382013-03-26 22:02:42 +01001533 } else {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301534 ieee80211_send_nullfunc(local, sdata, 1);
1535 /* Flush to get the tx status of nullfunc frame */
Johannes Berg39ecc012013-02-13 12:11:00 +01001536 ieee80211_flush_queues(local, sdata);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301537 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301538 }
1539
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001540 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
1541 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301542 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1543 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1544 local->hw.conf.flags |= IEEE80211_CONF_PS;
1545 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1546 }
Johannes Berg965beda2009-04-16 13:17:24 +02001547}
1548
1549void ieee80211_dynamic_ps_timer(unsigned long data)
1550{
1551 struct ieee80211_local *local = (void *) data;
1552
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -07001553 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +02001554 return;
1555
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001556 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001557}
1558
Simon Wunderlich164eb022013-02-08 18:16:20 +01001559void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1560{
1561 struct delayed_work *delayed_work =
1562 container_of(work, struct delayed_work, work);
1563 struct ieee80211_sub_if_data *sdata =
1564 container_of(delayed_work, struct ieee80211_sub_if_data,
1565 dfs_cac_timer_work);
1566
1567 ieee80211_vif_release_channel(sdata);
1568
1569 cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
1570}
1571
Johannes Berg60f8b392008-09-08 17:44:22 +02001572/* MLME */
Johannes Berg7d257452012-07-06 17:37:43 +02001573static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +02001574 struct ieee80211_sub_if_data *sdata,
Johannes Berg4a3cb702013-02-12 16:43:19 +01001575 const u8 *wmm_param, size_t wmm_param_len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001576{
Jiri Bencf0706e82007-05-05 11:45:53 -07001577 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +02001578 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001579 size_t left;
1580 int count;
Johannes Berg4a3cb702013-02-12 16:43:19 +01001581 const u8 *pos;
1582 u8 uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001583
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001584 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001585 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001586
Johannes Berg32c50572012-03-28 11:04:29 +02001587 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001588 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001589
1590 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001591 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001592
Jiri Bencf0706e82007-05-05 11:45:53 -07001593 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001594 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001595
1596 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001597 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001598
Jiri Bencf0706e82007-05-05 11:45:53 -07001599 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +01001600 if (count == ifmgd->wmm_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001601 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001602 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001603
1604 pos = wmm_param + 8;
1605 left = wmm_param_len - 8;
1606
1607 memset(&params, 0, sizeof(params));
1608
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001609 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001610 for (; left >= 4; left -= 4, pos += 4) {
1611 int aci = (pos[0] >> 5) & 0x03;
1612 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001613 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001614 int queue;
1615
1616 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001617 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +02001618 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +02001619 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001620 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001621 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1622 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001623 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001624 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +02001625 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +02001626 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001627 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001628 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1629 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001630 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001631 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +02001632 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +02001633 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001634 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02001635 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1636 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001637 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001638 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001639 default:
Johannes Berge100bb62008-04-30 18:51:21 +02001640 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +02001641 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001642 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02001643 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1644 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001645 break;
1646 }
1647
1648 params.aifs = pos[0] & 0x0f;
1649 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1650 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +02001651 params.txop = get_unaligned_le16(pos + 2);
Alexander Bondar908f8d02013-04-07 09:53:30 +03001652 params.acm = acm;
Kalle Valoab133152010-01-12 10:42:31 +02001653 params.uapsd = uapsd;
1654
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001655 mlme_dbg(sdata,
1656 "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
1657 queue, aci, acm,
1658 params.aifs, params.cw_min, params.cw_max,
1659 params.txop, params.uapsd);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001660 sdata->tx_conf[queue] = params;
1661 if (drv_conf_tx(local, sdata, queue, &params))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001662 sdata_err(sdata,
1663 "failed to set TX queue parameters for queue %d\n",
1664 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -07001665 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001666
1667 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02001668 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02001669 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001670}
1671
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001672static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1673{
1674 lockdep_assert_held(&sdata->local->mtx);
1675
1676 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1677 IEEE80211_STA_BEACON_POLL);
1678 ieee80211_run_deferred_scan(sdata->local);
1679}
1680
1681static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1682{
1683 mutex_lock(&sdata->local->mtx);
1684 __ieee80211_stop_poll(sdata);
1685 mutex_unlock(&sdata->local->mtx);
1686}
1687
Johannes Berg7a5158e2008-10-08 10:59:33 +02001688static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1689 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02001690{
Johannes Bergbda39332008-10-11 01:51:51 +02001691 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001692 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001693 bool use_protection;
1694 bool use_short_preamble;
1695 bool use_short_slot;
1696
1697 if (erp_valid) {
1698 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1699 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1700 } else {
1701 use_protection = false;
1702 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1703 }
1704
1705 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Johannes Berg55de9082012-07-26 17:24:39 +02001706 if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01001707 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02001708
Johannes Berg471b3ef2007-12-28 14:32:58 +01001709 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01001710 bss_conf->use_cts_prot = use_protection;
1711 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02001712 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02001713
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001714 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001715 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001716 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02001717 }
Daniel Draked9430a32007-07-27 15:43:24 +02001718
Johannes Berg7a5158e2008-10-08 10:59:33 +02001719 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02001720 bss_conf->use_short_slot = use_short_slot;
1721 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04001722 }
1723
1724 return changed;
1725}
1726
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001727static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001728 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02001729 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07001730{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001731 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001732 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001733 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001734
Johannes Bergae5eb022008-10-14 16:58:37 +02001735 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001736 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03001737 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001738
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01001739 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
Ben Greear59c1ec22013-03-19 14:19:56 -07001740 beacon_loss_count * bss_conf->beacon_int));
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01001741
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001742 sdata->u.mgd.associated = cbss;
1743 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01001744
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001745 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1746
Johannes Berg488dd7b2012-10-29 20:08:01 +01001747 if (sdata->vif.p2p) {
Johannes Berg9caf0362012-11-29 01:25:20 +01001748 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01001749
Johannes Berg9caf0362012-11-29 01:25:20 +01001750 rcu_read_lock();
1751 ies = rcu_dereference(cbss->ies);
1752 if (ies) {
Johannes Berg9caf0362012-11-29 01:25:20 +01001753 int ret;
1754
1755 ret = cfg80211_get_p2p_attr(
1756 ies->data, ies->len,
1757 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001758 (u8 *) &bss_conf->p2p_noa_attr,
1759 sizeof(bss_conf->p2p_noa_attr));
Johannes Berg9caf0362012-11-29 01:25:20 +01001760 if (ret >= 2) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001761 sdata->u.mgd.p2p_noa_index =
1762 bss_conf->p2p_noa_attr.index;
Johannes Berg9caf0362012-11-29 01:25:20 +01001763 bss_info_changed |= BSS_CHANGED_P2P_PS;
Johannes Berg9caf0362012-11-29 01:25:20 +01001764 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01001765 }
Johannes Berg9caf0362012-11-29 01:25:20 +01001766 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01001767 }
1768
Johannes Bergb291ba12009-07-10 15:29:03 +02001769 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001770 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001771
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001772 ieee80211_led_assoc(local, 1);
1773
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02001774 if (sdata->u.mgd.assoc_data->have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02001775 /*
1776 * If the AP is buggy we may get here with no DTIM period
1777 * known, so assume it's 1 which is the only safe assumption
1778 * in that case, although if the TIM IE is broken powersave
1779 * probably just won't work at all.
1780 */
1781 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02001782 bss_info_changed |= BSS_CHANGED_DTIM_PERIOD;
Johannes Berg826262c2012-12-10 16:38:14 +02001783 } else {
Johannes Berge5b900d2010-07-29 16:08:55 +02001784 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02001785 }
Johannes Berge5b900d2010-07-29 16:08:55 +02001786
Juuso Oikarinen68542962010-06-09 13:43:26 +03001787 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02001788
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001789 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01001790 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03001791 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001792 bss_info_changed |= BSS_CHANGED_CQM;
1793
Juuso Oikarinen68542962010-06-09 13:43:26 +03001794 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01001795 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03001796 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001797
Johannes Bergae5eb022008-10-14 16:58:37 +02001798 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03001799
Johannes Berg056508d2009-07-30 21:43:55 +02001800 mutex_lock(&local->iflist_mtx);
1801 ieee80211_recalc_ps(local, -1);
1802 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02001803
Johannes Berg04ecd252012-09-11 14:34:12 +02001804 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03001805 ieee80211_recalc_ps_vif(sdata);
1806
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001807 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001808}
1809
Jouni Malinene69e95d2010-03-29 23:29:31 -07001810static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01001811 u16 stype, u16 reason, bool tx,
1812 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03001813{
Johannes Berg46900292009-02-15 12:44:28 +01001814 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001815 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01001816 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001817
Johannes Berg8d61ffa2013-05-10 12:32:47 +02001818 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001819
Johannes Berg37ad3882012-02-24 13:50:54 +01001820 if (WARN_ON_ONCE(tx && !frame_buf))
1821 return;
1822
Johannes Bergb291ba12009-07-10 15:29:03 +02001823 if (WARN_ON(!ifmgd->associated))
1824 return;
1825
David Spinadel79543d82012-06-12 09:59:45 +03001826 ieee80211_stop_poll(sdata);
1827
Johannes Berg77fdaa12009-07-07 03:45:17 +02001828 ifmgd->associated = NULL;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001829 netif_carrier_off(sdata->dev);
1830
Eliad Peller88bc40e2012-07-12 17:35:33 +03001831 /*
1832 * if we want to get out of ps before disassoc (why?) we have
1833 * to do it before sending disassoc, as otherwise the null-packet
1834 * won't be valid.
1835 */
1836 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1837 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1838 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1839 }
1840 local->ps_sdata = NULL;
1841
Eliad Pellerab095872012-07-27 12:33:22 +03001842 /* disable per-vif ps */
1843 ieee80211_recalc_ps_vif(sdata);
1844
Eliad Pellerf8239812012-06-27 14:18:22 +03001845 /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
1846 if (tx)
Johannes Berg39ecc012013-02-13 12:11:00 +01001847 ieee80211_flush_queues(local, sdata);
Eliad Pellerf8239812012-06-27 14:18:22 +03001848
Johannes Berg37ad3882012-02-24 13:50:54 +01001849 /* deauthenticate/disassociate now */
1850 if (tx || frame_buf)
Eliad Peller88a9e312012-06-01 11:14:03 +03001851 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
1852 reason, tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01001853
1854 /* flush out frame */
1855 if (tx)
Johannes Berg39ecc012013-02-13 12:11:00 +01001856 ieee80211_flush_queues(local, sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01001857
Eliad Peller88a9e312012-06-01 11:14:03 +03001858 /* clear bssid only after building the needed mgmt frames */
1859 memset(ifmgd->bssid, 0, ETH_ALEN);
1860
Johannes Berg37ad3882012-02-24 13:50:54 +01001861 /* remove AP and TDLS peers */
Johannes Berg051007d2012-12-13 23:49:02 +01001862 sta_info_flush_defer(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01001863
1864 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001865 changed |= ieee80211_reset_erp_info(sdata);
1866
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001867 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001868 changed |= BSS_CHANGED_ASSOC;
1869 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001870
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001871 ifmgd->p2p_noa_index = -1;
1872 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1873 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01001874
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01001875 /* on the next assoc, re-program HT/VHT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08001876 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
1877 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01001878 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
1879 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
Johannes Berg413ad502009-05-08 21:21:06 +02001880
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001881 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301882
Kalle Valo520eb822008-12-18 23:35:27 +02001883 del_timer_sync(&local->dynamic_ps_timer);
1884 cancel_work_sync(&local->dynamic_ps_enable_work);
1885
Juuso Oikarinen68542962010-06-09 13:43:26 +03001886 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01001887 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03001888 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001889
Johannes Berg3abead52012-03-02 15:56:59 +01001890 sdata->vif.bss_conf.qos = false;
1891 changed |= BSS_CHANGED_QOS;
1892
Johannes Berg0aaffa92010-05-05 15:28:27 +02001893 /* The BSSID (not really interesting) and HT changed */
1894 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001895 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001896
Johannes Berg3abead52012-03-02 15:56:59 +01001897 /* disassociated - set to defaults now */
1898 ieee80211_set_wmm_default(sdata, false);
1899
Johannes Bergb9dcf712010-08-27 12:35:54 +02001900 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1901 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1902 del_timer_sync(&sdata->u.mgd.timer);
1903 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02001904
Johannes Berg826262c2012-12-10 16:38:14 +02001905 sdata->vif.bss_conf.dtim_period = 0;
1906
Johannes Berg028e8da02012-11-26 11:57:41 +01001907 ifmgd->flags = 0;
1908 ieee80211_vif_release_channel(sdata);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001909}
Jiri Bencf0706e82007-05-05 11:45:53 -07001910
Kalle Valo3cf335d2009-03-22 21:57:06 +02001911void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1912 struct ieee80211_hdr *hdr)
1913{
1914 /*
1915 * We can postpone the mgd.timer whenever receiving unicast frames
1916 * from AP because we know that the connection is working both ways
1917 * at that time. But multicast frames (and hence also beacons) must
1918 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001919 * data idle periods for sending the periodic probe request to the
1920 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001921 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001922 if (is_multicast_ether_addr(hdr->addr1))
1923 return;
1924
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001925 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02001926}
Jiri Bencf0706e82007-05-05 11:45:53 -07001927
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001928static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1929{
1930 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001931 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001932
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001933 mutex_lock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001934 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001935 IEEE80211_STA_CONNECTION_POLL))) {
1936 mutex_unlock(&local->mtx);
1937 return;
1938 }
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001939
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001940 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001941
1942 mutex_lock(&local->iflist_mtx);
1943 ieee80211_recalc_ps(local, -1);
1944 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001945
1946 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001947 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001948
1949 /*
1950 * We've received a probe response, but are not sure whether
1951 * we have or will be receiving any beacons or data, so let's
1952 * schedule the timers again, just in case.
1953 */
1954 ieee80211_sta_reset_beacon_monitor(sdata);
1955
1956 mod_timer(&ifmgd->conn_mon_timer,
1957 round_jiffies_up(jiffies +
1958 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001959out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001960 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001961}
1962
1963void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001964 struct ieee80211_hdr *hdr, bool ack)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001965{
Felix Fietkau75706d02010-12-02 21:01:07 +01001966 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001967 return;
1968
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001969 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1970 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001971 if (ack)
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01001972 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001973 else
1974 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001975 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01001976 return;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001977 }
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01001978
1979 if (ack)
1980 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001981}
1982
Maxim Levitskya43abf22009-07-31 18:54:12 +03001983static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1984{
1985 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1986 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001987 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08001988 u8 unicast_limit = max(1, max_probe_tries - 3);
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001989
1990 /*
1991 * Try sending broadcast probe requests for the last three
1992 * probe requests after the first ones failed since some
1993 * buggy APs only support broadcast probe requests.
1994 */
1995 if (ifmgd->probe_send_count >= unicast_limit)
1996 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03001997
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001998 /*
1999 * When the hardware reports an accurate Tx ACK status, it's
2000 * better to send a nullfunc frame instead of a probe request,
2001 * as it will kick us off the AP quickly if we aren't associated
2002 * anymore. The timeout will be reset if the frame is ACKed by
2003 * the AP.
2004 */
Soumik Das992e68b2012-05-20 15:31:13 +05302005 ifmgd->probe_send_count++;
2006
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002007 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
2008 ifmgd->nullfunc_failed = false;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002009 ieee80211_send_nullfunc(sdata->local, sdata, 0);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002010 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002011 int ssid_len;
2012
Johannes Berg9caf0362012-11-29 01:25:20 +01002013 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002014 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002015 if (WARN_ON_ONCE(ssid == NULL))
2016 ssid_len = 0;
2017 else
2018 ssid_len = ssid[1];
2019
2020 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002021 0, (u32) -1, true, 0,
Johannes Berg55de9082012-07-26 17:24:39 +02002022 ifmgd->associated->channel, false);
Johannes Berg9caf0362012-11-29 01:25:20 +01002023 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002024 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03002025
Ben Greear180205b2011-02-04 15:30:24 -08002026 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002027 run_again(sdata, ifmgd->probe_timeout);
Rajkumar Manoharanf69b9c72012-03-15 06:15:26 +05302028 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Johannes Berg39ecc012013-02-13 12:11:00 +01002029 ieee80211_flush_queues(sdata->local, sdata);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002030}
2031
Johannes Bergb291ba12009-07-10 15:29:03 +02002032static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2033 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02002034{
Kalle Valo04de8382009-03-22 21:57:35 +02002035 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002036 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02002037
Johannes Berg9607e6b2009-12-23 13:15:31 +01002038 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02002039 return;
2040
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002041 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002042
2043 if (!ifmgd->associated)
2044 goto out;
2045
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002046 mutex_lock(&sdata->local->mtx);
2047
2048 if (sdata->local->tmp_channel || sdata->local->scanning) {
2049 mutex_unlock(&sdata->local->mtx);
2050 goto out;
2051 }
2052
Ben Greeara13fbe52013-03-25 11:19:35 -07002053 if (beacon) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002054 mlme_dbg_ratelimited(sdata,
Ben Greear59c1ec22013-03-19 14:19:56 -07002055 "detected beacon loss from AP (missed %d beacons) - probing\n",
2056 beacon_loss_count);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002057
Ben Greeara13fbe52013-03-25 11:19:35 -07002058 ieee80211_cqm_rssi_notify(&sdata->vif,
2059 NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
2060 GFP_KERNEL);
2061 }
Kalle Valo04de8382009-03-22 21:57:35 +02002062
Johannes Bergb291ba12009-07-10 15:29:03 +02002063 /*
2064 * The driver/our work has already reported this event or the
2065 * connection monitoring has kicked in and we have already sent
2066 * a probe request. Or maybe the AP died and the driver keeps
2067 * reporting until we disassociate...
2068 *
2069 * In either case we have to ignore the current call to this
2070 * function (except for setting the correct probe reason bit)
2071 * because otherwise we would reset the timer every time and
2072 * never check whether we received a probe response!
2073 */
2074 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
2075 IEEE80211_STA_CONNECTION_POLL))
2076 already = true;
2077
2078 if (beacon)
2079 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
2080 else
2081 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2082
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002083 mutex_unlock(&sdata->local->mtx);
2084
Johannes Bergb291ba12009-07-10 15:29:03 +02002085 if (already)
2086 goto out;
2087
Johannes Berg4e751842009-06-10 15:16:52 +02002088 mutex_lock(&sdata->local->iflist_mtx);
2089 ieee80211_recalc_ps(sdata->local, -1);
2090 mutex_unlock(&sdata->local->iflist_mtx);
2091
Maxim Levitskya43abf22009-07-31 18:54:12 +03002092 ifmgd->probe_send_count = 0;
2093 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002094 out:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002095 sdata_unlock(sdata);
Kalle Valo04de8382009-03-22 21:57:35 +02002096}
2097
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002098struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2099 struct ieee80211_vif *vif)
2100{
2101 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2102 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002103 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002104 struct sk_buff *skb;
2105 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002106 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002107
2108 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2109 return NULL;
2110
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002111 sdata_assert_lock(sdata);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002112
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002113 if (ifmgd->associated)
2114 cbss = ifmgd->associated;
2115 else if (ifmgd->auth_data)
2116 cbss = ifmgd->auth_data->bss;
2117 else if (ifmgd->assoc_data)
2118 cbss = ifmgd->assoc_data->bss;
2119 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002120 return NULL;
2121
Johannes Berg9caf0362012-11-29 01:25:20 +01002122 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002123 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002124 if (WARN_ON_ONCE(ssid == NULL))
2125 ssid_len = 0;
2126 else
2127 ssid_len = ssid[1];
2128
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002129 skb = ieee80211_build_probe_req(sdata, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02002130 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02002131 ssid + 2, ssid_len,
Johannes Berg85a237f2011-07-18 18:08:36 +02002132 NULL, 0, true);
Johannes Berg9caf0362012-11-29 01:25:20 +01002133 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002134
2135 return skb;
2136}
2137EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2138
Johannes Bergeef9e542013-01-29 13:09:34 +01002139static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002140{
2141 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002142 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002143
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002144 sdata_lock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002145 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002146 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002147 return;
2148 }
2149
Johannes Berg37ad3882012-02-24 13:50:54 +01002150 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2151 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Johannes Bergeef9e542013-01-29 13:09:34 +01002152 true, frame_buf);
Johannes Berg882a7c62012-08-01 22:32:45 +02002153 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
Johannes Berg5b36ebd2013-02-13 14:21:45 +01002154 ieee80211_wake_queues_by_reason(&sdata->local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01002155 IEEE80211_MAX_QUEUE_MAP,
Johannes Berg5b36ebd2013-02-13 14:21:45 +01002156 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002157
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002158 cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002159 sdata_unlock(sdata);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002160}
2161
Johannes Bergcc74c0c2012-08-01 16:49:34 +02002162static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02002163{
2164 struct ieee80211_sub_if_data *sdata =
2165 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002166 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002167 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2168 struct sta_info *sta;
2169
2170 if (ifmgd->associated) {
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05302171 rcu_read_lock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08002172 sta = sta_info_get(sdata, ifmgd->bssid);
2173 if (sta)
2174 sta->beacon_loss_count++;
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05302175 rcu_read_unlock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08002176 }
Johannes Bergb291ba12009-07-10 15:29:03 +02002177
Johannes Berg682bd382013-01-29 13:13:50 +01002178 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02002179 sdata_info(sdata, "Connection to AP %pM lost\n",
2180 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01002181 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02002182 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002183 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02002184 }
2185}
2186
2187static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2188{
2189 struct ieee80211_sub_if_data *sdata =
2190 container_of(work, struct ieee80211_sub_if_data,
2191 u.mgd.csa_connection_drop_work);
2192
Johannes Bergeef9e542013-01-29 13:09:34 +01002193 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002194}
2195
Kalle Valo04de8382009-03-22 21:57:35 +02002196void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2197{
2198 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002199 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02002200
Johannes Bergb5878a22010-04-07 16:48:40 +02002201 trace_api_beacon_loss(sdata);
2202
Johannes Berg682bd382013-01-29 13:13:50 +01002203 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002204 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002205}
2206EXPORT_SYMBOL(ieee80211_beacon_loss);
2207
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002208void ieee80211_connection_loss(struct ieee80211_vif *vif)
2209{
2210 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2211 struct ieee80211_hw *hw = &sdata->local->hw;
2212
Johannes Bergb5878a22010-04-07 16:48:40 +02002213 trace_api_connection_loss(sdata);
2214
Johannes Berg682bd382013-01-29 13:13:50 +01002215 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002216 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2217}
2218EXPORT_SYMBOL(ieee80211_connection_loss);
2219
2220
Johannes Berg66e67e42012-01-20 13:55:27 +01002221static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2222 bool assoc)
2223{
2224 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2225
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002226 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002227
Johannes Berg66e67e42012-01-20 13:55:27 +01002228 if (!assoc) {
2229 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2230
2231 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2232 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002233 sdata->u.mgd.flags = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002234 ieee80211_vif_release_channel(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002235 }
2236
Johannes Berg5b112d32013-02-01 01:49:58 +01002237 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002238 kfree(auth_data);
2239 sdata->u.mgd.auth_data = NULL;
2240}
2241
2242static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2243 struct ieee80211_mgmt *mgmt, size_t len)
2244{
Johannes Berg1672c0e32013-01-29 15:02:27 +01002245 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01002246 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2247 u8 *pos;
2248 struct ieee802_11_elems elems;
Johannes Berg1672c0e32013-01-29 15:02:27 +01002249 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002250
2251 pos = mgmt->u.auth.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002252 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002253 if (!elems.challenge)
2254 return;
2255 auth_data->expected_transaction = 4;
Johannes Berga1845fc2012-06-27 13:18:36 +02002256 drv_mgd_prepare_tx(sdata->local, sdata);
Johannes Berg1672c0e32013-01-29 15:02:27 +01002257 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
2258 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2259 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03002260 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01002261 elems.challenge - 2, elems.challenge_len + 2,
2262 auth_data->bss->bssid, auth_data->bss->bssid,
2263 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002264 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002265}
2266
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002267static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2268 struct ieee80211_mgmt *mgmt, size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002269{
2270 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2271 u8 bssid[ETH_ALEN];
2272 u16 auth_alg, auth_transaction, status_code;
2273 struct sta_info *sta;
2274
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002275 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002276
2277 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002278 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002279
2280 if (!ifmgd->auth_data || ifmgd->auth_data->done)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002281 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002282
2283 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2284
Joe Perchesb203ca32012-05-08 18:56:52 +00002285 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002286 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002287
2288 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2289 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2290 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2291
2292 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002293 auth_transaction != ifmgd->auth_data->expected_transaction) {
2294 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2295 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2296 auth_transaction,
2297 ifmgd->auth_data->expected_transaction);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002298 return;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002299 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002300
2301 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002302 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2303 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002304 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002305 cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, len);
2306 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002307 }
2308
2309 switch (ifmgd->auth_data->algorithm) {
2310 case WLAN_AUTH_OPEN:
2311 case WLAN_AUTH_LEAP:
2312 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002313 case WLAN_AUTH_SAE:
Johannes Berg66e67e42012-01-20 13:55:27 +01002314 break;
2315 case WLAN_AUTH_SHARED_KEY:
2316 if (ifmgd->auth_data->expected_transaction != 4) {
2317 ieee80211_auth_challenge(sdata, mgmt, len);
2318 /* need another frame */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002319 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002320 }
2321 break;
2322 default:
2323 WARN_ONCE(1, "invalid auth alg %d",
2324 ifmgd->auth_data->algorithm);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002325 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002326 }
2327
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002328 sdata_info(sdata, "authenticated\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002329 ifmgd->auth_data->done = true;
2330 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
Johannes Berg89afe612013-02-13 15:39:57 +01002331 ifmgd->auth_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002332 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01002333
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002334 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2335 ifmgd->auth_data->expected_transaction != 2) {
2336 /*
2337 * Report auth frame to user space for processing since another
2338 * round of Authentication frames is still needed.
2339 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002340 cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, len);
2341 return;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002342 }
2343
Johannes Berg66e67e42012-01-20 13:55:27 +01002344 /* move station state to auth */
2345 mutex_lock(&sdata->local->sta_mtx);
2346 sta = sta_info_get(sdata, bssid);
2347 if (!sta) {
2348 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2349 goto out_err;
2350 }
2351 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002352 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002353 goto out_err;
2354 }
2355 mutex_unlock(&sdata->local->sta_mtx);
2356
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002357 cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, len);
2358 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002359 out_err:
2360 mutex_unlock(&sdata->local->sta_mtx);
2361 /* ignore frame -- wait for timeout */
Johannes Berg66e67e42012-01-20 13:55:27 +01002362}
2363
2364
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002365static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
2366 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002367{
Johannes Berg46900292009-02-15 12:44:28 +01002368 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002369 const u8 *bssid = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07002370 u16 reason_code;
2371
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002372 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002373
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002374 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002375 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002376
Johannes Berg66e67e42012-01-20 13:55:27 +01002377 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002378 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002379 return;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002380
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002381 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002382
2383 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
2384
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002385 sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n",
2386 bssid, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002387
Johannes Berg37ad3882012-02-24 13:50:54 +01002388 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2389
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002390 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07002391}
2392
2393
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002394static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2395 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002396{
Johannes Berg46900292009-02-15 12:44:28 +01002397 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002398 u16 reason_code;
2399
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002400 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002401
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002402 if (len < 24 + 2)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002403 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002404
Johannes Berg66e67e42012-01-20 13:55:27 +01002405 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002406 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002407 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002408
2409 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2410
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002411 sdata_info(sdata, "disassociated from %pM (Reason: %u)\n",
2412 mgmt->sa, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002413
Johannes Berg37ad3882012-02-24 13:50:54 +01002414 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2415
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002416 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07002417}
2418
Christian Lamparterc74d0842011-10-15 00:14:49 +02002419static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2420 u8 *supp_rates, unsigned int supp_rates_len,
2421 u32 *rates, u32 *basic_rates,
2422 bool *have_higher_than_11mbit,
2423 int *min_rate, int *min_rate_index)
2424{
2425 int i, j;
2426
2427 for (i = 0; i < supp_rates_len; i++) {
2428 int rate = (supp_rates[i] & 0x7f) * 5;
2429 bool is_basic = !!(supp_rates[i] & 0x80);
2430
2431 if (rate > 110)
2432 *have_higher_than_11mbit = true;
2433
2434 /*
2435 * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
2436 * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
2437 *
2438 * Note: Even through the membership selector and the basic
2439 * rate flag share the same bit, they are not exactly
2440 * the same.
2441 */
2442 if (!!(supp_rates[i] & 0x80) &&
2443 (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
2444 continue;
2445
2446 for (j = 0; j < sband->n_bitrates; j++) {
2447 if (sband->bitrates[j].bitrate == rate) {
2448 *rates |= BIT(j);
2449 if (is_basic)
2450 *basic_rates |= BIT(j);
2451 if (rate < *min_rate) {
2452 *min_rate = rate;
2453 *min_rate_index = j;
2454 }
2455 break;
2456 }
2457 }
2458 }
2459}
Jiri Bencf0706e82007-05-05 11:45:53 -07002460
Johannes Berg66e67e42012-01-20 13:55:27 +01002461static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2462 bool assoc)
2463{
2464 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2465
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002466 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002467
Johannes Berg66e67e42012-01-20 13:55:27 +01002468 if (!assoc) {
2469 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2470
2471 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2472 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002473 sdata->u.mgd.flags = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002474 ieee80211_vif_release_channel(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002475 }
2476
2477 kfree(assoc_data);
2478 sdata->u.mgd.assoc_data = NULL;
2479}
2480
2481static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2482 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002483 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002484{
Johannes Berg46900292009-02-15 12:44:28 +01002485 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002486 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01002487 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07002488 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002489 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002490 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002491 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02002492 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Bergae5eb022008-10-14 16:58:37 +02002493 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02002494 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -07002495
Johannes Bergaf6b6372009-12-23 13:15:35 +01002496 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07002497
Jiri Bencf0706e82007-05-05 11:45:53 -07002498 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002499 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07002500
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002501 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002502 sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
2503 aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002504 aid &= ~(BIT(15) | BIT(14));
2505
Johannes Berg05cb9102011-10-28 11:59:47 +02002506 ifmgd->broken_ap = false;
2507
2508 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002509 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
2510 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02002511 aid = 0;
2512 ifmgd->broken_ap = true;
2513 }
2514
Johannes Bergaf6b6372009-12-23 13:15:35 +01002515 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002516 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002517
Jiri Bencf0706e82007-05-05 11:45:53 -07002518 if (!elems.supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002519 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01002520 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002521 }
2522
Johannes Berg46900292009-02-15 12:44:28 +01002523 ifmgd->aid = aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002524
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002525 /*
2526 * We previously checked these in the beacon/probe response, so
2527 * they should be present here. This is just a safety net.
2528 */
2529 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
2530 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
2531 sdata_info(sdata,
2532 "HT AP is missing WMM params or HT capability/operation in AssocResp\n");
2533 return false;
2534 }
2535
2536 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
2537 (!elems.vht_cap_elem || !elems.vht_operation)) {
2538 sdata_info(sdata,
2539 "VHT AP is missing VHT capability/operation in AssocResp\n");
2540 return false;
2541 }
2542
Guy Eilam2a33bee2011-08-17 15:18:15 +03002543 mutex_lock(&sdata->local->sta_mtx);
2544 /*
2545 * station info was already allocated and inserted before
2546 * the association and should be available to us
2547 */
Johannes Berg7852e362012-01-20 13:55:24 +01002548 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03002549 if (WARN_ON(!sta)) {
2550 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002551 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002552 }
2553
Johannes Berg55de9082012-07-26 17:24:39 +02002554 sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
Johannes Berg8318d782008-01-24 19:38:38 +01002555
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002556 /* Set up internal HT/VHT capabilities */
Johannes Berga8243b72012-11-22 14:32:09 +01002557 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08002558 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01002559 elems.ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02002560
Mahesh Palivela818255e2012-10-10 11:33:04 +00002561 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2562 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01002563 elems.vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00002564
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002565 /*
2566 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
2567 * in their association response, so ignore that data for our own
2568 * configuration. If it changed since the last beacon, we'll get the
2569 * next beacon and update then.
2570 */
Johannes Berg11289582013-02-07 17:36:12 +01002571
Johannes Bergbee7f582013-02-07 22:24:55 +01002572 /*
2573 * If an operating mode notification IE is present, override the
2574 * NSS calculation (that would be done in rate_control_rate_init())
2575 * and use the # of streams from that element.
2576 */
2577 if (elems.opmode_notif &&
2578 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
2579 u8 nss;
2580
2581 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
2582 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
2583 nss += 1;
2584 sta->sta.rx_nss = nss;
2585 }
2586
Johannes Berg4b7679a2008-09-18 18:14:18 +02002587 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07002588
Johannes Berg46900292009-02-15 12:44:28 +01002589 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002590 set_sta_flag(sta, WLAN_STA_MFP);
Jouni Malinen5394af42009-01-08 13:31:59 +02002591
Johannes Bergddf4ac52008-10-22 11:41:38 +02002592 if (elems.wmm_param)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002593 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002594
Johannes Berg3e4d40f2013-02-07 17:19:08 +01002595 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01002596 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
2597 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
2598 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002599 sdata_info(sdata,
2600 "failed to move station %pM to desired state\n",
2601 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01002602 WARN_ON(__sta_info_destroy(sta));
2603 mutex_unlock(&sdata->local->sta_mtx);
2604 return false;
2605 }
2606
Johannes Berg7852e362012-01-20 13:55:24 +01002607 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002608
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03002609 /*
2610 * Always handle WMM once after association regardless
2611 * of the first value the AP uses. Setting -1 here has
2612 * that effect because the AP values is an unsigned
2613 * 4-bit value.
2614 */
2615 ifmgd->wmm_last_param_set = -1;
2616
Johannes Bergddf4ac52008-10-22 11:41:38 +02002617 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02002618 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07002619 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02002620 else
Johannes Berg3abead52012-03-02 15:56:59 +01002621 ieee80211_set_wmm_default(sdata, false);
2622 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07002623
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002624 /* set AID and assoc capability,
2625 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01002626 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002627 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002628 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07002629
Kalle Valo15b7b062009-03-22 21:57:14 +02002630 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01002631 * If we're using 4-addr mode, let the AP know that we're
2632 * doing so, so that it can create the STA VLAN on its side
2633 */
2634 if (ifmgd->use_4addr)
2635 ieee80211_send_4addr_nullfunc(local, sdata);
2636
2637 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02002638 * Start timer to probe the connection to the AP now.
2639 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02002640 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002641 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04002642 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02002643
Johannes Bergaf6b6372009-12-23 13:15:35 +01002644 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07002645}
2646
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002647static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2648 struct ieee80211_mgmt *mgmt,
2649 size_t len)
Johannes Berg66e67e42012-01-20 13:55:27 +01002650{
2651 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2652 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
2653 u16 capab_info, status_code, aid;
2654 struct ieee802_11_elems elems;
2655 u8 *pos;
2656 bool reassoc;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002657 struct cfg80211_bss *bss;
Jiri Bencf0706e82007-05-05 11:45:53 -07002658
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002659 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002660
2661 if (!assoc_data)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002662 return;
Joe Perchesb203ca32012-05-08 18:56:52 +00002663 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002664 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002665
2666 /*
2667 * AssocResp and ReassocResp have identical structure, so process both
2668 * of them in this function.
2669 */
2670
2671 if (len < 24 + 6)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002672 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002673
2674 reassoc = ieee80211_is_reassoc_req(mgmt->frame_control);
2675 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2676 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2677 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2678
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002679 sdata_info(sdata,
2680 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
2681 reassoc ? "Rea" : "A", mgmt->sa,
2682 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01002683
2684 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002685 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002686
2687 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01002688 elems.timeout_int &&
2689 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002690 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01002691 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01002692 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002693 sdata_info(sdata,
2694 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
2695 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01002696 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01002697 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01002698 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002699 run_again(sdata, assoc_data->timeout);
2700 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002701 }
2702
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002703 bss = assoc_data->bss;
Johannes Berg66e67e42012-01-20 13:55:27 +01002704
2705 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002706 sdata_info(sdata, "%pM denied association (code=%d)\n",
2707 mgmt->sa, status_code);
Johannes Berg66e67e42012-01-20 13:55:27 +01002708 ieee80211_destroy_assoc_data(sdata, false);
2709 } else {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002710 if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002711 /* oops -- internal error -- send timeout for now */
Eliad Peller10a91092012-07-02 14:42:03 +03002712 ieee80211_destroy_assoc_data(sdata, false);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002713 cfg80211_put_bss(sdata->local->hw.wiphy, bss);
2714 cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid);
2715 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002716 }
John W. Linville635d9992012-07-09 16:34:34 -04002717 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01002718
2719 /*
2720 * destroy assoc_data afterwards, as otherwise an idle
2721 * recalc after assoc_data is NULL but before associated
2722 * is set can cause the interface to go idle
2723 */
2724 ieee80211_destroy_assoc_data(sdata, true);
Johannes Berg66e67e42012-01-20 13:55:27 +01002725 }
2726
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002727 cfg80211_send_rx_assoc(sdata->dev, bss, (u8 *)mgmt, len);
Johannes Berg66e67e42012-01-20 13:55:27 +01002728}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01002729
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002730static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01002731 struct ieee80211_mgmt *mgmt, size_t len,
Jiri Bencf0706e82007-05-05 11:45:53 -07002732 struct ieee80211_rx_status *rx_status,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002733 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07002734{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002735 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002736 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02002737 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002738 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01002739 bool need_ps = false;
2740
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002741 sdata_assert_lock(sdata);
Johannes Bergb4f286a12013-03-26 14:13:58 +01002742
Johannes Berg826262c2012-12-10 16:38:14 +02002743 if ((sdata->u.mgd.associated &&
2744 ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) ||
2745 (sdata->u.mgd.assoc_data &&
2746 ether_addr_equal(mgmt->bssid,
2747 sdata->u.mgd.assoc_data->bss->bssid))) {
Johannes Berg56007a02010-01-26 14:19:52 +01002748 /* not previously set so we may need to recalc */
Johannes Berg826262c2012-12-10 16:38:14 +02002749 need_ps = sdata->u.mgd.associated && !sdata->u.mgd.dtim_period;
2750
2751 if (elems->tim && !elems->parse_error) {
Johannes Berg4a3cb702013-02-12 16:43:19 +01002752 const struct ieee80211_tim_ie *tim_ie = elems->tim;
Johannes Berg826262c2012-12-10 16:38:14 +02002753 sdata->u.mgd.dtim_period = tim_ie->dtim_period;
2754 }
Johannes Berg56007a02010-01-26 14:19:52 +01002755 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002756
Johannes Berg1cd8e882013-03-27 14:30:12 +01002757 if (elems->ds_params)
Bruno Randolf59eb21a2011-01-17 13:37:28 +09002758 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
2759 rx_status->band);
Johannes Berg5bda6172008-09-08 11:05:10 +02002760 else
2761 freq = rx_status->freq;
2762
2763 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2764
2765 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2766 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002767
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002768 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002769 channel);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002770 if (bss)
2771 ieee80211_rx_bss_put(local, bss);
2772
Johannes Berg37799e52013-03-26 14:02:26 +01002773 if (!sdata->u.mgd.associated ||
2774 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid))
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002775 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002776
Johannes Berg56007a02010-01-26 14:19:52 +01002777 if (need_ps) {
2778 mutex_lock(&local->iflist_mtx);
2779 ieee80211_recalc_ps(local, -1);
2780 mutex_unlock(&local->iflist_mtx);
2781 }
2782
Johannes Berg04a161f2013-05-03 09:35:35 +02002783 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
2784 elems, true);
Johannes Bergb4f286a12013-03-26 14:13:58 +01002785
Jiri Bencf0706e82007-05-05 11:45:53 -07002786}
2787
2788
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002789static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002790 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07002791{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002792 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02002793 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002794 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
2795 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002796 struct ieee802_11_elems elems;
2797
Kalle Valo15b7b062009-03-22 21:57:14 +02002798 ifmgd = &sdata->u.mgd;
2799
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002800 sdata_assert_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002801
Joe Perchesb203ca32012-05-08 18:56:52 +00002802 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03002803 return; /* ignore ProbeResp to foreign address */
2804
Ester Kummerae6a44e2008-06-27 18:54:48 +03002805 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
2806 if (baselen > len)
2807 return;
2808
2809 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
Johannes Bergb2e506b2013-03-26 14:54:16 +01002810 false, &elems);
Ester Kummerae6a44e2008-06-27 18:54:48 +03002811
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002812 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03002813
Johannes Berg77fdaa12009-07-07 03:45:17 +02002814 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002815 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002816 ieee80211_reset_ap_probe(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002817
2818 if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002819 ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002820 /* got probe response, continue with auth */
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002821 sdata_info(sdata, "direct probe responded\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002822 ifmgd->auth_data->tries = 0;
2823 ifmgd->auth_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01002824 ifmgd->auth_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002825 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01002826 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002827}
2828
Johannes Bergd91f36d2009-04-16 13:17:26 +02002829/*
2830 * This is the canonical list of information elements we care about,
2831 * the filter code also gives us all changes to the Microsoft OUI
2832 * (00:50:F2) vendor IE which is used for WMM which we need to track.
2833 *
2834 * We implement beacon filtering in software since that means we can
2835 * avoid processing the frame here and in cfg80211, and userspace
2836 * will not be able to tell whether the hardware supports it or not.
2837 *
2838 * XXX: This list needs to be dynamic -- userspace needs to be able to
2839 * add items it requires. It also needs to be able to tell us to
2840 * look out for other vendor IEs.
2841 */
2842static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02002843 (1ULL << WLAN_EID_COUNTRY) |
2844 (1ULL << WLAN_EID_ERP_INFO) |
2845 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
2846 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
2847 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg074d46d2012-03-15 19:45:16 +01002848 (1ULL << WLAN_EID_HT_OPERATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02002849
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002850static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2851 struct ieee80211_mgmt *mgmt, size_t len,
2852 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07002853{
Johannes Bergd91f36d2009-04-16 13:17:26 +02002854 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002855 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07002856 size_t baselen;
2857 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002858 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +02002859 struct ieee80211_chanctx_conf *chanctx_conf;
2860 struct ieee80211_channel *chan;
Johannes Bergbee7f582013-02-07 22:24:55 +01002861 struct sta_info *sta;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002862 u32 changed = 0;
Rami Rosenf87ad632012-10-25 10:16:23 +02002863 bool erp_valid;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002864 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02002865 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002866 u8 *bssid;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002867 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002868
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002869 sdata_assert_lock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07002870
Ester Kummerae6a44e2008-06-27 18:54:48 +03002871 /* Process beacon from the current BSS */
2872 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2873 if (baselen > len)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002874 return;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002875
Johannes Berg55de9082012-07-26 17:24:39 +02002876 rcu_read_lock();
2877 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2878 if (!chanctx_conf) {
2879 rcu_read_unlock();
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002880 return;
Johannes Berg55de9082012-07-26 17:24:39 +02002881 }
2882
Johannes Berg4bf88532012-11-09 11:39:59 +01002883 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
Johannes Berg55de9082012-07-26 17:24:39 +02002884 rcu_read_unlock();
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002885 return;
Johannes Berg55de9082012-07-26 17:24:39 +02002886 }
Johannes Berg4bf88532012-11-09 11:39:59 +01002887 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +02002888 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002889
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002890 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002891 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002892 ieee802_11_parse_elems(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01002893 len - baselen, false, &elems);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002894
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002895 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002896 ifmgd->assoc_data->have_beacon = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002897 ifmgd->assoc_data->need_beacon = false;
Johannes Bergef429da2013-02-05 17:48:40 +01002898 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
2899 sdata->vif.bss_conf.sync_tsf =
2900 le64_to_cpu(mgmt->u.beacon.timestamp);
2901 sdata->vif.bss_conf.sync_device_ts =
2902 rx_status->device_timestamp;
2903 if (elems.tim)
2904 sdata->vif.bss_conf.sync_dtim_count =
2905 elems.tim->dtim_count;
2906 else
2907 sdata->vif.bss_conf.sync_dtim_count = 0;
2908 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002909 /* continue assoc process */
2910 ifmgd->assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01002911 ifmgd->assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002912 run_again(sdata, ifmgd->assoc_data->timeout);
2913 return;
Johannes Berg66e67e42012-01-20 13:55:27 +01002914 }
2915
2916 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002917 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002918 return;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002919 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002920
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002921 /* Track average RSSI from the Beacon frames of the current AP */
2922 ifmgd->last_beacon_signal = rx_status->signal;
2923 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
2924 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03002925 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002926 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03002927 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002928 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002929 } else {
2930 ifmgd->ave_beacon_signal =
2931 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
2932 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
2933 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03002934 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002935 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002936
2937 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
2938 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
2939 int sig = ifmgd->ave_beacon_signal;
2940 int last_sig = ifmgd->last_ave_beacon_signal;
2941
2942 /*
2943 * if signal crosses either of the boundaries, invoke callback
2944 * with appropriate parameters
2945 */
2946 if (sig > ifmgd->rssi_max_thold &&
2947 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
2948 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbach887da912013-01-20 17:32:41 +02002949 drv_rssi_callback(local, sdata, RSSI_EVENT_HIGH);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002950 } else if (sig < ifmgd->rssi_min_thold &&
2951 (last_sig >= ifmgd->rssi_max_thold ||
2952 last_sig == 0)) {
2953 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbach887da912013-01-20 17:32:41 +02002954 drv_rssi_callback(local, sdata, RSSI_EVENT_LOW);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002955 }
2956 }
2957
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002958 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03002959 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01002960 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002961 int sig = ifmgd->ave_beacon_signal / 16;
2962 int last_event = ifmgd->last_cqm_event_signal;
2963 int thold = bss_conf->cqm_rssi_thold;
2964 int hyst = bss_conf->cqm_rssi_hyst;
2965 if (sig < thold &&
2966 (last_event == 0 || sig < last_event - hyst)) {
2967 ifmgd->last_cqm_event_signal = sig;
2968 ieee80211_cqm_rssi_notify(
2969 &sdata->vif,
2970 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
2971 GFP_KERNEL);
2972 } else if (sig > thold &&
2973 (last_event == 0 || sig > last_event + hyst)) {
2974 ifmgd->last_cqm_event_signal = sig;
2975 ieee80211_cqm_rssi_notify(
2976 &sdata->vif,
2977 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
2978 GFP_KERNEL);
2979 }
2980 }
2981
Johannes Bergb291ba12009-07-10 15:29:03 +02002982 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002983 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01002984 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002985 mutex_lock(&local->mtx);
Johannes Bergb291ba12009-07-10 15:29:03 +02002986 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002987 ieee80211_run_deferred_scan(local);
2988 mutex_unlock(&local->mtx);
2989
Johannes Berg4e751842009-06-10 15:16:52 +02002990 mutex_lock(&local->iflist_mtx);
2991 ieee80211_recalc_ps(local, -1);
2992 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03002993 }
2994
Johannes Bergb291ba12009-07-10 15:29:03 +02002995 /*
2996 * Push the beacon loss detection into the future since
2997 * we are processing a beacon from the AP just now.
2998 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04002999 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003000
Johannes Bergd91f36d2009-04-16 13:17:26 +02003001 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3002 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003003 len - baselen, false, &elems,
Johannes Bergd91f36d2009-04-16 13:17:26 +02003004 care_about_ies, ncrc);
3005
Vivek Natarajan25c9c872009-03-02 20:20:30 +05303006 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Rami Rosenf87ad632012-10-25 10:16:23 +02003007 bool directed_tim = ieee80211_check_tim(elems.tim,
3008 elems.tim_len,
3009 ifmgd->aid);
Kalle Valo1fb36062009-02-10 17:09:24 +02003010 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02003011 if (local->hw.conf.dynamic_ps_timeout > 0) {
Ronald Wahl70b12f22012-03-19 14:37:20 +01003012 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3013 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3014 ieee80211_hw_config(local,
3015 IEEE80211_CONF_CHANGE_PS);
3016 }
Kalle Valo572e0012009-02-10 17:09:31 +02003017 ieee80211_send_nullfunc(local, sdata, 0);
Rajkumar Manoharan6f0756a2012-03-15 05:50:36 +05303018 } else if (!local->pspolling && sdata->u.mgd.powersave) {
Kalle Valo572e0012009-02-10 17:09:31 +02003019 local->pspolling = true;
3020
3021 /*
3022 * Here is assumed that the driver will be
3023 * able to send ps-poll frame and receive a
3024 * response even though power save mode is
3025 * enabled, but some drivers might require
3026 * to disable power save here. This needs
3027 * to be investigated.
3028 */
3029 ieee80211_send_pspoll(local, sdata);
3030 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003031 }
3032 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003033
Johannes Berg488dd7b2012-10-29 20:08:01 +01003034 if (sdata->vif.p2p) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003035 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003036 int ret;
3037
3038 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3039 len - baselen,
3040 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003041 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003042 if (ret >= 2) {
3043 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3044 /* valid noa_attr and index changed */
3045 sdata->u.mgd.p2p_noa_index = noa.index;
3046 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3047 changed |= BSS_CHANGED_P2P_PS;
3048 /*
3049 * make sure we update all information, the CRC
3050 * mechanism doesn't look at P2P attributes.
3051 */
3052 ifmgd->beacon_crc_valid = false;
3053 }
3054 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3055 /* noa_attr not found and we had valid noa_attr before */
3056 sdata->u.mgd.p2p_noa_index = -1;
3057 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003058 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003059 ifmgd->beacon_crc_valid = false;
3060 }
3061 }
3062
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003063 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003064 return;
Jouni Malinen30196672009-05-19 17:01:43 +03003065 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003066 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03003067
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003068 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg7d257452012-07-06 17:37:43 +02003069
3070 if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3071 elems.wmm_param_len))
3072 changed |= BSS_CHANGED_QOS;
3073
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003074 /*
3075 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01003076 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003077 */
3078 if (!bss_conf->dtim_period) {
3079 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3080 if (elems.tim)
3081 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3082 else
3083 bss_conf->dtim_period = 1;
Johannes Bergef429da2013-02-05 17:48:40 +01003084
3085 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
3086 sdata->vif.bss_conf.sync_tsf =
3087 le64_to_cpu(mgmt->u.beacon.timestamp);
3088 sdata->vif.bss_conf.sync_device_ts =
3089 rx_status->device_timestamp;
3090 if (elems.tim)
3091 sdata->vif.bss_conf.sync_dtim_count =
3092 elems.tim->dtim_count;
3093 else
3094 sdata->vif.bss_conf.sync_dtim_count = 0;
3095 }
3096
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003097 changed |= BSS_CHANGED_DTIM_PERIOD;
Alexander Bondarce857882013-05-06 17:17:04 +03003098 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003099 }
3100
Johannes Berg1946bed2013-03-27 14:31:53 +01003101 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02003102 erp_valid = true;
3103 erp_value = elems.erp_info[0];
3104 } else {
3105 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04003106 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003107 changed |= ieee80211_handle_bss_capability(sdata,
3108 le16_to_cpu(mgmt->u.beacon.capab_info),
3109 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07003110
Johannes Berg11289582013-02-07 17:36:12 +01003111 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f582013-02-07 22:24:55 +01003112 sta = sta_info_get(sdata, bssid);
3113
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003114 if (ieee80211_config_bw(sdata, sta, elems.ht_operation,
3115 elems.vht_operation, bssid, &changed)) {
3116 mutex_unlock(&local->sta_mtx);
3117 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3118 WLAN_REASON_DEAUTH_LEAVING,
3119 true, deauth_buf);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003120 cfg80211_send_deauth(sdata->dev, deauth_buf,
3121 sizeof(deauth_buf));
3122 return;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003123 }
Johannes Bergbee7f582013-02-07 22:24:55 +01003124
3125 if (sta && elems.opmode_notif)
3126 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
3127 rx_status->band, true);
Johannes Berg11289582013-02-07 17:36:12 +01003128 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003129
Johannes Berg04b7b2f2012-09-05 13:41:37 +02003130 if (elems.country_elem && elems.pwr_constr_elem &&
3131 mgmt->u.probe_resp.capab_info &
3132 cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02003133 changed |= ieee80211_handle_pwr_constr(sdata, chan,
3134 elems.country_elem,
3135 elems.country_elem_len,
3136 elems.pwr_constr_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08003137
Johannes Berg471b3ef2007-12-28 14:32:58 +01003138 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07003139}
3140
Johannes Berg1fa57d02010-06-10 10:21:32 +02003141void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3142 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003143{
3144 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07003145 struct ieee80211_mgmt *mgmt;
3146 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003147 struct ieee802_11_elems elems;
3148 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07003149
Jiri Bencf0706e82007-05-05 11:45:53 -07003150 rx_status = (struct ieee80211_rx_status *) skb->cb;
3151 mgmt = (struct ieee80211_mgmt *) skb->data;
3152 fc = le16_to_cpu(mgmt->frame_control);
3153
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003154 sdata_lock(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003155
Johannes Berg66e67e42012-01-20 13:55:27 +01003156 switch (fc & IEEE80211_FCTL_STYPE) {
3157 case IEEE80211_STYPE_BEACON:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003158 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01003159 break;
3160 case IEEE80211_STYPE_PROBE_RESP:
3161 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3162 break;
3163 case IEEE80211_STYPE_AUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003164 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003165 break;
3166 case IEEE80211_STYPE_DEAUTH:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003167 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003168 break;
3169 case IEEE80211_STYPE_DISASSOC:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003170 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003171 break;
3172 case IEEE80211_STYPE_ASSOC_RESP:
3173 case IEEE80211_STYPE_REASSOC_RESP:
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003174 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003175 break;
3176 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01003177 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003178 ies_len = skb->len -
3179 offsetof(struct ieee80211_mgmt,
3180 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01003181
3182 if (ies_len < 0)
3183 break;
3184
3185 ieee802_11_parse_elems(
3186 mgmt->u.action.u.chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003187 ies_len, true, &elems);
Johannes Berg37799e52013-03-26 14:02:26 +01003188
3189 if (elems.parse_error)
3190 break;
3191
Johannes Berg66e67e42012-01-20 13:55:27 +01003192 ieee80211_sta_process_chanswitch(sdata,
Johannes Berg37799e52013-03-26 14:02:26 +01003193 rx_status->mactime,
Johannes Berg04a161f2013-05-03 09:35:35 +02003194 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003195 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3196 ies_len = skb->len -
3197 offsetof(struct ieee80211_mgmt,
3198 u.action.u.ext_chan_switch.variable);
3199
3200 if (ies_len < 0)
3201 break;
3202
3203 ieee802_11_parse_elems(
3204 mgmt->u.action.u.ext_chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003205 ies_len, true, &elems);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003206
3207 if (elems.parse_error)
3208 break;
3209
3210 /* for the handling code pretend this was also an IE */
3211 elems.ext_chansw_ie =
3212 &mgmt->u.action.u.ext_chan_switch.data;
3213
3214 ieee80211_sta_process_chanswitch(sdata,
3215 rx_status->mactime,
Johannes Berg04a161f2013-05-03 09:35:35 +02003216 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003217 }
Johannes Berg37799e52013-03-26 14:02:26 +01003218 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003219 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003220 sdata_unlock(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07003221}
3222
Johannes Berg9c6bd792008-09-11 00:01:52 +02003223static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07003224{
3225 struct ieee80211_sub_if_data *sdata =
3226 (struct ieee80211_sub_if_data *) data;
Jiri Bencf0706e82007-05-05 11:45:53 -07003227
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01003228 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07003229}
3230
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003231static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01003232 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003233{
Antonio Quartulli6ae16772012-09-07 13:28:52 +02003234 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003235
Johannes Berg37ad3882012-02-24 13:50:54 +01003236 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01003237 tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01003238
Antonio Quartulli6ae16772012-09-07 13:28:52 +02003239 cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003240}
3241
Johannes Berg66e67e42012-01-20 13:55:27 +01003242static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
3243{
3244 struct ieee80211_local *local = sdata->local;
3245 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3246 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003247 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01003248
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003249 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003250
3251 if (WARN_ON_ONCE(!auth_data))
3252 return -EINVAL;
3253
Johannes Berg66e67e42012-01-20 13:55:27 +01003254 auth_data->tries++;
3255
3256 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003257 sdata_info(sdata, "authentication with %pM timed out\n",
3258 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003259
3260 /*
3261 * Most likely AP is not in the range so remove the
3262 * bss struct for that AP.
3263 */
3264 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
3265
3266 return -ETIMEDOUT;
3267 }
3268
Johannes Berga1845fc2012-06-27 13:18:36 +02003269 drv_mgd_prepare_tx(local, sdata);
3270
Johannes Berg66e67e42012-01-20 13:55:27 +01003271 if (auth_data->bss->proberesp_ies) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003272 u16 trans = 1;
3273 u16 status = 0;
3274
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003275 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
3276 auth_data->bss->bssid, auth_data->tries,
3277 IEEE80211_AUTH_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01003278
3279 auth_data->expected_transaction = 2;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003280
3281 if (auth_data->algorithm == WLAN_AUTH_SAE) {
3282 trans = auth_data->sae_trans;
3283 status = auth_data->sae_status;
3284 auth_data->expected_transaction = trans;
3285 }
3286
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02003287 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
3288 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3289 IEEE80211_TX_INTFL_MLME_CONN_TX;
3290
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003291 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
3292 auth_data->data, auth_data->data_len,
Johannes Berg66e67e42012-01-20 13:55:27 +01003293 auth_data->bss->bssid,
Johannes Berg1672c0e32013-01-29 15:02:27 +01003294 auth_data->bss->bssid, NULL, 0, 0,
3295 tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01003296 } else {
3297 const u8 *ssidie;
3298
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003299 sdata_info(sdata, "direct probe to %pM (try %d/%i)\n",
3300 auth_data->bss->bssid, auth_data->tries,
3301 IEEE80211_AUTH_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01003302
Johannes Berg9caf0362012-11-29 01:25:20 +01003303 rcu_read_lock();
Johannes Berg66e67e42012-01-20 13:55:27 +01003304 ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
Johannes Berg9caf0362012-11-29 01:25:20 +01003305 if (!ssidie) {
3306 rcu_read_unlock();
Johannes Berg66e67e42012-01-20 13:55:27 +01003307 return -EINVAL;
Johannes Berg9caf0362012-11-29 01:25:20 +01003308 }
Johannes Berg66e67e42012-01-20 13:55:27 +01003309 /*
3310 * Direct probe is sent to broadcast address as some APs
3311 * will not answer to direct packet in unassociated state.
3312 */
3313 ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02003314 NULL, 0, (u32) -1, true, 0,
Johannes Berg55de9082012-07-26 17:24:39 +02003315 auth_data->bss->channel, false);
Johannes Berg9caf0362012-11-29 01:25:20 +01003316 rcu_read_unlock();
Johannes Berg66e67e42012-01-20 13:55:27 +01003317 }
3318
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02003319 if (tx_flags == 0) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01003320 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01003321 ifmgd->auth_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003322 run_again(sdata, auth_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01003323 } else {
3324 auth_data->timeout_started = false;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003325 }
Johannes Berg66e67e42012-01-20 13:55:27 +01003326
3327 return 0;
3328}
3329
3330static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
3331{
3332 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3333 struct ieee80211_local *local = sdata->local;
3334
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003335 sdata_assert_lock(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01003336
Johannes Berg66e67e42012-01-20 13:55:27 +01003337 assoc_data->tries++;
3338 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003339 sdata_info(sdata, "association with %pM timed out\n",
3340 assoc_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, assoc_data->bss);
3347
3348 return -ETIMEDOUT;
3349 }
3350
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003351 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
3352 assoc_data->bss->bssid, assoc_data->tries,
3353 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01003354 ieee80211_send_assoc(sdata);
3355
Johannes Berg1672c0e32013-01-29 15:02:27 +01003356 if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
3357 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01003358 assoc_data->timeout_started = true;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003359 run_again(sdata, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01003360 } else {
3361 assoc_data->timeout_started = false;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003362 }
Johannes Berg66e67e42012-01-20 13:55:27 +01003363
3364 return 0;
3365}
3366
Johannes Berg1672c0e32013-01-29 15:02:27 +01003367void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
3368 __le16 fc, bool acked)
3369{
3370 struct ieee80211_local *local = sdata->local;
3371
3372 sdata->u.mgd.status_fc = fc;
3373 sdata->u.mgd.status_acked = acked;
3374 sdata->u.mgd.status_received = true;
3375
3376 ieee80211_queue_work(&local->hw, &sdata->work);
3377}
3378
Johannes Berg1fa57d02010-06-10 10:21:32 +02003379void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02003380{
Johannes Berg60f8b392008-09-08 17:44:22 +02003381 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02003382 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02003383
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003384 sdata_lock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02003385
Johannes Berg1672c0e32013-01-29 15:02:27 +01003386 if (ifmgd->status_received) {
3387 __le16 fc = ifmgd->status_fc;
3388 bool status_acked = ifmgd->status_acked;
3389
3390 ifmgd->status_received = false;
3391 if (ifmgd->auth_data &&
3392 (ieee80211_is_probe_req(fc) || ieee80211_is_auth(fc))) {
3393 if (status_acked) {
3394 ifmgd->auth_data->timeout =
3395 jiffies + IEEE80211_AUTH_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003396 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01003397 } else {
3398 ifmgd->auth_data->timeout = jiffies - 1;
3399 }
Johannes Berg89afe612013-02-13 15:39:57 +01003400 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003401 } else if (ifmgd->assoc_data &&
3402 (ieee80211_is_assoc_req(fc) ||
3403 ieee80211_is_reassoc_req(fc))) {
3404 if (status_acked) {
3405 ifmgd->assoc_data->timeout =
3406 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003407 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg1672c0e32013-01-29 15:02:27 +01003408 } else {
3409 ifmgd->assoc_data->timeout = jiffies - 1;
3410 }
Johannes Berg89afe612013-02-13 15:39:57 +01003411 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003412 }
3413 }
3414
Johannes Berg89afe612013-02-13 15:39:57 +01003415 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01003416 time_after(jiffies, ifmgd->auth_data->timeout)) {
3417 if (ifmgd->auth_data->done) {
3418 /*
3419 * ok ... we waited for assoc but userspace didn't,
3420 * so let's just kill the auth data
3421 */
3422 ieee80211_destroy_auth_data(sdata, false);
3423 } else if (ieee80211_probe_auth(sdata)) {
3424 u8 bssid[ETH_ALEN];
3425
3426 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
3427
3428 ieee80211_destroy_auth_data(sdata, false);
3429
Johannes Berg66e67e42012-01-20 13:55:27 +01003430 cfg80211_send_auth_timeout(sdata->dev, bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003431 }
Johannes Berg89afe612013-02-13 15:39:57 +01003432 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003433 run_again(sdata, ifmgd->auth_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01003434
Johannes Berg89afe612013-02-13 15:39:57 +01003435 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01003436 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003437 if ((ifmgd->assoc_data->need_beacon &&
3438 !ifmgd->assoc_data->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01003439 ieee80211_do_assoc(sdata)) {
3440 u8 bssid[ETH_ALEN];
3441
3442 memcpy(bssid, ifmgd->assoc_data->bss->bssid, ETH_ALEN);
3443
3444 ieee80211_destroy_assoc_data(sdata, false);
3445
Johannes Berg66e67e42012-01-20 13:55:27 +01003446 cfg80211_send_assoc_timeout(sdata->dev, bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003447 }
Johannes Berg89afe612013-02-13 15:39:57 +01003448 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003449 run_again(sdata, ifmgd->assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01003450
Johannes Bergb291ba12009-07-10 15:29:03 +02003451 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
3452 IEEE80211_STA_CONNECTION_POLL) &&
3453 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03003454 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003455 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03003456
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003457 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003458
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003459 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Ben Greear180205b2011-02-04 15:30:24 -08003460 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003461 else
Ben Greear180205b2011-02-04 15:30:24 -08003462 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003463
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003464 /* ACK received for nullfunc probing frame */
3465 if (!ifmgd->probe_send_count)
3466 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003467 else if (ifmgd->nullfunc_failed) {
3468 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003469 mlme_dbg(sdata,
3470 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
3471 bssid, ifmgd->probe_send_count,
3472 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003473 ieee80211_mgd_probe_ap_send(sdata);
3474 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003475 mlme_dbg(sdata,
3476 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
3477 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02003478 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003479 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3480 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003481 }
3482 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003483 run_again(sdata, ifmgd->probe_timeout);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003484 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003485 mlme_dbg(sdata,
3486 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
3487 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02003488 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003489 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003490 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003491 mlme_dbg(sdata,
3492 "No probe response from AP %pM after %dms, try %d/%i\n",
3493 bssid, probe_wait_ms,
3494 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03003495 ieee80211_mgd_probe_ap_send(sdata);
3496 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02003497 /*
3498 * We actually lost the connection ... or did we?
3499 * Let's make sure!
3500 */
Ben Greearb38afa82010-10-07 16:12:06 -07003501 wiphy_debug(local->hw.wiphy,
3502 "%s: No probe response from AP %pM"
3503 " after %dms, disconnecting.\n",
3504 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08003505 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003506
Johannes Berg95acac62011-07-12 12:30:59 +02003507 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003508 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02003509 }
3510 }
3511
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003512 sdata_unlock(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02003513}
Johannes Berg0a51b272008-09-08 17:44:25 +02003514
Johannes Bergb291ba12009-07-10 15:29:03 +02003515static void ieee80211_sta_bcn_mon_timer(unsigned long data)
3516{
3517 struct ieee80211_sub_if_data *sdata =
3518 (struct ieee80211_sub_if_data *) data;
3519 struct ieee80211_local *local = sdata->local;
3520
3521 if (local->quiescing)
3522 return;
3523
Johannes Berg682bd382013-01-29 13:13:50 +01003524 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003525 ieee80211_queue_work(&sdata->local->hw,
3526 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003527}
3528
3529static void ieee80211_sta_conn_mon_timer(unsigned long data)
3530{
3531 struct ieee80211_sub_if_data *sdata =
3532 (struct ieee80211_sub_if_data *) data;
3533 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3534 struct ieee80211_local *local = sdata->local;
3535
3536 if (local->quiescing)
3537 return;
3538
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04003539 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003540}
3541
3542static void ieee80211_sta_monitor_work(struct work_struct *work)
3543{
3544 struct ieee80211_sub_if_data *sdata =
3545 container_of(work, struct ieee80211_sub_if_data,
3546 u.mgd.monitor_work);
3547
3548 ieee80211_mgd_probe_ap(sdata, false);
3549}
3550
Johannes Berga1678f82008-09-11 00:01:47 +02003551static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3552{
Eliad Peller494f1fe2012-02-19 15:26:09 +02003553 u32 flags;
3554
Kalle Vaload935682009-04-19 08:47:19 +03003555 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003556 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03003557
Johannes Bergb291ba12009-07-10 15:29:03 +02003558 /* let's probe the connection once */
Eliad Peller494f1fe2012-02-19 15:26:09 +02003559 flags = sdata->local->hw.flags;
3560 if (!(flags & IEEE80211_HW_CONNECTION_MONITOR))
3561 ieee80211_queue_work(&sdata->local->hw,
3562 &sdata->u.mgd.monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003563 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02003564 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03003565 }
Johannes Berga1678f82008-09-11 00:01:47 +02003566}
3567
Johannes Bergb8360ab2013-04-29 14:57:44 +02003568#ifdef CONFIG_PM
3569void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
3570{
3571 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3572
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003573 sdata_lock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02003574 if (!ifmgd->associated) {
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003575 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02003576 return;
3577 }
3578
3579 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
3580 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
3581 mlme_dbg(sdata, "driver requested disconnect after resume\n");
3582 ieee80211_sta_connection_lost(sdata,
3583 ifmgd->associated->bssid,
3584 WLAN_REASON_UNSPECIFIED,
3585 true);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003586 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02003587 return;
3588 }
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003589 sdata_unlock(sdata);
Johannes Bergb8360ab2013-04-29 14:57:44 +02003590}
3591#endif
3592
Johannes Berg9c6bd792008-09-11 00:01:52 +02003593/* interface setup */
3594void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
3595{
Johannes Berg46900292009-02-15 12:44:28 +01003596 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003597
Johannes Berg46900292009-02-15 12:44:28 +01003598 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02003599 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01003600 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003601 INIT_WORK(&ifmgd->beacon_connection_loss_work,
3602 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02003603 INIT_WORK(&ifmgd->csa_connection_drop_work,
3604 ieee80211_csa_connection_drop_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02003605 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01003606 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02003607 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003608 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
3609 (unsigned long) sdata);
3610 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
3611 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01003612 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05303613 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02003614
Johannes Bergab1faea2009-07-01 21:41:17 +02003615 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05303616 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02003617 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
3618 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003619 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02003620
Johannes Berg0f782312009-12-01 13:37:02 +01003621 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
3622 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
3623 else
3624 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003625}
3626
3627/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02003628void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
3629{
Johannes Berg31ee67a2012-07-06 21:18:24 +02003630 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02003631
3632 /* Restart STA timers */
3633 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07003634 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3635 if (ieee80211_sdata_running(sdata))
3636 ieee80211_restart_sta_timer(sdata);
3637 }
Johannes Berga1678f82008-09-11 00:01:47 +02003638 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02003639}
Johannes Berg10f644a2009-04-16 13:17:25 +02003640
3641int ieee80211_max_network_latency(struct notifier_block *nb,
3642 unsigned long data, void *dummy)
3643{
3644 s32 latency_usec = (s32) data;
3645 struct ieee80211_local *local =
3646 container_of(nb, struct ieee80211_local,
3647 network_latency_notifier);
3648
3649 mutex_lock(&local->iflist_mtx);
3650 ieee80211_recalc_ps(local, latency_usec);
3651 mutex_unlock(&local->iflist_mtx);
3652
3653 return 0;
3654}
Johannes Berg77fdaa12009-07-07 03:45:17 +02003655
Johannes Bergf2d9d272012-11-22 14:11:39 +01003656static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
3657 struct cfg80211_bss *cbss)
3658{
3659 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3660 const u8 *ht_cap_ie, *vht_cap_ie;
3661 const struct ieee80211_ht_cap *ht_cap;
3662 const struct ieee80211_vht_cap *vht_cap;
3663 u8 chains = 1;
3664
3665 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
3666 return chains;
3667
Johannes Berg9caf0362012-11-29 01:25:20 +01003668 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003669 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
3670 ht_cap = (void *)(ht_cap_ie + 2);
3671 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
3672 /*
3673 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
3674 * "Tx Unequal Modulation Supported" fields.
3675 */
3676 }
3677
3678 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
3679 return chains;
3680
Johannes Berg9caf0362012-11-29 01:25:20 +01003681 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003682 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
3683 u8 nss;
3684 u16 tx_mcs_map;
3685
3686 vht_cap = (void *)(vht_cap_ie + 2);
3687 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
3688 for (nss = 8; nss > 0; nss--) {
3689 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
3690 IEEE80211_VHT_MCS_NOT_SUPPORTED)
3691 break;
3692 }
3693 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
3694 chains = max(chains, nss);
3695 }
3696
3697 return chains;
3698}
3699
Johannes Bergb17166a2012-07-27 11:41:27 +02003700static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
3701 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01003702{
3703 struct ieee80211_local *local = sdata->local;
3704 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg24398e32012-03-28 10:58:36 +02003705 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003706 const struct ieee80211_vht_operation *vht_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02003707 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01003708 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003709 int ret;
Johannes Berga1cf7752012-03-08 15:02:07 +01003710
Johannes Berg24398e32012-03-28 10:58:36 +02003711 sband = local->hw.wiphy->bands[cbss->channel->band];
3712
Johannes Bergf2d9d272012-11-22 14:11:39 +01003713 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
3714 IEEE80211_STA_DISABLE_80P80MHZ |
3715 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02003716
Johannes Berg9caf0362012-11-29 01:25:20 +01003717 rcu_read_lock();
3718
Johannes Bergf2d9d272012-11-22 14:11:39 +01003719 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3720 sband->ht_cap.ht_supported) {
Johannes Berg08e6eff2013-02-07 23:33:32 +01003721 const u8 *ht_oper_ie, *ht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003722
Johannes Berg9caf0362012-11-29 01:25:20 +01003723 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02003724 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
3725 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6eff2013-02-07 23:33:32 +01003726
3727 ht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
3728 if (!ht_cap || ht_cap[1] < sizeof(struct ieee80211_ht_cap)) {
3729 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3730 ht_oper = NULL;
3731 }
Johannes Berg24398e32012-03-28 10:58:36 +02003732 }
3733
Johannes Bergf2d9d272012-11-22 14:11:39 +01003734 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3735 sband->vht_cap.vht_supported) {
Johannes Berg08e6eff2013-02-07 23:33:32 +01003736 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003737
Johannes Berg9caf0362012-11-29 01:25:20 +01003738 vht_oper_ie = ieee80211_bss_get_ie(cbss,
3739 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003740 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
3741 vht_oper = (void *)(vht_oper_ie + 2);
3742 if (vht_oper && !ht_oper) {
3743 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003744 sdata_info(sdata,
Johannes Bergf2d9d272012-11-22 14:11:39 +01003745 "AP advertised VHT without HT, disabling both\n");
Johannes Bergcb145022013-02-07 20:41:50 +01003746 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3747 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg24398e32012-03-28 10:58:36 +02003748 }
Johannes Berg08e6eff2013-02-07 23:33:32 +01003749
3750 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
3751 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
3752 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3753 vht_oper = NULL;
3754 }
Johannes Berg24398e32012-03-28 10:58:36 +02003755 }
3756
Johannes Bergf2d9d272012-11-22 14:11:39 +01003757 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
3758 cbss->channel,
3759 ht_oper, vht_oper,
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003760 &chandef, true);
Johannes Berg04ecd252012-09-11 14:34:12 +02003761
Johannes Bergf2d9d272012-11-22 14:11:39 +01003762 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
3763 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02003764
Johannes Berg9caf0362012-11-29 01:25:20 +01003765 rcu_read_unlock();
3766
Johannes Berg04ecd252012-09-11 14:34:12 +02003767 /* will change later if needed */
3768 sdata->smps_mode = IEEE80211_SMPS_OFF;
3769
Johannes Bergf2d9d272012-11-22 14:11:39 +01003770 /*
3771 * If this fails (possibly due to channel context sharing
3772 * on incompatible channels, e.g. 80+80 and 160 sharing the
3773 * same control channel) try to use a smaller bandwidth.
3774 */
3775 ret = ieee80211_vif_use_channel(sdata, &chandef,
3776 IEEE80211_CHANCTX_SHARED);
Johannes Bergd601cd82013-02-07 20:54:51 +01003777 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Johannes Bergf2d9d272012-11-22 14:11:39 +01003778 ifmgd->flags |= chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01003779 ret = ieee80211_vif_use_channel(sdata, &chandef,
3780 IEEE80211_CHANCTX_SHARED);
3781 }
Johannes Bergf2d9d272012-11-22 14:11:39 +01003782 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02003783}
3784
3785static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3786 struct cfg80211_bss *cbss, bool assoc)
3787{
3788 struct ieee80211_local *local = sdata->local;
3789 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3790 struct ieee80211_bss *bss = (void *)cbss->priv;
3791 struct sta_info *new_sta = NULL;
3792 bool have_sta = false;
3793 int err;
3794
3795 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
3796 return -EINVAL;
3797
3798 if (assoc) {
3799 rcu_read_lock();
3800 have_sta = sta_info_get(sdata, cbss->bssid);
3801 rcu_read_unlock();
3802 }
3803
3804 if (!have_sta) {
3805 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
3806 if (!new_sta)
3807 return -ENOMEM;
3808 }
3809
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003810 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003811 u32 rates = 0, basic_rates = 0;
3812 bool have_higher_than_11mbit;
3813 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Bergb17166a2012-07-27 11:41:27 +02003814 struct ieee80211_supported_band *sband;
Johannes Berg8cef2c92013-02-05 16:54:31 +01003815 const struct cfg80211_bss_ies *ies;
Johannes Bergb17166a2012-07-27 11:41:27 +02003816
3817 sband = local->hw.wiphy->bands[cbss->channel->band];
3818
3819 err = ieee80211_prep_channel(sdata, cbss);
3820 if (err) {
3821 sta_info_free(local, new_sta);
3822 return err;
3823 }
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003824
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003825 ieee80211_get_rates(sband, bss->supp_rates,
3826 bss->supp_rates_len,
3827 &rates, &basic_rates,
3828 &have_higher_than_11mbit,
3829 &min_rate, &min_rate_index);
3830
3831 /*
3832 * This used to be a workaround for basic rates missing
3833 * in the association response frame. Now that we no
3834 * longer use the basic rates from there, it probably
3835 * doesn't happen any more, but keep the workaround so
3836 * in case some *other* APs are buggy in different ways
3837 * we can connect -- with a warning.
3838 */
3839 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003840 sdata_info(sdata,
3841 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003842 basic_rates = BIT(min_rate_index);
3843 }
3844
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003845 new_sta->sta.supp_rates[cbss->channel->band] = rates;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003846 sdata->vif.bss_conf.basic_rates = basic_rates;
3847
3848 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg55de9082012-07-26 17:24:39 +02003849 if (cbss->channel->band == IEEE80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003850 have_higher_than_11mbit)
3851 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
3852 else
3853 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
3854
3855 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
3856
Johannes Berg8c358bc2012-05-22 22:13:05 +02003857 /* set timing information */
3858 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01003859 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01003860 ies = rcu_dereference(cbss->beacon_ies);
3861 if (ies) {
3862 const u8 *tim_ie;
3863
3864 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3865 sdata->vif.bss_conf.sync_device_ts =
3866 bss->device_ts_beacon;
3867 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
3868 ies->data, ies->len);
3869 if (tim_ie && tim_ie[1] >= 2)
3870 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
3871 else
3872 sdata->vif.bss_conf.sync_dtim_count = 0;
3873 } else if (!(local->hw.flags &
3874 IEEE80211_HW_TIMING_BEACON_ONLY)) {
3875 ies = rcu_dereference(cbss->proberesp_ies);
3876 /* must be non-NULL since beacon IEs were NULL */
3877 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3878 sdata->vif.bss_conf.sync_device_ts =
3879 bss->device_ts_presp;
3880 sdata->vif.bss_conf.sync_dtim_count = 0;
3881 } else {
3882 sdata->vif.bss_conf.sync_tsf = 0;
3883 sdata->vif.bss_conf.sync_device_ts = 0;
3884 sdata->vif.bss_conf.sync_dtim_count = 0;
3885 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01003886 rcu_read_unlock();
Johannes Berg8c358bc2012-05-22 22:13:05 +02003887
3888 /* tell driver about BSSID, basic rates and timing */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003889 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02003890 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
3891 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01003892
3893 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003894 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01003895
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003896 err = sta_info_insert(new_sta);
3897 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01003898 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003899 sdata_info(sdata,
3900 "failed to insert STA entry for the AP (error %d)\n",
3901 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01003902 return err;
3903 }
3904 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00003905 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01003906
3907 return 0;
3908}
3909
Johannes Berg77fdaa12009-07-07 03:45:17 +02003910/* config hooks */
3911int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
3912 struct cfg80211_auth_request *req)
3913{
Johannes Berg66e67e42012-01-20 13:55:27 +01003914 struct ieee80211_local *local = sdata->local;
3915 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3916 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003917 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01003918 int err;
3919
3920 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02003921
3922 switch (req->auth_type) {
3923 case NL80211_AUTHTYPE_OPEN_SYSTEM:
3924 auth_alg = WLAN_AUTH_OPEN;
3925 break;
3926 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01003927 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02003928 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003929 auth_alg = WLAN_AUTH_SHARED_KEY;
3930 break;
3931 case NL80211_AUTHTYPE_FT:
3932 auth_alg = WLAN_AUTH_FT;
3933 break;
3934 case NL80211_AUTHTYPE_NETWORK_EAP:
3935 auth_alg = WLAN_AUTH_LEAP;
3936 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003937 case NL80211_AUTHTYPE_SAE:
3938 auth_alg = WLAN_AUTH_SAE;
3939 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003940 default:
3941 return -EOPNOTSUPP;
3942 }
3943
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003944 auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len +
3945 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01003946 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02003947 return -ENOMEM;
3948
Johannes Berg66e67e42012-01-20 13:55:27 +01003949 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003950
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003951 if (req->sae_data_len >= 4) {
3952 __le16 *pos = (__le16 *) req->sae_data;
3953 auth_data->sae_trans = le16_to_cpu(pos[0]);
3954 auth_data->sae_status = le16_to_cpu(pos[1]);
3955 memcpy(auth_data->data, req->sae_data + 4,
3956 req->sae_data_len - 4);
3957 auth_data->data_len += req->sae_data_len - 4;
3958 }
3959
Johannes Berg77fdaa12009-07-07 03:45:17 +02003960 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003961 memcpy(&auth_data->data[auth_data->data_len],
3962 req->ie, req->ie_len);
3963 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003964 }
3965
Johannes Bergfffd0932009-07-08 14:22:54 +02003966 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003967 auth_data->key_len = req->key_len;
3968 auth_data->key_idx = req->key_idx;
3969 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02003970 }
3971
Johannes Berg66e67e42012-01-20 13:55:27 +01003972 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003973
Johannes Berg66e67e42012-01-20 13:55:27 +01003974 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01003975
Johannes Berg66e67e42012-01-20 13:55:27 +01003976 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
3977 ifmgd->assoc_data) {
3978 err = -EBUSY;
3979 goto err_free;
3980 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003981
Johannes Berg66e67e42012-01-20 13:55:27 +01003982 if (ifmgd->auth_data)
3983 ieee80211_destroy_auth_data(sdata, false);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003984
Johannes Berg66e67e42012-01-20 13:55:27 +01003985 /* prep auth_data so we don't go into idle on disassoc */
3986 ifmgd->auth_data = auth_data;
3987
Johannes Berg7b119dc2013-04-10 21:38:36 +02003988 if (ifmgd->associated) {
3989 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3990
3991 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3992 WLAN_REASON_UNSPECIFIED,
3993 false, frame_buf);
3994
Johannes Berg8d61ffa2013-05-10 12:32:47 +02003995 cfg80211_send_deauth(sdata->dev, frame_buf,
3996 sizeof(frame_buf));
Johannes Berg7b119dc2013-04-10 21:38:36 +02003997 }
Johannes Berg66e67e42012-01-20 13:55:27 +01003998
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003999 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004000
Johannes Berga1cf7752012-03-08 15:02:07 +01004001 err = ieee80211_prep_connection(sdata, req->bss, false);
4002 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01004003 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004004
Johannes Berg66e67e42012-01-20 13:55:27 +01004005 err = ieee80211_probe_auth(sdata);
4006 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004007 sta_info_destroy_addr(sdata, req->bss->bssid);
4008 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004009 }
4010
Johannes Berg66e67e42012-01-20 13:55:27 +01004011 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01004012 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004013 return 0;
Johannes Berge5b900d2010-07-29 16:08:55 +02004014
Johannes Berg66e67e42012-01-20 13:55:27 +01004015 err_clear:
Eliad Peller3d2abdf2012-09-04 17:44:45 +03004016 memset(ifmgd->bssid, 0, ETH_ALEN);
4017 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01004018 ifmgd->auth_data = NULL;
4019 err_free:
4020 kfree(auth_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01004021 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004022}
4023
Johannes Berg77fdaa12009-07-07 03:45:17 +02004024int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
4025 struct cfg80211_assoc_request *req)
4026{
Johannes Berg66e67e42012-01-20 13:55:27 +01004027 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004028 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004029 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01004030 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004031 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01004032 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01004033 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004034 int i, err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004035
Johannes Berg66e67e42012-01-20 13:55:27 +01004036 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
4037 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01004038 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004039
Johannes Berg9caf0362012-11-29 01:25:20 +01004040 rcu_read_lock();
4041 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
4042 if (!ssidie) {
4043 rcu_read_unlock();
4044 kfree(assoc_data);
4045 return -EINVAL;
4046 }
4047 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
4048 assoc_data->ssid_len = ssidie[1];
4049 rcu_read_unlock();
4050
Johannes Berg7b119dc2013-04-10 21:38:36 +02004051 if (ifmgd->associated) {
4052 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4053
4054 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4055 WLAN_REASON_UNSPECIFIED,
4056 false, frame_buf);
4057
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004058 cfg80211_send_deauth(sdata->dev, frame_buf,
4059 sizeof(frame_buf));
Johannes Berg7b119dc2013-04-10 21:38:36 +02004060 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004061
4062 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
4063 err = -EBUSY;
4064 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004065 }
4066
Johannes Berg66e67e42012-01-20 13:55:27 +01004067 if (ifmgd->assoc_data) {
4068 err = -EBUSY;
4069 goto err_free;
4070 }
4071
4072 if (ifmgd->auth_data) {
4073 bool match;
4074
4075 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00004076 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004077 ieee80211_destroy_auth_data(sdata, match);
4078 }
4079
4080 /* prepare assoc data */
Johannes Berg19c3b832012-08-01 20:13:36 +02004081
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03004082 ifmgd->beacon_crc_valid = false;
4083
Johannes Bergde5036a2012-03-08 15:02:03 +01004084 /*
4085 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
4086 * We still associate in non-HT mode (11a/b/g) if any one of these
4087 * ciphers is configured as pairwise.
4088 * We can set this to true for non-11n hardware, that'll be checked
4089 * separately along with the peer capabilities.
4090 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02004091 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02004092 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
4093 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02004094 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01004095 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004096 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg1c4cb922012-05-30 15:57:00 +02004097 netdev_info(sdata->dev,
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004098 "disabling HT/VHT due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02004099 }
4100 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004101
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004102 if (req->flags & ASSOC_REQ_DISABLE_HT) {
Johannes Berga8243b72012-11-22 14:32:09 +01004103 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004104 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4105 }
Ben Greearef96a8422011-11-18 11:32:00 -08004106
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01004107 if (req->flags & ASSOC_REQ_DISABLE_VHT)
4108 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4109
Johannes Berg4e74bfd2012-03-08 15:02:04 +01004110 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4111 sband = local->hw.wiphy->bands[req->bss->channel->band];
4112 if (!sband->ht_cap.ht_supported ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02004113 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
Johannes Berga8243b72012-11-22 14:32:09 +01004114 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg1b49de22012-07-27 10:29:14 +02004115 if (!bss->wmm_used)
4116 netdev_info(sdata->dev,
4117 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02004118 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01004119
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004120 /* disable VHT if we don't support it or the AP doesn't use WMM */
4121 if (!sband->vht_cap.vht_supported ||
4122 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
4123 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg1b49de22012-07-27 10:29:14 +02004124 if (!bss->wmm_used)
4125 netdev_info(sdata->dev,
4126 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004127 }
4128
Ben Greearef96a8422011-11-18 11:32:00 -08004129 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
4130 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
4131 sizeof(ifmgd->ht_capa_mask));
4132
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01004133 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
4134 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
4135 sizeof(ifmgd->vht_capa_mask));
4136
Johannes Berg77fdaa12009-07-07 03:45:17 +02004137 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004138 memcpy(assoc_data->ie, req->ie, req->ie_len);
4139 assoc_data->ie_len = req->ie_len;
4140 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004141
Johannes Berg66e67e42012-01-20 13:55:27 +01004142 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01004143
Johannes Bergaf6b6372009-12-23 13:15:35 +01004144 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
4145 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02004146 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004147 else
Johannes Berg04ecd252012-09-11 14:34:12 +02004148 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004149 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02004150 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004151
Johannes Berg66e67e42012-01-20 13:55:27 +01004152 assoc_data->capability = req->bss->capability;
Johannes Berg32c50572012-03-28 11:04:29 +02004153 assoc_data->wmm = bss->wmm_used &&
4154 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg66e67e42012-01-20 13:55:27 +01004155 assoc_data->supp_rates = bss->supp_rates;
4156 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02004157
Johannes Berg9caf0362012-11-29 01:25:20 +01004158 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02004159 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
4160 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
4161 assoc_data->ap_ht_param =
4162 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
4163 else
Johannes Berga8243b72012-11-22 14:32:09 +01004164 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01004165 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
4166 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
4167 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
4168 sizeof(struct ieee80211_vht_cap));
4169 else
4170 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01004171 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01004172
Kalle Valoab133152010-01-12 10:42:31 +02004173 if (bss->wmm_used && bss->uapsd_supported &&
Alexander Bondar24aa11a2013-04-02 15:30:14 +03004174 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) &&
4175 sdata->wmm_acm != 0xff) {
Johannes Berg76f03032012-03-08 15:02:05 +01004176 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02004177 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
4178 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01004179 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02004180 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
4181 }
4182
Johannes Berg77fdaa12009-07-07 03:45:17 +02004183 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01004184 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004185
4186 if (req->use_mfp) {
4187 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
4188 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
4189 } else {
4190 ifmgd->mfp = IEEE80211_MFP_DISABLED;
4191 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
4192 }
4193
4194 if (req->crypto.control_port)
4195 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
4196 else
4197 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
4198
Johannes Berga621fa42010-08-27 14:26:54 +03004199 sdata->control_port_protocol = req->crypto.control_port_ethertype;
4200 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
4201
Johannes Berg66e67e42012-01-20 13:55:27 +01004202 /* kick off associate process */
4203
4204 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02004205 ifmgd->dtim_period = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004206
Johannes Berga1cf7752012-03-08 15:02:07 +01004207 err = ieee80211_prep_connection(sdata, req->bss, true);
4208 if (err)
4209 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01004210
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004211 rcu_read_lock();
4212 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02004213
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004214 if (sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC &&
4215 !beacon_ies) {
4216 /*
4217 * Wait up to one beacon interval ...
4218 * should this be more if we miss one?
4219 */
4220 sdata_info(sdata, "waiting for beacon from %pM\n",
4221 ifmgd->bssid);
4222 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01004223 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004224 assoc_data->need_beacon = true;
4225 } else if (beacon_ies) {
4226 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4227 beacon_ies->data,
4228 beacon_ies->len);
Johannes Bergef429da2013-02-05 17:48:40 +01004229 u8 dtim_count = 0;
4230
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004231 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
4232 const struct ieee80211_tim_ie *tim;
4233 tim = (void *)(tim_ie + 2);
4234 ifmgd->dtim_period = tim->dtim_period;
Johannes Bergef429da2013-02-05 17:48:40 +01004235 dtim_count = tim->dtim_count;
Johannes Berg826262c2012-12-10 16:38:14 +02004236 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004237 assoc_data->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01004238 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01004239 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01004240
4241 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
4242 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
4243 sdata->vif.bss_conf.sync_device_ts =
4244 bss->device_ts_beacon;
4245 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
4246 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004247 } else {
4248 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01004249 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01004250 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004251 rcu_read_unlock();
4252
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004253 run_again(sdata, assoc_data->timeout);
Johannes Berg66e67e42012-01-20 13:55:27 +01004254
Paul Stewartfcff4f12012-02-23 17:59:53 -08004255 if (bss->corrupt_data) {
4256 char *corrupt_type = "data";
4257 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
4258 if (bss->corrupt_data &
4259 IEEE80211_BSS_CORRUPT_PROBE_RESP)
4260 corrupt_type = "beacon and probe response";
4261 else
4262 corrupt_type = "beacon";
4263 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
4264 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004265 sdata_info(sdata, "associating with AP with corrupt %s\n",
4266 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08004267 }
4268
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004269 return 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004270 err_clear:
Eliad Peller3d2abdf2012-09-04 17:44:45 +03004271 memset(ifmgd->bssid, 0, ETH_ALEN);
4272 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01004273 ifmgd->assoc_data = NULL;
4274 err_free:
4275 kfree(assoc_data);
Johannes Berg66e67e42012-01-20 13:55:27 +01004276 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004277}
4278
4279int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01004280 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004281{
4282 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004283 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02004284 bool tx = !req->local_state_change;
Johannes Bergde3d43a2013-05-14 09:39:02 +02004285 bool report_frame = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004286
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004287 sdata_info(sdata,
4288 "deauthenticating from %pM by local choice (reason=%d)\n",
4289 req->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02004290
Johannes Berg86552012012-10-29 09:46:31 +01004291 if (ifmgd->auth_data) {
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03004292 drv_mgd_prepare_tx(sdata->local, sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01004293 ieee80211_send_deauth_disassoc(sdata, req->bssid,
4294 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02004295 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01004296 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01004297 ieee80211_destroy_auth_data(sdata, false);
Johannes Berg86552012012-10-29 09:46:31 +01004298
Johannes Bergde3d43a2013-05-14 09:39:02 +02004299 report_frame = true;
Johannes Berg86552012012-10-29 09:46:31 +01004300 goto out;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03004301 }
4302
Johannes Berg86552012012-10-29 09:46:31 +01004303 if (ifmgd->associated &&
4304 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
4305 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4306 req->reason_code, tx, frame_buf);
Johannes Bergde3d43a2013-05-14 09:39:02 +02004307 report_frame = true;
Johannes Berg86552012012-10-29 09:46:31 +01004308 }
Johannes Berg37ad3882012-02-24 13:50:54 +01004309
Johannes Berg86552012012-10-29 09:46:31 +01004310 out:
Johannes Bergde3d43a2013-05-14 09:39:02 +02004311 if (report_frame)
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004312 cfg80211_send_deauth(sdata->dev, frame_buf,
4313 IEEE80211_DEAUTH_FRAME_LEN);
Johannes Berg86552012012-10-29 09:46:31 +01004314
Johannes Berg77fdaa12009-07-07 03:45:17 +02004315 return 0;
4316}
4317
4318int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01004319 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004320{
4321 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07004322 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004323 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02004324
Johannes Berg8d8b2612009-07-25 11:58:36 +02004325 /*
4326 * cfg80211 should catch this ... but it's racy since
4327 * we can receive a disassoc frame, process it, hand it
4328 * to cfg80211 while that's in a locked section already
4329 * trying to tell us that the user wants to disconnect.
4330 */
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004331 if (ifmgd->associated != req->bss)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004332 return -ENOLINK;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004333
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004334 sdata_info(sdata,
4335 "disassociating from %pM by local choice (reason=%d)\n",
4336 req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02004337
Jouni Malinene69e95d2010-03-29 23:29:31 -07004338 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01004339 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
4340 req->reason_code, !req->local_state_change,
4341 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004342
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004343 cfg80211_send_disassoc(sdata->dev, frame_buf,
4344 IEEE80211_DEAUTH_FRAME_LEN);
Johannes Bergbc83b682009-11-29 12:19:06 +01004345
Johannes Berg77fdaa12009-07-07 03:45:17 +02004346 return 0;
4347}
Jouni Malinen026331c2010-02-15 12:53:10 +02004348
Eliad Pellerafa762f2012-04-23 14:45:15 +03004349void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01004350{
4351 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4352
Ben Greear49921852013-02-20 09:41:09 -08004353 /*
4354 * Make sure some work items will not run after this,
4355 * they will not do anything but might not have been
4356 * cancelled when disconnecting.
4357 */
4358 cancel_work_sync(&ifmgd->monitor_work);
4359 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
4360 cancel_work_sync(&ifmgd->request_smps_work);
4361 cancel_work_sync(&ifmgd->csa_connection_drop_work);
4362 cancel_work_sync(&ifmgd->chswitch_work);
4363
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004364 sdata_lock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01004365 if (ifmgd->assoc_data)
4366 ieee80211_destroy_assoc_data(sdata, false);
4367 if (ifmgd->auth_data)
4368 ieee80211_destroy_auth_data(sdata, false);
4369 del_timer_sync(&ifmgd->timer);
Johannes Berg8d61ffa2013-05-10 12:32:47 +02004370 sdata_unlock(sdata);
Johannes Berg54e4ffb2012-02-25 21:48:08 +01004371}
4372
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02004373void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
4374 enum nl80211_cqm_rssi_threshold_event rssi_event,
4375 gfp_t gfp)
4376{
4377 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4378
Johannes Bergb5878a22010-04-07 16:48:40 +02004379 trace_api_cqm_rssi_notify(sdata, rssi_event);
4380
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02004381 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
4382}
4383EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);