blob: d2a4f78b4b0f658e44022d8cd6fe2b80cbff591e [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 Berg66e67e42012-01-20 13:55:27 +010033#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
34#define IEEE80211_AUTH_MAX_TRIES 3
35#define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
36#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
37#define IEEE80211_ASSOC_MAX_TRIES 3
38
Ben Greear180205b2011-02-04 15:30:24 -080039static int max_nullfunc_tries = 2;
40module_param(max_nullfunc_tries, int, 0644);
41MODULE_PARM_DESC(max_nullfunc_tries,
42 "Maximum nullfunc tx tries before disconnecting (reason 4).");
43
44static int max_probe_tries = 5;
45module_param(max_probe_tries, int, 0644);
46MODULE_PARM_DESC(max_probe_tries,
47 "Maximum probe tries before disconnecting (reason 4).");
Johannes Bergb291ba12009-07-10 15:29:03 +020048
49/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010050 * Beacon loss timeout is calculated as N frames times the
51 * advertised beacon interval. This may need to be somewhat
52 * higher than what hardware might detect to account for
53 * delays in the host processing frames. But since we also
54 * probe on beacon miss before declaring the connection lost
55 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020056 */
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010057#define IEEE80211_BEACON_LOSS_COUNT 7
58
Johannes Bergb291ba12009-07-10 15:29:03 +020059/*
60 * Time the connection can be idle before we probe
61 * it to see if we can still talk to the AP.
62 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030063#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020064/*
65 * Time we wait for a probe response after sending
66 * a probe request because of beacon loss or for
67 * checking the connection still works.
68 */
Ben Greear180205b2011-02-04 15:30:24 -080069static int probe_wait_ms = 500;
70module_param(probe_wait_ms, int, 0644);
71MODULE_PARM_DESC(probe_wait_ms,
72 "Maximum time(ms) to wait for probe response"
73 " before disconnecting (reason 4).");
Jiri Bencf0706e82007-05-05 11:45:53 -070074
Jouni Malinen17e4ec12010-03-29 23:28:30 -070075/*
76 * Weight given to the latest Beacon frame when calculating average signal
77 * strength for Beacon frames received in the current BSS. This must be
78 * between 1 and 15.
79 */
80#define IEEE80211_SIGNAL_AVE_WEIGHT 3
81
Jouni Malinen391a2002010-08-27 22:22:00 +030082/*
83 * How many Beacon frames need to have been used in average signal strength
84 * before starting to indicate signal change events.
85 */
86#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
87
Johannes Berg5bb644a2009-05-17 11:40:42 +020088#define TMR_RUNNING_TIMER 0
89#define TMR_RUNNING_CHANSW 1
90
Johannes Berg77fdaa12009-07-07 03:45:17 +020091/*
92 * All cfg80211 functions have to be called outside a locked
93 * section so that they can acquire a lock themselves... This
94 * is much simpler than queuing up things in cfg80211, but we
95 * do need some indirection for that here.
96 */
97enum rx_mgmt_action {
98 /* no action required */
99 RX_MGMT_NONE,
100
Johannes Berg77fdaa12009-07-07 03:45:17 +0200101 /* caller must call cfg80211_send_deauth() */
102 RX_MGMT_CFG80211_DEAUTH,
103
104 /* caller must call cfg80211_send_disassoc() */
105 RX_MGMT_CFG80211_DISASSOC,
Johannes Berg66e67e42012-01-20 13:55:27 +0100106
107 /* caller must call cfg80211_send_rx_auth() */
108 RX_MGMT_CFG80211_RX_AUTH,
109
110 /* caller must call cfg80211_send_rx_assoc() */
111 RX_MGMT_CFG80211_RX_ASSOC,
112
113 /* caller must call cfg80211_send_assoc_timeout() */
114 RX_MGMT_CFG80211_ASSOC_TIMEOUT,
Johannes Berg77fdaa12009-07-07 03:45:17 +0200115};
116
Johannes Berg5484e232008-09-08 17:44:27 +0200117/* utils */
Johannes Berg77fdaa12009-07-07 03:45:17 +0200118static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
119{
Johannes Berg46a5eba2010-09-15 13:28:15 +0200120 lockdep_assert_held(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200121}
122
Johannes Bergca386f32009-07-10 02:39:48 +0200123/*
124 * We can have multiple work items (and connection probing)
125 * scheduling this timer, but we need to take care to only
126 * reschedule it when it should fire _earlier_ than it was
127 * asked for before, or if it's not pending right now. This
128 * function ensures that. Note that it then is required to
129 * run this function for all timeouts after the first one
130 * has happened -- the work that runs from this timer will
131 * do that.
132 */
Johannes Berg66e67e42012-01-20 13:55:27 +0100133static void run_again(struct ieee80211_if_managed *ifmgd, unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200134{
135 ASSERT_MGD_MTX(ifmgd);
136
137 if (!timer_pending(&ifmgd->timer) ||
138 time_before(timeout, ifmgd->timer.expires))
139 mod_timer(&ifmgd->timer, timeout);
140}
141
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400142void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200143{
Johannes Bergc1288b12012-01-19 09:29:57 +0100144 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200145 return;
146
Johannes Berg7eeff742012-07-18 10:27:27 +0200147 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
148 return;
149
Johannes Bergb291ba12009-07-10 15:29:03 +0200150 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100151 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200152}
153
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400154void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
155{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400156 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
157
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100158 if (unlikely(!sdata->u.mgd.associated))
159 return;
160
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400161 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
162 return;
163
164 mod_timer(&sdata->u.mgd.conn_mon_timer,
165 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400166
167 ifmgd->probe_send_count = 0;
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400168}
169
Johannes Berg5484e232008-09-08 17:44:27 +0200170static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200171{
Johannes Berg5484e232008-09-08 17:44:27 +0200172 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200173}
174
Johannes Berg24398e32012-03-28 10:58:36 +0200175static u32 ieee80211_config_ht_tx(struct ieee80211_sub_if_data *sdata,
176 struct ieee80211_ht_operation *ht_oper,
177 const u8 *bssid, bool reconfig)
Johannes Bergd5522e02009-03-30 13:23:35 +0200178{
179 struct ieee80211_local *local = sdata->local;
180 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200181 struct ieee80211_chanctx_conf *chanctx_conf;
182 struct ieee80211_channel *chan;
Johannes Bergd5522e02009-03-30 13:23:35 +0200183 struct sta_info *sta;
184 u32 changed = 0;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200185 u16 ht_opmode;
Johannes Berg64f68e52012-03-28 10:58:37 +0200186 bool disable_40 = false;
Johannes Bergd5522e02009-03-30 13:23:35 +0200187
Johannes Berg55de9082012-07-26 17:24:39 +0200188 rcu_read_lock();
189 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
190 if (WARN_ON(!chanctx_conf)) {
191 rcu_read_unlock();
192 return 0;
193 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100194 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200195 rcu_read_unlock();
196 sband = local->hw.wiphy->bands[chan->band];
Johannes Berg0aaffa92010-05-05 15:28:27 +0200197
Johannes Berg4bf88532012-11-09 11:39:59 +0100198 switch (sdata->vif.bss_conf.chandef.width) {
199 case NL80211_CHAN_WIDTH_40:
200 if (sdata->vif.bss_conf.chandef.chan->center_freq >
201 sdata->vif.bss_conf.chandef.center_freq1 &&
202 chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
Johannes Berg64f68e52012-03-28 10:58:37 +0200203 disable_40 = true;
Johannes Berg4bf88532012-11-09 11:39:59 +0100204 if (sdata->vif.bss_conf.chandef.chan->center_freq <
205 sdata->vif.bss_conf.chandef.center_freq1 &&
206 chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
Johannes Berg64f68e52012-03-28 10:58:37 +0200207 disable_40 = true;
208 break;
209 default:
210 break;
211 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200212
Johannes Berg24398e32012-03-28 10:58:36 +0200213 /* This can change during the lifetime of the BSS */
214 if (!(ht_oper->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY))
Johannes Berg64f68e52012-03-28 10:58:37 +0200215 disable_40 = true;
Johannes Bergd5522e02009-03-30 13:23:35 +0200216
Johannes Berg64f68e52012-03-28 10:58:37 +0200217 mutex_lock(&local->sta_mtx);
218 sta = sta_info_get(sdata, bssid);
219
220 WARN_ON_ONCE(!sta);
221
222 if (sta && !sta->supports_40mhz)
223 disable_40 = true;
224
225 if (sta && (!reconfig ||
Rajkumar Manoharan91a00992012-04-25 20:24:24 +0530226 (disable_40 != !(sta->sta.ht_cap.cap &
Johannes Berg64f68e52012-03-28 10:58:37 +0200227 IEEE80211_HT_CAP_SUP_WIDTH_20_40)))) {
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530228
Johannes Berg64f68e52012-03-28 10:58:37 +0200229 if (disable_40)
230 sta->sta.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
231 else
232 sta->sta.ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530233
Johannes Berg64f68e52012-03-28 10:58:37 +0200234 rate_control_rate_update(local, sband, sta,
Johannes Berg8f727ef2012-03-30 08:43:32 +0200235 IEEE80211_RC_BW_CHANGED);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200236 }
Johannes Berg64f68e52012-03-28 10:58:37 +0200237 mutex_unlock(&local->sta_mtx);
Johannes Bergd5522e02009-03-30 13:23:35 +0200238
Johannes Berg074d46d2012-03-15 19:45:16 +0100239 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200240
241 /* if bss configuration changed store the new one */
Johannes Berg24398e32012-03-28 10:58:36 +0200242 if (!reconfig || (sdata->vif.bss_conf.ht_operation_mode != ht_opmode)) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200243 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200244 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Bergd5522e02009-03-30 13:23:35 +0200245 }
246
247 return changed;
248}
249
Johannes Berg9c6bd792008-09-11 00:01:52 +0200250/* frame sending functions */
251
Johannes Berg66e67e42012-01-20 13:55:27 +0100252static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
253 struct ieee80211_supported_band *sband,
254 u32 *rates)
255{
256 int i, j, count;
257 *rates = 0;
258 count = 0;
259 for (i = 0; i < supp_rates_len; i++) {
260 int rate = (supp_rates[i] & 0x7F) * 5;
261
262 for (j = 0; j < sband->n_bitrates; j++)
263 if (sband->bitrates[j].bitrate == rate) {
264 *rates |= BIT(j);
265 count++;
266 break;
267 }
268 }
269
270 return count;
271}
272
273static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
Johannes Berg9dde6422012-05-16 23:43:19 +0200274 struct sk_buff *skb, u8 ap_ht_param,
Johannes Berg66e67e42012-01-20 13:55:27 +0100275 struct ieee80211_supported_band *sband,
276 struct ieee80211_channel *channel,
277 enum ieee80211_smps_mode smps)
278{
Johannes Berg66e67e42012-01-20 13:55:27 +0100279 u8 *pos;
280 u32 flags = channel->flags;
281 u16 cap;
282 struct ieee80211_sta_ht_cap ht_cap;
283
284 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
285
Johannes Berg66e67e42012-01-20 13:55:27 +0100286 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
287 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
288
Johannes Berg66e67e42012-01-20 13:55:27 +0100289 /* determine capability flags */
290 cap = ht_cap.cap;
291
Johannes Berg9dde6422012-05-16 23:43:19 +0200292 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
Johannes Berg66e67e42012-01-20 13:55:27 +0100293 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
294 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
295 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
296 cap &= ~IEEE80211_HT_CAP_SGI_40;
297 }
298 break;
299 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
300 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
301 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
302 cap &= ~IEEE80211_HT_CAP_SGI_40;
303 }
304 break;
305 }
306
Johannes Berg24398e32012-03-28 10:58:36 +0200307 /*
308 * If 40 MHz was disabled associate as though we weren't
309 * capable of 40 MHz -- some broken APs will never fall
310 * back to trying to transmit in 20 MHz.
311 */
312 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
313 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
314 cap &= ~IEEE80211_HT_CAP_SGI_40;
315 }
316
Johannes Berg66e67e42012-01-20 13:55:27 +0100317 /* set SM PS mode properly */
318 cap &= ~IEEE80211_HT_CAP_SM_PS;
319 switch (smps) {
320 case IEEE80211_SMPS_AUTOMATIC:
321 case IEEE80211_SMPS_NUM_MODES:
322 WARN_ON(1);
323 case IEEE80211_SMPS_OFF:
324 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
325 IEEE80211_HT_CAP_SM_PS_SHIFT;
326 break;
327 case IEEE80211_SMPS_STATIC:
328 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
329 IEEE80211_HT_CAP_SM_PS_SHIFT;
330 break;
331 case IEEE80211_SMPS_DYNAMIC:
332 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
333 IEEE80211_HT_CAP_SM_PS_SHIFT;
334 break;
335 }
336
337 /* reserve and fill IE */
338 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
339 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
340}
341
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000342static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
343 struct sk_buff *skb,
344 struct ieee80211_supported_band *sband)
345{
346 u8 *pos;
347 u32 cap;
348 struct ieee80211_sta_vht_cap vht_cap;
349
350 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
351
352 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
353
354 /* determine capability flags */
355 cap = vht_cap.cap;
356
357 /* reserve and fill IE */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000358 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000359 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
360}
361
Johannes Berg66e67e42012-01-20 13:55:27 +0100362static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
363{
364 struct ieee80211_local *local = sdata->local;
365 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
366 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
367 struct sk_buff *skb;
368 struct ieee80211_mgmt *mgmt;
369 u8 *pos, qos_info;
370 size_t offset = 0, noffset;
371 int i, count, rates_len, supp_rates_len;
372 u16 capab;
373 struct ieee80211_supported_band *sband;
Johannes Berg55de9082012-07-26 17:24:39 +0200374 struct ieee80211_chanctx_conf *chanctx_conf;
375 struct ieee80211_channel *chan;
Johannes Berg66e67e42012-01-20 13:55:27 +0100376 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100377
378 lockdep_assert_held(&ifmgd->mtx);
379
Johannes Berg55de9082012-07-26 17:24:39 +0200380 rcu_read_lock();
381 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
382 if (WARN_ON(!chanctx_conf)) {
383 rcu_read_unlock();
384 return;
385 }
Johannes Berg4bf88532012-11-09 11:39:59 +0100386 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200387 rcu_read_unlock();
388 sband = local->hw.wiphy->bands[chan->band];
Johannes Berg66e67e42012-01-20 13:55:27 +0100389
390 if (assoc_data->supp_rates_len) {
391 /*
392 * Get all rates supported by the device and the AP as
393 * some APs don't like getting a superset of their rates
394 * in the association request (e.g. D-Link DAP 1353 in
395 * b-only mode)...
396 */
397 rates_len = ieee80211_compatible_rates(assoc_data->supp_rates,
398 assoc_data->supp_rates_len,
399 sband, &rates);
400 } else {
401 /*
402 * In case AP not provide any supported rates information
403 * before association, we send information element(s) with
404 * all rates that we support.
405 */
406 rates = ~0;
407 rates_len = sband->n_bitrates;
408 }
409
410 skb = alloc_skb(local->hw.extra_tx_headroom +
411 sizeof(*mgmt) + /* bit too much but doesn't matter */
412 2 + assoc_data->ssid_len + /* SSID */
413 4 + rates_len + /* (extended) rates */
414 4 + /* power capability */
415 2 + 2 * sband->n_channels + /* supported channels */
416 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivelad4950282012-10-10 11:25:40 +0000417 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Johannes Berg66e67e42012-01-20 13:55:27 +0100418 assoc_data->ie_len + /* extra IEs */
419 9, /* WMM */
420 GFP_KERNEL);
421 if (!skb)
422 return;
423
424 skb_reserve(skb, local->hw.extra_tx_headroom);
425
426 capab = WLAN_CAPABILITY_ESS;
427
428 if (sband->band == IEEE80211_BAND_2GHZ) {
429 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
430 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
431 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
432 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
433 }
434
435 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
436 capab |= WLAN_CAPABILITY_PRIVACY;
437
438 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
439 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
440 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
441
442 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
443 memset(mgmt, 0, 24);
444 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
445 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
446 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
447
448 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
449 skb_put(skb, 10);
450 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
451 IEEE80211_STYPE_REASSOC_REQ);
452 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
453 mgmt->u.reassoc_req.listen_interval =
454 cpu_to_le16(local->hw.conf.listen_interval);
455 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
456 ETH_ALEN);
457 } else {
458 skb_put(skb, 4);
459 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
460 IEEE80211_STYPE_ASSOC_REQ);
461 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
462 mgmt->u.assoc_req.listen_interval =
463 cpu_to_le16(local->hw.conf.listen_interval);
464 }
465
466 /* SSID */
467 pos = skb_put(skb, 2 + assoc_data->ssid_len);
468 *pos++ = WLAN_EID_SSID;
469 *pos++ = assoc_data->ssid_len;
470 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
471
472 /* add all rates which were marked to be used above */
473 supp_rates_len = rates_len;
474 if (supp_rates_len > 8)
475 supp_rates_len = 8;
476
477 pos = skb_put(skb, supp_rates_len + 2);
478 *pos++ = WLAN_EID_SUPP_RATES;
479 *pos++ = supp_rates_len;
480
481 count = 0;
482 for (i = 0; i < sband->n_bitrates; i++) {
483 if (BIT(i) & rates) {
484 int rate = sband->bitrates[i].bitrate;
485 *pos++ = (u8) (rate / 5);
486 if (++count == 8)
487 break;
488 }
489 }
490
491 if (rates_len > count) {
492 pos = skb_put(skb, rates_len - count + 2);
493 *pos++ = WLAN_EID_EXT_SUPP_RATES;
494 *pos++ = rates_len - count;
495
496 for (i++; i < sband->n_bitrates; i++) {
497 if (BIT(i) & rates) {
498 int rate = sband->bitrates[i].bitrate;
499 *pos++ = (u8) (rate / 5);
500 }
501 }
502 }
503
504 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
505 /* 1. power capabilities */
506 pos = skb_put(skb, 4);
507 *pos++ = WLAN_EID_PWR_CAPABILITY;
508 *pos++ = 2;
509 *pos++ = 0; /* min tx power */
Johannes Berg55de9082012-07-26 17:24:39 +0200510 *pos++ = chan->max_power; /* max tx power */
Johannes Berg66e67e42012-01-20 13:55:27 +0100511
512 /* 2. supported channels */
513 /* TODO: get this in reg domain format */
514 pos = skb_put(skb, 2 * sband->n_channels + 2);
515 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
516 *pos++ = 2 * sband->n_channels;
517 for (i = 0; i < sband->n_channels; i++) {
518 *pos++ = ieee80211_frequency_to_channel(
519 sband->channels[i].center_freq);
520 *pos++ = 1; /* one channel in the subband*/
521 }
522 }
523
524 /* if present, add any custom IEs that go before HT */
525 if (assoc_data->ie_len && assoc_data->ie) {
526 static const u8 before_ht[] = {
527 WLAN_EID_SSID,
528 WLAN_EID_SUPP_RATES,
529 WLAN_EID_EXT_SUPP_RATES,
530 WLAN_EID_PWR_CAPABILITY,
531 WLAN_EID_SUPPORTED_CHANNELS,
532 WLAN_EID_RSN,
533 WLAN_EID_QOS_CAPA,
534 WLAN_EID_RRM_ENABLED_CAPABILITIES,
535 WLAN_EID_MOBILITY_DOMAIN,
536 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
537 };
538 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
539 before_ht, ARRAY_SIZE(before_ht),
540 offset);
541 pos = skb_put(skb, noffset - offset);
542 memcpy(pos, assoc_data->ie + offset, noffset - offset);
543 offset = noffset;
544 }
545
Johannes Berga8243b72012-11-22 14:32:09 +0100546 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg9dde6422012-05-16 23:43:19 +0200547 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
Johannes Berg04ecd252012-09-11 14:34:12 +0200548 sband, chan, sdata->smps_mode);
Johannes Berg66e67e42012-01-20 13:55:27 +0100549
Mahesh Palivelad545dab2012-07-24 03:33:10 +0000550 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
551 ieee80211_add_vht_ie(sdata, skb, sband);
552
Johannes Berg66e67e42012-01-20 13:55:27 +0100553 /* if present, add any custom non-vendor IEs that go after HT */
554 if (assoc_data->ie_len && assoc_data->ie) {
555 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
556 assoc_data->ie_len,
557 offset);
558 pos = skb_put(skb, noffset - offset);
559 memcpy(pos, assoc_data->ie + offset, noffset - offset);
560 offset = noffset;
561 }
562
Johannes Berg76f03032012-03-08 15:02:05 +0100563 if (assoc_data->wmm) {
564 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200565 qos_info = ifmgd->uapsd_queues;
566 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100567 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
568 } else {
569 qos_info = 0;
570 }
571
572 pos = skb_put(skb, 9);
573 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
574 *pos++ = 7; /* len */
575 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
576 *pos++ = 0x50;
577 *pos++ = 0xf2;
578 *pos++ = 2; /* WME */
579 *pos++ = 0; /* WME info */
580 *pos++ = 1; /* WME ver */
581 *pos++ = qos_info;
582 }
583
584 /* add any remaining custom (i.e. vendor specific here) IEs */
585 if (assoc_data->ie_len && assoc_data->ie) {
586 noffset = assoc_data->ie_len;
587 pos = skb_put(skb, noffset - offset);
588 memcpy(pos, assoc_data->ie + offset, noffset - offset);
589 }
590
Johannes Berga1845fc2012-06-27 13:18:36 +0200591 drv_mgd_prepare_tx(local, sdata);
592
Johannes Berg66e67e42012-01-20 13:55:27 +0100593 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
594 ieee80211_tx_skb(sdata, skb);
595}
596
Kalle Valo572e0012009-02-10 17:09:31 +0200597void ieee80211_send_pspoll(struct ieee80211_local *local,
598 struct ieee80211_sub_if_data *sdata)
599{
Kalle Valo572e0012009-02-10 17:09:31 +0200600 struct ieee80211_pspoll *pspoll;
601 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200602
Kalle Valod8cd1892010-01-05 20:16:26 +0200603 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
604 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200605 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200606
Kalle Valod8cd1892010-01-05 20:16:26 +0200607 pspoll = (struct ieee80211_pspoll *) skb->data;
608 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200609
Johannes Berg62ae67b2009-11-18 18:42:05 +0100610 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
611 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200612}
613
Johannes Berg965beda2009-04-16 13:17:24 +0200614void ieee80211_send_nullfunc(struct ieee80211_local *local,
615 struct ieee80211_sub_if_data *sdata,
616 int powersave)
617{
618 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200619 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530620 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200621
Kalle Valod8cd1892010-01-05 20:16:26 +0200622 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
623 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200624 return;
625
Kalle Valod8cd1892010-01-05 20:16:26 +0200626 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200627 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200628 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200629
Johannes Berg62ae67b2009-11-18 18:42:05 +0100630 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530631 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
632 IEEE80211_STA_CONNECTION_POLL))
633 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
634
Johannes Berg62ae67b2009-11-18 18:42:05 +0100635 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200636}
637
Felix Fietkaud5242152010-01-08 18:06:26 +0100638static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
639 struct ieee80211_sub_if_data *sdata)
640{
641 struct sk_buff *skb;
642 struct ieee80211_hdr *nullfunc;
643 __le16 fc;
644
645 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
646 return;
647
648 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -0700649 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +0100650 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700651
Felix Fietkaud5242152010-01-08 18:06:26 +0100652 skb_reserve(skb, local->hw.extra_tx_headroom);
653
654 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
655 memset(nullfunc, 0, 30);
656 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
657 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
658 nullfunc->frame_control = fc;
659 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
660 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
661 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
662 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
663
664 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
665 ieee80211_tx_skb(sdata, skb);
666}
667
Johannes Bergcc32abd2009-05-15 11:52:31 +0200668/* spectrum management related things */
669static void ieee80211_chswitch_work(struct work_struct *work)
670{
671 struct ieee80211_sub_if_data *sdata =
672 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200673 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
674
Johannes Berg9607e6b2009-12-23 13:15:31 +0100675 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200676 return;
677
Johannes Berg77fdaa12009-07-07 03:45:17 +0200678 mutex_lock(&ifmgd->mtx);
679 if (!ifmgd->associated)
680 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200681
Johannes Berg55de9082012-07-26 17:24:39 +0200682 sdata->local->_oper_channel = sdata->local->csa_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200683 if (!sdata->local->ops->channel_switch) {
684 /* call "hw_config" only if doing sw channel switch */
685 ieee80211_hw_config(sdata->local,
686 IEEE80211_CONF_CHANGE_CHANNEL);
Shahar Levi1ea57b12011-09-08 08:44:05 +0300687 } else {
688 /* update the device channel directly */
Johannes Berg55de9082012-07-26 17:24:39 +0200689 sdata->local->hw.conf.channel = sdata->local->_oper_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200690 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200691
Johannes Berg77fdaa12009-07-07 03:45:17 +0200692 /* XXX: shouldn't really modify cfg80211-owned data! */
Johannes Berg55de9082012-07-26 17:24:39 +0200693 ifmgd->associated->channel = sdata->local->_oper_channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200694
Johannes Berg57eebdf2012-08-01 15:50:46 +0200695 /* XXX: wait for a beacon first? */
Johannes Bergcc32abd2009-05-15 11:52:31 +0200696 ieee80211_wake_queues_by_reason(&sdata->local->hw,
697 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200698 out:
699 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
700 mutex_unlock(&ifmgd->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200701}
702
Johannes Berg5ce6e432010-05-11 16:20:57 +0200703void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
704{
Johannes Berg55de9082012-07-26 17:24:39 +0200705 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
706 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200707
708 trace_api_chswitch_done(sdata, success);
709 if (!success) {
Johannes Berg882a7c62012-08-01 22:32:45 +0200710 sdata_info(sdata,
711 "driver channel switch failed, disconnecting\n");
712 ieee80211_queue_work(&sdata->local->hw,
713 &ifmgd->csa_connection_drop_work);
714 } else {
715 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg5ce6e432010-05-11 16:20:57 +0200716 }
Johannes Berg5ce6e432010-05-11 16:20:57 +0200717}
718EXPORT_SYMBOL(ieee80211_chswitch_done);
719
Johannes Bergcc32abd2009-05-15 11:52:31 +0200720static void ieee80211_chswitch_timer(unsigned long data)
721{
722 struct ieee80211_sub_if_data *sdata =
723 (struct ieee80211_sub_if_data *) data;
724 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
725
Johannes Berg5bb644a2009-05-17 11:40:42 +0200726 if (sdata->local->quiescing) {
727 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
728 return;
729 }
730
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400731 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200732}
733
734void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
735 struct ieee80211_channel_sw_ie *sw_elem,
Johannes Berg5ce6e432010-05-11 16:20:57 +0200736 struct ieee80211_bss *bss,
737 u64 timestamp)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200738{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100739 struct cfg80211_bss *cbss =
740 container_of((void *)bss, struct cfg80211_bss, priv);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200741 struct ieee80211_channel *new_ch;
742 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900743 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
744 cbss->channel->band);
Johannes Berg55de9082012-07-26 17:24:39 +0200745 struct ieee80211_chanctx *chanctx;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200746
Johannes Berg77fdaa12009-07-07 03:45:17 +0200747 ASSERT_MGD_MTX(ifmgd);
748
749 if (!ifmgd->associated)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200750 return;
751
Helmut Schaafbe9c422009-07-23 12:14:04 +0200752 if (sdata->local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200753 return;
754
755 /* Disregard subsequent beacons if we are already running a timer
756 processing a CSA */
757
758 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
759 return;
760
761 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
Johannes Berg882a7c62012-08-01 22:32:45 +0200762 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) {
763 sdata_info(sdata,
764 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
765 ifmgd->associated->bssid, new_freq);
766 ieee80211_queue_work(&sdata->local->hw,
767 &ifmgd->csa_connection_drop_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200768 return;
Johannes Berg882a7c62012-08-01 22:32:45 +0200769 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200770
Johannes Berg57eebdf2012-08-01 15:50:46 +0200771 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
772
Johannes Berg55de9082012-07-26 17:24:39 +0200773 if (sdata->local->use_chanctx) {
774 sdata_info(sdata,
775 "not handling channel switch with channel contexts\n");
776 ieee80211_queue_work(&sdata->local->hw,
777 &ifmgd->csa_connection_drop_work);
778 }
779
780 mutex_lock(&sdata->local->chanctx_mtx);
781 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
782 mutex_unlock(&sdata->local->chanctx_mtx);
783 return;
784 }
785 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
786 struct ieee80211_chanctx, conf);
787 if (chanctx->refcount > 1) {
788 sdata_info(sdata,
789 "channel switch with multiple interfaces on the same channel, disconnecting\n");
790 ieee80211_queue_work(&sdata->local->hw,
791 &ifmgd->csa_connection_drop_work);
792 mutex_unlock(&sdata->local->chanctx_mtx);
793 return;
794 }
795 mutex_unlock(&sdata->local->chanctx_mtx);
796
797 sdata->local->csa_channel = new_ch;
798
Johannes Berg57eebdf2012-08-01 15:50:46 +0200799 if (sw_elem->mode)
800 ieee80211_stop_queues_by_reason(&sdata->local->hw,
801 IEEE80211_QUEUE_STOP_REASON_CSA);
802
Johannes Berg5ce6e432010-05-11 16:20:57 +0200803 if (sdata->local->ops->channel_switch) {
804 /* use driver's channel switch callback */
Johannes Berg57eebdf2012-08-01 15:50:46 +0200805 struct ieee80211_channel_switch ch_switch = {
806 .timestamp = timestamp,
807 .block_tx = sw_elem->mode,
808 .channel = new_ch,
809 .count = sw_elem->count,
810 };
811
Johannes Berg5ce6e432010-05-11 16:20:57 +0200812 drv_channel_switch(sdata->local, &ch_switch);
813 return;
814 }
815
816 /* channel switch handled in software */
Johannes Berg57eebdf2012-08-01 15:50:46 +0200817 if (sw_elem->count <= 1)
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400818 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Berg57eebdf2012-08-01 15:50:46 +0200819 else
Johannes Bergcc32abd2009-05-15 11:52:31 +0200820 mod_timer(&ifmgd->chswitch_timer,
Johannes Berg30490002012-08-01 15:53:45 +0200821 TU_TO_EXP_TIME(sw_elem->count *
822 cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +0200823}
824
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200825static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
826 struct ieee80211_channel *channel,
827 const u8 *country_ie, u8 country_ie_len,
828 const u8 *pwr_constr_elem)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200829{
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200830 struct ieee80211_country_ie_triplet *triplet;
831 int chan = ieee80211_frequency_to_channel(channel->center_freq);
832 int i, chan_pwr, chan_increment, new_ap_level;
833 bool have_chan_pwr = false;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200834
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200835 /* Invalid IE */
836 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200837 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200838
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200839 triplet = (void *)(country_ie + 3);
840 country_ie_len -= 3;
841
842 switch (channel->band) {
843 default:
844 WARN_ON_ONCE(1);
845 /* fall through */
846 case IEEE80211_BAND_2GHZ:
847 case IEEE80211_BAND_60GHZ:
848 chan_increment = 1;
849 break;
850 case IEEE80211_BAND_5GHZ:
851 chan_increment = 4;
852 break;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200853 }
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200854
855 /* find channel */
856 while (country_ie_len >= 3) {
857 u8 first_channel = triplet->chans.first_channel;
858
859 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
860 goto next;
861
862 for (i = 0; i < triplet->chans.num_channels; i++) {
863 if (first_channel + i * chan_increment == chan) {
864 have_chan_pwr = true;
865 chan_pwr = triplet->chans.max_power;
866 break;
867 }
868 }
869 if (have_chan_pwr)
870 break;
871
872 next:
873 triplet++;
874 country_ie_len -= 3;
875 }
876
877 if (!have_chan_pwr)
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200878 return 0;
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200879
880 new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem);
881
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200882 if (sdata->ap_power_level == new_ap_level)
883 return 0;
Johannes Berg04b7b2f2012-09-05 13:41:37 +0200884
885 sdata_info(sdata,
886 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
887 new_ap_level, chan_pwr, *pwr_constr_elem,
888 sdata->u.mgd.bssid);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +0200889 sdata->ap_power_level = new_ap_level;
890 if (__ieee80211_recalc_txpower(sdata))
891 return BSS_CHANGED_TXPOWER;
892 return 0;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200893}
894
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300895void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
896{
897 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
898 struct ieee80211_local *local = sdata->local;
899 struct ieee80211_conf *conf = &local->hw.conf;
900
901 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
902 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
903 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
904
905 local->disable_dynamic_ps = false;
906 conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
907}
908EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
909
910void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
911{
912 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
913 struct ieee80211_local *local = sdata->local;
914 struct ieee80211_conf *conf = &local->hw.conf;
915
916 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
917 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
918 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
919
920 local->disable_dynamic_ps = true;
921 conf->dynamic_ps_timeout = 0;
922 del_timer_sync(&local->dynamic_ps_timer);
923 ieee80211_queue_work(&local->hw,
924 &local->dynamic_ps_enable_work);
925}
926EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
927
Johannes Berg965beda2009-04-16 13:17:24 +0200928/* powersave */
929static void ieee80211_enable_ps(struct ieee80211_local *local,
930 struct ieee80211_sub_if_data *sdata)
931{
932 struct ieee80211_conf *conf = &local->hw.conf;
933
Johannes Bergd5edaed2009-04-22 23:02:51 +0200934 /*
935 * If we are scanning right now then the parameters will
936 * take effect when scan finishes.
937 */
Helmut Schaafbe9c422009-07-23 12:14:04 +0200938 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +0200939 return;
940
Johannes Berg965beda2009-04-16 13:17:24 +0200941 if (conf->dynamic_ps_timeout > 0 &&
942 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
943 mod_timer(&local->dynamic_ps_timer, jiffies +
944 msecs_to_jiffies(conf->dynamic_ps_timeout));
945 } else {
946 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
947 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +0530948
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200949 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
950 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
951 return;
952
953 conf->flags |= IEEE80211_CONF_PS;
954 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +0200955 }
956}
957
958static void ieee80211_change_ps(struct ieee80211_local *local)
959{
960 struct ieee80211_conf *conf = &local->hw.conf;
961
962 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +0200963 ieee80211_enable_ps(local, local->ps_sdata);
964 } else if (conf->flags & IEEE80211_CONF_PS) {
965 conf->flags &= ~IEEE80211_CONF_PS;
966 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
967 del_timer_sync(&local->dynamic_ps_timer);
968 cancel_work_sync(&local->dynamic_ps_enable_work);
969 }
970}
971
Jason Young808118c2011-03-10 16:43:19 -0800972static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
973{
974 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
975 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200976 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -0800977
978 if (!mgd->powersave)
979 return false;
980
Johannes Berg05cb9102011-10-28 11:59:47 +0200981 if (mgd->broken_ap)
982 return false;
983
Jason Young808118c2011-03-10 16:43:19 -0800984 if (!mgd->associated)
985 return false;
986
Jason Young808118c2011-03-10 16:43:19 -0800987 if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
988 IEEE80211_STA_CONNECTION_POLL))
989 return false;
990
991 rcu_read_lock();
992 sta = sta_info_get(sdata, mgd->bssid);
993 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200994 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -0800995 rcu_read_unlock();
996
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200997 return authorized;
Jason Young808118c2011-03-10 16:43:19 -0800998}
999
Johannes Berg965beda2009-04-16 13:17:24 +02001000/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +02001001void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +02001002{
1003 struct ieee80211_sub_if_data *sdata, *found = NULL;
1004 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001005 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001006
1007 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
1008 local->ps_sdata = NULL;
1009 return;
1010 }
1011
1012 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01001013 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001014 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301015 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1016 /* If an AP vif is found, then disable PS
1017 * by setting the count to zero thereby setting
1018 * ps_sdata to NULL.
1019 */
1020 count = 0;
1021 break;
1022 }
Johannes Berg965beda2009-04-16 13:17:24 +02001023 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1024 continue;
1025 found = sdata;
1026 count++;
1027 }
1028
Jason Young808118c2011-03-10 16:43:19 -08001029 if (count == 1 && ieee80211_powersave_allowed(found)) {
Juuso Oikarinenf90754c2010-06-21 08:59:39 +03001030 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg10f644a2009-04-16 13:17:25 +02001031 s32 beaconint_us;
1032
1033 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +02001034 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +02001035
1036 beaconint_us = ieee80211_tu_to_usec(
1037 found->vif.bss_conf.beacon_int);
1038
Juuso Oikarinenff616382010-06-09 09:51:52 +03001039 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001040 if (timeout < 0) {
1041 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +03001042 * Go to full PSM if the user configures a very low
1043 * latency requirement.
Eliad Peller0ab82b02010-12-03 02:16:23 +02001044 * The 2000 second value is there for compatibility
1045 * until the PM_QOS_NETWORK_LATENCY is configured
1046 * with real values.
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001047 */
Eliad Peller0ab82b02010-12-03 02:16:23 +02001048 if (latency > (1900 * USEC_PER_MSEC) &&
1049 latency != (2000 * USEC_PER_SEC))
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001050 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001051 else
1052 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001053 }
Juuso Oikarinenf90754c2010-06-21 08:59:39 +03001054 local->dynamic_ps_user_timeout = timeout;
1055 if (!local->disable_dynamic_ps)
1056 conf->dynamic_ps_timeout =
1057 local->dynamic_ps_user_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001058
Johannes Berg04fe2032009-04-22 18:44:37 +02001059 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +02001060 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +02001061 } else {
Johannes Berg56007a02010-01-26 14:19:52 +01001062 struct ieee80211_bss *bss;
Johannes Berg04fe2032009-04-22 18:44:37 +02001063 int maxslp = 1;
Johannes Berg56007a02010-01-26 14:19:52 +01001064 u8 dtimper;
Johannes Berg04fe2032009-04-22 18:44:37 +02001065
Johannes Berg56007a02010-01-26 14:19:52 +01001066 bss = (void *)found->u.mgd.associated->priv;
1067 dtimper = bss->dtim_period;
1068
1069 /* If the TIM IE is invalid, pretend the value is 1 */
1070 if (!dtimper)
1071 dtimper = 1;
1072 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +02001073 maxslp = min_t(int, dtimper,
1074 latency / beaconint_us);
1075
Johannes Berg9ccebe62009-04-23 10:32:36 +02001076 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +01001077 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +02001078 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +02001079 }
Johannes Berg10f644a2009-04-16 13:17:25 +02001080 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001081 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001082 }
Johannes Berg965beda2009-04-16 13:17:24 +02001083
1084 ieee80211_change_ps(local);
1085}
1086
Eliad Pellerab095872012-07-27 12:33:22 +03001087void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1088{
1089 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1090
1091 if (sdata->vif.bss_conf.ps != ps_allowed) {
1092 sdata->vif.bss_conf.ps = ps_allowed;
1093 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1094 }
1095}
1096
Johannes Berg965beda2009-04-16 13:17:24 +02001097void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1098{
1099 struct ieee80211_local *local =
1100 container_of(work, struct ieee80211_local,
1101 dynamic_ps_disable_work);
1102
1103 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1104 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1105 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1106 }
1107
1108 ieee80211_wake_queues_by_reason(&local->hw,
1109 IEEE80211_QUEUE_STOP_REASON_PS);
1110}
1111
1112void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1113{
1114 struct ieee80211_local *local =
1115 container_of(work, struct ieee80211_local,
1116 dynamic_ps_enable_work);
1117 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001118 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301119 unsigned long flags;
1120 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001121
1122 /* can only happen when PS was just disabled anyway */
1123 if (!sdata)
1124 return;
1125
Christian Lamparter5e340692011-06-30 21:08:43 +02001126 ifmgd = &sdata->u.mgd;
1127
Johannes Berg965beda2009-04-16 13:17:24 +02001128 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1129 return;
1130
Arik Nemtsov77b70232011-06-26 12:06:54 +03001131 if (!local->disable_dynamic_ps &&
1132 local->hw.conf.dynamic_ps_timeout > 0) {
1133 /* don't enter PS if TX frames are pending */
1134 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301135 mod_timer(&local->dynamic_ps_timer, jiffies +
1136 msecs_to_jiffies(
1137 local->hw.conf.dynamic_ps_timeout));
1138 return;
1139 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001140
1141 /*
1142 * transmission can be stopped by others which leads to
1143 * dynamic_ps_timer expiry. Postpone the ps timer if it
1144 * is not the actual idle state.
1145 */
1146 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1147 for (q = 0; q < local->hw.queues; q++) {
1148 if (local->queue_stop_reasons[q]) {
1149 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1150 flags);
1151 mod_timer(&local->dynamic_ps_timer, jiffies +
1152 msecs_to_jiffies(
1153 local->hw.conf.dynamic_ps_timeout));
1154 return;
1155 }
1156 }
1157 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301158 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301159
Vivek Natarajan375177b2010-02-09 14:50:28 +05301160 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301161 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301162 netif_tx_stop_all_queues(sdata->dev);
Johannes Berg965beda2009-04-16 13:17:24 +02001163
Vivek Natarajane8306f92011-04-06 11:41:10 +05301164 if (drv_tx_frames_pending(local))
1165 mod_timer(&local->dynamic_ps_timer, jiffies +
1166 msecs_to_jiffies(
1167 local->hw.conf.dynamic_ps_timeout));
1168 else {
1169 ieee80211_send_nullfunc(local, sdata, 1);
1170 /* Flush to get the tx status of nullfunc frame */
1171 drv_flush(local, false);
1172 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301173 }
1174
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001175 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
1176 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301177 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1178 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1179 local->hw.conf.flags |= IEEE80211_CONF_PS;
1180 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1181 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301182
Arik Nemtsov77b70232011-06-26 12:06:54 +03001183 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1184 netif_tx_wake_all_queues(sdata->dev);
Johannes Berg965beda2009-04-16 13:17:24 +02001185}
1186
1187void ieee80211_dynamic_ps_timer(unsigned long data)
1188{
1189 struct ieee80211_local *local = (void *) data;
1190
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -07001191 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +02001192 return;
1193
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001194 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001195}
1196
Johannes Berg60f8b392008-09-08 17:44:22 +02001197/* MLME */
Johannes Berg7d257452012-07-06 17:37:43 +02001198static bool ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +02001199 struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001200 u8 *wmm_param, size_t wmm_param_len)
1201{
Jiri Bencf0706e82007-05-05 11:45:53 -07001202 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +02001203 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001204 size_t left;
1205 int count;
Kalle Valoab133152010-01-12 10:42:31 +02001206 u8 *pos, uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001207
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001208 if (!local->ops->conf_tx)
Johannes Berg7d257452012-07-06 17:37:43 +02001209 return false;
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001210
Johannes Berg32c50572012-03-28 11:04:29 +02001211 if (local->hw.queues < IEEE80211_NUM_ACS)
Johannes Berg7d257452012-07-06 17:37:43 +02001212 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001213
1214 if (!wmm_param)
Johannes Berg7d257452012-07-06 17:37:43 +02001215 return false;
Johannes Berg3434fbd2008-05-03 00:59:37 +02001216
Jiri Bencf0706e82007-05-05 11:45:53 -07001217 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
Johannes Berg7d257452012-07-06 17:37:43 +02001218 return false;
Kalle Valoab133152010-01-12 10:42:31 +02001219
1220 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001221 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001222
Jiri Bencf0706e82007-05-05 11:45:53 -07001223 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +01001224 if (count == ifmgd->wmm_last_param_set)
Johannes Berg7d257452012-07-06 17:37:43 +02001225 return false;
Johannes Berg46900292009-02-15 12:44:28 +01001226 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -07001227
1228 pos = wmm_param + 8;
1229 left = wmm_param_len - 8;
1230
1231 memset(&params, 0, sizeof(params));
1232
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001233 sdata->wmm_acm = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001234 for (; left >= 4; left -= 4, pos += 4) {
1235 int aci = (pos[0] >> 5) & 0x03;
1236 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001237 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001238 int queue;
1239
1240 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001241 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +02001242 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +02001243 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001244 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001245 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1246 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001247 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001248 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +02001249 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +02001250 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001251 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001252 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1253 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001254 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001255 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +02001256 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +02001257 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001258 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02001259 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1260 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001261 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001262 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001263 default:
Johannes Berge100bb62008-04-30 18:51:21 +02001264 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +02001265 if (acm)
Yoni Divinsky00e96de2012-06-20 15:39:13 +03001266 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02001267 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1268 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001269 break;
1270 }
1271
1272 params.aifs = pos[0] & 0x0f;
1273 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1274 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +02001275 params.txop = get_unaligned_le16(pos + 2);
Kalle Valoab133152010-01-12 10:42:31 +02001276 params.uapsd = uapsd;
1277
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001278 mlme_dbg(sdata,
1279 "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
1280 queue, aci, acm,
1281 params.aifs, params.cw_min, params.cw_max,
1282 params.txop, params.uapsd);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001283 sdata->tx_conf[queue] = params;
1284 if (drv_conf_tx(local, sdata, queue, &params))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001285 sdata_err(sdata,
1286 "failed to set TX queue parameters for queue %d\n",
1287 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -07001288 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001289
1290 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02001291 sdata->vif.bss_conf.qos = true;
Johannes Berg7d257452012-07-06 17:37:43 +02001292 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001293}
1294
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001295static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1296{
1297 lockdep_assert_held(&sdata->local->mtx);
1298
1299 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1300 IEEE80211_STA_BEACON_POLL);
1301 ieee80211_run_deferred_scan(sdata->local);
1302}
1303
1304static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
1305{
1306 mutex_lock(&sdata->local->mtx);
1307 __ieee80211_stop_poll(sdata);
1308 mutex_unlock(&sdata->local->mtx);
1309}
1310
Johannes Berg7a5158e2008-10-08 10:59:33 +02001311static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1312 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02001313{
Johannes Bergbda39332008-10-11 01:51:51 +02001314 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001315 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001316 bool use_protection;
1317 bool use_short_preamble;
1318 bool use_short_slot;
1319
1320 if (erp_valid) {
1321 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1322 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1323 } else {
1324 use_protection = false;
1325 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1326 }
1327
1328 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Johannes Berg55de9082012-07-26 17:24:39 +02001329 if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ)
Felix Fietkau43d35342010-01-15 03:00:48 +01001330 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02001331
Johannes Berg471b3ef2007-12-28 14:32:58 +01001332 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01001333 bss_conf->use_cts_prot = use_protection;
1334 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02001335 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02001336
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001337 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001338 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001339 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02001340 }
Daniel Draked9430a32007-07-27 15:43:24 +02001341
Johannes Berg7a5158e2008-10-08 10:59:33 +02001342 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02001343 bss_conf->use_short_slot = use_short_slot;
1344 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04001345 }
1346
1347 return changed;
1348}
1349
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001350static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001351 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02001352 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -07001353{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001354 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001355 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001356 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001357
Johannes Bergae5eb022008-10-14 16:58:37 +02001358 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001359 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Luciano Coelho50ae34a2012-06-20 17:23:24 +03001360 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001361
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01001362 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
1363 IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
1364
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001365 sdata->u.mgd.associated = cbss;
1366 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01001367
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001368 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1369
Johannes Berg488dd7b2012-10-29 20:08:01 +01001370 if (sdata->vif.p2p) {
1371 u8 noa[2];
1372 int ret;
1373
1374 ret = cfg80211_get_p2p_attr(cbss->information_elements,
1375 cbss->len_information_elements,
1376 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
1377 noa, sizeof(noa));
1378 if (ret >= 2) {
1379 bss_conf->p2p_oppps = noa[1] & 0x80;
1380 bss_conf->p2p_ctwindow = noa[1] & 0x7f;
1381 bss_info_changed |= BSS_CHANGED_P2P_PS;
1382 sdata->u.mgd.p2p_noa_index = noa[0];
1383 }
1384 }
1385
Johannes Bergb291ba12009-07-10 15:29:03 +02001386 /* just to be sure */
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001387 ieee80211_stop_poll(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001388
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001389 ieee80211_led_assoc(local, 1);
1390
Johannes Berge5b900d2010-07-29 16:08:55 +02001391 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
1392 bss_conf->dtim_period = bss->dtim_period;
1393 else
1394 bss_conf->dtim_period = 0;
1395
Juuso Oikarinen68542962010-06-09 13:43:26 +03001396 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02001397
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001398 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01001399 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03001400 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001401 bss_info_changed |= BSS_CHANGED_CQM;
1402
Juuso Oikarinen68542962010-06-09 13:43:26 +03001403 /* Enable ARP filtering */
1404 if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
1405 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
1406 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
1407 }
1408
Johannes Bergae5eb022008-10-14 16:58:37 +02001409 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03001410
Johannes Berg056508d2009-07-30 21:43:55 +02001411 mutex_lock(&local->iflist_mtx);
1412 ieee80211_recalc_ps(local, -1);
1413 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02001414
Johannes Berg04ecd252012-09-11 14:34:12 +02001415 ieee80211_recalc_smps(sdata);
Eliad Pellerab095872012-07-27 12:33:22 +03001416 ieee80211_recalc_ps_vif(sdata);
1417
John W. Linville8a5b33f2010-01-06 15:39:39 -05001418 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001419 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001420}
1421
Jouni Malinene69e95d2010-03-29 23:29:31 -07001422static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01001423 u16 stype, u16 reason, bool tx,
1424 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03001425{
Johannes Berg46900292009-02-15 12:44:28 +01001426 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001427 struct ieee80211_local *local = sdata->local;
1428 struct sta_info *sta;
Johannes Berg3cc52402012-03-09 13:12:35 +01001429 u32 changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001430
Johannes Berg77fdaa12009-07-07 03:45:17 +02001431 ASSERT_MGD_MTX(ifmgd);
1432
Johannes Berg37ad3882012-02-24 13:50:54 +01001433 if (WARN_ON_ONCE(tx && !frame_buf))
1434 return;
1435
Johannes Bergb291ba12009-07-10 15:29:03 +02001436 if (WARN_ON(!ifmgd->associated))
1437 return;
1438
David Spinadel79543d82012-06-12 09:59:45 +03001439 ieee80211_stop_poll(sdata);
1440
Johannes Berg77fdaa12009-07-07 03:45:17 +02001441 ifmgd->associated = NULL;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001442
1443 /*
1444 * we need to commit the associated = NULL change because the
1445 * scan code uses that to determine whether this iface should
1446 * go to/wake up from powersave or not -- and could otherwise
1447 * wake the queues erroneously.
1448 */
1449 smp_mb();
1450
1451 /*
1452 * Thus, we can only afterwards stop the queues -- to account
1453 * for the case where another CPU is finishing a scan at this
1454 * time -- we don't want the scan code to enable queues.
1455 */
Tomas Winkleraa458d12008-09-09 00:32:12 +03001456
John W. Linville8a5b33f2010-01-06 15:39:39 -05001457 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001458 netif_carrier_off(sdata->dev);
1459
Johannes Berg2a419052010-06-10 10:21:29 +02001460 mutex_lock(&local->sta_mtx);
Eliad Peller88a9e312012-06-01 11:14:03 +03001461 sta = sta_info_get(sdata, ifmgd->bssid);
Sujith4cad6c72010-02-10 14:52:21 +05301462 if (sta) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001463 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
Johannes Berg7f161142012-07-18 12:53:34 +02001464 ieee80211_sta_tear_down_BA_sessions(sta, false);
Sujith4cad6c72010-02-10 14:52:21 +05301465 }
Johannes Berg2a419052010-06-10 10:21:29 +02001466 mutex_unlock(&local->sta_mtx);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001467
Eliad Peller88bc40e2012-07-12 17:35:33 +03001468 /*
1469 * if we want to get out of ps before disassoc (why?) we have
1470 * to do it before sending disassoc, as otherwise the null-packet
1471 * won't be valid.
1472 */
1473 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1474 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1475 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1476 }
1477 local->ps_sdata = NULL;
1478
Eliad Pellerab095872012-07-27 12:33:22 +03001479 /* disable per-vif ps */
1480 ieee80211_recalc_ps_vif(sdata);
1481
Eliad Pellerf8239812012-06-27 14:18:22 +03001482 /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
1483 if (tx)
1484 drv_flush(local, false);
1485
Johannes Berg37ad3882012-02-24 13:50:54 +01001486 /* deauthenticate/disassociate now */
1487 if (tx || frame_buf)
Eliad Peller88a9e312012-06-01 11:14:03 +03001488 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
1489 reason, tx, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01001490
1491 /* flush out frame */
1492 if (tx)
1493 drv_flush(local, false);
1494
Eliad Peller88a9e312012-06-01 11:14:03 +03001495 /* clear bssid only after building the needed mgmt frames */
1496 memset(ifmgd->bssid, 0, ETH_ALEN);
1497
Johannes Berg37ad3882012-02-24 13:50:54 +01001498 /* remove AP and TDLS peers */
1499 sta_info_flush(local, sdata);
1500
1501 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001502 changed |= ieee80211_reset_erp_info(sdata);
1503
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001504 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001505 changed |= BSS_CHANGED_ASSOC;
1506 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001507
Johannes Berg488dd7b2012-10-29 20:08:01 +01001508 sdata->vif.bss_conf.p2p_ctwindow = 0;
1509 sdata->vif.bss_conf.p2p_oppps = false;
1510
Johannes Berg413ad502009-05-08 21:21:06 +02001511 /* on the next assoc, re-program HT parameters */
Ben Greearef96a8422011-11-18 11:32:00 -08001512 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
1513 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Berg413ad502009-05-08 21:21:06 +02001514
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02001515 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301516
Kalle Valo520eb822008-12-18 23:35:27 +02001517 del_timer_sync(&local->dynamic_ps_timer);
1518 cancel_work_sync(&local->dynamic_ps_enable_work);
1519
Juuso Oikarinen68542962010-06-09 13:43:26 +03001520 /* Disable ARP filtering */
1521 if (sdata->vif.bss_conf.arp_filter_enabled) {
1522 sdata->vif.bss_conf.arp_filter_enabled = false;
1523 changed |= BSS_CHANGED_ARP_FILTER;
1524 }
1525
Johannes Berg3abead52012-03-02 15:56:59 +01001526 sdata->vif.bss_conf.qos = false;
1527 changed |= BSS_CHANGED_QOS;
1528
Johannes Berg0aaffa92010-05-05 15:28:27 +02001529 /* The BSSID (not really interesting) and HT changed */
1530 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001531 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001532
Johannes Berg3abead52012-03-02 15:56:59 +01001533 /* disassociated - set to defaults now */
1534 ieee80211_set_wmm_default(sdata, false);
1535
Johannes Bergb9dcf712010-08-27 12:35:54 +02001536 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1537 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1538 del_timer_sync(&sdata->u.mgd.timer);
1539 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Johannes Berg2d9957c2012-08-01 20:54:52 +02001540
1541 sdata->u.mgd.timers_running = 0;
Johannes Berg028e8da02012-11-26 11:57:41 +01001542
1543 ifmgd->flags = 0;
1544 ieee80211_vif_release_channel(sdata);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001545}
Jiri Bencf0706e82007-05-05 11:45:53 -07001546
Kalle Valo3cf335d2009-03-22 21:57:06 +02001547void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1548 struct ieee80211_hdr *hdr)
1549{
1550 /*
1551 * We can postpone the mgd.timer whenever receiving unicast frames
1552 * from AP because we know that the connection is working both ways
1553 * at that time. But multicast frames (and hence also beacons) must
1554 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001555 * data idle periods for sending the periodic probe request to the
1556 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001557 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001558 if (is_multicast_ether_addr(hdr->addr1))
1559 return;
1560
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001561 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02001562}
Jiri Bencf0706e82007-05-05 11:45:53 -07001563
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001564static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1565{
1566 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001567 struct ieee80211_local *local = sdata->local;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001568
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001569 mutex_lock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001570 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001571 IEEE80211_STA_CONNECTION_POLL))) {
1572 mutex_unlock(&local->mtx);
1573 return;
1574 }
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001575
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02001576 __ieee80211_stop_poll(sdata);
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001577
1578 mutex_lock(&local->iflist_mtx);
1579 ieee80211_recalc_ps(local, -1);
1580 mutex_unlock(&local->iflist_mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001581
1582 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001583 goto out;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001584
1585 /*
1586 * We've received a probe response, but are not sure whether
1587 * we have or will be receiving any beacons or data, so let's
1588 * schedule the timers again, just in case.
1589 */
1590 ieee80211_sta_reset_beacon_monitor(sdata);
1591
1592 mod_timer(&ifmgd->conn_mon_timer,
1593 round_jiffies_up(jiffies +
1594 IEEE80211_CONNECTION_IDLE_TIME));
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001595out:
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001596 mutex_unlock(&local->mtx);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001597}
1598
1599void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001600 struct ieee80211_hdr *hdr, bool ack)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001601{
Felix Fietkau75706d02010-12-02 21:01:07 +01001602 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001603 return;
1604
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001605 if (ack)
1606 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001607
1608 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1609 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001610 if (ack)
1611 sdata->u.mgd.probe_send_count = 0;
1612 else
1613 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001614 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1615 }
1616}
1617
Maxim Levitskya43abf22009-07-31 18:54:12 +03001618static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1619{
1620 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1621 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001622 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08001623 u8 unicast_limit = max(1, max_probe_tries - 3);
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001624
1625 /*
1626 * Try sending broadcast probe requests for the last three
1627 * probe requests after the first ones failed since some
1628 * buggy APs only support broadcast probe requests.
1629 */
1630 if (ifmgd->probe_send_count >= unicast_limit)
1631 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03001632
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001633 /*
1634 * When the hardware reports an accurate Tx ACK status, it's
1635 * better to send a nullfunc frame instead of a probe request,
1636 * as it will kick us off the AP quickly if we aren't associated
1637 * anymore. The timeout will be reset if the frame is ACKed by
1638 * the AP.
1639 */
Soumik Das992e68b2012-05-20 15:31:13 +05301640 ifmgd->probe_send_count++;
1641
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001642 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1643 ifmgd->nullfunc_failed = false;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001644 ieee80211_send_nullfunc(sdata->local, sdata, 0);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001645 } else {
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02001646 int ssid_len;
1647
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001648 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02001649 if (WARN_ON_ONCE(ssid == NULL))
1650 ssid_len = 0;
1651 else
1652 ssid_len = ssid[1];
1653
1654 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL,
Johannes Bergfe94fe02012-07-30 12:26:34 +02001655 0, (u32) -1, true, false,
Johannes Berg55de9082012-07-26 17:24:39 +02001656 ifmgd->associated->channel, false);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001657 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03001658
Ben Greear180205b2011-02-04 15:30:24 -08001659 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Maxim Levitskya43abf22009-07-31 18:54:12 +03001660 run_again(ifmgd, ifmgd->probe_timeout);
Rajkumar Manoharanf69b9c72012-03-15 06:15:26 +05301661 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
1662 drv_flush(sdata->local, false);
Maxim Levitskya43abf22009-07-31 18:54:12 +03001663}
1664
Johannes Bergb291ba12009-07-10 15:29:03 +02001665static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1666 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02001667{
Kalle Valo04de8382009-03-22 21:57:35 +02001668 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02001669 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02001670
Johannes Berg9607e6b2009-12-23 13:15:31 +01001671 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02001672 return;
1673
Johannes Berg77fdaa12009-07-07 03:45:17 +02001674 mutex_lock(&ifmgd->mtx);
1675
1676 if (!ifmgd->associated)
1677 goto out;
1678
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001679 mutex_lock(&sdata->local->mtx);
1680
1681 if (sdata->local->tmp_channel || sdata->local->scanning) {
1682 mutex_unlock(&sdata->local->mtx);
1683 goto out;
1684 }
1685
Joe Perchese87cc472012-05-13 21:56:26 +00001686 if (beacon)
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001687 mlme_dbg_ratelimited(sdata,
1688 "detected beacon loss from AP - sending probe request\n");
1689
Holger Schurig6efb71b2012-05-15 15:38:59 +02001690 ieee80211_cqm_rssi_notify(&sdata->vif,
1691 NL80211_CQM_RSSI_BEACON_LOSS_EVENT, GFP_KERNEL);
Kalle Valo04de8382009-03-22 21:57:35 +02001692
Johannes Bergb291ba12009-07-10 15:29:03 +02001693 /*
1694 * The driver/our work has already reported this event or the
1695 * connection monitoring has kicked in and we have already sent
1696 * a probe request. Or maybe the AP died and the driver keeps
1697 * reporting until we disassociate...
1698 *
1699 * In either case we have to ignore the current call to this
1700 * function (except for setting the correct probe reason bit)
1701 * because otherwise we would reset the timer every time and
1702 * never check whether we received a probe response!
1703 */
1704 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1705 IEEE80211_STA_CONNECTION_POLL))
1706 already = true;
1707
1708 if (beacon)
1709 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1710 else
1711 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1712
Stanislaw Gruszka133d40f2012-03-28 16:01:19 +02001713 mutex_unlock(&sdata->local->mtx);
1714
Johannes Bergb291ba12009-07-10 15:29:03 +02001715 if (already)
1716 goto out;
1717
Johannes Berg4e751842009-06-10 15:16:52 +02001718 mutex_lock(&sdata->local->iflist_mtx);
1719 ieee80211_recalc_ps(sdata->local, -1);
1720 mutex_unlock(&sdata->local->iflist_mtx);
1721
Maxim Levitskya43abf22009-07-31 18:54:12 +03001722 ifmgd->probe_send_count = 0;
1723 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001724 out:
1725 mutex_unlock(&ifmgd->mtx);
Kalle Valo04de8382009-03-22 21:57:35 +02001726}
1727
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001728struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
1729 struct ieee80211_vif *vif)
1730{
1731 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1732 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Eliad Pellerd9b3b282012-06-28 15:03:13 +03001733 struct cfg80211_bss *cbss;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001734 struct sk_buff *skb;
1735 const u8 *ssid;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02001736 int ssid_len;
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001737
1738 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1739 return NULL;
1740
1741 ASSERT_MGD_MTX(ifmgd);
1742
Eliad Pellerd9b3b282012-06-28 15:03:13 +03001743 if (ifmgd->associated)
1744 cbss = ifmgd->associated;
1745 else if (ifmgd->auth_data)
1746 cbss = ifmgd->auth_data->bss;
1747 else if (ifmgd->assoc_data)
1748 cbss = ifmgd->assoc_data->bss;
1749 else
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001750 return NULL;
1751
Eliad Pellerd9b3b282012-06-28 15:03:13 +03001752 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02001753 if (WARN_ON_ONCE(ssid == NULL))
1754 ssid_len = 0;
1755 else
1756 ssid_len = ssid[1];
1757
Eliad Pellerd9b3b282012-06-28 15:03:13 +03001758 skb = ieee80211_build_probe_req(sdata, cbss->bssid,
Johannes Berg55de9082012-07-26 17:24:39 +02001759 (u32) -1, cbss->channel,
Johannes Berg6b778632012-07-23 14:53:27 +02001760 ssid + 2, ssid_len,
Johannes Berg85a237f2011-07-18 18:08:36 +02001761 NULL, 0, true);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001762
1763 return skb;
1764}
1765EXPORT_SYMBOL(ieee80211_ap_probereq_get);
1766
Johannes Berg882a7c62012-08-01 22:32:45 +02001767static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata,
1768 bool transmit_frame)
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001769{
1770 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1771 struct ieee80211_local *local = sdata->local;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02001772 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001773
1774 mutex_lock(&ifmgd->mtx);
1775 if (!ifmgd->associated) {
1776 mutex_unlock(&ifmgd->mtx);
1777 return;
1778 }
1779
Johannes Berg37ad3882012-02-24 13:50:54 +01001780 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
1781 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Johannes Berg882a7c62012-08-01 22:32:45 +02001782 transmit_frame, frame_buf);
1783 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001784 mutex_unlock(&ifmgd->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001785
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001786 /*
1787 * must be outside lock due to cfg80211,
1788 * but that's not a problem.
1789 */
Antonio Quartulli6ae16772012-09-07 13:28:52 +02001790 cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN);
Felix Fietkaufcac4fb2011-11-16 13:34:55 +01001791
1792 mutex_lock(&local->mtx);
1793 ieee80211_recalc_idle(local);
1794 mutex_unlock(&local->mtx);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001795}
1796
Johannes Bergcc74c0c2012-08-01 16:49:34 +02001797static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02001798{
1799 struct ieee80211_sub_if_data *sdata =
1800 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001801 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08001802 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1803 struct sta_info *sta;
1804
1805 if (ifmgd->associated) {
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05301806 rcu_read_lock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08001807 sta = sta_info_get(sdata, ifmgd->bssid);
1808 if (sta)
1809 sta->beacon_loss_count++;
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05301810 rcu_read_unlock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08001811 }
Johannes Bergb291ba12009-07-10 15:29:03 +02001812
Johannes Berg882a7c62012-08-01 22:32:45 +02001813 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) {
1814 sdata_info(sdata, "Connection to AP %pM lost\n",
1815 ifmgd->bssid);
1816 __ieee80211_disconnect(sdata, false);
1817 } else {
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001818 ieee80211_mgd_probe_ap(sdata, true);
Johannes Berg882a7c62012-08-01 22:32:45 +02001819 }
1820}
1821
1822static void ieee80211_csa_connection_drop_work(struct work_struct *work)
1823{
1824 struct ieee80211_sub_if_data *sdata =
1825 container_of(work, struct ieee80211_sub_if_data,
1826 u.mgd.csa_connection_drop_work);
1827
1828 ieee80211_wake_queues_by_reason(&sdata->local->hw,
1829 IEEE80211_QUEUE_STOP_REASON_CSA);
1830 __ieee80211_disconnect(sdata, true);
Johannes Bergb291ba12009-07-10 15:29:03 +02001831}
1832
Kalle Valo04de8382009-03-22 21:57:35 +02001833void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1834{
1835 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001836 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02001837
Johannes Bergb5878a22010-04-07 16:48:40 +02001838 trace_api_beacon_loss(sdata);
1839
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001840 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
1841 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02001842}
1843EXPORT_SYMBOL(ieee80211_beacon_loss);
1844
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001845void ieee80211_connection_loss(struct ieee80211_vif *vif)
1846{
1847 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1848 struct ieee80211_hw *hw = &sdata->local->hw;
1849
Johannes Bergb5878a22010-04-07 16:48:40 +02001850 trace_api_connection_loss(sdata);
1851
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001852 WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
1853 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1854}
1855EXPORT_SYMBOL(ieee80211_connection_loss);
1856
1857
Johannes Berg66e67e42012-01-20 13:55:27 +01001858static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
1859 bool assoc)
1860{
1861 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
1862
1863 lockdep_assert_held(&sdata->u.mgd.mtx);
1864
Johannes Berg66e67e42012-01-20 13:55:27 +01001865 if (!assoc) {
1866 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
1867
1868 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
1869 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01001870 sdata->u.mgd.flags = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02001871 ieee80211_vif_release_channel(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01001872 }
1873
1874 cfg80211_put_bss(auth_data->bss);
1875 kfree(auth_data);
1876 sdata->u.mgd.auth_data = NULL;
1877}
1878
1879static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1880 struct ieee80211_mgmt *mgmt, size_t len)
1881{
1882 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
1883 u8 *pos;
1884 struct ieee802_11_elems elems;
1885
1886 pos = mgmt->u.auth.variable;
1887 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1888 if (!elems.challenge)
1889 return;
1890 auth_data->expected_transaction = 4;
Johannes Berga1845fc2012-06-27 13:18:36 +02001891 drv_mgd_prepare_tx(sdata->local, sdata);
Jouni Malinen700e8ea2012-09-30 19:29:37 +03001892 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
Johannes Berg66e67e42012-01-20 13:55:27 +01001893 elems.challenge - 2, elems.challenge_len + 2,
1894 auth_data->bss->bssid, auth_data->bss->bssid,
1895 auth_data->key, auth_data->key_len,
1896 auth_data->key_idx);
1897}
1898
1899static enum rx_mgmt_action __must_check
1900ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1901 struct ieee80211_mgmt *mgmt, size_t len)
1902{
1903 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1904 u8 bssid[ETH_ALEN];
1905 u16 auth_alg, auth_transaction, status_code;
1906 struct sta_info *sta;
1907
1908 lockdep_assert_held(&ifmgd->mtx);
1909
1910 if (len < 24 + 6)
1911 return RX_MGMT_NONE;
1912
1913 if (!ifmgd->auth_data || ifmgd->auth_data->done)
1914 return RX_MGMT_NONE;
1915
1916 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
1917
Joe Perchesb203ca32012-05-08 18:56:52 +00001918 if (!ether_addr_equal(bssid, mgmt->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01001919 return RX_MGMT_NONE;
1920
1921 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1922 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1923 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1924
1925 if (auth_alg != ifmgd->auth_data->algorithm ||
Jouni Malinen0f4126e2012-09-30 19:29:38 +03001926 auth_transaction != ifmgd->auth_data->expected_transaction) {
1927 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
1928 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
1929 auth_transaction,
1930 ifmgd->auth_data->expected_transaction);
Johannes Berg66e67e42012-01-20 13:55:27 +01001931 return RX_MGMT_NONE;
Jouni Malinen0f4126e2012-09-30 19:29:38 +03001932 }
Johannes Berg66e67e42012-01-20 13:55:27 +01001933
1934 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001935 sdata_info(sdata, "%pM denied authentication (status %d)\n",
1936 mgmt->sa, status_code);
Eliad Pellerdac211e2012-05-13 18:07:04 +03001937 ieee80211_destroy_auth_data(sdata, false);
1938 return RX_MGMT_CFG80211_RX_AUTH;
Johannes Berg66e67e42012-01-20 13:55:27 +01001939 }
1940
1941 switch (ifmgd->auth_data->algorithm) {
1942 case WLAN_AUTH_OPEN:
1943 case WLAN_AUTH_LEAP:
1944 case WLAN_AUTH_FT:
Jouni Malinen6b8ece32012-09-30 19:29:40 +03001945 case WLAN_AUTH_SAE:
Johannes Berg66e67e42012-01-20 13:55:27 +01001946 break;
1947 case WLAN_AUTH_SHARED_KEY:
1948 if (ifmgd->auth_data->expected_transaction != 4) {
1949 ieee80211_auth_challenge(sdata, mgmt, len);
1950 /* need another frame */
1951 return RX_MGMT_NONE;
1952 }
1953 break;
1954 default:
1955 WARN_ONCE(1, "invalid auth alg %d",
1956 ifmgd->auth_data->algorithm);
1957 return RX_MGMT_NONE;
1958 }
1959
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001960 sdata_info(sdata, "authenticated\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01001961 ifmgd->auth_data->done = true;
1962 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
1963 run_again(ifmgd, ifmgd->auth_data->timeout);
1964
Jouni Malinen6b8ece32012-09-30 19:29:40 +03001965 if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
1966 ifmgd->auth_data->expected_transaction != 2) {
1967 /*
1968 * Report auth frame to user space for processing since another
1969 * round of Authentication frames is still needed.
1970 */
1971 return RX_MGMT_CFG80211_RX_AUTH;
1972 }
1973
Johannes Berg66e67e42012-01-20 13:55:27 +01001974 /* move station state to auth */
1975 mutex_lock(&sdata->local->sta_mtx);
1976 sta = sta_info_get(sdata, bssid);
1977 if (!sta) {
1978 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
1979 goto out_err;
1980 }
1981 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02001982 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01001983 goto out_err;
1984 }
1985 mutex_unlock(&sdata->local->sta_mtx);
1986
1987 return RX_MGMT_CFG80211_RX_AUTH;
1988 out_err:
1989 mutex_unlock(&sdata->local->sta_mtx);
1990 /* ignore frame -- wait for timeout */
1991 return RX_MGMT_NONE;
1992}
1993
1994
Johannes Berg77fdaa12009-07-07 03:45:17 +02001995static enum rx_mgmt_action __must_check
1996ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001997 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001998{
Johannes Berg46900292009-02-15 12:44:28 +01001999 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002000 const u8 *bssid = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07002001 u16 reason_code;
2002
Johannes Berg66e67e42012-01-20 13:55:27 +01002003 lockdep_assert_held(&ifmgd->mtx);
2004
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002005 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002006 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002007
Johannes Berg66e67e42012-01-20 13:55:27 +01002008 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002009 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002010 return RX_MGMT_NONE;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002011
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002012 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002013
2014 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
2015
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002016 sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n",
2017 bssid, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002018
Johannes Berg37ad3882012-02-24 13:50:54 +01002019 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2020
Johannes Berg7da7cc12010-08-05 17:02:38 +02002021 mutex_lock(&sdata->local->mtx);
Johannes Berg63f170e2009-12-23 13:15:33 +01002022 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002023 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002024
2025 return RX_MGMT_CFG80211_DEAUTH;
Jiri Bencf0706e82007-05-05 11:45:53 -07002026}
2027
2028
Johannes Berg77fdaa12009-07-07 03:45:17 +02002029static enum rx_mgmt_action __must_check
2030ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
2031 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002032{
Johannes Berg46900292009-02-15 12:44:28 +01002033 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002034 u16 reason_code;
2035
Johannes Berg66e67e42012-01-20 13:55:27 +01002036 lockdep_assert_held(&ifmgd->mtx);
2037
Johannes Bergf4ea83d2008-06-30 15:10:46 +02002038 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002039 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002040
Johannes Berg66e67e42012-01-20 13:55:27 +01002041 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002042 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg77fdaa12009-07-07 03:45:17 +02002043 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002044
2045 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
2046
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002047 sdata_info(sdata, "disassociated from %pM (Reason: %u)\n",
2048 mgmt->sa, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07002049
Johannes Berg37ad3882012-02-24 13:50:54 +01002050 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
2051
Johannes Berg7da7cc12010-08-05 17:02:38 +02002052 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002053 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002054 mutex_unlock(&sdata->local->mtx);
Johannes Berg37ad3882012-02-24 13:50:54 +01002055
Johannes Berg77fdaa12009-07-07 03:45:17 +02002056 return RX_MGMT_CFG80211_DISASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -07002057}
2058
Christian Lamparterc74d0842011-10-15 00:14:49 +02002059static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
2060 u8 *supp_rates, unsigned int supp_rates_len,
2061 u32 *rates, u32 *basic_rates,
2062 bool *have_higher_than_11mbit,
2063 int *min_rate, int *min_rate_index)
2064{
2065 int i, j;
2066
2067 for (i = 0; i < supp_rates_len; i++) {
2068 int rate = (supp_rates[i] & 0x7f) * 5;
2069 bool is_basic = !!(supp_rates[i] & 0x80);
2070
2071 if (rate > 110)
2072 *have_higher_than_11mbit = true;
2073
2074 /*
2075 * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
2076 * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
2077 *
2078 * Note: Even through the membership selector and the basic
2079 * rate flag share the same bit, they are not exactly
2080 * the same.
2081 */
2082 if (!!(supp_rates[i] & 0x80) &&
2083 (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
2084 continue;
2085
2086 for (j = 0; j < sband->n_bitrates; j++) {
2087 if (sband->bitrates[j].bitrate == rate) {
2088 *rates |= BIT(j);
2089 if (is_basic)
2090 *basic_rates |= BIT(j);
2091 if (rate < *min_rate) {
2092 *min_rate = rate;
2093 *min_rate_index = j;
2094 }
2095 break;
2096 }
2097 }
2098 }
2099}
Jiri Bencf0706e82007-05-05 11:45:53 -07002100
Johannes Berg66e67e42012-01-20 13:55:27 +01002101static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2102 bool assoc)
2103{
2104 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2105
2106 lockdep_assert_held(&sdata->u.mgd.mtx);
2107
Johannes Berg66e67e42012-01-20 13:55:27 +01002108 if (!assoc) {
2109 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2110
2111 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2112 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg028e8da02012-11-26 11:57:41 +01002113 sdata->u.mgd.flags = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002114 ieee80211_vif_release_channel(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002115 }
2116
2117 kfree(assoc_data);
2118 sdata->u.mgd.assoc_data = NULL;
2119}
2120
2121static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2122 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002123 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07002124{
Johannes Berg46900292009-02-15 12:44:28 +01002125 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002126 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01002127 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07002128 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002129 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002130 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002131 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02002132 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Bergae5eb022008-10-14 16:58:37 +02002133 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02002134 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -07002135
Johannes Bergaf6b6372009-12-23 13:15:35 +01002136 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07002137
Jiri Bencf0706e82007-05-05 11:45:53 -07002138 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002139 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07002140
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002141 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002142 sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n",
2143 aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002144 aid &= ~(BIT(15) | BIT(14));
2145
Johannes Berg05cb9102011-10-28 11:59:47 +02002146 ifmgd->broken_ap = false;
2147
2148 if (aid == 0 || aid > IEEE80211_MAX_AID) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002149 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
2150 aid);
Johannes Berg05cb9102011-10-28 11:59:47 +02002151 aid = 0;
2152 ifmgd->broken_ap = true;
2153 }
2154
Johannes Bergaf6b6372009-12-23 13:15:35 +01002155 pos = mgmt->u.assoc_resp.variable;
2156 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2157
Jiri Bencf0706e82007-05-05 11:45:53 -07002158 if (!elems.supp_rates) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002159 sdata_info(sdata, "no SuppRates element in AssocResp\n");
Johannes Bergaf6b6372009-12-23 13:15:35 +01002160 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002161 }
2162
Johannes Berg46900292009-02-15 12:44:28 +01002163 ifmgd->aid = aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07002164
Guy Eilam2a33bee2011-08-17 15:18:15 +03002165 mutex_lock(&sdata->local->sta_mtx);
2166 /*
2167 * station info was already allocated and inserted before
2168 * the association and should be available to us
2169 */
Johannes Berg7852e362012-01-20 13:55:24 +01002170 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03002171 if (WARN_ON(!sta)) {
2172 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002173 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07002174 }
2175
Johannes Berg55de9082012-07-26 17:24:39 +02002176 sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
Johannes Berg8318d782008-01-24 19:38:38 +01002177
Johannes Berga8243b72012-11-22 14:32:09 +01002178 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Ben Greearef96a8422011-11-18 11:32:00 -08002179 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02002180 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02002181
Johannes Berg64f68e52012-03-28 10:58:37 +02002182 sta->supports_40mhz =
2183 sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2184
Mahesh Palivela818255e2012-10-10 11:33:04 +00002185 if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2186 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
2187 elems.vht_cap_elem,
2188 &sta->sta.vht_cap);
2189
Johannes Berg4b7679a2008-09-18 18:14:18 +02002190 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07002191
Johannes Berg46900292009-02-15 12:44:28 +01002192 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002193 set_sta_flag(sta, WLAN_STA_MFP);
Jouni Malinen5394af42009-01-08 13:31:59 +02002194
Johannes Bergddf4ac52008-10-22 11:41:38 +02002195 if (elems.wmm_param)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002196 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002197
Johannes Bergc8987872012-01-20 13:55:17 +01002198 err = sta_info_move_state(sta, IEEE80211_STA_AUTH);
2199 if (!err)
2200 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
2201 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
2202 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
2203 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002204 sdata_info(sdata,
2205 "failed to move station %pM to desired state\n",
2206 sta->sta.addr);
Johannes Bergc8987872012-01-20 13:55:17 +01002207 WARN_ON(__sta_info_destroy(sta));
2208 mutex_unlock(&sdata->local->sta_mtx);
2209 return false;
2210 }
2211
Johannes Berg7852e362012-01-20 13:55:24 +01002212 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002213
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03002214 /*
2215 * Always handle WMM once after association regardless
2216 * of the first value the AP uses. Setting -1 here has
2217 * that effect because the AP values is an unsigned
2218 * 4-bit value.
2219 */
2220 ifmgd->wmm_last_param_set = -1;
2221
Johannes Bergddf4ac52008-10-22 11:41:38 +02002222 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02002223 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07002224 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02002225 else
Johannes Berg3abead52012-03-02 15:56:59 +01002226 ieee80211_set_wmm_default(sdata, false);
2227 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e82007-05-05 11:45:53 -07002228
Johannes Berg074d46d2012-03-15 19:45:16 +01002229 if (elems.ht_operation && elems.wmm_param &&
Johannes Berga8243b72012-11-22 14:32:09 +01002230 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg24398e32012-03-28 10:58:36 +02002231 changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation,
2232 cbss->bssid, false);
Johannes Bergae5eb022008-10-14 16:58:37 +02002233
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002234 /* set AID and assoc capability,
2235 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01002236 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002237 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002238 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07002239
Kalle Valo15b7b062009-03-22 21:57:14 +02002240 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01002241 * If we're using 4-addr mode, let the AP know that we're
2242 * doing so, so that it can create the STA VLAN on its side
2243 */
2244 if (ifmgd->use_4addr)
2245 ieee80211_send_4addr_nullfunc(local, sdata);
2246
2247 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02002248 * Start timer to probe the connection to the AP now.
2249 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02002250 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002251 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04002252 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02002253
Johannes Bergaf6b6372009-12-23 13:15:35 +01002254 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07002255}
2256
Johannes Berg66e67e42012-01-20 13:55:27 +01002257static enum rx_mgmt_action __must_check
2258ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2259 struct ieee80211_mgmt *mgmt, size_t len,
2260 struct cfg80211_bss **bss)
2261{
2262 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2263 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
2264 u16 capab_info, status_code, aid;
2265 struct ieee802_11_elems elems;
2266 u8 *pos;
2267 bool reassoc;
Jiri Bencf0706e82007-05-05 11:45:53 -07002268
Johannes Berg66e67e42012-01-20 13:55:27 +01002269 lockdep_assert_held(&ifmgd->mtx);
2270
2271 if (!assoc_data)
2272 return RX_MGMT_NONE;
Joe Perchesb203ca32012-05-08 18:56:52 +00002273 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002274 return RX_MGMT_NONE;
2275
2276 /*
2277 * AssocResp and ReassocResp have identical structure, so process both
2278 * of them in this function.
2279 */
2280
2281 if (len < 24 + 6)
2282 return RX_MGMT_NONE;
2283
2284 reassoc = ieee80211_is_reassoc_req(mgmt->frame_control);
2285 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2286 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2287 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2288
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002289 sdata_info(sdata,
2290 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
2291 reassoc ? "Rea" : "A", mgmt->sa,
2292 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Johannes Berg66e67e42012-01-20 13:55:27 +01002293
2294 pos = mgmt->u.assoc_resp.variable;
2295 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2296
2297 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
2298 elems.timeout_int && elems.timeout_int_len == 5 &&
2299 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
2300 u32 tu, ms;
2301 tu = get_unaligned_le32(elems.timeout_int + 1);
2302 ms = tu * 1024 / 1000;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002303 sdata_info(sdata,
2304 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
2305 mgmt->sa, tu, ms);
Johannes Berg66e67e42012-01-20 13:55:27 +01002306 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
2307 if (ms > IEEE80211_ASSOC_TIMEOUT)
2308 run_again(ifmgd, assoc_data->timeout);
2309 return RX_MGMT_NONE;
2310 }
2311
2312 *bss = assoc_data->bss;
2313
2314 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002315 sdata_info(sdata, "%pM denied association (code=%d)\n",
2316 mgmt->sa, status_code);
Johannes Berg66e67e42012-01-20 13:55:27 +01002317 ieee80211_destroy_assoc_data(sdata, false);
2318 } else {
Johannes Berg66e67e42012-01-20 13:55:27 +01002319 if (!ieee80211_assoc_success(sdata, *bss, mgmt, len)) {
2320 /* oops -- internal error -- send timeout for now */
Eliad Peller10a91092012-07-02 14:42:03 +03002321 ieee80211_destroy_assoc_data(sdata, false);
Johannes Berg66e67e42012-01-20 13:55:27 +01002322 cfg80211_put_bss(*bss);
2323 return RX_MGMT_CFG80211_ASSOC_TIMEOUT;
2324 }
John W. Linville635d9992012-07-09 16:34:34 -04002325 sdata_info(sdata, "associated\n");
Johannes Berg79ebfb82012-02-20 14:19:58 +01002326
2327 /*
2328 * destroy assoc_data afterwards, as otherwise an idle
2329 * recalc after assoc_data is NULL but before associated
2330 * is set can cause the interface to go idle
2331 */
2332 ieee80211_destroy_assoc_data(sdata, true);
Johannes Berg66e67e42012-01-20 13:55:27 +01002333 }
2334
2335 return RX_MGMT_CFG80211_RX_ASSOC;
2336}
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002337static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07002338 struct ieee80211_mgmt *mgmt,
2339 size_t len,
2340 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002341 struct ieee802_11_elems *elems,
2342 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07002343{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002344 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002345 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02002346 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002347 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01002348 bool need_ps = false;
2349
Johannes Berg66e67e42012-01-20 13:55:27 +01002350 if (sdata->u.mgd.associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002351 ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) {
Johannes Berg56007a02010-01-26 14:19:52 +01002352 bss = (void *)sdata->u.mgd.associated->priv;
2353 /* not previously set so we may need to recalc */
2354 need_ps = !bss->dtim_period;
2355 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002356
Johannes Berg5bda6172008-09-08 11:05:10 +02002357 if (elems->ds_params && elems->ds_params_len == 1)
Bruno Randolf59eb21a2011-01-17 13:37:28 +09002358 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
2359 rx_status->band);
Johannes Berg5bda6172008-09-08 11:05:10 +02002360 else
2361 freq = rx_status->freq;
2362
2363 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2364
2365 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2366 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002367
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002368 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01002369 channel, beacon);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002370 if (bss)
2371 ieee80211_rx_bss_put(local, bss);
2372
2373 if (!sdata->u.mgd.associated)
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002374 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07002375
Johannes Berg56007a02010-01-26 14:19:52 +01002376 if (need_ps) {
2377 mutex_lock(&local->iflist_mtx);
2378 ieee80211_recalc_ps(local, -1);
2379 mutex_unlock(&local->iflist_mtx);
2380 }
2381
Johannes Berg5bc14202012-08-01 16:13:02 +02002382 if (elems->ch_switch_ie &&
2383 memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0)
2384 ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie,
Johannes Berg5ce6e432010-05-11 16:20:57 +02002385 bss, rx_status->mactime);
Jiri Bencf0706e82007-05-05 11:45:53 -07002386}
2387
2388
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002389static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002390 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07002391{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002392 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02002393 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002394 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
2395 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002396 struct ieee802_11_elems elems;
2397
Kalle Valo15b7b062009-03-22 21:57:14 +02002398 ifmgd = &sdata->u.mgd;
2399
Johannes Berg77fdaa12009-07-07 03:45:17 +02002400 ASSERT_MGD_MTX(ifmgd);
2401
Joe Perchesb203ca32012-05-08 18:56:52 +00002402 if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03002403 return; /* ignore ProbeResp to foreign address */
2404
Ester Kummerae6a44e2008-06-27 18:54:48 +03002405 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
2406 if (baselen > len)
2407 return;
2408
2409 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
2410 &elems);
2411
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002412 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03002413
Johannes Berg77fdaa12009-07-07 03:45:17 +02002414 if (ifmgd->associated &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002415 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002416 ieee80211_reset_ap_probe(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002417
2418 if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002419 ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002420 /* got probe response, continue with auth */
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002421 sdata_info(sdata, "direct probe responded\n");
Johannes Berg66e67e42012-01-20 13:55:27 +01002422 ifmgd->auth_data->tries = 0;
2423 ifmgd->auth_data->timeout = jiffies;
2424 run_again(ifmgd, ifmgd->auth_data->timeout);
2425 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002426}
2427
Johannes Bergd91f36d2009-04-16 13:17:26 +02002428/*
2429 * This is the canonical list of information elements we care about,
2430 * the filter code also gives us all changes to the Microsoft OUI
2431 * (00:50:F2) vendor IE which is used for WMM which we need to track.
2432 *
2433 * We implement beacon filtering in software since that means we can
2434 * avoid processing the frame here and in cfg80211, and userspace
2435 * will not be able to tell whether the hardware supports it or not.
2436 *
2437 * XXX: This list needs to be dynamic -- userspace needs to be able to
2438 * add items it requires. It also needs to be able to tell us to
2439 * look out for other vendor IEs.
2440 */
2441static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02002442 (1ULL << WLAN_EID_COUNTRY) |
2443 (1ULL << WLAN_EID_ERP_INFO) |
2444 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
2445 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
2446 (1ULL << WLAN_EID_HT_CAPABILITY) |
Johannes Berg074d46d2012-03-15 19:45:16 +01002447 (1ULL << WLAN_EID_HT_OPERATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02002448
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002449static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07002450 struct ieee80211_mgmt *mgmt,
2451 size_t len,
2452 struct ieee80211_rx_status *rx_status)
2453{
Johannes Bergd91f36d2009-04-16 13:17:26 +02002454 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002455 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07002456 size_t baselen;
2457 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002458 struct ieee80211_local *local = sdata->local;
Johannes Berg55de9082012-07-26 17:24:39 +02002459 struct ieee80211_chanctx_conf *chanctx_conf;
2460 struct ieee80211_channel *chan;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002461 u32 changed = 0;
Rami Rosenf87ad632012-10-25 10:16:23 +02002462 bool erp_valid;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002463 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02002464 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002465 u8 *bssid;
2466
Johannes Berg66e67e42012-01-20 13:55:27 +01002467 lockdep_assert_held(&ifmgd->mtx);
Jiri Bencf0706e82007-05-05 11:45:53 -07002468
Ester Kummerae6a44e2008-06-27 18:54:48 +03002469 /* Process beacon from the current BSS */
2470 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2471 if (baselen > len)
2472 return;
2473
Johannes Berg55de9082012-07-26 17:24:39 +02002474 rcu_read_lock();
2475 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2476 if (!chanctx_conf) {
2477 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002478 return;
Johannes Berg55de9082012-07-26 17:24:39 +02002479 }
2480
Johannes Berg4bf88532012-11-09 11:39:59 +01002481 if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
Johannes Berg55de9082012-07-26 17:24:39 +02002482 rcu_read_unlock();
2483 return;
2484 }
Johannes Berg4bf88532012-11-09 11:39:59 +01002485 chan = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +02002486 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07002487
Johannes Berg66e67e42012-01-20 13:55:27 +01002488 if (ifmgd->assoc_data && !ifmgd->assoc_data->have_beacon &&
Joe Perchesb203ca32012-05-08 18:56:52 +00002489 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002490 ieee802_11_parse_elems(mgmt->u.beacon.variable,
2491 len - baselen, &elems);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002492
Johannes Berg66e67e42012-01-20 13:55:27 +01002493 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
2494 false);
2495 ifmgd->assoc_data->have_beacon = true;
2496 ifmgd->assoc_data->sent_assoc = false;
2497 /* continue assoc process */
2498 ifmgd->assoc_data->timeout = jiffies;
2499 run_again(ifmgd, ifmgd->assoc_data->timeout);
2500 return;
2501 }
2502
2503 if (!ifmgd->associated ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002504 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002505 return;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002506 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002507
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002508 /* Track average RSSI from the Beacon frames of the current AP */
2509 ifmgd->last_beacon_signal = rx_status->signal;
2510 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
2511 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03002512 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002513 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03002514 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002515 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002516 } else {
2517 ifmgd->ave_beacon_signal =
2518 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
2519 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
2520 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03002521 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002522 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002523
2524 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
2525 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
2526 int sig = ifmgd->ave_beacon_signal;
2527 int last_sig = ifmgd->last_ave_beacon_signal;
2528
2529 /*
2530 * if signal crosses either of the boundaries, invoke callback
2531 * with appropriate parameters
2532 */
2533 if (sig > ifmgd->rssi_max_thold &&
2534 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
2535 ifmgd->last_ave_beacon_signal = sig;
2536 drv_rssi_callback(local, RSSI_EVENT_HIGH);
2537 } else if (sig < ifmgd->rssi_min_thold &&
2538 (last_sig >= ifmgd->rssi_max_thold ||
2539 last_sig == 0)) {
2540 ifmgd->last_ave_beacon_signal = sig;
2541 drv_rssi_callback(local, RSSI_EVENT_LOW);
2542 }
2543 }
2544
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002545 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03002546 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01002547 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002548 int sig = ifmgd->ave_beacon_signal / 16;
2549 int last_event = ifmgd->last_cqm_event_signal;
2550 int thold = bss_conf->cqm_rssi_thold;
2551 int hyst = bss_conf->cqm_rssi_hyst;
2552 if (sig < thold &&
2553 (last_event == 0 || sig < last_event - hyst)) {
2554 ifmgd->last_cqm_event_signal = sig;
2555 ieee80211_cqm_rssi_notify(
2556 &sdata->vif,
2557 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
2558 GFP_KERNEL);
2559 } else if (sig > thold &&
2560 (last_event == 0 || sig > last_event + hyst)) {
2561 ifmgd->last_cqm_event_signal = sig;
2562 ieee80211_cqm_rssi_notify(
2563 &sdata->vif,
2564 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
2565 GFP_KERNEL);
2566 }
2567 }
2568
Johannes Bergb291ba12009-07-10 15:29:03 +02002569 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002570 mlme_dbg_ratelimited(sdata,
2571 "cancelling probereq poll due to a received beacon\n");
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002572 mutex_lock(&local->mtx);
Johannes Bergb291ba12009-07-10 15:29:03 +02002573 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02002574 ieee80211_run_deferred_scan(local);
2575 mutex_unlock(&local->mtx);
2576
Johannes Berg4e751842009-06-10 15:16:52 +02002577 mutex_lock(&local->iflist_mtx);
2578 ieee80211_recalc_ps(local, -1);
2579 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03002580 }
2581
Johannes Bergb291ba12009-07-10 15:29:03 +02002582 /*
2583 * Push the beacon loss detection into the future since
2584 * we are processing a beacon from the AP just now.
2585 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04002586 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002587
Johannes Bergd91f36d2009-04-16 13:17:26 +02002588 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
2589 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
2590 len - baselen, &elems,
2591 care_about_ies, ncrc);
2592
Vivek Natarajan25c9c872009-03-02 20:20:30 +05302593 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Rami Rosenf87ad632012-10-25 10:16:23 +02002594 bool directed_tim = ieee80211_check_tim(elems.tim,
2595 elems.tim_len,
2596 ifmgd->aid);
Kalle Valo1fb36062009-02-10 17:09:24 +02002597 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02002598 if (local->hw.conf.dynamic_ps_timeout > 0) {
Ronald Wahl70b12f22012-03-19 14:37:20 +01002599 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2600 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2601 ieee80211_hw_config(local,
2602 IEEE80211_CONF_CHANGE_PS);
2603 }
Kalle Valo572e0012009-02-10 17:09:31 +02002604 ieee80211_send_nullfunc(local, sdata, 0);
Rajkumar Manoharan6f0756a2012-03-15 05:50:36 +05302605 } else if (!local->pspolling && sdata->u.mgd.powersave) {
Kalle Valo572e0012009-02-10 17:09:31 +02002606 local->pspolling = true;
2607
2608 /*
2609 * Here is assumed that the driver will be
2610 * able to send ps-poll frame and receive a
2611 * response even though power save mode is
2612 * enabled, but some drivers might require
2613 * to disable power save here. This needs
2614 * to be investigated.
2615 */
2616 ieee80211_send_pspoll(local, sdata);
2617 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08002618 }
2619 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02002620
Johannes Berg488dd7b2012-10-29 20:08:01 +01002621 if (sdata->vif.p2p) {
2622 u8 noa[2];
2623 int ret;
2624
2625 ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
2626 len - baselen,
2627 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2628 noa, sizeof(noa));
2629 if (ret >= 2 && sdata->u.mgd.p2p_noa_index != noa[0]) {
2630 bss_conf->p2p_oppps = noa[1] & 0x80;
2631 bss_conf->p2p_ctwindow = noa[1] & 0x7f;
2632 changed |= BSS_CHANGED_P2P_PS;
2633 sdata->u.mgd.p2p_noa_index = noa[0];
2634 /*
2635 * make sure we update all information, the CRC
2636 * mechanism doesn't look at P2P attributes.
2637 */
2638 ifmgd->beacon_crc_valid = false;
2639 }
2640 }
2641
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002642 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Jouni Malinen30196672009-05-19 17:01:43 +03002643 return;
2644 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002645 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03002646
Johannes Berg7d257452012-07-06 17:37:43 +02002647 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
2648 true);
2649
2650 if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
2651 elems.wmm_param_len))
2652 changed |= BSS_CHANGED_QOS;
2653
Johannes Berg7a5158e2008-10-08 10:59:33 +02002654 if (elems.erp_info && elems.erp_info_len >= 1) {
2655 erp_valid = true;
2656 erp_value = elems.erp_info[0];
2657 } else {
2658 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04002659 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02002660 changed |= ieee80211_handle_bss_capability(sdata,
2661 le16_to_cpu(mgmt->u.beacon.capab_info),
2662 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07002663
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002664
Johannes Berg074d46d2012-03-15 19:45:16 +01002665 if (elems.ht_cap_elem && elems.ht_operation && elems.wmm_param &&
Johannes Berga8243b72012-11-22 14:32:09 +01002666 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
Johannes Berg24398e32012-03-28 10:58:36 +02002667 changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation,
2668 bssid, true);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002669
Johannes Berg04b7b2f2012-09-05 13:41:37 +02002670 if (elems.country_elem && elems.pwr_constr_elem &&
2671 mgmt->u.probe_resp.capab_info &
2672 cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT))
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002673 changed |= ieee80211_handle_pwr_constr(sdata, chan,
2674 elems.country_elem,
2675 elems.country_elem_len,
2676 elems.pwr_constr_elem);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002677
Johannes Berg471b3ef2007-12-28 14:32:58 +01002678 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07002679}
2680
Johannes Berg1fa57d02010-06-10 10:21:32 +02002681void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
2682 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07002683{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002684 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07002685 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07002686 struct ieee80211_mgmt *mgmt;
Johannes Berg66e67e42012-01-20 13:55:27 +01002687 struct cfg80211_bss *bss = NULL;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002688 enum rx_mgmt_action rma = RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07002689 u16 fc;
2690
Jiri Bencf0706e82007-05-05 11:45:53 -07002691 rx_status = (struct ieee80211_rx_status *) skb->cb;
2692 mgmt = (struct ieee80211_mgmt *) skb->data;
2693 fc = le16_to_cpu(mgmt->frame_control);
2694
Johannes Berg77fdaa12009-07-07 03:45:17 +02002695 mutex_lock(&ifmgd->mtx);
2696
Johannes Berg66e67e42012-01-20 13:55:27 +01002697 switch (fc & IEEE80211_FCTL_STYPE) {
2698 case IEEE80211_STYPE_BEACON:
2699 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
2700 break;
2701 case IEEE80211_STYPE_PROBE_RESP:
2702 ieee80211_rx_mgmt_probe_resp(sdata, skb);
2703 break;
2704 case IEEE80211_STYPE_AUTH:
2705 rma = ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
2706 break;
2707 case IEEE80211_STYPE_DEAUTH:
2708 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
2709 break;
2710 case IEEE80211_STYPE_DISASSOC:
2711 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
2712 break;
2713 case IEEE80211_STYPE_ASSOC_RESP:
2714 case IEEE80211_STYPE_REASSOC_RESP:
2715 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss);
2716 break;
2717 case IEEE80211_STYPE_ACTION:
2718 switch (mgmt->u.action.category) {
2719 case WLAN_CATEGORY_SPECTRUM_MGMT:
2720 ieee80211_sta_process_chanswitch(sdata,
2721 &mgmt->u.action.u.chan_switch.sw_elem,
2722 (void *)ifmgd->associated->priv,
2723 rx_status->mactime);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002724 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002725 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002726 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002727 mutex_unlock(&ifmgd->mtx);
2728
Johannes Berg66e67e42012-01-20 13:55:27 +01002729 switch (rma) {
2730 case RX_MGMT_NONE:
2731 /* no action */
2732 break;
2733 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470612009-10-13 13:28:13 +02002734 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01002735 break;
2736 case RX_MGMT_CFG80211_DISASSOC:
2737 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
2738 break;
2739 case RX_MGMT_CFG80211_RX_AUTH:
2740 cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, skb->len);
2741 break;
2742 case RX_MGMT_CFG80211_RX_ASSOC:
2743 cfg80211_send_rx_assoc(sdata->dev, bss, (u8 *)mgmt, skb->len);
2744 break;
2745 case RX_MGMT_CFG80211_ASSOC_TIMEOUT:
2746 cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid);
2747 break;
2748 default:
2749 WARN(1, "unexpected: %d", rma);
Johannes Bergb054b742010-06-07 21:50:07 +02002750 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002751}
2752
Johannes Berg9c6bd792008-09-11 00:01:52 +02002753static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07002754{
2755 struct ieee80211_sub_if_data *sdata =
2756 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01002757 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002758 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07002759
Johannes Berg5bb644a2009-05-17 11:40:42 +02002760 if (local->quiescing) {
2761 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2762 return;
2763 }
2764
Johannes Berg64592c82010-06-10 10:21:31 +02002765 ieee80211_queue_work(&local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07002766}
2767
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002768static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg95acac62011-07-12 12:30:59 +02002769 u8 *bssid, u8 reason)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002770{
2771 struct ieee80211_local *local = sdata->local;
2772 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002773 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002774
Johannes Berg37ad3882012-02-24 13:50:54 +01002775 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
2776 false, frame_buf);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002777 mutex_unlock(&ifmgd->mtx);
Johannes Berg37ad3882012-02-24 13:50:54 +01002778
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002779 /*
2780 * must be outside lock due to cfg80211,
2781 * but that's not a problem.
2782 */
Antonio Quartulli6ae16772012-09-07 13:28:52 +02002783 cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN);
Felix Fietkaufcac4fb2011-11-16 13:34:55 +01002784
2785 mutex_lock(&local->mtx);
2786 ieee80211_recalc_idle(local);
2787 mutex_unlock(&local->mtx);
2788
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002789 mutex_lock(&ifmgd->mtx);
2790}
2791
Johannes Berg66e67e42012-01-20 13:55:27 +01002792static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
2793{
2794 struct ieee80211_local *local = sdata->local;
2795 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2796 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
2797
2798 lockdep_assert_held(&ifmgd->mtx);
2799
2800 if (WARN_ON_ONCE(!auth_data))
2801 return -EINVAL;
2802
Johannes Berg66e67e42012-01-20 13:55:27 +01002803 auth_data->tries++;
2804
2805 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002806 sdata_info(sdata, "authentication with %pM timed out\n",
2807 auth_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002808
2809 /*
2810 * Most likely AP is not in the range so remove the
2811 * bss struct for that AP.
2812 */
2813 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
2814
2815 return -ETIMEDOUT;
2816 }
2817
Johannes Berga1845fc2012-06-27 13:18:36 +02002818 drv_mgd_prepare_tx(local, sdata);
2819
Johannes Berg66e67e42012-01-20 13:55:27 +01002820 if (auth_data->bss->proberesp_ies) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002821 u16 trans = 1;
2822 u16 status = 0;
2823
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002824 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
2825 auth_data->bss->bssid, auth_data->tries,
2826 IEEE80211_AUTH_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01002827
2828 auth_data->expected_transaction = 2;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03002829
2830 if (auth_data->algorithm == WLAN_AUTH_SAE) {
2831 trans = auth_data->sae_trans;
2832 status = auth_data->sae_status;
2833 auth_data->expected_transaction = trans;
2834 }
2835
2836 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
2837 auth_data->data, auth_data->data_len,
Johannes Berg66e67e42012-01-20 13:55:27 +01002838 auth_data->bss->bssid,
2839 auth_data->bss->bssid, NULL, 0, 0);
2840 } else {
2841 const u8 *ssidie;
2842
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002843 sdata_info(sdata, "direct probe to %pM (try %d/%i)\n",
2844 auth_data->bss->bssid, auth_data->tries,
2845 IEEE80211_AUTH_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01002846
2847 ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
2848 if (!ssidie)
2849 return -EINVAL;
2850 /*
2851 * Direct probe is sent to broadcast address as some APs
2852 * will not answer to direct packet in unassociated state.
2853 */
2854 ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
Johannes Bergfe94fe02012-07-30 12:26:34 +02002855 NULL, 0, (u32) -1, true, false,
Johannes Berg55de9082012-07-26 17:24:39 +02002856 auth_data->bss->channel, false);
Johannes Berg66e67e42012-01-20 13:55:27 +01002857 }
2858
2859 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
2860 run_again(ifmgd, auth_data->timeout);
2861
2862 return 0;
2863}
2864
2865static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
2866{
2867 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2868 struct ieee80211_local *local = sdata->local;
2869
2870 lockdep_assert_held(&sdata->u.mgd.mtx);
2871
Johannes Berg66e67e42012-01-20 13:55:27 +01002872 assoc_data->tries++;
2873 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002874 sdata_info(sdata, "association with %pM timed out\n",
2875 assoc_data->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01002876
2877 /*
2878 * Most likely AP is not in the range so remove the
2879 * bss struct for that AP.
2880 */
2881 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
2882
2883 return -ETIMEDOUT;
2884 }
2885
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002886 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
2887 assoc_data->bss->bssid, assoc_data->tries,
2888 IEEE80211_ASSOC_MAX_TRIES);
Johannes Berg66e67e42012-01-20 13:55:27 +01002889 ieee80211_send_assoc(sdata);
2890
2891 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
2892 run_again(&sdata->u.mgd, assoc_data->timeout);
2893
2894 return 0;
2895}
2896
Johannes Berg1fa57d02010-06-10 10:21:32 +02002897void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02002898{
Johannes Berg60f8b392008-09-08 17:44:22 +02002899 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02002900 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002901
Johannes Berg77fdaa12009-07-07 03:45:17 +02002902 mutex_lock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002903
Johannes Berg66e67e42012-01-20 13:55:27 +01002904 if (ifmgd->auth_data &&
2905 time_after(jiffies, ifmgd->auth_data->timeout)) {
2906 if (ifmgd->auth_data->done) {
2907 /*
2908 * ok ... we waited for assoc but userspace didn't,
2909 * so let's just kill the auth data
2910 */
2911 ieee80211_destroy_auth_data(sdata, false);
2912 } else if (ieee80211_probe_auth(sdata)) {
2913 u8 bssid[ETH_ALEN];
2914
2915 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2916
2917 ieee80211_destroy_auth_data(sdata, false);
2918
2919 mutex_unlock(&ifmgd->mtx);
2920 cfg80211_send_auth_timeout(sdata->dev, bssid);
2921 mutex_lock(&ifmgd->mtx);
2922 }
2923 } else if (ifmgd->auth_data)
2924 run_again(ifmgd, ifmgd->auth_data->timeout);
2925
2926 if (ifmgd->assoc_data &&
2927 time_after(jiffies, ifmgd->assoc_data->timeout)) {
2928 if (!ifmgd->assoc_data->have_beacon ||
2929 ieee80211_do_assoc(sdata)) {
2930 u8 bssid[ETH_ALEN];
2931
2932 memcpy(bssid, ifmgd->assoc_data->bss->bssid, ETH_ALEN);
2933
2934 ieee80211_destroy_assoc_data(sdata, false);
2935
2936 mutex_unlock(&ifmgd->mtx);
2937 cfg80211_send_assoc_timeout(sdata->dev, bssid);
2938 mutex_lock(&ifmgd->mtx);
2939 }
2940 } else if (ifmgd->assoc_data)
2941 run_again(ifmgd, ifmgd->assoc_data->timeout);
2942
Johannes Bergb291ba12009-07-10 15:29:03 +02002943 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
2944 IEEE80211_STA_CONNECTION_POLL) &&
2945 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03002946 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002947 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002948
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002949 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002950
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002951 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Ben Greear180205b2011-02-04 15:30:24 -08002952 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002953 else
Ben Greear180205b2011-02-04 15:30:24 -08002954 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002955
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002956 /* ACK received for nullfunc probing frame */
2957 if (!ifmgd->probe_send_count)
2958 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002959 else if (ifmgd->nullfunc_failed) {
2960 if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002961 mlme_dbg(sdata,
2962 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
2963 bssid, ifmgd->probe_send_count,
2964 max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002965 ieee80211_mgd_probe_ap_send(sdata);
2966 } else {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002967 mlme_dbg(sdata,
2968 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
2969 bssid);
Johannes Berg95acac62011-07-12 12:30:59 +02002970 ieee80211_sta_connection_lost(sdata, bssid,
2971 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002972 }
2973 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Bergb291ba12009-07-10 15:29:03 +02002974 run_again(ifmgd, ifmgd->probe_timeout);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002975 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002976 mlme_dbg(sdata,
2977 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
2978 bssid, probe_wait_ms);
Johannes Berg95acac62011-07-12 12:30:59 +02002979 ieee80211_sta_connection_lost(sdata, bssid,
2980 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002981 } else if (ifmgd->probe_send_count < max_tries) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002982 mlme_dbg(sdata,
2983 "No probe response from AP %pM after %dms, try %d/%i\n",
2984 bssid, probe_wait_ms,
2985 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002986 ieee80211_mgd_probe_ap_send(sdata);
2987 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02002988 /*
2989 * We actually lost the connection ... or did we?
2990 * Let's make sure!
2991 */
Ben Greearb38afa82010-10-07 16:12:06 -07002992 wiphy_debug(local->hw.wiphy,
2993 "%s: No probe response from AP %pM"
2994 " after %dms, disconnecting.\n",
2995 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08002996 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002997
Johannes Berg95acac62011-07-12 12:30:59 +02002998 ieee80211_sta_connection_lost(sdata, bssid,
2999 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Johannes Bergb291ba12009-07-10 15:29:03 +02003000 }
3001 }
3002
Johannes Berg77fdaa12009-07-07 03:45:17 +02003003 mutex_unlock(&ifmgd->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01003004
3005 mutex_lock(&local->mtx);
3006 ieee80211_recalc_idle(local);
3007 mutex_unlock(&local->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02003008}
Johannes Berg0a51b272008-09-08 17:44:25 +02003009
Johannes Bergb291ba12009-07-10 15:29:03 +02003010static void ieee80211_sta_bcn_mon_timer(unsigned long data)
3011{
3012 struct ieee80211_sub_if_data *sdata =
3013 (struct ieee80211_sub_if_data *) data;
3014 struct ieee80211_local *local = sdata->local;
3015
3016 if (local->quiescing)
3017 return;
3018
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003019 ieee80211_queue_work(&sdata->local->hw,
3020 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003021}
3022
3023static void ieee80211_sta_conn_mon_timer(unsigned long data)
3024{
3025 struct ieee80211_sub_if_data *sdata =
3026 (struct ieee80211_sub_if_data *) data;
3027 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3028 struct ieee80211_local *local = sdata->local;
3029
3030 if (local->quiescing)
3031 return;
3032
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04003033 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003034}
3035
3036static void ieee80211_sta_monitor_work(struct work_struct *work)
3037{
3038 struct ieee80211_sub_if_data *sdata =
3039 container_of(work, struct ieee80211_sub_if_data,
3040 u.mgd.monitor_work);
3041
3042 ieee80211_mgd_probe_ap(sdata, false);
3043}
3044
Johannes Berga1678f82008-09-11 00:01:47 +02003045static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3046{
Eliad Peller494f1fe2012-02-19 15:26:09 +02003047 u32 flags;
3048
Kalle Vaload935682009-04-19 08:47:19 +03003049 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003050 __ieee80211_stop_poll(sdata);
Kalle Vaload935682009-04-19 08:47:19 +03003051
Johannes Bergb291ba12009-07-10 15:29:03 +02003052 /* let's probe the connection once */
Eliad Peller494f1fe2012-02-19 15:26:09 +02003053 flags = sdata->local->hw.flags;
3054 if (!(flags & IEEE80211_HW_CONNECTION_MONITOR))
3055 ieee80211_queue_work(&sdata->local->hw,
3056 &sdata->u.mgd.monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02003057 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02003058 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03003059 }
Johannes Berga1678f82008-09-11 00:01:47 +02003060}
3061
Johannes Berg5bb644a2009-05-17 11:40:42 +02003062#ifdef CONFIG_PM
3063void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
3064{
3065 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3066
3067 /*
3068 * we need to use atomic bitops for the running bits
3069 * only because both timers might fire at the same
3070 * time -- the code here is properly synchronised.
3071 */
3072
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02003073 cancel_work_sync(&ifmgd->request_smps_work);
3074
Johannes Berg0ecfe8062011-11-09 12:14:16 +01003075 cancel_work_sync(&ifmgd->monitor_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003076 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02003077 cancel_work_sync(&ifmgd->csa_connection_drop_work);
Johannes Berg5bb644a2009-05-17 11:40:42 +02003078 if (del_timer_sync(&ifmgd->timer))
3079 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
3080
3081 cancel_work_sync(&ifmgd->chswitch_work);
3082 if (del_timer_sync(&ifmgd->chswitch_timer))
3083 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
Johannes Bergb291ba12009-07-10 15:29:03 +02003084
Johannes Bergb291ba12009-07-10 15:29:03 +02003085 /* these will just be re-established on connection */
3086 del_timer_sync(&ifmgd->conn_mon_timer);
3087 del_timer_sync(&ifmgd->bcn_mon_timer);
Johannes Berg5bb644a2009-05-17 11:40:42 +02003088}
3089
3090void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
3091{
3092 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3093
Rajkumar Manoharan676b58c2011-07-07 23:33:39 +05303094 if (!ifmgd->associated)
3095 return;
3096
Johannes Berg95acac62011-07-12 12:30:59 +02003097 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
3098 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
3099 mutex_lock(&ifmgd->mtx);
3100 if (ifmgd->associated) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003101 mlme_dbg(sdata,
3102 "driver requested disconnect after resume\n");
Johannes Berg95acac62011-07-12 12:30:59 +02003103 ieee80211_sta_connection_lost(sdata,
3104 ifmgd->associated->bssid,
3105 WLAN_REASON_UNSPECIFIED);
3106 mutex_unlock(&ifmgd->mtx);
3107 return;
3108 }
3109 mutex_unlock(&ifmgd->mtx);
3110 }
3111
Johannes Berg5bb644a2009-05-17 11:40:42 +02003112 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
3113 add_timer(&ifmgd->timer);
3114 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
3115 add_timer(&ifmgd->chswitch_timer);
Felix Fietkauc8a79722010-11-19 22:55:37 +01003116 ieee80211_sta_reset_beacon_monitor(sdata);
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003117
3118 mutex_lock(&sdata->local->mtx);
Felix Fietkau46090972010-11-23 20:28:03 +01003119 ieee80211_restart_sta_timer(sdata);
Stanislaw Gruszka925e64c2012-05-16 15:27:20 +02003120 mutex_unlock(&sdata->local->mtx);
Johannes Berg5bb644a2009-05-17 11:40:42 +02003121}
3122#endif
3123
Johannes Berg9c6bd792008-09-11 00:01:52 +02003124/* interface setup */
3125void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
3126{
Johannes Berg46900292009-02-15 12:44:28 +01003127 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003128
Johannes Berg46900292009-02-15 12:44:28 +01003129 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02003130 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01003131 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003132 INIT_WORK(&ifmgd->beacon_connection_loss_work,
3133 ieee80211_beacon_connection_loss_work);
Johannes Berg882a7c62012-08-01 22:32:45 +02003134 INIT_WORK(&ifmgd->csa_connection_drop_work,
3135 ieee80211_csa_connection_drop_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02003136 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01003137 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02003138 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003139 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
3140 (unsigned long) sdata);
3141 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
3142 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01003143 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05303144 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02003145
Johannes Bergab1faea2009-07-01 21:41:17 +02003146 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05303147 ifmgd->powersave = sdata->wdev.ps;
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02003148 ifmgd->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
3149 ifmgd->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
Johannes Bergbbbdff92009-04-16 13:27:42 +02003150
Johannes Berg77fdaa12009-07-07 03:45:17 +02003151 mutex_init(&ifmgd->mtx);
Johannes Berg0f782312009-12-01 13:37:02 +01003152
3153 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
3154 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
3155 else
3156 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003157}
3158
3159/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02003160void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
3161{
Johannes Berg31ee67a2012-07-06 21:18:24 +02003162 struct ieee80211_sub_if_data *sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02003163
3164 /* Restart STA timers */
3165 rcu_read_lock();
3166 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3167 ieee80211_restart_sta_timer(sdata);
3168 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02003169}
Johannes Berg10f644a2009-04-16 13:17:25 +02003170
3171int ieee80211_max_network_latency(struct notifier_block *nb,
3172 unsigned long data, void *dummy)
3173{
3174 s32 latency_usec = (s32) data;
3175 struct ieee80211_local *local =
3176 container_of(nb, struct ieee80211_local,
3177 network_latency_notifier);
3178
3179 mutex_lock(&local->iflist_mtx);
3180 ieee80211_recalc_ps(local, latency_usec);
3181 mutex_unlock(&local->iflist_mtx);
3182
3183 return 0;
3184}
Johannes Berg77fdaa12009-07-07 03:45:17 +02003185
Johannes Bergb17166a2012-07-27 11:41:27 +02003186static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
3187 struct cfg80211_bss *cbss)
Johannes Berga1cf7752012-03-08 15:02:07 +01003188{
3189 struct ieee80211_local *local = sdata->local;
3190 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg24398e32012-03-28 10:58:36 +02003191 int ht_cfreq;
3192 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
3193 const u8 *ht_oper_ie;
3194 const struct ieee80211_ht_operation *ht_oper = NULL;
3195 struct ieee80211_supported_band *sband;
Johannes Berg4bf88532012-11-09 11:39:59 +01003196 struct cfg80211_chan_def chandef;
Johannes Berga1cf7752012-03-08 15:02:07 +01003197
Johannes Berg24398e32012-03-28 10:58:36 +02003198 sband = local->hw.wiphy->bands[cbss->channel->band];
3199
3200 ifmgd->flags &= ~IEEE80211_STA_DISABLE_40MHZ;
3201
3202 if (sband->ht_cap.ht_supported) {
3203 ht_oper_ie = cfg80211_find_ie(WLAN_EID_HT_OPERATION,
3204 cbss->information_elements,
3205 cbss->len_information_elements);
3206 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
3207 ht_oper = (void *)(ht_oper_ie + 2);
3208 }
3209
3210 if (ht_oper) {
3211 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
3212 cbss->channel->band);
3213 /* check that channel matches the right operating channel */
3214 if (cbss->channel->center_freq != ht_cfreq) {
3215 /*
3216 * It's possible that some APs are confused here;
3217 * Netgear WNDR3700 sometimes reports 4 higher than
3218 * the actual channel in association responses, but
3219 * since we look at probe response/beacon data here
3220 * it should be OK.
3221 */
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003222 sdata_info(sdata,
3223 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
3224 cbss->channel->center_freq,
3225 ht_cfreq, ht_oper->primary_chan,
3226 cbss->channel->band);
Johannes Berg24398e32012-03-28 10:58:36 +02003227 ht_oper = NULL;
3228 }
3229 }
3230
Johannes Berg76c5fa02012-11-22 14:17:23 +01003231 if (ht_oper) {
Johannes Berg3a404142012-10-01 15:52:00 +02003232 /*
3233 * cfg80211 already verified that the channel itself can
3234 * be used, but it didn't check that we can do the right
3235 * HT type, so do that here as well. If HT40 isn't allowed
3236 * on this channel, disable 40 MHz operation.
3237 */
Johannes Berg04ecd252012-09-11 14:34:12 +02003238 const u8 *ht_cap_ie;
3239 const struct ieee80211_ht_cap *ht_cap;
3240 u8 chains = 1;
3241
Johannes Berg24398e32012-03-28 10:58:36 +02003242 channel_type = NL80211_CHAN_HT20;
3243
Johannes Berg76c5fa02012-11-22 14:17:23 +01003244 if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
3245 switch (ht_oper->ht_param &
3246 IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
3247 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
3248 if (cbss->channel->flags &
3249 IEEE80211_CHAN_NO_HT40PLUS)
3250 ifmgd->flags |=
3251 IEEE80211_STA_DISABLE_40MHZ;
3252 else
3253 channel_type = NL80211_CHAN_HT40PLUS;
3254 break;
3255 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
3256 if (cbss->channel->flags &
3257 IEEE80211_CHAN_NO_HT40MINUS)
3258 ifmgd->flags |=
3259 IEEE80211_STA_DISABLE_40MHZ;
3260 else
3261 channel_type = NL80211_CHAN_HT40MINUS;
3262 break;
3263 }
Johannes Berg24398e32012-03-28 10:58:36 +02003264 }
Johannes Berg04ecd252012-09-11 14:34:12 +02003265
3266 ht_cap_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY,
3267 cbss->information_elements,
3268 cbss->len_information_elements);
3269 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
3270 ht_cap = (void *)(ht_cap_ie + 2);
3271 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
3272 }
3273 sdata->needed_rx_chains = min(chains, local->rx_chains);
3274 } else {
3275 sdata->needed_rx_chains = 1;
Johannes Berg03ae834f2012-11-22 14:34:05 +01003276 sdata->u.mgd.flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg24398e32012-03-28 10:58:36 +02003277 }
3278
Johannes Berg04ecd252012-09-11 14:34:12 +02003279 /* will change later if needed */
3280 sdata->smps_mode = IEEE80211_SMPS_OFF;
3281
Johannes Berg55de9082012-07-26 17:24:39 +02003282 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +01003283 cfg80211_chandef_create(&chandef, cbss->channel, channel_type);
3284 return ieee80211_vif_use_channel(sdata, &chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02003285 IEEE80211_CHANCTX_SHARED);
Johannes Bergb17166a2012-07-27 11:41:27 +02003286}
3287
3288static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3289 struct cfg80211_bss *cbss, bool assoc)
3290{
3291 struct ieee80211_local *local = sdata->local;
3292 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3293 struct ieee80211_bss *bss = (void *)cbss->priv;
3294 struct sta_info *new_sta = NULL;
3295 bool have_sta = false;
3296 int err;
3297
3298 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
3299 return -EINVAL;
3300
3301 if (assoc) {
3302 rcu_read_lock();
3303 have_sta = sta_info_get(sdata, cbss->bssid);
3304 rcu_read_unlock();
3305 }
3306
3307 if (!have_sta) {
3308 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
3309 if (!new_sta)
3310 return -ENOMEM;
3311 }
3312
3313 mutex_lock(&local->mtx);
3314 ieee80211_recalc_idle(sdata->local);
3315 mutex_unlock(&local->mtx);
3316
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003317 if (new_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003318 u32 rates = 0, basic_rates = 0;
3319 bool have_higher_than_11mbit;
3320 int min_rate = INT_MAX, min_rate_index = -1;
Johannes Bergb17166a2012-07-27 11:41:27 +02003321 struct ieee80211_supported_band *sband;
3322
3323 sband = local->hw.wiphy->bands[cbss->channel->band];
3324
3325 err = ieee80211_prep_channel(sdata, cbss);
3326 if (err) {
3327 sta_info_free(local, new_sta);
3328 return err;
3329 }
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003330
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003331 ieee80211_get_rates(sband, bss->supp_rates,
3332 bss->supp_rates_len,
3333 &rates, &basic_rates,
3334 &have_higher_than_11mbit,
3335 &min_rate, &min_rate_index);
3336
3337 /*
3338 * This used to be a workaround for basic rates missing
3339 * in the association response frame. Now that we no
3340 * longer use the basic rates from there, it probably
3341 * doesn't happen any more, but keep the workaround so
3342 * in case some *other* APs are buggy in different ways
3343 * we can connect -- with a warning.
3344 */
3345 if (!basic_rates && min_rate_index >= 0) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003346 sdata_info(sdata,
3347 "No basic rates, using min rate instead\n");
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003348 basic_rates = BIT(min_rate_index);
3349 }
3350
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003351 new_sta->sta.supp_rates[cbss->channel->band] = rates;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003352 sdata->vif.bss_conf.basic_rates = basic_rates;
3353
3354 /* cf. IEEE 802.11 9.2.12 */
Johannes Berg55de9082012-07-26 17:24:39 +02003355 if (cbss->channel->band == IEEE80211_BAND_2GHZ &&
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003356 have_higher_than_11mbit)
3357 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
3358 else
3359 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
3360
3361 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
3362
Johannes Berg8c358bc2012-05-22 22:13:05 +02003363 /* set timing information */
3364 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
3365 sdata->vif.bss_conf.sync_tsf = cbss->tsf;
3366 sdata->vif.bss_conf.sync_device_ts = bss->device_ts;
3367
3368 /* tell driver about BSSID, basic rates and timing */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003369 ieee80211_bss_info_change_notify(sdata,
Johannes Berg8c358bc2012-05-22 22:13:05 +02003370 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
3371 BSS_CHANGED_BEACON_INT);
Johannes Berga1cf7752012-03-08 15:02:07 +01003372
3373 if (assoc)
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003374 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
Johannes Berga1cf7752012-03-08 15:02:07 +01003375
Johannes Berg13e0c8e2012-07-27 10:43:16 +02003376 err = sta_info_insert(new_sta);
3377 new_sta = NULL;
Johannes Berga1cf7752012-03-08 15:02:07 +01003378 if (err) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003379 sdata_info(sdata,
3380 "failed to insert STA entry for the AP (error %d)\n",
3381 err);
Johannes Berga1cf7752012-03-08 15:02:07 +01003382 return err;
3383 }
3384 } else
Joe Perchesb203ca32012-05-08 18:56:52 +00003385 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01003386
3387 return 0;
3388}
3389
Johannes Berg77fdaa12009-07-07 03:45:17 +02003390/* config hooks */
3391int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
3392 struct cfg80211_auth_request *req)
3393{
Johannes Berg66e67e42012-01-20 13:55:27 +01003394 struct ieee80211_local *local = sdata->local;
3395 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3396 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003397 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01003398 int err;
3399
3400 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02003401
3402 switch (req->auth_type) {
3403 case NL80211_AUTHTYPE_OPEN_SYSTEM:
3404 auth_alg = WLAN_AUTH_OPEN;
3405 break;
3406 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01003407 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02003408 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003409 auth_alg = WLAN_AUTH_SHARED_KEY;
3410 break;
3411 case NL80211_AUTHTYPE_FT:
3412 auth_alg = WLAN_AUTH_FT;
3413 break;
3414 case NL80211_AUTHTYPE_NETWORK_EAP:
3415 auth_alg = WLAN_AUTH_LEAP;
3416 break;
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003417 case NL80211_AUTHTYPE_SAE:
3418 auth_alg = WLAN_AUTH_SAE;
3419 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003420 default:
3421 return -EOPNOTSUPP;
3422 }
3423
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003424 auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len +
3425 req->ie_len, GFP_KERNEL);
Johannes Berg66e67e42012-01-20 13:55:27 +01003426 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02003427 return -ENOMEM;
3428
Johannes Berg66e67e42012-01-20 13:55:27 +01003429 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003430
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003431 if (req->sae_data_len >= 4) {
3432 __le16 *pos = (__le16 *) req->sae_data;
3433 auth_data->sae_trans = le16_to_cpu(pos[0]);
3434 auth_data->sae_status = le16_to_cpu(pos[1]);
3435 memcpy(auth_data->data, req->sae_data + 4,
3436 req->sae_data_len - 4);
3437 auth_data->data_len += req->sae_data_len - 4;
3438 }
3439
Johannes Berg77fdaa12009-07-07 03:45:17 +02003440 if (req->ie && req->ie_len) {
Jouni Malinen6b8ece32012-09-30 19:29:40 +03003441 memcpy(&auth_data->data[auth_data->data_len],
3442 req->ie, req->ie_len);
3443 auth_data->data_len += req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003444 }
3445
Johannes Bergfffd0932009-07-08 14:22:54 +02003446 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003447 auth_data->key_len = req->key_len;
3448 auth_data->key_idx = req->key_idx;
3449 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02003450 }
3451
Johannes Berg66e67e42012-01-20 13:55:27 +01003452 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003453
Johannes Berg66e67e42012-01-20 13:55:27 +01003454 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01003455
Johannes Berg66e67e42012-01-20 13:55:27 +01003456 mutex_lock(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003457
Johannes Berg66e67e42012-01-20 13:55:27 +01003458 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
3459 ifmgd->assoc_data) {
3460 err = -EBUSY;
3461 goto err_free;
3462 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003463
Johannes Berg66e67e42012-01-20 13:55:27 +01003464 if (ifmgd->auth_data)
3465 ieee80211_destroy_auth_data(sdata, false);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003466
Johannes Berg66e67e42012-01-20 13:55:27 +01003467 /* prep auth_data so we don't go into idle on disassoc */
3468 ifmgd->auth_data = auth_data;
3469
3470 if (ifmgd->associated)
Johannes Berg37ad3882012-02-24 13:50:54 +01003471 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
Johannes Berg66e67e42012-01-20 13:55:27 +01003472
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003473 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003474
Johannes Berga1cf7752012-03-08 15:02:07 +01003475 err = ieee80211_prep_connection(sdata, req->bss, false);
3476 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01003477 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03003478
Johannes Berg66e67e42012-01-20 13:55:27 +01003479 err = ieee80211_probe_auth(sdata);
3480 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003481 sta_info_destroy_addr(sdata, req->bss->bssid);
3482 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003483 }
3484
Johannes Berg66e67e42012-01-20 13:55:27 +01003485 /* hold our own reference */
3486 cfg80211_ref_bss(auth_data->bss);
3487 err = 0;
3488 goto out_unlock;
Johannes Berge5b900d2010-07-29 16:08:55 +02003489
Johannes Berg66e67e42012-01-20 13:55:27 +01003490 err_clear:
Eliad Peller3d2abdf2012-09-04 17:44:45 +03003491 memset(ifmgd->bssid, 0, ETH_ALEN);
3492 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01003493 ifmgd->auth_data = NULL;
3494 err_free:
3495 kfree(auth_data);
3496 out_unlock:
3497 mutex_unlock(&ifmgd->mtx);
Johannes Berge5b900d2010-07-29 16:08:55 +02003498
Johannes Berg66e67e42012-01-20 13:55:27 +01003499 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003500}
3501
Johannes Berg77fdaa12009-07-07 03:45:17 +02003502int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3503 struct cfg80211_assoc_request *req)
3504{
Johannes Berg66e67e42012-01-20 13:55:27 +01003505 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003506 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003507 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01003508 struct ieee80211_mgd_assoc_data *assoc_data;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01003509 struct ieee80211_supported_band *sband;
Johannes Berg9dde6422012-05-16 23:43:19 +02003510 const u8 *ssidie, *ht_ie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03003511 int i, err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003512
Johannes Berg66e67e42012-01-20 13:55:27 +01003513 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
3514 if (!ssidie)
3515 return -EINVAL;
Jouni Malinen9c87ba62010-02-28 12:13:46 +02003516
Johannes Berg66e67e42012-01-20 13:55:27 +01003517 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
3518 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01003519 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003520
Johannes Berg66e67e42012-01-20 13:55:27 +01003521 mutex_lock(&ifmgd->mtx);
3522
3523 if (ifmgd->associated)
Johannes Berg37ad3882012-02-24 13:50:54 +01003524 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
Johannes Berg66e67e42012-01-20 13:55:27 +01003525
3526 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
3527 err = -EBUSY;
3528 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03003529 }
3530
Johannes Berg66e67e42012-01-20 13:55:27 +01003531 if (ifmgd->assoc_data) {
3532 err = -EBUSY;
3533 goto err_free;
3534 }
3535
3536 if (ifmgd->auth_data) {
3537 bool match;
3538
3539 /* keep sta info, bssid if matching */
Joe Perchesb203ca32012-05-08 18:56:52 +00003540 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
Johannes Berg66e67e42012-01-20 13:55:27 +01003541 ieee80211_destroy_auth_data(sdata, match);
3542 }
3543
3544 /* prepare assoc data */
Johannes Berg19c3b832012-08-01 20:13:36 +02003545
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003546 ifmgd->beacon_crc_valid = false;
3547
Johannes Bergde5036a2012-03-08 15:02:03 +01003548 /*
3549 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
3550 * We still associate in non-HT mode (11a/b/g) if any one of these
3551 * ciphers is configured as pairwise.
3552 * We can set this to true for non-11n hardware, that'll be checked
3553 * separately along with the peer capabilities.
3554 */
Johannes Berg1c4cb922012-05-30 15:57:00 +02003555 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02003556 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
3557 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02003558 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berga8243b72012-11-22 14:32:09 +01003559 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003560 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg1c4cb922012-05-30 15:57:00 +02003561 netdev_info(sdata->dev,
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003562 "disabling HT/VHT due to WEP/TKIP use\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02003563 }
3564 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003565
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003566 if (req->flags & ASSOC_REQ_DISABLE_HT) {
Johannes Berga8243b72012-11-22 14:32:09 +01003567 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003568 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3569 }
Ben Greearef96a8422011-11-18 11:32:00 -08003570
Johannes Berg4e74bfd2012-03-08 15:02:04 +01003571 /* Also disable HT if we don't support it or the AP doesn't use WMM */
3572 sband = local->hw.wiphy->bands[req->bss->channel->band];
3573 if (!sband->ht_cap.ht_supported ||
Johannes Berg1c4cb922012-05-30 15:57:00 +02003574 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
Johannes Berga8243b72012-11-22 14:32:09 +01003575 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg1b49de22012-07-27 10:29:14 +02003576 if (!bss->wmm_used)
3577 netdev_info(sdata->dev,
3578 "disabling HT as WMM/QoS is not supported by the AP\n");
Johannes Berg1c4cb922012-05-30 15:57:00 +02003579 }
Johannes Berg4e74bfd2012-03-08 15:02:04 +01003580
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003581 /* disable VHT if we don't support it or the AP doesn't use WMM */
3582 if (!sband->vht_cap.vht_supported ||
3583 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
3584 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
Johannes Berg1b49de22012-07-27 10:29:14 +02003585 if (!bss->wmm_used)
3586 netdev_info(sdata->dev,
3587 "disabling VHT as WMM/QoS is not supported by the AP\n");
Mahesh Palivelad545dab2012-07-24 03:33:10 +00003588 }
3589
Ben Greearef96a8422011-11-18 11:32:00 -08003590 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
3591 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
3592 sizeof(ifmgd->ht_capa_mask));
3593
Johannes Berg77fdaa12009-07-07 03:45:17 +02003594 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003595 memcpy(assoc_data->ie, req->ie, req->ie_len);
3596 assoc_data->ie_len = req->ie_len;
3597 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003598
Johannes Berg66e67e42012-01-20 13:55:27 +01003599 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01003600
Johannes Bergaf6b6372009-12-23 13:15:35 +01003601 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
3602 if (ifmgd->powersave)
Johannes Berg04ecd252012-09-11 14:34:12 +02003603 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003604 else
Johannes Berg04ecd252012-09-11 14:34:12 +02003605 sdata->smps_mode = IEEE80211_SMPS_OFF;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003606 } else
Johannes Berg04ecd252012-09-11 14:34:12 +02003607 sdata->smps_mode = ifmgd->req_smps;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003608
Johannes Berg66e67e42012-01-20 13:55:27 +01003609 assoc_data->capability = req->bss->capability;
Johannes Berg32c50572012-03-28 11:04:29 +02003610 assoc_data->wmm = bss->wmm_used &&
3611 (local->hw.queues >= IEEE80211_NUM_ACS);
Johannes Berg66e67e42012-01-20 13:55:27 +01003612 assoc_data->supp_rates = bss->supp_rates;
3613 assoc_data->supp_rates_len = bss->supp_rates_len;
Johannes Berg9dde6422012-05-16 23:43:19 +02003614
3615 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
3616 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
3617 assoc_data->ap_ht_param =
3618 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
3619 else
Johannes Berga8243b72012-11-22 14:32:09 +01003620 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
Johannes Berg63f170e2009-12-23 13:15:33 +01003621
Kalle Valoab133152010-01-12 10:42:31 +02003622 if (bss->wmm_used && bss->uapsd_supported &&
3623 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01003624 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02003625 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
3626 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01003627 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02003628 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
3629 }
3630
Johannes Berg66e67e42012-01-20 13:55:27 +01003631 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
3632 assoc_data->ssid_len = ssidie[1];
Johannes Berg63f170e2009-12-23 13:15:33 +01003633
Johannes Berg77fdaa12009-07-07 03:45:17 +02003634 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01003635 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003636
3637 if (req->use_mfp) {
3638 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
3639 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
3640 } else {
3641 ifmgd->mfp = IEEE80211_MFP_DISABLED;
3642 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
3643 }
3644
3645 if (req->crypto.control_port)
3646 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
3647 else
3648 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
3649
Johannes Berga621fa42010-08-27 14:26:54 +03003650 sdata->control_port_protocol = req->crypto.control_port_ethertype;
3651 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
3652
Johannes Berg66e67e42012-01-20 13:55:27 +01003653 /* kick off associate process */
3654
3655 ifmgd->assoc_data = assoc_data;
3656
Johannes Berga1cf7752012-03-08 15:02:07 +01003657 err = ieee80211_prep_connection(sdata, req->bss, true);
3658 if (err)
3659 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01003660
3661 if (!bss->dtim_period &&
3662 sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) {
3663 /*
3664 * Wait up to one beacon interval ...
3665 * should this be more if we miss one?
3666 */
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003667 sdata_info(sdata, "waiting for beacon from %pM\n",
3668 ifmgd->bssid);
Johannes Berg3f9768a2012-03-28 21:02:46 +02003669 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg66e67e42012-01-20 13:55:27 +01003670 } else {
3671 assoc_data->have_beacon = true;
3672 assoc_data->sent_assoc = false;
3673 assoc_data->timeout = jiffies;
3674 }
3675 run_again(ifmgd, assoc_data->timeout);
3676
Paul Stewartfcff4f12012-02-23 17:59:53 -08003677 if (bss->corrupt_data) {
3678 char *corrupt_type = "data";
3679 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
3680 if (bss->corrupt_data &
3681 IEEE80211_BSS_CORRUPT_PROBE_RESP)
3682 corrupt_type = "beacon and probe response";
3683 else
3684 corrupt_type = "beacon";
3685 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
3686 corrupt_type = "probe response";
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003687 sdata_info(sdata, "associating with AP with corrupt %s\n",
3688 corrupt_type);
Paul Stewartfcff4f12012-02-23 17:59:53 -08003689 }
3690
Johannes Berg66e67e42012-01-20 13:55:27 +01003691 err = 0;
3692 goto out;
3693 err_clear:
Eliad Peller3d2abdf2012-09-04 17:44:45 +03003694 memset(ifmgd->bssid, 0, ETH_ALEN);
3695 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg66e67e42012-01-20 13:55:27 +01003696 ifmgd->assoc_data = NULL;
3697 err_free:
3698 kfree(assoc_data);
3699 out:
3700 mutex_unlock(&ifmgd->mtx);
3701
3702 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003703}
3704
3705int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01003706 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02003707{
3708 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Antonio Quartulli6ae16772012-09-07 13:28:52 +02003709 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Stanislaw Gruszka68632552012-10-15 14:52:41 +02003710 bool tx = !req->local_state_change;
Johannes Berg86552012012-10-29 09:46:31 +01003711 bool sent_frame = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003712
Johannes Berg77fdaa12009-07-07 03:45:17 +02003713 mutex_lock(&ifmgd->mtx);
3714
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003715 sdata_info(sdata,
3716 "deauthenticating from %pM by local choice (reason=%d)\n",
3717 req->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02003718
Johannes Berg86552012012-10-29 09:46:31 +01003719 if (ifmgd->auth_data) {
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03003720 drv_mgd_prepare_tx(sdata->local, sdata);
Johannes Berg37ad3882012-02-24 13:50:54 +01003721 ieee80211_send_deauth_disassoc(sdata, req->bssid,
3722 IEEE80211_STYPE_DEAUTH,
Stanislaw Gruszka68632552012-10-15 14:52:41 +02003723 req->reason_code, tx,
Johannes Berg37ad3882012-02-24 13:50:54 +01003724 frame_buf);
Johannes Berg86552012012-10-29 09:46:31 +01003725 ieee80211_destroy_auth_data(sdata, false);
3726 mutex_unlock(&ifmgd->mtx);
3727
3728 sent_frame = tx;
3729 goto out;
Emmanuel Grumbach8c7d8572012-07-25 01:42:36 +03003730 }
3731
Johannes Berg86552012012-10-29 09:46:31 +01003732 if (ifmgd->associated &&
3733 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
3734 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3735 req->reason_code, tx, frame_buf);
3736 sent_frame = tx;
3737 }
Johannes Berg37ad3882012-02-24 13:50:54 +01003738 mutex_unlock(&ifmgd->mtx);
3739
Johannes Berg86552012012-10-29 09:46:31 +01003740 out:
Johannes Berg7da7cc12010-08-05 17:02:38 +02003741 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01003742 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02003743 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01003744
Johannes Berg86552012012-10-29 09:46:31 +01003745 if (sent_frame)
3746 __cfg80211_send_deauth(sdata->dev, frame_buf,
3747 IEEE80211_DEAUTH_FRAME_LEN);
3748
Johannes Berg77fdaa12009-07-07 03:45:17 +02003749 return 0;
3750}
3751
3752int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01003753 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02003754{
3755 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07003756 u8 bssid[ETH_ALEN];
Antonio Quartulli6ae16772012-09-07 13:28:52 +02003757 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02003758
Johannes Berg77fdaa12009-07-07 03:45:17 +02003759 mutex_lock(&ifmgd->mtx);
3760
Johannes Berg8d8b2612009-07-25 11:58:36 +02003761 /*
3762 * cfg80211 should catch this ... but it's racy since
3763 * we can receive a disassoc frame, process it, hand it
3764 * to cfg80211 while that's in a locked section already
3765 * trying to tell us that the user wants to disconnect.
3766 */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003767 if (ifmgd->associated != req->bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02003768 mutex_unlock(&ifmgd->mtx);
3769 return -ENOLINK;
3770 }
3771
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003772 sdata_info(sdata,
3773 "disassociating from %pM by local choice (reason=%d)\n",
3774 req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02003775
Jouni Malinene69e95d2010-03-29 23:29:31 -07003776 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01003777 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
3778 req->reason_code, !req->local_state_change,
3779 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003780 mutex_unlock(&ifmgd->mtx);
3781
Antonio Quartulli6ae16772012-09-07 13:28:52 +02003782 __cfg80211_send_disassoc(sdata->dev, frame_buf,
3783 IEEE80211_DEAUTH_FRAME_LEN);
Johannes Bergbc83b682009-11-29 12:19:06 +01003784
Johannes Berg7da7cc12010-08-05 17:02:38 +02003785 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01003786 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02003787 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01003788
Johannes Berg77fdaa12009-07-07 03:45:17 +02003789 return 0;
3790}
Jouni Malinen026331c2010-02-15 12:53:10 +02003791
Eliad Pellerafa762f2012-04-23 14:45:15 +03003792void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01003793{
3794 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3795
3796 mutex_lock(&ifmgd->mtx);
3797 if (ifmgd->assoc_data)
3798 ieee80211_destroy_assoc_data(sdata, false);
3799 if (ifmgd->auth_data)
3800 ieee80211_destroy_auth_data(sdata, false);
3801 del_timer_sync(&ifmgd->timer);
3802 mutex_unlock(&ifmgd->mtx);
3803}
3804
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003805void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
3806 enum nl80211_cqm_rssi_threshold_event rssi_event,
3807 gfp_t gfp)
3808{
3809 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3810
Johannes Bergb5878a22010-04-07 16:48:40 +02003811 trace_api_cqm_rssi_notify(sdata, rssi_event);
3812
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003813 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
3814}
3815EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);