blob: a48a35c7ce64ae5cc8932717aa60dfa85fec0e0b [file] [log] [blame]
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070015#include <linux/if_ether.h>
16#include <linux/skbuff.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070017#include <linux/if_arp.h>
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Berg5fef7db2012-02-24 13:50:52 +010091#define DEAUTH_DISASSOC_LEN (24 /* hdr */ + 2 /* reason */)
92
Johannes Berg77fdaa12009-07-07 03:45:17 +020093/*
94 * All cfg80211 functions have to be called outside a locked
95 * section so that they can acquire a lock themselves... This
96 * is much simpler than queuing up things in cfg80211, but we
97 * do need some indirection for that here.
98 */
99enum rx_mgmt_action {
100 /* no action required */
101 RX_MGMT_NONE,
102
Johannes Berg77fdaa12009-07-07 03:45:17 +0200103 /* caller must call cfg80211_send_deauth() */
104 RX_MGMT_CFG80211_DEAUTH,
105
106 /* caller must call cfg80211_send_disassoc() */
107 RX_MGMT_CFG80211_DISASSOC,
Johannes Berg66e67e42012-01-20 13:55:27 +0100108
109 /* caller must call cfg80211_send_rx_auth() */
110 RX_MGMT_CFG80211_RX_AUTH,
111
112 /* caller must call cfg80211_send_rx_assoc() */
113 RX_MGMT_CFG80211_RX_ASSOC,
114
115 /* caller must call cfg80211_send_assoc_timeout() */
116 RX_MGMT_CFG80211_ASSOC_TIMEOUT,
Johannes Berg77fdaa12009-07-07 03:45:17 +0200117};
118
Johannes Berg5484e232008-09-08 17:44:27 +0200119/* utils */
Johannes Berg77fdaa12009-07-07 03:45:17 +0200120static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
121{
Johannes Berg46a5eba2010-09-15 13:28:15 +0200122 lockdep_assert_held(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200123}
124
Johannes Bergca386f32009-07-10 02:39:48 +0200125/*
126 * We can have multiple work items (and connection probing)
127 * scheduling this timer, but we need to take care to only
128 * reschedule it when it should fire _earlier_ than it was
129 * asked for before, or if it's not pending right now. This
130 * function ensures that. Note that it then is required to
131 * run this function for all timeouts after the first one
132 * has happened -- the work that runs from this timer will
133 * do that.
134 */
Johannes Berg66e67e42012-01-20 13:55:27 +0100135static void run_again(struct ieee80211_if_managed *ifmgd, unsigned long timeout)
Johannes Bergca386f32009-07-10 02:39:48 +0200136{
137 ASSERT_MGD_MTX(ifmgd);
138
139 if (!timer_pending(&ifmgd->timer) ||
140 time_before(timeout, ifmgd->timer.expires))
141 mod_timer(&ifmgd->timer, timeout);
142}
143
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400144void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200145{
Johannes Bergc1288b12012-01-19 09:29:57 +0100146 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
Johannes Bergb291ba12009-07-10 15:29:03 +0200147 return;
148
149 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100150 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200151}
152
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400153void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
154{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400155 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
156
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100157 if (unlikely(!sdata->u.mgd.associated))
158 return;
159
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400160 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
161 return;
162
163 mod_timer(&sdata->u.mgd.conn_mon_timer,
164 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400165
166 ifmgd->probe_send_count = 0;
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400167}
168
Johannes Berg5484e232008-09-08 17:44:27 +0200169static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200170{
Johannes Berg5484e232008-09-08 17:44:27 +0200171 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200172}
173
Johannes Bergd5522e02009-03-30 13:23:35 +0200174/*
175 * ieee80211_enable_ht should be called only after the operating band
176 * has been determined as ht configuration depends on the hw's
177 * HT abilities for a specific band.
178 */
179static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
180 struct ieee80211_ht_info *hti,
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530181 const u8 *bssid, u16 ap_ht_cap_flags,
182 bool beacon_htcap_ie)
Johannes Bergd5522e02009-03-30 13:23:35 +0200183{
184 struct ieee80211_local *local = sdata->local;
185 struct ieee80211_supported_band *sband;
Johannes Bergd5522e02009-03-30 13:23:35 +0200186 struct sta_info *sta;
187 u32 changed = 0;
Ben Greear172710b2011-01-28 17:05:43 -0800188 int hti_cfreq;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200189 u16 ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200190 bool enable_ht = true;
191 enum nl80211_channel_type prev_chantype;
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700192 enum nl80211_channel_type rx_channel_type = NL80211_CHAN_NO_HT;
193 enum nl80211_channel_type tx_channel_type;
Johannes Bergd5522e02009-03-30 13:23:35 +0200194
195 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
Johannes Berg0aaffa92010-05-05 15:28:27 +0200196 prev_chantype = sdata->vif.bss_conf.channel_type;
197
Johannes Bergd5522e02009-03-30 13:23:35 +0200198
Johannes Berg4e74bfd2012-03-08 15:02:04 +0100199 hti_cfreq = ieee80211_channel_to_frequency(hti->control_chan,
200 sband->band);
201 /* check that channel matches the right operating channel */
202 if (local->hw.conf.channel->center_freq != hti_cfreq) {
203 /* Some APs mess this up, evidently.
204 * Netgear WNDR3700 sometimes reports 4 higher than
205 * the actual channel, for instance.
206 */
207 printk(KERN_DEBUG
208 "%s: Wrong control channel in association"
209 " response: configured center-freq: %d"
210 " hti-cfreq: %d hti->control_chan: %d"
211 " band: %d. Disabling HT.\n",
212 sdata->name,
213 local->hw.conf.channel->center_freq,
214 hti_cfreq, hti->control_chan,
215 sband->band);
216 enable_ht = false;
Ben Greear172710b2011-01-28 17:05:43 -0800217 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200218
219 if (enable_ht) {
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700220 rx_channel_type = NL80211_CHAN_HT20;
Johannes Bergd5522e02009-03-30 13:23:35 +0200221
222 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
Ben Greearef96a8422011-11-18 11:32:00 -0800223 !ieee80111_cfg_override_disables_ht40(sdata) &&
Johannes Bergd5522e02009-03-30 13:23:35 +0200224 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
225 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
226 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
227 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700228 rx_channel_type = NL80211_CHAN_HT40PLUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200229 break;
230 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700231 rx_channel_type = NL80211_CHAN_HT40MINUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200232 break;
233 }
234 }
235 }
236
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700237 tx_channel_type = ieee80211_get_tx_channel_type(local, rx_channel_type);
Johannes Bergd5522e02009-03-30 13:23:35 +0200238
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700239 if (local->tmp_channel)
240 local->tmp_channel_type = rx_channel_type;
241
242 if (!ieee80211_set_channel_type(local, sdata, rx_channel_type)) {
Johannes Berg0aaffa92010-05-05 15:28:27 +0200243 /* can only fail due to HT40+/- mismatch */
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700244 rx_channel_type = NL80211_CHAN_HT20;
245 WARN_ON(!ieee80211_set_channel_type(local, sdata,
246 rx_channel_type));
Johannes Berg0aaffa92010-05-05 15:28:27 +0200247 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200248
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700249 if (beacon_htcap_ie && (prev_chantype != rx_channel_type)) {
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530250 /*
251 * Whenever the AP announces the HT mode change that can be
252 * 40MHz intolerant or etc., it would be safer to stop tx
253 * queues before doing hw config to avoid buffer overflow.
254 */
255 ieee80211_stop_queues_by_reason(&sdata->local->hw,
256 IEEE80211_QUEUE_STOP_REASON_CHTYPE_CHANGE);
257
258 /* flush out all packets */
259 synchronize_net();
260
261 drv_flush(local, false);
262 }
263
Johannes Berg0aaffa92010-05-05 15:28:27 +0200264 /* channel_type change automatically detected */
265 ieee80211_hw_config(local, 0);
266
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700267 if (prev_chantype != tx_channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200268 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100269 sta = sta_info_get(sdata, bssid);
Johannes Bergd5522e02009-03-30 13:23:35 +0200270 if (sta)
271 rate_control_rate_update(local, sband, sta,
Sujith4fa00432010-03-01 14:42:57 +0530272 IEEE80211_RC_HT_CHANGED,
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700273 tx_channel_type);
Johannes Bergd5522e02009-03-30 13:23:35 +0200274 rcu_read_unlock();
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530275
276 if (beacon_htcap_ie)
277 ieee80211_wake_queues_by_reason(&sdata->local->hw,
278 IEEE80211_QUEUE_STOP_REASON_CHTYPE_CHANGE);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200279 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200280
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200281 ht_opmode = le16_to_cpu(hti->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200282
283 /* if bss configuration changed store the new one */
Johannes Berg0aaffa92010-05-05 15:28:27 +0200284 if (sdata->ht_opmode_valid != enable_ht ||
285 sdata->vif.bss_conf.ht_operation_mode != ht_opmode ||
Paul Stewart3117bbdb2012-03-13 07:46:18 -0700286 prev_chantype != rx_channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200287 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200288 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200289 sdata->ht_opmode_valid = enable_ht;
Johannes Bergd5522e02009-03-30 13:23:35 +0200290 }
291
292 return changed;
293}
294
Johannes Berg9c6bd792008-09-11 00:01:52 +0200295/* frame sending functions */
296
Johannes Berg66e67e42012-01-20 13:55:27 +0100297static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
298 struct ieee80211_supported_band *sband,
299 u32 *rates)
300{
301 int i, j, count;
302 *rates = 0;
303 count = 0;
304 for (i = 0; i < supp_rates_len; i++) {
305 int rate = (supp_rates[i] & 0x7F) * 5;
306
307 for (j = 0; j < sband->n_bitrates; j++)
308 if (sband->bitrates[j].bitrate == rate) {
309 *rates |= BIT(j);
310 count++;
311 break;
312 }
313 }
314
315 return count;
316}
317
318static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
319 struct sk_buff *skb, const u8 *ht_info_ie,
320 struct ieee80211_supported_band *sband,
321 struct ieee80211_channel *channel,
322 enum ieee80211_smps_mode smps)
323{
324 struct ieee80211_ht_info *ht_info;
325 u8 *pos;
326 u32 flags = channel->flags;
327 u16 cap;
328 struct ieee80211_sta_ht_cap ht_cap;
329
330 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
331
Johannes Berg66e67e42012-01-20 13:55:27 +0100332 if (!ht_info_ie)
333 return;
334
335 if (ht_info_ie[1] < sizeof(struct ieee80211_ht_info))
336 return;
337
338 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
339 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
340
341 ht_info = (struct ieee80211_ht_info *)(ht_info_ie + 2);
342
343 /* determine capability flags */
344 cap = ht_cap.cap;
345
346 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
347 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
348 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
349 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
350 cap &= ~IEEE80211_HT_CAP_SGI_40;
351 }
352 break;
353 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
354 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
355 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
356 cap &= ~IEEE80211_HT_CAP_SGI_40;
357 }
358 break;
359 }
360
361 /* set SM PS mode properly */
362 cap &= ~IEEE80211_HT_CAP_SM_PS;
363 switch (smps) {
364 case IEEE80211_SMPS_AUTOMATIC:
365 case IEEE80211_SMPS_NUM_MODES:
366 WARN_ON(1);
367 case IEEE80211_SMPS_OFF:
368 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
369 IEEE80211_HT_CAP_SM_PS_SHIFT;
370 break;
371 case IEEE80211_SMPS_STATIC:
372 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
373 IEEE80211_HT_CAP_SM_PS_SHIFT;
374 break;
375 case IEEE80211_SMPS_DYNAMIC:
376 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
377 IEEE80211_HT_CAP_SM_PS_SHIFT;
378 break;
379 }
380
381 /* reserve and fill IE */
382 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
383 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
384}
385
Mahesh Palivelad56a75d2013-02-21 07:04:14 +0530386static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
387 struct sk_buff *skb,
388 struct ieee80211_supported_band *sband)
389{
390 u8 *pos;
391 u32 cap;
392 struct ieee80211_sta_vht_cap vht_cap;
393
394 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
395
396 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
397
398 /* determine capability flags */
399 cap = vht_cap.cap;
400
401 /* reserve and fill IE */
Mahesh Palivela8d200ae2012-10-10 11:25:40 +0000402 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
Mahesh Palivelad56a75d2013-02-21 07:04:14 +0530403 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
404}
405
Johannes Berg66e67e42012-01-20 13:55:27 +0100406static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
407{
408 struct ieee80211_local *local = sdata->local;
409 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
410 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
411 struct sk_buff *skb;
412 struct ieee80211_mgmt *mgmt;
413 u8 *pos, qos_info;
414 size_t offset = 0, noffset;
415 int i, count, rates_len, supp_rates_len;
416 u16 capab;
417 struct ieee80211_supported_band *sband;
418 u32 rates = 0;
Johannes Berg66e67e42012-01-20 13:55:27 +0100419
420 lockdep_assert_held(&ifmgd->mtx);
421
422 sband = local->hw.wiphy->bands[local->oper_channel->band];
423
424 if (assoc_data->supp_rates_len) {
425 /*
426 * Get all rates supported by the device and the AP as
427 * some APs don't like getting a superset of their rates
428 * in the association request (e.g. D-Link DAP 1353 in
429 * b-only mode)...
430 */
431 rates_len = ieee80211_compatible_rates(assoc_data->supp_rates,
432 assoc_data->supp_rates_len,
433 sband, &rates);
434 } else {
435 /*
436 * In case AP not provide any supported rates information
437 * before association, we send information element(s) with
438 * all rates that we support.
439 */
440 rates = ~0;
441 rates_len = sband->n_bitrates;
442 }
443
444 skb = alloc_skb(local->hw.extra_tx_headroom +
445 sizeof(*mgmt) + /* bit too much but doesn't matter */
446 2 + assoc_data->ssid_len + /* SSID */
447 4 + rates_len + /* (extended) rates */
448 4 + /* power capability */
449 2 + 2 * sband->n_channels + /* supported channels */
450 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
Mahesh Palivela8d200ae2012-10-10 11:25:40 +0000451 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
Johannes Berg66e67e42012-01-20 13:55:27 +0100452 assoc_data->ie_len + /* extra IEs */
453 9, /* WMM */
454 GFP_KERNEL);
455 if (!skb)
456 return;
457
458 skb_reserve(skb, local->hw.extra_tx_headroom);
459
460 capab = WLAN_CAPABILITY_ESS;
461
462 if (sband->band == IEEE80211_BAND_2GHZ) {
463 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
464 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
465 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
466 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
467 }
468
469 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
470 capab |= WLAN_CAPABILITY_PRIVACY;
471
472 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
473 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
474 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
475
476 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
477 memset(mgmt, 0, 24);
478 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
479 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
480 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
481
482 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
483 skb_put(skb, 10);
484 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
485 IEEE80211_STYPE_REASSOC_REQ);
486 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
487 mgmt->u.reassoc_req.listen_interval =
488 cpu_to_le16(local->hw.conf.listen_interval);
489 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
490 ETH_ALEN);
491 } else {
492 skb_put(skb, 4);
493 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
494 IEEE80211_STYPE_ASSOC_REQ);
495 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
496 mgmt->u.assoc_req.listen_interval =
497 cpu_to_le16(local->hw.conf.listen_interval);
498 }
499
500 /* SSID */
501 pos = skb_put(skb, 2 + assoc_data->ssid_len);
502 *pos++ = WLAN_EID_SSID;
503 *pos++ = assoc_data->ssid_len;
504 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
505
506 /* add all rates which were marked to be used above */
507 supp_rates_len = rates_len;
508 if (supp_rates_len > 8)
509 supp_rates_len = 8;
510
511 pos = skb_put(skb, supp_rates_len + 2);
512 *pos++ = WLAN_EID_SUPP_RATES;
513 *pos++ = supp_rates_len;
514
515 count = 0;
516 for (i = 0; i < sband->n_bitrates; i++) {
517 if (BIT(i) & rates) {
518 int rate = sband->bitrates[i].bitrate;
519 *pos++ = (u8) (rate / 5);
520 if (++count == 8)
521 break;
522 }
523 }
524
525 if (rates_len > count) {
526 pos = skb_put(skb, rates_len - count + 2);
527 *pos++ = WLAN_EID_EXT_SUPP_RATES;
528 *pos++ = rates_len - count;
529
530 for (i++; i < sband->n_bitrates; i++) {
531 if (BIT(i) & rates) {
532 int rate = sband->bitrates[i].bitrate;
533 *pos++ = (u8) (rate / 5);
534 }
535 }
536 }
537
538 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
539 /* 1. power capabilities */
540 pos = skb_put(skb, 4);
541 *pos++ = WLAN_EID_PWR_CAPABILITY;
542 *pos++ = 2;
543 *pos++ = 0; /* min tx power */
544 *pos++ = local->oper_channel->max_power; /* max tx power */
545
546 /* 2. supported channels */
547 /* TODO: get this in reg domain format */
548 pos = skb_put(skb, 2 * sband->n_channels + 2);
549 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
550 *pos++ = 2 * sband->n_channels;
551 for (i = 0; i < sband->n_channels; i++) {
552 *pos++ = ieee80211_frequency_to_channel(
553 sband->channels[i].center_freq);
554 *pos++ = 1; /* one channel in the subband*/
555 }
556 }
557
558 /* if present, add any custom IEs that go before HT */
559 if (assoc_data->ie_len && assoc_data->ie) {
560 static const u8 before_ht[] = {
561 WLAN_EID_SSID,
562 WLAN_EID_SUPP_RATES,
563 WLAN_EID_EXT_SUPP_RATES,
564 WLAN_EID_PWR_CAPABILITY,
565 WLAN_EID_SUPPORTED_CHANNELS,
566 WLAN_EID_RSN,
567 WLAN_EID_QOS_CAPA,
568 WLAN_EID_RRM_ENABLED_CAPABILITIES,
569 WLAN_EID_MOBILITY_DOMAIN,
570 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
571 };
572 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
573 before_ht, ARRAY_SIZE(before_ht),
574 offset);
575 pos = skb_put(skb, noffset - offset);
576 memcpy(pos, assoc_data->ie + offset, noffset - offset);
577 offset = noffset;
578 }
579
Johannes Berg4e74bfd2012-03-08 15:02:04 +0100580 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Berg66e67e42012-01-20 13:55:27 +0100581 ieee80211_add_ht_ie(sdata, skb, assoc_data->ht_information_ie,
582 sband, local->oper_channel, ifmgd->ap_smps);
583
Mahesh Palivelad56a75d2013-02-21 07:04:14 +0530584 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
585 ieee80211_add_vht_ie(sdata, skb, sband);
586
Johannes Berg66e67e42012-01-20 13:55:27 +0100587 /* if present, add any custom non-vendor IEs that go after HT */
588 if (assoc_data->ie_len && assoc_data->ie) {
589 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
590 assoc_data->ie_len,
591 offset);
592 pos = skb_put(skb, noffset - offset);
593 memcpy(pos, assoc_data->ie + offset, noffset - offset);
594 offset = noffset;
595 }
596
Johannes Berg76f03032012-03-08 15:02:05 +0100597 if (assoc_data->wmm) {
598 if (assoc_data->uapsd) {
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200599 qos_info = ifmgd->uapsd_queues;
600 qos_info |= (ifmgd->uapsd_max_sp_len <<
Johannes Berg66e67e42012-01-20 13:55:27 +0100601 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
602 } else {
603 qos_info = 0;
604 }
605
606 pos = skb_put(skb, 9);
607 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
608 *pos++ = 7; /* len */
609 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
610 *pos++ = 0x50;
611 *pos++ = 0xf2;
612 *pos++ = 2; /* WME */
613 *pos++ = 0; /* WME info */
614 *pos++ = 1; /* WME ver */
615 *pos++ = qos_info;
616 }
617
618 /* add any remaining custom (i.e. vendor specific here) IEs */
619 if (assoc_data->ie_len && assoc_data->ie) {
620 noffset = assoc_data->ie_len;
621 pos = skb_put(skb, noffset - offset);
622 memcpy(pos, assoc_data->ie + offset, noffset - offset);
623 }
624
625 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
626 ieee80211_tx_skb(sdata, skb);
627}
628
Johannes Bergef422bc2008-09-09 10:58:25 +0200629static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +0100630 const u8 *bssid, u16 stype,
Johannes Berg5fef7db2012-02-24 13:50:52 +0100631 u16 reason, bool send_frame,
632 u8 *frame_buf)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200633{
634 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100635 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200636 struct sk_buff *skb;
Johannes Berg5fef7db2012-02-24 13:50:52 +0100637 struct ieee80211_mgmt *mgmt = (void *)frame_buf;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200638
Johannes Berg5fef7db2012-02-24 13:50:52 +0100639 /* build frame */
640 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
641 mgmt->duration = 0; /* initialize only */
642 mgmt->seq_ctrl = 0; /* initialize only */
Johannes Berg77fdaa12009-07-07 03:45:17 +0200643 memcpy(mgmt->da, bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100644 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200645 memcpy(mgmt->bssid, bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200646 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200647 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
648
Johannes Berg5fef7db2012-02-24 13:50:52 +0100649 if (send_frame) {
650 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
651 DEAUTH_DISASSOC_LEN);
652 if (!skb)
653 return;
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300654
Johannes Berg5fef7db2012-02-24 13:50:52 +0100655 skb_reserve(skb, local->hw.extra_tx_headroom);
656
657 /* copy in frame */
658 memcpy(skb_put(skb, DEAUTH_DISASSOC_LEN),
659 mgmt, DEAUTH_DISASSOC_LEN);
660
661 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
662 IEEE80211_SKB_CB(skb)->flags |=
663 IEEE80211_TX_INTFL_DONT_ENCRYPT;
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300664 ieee80211_tx_skb(sdata, skb);
Johannes Berg5fef7db2012-02-24 13:50:52 +0100665 }
Johannes Berg9ac19a92008-09-09 10:57:09 +0200666}
667
Kalle Valo572e0012009-02-10 17:09:31 +0200668void ieee80211_send_pspoll(struct ieee80211_local *local,
669 struct ieee80211_sub_if_data *sdata)
670{
Kalle Valo572e0012009-02-10 17:09:31 +0200671 struct ieee80211_pspoll *pspoll;
672 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200673
Kalle Valod8cd1892010-01-05 20:16:26 +0200674 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
675 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200676 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200677
Kalle Valod8cd1892010-01-05 20:16:26 +0200678 pspoll = (struct ieee80211_pspoll *) skb->data;
679 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200680
Johannes Berg62ae67b2009-11-18 18:42:05 +0100681 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
682 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200683}
684
Johannes Berg965beda2009-04-16 13:17:24 +0200685void ieee80211_send_nullfunc(struct ieee80211_local *local,
686 struct ieee80211_sub_if_data *sdata,
687 int powersave)
688{
689 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200690 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530691 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200692
Kalle Valod8cd1892010-01-05 20:16:26 +0200693 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
694 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200695 return;
696
Kalle Valod8cd1892010-01-05 20:16:26 +0200697 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200698 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200699 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200700
Johannes Berg62ae67b2009-11-18 18:42:05 +0100701 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530702 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
703 IEEE80211_STA_CONNECTION_POLL))
704 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
705
Johannes Berg62ae67b2009-11-18 18:42:05 +0100706 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200707}
708
Felix Fietkaud5242152010-01-08 18:06:26 +0100709static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
710 struct ieee80211_sub_if_data *sdata)
711{
712 struct sk_buff *skb;
713 struct ieee80211_hdr *nullfunc;
714 __le16 fc;
715
716 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
717 return;
718
719 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -0700720 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +0100721 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700722
Felix Fietkaud5242152010-01-08 18:06:26 +0100723 skb_reserve(skb, local->hw.extra_tx_headroom);
724
725 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
726 memset(nullfunc, 0, 30);
727 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
728 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
729 nullfunc->frame_control = fc;
730 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
731 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
732 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
733 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
734
735 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
736 ieee80211_tx_skb(sdata, skb);
737}
738
Johannes Bergcc32abd2009-05-15 11:52:31 +0200739/* spectrum management related things */
740static void ieee80211_chswitch_work(struct work_struct *work)
741{
742 struct ieee80211_sub_if_data *sdata =
743 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200744 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
745
Johannes Berg9607e6b2009-12-23 13:15:31 +0100746 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200747 return;
748
Johannes Berg77fdaa12009-07-07 03:45:17 +0200749 mutex_lock(&ifmgd->mtx);
750 if (!ifmgd->associated)
751 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200752
753 sdata->local->oper_channel = sdata->local->csa_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200754 if (!sdata->local->ops->channel_switch) {
755 /* call "hw_config" only if doing sw channel switch */
756 ieee80211_hw_config(sdata->local,
757 IEEE80211_CONF_CHANGE_CHANNEL);
Shahar Levi1ea57b12011-09-08 08:44:05 +0300758 } else {
759 /* update the device channel directly */
760 sdata->local->hw.conf.channel = sdata->local->oper_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200761 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200762
Johannes Berg77fdaa12009-07-07 03:45:17 +0200763 /* XXX: shouldn't really modify cfg80211-owned data! */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100764 ifmgd->associated->channel = sdata->local->oper_channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200765
Johannes Bergcc32abd2009-05-15 11:52:31 +0200766 ieee80211_wake_queues_by_reason(&sdata->local->hw,
767 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200768 out:
769 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
770 mutex_unlock(&ifmgd->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200771}
772
Johannes Berg5ce6e432010-05-11 16:20:57 +0200773void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
774{
775 struct ieee80211_sub_if_data *sdata;
776 struct ieee80211_if_managed *ifmgd;
777
778 sdata = vif_to_sdata(vif);
779 ifmgd = &sdata->u.mgd;
780
781 trace_api_chswitch_done(sdata, success);
782 if (!success) {
783 /*
784 * If the channel switch was not successful, stay
785 * around on the old channel. We currently lack
786 * good handling of this situation, possibly we
787 * should just drop the association.
788 */
789 sdata->local->csa_channel = sdata->local->oper_channel;
790 }
791
792 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
793}
794EXPORT_SYMBOL(ieee80211_chswitch_done);
795
Johannes Bergcc32abd2009-05-15 11:52:31 +0200796static void ieee80211_chswitch_timer(unsigned long data)
797{
798 struct ieee80211_sub_if_data *sdata =
799 (struct ieee80211_sub_if_data *) data;
800 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
801
Johannes Berg5bb644a2009-05-17 11:40:42 +0200802 if (sdata->local->quiescing) {
803 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
804 return;
805 }
806
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400807 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200808}
809
810void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
811 struct ieee80211_channel_sw_ie *sw_elem,
Johannes Berg5ce6e432010-05-11 16:20:57 +0200812 struct ieee80211_bss *bss,
813 u64 timestamp)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200814{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100815 struct cfg80211_bss *cbss =
816 container_of((void *)bss, struct cfg80211_bss, priv);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200817 struct ieee80211_channel *new_ch;
818 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900819 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
820 cbss->channel->band);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200821
Johannes Berg77fdaa12009-07-07 03:45:17 +0200822 ASSERT_MGD_MTX(ifmgd);
823
824 if (!ifmgd->associated)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200825 return;
826
Helmut Schaafbe9c422009-07-23 12:14:04 +0200827 if (sdata->local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200828 return;
829
830 /* Disregard subsequent beacons if we are already running a timer
831 processing a CSA */
832
833 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
834 return;
835
836 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
837 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
838 return;
839
840 sdata->local->csa_channel = new_ch;
841
Johannes Berg5ce6e432010-05-11 16:20:57 +0200842 if (sdata->local->ops->channel_switch) {
843 /* use driver's channel switch callback */
844 struct ieee80211_channel_switch ch_switch;
845 memset(&ch_switch, 0, sizeof(ch_switch));
846 ch_switch.timestamp = timestamp;
847 if (sw_elem->mode) {
848 ch_switch.block_tx = true;
849 ieee80211_stop_queues_by_reason(&sdata->local->hw,
850 IEEE80211_QUEUE_STOP_REASON_CSA);
851 }
852 ch_switch.channel = new_ch;
853 ch_switch.count = sw_elem->count;
854 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
855 drv_channel_switch(sdata->local, &ch_switch);
856 return;
857 }
858
859 /* channel switch handled in software */
Johannes Bergcc32abd2009-05-15 11:52:31 +0200860 if (sw_elem->count <= 1) {
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400861 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200862 } else {
Wey-Yi Guy9feaddc2010-05-05 20:34:02 -0700863 if (sw_elem->mode)
864 ieee80211_stop_queues_by_reason(&sdata->local->hw,
Johannes Bergcc32abd2009-05-15 11:52:31 +0200865 IEEE80211_QUEUE_STOP_REASON_CSA);
866 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
867 mod_timer(&ifmgd->chswitch_timer,
868 jiffies +
869 msecs_to_jiffies(sw_elem->count *
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100870 cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +0200871 }
872}
873
874static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
875 u16 capab_info, u8 *pwr_constr_elem,
876 u8 pwr_constr_elem_len)
877{
878 struct ieee80211_conf *conf = &sdata->local->hw.conf;
879
880 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
881 return;
882
883 /* Power constraint IE length should be 1 octet */
884 if (pwr_constr_elem_len != 1)
885 return;
886
Hong Wua48b13a2012-01-11 20:34:30 +0200887 if ((*pwr_constr_elem <= conf->channel->max_reg_power) &&
Johannes Bergcc32abd2009-05-15 11:52:31 +0200888 (*pwr_constr_elem != sdata->local->power_constr_level)) {
889 sdata->local->power_constr_level = *pwr_constr_elem;
890 ieee80211_hw_config(sdata->local, 0);
891 }
892}
893
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300894void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
895{
896 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
897 struct ieee80211_local *local = sdata->local;
898 struct ieee80211_conf *conf = &local->hw.conf;
899
900 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
901 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
902 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
903
904 local->disable_dynamic_ps = false;
905 conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
906}
907EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
908
909void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
910{
911 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
912 struct ieee80211_local *local = sdata->local;
913 struct ieee80211_conf *conf = &local->hw.conf;
914
915 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
916 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
917 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
918
919 local->disable_dynamic_ps = true;
920 conf->dynamic_ps_timeout = 0;
921 del_timer_sync(&local->dynamic_ps_timer);
922 ieee80211_queue_work(&local->hw,
923 &local->dynamic_ps_enable_work);
924}
925EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
926
Johannes Berg965beda2009-04-16 13:17:24 +0200927/* powersave */
928static void ieee80211_enable_ps(struct ieee80211_local *local,
929 struct ieee80211_sub_if_data *sdata)
930{
931 struct ieee80211_conf *conf = &local->hw.conf;
932
Johannes Bergd5edaed2009-04-22 23:02:51 +0200933 /*
934 * If we are scanning right now then the parameters will
935 * take effect when scan finishes.
936 */
Helmut Schaafbe9c422009-07-23 12:14:04 +0200937 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +0200938 return;
939
Johannes Berg965beda2009-04-16 13:17:24 +0200940 if (conf->dynamic_ps_timeout > 0 &&
941 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
942 mod_timer(&local->dynamic_ps_timer, jiffies +
943 msecs_to_jiffies(conf->dynamic_ps_timeout));
944 } else {
945 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
946 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +0530947
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200948 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
949 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
950 return;
951
952 conf->flags |= IEEE80211_CONF_PS;
953 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +0200954 }
955}
956
957static void ieee80211_change_ps(struct ieee80211_local *local)
958{
959 struct ieee80211_conf *conf = &local->hw.conf;
960
961 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +0200962 ieee80211_enable_ps(local, local->ps_sdata);
963 } else if (conf->flags & IEEE80211_CONF_PS) {
964 conf->flags &= ~IEEE80211_CONF_PS;
965 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
966 del_timer_sync(&local->dynamic_ps_timer);
967 cancel_work_sync(&local->dynamic_ps_enable_work);
968 }
969}
970
Jason Young808118c2011-03-10 16:43:19 -0800971static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
972{
973 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
974 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200975 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -0800976
977 if (!mgd->powersave)
978 return false;
979
Johannes Berg05cb9102011-10-28 11:59:47 +0200980 if (mgd->broken_ap)
981 return false;
982
Jason Young808118c2011-03-10 16:43:19 -0800983 if (!mgd->associated)
984 return false;
985
986 if (!mgd->associated->beacon_ies)
987 return false;
988
989 if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
990 IEEE80211_STA_CONNECTION_POLL))
991 return false;
992
993 rcu_read_lock();
994 sta = sta_info_get(sdata, mgd->bssid);
995 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200996 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -0800997 rcu_read_unlock();
998
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200999 return authorized;
Jason Young808118c2011-03-10 16:43:19 -08001000}
1001
Johannes Berg965beda2009-04-16 13:17:24 +02001002/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +02001003void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +02001004{
1005 struct ieee80211_sub_if_data *sdata, *found = NULL;
1006 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001007 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +02001008
1009 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
1010 local->ps_sdata = NULL;
1011 return;
1012 }
1013
Johannes Bergaf6b6372009-12-23 13:15:35 +01001014 if (!list_empty(&local->work_list)) {
1015 local->ps_sdata = NULL;
1016 goto change;
1017 }
1018
Johannes Berg965beda2009-04-16 13:17:24 +02001019 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +01001020 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +02001021 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +05301022 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1023 /* If an AP vif is found, then disable PS
1024 * by setting the count to zero thereby setting
1025 * ps_sdata to NULL.
1026 */
1027 count = 0;
1028 break;
1029 }
Johannes Berg965beda2009-04-16 13:17:24 +02001030 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1031 continue;
1032 found = sdata;
1033 count++;
1034 }
1035
Jason Young808118c2011-03-10 16:43:19 -08001036 if (count == 1 && ieee80211_powersave_allowed(found)) {
Juuso Oikarinenf90754c2010-06-21 08:59:39 +03001037 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg10f644a2009-04-16 13:17:25 +02001038 s32 beaconint_us;
1039
1040 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +02001041 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +02001042
1043 beaconint_us = ieee80211_tu_to_usec(
1044 found->vif.bss_conf.beacon_int);
1045
Juuso Oikarinenff616382010-06-09 09:51:52 +03001046 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001047 if (timeout < 0) {
1048 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +03001049 * Go to full PSM if the user configures a very low
1050 * latency requirement.
Eliad Peller0ab82b02010-12-03 02:16:23 +02001051 * The 2000 second value is there for compatibility
1052 * until the PM_QOS_NETWORK_LATENCY is configured
1053 * with real values.
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001054 */
Eliad Peller0ab82b02010-12-03 02:16:23 +02001055 if (latency > (1900 * USEC_PER_MSEC) &&
1056 latency != (2000 * USEC_PER_SEC))
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001057 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001058 else
1059 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001060 }
Juuso Oikarinenf90754c2010-06-21 08:59:39 +03001061 local->dynamic_ps_user_timeout = timeout;
1062 if (!local->disable_dynamic_ps)
1063 conf->dynamic_ps_timeout =
1064 local->dynamic_ps_user_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +03001065
Johannes Berg04fe2032009-04-22 18:44:37 +02001066 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +02001067 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +02001068 } else {
Johannes Berg56007a02010-01-26 14:19:52 +01001069 struct ieee80211_bss *bss;
Johannes Berg04fe2032009-04-22 18:44:37 +02001070 int maxslp = 1;
Johannes Berg56007a02010-01-26 14:19:52 +01001071 u8 dtimper;
Johannes Berg04fe2032009-04-22 18:44:37 +02001072
Johannes Berg56007a02010-01-26 14:19:52 +01001073 bss = (void *)found->u.mgd.associated->priv;
1074 dtimper = bss->dtim_period;
1075
1076 /* If the TIM IE is invalid, pretend the value is 1 */
1077 if (!dtimper)
1078 dtimper = 1;
1079 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +02001080 maxslp = min_t(int, dtimper,
1081 latency / beaconint_us);
1082
Johannes Berg9ccebe62009-04-23 10:32:36 +02001083 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +01001084 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +02001085 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +02001086 }
Johannes Berg10f644a2009-04-16 13:17:25 +02001087 } else {
Johannes Berg965beda2009-04-16 13:17:24 +02001088 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +02001089 }
Johannes Berg965beda2009-04-16 13:17:24 +02001090
Johannes Bergaf6b6372009-12-23 13:15:35 +01001091 change:
Johannes Berg965beda2009-04-16 13:17:24 +02001092 ieee80211_change_ps(local);
1093}
1094
1095void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1096{
1097 struct ieee80211_local *local =
1098 container_of(work, struct ieee80211_local,
1099 dynamic_ps_disable_work);
1100
1101 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1102 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1103 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1104 }
1105
1106 ieee80211_wake_queues_by_reason(&local->hw,
1107 IEEE80211_QUEUE_STOP_REASON_PS);
1108}
1109
1110void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1111{
1112 struct ieee80211_local *local =
1113 container_of(work, struct ieee80211_local,
1114 dynamic_ps_enable_work);
1115 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +02001116 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301117 unsigned long flags;
1118 int q;
Johannes Berg965beda2009-04-16 13:17:24 +02001119
1120 /* can only happen when PS was just disabled anyway */
1121 if (!sdata)
1122 return;
1123
Christian Lamparter5e340692011-06-30 21:08:43 +02001124 ifmgd = &sdata->u.mgd;
1125
Johannes Berg965beda2009-04-16 13:17:24 +02001126 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1127 return;
1128
Arik Nemtsov77b70232011-06-26 12:06:54 +03001129 if (!local->disable_dynamic_ps &&
1130 local->hw.conf.dynamic_ps_timeout > 0) {
1131 /* don't enter PS if TX frames are pending */
1132 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301133 mod_timer(&local->dynamic_ps_timer, jiffies +
1134 msecs_to_jiffies(
1135 local->hw.conf.dynamic_ps_timeout));
1136 return;
1137 }
Arik Nemtsov77b70232011-06-26 12:06:54 +03001138
1139 /*
1140 * transmission can be stopped by others which leads to
1141 * dynamic_ps_timer expiry. Postpone the ps timer if it
1142 * is not the actual idle state.
1143 */
1144 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1145 for (q = 0; q < local->hw.queues; q++) {
1146 if (local->queue_stop_reasons[q]) {
1147 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1148 flags);
1149 mod_timer(&local->dynamic_ps_timer, jiffies +
1150 msecs_to_jiffies(
1151 local->hw.conf.dynamic_ps_timeout));
1152 return;
1153 }
1154 }
1155 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301156 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +05301157
Vivek Natarajan375177b2010-02-09 14:50:28 +05301158 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
Mohammed Shafi Shajakhan9c38a8b2011-12-14 19:46:07 +05301159 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301160 netif_tx_stop_all_queues(sdata->dev);
Johannes Berg965beda2009-04-16 13:17:24 +02001161
Vivek Natarajane8306f92011-04-06 11:41:10 +05301162 if (drv_tx_frames_pending(local))
1163 mod_timer(&local->dynamic_ps_timer, jiffies +
1164 msecs_to_jiffies(
1165 local->hw.conf.dynamic_ps_timeout));
1166 else {
1167 ieee80211_send_nullfunc(local, sdata, 1);
1168 /* Flush to get the tx status of nullfunc frame */
1169 drv_flush(local, false);
1170 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301171 }
1172
Juuso Oikarinen2a130522010-03-09 14:25:02 +02001173 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
1174 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +05301175 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1176 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1177 local->hw.conf.flags |= IEEE80211_CONF_PS;
1178 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1179 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +05301180
Arik Nemtsov77b70232011-06-26 12:06:54 +03001181 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1182 netif_tx_wake_all_queues(sdata->dev);
Johannes Berg965beda2009-04-16 13:17:24 +02001183}
1184
1185void ieee80211_dynamic_ps_timer(unsigned long data)
1186{
1187 struct ieee80211_local *local = (void *) data;
1188
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -07001189 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +02001190 return;
1191
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001192 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +02001193}
1194
Johannes Berg60f8b392008-09-08 17:44:22 +02001195/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001196static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +02001197 struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e822007-05-05 11:45:53 -07001198 u8 *wmm_param, size_t wmm_param_len)
1199{
Jiri Bencf0706e822007-05-05 11:45:53 -07001200 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +02001201 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e822007-05-05 11:45:53 -07001202 size_t left;
1203 int count;
Kalle Valoab133152010-01-12 10:42:31 +02001204 u8 *pos, uapsd_queues = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -07001205
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001206 if (!local->ops->conf_tx)
1207 return;
1208
Johannes Bergaf6b6372009-12-23 13:15:35 +01001209 if (local->hw.queues < 4)
Johannes Berg3434fbd2008-05-03 00:59:37 +02001210 return;
1211
1212 if (!wmm_param)
1213 return;
1214
Jiri Bencf0706e822007-05-05 11:45:53 -07001215 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
1216 return;
Kalle Valoab133152010-01-12 10:42:31 +02001217
1218 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02001219 uapsd_queues = ifmgd->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +02001220
Jiri Bencf0706e822007-05-05 11:45:53 -07001221 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +01001222 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e822007-05-05 11:45:53 -07001223 return;
Johannes Berg46900292009-02-15 12:44:28 +01001224 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e822007-05-05 11:45:53 -07001225
1226 pos = wmm_param + 8;
1227 left = wmm_param_len - 8;
1228
1229 memset(&params, 0, sizeof(params));
1230
Jiri Bencf0706e822007-05-05 11:45:53 -07001231 local->wmm_acm = 0;
1232 for (; left >= 4; left -= 4, pos += 4) {
1233 int aci = (pos[0] >> 5) & 0x03;
1234 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +02001235 bool uapsd = false;
Jiri Bencf0706e822007-05-05 11:45:53 -07001236 int queue;
1237
1238 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001239 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +02001240 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +02001241 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001242 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +02001243 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1244 uapsd = true;
Jiri Bencf0706e822007-05-05 11:45:53 -07001245 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001246 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +02001247 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +02001248 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001249 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +02001250 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1251 uapsd = true;
Jiri Bencf0706e822007-05-05 11:45:53 -07001252 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001253 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +02001254 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +02001255 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001256 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +02001257 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1258 uapsd = true;
Jiri Bencf0706e822007-05-05 11:45:53 -07001259 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001260 case 0: /* AC_BE */
Jiri Bencf0706e822007-05-05 11:45:53 -07001261 default:
Johannes Berge100bb62008-04-30 18:51:21 +02001262 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +02001263 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +02001264 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +02001265 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1266 uapsd = true;
Jiri Bencf0706e822007-05-05 11:45:53 -07001267 break;
1268 }
1269
1270 params.aifs = pos[0] & 0x0f;
1271 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
1272 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +02001273 params.txop = get_unaligned_le16(pos + 2);
Kalle Valoab133152010-01-12 10:42:31 +02001274 params.uapsd = uapsd;
1275
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001276#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001277 wiphy_debug(local->hw.wiphy,
1278 "WMM queue=%d aci=%d acm=%d aifs=%d "
1279 "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);
Johannes Berg3330d7b2008-02-10 16:49:38 +01001283#endif
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001284 sdata->tx_conf[queue] = params;
1285 if (drv_conf_tx(local, sdata, queue, &params))
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001286 wiphy_debug(local->hw.wiphy,
1287 "failed to set TX queue parameters for queue %d\n",
1288 queue);
Jiri Bencf0706e822007-05-05 11:45:53 -07001289 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +02001290
1291 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +02001292 sdata->vif.bss_conf.qos = true;
Jiri Bencf0706e822007-05-05 11:45:53 -07001293}
1294
Johannes Berg7a5158e2008-10-08 10:59:33 +02001295static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
1296 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +02001297{
Johannes Bergbda39332008-10-11 01:51:51 +02001298 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001299 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001300 bool use_protection;
1301 bool use_short_preamble;
1302 bool use_short_slot;
1303
1304 if (erp_valid) {
1305 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
1306 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
1307 } else {
1308 use_protection = false;
1309 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
1310 }
1311
1312 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Felix Fietkau43d35342010-01-15 03:00:48 +01001313 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
1314 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +02001315
Johannes Berg471b3ef2007-12-28 14:32:58 +01001316 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +01001317 bss_conf->use_cts_prot = use_protection;
1318 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +02001319 }
Daniel Drake7e9ed182007-07-27 15:43:24 +02001320
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001321 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +02001322 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001323 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +02001324 }
Daniel Draked9430a32007-07-27 15:43:24 +02001325
Johannes Berg7a5158e2008-10-08 10:59:33 +02001326 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +02001327 bss_conf->use_short_slot = use_short_slot;
1328 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -04001329 }
1330
1331 return changed;
1332}
1333
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001334static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001335 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +02001336 u32 bss_info_changed)
Jiri Bencf0706e822007-05-05 11:45:53 -07001337{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001338 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001339 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +03001340 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001341
Johannes Bergae5eb022008-10-14 16:58:37 +02001342 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001343 /* set timing information */
Juuso Oikarinen68542962010-06-09 13:43:26 +03001344 bss_conf->beacon_int = cbss->beacon_interval;
Johannes Berge9ac0742012-03-13 14:29:30 +01001345 bss_conf->last_tsf = cbss->tsf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001346
Johannes Berg77fdaa12009-07-07 03:45:17 +02001347 bss_info_changed |= BSS_CHANGED_BEACON_INT;
1348 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001349 cbss->capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001350
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01001351 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
1352 IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
1353
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001354 sdata->u.mgd.associated = cbss;
1355 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01001356
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001357 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1358
Johannes Bergb291ba12009-07-10 15:29:03 +02001359 /* just to be sure */
1360 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1361 IEEE80211_STA_BEACON_POLL);
1362
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001363 ieee80211_led_assoc(local, 1);
1364
Johannes Berge5b900d2010-07-29 16:08:55 +02001365 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
1366 bss_conf->dtim_period = bss->dtim_period;
1367 else
1368 bss_conf->dtim_period = 0;
1369
Juuso Oikarinen68542962010-06-09 13:43:26 +03001370 bss_conf->assoc = 1;
Johannes Berg9cef8732009-05-14 13:10:14 +02001371
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001372 /* Tell the driver to monitor connection quality (if supported) */
Johannes Bergea086352012-01-19 09:29:58 +01001373 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03001374 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001375 bss_info_changed |= BSS_CHANGED_CQM;
1376
Juuso Oikarinen68542962010-06-09 13:43:26 +03001377 /* Enable ARP filtering */
1378 if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
1379 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
1380 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
1381 }
1382
Johannes Bergae5eb022008-10-14 16:58:37 +02001383 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03001384
Johannes Berg056508d2009-07-30 21:43:55 +02001385 mutex_lock(&local->iflist_mtx);
1386 ieee80211_recalc_ps(local, -1);
Johannes Berg025e6be2010-10-05 10:41:47 +02001387 ieee80211_recalc_smps(local);
Johannes Berg056508d2009-07-30 21:43:55 +02001388 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02001389
John W. Linville8a5b33f2010-01-06 15:39:39 -05001390 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001391 netif_carrier_on(sdata->dev);
Jiri Bencf0706e822007-05-05 11:45:53 -07001392}
1393
Jouni Malinene69e95d2010-03-29 23:29:31 -07001394static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg37ad3882012-02-24 13:50:54 +01001395 u16 stype, u16 reason, bool tx,
1396 u8 *frame_buf)
Tomas Winkleraa458d12008-09-09 00:32:12 +03001397{
Johannes Berg46900292009-02-15 12:44:28 +01001398 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001399 struct ieee80211_local *local = sdata->local;
1400 struct sta_info *sta;
Johannes Berg3cc52402012-03-09 13:12:35 +01001401 u32 changed = 0;
Johannes Bergb291ba12009-07-10 15:29:03 +02001402 u8 bssid[ETH_ALEN];
Tomas Winkleraa458d12008-09-09 00:32:12 +03001403
Johannes Berg77fdaa12009-07-07 03:45:17 +02001404 ASSERT_MGD_MTX(ifmgd);
1405
Johannes Berg37ad3882012-02-24 13:50:54 +01001406 if (WARN_ON_ONCE(tx && !frame_buf))
1407 return;
1408
Johannes Bergb291ba12009-07-10 15:29:03 +02001409 if (WARN_ON(!ifmgd->associated))
1410 return;
1411
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001412 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Johannes Bergb291ba12009-07-10 15:29:03 +02001413
Johannes Berg77fdaa12009-07-07 03:45:17 +02001414 ifmgd->associated = NULL;
1415 memset(ifmgd->bssid, 0, ETH_ALEN);
1416
1417 /*
1418 * we need to commit the associated = NULL change because the
1419 * scan code uses that to determine whether this iface should
1420 * go to/wake up from powersave or not -- and could otherwise
1421 * wake the queues erroneously.
1422 */
1423 smp_mb();
1424
1425 /*
1426 * Thus, we can only afterwards stop the queues -- to account
1427 * for the case where another CPU is finishing a scan at this
1428 * time -- we don't want the scan code to enable queues.
1429 */
Tomas Winkleraa458d12008-09-09 00:32:12 +03001430
John W. Linville8a5b33f2010-01-06 15:39:39 -05001431 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001432 netif_carrier_off(sdata->dev);
1433
Johannes Berg2a419052010-06-10 10:21:29 +02001434 mutex_lock(&local->sta_mtx);
Johannes Bergabe60632009-11-25 17:46:18 +01001435 sta = sta_info_get(sdata, bssid);
Sujith4cad6c72010-02-10 14:52:21 +05301436 if (sta) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001437 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
Johannes Berg53f73c02010-10-05 19:37:40 +02001438 ieee80211_sta_tear_down_BA_sessions(sta, tx);
Sujith4cad6c72010-02-10 14:52:21 +05301439 }
Johannes Berg2a419052010-06-10 10:21:29 +02001440 mutex_unlock(&local->sta_mtx);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001441
Johannes Berg37ad3882012-02-24 13:50:54 +01001442 /* deauthenticate/disassociate now */
1443 if (tx || frame_buf)
1444 ieee80211_send_deauth_disassoc(sdata, bssid, stype, reason,
1445 tx, frame_buf);
1446
1447 /* flush out frame */
1448 if (tx)
1449 drv_flush(local, false);
1450
1451 /* remove AP and TDLS peers */
1452 sta_info_flush(local, sdata);
1453
1454 /* finally reset all BSS / config parameters */
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001455 changed |= ieee80211_reset_erp_info(sdata);
1456
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001457 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001458 changed |= BSS_CHANGED_ASSOC;
1459 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001460
Johannes Berg413ad502009-05-08 21:21:06 +02001461 /* on the next assoc, re-program HT parameters */
1462 sdata->ht_opmode_valid = false;
Ben Greearef96a8422011-11-18 11:32:00 -08001463 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
1464 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
Johannes Berg413ad502009-05-08 21:21:06 +02001465
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301466 local->power_constr_level = 0;
1467
Kalle Valo520eb822008-12-18 23:35:27 +02001468 del_timer_sync(&local->dynamic_ps_timer);
1469 cancel_work_sync(&local->dynamic_ps_enable_work);
1470
Kalle Valoe0cb6862008-12-18 23:35:13 +02001471 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1472 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
Johannes Berg3cc52402012-03-09 13:12:35 +01001473 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Kalle Valoe0cb6862008-12-18 23:35:13 +02001474 }
Eliad Pellera3314002011-05-26 11:46:37 +03001475 local->ps_sdata = NULL;
Kalle Valoe0cb6862008-12-18 23:35:13 +02001476
Juuso Oikarinen68542962010-06-09 13:43:26 +03001477 /* Disable ARP filtering */
1478 if (sdata->vif.bss_conf.arp_filter_enabled) {
1479 sdata->vif.bss_conf.arp_filter_enabled = false;
1480 changed |= BSS_CHANGED_ARP_FILTER;
1481 }
1482
Johannes Berg3abead52012-03-02 15:56:59 +01001483 sdata->vif.bss_conf.qos = false;
1484 changed |= BSS_CHANGED_QOS;
1485
Johannes Berg0aaffa92010-05-05 15:28:27 +02001486 /* The BSSID (not really interesting) and HT changed */
1487 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001488 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001489
Johannes Berg3cc52402012-03-09 13:12:35 +01001490 /* channel(_type) changes are handled by ieee80211_hw_config */
1491 WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
1492 ieee80211_hw_config(local, 0);
1493
Johannes Berg3abead52012-03-02 15:56:59 +01001494 /* disassociated - set to defaults now */
1495 ieee80211_set_wmm_default(sdata, false);
1496
Johannes Bergb9dcf712010-08-27 12:35:54 +02001497 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1498 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1499 del_timer_sync(&sdata->u.mgd.timer);
1500 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001501}
Jiri Bencf0706e822007-05-05 11:45:53 -07001502
Kalle Valo3cf335d2009-03-22 21:57:06 +02001503void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1504 struct ieee80211_hdr *hdr)
1505{
1506 /*
1507 * We can postpone the mgd.timer whenever receiving unicast frames
1508 * from AP because we know that the connection is working both ways
1509 * at that time. But multicast frames (and hence also beacons) must
1510 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001511 * data idle periods for sending the periodic probe request to the
1512 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001513 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001514 if (is_multicast_ether_addr(hdr->addr1))
1515 return;
1516
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001517 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02001518}
Jiri Bencf0706e822007-05-05 11:45:53 -07001519
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001520static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1521{
1522 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1523
1524 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1525 IEEE80211_STA_CONNECTION_POLL)))
1526 return;
1527
1528 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1529 IEEE80211_STA_BEACON_POLL);
1530 mutex_lock(&sdata->local->iflist_mtx);
1531 ieee80211_recalc_ps(sdata->local, -1);
1532 mutex_unlock(&sdata->local->iflist_mtx);
1533
1534 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1535 return;
1536
1537 /*
1538 * We've received a probe response, but are not sure whether
1539 * we have or will be receiving any beacons or data, so let's
1540 * schedule the timers again, just in case.
1541 */
1542 ieee80211_sta_reset_beacon_monitor(sdata);
1543
1544 mod_timer(&ifmgd->conn_mon_timer,
1545 round_jiffies_up(jiffies +
1546 IEEE80211_CONNECTION_IDLE_TIME));
1547}
1548
1549void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001550 struct ieee80211_hdr *hdr, bool ack)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001551{
Felix Fietkau75706d02010-12-02 21:01:07 +01001552 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001553 return;
1554
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001555 if (ack)
1556 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001557
1558 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1559 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001560 if (ack)
1561 sdata->u.mgd.probe_send_count = 0;
1562 else
1563 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001564 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1565 }
1566}
1567
Maxim Levitskya43abf22009-07-31 18:54:12 +03001568static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1569{
1570 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1571 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001572 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08001573 u8 unicast_limit = max(1, max_probe_tries - 3);
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001574
1575 /*
1576 * Try sending broadcast probe requests for the last three
1577 * probe requests after the first ones failed since some
1578 * buggy APs only support broadcast probe requests.
1579 */
1580 if (ifmgd->probe_send_count >= unicast_limit)
1581 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03001582
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001583 /*
1584 * When the hardware reports an accurate Tx ACK status, it's
1585 * better to send a nullfunc frame instead of a probe request,
1586 * as it will kick us off the AP quickly if we aren't associated
1587 * anymore. The timeout will be reset if the frame is ACKed by
1588 * the AP.
1589 */
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001590 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1591 ifmgd->nullfunc_failed = false;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001592 ieee80211_send_nullfunc(sdata->local, sdata, 0);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001593 } else {
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001594 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Paul Stewarta806c552011-06-23 09:00:11 -08001595 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0,
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05301596 (u32) -1, true, false);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001597 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03001598
1599 ifmgd->probe_send_count++;
Ben Greear180205b2011-02-04 15:30:24 -08001600 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Maxim Levitskya43abf22009-07-31 18:54:12 +03001601 run_again(ifmgd, ifmgd->probe_timeout);
1602}
1603
Johannes Bergb291ba12009-07-10 15:29:03 +02001604static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1605 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02001606{
Kalle Valo04de8382009-03-22 21:57:35 +02001607 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02001608 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02001609
Johannes Berg9607e6b2009-12-23 13:15:31 +01001610 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02001611 return;
1612
Luis R. Rodriguez91a3bd72009-07-23 16:37:47 -07001613 if (sdata->local->scanning)
1614 return;
1615
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001616 if (sdata->local->tmp_channel)
1617 return;
1618
Johannes Berg77fdaa12009-07-07 03:45:17 +02001619 mutex_lock(&ifmgd->mtx);
1620
1621 if (!ifmgd->associated)
1622 goto out;
1623
Michael Buescha8604022009-04-15 14:41:22 -04001624#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergb291ba12009-07-10 15:29:03 +02001625 if (beacon && net_ratelimit())
1626 printk(KERN_DEBUG "%s: detected beacon loss from AP "
Johannes Berg47846c92009-11-25 17:46:19 +01001627 "- sending probe request\n", sdata->name);
Michael Buescha8604022009-04-15 14:41:22 -04001628#endif
Kalle Valo04de8382009-03-22 21:57:35 +02001629
Johannes Bergb291ba12009-07-10 15:29:03 +02001630 /*
1631 * The driver/our work has already reported this event or the
1632 * connection monitoring has kicked in and we have already sent
1633 * a probe request. Or maybe the AP died and the driver keeps
1634 * reporting until we disassociate...
1635 *
1636 * In either case we have to ignore the current call to this
1637 * function (except for setting the correct probe reason bit)
1638 * because otherwise we would reset the timer every time and
1639 * never check whether we received a probe response!
1640 */
1641 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1642 IEEE80211_STA_CONNECTION_POLL))
1643 already = true;
1644
1645 if (beacon)
1646 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1647 else
1648 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1649
1650 if (already)
1651 goto out;
1652
Johannes Berg4e751842009-06-10 15:16:52 +02001653 mutex_lock(&sdata->local->iflist_mtx);
1654 ieee80211_recalc_ps(sdata->local, -1);
1655 mutex_unlock(&sdata->local->iflist_mtx);
1656
Maxim Levitskya43abf22009-07-31 18:54:12 +03001657 ifmgd->probe_send_count = 0;
1658 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001659 out:
1660 mutex_unlock(&ifmgd->mtx);
Kalle Valo04de8382009-03-22 21:57:35 +02001661}
1662
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001663struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
1664 struct ieee80211_vif *vif)
1665{
1666 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1667 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1668 struct sk_buff *skb;
1669 const u8 *ssid;
1670
1671 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1672 return NULL;
1673
1674 ASSERT_MGD_MTX(ifmgd);
1675
1676 if (!ifmgd->associated)
1677 return NULL;
1678
1679 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1680 skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid,
Johannes Berg85a237f2011-07-18 18:08:36 +02001681 (u32) -1, ssid + 2, ssid[1],
1682 NULL, 0, true);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001683
1684 return skb;
1685}
1686EXPORT_SYMBOL(ieee80211_ap_probereq_get);
1687
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001688static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
1689{
1690 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1691 struct ieee80211_local *local = sdata->local;
1692 u8 bssid[ETH_ALEN];
Johannes Berg5fef7db2012-02-24 13:50:52 +01001693 u8 frame_buf[DEAUTH_DISASSOC_LEN];
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001694
1695 mutex_lock(&ifmgd->mtx);
1696 if (!ifmgd->associated) {
1697 mutex_unlock(&ifmgd->mtx);
1698 return;
1699 }
1700
1701 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1702
Ben Greear180205b2011-02-04 15:30:24 -08001703 printk(KERN_DEBUG "%s: Connection to AP %pM lost.\n",
1704 sdata->name, bssid);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001705
Johannes Berg37ad3882012-02-24 13:50:54 +01001706 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
1707 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
1708 false, frame_buf);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001709 mutex_unlock(&ifmgd->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001710
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001711 /*
1712 * must be outside lock due to cfg80211,
1713 * but that's not a problem.
1714 */
Johannes Berg5fef7db2012-02-24 13:50:52 +01001715 cfg80211_send_deauth(sdata->dev, frame_buf, DEAUTH_DISASSOC_LEN);
Felix Fietkaufcac4fb2011-11-16 13:34:55 +01001716
1717 mutex_lock(&local->mtx);
1718 ieee80211_recalc_idle(local);
1719 mutex_unlock(&local->mtx);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001720}
1721
1722void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02001723{
1724 struct ieee80211_sub_if_data *sdata =
1725 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001726 u.mgd.beacon_connection_loss_work);
Paul Stewarta85e1d52011-12-09 11:01:49 -08001727 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1728 struct sta_info *sta;
1729
1730 if (ifmgd->associated) {
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05301731 rcu_read_lock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08001732 sta = sta_info_get(sdata, ifmgd->bssid);
1733 if (sta)
1734 sta->beacon_loss_count++;
Mohammed Shafi Shajakhan30fa9042011-12-27 18:54:07 +05301735 rcu_read_unlock();
Paul Stewarta85e1d52011-12-09 11:01:49 -08001736 }
Johannes Bergb291ba12009-07-10 15:29:03 +02001737
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001738 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1739 __ieee80211_connection_loss(sdata);
1740 else
1741 ieee80211_mgd_probe_ap(sdata, true);
Johannes Bergb291ba12009-07-10 15:29:03 +02001742}
1743
Kalle Valo04de8382009-03-22 21:57:35 +02001744void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1745{
1746 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001747 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02001748
Johannes Bergb5878a22010-04-07 16:48:40 +02001749 trace_api_beacon_loss(sdata);
1750
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001751 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
1752 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02001753}
1754EXPORT_SYMBOL(ieee80211_beacon_loss);
1755
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001756void ieee80211_connection_loss(struct ieee80211_vif *vif)
1757{
1758 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1759 struct ieee80211_hw *hw = &sdata->local->hw;
1760
Johannes Bergb5878a22010-04-07 16:48:40 +02001761 trace_api_connection_loss(sdata);
1762
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001763 WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
1764 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1765}
1766EXPORT_SYMBOL(ieee80211_connection_loss);
1767
1768
Johannes Berg66e67e42012-01-20 13:55:27 +01001769static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
1770 bool assoc)
1771{
1772 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
1773
1774 lockdep_assert_held(&sdata->u.mgd.mtx);
1775
Johannes Berg66e67e42012-01-20 13:55:27 +01001776 if (!assoc) {
1777 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
1778
1779 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
1780 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
1781 }
1782
1783 cfg80211_put_bss(auth_data->bss);
1784 kfree(auth_data);
1785 sdata->u.mgd.auth_data = NULL;
1786}
1787
1788static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1789 struct ieee80211_mgmt *mgmt, size_t len)
1790{
1791 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
1792 u8 *pos;
1793 struct ieee802_11_elems elems;
1794
1795 pos = mgmt->u.auth.variable;
1796 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1797 if (!elems.challenge)
1798 return;
1799 auth_data->expected_transaction = 4;
1800 ieee80211_send_auth(sdata, 3, auth_data->algorithm,
1801 elems.challenge - 2, elems.challenge_len + 2,
1802 auth_data->bss->bssid, auth_data->bss->bssid,
1803 auth_data->key, auth_data->key_len,
1804 auth_data->key_idx);
1805}
1806
1807static enum rx_mgmt_action __must_check
1808ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1809 struct ieee80211_mgmt *mgmt, size_t len)
1810{
1811 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1812 u8 bssid[ETH_ALEN];
1813 u16 auth_alg, auth_transaction, status_code;
1814 struct sta_info *sta;
1815
1816 lockdep_assert_held(&ifmgd->mtx);
1817
1818 if (len < 24 + 6)
1819 return RX_MGMT_NONE;
1820
1821 if (!ifmgd->auth_data || ifmgd->auth_data->done)
1822 return RX_MGMT_NONE;
1823
1824 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
1825
Felix Fietkau888d04d2012-03-01 15:22:09 +01001826 if (compare_ether_addr(bssid, mgmt->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01001827 return RX_MGMT_NONE;
1828
1829 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1830 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1831 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1832
1833 if (auth_alg != ifmgd->auth_data->algorithm ||
1834 auth_transaction != ifmgd->auth_data->expected_transaction)
1835 return RX_MGMT_NONE;
1836
1837 if (status_code != WLAN_STATUS_SUCCESS) {
1838 printk(KERN_DEBUG "%s: %pM denied authentication (status %d)\n",
1839 sdata->name, mgmt->sa, status_code);
1840 goto out;
1841 }
1842
1843 switch (ifmgd->auth_data->algorithm) {
1844 case WLAN_AUTH_OPEN:
1845 case WLAN_AUTH_LEAP:
1846 case WLAN_AUTH_FT:
1847 break;
1848 case WLAN_AUTH_SHARED_KEY:
1849 if (ifmgd->auth_data->expected_transaction != 4) {
1850 ieee80211_auth_challenge(sdata, mgmt, len);
1851 /* need another frame */
1852 return RX_MGMT_NONE;
1853 }
1854 break;
1855 default:
1856 WARN_ONCE(1, "invalid auth alg %d",
1857 ifmgd->auth_data->algorithm);
1858 return RX_MGMT_NONE;
1859 }
1860
1861 printk(KERN_DEBUG "%s: authenticated\n", sdata->name);
1862 out:
Johannes Berg66e67e42012-01-20 13:55:27 +01001863 ifmgd->auth_data->done = true;
1864 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
1865 run_again(ifmgd, ifmgd->auth_data->timeout);
1866
1867 /* move station state to auth */
1868 mutex_lock(&sdata->local->sta_mtx);
1869 sta = sta_info_get(sdata, bssid);
1870 if (!sta) {
1871 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
1872 goto out_err;
1873 }
1874 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
1875 printk(KERN_DEBUG "%s: failed moving %pM to auth\n",
1876 sdata->name, bssid);
1877 goto out_err;
1878 }
1879 mutex_unlock(&sdata->local->sta_mtx);
1880
1881 return RX_MGMT_CFG80211_RX_AUTH;
1882 out_err:
1883 mutex_unlock(&sdata->local->sta_mtx);
1884 /* ignore frame -- wait for timeout */
1885 return RX_MGMT_NONE;
1886}
1887
1888
Johannes Berg77fdaa12009-07-07 03:45:17 +02001889static enum rx_mgmt_action __must_check
1890ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001891 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e822007-05-05 11:45:53 -07001892{
Johannes Berg46900292009-02-15 12:44:28 +01001893 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001894 const u8 *bssid = NULL;
Jiri Bencf0706e822007-05-05 11:45:53 -07001895 u16 reason_code;
1896
Johannes Berg66e67e42012-01-20 13:55:27 +01001897 lockdep_assert_held(&ifmgd->mtx);
1898
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001899 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001900 return RX_MGMT_NONE;
Jiri Bencf0706e822007-05-05 11:45:53 -07001901
Johannes Berg66e67e42012-01-20 13:55:27 +01001902 if (!ifmgd->associated ||
Felix Fietkau888d04d2012-03-01 15:22:09 +01001903 compare_ether_addr(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01001904 return RX_MGMT_NONE;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001905
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001906 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e822007-05-05 11:45:53 -07001907
1908 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1909
Johannes Berg77fdaa12009-07-07 03:45:17 +02001910 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001911 sdata->name, bssid, reason_code);
Jiri Bencf0706e822007-05-05 11:45:53 -07001912
Johannes Berg37ad3882012-02-24 13:50:54 +01001913 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
1914
Johannes Berg7da7cc12010-08-05 17:02:38 +02001915 mutex_lock(&sdata->local->mtx);
Johannes Berg63f170e2009-12-23 13:15:33 +01001916 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001917 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001918
1919 return RX_MGMT_CFG80211_DEAUTH;
Jiri Bencf0706e822007-05-05 11:45:53 -07001920}
1921
1922
Johannes Berg77fdaa12009-07-07 03:45:17 +02001923static enum rx_mgmt_action __must_check
1924ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1925 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e822007-05-05 11:45:53 -07001926{
Johannes Berg46900292009-02-15 12:44:28 +01001927 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e822007-05-05 11:45:53 -07001928 u16 reason_code;
1929
Johannes Berg66e67e42012-01-20 13:55:27 +01001930 lockdep_assert_held(&ifmgd->mtx);
1931
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001932 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001933 return RX_MGMT_NONE;
Jiri Bencf0706e822007-05-05 11:45:53 -07001934
Johannes Berg66e67e42012-01-20 13:55:27 +01001935 if (!ifmgd->associated ||
Felix Fietkau888d04d2012-03-01 15:22:09 +01001936 compare_ether_addr(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg77fdaa12009-07-07 03:45:17 +02001937 return RX_MGMT_NONE;
Jiri Bencf0706e822007-05-05 11:45:53 -07001938
1939 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1940
Johannes Berg0ff71612009-09-26 14:45:41 +02001941 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001942 sdata->name, mgmt->sa, reason_code);
Jiri Bencf0706e822007-05-05 11:45:53 -07001943
Johannes Berg37ad3882012-02-24 13:50:54 +01001944 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
1945
Johannes Berg7da7cc12010-08-05 17:02:38 +02001946 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01001947 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001948 mutex_unlock(&sdata->local->mtx);
Johannes Berg37ad3882012-02-24 13:50:54 +01001949
Johannes Berg77fdaa12009-07-07 03:45:17 +02001950 return RX_MGMT_CFG80211_DISASSOC;
Jiri Bencf0706e822007-05-05 11:45:53 -07001951}
1952
Christian Lamparterc74d0842011-10-15 00:14:49 +02001953static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
1954 u8 *supp_rates, unsigned int supp_rates_len,
1955 u32 *rates, u32 *basic_rates,
1956 bool *have_higher_than_11mbit,
1957 int *min_rate, int *min_rate_index)
1958{
1959 int i, j;
1960
1961 for (i = 0; i < supp_rates_len; i++) {
1962 int rate = (supp_rates[i] & 0x7f) * 5;
1963 bool is_basic = !!(supp_rates[i] & 0x80);
1964
1965 if (rate > 110)
1966 *have_higher_than_11mbit = true;
1967
1968 /*
1969 * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
1970 * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
1971 *
1972 * Note: Even through the membership selector and the basic
1973 * rate flag share the same bit, they are not exactly
1974 * the same.
1975 */
1976 if (!!(supp_rates[i] & 0x80) &&
1977 (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
1978 continue;
1979
1980 for (j = 0; j < sband->n_bitrates; j++) {
1981 if (sband->bitrates[j].bitrate == rate) {
1982 *rates |= BIT(j);
1983 if (is_basic)
1984 *basic_rates |= BIT(j);
1985 if (rate < *min_rate) {
1986 *min_rate = rate;
1987 *min_rate_index = j;
1988 }
1989 break;
1990 }
1991 }
1992 }
1993}
Jiri Bencf0706e822007-05-05 11:45:53 -07001994
Johannes Berg66e67e42012-01-20 13:55:27 +01001995static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
1996 bool assoc)
1997{
1998 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
1999
2000 lockdep_assert_held(&sdata->u.mgd.mtx);
2001
Johannes Berg66e67e42012-01-20 13:55:27 +01002002 if (!assoc) {
2003 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2004
2005 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
2006 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2007 }
2008
2009 kfree(assoc_data);
2010 sdata->u.mgd.assoc_data = NULL;
2011}
2012
2013static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2014 struct cfg80211_bss *cbss,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002015 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e822007-05-05 11:45:53 -07002016{
Johannes Berg46900292009-02-15 12:44:28 +01002017 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002018 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01002019 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -07002020 struct sta_info *sta;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002021 u8 *pos;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002022 u16 capab_info, aid;
Jiri Bencf0706e822007-05-05 11:45:53 -07002023 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02002024 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Bergae5eb022008-10-14 16:58:37 +02002025 u32 changed = 0;
Christian Lamparterc74d0842011-10-15 00:14:49 +02002026 int err;
Johannes Bergae5eb022008-10-14 16:58:37 +02002027 u16 ap_ht_cap_flags;
Jiri Bencf0706e822007-05-05 11:45:53 -07002028
Johannes Bergaf6b6372009-12-23 13:15:35 +01002029 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e822007-05-05 11:45:53 -07002030
Jiri Bencf0706e822007-05-05 11:45:53 -07002031 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002032 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e822007-05-05 11:45:53 -07002033
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002034 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
Johannes Berg05cb9102011-10-28 11:59:47 +02002035 printk(KERN_DEBUG
2036 "%s: invalid AID value 0x%x; bits 15:14 not set\n",
2037 sdata->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02002038 aid &= ~(BIT(15) | BIT(14));
2039
Johannes Berg05cb9102011-10-28 11:59:47 +02002040 ifmgd->broken_ap = false;
2041
2042 if (aid == 0 || aid > IEEE80211_MAX_AID) {
2043 printk(KERN_DEBUG
2044 "%s: invalid AID value %d (out of range), turn off PS\n",
2045 sdata->name, aid);
2046 aid = 0;
2047 ifmgd->broken_ap = true;
2048 }
2049
Johannes Bergaf6b6372009-12-23 13:15:35 +01002050 pos = mgmt->u.assoc_resp.variable;
2051 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2052
Jiri Bencf0706e822007-05-05 11:45:53 -07002053 if (!elems.supp_rates) {
2054 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002055 sdata->name);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002056 return false;
Jiri Bencf0706e822007-05-05 11:45:53 -07002057 }
2058
Johannes Berg46900292009-02-15 12:44:28 +01002059 ifmgd->aid = aid;
Jiri Bencf0706e822007-05-05 11:45:53 -07002060
Guy Eilam2a33bee2011-08-17 15:18:15 +03002061 mutex_lock(&sdata->local->sta_mtx);
2062 /*
2063 * station info was already allocated and inserted before
2064 * the association and should be available to us
2065 */
Johannes Berg7852e362012-01-20 13:55:24 +01002066 sta = sta_info_get(sdata, cbss->bssid);
Guy Eilam2a33bee2011-08-17 15:18:15 +03002067 if (WARN_ON(!sta)) {
2068 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002069 return false;
Jiri Bencf0706e822007-05-05 11:45:53 -07002070 }
2071
Johannes Berg66e67e42012-01-20 13:55:27 +01002072 sband = local->hw.wiphy->bands[local->oper_channel->band];
Johannes Berg8318d782008-01-24 19:38:38 +01002073
Johannes Bergab1faea2009-07-01 21:41:17 +02002074 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Ben Greearef96a8422011-11-18 11:32:00 -08002075 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02002076 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02002077
2078 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002079
Johannes Berg4b7679a2008-09-18 18:14:18 +02002080 rate_control_rate_init(sta);
Jiri Bencf0706e822007-05-05 11:45:53 -07002081
Johannes Berg46900292009-02-15 12:44:28 +01002082 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002083 set_sta_flag(sta, WLAN_STA_MFP);
Jouni Malinen5394af42009-01-08 13:31:59 +02002084
Johannes Bergddf4ac52008-10-22 11:41:38 +02002085 if (elems.wmm_param)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002086 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002087
Johannes Bergc8987872012-01-20 13:55:17 +01002088 err = sta_info_move_state(sta, IEEE80211_STA_AUTH);
2089 if (!err)
2090 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
2091 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
2092 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
2093 if (err) {
2094 printk(KERN_DEBUG
2095 "%s: failed to move station %pM to desired state\n",
2096 sdata->name, sta->sta.addr);
2097 WARN_ON(__sta_info_destroy(sta));
2098 mutex_unlock(&sdata->local->sta_mtx);
2099 return false;
2100 }
2101
Johannes Berg7852e362012-01-20 13:55:24 +01002102 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergddf4ac52008-10-22 11:41:38 +02002103
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03002104 /*
2105 * Always handle WMM once after association regardless
2106 * of the first value the AP uses. Setting -1 here has
2107 * that effect because the AP values is an unsigned
2108 * 4-bit value.
2109 */
2110 ifmgd->wmm_last_param_set = -1;
2111
Johannes Bergddf4ac52008-10-22 11:41:38 +02002112 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02002113 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e822007-05-05 11:45:53 -07002114 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02002115 else
Johannes Berg3abead52012-03-02 15:56:59 +01002116 ieee80211_set_wmm_default(sdata, false);
2117 changed |= BSS_CHANGED_QOS;
Jiri Bencf0706e822007-05-05 11:45:53 -07002118
Johannes Bergae5eb022008-10-14 16:58:37 +02002119 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Bergab1faea2009-07-01 21:41:17 +02002120 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02002121 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +05302122 cbss->bssid, ap_ht_cap_flags,
2123 false);
Johannes Bergae5eb022008-10-14 16:58:37 +02002124
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002125 /* set AID and assoc capability,
2126 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01002127 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07002128 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002129 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e822007-05-05 11:45:53 -07002130
Kalle Valo15b7b062009-03-22 21:57:14 +02002131 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01002132 * If we're using 4-addr mode, let the AP know that we're
2133 * doing so, so that it can create the STA VLAN on its side
2134 */
2135 if (ifmgd->use_4addr)
2136 ieee80211_send_4addr_nullfunc(local, sdata);
2137
2138 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02002139 * Start timer to probe the connection to the AP now.
2140 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02002141 */
Johannes Bergb291ba12009-07-10 15:29:03 +02002142 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04002143 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02002144
Johannes Bergaf6b6372009-12-23 13:15:35 +01002145 return true;
Jiri Bencf0706e822007-05-05 11:45:53 -07002146}
2147
Johannes Berg66e67e42012-01-20 13:55:27 +01002148static enum rx_mgmt_action __must_check
2149ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2150 struct ieee80211_mgmt *mgmt, size_t len,
2151 struct cfg80211_bss **bss)
2152{
2153 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2154 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
2155 u16 capab_info, status_code, aid;
2156 struct ieee802_11_elems elems;
2157 u8 *pos;
2158 bool reassoc;
Jiri Bencf0706e822007-05-05 11:45:53 -07002159
Johannes Berg66e67e42012-01-20 13:55:27 +01002160 lockdep_assert_held(&ifmgd->mtx);
2161
2162 if (!assoc_data)
2163 return RX_MGMT_NONE;
Felix Fietkau888d04d2012-03-01 15:22:09 +01002164 if (compare_ether_addr(assoc_data->bss->bssid, mgmt->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002165 return RX_MGMT_NONE;
2166
2167 /*
2168 * AssocResp and ReassocResp have identical structure, so process both
2169 * of them in this function.
2170 */
2171
2172 if (len < 24 + 6)
2173 return RX_MGMT_NONE;
2174
2175 reassoc = ieee80211_is_reassoc_req(mgmt->frame_control);
2176 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2177 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2178 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2179
2180 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
2181 "status=%d aid=%d)\n",
2182 sdata->name, reassoc ? "Rea" : "A", mgmt->sa,
2183 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
2184
2185 pos = mgmt->u.assoc_resp.variable;
2186 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2187
2188 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
2189 elems.timeout_int && elems.timeout_int_len == 5 &&
2190 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
2191 u32 tu, ms;
2192 tu = get_unaligned_le32(elems.timeout_int + 1);
2193 ms = tu * 1024 / 1000;
2194 printk(KERN_DEBUG "%s: %pM rejected association temporarily; "
2195 "comeback duration %u TU (%u ms)\n",
2196 sdata->name, mgmt->sa, tu, ms);
2197 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
2198 if (ms > IEEE80211_ASSOC_TIMEOUT)
2199 run_again(ifmgd, assoc_data->timeout);
2200 return RX_MGMT_NONE;
2201 }
2202
2203 *bss = assoc_data->bss;
2204
2205 if (status_code != WLAN_STATUS_SUCCESS) {
2206 printk(KERN_DEBUG "%s: %pM denied association (code=%d)\n",
2207 sdata->name, mgmt->sa, status_code);
2208 ieee80211_destroy_assoc_data(sdata, false);
2209 } else {
2210 printk(KERN_DEBUG "%s: associated\n", sdata->name);
2211
Johannes Berg66e67e42012-01-20 13:55:27 +01002212 if (!ieee80211_assoc_success(sdata, *bss, mgmt, len)) {
2213 /* oops -- internal error -- send timeout for now */
Johannes Berg79ebfb82012-02-20 14:19:58 +01002214 ieee80211_destroy_assoc_data(sdata, true);
Johannes Berg66e67e42012-01-20 13:55:27 +01002215 sta_info_destroy_addr(sdata, mgmt->bssid);
2216 cfg80211_put_bss(*bss);
2217 return RX_MGMT_CFG80211_ASSOC_TIMEOUT;
2218 }
Johannes Berg79ebfb82012-02-20 14:19:58 +01002219
2220 /*
2221 * destroy assoc_data afterwards, as otherwise an idle
2222 * recalc after assoc_data is NULL but before associated
2223 * is set can cause the interface to go idle
2224 */
2225 ieee80211_destroy_assoc_data(sdata, true);
Johannes Berg66e67e42012-01-20 13:55:27 +01002226 }
2227
2228 return RX_MGMT_CFG80211_RX_ASSOC;
2229}
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002230static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e822007-05-05 11:45:53 -07002231 struct ieee80211_mgmt *mgmt,
2232 size_t len,
2233 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002234 struct ieee802_11_elems *elems,
2235 bool beacon)
Jiri Bencf0706e822007-05-05 11:45:53 -07002236{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002237 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002238 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02002239 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01002240 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01002241 bool need_ps = false;
2242
Johannes Berg66e67e42012-01-20 13:55:27 +01002243 if (sdata->u.mgd.associated &&
Felix Fietkau888d04d2012-03-01 15:22:09 +01002244 compare_ether_addr(mgmt->bssid, sdata->u.mgd.associated->bssid)
2245 == 0) {
Johannes Berg56007a02010-01-26 14:19:52 +01002246 bss = (void *)sdata->u.mgd.associated->priv;
2247 /* not previously set so we may need to recalc */
2248 need_ps = !bss->dtim_period;
2249 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002250
Johannes Berg5bda6172008-09-08 11:05:10 +02002251 if (elems->ds_params && elems->ds_params_len == 1)
Bruno Randolf59eb21a2011-01-17 13:37:28 +09002252 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
2253 rx_status->band);
Johannes Berg5bda6172008-09-08 11:05:10 +02002254 else
2255 freq = rx_status->freq;
2256
2257 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2258
2259 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2260 return;
Jiri Bencf0706e822007-05-05 11:45:53 -07002261
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002262 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01002263 channel, beacon);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002264 if (bss)
2265 ieee80211_rx_bss_put(local, bss);
2266
2267 if (!sdata->u.mgd.associated)
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002268 return;
Jiri Bencf0706e822007-05-05 11:45:53 -07002269
Johannes Berg56007a02010-01-26 14:19:52 +01002270 if (need_ps) {
2271 mutex_lock(&local->iflist_mtx);
2272 ieee80211_recalc_ps(local, -1);
2273 mutex_unlock(&local->iflist_mtx);
2274 }
2275
Sujithc481ec92009-01-06 09:28:37 +05302276 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002277 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
Johannes Berg77fdaa12009-07-07 03:45:17 +02002278 ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05302279 struct ieee80211_channel_sw_ie *sw_elem =
2280 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
Johannes Berg5ce6e432010-05-11 16:20:57 +02002281 ieee80211_sta_process_chanswitch(sdata, sw_elem,
2282 bss, rx_status->mactime);
Sujithc481ec92009-01-06 09:28:37 +05302283 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002284}
2285
2286
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002287static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01002288 struct sk_buff *skb)
Jiri Bencf0706e822007-05-05 11:45:53 -07002289{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002290 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02002291 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002292 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
2293 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03002294 struct ieee802_11_elems elems;
2295
Kalle Valo15b7b062009-03-22 21:57:14 +02002296 ifmgd = &sdata->u.mgd;
2297
Johannes Berg77fdaa12009-07-07 03:45:17 +02002298 ASSERT_MGD_MTX(ifmgd);
2299
Felix Fietkau888d04d2012-03-01 15:22:09 +01002300 if (compare_ether_addr(mgmt->da, sdata->vif.addr))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03002301 return; /* ignore ProbeResp to foreign address */
2302
Ester Kummerae6a44e2008-06-27 18:54:48 +03002303 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
2304 if (baselen > len)
2305 return;
2306
2307 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
2308 &elems);
2309
Johannes Berg98c8fcc2008-09-08 17:44:26 +02002310 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03002311
Johannes Berg77fdaa12009-07-07 03:45:17 +02002312 if (ifmgd->associated &&
Felix Fietkau888d04d2012-03-01 15:22:09 +01002313 compare_ether_addr(mgmt->bssid, ifmgd->associated->bssid) == 0)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002314 ieee80211_reset_ap_probe(sdata);
Johannes Berg66e67e42012-01-20 13:55:27 +01002315
2316 if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
Felix Fietkau888d04d2012-03-01 15:22:09 +01002317 compare_ether_addr(mgmt->bssid, ifmgd->auth_data->bss->bssid)
2318 == 0) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002319 /* got probe response, continue with auth */
2320 printk(KERN_DEBUG "%s: direct probe responded\n", sdata->name);
2321 ifmgd->auth_data->tries = 0;
2322 ifmgd->auth_data->timeout = jiffies;
2323 run_again(ifmgd, ifmgd->auth_data->timeout);
2324 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002325}
2326
Johannes Bergd91f36d2009-04-16 13:17:26 +02002327/*
2328 * This is the canonical list of information elements we care about,
2329 * the filter code also gives us all changes to the Microsoft OUI
2330 * (00:50:F2) vendor IE which is used for WMM which we need to track.
2331 *
2332 * We implement beacon filtering in software since that means we can
2333 * avoid processing the frame here and in cfg80211, and userspace
2334 * will not be able to tell whether the hardware supports it or not.
2335 *
2336 * XXX: This list needs to be dynamic -- userspace needs to be able to
2337 * add items it requires. It also needs to be able to tell us to
2338 * look out for other vendor IEs.
2339 */
2340static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02002341 (1ULL << WLAN_EID_COUNTRY) |
2342 (1ULL << WLAN_EID_ERP_INFO) |
2343 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
2344 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
2345 (1ULL << WLAN_EID_HT_CAPABILITY) |
2346 (1ULL << WLAN_EID_HT_INFORMATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02002347
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002348static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e822007-05-05 11:45:53 -07002349 struct ieee80211_mgmt *mgmt,
2350 size_t len,
2351 struct ieee80211_rx_status *rx_status)
2352{
Johannes Bergd91f36d2009-04-16 13:17:26 +02002353 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002354 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e822007-05-05 11:45:53 -07002355 size_t baselen;
2356 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002357 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01002358 u32 changed = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02002359 bool erp_valid, directed_tim = false;
Johannes Berg7a5158e2008-10-08 10:59:33 +02002360 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02002361 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002362 u8 *bssid;
2363
Johannes Berg66e67e42012-01-20 13:55:27 +01002364 lockdep_assert_held(&ifmgd->mtx);
Jiri Bencf0706e822007-05-05 11:45:53 -07002365
Ester Kummerae6a44e2008-06-27 18:54:48 +03002366 /* Process beacon from the current BSS */
2367 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2368 if (baselen > len)
2369 return;
2370
Johannes Bergd91f36d2009-04-16 13:17:26 +02002371 if (rx_status->freq != local->hw.conf.channel->center_freq)
Jiri Bencf0706e822007-05-05 11:45:53 -07002372 return;
Jiri Bencf0706e822007-05-05 11:45:53 -07002373
Johannes Berg66e67e42012-01-20 13:55:27 +01002374 if (ifmgd->assoc_data && !ifmgd->assoc_data->have_beacon &&
Felix Fietkau888d04d2012-03-01 15:22:09 +01002375 compare_ether_addr(mgmt->bssid, ifmgd->assoc_data->bss->bssid)
2376 == 0) {
Johannes Berg66e67e42012-01-20 13:55:27 +01002377 ieee802_11_parse_elems(mgmt->u.beacon.variable,
2378 len - baselen, &elems);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002379
Johannes Berg66e67e42012-01-20 13:55:27 +01002380 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
2381 false);
2382 ifmgd->assoc_data->have_beacon = true;
2383 ifmgd->assoc_data->sent_assoc = false;
2384 /* continue assoc process */
2385 ifmgd->assoc_data->timeout = jiffies;
2386 run_again(ifmgd, ifmgd->assoc_data->timeout);
2387 return;
2388 }
2389
2390 if (!ifmgd->associated ||
Felix Fietkau888d04d2012-03-01 15:22:09 +01002391 compare_ether_addr(mgmt->bssid, ifmgd->associated->bssid))
Johannes Berg66e67e42012-01-20 13:55:27 +01002392 return;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002393 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002394
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002395 /* Track average RSSI from the Beacon frames of the current AP */
2396 ifmgd->last_beacon_signal = rx_status->signal;
2397 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
2398 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03002399 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002400 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03002401 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002402 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002403 } else {
2404 ifmgd->ave_beacon_signal =
2405 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
2406 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
2407 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03002408 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002409 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07002410
2411 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
2412 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
2413 int sig = ifmgd->ave_beacon_signal;
2414 int last_sig = ifmgd->last_ave_beacon_signal;
2415
2416 /*
2417 * if signal crosses either of the boundaries, invoke callback
2418 * with appropriate parameters
2419 */
2420 if (sig > ifmgd->rssi_max_thold &&
2421 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
2422 ifmgd->last_ave_beacon_signal = sig;
2423 drv_rssi_callback(local, RSSI_EVENT_HIGH);
2424 } else if (sig < ifmgd->rssi_min_thold &&
2425 (last_sig >= ifmgd->rssi_max_thold ||
2426 last_sig == 0)) {
2427 ifmgd->last_ave_beacon_signal = sig;
2428 drv_rssi_callback(local, RSSI_EVENT_LOW);
2429 }
2430 }
2431
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002432 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03002433 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Johannes Bergea086352012-01-19 09:29:58 +01002434 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
Jouni Malinen17e4ec12010-03-29 23:28:30 -07002435 int sig = ifmgd->ave_beacon_signal / 16;
2436 int last_event = ifmgd->last_cqm_event_signal;
2437 int thold = bss_conf->cqm_rssi_thold;
2438 int hyst = bss_conf->cqm_rssi_hyst;
2439 if (sig < thold &&
2440 (last_event == 0 || sig < last_event - hyst)) {
2441 ifmgd->last_cqm_event_signal = sig;
2442 ieee80211_cqm_rssi_notify(
2443 &sdata->vif,
2444 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
2445 GFP_KERNEL);
2446 } else if (sig > thold &&
2447 (last_event == 0 || sig > last_event + hyst)) {
2448 ifmgd->last_cqm_event_signal = sig;
2449 ieee80211_cqm_rssi_notify(
2450 &sdata->vif,
2451 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
2452 GFP_KERNEL);
2453 }
2454 }
2455
Johannes Bergb291ba12009-07-10 15:29:03 +02002456 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Jouni Malinen92778182009-05-14 21:15:36 +03002457#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2458 if (net_ratelimit()) {
2459 printk(KERN_DEBUG "%s: cancelling probereq poll due "
Johannes Berg47846c92009-11-25 17:46:19 +01002460 "to a received beacon\n", sdata->name);
Jouni Malinen92778182009-05-14 21:15:36 +03002461 }
2462#endif
Johannes Bergb291ba12009-07-10 15:29:03 +02002463 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Johannes Berg4e751842009-06-10 15:16:52 +02002464 mutex_lock(&local->iflist_mtx);
2465 ieee80211_recalc_ps(local, -1);
2466 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03002467 }
2468
Johannes Bergb291ba12009-07-10 15:29:03 +02002469 /*
2470 * Push the beacon loss detection into the future since
2471 * we are processing a beacon from the AP just now.
2472 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04002473 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002474
Johannes Bergd91f36d2009-04-16 13:17:26 +02002475 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
2476 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
2477 len - baselen, &elems,
2478 care_about_ies, ncrc);
2479
2480 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Johannes Berge7ec86f2009-04-18 17:33:24 +02002481 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
2482 ifmgd->aid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02002483
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002484 if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) {
Jouni Malinen30196672009-05-19 17:01:43 +03002485 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
2486 true);
Johannes Bergd91f36d2009-04-16 13:17:26 +02002487
Johannes Berg4ced3f72010-07-19 16:39:04 +02002488 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jouni Malinen30196672009-05-19 17:01:43 +03002489 elems.wmm_param_len);
2490 }
Johannes Bergfe3fa822008-09-08 11:05:09 +02002491
Vivek Natarajan25c9c872009-03-02 20:20:30 +05302492 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Kalle Valo1fb36062009-02-10 17:09:24 +02002493 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02002494 if (local->hw.conf.dynamic_ps_timeout > 0) {
2495 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2496 ieee80211_hw_config(local,
2497 IEEE80211_CONF_CHANGE_PS);
2498 ieee80211_send_nullfunc(local, sdata, 0);
2499 } else {
2500 local->pspolling = true;
2501
2502 /*
2503 * Here is assumed that the driver will be
2504 * able to send ps-poll frame and receive a
2505 * response even though power save mode is
2506 * enabled, but some drivers might require
2507 * to disable power save here. This needs
2508 * to be investigated.
2509 */
2510 ieee80211_send_pspoll(local, sdata);
2511 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08002512 }
2513 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02002514
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002515 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Jouni Malinen30196672009-05-19 17:01:43 +03002516 return;
2517 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002518 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03002519
Johannes Berg7a5158e2008-10-08 10:59:33 +02002520 if (elems.erp_info && elems.erp_info_len >= 1) {
2521 erp_valid = true;
2522 erp_value = elems.erp_info[0];
2523 } else {
2524 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04002525 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02002526 changed |= ieee80211_handle_bss_capability(sdata,
2527 le16_to_cpu(mgmt->u.beacon.capab_info),
2528 erp_valid, erp_value);
Jiri Bencf0706e822007-05-05 11:45:53 -07002529
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002530
Vasanthakumar Thiagarajan53d6f812009-02-11 22:18:49 +05302531 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Bergab1faea2009-07-01 21:41:17 +02002532 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02002533 struct sta_info *sta;
2534 struct ieee80211_supported_band *sband;
2535 u16 ap_ht_cap_flags;
2536
2537 rcu_read_lock();
2538
Johannes Bergabe60632009-11-25 17:46:18 +01002539 sta = sta_info_get(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002540 if (WARN_ON(!sta)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02002541 rcu_read_unlock();
2542 return;
2543 }
2544
2545 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2546
Ben Greearef96a8422011-11-18 11:32:00 -08002547 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergae5eb022008-10-14 16:58:37 +02002548 elems.ht_cap_elem, &sta->sta.ht_cap);
2549
2550 ap_ht_cap_flags = sta->sta.ht_cap.cap;
2551
2552 rcu_read_unlock();
2553
2554 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +05302555 bssid, ap_ht_cap_flags, true);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02002556 }
2557
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -07002558 /* Note: country IE parsing is done for us by cfg80211 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002559 if (elems.country_elem) {
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05302560 /* TODO: IBSS also needs this */
2561 if (elems.pwr_constr_elem)
2562 ieee80211_handle_pwr_constr(sdata,
2563 le16_to_cpu(mgmt->u.probe_resp.capab_info),
2564 elems.pwr_constr_elem,
2565 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002566 }
2567
Johannes Berg471b3ef2007-12-28 14:32:58 +01002568 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e822007-05-05 11:45:53 -07002569}
2570
Johannes Berg1fa57d02010-06-10 10:21:32 +02002571void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
2572 struct sk_buff *skb)
Jiri Bencf0706e822007-05-05 11:45:53 -07002573{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002574 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e822007-05-05 11:45:53 -07002575 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e822007-05-05 11:45:53 -07002576 struct ieee80211_mgmt *mgmt;
Johannes Berg66e67e42012-01-20 13:55:27 +01002577 struct cfg80211_bss *bss = NULL;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002578 enum rx_mgmt_action rma = RX_MGMT_NONE;
Jiri Bencf0706e822007-05-05 11:45:53 -07002579 u16 fc;
2580
Jiri Bencf0706e822007-05-05 11:45:53 -07002581 rx_status = (struct ieee80211_rx_status *) skb->cb;
2582 mgmt = (struct ieee80211_mgmt *) skb->data;
2583 fc = le16_to_cpu(mgmt->frame_control);
2584
Johannes Berg77fdaa12009-07-07 03:45:17 +02002585 mutex_lock(&ifmgd->mtx);
2586
Johannes Berg66e67e42012-01-20 13:55:27 +01002587 switch (fc & IEEE80211_FCTL_STYPE) {
2588 case IEEE80211_STYPE_BEACON:
2589 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
2590 break;
2591 case IEEE80211_STYPE_PROBE_RESP:
2592 ieee80211_rx_mgmt_probe_resp(sdata, skb);
2593 break;
2594 case IEEE80211_STYPE_AUTH:
2595 rma = ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
2596 break;
2597 case IEEE80211_STYPE_DEAUTH:
2598 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
2599 break;
2600 case IEEE80211_STYPE_DISASSOC:
2601 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
2602 break;
2603 case IEEE80211_STYPE_ASSOC_RESP:
2604 case IEEE80211_STYPE_REASSOC_RESP:
2605 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss);
2606 break;
2607 case IEEE80211_STYPE_ACTION:
2608 switch (mgmt->u.action.category) {
2609 case WLAN_CATEGORY_SPECTRUM_MGMT:
2610 ieee80211_sta_process_chanswitch(sdata,
2611 &mgmt->u.action.u.chan_switch.sw_elem,
2612 (void *)ifmgd->associated->priv,
2613 rx_status->mactime);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002614 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002615 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002616 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002617 mutex_unlock(&ifmgd->mtx);
2618
Johannes Berg66e67e42012-01-20 13:55:27 +01002619 switch (rma) {
2620 case RX_MGMT_NONE:
2621 /* no action */
2622 break;
2623 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470613c2009-10-13 13:28:13 +02002624 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg66e67e42012-01-20 13:55:27 +01002625 break;
2626 case RX_MGMT_CFG80211_DISASSOC:
2627 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
2628 break;
2629 case RX_MGMT_CFG80211_RX_AUTH:
2630 cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, skb->len);
2631 break;
2632 case RX_MGMT_CFG80211_RX_ASSOC:
2633 cfg80211_send_rx_assoc(sdata->dev, bss, (u8 *)mgmt, skb->len);
2634 break;
2635 case RX_MGMT_CFG80211_ASSOC_TIMEOUT:
2636 cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid);
2637 break;
2638 default:
2639 WARN(1, "unexpected: %d", rma);
Johannes Bergb054b742010-06-07 21:50:07 +02002640 }
Jiri Bencf0706e822007-05-05 11:45:53 -07002641}
2642
Johannes Berg9c6bd792008-09-11 00:01:52 +02002643static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e822007-05-05 11:45:53 -07002644{
2645 struct ieee80211_sub_if_data *sdata =
2646 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01002647 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002648 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e822007-05-05 11:45:53 -07002649
Johannes Berg5bb644a2009-05-17 11:40:42 +02002650 if (local->quiescing) {
2651 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2652 return;
2653 }
2654
Johannes Berg64592c82010-06-10 10:21:31 +02002655 ieee80211_queue_work(&local->hw, &sdata->work);
Jiri Bencf0706e822007-05-05 11:45:53 -07002656}
2657
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002658static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg95acac62011-07-12 12:30:59 +02002659 u8 *bssid, u8 reason)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002660{
2661 struct ieee80211_local *local = sdata->local;
2662 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5fef7db2012-02-24 13:50:52 +01002663 u8 frame_buf[DEAUTH_DISASSOC_LEN];
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002664
2665 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
2666 IEEE80211_STA_BEACON_POLL);
2667
Johannes Berg37ad3882012-02-24 13:50:54 +01002668 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
2669 false, frame_buf);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002670 mutex_unlock(&ifmgd->mtx);
Johannes Berg37ad3882012-02-24 13:50:54 +01002671
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002672 /*
2673 * must be outside lock due to cfg80211,
2674 * but that's not a problem.
2675 */
Johannes Berg5fef7db2012-02-24 13:50:52 +01002676 cfg80211_send_deauth(sdata->dev, frame_buf, DEAUTH_DISASSOC_LEN);
Felix Fietkaufcac4fb2011-11-16 13:34:55 +01002677
2678 mutex_lock(&local->mtx);
2679 ieee80211_recalc_idle(local);
2680 mutex_unlock(&local->mtx);
2681
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002682 mutex_lock(&ifmgd->mtx);
2683}
2684
Johannes Berg66e67e42012-01-20 13:55:27 +01002685static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
2686{
2687 struct ieee80211_local *local = sdata->local;
2688 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2689 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
2690
2691 lockdep_assert_held(&ifmgd->mtx);
2692
2693 if (WARN_ON_ONCE(!auth_data))
2694 return -EINVAL;
2695
Johannes Berg66e67e42012-01-20 13:55:27 +01002696 auth_data->tries++;
2697
2698 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
2699 printk(KERN_DEBUG "%s: authentication with %pM timed out\n",
2700 sdata->name, auth_data->bss->bssid);
2701
2702 /*
2703 * Most likely AP is not in the range so remove the
2704 * bss struct for that AP.
2705 */
2706 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
2707
2708 return -ETIMEDOUT;
2709 }
2710
2711 if (auth_data->bss->proberesp_ies) {
2712 printk(KERN_DEBUG "%s: send auth to %pM (try %d/%d)\n",
2713 sdata->name, auth_data->bss->bssid, auth_data->tries,
2714 IEEE80211_AUTH_MAX_TRIES);
2715
2716 auth_data->expected_transaction = 2;
2717 ieee80211_send_auth(sdata, 1, auth_data->algorithm,
2718 auth_data->ie, auth_data->ie_len,
2719 auth_data->bss->bssid,
2720 auth_data->bss->bssid, NULL, 0, 0);
2721 } else {
2722 const u8 *ssidie;
2723
2724 printk(KERN_DEBUG "%s: direct probe to %pM (try %d/%i)\n",
2725 sdata->name, auth_data->bss->bssid, auth_data->tries,
2726 IEEE80211_AUTH_MAX_TRIES);
2727
2728 ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
2729 if (!ssidie)
2730 return -EINVAL;
2731 /*
2732 * Direct probe is sent to broadcast address as some APs
2733 * will not answer to direct packet in unassociated state.
2734 */
2735 ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1],
2736 NULL, 0, (u32) -1, true, false);
2737 }
2738
2739 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
2740 run_again(ifmgd, auth_data->timeout);
2741
2742 return 0;
2743}
2744
2745static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
2746{
2747 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2748 struct ieee80211_local *local = sdata->local;
2749
2750 lockdep_assert_held(&sdata->u.mgd.mtx);
2751
Johannes Berg66e67e42012-01-20 13:55:27 +01002752 assoc_data->tries++;
2753 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
2754 printk(KERN_DEBUG "%s: association with %pM timed out\n",
2755 sdata->name, assoc_data->bss->bssid);
2756
2757 /*
2758 * Most likely AP is not in the range so remove the
2759 * bss struct for that AP.
2760 */
2761 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
2762
2763 return -ETIMEDOUT;
2764 }
2765
2766 printk(KERN_DEBUG "%s: associate with %pM (try %d/%d)\n",
2767 sdata->name, assoc_data->bss->bssid, assoc_data->tries,
2768 IEEE80211_ASSOC_MAX_TRIES);
2769 ieee80211_send_assoc(sdata);
2770
2771 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
2772 run_again(&sdata->u.mgd, assoc_data->timeout);
2773
2774 return 0;
2775}
2776
Johannes Berg1fa57d02010-06-10 10:21:32 +02002777void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02002778{
Johannes Berg60f8b392008-09-08 17:44:22 +02002779 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02002780 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002781
Johannes Berg77fdaa12009-07-07 03:45:17 +02002782 mutex_lock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002783
Johannes Berg66e67e42012-01-20 13:55:27 +01002784 if (ifmgd->auth_data &&
2785 time_after(jiffies, ifmgd->auth_data->timeout)) {
2786 if (ifmgd->auth_data->done) {
2787 /*
2788 * ok ... we waited for assoc but userspace didn't,
2789 * so let's just kill the auth data
2790 */
2791 ieee80211_destroy_auth_data(sdata, false);
2792 } else if (ieee80211_probe_auth(sdata)) {
2793 u8 bssid[ETH_ALEN];
2794
2795 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2796
2797 ieee80211_destroy_auth_data(sdata, false);
2798
2799 mutex_unlock(&ifmgd->mtx);
2800 cfg80211_send_auth_timeout(sdata->dev, bssid);
2801 mutex_lock(&ifmgd->mtx);
2802 }
2803 } else if (ifmgd->auth_data)
2804 run_again(ifmgd, ifmgd->auth_data->timeout);
2805
2806 if (ifmgd->assoc_data &&
2807 time_after(jiffies, ifmgd->assoc_data->timeout)) {
2808 if (!ifmgd->assoc_data->have_beacon ||
2809 ieee80211_do_assoc(sdata)) {
2810 u8 bssid[ETH_ALEN];
2811
2812 memcpy(bssid, ifmgd->assoc_data->bss->bssid, ETH_ALEN);
2813
2814 ieee80211_destroy_assoc_data(sdata, false);
2815
2816 mutex_unlock(&ifmgd->mtx);
2817 cfg80211_send_assoc_timeout(sdata->dev, bssid);
2818 mutex_lock(&ifmgd->mtx);
2819 }
2820 } else if (ifmgd->assoc_data)
2821 run_again(ifmgd, ifmgd->assoc_data->timeout);
2822
Johannes Bergb291ba12009-07-10 15:29:03 +02002823 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
2824 IEEE80211_STA_CONNECTION_POLL) &&
2825 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03002826 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002827 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002828
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002829 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002830
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002831 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Ben Greear180205b2011-02-04 15:30:24 -08002832 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002833 else
Ben Greear180205b2011-02-04 15:30:24 -08002834 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002835
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002836 /* ACK received for nullfunc probing frame */
2837 if (!ifmgd->probe_send_count)
2838 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002839 else if (ifmgd->nullfunc_failed) {
2840 if (ifmgd->probe_send_count < max_tries) {
2841#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2842 wiphy_debug(local->hw.wiphy,
2843 "%s: No ack for nullfunc frame to"
Ben Greearbfc31df2011-01-14 09:32:18 -08002844 " AP %pM, try %d/%i\n",
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002845 sdata->name, bssid,
Ben Greearbfc31df2011-01-14 09:32:18 -08002846 ifmgd->probe_send_count, max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002847#endif
2848 ieee80211_mgd_probe_ap_send(sdata);
2849 } else {
2850#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2851 wiphy_debug(local->hw.wiphy,
2852 "%s: No ack for nullfunc frame to"
2853 " AP %pM, disconnecting.\n",
Felix Fietkauc658e5d2010-12-07 04:40:18 +01002854 sdata->name, bssid);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002855#endif
Johannes Berg95acac62011-07-12 12:30:59 +02002856 ieee80211_sta_connection_lost(sdata, bssid,
2857 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002858 }
2859 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Bergb291ba12009-07-10 15:29:03 +02002860 run_again(ifmgd, ifmgd->probe_timeout);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002861 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
2862#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2863 wiphy_debug(local->hw.wiphy,
2864 "%s: Failed to send nullfunc to AP %pM"
2865 " after %dms, disconnecting.\n",
2866 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08002867 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002868#endif
Johannes Berg95acac62011-07-12 12:30:59 +02002869 ieee80211_sta_connection_lost(sdata, bssid,
2870 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002871 } else if (ifmgd->probe_send_count < max_tries) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03002872#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Ben Greearb38afa82010-10-07 16:12:06 -07002873 wiphy_debug(local->hw.wiphy,
2874 "%s: No probe response from AP %pM"
Ben Greearbfc31df2011-01-14 09:32:18 -08002875 " after %dms, try %d/%i\n",
Ben Greearb38afa82010-10-07 16:12:06 -07002876 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08002877 bssid, probe_wait_ms,
Ben Greearbfc31df2011-01-14 09:32:18 -08002878 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002879#endif
2880 ieee80211_mgd_probe_ap_send(sdata);
2881 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02002882 /*
2883 * We actually lost the connection ... or did we?
2884 * Let's make sure!
2885 */
Ben Greearb38afa82010-10-07 16:12:06 -07002886 wiphy_debug(local->hw.wiphy,
2887 "%s: No probe response from AP %pM"
2888 " after %dms, disconnecting.\n",
2889 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08002890 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002891
Johannes Berg95acac62011-07-12 12:30:59 +02002892 ieee80211_sta_connection_lost(sdata, bssid,
2893 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Johannes Bergb291ba12009-07-10 15:29:03 +02002894 }
2895 }
2896
Johannes Berg77fdaa12009-07-07 03:45:17 +02002897 mutex_unlock(&ifmgd->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01002898
2899 mutex_lock(&local->mtx);
2900 ieee80211_recalc_idle(local);
2901 mutex_unlock(&local->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002902}
Johannes Berg0a51b272008-09-08 17:44:25 +02002903
Johannes Bergb291ba12009-07-10 15:29:03 +02002904static void ieee80211_sta_bcn_mon_timer(unsigned long data)
2905{
2906 struct ieee80211_sub_if_data *sdata =
2907 (struct ieee80211_sub_if_data *) data;
2908 struct ieee80211_local *local = sdata->local;
2909
2910 if (local->quiescing)
2911 return;
2912
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002913 ieee80211_queue_work(&sdata->local->hw,
2914 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002915}
2916
2917static void ieee80211_sta_conn_mon_timer(unsigned long data)
2918{
2919 struct ieee80211_sub_if_data *sdata =
2920 (struct ieee80211_sub_if_data *) data;
2921 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2922 struct ieee80211_local *local = sdata->local;
2923
2924 if (local->quiescing)
2925 return;
2926
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002927 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002928}
2929
2930static void ieee80211_sta_monitor_work(struct work_struct *work)
2931{
2932 struct ieee80211_sub_if_data *sdata =
2933 container_of(work, struct ieee80211_sub_if_data,
2934 u.mgd.monitor_work);
2935
2936 ieee80211_mgd_probe_ap(sdata, false);
2937}
2938
Johannes Berga1678f82008-09-11 00:01:47 +02002939static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2940{
Eliad Peller494f1fe2012-02-19 15:26:09 +02002941 u32 flags;
2942
Kalle Vaload935682009-04-19 08:47:19 +03002943 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Bergb291ba12009-07-10 15:29:03 +02002944 sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
2945 IEEE80211_STA_CONNECTION_POLL);
Kalle Vaload935682009-04-19 08:47:19 +03002946
Johannes Bergb291ba12009-07-10 15:29:03 +02002947 /* let's probe the connection once */
Eliad Peller494f1fe2012-02-19 15:26:09 +02002948 flags = sdata->local->hw.flags;
2949 if (!(flags & IEEE80211_HW_CONNECTION_MONITOR))
2950 ieee80211_queue_work(&sdata->local->hw,
2951 &sdata->u.mgd.monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002952 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02002953 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03002954 }
Johannes Berga1678f82008-09-11 00:01:47 +02002955}
2956
Johannes Berg5bb644a2009-05-17 11:40:42 +02002957#ifdef CONFIG_PM
2958void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
2959{
2960 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2961
2962 /*
2963 * we need to use atomic bitops for the running bits
2964 * only because both timers might fire at the same
2965 * time -- the code here is properly synchronised.
2966 */
2967
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02002968 cancel_work_sync(&ifmgd->request_smps_work);
2969
Johannes Berg0ecfe802011-11-09 12:14:16 +01002970 cancel_work_sync(&ifmgd->monitor_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002971 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002972 if (del_timer_sync(&ifmgd->timer))
2973 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2974
2975 cancel_work_sync(&ifmgd->chswitch_work);
2976 if (del_timer_sync(&ifmgd->chswitch_timer))
2977 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
Johannes Bergb291ba12009-07-10 15:29:03 +02002978
Johannes Bergb291ba12009-07-10 15:29:03 +02002979 /* these will just be re-established on connection */
2980 del_timer_sync(&ifmgd->conn_mon_timer);
2981 del_timer_sync(&ifmgd->bcn_mon_timer);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002982}
2983
2984void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
2985{
2986 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2987
Rajkumar Manoharan676b58c2011-07-07 23:33:39 +05302988 if (!ifmgd->associated)
2989 return;
2990
Johannes Berg95acac62011-07-12 12:30:59 +02002991 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
2992 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
2993 mutex_lock(&ifmgd->mtx);
2994 if (ifmgd->associated) {
2995#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2996 wiphy_debug(sdata->local->hw.wiphy,
2997 "%s: driver requested disconnect after resume.\n",
2998 sdata->name);
2999#endif
3000 ieee80211_sta_connection_lost(sdata,
3001 ifmgd->associated->bssid,
3002 WLAN_REASON_UNSPECIFIED);
3003 mutex_unlock(&ifmgd->mtx);
3004 return;
3005 }
3006 mutex_unlock(&ifmgd->mtx);
3007 }
3008
Johannes Berg5bb644a2009-05-17 11:40:42 +02003009 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
3010 add_timer(&ifmgd->timer);
3011 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
3012 add_timer(&ifmgd->chswitch_timer);
Felix Fietkauc8a79722010-11-19 22:55:37 +01003013 ieee80211_sta_reset_beacon_monitor(sdata);
Felix Fietkau46090972010-11-23 20:28:03 +01003014 ieee80211_restart_sta_timer(sdata);
Johannes Berg5bb644a2009-05-17 11:40:42 +02003015}
3016#endif
3017
Johannes Berg9c6bd792008-09-11 00:01:52 +02003018/* interface setup */
3019void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
3020{
Johannes Berg46900292009-02-15 12:44:28 +01003021 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003022
Johannes Berg46900292009-02-15 12:44:28 +01003023 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02003024 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01003025 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02003026 INIT_WORK(&ifmgd->beacon_connection_loss_work,
3027 ieee80211_beacon_connection_loss_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02003028 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01003029 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02003030 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02003031 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
3032 (unsigned long) sdata);
3033 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
3034 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01003035 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05303036 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02003037
Johannes Bergab1faea2009-07-01 21:41:17 +02003038 ifmgd->flags = 0;
Mohammed Shafi Shajakhan1478acb2011-12-14 19:46:08 +05303039 ifmgd->powersave = sdata->wdev.ps;
Eliad Pellerdc41e4d2012-03-14 16:15:03 +02003040 ifmgd->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
3041 ifmgd->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
Johannes Bergbbbdff92009-04-16 13:27:42 +02003042
Johannes Berg77fdaa12009-07-07 03:45:17 +02003043 mutex_init(&ifmgd->mtx);
Johannes Berg0f782312009-12-01 13:37:02 +01003044
3045 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
3046 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
3047 else
3048 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02003049}
3050
3051/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02003052void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
3053{
3054 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02003055
3056 /* Restart STA timers */
3057 rcu_read_lock();
3058 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3059 ieee80211_restart_sta_timer(sdata);
3060 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02003061}
Johannes Berg10f644a2009-04-16 13:17:25 +02003062
3063int ieee80211_max_network_latency(struct notifier_block *nb,
3064 unsigned long data, void *dummy)
3065{
3066 s32 latency_usec = (s32) data;
3067 struct ieee80211_local *local =
3068 container_of(nb, struct ieee80211_local,
3069 network_latency_notifier);
3070
3071 mutex_lock(&local->iflist_mtx);
3072 ieee80211_recalc_ps(local, latency_usec);
3073 mutex_unlock(&local->iflist_mtx);
3074
3075 return 0;
3076}
Johannes Berg77fdaa12009-07-07 03:45:17 +02003077
Johannes Berga1cf7752012-03-08 15:02:07 +01003078static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003079 struct cfg80211_bss *cbss, bool assoc)
Johannes Berga1cf7752012-03-08 15:02:07 +01003080{
3081 struct ieee80211_local *local = sdata->local;
3082 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003083 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berga1cf7752012-03-08 15:02:07 +01003084 struct sta_info *sta;
3085 bool have_sta = false;
3086 int err;
3087
3088 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
3089 return -EINVAL;
3090
3091 if (assoc) {
3092 rcu_read_lock();
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003093 have_sta = sta_info_get(sdata, cbss->bssid);
Johannes Berga1cf7752012-03-08 15:02:07 +01003094 rcu_read_unlock();
3095 }
3096
3097 if (!have_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003098 sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
Johannes Berga1cf7752012-03-08 15:02:07 +01003099 if (!sta)
3100 return -ENOMEM;
3101 }
3102
3103 mutex_lock(&local->mtx);
3104 ieee80211_recalc_idle(sdata->local);
3105 mutex_unlock(&local->mtx);
3106
3107 /* switch to the right channel */
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003108 local->oper_channel = cbss->channel;
Johannes Berga1cf7752012-03-08 15:02:07 +01003109 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
3110
3111 if (!have_sta) {
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003112 struct ieee80211_supported_band *sband;
3113 u32 rates = 0, basic_rates = 0;
3114 bool have_higher_than_11mbit;
3115 int min_rate = INT_MAX, min_rate_index = -1;
3116
3117 sband = sdata->local->hw.wiphy->bands[cbss->channel->band];
3118
3119 ieee80211_get_rates(sband, bss->supp_rates,
3120 bss->supp_rates_len,
3121 &rates, &basic_rates,
3122 &have_higher_than_11mbit,
3123 &min_rate, &min_rate_index);
3124
3125 /*
3126 * This used to be a workaround for basic rates missing
3127 * in the association response frame. Now that we no
3128 * longer use the basic rates from there, it probably
3129 * doesn't happen any more, but keep the workaround so
3130 * in case some *other* APs are buggy in different ways
3131 * we can connect -- with a warning.
3132 */
3133 if (!basic_rates && min_rate_index >= 0) {
3134 printk(KERN_DEBUG
3135 "%s: No basic rates, using min rate instead.\n",
3136 sdata->name);
3137 basic_rates = BIT(min_rate_index);
3138 }
3139
3140 sta->sta.supp_rates[cbss->channel->band] = rates;
3141 sdata->vif.bss_conf.basic_rates = basic_rates;
3142
3143 /* cf. IEEE 802.11 9.2.12 */
3144 if (local->oper_channel->band == IEEE80211_BAND_2GHZ &&
3145 have_higher_than_11mbit)
3146 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
3147 else
3148 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
3149
3150 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
3151
3152 /* tell driver about BSSID and basic rates */
3153 ieee80211_bss_info_change_notify(sdata,
3154 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES);
Johannes Berga1cf7752012-03-08 15:02:07 +01003155
3156 if (assoc)
3157 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
3158
3159 err = sta_info_insert(sta);
3160 sta = NULL;
3161 if (err) {
3162 printk(KERN_DEBUG
3163 "%s: failed to insert STA entry for the AP (error %d)\n",
3164 sdata->name, err);
3165 return err;
3166 }
3167 } else
Johannes Berg5d6a1b02012-03-08 15:02:08 +01003168 WARN_ON_ONCE(compare_ether_addr(ifmgd->bssid, cbss->bssid));
Johannes Berga1cf7752012-03-08 15:02:07 +01003169
3170 return 0;
3171}
3172
Johannes Berg77fdaa12009-07-07 03:45:17 +02003173/* config hooks */
3174int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
3175 struct cfg80211_auth_request *req)
3176{
Johannes Berg66e67e42012-01-20 13:55:27 +01003177 struct ieee80211_local *local = sdata->local;
3178 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3179 struct ieee80211_mgd_auth_data *auth_data;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003180 u16 auth_alg;
Johannes Berg66e67e42012-01-20 13:55:27 +01003181 int err;
3182
3183 /* prepare auth data structure */
Johannes Berg77fdaa12009-07-07 03:45:17 +02003184
3185 switch (req->auth_type) {
3186 case NL80211_AUTHTYPE_OPEN_SYSTEM:
3187 auth_alg = WLAN_AUTH_OPEN;
3188 break;
3189 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg66e67e42012-01-20 13:55:27 +01003190 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg9dca9c42010-07-21 10:09:25 +02003191 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003192 auth_alg = WLAN_AUTH_SHARED_KEY;
3193 break;
3194 case NL80211_AUTHTYPE_FT:
3195 auth_alg = WLAN_AUTH_FT;
3196 break;
3197 case NL80211_AUTHTYPE_NETWORK_EAP:
3198 auth_alg = WLAN_AUTH_LEAP;
3199 break;
3200 default:
3201 return -EOPNOTSUPP;
3202 }
3203
Johannes Berg66e67e42012-01-20 13:55:27 +01003204 auth_data = kzalloc(sizeof(*auth_data) + req->ie_len, GFP_KERNEL);
3205 if (!auth_data)
Johannes Berg77fdaa12009-07-07 03:45:17 +02003206 return -ENOMEM;
3207
Johannes Berg66e67e42012-01-20 13:55:27 +01003208 auth_data->bss = req->bss;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003209
3210 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003211 memcpy(auth_data->ie, req->ie, req->ie_len);
3212 auth_data->ie_len = req->ie_len;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003213 }
3214
Johannes Bergfffd0932009-07-08 14:22:54 +02003215 if (req->key && req->key_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003216 auth_data->key_len = req->key_len;
3217 auth_data->key_idx = req->key_idx;
3218 memcpy(auth_data->key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02003219 }
3220
Johannes Berg66e67e42012-01-20 13:55:27 +01003221 auth_data->algorithm = auth_alg;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003222
Johannes Berg66e67e42012-01-20 13:55:27 +01003223 /* try to authenticate/probe */
Johannes Bergf679f652009-12-23 13:15:34 +01003224
Johannes Berg66e67e42012-01-20 13:55:27 +01003225 mutex_lock(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003226
Johannes Berg66e67e42012-01-20 13:55:27 +01003227 if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
3228 ifmgd->assoc_data) {
3229 err = -EBUSY;
3230 goto err_free;
3231 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003232
Johannes Berg66e67e42012-01-20 13:55:27 +01003233 if (ifmgd->auth_data)
3234 ieee80211_destroy_auth_data(sdata, false);
Guy Eilam2a33bee2011-08-17 15:18:15 +03003235
Johannes Berg66e67e42012-01-20 13:55:27 +01003236 /* prep auth_data so we don't go into idle on disassoc */
3237 ifmgd->auth_data = auth_data;
3238
3239 if (ifmgd->associated)
Johannes Berg37ad3882012-02-24 13:50:54 +01003240 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
Johannes Berg66e67e42012-01-20 13:55:27 +01003241
3242 printk(KERN_DEBUG "%s: authenticate with %pM\n",
3243 sdata->name, req->bss->bssid);
3244
Johannes Berga1cf7752012-03-08 15:02:07 +01003245 err = ieee80211_prep_connection(sdata, req->bss, false);
3246 if (err)
Johannes Berg66e67e42012-01-20 13:55:27 +01003247 goto err_clear;
Guy Eilam2a33bee2011-08-17 15:18:15 +03003248
Johannes Berg66e67e42012-01-20 13:55:27 +01003249 err = ieee80211_probe_auth(sdata);
3250 if (err) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003251 sta_info_destroy_addr(sdata, req->bss->bssid);
3252 goto err_clear;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003253 }
3254
Johannes Berg66e67e42012-01-20 13:55:27 +01003255 /* hold our own reference */
3256 cfg80211_ref_bss(auth_data->bss);
3257 err = 0;
3258 goto out_unlock;
Johannes Berge5b900d2010-07-29 16:08:55 +02003259
Johannes Berg66e67e42012-01-20 13:55:27 +01003260 err_clear:
3261 ifmgd->auth_data = NULL;
3262 err_free:
3263 kfree(auth_data);
3264 out_unlock:
3265 mutex_unlock(&ifmgd->mtx);
Johannes Berge5b900d2010-07-29 16:08:55 +02003266
Johannes Berg66e67e42012-01-20 13:55:27 +01003267 return err;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003268}
3269
Johannes Berg77fdaa12009-07-07 03:45:17 +02003270int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3271 struct cfg80211_assoc_request *req)
3272{
Johannes Berg66e67e42012-01-20 13:55:27 +01003273 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003274 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003275 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Berg66e67e42012-01-20 13:55:27 +01003276 struct ieee80211_mgd_assoc_data *assoc_data;
Johannes Berg4e74bfd2012-03-08 15:02:04 +01003277 struct ieee80211_supported_band *sband;
Johannes Berg66e67e42012-01-20 13:55:27 +01003278 const u8 *ssidie;
Guy Eilam2a33bee2011-08-17 15:18:15 +03003279 int i, err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003280
Johannes Berg66e67e42012-01-20 13:55:27 +01003281 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
3282 if (!ssidie)
3283 return -EINVAL;
Jouni Malinen9c87ba62010-02-28 12:13:46 +02003284
Johannes Berg66e67e42012-01-20 13:55:27 +01003285 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
3286 if (!assoc_data)
Johannes Bergaf6b6372009-12-23 13:15:35 +01003287 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003288
Johannes Berg66e67e42012-01-20 13:55:27 +01003289 mutex_lock(&ifmgd->mtx);
3290
3291 if (ifmgd->associated)
Johannes Berg37ad3882012-02-24 13:50:54 +01003292 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
Johannes Berg66e67e42012-01-20 13:55:27 +01003293
3294 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
3295 err = -EBUSY;
3296 goto err_free;
Guy Eilam2a33bee2011-08-17 15:18:15 +03003297 }
3298
Johannes Berg66e67e42012-01-20 13:55:27 +01003299 if (ifmgd->assoc_data) {
3300 err = -EBUSY;
3301 goto err_free;
3302 }
3303
3304 if (ifmgd->auth_data) {
3305 bool match;
3306
3307 /* keep sta info, bssid if matching */
Felix Fietkau888d04d2012-03-01 15:22:09 +01003308 match = compare_ether_addr(ifmgd->bssid, req->bss->bssid) == 0;
Johannes Berg66e67e42012-01-20 13:55:27 +01003309 ieee80211_destroy_auth_data(sdata, match);
3310 }
3311
3312 /* prepare assoc data */
3313
Johannes Berg77fdaa12009-07-07 03:45:17 +02003314 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
Vivek Natarajan375177b2010-02-09 14:50:28 +05303315 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
Mahesh Palivelad56a75d2013-02-21 07:04:14 +05303316 ifmgd->flags &= ~IEEE80211_STA_DISABLE_VHT;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003317
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03003318 ifmgd->beacon_crc_valid = false;
3319
Johannes Bergde5036a2012-03-08 15:02:03 +01003320 /*
3321 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
3322 * We still associate in non-HT mode (11a/b/g) if any one of these
3323 * ciphers is configured as pairwise.
3324 * We can set this to true for non-11n hardware, that'll be checked
3325 * separately along with the peer capabilities.
3326 */
Mahesh Palivelad56a75d2013-02-21 07:04:14 +05303327 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02003328 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
3329 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
Mahesh Palivelad56a75d2013-02-21 07:04:14 +05303330 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02003331 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
Mahesh Palivelad56a75d2013-02-21 07:04:14 +05303332 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3333 netdev_info(sdata->dev,
3334 "disabling HT/VHT due to WEP/TKIP use\n");
3335 }
3336 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003337
Mahesh Palivelad56a75d2013-02-21 07:04:14 +05303338 if (req->flags & ASSOC_REQ_DISABLE_HT) {
Ben Greearef96a8422011-11-18 11:32:00 -08003339 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
Mahesh Palivelad56a75d2013-02-21 07:04:14 +05303340 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3341 }
Ben Greearef96a8422011-11-18 11:32:00 -08003342
Johannes Berg4e74bfd2012-03-08 15:02:04 +01003343 /* Also disable HT if we don't support it or the AP doesn't use WMM */
3344 sband = local->hw.wiphy->bands[req->bss->channel->band];
3345 if (!sband->ht_cap.ht_supported ||
3346 local->hw.queues < 4 || !bss->wmm_used)
3347 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
3348
Mahesh Palivelad56a75d2013-02-21 07:04:14 +05303349 /* disable VHT if we don't support it or the AP doesn't use WMM */
3350 if (!sband->vht_cap.vht_supported ||
3351 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
3352 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
3353 netdev_info(sdata->dev,
3354 "disabling VHT as WMM/QoS is not supported\n");
3355 }
3356
Ben Greearef96a8422011-11-18 11:32:00 -08003357 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
3358 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
3359 sizeof(ifmgd->ht_capa_mask));
3360
Johannes Berg77fdaa12009-07-07 03:45:17 +02003361 if (req->ie && req->ie_len) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003362 memcpy(assoc_data->ie, req->ie, req->ie_len);
3363 assoc_data->ie_len = req->ie_len;
3364 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003365
Johannes Berg66e67e42012-01-20 13:55:27 +01003366 assoc_data->bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01003367
Johannes Bergaf6b6372009-12-23 13:15:35 +01003368 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
3369 if (ifmgd->powersave)
3370 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
3371 else
3372 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
3373 } else
3374 ifmgd->ap_smps = ifmgd->req_smps;
3375
Johannes Berg66e67e42012-01-20 13:55:27 +01003376 assoc_data->capability = req->bss->capability;
Johannes Berg76f03032012-03-08 15:02:05 +01003377 assoc_data->wmm = bss->wmm_used && (local->hw.queues >= 4);
Johannes Berg66e67e42012-01-20 13:55:27 +01003378 assoc_data->supp_rates = bss->supp_rates;
3379 assoc_data->supp_rates_len = bss->supp_rates_len;
3380 assoc_data->ht_information_ie =
Johannes Bergf679f652009-12-23 13:15:34 +01003381 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
Johannes Berg63f170e2009-12-23 13:15:33 +01003382
Kalle Valoab133152010-01-12 10:42:31 +02003383 if (bss->wmm_used && bss->uapsd_supported &&
3384 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
Johannes Berg76f03032012-03-08 15:02:05 +01003385 assoc_data->uapsd = true;
Kalle Valoab133152010-01-12 10:42:31 +02003386 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
3387 } else {
Johannes Berg76f03032012-03-08 15:02:05 +01003388 assoc_data->uapsd = false;
Kalle Valoab133152010-01-12 10:42:31 +02003389 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
3390 }
3391
Johannes Berg66e67e42012-01-20 13:55:27 +01003392 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
3393 assoc_data->ssid_len = ssidie[1];
Johannes Berg63f170e2009-12-23 13:15:33 +01003394
Johannes Berg77fdaa12009-07-07 03:45:17 +02003395 if (req->prev_bssid)
Johannes Berg66e67e42012-01-20 13:55:27 +01003396 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003397
3398 if (req->use_mfp) {
3399 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
3400 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
3401 } else {
3402 ifmgd->mfp = IEEE80211_MFP_DISABLED;
3403 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
3404 }
3405
3406 if (req->crypto.control_port)
3407 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
3408 else
3409 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
3410
Johannes Berga621fa42010-08-27 14:26:54 +03003411 sdata->control_port_protocol = req->crypto.control_port_ethertype;
3412 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
3413
Johannes Berg66e67e42012-01-20 13:55:27 +01003414 /* kick off associate process */
3415
3416 ifmgd->assoc_data = assoc_data;
3417
Johannes Berga1cf7752012-03-08 15:02:07 +01003418 err = ieee80211_prep_connection(sdata, req->bss, true);
3419 if (err)
3420 goto err_clear;
Johannes Berg66e67e42012-01-20 13:55:27 +01003421
3422 if (!bss->dtim_period &&
3423 sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) {
3424 /*
3425 * Wait up to one beacon interval ...
3426 * should this be more if we miss one?
3427 */
3428 printk(KERN_DEBUG "%s: waiting for beacon from %pM\n",
3429 sdata->name, ifmgd->bssid);
Johannes Berg3f9768a2012-03-28 21:02:46 +02003430 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
Johannes Berg66e67e42012-01-20 13:55:27 +01003431 } else {
3432 assoc_data->have_beacon = true;
3433 assoc_data->sent_assoc = false;
3434 assoc_data->timeout = jiffies;
3435 }
3436 run_again(ifmgd, assoc_data->timeout);
3437
Paul Stewartfcff4f12012-02-23 17:59:53 -08003438 if (bss->corrupt_data) {
3439 char *corrupt_type = "data";
3440 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
3441 if (bss->corrupt_data &
3442 IEEE80211_BSS_CORRUPT_PROBE_RESP)
3443 corrupt_type = "beacon and probe response";
3444 else
3445 corrupt_type = "beacon";
3446 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
3447 corrupt_type = "probe response";
3448 printk(KERN_DEBUG "%s: associating with AP with corrupt %s\n",
3449 sdata->name, corrupt_type);
3450 }
3451
Johannes Berg66e67e42012-01-20 13:55:27 +01003452 err = 0;
3453 goto out;
3454 err_clear:
3455 ifmgd->assoc_data = NULL;
3456 err_free:
3457 kfree(assoc_data);
3458 out:
3459 mutex_unlock(&ifmgd->mtx);
3460
3461 return err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02003462}
3463
3464int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01003465 struct cfg80211_deauth_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02003466{
3467 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg5fef7db2012-02-24 13:50:52 +01003468 u8 frame_buf[DEAUTH_DISASSOC_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02003469
Johannes Berg77fdaa12009-07-07 03:45:17 +02003470 mutex_lock(&ifmgd->mtx);
3471
Johannes Berg37ad3882012-02-24 13:50:54 +01003472 if (ifmgd->auth_data) {
Johannes Berg66e67e42012-01-20 13:55:27 +01003473 ieee80211_destroy_auth_data(sdata, false);
Johannes Bergaf6b6372009-12-23 13:15:35 +01003474 mutex_unlock(&ifmgd->mtx);
Johannes Berg66e67e42012-01-20 13:55:27 +01003475 return 0;
Johannes Bergaf6b6372009-12-23 13:15:35 +01003476 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02003477
Johannes Berg37ad3882012-02-24 13:50:54 +01003478 printk(KERN_DEBUG
3479 "%s: deauthenticating from %pM by local choice (reason=%d)\n",
Johannes Berg95de8172012-01-20 13:55:25 +01003480 sdata->name, req->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02003481
Johannes Berg37ad3882012-02-24 13:50:54 +01003482 if (ifmgd->associated &&
Felix Fietkau888d04d2012-03-01 15:22:09 +01003483 compare_ether_addr(ifmgd->associated->bssid, req->bssid) == 0)
Johannes Berg37ad3882012-02-24 13:50:54 +01003484 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
Johannes Berg5fef7db2012-02-24 13:50:52 +01003485 req->reason_code, true, frame_buf);
Johannes Berg37ad3882012-02-24 13:50:54 +01003486 else
3487 ieee80211_send_deauth_disassoc(sdata, req->bssid,
3488 IEEE80211_STYPE_DEAUTH,
3489 req->reason_code, true,
3490 frame_buf);
3491 mutex_unlock(&ifmgd->mtx);
3492
Johannes Berg5fef7db2012-02-24 13:50:52 +01003493 __cfg80211_send_deauth(sdata->dev, frame_buf, DEAUTH_DISASSOC_LEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003494
Johannes Berg7da7cc12010-08-05 17:02:38 +02003495 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01003496 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02003497 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01003498
Johannes Berg77fdaa12009-07-07 03:45:17 +02003499 return 0;
3500}
3501
3502int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01003503 struct cfg80211_disassoc_request *req)
Johannes Berg77fdaa12009-07-07 03:45:17 +02003504{
3505 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07003506 u8 bssid[ETH_ALEN];
Johannes Berg5fef7db2012-02-24 13:50:52 +01003507 u8 frame_buf[DEAUTH_DISASSOC_LEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02003508
Johannes Berg77fdaa12009-07-07 03:45:17 +02003509 mutex_lock(&ifmgd->mtx);
3510
Johannes Berg8d8b2612009-07-25 11:58:36 +02003511 /*
3512 * cfg80211 should catch this ... but it's racy since
3513 * we can receive a disassoc frame, process it, hand it
3514 * to cfg80211 while that's in a locked section already
3515 * trying to tell us that the user wants to disconnect.
3516 */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01003517 if (ifmgd->associated != req->bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02003518 mutex_unlock(&ifmgd->mtx);
3519 return -ENOLINK;
3520 }
3521
Johannes Berg0ff71612009-09-26 14:45:41 +02003522 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01003523 sdata->name, req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02003524
Jouni Malinene69e95d2010-03-29 23:29:31 -07003525 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg37ad3882012-02-24 13:50:54 +01003526 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
3527 req->reason_code, !req->local_state_change,
3528 frame_buf);
Johannes Berg77fdaa12009-07-07 03:45:17 +02003529 mutex_unlock(&ifmgd->mtx);
3530
Johannes Berg5fef7db2012-02-24 13:50:52 +01003531 __cfg80211_send_disassoc(sdata->dev, frame_buf, DEAUTH_DISASSOC_LEN);
Johannes Bergbc83b682009-11-29 12:19:06 +01003532
Johannes Berg7da7cc12010-08-05 17:02:38 +02003533 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01003534 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02003535 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01003536
Johannes Berg77fdaa12009-07-07 03:45:17 +02003537 return 0;
3538}
Jouni Malinen026331c2010-02-15 12:53:10 +02003539
Eliad Pellerafa762f2012-04-23 14:45:15 +03003540void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
Johannes Berg54e4ffb2012-02-25 21:48:08 +01003541{
3542 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3543
3544 mutex_lock(&ifmgd->mtx);
3545 if (ifmgd->assoc_data)
3546 ieee80211_destroy_assoc_data(sdata, false);
3547 if (ifmgd->auth_data)
3548 ieee80211_destroy_auth_data(sdata, false);
3549 del_timer_sync(&ifmgd->timer);
3550 mutex_unlock(&ifmgd->mtx);
3551}
3552
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003553void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
3554 enum nl80211_cqm_rssi_threshold_event rssi_event,
3555 gfp_t gfp)
3556{
3557 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3558
Johannes Bergb5878a22010-04-07 16:48:40 +02003559 trace_api_cqm_rssi_notify(sdata, rssi_event);
3560
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003561 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
3562}
3563EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
Eliad Peller1d34d102011-06-06 12:59:29 +03003564
3565unsigned char ieee80211_get_operstate(struct ieee80211_vif *vif)
3566{
3567 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3568 return sdata->dev->operstate;
3569}
3570EXPORT_SYMBOL(ieee80211_get_operstate);