blob: c65225f29bb6d3e9c75d8ab3412f1b90f8c73b2a [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * BSS client mode implementation
Jouni Malinen5394af42009-01-08 13:31:59 +02003 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
Jiri Bencf0706e82007-05-05 11:45:53 -07004 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070014#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070015#include <linux/if_ether.h>
16#include <linux/skbuff.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070017#include <linux/if_arp.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018#include <linux/etherdevice.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010019#include <linux/rtnetlink.h>
Johannes Berg10f644a2009-04-16 13:17:25 +020020#include <linux/pm_qos_params.h>
Johannes Bergd91f36d2009-04-16 13:17:26 +020021#include <linux/crc32.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070022#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020023#include <asm/unaligned.h>
Johannes Berg60f8b392008-09-08 17:44:22 +020024
Jiri Bencf0706e82007-05-05 11:45:53 -070025#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020026#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040027#include "rate.h"
28#include "led.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070029
30#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
31#define IEEE80211_AUTH_MAX_TRIES 3
32#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
33#define IEEE80211_ASSOC_MAX_TRIES 3
Maxim Levitskya43abf22009-07-31 18:54:12 +030034#define IEEE80211_MAX_PROBE_TRIES 5
Johannes Bergb291ba12009-07-10 15:29:03 +020035
36/*
37 * beacon loss detection timeout
38 * XXX: should depend on beacon interval
39 */
40#define IEEE80211_BEACON_LOSS_TIME (2 * HZ)
41/*
42 * Time the connection can be idle before we probe
43 * it to see if we can still talk to the AP.
44 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030045#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020046/*
47 * Time we wait for a probe response after sending
48 * a probe request because of beacon loss or for
49 * checking the connection still works.
50 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030051#define IEEE80211_PROBE_WAIT (HZ / 2)
Jiri Bencf0706e82007-05-05 11:45:53 -070052
Johannes Berg5bb644a2009-05-17 11:40:42 +020053#define TMR_RUNNING_TIMER 0
54#define TMR_RUNNING_CHANSW 1
55
Johannes Berg77fdaa12009-07-07 03:45:17 +020056/*
57 * All cfg80211 functions have to be called outside a locked
58 * section so that they can acquire a lock themselves... This
59 * is much simpler than queuing up things in cfg80211, but we
60 * do need some indirection for that here.
61 */
62enum rx_mgmt_action {
63 /* no action required */
64 RX_MGMT_NONE,
65
66 /* caller must call cfg80211_send_rx_auth() */
67 RX_MGMT_CFG80211_AUTH,
68
69 /* caller must call cfg80211_send_rx_assoc() */
70 RX_MGMT_CFG80211_ASSOC,
71
72 /* caller must call cfg80211_send_deauth() */
73 RX_MGMT_CFG80211_DEAUTH,
74
75 /* caller must call cfg80211_send_disassoc() */
76 RX_MGMT_CFG80211_DISASSOC,
77
Johannes Berg5d1ec852009-12-02 12:43:43 +010078 /* caller must tell cfg80211 about internal error */
79 RX_MGMT_CFG80211_ASSOC_ERROR,
80
Johannes Berg77fdaa12009-07-07 03:45:17 +020081 /* caller must call cfg80211_auth_timeout() & free work */
82 RX_MGMT_CFG80211_AUTH_TO,
83
84 /* caller must call cfg80211_assoc_timeout() & free work */
85 RX_MGMT_CFG80211_ASSOC_TO,
86};
87
Johannes Berg5484e232008-09-08 17:44:27 +020088/* utils */
Johannes Berg77fdaa12009-07-07 03:45:17 +020089static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
90{
91 WARN_ON(!mutex_is_locked(&ifmgd->mtx));
92}
93
Johannes Bergca386f32009-07-10 02:39:48 +020094/*
95 * We can have multiple work items (and connection probing)
96 * scheduling this timer, but we need to take care to only
97 * reschedule it when it should fire _earlier_ than it was
98 * asked for before, or if it's not pending right now. This
99 * function ensures that. Note that it then is required to
100 * run this function for all timeouts after the first one
101 * has happened -- the work that runs from this timer will
102 * do that.
103 */
104static void run_again(struct ieee80211_if_managed *ifmgd,
105 unsigned long timeout)
106{
107 ASSERT_MGD_MTX(ifmgd);
108
109 if (!timer_pending(&ifmgd->timer) ||
110 time_before(timeout, ifmgd->timer.expires))
111 mod_timer(&ifmgd->timer, timeout);
112}
113
Johannes Bergb291ba12009-07-10 15:29:03 +0200114static void mod_beacon_timer(struct ieee80211_sub_if_data *sdata)
115{
116 if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER)
117 return;
118
119 mod_timer(&sdata->u.mgd.bcn_mon_timer,
120 round_jiffies_up(jiffies + IEEE80211_BEACON_LOSS_TIME));
121}
122
Johannes Berg5484e232008-09-08 17:44:27 +0200123static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200124{
Johannes Berg5484e232008-09-08 17:44:27 +0200125 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200126}
127
Johannes Bergf679f652009-12-23 13:15:34 +0100128static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
Johannes Berg9ac19a92008-09-09 10:57:09 +0200129 struct ieee80211_supported_band *sband,
Johannes Berg881d9482009-01-21 15:13:48 +0100130 u32 *rates)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200131{
132 int i, j, count;
133 *rates = 0;
134 count = 0;
Johannes Bergf679f652009-12-23 13:15:34 +0100135 for (i = 0; i < supp_rates_len; i++) {
136 int rate = (supp_rates[i] & 0x7F) * 5;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200137
138 for (j = 0; j < sband->n_bitrates; j++)
139 if (sband->bitrates[j].bitrate == rate) {
140 *rates |= BIT(j);
141 count++;
142 break;
143 }
144 }
145
146 return count;
147}
148
Johannes Bergd5522e02009-03-30 13:23:35 +0200149/*
150 * ieee80211_enable_ht should be called only after the operating band
151 * has been determined as ht configuration depends on the hw's
152 * HT abilities for a specific band.
153 */
154static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
155 struct ieee80211_ht_info *hti,
Johannes Berg77fdaa12009-07-07 03:45:17 +0200156 const u8 *bssid, u16 ap_ht_cap_flags)
Johannes Bergd5522e02009-03-30 13:23:35 +0200157{
158 struct ieee80211_local *local = sdata->local;
159 struct ieee80211_supported_band *sband;
Johannes Bergd5522e02009-03-30 13:23:35 +0200160 struct sta_info *sta;
161 u32 changed = 0;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200162 u16 ht_opmode;
Johannes Bergd5522e02009-03-30 13:23:35 +0200163 bool enable_ht = true, ht_changed;
164 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
165
166 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
167
Johannes Bergd5522e02009-03-30 13:23:35 +0200168 /* HT is not supported */
169 if (!sband->ht_cap.ht_supported)
170 enable_ht = false;
171
172 /* check that channel matches the right operating channel */
173 if (local->hw.conf.channel->center_freq !=
174 ieee80211_channel_to_frequency(hti->control_chan))
175 enable_ht = false;
176
177 if (enable_ht) {
178 channel_type = NL80211_CHAN_HT20;
179
180 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
181 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
182 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
183 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
184 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400185 if (!(local->hw.conf.channel->flags &
186 IEEE80211_CHAN_NO_HT40PLUS))
187 channel_type = NL80211_CHAN_HT40PLUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200188 break;
189 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400190 if (!(local->hw.conf.channel->flags &
191 IEEE80211_CHAN_NO_HT40MINUS))
192 channel_type = NL80211_CHAN_HT40MINUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200193 break;
194 }
195 }
196 }
197
198 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
199 channel_type != local->hw.conf.channel_type;
200
201 local->oper_channel_type = channel_type;
202
203 if (ht_changed) {
204 /* channel_type change automatically detected */
205 ieee80211_hw_config(local, 0);
206
207 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100208 sta = sta_info_get(sdata, bssid);
Johannes Bergd5522e02009-03-30 13:23:35 +0200209 if (sta)
210 rate_control_rate_update(local, sband, sta,
211 IEEE80211_RC_HT_CHANGED);
Johannes Bergd5522e02009-03-30 13:23:35 +0200212 rcu_read_unlock();
Johannes Bergd5522e02009-03-30 13:23:35 +0200213 }
214
215 /* disable HT */
216 if (!enable_ht)
217 return 0;
218
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200219 ht_opmode = le16_to_cpu(hti->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200220
221 /* if bss configuration changed store the new one */
Johannes Berg413ad502009-05-08 21:21:06 +0200222 if (!sdata->ht_opmode_valid ||
223 sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200224 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200225 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Berg413ad502009-05-08 21:21:06 +0200226 sdata->ht_opmode_valid = true;
Johannes Bergd5522e02009-03-30 13:23:35 +0200227 }
228
229 return changed;
230}
231
Johannes Berg9c6bd792008-09-11 00:01:52 +0200232/* frame sending functions */
233
Johannes Berg77fdaa12009-07-07 03:45:17 +0200234static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
Johannes Bergf679f652009-12-23 13:15:34 +0100235 struct ieee80211_work *wk)
Johannes Berg60f8b392008-09-08 17:44:22 +0200236{
Johannes Berg46900292009-02-15 12:44:28 +0100237 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200238 struct ieee80211_local *local = sdata->local;
239 struct sk_buff *skb;
240 struct ieee80211_mgmt *mgmt;
Johannes Berg517357c2009-07-02 17:18:40 +0200241 u8 *pos;
242 const u8 *ies, *ht_ie;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200243 int i, len, count, rates_len, supp_rates_len;
244 u16 capab;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200245 int wmm = 0;
246 struct ieee80211_supported_band *sband;
Johannes Berg881d9482009-01-21 15:13:48 +0100247 u32 rates = 0;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200248
249 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
Johannes Berg77fdaa12009-07-07 03:45:17 +0200250 sizeof(*mgmt) + 200 + wk->ie_len +
Johannes Bergf679f652009-12-23 13:15:34 +0100251 wk->assoc.ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200252 if (!skb) {
253 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
Johannes Berg47846c92009-11-25 17:46:19 +0100254 "frame\n", sdata->name);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200255 return;
256 }
257 skb_reserve(skb, local->hw.extra_tx_headroom);
258
259 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
260
Johannes Berg46900292009-02-15 12:44:28 +0100261 capab = ifmgd->capab;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200262
263 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
264 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
265 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
266 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
267 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
268 }
269
Johannes Bergf679f652009-12-23 13:15:34 +0100270 if (wk->assoc.capability & WLAN_CAPABILITY_PRIVACY)
Johannes Berg77fdaa12009-07-07 03:45:17 +0200271 capab |= WLAN_CAPABILITY_PRIVACY;
Johannes Bergf679f652009-12-23 13:15:34 +0100272 if (wk->assoc.wmm_used)
Johannes Berg77fdaa12009-07-07 03:45:17 +0200273 wmm = 1;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200274
Johannes Berg77fdaa12009-07-07 03:45:17 +0200275 /* get all rates supported by the device and the AP as
276 * some APs don't like getting a superset of their rates
277 * in the association request (e.g. D-Link DAP 1353 in
278 * b-only mode) */
Johannes Bergf679f652009-12-23 13:15:34 +0100279 rates_len = ieee80211_compatible_rates(wk->assoc.supp_rates,
280 wk->assoc.supp_rates_len,
281 sband, &rates);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200282
Johannes Bergf679f652009-12-23 13:15:34 +0100283 if ((wk->assoc.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg77fdaa12009-07-07 03:45:17 +0200284 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
285 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200286
287 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
288 memset(mgmt, 0, 24);
Johannes Bergf679f652009-12-23 13:15:34 +0100289 memcpy(mgmt->da, wk->assoc.bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100290 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Bergf679f652009-12-23 13:15:34 +0100291 memcpy(mgmt->bssid, wk->assoc.bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200292
Johannes Bergf679f652009-12-23 13:15:34 +0100293 if (!is_zero_ether_addr(wk->assoc.prev_bssid)) {
Johannes Berg9ac19a92008-09-09 10:57:09 +0200294 skb_put(skb, 10);
295 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
296 IEEE80211_STYPE_REASSOC_REQ);
297 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
298 mgmt->u.reassoc_req.listen_interval =
299 cpu_to_le16(local->hw.conf.listen_interval);
Johannes Bergf679f652009-12-23 13:15:34 +0100300 memcpy(mgmt->u.reassoc_req.current_ap, wk->assoc.prev_bssid,
Johannes Berg9ac19a92008-09-09 10:57:09 +0200301 ETH_ALEN);
302 } else {
303 skb_put(skb, 4);
304 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
305 IEEE80211_STYPE_ASSOC_REQ);
306 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
Rami Rosen13554122008-12-16 22:38:29 +0200307 mgmt->u.assoc_req.listen_interval =
Johannes Berg9ac19a92008-09-09 10:57:09 +0200308 cpu_to_le16(local->hw.conf.listen_interval);
309 }
310
311 /* SSID */
Johannes Bergf679f652009-12-23 13:15:34 +0100312 ies = pos = skb_put(skb, 2 + wk->assoc.ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200313 *pos++ = WLAN_EID_SSID;
Johannes Bergf679f652009-12-23 13:15:34 +0100314 *pos++ = wk->assoc.ssid_len;
315 memcpy(pos, wk->assoc.ssid, wk->assoc.ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200316
317 /* add all rates which were marked to be used above */
318 supp_rates_len = rates_len;
319 if (supp_rates_len > 8)
320 supp_rates_len = 8;
321
322 len = sband->n_bitrates;
323 pos = skb_put(skb, supp_rates_len + 2);
324 *pos++ = WLAN_EID_SUPP_RATES;
325 *pos++ = supp_rates_len;
326
327 count = 0;
328 for (i = 0; i < sband->n_bitrates; i++) {
329 if (BIT(i) & rates) {
330 int rate = sband->bitrates[i].bitrate;
331 *pos++ = (u8) (rate / 5);
332 if (++count == 8)
333 break;
334 }
335 }
336
337 if (rates_len > count) {
338 pos = skb_put(skb, rates_len - count + 2);
339 *pos++ = WLAN_EID_EXT_SUPP_RATES;
340 *pos++ = rates_len - count;
341
342 for (i++; i < sband->n_bitrates; i++) {
343 if (BIT(i) & rates) {
344 int rate = sband->bitrates[i].bitrate;
345 *pos++ = (u8) (rate / 5);
346 }
347 }
348 }
349
350 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
351 /* 1. power capabilities */
352 pos = skb_put(skb, 4);
353 *pos++ = WLAN_EID_PWR_CAPABILITY;
354 *pos++ = 2;
355 *pos++ = 0; /* min tx power */
356 *pos++ = local->hw.conf.channel->max_power; /* max tx power */
357
358 /* 2. supported channels */
359 /* TODO: get this in reg domain format */
360 pos = skb_put(skb, 2 * sband->n_channels + 2);
361 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
362 *pos++ = 2 * sband->n_channels;
363 for (i = 0; i < sband->n_channels; i++) {
364 *pos++ = ieee80211_frequency_to_channel(
365 sband->channels[i].center_freq);
366 *pos++ = 1; /* one channel in the subband*/
367 }
368 }
369
Johannes Berg77fdaa12009-07-07 03:45:17 +0200370 if (wk->ie_len && wk->ie) {
371 pos = skb_put(skb, wk->ie_len);
372 memcpy(pos, wk->ie, wk->ie_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200373 }
374
Johannes Berg46900292009-02-15 12:44:28 +0100375 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
Johannes Berg9ac19a92008-09-09 10:57:09 +0200376 pos = skb_put(skb, 9);
377 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
378 *pos++ = 7; /* len */
379 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
380 *pos++ = 0x50;
381 *pos++ = 0xf2;
382 *pos++ = 2; /* WME */
383 *pos++ = 0; /* WME info */
384 *pos++ = 1; /* WME ver */
385 *pos++ = 0;
386 }
387
388 /* wmm support is a must to HT */
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530389 /*
390 * IEEE802.11n does not allow TKIP/WEP as pairwise
391 * ciphers in HT mode. We still associate in non-ht
392 * mode (11a/b/g) if any one of these ciphers is
393 * configured as pairwise.
394 */
Johannes Berg46900292009-02-15 12:44:28 +0100395 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200396 sband->ht_cap.ht_supported &&
Johannes Bergf679f652009-12-23 13:15:34 +0100397 (ht_ie = wk->assoc.ht_information_ie) &&
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530398 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
Johannes Bergab1faea2009-07-01 21:41:17 +0200399 (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N))) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200400 struct ieee80211_ht_info *ht_info =
401 (struct ieee80211_ht_info *)(ht_ie + 2);
402 u16 cap = sband->ht_cap.cap;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200403 __le16 tmp;
404 u32 flags = local->hw.conf.channel->flags;
405
Johannes Berg0f782312009-12-01 13:37:02 +0100406 /* determine capability flags */
407
Johannes Bergf38fd122009-12-01 18:29:42 +0100408 if (ieee80211_disable_40mhz_24ghz &&
409 sband->band == IEEE80211_BAND_2GHZ) {
410 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
411 cap &= ~IEEE80211_HT_CAP_SGI_40;
412 }
413
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200414 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
415 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Luis R. Rodriguez689da1b2009-05-02 00:37:18 -0400416 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200417 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200418 cap &= ~IEEE80211_HT_CAP_SGI_40;
419 }
420 break;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200421 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Luis R. Rodriguez689da1b2009-05-02 00:37:18 -0400422 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200423 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200424 cap &= ~IEEE80211_HT_CAP_SGI_40;
425 }
426 break;
427 }
428
Johannes Berg0f782312009-12-01 13:37:02 +0100429 /* set SM PS mode properly */
430 cap &= ~IEEE80211_HT_CAP_SM_PS;
431 /* new association always uses requested smps mode */
432 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
433 if (ifmgd->powersave)
434 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
435 else
436 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
437 } else
438 ifmgd->ap_smps = ifmgd->req_smps;
439
440 switch (ifmgd->ap_smps) {
441 case IEEE80211_SMPS_AUTOMATIC:
442 case IEEE80211_SMPS_NUM_MODES:
443 WARN_ON(1);
444 case IEEE80211_SMPS_OFF:
445 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
446 IEEE80211_HT_CAP_SM_PS_SHIFT;
447 break;
448 case IEEE80211_SMPS_STATIC:
449 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
450 IEEE80211_HT_CAP_SM_PS_SHIFT;
451 break;
452 case IEEE80211_SMPS_DYNAMIC:
453 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
454 IEEE80211_HT_CAP_SM_PS_SHIFT;
455 break;
456 }
457
458 /* reserve and fill IE */
459
460 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200461 *pos++ = WLAN_EID_HT_CAPABILITY;
462 *pos++ = sizeof(struct ieee80211_ht_cap);
463 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
Johannes Berg0f782312009-12-01 13:37:02 +0100464
465 /* capability flags */
466 tmp = cpu_to_le16(cap);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200467 memcpy(pos, &tmp, sizeof(u16));
468 pos += sizeof(u16);
Johannes Berg0f782312009-12-01 13:37:02 +0100469
470 /* AMPDU parameters */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200471 *pos++ = sband->ht_cap.ampdu_factor |
Johannes Berg0f782312009-12-01 13:37:02 +0100472 (sband->ht_cap.ampdu_density <<
473 IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
474
475 /* MCS set */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200476 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
Johannes Berg0f782312009-12-01 13:37:02 +0100477 pos += sizeof(sband->ht_cap.mcs);
478
479 /* extended capabilities */
480 pos += sizeof(__le16);
481
482 /* BF capabilities */
483 pos += sizeof(__le32);
484
485 /* antenna selection */
486 pos += sizeof(u8);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200487 }
488
Johannes Berg62ae67b2009-11-18 18:42:05 +0100489 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
490 ieee80211_tx_skb(sdata, skb);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200491}
492
493
Johannes Bergef422bc2008-09-09 10:58:25 +0200494static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503dd2009-07-07 03:56:11 +0200495 const u8 *bssid, u16 stype, u16 reason,
496 void *cookie)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200497{
498 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100499 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200500 struct sk_buff *skb;
501 struct ieee80211_mgmt *mgmt;
502
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200503 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200504 if (!skb) {
Johannes Bergef422bc2008-09-09 10:58:25 +0200505 printk(KERN_DEBUG "%s: failed to allocate buffer for "
Johannes Berg47846c92009-11-25 17:46:19 +0100506 "deauth/disassoc frame\n", sdata->name);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200507 return;
508 }
509 skb_reserve(skb, local->hw.extra_tx_headroom);
510
511 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
512 memset(mgmt, 0, 24);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200513 memcpy(mgmt->da, bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100514 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200515 memcpy(mgmt->bssid, bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200516 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200517 skb_put(skb, 2);
Johannes Bergef422bc2008-09-09 10:58:25 +0200518 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200519 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
520
Jouni Malinen53b46b82009-03-27 20:53:56 +0200521 if (stype == IEEE80211_STYPE_DEAUTH)
Holger Schurigce470612009-10-13 13:28:13 +0200522 if (cookie)
523 __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
524 else
525 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Jouni Malinen53b46b82009-03-27 20:53:56 +0200526 else
Holger Schurigce470612009-10-13 13:28:13 +0200527 if (cookie)
528 __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
529 else
530 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg62ae67b2009-11-18 18:42:05 +0100531 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
532 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
533 ieee80211_tx_skb(sdata, skb);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200534}
535
Kalle Valo572e0012009-02-10 17:09:31 +0200536void ieee80211_send_pspoll(struct ieee80211_local *local,
537 struct ieee80211_sub_if_data *sdata)
538{
Johannes Berg46900292009-02-15 12:44:28 +0100539 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Kalle Valo572e0012009-02-10 17:09:31 +0200540 struct ieee80211_pspoll *pspoll;
541 struct sk_buff *skb;
542 u16 fc;
543
544 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
545 if (!skb) {
546 printk(KERN_DEBUG "%s: failed to allocate buffer for "
Johannes Berg47846c92009-11-25 17:46:19 +0100547 "pspoll frame\n", sdata->name);
Kalle Valo572e0012009-02-10 17:09:31 +0200548 return;
549 }
550 skb_reserve(skb, local->hw.extra_tx_headroom);
551
552 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
553 memset(pspoll, 0, sizeof(*pspoll));
554 fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
555 pspoll->frame_control = cpu_to_le16(fc);
Johannes Berg46900292009-02-15 12:44:28 +0100556 pspoll->aid = cpu_to_le16(ifmgd->aid);
Kalle Valo572e0012009-02-10 17:09:31 +0200557
558 /* aid in PS-Poll has its two MSBs each set to 1 */
559 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
560
Johannes Berg46900292009-02-15 12:44:28 +0100561 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100562 memcpy(pspoll->ta, sdata->vif.addr, ETH_ALEN);
Kalle Valo572e0012009-02-10 17:09:31 +0200563
Johannes Berg62ae67b2009-11-18 18:42:05 +0100564 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
565 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200566}
567
Johannes Berg965beda2009-04-16 13:17:24 +0200568void ieee80211_send_nullfunc(struct ieee80211_local *local,
569 struct ieee80211_sub_if_data *sdata,
570 int powersave)
571{
572 struct sk_buff *skb;
573 struct ieee80211_hdr *nullfunc;
574 __le16 fc;
575
576 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
577 return;
578
579 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
580 if (!skb) {
581 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
Johannes Berg47846c92009-11-25 17:46:19 +0100582 "frame\n", sdata->name);
Johannes Berg965beda2009-04-16 13:17:24 +0200583 return;
584 }
585 skb_reserve(skb, local->hw.extra_tx_headroom);
586
587 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
588 memset(nullfunc, 0, 24);
589 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
590 IEEE80211_FCTL_TODS);
591 if (powersave)
592 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
593 nullfunc->frame_control = fc;
594 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100595 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
Johannes Berg965beda2009-04-16 13:17:24 +0200596 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
597
Johannes Berg62ae67b2009-11-18 18:42:05 +0100598 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
599 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200600}
601
Johannes Bergcc32abd2009-05-15 11:52:31 +0200602/* spectrum management related things */
603static void ieee80211_chswitch_work(struct work_struct *work)
604{
605 struct ieee80211_sub_if_data *sdata =
606 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200607 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
608
Johannes Berg9607e6b2009-12-23 13:15:31 +0100609 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200610 return;
611
Johannes Berg77fdaa12009-07-07 03:45:17 +0200612 mutex_lock(&ifmgd->mtx);
613 if (!ifmgd->associated)
614 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200615
616 sdata->local->oper_channel = sdata->local->csa_channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200617 ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200618
Johannes Berg77fdaa12009-07-07 03:45:17 +0200619 /* XXX: shouldn't really modify cfg80211-owned data! */
620 ifmgd->associated->cbss.channel = sdata->local->oper_channel;
621
Johannes Bergcc32abd2009-05-15 11:52:31 +0200622 ieee80211_wake_queues_by_reason(&sdata->local->hw,
623 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200624 out:
625 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
626 mutex_unlock(&ifmgd->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200627}
628
629static void ieee80211_chswitch_timer(unsigned long data)
630{
631 struct ieee80211_sub_if_data *sdata =
632 (struct ieee80211_sub_if_data *) data;
633 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
634
Johannes Berg5bb644a2009-05-17 11:40:42 +0200635 if (sdata->local->quiescing) {
636 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
637 return;
638 }
639
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400640 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200641}
642
643void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
644 struct ieee80211_channel_sw_ie *sw_elem,
645 struct ieee80211_bss *bss)
646{
647 struct ieee80211_channel *new_ch;
648 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
649 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
650
Johannes Berg77fdaa12009-07-07 03:45:17 +0200651 ASSERT_MGD_MTX(ifmgd);
652
653 if (!ifmgd->associated)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200654 return;
655
Helmut Schaafbe9c422009-07-23 12:14:04 +0200656 if (sdata->local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200657 return;
658
659 /* Disregard subsequent beacons if we are already running a timer
660 processing a CSA */
661
662 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
663 return;
664
665 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
666 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
667 return;
668
669 sdata->local->csa_channel = new_ch;
670
671 if (sw_elem->count <= 1) {
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400672 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200673 } else {
674 ieee80211_stop_queues_by_reason(&sdata->local->hw,
675 IEEE80211_QUEUE_STOP_REASON_CSA);
676 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
677 mod_timer(&ifmgd->chswitch_timer,
678 jiffies +
679 msecs_to_jiffies(sw_elem->count *
680 bss->cbss.beacon_interval));
681 }
682}
683
684static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
685 u16 capab_info, u8 *pwr_constr_elem,
686 u8 pwr_constr_elem_len)
687{
688 struct ieee80211_conf *conf = &sdata->local->hw.conf;
689
690 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
691 return;
692
693 /* Power constraint IE length should be 1 octet */
694 if (pwr_constr_elem_len != 1)
695 return;
696
697 if ((*pwr_constr_elem <= conf->channel->max_power) &&
698 (*pwr_constr_elem != sdata->local->power_constr_level)) {
699 sdata->local->power_constr_level = *pwr_constr_elem;
700 ieee80211_hw_config(sdata->local, 0);
701 }
702}
703
Johannes Berg965beda2009-04-16 13:17:24 +0200704/* powersave */
705static void ieee80211_enable_ps(struct ieee80211_local *local,
706 struct ieee80211_sub_if_data *sdata)
707{
708 struct ieee80211_conf *conf = &local->hw.conf;
709
Johannes Bergd5edaed2009-04-22 23:02:51 +0200710 /*
711 * If we are scanning right now then the parameters will
712 * take effect when scan finishes.
713 */
Helmut Schaafbe9c422009-07-23 12:14:04 +0200714 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +0200715 return;
716
Johannes Berg965beda2009-04-16 13:17:24 +0200717 if (conf->dynamic_ps_timeout > 0 &&
718 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
719 mod_timer(&local->dynamic_ps_timer, jiffies +
720 msecs_to_jiffies(conf->dynamic_ps_timeout));
721 } else {
722 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
723 ieee80211_send_nullfunc(local, sdata, 1);
724 conf->flags |= IEEE80211_CONF_PS;
725 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
726 }
727}
728
729static void ieee80211_change_ps(struct ieee80211_local *local)
730{
731 struct ieee80211_conf *conf = &local->hw.conf;
732
733 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +0200734 ieee80211_enable_ps(local, local->ps_sdata);
735 } else if (conf->flags & IEEE80211_CONF_PS) {
736 conf->flags &= ~IEEE80211_CONF_PS;
737 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
738 del_timer_sync(&local->dynamic_ps_timer);
739 cancel_work_sync(&local->dynamic_ps_enable_work);
740 }
741}
742
743/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +0200744void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +0200745{
746 struct ieee80211_sub_if_data *sdata, *found = NULL;
747 int count = 0;
748
749 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
750 local->ps_sdata = NULL;
751 return;
752 }
753
754 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +0100755 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +0200756 continue;
757 if (sdata->vif.type != NL80211_IFTYPE_STATION)
758 continue;
759 found = sdata;
760 count++;
761 }
762
Luis R. Rodriguez43f78532009-06-10 15:16:15 +0200763 if (count == 1 && found->u.mgd.powersave &&
Johannes Berg77fdaa12009-07-07 03:45:17 +0200764 found->u.mgd.associated && list_empty(&found->u.mgd.work_list) &&
Johannes Bergb291ba12009-07-10 15:29:03 +0200765 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
766 IEEE80211_STA_CONNECTION_POLL))) {
Johannes Berg10f644a2009-04-16 13:17:25 +0200767 s32 beaconint_us;
768
769 if (latency < 0)
770 latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY);
771
772 beaconint_us = ieee80211_tu_to_usec(
773 found->vif.bss_conf.beacon_int);
774
Johannes Berg04fe2032009-04-22 18:44:37 +0200775 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +0200776 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +0200777 } else {
778 u8 dtimper = found->vif.bss_conf.dtim_period;
779 int maxslp = 1;
780
781 if (dtimper > 1)
782 maxslp = min_t(int, dtimper,
783 latency / beaconint_us);
784
Johannes Berg9ccebe62009-04-23 10:32:36 +0200785 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg10f644a2009-04-16 13:17:25 +0200786 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +0200787 }
Johannes Berg10f644a2009-04-16 13:17:25 +0200788 } else {
Johannes Berg965beda2009-04-16 13:17:24 +0200789 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +0200790 }
Johannes Berg965beda2009-04-16 13:17:24 +0200791
792 ieee80211_change_ps(local);
793}
794
795void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
796{
797 struct ieee80211_local *local =
798 container_of(work, struct ieee80211_local,
799 dynamic_ps_disable_work);
800
801 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
802 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
803 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
804 }
805
806 ieee80211_wake_queues_by_reason(&local->hw,
807 IEEE80211_QUEUE_STOP_REASON_PS);
808}
809
810void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
811{
812 struct ieee80211_local *local =
813 container_of(work, struct ieee80211_local,
814 dynamic_ps_enable_work);
815 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
816
817 /* can only happen when PS was just disabled anyway */
818 if (!sdata)
819 return;
820
821 if (local->hw.conf.flags & IEEE80211_CONF_PS)
822 return;
823
824 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
825 ieee80211_send_nullfunc(local, sdata, 1);
826
827 local->hw.conf.flags |= IEEE80211_CONF_PS;
828 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
829}
830
831void ieee80211_dynamic_ps_timer(unsigned long data)
832{
833 struct ieee80211_local *local = (void *) data;
834
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -0700835 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +0200836 return;
837
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400838 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +0200839}
840
Johannes Berg60f8b392008-09-08 17:44:22 +0200841/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200842static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg46900292009-02-15 12:44:28 +0100843 struct ieee80211_if_managed *ifmgd,
Jiri Bencf0706e82007-05-05 11:45:53 -0700844 u8 *wmm_param, size_t wmm_param_len)
845{
Jiri Bencf0706e82007-05-05 11:45:53 -0700846 struct ieee80211_tx_queue_params params;
847 size_t left;
848 int count;
849 u8 *pos;
850
Johannes Berg46900292009-02-15 12:44:28 +0100851 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED))
Johannes Berg3434fbd2008-05-03 00:59:37 +0200852 return;
853
854 if (!wmm_param)
855 return;
856
Jiri Bencf0706e82007-05-05 11:45:53 -0700857 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
858 return;
859 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100860 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e82007-05-05 11:45:53 -0700861 return;
Johannes Berg46900292009-02-15 12:44:28 +0100862 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700863
864 pos = wmm_param + 8;
865 left = wmm_param_len - 8;
866
867 memset(&params, 0, sizeof(params));
868
Jiri Bencf0706e82007-05-05 11:45:53 -0700869 local->wmm_acm = 0;
870 for (; left >= 4; left -= 4, pos += 4) {
871 int aci = (pos[0] >> 5) & 0x03;
872 int acm = (pos[0] >> 4) & 0x01;
873 int queue;
874
875 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200876 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200877 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200878 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200879 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Jiri Bencf0706e82007-05-05 11:45:53 -0700880 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200881 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200882 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200883 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200884 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Jiri Bencf0706e82007-05-05 11:45:53 -0700885 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200886 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200887 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200888 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200889 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Jiri Bencf0706e82007-05-05 11:45:53 -0700890 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200891 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700892 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200893 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200894 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200895 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700896 break;
897 }
898
899 params.aifs = pos[0] & 0x0f;
900 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
901 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200902 params.txop = get_unaligned_le16(pos + 2);
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200903#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Jiri Bencf0706e82007-05-05 11:45:53 -0700904 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
Johannes Berg3330d7b2008-02-10 16:49:38 +0100905 "cWmin=%d cWmax=%d txop=%d\n",
Johannes Berg0bffe402009-06-09 16:18:32 +0200906 wiphy_name(local->hw.wiphy), queue, aci, acm,
907 params.aifs, params.cw_min, params.cw_max, params.txop);
Johannes Berg3330d7b2008-02-10 16:49:38 +0100908#endif
Johannes Berg24487982009-04-23 18:52:52 +0200909 if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx)
Jiri Bencf0706e82007-05-05 11:45:53 -0700910 printk(KERN_DEBUG "%s: failed to set TX queue "
Johannes Berg0bffe402009-06-09 16:18:32 +0200911 "parameters for queue %d\n",
912 wiphy_name(local->hw.wiphy), queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700913 }
914}
915
Johannes Berg7a5158e2008-10-08 10:59:33 +0200916static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
917 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200918{
Johannes Bergbda39332008-10-11 01:51:51 +0200919 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100920 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200921 bool use_protection;
922 bool use_short_preamble;
923 bool use_short_slot;
924
925 if (erp_valid) {
926 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
927 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
928 } else {
929 use_protection = false;
930 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
931 }
932
933 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Daniel Drake56282212007-07-10 19:32:10 +0200934
Johannes Berg471b3ef2007-12-28 14:32:58 +0100935 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +0100936 bss_conf->use_cts_prot = use_protection;
937 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200938 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200939
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200940 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200941 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100942 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200943 }
Daniel Draked9430a32007-07-27 15:43:24 +0200944
Johannes Berg7a5158e2008-10-08 10:59:33 +0200945 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +0200946 bss_conf->use_short_slot = use_short_slot;
947 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400948 }
949
950 return changed;
951}
952
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200953static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg63f170e2009-12-23 13:15:33 +0100954 struct ieee80211_bss *bss,
Johannes Bergae5eb022008-10-14 16:58:37 +0200955 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700956{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100957 struct ieee80211_local *local = sdata->local;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400958
Johannes Bergae5eb022008-10-14 16:58:37 +0200959 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200960 /* set timing information */
961 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
962 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
963 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400964
Johannes Berg77fdaa12009-07-07 03:45:17 +0200965 bss_info_changed |= BSS_CHANGED_BEACON_INT;
966 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
967 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700968
Johannes Berg77fdaa12009-07-07 03:45:17 +0200969 sdata->u.mgd.associated = bss;
970 memcpy(sdata->u.mgd.bssid, bss->cbss.bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +0100971
Johannes Bergb291ba12009-07-10 15:29:03 +0200972 /* just to be sure */
973 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
974 IEEE80211_STA_BEACON_POLL);
975
Johannes Berg01838262009-12-17 16:16:53 +0100976 /*
977 * Always handle WMM once after association regardless
978 * of the first value the AP uses. Setting -1 here has
979 * that effect because the AP values is an unsigned
980 * 4-bit value.
981 */
982 sdata->u.mgd.wmm_last_param_set = -1;
983
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200984 ieee80211_led_assoc(local, 1);
985
Johannes Bergbda39332008-10-11 01:51:51 +0200986 sdata->vif.bss_conf.assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200987 /*
988 * For now just always ask the driver to update the basic rateset
989 * when we have associated, we aren't checking whether it actually
990 * changed or not.
991 */
Johannes Bergae5eb022008-10-14 16:58:37 +0200992 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
Johannes Berg9cef8732009-05-14 13:10:14 +0200993
994 /* And the BSSID changed - we're associated now */
995 bss_info_changed |= BSS_CHANGED_BSSID;
996
Johannes Bergae5eb022008-10-14 16:58:37 +0200997 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +0300998
Johannes Berg056508d2009-07-30 21:43:55 +0200999 mutex_lock(&local->iflist_mtx);
1000 ieee80211_recalc_ps(local, -1);
Johannes Berg0f782312009-12-01 13:37:02 +01001001 ieee80211_recalc_smps(local, sdata);
Johannes Berg056508d2009-07-30 21:43:55 +02001002 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02001003
John W. Linville53623f12009-10-15 15:10:16 -04001004 netif_start_queue(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001005 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001006}
1007
Johannes Bergf679f652009-12-23 13:15:34 +01001008static void ieee80211_remove_auth_bss(struct ieee80211_local *local,
1009 struct ieee80211_work *wk)
1010{
1011 struct cfg80211_bss *cbss;
1012 u16 capa_val = WLAN_CAPABILITY_ESS;
1013
1014 if (wk->auth.privacy)
1015 capa_val |= WLAN_CAPABILITY_PRIVACY;
1016
1017 cbss = cfg80211_get_bss(local->hw.wiphy, wk->chan, wk->auth.bssid,
1018 wk->auth.ssid, wk->auth.ssid_len,
1019 WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY,
1020 capa_val);
1021 if (!cbss)
1022 return;
1023
1024 cfg80211_unlink_bss(local->hw.wiphy, cbss);
1025 cfg80211_put_bss(cbss);
1026}
1027
Johannes Berg77fdaa12009-07-07 03:45:17 +02001028static enum rx_mgmt_action __must_check
1029ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
Johannes Bergf679f652009-12-23 13:15:34 +01001030 struct ieee80211_work *wk)
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001031{
Johannes Berg46900292009-02-15 12:44:28 +01001032 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +01001033 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01001034
Johannes Bergf679f652009-12-23 13:15:34 +01001035 wk->auth.tries++;
1036 if (wk->auth.tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -07001037 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
Johannes Bergf679f652009-12-23 13:15:34 +01001038 sdata->name, wk->auth.bssid);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301039
1040 /*
1041 * Most likely AP is not in the range so remove the
Johannes Berg77fdaa12009-07-07 03:45:17 +02001042 * bss struct for that AP.
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301043 */
Johannes Bergf679f652009-12-23 13:15:34 +01001044 ieee80211_remove_auth_bss(local, wk);
Helmut Schaa11432372009-03-12 14:04:34 +01001045
1046 /*
1047 * We might have a pending scan which had no chance to run yet
Johannes Berg77fdaa12009-07-07 03:45:17 +02001048 * due to work needing to be done. Hence, queue the STAs work
1049 * again for that.
Helmut Schaa11432372009-03-12 14:04:34 +01001050 */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001051 ieee80211_queue_work(&local->hw, &ifmgd->work);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001052 return RX_MGMT_CFG80211_AUTH_TO;
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001053 }
1054
Johannes Berg77fdaa12009-07-07 03:45:17 +02001055 printk(KERN_DEBUG "%s: direct probe to AP %pM (try %d)\n",
Johannes Bergf679f652009-12-23 13:15:34 +01001056 sdata->name, wk->auth.bssid, wk->auth.tries);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001057
Johannes Berg77fdaa12009-07-07 03:45:17 +02001058 /*
1059 * Direct probe is sent to broadcast address as some APs
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001060 * will not answer to direct packet in unassociated state.
1061 */
Johannes Bergf679f652009-12-23 13:15:34 +01001062 ieee80211_send_probe_req(sdata, NULL, wk->auth.ssid, wk->auth.ssid_len,
1063 NULL, 0);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001064
Johannes Berg77fdaa12009-07-07 03:45:17 +02001065 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Bergca386f32009-07-10 02:39:48 +02001066 run_again(ifmgd, wk->timeout);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001067
1068 return RX_MGMT_NONE;
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001069}
1070
Jiri Bencf0706e82007-05-05 11:45:53 -07001071
Johannes Berg77fdaa12009-07-07 03:45:17 +02001072static enum rx_mgmt_action __must_check
1073ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
Johannes Bergf679f652009-12-23 13:15:34 +01001074 struct ieee80211_work *wk)
Jiri Bencf0706e82007-05-05 11:45:53 -07001075{
Johannes Berg46900292009-02-15 12:44:28 +01001076 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +01001077 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01001078
Johannes Bergf679f652009-12-23 13:15:34 +01001079 wk->auth.tries++;
1080 if (wk->auth.tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -07001081 printk(KERN_DEBUG "%s: authentication with AP %pM"
Johannes Bergf679f652009-12-23 13:15:34 +01001082 " timed out\n", sdata->name, wk->auth.bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001083
1084 /*
1085 * Most likely AP is not in the range so remove the
1086 * bss struct for that AP.
1087 */
Johannes Bergf679f652009-12-23 13:15:34 +01001088 ieee80211_remove_auth_bss(local, wk);
Helmut Schaa11432372009-03-12 14:04:34 +01001089
1090 /*
1091 * We might have a pending scan which had no chance to run yet
Johannes Berg77fdaa12009-07-07 03:45:17 +02001092 * due to work needing to be done. Hence, queue the STAs work
1093 * again for that.
Helmut Schaa11432372009-03-12 14:04:34 +01001094 */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001095 ieee80211_queue_work(&local->hw, &ifmgd->work);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001096 return RX_MGMT_CFG80211_AUTH_TO;
Jiri Bencf0706e82007-05-05 11:45:53 -07001097 }
1098
Johannes Berg77fdaa12009-07-07 03:45:17 +02001099 printk(KERN_DEBUG "%s: authenticate with AP %pM (try %d)\n",
Johannes Bergf679f652009-12-23 13:15:34 +01001100 sdata->name, wk->auth.bssid, wk->auth.tries);
Jiri Bencf0706e82007-05-05 11:45:53 -07001101
Johannes Bergf679f652009-12-23 13:15:34 +01001102 ieee80211_send_auth(sdata, 1, wk->auth.algorithm, wk->ie, wk->ie_len,
1103 wk->auth.bssid, NULL, 0, 0);
1104 wk->auth.transaction = 2;
Jiri Bencf0706e82007-05-05 11:45:53 -07001105
Johannes Berg77fdaa12009-07-07 03:45:17 +02001106 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
Johannes Bergca386f32009-07-10 02:39:48 +02001107 run_again(ifmgd, wk->timeout);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001108
1109 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001110}
1111
Johannes Berg63f170e2009-12-23 13:15:33 +01001112static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata)
Tomas Winkleraa458d12008-09-09 00:32:12 +03001113{
Johannes Berg46900292009-02-15 12:44:28 +01001114 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001115 struct ieee80211_local *local = sdata->local;
1116 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +02001117 u32 changed = 0, config_changed = 0;
Johannes Bergb291ba12009-07-10 15:29:03 +02001118 u8 bssid[ETH_ALEN];
Tomas Winkleraa458d12008-09-09 00:32:12 +03001119
Johannes Berg77fdaa12009-07-07 03:45:17 +02001120 ASSERT_MGD_MTX(ifmgd);
1121
Johannes Bergb291ba12009-07-10 15:29:03 +02001122 if (WARN_ON(!ifmgd->associated))
1123 return;
1124
1125 memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN);
1126
Johannes Berg77fdaa12009-07-07 03:45:17 +02001127 ifmgd->associated = NULL;
1128 memset(ifmgd->bssid, 0, ETH_ALEN);
1129
1130 /*
1131 * we need to commit the associated = NULL change because the
1132 * scan code uses that to determine whether this iface should
1133 * go to/wake up from powersave or not -- and could otherwise
1134 * wake the queues erroneously.
1135 */
1136 smp_mb();
1137
1138 /*
1139 * Thus, we can only afterwards stop the queues -- to account
1140 * for the case where another CPU is finishing a scan at this
1141 * time -- we don't want the scan code to enable queues.
1142 */
Tomas Winkleraa458d12008-09-09 00:32:12 +03001143
John W. Linville53623f12009-10-15 15:10:16 -04001144 netif_stop_queue(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001145 netif_carrier_off(sdata->dev);
1146
Johannes Berg1fa6f4a2009-06-15 18:13:58 +02001147 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001148 sta = sta_info_get(sdata, bssid);
Johannes Berg1fa6f4a2009-06-15 18:13:58 +02001149 if (sta)
1150 ieee80211_sta_tear_down_BA_sessions(sta);
1151 rcu_read_unlock();
Tomas Winkleraa458d12008-09-09 00:32:12 +03001152
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001153 changed |= ieee80211_reset_erp_info(sdata);
1154
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001155 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001156 changed |= BSS_CHANGED_ASSOC;
1157 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001158
Johannes Bergaa837e12009-05-07 16:16:24 +02001159 ieee80211_set_wmm_default(sdata);
1160
Johannes Berg47979382009-01-07 10:13:27 +01001161 /* channel(_type) changes are handled by ieee80211_hw_config */
Sujith094d05d2008-12-12 11:57:43 +05301162 local->oper_channel_type = NL80211_CHAN_NO_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001163
Johannes Berg413ad502009-05-08 21:21:06 +02001164 /* on the next assoc, re-program HT parameters */
1165 sdata->ht_opmode_valid = false;
1166
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301167 local->power_constr_level = 0;
1168
Kalle Valo520eb822008-12-18 23:35:27 +02001169 del_timer_sync(&local->dynamic_ps_timer);
1170 cancel_work_sync(&local->dynamic_ps_enable_work);
1171
Kalle Valoe0cb6862008-12-18 23:35:13 +02001172 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1173 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1174 config_changed |= IEEE80211_CONF_CHANGE_PS;
1175 }
1176
1177 ieee80211_hw_config(local, config_changed);
Johannes Berg9cef8732009-05-14 13:10:14 +02001178
1179 /* And the BSSID changed -- not very interesting here */
1180 changed |= BSS_CHANGED_BSSID;
Johannes Bergae5eb022008-10-14 16:58:37 +02001181 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001182
1183 rcu_read_lock();
1184
Johannes Bergabe60632009-11-25 17:46:18 +01001185 sta = sta_info_get(sdata, bssid);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001186 if (!sta) {
1187 rcu_read_unlock();
1188 return;
1189 }
1190
1191 sta_info_unlink(&sta);
1192
1193 rcu_read_unlock();
1194
1195 sta_info_destroy(sta);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001196}
Jiri Bencf0706e82007-05-05 11:45:53 -07001197
Johannes Berg77fdaa12009-07-07 03:45:17 +02001198static enum rx_mgmt_action __must_check
1199ieee80211_associate(struct ieee80211_sub_if_data *sdata,
Johannes Bergf679f652009-12-23 13:15:34 +01001200 struct ieee80211_work *wk)
Jiri Bencf0706e82007-05-05 11:45:53 -07001201{
Johannes Berg46900292009-02-15 12:44:28 +01001202 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +01001203 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01001204
Johannes Bergf679f652009-12-23 13:15:34 +01001205 wk->assoc.tries++;
1206 if (wk->assoc.tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -07001207 printk(KERN_DEBUG "%s: association with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -07001208 " timed out\n",
Johannes Bergf679f652009-12-23 13:15:34 +01001209 sdata->name, wk->assoc.bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001210
1211 /*
1212 * Most likely AP is not in the range so remove the
1213 * bss struct for that AP.
1214 */
Johannes Bergf679f652009-12-23 13:15:34 +01001215 cfg80211_unlink_bss(local->hw.wiphy, &wk->assoc.bss->cbss);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001216
Helmut Schaa11432372009-03-12 14:04:34 +01001217 /*
1218 * We might have a pending scan which had no chance to run yet
Johannes Berg77fdaa12009-07-07 03:45:17 +02001219 * due to work needing to be done. Hence, queue the STAs work
1220 * again for that.
Helmut Schaa11432372009-03-12 14:04:34 +01001221 */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001222 ieee80211_queue_work(&local->hw, &ifmgd->work);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001223 return RX_MGMT_CFG80211_ASSOC_TO;
Jiri Bencf0706e82007-05-05 11:45:53 -07001224 }
1225
Johannes Berg77fdaa12009-07-07 03:45:17 +02001226 printk(KERN_DEBUG "%s: associate with AP %pM (try %d)\n",
Johannes Bergf679f652009-12-23 13:15:34 +01001227 sdata->name, wk->assoc.bssid, wk->assoc.tries);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001228 ieee80211_send_assoc(sdata, wk);
Jiri Bencf0706e82007-05-05 11:45:53 -07001229
Johannes Berg77fdaa12009-07-07 03:45:17 +02001230 wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
Johannes Bergca386f32009-07-10 02:39:48 +02001231 run_again(ifmgd, wk->timeout);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001232
1233 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001234}
1235
Kalle Valo3cf335d2009-03-22 21:57:06 +02001236void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1237 struct ieee80211_hdr *hdr)
1238{
1239 /*
1240 * We can postpone the mgd.timer whenever receiving unicast frames
1241 * from AP because we know that the connection is working both ways
1242 * at that time. But multicast frames (and hence also beacons) must
1243 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001244 * data idle periods for sending the periodic probe request to the
1245 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001246 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001247 if (is_multicast_ether_addr(hdr->addr1))
1248 return;
1249
1250 mod_timer(&sdata->u.mgd.conn_mon_timer,
1251 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
Kalle Valo3cf335d2009-03-22 21:57:06 +02001252}
Jiri Bencf0706e82007-05-05 11:45:53 -07001253
Maxim Levitskya43abf22009-07-31 18:54:12 +03001254static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1255{
1256 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1257 const u8 *ssid;
1258
1259 ssid = ieee80211_bss_get_ie(&ifmgd->associated->cbss, WLAN_EID_SSID);
1260 ieee80211_send_probe_req(sdata, ifmgd->associated->cbss.bssid,
1261 ssid + 2, ssid[1], NULL, 0);
1262
1263 ifmgd->probe_send_count++;
1264 ifmgd->probe_timeout = jiffies + IEEE80211_PROBE_WAIT;
1265 run_again(ifmgd, ifmgd->probe_timeout);
1266}
1267
Johannes Bergb291ba12009-07-10 15:29:03 +02001268static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1269 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02001270{
Kalle Valo04de8382009-03-22 21:57:35 +02001271 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02001272 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02001273
Johannes Berg9607e6b2009-12-23 13:15:31 +01001274 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02001275 return;
1276
Luis R. Rodriguez91a3bd72009-07-23 16:37:47 -07001277 if (sdata->local->scanning)
1278 return;
1279
Johannes Berg77fdaa12009-07-07 03:45:17 +02001280 mutex_lock(&ifmgd->mtx);
1281
1282 if (!ifmgd->associated)
1283 goto out;
1284
Michael Buescha8604022009-04-15 14:41:22 -04001285#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergb291ba12009-07-10 15:29:03 +02001286 if (beacon && net_ratelimit())
1287 printk(KERN_DEBUG "%s: detected beacon loss from AP "
Johannes Berg47846c92009-11-25 17:46:19 +01001288 "- sending probe request\n", sdata->name);
Michael Buescha8604022009-04-15 14:41:22 -04001289#endif
Kalle Valo04de8382009-03-22 21:57:35 +02001290
Johannes Bergb291ba12009-07-10 15:29:03 +02001291 /*
1292 * The driver/our work has already reported this event or the
1293 * connection monitoring has kicked in and we have already sent
1294 * a probe request. Or maybe the AP died and the driver keeps
1295 * reporting until we disassociate...
1296 *
1297 * In either case we have to ignore the current call to this
1298 * function (except for setting the correct probe reason bit)
1299 * because otherwise we would reset the timer every time and
1300 * never check whether we received a probe response!
1301 */
1302 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1303 IEEE80211_STA_CONNECTION_POLL))
1304 already = true;
1305
1306 if (beacon)
1307 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1308 else
1309 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1310
1311 if (already)
1312 goto out;
1313
Johannes Berg4e751842009-06-10 15:16:52 +02001314 mutex_lock(&sdata->local->iflist_mtx);
1315 ieee80211_recalc_ps(sdata->local, -1);
1316 mutex_unlock(&sdata->local->iflist_mtx);
1317
Maxim Levitskya43abf22009-07-31 18:54:12 +03001318 ifmgd->probe_send_count = 0;
1319 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001320 out:
1321 mutex_unlock(&ifmgd->mtx);
Kalle Valo04de8382009-03-22 21:57:35 +02001322}
1323
Johannes Bergb291ba12009-07-10 15:29:03 +02001324void ieee80211_beacon_loss_work(struct work_struct *work)
1325{
1326 struct ieee80211_sub_if_data *sdata =
1327 container_of(work, struct ieee80211_sub_if_data,
1328 u.mgd.beacon_loss_work);
1329
1330 ieee80211_mgd_probe_ap(sdata, true);
1331}
1332
Kalle Valo04de8382009-03-22 21:57:35 +02001333void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1334{
1335 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1336
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001337 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.beacon_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02001338}
1339EXPORT_SYMBOL(ieee80211_beacon_loss);
1340
Johannes Berg77fdaa12009-07-07 03:45:17 +02001341static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
Johannes Bergf679f652009-12-23 13:15:34 +01001342 struct ieee80211_work *wk)
Jiri Bencf0706e82007-05-05 11:45:53 -07001343{
Johannes Berg63f170e2009-12-23 13:15:33 +01001344 list_del(&wk->list);
1345 kfree(wk);
Johannes Berg47846c92009-11-25 17:46:19 +01001346 printk(KERN_DEBUG "%s: authenticated\n", sdata->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07001347}
1348
1349
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001350static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
Johannes Bergf679f652009-12-23 13:15:34 +01001351 struct ieee80211_work *wk,
Jiri Bencf0706e82007-05-05 11:45:53 -07001352 struct ieee80211_mgmt *mgmt,
1353 size_t len)
1354{
1355 u8 *pos;
1356 struct ieee802_11_elems elems;
1357
Jiri Bencf0706e82007-05-05 11:45:53 -07001358 pos = mgmt->u.auth.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001359 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001360 if (!elems.challenge)
Jiri Bencf0706e82007-05-05 11:45:53 -07001361 return;
Johannes Bergf679f652009-12-23 13:15:34 +01001362 ieee80211_send_auth(sdata, 3, wk->auth.algorithm,
Johannes Berg46900292009-02-15 12:44:28 +01001363 elems.challenge - 2, elems.challenge_len + 2,
Johannes Bergf679f652009-12-23 13:15:34 +01001364 wk->auth.bssid, wk->auth.key, wk->auth.key_len,
1365 wk->auth.key_idx);
1366 wk->auth.transaction = 4;
Johannes Bergfe3d2c32009-02-10 21:26:03 +01001367}
1368
Johannes Berg77fdaa12009-07-07 03:45:17 +02001369static enum rx_mgmt_action __must_check
1370ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
Johannes Bergf679f652009-12-23 13:15:34 +01001371 struct ieee80211_work *wk,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001372 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001373{
Jiri Bencf0706e82007-05-05 11:45:53 -07001374 u16 auth_alg, auth_transaction, status_code;
1375
Johannes Bergf679f652009-12-23 13:15:34 +01001376 if (wk->type != IEEE80211_WORK_AUTH)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001377 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001378
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001379 if (len < 24 + 6)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001380 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001381
Johannes Bergf679f652009-12-23 13:15:34 +01001382 if (memcmp(wk->auth.bssid, mgmt->sa, ETH_ALEN) != 0)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001383 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001384
Johannes Bergf679f652009-12-23 13:15:34 +01001385 if (memcmp(wk->auth.bssid, mgmt->bssid, ETH_ALEN) != 0)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001386 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001387
1388 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1389 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1390 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1391
Johannes Bergf679f652009-12-23 13:15:34 +01001392 if (auth_alg != wk->auth.algorithm ||
1393 auth_transaction != wk->auth.transaction)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001394 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001395
1396 if (status_code != WLAN_STATUS_SUCCESS) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02001397 list_del(&wk->list);
1398 kfree(wk);
1399 return RX_MGMT_CFG80211_AUTH;
Jiri Bencf0706e82007-05-05 11:45:53 -07001400 }
1401
Johannes Bergf679f652009-12-23 13:15:34 +01001402 switch (wk->auth.algorithm) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001403 case WLAN_AUTH_OPEN:
1404 case WLAN_AUTH_LEAP:
Jouni Malinen636a5d32009-03-19 13:39:22 +02001405 case WLAN_AUTH_FT:
Johannes Berg77fdaa12009-07-07 03:45:17 +02001406 ieee80211_auth_completed(sdata, wk);
1407 return RX_MGMT_CFG80211_AUTH;
Jiri Bencf0706e82007-05-05 11:45:53 -07001408 case WLAN_AUTH_SHARED_KEY:
Johannes Bergf679f652009-12-23 13:15:34 +01001409 if (wk->auth.transaction == 4) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02001410 ieee80211_auth_completed(sdata, wk);
1411 return RX_MGMT_CFG80211_AUTH;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001412 } else
Johannes Berg77fdaa12009-07-07 03:45:17 +02001413 ieee80211_auth_challenge(sdata, wk, mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001414 break;
1415 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02001416
1417 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001418}
1419
1420
Johannes Berg77fdaa12009-07-07 03:45:17 +02001421static enum rx_mgmt_action __must_check
1422ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001423 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001424{
Johannes Berg46900292009-02-15 12:44:28 +01001425 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001426 const u8 *bssid = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001427 u16 reason_code;
1428
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001429 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001430 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001431
Johannes Berg77fdaa12009-07-07 03:45:17 +02001432 ASSERT_MGD_MTX(ifmgd);
1433
Johannes Berg63f170e2009-12-23 13:15:33 +01001434 bssid = ifmgd->associated->cbss.bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001435
1436 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1437
Johannes Berg77fdaa12009-07-07 03:45:17 +02001438 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001439 sdata->name, bssid, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001440
Johannes Berg63f170e2009-12-23 13:15:33 +01001441 ieee80211_set_disassoc(sdata);
1442 ieee80211_recalc_idle(sdata->local);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001443
1444 return RX_MGMT_CFG80211_DEAUTH;
Jiri Bencf0706e82007-05-05 11:45:53 -07001445}
1446
1447
Johannes Berg77fdaa12009-07-07 03:45:17 +02001448static enum rx_mgmt_action __must_check
1449ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1450 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001451{
Johannes Berg46900292009-02-15 12:44:28 +01001452 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001453 u16 reason_code;
1454
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001455 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001456 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001457
Johannes Berg77fdaa12009-07-07 03:45:17 +02001458 ASSERT_MGD_MTX(ifmgd);
1459
1460 if (WARN_ON(!ifmgd->associated))
1461 return RX_MGMT_NONE;
1462
1463 if (WARN_ON(memcmp(ifmgd->associated->cbss.bssid, mgmt->sa, ETH_ALEN)))
1464 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001465
1466 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1467
Johannes Berg0ff71612009-09-26 14:45:41 +02001468 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001469 sdata->name, mgmt->sa, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001470
Johannes Berg63f170e2009-12-23 13:15:33 +01001471 ieee80211_set_disassoc(sdata);
Johannes Bergbc83b682009-11-29 12:19:06 +01001472 ieee80211_recalc_idle(sdata->local);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001473 return RX_MGMT_CFG80211_DISASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -07001474}
1475
1476
Johannes Berg77fdaa12009-07-07 03:45:17 +02001477static enum rx_mgmt_action __must_check
1478ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergf679f652009-12-23 13:15:34 +01001479 struct ieee80211_work *wk,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001480 struct ieee80211_mgmt *mgmt, size_t len,
1481 bool reassoc)
Jiri Bencf0706e82007-05-05 11:45:53 -07001482{
Johannes Berg46900292009-02-15 12:44:28 +01001483 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001484 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001485 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001486 struct sta_info *sta;
Johannes Bergf679f652009-12-23 13:15:34 +01001487 struct ieee80211_bss *bss = wk->assoc.bss;
Johannes Berg881d9482009-01-21 15:13:48 +01001488 u32 rates, basic_rates;
Jiri Bencf0706e82007-05-05 11:45:53 -07001489 u16 capab_info, status_code, aid;
1490 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001491 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07001492 u8 *pos;
Johannes Bergae5eb022008-10-14 16:58:37 +02001493 u32 changed = 0;
Johannes Berg5d1ec852009-12-02 12:43:43 +01001494 int i, j, err;
1495 bool have_higher_than_11mbit = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001496 u16 ap_ht_cap_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001497
Johannes Berg77fdaa12009-07-07 03:45:17 +02001498 /*
1499 * AssocResp and ReassocResp have identical structure, so process both
1500 * of them in this function.
1501 */
Jiri Bencf0706e82007-05-05 11:45:53 -07001502
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001503 if (len < 24 + 6)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001504 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001505
Johannes Berg63f170e2009-12-23 13:15:33 +01001506 if (memcmp(bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001507 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001508
1509 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1510 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1511 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001512
Johannes Berg0c68ae262008-10-27 15:56:10 -07001513 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
Jiri Bencf0706e82007-05-05 11:45:53 -07001514 "status=%d aid=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001515 sdata->name, reassoc ? "Rea" : "A", mgmt->sa,
Johannes Bergddd68582007-10-22 14:51:37 +02001516 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Jiri Bencf0706e82007-05-05 11:45:53 -07001517
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001518 pos = mgmt->u.assoc_resp.variable;
1519 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1520
1521 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Jouni Malinenf797eb72009-01-19 18:48:46 +02001522 elems.timeout_int && elems.timeout_int_len == 5 &&
1523 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001524 u32 tu, ms;
Jouni Malinenf797eb72009-01-19 18:48:46 +02001525 tu = get_unaligned_le32(elems.timeout_int + 1);
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001526 ms = tu * 1024 / 1000;
1527 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1528 "comeback duration %u TU (%u ms)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001529 sdata->name, tu, ms);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001530 wk->timeout = jiffies + msecs_to_jiffies(ms);
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001531 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Bergca386f32009-07-10 02:39:48 +02001532 run_again(ifmgd, jiffies + msecs_to_jiffies(ms));
Johannes Berg77fdaa12009-07-07 03:45:17 +02001533 return RX_MGMT_NONE;
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001534 }
1535
Johannes Berg63f170e2009-12-23 13:15:33 +01001536 /*
1537 * Here the association was either successful or not.
1538 */
1539
1540 /* delete work item -- must be before set_associated for PS */
1541 list_del(&wk->list);
1542 kfree(wk);
1543
Jiri Bencf0706e82007-05-05 11:45:53 -07001544 if (status_code != WLAN_STATUS_SUCCESS) {
1545 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001546 sdata->name, status_code);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001547 return RX_MGMT_CFG80211_ASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -07001548 }
1549
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001550 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1551 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
Johannes Berg47846c92009-11-25 17:46:19 +01001552 "set\n", sdata->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001553 aid &= ~(BIT(15) | BIT(14));
1554
Jiri Bencf0706e82007-05-05 11:45:53 -07001555 if (!elems.supp_rates) {
1556 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001557 sdata->name);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001558 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001559 }
1560
Johannes Berg47846c92009-11-25 17:46:19 +01001561 printk(KERN_DEBUG "%s: associated\n", sdata->name);
Johannes Berg46900292009-02-15 12:44:28 +01001562 ifmgd->aid = aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001563
Johannes Berg63f170e2009-12-23 13:15:33 +01001564 sta = sta_info_alloc(sdata, bss->cbss.bssid, GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -07001565 if (!sta) {
Johannes Berg5d1ec852009-12-02 12:43:43 +01001566 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1567 " the AP\n", sdata->name);
1568 return RX_MGMT_CFG80211_ASSOC_ERROR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001569 }
1570
Johannes Berg5d1ec852009-12-02 12:43:43 +01001571 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1572 WLAN_STA_ASSOC_AP);
1573 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1574 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1575
Jiri Bencf0706e82007-05-05 11:45:53 -07001576 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001577 basic_rates = 0;
1578 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1579
Jiri Bencf0706e82007-05-05 11:45:53 -07001580 for (i = 0; i < elems.supp_rates_len; i++) {
1581 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001582 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001583
1584 if (rate > 110)
1585 have_higher_than_11mbit = true;
1586
1587 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001588 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001589 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001590 if (is_basic)
1591 basic_rates |= BIT(j);
1592 break;
1593 }
Johannes Berg8318d782008-01-24 19:38:38 +01001594 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001595 }
Johannes Berg8318d782008-01-24 19:38:38 +01001596
Jiri Bencf0706e82007-05-05 11:45:53 -07001597 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1598 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001599 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001600
1601 if (rate > 110)
1602 have_higher_than_11mbit = true;
1603
1604 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001605 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001606 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001607 if (is_basic)
1608 basic_rates |= BIT(j);
1609 break;
1610 }
Johannes Berg8318d782008-01-24 19:38:38 +01001611 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001612 }
Johannes Berg8318d782008-01-24 19:38:38 +01001613
Johannes Berg323ce792008-09-11 02:45:11 +02001614 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001615 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001616
1617 /* cf. IEEE 802.11 9.2.12 */
1618 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1619 have_higher_than_11mbit)
1620 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1621 else
1622 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001623
Johannes Bergab1faea2009-07-01 21:41:17 +02001624 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001625 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001626 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001627
1628 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001629
Johannes Berg4b7679a2008-09-18 18:14:18 +02001630 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001631
Johannes Berg46900292009-02-15 12:44:28 +01001632 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Jouni Malinen5394af42009-01-08 13:31:59 +02001633 set_sta_flags(sta, WLAN_STA_MFP);
1634
Johannes Bergddf4ac52008-10-22 11:41:38 +02001635 if (elems.wmm_param)
Johannes Berg07346f812008-05-03 01:02:02 +02001636 set_sta_flags(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001637
Johannes Berg5d1ec852009-12-02 12:43:43 +01001638 err = sta_info_insert(sta);
1639 sta = NULL;
1640 if (err) {
1641 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1642 " the AP (error %d)\n", sdata->name, err);
1643 return RX_MGMT_CFG80211_ASSOC_ERROR;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001644 }
1645
Johannes Bergddf4ac52008-10-22 11:41:38 +02001646 if (elems.wmm_param)
Johannes Berg46900292009-02-15 12:44:28 +01001647 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07001648 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02001649 else
1650 ieee80211_set_wmm_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001651
Johannes Bergae5eb022008-10-14 16:58:37 +02001652 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001653 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001654 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001655 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Johannes Berg63f170e2009-12-23 13:15:33 +01001656 bss->cbss.bssid,
Johannes Bergae5eb022008-10-14 16:58:37 +02001657 ap_ht_cap_flags);
1658
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001659 /* set AID and assoc capability,
1660 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001661 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001662 bss_conf->assoc_capability = capab_info;
Johannes Berg63f170e2009-12-23 13:15:33 +01001663 ieee80211_set_associated(sdata, bss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001664
Kalle Valo15b7b062009-03-22 21:57:14 +02001665 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02001666 * Start timer to probe the connection to the AP now.
1667 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02001668 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001669 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
1670 mod_beacon_timer(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02001671
Johannes Berg77fdaa12009-07-07 03:45:17 +02001672 return RX_MGMT_CFG80211_ASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -07001673}
1674
1675
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001676static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001677 struct ieee80211_mgmt *mgmt,
1678 size_t len,
1679 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001680 struct ieee802_11_elems *elems,
1681 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07001682{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001683 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001684 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001685 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001686 struct ieee80211_channel *channel;
Jiri Bencf0706e82007-05-05 11:45:53 -07001687
Johannes Berg5bda6172008-09-08 11:05:10 +02001688 if (elems->ds_params && elems->ds_params_len == 1)
1689 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
1690 else
1691 freq = rx_status->freq;
1692
1693 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1694
1695 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1696 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001697
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001698 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001699 channel, beacon);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001700 if (bss)
1701 ieee80211_rx_bss_put(local, bss);
1702
1703 if (!sdata->u.mgd.associated)
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001704 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001705
Sujithc481ec92009-01-06 09:28:37 +05301706 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg77fdaa12009-07-07 03:45:17 +02001707 (memcmp(mgmt->bssid, sdata->u.mgd.associated->cbss.bssid,
1708 ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301709 struct ieee80211_channel_sw_ie *sw_elem =
1710 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
Johannes Bergcc32abd2009-05-15 11:52:31 +02001711 ieee80211_sta_process_chanswitch(sdata, sw_elem, bss);
Sujithc481ec92009-01-06 09:28:37 +05301712 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001713}
1714
1715
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001716static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergf679f652009-12-23 13:15:34 +01001717 struct ieee80211_work *wk,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001718 struct ieee80211_mgmt *mgmt, size_t len,
Jiri Bencf0706e82007-05-05 11:45:53 -07001719 struct ieee80211_rx_status *rx_status)
1720{
Kalle Valo15b7b062009-03-22 21:57:14 +02001721 struct ieee80211_if_managed *ifmgd;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001722 size_t baselen;
1723 struct ieee802_11_elems elems;
1724
Kalle Valo15b7b062009-03-22 21:57:14 +02001725 ifmgd = &sdata->u.mgd;
1726
Johannes Berg77fdaa12009-07-07 03:45:17 +02001727 ASSERT_MGD_MTX(ifmgd);
1728
Johannes Berg47846c92009-11-25 17:46:19 +01001729 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001730 return; /* ignore ProbeResp to foreign address */
1731
Ester Kummerae6a44e2008-06-27 18:54:48 +03001732 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1733 if (baselen > len)
1734 return;
1735
1736 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1737 &elems);
1738
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001739 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001740
1741 /* direct probe may be part of the association flow */
Johannes Bergf679f652009-12-23 13:15:34 +01001742 if (wk && wk->type == IEEE80211_WORK_AUTH_PROBE) {
Johannes Berg0ff71612009-09-26 14:45:41 +02001743 printk(KERN_DEBUG "%s: direct probe responded\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001744 sdata->name);
Johannes Bergf679f652009-12-23 13:15:34 +01001745 wk->auth.tries = 0;
1746 wk->type = IEEE80211_WORK_AUTH;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001747 WARN_ON(ieee80211_authenticate(sdata, wk) != RX_MGMT_NONE);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001748 }
Kalle Valo15b7b062009-03-22 21:57:14 +02001749
Johannes Berg77fdaa12009-07-07 03:45:17 +02001750 if (ifmgd->associated &&
1751 memcmp(mgmt->bssid, ifmgd->associated->cbss.bssid, ETH_ALEN) == 0 &&
Johannes Bergb291ba12009-07-10 15:29:03 +02001752 ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1753 IEEE80211_STA_CONNECTION_POLL)) {
1754 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1755 IEEE80211_STA_BEACON_POLL);
Johannes Berg4e751842009-06-10 15:16:52 +02001756 mutex_lock(&sdata->local->iflist_mtx);
1757 ieee80211_recalc_ps(sdata->local, -1);
1758 mutex_unlock(&sdata->local->iflist_mtx);
Johannes Bergb291ba12009-07-10 15:29:03 +02001759 /*
1760 * We've received a probe response, but are not sure whether
1761 * we have or will be receiving any beacons or data, so let's
1762 * schedule the timers again, just in case.
1763 */
1764 mod_beacon_timer(sdata);
1765 mod_timer(&ifmgd->conn_mon_timer,
1766 round_jiffies_up(jiffies +
1767 IEEE80211_CONNECTION_IDLE_TIME));
Johannes Berg4e751842009-06-10 15:16:52 +02001768 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001769}
1770
Johannes Bergd91f36d2009-04-16 13:17:26 +02001771/*
1772 * This is the canonical list of information elements we care about,
1773 * the filter code also gives us all changes to the Microsoft OUI
1774 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1775 *
1776 * We implement beacon filtering in software since that means we can
1777 * avoid processing the frame here and in cfg80211, and userspace
1778 * will not be able to tell whether the hardware supports it or not.
1779 *
1780 * XXX: This list needs to be dynamic -- userspace needs to be able to
1781 * add items it requires. It also needs to be able to tell us to
1782 * look out for other vendor IEs.
1783 */
1784static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02001785 (1ULL << WLAN_EID_COUNTRY) |
1786 (1ULL << WLAN_EID_ERP_INFO) |
1787 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1788 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1789 (1ULL << WLAN_EID_HT_CAPABILITY) |
1790 (1ULL << WLAN_EID_HT_INFORMATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001791
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001792static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001793 struct ieee80211_mgmt *mgmt,
1794 size_t len,
1795 struct ieee80211_rx_status *rx_status)
1796{
Johannes Bergd91f36d2009-04-16 13:17:26 +02001797 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001798 size_t baselen;
1799 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001800 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001801 u32 changed = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001802 bool erp_valid, directed_tim = false;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001803 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001804 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001805 u8 *bssid;
1806
1807 ASSERT_MGD_MTX(ifmgd);
Jiri Bencf0706e82007-05-05 11:45:53 -07001808
Ester Kummerae6a44e2008-06-27 18:54:48 +03001809 /* Process beacon from the current BSS */
1810 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1811 if (baselen > len)
1812 return;
1813
Johannes Bergd91f36d2009-04-16 13:17:26 +02001814 if (rx_status->freq != local->hw.conf.channel->center_freq)
Jiri Bencf0706e82007-05-05 11:45:53 -07001815 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001816
Johannes Bergb291ba12009-07-10 15:29:03 +02001817 /*
1818 * We might have received a number of frames, among them a
1819 * disassoc frame and a beacon...
1820 */
1821 if (!ifmgd->associated)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001822 return;
1823
1824 bssid = ifmgd->associated->cbss.bssid;
1825
Johannes Bergb291ba12009-07-10 15:29:03 +02001826 /*
1827 * And in theory even frames from a different AP we were just
1828 * associated to a split-second ago!
1829 */
1830 if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001831 return;
1832
Johannes Bergb291ba12009-07-10 15:29:03 +02001833 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Jouni Malinen92778182009-05-14 21:15:36 +03001834#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1835 if (net_ratelimit()) {
1836 printk(KERN_DEBUG "%s: cancelling probereq poll due "
Johannes Berg47846c92009-11-25 17:46:19 +01001837 "to a received beacon\n", sdata->name);
Jouni Malinen92778182009-05-14 21:15:36 +03001838 }
1839#endif
Johannes Bergb291ba12009-07-10 15:29:03 +02001840 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Johannes Berg4e751842009-06-10 15:16:52 +02001841 mutex_lock(&local->iflist_mtx);
1842 ieee80211_recalc_ps(local, -1);
1843 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03001844 }
1845
Johannes Bergb291ba12009-07-10 15:29:03 +02001846 /*
1847 * Push the beacon loss detection into the future since
1848 * we are processing a beacon from the AP just now.
1849 */
1850 mod_beacon_timer(sdata);
1851
Johannes Bergd91f36d2009-04-16 13:17:26 +02001852 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1853 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1854 len - baselen, &elems,
1855 care_about_ies, ncrc);
1856
1857 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Johannes Berge7ec86f2009-04-18 17:33:24 +02001858 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1859 ifmgd->aid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001860
Jouni Malinen30196672009-05-19 17:01:43 +03001861 if (ncrc != ifmgd->beacon_crc) {
1862 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
1863 true);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001864
Jouni Malinen30196672009-05-19 17:01:43 +03001865 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1866 elems.wmm_param_len);
1867 }
Johannes Bergfe3fa822008-09-08 11:05:09 +02001868
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301869 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Kalle Valo1fb36062009-02-10 17:09:24 +02001870 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001871 if (local->hw.conf.dynamic_ps_timeout > 0) {
1872 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1873 ieee80211_hw_config(local,
1874 IEEE80211_CONF_CHANGE_PS);
1875 ieee80211_send_nullfunc(local, sdata, 0);
1876 } else {
1877 local->pspolling = true;
1878
1879 /*
1880 * Here is assumed that the driver will be
1881 * able to send ps-poll frame and receive a
1882 * response even though power save mode is
1883 * enabled, but some drivers might require
1884 * to disable power save here. This needs
1885 * to be investigated.
1886 */
1887 ieee80211_send_pspoll(local, sdata);
1888 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001889 }
1890 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001891
Jouni Malinen30196672009-05-19 17:01:43 +03001892 if (ncrc == ifmgd->beacon_crc)
1893 return;
1894 ifmgd->beacon_crc = ncrc;
1895
Johannes Berg7a5158e2008-10-08 10:59:33 +02001896 if (elems.erp_info && elems.erp_info_len >= 1) {
1897 erp_valid = true;
1898 erp_value = elems.erp_info[0];
1899 } else {
1900 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04001901 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001902 changed |= ieee80211_handle_bss_capability(sdata,
1903 le16_to_cpu(mgmt->u.beacon.capab_info),
1904 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07001905
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001906
Vasanthakumar Thiagarajan53d6f812009-02-11 22:18:49 +05301907 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001908 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001909 struct sta_info *sta;
1910 struct ieee80211_supported_band *sband;
1911 u16 ap_ht_cap_flags;
1912
1913 rcu_read_lock();
1914
Johannes Bergabe60632009-11-25 17:46:18 +01001915 sta = sta_info_get(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001916 if (WARN_ON(!sta)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001917 rcu_read_unlock();
1918 return;
1919 }
1920
1921 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1922
1923 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1924 elems.ht_cap_elem, &sta->sta.ht_cap);
1925
1926 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1927
1928 rcu_read_unlock();
1929
1930 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001931 bssid, ap_ht_cap_flags);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001932 }
1933
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -07001934 /* Note: country IE parsing is done for us by cfg80211 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001935 if (elems.country_elem) {
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301936 /* TODO: IBSS also needs this */
1937 if (elems.pwr_constr_elem)
1938 ieee80211_handle_pwr_constr(sdata,
1939 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1940 elems.pwr_constr_elem,
1941 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001942 }
1943
Johannes Berg471b3ef2007-12-28 14:32:58 +01001944 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001945}
1946
Johannes Berg46900292009-02-15 12:44:28 +01001947ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
Johannes Bergf1d58c22009-06-17 13:13:00 +02001948 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07001949{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001950 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001951 struct ieee80211_mgmt *mgmt;
1952 u16 fc;
1953
1954 if (skb->len < 24)
Johannes Berg46900292009-02-15 12:44:28 +01001955 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001956
1957 mgmt = (struct ieee80211_mgmt *) skb->data;
1958 fc = le16_to_cpu(mgmt->frame_control);
1959
1960 switch (fc & IEEE80211_FCTL_STYPE) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001961 case IEEE80211_STYPE_PROBE_RESP:
1962 case IEEE80211_STYPE_BEACON:
Jiri Bencf0706e82007-05-05 11:45:53 -07001963 case IEEE80211_STYPE_AUTH:
1964 case IEEE80211_STYPE_ASSOC_RESP:
1965 case IEEE80211_STYPE_REASSOC_RESP:
1966 case IEEE80211_STYPE_DEAUTH:
1967 case IEEE80211_STYPE_DISASSOC:
Johannes Berg77fdaa12009-07-07 03:45:17 +02001968 case IEEE80211_STYPE_ACTION:
Johannes Berg46900292009-02-15 12:44:28 +01001969 skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001970 ieee80211_queue_work(&local->hw, &sdata->u.mgd.work);
Johannes Berg46900292009-02-15 12:44:28 +01001971 return RX_QUEUED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001972 }
1973
Johannes Berg46900292009-02-15 12:44:28 +01001974 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001975}
1976
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001977static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001978 struct sk_buff *skb)
1979{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001980 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001981 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07001982 struct ieee80211_mgmt *mgmt;
Johannes Bergf679f652009-12-23 13:15:34 +01001983 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001984 enum rx_mgmt_action rma = RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001985 u16 fc;
1986
Jiri Bencf0706e82007-05-05 11:45:53 -07001987 rx_status = (struct ieee80211_rx_status *) skb->cb;
1988 mgmt = (struct ieee80211_mgmt *) skb->data;
1989 fc = le16_to_cpu(mgmt->frame_control);
1990
Johannes Berg77fdaa12009-07-07 03:45:17 +02001991 mutex_lock(&ifmgd->mtx);
1992
1993 if (ifmgd->associated &&
1994 memcmp(ifmgd->associated->cbss.bssid, mgmt->bssid,
1995 ETH_ALEN) == 0) {
1996 switch (fc & IEEE80211_FCTL_STYPE) {
1997 case IEEE80211_STYPE_BEACON:
1998 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1999 rx_status);
2000 break;
2001 case IEEE80211_STYPE_PROBE_RESP:
2002 ieee80211_rx_mgmt_probe_resp(sdata, NULL, mgmt,
2003 skb->len, rx_status);
2004 break;
2005 case IEEE80211_STYPE_DEAUTH:
Johannes Berg63f170e2009-12-23 13:15:33 +01002006 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002007 break;
2008 case IEEE80211_STYPE_DISASSOC:
2009 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
2010 break;
2011 case IEEE80211_STYPE_ACTION:
2012 /* XXX: differentiate, can only happen for CSA now! */
2013 ieee80211_sta_process_chanswitch(sdata,
2014 &mgmt->u.action.u.chan_switch.sw_elem,
2015 ifmgd->associated);
2016 break;
2017 }
2018 mutex_unlock(&ifmgd->mtx);
2019
2020 switch (rma) {
2021 case RX_MGMT_NONE:
2022 /* no action */
2023 break;
2024 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470612009-10-13 13:28:13 +02002025 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002026 break;
2027 case RX_MGMT_CFG80211_DISASSOC:
Holger Schurigce470612009-10-13 13:28:13 +02002028 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002029 break;
2030 default:
2031 WARN(1, "unexpected: %d", rma);
2032 }
2033 goto out;
2034 }
2035
2036 list_for_each_entry(wk, &ifmgd->work_list, list) {
Johannes Bergf679f652009-12-23 13:15:34 +01002037 const u8 *bssid = NULL;
2038
2039 switch (wk->type) {
2040 case IEEE80211_WORK_AUTH_PROBE:
2041 case IEEE80211_WORK_AUTH:
2042 bssid = wk->auth.bssid;
2043 break;
2044 case IEEE80211_WORK_ASSOC:
2045 bssid = wk->assoc.bssid;
2046 break;
2047 default:
2048 continue;
2049 }
2050 if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002051 continue;
2052
2053 switch (fc & IEEE80211_FCTL_STYPE) {
2054 case IEEE80211_STYPE_PROBE_RESP:
2055 ieee80211_rx_mgmt_probe_resp(sdata, wk, mgmt, skb->len,
2056 rx_status);
2057 break;
2058 case IEEE80211_STYPE_AUTH:
2059 rma = ieee80211_rx_mgmt_auth(sdata, wk, mgmt, skb->len);
2060 break;
2061 case IEEE80211_STYPE_ASSOC_RESP:
2062 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
2063 skb->len, false);
2064 break;
2065 case IEEE80211_STYPE_REASSOC_RESP:
2066 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
2067 skb->len, true);
2068 break;
2069 case IEEE80211_STYPE_DEAUTH:
Johannes Berg63f170e2009-12-23 13:15:33 +01002070 if (skb->len >= 24 + 2 /* mgmt + deauth reason */) {
2071 /*
2072 * We get here if we get deauth while
2073 * trying to auth/assoc. Telling cfg80211
2074 * is handled below, unconditionally.
2075 */
2076 list_del(&wk->list);
2077 kfree(wk);
2078 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002079 break;
2080 }
2081 /*
2082 * We've processed this frame for that work, so it can't
2083 * belong to another work struct.
2084 * NB: this is also required for correctness because the
2085 * called functions can free 'wk', and for 'rma'!
2086 */
Johannes Berg46900292009-02-15 12:44:28 +01002087 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07002088 }
2089
Johannes Berg77fdaa12009-07-07 03:45:17 +02002090 mutex_unlock(&ifmgd->mtx);
2091
Johannes Berg63f170e2009-12-23 13:15:33 +01002092 if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
2093 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
2094 WARN_ON(rma != RX_MGMT_NONE);
2095 rma = RX_MGMT_CFG80211_DEAUTH;
2096 }
2097
Johannes Berg77fdaa12009-07-07 03:45:17 +02002098 switch (rma) {
2099 case RX_MGMT_NONE:
2100 /* no action */
2101 break;
2102 case RX_MGMT_CFG80211_AUTH:
Johannes Bergcb0b4be2009-07-07 03:56:07 +02002103 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002104 break;
2105 case RX_MGMT_CFG80211_ASSOC:
Johannes Bergcb0b4be2009-07-07 03:56:07 +02002106 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002107 break;
Johannes Berg8d8b2612009-07-25 11:58:36 +02002108 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470612009-10-13 13:28:13 +02002109 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg8d8b2612009-07-25 11:58:36 +02002110 break;
Johannes Berg5d1ec852009-12-02 12:43:43 +01002111 case RX_MGMT_CFG80211_ASSOC_ERROR:
2112 /* an internal error -- pretend timeout for now */
2113 cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid);
2114 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002115 default:
2116 WARN(1, "unexpected: %d", rma);
2117 }
2118
2119 out:
Jiri Bencf0706e82007-05-05 11:45:53 -07002120 kfree_skb(skb);
2121}
2122
Johannes Berg9c6bd792008-09-11 00:01:52 +02002123static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07002124{
2125 struct ieee80211_sub_if_data *sdata =
2126 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01002127 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002128 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07002129
Johannes Berg5bb644a2009-05-17 11:40:42 +02002130 if (local->quiescing) {
2131 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2132 return;
2133 }
2134
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002135 ieee80211_queue_work(&local->hw, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07002136}
2137
Johannes Berg9c6bd792008-09-11 00:01:52 +02002138static void ieee80211_sta_work(struct work_struct *work)
Johannes Berg60f8b392008-09-08 17:44:22 +02002139{
2140 struct ieee80211_sub_if_data *sdata =
Johannes Berg46900292009-02-15 12:44:28 +01002141 container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
Johannes Berg60f8b392008-09-08 17:44:22 +02002142 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01002143 struct ieee80211_if_managed *ifmgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002144 struct sk_buff *skb;
Johannes Bergf679f652009-12-23 13:15:34 +01002145 struct ieee80211_work *wk, *tmp;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002146 LIST_HEAD(free_work);
2147 enum rx_mgmt_action rma;
Johannes Berg60f8b392008-09-08 17:44:22 +02002148
Johannes Berg9607e6b2009-12-23 13:15:31 +01002149 if (!ieee80211_sdata_running(sdata))
Johannes Berg60f8b392008-09-08 17:44:22 +02002150 return;
2151
Helmut Schaafbe9c422009-07-23 12:14:04 +02002152 if (local->scanning)
Johannes Berg60f8b392008-09-08 17:44:22 +02002153 return;
2154
Johannes Berg46900292009-02-15 12:44:28 +01002155 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg60f8b392008-09-08 17:44:22 +02002156 return;
Johannes Berg5bb644a2009-05-17 11:40:42 +02002157
2158 /*
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002159 * ieee80211_queue_work() should have picked up most cases,
2160 * here we'll pick the the rest.
Johannes Berg5bb644a2009-05-17 11:40:42 +02002161 */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002162 if (WARN(local->suspended, "STA MLME work scheduled while "
2163 "going to suspend\n"))
Johannes Berg5bb644a2009-05-17 11:40:42 +02002164 return;
2165
Johannes Berg46900292009-02-15 12:44:28 +01002166 ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002167
Johannes Berg77fdaa12009-07-07 03:45:17 +02002168 /* first process frames to avoid timing out while a frame is pending */
Johannes Berg46900292009-02-15 12:44:28 +01002169 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
Johannes Berg60f8b392008-09-08 17:44:22 +02002170 ieee80211_sta_rx_queued_mgmt(sdata, skb);
2171
Johannes Berg77fdaa12009-07-07 03:45:17 +02002172 /* then process the rest of the work */
2173 mutex_lock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002174
Johannes Bergb291ba12009-07-10 15:29:03 +02002175 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
2176 IEEE80211_STA_CONNECTION_POLL) &&
2177 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03002178 u8 bssid[ETH_ALEN];
2179
2180 memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN);
Johannes Bergb291ba12009-07-10 15:29:03 +02002181 if (time_is_after_jiffies(ifmgd->probe_timeout))
2182 run_again(ifmgd, ifmgd->probe_timeout);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002183
2184 else if (ifmgd->probe_send_count < IEEE80211_MAX_PROBE_TRIES) {
2185#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2186 printk(KERN_DEBUG "No probe response from AP %pM"
2187 " after %dms, try %d\n", bssid,
2188 (1000 * IEEE80211_PROBE_WAIT)/HZ,
2189 ifmgd->probe_send_count);
2190#endif
2191 ieee80211_mgd_probe_ap_send(sdata);
2192 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02002193 /*
2194 * We actually lost the connection ... or did we?
2195 * Let's make sure!
2196 */
2197 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
2198 IEEE80211_STA_BEACON_POLL);
Johannes Bergb291ba12009-07-10 15:29:03 +02002199 printk(KERN_DEBUG "No probe response from AP %pM"
2200 " after %dms, disconnecting.\n",
2201 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
Johannes Berg63f170e2009-12-23 13:15:33 +01002202 ieee80211_set_disassoc(sdata);
Johannes Bergbc83b682009-11-29 12:19:06 +01002203 ieee80211_recalc_idle(local);
Johannes Bergb291ba12009-07-10 15:29:03 +02002204 mutex_unlock(&ifmgd->mtx);
2205 /*
2206 * must be outside lock due to cfg80211,
2207 * but that's not a problem.
2208 */
2209 ieee80211_send_deauth_disassoc(sdata, bssid,
2210 IEEE80211_STYPE_DEAUTH,
2211 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2212 NULL);
2213 mutex_lock(&ifmgd->mtx);
2214 }
2215 }
2216
Johannes Berg60f8b392008-09-08 17:44:22 +02002217
Johannes Berg5cff20e2009-04-29 12:26:17 +02002218 ieee80211_recalc_idle(local);
2219
Johannes Berg77fdaa12009-07-07 03:45:17 +02002220 list_for_each_entry_safe(wk, tmp, &ifmgd->work_list, list) {
Johannes Bergca386f32009-07-10 02:39:48 +02002221 if (time_is_after_jiffies(wk->timeout)) {
2222 /*
2223 * This work item isn't supposed to be worked on
2224 * right now, but take care to adjust the timer
2225 * properly.
2226 */
2227 run_again(ifmgd, wk->timeout);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002228 continue;
Johannes Bergca386f32009-07-10 02:39:48 +02002229 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002230
Johannes Bergf679f652009-12-23 13:15:34 +01002231 switch (wk->type) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002232 default:
2233 WARN_ON(1);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002234 /* nothing */
2235 rma = RX_MGMT_NONE;
2236 break;
Johannes Bergf679f652009-12-23 13:15:34 +01002237 case IEEE80211_WORK_AUTH_PROBE:
Johannes Berg77fdaa12009-07-07 03:45:17 +02002238 rma = ieee80211_direct_probe(sdata, wk);
2239 break;
Johannes Bergf679f652009-12-23 13:15:34 +01002240 case IEEE80211_WORK_AUTH:
Johannes Berg77fdaa12009-07-07 03:45:17 +02002241 rma = ieee80211_authenticate(sdata, wk);
2242 break;
Johannes Bergf679f652009-12-23 13:15:34 +01002243 case IEEE80211_WORK_ASSOC:
Johannes Berg77fdaa12009-07-07 03:45:17 +02002244 rma = ieee80211_associate(sdata, wk);
2245 break;
2246 }
2247
2248 switch (rma) {
2249 case RX_MGMT_NONE:
2250 /* no action required */
2251 break;
2252 case RX_MGMT_CFG80211_AUTH_TO:
2253 case RX_MGMT_CFG80211_ASSOC_TO:
2254 list_del(&wk->list);
2255 list_add(&wk->list, &free_work);
Johannes Berg63f170e2009-12-23 13:15:33 +01002256 /*
2257 * small abuse but only local -- keep the
2258 * action type in wk->timeout while the item
2259 * is on the cleanup list
2260 */
2261 wk->timeout = rma;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002262 break;
2263 default:
2264 WARN(1, "unexpected: %d", rma);
2265 }
2266 }
2267
Johannes Berg63f170e2009-12-23 13:15:33 +01002268 if (list_empty(&ifmgd->work_list) &&
Jouni Malinen5bf6fcc2009-08-25 17:44:28 +03002269 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request))
2270 ieee80211_queue_delayed_work(&local->hw,
2271 &local->scan_work,
2272 round_jiffies_relative(0));
2273
Johannes Berg77fdaa12009-07-07 03:45:17 +02002274 mutex_unlock(&ifmgd->mtx);
2275
2276 list_for_each_entry_safe(wk, tmp, &free_work, list) {
Johannes Berg63f170e2009-12-23 13:15:33 +01002277 /* see above how we're using wk->timeout */
2278 switch (wk->timeout) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002279 case RX_MGMT_CFG80211_AUTH_TO:
Johannes Bergf679f652009-12-23 13:15:34 +01002280 cfg80211_send_auth_timeout(sdata->dev, wk->auth.bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002281 break;
2282 case RX_MGMT_CFG80211_ASSOC_TO:
Johannes Bergcb0b4be2009-07-07 03:56:07 +02002283 cfg80211_send_assoc_timeout(sdata->dev,
Johannes Bergf679f652009-12-23 13:15:34 +01002284 wk->assoc.bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002285 break;
2286 default:
Johannes Berg63f170e2009-12-23 13:15:33 +01002287 WARN(1, "unexpected: %lu", wk->timeout);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002288 }
2289
2290 list_del(&wk->list);
2291 kfree(wk);
2292 }
2293
2294 ieee80211_recalc_idle(local);
Johannes Berg60f8b392008-09-08 17:44:22 +02002295}
Johannes Berg0a51b272008-09-08 17:44:25 +02002296
Johannes Bergb291ba12009-07-10 15:29:03 +02002297static void ieee80211_sta_bcn_mon_timer(unsigned long data)
2298{
2299 struct ieee80211_sub_if_data *sdata =
2300 (struct ieee80211_sub_if_data *) data;
2301 struct ieee80211_local *local = sdata->local;
2302
2303 if (local->quiescing)
2304 return;
2305
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002306 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.beacon_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002307}
2308
2309static void ieee80211_sta_conn_mon_timer(unsigned long data)
2310{
2311 struct ieee80211_sub_if_data *sdata =
2312 (struct ieee80211_sub_if_data *) data;
2313 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2314 struct ieee80211_local *local = sdata->local;
2315
2316 if (local->quiescing)
2317 return;
2318
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002319 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002320}
2321
2322static void ieee80211_sta_monitor_work(struct work_struct *work)
2323{
2324 struct ieee80211_sub_if_data *sdata =
2325 container_of(work, struct ieee80211_sub_if_data,
2326 u.mgd.monitor_work);
2327
2328 ieee80211_mgd_probe_ap(sdata, false);
2329}
2330
Johannes Berga1678f82008-09-11 00:01:47 +02002331static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2332{
Kalle Vaload935682009-04-19 08:47:19 +03002333 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Bergb291ba12009-07-10 15:29:03 +02002334 sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
2335 IEEE80211_STA_CONNECTION_POLL);
Kalle Vaload935682009-04-19 08:47:19 +03002336
Johannes Bergb291ba12009-07-10 15:29:03 +02002337 /* let's probe the connection once */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002338 ieee80211_queue_work(&sdata->local->hw,
Johannes Bergb291ba12009-07-10 15:29:03 +02002339 &sdata->u.mgd.monitor_work);
2340 /* and do all the other regular work too */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002341 ieee80211_queue_work(&sdata->local->hw,
Johannes Berg46900292009-02-15 12:44:28 +01002342 &sdata->u.mgd.work);
Kalle Vaload935682009-04-19 08:47:19 +03002343 }
Johannes Berga1678f82008-09-11 00:01:47 +02002344}
2345
Johannes Berg5bb644a2009-05-17 11:40:42 +02002346#ifdef CONFIG_PM
2347void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
2348{
2349 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2350
2351 /*
2352 * we need to use atomic bitops for the running bits
2353 * only because both timers might fire at the same
2354 * time -- the code here is properly synchronised.
2355 */
2356
2357 cancel_work_sync(&ifmgd->work);
2358 cancel_work_sync(&ifmgd->beacon_loss_work);
2359 if (del_timer_sync(&ifmgd->timer))
2360 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2361
2362 cancel_work_sync(&ifmgd->chswitch_work);
2363 if (del_timer_sync(&ifmgd->chswitch_timer))
2364 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
Johannes Bergb291ba12009-07-10 15:29:03 +02002365
2366 cancel_work_sync(&ifmgd->monitor_work);
2367 /* these will just be re-established on connection */
2368 del_timer_sync(&ifmgd->conn_mon_timer);
2369 del_timer_sync(&ifmgd->bcn_mon_timer);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002370}
2371
2372void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
2373{
2374 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2375
2376 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
2377 add_timer(&ifmgd->timer);
2378 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
2379 add_timer(&ifmgd->chswitch_timer);
2380}
2381#endif
2382
Johannes Berg9c6bd792008-09-11 00:01:52 +02002383/* interface setup */
2384void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2385{
Johannes Berg46900292009-02-15 12:44:28 +01002386 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002387
Johannes Berg46900292009-02-15 12:44:28 +01002388 ifmgd = &sdata->u.mgd;
2389 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002390 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01002391 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002392 INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
Johannes Berg46900292009-02-15 12:44:28 +01002393 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002394 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002395 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
2396 (unsigned long) sdata);
2397 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
2398 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002399 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05302400 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002401 skb_queue_head_init(&ifmgd->skb_queue);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002402
Johannes Berg77fdaa12009-07-07 03:45:17 +02002403 INIT_LIST_HEAD(&ifmgd->work_list);
2404
Johannes Berg46900292009-02-15 12:44:28 +01002405 ifmgd->capab = WLAN_CAPABILITY_ESS;
Johannes Bergab1faea2009-07-01 21:41:17 +02002406 ifmgd->flags = 0;
Johannes Berg176be722009-03-12 23:49:28 +01002407 if (sdata->local->hw.queues >= 4)
Johannes Berg46900292009-02-15 12:44:28 +01002408 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
Johannes Bergbbbdff92009-04-16 13:27:42 +02002409
Johannes Berg77fdaa12009-07-07 03:45:17 +02002410 mutex_init(&ifmgd->mtx);
Johannes Berg0f782312009-12-01 13:37:02 +01002411
2412 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
2413 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
2414 else
2415 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002416}
2417
2418/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002419void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2420{
2421 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002422
2423 /* Restart STA timers */
2424 rcu_read_lock();
2425 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2426 ieee80211_restart_sta_timer(sdata);
2427 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02002428}
Johannes Berg10f644a2009-04-16 13:17:25 +02002429
2430int ieee80211_max_network_latency(struct notifier_block *nb,
2431 unsigned long data, void *dummy)
2432{
2433 s32 latency_usec = (s32) data;
2434 struct ieee80211_local *local =
2435 container_of(nb, struct ieee80211_local,
2436 network_latency_notifier);
2437
2438 mutex_lock(&local->iflist_mtx);
2439 ieee80211_recalc_ps(local, latency_usec);
2440 mutex_unlock(&local->iflist_mtx);
2441
2442 return 0;
2443}
Johannes Berg77fdaa12009-07-07 03:45:17 +02002444
2445/* config hooks */
2446int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2447 struct cfg80211_auth_request *req)
2448{
2449 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2450 const u8 *ssid;
Johannes Bergf679f652009-12-23 13:15:34 +01002451 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002452 u16 auth_alg;
2453
2454 switch (req->auth_type) {
2455 case NL80211_AUTHTYPE_OPEN_SYSTEM:
2456 auth_alg = WLAN_AUTH_OPEN;
2457 break;
2458 case NL80211_AUTHTYPE_SHARED_KEY:
2459 auth_alg = WLAN_AUTH_SHARED_KEY;
2460 break;
2461 case NL80211_AUTHTYPE_FT:
2462 auth_alg = WLAN_AUTH_FT;
2463 break;
2464 case NL80211_AUTHTYPE_NETWORK_EAP:
2465 auth_alg = WLAN_AUTH_LEAP;
2466 break;
2467 default:
2468 return -EOPNOTSUPP;
2469 }
2470
2471 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
2472 if (!wk)
2473 return -ENOMEM;
2474
Johannes Bergf679f652009-12-23 13:15:34 +01002475 memcpy(wk->auth.bssid, req->bss->bssid, ETH_ALEN);;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002476
2477 if (req->ie && req->ie_len) {
2478 memcpy(wk->ie, req->ie, req->ie_len);
2479 wk->ie_len = req->ie_len;
2480 }
2481
Johannes Bergfffd0932009-07-08 14:22:54 +02002482 if (req->key && req->key_len) {
Johannes Bergf679f652009-12-23 13:15:34 +01002483 wk->auth.key_len = req->key_len;
2484 wk->auth.key_idx = req->key_idx;
2485 memcpy(wk->auth.key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02002486 }
2487
Johannes Berg77fdaa12009-07-07 03:45:17 +02002488 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergf679f652009-12-23 13:15:34 +01002489 memcpy(wk->auth.ssid, ssid + 2, ssid[1]);
2490 wk->auth.ssid_len = ssid[1];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002491
Johannes Bergf679f652009-12-23 13:15:34 +01002492 wk->auth.algorithm = auth_alg;
2493 wk->auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
2494
2495 wk->type = IEEE80211_WORK_AUTH_PROBE;
Johannes Berg48531842009-07-23 16:50:16 +02002496 wk->timeout = jiffies; /* run right away */
Johannes Bergf679f652009-12-23 13:15:34 +01002497 wk->chan = req->bss->channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002498
2499 /*
2500 * XXX: if still associated need to tell AP that we're going
2501 * to sleep and then change channel etc.
Johannes Bergf679f652009-12-23 13:15:34 +01002502 * For now switch channel here, later will be handled
2503 * by submitting this as an off-channel work item.
Johannes Berg77fdaa12009-07-07 03:45:17 +02002504 */
2505 sdata->local->oper_channel = req->bss->channel;
2506 ieee80211_hw_config(sdata->local, 0);
2507
2508 mutex_lock(&ifmgd->mtx);
2509 list_add(&wk->list, &sdata->u.mgd.work_list);
2510 mutex_unlock(&ifmgd->mtx);
2511
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002512 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002513 return 0;
2514}
2515
2516int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2517 struct cfg80211_assoc_request *req)
2518{
2519 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergf679f652009-12-23 13:15:34 +01002520 struct ieee80211_work *wk;
Johannes Berg63f170e2009-12-23 13:15:33 +01002521 const u8 *ssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002522 int i, err;
2523
2524 mutex_lock(&ifmgd->mtx);
2525
Johannes Berg63f170e2009-12-23 13:15:33 +01002526 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002527 if (!wk) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002528 err = -ENOMEM;
2529 goto out;
2530 }
2531
Johannes Berg77fdaa12009-07-07 03:45:17 +02002532 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
2533
2534 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2535 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
2536 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
2537 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2538 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2539
Johannes Berg77fdaa12009-07-07 03:45:17 +02002540
2541 if (req->ie && req->ie_len) {
2542 memcpy(wk->ie, req->ie, req->ie_len);
2543 wk->ie_len = req->ie_len;
2544 } else
2545 wk->ie_len = 0;
2546
Johannes Bergf679f652009-12-23 13:15:34 +01002547 wk->assoc.bss = (void *)req->bss;
2548
2549 memcpy(wk->assoc.bssid, req->bss->bssid, ETH_ALEN);
2550
2551 wk->assoc.capability = req->bss->capability;
2552 wk->assoc.wmm_used = wk->assoc.bss->wmm_used;
2553 wk->assoc.supp_rates = wk->assoc.bss->supp_rates;
2554 wk->assoc.supp_rates_len = wk->assoc.bss->supp_rates_len;
2555 wk->assoc.ht_information_ie =
2556 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
Johannes Berg63f170e2009-12-23 13:15:33 +01002557
2558 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergf679f652009-12-23 13:15:34 +01002559 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
2560 wk->assoc.ssid_len = ssid[1];
Johannes Berg63f170e2009-12-23 13:15:33 +01002561
Johannes Berg77fdaa12009-07-07 03:45:17 +02002562 if (req->prev_bssid)
Johannes Bergf679f652009-12-23 13:15:34 +01002563 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002564
Johannes Bergf679f652009-12-23 13:15:34 +01002565 wk->type = IEEE80211_WORK_ASSOC;
Johannes Berg48531842009-07-23 16:50:16 +02002566 wk->timeout = jiffies; /* run right away */
Johannes Bergf679f652009-12-23 13:15:34 +01002567 wk->chan = req->bss->channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002568
2569 if (req->use_mfp) {
2570 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
2571 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
2572 } else {
2573 ifmgd->mfp = IEEE80211_MFP_DISABLED;
2574 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
2575 }
2576
2577 if (req->crypto.control_port)
2578 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
2579 else
2580 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2581
Johannes Berg63f170e2009-12-23 13:15:33 +01002582 sdata->local->oper_channel = req->bss->channel;
2583 ieee80211_hw_config(sdata->local, 0);
2584
2585 list_add(&wk->list, &ifmgd->work_list);
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002586 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002587
2588 err = 0;
2589
2590 out:
2591 mutex_unlock(&ifmgd->mtx);
2592 return err;
2593}
2594
2595int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503dd2009-07-07 03:56:11 +02002596 struct cfg80211_deauth_request *req,
2597 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002598{
2599 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergf679f652009-12-23 13:15:34 +01002600 struct ieee80211_work *wk;
Johannes Berg63f170e2009-12-23 13:15:33 +01002601 const u8 *bssid = req->bss->bssid;
Johannes Berga58ce432009-11-19 12:45:42 +01002602 bool not_auth_yet = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002603
Johannes Berg77fdaa12009-07-07 03:45:17 +02002604 mutex_lock(&ifmgd->mtx);
2605
2606 if (ifmgd->associated && &ifmgd->associated->cbss == req->bss) {
2607 bssid = req->bss->bssid;
Johannes Berg63f170e2009-12-23 13:15:33 +01002608 ieee80211_set_disassoc(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002609 } else list_for_each_entry(wk, &ifmgd->work_list, list) {
Johannes Bergf679f652009-12-23 13:15:34 +01002610 if (wk->type != IEEE80211_WORK_AUTH_PROBE)
Johannes Berg63f170e2009-12-23 13:15:33 +01002611 continue;
Johannes Bergf679f652009-12-23 13:15:34 +01002612 if (memcmp(req->bss->bssid, wk->auth.bssid, ETH_ALEN))
Johannes Berg63f170e2009-12-23 13:15:33 +01002613 continue;
2614 not_auth_yet = true;
2615 list_del(&wk->list);
2616 kfree(wk);
2617 break;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002618 }
2619
Johannes Berg8d8b2612009-07-25 11:58:36 +02002620 /*
Johannes Berga58ce432009-11-19 12:45:42 +01002621 * If somebody requests authentication and we haven't
2622 * sent out an auth frame yet there's no need to send
2623 * out a deauth frame either. If the state was PROBE,
2624 * then this is the case. If it's AUTH we have sent a
2625 * frame, and if it's IDLE we have completed the auth
2626 * process already.
2627 */
2628 if (not_auth_yet) {
2629 mutex_unlock(&ifmgd->mtx);
2630 __cfg80211_auth_canceled(sdata->dev, bssid);
2631 return 0;
2632 }
2633
Johannes Berg77fdaa12009-07-07 03:45:17 +02002634 mutex_unlock(&ifmgd->mtx);
2635
Johannes Berg0ff71612009-09-26 14:45:41 +02002636 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002637 sdata->name, bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002638
Johannes Berg77fdaa12009-07-07 03:45:17 +02002639 ieee80211_send_deauth_disassoc(sdata, bssid,
Johannes Berg667503dd2009-07-07 03:56:11 +02002640 IEEE80211_STYPE_DEAUTH, req->reason_code,
2641 cookie);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002642
Johannes Bergbc83b682009-11-29 12:19:06 +01002643 ieee80211_recalc_idle(sdata->local);
2644
Johannes Berg77fdaa12009-07-07 03:45:17 +02002645 return 0;
2646}
2647
2648int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503dd2009-07-07 03:56:11 +02002649 struct cfg80211_disassoc_request *req,
2650 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002651{
2652 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2653
Johannes Berg77fdaa12009-07-07 03:45:17 +02002654 mutex_lock(&ifmgd->mtx);
2655
Johannes Berg8d8b2612009-07-25 11:58:36 +02002656 /*
2657 * cfg80211 should catch this ... but it's racy since
2658 * we can receive a disassoc frame, process it, hand it
2659 * to cfg80211 while that's in a locked section already
2660 * trying to tell us that the user wants to disconnect.
2661 */
2662 if (&ifmgd->associated->cbss != req->bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002663 mutex_unlock(&ifmgd->mtx);
2664 return -ENOLINK;
2665 }
2666
Johannes Berg0ff71612009-09-26 14:45:41 +02002667 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002668 sdata->name, req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002669
Johannes Berg63f170e2009-12-23 13:15:33 +01002670 ieee80211_set_disassoc(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002671
2672 mutex_unlock(&ifmgd->mtx);
2673
2674 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
Johannes Berg667503dd2009-07-07 03:56:11 +02002675 IEEE80211_STYPE_DISASSOC, req->reason_code,
2676 cookie);
Johannes Bergbc83b682009-11-29 12:19:06 +01002677
2678 ieee80211_recalc_idle(sdata->local);
2679
Johannes Berg77fdaa12009-07-07 03:45:17 +02002680 return 0;
2681}