blob: 7d4cde7af98e558ada66e9e595fce9a1a2eb54cf [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 */
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010059#define IEEE80211_BEACON_LOSS_COUNT 7
60
Johannes Bergb291ba12009-07-10 15:29:03 +020061/*
62 * Time the connection can be idle before we probe
63 * it to see if we can still talk to the AP.
64 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030065#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020066/*
67 * Time we wait for a probe response after sending
68 * a probe request because of beacon loss or for
69 * checking the connection still works.
70 */
Ben Greear180205b2011-02-04 15:30:24 -080071static int probe_wait_ms = 500;
72module_param(probe_wait_ms, int, 0644);
73MODULE_PARM_DESC(probe_wait_ms,
74 "Maximum time(ms) to wait for probe response"
75 " before disconnecting (reason 4).");
Jiri Bencf0706e82007-05-05 11:45:53 -070076
Jouni Malinen17e4ec12010-03-29 23:28:30 -070077/*
78 * Weight given to the latest Beacon frame when calculating average signal
79 * strength for Beacon frames received in the current BSS. This must be
80 * between 1 and 15.
81 */
82#define IEEE80211_SIGNAL_AVE_WEIGHT 3
83
Jouni Malinen391a2002010-08-27 22:22:00 +030084/*
85 * How many Beacon frames need to have been used in average signal strength
86 * before starting to indicate signal change events.
87 */
88#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
89
Johannes Berg5bb644a2009-05-17 11:40:42 +020090#define TMR_RUNNING_TIMER 0
91#define TMR_RUNNING_CHANSW 1
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 Berg77fdaa12009-07-07 03:45:17 +0200117};
118
Johannes Berg5484e232008-09-08 17:44:27 +0200119/* utils */
Johannes Berg77fdaa12009-07-07 03:45:17 +0200120static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
121{
Johannes Berg46a5eba2010-09-15 13:28:15 +0200122 lockdep_assert_held(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200123}
124
Johannes Bergca386f32009-07-10 02:39:48 +0200125/*
126 * We can have multiple work items (and connection probing)
127 * scheduling this timer, but we need to take care to only
128 * reschedule it when it should fire _earlier_ than it was
129 * asked for before, or if it's not pending right now. This
130 * function ensures that. Note that it then is required to
131 * run this function for all timeouts after the first one
132 * has happened -- the work that runs from this timer will
133 * do that.
134 */
Johannes Berg66e67e42012-01-20 13:55:27 +0100135static void run_again(struct ieee80211_if_managed *ifmgd, unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200136{
137 ASSERT_MGD_MTX(ifmgd);
138
139 if (!timer_pending(&ifmgd->timer) ||
140 time_before(timeout, ifmgd->timer.expires))
141 mod_timer(&ifmgd->timer, timeout);
142}
143
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400144void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200145{
Johannes Bergc1288b12012-01-19 09:29:57 +0100146 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200147 return;
148
Johannes Berg7eeff742012-07-18 10:27:27 +0200149 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
150 return;
151
Johannes Bergb291ba12009-07-10 15:29:03 +0200152 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100153 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200154}
155
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400156void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
157{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400158 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
159
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100160 if (unlikely(!sdata->u.mgd.associated))
161 return;
162
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400163 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
164 return;
165
166 mod_timer(&sdata->u.mgd.conn_mon_timer,
167 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400168
169 ifmgd->probe_send_count = 0;
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400170}
171
Johannes Berg5484e232008-09-08 17:44:27 +0200172static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200173{
Johannes Berg5484e232008-09-08 17:44:27 +0200174 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200175}
176
Johannes Berg24398e32012-03-28 10:58:36 +0200177static u32 ieee80211_config_ht_tx(struct ieee80211_sub_if_data *sdata,
178 struct ieee80211_ht_operation *ht_oper,
179 const u8 *bssid, bool reconfig)
Johannes Bergd5522e02009-03-30 13:23:35 +0200180{
181 struct ieee80211_local *local = sdata->local;
182 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200183 struct ieee80211_chanctx_conf *chanctx_conf;
184 struct ieee80211_channel *chan;
Johannes Bergd5522e02009-03-30 13:23:35 +0200185 struct sta_info *sta;
186 u32 changed = 0;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200187 u16 ht_opmode;
Johannes Berg64f68e52012-03-28 10:58:37 +0200188 bool disable_40 = false;
Johannes Bergd5522e02009-03-30 13:23:35 +0200189
Johannes Berg55de9082012-07-26 17:24:39 +0200190 rcu_read_lock();
191 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
192 if (WARN_ON(!chanctx_conf)) {
193 rcu_read_unlock();
194 return 0;
195 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100196 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200197 rcu_read_unlock();
198 sband = local->hw.wiphy->bands[chan->band];
Johannes Berg0aaffa92010-05-05 15:28:27 +0200199
Johannes Berg4bf88532012-11-09 11:39:59 +0100200 switch (sdata->vif.bss_conf.chandef.width) {
201 case NL80211_CHAN_WIDTH_40:
202 if (sdata->vif.bss_conf.chandef.chan->center_freq >
203 sdata->vif.bss_conf.chandef.center_freq1 &&
Johannes Berg75e69342013-01-11 12:32:37 +0100204 chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
Johannes Berg64f68e52012-03-28 10:58:37 +0200205 disable_40 = true;
Johannes Berg4bf88532012-11-09 11:39:59 +0100206 if (sdata->vif.bss_conf.chandef.chan->center_freq <
207 sdata->vif.bss_conf.chandef.center_freq1 &&
Johannes Berg75e69342013-01-11 12:32:37 +0100208 chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
Johannes Berg64f68e52012-03-28 10:58:37 +0200209 disable_40 = true;
210 break;
211 default:
212 break;
213 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200214
Johannes Berg24398e32012-03-28 10:58:36 +0200215 /* This can change during the lifetime of the BSS */
216 if (!(ht_oper->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY))
Johannes Berg64f68e52012-03-28 10:58:37 +0200217 disable_40 = true;
Johannes Bergd5522e02009-03-30 13:23:35 +0200218
Johannes Berg64f68e52012-03-28 10:58:37 +0200219 mutex_lock(&local->sta_mtx);
220 sta = sta_info_get(sdata, bssid);
221
222 WARN_ON_ONCE(!sta);
223
224 if (sta && !sta->supports_40mhz)
225 disable_40 = true;
226
227 if (sta && (!reconfig ||
Rajkumar Manoharan91a00992012-04-25 20:24:24 +0530228 (disable_40 != !(sta->sta.ht_cap.cap &
Johannes Berg64f68e52012-03-28 10:58:37 +0200229 IEEE80211_HT_CAP_SUP_WIDTH_20_40)))) {
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530230
Johannes Berg64f68e52012-03-28 10:58:37 +0200231 if (disable_40)
232 sta->sta.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
233 else
234 sta->sta.ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530235
Johannes Berg64f68e52012-03-28 10:58:37 +0200236 rate_control_rate_update(local, sband, sta,
Johannes Berg8f727ef2012-03-30 08:43:32 +0200237 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200238 }
Johannes Berg64f68e52012-03-28 10:58:37 +0200239 mutex_unlock(&local->sta_mtx);
Johannes Bergd5522e02009-03-30 13:23:35 +0200240
Johannes Berg074d46d2012-03-15 19:45:16 +0100241 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200242
243 /* if bss configuration changed store the new one */
Johannes Berg24398e32012-03-28 10:58:36 +0200244 if (!reconfig || (sdata->vif.bss_conf.ht_operation_mode != ht_opmode)) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200245 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200246 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Bergd5522e02009-03-30 13:23:35 +0200247 }
248
249 return changed;
250}
251
Johannes Berg9c6bd792008-09-11 00:01:52 +0200252/* frame sending functions */
253
Johannes Berg66e67e42012-01-20 13:55:27 +0100254static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
255 struct ieee80211_supported_band *sband,
256 u32 *rates)
257{
258 int i, j, count;
259 *rates = 0;
260 count = 0;
261 for (i = 0; i < supp_rates_len; i++) {
262 int rate = (supp_rates[i] & 0x7F) * 5;
263
264 for (j = 0; j < sband->n_bitrates; j++)
265 if (sband->bitrates[j].bitrate == rate) {
266 *rates |= BIT(j);
267 count++;
268 break;
269 }
270 }
271
272 return count;
273}
274
275static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200276 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100277 struct ieee80211_supported_band *sband,
278 struct ieee80211_channel *channel,
279 enum ieee80211_smps_mode smps)
280{
Johannes Berg66e67e42012-01-20 13:55:27 +0100281 u8 *pos;
282 u32 flags = channel->flags;
283 u16 cap;
284 struct ieee80211_sta_ht_cap ht_cap;
285
286 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
287
Johannes Berg66e67e42012-01-20 13:55:27 +0100288 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
289 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
290
Johannes Berg66e67e42012-01-20 13:55:27 +0100291 /* determine capability flags */
292 cap = ht_cap.cap;
293
Johannes Berg9dde6422012-05-16 23:43:19 +0200294 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100295 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
296 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
297 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
298 cap &= ~IEEE80211_HT_CAP_SGI_40;
299 }
300 break;
301 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
302 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
303 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
304 cap &= ~IEEE80211_HT_CAP_SGI_40;
305 }
306 break;
307 }
308
Johannes Berg24398e32012-03-28 10:58:36 +0200309 /*
310 * If 40 MHz was disabled associate as though we weren't
311 * capable of 40 MHz -- some broken APs will never fall
312 * back to trying to transmit in 20 MHz.
313 */
314 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
315 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
316 cap &= ~IEEE80211_HT_CAP_SGI_40;
317 }
318
Johannes Berg66e67e42012-01-20 13:55:27 +0100319 /* set SM PS mode properly */
320 cap &= ~IEEE80211_HT_CAP_SM_PS;
321 switch (smps) {
322 case IEEE80211_SMPS_AUTOMATIC:
323 case IEEE80211_SMPS_NUM_MODES:
324 WARN_ON(1);
325 case IEEE80211_SMPS_OFF:
326 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
327 IEEE80211_HT_CAP_SM_PS_SHIFT;
328 break;
329 case IEEE80211_SMPS_STATIC:
330 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
331 IEEE80211_HT_CAP_SM_PS_SHIFT;
332 break;
333 case IEEE80211_SMPS_DYNAMIC:
334 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
335 IEEE80211_HT_CAP_SM_PS_SHIFT;
336 break;
337 }
338
339 /* reserve and fill IE */
340 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
341 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
342}
343
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000344static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
345 struct sk_buff *skb,
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100346 struct ieee80211_supported_band *sband,
347 struct ieee80211_vht_cap *ap_vht_cap)
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000348{
349 u8 *pos;
350 u32 cap;
351 struct ieee80211_sta_vht_cap vht_cap;
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100352 int i;
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000353
354 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
355
356 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
357
358 /* determine capability flags */
359 cap = vht_cap.cap;
360
Johannes Bergf2d9d272012-11-22 14:11:39 +0100361 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
362 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
363 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
364 }
365
366 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
367 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
368 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
369 }
370
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100371 /*
372 * Some APs apparently get confused if our capabilities are better
373 * than theirs, so restrict what we advertise in the assoc request.
374 */
375 if (!(ap_vht_cap->vht_cap_info &
376 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
377 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
378
379 if (!(ap_vht_cap->vht_cap_info &
380 cpu_to_le32(IEEE80211_VHT_CAP_TXSTBC)))
381 cap &= ~(IEEE80211_VHT_CAP_RXSTBC_1 |
382 IEEE80211_VHT_CAP_RXSTBC_3 |
383 IEEE80211_VHT_CAP_RXSTBC_4);
384
385 for (i = 0; i < 8; i++) {
386 int shift = i * 2;
387 u16 mask = IEEE80211_VHT_MCS_NOT_SUPPORTED << shift;
388 u16 ap_mcs, our_mcs;
389
390 ap_mcs = (le16_to_cpu(ap_vht_cap->supp_mcs.tx_mcs_map) &
391 mask) >> shift;
392 our_mcs = (le16_to_cpu(vht_cap.vht_mcs.rx_mcs_map) &
393 mask) >> shift;
394
395 switch (ap_mcs) {
396 default:
397 if (our_mcs <= ap_mcs)
398 break;
399 /* fall through */
400 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
401 vht_cap.vht_mcs.rx_mcs_map &= cpu_to_le16(~mask);
402 vht_cap.vht_mcs.rx_mcs_map |=
403 cpu_to_le16(ap_mcs << shift);
404 }
405 }
406
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000407 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000408 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000409 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
410}
411
Johannes Berg66e67e42012-01-20 13:55:27 +0100412static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
413{
414 struct ieee80211_local *local = sdata->local;
415 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
416 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
417 struct sk_buff *skb;
418 struct ieee80211_mgmt *mgmt;
419 u8 *pos, qos_info;
420 size_t offset = 0, noffset;
421 int i, count, rates_len, supp_rates_len;
422 u16 capab;
423 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200424 struct ieee80211_chanctx_conf *chanctx_conf;
425 struct ieee80211_channel *chan;
Johannes Berg66e67e42012-01-20 13:55:27 +0100426 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100427
428 lockdep_assert_held(&ifmgd->mtx);
429
Johannes Berg55de9082012-07-26 17:24:39 +0200430 rcu_read_lock();
431 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
432 if (WARN_ON(!chanctx_conf)) {
433 rcu_read_unlock();
434 return;
435 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100436 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200437 rcu_read_unlock();
438 sband = local->hw.wiphy->bands[chan->band];
Johannes Berg66e67e42012-01-20 13:55:27 +0100439
440 if (assoc_data->supp_rates_len) {
441 /*
442 * Get all rates supported by the device and the AP as
443 * some APs don't like getting a superset of their rates
444 * in the association request (e.g. D-Link DAP 1353 in
445 * b-only mode)...
446 */
447 rates_len = ieee80211_compatible_rates(assoc_data->supp_rates,
448 assoc_data->supp_rates_len,
449 sband, &rates);
450 } else {
451 /*
452 * In case AP not provide any supported rates information
453 * before association, we send information element(s) with
454 * all rates that we support.
455 */
456 rates = ~0;
457 rates_len = sband->n_bitrates;
458 }
459
460 skb = alloc_skb(local->hw.extra_tx_headroom +
461 sizeof(*mgmt) + /* bit too much but doesn't matter */
462 2 + assoc_data->ssid_len + /* SSID */
463 4 + rates_len + /* (extended) rates */
464 4 + /* power capability */
465 2 + 2 * sband->n_channels + /* supported channels */
466 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000467 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Johannes Berg66e67e42012-01-20 13:55:27 +0100468 assoc_data->ie_len + /* extra IEs */
469 9, /* WMM */
470 GFP_KERNEL);
471 if (!skb)
472 return;
473
474 skb_reserve(skb, local->hw.extra_tx_headroom);
475
476 capab = WLAN_CAPABILITY_ESS;
477
478 if (sband->band == IEEE80211_BAND_2GHZ) {
479 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
480 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
481 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
482 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
483 }
484
485 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
486 capab |= WLAN_CAPABILITY_PRIVACY;
487
488 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
489 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
490 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
491
492 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
493 memset(mgmt, 0, 24);
494 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
495 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
496 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
497
498 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
499 skb_put(skb, 10);
500 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
501 IEEE80211_STYPE_REASSOC_REQ);
502 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
503 mgmt->u.reassoc_req.listen_interval =
504 cpu_to_le16(local->hw.conf.listen_interval);
505 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
506 ETH_ALEN);
507 } else {
508 skb_put(skb, 4);
509 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
510 IEEE80211_STYPE_ASSOC_REQ);
511 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
512 mgmt->u.assoc_req.listen_interval =
513 cpu_to_le16(local->hw.conf.listen_interval);
514 }
515
516 /* SSID */
517 pos = skb_put(skb, 2 + assoc_data->ssid_len);
518 *pos++ = WLAN_EID_SSID;
519 *pos++ = assoc_data->ssid_len;
520 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
521
522 /* add all rates which were marked to be used above */
523 supp_rates_len = rates_len;
524 if (supp_rates_len > 8)
525 supp_rates_len = 8;
526
527 pos = skb_put(skb, supp_rates_len + 2);
528 *pos++ = WLAN_EID_SUPP_RATES;
529 *pos++ = supp_rates_len;
530
531 count = 0;
532 for (i = 0; i < sband->n_bitrates; i++) {
533 if (BIT(i) & rates) {
534 int rate = sband->bitrates[i].bitrate;
535 *pos++ = (u8) (rate / 5);
536 if (++count == 8)
537 break;
538 }
539 }
540
541 if (rates_len > count) {
542 pos = skb_put(skb, rates_len - count + 2);
543 *pos++ = WLAN_EID_EXT_SUPP_RATES;
544 *pos++ = rates_len - count;
545
546 for (i++; i < sband->n_bitrates; i++) {
547 if (BIT(i) & rates) {
548 int rate = sband->bitrates[i].bitrate;
549 *pos++ = (u8) (rate / 5);
550 }
551 }
552 }
553
554 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
555 /* 1. power capabilities */
556 pos = skb_put(skb, 4);
557 *pos++ = WLAN_EID_PWR_CAPABILITY;
558 *pos++ = 2;
559 *pos++ = 0; /* min tx power */
Johannes Berg55de9082012-07-26 17:24:39 +0200560 *pos++ = chan->max_power; /* max tx power */
Johannes Berg66e67e42012-01-20 13:55:27 +0100561
562 /* 2. supported channels */
563 /* TODO: get this in reg domain format */
564 pos = skb_put(skb, 2 * sband->n_channels + 2);
565 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
566 *pos++ = 2 * sband->n_channels;
567 for (i = 0; i < sband->n_channels; i++) {
568 *pos++ = ieee80211_frequency_to_channel(
569 sband->channels[i].center_freq);
570 *pos++ = 1; /* one channel in the subband*/
571 }
572 }
573
574 /* if present, add any custom IEs that go before HT */
575 if (assoc_data->ie_len && assoc_data->ie) {
576 static const u8 before_ht[] = {
577 WLAN_EID_SSID,
578 WLAN_EID_SUPP_RATES,
579 WLAN_EID_EXT_SUPP_RATES,
580 WLAN_EID_PWR_CAPABILITY,
581 WLAN_EID_SUPPORTED_CHANNELS,
582 WLAN_EID_RSN,
583 WLAN_EID_QOS_CAPA,
584 WLAN_EID_RRM_ENABLED_CAPABILITIES,
585 WLAN_EID_MOBILITY_DOMAIN,
586 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
587 };
588 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
589 before_ht, ARRAY_SIZE(before_ht),
590 offset);
591 pos = skb_put(skb, noffset - offset);
592 memcpy(pos, assoc_data->ie + offset, noffset - offset);
593 offset = noffset;
594 }
595
Johannes Bergf2d9d272012-11-22 14:11:39 +0100596 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
597 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
598 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
599
Johannes Berga8243b72012-11-22 14:32:09 +0100600 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200601 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200602 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100603
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000604 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
Johannes Bergb08fbbd2012-12-07 13:06:48 +0100605 ieee80211_add_vht_ie(sdata, skb, sband,
606 &assoc_data->ap_vht_cap);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000607
Johannes Berg66e67e42012-01-20 13:55:27 +0100608 /* if present, add any custom non-vendor IEs that go after HT */
609 if (assoc_data->ie_len && assoc_data->ie) {
610 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
611 assoc_data->ie_len,
612 offset);
613 pos = skb_put(skb, noffset - offset);
614 memcpy(pos, assoc_data->ie + offset, noffset - offset);
615 offset = noffset;
616 }
617
Johannes Berg76f03032012-03-08 15:02:05 +0100618 if (assoc_data->wmm) {
619 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200620 qos_info = ifmgd->uapsd_queues;
621 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100622 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
623 } else {
624 qos_info = 0;
625 }
626
627 pos = skb_put(skb, 9);
628 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
629 *pos++ = 7; /* len */
630 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
631 *pos++ = 0x50;
632 *pos++ = 0xf2;
633 *pos++ = 2; /* WME */
634 *pos++ = 0; /* WME info */
635 *pos++ = 1; /* WME ver */
636 *pos++ = qos_info;
637 }
638
639 /* add any remaining custom (i.e. vendor specific here) IEs */
640 if (assoc_data->ie_len && assoc_data->ie) {
641 noffset = assoc_data->ie_len;
642 pos = skb_put(skb, noffset - offset);
643 memcpy(pos, assoc_data->ie + offset, noffset - offset);
644 }
645
Johannes Berga1845fc2012-06-27 13:18:36 +0200646 drv_mgd_prepare_tx(local, sdata);
647
Johannes Berg66e67e42012-01-20 13:55:27 +0100648 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Johannes Berg1672c0e32013-01-29 15:02:27 +0100649 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
650 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
651 IEEE80211_TX_INTFL_MLME_CONN_TX;
Johannes Berg66e67e42012-01-20 13:55:27 +0100652 ieee80211_tx_skb(sdata, skb);
653}
654
Kalle Valo572e0012009-02-10 17:09:31 +0200655void ieee80211_send_pspoll(struct ieee80211_local *local,
656 struct ieee80211_sub_if_data *sdata)
657{
Kalle Valo572e0012009-02-10 17:09:31 +0200658 struct ieee80211_pspoll *pspoll;
659 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200660
Kalle Valod8cd1892010-01-05 20:16:26 +0200661 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
662 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200663 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200664
Kalle Valod8cd1892010-01-05 20:16:26 +0200665 pspoll = (struct ieee80211_pspoll *) skb->data;
666 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200667
Johannes Berg62ae67b2009-11-18 18:42:05 +0100668 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
669 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200670}
671
Johannes Berg965beda2009-04-16 13:17:24 +0200672void ieee80211_send_nullfunc(struct ieee80211_local *local,
673 struct ieee80211_sub_if_data *sdata,
674 int powersave)
675{
676 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200677 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530678 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200679
Kalle Valod8cd1892010-01-05 20:16:26 +0200680 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
681 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200682 return;
683
Kalle Valod8cd1892010-01-05 20:16:26 +0200684 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200685 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200686 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200687
Seth Forshee6c17b772013-02-11 11:21:07 -0600688 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
689 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530690 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
691 IEEE80211_STA_CONNECTION_POLL))
692 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
693
Johannes Berg62ae67b2009-11-18 18:42:05 +0100694 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200695}
696
Felix Fietkaud5242152010-01-08 18:06:26 +0100697static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
698 struct ieee80211_sub_if_data *sdata)
699{
700 struct sk_buff *skb;
701 struct ieee80211_hdr *nullfunc;
702 __le16 fc;
703
704 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
705 return;
706
707 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -0700708 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +0100709 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700710
Felix Fietkaud5242152010-01-08 18:06:26 +0100711 skb_reserve(skb, local->hw.extra_tx_headroom);
712
713 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
714 memset(nullfunc, 0, 30);
715 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
716 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
717 nullfunc->frame_control = fc;
718 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
719 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
720 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
721 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
722
723 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
724 ieee80211_tx_skb(sdata, skb);
725}
726
Johannes Bergcc32abd2009-05-15 11:52:31 +0200727/* spectrum management related things */
728static void ieee80211_chswitch_work(struct work_struct *work)
729{
730 struct ieee80211_sub_if_data *sdata =
731 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200732 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
733
Johannes Berg9607e6b2009-12-23 13:15:31 +0100734 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200735 return;
736
Johannes Berg77fdaa12009-07-07 03:45:17 +0200737 mutex_lock(&ifmgd->mtx);
738 if (!ifmgd->associated)
739 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200740
Johannes Berg55de9082012-07-26 17:24:39 +0200741 sdata->local->_oper_channel = sdata->local->csa_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200742 if (!sdata->local->ops->channel_switch) {
743 /* call "hw_config" only if doing sw channel switch */
744 ieee80211_hw_config(sdata->local,
745 IEEE80211_CONF_CHANGE_CHANNEL);
Shahar Levi1ea57b12011-09-08 08:44:05 +0300746 } else {
747 /* update the device channel directly */
Johannes Berg55de9082012-07-26 17:24:39 +0200748 sdata->local->hw.conf.channel = sdata->local->_oper_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200749 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200750
Johannes Berg77fdaa12009-07-07 03:45:17 +0200751 /* XXX: shouldn't really modify cfg80211-owned data! */
Johannes Berg55de9082012-07-26 17:24:39 +0200752 ifmgd->associated->channel = sdata->local->_oper_channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200753
Johannes Berg57eebdf2012-08-01 15:50:46 +0200754 /* XXX: wait for a beacon first? */
Johannes Bergcc32abd2009-05-15 11:52:31 +0200755 ieee80211_wake_queues_by_reason(&sdata->local->hw,
756 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200757 out:
758 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
759 mutex_unlock(&ifmgd->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200760}
761
Johannes Berg5ce6e432010-05-11 16:20:57 +0200762void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
763{
Johannes Berg55de9082012-07-26 17:24:39 +0200764 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
765 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200766
767 trace_api_chswitch_done(sdata, success);
768 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +0200769 sdata_info(sdata,
770 "driver channel switch failed, disconnecting\n");
771 ieee80211_queue_work(&sdata->local->hw,
772 &ifmgd->csa_connection_drop_work);
773 } else {
774 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +0200775 }
Johannes Berg5ce6e432010-05-11 16:20:57 +0200776}
777EXPORT_SYMBOL(ieee80211_chswitch_done);
778
Johannes Bergcc32abd2009-05-15 11:52:31 +0200779static void ieee80211_chswitch_timer(unsigned long data)
780{
781 struct ieee80211_sub_if_data *sdata =
782 (struct ieee80211_sub_if_data *) data;
783 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
784
Johannes Berg5bb644a2009-05-17 11:40:42 +0200785 if (sdata->local->quiescing) {
786 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
787 return;
788 }
789
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400790 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200791}
792
793void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
794 struct ieee80211_channel_sw_ie *sw_elem,
Johannes Berg5ce6e432010-05-11 16:20:57 +0200795 struct ieee80211_bss *bss,
796 u64 timestamp)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200797{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100798 struct cfg80211_bss *cbss =
799 container_of((void *)bss, struct cfg80211_bss, priv);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200800 struct ieee80211_channel *new_ch;
801 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900802 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
803 cbss->channel->band);
Johannes Berg55de9082012-07-26 17:24:39 +0200804 struct ieee80211_chanctx *chanctx;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200805
Johannes Berg77fdaa12009-07-07 03:45:17 +0200806 ASSERT_MGD_MTX(ifmgd);
807
808 if (!ifmgd->associated)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200809 return;
810
Helmut Schaafbe9c422009-07-23 12:14:04 +0200811 if (sdata->local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200812 return;
813
814 /* Disregard subsequent beacons if we are already running a timer
815 processing a CSA */
816
817 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
818 return;
819
820 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
Johannes Berg882a7c62012-08-01 22:32:45 +0200821 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) {
822 sdata_info(sdata,
823 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
824 ifmgd->associated->bssid, new_freq);
825 ieee80211_queue_work(&sdata->local->hw,
826 &ifmgd->csa_connection_drop_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200827 return;
Johannes Berg882a7c62012-08-01 22:32:45 +0200828 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200829
Johannes Berg57eebdf2012-08-01 15:50:46 +0200830 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
831
Johannes Berg55de9082012-07-26 17:24:39 +0200832 if (sdata->local->use_chanctx) {
833 sdata_info(sdata,
834 "not handling channel switch with channel contexts\n");
835 ieee80211_queue_work(&sdata->local->hw,
836 &ifmgd->csa_connection_drop_work);
Simon Wunderlich246dc3f2012-11-30 19:17:27 +0100837 return;
Johannes Berg55de9082012-07-26 17:24:39 +0200838 }
839
840 mutex_lock(&sdata->local->chanctx_mtx);
841 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
842 mutex_unlock(&sdata->local->chanctx_mtx);
843 return;
844 }
845 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
846 struct ieee80211_chanctx, conf);
847 if (chanctx->refcount > 1) {
848 sdata_info(sdata,
849 "channel switch with multiple interfaces on the same channel, disconnecting\n");
850 ieee80211_queue_work(&sdata->local->hw,
851 &ifmgd->csa_connection_drop_work);
852 mutex_unlock(&sdata->local->chanctx_mtx);
853 return;
854 }
855 mutex_unlock(&sdata->local->chanctx_mtx);
856
857 sdata->local->csa_channel = new_ch;
858
Johannes Berg57eebdf2012-08-01 15:50:46 +0200859 if (sw_elem->mode)
860 ieee80211_stop_queues_by_reason(&sdata->local->hw,
861 IEEE80211_QUEUE_STOP_REASON_CSA);
862
Johannes Berg5ce6e432010-05-11 16:20:57 +0200863 if (sdata->local->ops->channel_switch) {
864 /* use driver's channel switch callback */
Johannes Berg57eebdf2012-08-01 15:50:46 +0200865 struct ieee80211_channel_switch ch_switch = {
866 .timestamp = timestamp,
867 .block_tx = sw_elem->mode,
868 .channel = new_ch,
869 .count = sw_elem->count,
870 };
871
Johannes Berg5ce6e432010-05-11 16:20:57 +0200872 drv_channel_switch(sdata->local, &ch_switch);
873 return;
874 }
875
876 /* channel switch handled in software */
Johannes Berg57eebdf2012-08-01 15:50:46 +0200877 if (sw_elem->count <= 1)
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400878 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +0200879 else
Johannes Bergcc32abd2009-05-15 11:52:31 +0200880 mod_timer(&ifmgd->chswitch_timer,
Johannes Berg30490002012-08-01 15:53:45 +0200881 TU_TO_EXP_TIME(sw_elem->count *
882 cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +0200883}
884
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200885static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
886 struct ieee80211_channel *channel,
887 const u8 *country_ie, u8 country_ie_len,
888 const u8 *pwr_constr_elem)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200889{
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200890 struct ieee80211_country_ie_triplet *triplet;
891 int chan = ieee80211_frequency_to_channel(channel->center_freq);
892 int i, chan_pwr, chan_increment, new_ap_level;
893 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200894
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200895 /* Invalid IE */
896 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200897 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200898
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200899 triplet = (void *)(country_ie + 3);
900 country_ie_len -= 3;
901
902 switch (channel->band) {
903 default:
904 WARN_ON_ONCE(1);
905 /* fall through */
906 case IEEE80211_BAND_2GHZ:
907 case IEEE80211_BAND_60GHZ:
908 chan_increment = 1;
909 break;
910 case IEEE80211_BAND_5GHZ:
911 chan_increment = 4;
912 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200913 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200914
915 /* find channel */
916 while (country_ie_len >= 3) {
917 u8 first_channel = triplet->chans.first_channel;
918
919 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
920 goto next;
921
922 for (i = 0; i < triplet->chans.num_channels; i++) {
923 if (first_channel + i * chan_increment == chan) {
924 have_chan_pwr = true;
925 chan_pwr = triplet->chans.max_power;
926 break;
927 }
928 }
929 if (have_chan_pwr)
930 break;
931
932 next:
933 triplet++;
934 country_ie_len -= 3;
935 }
936
937 if (!have_chan_pwr)
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200938 return 0;
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200939
940 new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
941
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200942 if (sdata->ap_power_level == new_ap_level)
943 return 0;
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200944
945 sdata_info(sdata,
946 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
947 new_ap_level, chan_pwr, *pwr_constr_elem,
948 sdata->u.mgd.bssid);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200949 sdata->ap_power_level = new_ap_level;
950 if (__ieee80211_recalc_txpower(sdata))
951 return BSS_CHANGED_TXPOWER;
952 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200953}
954
Johannes Berg965beda2009-04-16 13:17:24 +0200955/* powersave */
956static void ieee80211_enable_ps(struct ieee80211_local *local,
957 struct ieee80211_sub_if_data *sdata)
958{
959 struct ieee80211_conf *conf = &local->hw.conf;
960
Johannes Bergd5edaed2009-04-22 23:02:51 +0200961 /*
962 * If we are scanning right now then the parameters will
963 * take effect when scan finishes.
964 */
Helmut Schaafbe9c422009-07-23 12:14:04 +0200965 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +0200966 return;
967
Johannes Berg965beda2009-04-16 13:17:24 +0200968 if (conf->dynamic_ps_timeout > 0 &&
969 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
970 mod_timer(&local->dynamic_ps_timer, jiffies +
971 msecs_to_jiffies(conf->dynamic_ps_timeout));
972 } else {
973 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
974 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +0530975
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200976 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
977 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
978 return;
979
980 conf->flags |= IEEE80211_CONF_PS;
981 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +0200982 }
983}
984
985static void ieee80211_change_ps(struct ieee80211_local *local)
986{
987 struct ieee80211_conf *conf = &local->hw.conf;
988
989 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +0200990 ieee80211_enable_ps(local, local->ps_sdata);
991 } else if (conf->flags & IEEE80211_CONF_PS) {
992 conf->flags &= ~IEEE80211_CONF_PS;
993 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
994 del_timer_sync(&local->dynamic_ps_timer);
995 cancel_work_sync(&local->dynamic_ps_enable_work);
996 }
997}
998
Jason Young808118c2011-03-10 16:43:19 -0800999static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1000{
1001 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1002 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001003 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -08001004
1005 if (!mgd->powersave)
1006 return false;
1007
Johannes Berg05cb9102011-10-28 11:59:47 +02001008 if (mgd->broken_ap)
1009 return false;
1010
Jason Young808118c2011-03-10 16:43:19 -08001011 if (!mgd->associated)
1012 return false;
1013
Jason Young808118c2011-03-10 16:43:19 -08001014 if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
1015 IEEE80211_STA_CONNECTION_POLL))
1016 return false;
1017
1018 rcu_read_lock();
1019 sta = sta_info_get(sdata, mgd->bssid);
1020 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001021 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -08001022 rcu_read_unlock();
1023
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001024 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001025}
1026
Johannes Berg965beda2009-04-16 13:17:24 +02001027/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +02001028void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +02001029{
1030 struct ieee80211_sub_if_data *sdata, *found = NULL;
1031 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001032 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001033
1034 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
1035 local->ps_sdata = NULL;
1036 return;
1037 }
1038
1039 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01001040 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001041 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301042 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1043 /* If an AP vif is found, then disable PS
1044 * by setting the count to zero thereby setting
1045 * ps_sdata to NULL.
1046 */
1047 count = 0;
1048 break;
1049 }
Johannes Berg965beda2009-04-16 13:17:24 +02001050 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1051 continue;
1052 found = sdata;
1053 count++;
1054 }
1055
Jason Young808118c2011-03-10 16:43:19 -08001056 if (count == 1 && ieee80211_powersave_allowed(found)) {
Johannes Berg10f644a2009-04-16 13:17:25 +02001057 s32 beaconint_us;
1058
1059 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +02001060 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +02001061
1062 beaconint_us = ieee80211_tu_to_usec(
1063 found->vif.bss_conf.beacon_int);
1064
Juuso Oikarinenff616382010-06-09 09:51:52 +03001065 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001066 if (timeout < 0) {
1067 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +03001068 * Go to full PSM if the user configures a very low
1069 * latency requirement.
Eliad Peller0ab82b02010-12-03 02:16:23 +02001070 * The 2000 second value is there for compatibility
1071 * until the PM_QOS_NETWORK_LATENCY is configured
1072 * with real values.
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001073 */
Eliad Peller0ab82b02010-12-03 02:16:23 +02001074 if (latency > (1900 * USEC_PER_MSEC) &&
1075 latency != (2000 * USEC_PER_SEC))
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001076 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001077 else
1078 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001079 }
Johannes Berg09b85562013-02-06 23:07:41 +01001080 local->hw.conf.dynamic_ps_timeout = timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001081
Johannes Berg04fe2032009-04-22 18:44:37 +02001082 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +02001083 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +02001084 } else {
Johannes Berg04fe2032009-04-22 18:44:37 +02001085 int maxslp = 1;
Johannes Berg826262c2012-12-10 16:38:14 +02001086 u8 dtimper = found->u.mgd.dtim_period;
Johannes Berg56007a02010-01-26 14:19:52 +01001087
1088 /* If the TIM IE is invalid, pretend the value is 1 */
1089 if (!dtimper)
1090 dtimper = 1;
1091 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +02001092 maxslp = min_t(int, dtimper,
1093 latency / beaconint_us);
1094
Johannes Berg9ccebe62009-04-23 10:32:36 +02001095 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +01001096 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +02001097 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +02001098 }
Johannes Berg10f644a2009-04-16 13:17:25 +02001099 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001100 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001101 }
Johannes Berg965beda2009-04-16 13:17:24 +02001102
1103 ieee80211_change_ps(local);
1104}
1105
Eliad Pellerab095872012-07-27 12:33:22 +03001106void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1107{
1108 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1109
1110 if (sdata->vif.bss_conf.ps != ps_allowed) {
1111 sdata->vif.bss_conf.ps = ps_allowed;
1112 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1113 }
1114}
1115
Johannes Berg965beda2009-04-16 13:17:24 +02001116void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1117{
1118 struct ieee80211_local *local =
1119 container_of(work, struct ieee80211_local,
1120 dynamic_ps_disable_work);
1121
1122 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1123 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1124 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1125 }
1126
1127 ieee80211_wake_queues_by_reason(&local->hw,
1128 IEEE80211_QUEUE_STOP_REASON_PS);
1129}
1130
1131void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1132{
1133 struct ieee80211_local *local =
1134 container_of(work, struct ieee80211_local,
1135 dynamic_ps_enable_work);
1136 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001137 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301138 unsigned long flags;
1139 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001140
1141 /* can only happen when PS was just disabled anyway */
1142 if (!sdata)
1143 return;
1144
Christian Lamparter5e340692011-06-30 21:08:43 +02001145 ifmgd = &sdata->u.mgd;
1146
Johannes Berg965beda2009-04-16 13:17:24 +02001147 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1148 return;
1149
Johannes Berg09b85562013-02-06 23:07:41 +01001150 if (local->hw.conf.dynamic_ps_timeout > 0) {
Arik Nemtsov77b70232011-06-26 12:06:54 +03001151 /* don't enter PS if TX frames are pending */
1152 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301153 mod_timer(&local->dynamic_ps_timer, jiffies +
1154 msecs_to_jiffies(
1155 local->hw.conf.dynamic_ps_timeout));
1156 return;
1157 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001158
1159 /*
1160 * transmission can be stopped by others which leads to
1161 * dynamic_ps_timer expiry. Postpone the ps timer if it
1162 * is not the actual idle state.
1163 */
1164 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1165 for (q = 0; q < local->hw.queues; q++) {
1166 if (local->queue_stop_reasons[q]) {
1167 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1168 flags);
1169 mod_timer(&local->dynamic_ps_timer, jiffies +
1170 msecs_to_jiffies(
1171 local->hw.conf.dynamic_ps_timeout));
1172 return;
1173 }
1174 }
1175 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301176 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301177
Vivek Natarajan375177b2010-02-09 14:50:28 +05301178 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301179 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301180 netif_tx_stop_all_queues(sdata->dev);
Johannes Berg965beda2009-04-16 13:17:24 +02001181
Vivek Natarajane8306f92011-04-06 11:41:10 +05301182 if (drv_tx_frames_pending(local))
1183 mod_timer(&local->dynamic_ps_timer, jiffies +
1184 msecs_to_jiffies(
1185 local->hw.conf.dynamic_ps_timeout));
1186 else {
1187 ieee80211_send_nullfunc(local, sdata, 1);
1188 /* Flush to get the tx status of nullfunc frame */
1189 drv_flush(local, false);
1190 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301191 }
1192
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001193 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
1194 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301195 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1196 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1197 local->hw.conf.flags |= IEEE80211_CONF_PS;
1198 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1199 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301200
Arik Nemtsov77b70232011-06-26 12:06:54 +03001201 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1202 netif_tx_wake_all_queues(sdata->dev);
Johannes Berg965beda2009-04-16 13:17:24 +02001203}
1204
1205void ieee80211_dynamic_ps_timer(unsigned long data)
1206{
1207 struct ieee80211_local *local = (void *) data;
1208
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -07001209 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +02001210 return;
1211
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001212 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001213}
1214
Simon Wunderlich164eb022013-02-08 18:16:20 +01001215void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1216{
1217 struct delayed_work *delayed_work =
1218 container_of(work, struct delayed_work, work);
1219 struct ieee80211_sub_if_data *sdata =
1220 container_of(delayed_work, struct ieee80211_sub_if_data,
1221 dfs_cac_timer_work);
1222
1223 ieee80211_vif_release_channel(sdata);
1224
1225 cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_FINISHED, GFP_KERNEL);
1226}
1227
Johannes Berg60f8b392008-09-08 17:44:22 +02001228/* MLME */
Johannes Berg7d257452012-07-06 17:37:43 +02001229static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +02001230 struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001231 u8 *wmm_param, size_t wmm_param_len)
1232{
Jiri Bencf0706e82007-05-05 11:45:53 -07001233 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +02001234 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001235 size_t left;
1236 int count;
Kalle Valoab133152010-01-12 10:42:31 +02001237 u8 *pos, uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001238
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001239 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001240 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001241
Johannes Berg32c50572012-03-28 11:04:29 +02001242 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001243 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001244
1245 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001246 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001247
Jiri Bencf0706e82007-05-05 11:45:53 -07001248 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001249 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001250
1251 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001252 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001253
Jiri Bencf0706e82007-05-05 11:45:53 -07001254 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +01001255 if (count == ifmgd->wmm_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001256 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001257 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001258
1259 pos = wmm_param + 8;
1260 left = wmm_param_len - 8;
1261
1262 memset(&params, 0, sizeof(params));
1263
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001264 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001265 for (; left >= 4; left -= 4, pos += 4) {
1266 int aci = (pos[0] >> 5) & 0x03;
1267 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001268 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001269 int queue;
1270
1271 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001272 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +02001273 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +02001274 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001275 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001276 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1277 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001278 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001279 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +02001280 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +02001281 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001282 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001283 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1284 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001285 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001286 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +02001287 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +02001288 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001289 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02001290 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1291 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001292 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001293 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001294 default:
Johannes Berge100bb62008-04-30 18:51:21 +02001295 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +02001296 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001297 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02001298 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1299 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001300 break;
1301 }
1302
1303 params.aifs = pos[0] & 0x0f;
1304 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1305 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +02001306 params.txop = get_unaligned_le16(pos + 2);
Kalle Valoab133152010-01-12 10:42:31 +02001307 params.uapsd = uapsd;
1308
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001309 mlme_dbg(sdata,
1310 "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
1311 queue, aci, acm,
1312 params.aifs, params.cw_min, params.cw_max,
1313 params.txop, params.uapsd);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001314 sdata->tx_conf[queue] = params;
1315 if (drv_conf_tx(local, sdata, queue, &params))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001316 sdata_err(sdata,
1317 "failed to set TX queue parameters for queue %d\n",
1318 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -07001319 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001320
1321 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02001322 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02001323 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001324}
1325
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001326static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1327{
1328 lockdep_assert_held(&sdata->local->mtx);
1329
1330 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1331 IEEE80211_STA_BEACON_POLL);
1332 ieee80211_run_deferred_scan(sdata->local);
1333}
1334
1335static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1336{
1337 mutex_lock(&sdata->local->mtx);
1338 __ieee80211_stop_poll(sdata);
1339 mutex_unlock(&sdata->local->mtx);
1340}
1341
Johannes Berg7a5158e2008-10-08 10:59:33 +02001342static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1343 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02001344{
Johannes Bergbda39332008-10-11 01:51:51 +02001345 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001346 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001347 bool use_protection;
1348 bool use_short_preamble;
1349 bool use_short_slot;
1350
1351 if (erp_valid) {
1352 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1353 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1354 } else {
1355 use_protection = false;
1356 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1357 }
1358
1359 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Johannes Berg55de9082012-07-26 17:24:39 +02001360 if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01001361 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02001362
Johannes Berg471b3ef2007-12-28 14:32:58 +01001363 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01001364 bss_conf->use_cts_prot = use_protection;
1365 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02001366 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02001367
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001368 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001369 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001370 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02001371 }
Daniel Draked9430a32007-07-27 15:43:24 +02001372
Johannes Berg7a5158e2008-10-08 10:59:33 +02001373 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02001374 bss_conf->use_short_slot = use_short_slot;
1375 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04001376 }
1377
1378 return changed;
1379}
1380
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001381static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001382 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02001383 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07001384{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001385 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001386 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001387 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001388
Johannes Bergae5eb022008-10-14 16:58:37 +02001389 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001390 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03001391 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001392
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01001393 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
1394 IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
1395
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001396 sdata->u.mgd.associated = cbss;
1397 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01001398
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001399 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1400
Johannes Berg488dd7b2012-10-29 20:08:01 +01001401 if (sdata->vif.p2p) {
Johannes Berg9caf0362012-11-29 01:25:20 +01001402 const struct cfg80211_bss_ies *ies;
Johannes Berg488dd7b2012-10-29 20:08:01 +01001403
Johannes Berg9caf0362012-11-29 01:25:20 +01001404 rcu_read_lock();
1405 ies = rcu_dereference(cbss->ies);
1406 if (ies) {
1407 u8 noa[2];
1408 int ret;
1409
1410 ret = cfg80211_get_p2p_attr(
1411 ies->data, ies->len,
1412 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
1413 noa, sizeof(noa));
1414 if (ret >= 2) {
1415 bss_conf->p2p_oppps = noa[1] & 0x80;
1416 bss_conf->p2p_ctwindow = noa[1] & 0x7f;
1417 bss_info_changed |= BSS_CHANGED_P2P_PS;
1418 sdata->u.mgd.p2p_noa_index = noa[0];
1419 }
Johannes Berg488dd7b2012-10-29 20:08:01 +01001420 }
Johannes Berg9caf0362012-11-29 01:25:20 +01001421 rcu_read_unlock();
Johannes Berg488dd7b2012-10-29 20:08:01 +01001422 }
1423
Johannes Bergb291ba12009-07-10 15:29:03 +02001424 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001425 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001426
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001427 ieee80211_led_assoc(local, 1);
1428
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02001429 if (sdata->u.mgd.assoc_data->have_beacon) {
Johannes Berg826262c2012-12-10 16:38:14 +02001430 /*
1431 * If the AP is buggy we may get here with no DTIM period
1432 * known, so assume it's 1 which is the only safe assumption
1433 * in that case, although if the TIM IE is broken powersave
1434 * probably just won't work at all.
1435 */
1436 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02001437 bss_info_changed |= BSS_CHANGED_DTIM_PERIOD;
Johannes Berg826262c2012-12-10 16:38:14 +02001438 } else {
Johannes Berge5b900d2010-07-29 16:08:55 +02001439 bss_conf->dtim_period = 0;
Johannes Berg826262c2012-12-10 16:38:14 +02001440 }
Johannes Berge5b900d2010-07-29 16:08:55 +02001441
Juuso Oikarinen68542962010-06-09 13:43:26 +03001442 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02001443
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001444 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01001445 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03001446 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001447 bss_info_changed |= BSS_CHANGED_CQM;
1448
Juuso Oikarinen68542962010-06-09 13:43:26 +03001449 /* Enable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01001450 if (bss_conf->arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03001451 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001452
Johannes Bergae5eb022008-10-14 16:58:37 +02001453 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03001454
Johannes Berg056508d2009-07-30 21:43:55 +02001455 mutex_lock(&local->iflist_mtx);
1456 ieee80211_recalc_ps(local, -1);
1457 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02001458
Johannes Berg04ecd252012-09-11 14:34:12 +02001459 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03001460 ieee80211_recalc_ps_vif(sdata);
1461
John W. Linville8a5b33f2010-01-06 15:39:39 -05001462 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001463 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001464}
1465
Jouni Malinene69e95d2010-03-29 23:29:31 -07001466static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01001467 u16 stype, u16 reason, bool tx,
1468 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03001469{
Johannes Berg46900292009-02-15 12:44:28 +01001470 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001471 struct ieee80211_local *local = sdata->local;
Johannes Berg3cc52402012-03-09 13:12:35 +01001472 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001473
Johannes Berg77fdaa12009-07-07 03:45:17 +02001474 ASSERT_MGD_MTX(ifmgd);
1475
Johannes Berg37ad3882012-02-24 13:50:54 +01001476 if (WARN_ON_ONCE(tx && !frame_buf))
1477 return;
1478
Johannes Bergb291ba12009-07-10 15:29:03 +02001479 if (WARN_ON(!ifmgd->associated))
1480 return;
1481
David Spinadel79543d82012-06-12 09:59:45 +03001482 ieee80211_stop_poll(sdata);
1483
Johannes Berg77fdaa12009-07-07 03:45:17 +02001484 ifmgd->associated = NULL;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001485
1486 /*
1487 * we need to commit the associated = NULL change because the
1488 * scan code uses that to determine whether this iface should
1489 * go to/wake up from powersave or not -- and could otherwise
1490 * wake the queues erroneously.
1491 */
1492 smp_mb();
1493
1494 /*
1495 * Thus, we can only afterwards stop the queues -- to account
1496 * for the case where another CPU is finishing a scan at this
1497 * time -- we don't want the scan code to enable queues.
1498 */
Tomas Winkleraa458d12008-09-09 00:32:12 +03001499
John W. Linville8a5b33f2010-01-06 15:39:39 -05001500 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001501 netif_carrier_off(sdata->dev);
1502
Eliad Peller88bc40e2012-07-12 17:35:33 +03001503 /*
1504 * if we want to get out of ps before disassoc (why?) we have
1505 * to do it before sending disassoc, as otherwise the null-packet
1506 * won't be valid.
1507 */
1508 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1509 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1510 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1511 }
1512 local->ps_sdata = NULL;
1513
Eliad Pellerab095872012-07-27 12:33:22 +03001514 /* disable per-vif ps */
1515 ieee80211_recalc_ps_vif(sdata);
1516
Eliad Pellerf8239812012-06-27 14:18:22 +03001517 /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
1518 if (tx)
1519 drv_flush(local, false);
1520
Johannes Berg37ad3882012-02-24 13:50:54 +01001521 /* deauthenticate/disassociate now */
1522 if (tx || frame_buf)
Eliad Peller88a9e312012-06-01 11:14:03 +03001523 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
1524 reason, tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01001525
1526 /* flush out frame */
1527 if (tx)
1528 drv_flush(local, false);
1529
Eliad Peller88a9e312012-06-01 11:14:03 +03001530 /* clear bssid only after building the needed mgmt frames */
1531 memset(ifmgd->bssid, 0, ETH_ALEN);
1532
Johannes Berg37ad3882012-02-24 13:50:54 +01001533 /* remove AP and TDLS peers */
Johannes Berg051007d2012-12-13 23:49:02 +01001534 sta_info_flush_defer(sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01001535
1536 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001537 changed |= ieee80211_reset_erp_info(sdata);
1538
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001539 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001540 changed |= BSS_CHANGED_ASSOC;
1541 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001542
Johannes Berg488dd7b2012-10-29 20:08:01 +01001543 sdata->vif.bss_conf.p2p_ctwindow = 0;
1544 sdata->vif.bss_conf.p2p_oppps = false;
1545
Johannes Berg413ad502009-05-08 21:21:06 +02001546 /* on the next assoc, re-program HT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08001547 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
1548 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Berg413ad502009-05-08 21:21:06 +02001549
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001550 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301551
Kalle Valo520eb822008-12-18 23:35:27 +02001552 del_timer_sync(&local->dynamic_ps_timer);
1553 cancel_work_sync(&local->dynamic_ps_enable_work);
1554
Juuso Oikarinen68542962010-06-09 13:43:26 +03001555 /* Disable ARP filtering */
Johannes Berg0f19b412013-01-14 16:39:07 +01001556 if (sdata->vif.bss_conf.arp_addr_cnt)
Juuso Oikarinen68542962010-06-09 13:43:26 +03001557 changed |= BSS_CHANGED_ARP_FILTER;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001558
Johannes Berg3abead52012-03-02 15:56:59 +01001559 sdata->vif.bss_conf.qos = false;
1560 changed |= BSS_CHANGED_QOS;
1561
Johannes Berg0aaffa92010-05-05 15:28:27 +02001562 /* The BSSID (not really interesting) and HT changed */
1563 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001564 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001565
Johannes Berg3abead52012-03-02 15:56:59 +01001566 /* disassociated - set to defaults now */
1567 ieee80211_set_wmm_default(sdata, false);
1568
Johannes Bergb9dcf712010-08-27 12:35:54 +02001569 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1570 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1571 del_timer_sync(&sdata->u.mgd.timer);
1572 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02001573
1574 sdata->u.mgd.timers_running = 0;
Johannes Berg028e8da02012-11-26 11:57:41 +01001575
Johannes Berg826262c2012-12-10 16:38:14 +02001576 sdata->vif.bss_conf.dtim_period = 0;
1577
Johannes Berg028e8da02012-11-26 11:57:41 +01001578 ifmgd->flags = 0;
1579 ieee80211_vif_release_channel(sdata);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001580}
Jiri Bencf0706e82007-05-05 11:45:53 -07001581
Kalle Valo3cf335d2009-03-22 21:57:06 +02001582void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1583 struct ieee80211_hdr *hdr)
1584{
1585 /*
1586 * We can postpone the mgd.timer whenever receiving unicast frames
1587 * from AP because we know that the connection is working both ways
1588 * at that time. But multicast frames (and hence also beacons) must
1589 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001590 * data idle periods for sending the periodic probe request to the
1591 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001592 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001593 if (is_multicast_ether_addr(hdr->addr1))
1594 return;
1595
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001596 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02001597}
Jiri Bencf0706e82007-05-05 11:45:53 -07001598
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001599static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1600{
1601 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001602 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001603
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001604 mutex_lock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001605 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001606 IEEE80211_STA_CONNECTION_POLL))) {
1607 mutex_unlock(&local->mtx);
1608 return;
1609 }
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001610
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001611 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001612
1613 mutex_lock(&local->iflist_mtx);
1614 ieee80211_recalc_ps(local, -1);
1615 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001616
1617 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001618 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001619
1620 /*
1621 * We've received a probe response, but are not sure whether
1622 * we have or will be receiving any beacons or data, so let's
1623 * schedule the timers again, just in case.
1624 */
1625 ieee80211_sta_reset_beacon_monitor(sdata);
1626
1627 mod_timer(&ifmgd->conn_mon_timer,
1628 round_jiffies_up(jiffies +
1629 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001630out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001631 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001632}
1633
1634void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001635 struct ieee80211_hdr *hdr, bool ack)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001636{
Felix Fietkau75706d02010-12-02 21:01:07 +01001637 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001638 return;
1639
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001640 if (ack)
1641 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001642
1643 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1644 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001645 if (ack)
1646 sdata->u.mgd.probe_send_count = 0;
1647 else
1648 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001649 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1650 }
1651}
1652
Maxim Levitskya43abf22009-07-31 18:54:12 +03001653static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1654{
1655 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1656 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001657 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08001658 u8 unicast_limit = max(1, max_probe_tries - 3);
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001659
1660 /*
1661 * Try sending broadcast probe requests for the last three
1662 * probe requests after the first ones failed since some
1663 * buggy APs only support broadcast probe requests.
1664 */
1665 if (ifmgd->probe_send_count >= unicast_limit)
1666 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03001667
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001668 /*
1669 * When the hardware reports an accurate Tx ACK status, it's
1670 * better to send a nullfunc frame instead of a probe request,
1671 * as it will kick us off the AP quickly if we aren't associated
1672 * anymore. The timeout will be reset if the frame is ACKed by
1673 * the AP.
1674 */
Soumik Das992e68b2012-05-20 15:31:13 +05301675 ifmgd->probe_send_count++;
1676
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001677 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1678 ifmgd->nullfunc_failed = false;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001679 ieee80211_send_nullfunc(sdata->local, sdata, 0);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001680 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02001681 int ssid_len;
1682
Johannes Berg9caf0362012-11-29 01:25:20 +01001683 rcu_read_lock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001684 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02001685 if (WARN_ON_ONCE(ssid == NULL))
1686 ssid_len = 0;
1687 else
1688 ssid_len = ssid[1];
1689
1690 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL,
Johannes Berg1672c0e32013-01-29 15:02:27 +01001691 0, (u32) -1, true, 0,
Johannes Berg55de9082012-07-26 17:24:39 +02001692 ifmgd->associated->channel, false);
Johannes Berg9caf0362012-11-29 01:25:20 +01001693 rcu_read_unlock();
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001694 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03001695
Ben Greear180205b2011-02-04 15:30:24 -08001696 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Maxim Levitskya43abf22009-07-31 18:54:12 +03001697 run_again(ifmgd, ifmgd->probe_timeout);
Rajkumar Manoharanf69b9c72012-03-15 06:15:26 +05301698 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
1699 drv_flush(sdata->local, false);
Maxim Levitskya43abf22009-07-31 18:54:12 +03001700}
1701
Johannes Bergb291ba12009-07-10 15:29:03 +02001702static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1703 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02001704{
Kalle Valo04de8382009-03-22 21:57:35 +02001705 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02001706 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02001707
Johannes Berg9607e6b2009-12-23 13:15:31 +01001708 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02001709 return;
1710
Johannes Berg77fdaa12009-07-07 03:45:17 +02001711 mutex_lock(&ifmgd->mtx);
1712
1713 if (!ifmgd->associated)
1714 goto out;
1715
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001716 mutex_lock(&sdata->local->mtx);
1717
1718 if (sdata->local->tmp_channel || sdata->local->scanning) {
1719 mutex_unlock(&sdata->local->mtx);
1720 goto out;
1721 }
1722
Joe Perchese87cc472012-05-13 21:56:26 +00001723 if (beacon)
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001724 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01001725 "detected beacon loss from AP - probing\n");
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001726
Holger Schurig6efb71b2012-05-15 15:38:59 +02001727 ieee80211_cqm_rssi_notify(&sdata->vif,
1728 NL80211_CQM_RSSI_BEACON_LOSS_EVENT, GFP_KERNEL);
Kalle Valo04de8382009-03-22 21:57:35 +02001729
Johannes Bergb291ba12009-07-10 15:29:03 +02001730 /*
1731 * The driver/our work has already reported this event or the
1732 * connection monitoring has kicked in and we have already sent
1733 * a probe request. Or maybe the AP died and the driver keeps
1734 * reporting until we disassociate...
1735 *
1736 * In either case we have to ignore the current call to this
1737 * function (except for setting the correct probe reason bit)
1738 * because otherwise we would reset the timer every time and
1739 * never check whether we received a probe response!
1740 */
1741 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1742 IEEE80211_STA_CONNECTION_POLL))
1743 already = true;
1744
1745 if (beacon)
1746 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1747 else
1748 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1749
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001750 mutex_unlock(&sdata->local->mtx);
1751
Johannes Bergb291ba12009-07-10 15:29:03 +02001752 if (already)
1753 goto out;
1754
Johannes Berg4e751842009-06-10 15:16:52 +02001755 mutex_lock(&sdata->local->iflist_mtx);
1756 ieee80211_recalc_ps(sdata->local, -1);
1757 mutex_unlock(&sdata->local->iflist_mtx);
1758
Maxim Levitskya43abf22009-07-31 18:54:12 +03001759 ifmgd->probe_send_count = 0;
1760 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001761 out:
1762 mutex_unlock(&ifmgd->mtx);
Kalle Valo04de8382009-03-22 21:57:35 +02001763}
1764
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001765struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
1766 struct ieee80211_vif *vif)
1767{
1768 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1769 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03001770 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001771 struct sk_buff *skb;
1772 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02001773 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001774
1775 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1776 return NULL;
1777
1778 ASSERT_MGD_MTX(ifmgd);
1779
Eliad Pellerd9b3b282012-06-28 15:03:13 +03001780 if (ifmgd->associated)
1781 cbss = ifmgd->associated;
1782 else if (ifmgd->auth_data)
1783 cbss = ifmgd->auth_data->bss;
1784 else if (ifmgd->assoc_data)
1785 cbss = ifmgd->assoc_data->bss;
1786 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001787 return NULL;
1788
Johannes Berg9caf0362012-11-29 01:25:20 +01001789 rcu_read_lock();
Eliad Pellerd9b3b282012-06-28 15:03:13 +03001790 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02001791 if (WARN_ON_ONCE(ssid == NULL))
1792 ssid_len = 0;
1793 else
1794 ssid_len = ssid[1];
1795
Eliad Pellerd9b3b282012-06-28 15:03:13 +03001796 skb = ieee80211_build_probe_req(sdata, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02001797 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02001798 ssid + 2, ssid_len,
Johannes Berg85a237f2011-07-18 18:08:36 +02001799 NULL, 0, true);
Johannes Berg9caf0362012-11-29 01:25:20 +01001800 rcu_read_unlock();
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001801
1802 return skb;
1803}
1804EXPORT_SYMBOL(ieee80211_ap_probereq_get);
1805
Johannes Bergeef9e542013-01-29 13:09:34 +01001806static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001807{
1808 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02001809 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001810
1811 mutex_lock(&ifmgd->mtx);
1812 if (!ifmgd->associated) {
1813 mutex_unlock(&ifmgd->mtx);
1814 return;
1815 }
1816
Johannes Berg37ad3882012-02-24 13:50:54 +01001817 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
1818 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Johannes Bergeef9e542013-01-29 13:09:34 +01001819 true, frame_buf);
Johannes Berg882a7c62012-08-01 22:32:45 +02001820 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001821 mutex_unlock(&ifmgd->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001822
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001823 /*
1824 * must be outside lock due to cfg80211,
1825 * but that's not a problem.
1826 */
Antonio Quartulli6ae16772012-09-07 13:28:52 +02001827 cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001828}
1829
Johannes Bergcc74c0c2012-08-01 16:49:34 +02001830static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02001831{
1832 struct ieee80211_sub_if_data *sdata =
1833 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001834 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08001835 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1836 struct sta_info *sta;
1837
1838 if (ifmgd->associated) {
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05301839 rcu_read_lock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08001840 sta = sta_info_get(sdata, ifmgd->bssid);
1841 if (sta)
1842 sta->beacon_loss_count++;
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05301843 rcu_read_unlock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08001844 }
Johannes Bergb291ba12009-07-10 15:29:03 +02001845
Johannes Berg682bd382013-01-29 13:13:50 +01001846 if (ifmgd->connection_loss) {
Johannes Berg882a7c62012-08-01 22:32:45 +02001847 sdata_info(sdata, "Connection to AP %pM lost\n",
1848 ifmgd->bssid);
Johannes Bergeef9e542013-01-29 13:09:34 +01001849 __ieee80211_disconnect(sdata);
Johannes Berg882a7c62012-08-01 22:32:45 +02001850 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001851 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02001852 }
1853}
1854
1855static void ieee80211_csa_connection_drop_work(struct work_struct *work)
1856{
1857 struct ieee80211_sub_if_data *sdata =
1858 container_of(work, struct ieee80211_sub_if_data,
1859 u.mgd.csa_connection_drop_work);
1860
1861 ieee80211_wake_queues_by_reason(&sdata->local->hw,
1862 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Bergeef9e542013-01-29 13:09:34 +01001863 __ieee80211_disconnect(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001864}
1865
Kalle Valo04de8382009-03-22 21:57:35 +02001866void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1867{
1868 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001869 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02001870
Johannes Bergb5878a22010-04-07 16:48:40 +02001871 trace_api_beacon_loss(sdata);
1872
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001873 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
Johannes Berg682bd382013-01-29 13:13:50 +01001874 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001875 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02001876}
1877EXPORT_SYMBOL(ieee80211_beacon_loss);
1878
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001879void ieee80211_connection_loss(struct ieee80211_vif *vif)
1880{
1881 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1882 struct ieee80211_hw *hw = &sdata->local->hw;
1883
Johannes Bergb5878a22010-04-07 16:48:40 +02001884 trace_api_connection_loss(sdata);
1885
Johannes Berg682bd382013-01-29 13:13:50 +01001886 sdata->u.mgd.connection_loss = true;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001887 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1888}
1889EXPORT_SYMBOL(ieee80211_connection_loss);
1890
1891
Johannes Berg66e67e42012-01-20 13:55:27 +01001892static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
1893 bool assoc)
1894{
1895 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
1896
1897 lockdep_assert_held(&sdata->u.mgd.mtx);
1898
Johannes Berg66e67e42012-01-20 13:55:27 +01001899 if (!assoc) {
1900 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
1901
1902 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
1903 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01001904 sdata->u.mgd.flags = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02001905 ieee80211_vif_release_channel(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01001906 }
1907
Johannes Berg5b112d32013-02-01 01:49:58 +01001908 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01001909 kfree(auth_data);
1910 sdata->u.mgd.auth_data = NULL;
1911}
1912
1913static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1914 struct ieee80211_mgmt *mgmt, size_t len)
1915{
Johannes Berg1672c0e32013-01-29 15:02:27 +01001916 struct ieee80211_local *local = sdata->local;
Johannes Berg66e67e42012-01-20 13:55:27 +01001917 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
1918 u8 *pos;
1919 struct ieee802_11_elems elems;
Johannes Berg1672c0e32013-01-29 15:02:27 +01001920 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01001921
1922 pos = mgmt->u.auth.variable;
1923 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1924 if (!elems.challenge)
1925 return;
1926 auth_data->expected_transaction = 4;
Johannes Berga1845fc2012-06-27 13:18:36 +02001927 drv_mgd_prepare_tx(sdata->local, sdata);
Johannes Berg1672c0e32013-01-29 15:02:27 +01001928 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
1929 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
1930 IEEE80211_TX_INTFL_MLME_CONN_TX;
Jouni Malinen700e8ea2012-09-30 19:29:37 +03001931 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01001932 elems.challenge - 2, elems.challenge_len + 2,
1933 auth_data->bss->bssid, auth_data->bss->bssid,
1934 auth_data->key, auth_data->key_len,
Johannes Berg1672c0e32013-01-29 15:02:27 +01001935 auth_data->key_idx, tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01001936}
1937
1938static enum rx_mgmt_action __must_check
1939ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1940 struct ieee80211_mgmt *mgmt, size_t len)
1941{
1942 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1943 u8 bssid[ETH_ALEN];
1944 u16 auth_alg, auth_transaction, status_code;
1945 struct sta_info *sta;
1946
1947 lockdep_assert_held(&ifmgd->mtx);
1948
1949 if (len < 24 + 6)
1950 return RX_MGMT_NONE;
1951
1952 if (!ifmgd->auth_data || ifmgd->auth_data->done)
1953 return RX_MGMT_NONE;
1954
1955 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
1956
Joe Perchesb203ca32012-05-08 18:56:52 +00001957 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01001958 return RX_MGMT_NONE;
1959
1960 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1961 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1962 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1963
1964 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinen0f4126e2012-09-30 19:29:38 +03001965 auth_transaction != ifmgd->auth_data->expected_transaction) {
1966 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
1967 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
1968 auth_transaction,
1969 ifmgd->auth_data->expected_transaction);
Johannes Berg66e67e42012-01-20 13:55:27 +01001970 return RX_MGMT_NONE;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03001971 }
Johannes Berg66e67e42012-01-20 13:55:27 +01001972
1973 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001974 sdata_info(sdata, "%pM denied authentication (status %d)\n",
1975 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03001976 ieee80211_destroy_auth_data(sdata, false);
1977 return RX_MGMT_CFG80211_RX_AUTH;
Johannes Berg66e67e42012-01-20 13:55:27 +01001978 }
1979
1980 switch (ifmgd->auth_data->algorithm) {
1981 case WLAN_AUTH_OPEN:
1982 case WLAN_AUTH_LEAP:
1983 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03001984 case WLAN_AUTH_SAE:
Johannes Berg66e67e42012-01-20 13:55:27 +01001985 break;
1986 case WLAN_AUTH_SHARED_KEY:
1987 if (ifmgd->auth_data->expected_transaction != 4) {
1988 ieee80211_auth_challenge(sdata, mgmt, len);
1989 /* need another frame */
1990 return RX_MGMT_NONE;
1991 }
1992 break;
1993 default:
1994 WARN_ONCE(1, "invalid auth alg %d",
1995 ifmgd->auth_data->algorithm);
1996 return RX_MGMT_NONE;
1997 }
1998
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001999 sdata_info(sdata, "authenticated\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002000 ifmgd->auth_data->done = true;
2001 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2002 run_again(ifmgd, ifmgd->auth_data->timeout);
2003
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002004 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
2005 ifmgd->auth_data->expected_transaction != 2) {
2006 /*
2007 * Report auth frame to user space for processing since another
2008 * round of Authentication frames is still needed.
2009 */
2010 return RX_MGMT_CFG80211_RX_AUTH;
2011 }
2012
Johannes Berg66e67e42012-01-20 13:55:27 +01002013 /* move station state to auth */
2014 mutex_lock(&sdata->local->sta_mtx);
2015 sta = sta_info_get(sdata, bssid);
2016 if (!sta) {
2017 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2018 goto out_err;
2019 }
2020 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002021 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002022 goto out_err;
2023 }
2024 mutex_unlock(&sdata->local->sta_mtx);
2025
2026 return RX_MGMT_CFG80211_RX_AUTH;
2027 out_err:
2028 mutex_unlock(&sdata->local->sta_mtx);
2029 /* ignore frame -- wait for timeout */
2030 return RX_MGMT_NONE;
2031}
2032
2033
Johannes Berg77fdaa12009-07-07 03:45:17 +02002034static enum rx_mgmt_action __must_check
2035ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg77fdaa12009-07-07 03:45:17 +02002036 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002037{
Johannes Berg46900292009-02-15 12:44:28 +01002038 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002039 const u8 *bssid = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07002040 u16 reason_code;
2041
Johannes Berg66e67e42012-01-20 13:55:27 +01002042 lockdep_assert_held(&ifmgd->mtx);
2043
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002044 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002045 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002046
Johannes Berg66e67e42012-01-20 13:55:27 +01002047 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002048 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002049 return RX_MGMT_NONE;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002050
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002051 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002052
2053 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
2054
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002055 sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n",
2056 bssid, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002057
Johannes Berg37ad3882012-02-24 13:50:54 +01002058 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2059
Johannes Berg77fdaa12009-07-07 03:45:17 +02002060 return RX_MGMT_CFG80211_DEAUTH;
Jiri Bencf0706e82007-05-05 11:45:53 -07002061}
2062
2063
Johannes Berg77fdaa12009-07-07 03:45:17 +02002064static enum rx_mgmt_action __must_check
2065ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2066 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002067{
Johannes Berg46900292009-02-15 12:44:28 +01002068 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002069 u16 reason_code;
2070
Johannes Berg66e67e42012-01-20 13:55:27 +01002071 lockdep_assert_held(&ifmgd->mtx);
2072
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002073 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002074 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002075
Johannes Berg66e67e42012-01-20 13:55:27 +01002076 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002077 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg77fdaa12009-07-07 03:45:17 +02002078 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002079
2080 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2081
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002082 sdata_info(sdata, "disassociated from %pM (Reason: %u)\n",
2083 mgmt->sa, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002084
Johannes Berg37ad3882012-02-24 13:50:54 +01002085 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2086
Johannes Berg77fdaa12009-07-07 03:45:17 +02002087 return RX_MGMT_CFG80211_DISASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -07002088}
2089
Christian Lamparterc74d0842011-10-15 00:14:49 +02002090static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2091 u8 *supp_rates, unsigned int supp_rates_len,
2092 u32 *rates, u32 *basic_rates,
2093 bool *have_higher_than_11mbit,
2094 int *min_rate, int *min_rate_index)
2095{
2096 int i, j;
2097
2098 for (i = 0; i < supp_rates_len; i++) {
2099 int rate = (supp_rates[i] & 0x7f) * 5;
2100 bool is_basic = !!(supp_rates[i] & 0x80);
2101
2102 if (rate > 110)
2103 *have_higher_than_11mbit = true;
2104
2105 /*
2106 * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
2107 * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
2108 *
2109 * Note: Even through the membership selector and the basic
2110 * rate flag share the same bit, they are not exactly
2111 * the same.
2112 */
2113 if (!!(supp_rates[i] & 0x80) &&
2114 (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
2115 continue;
2116
2117 for (j = 0; j < sband->n_bitrates; j++) {
2118 if (sband->bitrates[j].bitrate == rate) {
2119 *rates |= BIT(j);
2120 if (is_basic)
2121 *basic_rates |= BIT(j);
2122 if (rate < *min_rate) {
2123 *min_rate = rate;
2124 *min_rate_index = j;
2125 }
2126 break;
2127 }
2128 }
2129 }
2130}
Jiri Bencf0706e82007-05-05 11:45:53 -07002131
Johannes Berg66e67e42012-01-20 13:55:27 +01002132static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2133 bool assoc)
2134{
2135 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2136
2137 lockdep_assert_held(&sdata->u.mgd.mtx);
2138
Johannes Berg66e67e42012-01-20 13:55:27 +01002139 if (!assoc) {
2140 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2141
2142 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2143 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002144 sdata->u.mgd.flags = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002145 ieee80211_vif_release_channel(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002146 }
2147
2148 kfree(assoc_data);
2149 sdata->u.mgd.assoc_data = NULL;
2150}
2151
2152static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2153 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002154 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002155{
Johannes Berg46900292009-02-15 12:44:28 +01002156 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002157 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01002158 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07002159 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002160 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002161 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002162 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02002163 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Bergae5eb022008-10-14 16:58:37 +02002164 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02002165 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -07002166
Johannes Bergaf6b6372009-12-23 13:15:35 +01002167 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07002168
Jiri Bencf0706e82007-05-05 11:45:53 -07002169 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002170 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07002171
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002172 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002173 sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
2174 aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002175 aid &= ~(BIT(15) | BIT(14));
2176
Johannes Berg05cb9102011-10-28 11:59:47 +02002177 ifmgd->broken_ap = false;
2178
2179 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002180 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
2181 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02002182 aid = 0;
2183 ifmgd->broken_ap = true;
2184 }
2185
Johannes Bergaf6b6372009-12-23 13:15:35 +01002186 pos = mgmt->u.assoc_resp.variable;
2187 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2188
Jiri Bencf0706e82007-05-05 11:45:53 -07002189 if (!elems.supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002190 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01002191 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002192 }
2193
Johannes Berg46900292009-02-15 12:44:28 +01002194 ifmgd->aid = aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002195
Guy Eilam2a33bee2011-08-17 15:18:15 +03002196 mutex_lock(&sdata->local->sta_mtx);
2197 /*
2198 * station info was already allocated and inserted before
2199 * the association and should be available to us
2200 */
Johannes Berg7852e362012-01-20 13:55:24 +01002201 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03002202 if (WARN_ON(!sta)) {
2203 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002204 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002205 }
2206
Johannes Berg55de9082012-07-26 17:24:39 +02002207 sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
Johannes Berg8318d782008-01-24 19:38:38 +01002208
Johannes Berga8243b72012-11-22 14:32:09 +01002209 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08002210 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02002211 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02002212
Johannes Berg64f68e52012-03-28 10:58:37 +02002213 sta->supports_40mhz =
2214 sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2215
Mahesh Palivela818255e2012-10-10 11:33:04 +00002216 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2217 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
2218 elems.vht_cap_elem,
2219 &sta->sta.vht_cap);
2220
Johannes Berg4b7679a2008-09-18 18:14:18 +02002221 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07002222
Johannes Berg46900292009-02-15 12:44:28 +01002223 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002224 set_sta_flag(sta, WLAN_STA_MFP);
Jouni Malinen5394af42009-01-08 13:31:59 +02002225
Johannes Bergddf4ac52008-10-22 11:41:38 +02002226 if (elems.wmm_param)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002227 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002228
Johannes Berg3e4d40f2013-02-07 17:19:08 +01002229 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergc8987872012-01-20 13:55:17 +01002230 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
2231 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
2232 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002233 sdata_info(sdata,
2234 "failed to move station %pM to desired state\n",
2235 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01002236 WARN_ON(__sta_info_destroy(sta));
2237 mutex_unlock(&sdata->local->sta_mtx);
2238 return false;
2239 }
2240
Johannes Berg7852e362012-01-20 13:55:24 +01002241 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002242
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03002243 /*
2244 * Always handle WMM once after association regardless
2245 * of the first value the AP uses. Setting -1 here has
2246 * that effect because the AP values is an unsigned
2247 * 4-bit value.
2248 */
2249 ifmgd->wmm_last_param_set = -1;
2250
Johannes Bergddf4ac52008-10-22 11:41:38 +02002251 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02002252 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07002253 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02002254 else
Johannes Berg3abead52012-03-02 15:56:59 +01002255 ieee80211_set_wmm_default(sdata, false);
2256 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07002257
Johannes Berg074d46d2012-03-15 19:45:16 +01002258 if (elems.ht_operation && elems.wmm_param &&
Johannes Berga8243b72012-11-22 14:32:09 +01002259 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg24398e32012-03-28 10:58:36 +02002260 changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation,
2261 cbss->bssid, false);
Johannes Bergae5eb022008-10-14 16:58:37 +02002262
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002263 /* set AID and assoc capability,
2264 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01002265 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002266 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002267 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07002268
Kalle Valo15b7b062009-03-22 21:57:14 +02002269 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01002270 * If we're using 4-addr mode, let the AP know that we're
2271 * doing so, so that it can create the STA VLAN on its side
2272 */
2273 if (ifmgd->use_4addr)
2274 ieee80211_send_4addr_nullfunc(local, sdata);
2275
2276 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02002277 * Start timer to probe the connection to the AP now.
2278 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02002279 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002280 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04002281 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02002282
Johannes Bergaf6b6372009-12-23 13:15:35 +01002283 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07002284}
2285
Johannes Berg66e67e42012-01-20 13:55:27 +01002286static enum rx_mgmt_action __must_check
2287ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2288 struct ieee80211_mgmt *mgmt, size_t len,
2289 struct cfg80211_bss **bss)
2290{
2291 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2292 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
2293 u16 capab_info, status_code, aid;
2294 struct ieee802_11_elems elems;
2295 u8 *pos;
2296 bool reassoc;
Jiri Bencf0706e82007-05-05 11:45:53 -07002297
Johannes Berg66e67e42012-01-20 13:55:27 +01002298 lockdep_assert_held(&ifmgd->mtx);
2299
2300 if (!assoc_data)
2301 return RX_MGMT_NONE;
Joe Perchesb203ca32012-05-08 18:56:52 +00002302 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002303 return RX_MGMT_NONE;
2304
2305 /*
2306 * AssocResp and ReassocResp have identical structure, so process both
2307 * of them in this function.
2308 */
2309
2310 if (len < 24 + 6)
2311 return RX_MGMT_NONE;
2312
2313 reassoc = ieee80211_is_reassoc_req(mgmt->frame_control);
2314 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2315 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2316 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2317
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002318 sdata_info(sdata,
2319 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
2320 reassoc ? "Rea" : "A", mgmt->sa,
2321 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01002322
2323 pos = mgmt->u.assoc_resp.variable;
2324 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2325
2326 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
2327 elems.timeout_int && elems.timeout_int_len == 5 &&
2328 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
2329 u32 tu, ms;
2330 tu = get_unaligned_le32(elems.timeout_int + 1);
2331 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002332 sdata_info(sdata,
2333 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
2334 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01002335 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
2336 if (ms > IEEE80211_ASSOC_TIMEOUT)
2337 run_again(ifmgd, assoc_data->timeout);
2338 return RX_MGMT_NONE;
2339 }
2340
2341 *bss = assoc_data->bss;
2342
2343 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002344 sdata_info(sdata, "%pM denied association (code=%d)\n",
2345 mgmt->sa, status_code);
Johannes Berg66e67e42012-01-20 13:55:27 +01002346 ieee80211_destroy_assoc_data(sdata, false);
2347 } else {
Johannes Berg66e67e42012-01-20 13:55:27 +01002348 if (!ieee80211_assoc_success(sdata, *bss, mgmt, len)) {
2349 /* oops -- internal error -- send timeout for now */
Eliad Peller10a91092012-07-02 14:42:03 +03002350 ieee80211_destroy_assoc_data(sdata, false);
Johannes Berg5b112d32013-02-01 01:49:58 +01002351 cfg80211_put_bss(sdata->local->hw.wiphy, *bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01002352 return RX_MGMT_CFG80211_ASSOC_TIMEOUT;
2353 }
John W. Linville635d9992012-07-09 16:34:34 -04002354 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01002355
2356 /*
2357 * destroy assoc_data afterwards, as otherwise an idle
2358 * recalc after assoc_data is NULL but before associated
2359 * is set can cause the interface to go idle
2360 */
2361 ieee80211_destroy_assoc_data(sdata, true);
Johannes Berg66e67e42012-01-20 13:55:27 +01002362 }
2363
2364 return RX_MGMT_CFG80211_RX_ASSOC;
2365}
Johannes Berg8e3c1b72012-12-10 13:44:19 +01002366
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002367static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Johannes Berg8e3c1b72012-12-10 13:44:19 +01002368 struct ieee80211_mgmt *mgmt, size_t len,
Jiri Bencf0706e82007-05-05 11:45:53 -07002369 struct ieee80211_rx_status *rx_status,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002370 struct ieee802_11_elems *elems)
Jiri Bencf0706e82007-05-05 11:45:53 -07002371{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002372 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002373 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02002374 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002375 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01002376 bool need_ps = false;
2377
Johannes Berg826262c2012-12-10 16:38:14 +02002378 if ((sdata->u.mgd.associated &&
2379 ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) ||
2380 (sdata->u.mgd.assoc_data &&
2381 ether_addr_equal(mgmt->bssid,
2382 sdata->u.mgd.assoc_data->bss->bssid))) {
Johannes Berg56007a02010-01-26 14:19:52 +01002383 /* not previously set so we may need to recalc */
Johannes Berg826262c2012-12-10 16:38:14 +02002384 need_ps = sdata->u.mgd.associated && !sdata->u.mgd.dtim_period;
2385
2386 if (elems->tim && !elems->parse_error) {
2387 struct ieee80211_tim_ie *tim_ie = elems->tim;
2388 sdata->u.mgd.dtim_period = tim_ie->dtim_period;
2389 }
Johannes Berg56007a02010-01-26 14:19:52 +01002390 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002391
Johannes Berg5bda6172008-09-08 11:05:10 +02002392 if (elems->ds_params && elems->ds_params_len == 1)
Bruno Randolf59eb21a2011-01-17 13:37:28 +09002393 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
2394 rx_status->band);
Johannes Berg5bda6172008-09-08 11:05:10 +02002395 else
2396 freq = rx_status->freq;
2397
2398 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2399
2400 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2401 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002402
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002403 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002404 channel);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002405 if (bss)
2406 ieee80211_rx_bss_put(local, bss);
2407
2408 if (!sdata->u.mgd.associated)
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002409 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002410
Johannes Berg56007a02010-01-26 14:19:52 +01002411 if (need_ps) {
2412 mutex_lock(&local->iflist_mtx);
2413 ieee80211_recalc_ps(local, -1);
2414 mutex_unlock(&local->iflist_mtx);
2415 }
2416
Johannes Berg5bc14202012-08-01 16:13:02 +02002417 if (elems->ch_switch_ie &&
2418 memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0)
2419 ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie,
Johannes Berg5ce6e432010-05-11 16:20:57 +02002420 bss, rx_status->mactime);
Jiri Bencf0706e82007-05-05 11:45:53 -07002421}
2422
2423
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002424static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002425 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07002426{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002427 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02002428 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002429 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
2430 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002431 struct ieee802_11_elems elems;
2432
Kalle Valo15b7b062009-03-22 21:57:14 +02002433 ifmgd = &sdata->u.mgd;
2434
Johannes Berg77fdaa12009-07-07 03:45:17 +02002435 ASSERT_MGD_MTX(ifmgd);
2436
Joe Perchesb203ca32012-05-08 18:56:52 +00002437 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03002438 return; /* ignore ProbeResp to foreign address */
2439
Ester Kummerae6a44e2008-06-27 18:54:48 +03002440 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
2441 if (baselen > len)
2442 return;
2443
2444 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
2445 &elems);
2446
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002447 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03002448
Johannes Berg77fdaa12009-07-07 03:45:17 +02002449 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002450 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002451 ieee80211_reset_ap_probe(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002452
2453 if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002454 ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002455 /* got probe response, continue with auth */
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002456 sdata_info(sdata, "direct probe responded\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002457 ifmgd->auth_data->tries = 0;
2458 ifmgd->auth_data->timeout = jiffies;
2459 run_again(ifmgd, ifmgd->auth_data->timeout);
2460 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002461}
2462
Johannes Bergd91f36d2009-04-16 13:17:26 +02002463/*
2464 * This is the canonical list of information elements we care about,
2465 * the filter code also gives us all changes to the Microsoft OUI
2466 * (00:50:F2) vendor IE which is used for WMM which we need to track.
2467 *
2468 * We implement beacon filtering in software since that means we can
2469 * avoid processing the frame here and in cfg80211, and userspace
2470 * will not be able to tell whether the hardware supports it or not.
2471 *
2472 * XXX: This list needs to be dynamic -- userspace needs to be able to
2473 * add items it requires. It also needs to be able to tell us to
2474 * look out for other vendor IEs.
2475 */
2476static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02002477 (1ULL << WLAN_EID_COUNTRY) |
2478 (1ULL << WLAN_EID_ERP_INFO) |
2479 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
2480 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
2481 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg074d46d2012-03-15 19:45:16 +01002482 (1ULL << WLAN_EID_HT_OPERATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02002483
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002484static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07002485 struct ieee80211_mgmt *mgmt,
2486 size_t len,
2487 struct ieee80211_rx_status *rx_status)
2488{
Johannes Bergd91f36d2009-04-16 13:17:26 +02002489 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002490 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07002491 size_t baselen;
2492 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002493 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +02002494 struct ieee80211_chanctx_conf *chanctx_conf;
2495 struct ieee80211_channel *chan;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002496 u32 changed = 0;
Rami Rosenf87ad632012-10-25 10:16:23 +02002497 bool erp_valid;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002498 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02002499 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002500 u8 *bssid;
2501
Johannes Berg66e67e42012-01-20 13:55:27 +01002502 lockdep_assert_held(&ifmgd->mtx);
Jiri Bencf0706e82007-05-05 11:45:53 -07002503
Ester Kummerae6a44e2008-06-27 18:54:48 +03002504 /* Process beacon from the current BSS */
2505 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2506 if (baselen > len)
2507 return;
2508
Johannes Berg55de9082012-07-26 17:24:39 +02002509 rcu_read_lock();
2510 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2511 if (!chanctx_conf) {
2512 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002513 return;
Johannes Berg55de9082012-07-26 17:24:39 +02002514 }
2515
Johannes Berg4bf88532012-11-09 11:39:59 +01002516 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
Johannes Berg55de9082012-07-26 17:24:39 +02002517 rcu_read_unlock();
2518 return;
2519 }
Johannes Berg4bf88532012-11-09 11:39:59 +01002520 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +02002521 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002522
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002523 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002524 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002525 ieee802_11_parse_elems(mgmt->u.beacon.variable,
2526 len - baselen, &elems);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002527
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002528 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg66e67e42012-01-20 13:55:27 +01002529 ifmgd->assoc_data->have_beacon = true;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002530 ifmgd->assoc_data->need_beacon = false;
Johannes Bergef429da2013-02-05 17:48:40 +01002531 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
2532 sdata->vif.bss_conf.sync_tsf =
2533 le64_to_cpu(mgmt->u.beacon.timestamp);
2534 sdata->vif.bss_conf.sync_device_ts =
2535 rx_status->device_timestamp;
2536 if (elems.tim)
2537 sdata->vif.bss_conf.sync_dtim_count =
2538 elems.tim->dtim_count;
2539 else
2540 sdata->vif.bss_conf.sync_dtim_count = 0;
2541 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002542 /* continue assoc process */
2543 ifmgd->assoc_data->timeout = jiffies;
2544 run_again(ifmgd, ifmgd->assoc_data->timeout);
2545 return;
2546 }
2547
2548 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002549 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002550 return;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002551 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002552
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002553 /* Track average RSSI from the Beacon frames of the current AP */
2554 ifmgd->last_beacon_signal = rx_status->signal;
2555 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
2556 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03002557 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002558 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03002559 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002560 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002561 } else {
2562 ifmgd->ave_beacon_signal =
2563 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
2564 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
2565 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03002566 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002567 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002568
2569 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
2570 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
2571 int sig = ifmgd->ave_beacon_signal;
2572 int last_sig = ifmgd->last_ave_beacon_signal;
2573
2574 /*
2575 * if signal crosses either of the boundaries, invoke callback
2576 * with appropriate parameters
2577 */
2578 if (sig > ifmgd->rssi_max_thold &&
2579 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
2580 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbach887da912013-01-20 17:32:41 +02002581 drv_rssi_callback(local, sdata, RSSI_EVENT_HIGH);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002582 } else if (sig < ifmgd->rssi_min_thold &&
2583 (last_sig >= ifmgd->rssi_max_thold ||
2584 last_sig == 0)) {
2585 ifmgd->last_ave_beacon_signal = sig;
Emmanuel Grumbach887da912013-01-20 17:32:41 +02002586 drv_rssi_callback(local, sdata, RSSI_EVENT_LOW);
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002587 }
2588 }
2589
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002590 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03002591 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01002592 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002593 int sig = ifmgd->ave_beacon_signal / 16;
2594 int last_event = ifmgd->last_cqm_event_signal;
2595 int thold = bss_conf->cqm_rssi_thold;
2596 int hyst = bss_conf->cqm_rssi_hyst;
2597 if (sig < thold &&
2598 (last_event == 0 || sig < last_event - hyst)) {
2599 ifmgd->last_cqm_event_signal = sig;
2600 ieee80211_cqm_rssi_notify(
2601 &sdata->vif,
2602 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
2603 GFP_KERNEL);
2604 } else if (sig > thold &&
2605 (last_event == 0 || sig > last_event + hyst)) {
2606 ifmgd->last_cqm_event_signal = sig;
2607 ieee80211_cqm_rssi_notify(
2608 &sdata->vif,
2609 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
2610 GFP_KERNEL);
2611 }
2612 }
2613
Johannes Bergb291ba12009-07-10 15:29:03 +02002614 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002615 mlme_dbg_ratelimited(sdata,
Johannes Berg112c31f2013-02-08 22:59:00 +01002616 "cancelling AP probe due to a received beacon\n");
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002617 mutex_lock(&local->mtx);
Johannes Bergb291ba12009-07-10 15:29:03 +02002618 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002619 ieee80211_run_deferred_scan(local);
2620 mutex_unlock(&local->mtx);
2621
Johannes Berg4e751842009-06-10 15:16:52 +02002622 mutex_lock(&local->iflist_mtx);
2623 ieee80211_recalc_ps(local, -1);
2624 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03002625 }
2626
Johannes Bergb291ba12009-07-10 15:29:03 +02002627 /*
2628 * Push the beacon loss detection into the future since
2629 * we are processing a beacon from the AP just now.
2630 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04002631 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002632
Johannes Bergd91f36d2009-04-16 13:17:26 +02002633 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
2634 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
2635 len - baselen, &elems,
2636 care_about_ies, ncrc);
2637
Vivek Natarajan25c9c872009-03-02 20:20:30 +05302638 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Rami Rosenf87ad632012-10-25 10:16:23 +02002639 bool directed_tim = ieee80211_check_tim(elems.tim,
2640 elems.tim_len,
2641 ifmgd->aid);
Kalle Valo1fb36062009-02-10 17:09:24 +02002642 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02002643 if (local->hw.conf.dynamic_ps_timeout > 0) {
Ronald Wahl70b12f22012-03-19 14:37:20 +01002644 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2645 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2646 ieee80211_hw_config(local,
2647 IEEE80211_CONF_CHANGE_PS);
2648 }
Kalle Valo572e0012009-02-10 17:09:31 +02002649 ieee80211_send_nullfunc(local, sdata, 0);
Rajkumar Manoharan6f0756a2012-03-15 05:50:36 +05302650 } else if (!local->pspolling && sdata->u.mgd.powersave) {
Kalle Valo572e0012009-02-10 17:09:31 +02002651 local->pspolling = true;
2652
2653 /*
2654 * Here is assumed that the driver will be
2655 * able to send ps-poll frame and receive a
2656 * response even though power save mode is
2657 * enabled, but some drivers might require
2658 * to disable power save here. This needs
2659 * to be investigated.
2660 */
2661 ieee80211_send_pspoll(local, sdata);
2662 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08002663 }
2664 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02002665
Johannes Berg488dd7b2012-10-29 20:08:01 +01002666 if (sdata->vif.p2p) {
2667 u8 noa[2];
2668 int ret;
2669
2670 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
2671 len - baselen,
2672 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2673 noa, sizeof(noa));
2674 if (ret >= 2 && sdata->u.mgd.p2p_noa_index != noa[0]) {
2675 bss_conf->p2p_oppps = noa[1] & 0x80;
2676 bss_conf->p2p_ctwindow = noa[1] & 0x7f;
2677 changed |= BSS_CHANGED_P2P_PS;
2678 sdata->u.mgd.p2p_noa_index = noa[0];
2679 /*
2680 * make sure we update all information, the CRC
2681 * mechanism doesn't look at P2P attributes.
2682 */
2683 ifmgd->beacon_crc_valid = false;
2684 }
2685 }
2686
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002687 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Jouni Malinen30196672009-05-19 17:01:43 +03002688 return;
2689 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002690 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03002691
Emmanuel Grumbachd45c4172012-12-10 16:19:13 +02002692 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
Johannes Berg7d257452012-07-06 17:37:43 +02002693
2694 if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
2695 elems.wmm_param_len))
2696 changed |= BSS_CHANGED_QOS;
2697
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002698 /*
2699 * If we haven't had a beacon before, tell the driver about the
Johannes Bergef429da2013-02-05 17:48:40 +01002700 * DTIM period (and beacon timing if desired) now.
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002701 */
2702 if (!bss_conf->dtim_period) {
2703 /* a few bogus AP send dtim_period = 0 or no TIM IE */
2704 if (elems.tim)
2705 bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
2706 else
2707 bss_conf->dtim_period = 1;
Johannes Bergef429da2013-02-05 17:48:40 +01002708
2709 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
2710 sdata->vif.bss_conf.sync_tsf =
2711 le64_to_cpu(mgmt->u.beacon.timestamp);
2712 sdata->vif.bss_conf.sync_device_ts =
2713 rx_status->device_timestamp;
2714 if (elems.tim)
2715 sdata->vif.bss_conf.sync_dtim_count =
2716 elems.tim->dtim_count;
2717 else
2718 sdata->vif.bss_conf.sync_dtim_count = 0;
2719 }
2720
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02002721 changed |= BSS_CHANGED_DTIM_PERIOD;
2722 }
2723
Johannes Berg7a5158e2008-10-08 10:59:33 +02002724 if (elems.erp_info && elems.erp_info_len >= 1) {
2725 erp_valid = true;
2726 erp_value = elems.erp_info[0];
2727 } else {
2728 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04002729 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02002730 changed |= ieee80211_handle_bss_capability(sdata,
2731 le16_to_cpu(mgmt->u.beacon.capab_info),
2732 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07002733
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002734
Johannes Berg074d46d2012-03-15 19:45:16 +01002735 if (elems.ht_cap_elem && elems.ht_operation && elems.wmm_param &&
Johannes Berga8243b72012-11-22 14:32:09 +01002736 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg24398e32012-03-28 10:58:36 +02002737 changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation,
2738 bssid, true);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002739
Johannes Berg04b7b2f2012-09-05 13:41:37 +02002740 if (elems.country_elem && elems.pwr_constr_elem &&
2741 mgmt->u.probe_resp.capab_info &
2742 cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002743 changed |= ieee80211_handle_pwr_constr(sdata, chan,
2744 elems.country_elem,
2745 elems.country_elem_len,
2746 elems.pwr_constr_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002747
Johannes Berg471b3ef2007-12-28 14:32:58 +01002748 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07002749}
2750
Johannes Berg1fa57d02010-06-10 10:21:32 +02002751void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
2752 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07002753{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002754 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002755 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07002756 struct ieee80211_mgmt *mgmt;
Johannes Berg66e67e42012-01-20 13:55:27 +01002757 struct cfg80211_bss *bss = NULL;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002758 enum rx_mgmt_action rma = RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002759 u16 fc;
2760
Jiri Bencf0706e82007-05-05 11:45:53 -07002761 rx_status = (struct ieee80211_rx_status *) skb->cb;
2762 mgmt = (struct ieee80211_mgmt *) skb->data;
2763 fc = le16_to_cpu(mgmt->frame_control);
2764
Johannes Berg77fdaa12009-07-07 03:45:17 +02002765 mutex_lock(&ifmgd->mtx);
2766
Johannes Berg66e67e42012-01-20 13:55:27 +01002767 switch (fc & IEEE80211_FCTL_STYPE) {
2768 case IEEE80211_STYPE_BEACON:
2769 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
2770 break;
2771 case IEEE80211_STYPE_PROBE_RESP:
2772 ieee80211_rx_mgmt_probe_resp(sdata, skb);
2773 break;
2774 case IEEE80211_STYPE_AUTH:
2775 rma = ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
2776 break;
2777 case IEEE80211_STYPE_DEAUTH:
2778 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
2779 break;
2780 case IEEE80211_STYPE_DISASSOC:
2781 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
2782 break;
2783 case IEEE80211_STYPE_ASSOC_RESP:
2784 case IEEE80211_STYPE_REASSOC_RESP:
2785 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss);
2786 break;
2787 case IEEE80211_STYPE_ACTION:
2788 switch (mgmt->u.action.category) {
2789 case WLAN_CATEGORY_SPECTRUM_MGMT:
2790 ieee80211_sta_process_chanswitch(sdata,
2791 &mgmt->u.action.u.chan_switch.sw_elem,
2792 (void *)ifmgd->associated->priv,
2793 rx_status->mactime);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002794 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002795 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002796 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002797 mutex_unlock(&ifmgd->mtx);
2798
Johannes Berg66e67e42012-01-20 13:55:27 +01002799 switch (rma) {
2800 case RX_MGMT_NONE:
2801 /* no action */
2802 break;
2803 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470612009-10-13 13:28:13 +02002804 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01002805 break;
2806 case RX_MGMT_CFG80211_DISASSOC:
2807 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
2808 break;
2809 case RX_MGMT_CFG80211_RX_AUTH:
2810 cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, skb->len);
2811 break;
2812 case RX_MGMT_CFG80211_RX_ASSOC:
2813 cfg80211_send_rx_assoc(sdata->dev, bss, (u8 *)mgmt, skb->len);
2814 break;
2815 case RX_MGMT_CFG80211_ASSOC_TIMEOUT:
2816 cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid);
2817 break;
2818 default:
2819 WARN(1, "unexpected: %d", rma);
Johannes Bergb054b742010-06-07 21:50:07 +02002820 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002821}
2822
Johannes Berg9c6bd792008-09-11 00:01:52 +02002823static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07002824{
2825 struct ieee80211_sub_if_data *sdata =
2826 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01002827 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002828 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07002829
Johannes Berg5bb644a2009-05-17 11:40:42 +02002830 if (local->quiescing) {
2831 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2832 return;
2833 }
2834
Johannes Berg64592c82010-06-10 10:21:31 +02002835 ieee80211_queue_work(&local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07002836}
2837
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002838static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg6b684db2013-01-29 11:35:29 +01002839 u8 *bssid, u8 reason, bool tx)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002840{
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002841 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002842 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002843
Johannes Berg37ad3882012-02-24 13:50:54 +01002844 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
Johannes Berg6b684db2013-01-29 11:35:29 +01002845 tx, frame_buf);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002846 mutex_unlock(&ifmgd->mtx);
Johannes Berg37ad3882012-02-24 13:50:54 +01002847
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002848 /*
2849 * must be outside lock due to cfg80211,
2850 * but that's not a problem.
2851 */
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002852 cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN);
Felix Fietkaufcac4fb2011-11-16 13:34:55 +01002853
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002854 mutex_lock(&ifmgd->mtx);
2855}
2856
Johannes Berg66e67e42012-01-20 13:55:27 +01002857static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
2858{
2859 struct ieee80211_local *local = sdata->local;
2860 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2861 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
Johannes Berg1672c0e32013-01-29 15:02:27 +01002862 u32 tx_flags = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01002863
2864 lockdep_assert_held(&ifmgd->mtx);
2865
2866 if (WARN_ON_ONCE(!auth_data))
2867 return -EINVAL;
2868
Johannes Berg1672c0e32013-01-29 15:02:27 +01002869 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
2870 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2871 IEEE80211_TX_INTFL_MLME_CONN_TX;
2872
Johannes Berg66e67e42012-01-20 13:55:27 +01002873 auth_data->tries++;
2874
2875 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002876 sdata_info(sdata, "authentication with %pM timed out\n",
2877 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002878
2879 /*
2880 * Most likely AP is not in the range so remove the
2881 * bss struct for that AP.
2882 */
2883 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
2884
2885 return -ETIMEDOUT;
2886 }
2887
Johannes Berga1845fc2012-06-27 13:18:36 +02002888 drv_mgd_prepare_tx(local, sdata);
2889
Johannes Berg66e67e42012-01-20 13:55:27 +01002890 if (auth_data->bss->proberesp_ies) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002891 u16 trans = 1;
2892 u16 status = 0;
2893
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002894 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
2895 auth_data->bss->bssid, auth_data->tries,
2896 IEEE80211_AUTH_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01002897
2898 auth_data->expected_transaction = 2;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002899
2900 if (auth_data->algorithm == WLAN_AUTH_SAE) {
2901 trans = auth_data->sae_trans;
2902 status = auth_data->sae_status;
2903 auth_data->expected_transaction = trans;
2904 }
2905
2906 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
2907 auth_data->data, auth_data->data_len,
Johannes Berg66e67e42012-01-20 13:55:27 +01002908 auth_data->bss->bssid,
Johannes Berg1672c0e32013-01-29 15:02:27 +01002909 auth_data->bss->bssid, NULL, 0, 0,
2910 tx_flags);
Johannes Berg66e67e42012-01-20 13:55:27 +01002911 } else {
2912 const u8 *ssidie;
2913
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002914 sdata_info(sdata, "direct probe to %pM (try %d/%i)\n",
2915 auth_data->bss->bssid, auth_data->tries,
2916 IEEE80211_AUTH_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01002917
Johannes Berg9caf0362012-11-29 01:25:20 +01002918 rcu_read_lock();
Johannes Berg66e67e42012-01-20 13:55:27 +01002919 ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
Johannes Berg9caf0362012-11-29 01:25:20 +01002920 if (!ssidie) {
2921 rcu_read_unlock();
Johannes Berg66e67e42012-01-20 13:55:27 +01002922 return -EINVAL;
Johannes Berg9caf0362012-11-29 01:25:20 +01002923 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002924 /*
2925 * Direct probe is sent to broadcast address as some APs
2926 * will not answer to direct packet in unassociated state.
2927 */
2928 ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
Johannes Berg1672c0e32013-01-29 15:02:27 +01002929 NULL, 0, (u32) -1, true, tx_flags,
Johannes Berg55de9082012-07-26 17:24:39 +02002930 auth_data->bss->channel, false);
Johannes Berg9caf0362012-11-29 01:25:20 +01002931 rcu_read_unlock();
Johannes Berg66e67e42012-01-20 13:55:27 +01002932 }
2933
Johannes Berg1672c0e32013-01-29 15:02:27 +01002934 if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
2935 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
2936 run_again(ifmgd, auth_data->timeout);
2937 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002938
2939 return 0;
2940}
2941
2942static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
2943{
2944 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2945 struct ieee80211_local *local = sdata->local;
2946
2947 lockdep_assert_held(&sdata->u.mgd.mtx);
2948
Johannes Berg66e67e42012-01-20 13:55:27 +01002949 assoc_data->tries++;
2950 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002951 sdata_info(sdata, "association with %pM timed out\n",
2952 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002953
2954 /*
2955 * Most likely AP is not in the range so remove the
2956 * bss struct for that AP.
2957 */
2958 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
2959
2960 return -ETIMEDOUT;
2961 }
2962
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002963 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
2964 assoc_data->bss->bssid, assoc_data->tries,
2965 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01002966 ieee80211_send_assoc(sdata);
2967
Johannes Berg1672c0e32013-01-29 15:02:27 +01002968 if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
2969 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
2970 run_again(&sdata->u.mgd, assoc_data->timeout);
2971 }
Johannes Berg66e67e42012-01-20 13:55:27 +01002972
2973 return 0;
2974}
2975
Johannes Berg1672c0e32013-01-29 15:02:27 +01002976void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
2977 __le16 fc, bool acked)
2978{
2979 struct ieee80211_local *local = sdata->local;
2980
2981 sdata->u.mgd.status_fc = fc;
2982 sdata->u.mgd.status_acked = acked;
2983 sdata->u.mgd.status_received = true;
2984
2985 ieee80211_queue_work(&local->hw, &sdata->work);
2986}
2987
Johannes Berg1fa57d02010-06-10 10:21:32 +02002988void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02002989{
Johannes Berg60f8b392008-09-08 17:44:22 +02002990 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02002991 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002992
Johannes Berg77fdaa12009-07-07 03:45:17 +02002993 mutex_lock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002994
Johannes Berg1672c0e32013-01-29 15:02:27 +01002995 if (ifmgd->status_received) {
2996 __le16 fc = ifmgd->status_fc;
2997 bool status_acked = ifmgd->status_acked;
2998
2999 ifmgd->status_received = false;
3000 if (ifmgd->auth_data &&
3001 (ieee80211_is_probe_req(fc) || ieee80211_is_auth(fc))) {
3002 if (status_acked) {
3003 ifmgd->auth_data->timeout =
3004 jiffies + IEEE80211_AUTH_TIMEOUT_SHORT;
3005 run_again(ifmgd, ifmgd->auth_data->timeout);
3006 } else {
3007 ifmgd->auth_data->timeout = jiffies - 1;
3008 }
3009 } else if (ifmgd->assoc_data &&
3010 (ieee80211_is_assoc_req(fc) ||
3011 ieee80211_is_reassoc_req(fc))) {
3012 if (status_acked) {
3013 ifmgd->assoc_data->timeout =
3014 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
3015 run_again(ifmgd, ifmgd->assoc_data->timeout);
3016 } else {
3017 ifmgd->assoc_data->timeout = jiffies - 1;
3018 }
3019 }
3020 }
3021
Johannes Berg66e67e42012-01-20 13:55:27 +01003022 if (ifmgd->auth_data &&
3023 time_after(jiffies, ifmgd->auth_data->timeout)) {
3024 if (ifmgd->auth_data->done) {
3025 /*
3026 * ok ... we waited for assoc but userspace didn't,
3027 * so let's just kill the auth data
3028 */
3029 ieee80211_destroy_auth_data(sdata, false);
3030 } else if (ieee80211_probe_auth(sdata)) {
3031 u8 bssid[ETH_ALEN];
3032
3033 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
3034
3035 ieee80211_destroy_auth_data(sdata, false);
3036
3037 mutex_unlock(&ifmgd->mtx);
3038 cfg80211_send_auth_timeout(sdata->dev, bssid);
3039 mutex_lock(&ifmgd->mtx);
3040 }
3041 } else if (ifmgd->auth_data)
3042 run_again(ifmgd, ifmgd->auth_data->timeout);
3043
3044 if (ifmgd->assoc_data &&
3045 time_after(jiffies, ifmgd->assoc_data->timeout)) {
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003046 if ((ifmgd->assoc_data->need_beacon &&
3047 !ifmgd->assoc_data->have_beacon) ||
Johannes Berg66e67e42012-01-20 13:55:27 +01003048 ieee80211_do_assoc(sdata)) {
3049 u8 bssid[ETH_ALEN];
3050
3051 memcpy(bssid, ifmgd->assoc_data->bss->bssid, ETH_ALEN);
3052
3053 ieee80211_destroy_assoc_data(sdata, false);
3054
3055 mutex_unlock(&ifmgd->mtx);
3056 cfg80211_send_assoc_timeout(sdata->dev, bssid);
3057 mutex_lock(&ifmgd->mtx);
3058 }
3059 } else if (ifmgd->assoc_data)
3060 run_again(ifmgd, ifmgd->assoc_data->timeout);
3061
Johannes Bergb291ba12009-07-10 15:29:03 +02003062 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
3063 IEEE80211_STA_CONNECTION_POLL) &&
3064 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03003065 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003066 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03003067
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003068 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003069
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003070 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Ben Greear180205b2011-02-04 15:30:24 -08003071 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003072 else
Ben Greear180205b2011-02-04 15:30:24 -08003073 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01003074
Felix Fietkau4e5ff372010-11-23 03:10:31 +01003075 /* ACK received for nullfunc probing frame */
3076 if (!ifmgd->probe_send_count)
3077 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003078 else if (ifmgd->nullfunc_failed) {
3079 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003080 mlme_dbg(sdata,
3081 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
3082 bssid, ifmgd->probe_send_count,
3083 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003084 ieee80211_mgd_probe_ap_send(sdata);
3085 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003086 mlme_dbg(sdata,
3087 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
3088 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02003089 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003090 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3091 false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003092 }
3093 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Bergb291ba12009-07-10 15:29:03 +02003094 run_again(ifmgd, ifmgd->probe_timeout);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003095 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003096 mlme_dbg(sdata,
3097 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
3098 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02003099 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003100 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003101 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003102 mlme_dbg(sdata,
3103 "No probe response from AP %pM after %dms, try %d/%i\n",
3104 bssid, probe_wait_ms,
3105 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03003106 ieee80211_mgd_probe_ap_send(sdata);
3107 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02003108 /*
3109 * We actually lost the connection ... or did we?
3110 * Let's make sure!
3111 */
Ben Greearb38afa82010-10-07 16:12:06 -07003112 wiphy_debug(local->hw.wiphy,
3113 "%s: No probe response from AP %pM"
3114 " after %dms, disconnecting.\n",
3115 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08003116 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01003117
Johannes Berg95acac62011-07-12 12:30:59 +02003118 ieee80211_sta_connection_lost(sdata, bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003119 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
Johannes Bergb291ba12009-07-10 15:29:03 +02003120 }
3121 }
3122
Johannes Berg77fdaa12009-07-07 03:45:17 +02003123 mutex_unlock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02003124}
Johannes Berg0a51b272008-09-08 17:44:25 +02003125
Johannes Bergb291ba12009-07-10 15:29:03 +02003126static void ieee80211_sta_bcn_mon_timer(unsigned long data)
3127{
3128 struct ieee80211_sub_if_data *sdata =
3129 (struct ieee80211_sub_if_data *) data;
3130 struct ieee80211_local *local = sdata->local;
3131
3132 if (local->quiescing)
3133 return;
3134
Johannes Berg682bd382013-01-29 13:13:50 +01003135 sdata->u.mgd.connection_loss = false;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003136 ieee80211_queue_work(&sdata->local->hw,
3137 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003138}
3139
3140static void ieee80211_sta_conn_mon_timer(unsigned long data)
3141{
3142 struct ieee80211_sub_if_data *sdata =
3143 (struct ieee80211_sub_if_data *) data;
3144 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3145 struct ieee80211_local *local = sdata->local;
3146
3147 if (local->quiescing)
3148 return;
3149
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04003150 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003151}
3152
3153static void ieee80211_sta_monitor_work(struct work_struct *work)
3154{
3155 struct ieee80211_sub_if_data *sdata =
3156 container_of(work, struct ieee80211_sub_if_data,
3157 u.mgd.monitor_work);
3158
3159 ieee80211_mgd_probe_ap(sdata, false);
3160}
3161
Johannes Berga1678f82008-09-11 00:01:47 +02003162static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3163{
Eliad Peller494f1fe2012-02-19 15:26:09 +02003164 u32 flags;
3165
Kalle Vaload935682009-04-19 08:47:19 +03003166 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003167 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03003168
Johannes Bergb291ba12009-07-10 15:29:03 +02003169 /* let's probe the connection once */
Eliad Peller494f1fe2012-02-19 15:26:09 +02003170 flags = sdata->local->hw.flags;
3171 if (!(flags & IEEE80211_HW_CONNECTION_MONITOR))
3172 ieee80211_queue_work(&sdata->local->hw,
3173 &sdata->u.mgd.monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003174 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02003175 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03003176 }
Johannes Berga1678f82008-09-11 00:01:47 +02003177}
3178
Johannes Berg5bb644a2009-05-17 11:40:42 +02003179#ifdef CONFIG_PM
3180void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
3181{
3182 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3183
3184 /*
3185 * we need to use atomic bitops for the running bits
3186 * only because both timers might fire at the same
3187 * time -- the code here is properly synchronised.
3188 */
3189
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02003190 cancel_work_sync(&ifmgd->request_smps_work);
3191
Johannes Berg0ecfe8062011-11-09 12:14:16 +01003192 cancel_work_sync(&ifmgd->monitor_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003193 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02003194 cancel_work_sync(&ifmgd->csa_connection_drop_work);
Johannes Berg5bb644a2009-05-17 11:40:42 +02003195 if (del_timer_sync(&ifmgd->timer))
3196 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
3197
3198 cancel_work_sync(&ifmgd->chswitch_work);
3199 if (del_timer_sync(&ifmgd->chswitch_timer))
3200 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
Johannes Bergb291ba12009-07-10 15:29:03 +02003201
Johannes Bergb291ba12009-07-10 15:29:03 +02003202 /* these will just be re-established on connection */
3203 del_timer_sync(&ifmgd->conn_mon_timer);
3204 del_timer_sync(&ifmgd->bcn_mon_timer);
Johannes Berg5bb644a2009-05-17 11:40:42 +02003205}
3206
3207void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
3208{
3209 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3210
Johannes Berg782d2672013-01-18 21:21:31 +01003211 mutex_lock(&ifmgd->mtx);
3212 if (!ifmgd->associated) {
3213 mutex_unlock(&ifmgd->mtx);
Rajkumar Manoharan676b58c2011-07-07 23:33:39 +05303214 return;
Johannes Berg782d2672013-01-18 21:21:31 +01003215 }
Rajkumar Manoharan676b58c2011-07-07 23:33:39 +05303216
Johannes Berg95acac62011-07-12 12:30:59 +02003217 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
3218 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
Johannes Berg782d2672013-01-18 21:21:31 +01003219 mlme_dbg(sdata, "driver requested disconnect after resume\n");
3220 ieee80211_sta_connection_lost(sdata,
3221 ifmgd->associated->bssid,
Johannes Berg6b684db2013-01-29 11:35:29 +01003222 WLAN_REASON_UNSPECIFIED,
3223 true);
Johannes Berg95acac62011-07-12 12:30:59 +02003224 mutex_unlock(&ifmgd->mtx);
Johannes Berg782d2672013-01-18 21:21:31 +01003225 return;
Johannes Berg95acac62011-07-12 12:30:59 +02003226 }
Johannes Berg782d2672013-01-18 21:21:31 +01003227 mutex_unlock(&ifmgd->mtx);
Johannes Berg95acac62011-07-12 12:30:59 +02003228
Johannes Berg5bb644a2009-05-17 11:40:42 +02003229 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
3230 add_timer(&ifmgd->timer);
3231 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
3232 add_timer(&ifmgd->chswitch_timer);
Felix Fietkauc8a79722010-11-19 22:55:37 +01003233 ieee80211_sta_reset_beacon_monitor(sdata);
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003234
3235 mutex_lock(&sdata->local->mtx);
Felix Fietkau46090972010-11-23 20:28:03 +01003236 ieee80211_restart_sta_timer(sdata);
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003237 mutex_unlock(&sdata->local->mtx);
Johannes Berg5bb644a2009-05-17 11:40:42 +02003238}
3239#endif
3240
Johannes Berg9c6bd792008-09-11 00:01:52 +02003241/* interface setup */
3242void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
3243{
Johannes Berg46900292009-02-15 12:44:28 +01003244 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003245
Johannes Berg46900292009-02-15 12:44:28 +01003246 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02003247 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01003248 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003249 INIT_WORK(&ifmgd->beacon_connection_loss_work,
3250 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02003251 INIT_WORK(&ifmgd->csa_connection_drop_work,
3252 ieee80211_csa_connection_drop_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02003253 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01003254 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02003255 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003256 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
3257 (unsigned long) sdata);
3258 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
3259 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01003260 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05303261 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02003262
Johannes Bergab1faea2009-07-01 21:41:17 +02003263 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05303264 ifmgd->powersave = sdata->wdev.ps;
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02003265 ifmgd->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
3266 ifmgd->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
Johannes Bergbbbdff92009-04-16 13:27:42 +02003267
Johannes Berg77fdaa12009-07-07 03:45:17 +02003268 mutex_init(&ifmgd->mtx);
Johannes Berg0f782312009-12-01 13:37:02 +01003269
3270 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
3271 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
3272 else
3273 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003274}
3275
3276/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02003277void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
3278{
Johannes Berg31ee67a2012-07-06 21:18:24 +02003279 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02003280
3281 /* Restart STA timers */
3282 rcu_read_lock();
3283 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3284 ieee80211_restart_sta_timer(sdata);
3285 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02003286}
Johannes Berg10f644a2009-04-16 13:17:25 +02003287
3288int ieee80211_max_network_latency(struct notifier_block *nb,
3289 unsigned long data, void *dummy)
3290{
3291 s32 latency_usec = (s32) data;
3292 struct ieee80211_local *local =
3293 container_of(nb, struct ieee80211_local,
3294 network_latency_notifier);
3295
3296 mutex_lock(&local->iflist_mtx);
3297 ieee80211_recalc_ps(local, latency_usec);
3298 mutex_unlock(&local->iflist_mtx);
3299
3300 return 0;
3301}
Johannes Berg77fdaa12009-07-07 03:45:17 +02003302
Johannes Bergf2d9d272012-11-22 14:11:39 +01003303static u32 chandef_downgrade(struct cfg80211_chan_def *c)
3304{
3305 u32 ret;
3306 int tmp;
3307
3308 switch (c->width) {
3309 case NL80211_CHAN_WIDTH_20:
3310 c->width = NL80211_CHAN_WIDTH_20_NOHT;
3311 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
3312 break;
3313 case NL80211_CHAN_WIDTH_40:
3314 c->width = NL80211_CHAN_WIDTH_20;
3315 c->center_freq1 = c->chan->center_freq;
3316 ret = IEEE80211_STA_DISABLE_40MHZ |
3317 IEEE80211_STA_DISABLE_VHT;
3318 break;
3319 case NL80211_CHAN_WIDTH_80:
3320 tmp = (30 + c->chan->center_freq - c->center_freq1)/20;
3321 /* n_P40 */
3322 tmp /= 2;
3323 /* freq_P40 */
3324 c->center_freq1 = c->center_freq1 - 20 + 40 * tmp;
3325 c->width = NL80211_CHAN_WIDTH_40;
3326 ret = IEEE80211_STA_DISABLE_VHT;
3327 break;
3328 case NL80211_CHAN_WIDTH_80P80:
3329 c->center_freq2 = 0;
3330 c->width = NL80211_CHAN_WIDTH_80;
3331 ret = IEEE80211_STA_DISABLE_80P80MHZ |
3332 IEEE80211_STA_DISABLE_160MHZ;
3333 break;
3334 case NL80211_CHAN_WIDTH_160:
3335 /* n_P20 */
3336 tmp = (70 + c->chan->center_freq - c->center_freq1)/20;
3337 /* n_P80 */
3338 tmp /= 4;
3339 c->center_freq1 = c->center_freq1 - 40 + 80 * tmp;
3340 c->width = NL80211_CHAN_WIDTH_80;
3341 ret = IEEE80211_STA_DISABLE_80P80MHZ |
3342 IEEE80211_STA_DISABLE_160MHZ;
3343 break;
3344 default:
3345 case NL80211_CHAN_WIDTH_20_NOHT:
3346 WARN_ON_ONCE(1);
3347 c->width = NL80211_CHAN_WIDTH_20_NOHT;
3348 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
3349 break;
3350 }
3351
3352 WARN_ON_ONCE(!cfg80211_chandef_valid(c));
3353
3354 return ret;
3355}
3356
3357static u32
3358ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
3359 struct ieee80211_supported_band *sband,
3360 struct ieee80211_channel *channel,
3361 const struct ieee80211_ht_operation *ht_oper,
3362 const struct ieee80211_vht_operation *vht_oper,
3363 struct cfg80211_chan_def *chandef)
3364{
3365 struct cfg80211_chan_def vht_chandef;
3366 u32 ht_cfreq, ret;
3367
3368 chandef->chan = channel;
3369 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
3370 chandef->center_freq1 = channel->center_freq;
3371 chandef->center_freq2 = 0;
3372
3373 if (!ht_oper || !sband->ht_cap.ht_supported) {
3374 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
3375 goto out;
3376 }
3377
3378 chandef->width = NL80211_CHAN_WIDTH_20;
3379
3380 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
3381 channel->band);
3382 /* check that channel matches the right operating channel */
3383 if (channel->center_freq != ht_cfreq) {
3384 /*
3385 * It's possible that some APs are confused here;
3386 * Netgear WNDR3700 sometimes reports 4 higher than
3387 * the actual channel in association responses, but
3388 * since we look at probe response/beacon data here
3389 * it should be OK.
3390 */
3391 sdata_info(sdata,
3392 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
3393 channel->center_freq, ht_cfreq,
3394 ht_oper->primary_chan, channel->band);
3395 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
3396 goto out;
3397 }
3398
3399 /* check 40 MHz support, if we have it */
3400 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
3401 switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
3402 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
3403 chandef->width = NL80211_CHAN_WIDTH_40;
3404 chandef->center_freq1 += 10;
3405 break;
3406 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
3407 chandef->width = NL80211_CHAN_WIDTH_40;
3408 chandef->center_freq1 -= 10;
3409 break;
3410 }
3411 } else {
3412 /* 40 MHz (and 80 MHz) must be supported for VHT */
3413 ret = IEEE80211_STA_DISABLE_VHT;
3414 goto out;
3415 }
3416
3417 if (!vht_oper || !sband->vht_cap.vht_supported) {
3418 ret = IEEE80211_STA_DISABLE_VHT;
3419 goto out;
3420 }
3421
3422 vht_chandef.chan = channel;
3423 vht_chandef.center_freq1 =
3424 ieee80211_channel_to_frequency(vht_oper->center_freq_seg1_idx,
3425 channel->band);
3426 vht_chandef.center_freq2 = 0;
3427
3428 if (vht_oper->center_freq_seg2_idx)
3429 vht_chandef.center_freq2 =
3430 ieee80211_channel_to_frequency(
3431 vht_oper->center_freq_seg2_idx,
3432 channel->band);
3433
3434 switch (vht_oper->chan_width) {
3435 case IEEE80211_VHT_CHANWIDTH_USE_HT:
3436 vht_chandef.width = chandef->width;
3437 break;
3438 case IEEE80211_VHT_CHANWIDTH_80MHZ:
3439 vht_chandef.width = NL80211_CHAN_WIDTH_80;
3440 break;
3441 case IEEE80211_VHT_CHANWIDTH_160MHZ:
3442 vht_chandef.width = NL80211_CHAN_WIDTH_160;
3443 break;
3444 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
3445 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
3446 break;
3447 default:
3448 sdata_info(sdata,
3449 "AP VHT operation IE has invalid channel width (%d), disable VHT\n",
3450 vht_oper->chan_width);
3451 ret = IEEE80211_STA_DISABLE_VHT;
3452 goto out;
3453 }
3454
3455 if (!cfg80211_chandef_valid(&vht_chandef)) {
3456 sdata_info(sdata,
3457 "AP VHT information is invalid, disable VHT\n");
3458 ret = IEEE80211_STA_DISABLE_VHT;
3459 goto out;
3460 }
3461
3462 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
3463 ret = 0;
3464 goto out;
3465 }
3466
3467 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
3468 sdata_info(sdata,
3469 "AP VHT information doesn't match HT, disable VHT\n");
3470 ret = IEEE80211_STA_DISABLE_VHT;
3471 goto out;
3472 }
3473
3474 *chandef = vht_chandef;
3475
3476 ret = 0;
3477
3478 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
3479 IEEE80211_CHAN_DISABLED)) {
3480 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
3481 ret = IEEE80211_STA_DISABLE_HT |
3482 IEEE80211_STA_DISABLE_VHT;
3483 goto out;
3484 }
3485
3486 ret = chandef_downgrade(chandef);
3487 }
3488
3489 if (chandef->width != vht_chandef.width)
3490 sdata_info(sdata,
3491 "local regulatory prevented using AP HT/VHT configuration, downgraded\n");
3492
3493out:
3494 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
3495 return ret;
3496}
3497
3498static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
3499 struct cfg80211_bss *cbss)
3500{
3501 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3502 const u8 *ht_cap_ie, *vht_cap_ie;
3503 const struct ieee80211_ht_cap *ht_cap;
3504 const struct ieee80211_vht_cap *vht_cap;
3505 u8 chains = 1;
3506
3507 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
3508 return chains;
3509
Johannes Berg9caf0362012-11-29 01:25:20 +01003510 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003511 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
3512 ht_cap = (void *)(ht_cap_ie + 2);
3513 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
3514 /*
3515 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
3516 * "Tx Unequal Modulation Supported" fields.
3517 */
3518 }
3519
3520 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
3521 return chains;
3522
Johannes Berg9caf0362012-11-29 01:25:20 +01003523 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003524 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
3525 u8 nss;
3526 u16 tx_mcs_map;
3527
3528 vht_cap = (void *)(vht_cap_ie + 2);
3529 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
3530 for (nss = 8; nss > 0; nss--) {
3531 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
3532 IEEE80211_VHT_MCS_NOT_SUPPORTED)
3533 break;
3534 }
3535 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
3536 chains = max(chains, nss);
3537 }
3538
3539 return chains;
3540}
3541
Johannes Bergb17166a2012-07-27 11:41:27 +02003542static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
3543 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01003544{
3545 struct ieee80211_local *local = sdata->local;
3546 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg24398e32012-03-28 10:58:36 +02003547 const struct ieee80211_ht_operation *ht_oper = NULL;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003548 const struct ieee80211_vht_operation *vht_oper = NULL;
Johannes Berg24398e32012-03-28 10:58:36 +02003549 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01003550 struct cfg80211_chan_def chandef;
Johannes Bergf2d9d272012-11-22 14:11:39 +01003551 int ret;
Johannes Berga1cf7752012-03-08 15:02:07 +01003552
Johannes Berg24398e32012-03-28 10:58:36 +02003553 sband = local->hw.wiphy->bands[cbss->channel->band];
3554
Johannes Bergf2d9d272012-11-22 14:11:39 +01003555 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
3556 IEEE80211_STA_DISABLE_80P80MHZ |
3557 IEEE80211_STA_DISABLE_160MHZ);
Johannes Berg24398e32012-03-28 10:58:36 +02003558
Johannes Berg9caf0362012-11-29 01:25:20 +01003559 rcu_read_lock();
3560
Johannes Bergf2d9d272012-11-22 14:11:39 +01003561 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3562 sband->ht_cap.ht_supported) {
3563 const u8 *ht_oper_ie;
3564
Johannes Berg9caf0362012-11-29 01:25:20 +01003565 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
Johannes Berg24398e32012-03-28 10:58:36 +02003566 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
3567 ht_oper = (void *)(ht_oper_ie + 2);
3568 }
3569
Johannes Bergf2d9d272012-11-22 14:11:39 +01003570 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3571 sband->vht_cap.vht_supported) {
3572 const u8 *vht_oper_ie;
3573
Johannes Berg9caf0362012-11-29 01:25:20 +01003574 vht_oper_ie = ieee80211_bss_get_ie(cbss,
3575 WLAN_EID_VHT_OPERATION);
Johannes Bergf2d9d272012-11-22 14:11:39 +01003576 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
3577 vht_oper = (void *)(vht_oper_ie + 2);
3578 if (vht_oper && !ht_oper) {
3579 vht_oper = NULL;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003580 sdata_info(sdata,
Johannes Bergf2d9d272012-11-22 14:11:39 +01003581 "AP advertised VHT without HT, disabling both\n");
3582 sdata->flags |= IEEE80211_STA_DISABLE_HT;
3583 sdata->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg24398e32012-03-28 10:58:36 +02003584 }
3585 }
3586
Johannes Bergf2d9d272012-11-22 14:11:39 +01003587 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
3588 cbss->channel,
3589 ht_oper, vht_oper,
3590 &chandef);
Johannes Berg04ecd252012-09-11 14:34:12 +02003591
Johannes Bergf2d9d272012-11-22 14:11:39 +01003592 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
3593 local->rx_chains);
Johannes Berg24398e32012-03-28 10:58:36 +02003594
Johannes Berg9caf0362012-11-29 01:25:20 +01003595 rcu_read_unlock();
3596
Johannes Berg04ecd252012-09-11 14:34:12 +02003597 /* will change later if needed */
3598 sdata->smps_mode = IEEE80211_SMPS_OFF;
3599
Johannes Bergf2d9d272012-11-22 14:11:39 +01003600 /*
3601 * If this fails (possibly due to channel context sharing
3602 * on incompatible channels, e.g. 80+80 and 160 sharing the
3603 * same control channel) try to use a smaller bandwidth.
3604 */
3605 ret = ieee80211_vif_use_channel(sdata, &chandef,
3606 IEEE80211_CHANCTX_SHARED);
3607 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
3608 ifmgd->flags |= chandef_downgrade(&chandef);
3609 return ret;
Johannes Bergb17166a2012-07-27 11:41:27 +02003610}
3611
3612static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3613 struct cfg80211_bss *cbss, bool assoc)
3614{
3615 struct ieee80211_local *local = sdata->local;
3616 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3617 struct ieee80211_bss *bss = (void *)cbss->priv;
3618 struct sta_info *new_sta = NULL;
3619 bool have_sta = false;
3620 int err;
3621
3622 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
3623 return -EINVAL;
3624
3625 if (assoc) {
3626 rcu_read_lock();
3627 have_sta = sta_info_get(sdata, cbss->bssid);
3628 rcu_read_unlock();
3629 }
3630
3631 if (!have_sta) {
3632 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
3633 if (!new_sta)
3634 return -ENOMEM;
3635 }
3636
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003637 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003638 u32 rates = 0, basic_rates = 0;
3639 bool have_higher_than_11mbit;
3640 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Bergb17166a2012-07-27 11:41:27 +02003641 struct ieee80211_supported_band *sband;
Johannes Berg8cef2c92013-02-05 16:54:31 +01003642 const struct cfg80211_bss_ies *ies;
Johannes Bergb17166a2012-07-27 11:41:27 +02003643
3644 sband = local->hw.wiphy->bands[cbss->channel->band];
3645
3646 err = ieee80211_prep_channel(sdata, cbss);
3647 if (err) {
3648 sta_info_free(local, new_sta);
3649 return err;
3650 }
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003651
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003652 ieee80211_get_rates(sband, bss->supp_rates,
3653 bss->supp_rates_len,
3654 &rates, &basic_rates,
3655 &have_higher_than_11mbit,
3656 &min_rate, &min_rate_index);
3657
3658 /*
3659 * This used to be a workaround for basic rates missing
3660 * in the association response frame. Now that we no
3661 * longer use the basic rates from there, it probably
3662 * doesn't happen any more, but keep the workaround so
3663 * in case some *other* APs are buggy in different ways
3664 * we can connect -- with a warning.
3665 */
3666 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003667 sdata_info(sdata,
3668 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003669 basic_rates = BIT(min_rate_index);
3670 }
3671
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003672 new_sta->sta.supp_rates[cbss->channel->band] = rates;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003673 sdata->vif.bss_conf.basic_rates = basic_rates;
3674
3675 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg55de9082012-07-26 17:24:39 +02003676 if (cbss->channel->band == IEEE80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003677 have_higher_than_11mbit)
3678 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
3679 else
3680 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
3681
3682 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
3683
Johannes Berg8c358bc2012-05-22 22:13:05 +02003684 /* set timing information */
3685 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
Johannes Berg8cef2c92013-02-05 16:54:31 +01003686 rcu_read_lock();
Johannes Bergef429da2013-02-05 17:48:40 +01003687 ies = rcu_dereference(cbss->beacon_ies);
3688 if (ies) {
3689 const u8 *tim_ie;
3690
3691 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3692 sdata->vif.bss_conf.sync_device_ts =
3693 bss->device_ts_beacon;
3694 tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
3695 ies->data, ies->len);
3696 if (tim_ie && tim_ie[1] >= 2)
3697 sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
3698 else
3699 sdata->vif.bss_conf.sync_dtim_count = 0;
3700 } else if (!(local->hw.flags &
3701 IEEE80211_HW_TIMING_BEACON_ONLY)) {
3702 ies = rcu_dereference(cbss->proberesp_ies);
3703 /* must be non-NULL since beacon IEs were NULL */
3704 sdata->vif.bss_conf.sync_tsf = ies->tsf;
3705 sdata->vif.bss_conf.sync_device_ts =
3706 bss->device_ts_presp;
3707 sdata->vif.bss_conf.sync_dtim_count = 0;
3708 } else {
3709 sdata->vif.bss_conf.sync_tsf = 0;
3710 sdata->vif.bss_conf.sync_device_ts = 0;
3711 sdata->vif.bss_conf.sync_dtim_count = 0;
3712 }
Johannes Berg8cef2c92013-02-05 16:54:31 +01003713 rcu_read_unlock();
Johannes Berg8c358bc2012-05-22 22:13:05 +02003714
3715 /* tell driver about BSSID, basic rates and timing */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003716 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02003717 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
3718 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01003719
3720 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003721 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01003722
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003723 err = sta_info_insert(new_sta);
3724 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01003725 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003726 sdata_info(sdata,
3727 "failed to insert STA entry for the AP (error %d)\n",
3728 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01003729 return err;
3730 }
3731 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00003732 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01003733
3734 return 0;
3735}
3736
Johannes Berg77fdaa12009-07-07 03:45:17 +02003737/* config hooks */
3738int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
3739 struct cfg80211_auth_request *req)
3740{
Johannes Berg66e67e42012-01-20 13:55:27 +01003741 struct ieee80211_local *local = sdata->local;
3742 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3743 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003744 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01003745 int err;
3746
3747 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02003748
3749 switch (req->auth_type) {
3750 case NL80211_AUTHTYPE_OPEN_SYSTEM:
3751 auth_alg = WLAN_AUTH_OPEN;
3752 break;
3753 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01003754 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02003755 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003756 auth_alg = WLAN_AUTH_SHARED_KEY;
3757 break;
3758 case NL80211_AUTHTYPE_FT:
3759 auth_alg = WLAN_AUTH_FT;
3760 break;
3761 case NL80211_AUTHTYPE_NETWORK_EAP:
3762 auth_alg = WLAN_AUTH_LEAP;
3763 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003764 case NL80211_AUTHTYPE_SAE:
3765 auth_alg = WLAN_AUTH_SAE;
3766 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003767 default:
3768 return -EOPNOTSUPP;
3769 }
3770
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003771 auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len +
3772 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01003773 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02003774 return -ENOMEM;
3775
Johannes Berg66e67e42012-01-20 13:55:27 +01003776 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003777
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003778 if (req->sae_data_len >= 4) {
3779 __le16 *pos = (__le16 *) req->sae_data;
3780 auth_data->sae_trans = le16_to_cpu(pos[0]);
3781 auth_data->sae_status = le16_to_cpu(pos[1]);
3782 memcpy(auth_data->data, req->sae_data + 4,
3783 req->sae_data_len - 4);
3784 auth_data->data_len += req->sae_data_len - 4;
3785 }
3786
Johannes Berg77fdaa12009-07-07 03:45:17 +02003787 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003788 memcpy(&auth_data->data[auth_data->data_len],
3789 req->ie, req->ie_len);
3790 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003791 }
3792
Johannes Bergfffd0932009-07-08 14:22:54 +02003793 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003794 auth_data->key_len = req->key_len;
3795 auth_data->key_idx = req->key_idx;
3796 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02003797 }
3798
Johannes Berg66e67e42012-01-20 13:55:27 +01003799 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003800
Johannes Berg66e67e42012-01-20 13:55:27 +01003801 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01003802
Johannes Berg66e67e42012-01-20 13:55:27 +01003803 mutex_lock(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003804
Johannes Berg66e67e42012-01-20 13:55:27 +01003805 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
3806 ifmgd->assoc_data) {
3807 err = -EBUSY;
3808 goto err_free;
3809 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003810
Johannes Berg66e67e42012-01-20 13:55:27 +01003811 if (ifmgd->auth_data)
3812 ieee80211_destroy_auth_data(sdata, false);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003813
Johannes Berg66e67e42012-01-20 13:55:27 +01003814 /* prep auth_data so we don't go into idle on disassoc */
3815 ifmgd->auth_data = auth_data;
3816
3817 if (ifmgd->associated)
Johannes Berg37ad3882012-02-24 13:50:54 +01003818 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
Johannes Berg66e67e42012-01-20 13:55:27 +01003819
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003820 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003821
Johannes Berga1cf7752012-03-08 15:02:07 +01003822 err = ieee80211_prep_connection(sdata, req->bss, false);
3823 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01003824 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03003825
Johannes Berg66e67e42012-01-20 13:55:27 +01003826 err = ieee80211_probe_auth(sdata);
3827 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003828 sta_info_destroy_addr(sdata, req->bss->bssid);
3829 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003830 }
3831
Johannes Berg66e67e42012-01-20 13:55:27 +01003832 /* hold our own reference */
Johannes Berg5b112d32013-02-01 01:49:58 +01003833 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
Johannes Berg66e67e42012-01-20 13:55:27 +01003834 err = 0;
3835 goto out_unlock;
Johannes Berge5b900d2010-07-29 16:08:55 +02003836
Johannes Berg66e67e42012-01-20 13:55:27 +01003837 err_clear:
Eliad Peller3d2abdf2012-09-04 17:44:45 +03003838 memset(ifmgd->bssid, 0, ETH_ALEN);
3839 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01003840 ifmgd->auth_data = NULL;
3841 err_free:
3842 kfree(auth_data);
3843 out_unlock:
3844 mutex_unlock(&ifmgd->mtx);
Johannes Berge5b900d2010-07-29 16:08:55 +02003845
Johannes Berg66e67e42012-01-20 13:55:27 +01003846 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003847}
3848
Johannes Berg77fdaa12009-07-07 03:45:17 +02003849int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3850 struct cfg80211_assoc_request *req)
3851{
Johannes Berg66e67e42012-01-20 13:55:27 +01003852 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003853 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003854 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01003855 struct ieee80211_mgd_assoc_data *assoc_data;
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02003856 const struct cfg80211_bss_ies *beacon_ies;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01003857 struct ieee80211_supported_band *sband;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01003858 const u8 *ssidie, *ht_ie, *vht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03003859 int i, err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003860
Johannes Berg66e67e42012-01-20 13:55:27 +01003861 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
3862 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01003863 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003864
Johannes Berg9caf0362012-11-29 01:25:20 +01003865 rcu_read_lock();
3866 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
3867 if (!ssidie) {
3868 rcu_read_unlock();
3869 kfree(assoc_data);
3870 return -EINVAL;
3871 }
3872 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
3873 assoc_data->ssid_len = ssidie[1];
3874 rcu_read_unlock();
3875
Johannes Berg66e67e42012-01-20 13:55:27 +01003876 mutex_lock(&ifmgd->mtx);
3877
3878 if (ifmgd->associated)
Johannes Berg37ad3882012-02-24 13:50:54 +01003879 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
Johannes Berg66e67e42012-01-20 13:55:27 +01003880
3881 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
3882 err = -EBUSY;
3883 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03003884 }
3885
Johannes Berg66e67e42012-01-20 13:55:27 +01003886 if (ifmgd->assoc_data) {
3887 err = -EBUSY;
3888 goto err_free;
3889 }
3890
3891 if (ifmgd->auth_data) {
3892 bool match;
3893
3894 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00003895 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003896 ieee80211_destroy_auth_data(sdata, match);
3897 }
3898
3899 /* prepare assoc data */
Johannes Berg19c3b832012-08-01 20:13:36 +02003900
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003901 ifmgd->beacon_crc_valid = false;
3902
Johannes Bergde5036a2012-03-08 15:02:03 +01003903 /*
3904 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
3905 * We still associate in non-HT mode (11a/b/g) if any one of these
3906 * ciphers is configured as pairwise.
3907 * We can set this to true for non-11n hardware, that'll be checked
3908 * separately along with the peer capabilities.
3909 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02003910 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02003911 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
3912 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02003913 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01003914 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003915 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg1c4cb922012-05-30 15:57:00 +02003916 netdev_info(sdata->dev,
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003917 "disabling HT/VHT due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02003918 }
3919 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003920
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003921 if (req->flags & ASSOC_REQ_DISABLE_HT) {
Johannes Berga8243b72012-11-22 14:32:09 +01003922 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003923 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3924 }
Ben Greearef96a8422011-11-18 11:32:00 -08003925
Johannes Berg4e74bfd2012-03-08 15:02:04 +01003926 /* Also disable HT if we don't support it or the AP doesn't use WMM */
3927 sband = local->hw.wiphy->bands[req->bss->channel->band];
3928 if (!sband->ht_cap.ht_supported ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02003929 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
Johannes Berga8243b72012-11-22 14:32:09 +01003930 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg1b49de22012-07-27 10:29:14 +02003931 if (!bss->wmm_used)
3932 netdev_info(sdata->dev,
3933 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02003934 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01003935
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003936 /* disable VHT if we don't support it or the AP doesn't use WMM */
3937 if (!sband->vht_cap.vht_supported ||
3938 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
3939 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg1b49de22012-07-27 10:29:14 +02003940 if (!bss->wmm_used)
3941 netdev_info(sdata->dev,
3942 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003943 }
3944
Ben Greearef96a8422011-11-18 11:32:00 -08003945 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
3946 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
3947 sizeof(ifmgd->ht_capa_mask));
3948
Johannes Berg77fdaa12009-07-07 03:45:17 +02003949 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003950 memcpy(assoc_data->ie, req->ie, req->ie_len);
3951 assoc_data->ie_len = req->ie_len;
3952 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003953
Johannes Berg66e67e42012-01-20 13:55:27 +01003954 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01003955
Johannes Bergaf6b6372009-12-23 13:15:35 +01003956 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
3957 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02003958 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003959 else
Johannes Berg04ecd252012-09-11 14:34:12 +02003960 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003961 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02003962 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003963
Johannes Berg66e67e42012-01-20 13:55:27 +01003964 assoc_data->capability = req->bss->capability;
Johannes Berg32c50572012-03-28 11:04:29 +02003965 assoc_data->wmm = bss->wmm_used &&
3966 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg66e67e42012-01-20 13:55:27 +01003967 assoc_data->supp_rates = bss->supp_rates;
3968 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02003969
Johannes Berg9caf0362012-11-29 01:25:20 +01003970 rcu_read_lock();
Johannes Berg9dde6422012-05-16 23:43:19 +02003971 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
3972 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
3973 assoc_data->ap_ht_param =
3974 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
3975 else
Johannes Berga8243b72012-11-22 14:32:09 +01003976 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Bergb08fbbd2012-12-07 13:06:48 +01003977 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
3978 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
3979 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
3980 sizeof(struct ieee80211_vht_cap));
3981 else
3982 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg9caf0362012-11-29 01:25:20 +01003983 rcu_read_unlock();
Johannes Berg63f170e2009-12-23 13:15:33 +01003984
Kalle Valoab133152010-01-12 10:42:31 +02003985 if (bss->wmm_used && bss->uapsd_supported &&
3986 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01003987 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02003988 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
3989 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01003990 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02003991 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
3992 }
3993
Johannes Berg77fdaa12009-07-07 03:45:17 +02003994 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01003995 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003996
3997 if (req->use_mfp) {
3998 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
3999 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
4000 } else {
4001 ifmgd->mfp = IEEE80211_MFP_DISABLED;
4002 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
4003 }
4004
4005 if (req->crypto.control_port)
4006 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
4007 else
4008 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
4009
Johannes Berga621fa42010-08-27 14:26:54 +03004010 sdata->control_port_protocol = req->crypto.control_port_ethertype;
4011 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
4012
Johannes Berg66e67e42012-01-20 13:55:27 +01004013 /* kick off associate process */
4014
4015 ifmgd->assoc_data = assoc_data;
Johannes Berg826262c2012-12-10 16:38:14 +02004016 ifmgd->dtim_period = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01004017
Johannes Berga1cf7752012-03-08 15:02:07 +01004018 err = ieee80211_prep_connection(sdata, req->bss, true);
4019 if (err)
4020 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01004021
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004022 rcu_read_lock();
4023 beacon_ies = rcu_dereference(req->bss->beacon_ies);
Johannes Berg826262c2012-12-10 16:38:14 +02004024
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004025 if (sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC &&
4026 !beacon_ies) {
4027 /*
4028 * Wait up to one beacon interval ...
4029 * should this be more if we miss one?
4030 */
4031 sdata_info(sdata, "waiting for beacon from %pM\n",
4032 ifmgd->bssid);
4033 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
4034 assoc_data->need_beacon = true;
4035 } else if (beacon_ies) {
4036 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
4037 beacon_ies->data,
4038 beacon_ies->len);
Johannes Bergef429da2013-02-05 17:48:40 +01004039 u8 dtim_count = 0;
4040
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004041 if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
4042 const struct ieee80211_tim_ie *tim;
4043 tim = (void *)(tim_ie + 2);
4044 ifmgd->dtim_period = tim->dtim_period;
Johannes Bergef429da2013-02-05 17:48:40 +01004045 dtim_count = tim->dtim_count;
Johannes Berg826262c2012-12-10 16:38:14 +02004046 }
Johannes Berg66e67e42012-01-20 13:55:27 +01004047 assoc_data->have_beacon = true;
Johannes Berg66e67e42012-01-20 13:55:27 +01004048 assoc_data->timeout = jiffies;
Johannes Bergef429da2013-02-05 17:48:40 +01004049
4050 if (local->hw.flags & IEEE80211_HW_TIMING_BEACON_ONLY) {
4051 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
4052 sdata->vif.bss_conf.sync_device_ts =
4053 bss->device_ts_beacon;
4054 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
4055 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004056 } else {
4057 assoc_data->timeout = jiffies;
Johannes Berg66e67e42012-01-20 13:55:27 +01004058 }
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +02004059 rcu_read_unlock();
4060
Johannes Berg66e67e42012-01-20 13:55:27 +01004061 run_again(ifmgd, assoc_data->timeout);
4062
Paul Stewartfcff4f12012-02-23 17:59:53 -08004063 if (bss->corrupt_data) {
4064 char *corrupt_type = "data";
4065 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
4066 if (bss->corrupt_data &
4067 IEEE80211_BSS_CORRUPT_PROBE_RESP)
4068 corrupt_type = "beacon and probe response";
4069 else
4070 corrupt_type = "beacon";
4071 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
4072 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004073 sdata_info(sdata, "associating with AP with corrupt %s\n",
4074 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08004075 }
4076
Johannes Berg66e67e42012-01-20 13:55:27 +01004077 err = 0;
4078 goto out;
4079 err_clear:
Eliad Peller3d2abdf2012-09-04 17:44:45 +03004080 memset(ifmgd->bssid, 0, ETH_ALEN);
4081 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01004082 ifmgd->assoc_data = NULL;
4083 err_free:
4084 kfree(assoc_data);
4085 out:
4086 mutex_unlock(&ifmgd->mtx);
4087
4088 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004089}
4090
4091int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01004092 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004093{
4094 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004095 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02004096 bool tx = !req->local_state_change;
Johannes Berg86552012012-10-29 09:46:31 +01004097 bool sent_frame = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02004098
Johannes Berg77fdaa12009-07-07 03:45:17 +02004099 mutex_lock(&ifmgd->mtx);
4100
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004101 sdata_info(sdata,
4102 "deauthenticating from %pM by local choice (reason=%d)\n",
4103 req->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02004104
Johannes Berg86552012012-10-29 09:46:31 +01004105 if (ifmgd->auth_data) {
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03004106 drv_mgd_prepare_tx(sdata->local, sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01004107 ieee80211_send_deauth_disassoc(sdata, req->bssid,
4108 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02004109 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01004110 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01004111 ieee80211_destroy_auth_data(sdata, false);
4112 mutex_unlock(&ifmgd->mtx);
4113
4114 sent_frame = tx;
4115 goto out;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03004116 }
4117
Johannes Berg86552012012-10-29 09:46:31 +01004118 if (ifmgd->associated &&
4119 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
4120 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4121 req->reason_code, tx, frame_buf);
4122 sent_frame = tx;
4123 }
Johannes Berg37ad3882012-02-24 13:50:54 +01004124 mutex_unlock(&ifmgd->mtx);
4125
Johannes Berg86552012012-10-29 09:46:31 +01004126 out:
Johannes Berg86552012012-10-29 09:46:31 +01004127 if (sent_frame)
4128 __cfg80211_send_deauth(sdata->dev, frame_buf,
4129 IEEE80211_DEAUTH_FRAME_LEN);
4130
Johannes Berg77fdaa12009-07-07 03:45:17 +02004131 return 0;
4132}
4133
4134int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01004135 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02004136{
4137 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07004138 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004139 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02004140
Johannes Berg77fdaa12009-07-07 03:45:17 +02004141 mutex_lock(&ifmgd->mtx);
4142
Johannes Berg8d8b2612009-07-25 11:58:36 +02004143 /*
4144 * cfg80211 should catch this ... but it's racy since
4145 * we can receive a disassoc frame, process it, hand it
4146 * to cfg80211 while that's in a locked section already
4147 * trying to tell us that the user wants to disconnect.
4148 */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01004149 if (ifmgd->associated != req->bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02004150 mutex_unlock(&ifmgd->mtx);
4151 return -ENOLINK;
4152 }
4153
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02004154 sdata_info(sdata,
4155 "disassociating from %pM by local choice (reason=%d)\n",
4156 req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02004157
Jouni Malinene69e95d2010-03-29 23:29:31 -07004158 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01004159 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
4160 req->reason_code, !req->local_state_change,
4161 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02004162 mutex_unlock(&ifmgd->mtx);
4163
Antonio Quartulli6ae16772012-09-07 13:28:52 +02004164 __cfg80211_send_disassoc(sdata->dev, frame_buf,
4165 IEEE80211_DEAUTH_FRAME_LEN);
Johannes Bergbc83b682009-11-29 12:19:06 +01004166
Johannes Berg77fdaa12009-07-07 03:45:17 +02004167 return 0;
4168}
Jouni Malinen026331c2010-02-15 12:53:10 +02004169
Eliad Pellerafa762f2012-04-23 14:45:15 +03004170void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01004171{
4172 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4173
4174 mutex_lock(&ifmgd->mtx);
4175 if (ifmgd->assoc_data)
4176 ieee80211_destroy_assoc_data(sdata, false);
4177 if (ifmgd->auth_data)
4178 ieee80211_destroy_auth_data(sdata, false);
4179 del_timer_sync(&ifmgd->timer);
4180 mutex_unlock(&ifmgd->mtx);
4181}
4182
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02004183void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
4184 enum nl80211_cqm_rssi_threshold_event rssi_event,
4185 gfp_t gfp)
4186{
4187 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4188
Johannes Bergb5878a22010-04-07 16:48:40 +02004189 trace_api_cqm_rssi_notify(sdata, rssi_event);
4190
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02004191 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
4192}
4193EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);