ath9k: Fix bug in determining HT40 mode
[deliverable/linux.git] / net / mac80211 / mlme.c
CommitLineData
f0706e82
JB
1/*
2 * BSS client mode implementation
5394af4d 3 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
f0706e82
JB
4 * 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
5b323edb 14#include <linux/delay.h>
f0706e82
JB
15#include <linux/if_ether.h>
16#include <linux/skbuff.h>
f0706e82 17#include <linux/if_arp.h>
f0706e82 18#include <linux/etherdevice.h>
d0709a65 19#include <linux/rtnetlink.h>
f0706e82 20#include <net/mac80211.h>
472dbc45 21#include <asm/unaligned.h>
60f8b39c 22
f0706e82 23#include "ieee80211_i.h"
2c8dccc7
JB
24#include "rate.h"
25#include "led.h"
f0706e82 26
6042a3e3 27#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
f0706e82
JB
28#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
29#define IEEE80211_AUTH_MAX_TRIES 3
30#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
31#define IEEE80211_ASSOC_MAX_TRIES 3
32#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
15b7b062 33#define IEEE80211_PROBE_IDLE_TIME (60 * HZ)
f0706e82 34#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
f0706e82 35
5484e237
JB
36/* utils */
37static int ecw2cw(int ecw)
60f8b39c 38{
5484e237 39 return (1 << ecw) - 1;
60f8b39c
JB
40}
41
c2b13452 42static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
43ac2ca3
JM
43{
44 u8 *end, *pos;
45
00d3f14c 46 pos = bss->cbss.information_elements;
43ac2ca3
JM
47 if (pos == NULL)
48 return NULL;
00d3f14c 49 end = pos + bss->cbss.len_information_elements;
43ac2ca3
JM
50
51 while (pos + 1 < end) {
52 if (pos + 2 + pos[1] > end)
53 break;
54 if (pos[0] == ie)
55 return pos;
56 pos += 2 + pos[1];
57 }
58
59 return NULL;
60}
61
c2b13452 62static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
9ac19a90 63 struct ieee80211_supported_band *sband,
881d948c 64 u32 *rates)
9ac19a90
JB
65{
66 int i, j, count;
67 *rates = 0;
68 count = 0;
69 for (i = 0; i < bss->supp_rates_len; i++) {
70 int rate = (bss->supp_rates[i] & 0x7F) * 5;
71
72 for (j = 0; j < sband->n_bitrates; j++)
73 if (sband->bitrates[j].bitrate == rate) {
74 *rates |= BIT(j);
75 count++;
76 break;
77 }
78 }
79
80 return count;
81}
82
9c6bd790
JB
83/* frame sending functions */
84
46900298 85static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
9ac19a90 86{
46900298 87 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
9ac19a90
JB
88 struct ieee80211_local *local = sdata->local;
89 struct sk_buff *skb;
90 struct ieee80211_mgmt *mgmt;
65fc73ac 91 u8 *pos, *ies, *ht_ie;
9ac19a90
JB
92 int i, len, count, rates_len, supp_rates_len;
93 u16 capab;
c2b13452 94 struct ieee80211_bss *bss;
9ac19a90
JB
95 int wmm = 0;
96 struct ieee80211_supported_band *sband;
881d948c 97 u32 rates = 0;
9ac19a90
JB
98
99 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
46900298 100 sizeof(*mgmt) + 200 + ifmgd->extra_ie_len +
65fc73ac 101 ifmgd->ssid_len);
9ac19a90
JB
102 if (!skb) {
103 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
104 "frame\n", sdata->dev->name);
105 return;
106 }
107 skb_reserve(skb, local->hw.extra_tx_headroom);
108
109 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
110
46900298 111 capab = ifmgd->capab;
9ac19a90
JB
112
113 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
114 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
115 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
116 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
117 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
118 }
119
46900298 120 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
9ac19a90 121 local->hw.conf.channel->center_freq,
46900298 122 ifmgd->ssid, ifmgd->ssid_len);
9ac19a90 123 if (bss) {
00d3f14c 124 if (bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
9ac19a90
JB
125 capab |= WLAN_CAPABILITY_PRIVACY;
126 if (bss->wmm_used)
127 wmm = 1;
128
129 /* get all rates supported by the device and the AP as
130 * some APs don't like getting a superset of their rates
131 * in the association request (e.g. D-Link DAP 1353 in
132 * b-only mode) */
133 rates_len = ieee80211_compatible_rates(bss, sband, &rates);
134
00d3f14c 135 if ((bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
9ac19a90
JB
136 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
137 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
138
139 ieee80211_rx_bss_put(local, bss);
140 } else {
141 rates = ~0;
142 rates_len = sband->n_bitrates;
143 }
144
145 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
146 memset(mgmt, 0, 24);
46900298 147 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
9ac19a90 148 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
46900298 149 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
9ac19a90 150
46900298 151 if (ifmgd->flags & IEEE80211_STA_PREV_BSSID_SET) {
9ac19a90
JB
152 skb_put(skb, 10);
153 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
154 IEEE80211_STYPE_REASSOC_REQ);
155 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
156 mgmt->u.reassoc_req.listen_interval =
157 cpu_to_le16(local->hw.conf.listen_interval);
46900298 158 memcpy(mgmt->u.reassoc_req.current_ap, ifmgd->prev_bssid,
9ac19a90
JB
159 ETH_ALEN);
160 } else {
161 skb_put(skb, 4);
162 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
163 IEEE80211_STYPE_ASSOC_REQ);
164 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
13554121 165 mgmt->u.assoc_req.listen_interval =
9ac19a90
JB
166 cpu_to_le16(local->hw.conf.listen_interval);
167 }
168
169 /* SSID */
46900298 170 ies = pos = skb_put(skb, 2 + ifmgd->ssid_len);
9ac19a90 171 *pos++ = WLAN_EID_SSID;
46900298
JB
172 *pos++ = ifmgd->ssid_len;
173 memcpy(pos, ifmgd->ssid, ifmgd->ssid_len);
9ac19a90
JB
174
175 /* add all rates which were marked to be used above */
176 supp_rates_len = rates_len;
177 if (supp_rates_len > 8)
178 supp_rates_len = 8;
179
180 len = sband->n_bitrates;
181 pos = skb_put(skb, supp_rates_len + 2);
182 *pos++ = WLAN_EID_SUPP_RATES;
183 *pos++ = supp_rates_len;
184
185 count = 0;
186 for (i = 0; i < sband->n_bitrates; i++) {
187 if (BIT(i) & rates) {
188 int rate = sband->bitrates[i].bitrate;
189 *pos++ = (u8) (rate / 5);
190 if (++count == 8)
191 break;
192 }
193 }
194
195 if (rates_len > count) {
196 pos = skb_put(skb, rates_len - count + 2);
197 *pos++ = WLAN_EID_EXT_SUPP_RATES;
198 *pos++ = rates_len - count;
199
200 for (i++; i < sband->n_bitrates; i++) {
201 if (BIT(i) & rates) {
202 int rate = sband->bitrates[i].bitrate;
203 *pos++ = (u8) (rate / 5);
204 }
205 }
206 }
207
208 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
209 /* 1. power capabilities */
210 pos = skb_put(skb, 4);
211 *pos++ = WLAN_EID_PWR_CAPABILITY;
212 *pos++ = 2;
213 *pos++ = 0; /* min tx power */
214 *pos++ = local->hw.conf.channel->max_power; /* max tx power */
215
216 /* 2. supported channels */
217 /* TODO: get this in reg domain format */
218 pos = skb_put(skb, 2 * sband->n_channels + 2);
219 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
220 *pos++ = 2 * sband->n_channels;
221 for (i = 0; i < sband->n_channels; i++) {
222 *pos++ = ieee80211_frequency_to_channel(
223 sband->channels[i].center_freq);
224 *pos++ = 1; /* one channel in the subband*/
225 }
226 }
227
46900298
JB
228 if (ifmgd->extra_ie) {
229 pos = skb_put(skb, ifmgd->extra_ie_len);
230 memcpy(pos, ifmgd->extra_ie, ifmgd->extra_ie_len);
9ac19a90
JB
231 }
232
46900298 233 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
9ac19a90
JB
234 pos = skb_put(skb, 9);
235 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
236 *pos++ = 7; /* len */
237 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
238 *pos++ = 0x50;
239 *pos++ = 0xf2;
240 *pos++ = 2; /* WME */
241 *pos++ = 0; /* WME info */
242 *pos++ = 1; /* WME ver */
243 *pos++ = 0;
244 }
245
246 /* wmm support is a must to HT */
eb46936b
VT
247 /*
248 * IEEE802.11n does not allow TKIP/WEP as pairwise
249 * ciphers in HT mode. We still associate in non-ht
250 * mode (11a/b/g) if any one of these ciphers is
251 * configured as pairwise.
252 */
46900298 253 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
d9fe60de
JB
254 sband->ht_cap.ht_supported &&
255 (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) &&
eb46936b 256 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
46900298 257 (!(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))) {
d9fe60de
JB
258 struct ieee80211_ht_info *ht_info =
259 (struct ieee80211_ht_info *)(ht_ie + 2);
260 u16 cap = sband->ht_cap.cap;
9ac19a90
JB
261 __le16 tmp;
262 u32 flags = local->hw.conf.channel->flags;
263
d9fe60de
JB
264 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
265 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
9ac19a90 266 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
d9fe60de 267 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
9ac19a90
JB
268 cap &= ~IEEE80211_HT_CAP_SGI_40;
269 }
270 break;
d9fe60de 271 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
9ac19a90 272 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
d9fe60de 273 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
9ac19a90
JB
274 cap &= ~IEEE80211_HT_CAP_SGI_40;
275 }
276 break;
277 }
278
279 tmp = cpu_to_le16(cap);
280 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
281 *pos++ = WLAN_EID_HT_CAPABILITY;
282 *pos++ = sizeof(struct ieee80211_ht_cap);
283 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
284 memcpy(pos, &tmp, sizeof(u16));
285 pos += sizeof(u16);
286 /* TODO: needs a define here for << 2 */
d9fe60de
JB
287 *pos++ = sband->ht_cap.ampdu_factor |
288 (sband->ht_cap.ampdu_density << 2);
289 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
9ac19a90
JB
290 }
291
46900298
JB
292 kfree(ifmgd->assocreq_ies);
293 ifmgd->assocreq_ies_len = (skb->data + skb->len) - ies;
294 ifmgd->assocreq_ies = kmalloc(ifmgd->assocreq_ies_len, GFP_KERNEL);
295 if (ifmgd->assocreq_ies)
296 memcpy(ifmgd->assocreq_ies, ies, ifmgd->assocreq_ies_len);
9ac19a90 297
e50db65c 298 ieee80211_tx_skb(sdata, skb, 0);
9ac19a90
JB
299}
300
301
ef422bc0
JB
302static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
303 u16 stype, u16 reason)
9ac19a90
JB
304{
305 struct ieee80211_local *local = sdata->local;
46900298 306 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
9ac19a90
JB
307 struct sk_buff *skb;
308 struct ieee80211_mgmt *mgmt;
9aed3cc1 309
65fc73ac 310 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
9ac19a90 311 if (!skb) {
ef422bc0
JB
312 printk(KERN_DEBUG "%s: failed to allocate buffer for "
313 "deauth/disassoc frame\n", sdata->dev->name);
9ac19a90
JB
314 return;
315 }
316 skb_reserve(skb, local->hw.extra_tx_headroom);
317
318 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
319 memset(mgmt, 0, 24);
46900298 320 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
9ac19a90 321 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
46900298 322 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
ef422bc0 323 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
9ac19a90 324 skb_put(skb, 2);
ef422bc0 325 /* u.deauth.reason_code == u.disassoc.reason_code */
9ac19a90
JB
326 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
327
53b46b84
JM
328 if (stype == IEEE80211_STYPE_DEAUTH)
329 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len);
330 else
331 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len);
46900298 332 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
9ac19a90
JB
333}
334
572e0012
KV
335void ieee80211_send_pspoll(struct ieee80211_local *local,
336 struct ieee80211_sub_if_data *sdata)
337{
46900298 338 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
572e0012
KV
339 struct ieee80211_pspoll *pspoll;
340 struct sk_buff *skb;
341 u16 fc;
342
343 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
344 if (!skb) {
345 printk(KERN_DEBUG "%s: failed to allocate buffer for "
346 "pspoll frame\n", sdata->dev->name);
347 return;
348 }
349 skb_reserve(skb, local->hw.extra_tx_headroom);
350
351 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
352 memset(pspoll, 0, sizeof(*pspoll));
353 fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
354 pspoll->frame_control = cpu_to_le16(fc);
46900298 355 pspoll->aid = cpu_to_le16(ifmgd->aid);
572e0012
KV
356
357 /* aid in PS-Poll has its two MSBs each set to 1 */
358 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
359
46900298 360 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
572e0012
KV
361 memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN);
362
363 ieee80211_tx_skb(sdata, skb, 0);
572e0012
KV
364}
365
60f8b39c 366/* MLME */
f698d856 367static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
46900298 368 struct ieee80211_if_managed *ifmgd,
f0706e82
JB
369 u8 *wmm_param, size_t wmm_param_len)
370{
f0706e82
JB
371 struct ieee80211_tx_queue_params params;
372 size_t left;
373 int count;
374 u8 *pos;
375
46900298 376 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED))
3434fbd3
JB
377 return;
378
379 if (!wmm_param)
380 return;
381
f0706e82
JB
382 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
383 return;
384 count = wmm_param[6] & 0x0f;
46900298 385 if (count == ifmgd->wmm_last_param_set)
f0706e82 386 return;
46900298 387 ifmgd->wmm_last_param_set = count;
f0706e82
JB
388
389 pos = wmm_param + 8;
390 left = wmm_param_len - 8;
391
392 memset(&params, 0, sizeof(params));
393
f0706e82
JB
394 local->wmm_acm = 0;
395 for (; left >= 4; left -= 4, pos += 4) {
396 int aci = (pos[0] >> 5) & 0x03;
397 int acm = (pos[0] >> 4) & 0x01;
398 int queue;
399
400 switch (aci) {
0eeb59fe 401 case 1: /* AC_BK */
e100bb64 402 queue = 3;
988c0f72 403 if (acm)
0eeb59fe 404 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
f0706e82 405 break;
0eeb59fe 406 case 2: /* AC_VI */
e100bb64 407 queue = 1;
988c0f72 408 if (acm)
0eeb59fe 409 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
f0706e82 410 break;
0eeb59fe 411 case 3: /* AC_VO */
e100bb64 412 queue = 0;
988c0f72 413 if (acm)
0eeb59fe 414 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
f0706e82 415 break;
0eeb59fe 416 case 0: /* AC_BE */
f0706e82 417 default:
e100bb64 418 queue = 2;
988c0f72 419 if (acm)
0eeb59fe 420 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
f0706e82
JB
421 break;
422 }
423
424 params.aifs = pos[0] & 0x0f;
425 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
426 params.cw_min = ecw2cw(pos[1] & 0x0f);
f434b2d1 427 params.txop = get_unaligned_le16(pos + 2);
f4ea83dd 428#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
f0706e82 429 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
3330d7be 430 "cWmin=%d cWmax=%d txop=%d\n",
f698d856 431 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
3330d7be
JB
432 params.cw_max, params.txop);
433#endif
0eeb59fe
JM
434 if (local->ops->conf_tx &&
435 local->ops->conf_tx(local_to_hw(local), queue, &params)) {
f0706e82 436 printk(KERN_DEBUG "%s: failed to set TX queue "
f698d856 437 "parameters for queue %d\n", local->mdev->name, queue);
f0706e82
JB
438 }
439 }
440}
441
1fb3606b 442static bool ieee80211_check_tim(struct ieee802_11_elems *elems, u16 aid)
a97b77b9
VN
443{
444 u8 mask;
445 u8 index, indexn1, indexn2;
446 struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
447
60375541
JB
448 if (unlikely(!tim || elems->tim_len < 4))
449 return false;
450
a97b77b9
VN
451 aid &= 0x3fff;
452 index = aid / 8;
453 mask = 1 << (aid & 7);
454
a97b77b9
VN
455 indexn1 = tim->bitmap_ctrl & 0xfe;
456 indexn2 = elems->tim_len + indexn1 - 4;
457
458 if (index < indexn1 || index > indexn2)
459 return false;
460
461 index -= indexn1;
462
463 return !!(tim->virtual_map[index] & mask);
464}
465
7a5158ef
JB
466static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
467 u16 capab, bool erp_valid, u8 erp)
5628221c 468{
bda3933a 469 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
ebd74487 470#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
46900298 471 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
ebd74487 472#endif
471b3efd 473 u32 changed = 0;
7a5158ef
JB
474 bool use_protection;
475 bool use_short_preamble;
476 bool use_short_slot;
477
478 if (erp_valid) {
479 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
480 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
481 } else {
482 use_protection = false;
483 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
484 }
485
486 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
5628221c 487
471b3efd 488 if (use_protection != bss_conf->use_cts_prot) {
f4ea83dd 489#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
5628221c 490 if (net_ratelimit()) {
0c68ae26 491 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
471b3efd 492 sdata->dev->name,
5628221c 493 use_protection ? "enabled" : "disabled",
46900298 494 ifmgd->bssid);
5628221c 495 }
f4ea83dd 496#endif
471b3efd
JB
497 bss_conf->use_cts_prot = use_protection;
498 changed |= BSS_CHANGED_ERP_CTS_PROT;
5628221c 499 }
7e9ed188 500
d43c7b37 501 if (use_short_preamble != bss_conf->use_short_preamble) {
f4ea83dd 502#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
7e9ed188
DD
503 if (net_ratelimit()) {
504 printk(KERN_DEBUG "%s: switched to %s barker preamble"
0c68ae26 505 " (BSSID=%pM)\n",
471b3efd 506 sdata->dev->name,
d43c7b37 507 use_short_preamble ? "short" : "long",
46900298 508 ifmgd->bssid);
7e9ed188 509 }
f4ea83dd 510#endif
d43c7b37 511 bss_conf->use_short_preamble = use_short_preamble;
471b3efd 512 changed |= BSS_CHANGED_ERP_PREAMBLE;
7e9ed188 513 }
d9430a32 514
7a5158ef
JB
515 if (use_short_slot != bss_conf->use_short_slot) {
516#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
517 if (net_ratelimit()) {
391429c1
CL
518 printk(KERN_DEBUG "%s: switched to %s slot time"
519 " (BSSID=%pM)\n",
7a5158ef
JB
520 sdata->dev->name,
521 use_short_slot ? "short" : "long",
46900298 522 ifmgd->bssid);
7a5158ef
JB
523 }
524#endif
525 bss_conf->use_short_slot = use_short_slot;
526 changed |= BSS_CHANGED_ERP_SLOT;
50c4afb9
JL
527 }
528
529 return changed;
530}
531
46900298 532static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
f5e5bf25
TW
533{
534 union iwreq_data wrqu;
46900298 535
f5e5bf25 536 memset(&wrqu, 0, sizeof(wrqu));
46900298
JB
537 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
538 memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
f5e5bf25
TW
539 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
540 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
541}
542
46900298 543static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
f0706e82 544{
46900298 545 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
74af0250
LT
546 char *buf;
547 size_t len;
548 int i;
f0706e82
JB
549 union iwreq_data wrqu;
550
46900298 551 if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
74af0250
LT
552 return;
553
46900298
JB
554 buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
555 ifmgd->assocresp_ies_len), GFP_KERNEL);
74af0250
LT
556 if (!buf)
557 return;
558
559 len = sprintf(buf, "ASSOCINFO(");
46900298 560 if (ifmgd->assocreq_ies) {
74af0250 561 len += sprintf(buf + len, "ReqIEs=");
46900298 562 for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
74af0250 563 len += sprintf(buf + len, "%02x",
46900298 564 ifmgd->assocreq_ies[i]);
74af0250 565 }
f0706e82 566 }
46900298
JB
567 if (ifmgd->assocresp_ies) {
568 if (ifmgd->assocreq_ies)
74af0250
LT
569 len += sprintf(buf + len, " ");
570 len += sprintf(buf + len, "RespIEs=");
46900298 571 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
74af0250 572 len += sprintf(buf + len, "%02x",
46900298 573 ifmgd->assocresp_ies[i]);
74af0250 574 }
f0706e82 575 }
74af0250
LT
576 len += sprintf(buf + len, ")");
577
578 if (len > IW_CUSTOM_MAX) {
579 len = sprintf(buf, "ASSOCRESPIE=");
46900298 580 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
74af0250 581 len += sprintf(buf + len, "%02x",
46900298 582 ifmgd->assocresp_ies[i]);
74af0250
LT
583 }
584 }
585
ad788b5e
JL
586 if (len <= IW_CUSTOM_MAX) {
587 memset(&wrqu, 0, sizeof(wrqu));
588 wrqu.data.length = len;
589 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
590 }
74af0250
LT
591
592 kfree(buf);
f0706e82
JB
593}
594
595
f698d856 596static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
ae5eb026 597 u32 bss_info_changed)
f0706e82 598{
46900298 599 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
471b3efd 600 struct ieee80211_local *local = sdata->local;
38668c05 601 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
f0706e82 602
c2b13452 603 struct ieee80211_bss *bss;
d6f2da5b 604
ae5eb026 605 bss_info_changed |= BSS_CHANGED_ASSOC;
46900298 606 ifmgd->flags |= IEEE80211_STA_ASSOCIATED;
5628221c 607
46900298 608 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
f5e5bf25 609 conf->channel->center_freq,
46900298 610 ifmgd->ssid, ifmgd->ssid_len);
f5e5bf25
TW
611 if (bss) {
612 /* set timing information */
00d3f14c
JB
613 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
614 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
bda3933a 615 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
21c0cbe7 616
ae5eb026 617 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
00d3f14c 618 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
9ac19a90 619
04de8381
KV
620 cfg80211_hold_bss(&bss->cbss);
621
9ac19a90 622 ieee80211_rx_bss_put(local, bss);
f0706e82
JB
623 }
624
46900298
JB
625 ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
626 memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
627 ieee80211_sta_send_associnfo(sdata);
9306102e 628
46900298 629 ifmgd->last_probe = jiffies;
9ac19a90 630 ieee80211_led_assoc(local, 1);
9306102e 631
bda3933a 632 sdata->vif.bss_conf.assoc = 1;
96dd22ac
JB
633 /*
634 * For now just always ask the driver to update the basic rateset
635 * when we have associated, we aren't checking whether it actually
636 * changed or not.
637 */
ae5eb026
JB
638 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
639 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
f0706e82 640
4be8c387
JB
641 if (local->powersave) {
642 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) &&
643 local->hw.conf.dynamic_ps_timeout > 0) {
520eb820 644 mod_timer(&local->dynamic_ps_timer, jiffies +
46f2c4bd
JB
645 msecs_to_jiffies(
646 local->hw.conf.dynamic_ps_timeout));
4be8c387
JB
647 } else {
648 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
649 ieee80211_send_nullfunc(local, sdata, 1);
520eb820 650 conf->flags |= IEEE80211_CONF_PS;
4be8c387 651 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
520eb820 652 }
e0cb686f
KV
653 }
654
9ac19a90
JB
655 netif_tx_start_all_queues(sdata->dev);
656 netif_carrier_on(sdata->dev);
f0706e82 657
46900298 658 ieee80211_sta_send_apinfo(sdata);
f0706e82
JB
659}
660
46900298 661static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
f0706e82 662{
46900298 663 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
11432379 664 struct ieee80211_local *local = sdata->local;
46900298
JB
665
666 ifmgd->direct_probe_tries++;
667 if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
0c68ae26 668 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
46900298
JB
669 sdata->dev->name, ifmgd->bssid);
670 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
671 ieee80211_sta_send_apinfo(sdata);
7a947080
VT
672
673 /*
674 * Most likely AP is not in the range so remove the
675 * bss information associated to the AP
676 */
46900298 677 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
7a947080 678 sdata->local->hw.conf.channel->center_freq,
46900298 679 ifmgd->ssid, ifmgd->ssid_len);
11432379
HS
680
681 /*
682 * We might have a pending scan which had no chance to run yet
683 * due to state == IEEE80211_STA_MLME_DIRECT_PROBE.
684 * Hence, queue the STAs work again
685 */
686 queue_work(local->hw.workqueue, &ifmgd->work);
f0706e82
JB
687 return;
688 }
f0706e82 689
0c68ae26 690 printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
46900298
JB
691 sdata->dev->name, ifmgd->bssid,
692 ifmgd->direct_probe_tries);
f0706e82 693
46900298 694 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
f0706e82 695
46900298 696 set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifmgd->request);
9ac19a90
JB
697
698 /* Direct probe is sent to broadcast address as some APs
699 * will not answer to direct packet in unassociated state.
700 */
701 ieee80211_send_probe_req(sdata, NULL,
70692ad2 702 ifmgd->ssid, ifmgd->ssid_len, NULL, 0);
9ac19a90 703
46900298 704 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
60f8b39c 705}
f0706e82 706
9ac19a90 707
46900298 708static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
f0706e82 709{
46900298 710 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
11432379 711 struct ieee80211_local *local = sdata->local;
636a5d36
JM
712 u8 *ies;
713 size_t ies_len;
46900298
JB
714
715 ifmgd->auth_tries++;
716 if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
0c68ae26 717 printk(KERN_DEBUG "%s: authentication with AP %pM"
9ac19a90 718 " timed out\n",
46900298
JB
719 sdata->dev->name, ifmgd->bssid);
720 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
721 ieee80211_sta_send_apinfo(sdata);
722 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
7a947080 723 sdata->local->hw.conf.channel->center_freq,
46900298 724 ifmgd->ssid, ifmgd->ssid_len);
11432379
HS
725
726 /*
727 * We might have a pending scan which had no chance to run yet
728 * due to state == IEEE80211_STA_MLME_AUTHENTICATE.
729 * Hence, queue the STAs work again
730 */
731 queue_work(local->hw.workqueue, &ifmgd->work);
f0706e82
JB
732 return;
733 }
f0706e82 734
46900298 735 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
0c68ae26 736 printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
46900298 737 sdata->dev->name, ifmgd->bssid);
f0706e82 738
636a5d36
JM
739 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
740 ies = ifmgd->sme_auth_ie;
741 ies_len = ifmgd->sme_auth_ie_len;
742 } else {
743 ies = NULL;
744 ies_len = 0;
745 }
746 ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len,
46900298
JB
747 ifmgd->bssid, 0);
748 ifmgd->auth_transaction = 2;
9ac19a90 749
46900298 750 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
f0706e82
JB
751}
752
5925d976
VN
753/*
754 * The disassoc 'reason' argument can be either our own reason
755 * if self disconnected or a reason code from the AP.
756 */
aa458d17 757static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
46900298
JB
758 bool deauth, bool self_disconnected,
759 u16 reason)
aa458d17 760{
46900298 761 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
aa458d17 762 struct ieee80211_local *local = sdata->local;
04de8381
KV
763 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
764 struct ieee80211_bss *bss;
aa458d17 765 struct sta_info *sta;
e0cb686f 766 u32 changed = 0, config_changed = 0;
aa458d17
TW
767
768 rcu_read_lock();
769
46900298 770 sta = sta_info_get(local, ifmgd->bssid);
aa458d17
TW
771 if (!sta) {
772 rcu_read_unlock();
773 return;
774 }
775
776 if (deauth) {
46900298
JB
777 ifmgd->direct_probe_tries = 0;
778 ifmgd->auth_tries = 0;
aa458d17 779 }
46900298
JB
780 ifmgd->assoc_scan_tries = 0;
781 ifmgd->assoc_tries = 0;
aa458d17 782
24e64622 783 netif_tx_stop_all_queues(sdata->dev);
aa458d17
TW
784 netif_carrier_off(sdata->dev);
785
2dace10e 786 ieee80211_sta_tear_down_BA_sessions(sta);
aa458d17 787
04de8381
KV
788 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
789 conf->channel->center_freq,
790 ifmgd->ssid, ifmgd->ssid_len);
791
792 if (bss) {
793 cfg80211_unhold_bss(&bss->cbss);
794 ieee80211_rx_bss_put(local, bss);
795 }
796
aa458d17
TW
797 if (self_disconnected) {
798 if (deauth)
ef422bc0
JB
799 ieee80211_send_deauth_disassoc(sdata,
800 IEEE80211_STYPE_DEAUTH, reason);
aa458d17 801 else
ef422bc0
JB
802 ieee80211_send_deauth_disassoc(sdata,
803 IEEE80211_STYPE_DISASSOC, reason);
aa458d17
TW
804 }
805
46900298 806 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
f5e5bf25
TW
807 changed |= ieee80211_reset_erp_info(sdata);
808
f5e5bf25 809 ieee80211_led_assoc(local, 0);
ae5eb026
JB
810 changed |= BSS_CHANGED_ASSOC;
811 sdata->vif.bss_conf.assoc = false;
f5e5bf25 812
46900298 813 ieee80211_sta_send_apinfo(sdata);
aa458d17 814
7a947080 815 if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
46900298
JB
816 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
817 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
7a947080 818 sdata->local->hw.conf.channel->center_freq,
46900298 819 ifmgd->ssid, ifmgd->ssid_len);
7a947080 820 }
aa458d17 821
aa458d17
TW
822 rcu_read_unlock();
823
4797938c 824 /* channel(_type) changes are handled by ieee80211_hw_config */
094d05dc 825 local->oper_channel_type = NL80211_CHAN_NO_HT;
e0cb686f 826
a8302de9
VT
827 local->power_constr_level = 0;
828
520eb820
KV
829 del_timer_sync(&local->dynamic_ps_timer);
830 cancel_work_sync(&local->dynamic_ps_enable_work);
831
e0cb686f
KV
832 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
833 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
834 config_changed |= IEEE80211_CONF_CHANGE_PS;
835 }
ae5eb026 836
e0cb686f 837 ieee80211_hw_config(local, config_changed);
ae5eb026 838 ieee80211_bss_info_change_notify(sdata, changed);
8e268e47
TW
839
840 rcu_read_lock();
841
46900298 842 sta = sta_info_get(local, ifmgd->bssid);
8e268e47
TW
843 if (!sta) {
844 rcu_read_unlock();
845 return;
846 }
847
848 sta_info_unlink(&sta);
849
850 rcu_read_unlock();
851
852 sta_info_destroy(sta);
aa458d17 853}
f0706e82 854
9ac19a90
JB
855static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
856{
857 if (!sdata || !sdata->default_key ||
858 sdata->default_key->conf.alg != ALG_WEP)
859 return 0;
860 return 1;
861}
862
46900298 863static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
f0706e82 864{
46900298 865 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
f698d856 866 struct ieee80211_local *local = sdata->local;
c2b13452 867 struct ieee80211_bss *bss;
5b98b1f7
JB
868 int bss_privacy;
869 int wep_privacy;
870 int privacy_invoked;
f0706e82 871
7986cf95 872 if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
f0706e82
JB
873 return 0;
874
46900298 875 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
8318d78a 876 local->hw.conf.channel->center_freq,
46900298 877 ifmgd->ssid, ifmgd->ssid_len);
f0706e82
JB
878 if (!bss)
879 return 0;
880
00d3f14c 881 bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
f698d856 882 wep_privacy = !!ieee80211_sta_wep_configured(sdata);
46900298 883 privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
f0706e82 884
3e122be0 885 ieee80211_rx_bss_put(local, bss);
f0706e82 886
5b98b1f7
JB
887 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
888 return 0;
889
890 return 1;
f0706e82
JB
891}
892
46900298 893static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
f0706e82 894{
46900298 895 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
11432379 896 struct ieee80211_local *local = sdata->local;
46900298
JB
897
898 ifmgd->assoc_tries++;
899 if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
0c68ae26 900 printk(KERN_DEBUG "%s: association with AP %pM"
f0706e82 901 " timed out\n",
46900298
JB
902 sdata->dev->name, ifmgd->bssid);
903 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
904 ieee80211_sta_send_apinfo(sdata);
905 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
7a947080 906 sdata->local->hw.conf.channel->center_freq,
46900298 907 ifmgd->ssid, ifmgd->ssid_len);
11432379
HS
908 /*
909 * We might have a pending scan which had no chance to run yet
910 * due to state == IEEE80211_STA_MLME_ASSOCIATE.
911 * Hence, queue the STAs work again
912 */
913 queue_work(local->hw.workqueue, &ifmgd->work);
f0706e82
JB
914 return;
915 }
916
46900298 917 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
0c68ae26 918 printk(KERN_DEBUG "%s: associate with AP %pM\n",
46900298
JB
919 sdata->dev->name, ifmgd->bssid);
920 if (ieee80211_privacy_mismatch(sdata)) {
f0706e82 921 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
f698d856 922 "mixed-cell disabled - abort association\n", sdata->dev->name);
46900298 923 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
f0706e82
JB
924 return;
925 }
926
46900298 927 ieee80211_send_assoc(sdata);
f0706e82 928
46900298 929 mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
f0706e82
JB
930}
931
3cf335d5
KV
932void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
933 struct ieee80211_hdr *hdr)
934{
935 /*
936 * We can postpone the mgd.timer whenever receiving unicast frames
937 * from AP because we know that the connection is working both ways
938 * at that time. But multicast frames (and hence also beacons) must
939 * be ignored here, because we need to trigger the timer during
940 * data idle periods for sending the periodical probe request to
941 * the AP.
942 */
943 if (!is_multicast_ether_addr(hdr->addr1))
944 mod_timer(&sdata->u.mgd.timer,
945 jiffies + IEEE80211_MONITORING_INTERVAL);
946}
f0706e82 947
04de8381
KV
948void ieee80211_beacon_loss_work(struct work_struct *work)
949{
950 struct ieee80211_sub_if_data *sdata =
951 container_of(work, struct ieee80211_sub_if_data,
952 u.mgd.beacon_loss_work);
953 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
954
a860402d
MB
955#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
956 if (net_ratelimit()) {
957 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
958 "- sending probe request\n", sdata->dev->name,
959 sdata->u.mgd.bssid);
960 }
961#endif
04de8381
KV
962
963 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
964 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
965 ifmgd->ssid_len, NULL, 0);
966
967 mod_timer(&ifmgd->timer, jiffies + IEEE80211_MONITORING_INTERVAL);
968}
969
970void ieee80211_beacon_loss(struct ieee80211_vif *vif)
971{
972 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
973
974 queue_work(sdata->local->hw.workqueue,
975 &sdata->u.mgd.beacon_loss_work);
976}
977EXPORT_SYMBOL(ieee80211_beacon_loss);
978
46900298 979static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
f0706e82 980{
46900298 981 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
f698d856 982 struct ieee80211_local *local = sdata->local;
f0706e82 983 struct sta_info *sta;
15b7b062 984 bool disassoc = false;
f0706e82
JB
985
986 /* TODO: start monitoring current AP signal quality and number of
987 * missed beacons. Scan other channels every now and then and search
988 * for better APs. */
989 /* TODO: remove expired BSSes */
990
46900298 991 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED;
f0706e82 992
d0709a65
JB
993 rcu_read_lock();
994
46900298 995 sta = sta_info_get(local, ifmgd->bssid);
f0706e82 996 if (!sta) {
0c68ae26 997 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
46900298 998 sdata->dev->name, ifmgd->bssid);
15b7b062
KV
999 disassoc = true;
1000 goto unlock;
1001 }
1002
1003 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
1004 time_after(jiffies, sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
1005 printk(KERN_DEBUG "%s: no probe response from AP %pM "
1006 "- disassociating\n",
1007 sdata->dev->name, ifmgd->bssid);
1008 disassoc = true;
1009 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1010 goto unlock;
1011 }
1012
04de8381
KV
1013 /*
1014 * Beacon filtering is only enabled with power save and then the
1015 * stack should not check for beacon loss.
1016 */
1017 if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) &&
1018 (local->hw.conf.flags & IEEE80211_CONF_PS)) &&
1019 time_after(jiffies,
15b7b062 1020 ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
a860402d
MB
1021#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1022 if (net_ratelimit()) {
1023 printk(KERN_DEBUG "%s: beacon loss from AP %pM "
1024 "- sending probe request\n",
1025 sdata->dev->name, ifmgd->bssid);
1026 }
1027#endif
15b7b062
KV
1028 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1029 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1030 ifmgd->ssid_len, NULL, 0);
1031 goto unlock;
1032
1033 }
1034
1035 if (time_after(jiffies, sta->last_rx + IEEE80211_PROBE_IDLE_TIME)) {
1036 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1037 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1038 ifmgd->ssid_len, NULL, 0);
f0706e82 1039 }
d0709a65 1040
15b7b062 1041 unlock:
d0709a65
JB
1042 rcu_read_unlock();
1043
7a947080 1044 if (disassoc)
46900298 1045 ieee80211_set_disassoc(sdata, true, true,
60f8b39c 1046 WLAN_REASON_PREV_AUTH_NOT_VALID);
7a947080 1047 else
46900298 1048 mod_timer(&ifmgd->timer, jiffies +
60f8b39c 1049 IEEE80211_MONITORING_INTERVAL);
f0706e82
JB
1050}
1051
1052
46900298 1053static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
f0706e82 1054{
46900298
JB
1055 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1056
f698d856 1057 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
46900298 1058 ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
636a5d36
JM
1059 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1060 /* Wait for SME to request association */
1061 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1062 } else
1063 ieee80211_associate(sdata);
f0706e82
JB
1064}
1065
1066
f698d856 1067static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
f0706e82
JB
1068 struct ieee80211_mgmt *mgmt,
1069 size_t len)
1070{
1071 u8 *pos;
1072 struct ieee802_11_elems elems;
1073
f0706e82 1074 pos = mgmt->u.auth.variable;
67a4cce4 1075 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
f4ea83dd 1076 if (!elems.challenge)
f0706e82 1077 return;
46900298
JB
1078 ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg,
1079 elems.challenge - 2, elems.challenge_len + 2,
1080 sdata->u.mgd.bssid, 1);
1081 sdata->u.mgd.auth_transaction = 4;
fe3d2c3f
JB
1082}
1083
f698d856 1084static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
f0706e82
JB
1085 struct ieee80211_mgmt *mgmt,
1086 size_t len)
1087{
46900298 1088 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
f0706e82
JB
1089 u16 auth_alg, auth_transaction, status_code;
1090
46900298 1091 if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE)
f0706e82 1092 return;
f0706e82 1093
f4ea83dd 1094 if (len < 24 + 6)
f0706e82 1095 return;
f0706e82 1096
46900298 1097 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
f0706e82 1098 return;
f0706e82 1099
46900298 1100 if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
f0706e82 1101 return;
f0706e82
JB
1102
1103 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1104 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1105 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1106
46900298
JB
1107 if (auth_alg != ifmgd->auth_alg ||
1108 auth_transaction != ifmgd->auth_transaction)
f0706e82 1109 return;
f0706e82
JB
1110
1111 if (status_code != WLAN_STATUS_SUCCESS) {
f0706e82
JB
1112 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1113 u8 algs[3];
1114 const int num_algs = ARRAY_SIZE(algs);
1115 int i, pos;
1116 algs[0] = algs[1] = algs[2] = 0xff;
46900298 1117 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
f0706e82 1118 algs[0] = WLAN_AUTH_OPEN;
46900298 1119 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
f0706e82 1120 algs[1] = WLAN_AUTH_SHARED_KEY;
46900298 1121 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
f0706e82 1122 algs[2] = WLAN_AUTH_LEAP;
46900298 1123 if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
f0706e82 1124 pos = 0;
46900298 1125 else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
f0706e82
JB
1126 pos = 1;
1127 else
1128 pos = 2;
1129 for (i = 0; i < num_algs; i++) {
1130 pos++;
1131 if (pos >= num_algs)
1132 pos = 0;
46900298 1133 if (algs[pos] == ifmgd->auth_alg ||
f0706e82
JB
1134 algs[pos] == 0xff)
1135 continue;
1136 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
f698d856 1137 !ieee80211_sta_wep_configured(sdata))
f0706e82 1138 continue;
46900298 1139 ifmgd->auth_alg = algs[pos];
f0706e82
JB
1140 break;
1141 }
1142 }
1143 return;
1144 }
1145
46900298 1146 switch (ifmgd->auth_alg) {
f0706e82
JB
1147 case WLAN_AUTH_OPEN:
1148 case WLAN_AUTH_LEAP:
636a5d36 1149 case WLAN_AUTH_FT:
46900298 1150 ieee80211_auth_completed(sdata);
6039f6d2 1151 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
f0706e82
JB
1152 break;
1153 case WLAN_AUTH_SHARED_KEY:
6039f6d2 1154 if (ifmgd->auth_transaction == 4) {
46900298 1155 ieee80211_auth_completed(sdata);
6039f6d2
JM
1156 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
1157 } else
46900298 1158 ieee80211_auth_challenge(sdata, mgmt, len);
f0706e82
JB
1159 break;
1160 }
1161}
1162
1163
f698d856 1164static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
f0706e82
JB
1165 struct ieee80211_mgmt *mgmt,
1166 size_t len)
1167{
46900298 1168 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
f0706e82
JB
1169 u16 reason_code;
1170
f4ea83dd 1171 if (len < 24 + 2)
f0706e82 1172 return;
f0706e82 1173
46900298 1174 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
f0706e82 1175 return;
f0706e82
JB
1176
1177 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1178
46900298 1179 if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED)
97c8b013
ZY
1180 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
1181 sdata->dev->name, reason_code);
f0706e82 1182
636a5d36
JM
1183 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1184 (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
1185 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE ||
1186 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) {
46900298
JB
1187 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
1188 mod_timer(&ifmgd->timer, jiffies +
f0706e82
JB
1189 IEEE80211_RETRY_AUTH_INTERVAL);
1190 }
1191
46900298
JB
1192 ieee80211_set_disassoc(sdata, true, false, 0);
1193 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
53b46b84 1194 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
f0706e82
JB
1195}
1196
1197
f698d856 1198static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
f0706e82
JB
1199 struct ieee80211_mgmt *mgmt,
1200 size_t len)
1201{
46900298 1202 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
f0706e82
JB
1203 u16 reason_code;
1204
f4ea83dd 1205 if (len < 24 + 2)
f0706e82 1206 return;
f0706e82 1207
46900298 1208 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
f0706e82 1209 return;
f0706e82
JB
1210
1211 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1212
46900298 1213 if (ifmgd->flags & IEEE80211_STA_ASSOCIATED)
97c8b013
ZY
1214 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1215 sdata->dev->name, reason_code);
f0706e82 1216
636a5d36
JM
1217 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1218 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) {
46900298
JB
1219 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
1220 mod_timer(&ifmgd->timer, jiffies +
f0706e82
JB
1221 IEEE80211_RETRY_AUTH_INTERVAL);
1222 }
1223
46900298 1224 ieee80211_set_disassoc(sdata, false, false, reason_code);
53b46b84 1225 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
f0706e82
JB
1226}
1227
1228
471b3efd 1229static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
f0706e82
JB
1230 struct ieee80211_mgmt *mgmt,
1231 size_t len,
1232 int reassoc)
1233{
46900298 1234 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
471b3efd 1235 struct ieee80211_local *local = sdata->local;
8318d78a 1236 struct ieee80211_supported_band *sband;
f0706e82 1237 struct sta_info *sta;
881d948c 1238 u32 rates, basic_rates;
f0706e82
JB
1239 u16 capab_info, status_code, aid;
1240 struct ieee802_11_elems elems;
bda3933a 1241 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
f0706e82 1242 u8 *pos;
ae5eb026 1243 u32 changed = 0;
f0706e82 1244 int i, j;
ddf4ac53 1245 bool have_higher_than_11mbit = false, newsta = false;
ae5eb026 1246 u16 ap_ht_cap_flags;
f0706e82
JB
1247
1248 /* AssocResp and ReassocResp have identical structure, so process both
1249 * of them in this function. */
1250
46900298 1251 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
f0706e82 1252 return;
f0706e82 1253
f4ea83dd 1254 if (len < 24 + 6)
f0706e82 1255 return;
f0706e82 1256
46900298 1257 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
f0706e82 1258 return;
f0706e82
JB
1259
1260 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1261 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1262 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
f0706e82 1263
0c68ae26 1264 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
f0706e82 1265 "status=%d aid=%d)\n",
0c68ae26 1266 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
ddd68587 1267 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
f0706e82 1268
63a5ab82
JM
1269 pos = mgmt->u.assoc_resp.variable;
1270 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1271
1272 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
f797eb7e
JM
1273 elems.timeout_int && elems.timeout_int_len == 5 &&
1274 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
63a5ab82 1275 u32 tu, ms;
f797eb7e 1276 tu = get_unaligned_le32(elems.timeout_int + 1);
63a5ab82
JM
1277 ms = tu * 1024 / 1000;
1278 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1279 "comeback duration %u TU (%u ms)\n",
1280 sdata->dev->name, tu, ms);
1281 if (ms > IEEE80211_ASSOC_TIMEOUT)
46900298 1282 mod_timer(&ifmgd->timer,
63a5ab82
JM
1283 jiffies + msecs_to_jiffies(ms));
1284 return;
1285 }
1286
f0706e82
JB
1287 if (status_code != WLAN_STATUS_SUCCESS) {
1288 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
f698d856 1289 sdata->dev->name, status_code);
8a69aa93
DD
1290 /* if this was a reassociation, ensure we try a "full"
1291 * association next time. This works around some broken APs
1292 * which do not correctly reject reassociation requests. */
46900298 1293 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
f0706e82
JB
1294 return;
1295 }
1296
1dd84aa2
JB
1297 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1298 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
f698d856 1299 "set\n", sdata->dev->name, aid);
1dd84aa2
JB
1300 aid &= ~(BIT(15) | BIT(14));
1301
f0706e82
JB
1302 if (!elems.supp_rates) {
1303 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
f698d856 1304 sdata->dev->name);
f0706e82
JB
1305 return;
1306 }
1307
f698d856 1308 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
46900298
JB
1309 ifmgd->aid = aid;
1310 ifmgd->ap_capab = capab_info;
f0706e82 1311
46900298
JB
1312 kfree(ifmgd->assocresp_ies);
1313 ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1314 ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
1315 if (ifmgd->assocresp_ies)
1316 memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
f0706e82 1317
d0709a65
JB
1318 rcu_read_lock();
1319
f0706e82 1320 /* Add STA entry for the AP */
46900298 1321 sta = sta_info_get(local, ifmgd->bssid);
f0706e82 1322 if (!sta) {
ddf4ac53 1323 newsta = true;
d0709a65 1324
46900298 1325 sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC);
73651ee6
JB
1326 if (!sta) {
1327 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
f698d856 1328 " the AP\n", sdata->dev->name);
d0709a65 1329 rcu_read_unlock();
f0706e82
JB
1330 return;
1331 }
f709fc69 1332
60f8b39c
JB
1333 /* update new sta with its last rx activity */
1334 sta->last_rx = jiffies;
f709fc69 1335 }
f709fc69 1336
60f8b39c
JB
1337 /*
1338 * FIXME: Do we really need to update the sta_info's information here?
1339 * We already know about the AP (we found it in our list) so it
1340 * should already be filled with the right info, no?
1341 * As is stands, all this is racy because typically we assume
1342 * the information that is filled in here (except flags) doesn't
1343 * change while a STA structure is alive. As such, it should move
1344 * to between the sta_info_alloc() and sta_info_insert() above.
1345 */
f709fc69 1346
60f8b39c
JB
1347 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1348 WLAN_STA_AUTHORIZED);
05e5e883 1349
60f8b39c
JB
1350 rates = 0;
1351 basic_rates = 0;
1352 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
f709fc69 1353
60f8b39c
JB
1354 for (i = 0; i < elems.supp_rates_len; i++) {
1355 int rate = (elems.supp_rates[i] & 0x7f) * 5;
d61272cb 1356 bool is_basic = !!(elems.supp_rates[i] & 0x80);
f709fc69 1357
60f8b39c
JB
1358 if (rate > 110)
1359 have_higher_than_11mbit = true;
1360
1361 for (j = 0; j < sband->n_bitrates; j++) {
d61272cb 1362 if (sband->bitrates[j].bitrate == rate) {
60f8b39c 1363 rates |= BIT(j);
d61272cb
TW
1364 if (is_basic)
1365 basic_rates |= BIT(j);
1366 break;
1367 }
f709fc69 1368 }
f709fc69
LCC
1369 }
1370
60f8b39c
JB
1371 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1372 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
7e0986c1 1373 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
f0706e82 1374
60f8b39c
JB
1375 if (rate > 110)
1376 have_higher_than_11mbit = true;
f0706e82 1377
60f8b39c 1378 for (j = 0; j < sband->n_bitrates; j++) {
d61272cb 1379 if (sband->bitrates[j].bitrate == rate) {
60f8b39c 1380 rates |= BIT(j);
d61272cb
TW
1381 if (is_basic)
1382 basic_rates |= BIT(j);
1383 break;
1384 }
60f8b39c 1385 }
1ebebea8 1386 }
f0706e82 1387
323ce79a 1388 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
bda3933a 1389 sdata->vif.bss_conf.basic_rates = basic_rates;
60f8b39c
JB
1390
1391 /* cf. IEEE 802.11 9.2.12 */
1392 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1393 have_higher_than_11mbit)
1394 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1395 else
1396 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
f0706e82 1397
e65c2263
S
1398 /* If TKIP/WEP is used, no need to parse AP's HT capabilities */
1399 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
ae5eb026 1400 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
d9fe60de 1401 elems.ht_cap_elem, &sta->sta.ht_cap);
ae5eb026
JB
1402
1403 ap_ht_cap_flags = sta->sta.ht_cap.cap;
f0706e82 1404
4b7679a5 1405 rate_control_rate_init(sta);
f0706e82 1406
46900298 1407 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
5394af4d
JM
1408 set_sta_flags(sta, WLAN_STA_MFP);
1409
ddf4ac53 1410 if (elems.wmm_param)
60f8b39c 1411 set_sta_flags(sta, WLAN_STA_WME);
ddf4ac53
JB
1412
1413 if (newsta) {
1414 int err = sta_info_insert(sta);
1415 if (err) {
1416 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1417 " the AP (error %d)\n", sdata->dev->name, err);
1418 rcu_read_unlock();
1419 return;
1420 }
1421 }
1422
1423 rcu_read_unlock();
1424
1425 if (elems.wmm_param)
46900298 1426 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
60f8b39c 1427 elems.wmm_param_len);
f0706e82 1428
ae5eb026 1429 if (elems.ht_info_elem && elems.wmm_param &&
46900298
JB
1430 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
1431 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
ae5eb026
JB
1432 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1433 ap_ht_cap_flags);
1434
60f8b39c
JB
1435 /* set AID and assoc capability,
1436 * ieee80211_set_associated() will tell the driver */
1437 bss_conf->aid = aid;
1438 bss_conf->assoc_capability = capab_info;
46900298 1439 ieee80211_set_associated(sdata, changed);
f0706e82 1440
15b7b062
KV
1441 /*
1442 * initialise the time of last beacon to be the association time,
1443 * otherwise beacon loss check will trigger immediately
1444 */
1445 ifmgd->last_beacon = jiffies;
1446
46900298 1447 ieee80211_associated(sdata);
6039f6d2 1448 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
f0706e82
JB
1449}
1450
1451
98c8fccf
JB
1452static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1453 struct ieee80211_mgmt *mgmt,
1454 size_t len,
1455 struct ieee80211_rx_status *rx_status,
1456 struct ieee802_11_elems *elems,
1457 bool beacon)
1458{
1459 struct ieee80211_local *local = sdata->local;
1460 int freq;
c2b13452 1461 struct ieee80211_bss *bss;
98c8fccf 1462 struct ieee80211_channel *channel;
98c8fccf
JB
1463
1464 if (elems->ds_params && elems->ds_params_len == 1)
1465 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
1466 else
1467 freq = rx_status->freq;
1468
1469 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1470
1471 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1472 return;
1473
98c8fccf 1474 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
2a519311 1475 channel, beacon);
98c8fccf
JB
1476 if (!bss)
1477 return;
1478
c481ec97 1479 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
46900298 1480 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
c481ec97
S
1481 struct ieee80211_channel_sw_ie *sw_elem =
1482 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
1483 ieee80211_process_chanswitch(sdata, sw_elem, bss);
1484 }
1485
3e122be0 1486 ieee80211_rx_bss_put(local, bss);
f0706e82
JB
1487}
1488
1489
f698d856 1490static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
f0706e82
JB
1491 struct ieee80211_mgmt *mgmt,
1492 size_t len,
1493 struct ieee80211_rx_status *rx_status)
1494{
15b7b062 1495 struct ieee80211_if_managed *ifmgd;
ae6a44e3
EK
1496 size_t baselen;
1497 struct ieee802_11_elems elems;
1498
15b7b062
KV
1499 ifmgd = &sdata->u.mgd;
1500
8e7cdbb6
TW
1501 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
1502 return; /* ignore ProbeResp to foreign address */
1503
ae6a44e3
EK
1504 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1505 if (baselen > len)
1506 return;
1507
1508 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1509 &elems);
1510
98c8fccf 1511 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
9859b81e
RR
1512
1513 /* direct probe may be part of the association flow */
1514 if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
15b7b062 1515 &ifmgd->request)) {
9859b81e
RR
1516 printk(KERN_DEBUG "%s direct probe responded\n",
1517 sdata->dev->name);
46900298 1518 ieee80211_authenticate(sdata);
9859b81e 1519 }
15b7b062
KV
1520
1521 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1522 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
f0706e82
JB
1523}
1524
f698d856 1525static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
f0706e82
JB
1526 struct ieee80211_mgmt *mgmt,
1527 size_t len,
1528 struct ieee80211_rx_status *rx_status)
1529{
46900298 1530 struct ieee80211_if_managed *ifmgd;
f0706e82
JB
1531 size_t baselen;
1532 struct ieee802_11_elems elems;
f698d856 1533 struct ieee80211_local *local = sdata->local;
471b3efd 1534 u32 changed = 0;
1fb3606b 1535 bool erp_valid, directed_tim;
7a5158ef 1536 u8 erp_value = 0;
f0706e82 1537
ae6a44e3
EK
1538 /* Process beacon from the current BSS */
1539 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1540 if (baselen > len)
1541 return;
1542
1543 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
1544
98c8fccf 1545 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
f0706e82 1546
05c914fe 1547 if (sdata->vif.type != NL80211_IFTYPE_STATION)
f0706e82 1548 return;
f0706e82 1549
46900298
JB
1550 ifmgd = &sdata->u.mgd;
1551
1552 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
1553 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
f0706e82
JB
1554 return;
1555
c481ec97
S
1556 if (rx_status->freq != local->hw.conf.channel->center_freq)
1557 return;
1558
46900298 1559 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
fe3fa827
JB
1560 elems.wmm_param_len);
1561
25c9c875 1562 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
46900298 1563 directed_tim = ieee80211_check_tim(&elems, ifmgd->aid);
a97b77b9 1564
1fb3606b 1565 if (directed_tim) {
572e0012
KV
1566 if (local->hw.conf.dynamic_ps_timeout > 0) {
1567 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1568 ieee80211_hw_config(local,
1569 IEEE80211_CONF_CHANGE_PS);
1570 ieee80211_send_nullfunc(local, sdata, 0);
1571 } else {
1572 local->pspolling = true;
1573
1574 /*
1575 * Here is assumed that the driver will be
1576 * able to send ps-poll frame and receive a
1577 * response even though power save mode is
1578 * enabled, but some drivers might require
1579 * to disable power save here. This needs
1580 * to be investigated.
1581 */
1582 ieee80211_send_pspoll(local, sdata);
1583 }
a97b77b9
VN
1584 }
1585 }
7a5158ef
JB
1586
1587 if (elems.erp_info && elems.erp_info_len >= 1) {
1588 erp_valid = true;
1589 erp_value = elems.erp_info[0];
1590 } else {
1591 erp_valid = false;
50c4afb9 1592 }
7a5158ef
JB
1593 changed |= ieee80211_handle_bss_capability(sdata,
1594 le16_to_cpu(mgmt->u.beacon.capab_info),
1595 erp_valid, erp_value);
f0706e82 1596
d3c990fb 1597
53d6f81c 1598 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
46900298 1599 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) {
ae5eb026
JB
1600 struct sta_info *sta;
1601 struct ieee80211_supported_band *sband;
1602 u16 ap_ht_cap_flags;
1603
1604 rcu_read_lock();
1605
46900298 1606 sta = sta_info_get(local, ifmgd->bssid);
ae5eb026
JB
1607 if (!sta) {
1608 rcu_read_unlock();
1609 return;
1610 }
1611
1612 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1613
1614 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1615 elems.ht_cap_elem, &sta->sta.ht_cap);
1616
1617 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1618
1619 rcu_read_unlock();
1620
1621 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1622 ap_ht_cap_flags);
d3c990fb
RR
1623 }
1624
3f2355cb
LR
1625 if (elems.country_elem) {
1626 /* Note we are only reviewing this on beacons
1627 * for the BSSID we are associated to */
1628 regulatory_hint_11d(local->hw.wiphy,
1629 elems.country_elem, elems.country_elem_len);
a8302de9
VT
1630
1631 /* TODO: IBSS also needs this */
1632 if (elems.pwr_constr_elem)
1633 ieee80211_handle_pwr_constr(sdata,
1634 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1635 elems.pwr_constr_elem,
1636 elems.pwr_constr_elem_len);
3f2355cb
LR
1637 }
1638
471b3efd 1639 ieee80211_bss_info_change_notify(sdata, changed);
f0706e82
JB
1640}
1641
46900298
JB
1642ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1643 struct sk_buff *skb,
1644 struct ieee80211_rx_status *rx_status)
f0706e82 1645{
f698d856 1646 struct ieee80211_local *local = sdata->local;
f0706e82
JB
1647 struct ieee80211_mgmt *mgmt;
1648 u16 fc;
1649
1650 if (skb->len < 24)
46900298 1651 return RX_DROP_MONITOR;
f0706e82
JB
1652
1653 mgmt = (struct ieee80211_mgmt *) skb->data;
1654 fc = le16_to_cpu(mgmt->frame_control);
1655
1656 switch (fc & IEEE80211_FCTL_STYPE) {
1657 case IEEE80211_STYPE_PROBE_REQ:
1658 case IEEE80211_STYPE_PROBE_RESP:
1659 case IEEE80211_STYPE_BEACON:
1660 memcpy(skb->cb, rx_status, sizeof(*rx_status));
1661 case IEEE80211_STYPE_AUTH:
1662 case IEEE80211_STYPE_ASSOC_RESP:
1663 case IEEE80211_STYPE_REASSOC_RESP:
1664 case IEEE80211_STYPE_DEAUTH:
1665 case IEEE80211_STYPE_DISASSOC:
46900298
JB
1666 skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
1667 queue_work(local->hw.workqueue, &sdata->u.mgd.work);
1668 return RX_QUEUED;
f0706e82
JB
1669 }
1670
46900298 1671 return RX_DROP_MONITOR;
f0706e82
JB
1672}
1673
f698d856 1674static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
f0706e82
JB
1675 struct sk_buff *skb)
1676{
1677 struct ieee80211_rx_status *rx_status;
f0706e82
JB
1678 struct ieee80211_mgmt *mgmt;
1679 u16 fc;
1680
f0706e82
JB
1681 rx_status = (struct ieee80211_rx_status *) skb->cb;
1682 mgmt = (struct ieee80211_mgmt *) skb->data;
1683 fc = le16_to_cpu(mgmt->frame_control);
1684
46900298
JB
1685 switch (fc & IEEE80211_FCTL_STYPE) {
1686 case IEEE80211_STYPE_PROBE_RESP:
1687 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
1688 rx_status);
1689 break;
1690 case IEEE80211_STYPE_BEACON:
1691 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1692 rx_status);
1693 break;
1694 case IEEE80211_STYPE_AUTH:
1695 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
1696 break;
1697 case IEEE80211_STYPE_ASSOC_RESP:
1698 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0);
1699 break;
1700 case IEEE80211_STYPE_REASSOC_RESP:
1701 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1);
1702 break;
1703 case IEEE80211_STYPE_DEAUTH:
1704 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
1705 break;
1706 case IEEE80211_STYPE_DISASSOC:
1707 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1708 break;
f0706e82
JB
1709 }
1710
1711 kfree_skb(skb);
1712}
1713
9c6bd790 1714static void ieee80211_sta_timer(unsigned long data)
f0706e82 1715{
60f8b39c
JB
1716 struct ieee80211_sub_if_data *sdata =
1717 (struct ieee80211_sub_if_data *) data;
46900298 1718 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
60f8b39c 1719 struct ieee80211_local *local = sdata->local;
f0706e82 1720
46900298
JB
1721 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
1722 queue_work(local->hw.workqueue, &ifmgd->work);
f0706e82
JB
1723}
1724
46900298 1725static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
f0706e82 1726{
46900298 1727 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
f698d856 1728 struct ieee80211_local *local = sdata->local;
f0706e82
JB
1729
1730 if (local->ops->reset_tsf) {
1731 /* Reset own TSF to allow time synchronization work. */
1732 local->ops->reset_tsf(local_to_hw(local));
1733 }
1734
46900298 1735 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
f0706e82
JB
1736
1737
46900298
JB
1738 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1739 ifmgd->auth_alg = WLAN_AUTH_OPEN;
1740 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1741 ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY;
1742 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1743 ifmgd->auth_alg = WLAN_AUTH_LEAP;
636a5d36
JM
1744 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
1745 ifmgd->auth_alg = WLAN_AUTH_FT;
f0706e82 1746 else
46900298
JB
1747 ifmgd->auth_alg = WLAN_AUTH_OPEN;
1748 ifmgd->auth_transaction = -1;
1749 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
1750 ifmgd->assoc_scan_tries = 0;
1751 ifmgd->direct_probe_tries = 0;
1752 ifmgd->auth_tries = 0;
1753 ifmgd->assoc_tries = 0;
24e64622 1754 netif_tx_stop_all_queues(sdata->dev);
f698d856 1755 netif_carrier_off(sdata->dev);
f0706e82
JB
1756}
1757
46900298 1758static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
f0706e82 1759{
46900298 1760 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
f698d856 1761 struct ieee80211_local *local = sdata->local;
c2b13452 1762 struct ieee80211_bss *bss;
46900298
JB
1763 u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
1764 u8 ssid_len = ifmgd->ssid_len;
00d3f14c
JB
1765 u16 capa_mask = WLAN_CAPABILITY_ESS;
1766 u16 capa_val = WLAN_CAPABILITY_ESS;
1767 struct ieee80211_channel *chan = local->oper_channel;
1768
636a5d36
JM
1769 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1770 ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
00d3f14c
JB
1771 IEEE80211_STA_AUTO_BSSID_SEL |
1772 IEEE80211_STA_AUTO_CHANNEL_SEL)) {
1773 capa_mask |= WLAN_CAPABILITY_PRIVACY;
1774 if (sdata->default_key)
1775 capa_val |= WLAN_CAPABILITY_PRIVACY;
f0706e82 1776 }
9d139c81 1777
46900298 1778 if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
00d3f14c
JB
1779 chan = NULL;
1780
46900298 1781 if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
00d3f14c
JB
1782 bssid = NULL;
1783
46900298 1784 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
00d3f14c
JB
1785 ssid = NULL;
1786 ssid_len = 0;
1787 }
1788
1789 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan,
1790 bssid, ssid, ssid_len,
1791 capa_mask, capa_val);
1792
1793 if (bss) {
1794 ieee80211_set_freq(sdata, bss->cbss.channel->center_freq);
46900298 1795 if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
00d3f14c
JB
1796 ieee80211_sta_set_ssid(sdata, bss->ssid,
1797 bss->ssid_len);
1798 ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
1799 ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
1800 bss->supp_rates);
46900298
JB
1801 if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
1802 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
fdfacf0a 1803 else
46900298 1804 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
f0706e82 1805
9c6bd790
JB
1806 /* Send out direct probe if no probe resp was received or
1807 * the one we have is outdated
1808 */
00d3f14c
JB
1809 if (!bss->last_probe_resp ||
1810 time_after(jiffies, bss->last_probe_resp
9c6bd790 1811 + IEEE80211_SCAN_RESULT_EXPIRE))
46900298 1812 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
9c6bd790 1813 else
46900298 1814 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
f0706e82 1815
00d3f14c 1816 ieee80211_rx_bss_put(local, bss);
46900298 1817 ieee80211_sta_reset_auth(sdata);
9c6bd790
JB
1818 return 0;
1819 } else {
46900298
JB
1820 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
1821 ifmgd->assoc_scan_tries++;
2a519311
JB
1822 /* XXX maybe racy? */
1823 if (local->scan_req)
1824 return -1;
1825 memcpy(local->int_scan_req.ssids[0].ssid,
46900298
JB
1826 ifmgd->ssid, IEEE80211_MAX_SSID_LEN);
1827 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL)
2a519311 1828 local->int_scan_req.ssids[0].ssid_len = 0;
9c6bd790 1829 else
46900298 1830 local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
af88b907
HS
1831
1832 if (ieee80211_start_scan(sdata, &local->int_scan_req))
1833 ieee80211_scan_failed(local);
1834
46900298
JB
1835 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
1836 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
e374055a 1837 } else {
46900298
JB
1838 ifmgd->assoc_scan_tries = 0;
1839 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
e374055a 1840 }
9c6bd790
JB
1841 }
1842 return -1;
1843}
1844
1845
1846static void ieee80211_sta_work(struct work_struct *work)
1847{
1848 struct ieee80211_sub_if_data *sdata =
46900298 1849 container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
9c6bd790 1850 struct ieee80211_local *local = sdata->local;
46900298 1851 struct ieee80211_if_managed *ifmgd;
9c6bd790
JB
1852 struct sk_buff *skb;
1853
1854 if (!netif_running(sdata->dev))
1855 return;
1856
c2b13452 1857 if (local->sw_scanning || local->hw_scanning)
9c6bd790
JB
1858 return;
1859
46900298 1860 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
9c6bd790 1861 return;
46900298 1862 ifmgd = &sdata->u.mgd;
f0706e82 1863
46900298 1864 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
9c6bd790
JB
1865 ieee80211_sta_rx_queued_mgmt(sdata, skb);
1866
46900298
JB
1867 if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
1868 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
1869 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
1870 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
af88b907
HS
1871 /*
1872 * The call to ieee80211_start_scan can fail but ieee80211_request_scan
1873 * (which queued ieee80211_sta_work) did not return an error. Thus, call
1874 * ieee80211_scan_failed here if ieee80211_start_scan fails in order to
1875 * notify the scan requester.
1876 */
1877 if (ieee80211_start_scan(sdata, local->scan_req))
1878 ieee80211_scan_failed(local);
9c6bd790 1879 return;
f0706e82
JB
1880 }
1881
46900298
JB
1882 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) {
1883 if (ieee80211_sta_config_auth(sdata))
9c6bd790 1884 return;
46900298
JB
1885 clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
1886 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
9c6bd790 1887 return;
d6f2da5b 1888
46900298 1889 switch (ifmgd->state) {
9c6bd790
JB
1890 case IEEE80211_STA_MLME_DISABLED:
1891 break;
1892 case IEEE80211_STA_MLME_DIRECT_PROBE:
46900298 1893 ieee80211_direct_probe(sdata);
9c6bd790
JB
1894 break;
1895 case IEEE80211_STA_MLME_AUTHENTICATE:
46900298 1896 ieee80211_authenticate(sdata);
9c6bd790
JB
1897 break;
1898 case IEEE80211_STA_MLME_ASSOCIATE:
46900298 1899 ieee80211_associate(sdata);
9c6bd790
JB
1900 break;
1901 case IEEE80211_STA_MLME_ASSOCIATED:
46900298 1902 ieee80211_associated(sdata);
9c6bd790
JB
1903 break;
1904 default:
1905 WARN_ON(1);
1906 break;
1907 }
1908
46900298 1909 if (ieee80211_privacy_mismatch(sdata)) {
9c6bd790
JB
1910 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
1911 "mixed-cell disabled - disassociate\n", sdata->dev->name);
1912
46900298 1913 ieee80211_set_disassoc(sdata, false, true,
9c6bd790
JB
1914 WLAN_REASON_UNSPECIFIED);
1915 }
f0706e82
JB
1916}
1917
9c6bd790
JB
1918static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
1919{
ad935687
KV
1920 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
1921 /*
1922 * Need to update last_beacon to avoid beacon loss
1923 * test to trigger.
1924 */
1925 sdata->u.mgd.last_beacon = jiffies;
1926
1927
9c6bd790 1928 queue_work(sdata->local->hw.workqueue,
46900298 1929 &sdata->u.mgd.work);
ad935687 1930 }
9c6bd790 1931}
f0706e82 1932
9c6bd790
JB
1933/* interface setup */
1934void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
f0706e82 1935{
46900298 1936 struct ieee80211_if_managed *ifmgd;
988c0f72 1937
46900298
JB
1938 ifmgd = &sdata->u.mgd;
1939 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
1940 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
04de8381 1941 INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
46900298 1942 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
c481ec97 1943 (unsigned long) sdata);
46900298 1944 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
9c6bd790 1945 (unsigned long) sdata);
46900298 1946 skb_queue_head_init(&ifmgd->skb_queue);
9c6bd790 1947
46900298
JB
1948 ifmgd->capab = WLAN_CAPABILITY_ESS;
1949 ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN |
9c6bd790 1950 IEEE80211_AUTH_ALG_SHARED_KEY;
46900298 1951 ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
9c6bd790
JB
1952 IEEE80211_STA_AUTO_BSSID_SEL |
1953 IEEE80211_STA_AUTO_CHANNEL_SEL;
176be728 1954 if (sdata->local->hw.queues >= 4)
46900298 1955 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
f0706e82
JB
1956}
1957
9c6bd790 1958/* configuration hooks */
46900298 1959void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata)
60f8b39c 1960{
46900298 1961 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
60f8b39c 1962 struct ieee80211_local *local = sdata->local;
60f8b39c 1963
46900298 1964 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
9c6bd790 1965 return;
60f8b39c 1966
46900298 1967 if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
9c6bd790 1968 IEEE80211_STA_AUTO_BSSID_SEL)) &&
46900298 1969 (ifmgd->flags & (IEEE80211_STA_SSID_SET |
9c6bd790 1970 IEEE80211_STA_AUTO_SSID_SEL))) {
60f8b39c 1971
46900298
JB
1972 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
1973 ieee80211_set_disassoc(sdata, true, true,
9c6bd790 1974 WLAN_REASON_DEAUTH_LEAVING);
60f8b39c 1975
636a5d36
JM
1976 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) ||
1977 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
1978 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
1979 else if (ifmgd->flags & IEEE80211_STA_EXT_SME)
1980 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
46900298 1981 queue_work(local->hw.workqueue, &ifmgd->work);
9c6bd790
JB
1982 }
1983}
60f8b39c 1984
79f6440c
AF
1985int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata)
1986{
1987 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1988
79f6440c
AF
1989 if (ifmgd->ssid_len)
1990 ifmgd->flags |= IEEE80211_STA_SSID_SET;
1991 else
1992 ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
1993
1994 return 0;
1995}
1996
9c6bd790
JB
1997int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
1998{
46900298 1999 struct ieee80211_if_managed *ifmgd;
60f8b39c 2000
9c6bd790
JB
2001 if (len > IEEE80211_MAX_SSID_LEN)
2002 return -EINVAL;
2003
46900298 2004 ifmgd = &sdata->u.mgd;
9c6bd790 2005
46900298 2006 if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) {
a299542e
JM
2007 /*
2008 * Do not use reassociation if SSID is changed (different ESS).
2009 */
2010 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
46900298
JB
2011 memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
2012 memcpy(ifmgd->ssid, ssid, len);
2013 ifmgd->ssid_len = len;
60f8b39c 2014 }
60f8b39c 2015
79f6440c 2016 return ieee80211_sta_commit(sdata);
9c6bd790
JB
2017}
2018
2019int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
2020{
46900298
JB
2021 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2022 memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len);
2023 *len = ifmgd->ssid_len;
9c6bd790
JB
2024 return 0;
2025}
2026
2027int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2028{
46900298 2029 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
9c6bd790 2030
dfe67012 2031 if (is_valid_ether_addr(bssid)) {
46900298
JB
2032 memcpy(ifmgd->bssid, bssid, ETH_ALEN);
2033 ifmgd->flags |= IEEE80211_STA_BSSID_SET;
dfe67012 2034 } else {
46900298
JB
2035 memset(ifmgd->bssid, 0, ETH_ALEN);
2036 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
dfe67012
AF
2037 }
2038
2039 if (netif_running(sdata->dev)) {
2040 if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
9c6bd790
JB
2041 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
2042 "the low-level driver\n", sdata->dev->name);
9c6bd790
JB
2043 }
2044 }
60f8b39c 2045
79f6440c 2046 return ieee80211_sta_commit(sdata);
9c6bd790
JB
2047}
2048
636a5d36
JM
2049int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
2050 const char *ie, size_t len)
9c6bd790 2051{
46900298 2052 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
9c6bd790 2053
46900298 2054 kfree(ifmgd->extra_ie);
9c6bd790 2055 if (len == 0) {
46900298
JB
2056 ifmgd->extra_ie = NULL;
2057 ifmgd->extra_ie_len = 0;
60f8b39c 2058 return 0;
60f8b39c 2059 }
46900298
JB
2060 ifmgd->extra_ie = kmalloc(len, GFP_KERNEL);
2061 if (!ifmgd->extra_ie) {
2062 ifmgd->extra_ie_len = 0;
9c6bd790
JB
2063 return -ENOMEM;
2064 }
46900298
JB
2065 memcpy(ifmgd->extra_ie, ie, len);
2066 ifmgd->extra_ie_len = len;
9c6bd790 2067 return 0;
60f8b39c
JB
2068}
2069
f698d856 2070int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
f0706e82 2071{
f4ea83dd 2072 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
f698d856 2073 sdata->dev->name, reason);
f0706e82 2074
46900298 2075 if (sdata->vif.type != NL80211_IFTYPE_STATION)
f0706e82
JB
2076 return -EINVAL;
2077
46900298 2078 ieee80211_set_disassoc(sdata, true, true, reason);
f0706e82
JB
2079 return 0;
2080}
2081
f698d856 2082int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
f0706e82 2083{
46900298 2084 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
f0706e82 2085
f4ea83dd 2086 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
f698d856 2087 sdata->dev->name, reason);
f0706e82 2088
05c914fe 2089 if (sdata->vif.type != NL80211_IFTYPE_STATION)
f0706e82
JB
2090 return -EINVAL;
2091
46900298
JB
2092 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
2093 return -ENOLINK;
f0706e82 2094
46900298 2095 ieee80211_set_disassoc(sdata, false, true, reason);
f0706e82
JB
2096 return 0;
2097}
84363e6e 2098
9c6bd790
JB
2099/* scan finished notification */
2100void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2101{
2102 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
9c6bd790
JB
2103
2104 /* Restart STA timers */
2105 rcu_read_lock();
2106 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2107 ieee80211_restart_sta_timer(sdata);
2108 rcu_read_unlock();
2109}
520eb820
KV
2110
2111void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
2112{
2113 struct ieee80211_local *local =
2114 container_of(work, struct ieee80211_local,
2115 dynamic_ps_disable_work);
2116
2117 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2118 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2119 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2120 }
2121
2122 ieee80211_wake_queues_by_reason(&local->hw,
2123 IEEE80211_QUEUE_STOP_REASON_PS);
2124}
2125
2126void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
2127{
2128 struct ieee80211_local *local =
2129 container_of(work, struct ieee80211_local,
2130 dynamic_ps_enable_work);
7181d467 2131 /* XXX: using scan_sdata is completely broken! */
a97b77b9 2132 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
520eb820
KV
2133
2134 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2135 return;
2136
7181d467 2137 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK && sdata)
4be8c387 2138 ieee80211_send_nullfunc(local, sdata, 1);
520eb820 2139
4be8c387 2140 local->hw.conf.flags |= IEEE80211_CONF_PS;
520eb820
KV
2141 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2142}
2143
2144void ieee80211_dynamic_ps_timer(unsigned long data)
2145{
2146 struct ieee80211_local *local = (void *) data;
2147
2148 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
2149}
46900298
JB
2150
2151void ieee80211_send_nullfunc(struct ieee80211_local *local,
2152 struct ieee80211_sub_if_data *sdata,
2153 int powersave)
2154{
2155 struct sk_buff *skb;
2156 struct ieee80211_hdr *nullfunc;
2157 __le16 fc;
2158
2159 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2160 return;
2161
2162 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
2163 if (!skb) {
2164 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
2165 "frame\n", sdata->dev->name);
2166 return;
2167 }
2168 skb_reserve(skb, local->hw.extra_tx_headroom);
2169
2170 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
2171 memset(nullfunc, 0, 24);
2172 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
2173 IEEE80211_FCTL_TODS);
2174 if (powersave)
2175 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
2176 nullfunc->frame_control = fc;
2177 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
2178 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
2179 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
2180
2181 ieee80211_tx_skb(sdata, skb, 0);
2182}
This page took 0.647028 seconds and 5 git commands to generate.