blob: a1944b8722e93a436f2013f808e1a0efae1a1ff0 [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
Ron Rindjunsky6042a3e2008-08-08 01:50:46 +030030#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
Jiri Bencf0706e82007-05-05 11:45:53 -070031#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
32#define IEEE80211_AUTH_MAX_TRIES 3
33#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
34#define IEEE80211_ASSOC_MAX_TRIES 3
35#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
Johannes Berge0502de2009-05-12 20:11:26 +020036#define IEEE80211_PROBE_WAIT (HZ / 20)
Kalle Valo15b7b062009-03-22 21:57:14 +020037#define IEEE80211_PROBE_IDLE_TIME (60 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070038#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070039
Johannes Berg5484e232008-09-08 17:44:27 +020040/* utils */
41static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +020042{
Johannes Berg5484e232008-09-08 17:44:27 +020043 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +020044}
45
Johannes Bergc2b13452008-09-11 00:01:55 +020046static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030047{
48 u8 *end, *pos;
49
Johannes Berg00d3f142009-02-10 21:26:00 +010050 pos = bss->cbss.information_elements;
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030051 if (pos == NULL)
52 return NULL;
Johannes Berg00d3f142009-02-10 21:26:00 +010053 end = pos + bss->cbss.len_information_elements;
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030054
55 while (pos + 1 < end) {
56 if (pos + 2 + pos[1] > end)
57 break;
58 if (pos[0] == ie)
59 return pos;
60 pos += 2 + pos[1];
61 }
62
63 return NULL;
64}
65
Johannes Bergc2b13452008-09-11 00:01:55 +020066static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
Johannes Berg9ac19a92008-09-09 10:57:09 +020067 struct ieee80211_supported_band *sband,
Johannes Berg881d9482009-01-21 15:13:48 +010068 u32 *rates)
Johannes Berg9ac19a92008-09-09 10:57:09 +020069{
70 int i, j, count;
71 *rates = 0;
72 count = 0;
73 for (i = 0; i < bss->supp_rates_len; i++) {
74 int rate = (bss->supp_rates[i] & 0x7F) * 5;
75
76 for (j = 0; j < sband->n_bitrates; j++)
77 if (sband->bitrates[j].bitrate == rate) {
78 *rates |= BIT(j);
79 count++;
80 break;
81 }
82 }
83
84 return count;
85}
86
Johannes Bergd5522e02009-03-30 13:23:35 +020087/*
88 * ieee80211_enable_ht should be called only after the operating band
89 * has been determined as ht configuration depends on the hw's
90 * HT abilities for a specific band.
91 */
92static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
93 struct ieee80211_ht_info *hti,
94 u16 ap_ht_cap_flags)
95{
96 struct ieee80211_local *local = sdata->local;
97 struct ieee80211_supported_band *sband;
98 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergd5522e02009-03-30 13:23:35 +020099 struct sta_info *sta;
100 u32 changed = 0;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200101 u16 ht_opmode;
Johannes Bergd5522e02009-03-30 13:23:35 +0200102 bool enable_ht = true, ht_changed;
103 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
104
105 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
106
Johannes Bergd5522e02009-03-30 13:23:35 +0200107 /* HT is not supported */
108 if (!sband->ht_cap.ht_supported)
109 enable_ht = false;
110
111 /* check that channel matches the right operating channel */
112 if (local->hw.conf.channel->center_freq !=
113 ieee80211_channel_to_frequency(hti->control_chan))
114 enable_ht = false;
115
116 if (enable_ht) {
117 channel_type = NL80211_CHAN_HT20;
118
119 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
120 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
121 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
122 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
123 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400124 if (!(local->hw.conf.channel->flags &
125 IEEE80211_CHAN_NO_HT40PLUS))
126 channel_type = NL80211_CHAN_HT40PLUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200127 break;
128 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400129 if (!(local->hw.conf.channel->flags &
130 IEEE80211_CHAN_NO_HT40MINUS))
131 channel_type = NL80211_CHAN_HT40MINUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200132 break;
133 }
134 }
135 }
136
137 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
138 channel_type != local->hw.conf.channel_type;
139
140 local->oper_channel_type = channel_type;
141
142 if (ht_changed) {
143 /* channel_type change automatically detected */
144 ieee80211_hw_config(local, 0);
145
146 rcu_read_lock();
147
148 sta = sta_info_get(local, ifmgd->bssid);
149 if (sta)
150 rate_control_rate_update(local, sband, sta,
151 IEEE80211_RC_HT_CHANGED);
152
153 rcu_read_unlock();
Johannes Bergd5522e02009-03-30 13:23:35 +0200154 }
155
156 /* disable HT */
157 if (!enable_ht)
158 return 0;
159
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200160 ht_opmode = le16_to_cpu(hti->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200161
162 /* if bss configuration changed store the new one */
Johannes Berg413ad502009-05-08 21:21:06 +0200163 if (!sdata->ht_opmode_valid ||
164 sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200165 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200166 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Berg413ad502009-05-08 21:21:06 +0200167 sdata->ht_opmode_valid = true;
Johannes Bergd5522e02009-03-30 13:23:35 +0200168 }
169
170 return changed;
171}
172
Johannes Berg9c6bd792008-09-11 00:01:52 +0200173/* frame sending functions */
174
Johannes Berg46900292009-02-15 12:44:28 +0100175static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +0200176{
Johannes Berg46900292009-02-15 12:44:28 +0100177 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200178 struct ieee80211_local *local = sdata->local;
179 struct sk_buff *skb;
180 struct ieee80211_mgmt *mgmt;
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200181 u8 *pos, *ies, *ht_ie;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200182 int i, len, count, rates_len, supp_rates_len;
183 u16 capab;
Johannes Bergc2b13452008-09-11 00:01:55 +0200184 struct ieee80211_bss *bss;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200185 int wmm = 0;
186 struct ieee80211_supported_band *sband;
Johannes Berg881d9482009-01-21 15:13:48 +0100187 u32 rates = 0;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200188
189 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
Johannes Berg46900292009-02-15 12:44:28 +0100190 sizeof(*mgmt) + 200 + ifmgd->extra_ie_len +
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200191 ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200192 if (!skb) {
193 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
194 "frame\n", sdata->dev->name);
195 return;
196 }
197 skb_reserve(skb, local->hw.extra_tx_headroom);
198
199 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
200
Johannes Berg46900292009-02-15 12:44:28 +0100201 capab = ifmgd->capab;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200202
203 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
204 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
205 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
206 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
207 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
208 }
209
Johannes Berg46900292009-02-15 12:44:28 +0100210 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Johannes Berg9ac19a92008-09-09 10:57:09 +0200211 local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100212 ifmgd->ssid, ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200213 if (bss) {
Johannes Berg00d3f142009-02-10 21:26:00 +0100214 if (bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200215 capab |= WLAN_CAPABILITY_PRIVACY;
216 if (bss->wmm_used)
217 wmm = 1;
218
219 /* get all rates supported by the device and the AP as
220 * some APs don't like getting a superset of their rates
221 * in the association request (e.g. D-Link DAP 1353 in
222 * b-only mode) */
223 rates_len = ieee80211_compatible_rates(bss, sband, &rates);
224
Johannes Berg00d3f142009-02-10 21:26:00 +0100225 if ((bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg9ac19a92008-09-09 10:57:09 +0200226 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
227 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
228
229 ieee80211_rx_bss_put(local, bss);
230 } else {
231 rates = ~0;
232 rates_len = sband->n_bitrates;
233 }
234
235 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
236 memset(mgmt, 0, 24);
Johannes Berg46900292009-02-15 12:44:28 +0100237 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200238 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100239 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200240
Johannes Berg46900292009-02-15 12:44:28 +0100241 if (ifmgd->flags & IEEE80211_STA_PREV_BSSID_SET) {
Johannes Berg9ac19a92008-09-09 10:57:09 +0200242 skb_put(skb, 10);
243 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
244 IEEE80211_STYPE_REASSOC_REQ);
245 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
246 mgmt->u.reassoc_req.listen_interval =
247 cpu_to_le16(local->hw.conf.listen_interval);
Johannes Berg46900292009-02-15 12:44:28 +0100248 memcpy(mgmt->u.reassoc_req.current_ap, ifmgd->prev_bssid,
Johannes Berg9ac19a92008-09-09 10:57:09 +0200249 ETH_ALEN);
250 } else {
251 skb_put(skb, 4);
252 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
253 IEEE80211_STYPE_ASSOC_REQ);
254 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
Rami Rosen13554122008-12-16 22:38:29 +0200255 mgmt->u.assoc_req.listen_interval =
Johannes Berg9ac19a92008-09-09 10:57:09 +0200256 cpu_to_le16(local->hw.conf.listen_interval);
257 }
258
259 /* SSID */
Johannes Berg46900292009-02-15 12:44:28 +0100260 ies = pos = skb_put(skb, 2 + ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200261 *pos++ = WLAN_EID_SSID;
Johannes Berg46900292009-02-15 12:44:28 +0100262 *pos++ = ifmgd->ssid_len;
263 memcpy(pos, ifmgd->ssid, ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200264
265 /* add all rates which were marked to be used above */
266 supp_rates_len = rates_len;
267 if (supp_rates_len > 8)
268 supp_rates_len = 8;
269
270 len = sband->n_bitrates;
271 pos = skb_put(skb, supp_rates_len + 2);
272 *pos++ = WLAN_EID_SUPP_RATES;
273 *pos++ = supp_rates_len;
274
275 count = 0;
276 for (i = 0; i < sband->n_bitrates; i++) {
277 if (BIT(i) & rates) {
278 int rate = sband->bitrates[i].bitrate;
279 *pos++ = (u8) (rate / 5);
280 if (++count == 8)
281 break;
282 }
283 }
284
285 if (rates_len > count) {
286 pos = skb_put(skb, rates_len - count + 2);
287 *pos++ = WLAN_EID_EXT_SUPP_RATES;
288 *pos++ = rates_len - count;
289
290 for (i++; i < sband->n_bitrates; i++) {
291 if (BIT(i) & rates) {
292 int rate = sband->bitrates[i].bitrate;
293 *pos++ = (u8) (rate / 5);
294 }
295 }
296 }
297
298 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
299 /* 1. power capabilities */
300 pos = skb_put(skb, 4);
301 *pos++ = WLAN_EID_PWR_CAPABILITY;
302 *pos++ = 2;
303 *pos++ = 0; /* min tx power */
304 *pos++ = local->hw.conf.channel->max_power; /* max tx power */
305
306 /* 2. supported channels */
307 /* TODO: get this in reg domain format */
308 pos = skb_put(skb, 2 * sband->n_channels + 2);
309 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
310 *pos++ = 2 * sband->n_channels;
311 for (i = 0; i < sband->n_channels; i++) {
312 *pos++ = ieee80211_frequency_to_channel(
313 sband->channels[i].center_freq);
314 *pos++ = 1; /* one channel in the subband*/
315 }
316 }
317
Johannes Berg46900292009-02-15 12:44:28 +0100318 if (ifmgd->extra_ie) {
319 pos = skb_put(skb, ifmgd->extra_ie_len);
320 memcpy(pos, ifmgd->extra_ie, ifmgd->extra_ie_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200321 }
322
Johannes Berg46900292009-02-15 12:44:28 +0100323 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
Johannes Berg9ac19a92008-09-09 10:57:09 +0200324 pos = skb_put(skb, 9);
325 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
326 *pos++ = 7; /* len */
327 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
328 *pos++ = 0x50;
329 *pos++ = 0xf2;
330 *pos++ = 2; /* WME */
331 *pos++ = 0; /* WME info */
332 *pos++ = 1; /* WME ver */
333 *pos++ = 0;
334 }
335
336 /* wmm support is a must to HT */
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530337 /*
338 * IEEE802.11n does not allow TKIP/WEP as pairwise
339 * ciphers in HT mode. We still associate in non-ht
340 * mode (11a/b/g) if any one of these ciphers is
341 * configured as pairwise.
342 */
Johannes Berg46900292009-02-15 12:44:28 +0100343 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200344 sband->ht_cap.ht_supported &&
345 (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) &&
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530346 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
Johannes Berg46900292009-02-15 12:44:28 +0100347 (!(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200348 struct ieee80211_ht_info *ht_info =
349 (struct ieee80211_ht_info *)(ht_ie + 2);
350 u16 cap = sband->ht_cap.cap;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200351 __le16 tmp;
352 u32 flags = local->hw.conf.channel->flags;
353
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200354 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
355 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Luis R. Rodriguez689da1b2009-05-02 00:37:18 -0400356 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200357 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200358 cap &= ~IEEE80211_HT_CAP_SGI_40;
359 }
360 break;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200361 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Luis R. Rodriguez689da1b2009-05-02 00:37:18 -0400362 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200363 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200364 cap &= ~IEEE80211_HT_CAP_SGI_40;
365 }
366 break;
367 }
368
369 tmp = cpu_to_le16(cap);
370 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
371 *pos++ = WLAN_EID_HT_CAPABILITY;
372 *pos++ = sizeof(struct ieee80211_ht_cap);
373 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
374 memcpy(pos, &tmp, sizeof(u16));
375 pos += sizeof(u16);
376 /* TODO: needs a define here for << 2 */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200377 *pos++ = sband->ht_cap.ampdu_factor |
378 (sband->ht_cap.ampdu_density << 2);
379 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200380 }
381
Johannes Berg46900292009-02-15 12:44:28 +0100382 kfree(ifmgd->assocreq_ies);
383 ifmgd->assocreq_ies_len = (skb->data + skb->len) - ies;
384 ifmgd->assocreq_ies = kmalloc(ifmgd->assocreq_ies_len, GFP_KERNEL);
385 if (ifmgd->assocreq_ies)
386 memcpy(ifmgd->assocreq_ies, ies, ifmgd->assocreq_ies_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200387
Johannes Berge50db652008-09-09 15:07:09 +0200388 ieee80211_tx_skb(sdata, skb, 0);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200389}
390
391
Johannes Bergef422bc2008-09-09 10:58:25 +0200392static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
393 u16 stype, u16 reason)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200394{
395 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100396 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200397 struct sk_buff *skb;
398 struct ieee80211_mgmt *mgmt;
399
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200400 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200401 if (!skb) {
Johannes Bergef422bc2008-09-09 10:58:25 +0200402 printk(KERN_DEBUG "%s: failed to allocate buffer for "
403 "deauth/disassoc frame\n", sdata->dev->name);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200404 return;
405 }
406 skb_reserve(skb, local->hw.extra_tx_headroom);
407
408 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
409 memset(mgmt, 0, 24);
Johannes Berg46900292009-02-15 12:44:28 +0100410 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200411 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100412 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200413 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200414 skb_put(skb, 2);
Johannes Bergef422bc2008-09-09 10:58:25 +0200415 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200416 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
417
Jouni Malinen53b46b82009-03-27 20:53:56 +0200418 if (stype == IEEE80211_STYPE_DEAUTH)
419 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len);
420 else
421 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len);
Johannes Berg46900292009-02-15 12:44:28 +0100422 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200423}
424
Kalle Valo572e0012009-02-10 17:09:31 +0200425void ieee80211_send_pspoll(struct ieee80211_local *local,
426 struct ieee80211_sub_if_data *sdata)
427{
Johannes Berg46900292009-02-15 12:44:28 +0100428 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Kalle Valo572e0012009-02-10 17:09:31 +0200429 struct ieee80211_pspoll *pspoll;
430 struct sk_buff *skb;
431 u16 fc;
432
433 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
434 if (!skb) {
435 printk(KERN_DEBUG "%s: failed to allocate buffer for "
436 "pspoll frame\n", sdata->dev->name);
437 return;
438 }
439 skb_reserve(skb, local->hw.extra_tx_headroom);
440
441 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
442 memset(pspoll, 0, sizeof(*pspoll));
443 fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
444 pspoll->frame_control = cpu_to_le16(fc);
Johannes Berg46900292009-02-15 12:44:28 +0100445 pspoll->aid = cpu_to_le16(ifmgd->aid);
Kalle Valo572e0012009-02-10 17:09:31 +0200446
447 /* aid in PS-Poll has its two MSBs each set to 1 */
448 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
449
Johannes Berg46900292009-02-15 12:44:28 +0100450 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
Kalle Valo572e0012009-02-10 17:09:31 +0200451 memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN);
452
453 ieee80211_tx_skb(sdata, skb, 0);
Kalle Valo572e0012009-02-10 17:09:31 +0200454}
455
Johannes Berg965beda2009-04-16 13:17:24 +0200456void ieee80211_send_nullfunc(struct ieee80211_local *local,
457 struct ieee80211_sub_if_data *sdata,
458 int powersave)
459{
460 struct sk_buff *skb;
461 struct ieee80211_hdr *nullfunc;
462 __le16 fc;
463
464 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
465 return;
466
467 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
468 if (!skb) {
469 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
470 "frame\n", sdata->dev->name);
471 return;
472 }
473 skb_reserve(skb, local->hw.extra_tx_headroom);
474
475 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
476 memset(nullfunc, 0, 24);
477 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
478 IEEE80211_FCTL_TODS);
479 if (powersave)
480 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
481 nullfunc->frame_control = fc;
482 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
483 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
484 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
485
486 ieee80211_tx_skb(sdata, skb, 0);
487}
488
489/* powersave */
490static void ieee80211_enable_ps(struct ieee80211_local *local,
491 struct ieee80211_sub_if_data *sdata)
492{
493 struct ieee80211_conf *conf = &local->hw.conf;
494
Johannes Bergd5edaed2009-04-22 23:02:51 +0200495 /*
496 * If we are scanning right now then the parameters will
497 * take effect when scan finishes.
498 */
499 if (local->hw_scanning || local->sw_scanning)
500 return;
501
Johannes Berg965beda2009-04-16 13:17:24 +0200502 if (conf->dynamic_ps_timeout > 0 &&
503 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
504 mod_timer(&local->dynamic_ps_timer, jiffies +
505 msecs_to_jiffies(conf->dynamic_ps_timeout));
506 } else {
507 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
508 ieee80211_send_nullfunc(local, sdata, 1);
509 conf->flags |= IEEE80211_CONF_PS;
510 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
511 }
512}
513
514static void ieee80211_change_ps(struct ieee80211_local *local)
515{
516 struct ieee80211_conf *conf = &local->hw.conf;
517
518 if (local->ps_sdata) {
519 if (!(local->ps_sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
520 return;
521
522 ieee80211_enable_ps(local, local->ps_sdata);
523 } else if (conf->flags & IEEE80211_CONF_PS) {
524 conf->flags &= ~IEEE80211_CONF_PS;
525 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
526 del_timer_sync(&local->dynamic_ps_timer);
527 cancel_work_sync(&local->dynamic_ps_enable_work);
528 }
529}
530
531/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +0200532void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +0200533{
534 struct ieee80211_sub_if_data *sdata, *found = NULL;
535 int count = 0;
536
537 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
538 local->ps_sdata = NULL;
539 return;
540 }
541
542 list_for_each_entry(sdata, &local->interfaces, list) {
543 if (!netif_running(sdata->dev))
544 continue;
545 if (sdata->vif.type != NL80211_IFTYPE_STATION)
546 continue;
547 found = sdata;
548 count++;
549 }
550
Johannes Berg10f644a2009-04-16 13:17:25 +0200551 if (count == 1 && found->u.mgd.powersave) {
552 s32 beaconint_us;
553
554 if (latency < 0)
555 latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY);
556
557 beaconint_us = ieee80211_tu_to_usec(
558 found->vif.bss_conf.beacon_int);
559
Johannes Berg04fe2032009-04-22 18:44:37 +0200560 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +0200561 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +0200562 } else {
563 u8 dtimper = found->vif.bss_conf.dtim_period;
564 int maxslp = 1;
565
566 if (dtimper > 1)
567 maxslp = min_t(int, dtimper,
568 latency / beaconint_us);
569
Johannes Berg9ccebe62009-04-23 10:32:36 +0200570 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg10f644a2009-04-16 13:17:25 +0200571 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +0200572 }
Johannes Berg10f644a2009-04-16 13:17:25 +0200573 } else {
Johannes Berg965beda2009-04-16 13:17:24 +0200574 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +0200575 }
Johannes Berg965beda2009-04-16 13:17:24 +0200576
577 ieee80211_change_ps(local);
578}
579
580void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
581{
582 struct ieee80211_local *local =
583 container_of(work, struct ieee80211_local,
584 dynamic_ps_disable_work);
585
586 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
587 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
588 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
589 }
590
591 ieee80211_wake_queues_by_reason(&local->hw,
592 IEEE80211_QUEUE_STOP_REASON_PS);
593}
594
595void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
596{
597 struct ieee80211_local *local =
598 container_of(work, struct ieee80211_local,
599 dynamic_ps_enable_work);
600 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
601
602 /* can only happen when PS was just disabled anyway */
603 if (!sdata)
604 return;
605
606 if (local->hw.conf.flags & IEEE80211_CONF_PS)
607 return;
608
609 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
610 ieee80211_send_nullfunc(local, sdata, 1);
611
612 local->hw.conf.flags |= IEEE80211_CONF_PS;
613 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
614}
615
616void ieee80211_dynamic_ps_timer(unsigned long data)
617{
618 struct ieee80211_local *local = (void *) data;
619
620 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
621}
622
Johannes Berg60f8b392008-09-08 17:44:22 +0200623/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200624static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg46900292009-02-15 12:44:28 +0100625 struct ieee80211_if_managed *ifmgd,
Jiri Bencf0706e82007-05-05 11:45:53 -0700626 u8 *wmm_param, size_t wmm_param_len)
627{
Jiri Bencf0706e82007-05-05 11:45:53 -0700628 struct ieee80211_tx_queue_params params;
629 size_t left;
630 int count;
631 u8 *pos;
632
Johannes Berg46900292009-02-15 12:44:28 +0100633 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED))
Johannes Berg3434fbd2008-05-03 00:59:37 +0200634 return;
635
636 if (!wmm_param)
637 return;
638
Jiri Bencf0706e82007-05-05 11:45:53 -0700639 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
640 return;
641 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100642 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e82007-05-05 11:45:53 -0700643 return;
Johannes Berg46900292009-02-15 12:44:28 +0100644 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700645
646 pos = wmm_param + 8;
647 left = wmm_param_len - 8;
648
649 memset(&params, 0, sizeof(params));
650
Jiri Bencf0706e82007-05-05 11:45:53 -0700651 local->wmm_acm = 0;
652 for (; left >= 4; left -= 4, pos += 4) {
653 int aci = (pos[0] >> 5) & 0x03;
654 int acm = (pos[0] >> 4) & 0x01;
655 int queue;
656
657 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200658 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200659 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200660 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200661 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Jiri Bencf0706e82007-05-05 11:45:53 -0700662 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200663 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200664 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200665 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200666 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Jiri Bencf0706e82007-05-05 11:45:53 -0700667 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200668 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200669 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200670 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200671 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Jiri Bencf0706e82007-05-05 11:45:53 -0700672 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200673 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700674 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200675 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200676 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200677 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700678 break;
679 }
680
681 params.aifs = pos[0] & 0x0f;
682 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
683 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200684 params.txop = get_unaligned_le16(pos + 2);
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200685#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Jiri Bencf0706e82007-05-05 11:45:53 -0700686 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
Johannes Berg3330d7b2008-02-10 16:49:38 +0100687 "cWmin=%d cWmax=%d txop=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200688 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
Johannes Berg3330d7b2008-02-10 16:49:38 +0100689 params.cw_max, params.txop);
690#endif
Johannes Berg24487982009-04-23 18:52:52 +0200691 if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx)
Jiri Bencf0706e82007-05-05 11:45:53 -0700692 printk(KERN_DEBUG "%s: failed to set TX queue "
Johannes Berg24487982009-04-23 18:52:52 +0200693 "parameters for queue %d\n", local->mdev->name,
694 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700695 }
696}
697
Johannes Berg7a5158e2008-10-08 10:59:33 +0200698static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
699 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200700{
Johannes Bergbda39332008-10-11 01:51:51 +0200701 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Tomas Winklerebd74482008-07-01 10:44:50 +0300702#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg46900292009-02-15 12:44:28 +0100703 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winklerebd74482008-07-01 10:44:50 +0300704#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100705 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200706 bool use_protection;
707 bool use_short_preamble;
708 bool use_short_slot;
709
710 if (erp_valid) {
711 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
712 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
713 } else {
714 use_protection = false;
715 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
716 }
717
718 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Daniel Drake56282212007-07-10 19:32:10 +0200719
Johannes Berg471b3ef2007-12-28 14:32:58 +0100720 if (use_protection != bss_conf->use_cts_prot) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200721#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake56282212007-07-10 19:32:10 +0200722 if (net_ratelimit()) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700723 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100724 sdata->dev->name,
Daniel Drake56282212007-07-10 19:32:10 +0200725 use_protection ? "enabled" : "disabled",
Johannes Berg46900292009-02-15 12:44:28 +0100726 ifmgd->bssid);
Daniel Drake56282212007-07-10 19:32:10 +0200727 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200728#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100729 bss_conf->use_cts_prot = use_protection;
730 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200731 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200732
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200733 if (use_short_preamble != bss_conf->use_short_preamble) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200734#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake7e9ed182007-07-27 15:43:24 +0200735 if (net_ratelimit()) {
736 printk(KERN_DEBUG "%s: switched to %s barker preamble"
Johannes Berg0c68ae262008-10-27 15:56:10 -0700737 " (BSSID=%pM)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100738 sdata->dev->name,
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200739 use_short_preamble ? "short" : "long",
Johannes Berg46900292009-02-15 12:44:28 +0100740 ifmgd->bssid);
Daniel Drake7e9ed182007-07-27 15:43:24 +0200741 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200742#endif
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200743 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100744 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200745 }
Daniel Draked9430a32007-07-27 15:43:24 +0200746
Johannes Berg7a5158e2008-10-08 10:59:33 +0200747 if (use_short_slot != bss_conf->use_short_slot) {
748#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
749 if (net_ratelimit()) {
Christian Lamparter391429c2009-01-18 02:24:15 +0100750 printk(KERN_DEBUG "%s: switched to %s slot time"
751 " (BSSID=%pM)\n",
Johannes Berg7a5158e2008-10-08 10:59:33 +0200752 sdata->dev->name,
753 use_short_slot ? "short" : "long",
Johannes Berg46900292009-02-15 12:44:28 +0100754 ifmgd->bssid);
Johannes Berg7a5158e2008-10-08 10:59:33 +0200755 }
756#endif
757 bss_conf->use_short_slot = use_short_slot;
758 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400759 }
760
761 return changed;
762}
763
Johannes Berg46900292009-02-15 12:44:28 +0100764static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200765{
766 union iwreq_data wrqu;
Johannes Berg46900292009-02-15 12:44:28 +0100767
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200768 memset(&wrqu, 0, sizeof(wrqu));
Johannes Berg46900292009-02-15 12:44:28 +0100769 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
770 memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200771 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
772 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
773}
774
Johannes Berg46900292009-02-15 12:44:28 +0100775static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700776{
Johannes Berg46900292009-02-15 12:44:28 +0100777 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Linus Torvalds74af0252008-09-05 12:38:09 -0700778 char *buf;
779 size_t len;
780 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700781 union iwreq_data wrqu;
782
Johannes Berg46900292009-02-15 12:44:28 +0100783 if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
Linus Torvalds74af0252008-09-05 12:38:09 -0700784 return;
785
Johannes Berg46900292009-02-15 12:44:28 +0100786 buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
787 ifmgd->assocresp_ies_len), GFP_KERNEL);
Linus Torvalds74af0252008-09-05 12:38:09 -0700788 if (!buf)
789 return;
790
791 len = sprintf(buf, "ASSOCINFO(");
Johannes Berg46900292009-02-15 12:44:28 +0100792 if (ifmgd->assocreq_ies) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700793 len += sprintf(buf + len, "ReqIEs=");
Johannes Berg46900292009-02-15 12:44:28 +0100794 for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700795 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100796 ifmgd->assocreq_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700797 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700798 }
Johannes Berg46900292009-02-15 12:44:28 +0100799 if (ifmgd->assocresp_ies) {
800 if (ifmgd->assocreq_ies)
Linus Torvalds74af0252008-09-05 12:38:09 -0700801 len += sprintf(buf + len, " ");
802 len += sprintf(buf + len, "RespIEs=");
Johannes Berg46900292009-02-15 12:44:28 +0100803 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700804 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100805 ifmgd->assocresp_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700806 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700807 }
Linus Torvalds74af0252008-09-05 12:38:09 -0700808 len += sprintf(buf + len, ")");
809
810 if (len > IW_CUSTOM_MAX) {
811 len = sprintf(buf, "ASSOCRESPIE=");
Johannes Berg46900292009-02-15 12:44:28 +0100812 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700813 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100814 ifmgd->assocresp_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700815 }
816 }
817
John W. Linvillead788b52008-10-01 15:45:02 -0400818 if (len <= IW_CUSTOM_MAX) {
819 memset(&wrqu, 0, sizeof(wrqu));
820 wrqu.data.length = len;
821 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
822 }
Linus Torvalds74af0252008-09-05 12:38:09 -0700823
824 kfree(buf);
Jiri Bencf0706e82007-05-05 11:45:53 -0700825}
826
827
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200828static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Bergae5eb022008-10-14 16:58:37 +0200829 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700830{
Johannes Berg46900292009-02-15 12:44:28 +0100831 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100832 struct ieee80211_local *local = sdata->local;
Tomas Winkler38668c02008-03-28 16:33:32 -0700833 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
Jiri Bencf0706e82007-05-05 11:45:53 -0700834
Johannes Bergc2b13452008-09-11 00:01:55 +0200835 struct ieee80211_bss *bss;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400836
Johannes Bergae5eb022008-10-14 16:58:37 +0200837 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg46900292009-02-15 12:44:28 +0100838 ifmgd->flags |= IEEE80211_STA_ASSOCIATED;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400839
Johannes Berg46900292009-02-15 12:44:28 +0100840 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200841 conf->channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100842 ifmgd->ssid, ifmgd->ssid_len);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200843 if (bss) {
844 /* set timing information */
Johannes Berg00d3f142009-02-10 21:26:00 +0100845 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
846 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
Johannes Bergbda39332008-10-11 01:51:51 +0200847 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700848
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200849 bss_info_changed |= BSS_CHANGED_BEACON_INT;
Johannes Bergae5eb022008-10-14 16:58:37 +0200850 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg00d3f142009-02-10 21:26:00 +0100851 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700852
Kalle Valo04de8382009-03-22 21:57:35 +0200853 cfg80211_hold_bss(&bss->cbss);
854
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200855 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -0700856 }
Johannes Berg471b3ef2007-12-28 14:32:58 +0100857
Johannes Berg46900292009-02-15 12:44:28 +0100858 ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
859 memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
860 ieee80211_sta_send_associnfo(sdata);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200861
Johannes Berg46900292009-02-15 12:44:28 +0100862 ifmgd->last_probe = jiffies;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200863 ieee80211_led_assoc(local, 1);
864
Johannes Bergbda39332008-10-11 01:51:51 +0200865 sdata->vif.bss_conf.assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200866 /*
867 * For now just always ask the driver to update the basic rateset
868 * when we have associated, we aren't checking whether it actually
869 * changed or not.
870 */
Johannes Bergae5eb022008-10-14 16:58:37 +0200871 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
872 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +0300873
Johannes Berg965beda2009-04-16 13:17:24 +0200874 /* will be same as sdata */
Johannes Berg04fe2032009-04-22 18:44:37 +0200875 if (local->ps_sdata) {
876 mutex_lock(&local->iflist_mtx);
877 ieee80211_recalc_ps(local, -1);
878 mutex_unlock(&local->iflist_mtx);
879 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200880
Tomas Winkler24e64622008-09-08 17:33:40 +0200881 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200882 netif_carrier_on(sdata->dev);
Guy Cohen8db93692008-07-03 19:56:13 +0300883
Johannes Berg46900292009-02-15 12:44:28 +0100884 ieee80211_sta_send_apinfo(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700885}
886
Johannes Berg46900292009-02-15 12:44:28 +0100887static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300888{
Johannes Berg46900292009-02-15 12:44:28 +0100889 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100890 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100891
892 ifmgd->direct_probe_tries++;
893 if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700894 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100895 sdata->dev->name, ifmgd->bssid);
896 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +0200897 ieee80211_recalc_idle(local);
Jouni Malinene61f2342009-04-24 00:00:00 +0300898 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530899
900 /*
901 * Most likely AP is not in the range so remove the
902 * bss information associated to the AP
903 */
Johannes Berg46900292009-02-15 12:44:28 +0100904 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530905 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100906 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100907
908 /*
909 * We might have a pending scan which had no chance to run yet
910 * due to state == IEEE80211_STA_MLME_DIRECT_PROBE.
911 * Hence, queue the STAs work again
912 */
913 queue_work(local->hw.workqueue, &ifmgd->work);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300914 return;
915 }
916
Johannes Berg0c68ae262008-10-27 15:56:10 -0700917 printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
Johannes Berg46900292009-02-15 12:44:28 +0100918 sdata->dev->name, ifmgd->bssid,
919 ifmgd->direct_probe_tries);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300920
Johannes Berg46900292009-02-15 12:44:28 +0100921 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300922
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300923 /* Direct probe is sent to broadcast address as some APs
924 * will not answer to direct packet in unassociated state.
925 */
926 ieee80211_send_probe_req(sdata, NULL,
Jouni Malinen70692ad2009-02-16 19:39:13 +0200927 ifmgd->ssid, ifmgd->ssid_len, NULL, 0);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300928
Johannes Berg46900292009-02-15 12:44:28 +0100929 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300930}
931
Jiri Bencf0706e82007-05-05 11:45:53 -0700932
Johannes Berg46900292009-02-15 12:44:28 +0100933static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700934{
Johannes Berg46900292009-02-15 12:44:28 +0100935 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100936 struct ieee80211_local *local = sdata->local;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200937 u8 *ies;
938 size_t ies_len;
Johannes Berg46900292009-02-15 12:44:28 +0100939
940 ifmgd->auth_tries++;
941 if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700942 printk(KERN_DEBUG "%s: authentication with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -0700943 " timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100944 sdata->dev->name, ifmgd->bssid);
945 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +0200946 ieee80211_recalc_idle(local);
Jouni Malinen1965c852009-04-22 21:38:25 +0300947 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
Johannes Berg46900292009-02-15 12:44:28 +0100948 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530949 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100950 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100951
952 /*
953 * We might have a pending scan which had no chance to run yet
954 * due to state == IEEE80211_STA_MLME_AUTHENTICATE.
955 * Hence, queue the STAs work again
956 */
957 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -0700958 return;
959 }
960
Johannes Berg46900292009-02-15 12:44:28 +0100961 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700962 printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +0100963 sdata->dev->name, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -0700964
Jouni Malinen636a5d32009-03-19 13:39:22 +0200965 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
966 ies = ifmgd->sme_auth_ie;
967 ies_len = ifmgd->sme_auth_ie_len;
968 } else {
969 ies = NULL;
970 ies_len = 0;
971 }
972 ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len,
Johannes Berg46900292009-02-15 12:44:28 +0100973 ifmgd->bssid, 0);
974 ifmgd->auth_transaction = 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700975
Johannes Berg46900292009-02-15 12:44:28 +0100976 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
Jiri Bencf0706e82007-05-05 11:45:53 -0700977}
978
Vivek Natarajan5925d972008-11-21 22:19:50 -0800979/*
980 * The disassoc 'reason' argument can be either our own reason
981 * if self disconnected or a reason code from the AP.
982 */
Tomas Winkleraa458d12008-09-09 00:32:12 +0300983static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg46900292009-02-15 12:44:28 +0100984 bool deauth, bool self_disconnected,
985 u16 reason)
Tomas Winkleraa458d12008-09-09 00:32:12 +0300986{
Johannes Berg46900292009-02-15 12:44:28 +0100987 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300988 struct ieee80211_local *local = sdata->local;
Kalle Valo04de8382009-03-22 21:57:35 +0200989 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
990 struct ieee80211_bss *bss;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300991 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200992 u32 changed = 0, config_changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300993
994 rcu_read_lock();
995
Johannes Berg46900292009-02-15 12:44:28 +0100996 sta = sta_info_get(local, ifmgd->bssid);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300997 if (!sta) {
998 rcu_read_unlock();
999 return;
1000 }
1001
1002 if (deauth) {
Johannes Berg46900292009-02-15 12:44:28 +01001003 ifmgd->direct_probe_tries = 0;
1004 ifmgd->auth_tries = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001005 }
Johannes Berg46900292009-02-15 12:44:28 +01001006 ifmgd->assoc_scan_tries = 0;
1007 ifmgd->assoc_tries = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001008
Tomas Winkler24e64622008-09-08 17:33:40 +02001009 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001010 netif_carrier_off(sdata->dev);
1011
Johannes Berg2dace102009-02-10 21:25:52 +01001012 ieee80211_sta_tear_down_BA_sessions(sta);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001013
Kalle Valo04de8382009-03-22 21:57:35 +02001014 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
1015 conf->channel->center_freq,
1016 ifmgd->ssid, ifmgd->ssid_len);
1017
1018 if (bss) {
1019 cfg80211_unhold_bss(&bss->cbss);
1020 ieee80211_rx_bss_put(local, bss);
1021 }
1022
Tomas Winkleraa458d12008-09-09 00:32:12 +03001023 if (self_disconnected) {
1024 if (deauth)
Johannes Bergef422bc2008-09-09 10:58:25 +02001025 ieee80211_send_deauth_disassoc(sdata,
1026 IEEE80211_STYPE_DEAUTH, reason);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001027 else
Johannes Bergef422bc2008-09-09 10:58:25 +02001028 ieee80211_send_deauth_disassoc(sdata,
1029 IEEE80211_STYPE_DISASSOC, reason);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001030 }
1031
Johannes Berg46900292009-02-15 12:44:28 +01001032 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001033 changed |= ieee80211_reset_erp_info(sdata);
1034
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001035 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001036 changed |= BSS_CHANGED_ASSOC;
1037 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001038
Johannes Berg46900292009-02-15 12:44:28 +01001039 ieee80211_sta_send_apinfo(sdata);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001040
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301041 if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
Johannes Berg46900292009-02-15 12:44:28 +01001042 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1043 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301044 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +01001045 ifmgd->ssid, ifmgd->ssid_len);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301046 }
Tomas Winkleraa458d12008-09-09 00:32:12 +03001047
Tomas Winkleraa458d12008-09-09 00:32:12 +03001048 rcu_read_unlock();
1049
Johannes Bergaa837e12009-05-07 16:16:24 +02001050 ieee80211_set_wmm_default(sdata);
1051
Johannes Berg5cff20e2009-04-29 12:26:17 +02001052 ieee80211_recalc_idle(local);
1053
Johannes Berg47979382009-01-07 10:13:27 +01001054 /* channel(_type) changes are handled by ieee80211_hw_config */
Sujith094d05d2008-12-12 11:57:43 +05301055 local->oper_channel_type = NL80211_CHAN_NO_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001056
Johannes Berg413ad502009-05-08 21:21:06 +02001057 /* on the next assoc, re-program HT parameters */
1058 sdata->ht_opmode_valid = false;
1059
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301060 local->power_constr_level = 0;
1061
Kalle Valo520eb822008-12-18 23:35:27 +02001062 del_timer_sync(&local->dynamic_ps_timer);
1063 cancel_work_sync(&local->dynamic_ps_enable_work);
1064
Kalle Valoe0cb6862008-12-18 23:35:13 +02001065 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1066 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1067 config_changed |= IEEE80211_CONF_CHANGE_PS;
1068 }
1069
1070 ieee80211_hw_config(local, config_changed);
Johannes Bergae5eb022008-10-14 16:58:37 +02001071 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001072
1073 rcu_read_lock();
1074
Johannes Berg46900292009-02-15 12:44:28 +01001075 sta = sta_info_get(local, ifmgd->bssid);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001076 if (!sta) {
1077 rcu_read_unlock();
1078 return;
1079 }
1080
1081 sta_info_unlink(&sta);
1082
1083 rcu_read_unlock();
1084
1085 sta_info_destroy(sta);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001086}
Jiri Bencf0706e82007-05-05 11:45:53 -07001087
Johannes Berg9ac19a92008-09-09 10:57:09 +02001088static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
1089{
1090 if (!sdata || !sdata->default_key ||
1091 sdata->default_key->conf.alg != ALG_WEP)
1092 return 0;
1093 return 1;
1094}
1095
Johannes Berg46900292009-02-15 12:44:28 +01001096static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001097{
Johannes Berg46900292009-02-15 12:44:28 +01001098 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001099 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02001100 struct ieee80211_bss *bss;
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001101 int bss_privacy;
1102 int wep_privacy;
1103 int privacy_invoked;
Jiri Bencf0706e82007-05-05 11:45:53 -07001104
Johannes Berg7986cf92009-03-21 17:08:43 +01001105 if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
Jiri Bencf0706e82007-05-05 11:45:53 -07001106 return 0;
1107
Johannes Berg46900292009-02-15 12:44:28 +01001108 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +01001109 local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +01001110 ifmgd->ssid, ifmgd->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001111 if (!bss)
1112 return 0;
1113
Johannes Berg00d3f142009-02-10 21:26:00 +01001114 bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001115 wep_privacy = !!ieee80211_sta_wep_configured(sdata);
Johannes Berg46900292009-02-15 12:44:28 +01001116 privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
Jiri Bencf0706e82007-05-05 11:45:53 -07001117
Johannes Berg3e122be2008-07-09 14:40:34 +02001118 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07001119
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001120 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
1121 return 0;
1122
1123 return 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001124}
1125
Johannes Berg46900292009-02-15 12:44:28 +01001126static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001127{
Johannes Berg46900292009-02-15 12:44:28 +01001128 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +01001129 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01001130
1131 ifmgd->assoc_tries++;
1132 if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -07001133 printk(KERN_DEBUG "%s: association with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -07001134 " timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +01001135 sdata->dev->name, ifmgd->bssid);
1136 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +02001137 ieee80211_recalc_idle(local);
Jouni Malinen1965c852009-04-22 21:38:25 +03001138 cfg80211_send_assoc_timeout(sdata->dev, ifmgd->bssid);
Johannes Berg46900292009-02-15 12:44:28 +01001139 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301140 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +01001141 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +01001142 /*
1143 * We might have a pending scan which had no chance to run yet
1144 * due to state == IEEE80211_STA_MLME_ASSOCIATE.
1145 * Hence, queue the STAs work again
1146 */
1147 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001148 return;
1149 }
1150
Johannes Berg46900292009-02-15 12:44:28 +01001151 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
Johannes Berg0c68ae262008-10-27 15:56:10 -07001152 printk(KERN_DEBUG "%s: associate with AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +01001153 sdata->dev->name, ifmgd->bssid);
1154 if (ieee80211_privacy_mismatch(sdata)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001155 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001156 "mixed-cell disabled - abort association\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001157 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +02001158 ieee80211_recalc_idle(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001159 return;
1160 }
1161
Johannes Berg46900292009-02-15 12:44:28 +01001162 ieee80211_send_assoc(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001163
Johannes Berg46900292009-02-15 12:44:28 +01001164 mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
Jiri Bencf0706e82007-05-05 11:45:53 -07001165}
1166
Kalle Valo3cf335d2009-03-22 21:57:06 +02001167void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1168 struct ieee80211_hdr *hdr)
1169{
1170 /*
1171 * We can postpone the mgd.timer whenever receiving unicast frames
1172 * from AP because we know that the connection is working both ways
1173 * at that time. But multicast frames (and hence also beacons) must
1174 * be ignored here, because we need to trigger the timer during
1175 * data idle periods for sending the periodical probe request to
1176 * the AP.
1177 */
1178 if (!is_multicast_ether_addr(hdr->addr1))
1179 mod_timer(&sdata->u.mgd.timer,
1180 jiffies + IEEE80211_MONITORING_INTERVAL);
1181}
Jiri Bencf0706e82007-05-05 11:45:53 -07001182
Kalle Valo04de8382009-03-22 21:57:35 +02001183void ieee80211_beacon_loss_work(struct work_struct *work)
1184{
1185 struct ieee80211_sub_if_data *sdata =
1186 container_of(work, struct ieee80211_sub_if_data,
1187 u.mgd.beacon_loss_work);
1188 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1189
Johannes Berg34bfc412009-05-12 19:58:12 +02001190 /*
1191 * The driver has already reported this event and we have
1192 * already sent a probe request. Maybe the AP died and the
1193 * driver keeps reporting until we disassociate... We have
1194 * to ignore that because otherwise we would continually
1195 * reset the timer and never check whether we received a
1196 * probe response!
1197 */
1198 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1199 return;
1200
Michael Buescha8604022009-04-15 14:41:22 -04001201#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1202 if (net_ratelimit()) {
1203 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
1204 "- sending probe request\n", sdata->dev->name,
1205 sdata->u.mgd.bssid);
1206 }
1207#endif
Kalle Valo04de8382009-03-22 21:57:35 +02001208
1209 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1210 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1211 ifmgd->ssid_len, NULL, 0);
1212
Johannes Berge0502de2009-05-12 20:11:26 +02001213 mod_timer(&ifmgd->timer, jiffies + IEEE80211_PROBE_WAIT);
Kalle Valo04de8382009-03-22 21:57:35 +02001214}
1215
1216void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1217{
1218 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1219
1220 queue_work(sdata->local->hw.workqueue,
1221 &sdata->u.mgd.beacon_loss_work);
1222}
1223EXPORT_SYMBOL(ieee80211_beacon_loss);
1224
Johannes Berg46900292009-02-15 12:44:28 +01001225static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001226{
Johannes Berg46900292009-02-15 12:44:28 +01001227 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001228 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001229 struct sta_info *sta;
Kalle Valo15b7b062009-03-22 21:57:14 +02001230 bool disassoc = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001231
1232 /* TODO: start monitoring current AP signal quality and number of
1233 * missed beacons. Scan other channels every now and then and search
1234 * for better APs. */
1235 /* TODO: remove expired BSSes */
1236
Johannes Berg46900292009-02-15 12:44:28 +01001237 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001238
Johannes Bergd0709a62008-02-25 16:27:46 +01001239 rcu_read_lock();
1240
Johannes Berg46900292009-02-15 12:44:28 +01001241 sta = sta_info_get(local, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001242 if (!sta) {
Johannes Berg0c68ae262008-10-27 15:56:10 -07001243 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +01001244 sdata->dev->name, ifmgd->bssid);
Kalle Valo15b7b062009-03-22 21:57:14 +02001245 disassoc = true;
1246 goto unlock;
Jiri Bencf0706e82007-05-05 11:45:53 -07001247 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001248
Kalle Valo15b7b062009-03-22 21:57:14 +02001249 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
Johannes Berge0502de2009-05-12 20:11:26 +02001250 time_after(jiffies, sta->last_rx + IEEE80211_PROBE_WAIT)) {
Kalle Valo15b7b062009-03-22 21:57:14 +02001251 printk(KERN_DEBUG "%s: no probe response from AP %pM "
1252 "- disassociating\n",
1253 sdata->dev->name, ifmgd->bssid);
1254 disassoc = true;
1255 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1256 goto unlock;
1257 }
1258
Kalle Valo04de8382009-03-22 21:57:35 +02001259 /*
1260 * Beacon filtering is only enabled with power save and then the
1261 * stack should not check for beacon loss.
1262 */
1263 if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) &&
1264 (local->hw.conf.flags & IEEE80211_CONF_PS)) &&
1265 time_after(jiffies,
Kalle Valo15b7b062009-03-22 21:57:14 +02001266 ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
Michael Buescha8604022009-04-15 14:41:22 -04001267#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1268 if (net_ratelimit()) {
1269 printk(KERN_DEBUG "%s: beacon loss from AP %pM "
1270 "- sending probe request\n",
1271 sdata->dev->name, ifmgd->bssid);
1272 }
1273#endif
Kalle Valo15b7b062009-03-22 21:57:14 +02001274 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1275 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1276 ifmgd->ssid_len, NULL, 0);
1277 goto unlock;
1278
1279 }
1280
1281 if (time_after(jiffies, sta->last_rx + IEEE80211_PROBE_IDLE_TIME)) {
1282 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1283 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1284 ifmgd->ssid_len, NULL, 0);
1285 }
1286
1287 unlock:
Johannes Bergd0709a62008-02-25 16:27:46 +01001288 rcu_read_unlock();
1289
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301290 if (disassoc)
Johannes Berg46900292009-02-15 12:44:28 +01001291 ieee80211_set_disassoc(sdata, true, true,
Tomas Winkleraa458d12008-09-09 00:32:12 +03001292 WLAN_REASON_PREV_AUTH_NOT_VALID);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301293 else
Johannes Berg46900292009-02-15 12:44:28 +01001294 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001295 IEEE80211_MONITORING_INTERVAL);
Jiri Bencf0706e82007-05-05 11:45:53 -07001296}
1297
1298
Johannes Berg46900292009-02-15 12:44:28 +01001299static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001300{
Johannes Berg46900292009-02-15 12:44:28 +01001301 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1302
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001303 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001304 ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
Jouni Malinen636a5d32009-03-19 13:39:22 +02001305 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1306 /* Wait for SME to request association */
1307 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +02001308 ieee80211_recalc_idle(sdata->local);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001309 } else
1310 ieee80211_associate(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001311}
1312
1313
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001314static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001315 struct ieee80211_mgmt *mgmt,
1316 size_t len)
1317{
1318 u8 *pos;
1319 struct ieee802_11_elems elems;
1320
Jiri Bencf0706e82007-05-05 11:45:53 -07001321 pos = mgmt->u.auth.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001322 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001323 if (!elems.challenge)
Jiri Bencf0706e82007-05-05 11:45:53 -07001324 return;
Johannes Berg46900292009-02-15 12:44:28 +01001325 ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg,
1326 elems.challenge - 2, elems.challenge_len + 2,
1327 sdata->u.mgd.bssid, 1);
1328 sdata->u.mgd.auth_transaction = 4;
Johannes Bergfe3d2c32009-02-10 21:26:03 +01001329}
1330
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001331static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001332 struct ieee80211_mgmt *mgmt,
1333 size_t len)
1334{
Johannes Berg46900292009-02-15 12:44:28 +01001335 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001336 u16 auth_alg, auth_transaction, status_code;
1337
Johannes Berg46900292009-02-15 12:44:28 +01001338 if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07001339 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001340
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001341 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001342 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001343
Johannes Berg46900292009-02-15 12:44:28 +01001344 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001345 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001346
Johannes Berg46900292009-02-15 12:44:28 +01001347 if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001348 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001349
1350 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1351 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1352 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1353
Johannes Berg46900292009-02-15 12:44:28 +01001354 if (auth_alg != ifmgd->auth_alg ||
1355 auth_transaction != ifmgd->auth_transaction)
Jiri Bencf0706e82007-05-05 11:45:53 -07001356 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001357
1358 if (status_code != WLAN_STATUS_SUCCESS) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001359 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1360 u8 algs[3];
1361 const int num_algs = ARRAY_SIZE(algs);
1362 int i, pos;
1363 algs[0] = algs[1] = algs[2] = 0xff;
Johannes Berg46900292009-02-15 12:44:28 +01001364 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
Jiri Bencf0706e82007-05-05 11:45:53 -07001365 algs[0] = WLAN_AUTH_OPEN;
Johannes Berg46900292009-02-15 12:44:28 +01001366 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
Jiri Bencf0706e82007-05-05 11:45:53 -07001367 algs[1] = WLAN_AUTH_SHARED_KEY;
Johannes Berg46900292009-02-15 12:44:28 +01001368 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
Jiri Bencf0706e82007-05-05 11:45:53 -07001369 algs[2] = WLAN_AUTH_LEAP;
Johannes Berg46900292009-02-15 12:44:28 +01001370 if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
Jiri Bencf0706e82007-05-05 11:45:53 -07001371 pos = 0;
Johannes Berg46900292009-02-15 12:44:28 +01001372 else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
Jiri Bencf0706e82007-05-05 11:45:53 -07001373 pos = 1;
1374 else
1375 pos = 2;
1376 for (i = 0; i < num_algs; i++) {
1377 pos++;
1378 if (pos >= num_algs)
1379 pos = 0;
Johannes Berg46900292009-02-15 12:44:28 +01001380 if (algs[pos] == ifmgd->auth_alg ||
Jiri Bencf0706e82007-05-05 11:45:53 -07001381 algs[pos] == 0xff)
1382 continue;
1383 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001384 !ieee80211_sta_wep_configured(sdata))
Jiri Bencf0706e82007-05-05 11:45:53 -07001385 continue;
Johannes Berg46900292009-02-15 12:44:28 +01001386 ifmgd->auth_alg = algs[pos];
Jiri Bencf0706e82007-05-05 11:45:53 -07001387 break;
1388 }
1389 }
1390 return;
1391 }
1392
Johannes Berg46900292009-02-15 12:44:28 +01001393 switch (ifmgd->auth_alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001394 case WLAN_AUTH_OPEN:
1395 case WLAN_AUTH_LEAP:
Jouni Malinen636a5d32009-03-19 13:39:22 +02001396 case WLAN_AUTH_FT:
Johannes Berg46900292009-02-15 12:44:28 +01001397 ieee80211_auth_completed(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001398 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001399 break;
1400 case WLAN_AUTH_SHARED_KEY:
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001401 if (ifmgd->auth_transaction == 4) {
Johannes Berg46900292009-02-15 12:44:28 +01001402 ieee80211_auth_completed(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001403 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
1404 } else
Johannes Berg46900292009-02-15 12:44:28 +01001405 ieee80211_auth_challenge(sdata, mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001406 break;
1407 }
1408}
1409
1410
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001411static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001412 struct ieee80211_mgmt *mgmt,
1413 size_t len)
1414{
Johannes Berg46900292009-02-15 12:44:28 +01001415 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001416 u16 reason_code;
1417
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001418 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001419 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001420
Johannes Berg46900292009-02-15 12:44:28 +01001421 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001422 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001423
1424 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1425
Johannes Berg46900292009-02-15 12:44:28 +01001426 if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED)
Zhu Yi97c8b012008-10-28 15:58:31 +08001427 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
1428 sdata->dev->name, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001429
Jouni Malinen636a5d32009-03-19 13:39:22 +02001430 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1431 (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
1432 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE ||
1433 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) {
Johannes Berg46900292009-02-15 12:44:28 +01001434 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
1435 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001436 IEEE80211_RETRY_AUTH_INTERVAL);
1437 }
1438
Johannes Berg46900292009-02-15 12:44:28 +01001439 ieee80211_set_disassoc(sdata, true, false, 0);
1440 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
Jouni Malinen53b46b82009-03-27 20:53:56 +02001441 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001442}
1443
1444
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001445static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001446 struct ieee80211_mgmt *mgmt,
1447 size_t len)
1448{
Johannes Berg46900292009-02-15 12:44:28 +01001449 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001450 u16 reason_code;
1451
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001452 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001453 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001454
Johannes Berg46900292009-02-15 12:44:28 +01001455 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001456 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001457
1458 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1459
Johannes Berg46900292009-02-15 12:44:28 +01001460 if (ifmgd->flags & IEEE80211_STA_ASSOCIATED)
Zhu Yi97c8b012008-10-28 15:58:31 +08001461 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1462 sdata->dev->name, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001463
Jouni Malinen636a5d32009-03-19 13:39:22 +02001464 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1465 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) {
Johannes Berg46900292009-02-15 12:44:28 +01001466 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
1467 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001468 IEEE80211_RETRY_AUTH_INTERVAL);
1469 }
1470
Johannes Berg46900292009-02-15 12:44:28 +01001471 ieee80211_set_disassoc(sdata, false, false, reason_code);
Jouni Malinen53b46b82009-03-27 20:53:56 +02001472 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001473}
1474
1475
Johannes Berg471b3ef2007-12-28 14:32:58 +01001476static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001477 struct ieee80211_mgmt *mgmt,
1478 size_t len,
1479 int reassoc)
1480{
Johannes Berg46900292009-02-15 12:44:28 +01001481 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001482 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001483 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001484 struct sta_info *sta;
Johannes Berg881d9482009-01-21 15:13:48 +01001485 u32 rates, basic_rates;
Jiri Bencf0706e82007-05-05 11:45:53 -07001486 u16 capab_info, status_code, aid;
1487 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001488 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07001489 u8 *pos;
Johannes Bergae5eb022008-10-14 16:58:37 +02001490 u32 changed = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001491 int i, j;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001492 bool have_higher_than_11mbit = false, newsta = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001493 u16 ap_ht_cap_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001494
1495 /* AssocResp and ReassocResp have identical structure, so process both
1496 * of them in this function. */
1497
Johannes Berg46900292009-02-15 12:44:28 +01001498 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07001499 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001500
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001501 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001502 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001503
Johannes Berg46900292009-02-15 12:44:28 +01001504 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001505 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001506
1507 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1508 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1509 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001510
Johannes Berg0c68ae262008-10-27 15:56:10 -07001511 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
Jiri Bencf0706e82007-05-05 11:45:53 -07001512 "status=%d aid=%d)\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -07001513 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
Johannes Bergddd68582007-10-22 14:51:37 +02001514 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Jiri Bencf0706e82007-05-05 11:45:53 -07001515
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001516 pos = mgmt->u.assoc_resp.variable;
1517 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1518
1519 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Jouni Malinenf797eb72009-01-19 18:48:46 +02001520 elems.timeout_int && elems.timeout_int_len == 5 &&
1521 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001522 u32 tu, ms;
Jouni Malinenf797eb72009-01-19 18:48:46 +02001523 tu = get_unaligned_le32(elems.timeout_int + 1);
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001524 ms = tu * 1024 / 1000;
1525 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1526 "comeback duration %u TU (%u ms)\n",
1527 sdata->dev->name, tu, ms);
1528 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg46900292009-02-15 12:44:28 +01001529 mod_timer(&ifmgd->timer,
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001530 jiffies + msecs_to_jiffies(ms));
1531 return;
1532 }
1533
Jiri Bencf0706e82007-05-05 11:45:53 -07001534 if (status_code != WLAN_STATUS_SUCCESS) {
1535 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001536 sdata->dev->name, status_code);
Daniel Drake8a69aa92007-07-27 15:43:23 +02001537 /* if this was a reassociation, ensure we try a "full"
1538 * association next time. This works around some broken APs
1539 * which do not correctly reject reassociation requests. */
Johannes Berg46900292009-02-15 12:44:28 +01001540 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jouni Malinen66174bb2009-04-01 17:23:54 +03001541 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1542 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1543 /* Wait for SME to decide what to do next */
1544 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +02001545 ieee80211_recalc_idle(local);
Jouni Malinen66174bb2009-04-01 17:23:54 +03001546 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001547 return;
1548 }
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 "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001552 "set\n", sdata->dev->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",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001557 sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07001558 return;
1559 }
1560
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001561 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001562 ifmgd->aid = aid;
1563 ifmgd->ap_capab = capab_info;
Jiri Bencf0706e82007-05-05 11:45:53 -07001564
Johannes Berg46900292009-02-15 12:44:28 +01001565 kfree(ifmgd->assocresp_ies);
1566 ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1567 ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
1568 if (ifmgd->assocresp_ies)
1569 memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001570
Johannes Bergd0709a62008-02-25 16:27:46 +01001571 rcu_read_lock();
1572
Jiri Bencf0706e82007-05-05 11:45:53 -07001573 /* Add STA entry for the AP */
Johannes Berg46900292009-02-15 12:44:28 +01001574 sta = sta_info_get(local, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001575 if (!sta) {
Johannes Bergddf4ac52008-10-22 11:41:38 +02001576 newsta = true;
Johannes Bergd0709a62008-02-25 16:27:46 +01001577
Johannes Berg46900292009-02-15 12:44:28 +01001578 sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC);
Johannes Berg73651ee2008-02-25 16:27:47 +01001579 if (!sta) {
1580 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001581 " the AP\n", sdata->dev->name);
Johannes Bergd0709a62008-02-25 16:27:46 +01001582 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07001583 return;
1584 }
Johannes Berg73651ee2008-02-25 16:27:47 +01001585
Ron Rindjunskya61dae12008-08-10 00:54:34 +03001586 /* update new sta with its last rx activity */
1587 sta->last_rx = jiffies;
Jiri Bencf0706e82007-05-05 11:45:53 -07001588 }
1589
Johannes Berg73651ee2008-02-25 16:27:47 +01001590 /*
1591 * FIXME: Do we really need to update the sta_info's information here?
1592 * We already know about the AP (we found it in our list) so it
1593 * should already be filled with the right info, no?
1594 * As is stands, all this is racy because typically we assume
1595 * the information that is filled in here (except flags) doesn't
1596 * change while a STA structure is alive. As such, it should move
1597 * to between the sta_info_alloc() and sta_info_insert() above.
1598 */
1599
Jouni Malinen3f77316c2009-05-11 21:57:57 +03001600 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP);
1601 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1602 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
Jiri Bencf0706e82007-05-05 11:45:53 -07001603
1604 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001605 basic_rates = 0;
1606 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1607
Jiri Bencf0706e82007-05-05 11:45:53 -07001608 for (i = 0; i < elems.supp_rates_len; i++) {
1609 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001610 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001611
1612 if (rate > 110)
1613 have_higher_than_11mbit = true;
1614
1615 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001616 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001617 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001618 if (is_basic)
1619 basic_rates |= BIT(j);
1620 break;
1621 }
Johannes Berg8318d782008-01-24 19:38:38 +01001622 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001623 }
Johannes Berg8318d782008-01-24 19:38:38 +01001624
Jiri Bencf0706e82007-05-05 11:45:53 -07001625 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1626 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001627 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001628
1629 if (rate > 110)
1630 have_higher_than_11mbit = true;
1631
1632 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001633 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001634 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001635 if (is_basic)
1636 basic_rates |= BIT(j);
1637 break;
1638 }
Johannes Berg8318d782008-01-24 19:38:38 +01001639 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001640 }
Johannes Berg8318d782008-01-24 19:38:38 +01001641
Johannes Berg323ce792008-09-11 02:45:11 +02001642 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001643 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001644
1645 /* cf. IEEE 802.11 9.2.12 */
1646 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1647 have_higher_than_11mbit)
1648 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1649 else
1650 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001651
Sujithe65c2262009-03-02 13:28:31 +05301652 /* If TKIP/WEP is used, no need to parse AP's HT capabilities */
1653 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
Johannes Bergae5eb022008-10-14 16:58:37 +02001654 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001655 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001656
1657 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001658
Johannes Berg4b7679a2008-09-18 18:14:18 +02001659 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001660
Johannes Berg46900292009-02-15 12:44:28 +01001661 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Jouni Malinen5394af42009-01-08 13:31:59 +02001662 set_sta_flags(sta, WLAN_STA_MFP);
1663
Johannes Bergddf4ac52008-10-22 11:41:38 +02001664 if (elems.wmm_param)
Johannes Berg07346f812008-05-03 01:02:02 +02001665 set_sta_flags(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001666
1667 if (newsta) {
1668 int err = sta_info_insert(sta);
1669 if (err) {
1670 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1671 " the AP (error %d)\n", sdata->dev->name, err);
1672 rcu_read_unlock();
1673 return;
1674 }
1675 }
1676
1677 rcu_read_unlock();
1678
1679 if (elems.wmm_param)
Johannes Berg46900292009-02-15 12:44:28 +01001680 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07001681 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02001682 else
1683 ieee80211_set_wmm_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001684
Johannes Bergae5eb022008-10-14 16:58:37 +02001685 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001686 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
1687 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
Johannes Bergae5eb022008-10-14 16:58:37 +02001688 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1689 ap_ht_cap_flags);
1690
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001691 /* set AID and assoc capability,
1692 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001693 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001694 bss_conf->assoc_capability = capab_info;
Johannes Berg46900292009-02-15 12:44:28 +01001695 ieee80211_set_associated(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001696
Kalle Valo15b7b062009-03-22 21:57:14 +02001697 /*
1698 * initialise the time of last beacon to be the association time,
1699 * otherwise beacon loss check will trigger immediately
1700 */
1701 ifmgd->last_beacon = jiffies;
1702
Johannes Berg46900292009-02-15 12:44:28 +01001703 ieee80211_associated(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001704 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001705}
1706
1707
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001708static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001709 struct ieee80211_mgmt *mgmt,
1710 size_t len,
1711 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001712 struct ieee802_11_elems *elems,
1713 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07001714{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001715 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001716 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001717 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001718 struct ieee80211_channel *channel;
Jiri Bencf0706e82007-05-05 11:45:53 -07001719
Johannes Berg5bda6172008-09-08 11:05:10 +02001720 if (elems->ds_params && elems->ds_params_len == 1)
1721 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
1722 else
1723 freq = rx_status->freq;
1724
1725 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1726
1727 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1728 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001729
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001730 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001731 channel, beacon);
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001732 if (!bss)
1733 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001734
Sujithc481ec92009-01-06 09:28:37 +05301735 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg46900292009-02-15 12:44:28 +01001736 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301737 struct ieee80211_channel_sw_ie *sw_elem =
1738 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
1739 ieee80211_process_chanswitch(sdata, sw_elem, bss);
1740 }
1741
Johannes Berg3e122be2008-07-09 14:40:34 +02001742 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07001743}
1744
1745
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001746static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001747 struct ieee80211_mgmt *mgmt,
1748 size_t len,
1749 struct ieee80211_rx_status *rx_status)
1750{
Kalle Valo15b7b062009-03-22 21:57:14 +02001751 struct ieee80211_if_managed *ifmgd;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001752 size_t baselen;
1753 struct ieee802_11_elems elems;
1754
Kalle Valo15b7b062009-03-22 21:57:14 +02001755 ifmgd = &sdata->u.mgd;
1756
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001757 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
1758 return; /* ignore ProbeResp to foreign address */
1759
Ester Kummerae6a44e2008-06-27 18:54:48 +03001760 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1761 if (baselen > len)
1762 return;
1763
1764 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1765 &elems);
1766
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001767 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001768
1769 /* direct probe may be part of the association flow */
Johannes Berg16cf4382009-04-24 15:15:25 +02001770 if (ifmgd->state == IEEE80211_STA_MLME_DIRECT_PROBE) {
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001771 printk(KERN_DEBUG "%s direct probe responded\n",
1772 sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001773 ieee80211_authenticate(sdata);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001774 }
Kalle Valo15b7b062009-03-22 21:57:14 +02001775
1776 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1777 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001778}
1779
Johannes Bergd91f36d2009-04-16 13:17:26 +02001780/*
1781 * This is the canonical list of information elements we care about,
1782 * the filter code also gives us all changes to the Microsoft OUI
1783 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1784 *
1785 * We implement beacon filtering in software since that means we can
1786 * avoid processing the frame here and in cfg80211, and userspace
1787 * will not be able to tell whether the hardware supports it or not.
1788 *
1789 * XXX: This list needs to be dynamic -- userspace needs to be able to
1790 * add items it requires. It also needs to be able to tell us to
1791 * look out for other vendor IEs.
1792 */
1793static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02001794 (1ULL << WLAN_EID_COUNTRY) |
1795 (1ULL << WLAN_EID_ERP_INFO) |
1796 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1797 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1798 (1ULL << WLAN_EID_HT_CAPABILITY) |
1799 (1ULL << WLAN_EID_HT_INFORMATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001800
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001801static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001802 struct ieee80211_mgmt *mgmt,
1803 size_t len,
1804 struct ieee80211_rx_status *rx_status)
1805{
Johannes Bergd91f36d2009-04-16 13:17:26 +02001806 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001807 size_t baselen;
1808 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001809 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001810 u32 changed = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001811 bool erp_valid, directed_tim = false;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001812 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001813 u32 ncrc;
Jiri Bencf0706e82007-05-05 11:45:53 -07001814
Ester Kummerae6a44e2008-06-27 18:54:48 +03001815 /* Process beacon from the current BSS */
1816 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1817 if (baselen > len)
1818 return;
1819
Johannes Bergd91f36d2009-04-16 13:17:26 +02001820 if (rx_status->freq != local->hw.conf.channel->center_freq)
Jiri Bencf0706e82007-05-05 11:45:53 -07001821 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001822
Johannes Berg46900292009-02-15 12:44:28 +01001823 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
1824 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001825 return;
1826
Johannes Bergd91f36d2009-04-16 13:17:26 +02001827 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1828 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1829 len - baselen, &elems,
1830 care_about_ies, ncrc);
1831
1832 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Johannes Berge7ec86f2009-04-18 17:33:24 +02001833 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1834 ifmgd->aid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001835
1836 ncrc = crc32_be(ncrc, (void *)&directed_tim, sizeof(directed_tim));
1837
1838 if (ncrc == ifmgd->beacon_crc)
Sujithc481ec92009-01-06 09:28:37 +05301839 return;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001840 ifmgd->beacon_crc = ncrc;
1841
1842 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
Sujithc481ec92009-01-06 09:28:37 +05301843
Johannes Berg46900292009-02-15 12:44:28 +01001844 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Johannes Bergfe3fa822008-09-08 11:05:09 +02001845 elems.wmm_param_len);
1846
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301847 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Kalle Valo1fb36062009-02-10 17:09:24 +02001848 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001849 if (local->hw.conf.dynamic_ps_timeout > 0) {
1850 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1851 ieee80211_hw_config(local,
1852 IEEE80211_CONF_CHANGE_PS);
1853 ieee80211_send_nullfunc(local, sdata, 0);
1854 } else {
1855 local->pspolling = true;
1856
1857 /*
1858 * Here is assumed that the driver will be
1859 * able to send ps-poll frame and receive a
1860 * response even though power save mode is
1861 * enabled, but some drivers might require
1862 * to disable power save here. This needs
1863 * to be investigated.
1864 */
1865 ieee80211_send_pspoll(local, sdata);
1866 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001867 }
1868 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001869
1870 if (elems.erp_info && elems.erp_info_len >= 1) {
1871 erp_valid = true;
1872 erp_value = elems.erp_info[0];
1873 } else {
1874 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04001875 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001876 changed |= ieee80211_handle_bss_capability(sdata,
1877 le16_to_cpu(mgmt->u.beacon.capab_info),
1878 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07001879
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001880
Vasanthakumar Thiagarajan53d6f812009-02-11 22:18:49 +05301881 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001882 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001883 struct sta_info *sta;
1884 struct ieee80211_supported_band *sband;
1885 u16 ap_ht_cap_flags;
1886
1887 rcu_read_lock();
1888
Johannes Berg46900292009-02-15 12:44:28 +01001889 sta = sta_info_get(local, ifmgd->bssid);
Johannes Bergae5eb022008-10-14 16:58:37 +02001890 if (!sta) {
1891 rcu_read_unlock();
1892 return;
1893 }
1894
1895 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1896
1897 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1898 elems.ht_cap_elem, &sta->sta.ht_cap);
1899
1900 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1901
1902 rcu_read_unlock();
1903
1904 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1905 ap_ht_cap_flags);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001906 }
1907
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001908 if (elems.country_elem) {
1909 /* Note we are only reviewing this on beacons
1910 * for the BSSID we are associated to */
1911 regulatory_hint_11d(local->hw.wiphy,
1912 elems.country_elem, elems.country_elem_len);
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301913
1914 /* TODO: IBSS also needs this */
1915 if (elems.pwr_constr_elem)
1916 ieee80211_handle_pwr_constr(sdata,
1917 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1918 elems.pwr_constr_elem,
1919 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001920 }
1921
Johannes Berg471b3ef2007-12-28 14:32:58 +01001922 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001923}
1924
Johannes Berg46900292009-02-15 12:44:28 +01001925ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1926 struct sk_buff *skb,
1927 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07001928{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001929 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001930 struct ieee80211_mgmt *mgmt;
1931 u16 fc;
1932
1933 if (skb->len < 24)
Johannes Berg46900292009-02-15 12:44:28 +01001934 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001935
1936 mgmt = (struct ieee80211_mgmt *) skb->data;
1937 fc = le16_to_cpu(mgmt->frame_control);
1938
1939 switch (fc & IEEE80211_FCTL_STYPE) {
1940 case IEEE80211_STYPE_PROBE_REQ:
1941 case IEEE80211_STYPE_PROBE_RESP:
1942 case IEEE80211_STYPE_BEACON:
1943 memcpy(skb->cb, rx_status, sizeof(*rx_status));
1944 case IEEE80211_STYPE_AUTH:
1945 case IEEE80211_STYPE_ASSOC_RESP:
1946 case IEEE80211_STYPE_REASSOC_RESP:
1947 case IEEE80211_STYPE_DEAUTH:
1948 case IEEE80211_STYPE_DISASSOC:
Johannes Berg46900292009-02-15 12:44:28 +01001949 skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
1950 queue_work(local->hw.workqueue, &sdata->u.mgd.work);
1951 return RX_QUEUED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001952 }
1953
Johannes Berg46900292009-02-15 12:44:28 +01001954 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001955}
1956
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001957static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001958 struct sk_buff *skb)
1959{
1960 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07001961 struct ieee80211_mgmt *mgmt;
1962 u16 fc;
1963
Jiri Bencf0706e82007-05-05 11:45:53 -07001964 rx_status = (struct ieee80211_rx_status *) skb->cb;
1965 mgmt = (struct ieee80211_mgmt *) skb->data;
1966 fc = le16_to_cpu(mgmt->frame_control);
1967
Johannes Berg46900292009-02-15 12:44:28 +01001968 switch (fc & IEEE80211_FCTL_STYPE) {
1969 case IEEE80211_STYPE_PROBE_RESP:
1970 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
1971 rx_status);
1972 break;
1973 case IEEE80211_STYPE_BEACON:
1974 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1975 rx_status);
1976 break;
1977 case IEEE80211_STYPE_AUTH:
1978 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
1979 break;
1980 case IEEE80211_STYPE_ASSOC_RESP:
1981 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0);
1982 break;
1983 case IEEE80211_STYPE_REASSOC_RESP:
1984 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1);
1985 break;
1986 case IEEE80211_STYPE_DEAUTH:
1987 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
1988 break;
1989 case IEEE80211_STYPE_DISASSOC:
1990 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1991 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001992 }
1993
1994 kfree_skb(skb);
1995}
1996
Johannes Berg9c6bd792008-09-11 00:01:52 +02001997static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07001998{
1999 struct ieee80211_sub_if_data *sdata =
2000 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01002001 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002002 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07002003
Johannes Berg46900292009-02-15 12:44:28 +01002004 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
2005 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07002006}
2007
Johannes Berg46900292009-02-15 12:44:28 +01002008static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07002009{
Johannes Berg46900292009-02-15 12:44:28 +01002010 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002011 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07002012
Johannes Berg24487982009-04-23 18:52:52 +02002013 /* Reset own TSF to allow time synchronization work. */
2014 drv_reset_tsf(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07002015
Johannes Berg46900292009-02-15 12:44:28 +01002016 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
Jiri Bencf0706e82007-05-05 11:45:53 -07002017
2018
Johannes Berg46900292009-02-15 12:44:28 +01002019 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
2020 ifmgd->auth_alg = WLAN_AUTH_OPEN;
2021 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
2022 ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY;
2023 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
2024 ifmgd->auth_alg = WLAN_AUTH_LEAP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02002025 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
2026 ifmgd->auth_alg = WLAN_AUTH_FT;
Jiri Bencf0706e82007-05-05 11:45:53 -07002027 else
Johannes Berg46900292009-02-15 12:44:28 +01002028 ifmgd->auth_alg = WLAN_AUTH_OPEN;
2029 ifmgd->auth_transaction = -1;
2030 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
2031 ifmgd->assoc_scan_tries = 0;
2032 ifmgd->direct_probe_tries = 0;
2033 ifmgd->auth_tries = 0;
2034 ifmgd->assoc_tries = 0;
Tomas Winkler24e64622008-09-08 17:33:40 +02002035 netif_tx_stop_all_queues(sdata->dev);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002036 netif_carrier_off(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07002037}
2038
Johannes Berg46900292009-02-15 12:44:28 +01002039static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07002040{
Johannes Berg46900292009-02-15 12:44:28 +01002041 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002042 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02002043 struct ieee80211_bss *bss;
Johannes Berg46900292009-02-15 12:44:28 +01002044 u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
2045 u8 ssid_len = ifmgd->ssid_len;
Johannes Berg00d3f142009-02-10 21:26:00 +01002046 u16 capa_mask = WLAN_CAPABILITY_ESS;
2047 u16 capa_val = WLAN_CAPABILITY_ESS;
2048 struct ieee80211_channel *chan = local->oper_channel;
Johannes Berg60f8b392008-09-08 17:44:22 +02002049
Jouni Malinen636a5d32009-03-19 13:39:22 +02002050 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
2051 ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
Johannes Berg00d3f142009-02-10 21:26:00 +01002052 IEEE80211_STA_AUTO_BSSID_SEL |
2053 IEEE80211_STA_AUTO_CHANNEL_SEL)) {
2054 capa_mask |= WLAN_CAPABILITY_PRIVACY;
2055 if (sdata->default_key)
2056 capa_val |= WLAN_CAPABILITY_PRIVACY;
Johannes Berg60f8b392008-09-08 17:44:22 +02002057 }
Johannes Berg60f8b392008-09-08 17:44:22 +02002058
Johannes Berg46900292009-02-15 12:44:28 +01002059 if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
Johannes Berg00d3f142009-02-10 21:26:00 +01002060 chan = NULL;
2061
Johannes Berg46900292009-02-15 12:44:28 +01002062 if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
Johannes Berg00d3f142009-02-10 21:26:00 +01002063 bssid = NULL;
2064
Johannes Berg46900292009-02-15 12:44:28 +01002065 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
Johannes Berg00d3f142009-02-10 21:26:00 +01002066 ssid = NULL;
2067 ssid_len = 0;
2068 }
2069
2070 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan,
2071 bssid, ssid, ssid_len,
2072 capa_mask, capa_val);
2073
2074 if (bss) {
2075 ieee80211_set_freq(sdata, bss->cbss.channel->center_freq);
Johannes Berg46900292009-02-15 12:44:28 +01002076 if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
Johannes Berg00d3f142009-02-10 21:26:00 +01002077 ieee80211_sta_set_ssid(sdata, bss->ssid,
2078 bss->ssid_len);
2079 ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
2080 ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
2081 bss->supp_rates);
Johannes Berg46900292009-02-15 12:44:28 +01002082 if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
2083 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
Jouni Malinenfdfacf02009-01-08 13:32:05 +02002084 else
Johannes Berg46900292009-02-15 12:44:28 +01002085 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
Johannes Berg60f8b392008-09-08 17:44:22 +02002086
2087 /* Send out direct probe if no probe resp was received or
2088 * the one we have is outdated
2089 */
Johannes Berg00d3f142009-02-10 21:26:00 +01002090 if (!bss->last_probe_resp ||
2091 time_after(jiffies, bss->last_probe_resp
Johannes Berg60f8b392008-09-08 17:44:22 +02002092 + IEEE80211_SCAN_RESULT_EXPIRE))
Johannes Berg46900292009-02-15 12:44:28 +01002093 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
Johannes Berg60f8b392008-09-08 17:44:22 +02002094 else
Johannes Berg46900292009-02-15 12:44:28 +01002095 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
Johannes Berg60f8b392008-09-08 17:44:22 +02002096
Johannes Berg00d3f142009-02-10 21:26:00 +01002097 ieee80211_rx_bss_put(local, bss);
Johannes Berg46900292009-02-15 12:44:28 +01002098 ieee80211_sta_reset_auth(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002099 return 0;
2100 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002101 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
Johannes Bergf3b85252009-04-23 16:01:47 +02002102
2103 ifmgd->assoc_scan_tries++;
2104
2105 ieee80211_request_internal_scan(sdata, ifmgd->ssid,
2106 ssid_len);
Helmut Schaaaf88b902009-03-09 15:47:08 +01002107
Johannes Berg46900292009-02-15 12:44:28 +01002108 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
2109 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
Sujithe3740552009-01-29 09:34:22 +05302110 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002111 ifmgd->assoc_scan_tries = 0;
2112 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +02002113 ieee80211_recalc_idle(local);
Sujithe3740552009-01-29 09:34:22 +05302114 }
Johannes Berg60f8b392008-09-08 17:44:22 +02002115 }
2116 return -1;
2117}
2118
2119
Johannes Berg9c6bd792008-09-11 00:01:52 +02002120static void ieee80211_sta_work(struct work_struct *work)
Johannes Berg60f8b392008-09-08 17:44:22 +02002121{
2122 struct ieee80211_sub_if_data *sdata =
Johannes Berg46900292009-02-15 12:44:28 +01002123 container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
Johannes Berg60f8b392008-09-08 17:44:22 +02002124 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01002125 struct ieee80211_if_managed *ifmgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002126 struct sk_buff *skb;
2127
2128 if (!netif_running(sdata->dev))
2129 return;
2130
Johannes Bergc2b13452008-09-11 00:01:55 +02002131 if (local->sw_scanning || local->hw_scanning)
Johannes Berg60f8b392008-09-08 17:44:22 +02002132 return;
2133
Johannes Berg46900292009-02-15 12:44:28 +01002134 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg60f8b392008-09-08 17:44:22 +02002135 return;
Johannes Berg46900292009-02-15 12:44:28 +01002136 ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002137
Johannes Berg46900292009-02-15 12:44:28 +01002138 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
Johannes Berg60f8b392008-09-08 17:44:22 +02002139 ieee80211_sta_rx_queued_mgmt(sdata, skb);
2140
Johannes Berg46900292009-02-15 12:44:28 +01002141 if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
2142 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
2143 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
2144 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
Johannes Bergf3b85252009-04-23 16:01:47 +02002145 queue_delayed_work(local->hw.workqueue, &local->scan_work,
2146 round_jiffies_relative(0));
Johannes Berg60f8b392008-09-08 17:44:22 +02002147 return;
2148 }
2149
Johannes Berg46900292009-02-15 12:44:28 +01002150 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) {
2151 if (ieee80211_sta_config_auth(sdata))
Johannes Berg60f8b392008-09-08 17:44:22 +02002152 return;
Johannes Berg46900292009-02-15 12:44:28 +01002153 clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
2154 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
Johannes Berg60f8b392008-09-08 17:44:22 +02002155 return;
2156
Johannes Berg5cff20e2009-04-29 12:26:17 +02002157 ieee80211_recalc_idle(local);
2158
Johannes Berg46900292009-02-15 12:44:28 +01002159 switch (ifmgd->state) {
Johannes Berg60f8b392008-09-08 17:44:22 +02002160 case IEEE80211_STA_MLME_DISABLED:
2161 break;
2162 case IEEE80211_STA_MLME_DIRECT_PROBE:
Johannes Berg46900292009-02-15 12:44:28 +01002163 ieee80211_direct_probe(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002164 break;
2165 case IEEE80211_STA_MLME_AUTHENTICATE:
Johannes Berg46900292009-02-15 12:44:28 +01002166 ieee80211_authenticate(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002167 break;
2168 case IEEE80211_STA_MLME_ASSOCIATE:
Johannes Berg46900292009-02-15 12:44:28 +01002169 ieee80211_associate(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002170 break;
2171 case IEEE80211_STA_MLME_ASSOCIATED:
Johannes Berg46900292009-02-15 12:44:28 +01002172 ieee80211_associated(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002173 break;
Johannes Berg60f8b392008-09-08 17:44:22 +02002174 default:
2175 WARN_ON(1);
2176 break;
2177 }
2178
Johannes Berg46900292009-02-15 12:44:28 +01002179 if (ieee80211_privacy_mismatch(sdata)) {
Johannes Berg60f8b392008-09-08 17:44:22 +02002180 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
2181 "mixed-cell disabled - disassociate\n", sdata->dev->name);
2182
Johannes Berg46900292009-02-15 12:44:28 +01002183 ieee80211_set_disassoc(sdata, false, true,
Johannes Berg60f8b392008-09-08 17:44:22 +02002184 WLAN_REASON_UNSPECIFIED);
2185 }
2186}
Johannes Berg0a51b272008-09-08 17:44:25 +02002187
Johannes Berga1678f82008-09-11 00:01:47 +02002188static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2189{
Kalle Vaload935682009-04-19 08:47:19 +03002190 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2191 /*
2192 * Need to update last_beacon to avoid beacon loss
2193 * test to trigger.
2194 */
2195 sdata->u.mgd.last_beacon = jiffies;
2196
2197
Johannes Berg7c950692008-09-11 00:01:48 +02002198 queue_work(sdata->local->hw.workqueue,
Johannes Berg46900292009-02-15 12:44:28 +01002199 &sdata->u.mgd.work);
Kalle Vaload935682009-04-19 08:47:19 +03002200 }
Johannes Berga1678f82008-09-11 00:01:47 +02002201}
2202
Johannes Berg9c6bd792008-09-11 00:01:52 +02002203/* interface setup */
2204void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2205{
Johannes Berg46900292009-02-15 12:44:28 +01002206 struct ieee80211_if_managed *ifmgd;
Johannes Bergbbbdff92009-04-16 13:27:42 +02002207 u32 hw_flags;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002208
Johannes Berg46900292009-02-15 12:44:28 +01002209 ifmgd = &sdata->u.mgd;
2210 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
2211 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002212 INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
Johannes Berg46900292009-02-15 12:44:28 +01002213 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002214 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002215 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05302216 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002217 skb_queue_head_init(&ifmgd->skb_queue);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002218
Johannes Berg46900292009-02-15 12:44:28 +01002219 ifmgd->capab = WLAN_CAPABILITY_ESS;
2220 ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002221 IEEE80211_AUTH_ALG_SHARED_KEY;
Johannes Berg46900292009-02-15 12:44:28 +01002222 ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002223 IEEE80211_STA_AUTO_BSSID_SEL |
2224 IEEE80211_STA_AUTO_CHANNEL_SEL;
Johannes Berg176be722009-03-12 23:49:28 +01002225 if (sdata->local->hw.queues >= 4)
Johannes Berg46900292009-02-15 12:44:28 +01002226 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
Johannes Bergbbbdff92009-04-16 13:27:42 +02002227
2228 hw_flags = sdata->local->hw.flags;
2229
2230 if (hw_flags & IEEE80211_HW_SUPPORTS_PS) {
2231 ifmgd->powersave = CONFIG_MAC80211_DEFAULT_PS_VALUE;
2232 sdata->local->hw.conf.dynamic_ps_timeout = 500;
2233 }
Johannes Berg9c6bd792008-09-11 00:01:52 +02002234}
2235
2236/* configuration hooks */
Johannes Berg46900292009-02-15 12:44:28 +01002237void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002238{
Johannes Berg46900292009-02-15 12:44:28 +01002239 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002240 struct ieee80211_local *local = sdata->local;
2241
Johannes Berg46900292009-02-15 12:44:28 +01002242 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg9c6bd792008-09-11 00:01:52 +02002243 return;
2244
Johannes Berg46900292009-02-15 12:44:28 +01002245 if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002246 IEEE80211_STA_AUTO_BSSID_SEL)) &&
Johannes Berg46900292009-02-15 12:44:28 +01002247 (ifmgd->flags & (IEEE80211_STA_SSID_SET |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002248 IEEE80211_STA_AUTO_SSID_SEL))) {
2249
Johannes Berg46900292009-02-15 12:44:28 +01002250 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2251 ieee80211_set_disassoc(sdata, true, true,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002252 WLAN_REASON_DEAUTH_LEAVING);
2253
Jouni Malinen636a5d32009-03-19 13:39:22 +02002254 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) ||
2255 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
2256 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
2257 else if (ifmgd->flags & IEEE80211_STA_EXT_SME)
2258 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
Johannes Berg46900292009-02-15 12:44:28 +01002259 queue_work(local->hw.workqueue, &ifmgd->work);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002260 }
2261}
2262
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002263int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata)
2264{
2265 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2266
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002267 if (ifmgd->ssid_len)
2268 ifmgd->flags |= IEEE80211_STA_SSID_SET;
2269 else
2270 ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
2271
2272 return 0;
2273}
2274
Johannes Berg9c6bd792008-09-11 00:01:52 +02002275int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
2276{
Johannes Berg46900292009-02-15 12:44:28 +01002277 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002278
2279 if (len > IEEE80211_MAX_SSID_LEN)
2280 return -EINVAL;
2281
Johannes Berg46900292009-02-15 12:44:28 +01002282 ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002283
Johannes Berg46900292009-02-15 12:44:28 +01002284 if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) {
Jouni Malinena2995422009-03-19 13:39:20 +02002285 /*
2286 * Do not use reassociation if SSID is changed (different ESS).
2287 */
2288 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Johannes Berg46900292009-02-15 12:44:28 +01002289 memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
2290 memcpy(ifmgd->ssid, ssid, len);
2291 ifmgd->ssid_len = len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002292 }
2293
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002294 return ieee80211_sta_commit(sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002295}
2296
2297int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
2298{
Johannes Berg46900292009-02-15 12:44:28 +01002299 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2300 memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len);
2301 *len = ifmgd->ssid_len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002302 return 0;
2303}
2304
2305int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2306{
Johannes Berg46900292009-02-15 12:44:28 +01002307 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002308
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002309 if (is_valid_ether_addr(bssid)) {
Johannes Berg46900292009-02-15 12:44:28 +01002310 memcpy(ifmgd->bssid, bssid, ETH_ALEN);
2311 ifmgd->flags |= IEEE80211_STA_BSSID_SET;
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002312 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002313 memset(ifmgd->bssid, 0, ETH_ALEN);
2314 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002315 }
2316
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002317 if (netif_running(sdata->dev))
2318 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002319
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002320 return ieee80211_sta_commit(sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002321}
2322
Jouni Malinen636a5d32009-03-19 13:39:22 +02002323int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
2324 const char *ie, size_t len)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002325{
Johannes Berg46900292009-02-15 12:44:28 +01002326 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002327
Johannes Berg46900292009-02-15 12:44:28 +01002328 kfree(ifmgd->extra_ie);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002329 if (len == 0) {
Johannes Berg46900292009-02-15 12:44:28 +01002330 ifmgd->extra_ie = NULL;
2331 ifmgd->extra_ie_len = 0;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002332 return 0;
2333 }
Johannes Berg46900292009-02-15 12:44:28 +01002334 ifmgd->extra_ie = kmalloc(len, GFP_KERNEL);
2335 if (!ifmgd->extra_ie) {
2336 ifmgd->extra_ie_len = 0;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002337 return -ENOMEM;
2338 }
Johannes Berg46900292009-02-15 12:44:28 +01002339 memcpy(ifmgd->extra_ie, ie, len);
2340 ifmgd->extra_ie_len = len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002341 return 0;
2342}
2343
2344int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
2345{
Johannes Berg9c6bd792008-09-11 00:01:52 +02002346 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2347 sdata->dev->name, reason);
2348
Johannes Berg46900292009-02-15 12:44:28 +01002349 ieee80211_set_disassoc(sdata, true, true, reason);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002350 return 0;
2351}
2352
2353int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
2354{
Johannes Berg46900292009-02-15 12:44:28 +01002355 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002356
2357 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2358 sdata->dev->name, reason);
2359
Johannes Berg46900292009-02-15 12:44:28 +01002360 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
2361 return -ENOLINK;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002362
Johannes Berg46900292009-02-15 12:44:28 +01002363 ieee80211_set_disassoc(sdata, false, true, reason);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002364 return 0;
2365}
2366
2367/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002368void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2369{
2370 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002371
2372 /* Restart STA timers */
2373 rcu_read_lock();
2374 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2375 ieee80211_restart_sta_timer(sdata);
2376 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02002377}
Johannes Berg10f644a2009-04-16 13:17:25 +02002378
2379int ieee80211_max_network_latency(struct notifier_block *nb,
2380 unsigned long data, void *dummy)
2381{
2382 s32 latency_usec = (s32) data;
2383 struct ieee80211_local *local =
2384 container_of(nb, struct ieee80211_local,
2385 network_latency_notifier);
2386
2387 mutex_lock(&local->iflist_mtx);
2388 ieee80211_recalc_ps(local, latency_usec);
2389 mutex_unlock(&local->iflist_mtx);
2390
2391 return 0;
2392}