blob: 1da3d6be8e112f6b4d2a9f1d997b62a89e782fbe [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/*
94 * All cfg80211 functions have to be called outside a locked
95 * section so that they can acquire a lock themselves... This
96 * is much simpler than queuing up things in cfg80211, but we
97 * do need some indirection for that here.
98 */
99enum rx_mgmt_action {
100 /* no action required */
101 RX_MGMT_NONE,
102
Johannes Berg77fdaa12009-07-07 03:45:17 +0200103 /* caller must call cfg80211_send_deauth() */
104 RX_MGMT_CFG80211_DEAUTH,
105
106 /* caller must call cfg80211_send_disassoc() */
107 RX_MGMT_CFG80211_DISASSOC,
Johannes Berg66e67e42012-01-20 13:55:27 +0100108
109 /* caller must call cfg80211_send_rx_auth() */
110 RX_MGMT_CFG80211_RX_AUTH,
111
112 /* caller must call cfg80211_send_rx_assoc() */
113 RX_MGMT_CFG80211_RX_ASSOC,
114
115 /* caller must call cfg80211_send_assoc_timeout() */
116 RX_MGMT_CFG80211_ASSOC_TIMEOUT,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100117
118 /* used when a processed beacon causes a deauth */
119 RX_MGMT_CFG80211_TX_DEAUTH,
Johannes Berg77fdaa12009-07-07 03:45:17 +0200120};
121
Johannes Berg5484e232008-09-08 17:44:27 +0200122/* utils */
Johannes Berg77fdaa12009-07-07 03:45:17 +0200123static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
124{
Johannes Berg46a5eba2010-09-15 13:28:15 +0200125 lockdep_assert_held(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200126}
127
Johannes Bergca386f32009-07-10 02:39:48 +0200128/*
129 * We can have multiple work items (and connection probing)
130 * scheduling this timer, but we need to take care to only
131 * reschedule it when it should fire _earlier_ than it was
132 * asked for before, or if it's not pending right now. This
133 * function ensures that. Note that it then is required to
134 * run this function for all timeouts after the first one
135 * has happened -- the work that runs from this timer will
136 * do that.
137 */
Johannes Berg66e67e42012-01-20 13:55:27 +0100138static void run_again(struct ieee80211_if_managed *ifmgd, unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200139{
140 ASSERT_MGD_MTX(ifmgd);
141
142 if (!timer_pending(&ifmgd->timer) ||
143 time_before(timeout, ifmgd->timer.expires))
144 mod_timer(&ifmgd->timer, timeout);
145}
146
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400147void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200148{
Johannes Bergc1288b12012-01-19 09:29:57 +0100149 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200150 return;
151
Johannes Berg7eeff742012-07-18 10:27:27 +0200152 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
153 return;
154
Johannes Bergb291ba12009-07-10 15:29:03 +0200155 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100156 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200157}
158
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400159void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
160{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400161 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
162
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100163 if (unlikely(!sdata->u.mgd.associated))
164 return;
165
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400166 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
167 return;
168
169 mod_timer(&sdata->u.mgd.conn_mon_timer,
170 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400171
172 ifmgd->probe_send_count = 0;
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400173}
174
Johannes Berg5484e232008-09-08 17:44:27 +0200175static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200176{
Johannes Berg5484e232008-09-08 17:44:27 +0200177 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200178}
179
Johannes Berg6565ec92013-02-08 14:52:32 +0100180static u32 chandef_downgrade(struct cfg80211_chan_def *c)
181{
182 u32 ret;
183 int tmp;
184
185 switch (c->width) {
186 case NL80211_CHAN_WIDTH_20:
187 c->width = NL80211_CHAN_WIDTH_20_NOHT;
188 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
189 break;
190 case NL80211_CHAN_WIDTH_40:
191 c->width = NL80211_CHAN_WIDTH_20;
192 c->center_freq1 = c->chan->center_freq;
193 ret = IEEE80211_STA_DISABLE_40MHZ |
194 IEEE80211_STA_DISABLE_VHT;
195 break;
196 case NL80211_CHAN_WIDTH_80:
197 tmp = (30 + c->chan->center_freq - c->center_freq1)/20;
198 /* n_P40 */
199 tmp /= 2;
200 /* freq_P40 */
201 c->center_freq1 = c->center_freq1 - 20 + 40 * tmp;
202 c->width = NL80211_CHAN_WIDTH_40;
203 ret = IEEE80211_STA_DISABLE_VHT;
204 break;
205 case NL80211_CHAN_WIDTH_80P80:
206 c->center_freq2 = 0;
207 c->width = NL80211_CHAN_WIDTH_80;
208 ret = IEEE80211_STA_DISABLE_80P80MHZ |
209 IEEE80211_STA_DISABLE_160MHZ;
210 break;
211 case NL80211_CHAN_WIDTH_160:
212 /* n_P20 */
213 tmp = (70 + c->chan->center_freq - c->center_freq1)/20;
214 /* n_P80 */
215 tmp /= 4;
216 c->center_freq1 = c->center_freq1 - 40 + 80 * tmp;
217 c->width = NL80211_CHAN_WIDTH_80;
218 ret = IEEE80211_STA_DISABLE_80P80MHZ |
219 IEEE80211_STA_DISABLE_160MHZ;
220 break;
221 default:
222 case NL80211_CHAN_WIDTH_20_NOHT:
223 WARN_ON_ONCE(1);
224 c->width = NL80211_CHAN_WIDTH_20_NOHT;
225 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
226 break;
227 }
228
229 WARN_ON_ONCE(!cfg80211_chandef_valid(c));
230
231 return ret;
232}
233
234static u32
235ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
236 struct ieee80211_supported_band *sband,
237 struct ieee80211_channel *channel,
238 const struct ieee80211_ht_operation *ht_oper,
239 const struct ieee80211_vht_operation *vht_oper,
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100240 struct cfg80211_chan_def *chandef, bool verbose)
Johannes Berg6565ec92013-02-08 14:52:32 +0100241{
242 struct cfg80211_chan_def vht_chandef;
243 u32 ht_cfreq, ret;
244
245 chandef->chan = channel;
246 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
247 chandef->center_freq1 = channel->center_freq;
248 chandef->center_freq2 = 0;
249
250 if (!ht_oper || !sband->ht_cap.ht_supported) {
251 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
252 goto out;
253 }
254
255 chandef->width = NL80211_CHAN_WIDTH_20;
256
257 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
258 channel->band);
259 /* check that channel matches the right operating channel */
260 if (channel->center_freq != ht_cfreq) {
261 /*
262 * It's possible that some APs are confused here;
263 * Netgear WNDR3700 sometimes reports 4 higher than
264 * the actual channel in association responses, but
265 * since we look at probe response/beacon data here
266 * it should be OK.
267 */
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100268 if (verbose)
269 sdata_info(sdata,
270 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
271 channel->center_freq, ht_cfreq,
272 ht_oper->primary_chan, channel->band);
Johannes Berg6565ec92013-02-08 14:52:32 +0100273 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
274 goto out;
275 }
276
277 /* check 40 MHz support, if we have it */
278 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
279 switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
280 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
281 chandef->width = NL80211_CHAN_WIDTH_40;
282 chandef->center_freq1 += 10;
283 break;
284 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
285 chandef->width = NL80211_CHAN_WIDTH_40;
286 chandef->center_freq1 -= 10;
287 break;
288 }
289 } else {
290 /* 40 MHz (and 80 MHz) must be supported for VHT */
291 ret = IEEE80211_STA_DISABLE_VHT;
Johannes Berg85220d72013-03-25 18:29:27 +0100292 /* also mark 40 MHz disabled */
293 ret |= IEEE80211_STA_DISABLE_40MHZ;
Johannes Berg6565ec92013-02-08 14:52:32 +0100294 goto out;
295 }
296
297 if (!vht_oper || !sband->vht_cap.vht_supported) {
298 ret = IEEE80211_STA_DISABLE_VHT;
299 goto out;
300 }
301
302 vht_chandef.chan = channel;
303 vht_chandef.center_freq1 =
304 ieee80211_channel_to_frequency(vht_oper->center_freq_seg1_idx,
305 channel->band);
306 vht_chandef.center_freq2 = 0;
307
Johannes Berg6565ec92013-02-08 14:52:32 +0100308 switch (vht_oper->chan_width) {
309 case IEEE80211_VHT_CHANWIDTH_USE_HT:
310 vht_chandef.width = chandef->width;
311 break;
312 case IEEE80211_VHT_CHANWIDTH_80MHZ:
313 vht_chandef.width = NL80211_CHAN_WIDTH_80;
314 break;
315 case IEEE80211_VHT_CHANWIDTH_160MHZ:
316 vht_chandef.width = NL80211_CHAN_WIDTH_160;
317 break;
318 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
319 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
Johannes Berg6553bf042013-03-28 10:26:17 +0100320 vht_chandef.center_freq2 =
321 ieee80211_channel_to_frequency(
322 vht_oper->center_freq_seg2_idx,
323 channel->band);
Johannes Berg6565ec92013-02-08 14:52:32 +0100324 break;
325 default:
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100326 if (verbose)
327 sdata_info(sdata,
328 "AP VHT operation IE has invalid channel width (%d), disable VHT\n",
329 vht_oper->chan_width);
Johannes Berg6565ec92013-02-08 14:52:32 +0100330 ret = IEEE80211_STA_DISABLE_VHT;
331 goto out;
332 }
333
334 if (!cfg80211_chandef_valid(&vht_chandef)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100335 if (verbose)
336 sdata_info(sdata,
337 "AP VHT information is invalid, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100338 ret = IEEE80211_STA_DISABLE_VHT;
339 goto out;
340 }
341
342 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
343 ret = 0;
344 goto out;
345 }
346
347 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100348 if (verbose)
349 sdata_info(sdata,
350 "AP VHT information doesn't match HT, disable VHT\n");
Johannes Berg6565ec92013-02-08 14:52:32 +0100351 ret = IEEE80211_STA_DISABLE_VHT;
352 goto out;
353 }
354
355 *chandef = vht_chandef;
356
357 ret = 0;
358
359out:
Johannes Berg586e01e2013-02-14 12:13:53 +0100360 /* don't print the message below for VHT mismatch if VHT is disabled */
361 if (ret & IEEE80211_STA_DISABLE_VHT)
362 vht_chandef = *chandef;
363
Johannes Berg6565ec92013-02-08 14:52:32 +0100364 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
365 IEEE80211_CHAN_DISABLED)) {
366 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
367 ret = IEEE80211_STA_DISABLE_HT |
368 IEEE80211_STA_DISABLE_VHT;
369 goto out;
370 }
371
372 ret |= chandef_downgrade(chandef);
373 }
374
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100375 if (chandef->width != vht_chandef.width && verbose)
Johannes Berg6565ec92013-02-08 14:52:32 +0100376 sdata_info(sdata,
377 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
378
379 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
380 return ret;
381}
382
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100383static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
384 struct sta_info *sta,
385 const struct ieee80211_ht_operation *ht_oper,
386 const struct ieee80211_vht_operation *vht_oper,
387 const u8 *bssid, u32 *changed)
Johannes Bergd5522e02009-03-30 13:23:35 +0200388{
389 struct ieee80211_local *local = sdata->local;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100390 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergd5522e02009-03-30 13:23:35 +0200391 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200392 struct ieee80211_channel *chan;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100393 struct cfg80211_chan_def chandef;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200394 u16 ht_opmode;
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100395 u32 flags;
396 enum ieee80211_sta_rx_bandwidth new_sta_bw;
397 int ret;
398
399 /* if HT was/is disabled, don't track any bandwidth changes */
400 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
401 return 0;
402
403 /* don't check VHT if we associated as non-VHT station */
404 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
405 vht_oper = NULL;
Johannes Bergd5522e02009-03-30 13:23:35 +0200406
Johannes Berg11289582013-02-07 17:36:12 +0100407 if (WARN_ON_ONCE(!sta))
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100408 return -EINVAL;
Johannes Berg11289582013-02-07 17:36:12 +0100409
Johannes Bergf2d93302013-02-08 13:15:55 +0100410 chan = sdata->vif.bss_conf.chandef.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200411 sband = local->hw.wiphy->bands[chan->band];
Johannes Berg0aaffa92010-05-05 15:28:27 +0200412
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100413 /* calculate new channel (type) based on HT/VHT operation IEs */
414 flags = ieee80211_determine_chantype(sdata, sband, chan, ht_oper,
415 vht_oper, &chandef, false);
416
417 /*
418 * Downgrade the new channel if we associated with restricted
419 * capabilities. For example, if we associated as a 20 MHz STA
420 * to a 40 MHz AP (due to regulatory, capabilities or config
421 * reasons) then switching to a 40 MHz channel now won't do us
422 * any good -- we couldn't use it with the AP.
423 */
424 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
425 chandef.width == NL80211_CHAN_WIDTH_80P80)
426 flags |= chandef_downgrade(&chandef);
427 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
428 chandef.width == NL80211_CHAN_WIDTH_160)
429 flags |= chandef_downgrade(&chandef);
430 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
431 chandef.width > NL80211_CHAN_WIDTH_20)
432 flags |= chandef_downgrade(&chandef);
433
434 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
435 return 0;
436
437 sdata_info(sdata,
438 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
439 ifmgd->bssid, chandef.chan->center_freq, chandef.width,
440 chandef.center_freq1, chandef.center_freq2);
441
442 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
443 IEEE80211_STA_DISABLE_VHT |
444 IEEE80211_STA_DISABLE_40MHZ |
445 IEEE80211_STA_DISABLE_80P80MHZ |
446 IEEE80211_STA_DISABLE_160MHZ)) ||
447 !cfg80211_chandef_valid(&chandef)) {
448 sdata_info(sdata,
449 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
450 ifmgd->bssid);
451 return -EINVAL;
Johannes Berg64f68e52012-03-28 10:58:37 +0200452 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200453
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100454 switch (chandef.width) {
455 case NL80211_CHAN_WIDTH_20_NOHT:
456 case NL80211_CHAN_WIDTH_20:
457 new_sta_bw = IEEE80211_STA_RX_BW_20;
458 break;
459 case NL80211_CHAN_WIDTH_40:
460 new_sta_bw = IEEE80211_STA_RX_BW_40;
461 break;
462 case NL80211_CHAN_WIDTH_80:
463 new_sta_bw = IEEE80211_STA_RX_BW_80;
464 break;
465 case NL80211_CHAN_WIDTH_80P80:
466 case NL80211_CHAN_WIDTH_160:
467 new_sta_bw = IEEE80211_STA_RX_BW_160;
468 break;
469 default:
470 return -EINVAL;
471 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200472
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100473 if (new_sta_bw > sta->cur_max_bandwidth)
474 new_sta_bw = sta->cur_max_bandwidth;
Johannes Berg64f68e52012-03-28 10:58:37 +0200475
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100476 if (new_sta_bw < sta->sta.bandwidth) {
477 sta->sta.bandwidth = new_sta_bw;
478 rate_control_rate_update(local, sband, sta,
479 IEEE80211_RC_BW_CHANGED);
480 }
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530481
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100482 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
483 if (ret) {
484 sdata_info(sdata,
485 "AP %pM changed bandwidth to incompatible one - disconnect\n",
486 ifmgd->bssid);
487 return ret;
488 }
489
490 if (new_sta_bw > sta->sta.bandwidth) {
491 sta->sta.bandwidth = new_sta_bw;
492 rate_control_rate_update(local, sband, sta,
493 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200494 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200495
Johannes Berg074d46d2012-03-15 19:45:16 +0100496 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200497
498 /* if bss configuration changed store the new one */
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100499 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
500 *changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200501 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Bergd5522e02009-03-30 13:23:35 +0200502 }
503
Johannes Berg30eb1dc2013-02-08 15:12:14 +0100504 return 0;
Johannes Bergd5522e02009-03-30 13:23:35 +0200505}
506
Johannes Berg9c6bd792008-09-11 00:01:52 +0200507/* frame sending functions */
508
Johannes Berg66e67e42012-01-20 13:55:27 +0100509static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
510 struct ieee80211_supported_band *sband,
511 u32 *rates)
512{
513 int i, j, count;
514 *rates = 0;
515 count = 0;
516 for (i = 0; i < supp_rates_len; i++) {
517 int rate = (supp_rates[i] & 0x7F) * 5;
518
519 for (j = 0; j < sband->n_bitrates; j++)
520 if (sband->bitrates[j].bitrate == rate) {
521 *rates |= BIT(j);
522 count++;
523 break;
524 }
525 }
526
527 return count;
528}
529
530static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200531 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100532 struct ieee80211_supported_band *sband,
533 struct ieee80211_channel *channel,
534 enum ieee80211_smps_mode smps)
535{
Johannes Berg66e67e42012-01-20 13:55:27 +0100536 u8 *pos;
537 u32 flags = channel->flags;
538 u16 cap;
539 struct ieee80211_sta_ht_cap ht_cap;
540
541 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
542
Johannes Berg66e67e42012-01-20 13:55:27 +0100543 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
544 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
545
Johannes Berg66e67e42012-01-20 13:55:27 +0100546 /* determine capability flags */
547 cap = ht_cap.cap;
548
Johannes Berg9dde6422012-05-16 23:43:19 +0200549 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100550 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
551 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
552 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
553 cap &= ~IEEE80211_HT_CAP_SGI_40;
554 }
555 break;
556 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
557 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
558 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
559 cap &= ~IEEE80211_HT_CAP_SGI_40;
560 }
561 break;
562 }
563
Johannes Berg24398e32012-03-28 10:58:36 +0200564 /*
565 * If 40 MHz was disabled associate as though we weren't
566 * capable of 40 MHz -- some broken APs will never fall
567 * back to trying to transmit in 20 MHz.
568 */
569 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
570 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
571 cap &= ~IEEE80211_HT_CAP_SGI_40;
572 }
573
Johannes Berg66e67e42012-01-20 13:55:27 +0100574 /* set SM PS mode properly */
575 cap &= ~IEEE80211_HT_CAP_SM_PS;
576 switch (smps) {
577 case IEEE80211_SMPS_AUTOMATIC:
578 case IEEE80211_SMPS_NUM_MODES:
579 WARN_ON(1);
580 case IEEE80211_SMPS_OFF:
581 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
582 IEEE80211_HT_CAP_SM_PS_SHIFT;
583 break;
584 case IEEE80211_SMPS_STATIC:
585 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
586 IEEE80211_HT_CAP_SM_PS_SHIFT;
587 break;
588 case IEEE80211_SMPS_DYNAMIC:
589 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
590 IEEE80211_HT_CAP_SM_PS_SHIFT;
591 break;
592 }
593
594 /* reserve and fill IE */
595 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
596 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
597}
598
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000599static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
600 struct sk_buff *skb,
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100601 struct ieee80211_supported_band *sband,
602 struct ieee80211_vht_cap *ap_vht_cap)
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000603{
604 u8 *pos;
605 u32 cap;
606 struct ieee80211_sta_vht_cap vht_cap;
607
608 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
609
610 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +0100611 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000612
613 /* determine capability flags */
614 cap = vht_cap.cap;
615
Johannes Bergf2d9d272012-11-22 14:11:39 +0100616 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
617 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
618 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
619 }
620
621 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
622 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
623 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
624 }
625
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100626 /*
627 * Some APs apparently get confused if our capabilities are better
628 * than theirs, so restrict what we advertise in the assoc request.
629 */
630 if (!(ap_vht_cap->vht_cap_info &
631 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
632 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
633
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000634 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000635 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000636 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
637}
638
Johannes Berg66e67e42012-01-20 13:55:27 +0100639static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
640{
641 struct ieee80211_local *local = sdata->local;
642 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
643 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
644 struct sk_buff *skb;
645 struct ieee80211_mgmt *mgmt;
646 u8 *pos, qos_info;
647 size_t offset = 0, noffset;
648 int i, count, rates_len, supp_rates_len;
649 u16 capab;
650 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200651 struct ieee80211_chanctx_conf *chanctx_conf;
652 struct ieee80211_channel *chan;
Johannes Berg66e67e42012-01-20 13:55:27 +0100653 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100654
655 lockdep_assert_held(&ifmgd->mtx);
656
Johannes Berg55de9082012-07-26 17:24:39 +0200657 rcu_read_lock();
658 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
659 if (WARN_ON(!chanctx_conf)) {
660 rcu_read_unlock();
661 return;
662 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100663 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200664 rcu_read_unlock();
665 sband = local->hw.wiphy->bands[chan->band];
Johannes Berg66e67e42012-01-20 13:55:27 +0100666
667 if (assoc_data->supp_rates_len) {
668 /*
669 * Get all rates supported by the device and the AP as
670 * some APs don't like getting a superset of their rates
671 * in the association request (e.g. D-Link DAP 1353 in
672 * b-only mode)...
673 */
674 rates_len = ieee80211_compatible_rates(assoc_data->supp_rates,
675 assoc_data->supp_rates_len,
676 sband, &rates);
677 } else {
678 /*
679 * In case AP not provide any supported rates information
680 * before association, we send information element(s) with
681 * all rates that we support.
682 */
683 rates = ~0;
684 rates_len = sband->n_bitrates;
685 }
686
687 skb = alloc_skb(local->hw.extra_tx_headroom +
688 sizeof(*mgmt) + /* bit too much but doesn't matter */
689 2 + assoc_data->ssid_len + /* SSID */
690 4 + rates_len + /* (extended) rates */
691 4 + /* power capability */
692 2 + 2 * sband->n_channels + /* supported channels */
693 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000694 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Johannes Berg66e67e42012-01-20 13:55:27 +0100695 assoc_data->ie_len + /* extra IEs */
696 9, /* WMM */
697 GFP_KERNEL);
698 if (!skb)
699 return;
700
701 skb_reserve(skb, local->hw.extra_tx_headroom);
702
703 capab = WLAN_CAPABILITY_ESS;
704
705 if (sband->band == IEEE80211_BAND_2GHZ) {
706 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
707 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
708 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
709 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
710 }
711
712 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
713 capab |= WLAN_CAPABILITY_PRIVACY;
714
715 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
716 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
717 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
718
719 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
720 memset(mgmt, 0, 24);
721 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
722 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
723 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
724
725 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
726 skb_put(skb, 10);
727 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
728 IEEE80211_STYPE_REASSOC_REQ);
729 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
730 mgmt->u.reassoc_req.listen_interval =
731 cpu_to_le16(local->hw.conf.listen_interval);
732 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
733 ETH_ALEN);
734 } else {
735 skb_put(skb, 4);
736 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
737 IEEE80211_STYPE_ASSOC_REQ);
738 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
739 mgmt->u.assoc_req.listen_interval =
740 cpu_to_le16(local->hw.conf.listen_interval);
741 }
742
743 /* SSID */
744 pos = skb_put(skb, 2 + assoc_data->ssid_len);
745 *pos++ = WLAN_EID_SSID;
746 *pos++ = assoc_data->ssid_len;
747 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
748
749 /* add all rates which were marked to be used above */
750 supp_rates_len = rates_len;
751 if (supp_rates_len > 8)
752 supp_rates_len = 8;
753
754 pos = skb_put(skb, supp_rates_len + 2);
755 *pos++ = WLAN_EID_SUPP_RATES;
756 *pos++ = supp_rates_len;
757
758 count = 0;
759 for (i = 0; i < sband->n_bitrates; i++) {
760 if (BIT(i) & rates) {
761 int rate = sband->bitrates[i].bitrate;
762 *pos++ = (u8) (rate / 5);
763 if (++count == 8)
764 break;
765 }
766 }
767
768 if (rates_len > count) {
769 pos = skb_put(skb, rates_len - count + 2);
770 *pos++ = WLAN_EID_EXT_SUPP_RATES;
771 *pos++ = rates_len - count;
772
773 for (i++; i < sband->n_bitrates; i++) {
774 if (BIT(i) & rates) {
775 int rate = sband->bitrates[i].bitrate;
776 *pos++ = (u8) (rate / 5);
777 }
778 }
779 }
780
781 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
782 /* 1. power capabilities */
783 pos = skb_put(skb, 4);
784 *pos++ = WLAN_EID_PWR_CAPABILITY;
785 *pos++ = 2;
786 *pos++ = 0; /* min tx power */
Johannes Berg55de9082012-07-26 17:24:39 +0200787 *pos++ = chan->max_power; /* max tx power */
Johannes Berg66e67e42012-01-20 13:55:27 +0100788
789 /* 2. supported channels */
790 /* TODO: get this in reg domain format */
791 pos = skb_put(skb, 2 * sband->n_channels + 2);
792 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
793 *pos++ = 2 * sband->n_channels;
794 for (i = 0; i < sband->n_channels; i++) {
795 *pos++ = ieee80211_frequency_to_channel(
796 sband->channels[i].center_freq);
797 *pos++ = 1; /* one channel in the subband*/
798 }
799 }
800
801 /* if present, add any custom IEs that go before HT */
802 if (assoc_data->ie_len && assoc_data->ie) {
803 static const u8 before_ht[] = {
804 WLAN_EID_SSID,
805 WLAN_EID_SUPP_RATES,
806 WLAN_EID_EXT_SUPP_RATES,
807 WLAN_EID_PWR_CAPABILITY,
808 WLAN_EID_SUPPORTED_CHANNELS,
809 WLAN_EID_RSN,
810 WLAN_EID_QOS_CAPA,
811 WLAN_EID_RRM_ENABLED_CAPABILITIES,
812 WLAN_EID_MOBILITY_DOMAIN,
813 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
814 };
815 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
816 before_ht, ARRAY_SIZE(before_ht),
817 offset);
818 pos = skb_put(skb, noffset - offset);
819 memcpy(pos, assoc_data->ie + offset, noffset - offset);
820 offset = noffset;
821 }
822
Johannes Bergf2d9d272012-11-22 14:11:39 +0100823 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
824 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
825 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
826
Johannes Berga8243b72012-11-22 14:32:09 +0100827 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200828 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200829 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100830
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000831 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100832 ieee80211_add_vht_ie(sdata, skb, sband,
833 &assoc_data->ap_vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000834
Johannes Berg66e67e42012-01-20 13:55:27 +0100835 /* if present, add any custom non-vendor IEs that go after HT */
836 if (assoc_data->ie_len && assoc_data->ie) {
837 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
838 assoc_data->ie_len,
839 offset);
840 pos = skb_put(skb, noffset - offset);
841 memcpy(pos, assoc_data->ie + offset, noffset - offset);
842 offset = noffset;
843 }
844
Johannes Berg76f03032012-03-08 15:02:05 +0100845 if (assoc_data->wmm) {
846 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200847 qos_info = ifmgd->uapsd_queues;
848 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100849 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
850 } else {
851 qos_info = 0;
852 }
853
854 pos = skb_put(skb, 9);
855 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
856 *pos++ = 7; /* len */
857 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
858 *pos++ = 0x50;
859 *pos++ = 0xf2;
860 *pos++ = 2; /* WME */
861 *pos++ = 0; /* WME info */
862 *pos++ = 1; /* WME ver */
863 *pos++ = qos_info;
864 }
865
866 /* add any remaining custom (i.e. vendor specific here) IEs */
867 if (assoc_data->ie_len && assoc_data->ie) {
868 noffset = assoc_data->ie_len;
869 pos = skb_put(skb, noffset - offset);
870 memcpy(pos, assoc_data->ie + offset, noffset - offset);
871 }
872
Johannes Berga1845fc2012-06-27 13:18:36 +0200873 drv_mgd_prepare_tx(local, sdata);
874
Johannes Berg66e67e42012-01-20 13:55:27 +0100875 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Johannes Berg1672c0e32013-01-29 15:02:27 +0100876 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
877 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
878 IEEE80211_TX_INTFL_MLME_CONN_TX;
Johannes Berg66e67e42012-01-20 13:55:27 +0100879 ieee80211_tx_skb(sdata, skb);
880}
881
Kalle Valo572e0012009-02-10 17:09:31 +0200882void ieee80211_send_pspoll(struct ieee80211_local *local,
883 struct ieee80211_sub_if_data *sdata)
884{
Kalle Valo572e0012009-02-10 17:09:31 +0200885 struct ieee80211_pspoll *pspoll;
886 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200887
Kalle Valod8cd1892010-01-05 20:16:26 +0200888 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
889 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200890 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200891
Kalle Valod8cd1892010-01-05 20:16:26 +0200892 pspoll = (struct ieee80211_pspoll *) skb->data;
893 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200894
Johannes Berg62ae67b2009-11-18 18:42:05 +0100895 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
896 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200897}
898
Johannes Berg965beda2009-04-16 13:17:24 +0200899void ieee80211_send_nullfunc(struct ieee80211_local *local,
900 struct ieee80211_sub_if_data *sdata,
901 int powersave)
902{
903 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200904 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530905 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200906
Kalle Valod8cd1892010-01-05 20:16:26 +0200907 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
908 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200909 return;
910
Kalle Valod8cd1892010-01-05 20:16:26 +0200911 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200912 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200913 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200914
Seth Forshee6c17b772013-02-11 11:21:07 -0600915 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
916 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530917 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
918 IEEE80211_STA_CONNECTION_POLL))
919 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
920
Johannes Berg62ae67b2009-11-18 18:42:05 +0100921 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200922}
923
Felix Fietkaud5242152010-01-08 18:06:26 +0100924static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
925 struct ieee80211_sub_if_data *sdata)
926{
927 struct sk_buff *skb;
928 struct ieee80211_hdr *nullfunc;
929 __le16 fc;
930
931 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
932 return;
933
934 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -0700935 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +0100936 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700937
Felix Fietkaud5242152010-01-08 18:06:26 +0100938 skb_reserve(skb, local->hw.extra_tx_headroom);
939
940 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
941 memset(nullfunc, 0, 30);
942 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
943 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
944 nullfunc->frame_control = fc;
945 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
946 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
947 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
948 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
949
950 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
951 ieee80211_tx_skb(sdata, skb);
952}
953
Johannes Bergcc32abd2009-05-15 11:52:31 +0200954/* spectrum management related things */
955static void ieee80211_chswitch_work(struct work_struct *work)
956{
957 struct ieee80211_sub_if_data *sdata =
958 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Karl Beldan675a0b02013-03-25 16:26:57 +0100959 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200960 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
961
Johannes Berg9607e6b662009-12-23 13:15:31 +0100962 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200963 return;
964
Johannes Berg77fdaa12009-07-07 03:45:17 +0200965 mutex_lock(&ifmgd->mtx);
966 if (!ifmgd->associated)
967 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200968
Johannes Berg85220d72013-03-25 18:29:27 +0100969 local->_oper_chandef = local->csa_chandef;
Karl Beldan675a0b02013-03-25 16:26:57 +0100970
971 if (!local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +0200972 /* call "hw_config" only if doing sw channel switch */
Karl Beldan675a0b02013-03-25 16:26:57 +0100973 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
Shahar Levi1ea57b12011-09-08 08:44:05 +0300974 } else {
975 /* update the device channel directly */
Karl Beldan675a0b02013-03-25 16:26:57 +0100976 local->hw.conf.chandef = local->_oper_chandef;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200977 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200978
Johannes Berg77fdaa12009-07-07 03:45:17 +0200979 /* XXX: shouldn't really modify cfg80211-owned data! */
Karl Beldan675a0b02013-03-25 16:26:57 +0100980 ifmgd->associated->channel = local->_oper_chandef.chan;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200981
Johannes Berg57eebdf2012-08-01 15:50:46 +0200982 /* XXX: wait for a beacon first? */
Karl Beldan675a0b02013-03-25 16:26:57 +0100983 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +0100984 IEEE80211_MAX_QUEUE_MAP,
Johannes Bergcc32abd2009-05-15 11:52:31 +0200985 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200986 out:
987 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
988 mutex_unlock(&ifmgd->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200989}
990
Johannes Berg5ce6e432010-05-11 16:20:57 +0200991void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
992{
Johannes Berg55de9082012-07-26 17:24:39 +0200993 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
994 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200995
996 trace_api_chswitch_done(sdata, success);
997 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +0200998 sdata_info(sdata,
999 "driver channel switch failed, disconnecting\n");
1000 ieee80211_queue_work(&sdata->local->hw,
1001 &ifmgd->csa_connection_drop_work);
1002 } else {
1003 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001004 }
Johannes Berg5ce6e432010-05-11 16:20:57 +02001005}
1006EXPORT_SYMBOL(ieee80211_chswitch_done);
1007
Johannes Bergcc32abd2009-05-15 11:52:31 +02001008static void ieee80211_chswitch_timer(unsigned long data)
1009{
1010 struct ieee80211_sub_if_data *sdata =
1011 (struct ieee80211_sub_if_data *) data;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001012
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01001013 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001014}
1015
Johannes Berg37799e52013-03-26 14:02:26 +01001016static void
Johannes Berg4a3cb702013-02-12 16:43:19 +01001017ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
Johannes Berg04a161f2013-05-03 09:35:35 +02001018 u64 timestamp, struct ieee802_11_elems *elems,
1019 bool beacon)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001020{
Johannes Bergb4f286a12013-03-26 14:13:58 +01001021 struct ieee80211_local *local = sdata->local;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001022 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg37799e52013-03-26 14:02:26 +01001023 struct cfg80211_bss *cbss = ifmgd->associated;
1024 struct ieee80211_bss *bss;
Johannes Berg55de9082012-07-26 17:24:39 +02001025 struct ieee80211_chanctx *chanctx;
Johannes Bergb4f286a12013-03-26 14:13:58 +01001026 enum ieee80211_band new_band;
1027 int new_freq;
1028 u8 new_chan_no;
1029 u8 count;
1030 u8 mode;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001031 struct ieee80211_channel *new_chan;
Johannes Berg85220d72013-03-25 18:29:27 +01001032 struct cfg80211_chan_def new_chandef = {};
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001033 struct cfg80211_chan_def new_vht_chandef = {};
1034 const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1035 const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
Johannes Berg04a161f2013-05-03 09:35:35 +02001036 const struct ieee80211_ht_operation *ht_oper;
Johannes Berg85220d72013-03-25 18:29:27 +01001037 int secondary_channel_offset = -1;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001038
Johannes Berg77fdaa12009-07-07 03:45:17 +02001039 ASSERT_MGD_MTX(ifmgd);
1040
Johannes Berg37799e52013-03-26 14:02:26 +01001041 if (!cbss)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001042 return;
1043
Johannes Bergb4f286a12013-03-26 14:13:58 +01001044 if (local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001045 return;
1046
Johannes Berg37799e52013-03-26 14:02:26 +01001047 /* disregard subsequent announcements if we are already processing */
Johannes Bergcc32abd2009-05-15 11:52:31 +02001048 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1049 return;
1050
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001051 sec_chan_offs = elems->sec_chan_offs;
1052 wide_bw_chansw_ie = elems->wide_bw_chansw_ie;
Johannes Berg04a161f2013-05-03 09:35:35 +02001053 ht_oper = elems->ht_operation;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001054
1055 if (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
1056 IEEE80211_STA_DISABLE_40MHZ)) {
1057 sec_chan_offs = NULL;
1058 wide_bw_chansw_ie = NULL;
Johannes Berg04a161f2013-05-03 09:35:35 +02001059 /* only used for bandwidth here */
1060 ht_oper = NULL;
Johannes Berg85220d72013-03-25 18:29:27 +01001061 }
1062
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001063 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
1064 wide_bw_chansw_ie = NULL;
Johannes Berg85220d72013-03-25 18:29:27 +01001065
Johannes Bergb4f286a12013-03-26 14:13:58 +01001066 if (elems->ext_chansw_ie) {
1067 if (!ieee80211_operating_class_to_band(
1068 elems->ext_chansw_ie->new_operating_class,
1069 &new_band)) {
1070 sdata_info(sdata,
1071 "cannot understand ECSA IE operating class %d, disconnecting\n",
1072 elems->ext_chansw_ie->new_operating_class);
1073 ieee80211_queue_work(&local->hw,
1074 &ifmgd->csa_connection_drop_work);
1075 }
1076 new_chan_no = elems->ext_chansw_ie->new_ch_num;
1077 count = elems->ext_chansw_ie->count;
1078 mode = elems->ext_chansw_ie->mode;
1079 } else if (elems->ch_switch_ie) {
1080 new_band = cbss->channel->band;
1081 new_chan_no = elems->ch_switch_ie->new_ch_num;
1082 count = elems->ch_switch_ie->count;
1083 mode = elems->ch_switch_ie->mode;
1084 } else {
1085 /* nothing here we understand */
Johannes Berg37799e52013-03-26 14:02:26 +01001086 return;
Johannes Bergb4f286a12013-03-26 14:13:58 +01001087 }
Johannes Berg37799e52013-03-26 14:02:26 +01001088
1089 bss = (void *)cbss->priv;
1090
Johannes Bergb4f286a12013-03-26 14:13:58 +01001091 new_freq = ieee80211_channel_to_frequency(new_chan_no, new_band);
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001092 new_chan = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1093 if (!new_chan || new_chan->flags & IEEE80211_CHAN_DISABLED) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001094 sdata_info(sdata,
1095 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
1096 ifmgd->associated->bssid, new_freq);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001097 ieee80211_queue_work(&local->hw,
Johannes Berg882a7c62012-08-01 22:32:45 +02001098 &ifmgd->csa_connection_drop_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +02001099 return;
Johannes Berg882a7c62012-08-01 22:32:45 +02001100 }
Johannes Bergcc32abd2009-05-15 11:52:31 +02001101
Johannes Berg04a161f2013-05-03 09:35:35 +02001102 if (!beacon && sec_chan_offs) {
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001103 secondary_channel_offset = sec_chan_offs->sec_chan_offs;
Johannes Berg04a161f2013-05-03 09:35:35 +02001104 } else if (beacon && ht_oper) {
1105 secondary_channel_offset =
1106 ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001107 } else if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
Johannes Berg04a161f2013-05-03 09:35:35 +02001108 /*
1109 * If it's not a beacon, HT is enabled and the IE not present,
1110 * it's 20 MHz, 802.11-2012 8.5.2.6:
1111 * This element [the Secondary Channel Offset Element] is
1112 * present when switching to a 40 MHz channel. It may be
1113 * present when switching to a 20 MHz channel (in which
1114 * case the secondary channel offset is set to SCN).
1115 */
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001116 secondary_channel_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1117 }
1118
Johannes Berg85220d72013-03-25 18:29:27 +01001119 switch (secondary_channel_offset) {
1120 default:
1121 /* secondary_channel_offset was present but is invalid */
1122 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001123 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001124 NL80211_CHAN_HT20);
1125 break;
1126 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001127 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001128 NL80211_CHAN_HT40PLUS);
1129 break;
1130 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001131 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001132 NL80211_CHAN_HT40MINUS);
1133 break;
1134 case -1:
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001135 cfg80211_chandef_create(&new_chandef, new_chan,
Johannes Berg85220d72013-03-25 18:29:27 +01001136 NL80211_CHAN_NO_HT);
1137 break;
1138 }
1139
Johannes Bergcd64f2a2013-03-28 10:44:18 +01001140 if (wide_bw_chansw_ie) {
1141 new_vht_chandef.chan = new_chan;
1142 new_vht_chandef.center_freq1 =
1143 ieee80211_channel_to_frequency(
1144 wide_bw_chansw_ie->new_center_freq_seg0,
1145 new_band);
1146
1147 switch (wide_bw_chansw_ie->new_channel_width) {
1148 default:
1149 /* hmmm, ignore VHT and use HT if present */
1150 case IEEE80211_VHT_CHANWIDTH_USE_HT:
1151 new_vht_chandef.chan = NULL;
1152 break;
1153 case IEEE80211_VHT_CHANWIDTH_80MHZ:
1154 new_vht_chandef.width = NL80211_CHAN_WIDTH_80;
1155 break;
1156 case IEEE80211_VHT_CHANWIDTH_160MHZ:
1157 new_vht_chandef.width = NL80211_CHAN_WIDTH_160;
1158 break;
1159 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1160 /* field is otherwise reserved */
1161 new_vht_chandef.center_freq2 =
1162 ieee80211_channel_to_frequency(
1163 wide_bw_chansw_ie->new_center_freq_seg1,
1164 new_band);
1165 new_vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1166 break;
1167 }
1168 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
1169 new_vht_chandef.width == NL80211_CHAN_WIDTH_80P80)
1170 chandef_downgrade(&new_vht_chandef);
1171 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
1172 new_vht_chandef.width == NL80211_CHAN_WIDTH_160)
1173 chandef_downgrade(&new_vht_chandef);
1174 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
1175 new_vht_chandef.width > NL80211_CHAN_WIDTH_20)
1176 chandef_downgrade(&new_vht_chandef);
1177 }
1178
1179 /* if VHT data is there validate & use it */
1180 if (new_vht_chandef.chan) {
1181 if (!cfg80211_chandef_compatible(&new_vht_chandef,
1182 &new_chandef)) {
1183 sdata_info(sdata,
1184 "AP %pM CSA has inconsistent channel data, disconnecting\n",
1185 ifmgd->associated->bssid);
1186 ieee80211_queue_work(&local->hw,
1187 &ifmgd->csa_connection_drop_work);
1188 return;
1189 }
1190 new_chandef = new_vht_chandef;
1191 }
1192
Johannes Berg85220d72013-03-25 18:29:27 +01001193 if (!cfg80211_chandef_usable(local->hw.wiphy, &new_chandef,
1194 IEEE80211_CHAN_DISABLED)) {
1195 sdata_info(sdata,
1196 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1197 ifmgd->associated->bssid, new_freq,
1198 new_chandef.width, new_chandef.center_freq1,
1199 new_chandef.center_freq2);
1200 ieee80211_queue_work(&local->hw,
1201 &ifmgd->csa_connection_drop_work);
1202 return;
1203 }
1204
Johannes Berg57eebdf2012-08-01 15:50:46 +02001205 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
1206
Johannes Bergb4f286a12013-03-26 14:13:58 +01001207 if (local->use_chanctx) {
Johannes Berg55de9082012-07-26 17:24:39 +02001208 sdata_info(sdata,
1209 "not handling channel switch with channel contexts\n");
Johannes Bergb4f286a12013-03-26 14:13:58 +01001210 ieee80211_queue_work(&local->hw,
Johannes Berg55de9082012-07-26 17:24:39 +02001211 &ifmgd->csa_connection_drop_work);
Simon Wunderlich246dc3f2012-11-30 19:17:27 +01001212 return;
Johannes Berg55de9082012-07-26 17:24:39 +02001213 }
1214
Johannes Bergb4f286a12013-03-26 14:13:58 +01001215 mutex_lock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001216 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
Johannes Bergb4f286a12013-03-26 14:13:58 +01001217 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001218 return;
1219 }
1220 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
1221 struct ieee80211_chanctx, conf);
1222 if (chanctx->refcount > 1) {
1223 sdata_info(sdata,
1224 "channel switch with multiple interfaces on the same channel, disconnecting\n");
Johannes Bergb4f286a12013-03-26 14:13:58 +01001225 ieee80211_queue_work(&local->hw,
Johannes Berg55de9082012-07-26 17:24:39 +02001226 &ifmgd->csa_connection_drop_work);
Johannes Bergb4f286a12013-03-26 14:13:58 +01001227 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001228 return;
1229 }
Johannes Bergb4f286a12013-03-26 14:13:58 +01001230 mutex_unlock(&local->chanctx_mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001231
Johannes Berg85220d72013-03-25 18:29:27 +01001232 local->csa_chandef = new_chandef;
Johannes Berg55de9082012-07-26 17:24:39 +02001233
Johannes Bergb4f286a12013-03-26 14:13:58 +01001234 if (mode)
1235 ieee80211_stop_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001236 IEEE80211_MAX_QUEUE_MAP,
Johannes Berg57eebdf2012-08-01 15:50:46 +02001237 IEEE80211_QUEUE_STOP_REASON_CSA);
1238
Johannes Bergb4f286a12013-03-26 14:13:58 +01001239 if (local->ops->channel_switch) {
Johannes Berg5ce6e432010-05-11 16:20:57 +02001240 /* use driver's channel switch callback */
Johannes Berg57eebdf2012-08-01 15:50:46 +02001241 struct ieee80211_channel_switch ch_switch = {
1242 .timestamp = timestamp,
Johannes Bergb4f286a12013-03-26 14:13:58 +01001243 .block_tx = mode,
Johannes Berg85220d72013-03-25 18:29:27 +01001244 .chandef = new_chandef,
Johannes Bergb4f286a12013-03-26 14:13:58 +01001245 .count = count,
Johannes Berg57eebdf2012-08-01 15:50:46 +02001246 };
1247
Johannes Bergb4f286a12013-03-26 14:13:58 +01001248 drv_channel_switch(local, &ch_switch);
Johannes Berg5ce6e432010-05-11 16:20:57 +02001249 return;
1250 }
1251
1252 /* channel switch handled in software */
Johannes Bergb4f286a12013-03-26 14:13:58 +01001253 if (count <= 1)
1254 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +02001255 else
Johannes Bergcc32abd2009-05-15 11:52:31 +02001256 mod_timer(&ifmgd->chswitch_timer,
Johannes Bergb4f286a12013-03-26 14:13:58 +01001257 TU_TO_EXP_TIME(count * cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +02001258}
1259
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001260static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1261 struct ieee80211_channel *channel,
1262 const u8 *country_ie, u8 country_ie_len,
1263 const u8 *pwr_constr_elem)
Johannes Bergcc32abd2009-05-15 11:52:31 +02001264{
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001265 struct ieee80211_country_ie_triplet *triplet;
1266 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1267 int i, chan_pwr, chan_increment, new_ap_level;
1268 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001269
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001270 /* Invalid IE */
1271 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001272 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001273
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001274 triplet = (void *)(country_ie + 3);
1275 country_ie_len -= 3;
1276
1277 switch (channel->band) {
1278 default:
1279 WARN_ON_ONCE(1);
1280 /* fall through */
1281 case IEEE80211_BAND_2GHZ:
1282 case IEEE80211_BAND_60GHZ:
1283 chan_increment = 1;
1284 break;
1285 case IEEE80211_BAND_5GHZ:
1286 chan_increment = 4;
1287 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001288 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001289
1290 /* find channel */
1291 while (country_ie_len >= 3) {
1292 u8 first_channel = triplet->chans.first_channel;
1293
1294 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1295 goto next;
1296
1297 for (i = 0; i < triplet->chans.num_channels; i++) {
1298 if (first_channel + i * chan_increment == chan) {
1299 have_chan_pwr = true;
1300 chan_pwr = triplet->chans.max_power;
1301 break;
1302 }
1303 }
1304 if (have_chan_pwr)
1305 break;
1306
1307 next:
1308 triplet++;
1309 country_ie_len -= 3;
1310 }
1311
1312 if (!have_chan_pwr)
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001313 return 0;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001314
1315 new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
1316
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001317 if (sdata->ap_power_level == new_ap_level)
1318 return 0;
Johannes Berg04b7b2f2012-09-05 13:41:37 +02001319
1320 sdata_info(sdata,
1321 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1322 new_ap_level, chan_pwr, *pwr_constr_elem,
1323 sdata->u.mgd.bssid);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001324 sdata->ap_power_level = new_ap_level;
1325 if (__ieee80211_recalc_txpower(sdata))
1326 return BSS_CHANGED_TXPOWER;
1327 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001328}
1329
Johannes Berg965beda2009-04-16 13:17:24 +02001330/* powersave */
1331static void ieee80211_enable_ps(struct ieee80211_local *local,
1332 struct ieee80211_sub_if_data *sdata)
1333{
1334 struct ieee80211_conf *conf = &local->hw.conf;
1335
Johannes Bergd5edaed2009-04-22 23:02:51 +02001336 /*
1337 * If we are scanning right now then the parameters will
1338 * take effect when scan finishes.
1339 */
Helmut Schaafbe9c4292009-07-23 12:14:04 +02001340 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +02001341 return;
1342
Johannes Berg965beda2009-04-16 13:17:24 +02001343 if (conf->dynamic_ps_timeout > 0 &&
1344 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
1345 mod_timer(&local->dynamic_ps_timer, jiffies +
1346 msecs_to_jiffies(conf->dynamic_ps_timeout));
1347 } else {
1348 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1349 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +05301350
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001351 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
1352 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
1353 return;
1354
1355 conf->flags |= IEEE80211_CONF_PS;
1356 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +02001357 }
1358}
1359
1360static void ieee80211_change_ps(struct ieee80211_local *local)
1361{
1362 struct ieee80211_conf *conf = &local->hw.conf;
1363
1364 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +02001365 ieee80211_enable_ps(local, local->ps_sdata);
1366 } else if (conf->flags & IEEE80211_CONF_PS) {
1367 conf->flags &= ~IEEE80211_CONF_PS;
1368 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1369 del_timer_sync(&local->dynamic_ps_timer);
1370 cancel_work_sync(&local->dynamic_ps_enable_work);
1371 }
1372}
1373
Jason Young808118c2011-03-10 16:43:19 -08001374static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1375{
1376 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1377 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001378 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001379
1380 if (!mgd->powersave)
1381 return false;
1382
Johannes Berg05cb9102011-10-28 11:59:47 +02001383 if (mgd->broken_ap)
1384 return false;
1385
Jason Young808118c2011-03-10 16:43:19 -08001386 if (!mgd->associated)
1387 return false;
1388
Jason Young808118c2011-03-10 16:43:19 -08001389 if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
1390 IEEE80211_STA_CONNECTION_POLL))
1391 return false;
1392
Alexander Bondarce857882013-05-06 17:17:04 +03001393 if (!sdata->vif.bss_conf.dtim_period)
1394 return false;
1395
Jason Young808118c2011-03-10 16:43:19 -08001396 rcu_read_lock();
1397 sta = sta_info_get(sdata, mgd->bssid);
1398 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001399 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001400 rcu_read_unlock();
1401
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001402 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001403}
1404
Johannes Berg965beda2009-04-16 13:17:24 +02001405/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +02001406void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +02001407{
1408 struct ieee80211_sub_if_data *sdata, *found = NULL;
1409 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001410 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001411
1412 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
1413 local->ps_sdata = NULL;
1414 return;
1415 }
1416
1417 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b662009-12-23 13:15:31 +01001418 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001419 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301420 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1421 /* If an AP vif is found, then disable PS
1422 * by setting the count to zero thereby setting
1423 * ps_sdata to NULL.
1424 */
1425 count = 0;
1426 break;
1427 }
Johannes Berg965beda2009-04-16 13:17:24 +02001428 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1429 continue;
1430 found = sdata;
1431 count++;
1432 }
1433
Jason Young808118c2011-03-10 16:43:19 -08001434 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg10f644a2009-04-16 13:17:25 +02001435 s32 beaconint_us;
1436
1437 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +02001438 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +02001439
1440 beaconint_us = ieee80211_tu_to_usec(
1441 found->vif.bss_conf.beacon_int);
1442
Juuso Oikarinenff616382010-06-09 09:51:52 +03001443 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001444 if (timeout < 0) {
1445 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +03001446 * Go to full PSM if the user configures a very low
1447 * latency requirement.
Eliad Peller0ab82b02010-12-03 02:16:23 +02001448 * The 2000 second value is there for compatibility
1449 * until the PM_QOS_NETWORK_LATENCY is configured
1450 * with real values.
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001451 */
Eliad Peller0ab82b02010-12-03 02:16:23 +02001452 if (latency > (1900 * USEC_PER_MSEC) &&
1453 latency != (2000 * USEC_PER_SEC))
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001454 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001455 else
1456 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001457 }
Johannes Berg09b85562013-02-06 23:07:41 +01001458 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001459
Johannes Berg04fe2032009-04-22 18:44:37 +02001460 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +02001461 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +02001462 } else {
Johannes Berg04fe2032009-04-22 18:44:37 +02001463 int maxslp = 1;
Johannes Berg826262c2012-12-10 16:38:14 +02001464 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg56007a02010-01-26 14:19:52 +01001465
1466 /* If the TIM IE is invalid, pretend the value is 1 */
1467 if (!dtimper)
1468 dtimper = 1;
1469 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +02001470 maxslp = min_t(int, dtimper,
1471 latency / beaconint_us);
1472
Johannes Berg9ccebe62009-04-23 10:32:36 +02001473 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +01001474 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +02001475 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +02001476 }
Johannes Berg10f644a2009-04-16 13:17:25 +02001477 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001478 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001479 }
Johannes Berg965beda2009-04-16 13:17:24 +02001480
1481 ieee80211_change_ps(local);
1482}
1483
Eliad Pellerab095872012-07-27 12:33:22 +03001484void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1485{
1486 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1487
1488 if (sdata->vif.bss_conf.ps != ps_allowed) {
1489 sdata->vif.bss_conf.ps = ps_allowed;
1490 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1491 }
1492}
1493
Johannes Berg965beda2009-04-16 13:17:24 +02001494void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1495{
1496 struct ieee80211_local *local =
1497 container_of(work, struct ieee80211_local,
1498 dynamic_ps_disable_work);
1499
1500 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1501 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1502 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1503 }
1504
1505 ieee80211_wake_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01001506 IEEE80211_MAX_QUEUE_MAP,
Johannes Berg965beda2009-04-16 13:17:24 +02001507 IEEE80211_QUEUE_STOP_REASON_PS);
1508}
1509
1510void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1511{
1512 struct ieee80211_local *local =
1513 container_of(work, struct ieee80211_local,
1514 dynamic_ps_enable_work);
1515 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001516 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301517 unsigned long flags;
1518 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001519
1520 /* can only happen when PS was just disabled anyway */
1521 if (!sdata)
1522 return;
1523
Christian Lamparter5e340692011-06-30 21:08:43 +02001524 ifmgd = &sdata->u.mgd;
1525
Johannes Berg965beda2009-04-16 13:17:24 +02001526 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1527 return;
1528
Johannes Berg09b85562013-02-06 23:07:41 +01001529 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001530 /* don't enter PS if TX frames are pending */
1531 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301532 mod_timer(&local->dynamic_ps_timer, jiffies +
1533 msecs_to_jiffies(
1534 local->hw.conf.dynamic_ps_timeout));
1535 return;
1536 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001537
1538 /*
1539 * transmission can be stopped by others which leads to
1540 * dynamic_ps_timer expiry. Postpone the ps timer if it
1541 * is not the actual idle state.
1542 */
1543 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1544 for (q = 0; q < local->hw.queues; q++) {
1545 if (local->queue_stop_reasons[q]) {
1546 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1547 flags);
1548 mod_timer(&local->dynamic_ps_timer, jiffies +
1549 msecs_to_jiffies(
1550 local->hw.conf.dynamic_ps_timeout));
1551 return;
1552 }
1553 }
1554 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301555 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301556
Vivek Natarajan375177b2010-02-09 14:50:28 +05301557 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301558 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Johannes Berga1598382013-03-26 22:02:42 +01001559 if (drv_tx_frames_pending(local)) {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301560 mod_timer(&local->dynamic_ps_timer, jiffies +
1561 msecs_to_jiffies(
1562 local->hw.conf.dynamic_ps_timeout));
Johannes Berga1598382013-03-26 22:02:42 +01001563 } else {
Vivek Natarajane8306f92011-04-06 11:41:10 +05301564 ieee80211_send_nullfunc(local, sdata, 1);
1565 /* Flush to get the tx status of nullfunc frame */
Johannes Berg39ecc012013-02-13 12:11:00 +01001566 ieee80211_flush_queues(local, sdata);
Vivek Natarajane8306f92011-04-06 11:41:10 +05301567 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301568 }
1569
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001570 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
1571 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301572 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1573 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1574 local->hw.conf.flags |= IEEE80211_CONF_PS;
1575 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1576 }
Johannes Berg965beda2009-04-16 13:17:24 +02001577}
1578
1579void ieee80211_dynamic_ps_timer(unsigned long data)
1580{
1581 struct ieee80211_local *local = (void *) data;
1582
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -07001583 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +02001584 return;
1585
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001586 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001587}
1588
Simon Wunderlich164eb022013-02-08 18:16:20 +01001589void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1590{
1591 struct delayed_work *delayed_work =
1592 container_of(work, struct delayed_work, work);
1593 struct ieee80211_sub_if_data *sdata =
1594 container_of(delayed_work, struct ieee80211_sub_if_data,
1595 dfs_cac_timer_work);
1596
1597 ieee80211_vif_release_channel(sdata);
1598
1599 cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
1600}
1601
Johannes Berg60f8b392008-09-08 17:44:22 +02001602/* MLME */
Johannes Berg7d257452012-07-06 17:37:43 +02001603static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +02001604 struct ieee80211_sub_if_data *sdata,
Johannes Berg4a3cb702013-02-12 16:43:19 +01001605 const u8 *wmm_param, size_t wmm_param_len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001606{
Jiri Bencf0706e82007-05-05 11:45:53 -07001607 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +02001608 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001609 size_t left;
1610 int count;
Johannes Berg4a3cb702013-02-12 16:43:19 +01001611 const u8 *pos;
1612 u8 uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001613
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001614 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001615 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001616
Johannes Berg32c50572012-03-28 11:04:29 +02001617 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001618 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001619
1620 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001621 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001622
Jiri Bencf0706e82007-05-05 11:45:53 -07001623 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001624 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001625
1626 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001627 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001628
Jiri Bencf0706e82007-05-05 11:45:53 -07001629 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +01001630 if (count == ifmgd->wmm_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001631 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001632 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001633
1634 pos = wmm_param + 8;
1635 left = wmm_param_len - 8;
1636
1637 memset(&params, 0, sizeof(params));
1638
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001639 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001640 for (; left >= 4; left -= 4, pos += 4) {
1641 int aci = (pos[0] >> 5) & 0x03;
1642 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001643 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001644 int queue;
1645
1646 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001647 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +02001648 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +02001649 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001650 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001651 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1652 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001653 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001654 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +02001655 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +02001656 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001657 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001658 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1659 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001660 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001661 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +02001662 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +02001663 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001664 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02001665 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1666 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001667 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001668 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001669 default:
Johannes Berge100bb62008-04-30 18:51:21 +02001670 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +02001671 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001672 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02001673 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1674 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001675 break;
1676 }
1677
1678 params.aifs = pos[0] & 0x0f;
1679 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1680 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +02001681 params.txop = get_unaligned_le16(pos + 2);
Alexander Bondar908f8d02013-04-07 09:53:30 +03001682 params.acm = acm;
Kalle Valoab133152010-01-12 10:42:31 +02001683 params.uapsd = uapsd;
1684
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001685 mlme_dbg(sdata,
1686 "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
1687 queue, aci, acm,
1688 params.aifs, params.cw_min, params.cw_max,
1689 params.txop, params.uapsd);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001690 sdata->tx_conf[queue] = params;
1691 if (drv_conf_tx(local, sdata, queue, &params))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001692 sdata_err(sdata,
1693 "failed to set TX queue parameters for queue %d\n",
1694 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -07001695 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001696
1697 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02001698 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02001699 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001700}
1701
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001702static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1703{
1704 lockdep_assert_held(&sdata->local->mtx);
1705
1706 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1707 IEEE80211_STA_BEACON_POLL);
1708 ieee80211_run_deferred_scan(sdata->local);
1709}
1710
1711static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1712{
1713 mutex_lock(&sdata->local->mtx);
1714 __ieee80211_stop_poll(sdata);
1715 mutex_unlock(&sdata->local->mtx);
1716}
1717
Johannes Berg7a5158e2008-10-08 10:59:33 +02001718static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1719 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02001720{
Johannes Bergbda39332008-10-11 01:51:51 +02001721 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001722 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001723 bool use_protection;
1724 bool use_short_preamble;
1725 bool use_short_slot;
1726
1727 if (erp_valid) {
1728 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1729 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1730 } else {
1731 use_protection = false;
1732 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1733 }
1734
1735 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Johannes Berg55de9082012-07-26 17:24:39 +02001736 if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01001737 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02001738
Johannes Berg471b3ef2007-12-28 14:32:58 +01001739 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01001740 bss_conf->use_cts_prot = use_protection;
1741 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02001742 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02001743
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001744 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001745 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001746 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02001747 }
Daniel Draked9430a32007-07-27 15:43:24 +02001748
Johannes Berg7a5158e2008-10-08 10:59:33 +02001749 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02001750 bss_conf->use_short_slot = use_short_slot;
1751 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04001752 }
1753
1754 return changed;
1755}
1756
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001757static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001758 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02001759 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07001760{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001761 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001762 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001763 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001764
Johannes Bergae5eb022008-10-14 16:58:37 +02001765 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001766 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03001767 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001768
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01001769 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
Ben Greear59c1ec22013-03-19 14:19:56 -07001770 beacon_loss_count * bss_conf->beacon_int));
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01001771
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001772 sdata->u.mgd.associated = cbss;
1773 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01001774
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001775 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1776
Johannes Berg488dd7b2012-10-29 20:08:01 +01001777 if (sdata->vif.p2p) {
Johannes Berg9caf0362012-11-29 01:25:20 +01001778 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01001779
Johannes Berg9caf0362012-11-29 01:25:20 +01001780 rcu_read_lock();
1781 ies = rcu_dereference(cbss->ies);
1782 if (ies) {
Johannes Berg9caf0362012-11-29 01:25:20 +01001783 int ret;
1784
1785 ret = cfg80211_get_p2p_attr(
1786 ies->data, ies->len,
1787 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001788 (u8 *) &bss_conf->p2p_noa_attr,
1789 sizeof(bss_conf->p2p_noa_attr));
Johannes Berg9caf0362012-11-29 01:25:20 +01001790 if (ret >= 2) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001791 sdata->u.mgd.p2p_noa_index =
1792 bss_conf->p2p_noa_attr.index;
Johannes Berg9caf0362012-11-29 01:25:20 +01001793 bss_info_changed |= BSS_CHANGED_P2P_PS;
Johannes Berg9caf0362012-11-29 01:25:20 +01001794 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01001795 }
Johannes Berg9caf0362012-11-29 01:25:20 +01001796 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01001797 }
1798
Johannes Bergb291ba12009-07-10 15:29:03 +02001799 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001800 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001801
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001802 ieee80211_led_assoc(local, 1);
1803
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02001804 if (sdata->u.mgd.assoc_data->have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02001805 /*
1806 * If the AP is buggy we may get here with no DTIM period
1807 * known, so assume it's 1 which is the only safe assumption
1808 * in that case, although if the TIM IE is broken powersave
1809 * probably just won't work at all.
1810 */
1811 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02001812 bss_info_changed |= BSS_CHANGED_DTIM_PERIOD;
Johannes Berg826262c2012-12-10 16:38:14 +02001813 } else {
Johannes Berge5b900d2010-07-29 16:08:55 +02001814 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02001815 }
Johannes Berge5b900d2010-07-29 16:08:55 +02001816
Juuso Oikarinen68542962010-06-09 13:43:26 +03001817 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02001818
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001819 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01001820 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03001821 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001822 bss_info_changed |= BSS_CHANGED_CQM;
1823
Juuso Oikarinen68542962010-06-09 13:43:26 +03001824 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01001825 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03001826 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001827
Johannes Bergae5eb022008-10-14 16:58:37 +02001828 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03001829
Johannes Berg056508d2009-07-30 21:43:55 +02001830 mutex_lock(&local->iflist_mtx);
1831 ieee80211_recalc_ps(local, -1);
1832 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02001833
Johannes Berg04ecd252012-09-11 14:34:12 +02001834 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03001835 ieee80211_recalc_ps_vif(sdata);
1836
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001837 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001838}
1839
Jouni Malinene69e95d2010-03-29 23:29:31 -07001840static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01001841 u16 stype, u16 reason, bool tx,
1842 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03001843{
Johannes Berg46900292009-02-15 12:44:28 +01001844 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001845 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01001846 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001847
Johannes Berg77fdaa12009-07-07 03:45:17 +02001848 ASSERT_MGD_MTX(ifmgd);
1849
Johannes Berg37ad3882012-02-24 13:50:54 +01001850 if (WARN_ON_ONCE(tx && !frame_buf))
1851 return;
1852
Johannes Bergb291ba12009-07-10 15:29:03 +02001853 if (WARN_ON(!ifmgd->associated))
1854 return;
1855
David Spinadel79543d82012-06-12 09:59:45 +03001856 ieee80211_stop_poll(sdata);
1857
Johannes Berg77fdaa12009-07-07 03:45:17 +02001858 ifmgd->associated = NULL;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001859 netif_carrier_off(sdata->dev);
1860
Eliad Peller88bc40e2012-07-12 17:35:33 +03001861 /*
1862 * if we want to get out of ps before disassoc (why?) we have
1863 * to do it before sending disassoc, as otherwise the null-packet
1864 * won't be valid.
1865 */
1866 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1867 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1868 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1869 }
1870 local->ps_sdata = NULL;
1871
Eliad Pellerab095872012-07-27 12:33:22 +03001872 /* disable per-vif ps */
1873 ieee80211_recalc_ps_vif(sdata);
1874
Eliad Pellerf8239812012-06-27 14:18:22 +03001875 /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
1876 if (tx)
Johannes Berg39ecc012013-02-13 12:11:00 +01001877 ieee80211_flush_queues(local, sdata);
Eliad Pellerf8239812012-06-27 14:18:22 +03001878
Johannes Berg37ad3882012-02-24 13:50:54 +01001879 /* deauthenticate/disassociate now */
1880 if (tx || frame_buf)
Eliad Peller88a9e312012-06-01 11:14:03 +03001881 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
1882 reason, tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01001883
1884 /* flush out frame */
1885 if (tx)
Johannes Berg39ecc012013-02-13 12:11:00 +01001886 ieee80211_flush_queues(local, sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01001887
Eliad Peller88a9e312012-06-01 11:14:03 +03001888 /* clear bssid only after building the needed mgmt frames */
1889 memset(ifmgd->bssid, 0, ETH_ALEN);
1890
Johannes Berg37ad3882012-02-24 13:50:54 +01001891 /* remove AP and TDLS peers */
Johannes Berg051007d2012-12-13 23:49:02 +01001892 sta_info_flush_defer(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01001893
1894 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001895 changed |= ieee80211_reset_erp_info(sdata);
1896
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001897 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001898 changed |= BSS_CHANGED_ASSOC;
1899 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001900
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001901 ifmgd->p2p_noa_index = -1;
1902 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1903 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01001904
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01001905 /* on the next assoc, re-program HT/VHT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08001906 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
1907 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01001908 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
1909 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
Johannes Berg413ad502009-05-08 21:21:06 +02001910
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001911 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301912
Kalle Valo520eb822008-12-18 23:35:27 +02001913 del_timer_sync(&local->dynamic_ps_timer);
1914 cancel_work_sync(&local->dynamic_ps_enable_work);
1915
Juuso Oikarinen68542962010-06-09 13:43:26 +03001916 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01001917 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03001918 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001919
Johannes Berg3abead52012-03-02 15:56:59 +01001920 sdata->vif.bss_conf.qos = false;
1921 changed |= BSS_CHANGED_QOS;
1922
Johannes Berg0aaffa92010-05-05 15:28:27 +02001923 /* The BSSID (not really interesting) and HT changed */
1924 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001925 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001926
Johannes Berg3abead52012-03-02 15:56:59 +01001927 /* disassociated - set to defaults now */
1928 ieee80211_set_wmm_default(sdata, false);
1929
Johannes Bergb9dcf712010-08-27 12:35:54 +02001930 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1931 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1932 del_timer_sync(&sdata->u.mgd.timer);
1933 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02001934
Johannes Berg826262c2012-12-10 16:38:14 +02001935 sdata->vif.bss_conf.dtim_period = 0;
1936
Johannes Berg028e8da02012-11-26 11:57:41 +01001937 ifmgd->flags = 0;
1938 ieee80211_vif_release_channel(sdata);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001939}
Jiri Bencf0706e82007-05-05 11:45:53 -07001940
Kalle Valo3cf335d52009-03-22 21:57:06 +02001941void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1942 struct ieee80211_hdr *hdr)
1943{
1944 /*
1945 * We can postpone the mgd.timer whenever receiving unicast frames
1946 * from AP because we know that the connection is working both ways
1947 * at that time. But multicast frames (and hence also beacons) must
1948 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001949 * data idle periods for sending the periodic probe request to the
1950 * AP we're connected to.
Kalle Valo3cf335d52009-03-22 21:57:06 +02001951 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001952 if (is_multicast_ether_addr(hdr->addr1))
1953 return;
1954
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001955 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d52009-03-22 21:57:06 +02001956}
Jiri Bencf0706e82007-05-05 11:45:53 -07001957
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001958static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1959{
1960 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001961 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001962
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001963 mutex_lock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001964 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001965 IEEE80211_STA_CONNECTION_POLL))) {
1966 mutex_unlock(&local->mtx);
1967 return;
1968 }
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001969
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001970 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001971
1972 mutex_lock(&local->iflist_mtx);
1973 ieee80211_recalc_ps(local, -1);
1974 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001975
1976 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001977 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001978
1979 /*
1980 * We've received a probe response, but are not sure whether
1981 * we have or will be receiving any beacons or data, so let's
1982 * schedule the timers again, just in case.
1983 */
1984 ieee80211_sta_reset_beacon_monitor(sdata);
1985
1986 mod_timer(&ifmgd->conn_mon_timer,
1987 round_jiffies_up(jiffies +
1988 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001989out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001990 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001991}
1992
1993void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001994 struct ieee80211_hdr *hdr, bool ack)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001995{
Felix Fietkau75706d02010-12-02 21:01:07 +01001996 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001997 return;
1998
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001999 if (ieee80211_is_nullfunc(hdr->frame_control) &&
2000 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002001 if (ack)
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002002 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002003 else
2004 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002005 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002006 return;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002007 }
Wojciech Dubowikcab1c7f2013-02-14 14:08:37 +01002008
2009 if (ack)
2010 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002011}
2012
Maxim Levitskya43abf22009-07-31 18:54:12 +03002013static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2014{
2015 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2016 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002017 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08002018 u8 unicast_limit = max(1, max_probe_tries - 3);
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04002019
2020 /*
2021 * Try sending broadcast probe requests for the last three
2022 * probe requests after the first ones failed since some
2023 * buggy APs only support broadcast probe requests.
2024 */
2025 if (ifmgd->probe_send_count >= unicast_limit)
2026 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002027
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002028 /*
2029 * When the hardware reports an accurate Tx ACK status, it's
2030 * better to send a nullfunc frame instead of a probe request,
2031 * as it will kick us off the AP quickly if we aren't associated
2032 * anymore. The timeout will be reset if the frame is ACKed by
2033 * the AP.
2034 */
Soumik Das992e68b2012-05-20 15:31:13 +05302035 ifmgd->probe_send_count++;
2036
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002037 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
2038 ifmgd->nullfunc_failed = false;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002039 ieee80211_send_nullfunc(sdata->local, sdata, 0);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002040 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002041 int ssid_len;
2042
Johannes Berg9caf0362012-11-29 01:25:20 +01002043 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002044 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002045 if (WARN_ON_ONCE(ssid == NULL))
2046 ssid_len = 0;
2047 else
2048 ssid_len = ssid[1];
2049
2050 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002051 0, (u32) -1, true, 0,
Johannes Berg55de9082012-07-26 17:24:39 +02002052 ifmgd->associated->channel, false);
Johannes Berg9caf0362012-11-29 01:25:20 +01002053 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002054 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03002055
Ben Greear180205b2011-02-04 15:30:24 -08002056 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002057 run_again(ifmgd, ifmgd->probe_timeout);
Rajkumar Manoharanf69b9c72012-03-15 06:15:26 +05302058 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Johannes Berg39ecc012013-02-13 12:11:00 +01002059 ieee80211_flush_queues(sdata->local, sdata);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002060}
2061
Johannes Bergb291ba12009-07-10 15:29:03 +02002062static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2063 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02002064{
Kalle Valo04de8382009-03-22 21:57:35 +02002065 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002066 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02002067
Johannes Berg9607e6b662009-12-23 13:15:31 +01002068 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02002069 return;
2070
Johannes Berg77fdaa12009-07-07 03:45:17 +02002071 mutex_lock(&ifmgd->mtx);
2072
2073 if (!ifmgd->associated)
2074 goto out;
2075
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002076 mutex_lock(&sdata->local->mtx);
2077
2078 if (sdata->local->tmp_channel || sdata->local->scanning) {
2079 mutex_unlock(&sdata->local->mtx);
2080 goto out;
2081 }
2082
Ben Greeara13fbe52013-03-25 11:19:35 -07002083 if (beacon) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002084 mlme_dbg_ratelimited(sdata,
Ben Greear59c1ec22013-03-19 14:19:56 -07002085 "detected beacon loss from AP (missed %d beacons) - probing\n",
2086 beacon_loss_count);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002087
Ben Greeara13fbe52013-03-25 11:19:35 -07002088 ieee80211_cqm_rssi_notify(&sdata->vif,
2089 NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
2090 GFP_KERNEL);
2091 }
Kalle Valo04de8382009-03-22 21:57:35 +02002092
Johannes Bergb291ba12009-07-10 15:29:03 +02002093 /*
2094 * The driver/our work has already reported this event or the
2095 * connection monitoring has kicked in and we have already sent
2096 * a probe request. Or maybe the AP died and the driver keeps
2097 * reporting until we disassociate...
2098 *
2099 * In either case we have to ignore the current call to this
2100 * function (except for setting the correct probe reason bit)
2101 * because otherwise we would reset the timer every time and
2102 * never check whether we received a probe response!
2103 */
2104 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
2105 IEEE80211_STA_CONNECTION_POLL))
2106 already = true;
2107
2108 if (beacon)
2109 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
2110 else
2111 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2112
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02002113 mutex_unlock(&sdata->local->mtx);
2114
Johannes Bergb291ba12009-07-10 15:29:03 +02002115 if (already)
2116 goto out;
2117
Johannes Berg4e751842009-06-10 15:16:52 +02002118 mutex_lock(&sdata->local->iflist_mtx);
2119 ieee80211_recalc_ps(sdata->local, -1);
2120 mutex_unlock(&sdata->local->iflist_mtx);
2121
Maxim Levitskya43abf22009-07-31 18:54:12 +03002122 ifmgd->probe_send_count = 0;
2123 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002124 out:
2125 mutex_unlock(&ifmgd->mtx);
Kalle Valo04de8382009-03-22 21:57:35 +02002126}
2127
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002128struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2129 struct ieee80211_vif *vif)
2130{
2131 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2132 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002133 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002134 struct sk_buff *skb;
2135 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002136 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002137
2138 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2139 return NULL;
2140
2141 ASSERT_MGD_MTX(ifmgd);
2142
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002143 if (ifmgd->associated)
2144 cbss = ifmgd->associated;
2145 else if (ifmgd->auth_data)
2146 cbss = ifmgd->auth_data->bss;
2147 else if (ifmgd->assoc_data)
2148 cbss = ifmgd->assoc_data->bss;
2149 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002150 return NULL;
2151
Johannes Berg9caf0362012-11-29 01:25:20 +01002152 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002153 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02002154 if (WARN_ON_ONCE(ssid == NULL))
2155 ssid_len = 0;
2156 else
2157 ssid_len = ssid[1];
2158
Eliad Pellerd9b3b282012-06-28 15:03:13 +03002159 skb = ieee80211_build_probe_req(sdata, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02002160 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02002161 ssid + 2, ssid_len,
Johannes Berg85a237f2011-07-18 18:08:36 +02002162 NULL, 0, true);
Johannes Berg9caf0362012-11-29 01:25:20 +01002163 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02002164
2165 return skb;
2166}
2167EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2168
Johannes Bergeef9e542013-01-29 13:09:34 +01002169static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002170{
2171 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002172 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002173
2174 mutex_lock(&ifmgd->mtx);
2175 if (!ifmgd->associated) {
2176 mutex_unlock(&ifmgd->mtx);
2177 return;
2178 }
2179
Johannes Berg37ad3882012-02-24 13:50:54 +01002180 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2181 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Johannes Bergeef9e542013-01-29 13:09:34 +01002182 true, frame_buf);
Johannes Berg882a7c62012-08-01 22:32:45 +02002183 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
Johannes Berg5b36ebd2013-02-13 14:21:45 +01002184 ieee80211_wake_queues_by_reason(&sdata->local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +01002185 IEEE80211_MAX_QUEUE_MAP,
Johannes Berg5b36ebd2013-02-13 14:21:45 +01002186 IEEE80211_QUEUE_STOP_REASON_CSA);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002187 mutex_unlock(&ifmgd->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002188
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002189 /*
2190 * must be outside lock due to cfg80211,
2191 * but that's not a problem.
2192 */
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002193 cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002194}
2195
Johannes Bergcc74c0c2012-08-01 16:49:34 +02002196static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02002197{
2198 struct ieee80211_sub_if_data *sdata =
2199 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002200 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08002201 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2202 struct sta_info *sta;
2203
2204 if (ifmgd->associated) {
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05302205 rcu_read_lock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08002206 sta = sta_info_get(sdata, ifmgd->bssid);
2207 if (sta)
2208 sta->beacon_loss_count++;
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05302209 rcu_read_unlock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08002210 }
Johannes Bergb291ba12009-07-10 15:29:03 +02002211
Johannes Berg682bd382013-01-29 13:13:50 +01002212 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02002213 sdata_info(sdata, "Connection to AP %pM lost\n",
2214 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01002215 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02002216 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002217 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02002218 }
2219}
2220
2221static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2222{
2223 struct ieee80211_sub_if_data *sdata =
2224 container_of(work, struct ieee80211_sub_if_data,
2225 u.mgd.csa_connection_drop_work);
2226
Johannes Bergeef9e542013-01-29 13:09:34 +01002227 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002228}
2229
Kalle Valo04de8382009-03-22 21:57:35 +02002230void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2231{
2232 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002233 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02002234
Johannes Bergb5878a22010-04-07 16:48:40 +02002235 trace_api_beacon_loss(sdata);
2236
Johannes Berg682bd382013-01-29 13:13:50 +01002237 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002238 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002239}
2240EXPORT_SYMBOL(ieee80211_beacon_loss);
2241
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002242void ieee80211_connection_loss(struct ieee80211_vif *vif)
2243{
2244 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2245 struct ieee80211_hw *hw = &sdata->local->hw;
2246
Johannes Bergb5878a22010-04-07 16:48:40 +02002247 trace_api_connection_loss(sdata);
2248
Johannes Berg682bd382013-01-29 13:13:50 +01002249 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002250 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2251}
2252EXPORT_SYMBOL(ieee80211_connection_loss);
2253
2254
Johannes Berg66e67e42012-01-20 13:55:27 +01002255static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2256 bool assoc)
2257{
2258 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2259
2260 lockdep_assert_held(&sdata->u.mgd.mtx);
2261
Johannes Berg66e67e42012-01-20 13:55:27 +01002262 if (!assoc) {
2263 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2264
2265 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2266 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002267 sdata->u.mgd.flags = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002268 ieee80211_vif_release_channel(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002269 }
2270
Johannes Berg5b112d32013-02-01 01:49:58 +01002271 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002272 kfree(auth_data);
2273 sdata->u.mgd.auth_data = NULL;
2274}
2275
2276static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2277 struct ieee80211_mgmt *mgmt, size_t len)
2278{
Johannes Berg1672c0e32013-01-29 15:02:27 +01002279 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01002280 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2281 u8 *pos;
2282 struct ieee802_11_elems elems;
Johannes Berg1672c0e32013-01-29 15:02:27 +01002283 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002284
2285 pos = mgmt->u.auth.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002286 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002287 if (!elems.challenge)
2288 return;
2289 auth_data->expected_transaction = 4;
Johannes Berga1845fc2012-06-27 13:18:36 +02002290 drv_mgd_prepare_tx(sdata->local, sdata);
Johannes Berg1672c0e32013-01-29 15:02:27 +01002291 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
2292 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2293 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03002294 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01002295 elems.challenge - 2, elems.challenge_len + 2,
2296 auth_data->bss->bssid, auth_data->bss->bssid,
2297 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002298 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002299}
2300
2301static enum rx_mgmt_action __must_check
2302ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2303 struct ieee80211_mgmt *mgmt, size_t len)
2304{
2305 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2306 u8 bssid[ETH_ALEN];
2307 u16 auth_alg, auth_transaction, status_code;
2308 struct sta_info *sta;
2309
2310 lockdep_assert_held(&ifmgd->mtx);
2311
2312 if (len < 24 + 6)
2313 return RX_MGMT_NONE;
2314
2315 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2316 return RX_MGMT_NONE;
2317
2318 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2319
Joe Perchesb203ca32012-05-08 18:56:52 +00002320 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002321 return RX_MGMT_NONE;
2322
2323 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2324 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2325 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2326
2327 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002328 auth_transaction != ifmgd->auth_data->expected_transaction) {
2329 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2330 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2331 auth_transaction,
2332 ifmgd->auth_data->expected_transaction);
Johannes Berg66e67e42012-01-20 13:55:27 +01002333 return RX_MGMT_NONE;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03002334 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002335
2336 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002337 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2338 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03002339 ieee80211_destroy_auth_data(sdata, false);
2340 return RX_MGMT_CFG80211_RX_AUTH;
Johannes Berg66e67e42012-01-20 13:55:27 +01002341 }
2342
2343 switch (ifmgd->auth_data->algorithm) {
2344 case WLAN_AUTH_OPEN:
2345 case WLAN_AUTH_LEAP:
2346 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002347 case WLAN_AUTH_SAE:
Johannes Berg66e67e42012-01-20 13:55:27 +01002348 break;
2349 case WLAN_AUTH_SHARED_KEY:
2350 if (ifmgd->auth_data->expected_transaction != 4) {
2351 ieee80211_auth_challenge(sdata, mgmt, len);
2352 /* need another frame */
2353 return RX_MGMT_NONE;
2354 }
2355 break;
2356 default:
2357 WARN_ONCE(1, "invalid auth alg %d",
2358 ifmgd->auth_data->algorithm);
2359 return RX_MGMT_NONE;
2360 }
2361
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002362 sdata_info(sdata, "authenticated\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002363 ifmgd->auth_data->done = true;
2364 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
Johannes Berg89afe612013-02-13 15:39:57 +01002365 ifmgd->auth_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01002366 run_again(ifmgd, ifmgd->auth_data->timeout);
2367
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002368 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2369 ifmgd->auth_data->expected_transaction != 2) {
2370 /*
2371 * Report auth frame to user space for processing since another
2372 * round of Authentication frames is still needed.
2373 */
2374 return RX_MGMT_CFG80211_RX_AUTH;
2375 }
2376
Johannes Berg66e67e42012-01-20 13:55:27 +01002377 /* move station state to auth */
2378 mutex_lock(&sdata->local->sta_mtx);
2379 sta = sta_info_get(sdata, bssid);
2380 if (!sta) {
2381 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2382 goto out_err;
2383 }
2384 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002385 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002386 goto out_err;
2387 }
2388 mutex_unlock(&sdata->local->sta_mtx);
2389
2390 return RX_MGMT_CFG80211_RX_AUTH;
2391 out_err:
2392 mutex_unlock(&sdata->local->sta_mtx);
2393 /* ignore frame -- wait for timeout */
2394 return RX_MGMT_NONE;
2395}
2396
2397
Johannes Berg77fdaa12009-07-07 03:45:17 +02002398static enum rx_mgmt_action __must_check
2399ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg77fdaa12009-07-07 03:45:17 +02002400 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002401{
Johannes Berg46900292009-02-15 12:44:28 +01002402 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002403 const u8 *bssid = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07002404 u16 reason_code;
2405
Johannes Berg66e67e42012-01-20 13:55:27 +01002406 lockdep_assert_held(&ifmgd->mtx);
2407
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002408 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002409 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002410
Johannes Berg66e67e42012-01-20 13:55:27 +01002411 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002412 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002413 return RX_MGMT_NONE;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002414
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002415 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002416
2417 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
2418
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002419 sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n",
2420 bssid, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002421
Johannes Berg37ad3882012-02-24 13:50:54 +01002422 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2423
Johannes Berg77fdaa12009-07-07 03:45:17 +02002424 return RX_MGMT_CFG80211_DEAUTH;
Jiri Bencf0706e82007-05-05 11:45:53 -07002425}
2426
2427
Johannes Berg77fdaa12009-07-07 03:45:17 +02002428static enum rx_mgmt_action __must_check
2429ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2430 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002431{
Johannes Berg46900292009-02-15 12:44:28 +01002432 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002433 u16 reason_code;
2434
Johannes Berg66e67e42012-01-20 13:55:27 +01002435 lockdep_assert_held(&ifmgd->mtx);
2436
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002437 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002438 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002439
Johannes Berg66e67e42012-01-20 13:55:27 +01002440 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002441 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg77fdaa12009-07-07 03:45:17 +02002442 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002443
2444 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2445
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002446 sdata_info(sdata, "disassociated from %pM (Reason: %u)\n",
2447 mgmt->sa, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002448
Johannes Berg37ad3882012-02-24 13:50:54 +01002449 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2450
Johannes Berg77fdaa12009-07-07 03:45:17 +02002451 return RX_MGMT_CFG80211_DISASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -07002452}
2453
Christian Lamparterc74d0842011-10-15 00:14:49 +02002454static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2455 u8 *supp_rates, unsigned int supp_rates_len,
2456 u32 *rates, u32 *basic_rates,
2457 bool *have_higher_than_11mbit,
2458 int *min_rate, int *min_rate_index)
2459{
2460 int i, j;
2461
2462 for (i = 0; i < supp_rates_len; i++) {
2463 int rate = (supp_rates[i] & 0x7f) * 5;
2464 bool is_basic = !!(supp_rates[i] & 0x80);
2465
2466 if (rate > 110)
2467 *have_higher_than_11mbit = true;
2468
2469 /*
2470 * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
2471 * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
2472 *
2473 * Note: Even through the membership selector and the basic
2474 * rate flag share the same bit, they are not exactly
2475 * the same.
2476 */
2477 if (!!(supp_rates[i] & 0x80) &&
2478 (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
2479 continue;
2480
2481 for (j = 0; j < sband->n_bitrates; j++) {
2482 if (sband->bitrates[j].bitrate == rate) {
2483 *rates |= BIT(j);
2484 if (is_basic)
2485 *basic_rates |= BIT(j);
2486 if (rate < *min_rate) {
2487 *min_rate = rate;
2488 *min_rate_index = j;
2489 }
2490 break;
2491 }
2492 }
2493 }
2494}
Jiri Bencf0706e82007-05-05 11:45:53 -07002495
Johannes Berg66e67e42012-01-20 13:55:27 +01002496static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2497 bool assoc)
2498{
2499 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2500
2501 lockdep_assert_held(&sdata->u.mgd.mtx);
2502
Johannes Berg66e67e42012-01-20 13:55:27 +01002503 if (!assoc) {
2504 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2505
2506 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2507 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002508 sdata->u.mgd.flags = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002509 ieee80211_vif_release_channel(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002510 }
2511
2512 kfree(assoc_data);
2513 sdata->u.mgd.assoc_data = NULL;
2514}
2515
2516static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2517 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002518 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002519{
Johannes Berg46900292009-02-15 12:44:28 +01002520 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002521 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01002522 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07002523 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002524 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002525 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002526 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02002527 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Bergae5eb022008-10-14 16:58:37 +02002528 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02002529 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -07002530
Johannes Bergaf6b6372009-12-23 13:15:35 +01002531 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07002532
Jiri Bencf0706e82007-05-05 11:45:53 -07002533 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002534 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07002535
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002536 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002537 sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
2538 aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002539 aid &= ~(BIT(15) | BIT(14));
2540
Johannes Berg05cb9102011-10-28 11:59:47 +02002541 ifmgd->broken_ap = false;
2542
2543 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002544 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
2545 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02002546 aid = 0;
2547 ifmgd->broken_ap = true;
2548 }
2549
Johannes Bergaf6b6372009-12-23 13:15:35 +01002550 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002551 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002552
Jiri Bencf0706e82007-05-05 11:45:53 -07002553 if (!elems.supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002554 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01002555 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002556 }
2557
Johannes Berg46900292009-02-15 12:44:28 +01002558 ifmgd->aid = aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002559
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002560 /*
2561 * We previously checked these in the beacon/probe response, so
2562 * they should be present here. This is just a safety net.
2563 */
2564 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
2565 (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
2566 sdata_info(sdata,
2567 "HT AP is missing WMM params or HT capability/operation in AssocResp\n");
2568 return false;
2569 }
2570
2571 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
2572 (!elems.vht_cap_elem || !elems.vht_operation)) {
2573 sdata_info(sdata,
2574 "VHT AP is missing VHT capability/operation in AssocResp\n");
2575 return false;
2576 }
2577
Guy Eilam2a33bee2011-08-17 15:18:15 +03002578 mutex_lock(&sdata->local->sta_mtx);
2579 /*
2580 * station info was already allocated and inserted before
2581 * the association and should be available to us
2582 */
Johannes Berg7852e362012-01-20 13:55:24 +01002583 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03002584 if (WARN_ON(!sta)) {
2585 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002586 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002587 }
2588
Johannes Berg55de9082012-07-26 17:24:39 +02002589 sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
Johannes Berg8318d782008-01-24 19:38:38 +01002590
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002591 /* Set up internal HT/VHT capabilities */
Johannes Berga8243b72012-11-22 14:32:09 +01002592 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08002593 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01002594 elems.ht_cap_elem, sta);
Johannes Berg64f68e52012-03-28 10:58:37 +02002595
Mahesh Palivela818255e2012-10-10 11:33:04 +00002596 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2597 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01002598 elems.vht_cap_elem, sta);
Mahesh Palivela818255e2012-10-10 11:33:04 +00002599
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002600 /*
2601 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
2602 * in their association response, so ignore that data for our own
2603 * configuration. If it changed since the last beacon, we'll get the
2604 * next beacon and update then.
2605 */
Johannes Berg11289582013-02-07 17:36:12 +01002606
Johannes Bergbee7f5862013-02-07 22:24:55 +01002607 /*
2608 * If an operating mode notification IE is present, override the
2609 * NSS calculation (that would be done in rate_control_rate_init())
2610 * and use the # of streams from that element.
2611 */
2612 if (elems.opmode_notif &&
2613 !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
2614 u8 nss;
2615
2616 nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
2617 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
2618 nss += 1;
2619 sta->sta.rx_nss = nss;
2620 }
2621
Johannes Berg4b7679a2008-09-18 18:14:18 +02002622 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07002623
Johannes Berg46900292009-02-15 12:44:28 +01002624 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002625 set_sta_flag(sta, WLAN_STA_MFP);
Jouni Malinen5394af42009-01-08 13:31:59 +02002626
Johannes Bergddf4ac52008-10-22 11:41:38 +02002627 if (elems.wmm_param)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002628 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002629
Johannes Berg3e4d40f2013-02-07 17:19:08 +01002630 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01002631 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
2632 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
2633 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002634 sdata_info(sdata,
2635 "failed to move station %pM to desired state\n",
2636 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01002637 WARN_ON(__sta_info_destroy(sta));
2638 mutex_unlock(&sdata->local->sta_mtx);
2639 return false;
2640 }
2641
Johannes Berg7852e362012-01-20 13:55:24 +01002642 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002643
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03002644 /*
2645 * Always handle WMM once after association regardless
2646 * of the first value the AP uses. Setting -1 here has
2647 * that effect because the AP values is an unsigned
2648 * 4-bit value.
2649 */
2650 ifmgd->wmm_last_param_set = -1;
2651
Johannes Bergddf4ac52008-10-22 11:41:38 +02002652 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02002653 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07002654 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02002655 else
Johannes Berg3abead52012-03-02 15:56:59 +01002656 ieee80211_set_wmm_default(sdata, false);
2657 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07002658
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002659 /* set AID and assoc capability,
2660 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01002661 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002662 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002663 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07002664
Kalle Valo15b7b062009-03-22 21:57:14 +02002665 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01002666 * If we're using 4-addr mode, let the AP know that we're
2667 * doing so, so that it can create the STA VLAN on its side
2668 */
2669 if (ifmgd->use_4addr)
2670 ieee80211_send_4addr_nullfunc(local, sdata);
2671
2672 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02002673 * Start timer to probe the connection to the AP now.
2674 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02002675 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002676 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04002677 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02002678
Johannes Bergaf6b6372009-12-23 13:15:35 +01002679 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07002680}
2681
Johannes Berg66e67e42012-01-20 13:55:27 +01002682static enum rx_mgmt_action __must_check
2683ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2684 struct ieee80211_mgmt *mgmt, size_t len,
2685 struct cfg80211_bss **bss)
2686{
2687 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2688 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
2689 u16 capab_info, status_code, aid;
2690 struct ieee802_11_elems elems;
2691 u8 *pos;
2692 bool reassoc;
Jiri Bencf0706e82007-05-05 11:45:53 -07002693
Johannes Berg66e67e42012-01-20 13:55:27 +01002694 lockdep_assert_held(&ifmgd->mtx);
2695
2696 if (!assoc_data)
2697 return RX_MGMT_NONE;
Joe Perchesb203ca32012-05-08 18:56:52 +00002698 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002699 return RX_MGMT_NONE;
2700
2701 /*
2702 * AssocResp and ReassocResp have identical structure, so process both
2703 * of them in this function.
2704 */
2705
2706 if (len < 24 + 6)
2707 return RX_MGMT_NONE;
2708
2709 reassoc = ieee80211_is_reassoc_req(mgmt->frame_control);
2710 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2711 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2712 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2713
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002714 sdata_info(sdata,
2715 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
2716 reassoc ? "Rea" : "A", mgmt->sa,
2717 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01002718
2719 pos = mgmt->u.assoc_resp.variable;
Johannes Bergb2e506b2013-03-26 14:54:16 +01002720 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002721
2722 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Johannes Berg79ba1d82013-03-27 14:38:07 +01002723 elems.timeout_int &&
2724 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002725 u32 tu, ms;
Johannes Berg79ba1d82013-03-27 14:38:07 +01002726 tu = le32_to_cpu(elems.timeout_int->value);
Johannes Berg66e67e42012-01-20 13:55:27 +01002727 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002728 sdata_info(sdata,
2729 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
2730 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01002731 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
Johannes Berg89afe612013-02-13 15:39:57 +01002732 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01002733 if (ms > IEEE80211_ASSOC_TIMEOUT)
2734 run_again(ifmgd, assoc_data->timeout);
2735 return RX_MGMT_NONE;
2736 }
2737
2738 *bss = assoc_data->bss;
2739
2740 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002741 sdata_info(sdata, "%pM denied association (code=%d)\n",
2742 mgmt->sa, status_code);
Johannes Berg66e67e42012-01-20 13:55:27 +01002743 ieee80211_destroy_assoc_data(sdata, false);
2744 } else {
Johannes Berg66e67e42012-01-20 13:55:27 +01002745 if (!ieee80211_assoc_success(sdata, *bss, mgmt, len)) {
2746 /* oops -- internal error -- send timeout for now */
Eliad Peller10a91092012-07-02 14:42:03 +03002747 ieee80211_destroy_assoc_data(sdata, false);
Johannes Berg5b112d32013-02-01 01:49:58 +01002748 cfg80211_put_bss(sdata->local->hw.wiphy, *bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002749 return RX_MGMT_CFG80211_ASSOC_TIMEOUT;
2750 }
John W. Linville635d9992012-07-09 16:34:34 -04002751 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01002752
2753 /*
2754 * destroy assoc_data afterwards, as otherwise an idle
2755 * recalc after assoc_data is NULL but before associated
2756 * is set can cause the interface to go idle
2757 */
2758 ieee80211_destroy_assoc_data(sdata, true);
Johannes Berg66e67e42012-01-20 13:55:27 +01002759 }
2760
2761 return RX_MGMT_CFG80211_RX_ASSOC;
2762}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01002763
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002764static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01002765 struct ieee80211_mgmt *mgmt, size_t len,
Jiri Bencf0706e82007-05-05 11:45:53 -07002766 struct ieee80211_rx_status *rx_status,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002767 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07002768{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002769 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002770 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02002771 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002772 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01002773 bool need_ps = false;
2774
Johannes Bergb4f286a12013-03-26 14:13:58 +01002775 lockdep_assert_held(&sdata->u.mgd.mtx);
2776
Johannes Berg826262c2012-12-10 16:38:14 +02002777 if ((sdata->u.mgd.associated &&
2778 ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) ||
2779 (sdata->u.mgd.assoc_data &&
2780 ether_addr_equal(mgmt->bssid,
2781 sdata->u.mgd.assoc_data->bss->bssid))) {
Johannes Berg56007a02010-01-26 14:19:52 +01002782 /* not previously set so we may need to recalc */
Johannes Berg826262c2012-12-10 16:38:14 +02002783 need_ps = sdata->u.mgd.associated && !sdata->u.mgd.dtim_period;
2784
2785 if (elems->tim && !elems->parse_error) {
Johannes Berg4a3cb702013-02-12 16:43:19 +01002786 const struct ieee80211_tim_ie *tim_ie = elems->tim;
Johannes Berg826262c2012-12-10 16:38:14 +02002787 sdata->u.mgd.dtim_period = tim_ie->dtim_period;
2788 }
Johannes Berg56007a02010-01-26 14:19:52 +01002789 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002790
Johannes Berg1cd8e882013-03-27 14:30:12 +01002791 if (elems->ds_params)
Bruno Randolf59eb21a2011-01-17 13:37:28 +09002792 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
2793 rx_status->band);
Johannes Berg5bda6172008-09-08 11:05:10 +02002794 else
2795 freq = rx_status->freq;
2796
2797 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2798
2799 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2800 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002801
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002802 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002803 channel);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002804 if (bss)
2805 ieee80211_rx_bss_put(local, bss);
2806
Johannes Berg37799e52013-03-26 14:02:26 +01002807 if (!sdata->u.mgd.associated ||
2808 !ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid))
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002809 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002810
Johannes Berg56007a02010-01-26 14:19:52 +01002811 if (need_ps) {
2812 mutex_lock(&local->iflist_mtx);
2813 ieee80211_recalc_ps(local, -1);
2814 mutex_unlock(&local->iflist_mtx);
2815 }
2816
Johannes Berg04a161f2013-05-03 09:35:35 +02002817 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
2818 elems, true);
Johannes Bergb4f286a12013-03-26 14:13:58 +01002819
Jiri Bencf0706e82007-05-05 11:45:53 -07002820}
2821
2822
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002823static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002824 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07002825{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002826 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02002827 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002828 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
2829 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002830 struct ieee802_11_elems elems;
2831
Kalle Valo15b7b062009-03-22 21:57:14 +02002832 ifmgd = &sdata->u.mgd;
2833
Johannes Berg77fdaa12009-07-07 03:45:17 +02002834 ASSERT_MGD_MTX(ifmgd);
2835
Joe Perchesb203ca32012-05-08 18:56:52 +00002836 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03002837 return; /* ignore ProbeResp to foreign address */
2838
Ester Kummerae6a44e2008-06-27 18:54:48 +03002839 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
2840 if (baselen > len)
2841 return;
2842
2843 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
Johannes Bergb2e506b2013-03-26 14:54:16 +01002844 false, &elems);
Ester Kummerae6a44e2008-06-27 18:54:48 +03002845
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002846 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03002847
Johannes Berg77fdaa12009-07-07 03:45:17 +02002848 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002849 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002850 ieee80211_reset_ap_probe(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002851
2852 if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002853 ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002854 /* got probe response, continue with auth */
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002855 sdata_info(sdata, "direct probe responded\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002856 ifmgd->auth_data->tries = 0;
2857 ifmgd->auth_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01002858 ifmgd->auth_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01002859 run_again(ifmgd, ifmgd->auth_data->timeout);
2860 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002861}
2862
Johannes Bergd91f36d2009-04-16 13:17:26 +02002863/*
2864 * This is the canonical list of information elements we care about,
2865 * the filter code also gives us all changes to the Microsoft OUI
2866 * (00:50:F2) vendor IE which is used for WMM which we need to track.
2867 *
2868 * We implement beacon filtering in software since that means we can
2869 * avoid processing the frame here and in cfg80211, and userspace
2870 * will not be able to tell whether the hardware supports it or not.
2871 *
2872 * XXX: This list needs to be dynamic -- userspace needs to be able to
2873 * add items it requires. It also needs to be able to tell us to
2874 * look out for other vendor IEs.
2875 */
2876static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02002877 (1ULL << WLAN_EID_COUNTRY) |
2878 (1ULL << WLAN_EID_ERP_INFO) |
2879 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
2880 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
2881 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg074d46d2012-03-15 19:45:16 +01002882 (1ULL << WLAN_EID_HT_OPERATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02002883
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002884static enum rx_mgmt_action
2885ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2886 struct ieee80211_mgmt *mgmt, size_t len,
2887 u8 *deauth_buf, struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07002888{
Johannes Bergd91f36d2009-04-16 13:17:26 +02002889 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002890 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07002891 size_t baselen;
2892 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002893 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +02002894 struct ieee80211_chanctx_conf *chanctx_conf;
2895 struct ieee80211_channel *chan;
Johannes Bergbee7f5862013-02-07 22:24:55 +01002896 struct sta_info *sta;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002897 u32 changed = 0;
Rami Rosenf87ad632012-10-25 10:16:23 +02002898 bool erp_valid;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002899 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02002900 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002901 u8 *bssid;
2902
Johannes Berg66e67e42012-01-20 13:55:27 +01002903 lockdep_assert_held(&ifmgd->mtx);
Jiri Bencf0706e82007-05-05 11:45:53 -07002904
Ester Kummerae6a44e2008-06-27 18:54:48 +03002905 /* Process beacon from the current BSS */
2906 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2907 if (baselen > len)
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002908 return RX_MGMT_NONE;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002909
Johannes Berg55de9082012-07-26 17:24:39 +02002910 rcu_read_lock();
2911 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2912 if (!chanctx_conf) {
2913 rcu_read_unlock();
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002914 return RX_MGMT_NONE;
Johannes Berg55de9082012-07-26 17:24:39 +02002915 }
2916
Johannes Berg4bf88532012-11-09 11:39:59 +01002917 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
Johannes Berg55de9082012-07-26 17:24:39 +02002918 rcu_read_unlock();
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002919 return RX_MGMT_NONE;
Johannes Berg55de9082012-07-26 17:24:39 +02002920 }
Johannes Berg4bf88532012-11-09 11:39:59 +01002921 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +02002922 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002923
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002924 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002925 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002926 ieee802_11_parse_elems(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01002927 len - baselen, false, &elems);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002928
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002929 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002930 ifmgd->assoc_data->have_beacon = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002931 ifmgd->assoc_data->need_beacon = false;
Johannes Bergef429da2013-02-05 17:48:40 +01002932 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
2933 sdata->vif.bss_conf.sync_tsf =
2934 le64_to_cpu(mgmt->u.beacon.timestamp);
2935 sdata->vif.bss_conf.sync_device_ts =
2936 rx_status->device_timestamp;
2937 if (elems.tim)
2938 sdata->vif.bss_conf.sync_dtim_count =
2939 elems.tim->dtim_count;
2940 else
2941 sdata->vif.bss_conf.sync_dtim_count = 0;
2942 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002943 /* continue assoc process */
2944 ifmgd->assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01002945 ifmgd->assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01002946 run_again(ifmgd, ifmgd->assoc_data->timeout);
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002947 return RX_MGMT_NONE;
Johannes Berg66e67e42012-01-20 13:55:27 +01002948 }
2949
2950 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002951 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg30eb1dc2013-02-08 15:12:14 +01002952 return RX_MGMT_NONE;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002953 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002954
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002955 /* Track average RSSI from the Beacon frames of the current AP */
2956 ifmgd->last_beacon_signal = rx_status->signal;
2957 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
2958 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03002959 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002960 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03002961 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002962 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002963 } else {
2964 ifmgd->ave_beacon_signal =
2965 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
2966 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
2967 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03002968 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002969 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002970
2971 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
2972 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
2973 int sig = ifmgd->ave_beacon_signal;
2974 int last_sig = ifmgd->last_ave_beacon_signal;
2975
2976 /*
2977 * if signal crosses either of the boundaries, invoke callback
2978 * with appropriate parameters
2979 */
2980 if (sig > ifmgd->rssi_max_thold &&
2981 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
2982 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbach887da912013-01-20 17:32:41 +02002983 drv_rssi_callback(local, sdata, RSSI_EVENT_HIGH);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002984 } else if (sig < ifmgd->rssi_min_thold &&
2985 (last_sig >= ifmgd->rssi_max_thold ||
2986 last_sig == 0)) {
2987 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbach887da912013-01-20 17:32:41 +02002988 drv_rssi_callback(local, sdata, RSSI_EVENT_LOW);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002989 }
2990 }
2991
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002992 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03002993 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01002994 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002995 int sig = ifmgd->ave_beacon_signal / 16;
2996 int last_event = ifmgd->last_cqm_event_signal;
2997 int thold = bss_conf->cqm_rssi_thold;
2998 int hyst = bss_conf->cqm_rssi_hyst;
2999 if (sig < thold &&
3000 (last_event == 0 || sig < last_event - hyst)) {
3001 ifmgd->last_cqm_event_signal = sig;
3002 ieee80211_cqm_rssi_notify(
3003 &sdata->vif,
3004 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3005 GFP_KERNEL);
3006 } else if (sig > thold &&
3007 (last_event == 0 || sig > last_event + hyst)) {
3008 ifmgd->last_cqm_event_signal = sig;
3009 ieee80211_cqm_rssi_notify(
3010 &sdata->vif,
3011 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3012 GFP_KERNEL);
3013 }
3014 }
3015
Johannes Bergb291ba12009-07-10 15:29:03 +02003016 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003017 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01003018 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003019 mutex_lock(&local->mtx);
Johannes Bergb291ba12009-07-10 15:29:03 +02003020 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003021 ieee80211_run_deferred_scan(local);
3022 mutex_unlock(&local->mtx);
3023
Johannes Berg4e751842009-06-10 15:16:52 +02003024 mutex_lock(&local->iflist_mtx);
3025 ieee80211_recalc_ps(local, -1);
3026 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03003027 }
3028
Johannes Bergb291ba12009-07-10 15:29:03 +02003029 /*
3030 * Push the beacon loss detection into the future since
3031 * we are processing a beacon from the AP just now.
3032 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04003033 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003034
Johannes Bergd91f36d2009-04-16 13:17:26 +02003035 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
3036 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003037 len - baselen, false, &elems,
Johannes Bergd91f36d2009-04-16 13:17:26 +02003038 care_about_ies, ncrc);
3039
Vivek Natarajan25c9c872009-03-02 20:20:30 +05303040 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Rami Rosenf87ad632012-10-25 10:16:23 +02003041 bool directed_tim = ieee80211_check_tim(elems.tim,
3042 elems.tim_len,
3043 ifmgd->aid);
Kalle Valo1fb36062009-02-10 17:09:24 +02003044 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02003045 if (local->hw.conf.dynamic_ps_timeout > 0) {
Ronald Wahl70b12f22012-03-19 14:37:20 +01003046 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
3047 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
3048 ieee80211_hw_config(local,
3049 IEEE80211_CONF_CHANGE_PS);
3050 }
Kalle Valo572e0012009-02-10 17:09:31 +02003051 ieee80211_send_nullfunc(local, sdata, 0);
Rajkumar Manoharan6f0756a2012-03-15 05:50:36 +05303052 } else if (!local->pspolling && sdata->u.mgd.powersave) {
Kalle Valo572e0012009-02-10 17:09:31 +02003053 local->pspolling = true;
3054
3055 /*
3056 * Here is assumed that the driver will be
3057 * able to send ps-poll frame and receive a
3058 * response even though power save mode is
3059 * enabled, but some drivers might require
3060 * to disable power save here. This needs
3061 * to be investigated.
3062 */
3063 ieee80211_send_pspoll(local, sdata);
3064 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08003065 }
3066 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003067
Johannes Berg488dd7b2012-10-29 20:08:01 +01003068 if (sdata->vif.p2p) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003069 struct ieee80211_p2p_noa_attr noa = {};
Johannes Berg488dd7b2012-10-29 20:08:01 +01003070 int ret;
3071
3072 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
3073 len - baselen,
3074 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
Janusz Dziedzic934457e2013-03-21 15:47:55 +01003075 (u8 *) &noa, sizeof(noa));
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003076 if (ret >= 2) {
3077 if (sdata->u.mgd.p2p_noa_index != noa.index) {
3078 /* valid noa_attr and index changed */
3079 sdata->u.mgd.p2p_noa_index = noa.index;
3080 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
3081 changed |= BSS_CHANGED_P2P_PS;
3082 /*
3083 * make sure we update all information, the CRC
3084 * mechanism doesn't look at P2P attributes.
3085 */
3086 ifmgd->beacon_crc_valid = false;
3087 }
3088 } else if (sdata->u.mgd.p2p_noa_index != -1) {
3089 /* noa_attr not found and we had valid noa_attr before */
3090 sdata->u.mgd.p2p_noa_index = -1;
3091 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
Johannes Berg488dd7b2012-10-29 20:08:01 +01003092 changed |= BSS_CHANGED_P2P_PS;
Johannes Berg488dd7b2012-10-29 20:08:01 +01003093 ifmgd->beacon_crc_valid = false;
3094 }
3095 }
3096
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003097 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003098 return RX_MGMT_NONE;
Jouni Malinen30196672009-05-19 17:01:43 +03003099 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003100 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03003101
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02003102 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg7d257452012-07-06 17:37:43 +02003103
3104 if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
3105 elems.wmm_param_len))
3106 changed |= BSS_CHANGED_QOS;
3107
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003108 /*
3109 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01003110 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003111 */
3112 if (!bss_conf->dtim_period) {
3113 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3114 if (elems.tim)
3115 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
3116 else
3117 bss_conf->dtim_period = 1;
Johannes Bergef429da2013-02-05 17:48:40 +01003118
3119 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
3120 sdata->vif.bss_conf.sync_tsf =
3121 le64_to_cpu(mgmt->u.beacon.timestamp);
3122 sdata->vif.bss_conf.sync_device_ts =
3123 rx_status->device_timestamp;
3124 if (elems.tim)
3125 sdata->vif.bss_conf.sync_dtim_count =
3126 elems.tim->dtim_count;
3127 else
3128 sdata->vif.bss_conf.sync_dtim_count = 0;
3129 }
3130
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003131 changed |= BSS_CHANGED_DTIM_PERIOD;
Alexander Bondarce857882013-05-06 17:17:04 +03003132 ieee80211_recalc_ps_vif(sdata);
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003133 }
3134
Johannes Berg1946bed2013-03-27 14:31:53 +01003135 if (elems.erp_info) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02003136 erp_valid = true;
3137 erp_value = elems.erp_info[0];
3138 } else {
3139 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04003140 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02003141 changed |= ieee80211_handle_bss_capability(sdata,
3142 le16_to_cpu(mgmt->u.beacon.capab_info),
3143 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07003144
Johannes Berg11289582013-02-07 17:36:12 +01003145 mutex_lock(&local->sta_mtx);
Johannes Bergbee7f5862013-02-07 22:24:55 +01003146 sta = sta_info_get(sdata, bssid);
3147
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003148 if (ieee80211_config_bw(sdata, sta, elems.ht_operation,
3149 elems.vht_operation, bssid, &changed)) {
3150 mutex_unlock(&local->sta_mtx);
3151 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3152 WLAN_REASON_DEAUTH_LEAVING,
3153 true, deauth_buf);
3154 return RX_MGMT_CFG80211_TX_DEAUTH;
3155 }
Johannes Bergbee7f5862013-02-07 22:24:55 +01003156
3157 if (sta && elems.opmode_notif)
3158 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
3159 rx_status->band, true);
Johannes Berg11289582013-02-07 17:36:12 +01003160 mutex_unlock(&local->sta_mtx);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02003161
Johannes Berg04b7b2f2012-09-05 13:41:37 +02003162 if (elems.country_elem && elems.pwr_constr_elem &&
3163 mgmt->u.probe_resp.capab_info &
3164 cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02003165 changed |= ieee80211_handle_pwr_constr(sdata, chan,
3166 elems.country_elem,
3167 elems.country_elem_len,
3168 elems.pwr_constr_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08003169
Johannes Berg471b3ef2007-12-28 14:32:58 +01003170 ieee80211_bss_info_change_notify(sdata, changed);
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003171
3172 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07003173}
3174
Johannes Berg1fa57d02010-06-10 10:21:32 +02003175void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
3176 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07003177{
Johannes Berg77fdaa12009-07-07 03:45:17 +02003178 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07003179 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07003180 struct ieee80211_mgmt *mgmt;
Johannes Berg66e67e42012-01-20 13:55:27 +01003181 struct cfg80211_bss *bss = NULL;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003182 enum rx_mgmt_action rma = RX_MGMT_NONE;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003183 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
Jiri Bencf0706e82007-05-05 11:45:53 -07003184 u16 fc;
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003185 struct ieee802_11_elems elems;
3186 int ies_len;
Jiri Bencf0706e82007-05-05 11:45:53 -07003187
Jiri Bencf0706e82007-05-05 11:45:53 -07003188 rx_status = (struct ieee80211_rx_status *) skb->cb;
3189 mgmt = (struct ieee80211_mgmt *) skb->data;
3190 fc = le16_to_cpu(mgmt->frame_control);
3191
Johannes Berg77fdaa12009-07-07 03:45:17 +02003192 mutex_lock(&ifmgd->mtx);
3193
Johannes Berg66e67e42012-01-20 13:55:27 +01003194 switch (fc & IEEE80211_FCTL_STYPE) {
3195 case IEEE80211_STYPE_BEACON:
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003196 rma = ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
3197 deauth_buf, rx_status);
Johannes Berg66e67e42012-01-20 13:55:27 +01003198 break;
3199 case IEEE80211_STYPE_PROBE_RESP:
3200 ieee80211_rx_mgmt_probe_resp(sdata, skb);
3201 break;
3202 case IEEE80211_STYPE_AUTH:
3203 rma = ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
3204 break;
3205 case IEEE80211_STYPE_DEAUTH:
3206 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
3207 break;
3208 case IEEE80211_STYPE_DISASSOC:
3209 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
3210 break;
3211 case IEEE80211_STYPE_ASSOC_RESP:
3212 case IEEE80211_STYPE_REASSOC_RESP:
3213 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss);
3214 break;
3215 case IEEE80211_STYPE_ACTION:
Johannes Berg37799e52013-03-26 14:02:26 +01003216 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003217 ies_len = skb->len -
3218 offsetof(struct ieee80211_mgmt,
3219 u.action.u.chan_switch.variable);
Johannes Berg37799e52013-03-26 14:02:26 +01003220
3221 if (ies_len < 0)
3222 break;
3223
3224 ieee802_11_parse_elems(
3225 mgmt->u.action.u.chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003226 ies_len, true, &elems);
Johannes Berg37799e52013-03-26 14:02:26 +01003227
3228 if (elems.parse_error)
3229 break;
3230
Johannes Berg66e67e42012-01-20 13:55:27 +01003231 ieee80211_sta_process_chanswitch(sdata,
Johannes Berg37799e52013-03-26 14:02:26 +01003232 rx_status->mactime,
Johannes Berg04a161f2013-05-03 09:35:35 +02003233 &elems, false);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003234 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
3235 ies_len = skb->len -
3236 offsetof(struct ieee80211_mgmt,
3237 u.action.u.ext_chan_switch.variable);
3238
3239 if (ies_len < 0)
3240 break;
3241
3242 ieee802_11_parse_elems(
3243 mgmt->u.action.u.ext_chan_switch.variable,
Johannes Bergb2e506b2013-03-26 14:54:16 +01003244 ies_len, true, &elems);
Johannes Berg1b3a2e42013-03-26 15:17:18 +01003245
3246 if (elems.parse_error)
3247 break;
3248
3249 /* for the handling code pretend this was also an IE */
3250 elems.ext_chansw_ie =
3251 &mgmt->u.action.u.ext_chan_switch.data;
3252
3253 ieee80211_sta_process_chanswitch(sdata,
3254 rx_status->mactime,
Johannes Berg04a161f2013-05-03 09:35:35 +02003255 &elems, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003256 }
Johannes Berg37799e52013-03-26 14:02:26 +01003257 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003258 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003259 mutex_unlock(&ifmgd->mtx);
3260
Johannes Berg66e67e42012-01-20 13:55:27 +01003261 switch (rma) {
3262 case RX_MGMT_NONE:
3263 /* no action */
3264 break;
3265 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470612009-10-13 13:28:13 +02003266 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01003267 break;
3268 case RX_MGMT_CFG80211_DISASSOC:
3269 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
3270 break;
3271 case RX_MGMT_CFG80211_RX_AUTH:
3272 cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, skb->len);
3273 break;
3274 case RX_MGMT_CFG80211_RX_ASSOC:
3275 cfg80211_send_rx_assoc(sdata->dev, bss, (u8 *)mgmt, skb->len);
3276 break;
3277 case RX_MGMT_CFG80211_ASSOC_TIMEOUT:
3278 cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid);
3279 break;
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003280 case RX_MGMT_CFG80211_TX_DEAUTH:
3281 cfg80211_send_deauth(sdata->dev, deauth_buf,
3282 sizeof(deauth_buf));
3283 break;
Johannes Berg66e67e42012-01-20 13:55:27 +01003284 default:
3285 WARN(1, "unexpected: %d", rma);
Johannes Bergb054b742010-06-07 21:50:07 +02003286 }
Jiri Bencf0706e82007-05-05 11:45:53 -07003287}
3288
Johannes Berg9c6bd792008-09-11 00:01:52 +02003289static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07003290{
3291 struct ieee80211_sub_if_data *sdata =
3292 (struct ieee80211_sub_if_data *) data;
Jiri Bencf0706e82007-05-05 11:45:53 -07003293
Stanislaw Gruszka9b7d72c2013-02-28 10:55:27 +01003294 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07003295}
3296
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003297static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01003298 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003299{
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003300 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02003301 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003302
Johannes Berg37ad3882012-02-24 13:50:54 +01003303 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01003304 tx, frame_buf);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003305 mutex_unlock(&ifmgd->mtx);
Johannes Berg37ad3882012-02-24 13:50:54 +01003306
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003307 /*
3308 * must be outside lock due to cfg80211,
3309 * but that's not a problem.
3310 */
Antonio Quartulli6ae16772012-09-07 13:28:52 +02003311 cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN);
Felix Fietkaufcac4fb2011-11-16 13:34:55 +01003312
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003313 mutex_lock(&ifmgd->mtx);
3314}
3315
Johannes Berg66e67e42012-01-20 13:55:27 +01003316static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
3317{
3318 struct ieee80211_local *local = sdata->local;
3319 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3320 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003321 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01003322
3323 lockdep_assert_held(&ifmgd->mtx);
3324
3325 if (WARN_ON_ONCE(!auth_data))
3326 return -EINVAL;
3327
Johannes Berg66e67e42012-01-20 13:55:27 +01003328 auth_data->tries++;
3329
3330 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003331 sdata_info(sdata, "authentication with %pM timed out\n",
3332 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003333
3334 /*
3335 * Most likely AP is not in the range so remove the
3336 * bss struct for that AP.
3337 */
3338 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
3339
3340 return -ETIMEDOUT;
3341 }
3342
Johannes Berga1845fc2012-06-27 13:18:36 +02003343 drv_mgd_prepare_tx(local, sdata);
3344
Johannes Berg66e67e42012-01-20 13:55:27 +01003345 if (auth_data->bss->proberesp_ies) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003346 u16 trans = 1;
3347 u16 status = 0;
3348
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003349 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
3350 auth_data->bss->bssid, auth_data->tries,
3351 IEEE80211_AUTH_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01003352
3353 auth_data->expected_transaction = 2;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003354
3355 if (auth_data->algorithm == WLAN_AUTH_SAE) {
3356 trans = auth_data->sae_trans;
3357 status = auth_data->sae_status;
3358 auth_data->expected_transaction = trans;
3359 }
3360
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02003361 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
3362 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3363 IEEE80211_TX_INTFL_MLME_CONN_TX;
3364
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003365 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
3366 auth_data->data, auth_data->data_len,
Johannes Berg66e67e42012-01-20 13:55:27 +01003367 auth_data->bss->bssid,
Johannes Berg1672c0e32013-01-29 15:02:27 +01003368 auth_data->bss->bssid, NULL, 0, 0,
3369 tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01003370 } else {
3371 const u8 *ssidie;
3372
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003373 sdata_info(sdata, "direct probe to %pM (try %d/%i)\n",
3374 auth_data->bss->bssid, auth_data->tries,
3375 IEEE80211_AUTH_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01003376
Johannes Berg9caf0362012-11-29 01:25:20 +01003377 rcu_read_lock();
Johannes Berg66e67e42012-01-20 13:55:27 +01003378 ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
Johannes Berg9caf0362012-11-29 01:25:20 +01003379 if (!ssidie) {
3380 rcu_read_unlock();
Johannes Berg66e67e42012-01-20 13:55:27 +01003381 return -EINVAL;
Johannes Berg9caf0362012-11-29 01:25:20 +01003382 }
Johannes Berg66e67e42012-01-20 13:55:27 +01003383 /*
3384 * Direct probe is sent to broadcast address as some APs
3385 * will not answer to direct packet in unassociated state.
3386 */
3387 ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02003388 NULL, 0, (u32) -1, true, 0,
Johannes Berg55de9082012-07-26 17:24:39 +02003389 auth_data->bss->channel, false);
Johannes Berg9caf0362012-11-29 01:25:20 +01003390 rcu_read_unlock();
Johannes Berg66e67e42012-01-20 13:55:27 +01003391 }
3392
Stanislaw Gruszka6211dd12013-05-17 13:43:04 +02003393 if (tx_flags == 0) {
Johannes Berg1672c0e32013-01-29 15:02:27 +01003394 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01003395 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003396 run_again(ifmgd, auth_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01003397 } else {
3398 auth_data->timeout_started = false;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003399 }
Johannes Berg66e67e42012-01-20 13:55:27 +01003400
3401 return 0;
3402}
3403
3404static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
3405{
3406 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3407 struct ieee80211_local *local = sdata->local;
3408
3409 lockdep_assert_held(&sdata->u.mgd.mtx);
3410
Johannes Berg66e67e42012-01-20 13:55:27 +01003411 assoc_data->tries++;
3412 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003413 sdata_info(sdata, "association with %pM timed out\n",
3414 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003415
3416 /*
3417 * Most likely AP is not in the range so remove the
3418 * bss struct for that AP.
3419 */
3420 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
3421
3422 return -ETIMEDOUT;
3423 }
3424
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003425 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
3426 assoc_data->bss->bssid, assoc_data->tries,
3427 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01003428 ieee80211_send_assoc(sdata);
3429
Johannes Berg1672c0e32013-01-29 15:02:27 +01003430 if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
3431 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Berg89afe612013-02-13 15:39:57 +01003432 assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003433 run_again(&sdata->u.mgd, assoc_data->timeout);
Johannes Berg89afe612013-02-13 15:39:57 +01003434 } else {
3435 assoc_data->timeout_started = false;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003436 }
Johannes Berg66e67e42012-01-20 13:55:27 +01003437
3438 return 0;
3439}
3440
Johannes Berg1672c0e32013-01-29 15:02:27 +01003441void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
3442 __le16 fc, bool acked)
3443{
3444 struct ieee80211_local *local = sdata->local;
3445
3446 sdata->u.mgd.status_fc = fc;
3447 sdata->u.mgd.status_acked = acked;
3448 sdata->u.mgd.status_received = true;
3449
3450 ieee80211_queue_work(&local->hw, &sdata->work);
3451}
3452
Johannes Berg1fa57d02010-06-10 10:21:32 +02003453void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02003454{
Johannes Berg60f8b392008-09-08 17:44:22 +02003455 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02003456 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02003457
Johannes Berg77fdaa12009-07-07 03:45:17 +02003458 mutex_lock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02003459
Johannes Berg1672c0e32013-01-29 15:02:27 +01003460 if (ifmgd->status_received) {
3461 __le16 fc = ifmgd->status_fc;
3462 bool status_acked = ifmgd->status_acked;
3463
3464 ifmgd->status_received = false;
3465 if (ifmgd->auth_data &&
3466 (ieee80211_is_probe_req(fc) || ieee80211_is_auth(fc))) {
3467 if (status_acked) {
3468 ifmgd->auth_data->timeout =
3469 jiffies + IEEE80211_AUTH_TIMEOUT_SHORT;
3470 run_again(ifmgd, ifmgd->auth_data->timeout);
3471 } else {
3472 ifmgd->auth_data->timeout = jiffies - 1;
3473 }
Johannes Berg89afe612013-02-13 15:39:57 +01003474 ifmgd->auth_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003475 } else if (ifmgd->assoc_data &&
3476 (ieee80211_is_assoc_req(fc) ||
3477 ieee80211_is_reassoc_req(fc))) {
3478 if (status_acked) {
3479 ifmgd->assoc_data->timeout =
3480 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
3481 run_again(ifmgd, ifmgd->assoc_data->timeout);
3482 } else {
3483 ifmgd->assoc_data->timeout = jiffies - 1;
3484 }
Johannes Berg89afe612013-02-13 15:39:57 +01003485 ifmgd->assoc_data->timeout_started = true;
Johannes Berg1672c0e32013-01-29 15:02:27 +01003486 }
3487 }
3488
Johannes Berg89afe612013-02-13 15:39:57 +01003489 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01003490 time_after(jiffies, ifmgd->auth_data->timeout)) {
3491 if (ifmgd->auth_data->done) {
3492 /*
3493 * ok ... we waited for assoc but userspace didn't,
3494 * so let's just kill the auth data
3495 */
3496 ieee80211_destroy_auth_data(sdata, false);
3497 } else if (ieee80211_probe_auth(sdata)) {
3498 u8 bssid[ETH_ALEN];
3499
3500 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
3501
3502 ieee80211_destroy_auth_data(sdata, false);
3503
3504 mutex_unlock(&ifmgd->mtx);
3505 cfg80211_send_auth_timeout(sdata->dev, bssid);
3506 mutex_lock(&ifmgd->mtx);
3507 }
Johannes Berg89afe612013-02-13 15:39:57 +01003508 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
Johannes Berg66e67e42012-01-20 13:55:27 +01003509 run_again(ifmgd, ifmgd->auth_data->timeout);
3510
Johannes Berg89afe612013-02-13 15:39:57 +01003511 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
Johannes Berg66e67e42012-01-20 13:55:27 +01003512 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003513 if ((ifmgd->assoc_data->need_beacon &&
3514 !ifmgd->assoc_data->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01003515 ieee80211_do_assoc(sdata)) {
3516 u8 bssid[ETH_ALEN];
3517
3518 memcpy(bssid, ifmgd->assoc_data->bss->bssid, ETH_ALEN);
3519
3520 ieee80211_destroy_assoc_data(sdata, false);
3521
3522 mutex_unlock(&ifmgd->mtx);
3523 cfg80211_send_assoc_timeout(sdata->dev, bssid);
3524 mutex_lock(&ifmgd->mtx);
3525 }
Johannes Berg89afe612013-02-13 15:39:57 +01003526 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
Johannes Berg66e67e42012-01-20 13:55:27 +01003527 run_again(ifmgd, ifmgd->assoc_data->timeout);
3528
Johannes Bergb291ba12009-07-10 15:29:03 +02003529 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
3530 IEEE80211_STA_CONNECTION_POLL) &&
3531 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03003532 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003533 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03003534
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003535 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003536
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003537 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Ben Greear180205b2011-02-04 15:30:24 -08003538 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003539 else
Ben Greear180205b2011-02-04 15:30:24 -08003540 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003541
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003542 /* ACK received for nullfunc probing frame */
3543 if (!ifmgd->probe_send_count)
3544 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003545 else if (ifmgd->nullfunc_failed) {
3546 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003547 mlme_dbg(sdata,
3548 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
3549 bssid, ifmgd->probe_send_count,
3550 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003551 ieee80211_mgd_probe_ap_send(sdata);
3552 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003553 mlme_dbg(sdata,
3554 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
3555 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02003556 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003557 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3558 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003559 }
3560 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Bergb291ba12009-07-10 15:29:03 +02003561 run_again(ifmgd, ifmgd->probe_timeout);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003562 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003563 mlme_dbg(sdata,
3564 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
3565 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02003566 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003567 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003568 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003569 mlme_dbg(sdata,
3570 "No probe response from AP %pM after %dms, try %d/%i\n",
3571 bssid, probe_wait_ms,
3572 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03003573 ieee80211_mgd_probe_ap_send(sdata);
3574 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02003575 /*
3576 * We actually lost the connection ... or did we?
3577 * Let's make sure!
3578 */
Ben Greearb38afa82010-10-07 16:12:06 -07003579 wiphy_debug(local->hw.wiphy,
3580 "%s: No probe response from AP %pM"
3581 " after %dms, disconnecting.\n",
3582 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08003583 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003584
Johannes Berg95acac62011-07-12 12:30:59 +02003585 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003586 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02003587 }
3588 }
3589
Johannes Berg77fdaa12009-07-07 03:45:17 +02003590 mutex_unlock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02003591}
Johannes Berg0a51b272008-09-08 17:44:25 +02003592
Johannes Bergb291ba12009-07-10 15:29:03 +02003593static void ieee80211_sta_bcn_mon_timer(unsigned long data)
3594{
3595 struct ieee80211_sub_if_data *sdata =
3596 (struct ieee80211_sub_if_data *) data;
3597 struct ieee80211_local *local = sdata->local;
3598
3599 if (local->quiescing)
3600 return;
3601
Johannes Berg682bd382013-01-29 13:13:50 +01003602 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003603 ieee80211_queue_work(&sdata->local->hw,
3604 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003605}
3606
3607static void ieee80211_sta_conn_mon_timer(unsigned long data)
3608{
3609 struct ieee80211_sub_if_data *sdata =
3610 (struct ieee80211_sub_if_data *) data;
3611 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3612 struct ieee80211_local *local = sdata->local;
3613
3614 if (local->quiescing)
3615 return;
3616
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04003617 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003618}
3619
3620static void ieee80211_sta_monitor_work(struct work_struct *work)
3621{
3622 struct ieee80211_sub_if_data *sdata =
3623 container_of(work, struct ieee80211_sub_if_data,
3624 u.mgd.monitor_work);
3625
3626 ieee80211_mgd_probe_ap(sdata, false);
3627}
3628
Johannes Berga1678f82008-09-11 00:01:47 +02003629static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3630{
Eliad Peller494f1fe2012-02-19 15:26:09 +02003631 u32 flags;
3632
Kalle Vaload935682009-04-19 08:47:19 +03003633 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003634 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03003635
Johannes Bergb291ba12009-07-10 15:29:03 +02003636 /* let's probe the connection once */
Eliad Peller494f1fe2012-02-19 15:26:09 +02003637 flags = sdata->local->hw.flags;
3638 if (!(flags & IEEE80211_HW_CONNECTION_MONITOR))
3639 ieee80211_queue_work(&sdata->local->hw,
3640 &sdata->u.mgd.monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003641 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02003642 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03003643 }
Johannes Berga1678f82008-09-11 00:01:47 +02003644}
3645
Johannes Bergb8360ab2013-04-29 14:57:44 +02003646#ifdef CONFIG_PM
3647void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
3648{
3649 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3650
3651 mutex_lock(&ifmgd->mtx);
3652 if (!ifmgd->associated) {
3653 mutex_unlock(&ifmgd->mtx);
3654 return;
3655 }
3656
3657 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
3658 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
3659 mlme_dbg(sdata, "driver requested disconnect after resume\n");
3660 ieee80211_sta_connection_lost(sdata,
3661 ifmgd->associated->bssid,
3662 WLAN_REASON_UNSPECIFIED,
3663 true);
3664 mutex_unlock(&ifmgd->mtx);
3665 return;
3666 }
3667 mutex_unlock(&ifmgd->mtx);
3668}
3669#endif
3670
Johannes Berg9c6bd792008-09-11 00:01:52 +02003671/* interface setup */
3672void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
3673{
Johannes Berg46900292009-02-15 12:44:28 +01003674 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003675
Johannes Berg46900292009-02-15 12:44:28 +01003676 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02003677 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01003678 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003679 INIT_WORK(&ifmgd->beacon_connection_loss_work,
3680 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02003681 INIT_WORK(&ifmgd->csa_connection_drop_work,
3682 ieee80211_csa_connection_drop_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02003683 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01003684 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02003685 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003686 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
3687 (unsigned long) sdata);
3688 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
3689 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01003690 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05303691 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02003692
Johannes Bergab1faea2009-07-01 21:41:17 +02003693 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05303694 ifmgd->powersave = sdata->wdev.ps;
Alexander Bondar219c3862013-01-22 16:52:23 +02003695 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
3696 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
Janusz Dziedzic67baf662013-03-21 15:47:56 +01003697 ifmgd->p2p_noa_index = -1;
Johannes Bergbbbdff92009-04-16 13:27:42 +02003698
Johannes Berg77fdaa12009-07-07 03:45:17 +02003699 mutex_init(&ifmgd->mtx);
Johannes Berg0f782312009-12-01 13:37:02 +01003700
3701 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
3702 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
3703 else
3704 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003705}
3706
3707/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02003708void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
3709{
Johannes Berg31ee67a2012-07-06 21:18:24 +02003710 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02003711
3712 /* Restart STA timers */
3713 rcu_read_lock();
Ben Greear370bd002013-03-19 17:50:50 -07003714 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3715 if (ieee80211_sdata_running(sdata))
3716 ieee80211_restart_sta_timer(sdata);
3717 }
Johannes Berga1678f82008-09-11 00:01:47 +02003718 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02003719}
Johannes Berg10f644a2009-04-16 13:17:25 +02003720
3721int ieee80211_max_network_latency(struct notifier_block *nb,
3722 unsigned long data, void *dummy)
3723{
3724 s32 latency_usec = (s32) data;
3725 struct ieee80211_local *local =
3726 container_of(nb, struct ieee80211_local,
3727 network_latency_notifier);
3728
3729 mutex_lock(&local->iflist_mtx);
3730 ieee80211_recalc_ps(local, latency_usec);
3731 mutex_unlock(&local->iflist_mtx);
3732
3733 return 0;
3734}
Johannes Berg77fdaa12009-07-07 03:45:17 +02003735
Johannes Bergf2d9d272012-11-22 14:11:39 +01003736static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
3737 struct cfg80211_bss *cbss)
3738{
3739 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3740 const u8 *ht_cap_ie, *vht_cap_ie;
3741 const struct ieee80211_ht_cap *ht_cap;
3742 const struct ieee80211_vht_cap *vht_cap;
3743 u8 chains = 1;
3744
3745 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
3746 return chains;
3747
Johannes Berg9caf0362012-11-29 01:25:20 +01003748 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003749 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
3750 ht_cap = (void *)(ht_cap_ie + 2);
3751 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
3752 /*
3753 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
3754 * "Tx Unequal Modulation Supported" fields.
3755 */
3756 }
3757
3758 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
3759 return chains;
3760
Johannes Berg9caf0362012-11-29 01:25:20 +01003761 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003762 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
3763 u8 nss;
3764 u16 tx_mcs_map;
3765
3766 vht_cap = (void *)(vht_cap_ie + 2);
3767 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
3768 for (nss = 8; nss > 0; nss--) {
3769 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
3770 IEEE80211_VHT_MCS_NOT_SUPPORTED)
3771 break;
3772 }
3773 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
3774 chains = max(chains, nss);
3775 }
3776
3777 return chains;
3778}
3779
Johannes Bergb17166a2012-07-27 11:41:27 +02003780static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
3781 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01003782{
3783 struct ieee80211_local *local = sdata->local;
3784 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg24398e32012-03-28 10:58:36 +02003785 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003786 const struct ieee80211_vht_operation *vht_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02003787 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01003788 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003789 int ret;
Johannes Berga1cf7752012-03-08 15:02:07 +01003790
Johannes Berg24398e32012-03-28 10:58:36 +02003791 sband = local->hw.wiphy->bands[cbss->channel->band];
3792
Johannes Bergf2d9d272012-11-22 14:11:39 +01003793 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
3794 IEEE80211_STA_DISABLE_80P80MHZ |
3795 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02003796
Johannes Berg9caf0362012-11-29 01:25:20 +01003797 rcu_read_lock();
3798
Johannes Bergf2d9d272012-11-22 14:11:39 +01003799 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3800 sband->ht_cap.ht_supported) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01003801 const u8 *ht_oper_ie, *ht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003802
Johannes Berg9caf0362012-11-29 01:25:20 +01003803 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02003804 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
3805 ht_oper = (void *)(ht_oper_ie + 2);
Johannes Berg08e6effa2013-02-07 23:33:32 +01003806
3807 ht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
3808 if (!ht_cap || ht_cap[1] < sizeof(struct ieee80211_ht_cap)) {
3809 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3810 ht_oper = NULL;
3811 }
Johannes Berg24398e32012-03-28 10:58:36 +02003812 }
3813
Johannes Bergf2d9d272012-11-22 14:11:39 +01003814 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3815 sband->vht_cap.vht_supported) {
Johannes Berg08e6effa2013-02-07 23:33:32 +01003816 const u8 *vht_oper_ie, *vht_cap;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003817
Johannes Berg9caf0362012-11-29 01:25:20 +01003818 vht_oper_ie = ieee80211_bss_get_ie(cbss,
3819 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003820 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
3821 vht_oper = (void *)(vht_oper_ie + 2);
3822 if (vht_oper && !ht_oper) {
3823 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003824 sdata_info(sdata,
Johannes Bergf2d9d272012-11-22 14:11:39 +01003825 "AP advertised VHT without HT, disabling both\n");
Johannes Bergcb145022013-02-07 20:41:50 +01003826 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
3827 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg24398e32012-03-28 10:58:36 +02003828 }
Johannes Berg08e6effa2013-02-07 23:33:32 +01003829
3830 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
3831 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
3832 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3833 vht_oper = NULL;
3834 }
Johannes Berg24398e32012-03-28 10:58:36 +02003835 }
3836
Johannes Bergf2d9d272012-11-22 14:11:39 +01003837 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
3838 cbss->channel,
3839 ht_oper, vht_oper,
Johannes Berg30eb1dc2013-02-08 15:12:14 +01003840 &chandef, true);
Johannes Berg04ecd252012-09-11 14:34:12 +02003841
Johannes Bergf2d9d272012-11-22 14:11:39 +01003842 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
3843 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02003844
Johannes Berg9caf0362012-11-29 01:25:20 +01003845 rcu_read_unlock();
3846
Johannes Berg04ecd252012-09-11 14:34:12 +02003847 /* will change later if needed */
3848 sdata->smps_mode = IEEE80211_SMPS_OFF;
3849
Johannes Bergf2d9d272012-11-22 14:11:39 +01003850 /*
3851 * If this fails (possibly due to channel context sharing
3852 * on incompatible channels, e.g. 80+80 and 160 sharing the
3853 * same control channel) try to use a smaller bandwidth.
3854 */
3855 ret = ieee80211_vif_use_channel(sdata, &chandef,
3856 IEEE80211_CHANCTX_SHARED);
Johannes Bergd601cd82013-02-07 20:54:51 +01003857 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
Johannes Bergf2d9d272012-11-22 14:11:39 +01003858 ifmgd->flags |= chandef_downgrade(&chandef);
Johannes Bergd601cd82013-02-07 20:54:51 +01003859 ret = ieee80211_vif_use_channel(sdata, &chandef,
3860 IEEE80211_CHANCTX_SHARED);
3861 }
Johannes Bergf2d9d272012-11-22 14:11:39 +01003862 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02003863}
3864
3865static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3866 struct cfg80211_bss *cbss, bool assoc)
3867{
3868 struct ieee80211_local *local = sdata->local;
3869 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3870 struct ieee80211_bss *bss = (void *)cbss->priv;
3871 struct sta_info *new_sta = NULL;
3872 bool have_sta = false;
3873 int err;
3874
3875 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
3876 return -EINVAL;
3877
3878 if (assoc) {
3879 rcu_read_lock();
3880 have_sta = sta_info_get(sdata, cbss->bssid);
3881 rcu_read_unlock();
3882 }
3883
3884 if (!have_sta) {
3885 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
3886 if (!new_sta)
3887 return -ENOMEM;
3888 }
3889
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003890 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003891 u32 rates = 0, basic_rates = 0;
3892 bool have_higher_than_11mbit;
3893 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Bergb17166a2012-07-27 11:41:27 +02003894 struct ieee80211_supported_band *sband;
Johannes Berg8cef2c92013-02-05 16:54:31 +01003895 const struct cfg80211_bss_ies *ies;
Johannes Bergb17166a2012-07-27 11:41:27 +02003896
3897 sband = local->hw.wiphy->bands[cbss->channel->band];
3898
3899 err = ieee80211_prep_channel(sdata, cbss);
3900 if (err) {
3901 sta_info_free(local, new_sta);
3902 return err;
3903 }
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003904
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003905 ieee80211_get_rates(sband, bss->supp_rates,
3906 bss->supp_rates_len,
3907 &rates, &basic_rates,
3908 &have_higher_than_11mbit,
3909 &min_rate, &min_rate_index);
3910
3911 /*
3912 * This used to be a workaround for basic rates missing
3913 * in the association response frame. Now that we no
3914 * longer use the basic rates from there, it probably
3915 * doesn't happen any more, but keep the workaround so
3916 * in case some *other* APs are buggy in different ways
3917 * we can connect -- with a warning.
3918 */
3919 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003920 sdata_info(sdata,
3921 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003922 basic_rates = BIT(min_rate_index);
3923 }
3924
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003925 new_sta->sta.supp_rates[cbss->channel->band] = rates;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003926 sdata->vif.bss_conf.basic_rates = basic_rates;
3927
3928 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg55de9082012-07-26 17:24:39 +02003929 if (cbss->channel->band == IEEE80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003930 have_higher_than_11mbit)
3931 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
3932 else
3933 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
3934
3935 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
3936
Johannes Berg8c358bc2012-05-22 22:13:05 +02003937 /* set timing information */
3938 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01003939 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01003940 ies = rcu_dereference(cbss->beacon_ies);
3941 if (ies) {
3942 const u8 *tim_ie;
3943
3944 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3945 sdata->vif.bss_conf.sync_device_ts =
3946 bss->device_ts_beacon;
3947 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
3948 ies->data, ies->len);
3949 if (tim_ie && tim_ie[1] >= 2)
3950 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
3951 else
3952 sdata->vif.bss_conf.sync_dtim_count = 0;
3953 } else if (!(local->hw.flags &
3954 IEEE80211_HW_TIMING_BEACON_ONLY)) {
3955 ies = rcu_dereference(cbss->proberesp_ies);
3956 /* must be non-NULL since beacon IEs were NULL */
3957 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3958 sdata->vif.bss_conf.sync_device_ts =
3959 bss->device_ts_presp;
3960 sdata->vif.bss_conf.sync_dtim_count = 0;
3961 } else {
3962 sdata->vif.bss_conf.sync_tsf = 0;
3963 sdata->vif.bss_conf.sync_device_ts = 0;
3964 sdata->vif.bss_conf.sync_dtim_count = 0;
3965 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01003966 rcu_read_unlock();
Johannes Berg8c358bc2012-05-22 22:13:05 +02003967
3968 /* tell driver about BSSID, basic rates and timing */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003969 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02003970 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
3971 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01003972
3973 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003974 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01003975
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003976 err = sta_info_insert(new_sta);
3977 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01003978 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003979 sdata_info(sdata,
3980 "failed to insert STA entry for the AP (error %d)\n",
3981 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01003982 return err;
3983 }
3984 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00003985 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01003986
3987 return 0;
3988}
3989
Johannes Berg77fdaa12009-07-07 03:45:17 +02003990/* config hooks */
3991int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
3992 struct cfg80211_auth_request *req)
3993{
Johannes Berg66e67e42012-01-20 13:55:27 +01003994 struct ieee80211_local *local = sdata->local;
3995 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3996 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003997 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01003998 int err;
3999
4000 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02004001
4002 switch (req->auth_type) {
4003 case NL80211_AUTHTYPE_OPEN_SYSTEM:
4004 auth_alg = WLAN_AUTH_OPEN;
4005 break;
4006 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01004007 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02004008 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004009 auth_alg = WLAN_AUTH_SHARED_KEY;
4010 break;
4011 case NL80211_AUTHTYPE_FT:
4012 auth_alg = WLAN_AUTH_FT;
4013 break;
4014 case NL80211_AUTHTYPE_NETWORK_EAP:
4015 auth_alg = WLAN_AUTH_LEAP;
4016 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004017 case NL80211_AUTHTYPE_SAE:
4018 auth_alg = WLAN_AUTH_SAE;
4019 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004020 default:
4021 return -EOPNOTSUPP;
4022 }
4023
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004024 auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len +
4025 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01004026 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004027 return -ENOMEM;
4028
Johannes Berg66e67e42012-01-20 13:55:27 +01004029 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004030
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004031 if (req->sae_data_len >= 4) {
4032 __le16 *pos = (__le16 *) req->sae_data;
4033 auth_data->sae_trans = le16_to_cpu(pos[0]);
4034 auth_data->sae_status = le16_to_cpu(pos[1]);
4035 memcpy(auth_data->data, req->sae_data + 4,
4036 req->sae_data_len - 4);
4037 auth_data->data_len += req->sae_data_len - 4;
4038 }
4039
Johannes Berg77fdaa12009-07-07 03:45:17 +02004040 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03004041 memcpy(&auth_data->data[auth_data->data_len],
4042 req->ie, req->ie_len);
4043 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004044 }
4045
Johannes Bergfffd0932009-07-08 14:22:54 +02004046 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004047 auth_data->key_len = req->key_len;
4048 auth_data->key_idx = req->key_idx;
4049 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02004050 }
4051
Johannes Berg66e67e42012-01-20 13:55:27 +01004052 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004053
Johannes Berg66e67e42012-01-20 13:55:27 +01004054 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01004055
Johannes Berg66e67e42012-01-20 13:55:27 +01004056 mutex_lock(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004057
Johannes Berg66e67e42012-01-20 13:55:27 +01004058 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
4059 ifmgd->assoc_data) {
4060 err = -EBUSY;
4061 goto err_free;
4062 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004063
Johannes Berg66e67e42012-01-20 13:55:27 +01004064 if (ifmgd->auth_data)
4065 ieee80211_destroy_auth_data(sdata, false);
Guy Eilam2a33bee2011-08-17 15:18:15 +03004066
Johannes Berg66e67e42012-01-20 13:55:27 +01004067 /* prep auth_data so we don't go into idle on disassoc */
4068 ifmgd->auth_data = auth_data;
4069
Johannes Berg7b119dc2013-04-10 21:38:36 +02004070 if (ifmgd->associated) {
4071 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4072
4073 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4074 WLAN_REASON_UNSPECIFIED,
4075 false, frame_buf);
4076
4077 __cfg80211_send_deauth(sdata->dev, frame_buf,
4078 sizeof(frame_buf));
4079 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004080
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004081 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004082
Johannes Berga1cf7752012-03-08 15:02:07 +01004083 err = ieee80211_prep_connection(sdata, req->bss, false);
4084 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01004085 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004086
Johannes Berg66e67e42012-01-20 13:55:27 +01004087 err = ieee80211_probe_auth(sdata);
4088 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004089 sta_info_destroy_addr(sdata, req->bss->bssid);
4090 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004091 }
4092
Johannes Berg66e67e42012-01-20 13:55:27 +01004093 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01004094 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01004095 err = 0;
4096 goto out_unlock;
Johannes Berge5b900d2010-07-29 16:08:55 +02004097
Johannes Berg66e67e42012-01-20 13:55:27 +01004098 err_clear:
Eliad Peller3d2abdf2012-09-04 17:44:45 +03004099 memset(ifmgd->bssid, 0, ETH_ALEN);
4100 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01004101 ifmgd->auth_data = NULL;
4102 err_free:
4103 kfree(auth_data);
4104 out_unlock:
4105 mutex_unlock(&ifmgd->mtx);
Johannes Berge5b900d2010-07-29 16:08:55 +02004106
Johannes Berg66e67e42012-01-20 13:55:27 +01004107 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004108}
4109
Johannes Berg77fdaa12009-07-07 03:45:17 +02004110int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
4111 struct cfg80211_assoc_request *req)
4112{
Johannes Berg66e67e42012-01-20 13:55:27 +01004113 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004114 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004115 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01004116 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004117 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01004118 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01004119 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004120 int i, err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004121
Johannes Berg66e67e42012-01-20 13:55:27 +01004122 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
4123 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01004124 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004125
Johannes Berg9caf0362012-11-29 01:25:20 +01004126 rcu_read_lock();
4127 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
4128 if (!ssidie) {
4129 rcu_read_unlock();
4130 kfree(assoc_data);
4131 return -EINVAL;
4132 }
4133 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
4134 assoc_data->ssid_len = ssidie[1];
4135 rcu_read_unlock();
4136
Johannes Berg66e67e42012-01-20 13:55:27 +01004137 mutex_lock(&ifmgd->mtx);
4138
Johannes Berg7b119dc2013-04-10 21:38:36 +02004139 if (ifmgd->associated) {
4140 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4141
4142 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4143 WLAN_REASON_UNSPECIFIED,
4144 false, frame_buf);
4145
4146 __cfg80211_send_deauth(sdata->dev, frame_buf,
4147 sizeof(frame_buf));
4148 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004149
4150 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
4151 err = -EBUSY;
4152 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03004153 }
4154
Johannes Berg66e67e42012-01-20 13:55:27 +01004155 if (ifmgd->assoc_data) {
4156 err = -EBUSY;
4157 goto err_free;
4158 }
4159
4160 if (ifmgd->auth_data) {
4161 bool match;
4162
4163 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00004164 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01004165 ieee80211_destroy_auth_data(sdata, match);
4166 }
4167
4168 /* prepare assoc data */
Johannes Berg19c3b832012-08-01 20:13:36 +02004169
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03004170 ifmgd->beacon_crc_valid = false;
4171
Johannes Bergde5036a2012-03-08 15:02:03 +01004172 /*
4173 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
4174 * We still associate in non-HT mode (11a/b/g) if any one of these
4175 * ciphers is configured as pairwise.
4176 * We can set this to true for non-11n hardware, that'll be checked
4177 * separately along with the peer capabilities.
4178 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02004179 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02004180 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
4181 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02004182 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01004183 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004184 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg1c4cb922012-05-30 15:57:00 +02004185 netdev_info(sdata->dev,
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004186 "disabling HT/VHT due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02004187 }
4188 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004189
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004190 if (req->flags & ASSOC_REQ_DISABLE_HT) {
Johannes Berga8243b72012-11-22 14:32:09 +01004191 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004192 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4193 }
Ben Greearef96a8422011-11-18 11:32:00 -08004194
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01004195 if (req->flags & ASSOC_REQ_DISABLE_VHT)
4196 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4197
Johannes Berg4e74bfd2012-03-08 15:02:04 +01004198 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4199 sband = local->hw.wiphy->bands[req->bss->channel->band];
4200 if (!sband->ht_cap.ht_supported ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02004201 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
Johannes Berga8243b72012-11-22 14:32:09 +01004202 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg1b49de22012-07-27 10:29:14 +02004203 if (!bss->wmm_used)
4204 netdev_info(sdata->dev,
4205 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02004206 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01004207
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004208 /* disable VHT if we don't support it or the AP doesn't use WMM */
4209 if (!sband->vht_cap.vht_supported ||
4210 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
4211 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg1b49de22012-07-27 10:29:14 +02004212 if (!bss->wmm_used)
4213 netdev_info(sdata->dev,
4214 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00004215 }
4216
Ben Greearef96a8422011-11-18 11:32:00 -08004217 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
4218 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
4219 sizeof(ifmgd->ht_capa_mask));
4220
Johannes Bergdd5ecfe2013-02-21 17:40:19 +01004221 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
4222 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
4223 sizeof(ifmgd->vht_capa_mask));
4224
Johannes Berg77fdaa12009-07-07 03:45:17 +02004225 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01004226 memcpy(assoc_data->ie, req->ie, req->ie_len);
4227 assoc_data->ie_len = req->ie_len;
4228 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02004229
Johannes Berg66e67e42012-01-20 13:55:27 +01004230 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01004231
Johannes Bergaf6b6372009-12-23 13:15:35 +01004232 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
4233 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02004234 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004235 else
Johannes Berg04ecd252012-09-11 14:34:12 +02004236 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004237 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02004238 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01004239
Johannes Berg66e67e42012-01-20 13:55:27 +01004240 assoc_data->capability = req->bss->capability;
Johannes Berg32c50572012-03-28 11:04:29 +02004241 assoc_data->wmm = bss->wmm_used &&
4242 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg66e67e42012-01-20 13:55:27 +01004243 assoc_data->supp_rates = bss->supp_rates;
4244 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02004245
Johannes Berg9caf0362012-11-29 01:25:20 +01004246 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02004247 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
4248 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
4249 assoc_data->ap_ht_param =
4250 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
4251 else
Johannes Berga8243b72012-11-22 14:32:09 +01004252 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01004253 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
4254 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
4255 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
4256 sizeof(struct ieee80211_vht_cap));
4257 else
4258 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01004259 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01004260
Kalle Valoab133152010-01-12 10:42:31 +02004261 if (bss->wmm_used && bss->uapsd_supported &&
Alexander Bondar24aa11a2013-04-02 15:30:14 +03004262 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) &&
4263 sdata->wmm_acm != 0xff) {
Johannes Berg76f03032012-03-08 15:02:05 +01004264 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02004265 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
4266 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01004267 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02004268 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
4269 }
4270
Johannes Berg77fdaa12009-07-07 03:45:17 +02004271 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01004272 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004273
4274 if (req->use_mfp) {
4275 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
4276 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
4277 } else {
4278 ifmgd->mfp = IEEE80211_MFP_DISABLED;
4279 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
4280 }
4281
4282 if (req->crypto.control_port)
4283 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
4284 else
4285 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
4286
Johannes Berga621fa42010-08-27 14:26:54 +03004287 sdata->control_port_protocol = req->crypto.control_port_ethertype;
4288 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
4289
Johannes Berg66e67e42012-01-20 13:55:27 +01004290 /* kick off associate process */
4291
4292 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02004293 ifmgd->dtim_period = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004294
Johannes Berga1cf7752012-03-08 15:02:07 +01004295 err = ieee80211_prep_connection(sdata, req->bss, true);
4296 if (err)
4297 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01004298
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004299 rcu_read_lock();
4300 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02004301
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004302 if (sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC &&
4303 !beacon_ies) {
4304 /*
4305 * Wait up to one beacon interval ...
4306 * should this be more if we miss one?
4307 */
4308 sdata_info(sdata, "waiting for beacon from %pM\n",
4309 ifmgd->bssid);
4310 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg89afe612013-02-13 15:39:57 +01004311 assoc_data->timeout_started = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004312 assoc_data->need_beacon = true;
4313 } else if (beacon_ies) {
4314 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4315 beacon_ies->data,
4316 beacon_ies->len);
Johannes Bergef429da2013-02-05 17:48:40 +01004317 u8 dtim_count = 0;
4318
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004319 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
4320 const struct ieee80211_tim_ie *tim;
4321 tim = (void *)(tim_ie + 2);
4322 ifmgd->dtim_period = tim->dtim_period;
Johannes Bergef429da2013-02-05 17:48:40 +01004323 dtim_count = tim->dtim_count;
Johannes Berg826262c2012-12-10 16:38:14 +02004324 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004325 assoc_data->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01004326 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01004327 assoc_data->timeout_started = true;
Johannes Bergef429da2013-02-05 17:48:40 +01004328
4329 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
4330 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
4331 sdata->vif.bss_conf.sync_device_ts =
4332 bss->device_ts_beacon;
4333 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
4334 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004335 } else {
4336 assoc_data->timeout = jiffies;
Johannes Berg89afe612013-02-13 15:39:57 +01004337 assoc_data->timeout_started = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01004338 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004339 rcu_read_unlock();
4340
Johannes Berg66e67e42012-01-20 13:55:27 +01004341 run_again(ifmgd, assoc_data->timeout);
4342
Paul Stewartfcff4f12012-02-23 17:59:53 -08004343 if (bss->corrupt_data) {
4344 char *corrupt_type = "data";
4345 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
4346 if (bss->corrupt_data &
4347 IEEE80211_BSS_CORRUPT_PROBE_RESP)
4348 corrupt_type = "beacon and probe response";
4349 else
4350 corrupt_type = "beacon";
4351 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
4352 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004353 sdata_info(sdata, "associating with AP with corrupt %s\n",
4354 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08004355 }
4356
Johannes Berg66e67e42012-01-20 13:55:27 +01004357 err = 0;
4358 goto out;
4359 err_clear:
Eliad Peller3d2abdf2012-09-04 17:44:45 +03004360 memset(ifmgd->bssid, 0, ETH_ALEN);
4361 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01004362 ifmgd->assoc_data = NULL;
4363 err_free:
4364 kfree(assoc_data);
4365 out:
4366 mutex_unlock(&ifmgd->mtx);
4367
4368 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004369}
4370
4371int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01004372 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004373{
4374 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004375 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02004376 bool tx = !req->local_state_change;
Johannes Bergde3d43a2013-05-14 09:39:02 +02004377 bool report_frame = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004378
Johannes Berg77fdaa12009-07-07 03:45:17 +02004379 mutex_lock(&ifmgd->mtx);
4380
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004381 sdata_info(sdata,
4382 "deauthenticating from %pM by local choice (reason=%d)\n",
4383 req->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02004384
Johannes Berg86552012012-10-29 09:46:31 +01004385 if (ifmgd->auth_data) {
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03004386 drv_mgd_prepare_tx(sdata->local, sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01004387 ieee80211_send_deauth_disassoc(sdata, req->bssid,
4388 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02004389 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01004390 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01004391 ieee80211_destroy_auth_data(sdata, false);
4392 mutex_unlock(&ifmgd->mtx);
4393
Johannes Bergde3d43a2013-05-14 09:39:02 +02004394 report_frame = true;
Johannes Berg86552012012-10-29 09:46:31 +01004395 goto out;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03004396 }
4397
Johannes Berg86552012012-10-29 09:46:31 +01004398 if (ifmgd->associated &&
4399 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
4400 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4401 req->reason_code, tx, frame_buf);
Johannes Bergde3d43a2013-05-14 09:39:02 +02004402 report_frame = true;
Johannes Berg86552012012-10-29 09:46:31 +01004403 }
Johannes Berg37ad3882012-02-24 13:50:54 +01004404 mutex_unlock(&ifmgd->mtx);
4405
Johannes Berg86552012012-10-29 09:46:31 +01004406 out:
Johannes Bergde3d43a2013-05-14 09:39:02 +02004407 if (report_frame)
Johannes Berg86552012012-10-29 09:46:31 +01004408 __cfg80211_send_deauth(sdata->dev, frame_buf,
4409 IEEE80211_DEAUTH_FRAME_LEN);
4410
Johannes Berg77fdaa12009-07-07 03:45:17 +02004411 return 0;
4412}
4413
4414int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01004415 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004416{
4417 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07004418 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004419 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02004420
Johannes Berg77fdaa12009-07-07 03:45:17 +02004421 mutex_lock(&ifmgd->mtx);
4422
Johannes Berg8d8b2612009-07-25 11:58:36 +02004423 /*
4424 * cfg80211 should catch this ... but it's racy since
4425 * we can receive a disassoc frame, process it, hand it
4426 * to cfg80211 while that's in a locked section already
4427 * trying to tell us that the user wants to disconnect.
4428 */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004429 if (ifmgd->associated != req->bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02004430 mutex_unlock(&ifmgd->mtx);
4431 return -ENOLINK;
4432 }
4433
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004434 sdata_info(sdata,
4435 "disassociating from %pM by local choice (reason=%d)\n",
4436 req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02004437
Jouni Malinene69e95d2010-03-29 23:29:31 -07004438 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01004439 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
4440 req->reason_code, !req->local_state_change,
4441 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004442 mutex_unlock(&ifmgd->mtx);
4443
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004444 __cfg80211_send_disassoc(sdata->dev, frame_buf,
4445 IEEE80211_DEAUTH_FRAME_LEN);
Johannes Bergbc83b682009-11-29 12:19:06 +01004446
Johannes Berg77fdaa12009-07-07 03:45:17 +02004447 return 0;
4448}
Jouni Malinen026331c2010-02-15 12:53:10 +02004449
Eliad Pellerafa762f2012-04-23 14:45:15 +03004450void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01004451{
4452 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4453
Ben Greear49921852013-02-20 09:41:09 -08004454 /*
4455 * Make sure some work items will not run after this,
4456 * they will not do anything but might not have been
4457 * cancelled when disconnecting.
4458 */
4459 cancel_work_sync(&ifmgd->monitor_work);
4460 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
4461 cancel_work_sync(&ifmgd->request_smps_work);
4462 cancel_work_sync(&ifmgd->csa_connection_drop_work);
4463 cancel_work_sync(&ifmgd->chswitch_work);
4464
Johannes Berg54e4ffb2012-02-25 21:48:08 +01004465 mutex_lock(&ifmgd->mtx);
4466 if (ifmgd->assoc_data)
4467 ieee80211_destroy_assoc_data(sdata, false);
4468 if (ifmgd->auth_data)
4469 ieee80211_destroy_auth_data(sdata, false);
4470 del_timer_sync(&ifmgd->timer);
4471 mutex_unlock(&ifmgd->mtx);
4472}
4473
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02004474void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
4475 enum nl80211_cqm_rssi_threshold_event rssi_event,
4476 gfp_t gfp)
4477{
4478 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4479
Johannes Bergb5878a22010-04-07 16:48:40 +02004480 trace_api_cqm_rssi_notify(sdata, rssi_event);
4481
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02004482 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
4483}
4484EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);