aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211/mlme.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211/mlme.c')
-rw-r--r--net/mac80211/mlme.c1366
1 files changed, 468 insertions, 898 deletions
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index dc5049d58c51..875c8dec940a 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -19,6 +19,7 @@
19#include <linux/rtnetlink.h> 19#include <linux/rtnetlink.h>
20#include <linux/pm_qos_params.h> 20#include <linux/pm_qos_params.h>
21#include <linux/crc32.h> 21#include <linux/crc32.h>
22#include <linux/slab.h>
22#include <net/mac80211.h> 23#include <net/mac80211.h>
23#include <asm/unaligned.h> 24#include <asm/unaligned.h>
24 25
@@ -27,10 +28,6 @@
27#include "rate.h" 28#include "rate.h"
28#include "led.h" 29#include "led.h"
29 30
30#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
31#define IEEE80211_AUTH_MAX_TRIES 3
32#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
33#define IEEE80211_ASSOC_MAX_TRIES 3
34#define IEEE80211_MAX_PROBE_TRIES 5 31#define IEEE80211_MAX_PROBE_TRIES 5
35 32
36/* 33/*
@@ -75,11 +72,8 @@ enum rx_mgmt_action {
75 /* caller must call cfg80211_send_disassoc() */ 72 /* caller must call cfg80211_send_disassoc() */
76 RX_MGMT_CFG80211_DISASSOC, 73 RX_MGMT_CFG80211_DISASSOC,
77 74
78 /* caller must call cfg80211_auth_timeout() & free work */ 75 /* caller must tell cfg80211 about internal error */
79 RX_MGMT_CFG80211_AUTH_TO, 76 RX_MGMT_CFG80211_ASSOC_ERROR,
80
81 /* caller must call cfg80211_assoc_timeout() & free work */
82 RX_MGMT_CFG80211_ASSOC_TO,
83}; 77};
84 78
85/* utils */ 79/* utils */
@@ -122,27 +116,6 @@ static int ecw2cw(int ecw)
122 return (1 << ecw) - 1; 116 return (1 << ecw) - 1;
123} 117}
124 118
125static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
126 struct ieee80211_supported_band *sband,
127 u32 *rates)
128{
129 int i, j, count;
130 *rates = 0;
131 count = 0;
132 for (i = 0; i < bss->supp_rates_len; i++) {
133 int rate = (bss->supp_rates[i] & 0x7F) * 5;
134
135 for (j = 0; j < sband->n_bitrates; j++)
136 if (sband->bitrates[j].bitrate == rate) {
137 *rates |= BIT(j);
138 count++;
139 break;
140 }
141 }
142
143 return count;
144}
145
146/* 119/*
147 * ieee80211_enable_ht should be called only after the operating band 120 * ieee80211_enable_ht should be called only after the operating band
148 * has been determined as ht configuration depends on the hw's 121 * has been determined as ht configuration depends on the hw's
@@ -195,6 +168,8 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
195 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht || 168 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
196 channel_type != local->hw.conf.channel_type; 169 channel_type != local->hw.conf.channel_type;
197 170
171 if (local->tmp_channel)
172 local->tmp_channel_type = channel_type;
198 local->oper_channel_type = channel_type; 173 local->oper_channel_type = channel_type;
199 174
200 if (ht_changed) { 175 if (ht_changed) {
@@ -202,10 +177,11 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
202 ieee80211_hw_config(local, 0); 177 ieee80211_hw_config(local, 0);
203 178
204 rcu_read_lock(); 179 rcu_read_lock();
205 sta = sta_info_get(local, bssid); 180 sta = sta_info_get(sdata, bssid);
206 if (sta) 181 if (sta)
207 rate_control_rate_update(local, sband, sta, 182 rate_control_rate_update(local, sband, sta,
208 IEEE80211_RC_HT_CHANGED); 183 IEEE80211_RC_HT_CHANGED,
184 local->oper_channel_type);
209 rcu_read_unlock(); 185 rcu_read_unlock();
210 } 186 }
211 187
@@ -228,208 +204,6 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
228 204
229/* frame sending functions */ 205/* frame sending functions */
230 206
231static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
232 struct ieee80211_mgd_work *wk)
233{
234 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
235 struct ieee80211_local *local = sdata->local;
236 struct sk_buff *skb;
237 struct ieee80211_mgmt *mgmt;
238 u8 *pos;
239 const u8 *ies, *ht_ie;
240 int i, len, count, rates_len, supp_rates_len;
241 u16 capab;
242 int wmm = 0;
243 struct ieee80211_supported_band *sband;
244 u32 rates = 0;
245
246 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
247 sizeof(*mgmt) + 200 + wk->ie_len +
248 wk->ssid_len);
249 if (!skb) {
250 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
251 "frame\n", sdata->dev->name);
252 return;
253 }
254 skb_reserve(skb, local->hw.extra_tx_headroom);
255
256 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
257
258 capab = ifmgd->capab;
259
260 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
261 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
262 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
263 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
264 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
265 }
266
267 if (wk->bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
268 capab |= WLAN_CAPABILITY_PRIVACY;
269 if (wk->bss->wmm_used)
270 wmm = 1;
271
272 /* get all rates supported by the device and the AP as
273 * some APs don't like getting a superset of their rates
274 * in the association request (e.g. D-Link DAP 1353 in
275 * b-only mode) */
276 rates_len = ieee80211_compatible_rates(wk->bss, sband, &rates);
277
278 if ((wk->bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
279 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
280 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
281
282 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
283 memset(mgmt, 0, 24);
284 memcpy(mgmt->da, wk->bss->cbss.bssid, ETH_ALEN);
285 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
286 memcpy(mgmt->bssid, wk->bss->cbss.bssid, ETH_ALEN);
287
288 if (!is_zero_ether_addr(wk->prev_bssid)) {
289 skb_put(skb, 10);
290 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
291 IEEE80211_STYPE_REASSOC_REQ);
292 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
293 mgmt->u.reassoc_req.listen_interval =
294 cpu_to_le16(local->hw.conf.listen_interval);
295 memcpy(mgmt->u.reassoc_req.current_ap, wk->prev_bssid,
296 ETH_ALEN);
297 } else {
298 skb_put(skb, 4);
299 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
300 IEEE80211_STYPE_ASSOC_REQ);
301 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
302 mgmt->u.assoc_req.listen_interval =
303 cpu_to_le16(local->hw.conf.listen_interval);
304 }
305
306 /* SSID */
307 ies = pos = skb_put(skb, 2 + wk->ssid_len);
308 *pos++ = WLAN_EID_SSID;
309 *pos++ = wk->ssid_len;
310 memcpy(pos, wk->ssid, wk->ssid_len);
311
312 /* add all rates which were marked to be used above */
313 supp_rates_len = rates_len;
314 if (supp_rates_len > 8)
315 supp_rates_len = 8;
316
317 len = sband->n_bitrates;
318 pos = skb_put(skb, supp_rates_len + 2);
319 *pos++ = WLAN_EID_SUPP_RATES;
320 *pos++ = supp_rates_len;
321
322 count = 0;
323 for (i = 0; i < sband->n_bitrates; i++) {
324 if (BIT(i) & rates) {
325 int rate = sband->bitrates[i].bitrate;
326 *pos++ = (u8) (rate / 5);
327 if (++count == 8)
328 break;
329 }
330 }
331
332 if (rates_len > count) {
333 pos = skb_put(skb, rates_len - count + 2);
334 *pos++ = WLAN_EID_EXT_SUPP_RATES;
335 *pos++ = rates_len - count;
336
337 for (i++; i < sband->n_bitrates; i++) {
338 if (BIT(i) & rates) {
339 int rate = sband->bitrates[i].bitrate;
340 *pos++ = (u8) (rate / 5);
341 }
342 }
343 }
344
345 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
346 /* 1. power capabilities */
347 pos = skb_put(skb, 4);
348 *pos++ = WLAN_EID_PWR_CAPABILITY;
349 *pos++ = 2;
350 *pos++ = 0; /* min tx power */
351 *pos++ = local->hw.conf.channel->max_power; /* max tx power */
352
353 /* 2. supported channels */
354 /* TODO: get this in reg domain format */
355 pos = skb_put(skb, 2 * sband->n_channels + 2);
356 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
357 *pos++ = 2 * sband->n_channels;
358 for (i = 0; i < sband->n_channels; i++) {
359 *pos++ = ieee80211_frequency_to_channel(
360 sband->channels[i].center_freq);
361 *pos++ = 1; /* one channel in the subband*/
362 }
363 }
364
365 if (wk->ie_len && wk->ie) {
366 pos = skb_put(skb, wk->ie_len);
367 memcpy(pos, wk->ie, wk->ie_len);
368 }
369
370 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
371 pos = skb_put(skb, 9);
372 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
373 *pos++ = 7; /* len */
374 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
375 *pos++ = 0x50;
376 *pos++ = 0xf2;
377 *pos++ = 2; /* WME */
378 *pos++ = 0; /* WME info */
379 *pos++ = 1; /* WME ver */
380 *pos++ = 0;
381 }
382
383 /* wmm support is a must to HT */
384 /*
385 * IEEE802.11n does not allow TKIP/WEP as pairwise
386 * ciphers in HT mode. We still associate in non-ht
387 * mode (11a/b/g) if any one of these ciphers is
388 * configured as pairwise.
389 */
390 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
391 sband->ht_cap.ht_supported &&
392 (ht_ie = ieee80211_bss_get_ie(&wk->bss->cbss, WLAN_EID_HT_INFORMATION)) &&
393 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
394 (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N))) {
395 struct ieee80211_ht_info *ht_info =
396 (struct ieee80211_ht_info *)(ht_ie + 2);
397 u16 cap = sband->ht_cap.cap;
398 __le16 tmp;
399 u32 flags = local->hw.conf.channel->flags;
400
401 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
402 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
403 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
404 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
405 cap &= ~IEEE80211_HT_CAP_SGI_40;
406 }
407 break;
408 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
409 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
410 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
411 cap &= ~IEEE80211_HT_CAP_SGI_40;
412 }
413 break;
414 }
415
416 tmp = cpu_to_le16(cap);
417 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
418 *pos++ = WLAN_EID_HT_CAPABILITY;
419 *pos++ = sizeof(struct ieee80211_ht_cap);
420 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
421 memcpy(pos, &tmp, sizeof(u16));
422 pos += sizeof(u16);
423 /* TODO: needs a define here for << 2 */
424 *pos++ = sband->ht_cap.ampdu_factor |
425 (sband->ht_cap.ampdu_density << 2);
426 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
427 }
428
429 ieee80211_tx_skb(sdata, skb, 0);
430}
431
432
433static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, 207static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
434 const u8 *bssid, u16 stype, u16 reason, 208 const u8 *bssid, u16 stype, u16 reason,
435 void *cookie) 209 void *cookie)
@@ -442,7 +216,7 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
442 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); 216 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
443 if (!skb) { 217 if (!skb) {
444 printk(KERN_DEBUG "%s: failed to allocate buffer for " 218 printk(KERN_DEBUG "%s: failed to allocate buffer for "
445 "deauth/disassoc frame\n", sdata->dev->name); 219 "deauth/disassoc frame\n", sdata->name);
446 return; 220 return;
447 } 221 }
448 skb_reserve(skb, local->hw.extra_tx_headroom); 222 skb_reserve(skb, local->hw.extra_tx_headroom);
@@ -450,7 +224,7 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
450 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 224 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
451 memset(mgmt, 0, 24); 225 memset(mgmt, 0, 24);
452 memcpy(mgmt->da, bssid, ETH_ALEN); 226 memcpy(mgmt->da, bssid, ETH_ALEN);
453 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 227 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
454 memcpy(mgmt->bssid, bssid, ETH_ALEN); 228 memcpy(mgmt->bssid, bssid, ETH_ALEN);
455 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); 229 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
456 skb_put(skb, 2); 230 skb_put(skb, 2);
@@ -458,41 +232,35 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
458 mgmt->u.deauth.reason_code = cpu_to_le16(reason); 232 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
459 233
460 if (stype == IEEE80211_STYPE_DEAUTH) 234 if (stype == IEEE80211_STYPE_DEAUTH)
461 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len, cookie); 235 if (cookie)
236 __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
237 else
238 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
462 else 239 else
463 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len, cookie); 240 if (cookie)
464 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED); 241 __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
242 else
243 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
244 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
245 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
246 ieee80211_tx_skb(sdata, skb);
465} 247}
466 248
467void ieee80211_send_pspoll(struct ieee80211_local *local, 249void ieee80211_send_pspoll(struct ieee80211_local *local,
468 struct ieee80211_sub_if_data *sdata) 250 struct ieee80211_sub_if_data *sdata)
469{ 251{
470 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
471 struct ieee80211_pspoll *pspoll; 252 struct ieee80211_pspoll *pspoll;
472 struct sk_buff *skb; 253 struct sk_buff *skb;
473 u16 fc;
474 254
475 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll)); 255 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
476 if (!skb) { 256 if (!skb)
477 printk(KERN_DEBUG "%s: failed to allocate buffer for "
478 "pspoll frame\n", sdata->dev->name);
479 return; 257 return;
480 }
481 skb_reserve(skb, local->hw.extra_tx_headroom);
482
483 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
484 memset(pspoll, 0, sizeof(*pspoll));
485 fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
486 pspoll->frame_control = cpu_to_le16(fc);
487 pspoll->aid = cpu_to_le16(ifmgd->aid);
488 258
489 /* aid in PS-Poll has its two MSBs each set to 1 */ 259 pspoll = (struct ieee80211_pspoll *) skb->data;
490 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14); 260 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
491 261
492 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN); 262 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
493 memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN); 263 ieee80211_tx_skb(sdata, skb);
494
495 ieee80211_tx_skb(sdata, skb, 0);
496} 264}
497 265
498void ieee80211_send_nullfunc(struct ieee80211_local *local, 266void ieee80211_send_nullfunc(struct ieee80211_local *local,
@@ -500,32 +268,50 @@ void ieee80211_send_nullfunc(struct ieee80211_local *local,
500 int powersave) 268 int powersave)
501{ 269{
502 struct sk_buff *skb; 270 struct sk_buff *skb;
271 struct ieee80211_hdr_3addr *nullfunc;
272
273 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
274 if (!skb)
275 return;
276
277 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
278 if (powersave)
279 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
280
281 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
282 ieee80211_tx_skb(sdata, skb);
283}
284
285static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
286 struct ieee80211_sub_if_data *sdata)
287{
288 struct sk_buff *skb;
503 struct ieee80211_hdr *nullfunc; 289 struct ieee80211_hdr *nullfunc;
504 __le16 fc; 290 __le16 fc;
505 291
506 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 292 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
507 return; 293 return;
508 294
509 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); 295 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
510 if (!skb) { 296 if (!skb) {
511 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " 297 printk(KERN_DEBUG "%s: failed to allocate buffer for 4addr "
512 "frame\n", sdata->dev->name); 298 "nullfunc frame\n", sdata->name);
513 return; 299 return;
514 } 300 }
515 skb_reserve(skb, local->hw.extra_tx_headroom); 301 skb_reserve(skb, local->hw.extra_tx_headroom);
516 302
517 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); 303 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
518 memset(nullfunc, 0, 24); 304 memset(nullfunc, 0, 30);
519 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | 305 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
520 IEEE80211_FCTL_TODS); 306 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
521 if (powersave)
522 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
523 nullfunc->frame_control = fc; 307 nullfunc->frame_control = fc;
524 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); 308 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
525 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); 309 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
526 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); 310 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
311 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
527 312
528 ieee80211_tx_skb(sdata, skb, 0); 313 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
314 ieee80211_tx_skb(sdata, skb);
529} 315}
530 316
531/* spectrum management related things */ 317/* spectrum management related things */
@@ -535,7 +321,7 @@ static void ieee80211_chswitch_work(struct work_struct *work)
535 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); 321 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
536 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 322 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
537 323
538 if (!netif_running(sdata->dev)) 324 if (!ieee80211_sdata_running(sdata))
539 return; 325 return;
540 326
541 mutex_lock(&ifmgd->mtx); 327 mutex_lock(&ifmgd->mtx);
@@ -546,7 +332,7 @@ static void ieee80211_chswitch_work(struct work_struct *work)
546 ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL); 332 ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL);
547 333
548 /* XXX: shouldn't really modify cfg80211-owned data! */ 334 /* XXX: shouldn't really modify cfg80211-owned data! */
549 ifmgd->associated->cbss.channel = sdata->local->oper_channel; 335 ifmgd->associated->channel = sdata->local->oper_channel;
550 336
551 ieee80211_wake_queues_by_reason(&sdata->local->hw, 337 ieee80211_wake_queues_by_reason(&sdata->local->hw,
552 IEEE80211_QUEUE_STOP_REASON_CSA); 338 IEEE80211_QUEUE_STOP_REASON_CSA);
@@ -573,6 +359,8 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
573 struct ieee80211_channel_sw_ie *sw_elem, 359 struct ieee80211_channel_sw_ie *sw_elem,
574 struct ieee80211_bss *bss) 360 struct ieee80211_bss *bss)
575{ 361{
362 struct cfg80211_bss *cbss =
363 container_of((void *)bss, struct cfg80211_bss, priv);
576 struct ieee80211_channel *new_ch; 364 struct ieee80211_channel *new_ch;
577 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 365 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
578 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num); 366 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
@@ -606,7 +394,7 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
606 mod_timer(&ifmgd->chswitch_timer, 394 mod_timer(&ifmgd->chswitch_timer,
607 jiffies + 395 jiffies +
608 msecs_to_jiffies(sw_elem->count * 396 msecs_to_jiffies(sw_elem->count *
609 bss->cbss.beacon_interval)); 397 cbss->beacon_interval));
610 } 398 }
611} 399}
612 400
@@ -650,6 +438,11 @@ static void ieee80211_enable_ps(struct ieee80211_local *local,
650 } else { 438 } else {
651 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) 439 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
652 ieee80211_send_nullfunc(local, sdata, 1); 440 ieee80211_send_nullfunc(local, sdata, 1);
441
442 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
443 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
444 return;
445
653 conf->flags |= IEEE80211_CONF_PS; 446 conf->flags |= IEEE80211_CONF_PS;
654 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 447 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
655 } 448 }
@@ -680,8 +473,13 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
680 return; 473 return;
681 } 474 }
682 475
476 if (!list_empty(&local->work_list)) {
477 local->ps_sdata = NULL;
478 goto change;
479 }
480
683 list_for_each_entry(sdata, &local->interfaces, list) { 481 list_for_each_entry(sdata, &local->interfaces, list) {
684 if (!netif_running(sdata->dev)) 482 if (!ieee80211_sdata_running(sdata))
685 continue; 483 continue;
686 if (sdata->vif.type != NL80211_IFTYPE_STATION) 484 if (sdata->vif.type != NL80211_IFTYPE_STATION)
687 continue; 485 continue;
@@ -690,7 +488,8 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
690 } 488 }
691 489
692 if (count == 1 && found->u.mgd.powersave && 490 if (count == 1 && found->u.mgd.powersave &&
693 found->u.mgd.associated && list_empty(&found->u.mgd.work_list) && 491 found->u.mgd.associated &&
492 found->u.mgd.associated->beacon_ies &&
694 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL | 493 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
695 IEEE80211_STA_CONNECTION_POLL))) { 494 IEEE80211_STA_CONNECTION_POLL))) {
696 s32 beaconint_us; 495 s32 beaconint_us;
@@ -704,20 +503,29 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
704 if (beaconint_us > latency) { 503 if (beaconint_us > latency) {
705 local->ps_sdata = NULL; 504 local->ps_sdata = NULL;
706 } else { 505 } else {
707 u8 dtimper = found->vif.bss_conf.dtim_period; 506 struct ieee80211_bss *bss;
708 int maxslp = 1; 507 int maxslp = 1;
508 u8 dtimper;
509
510 bss = (void *)found->u.mgd.associated->priv;
511 dtimper = bss->dtim_period;
709 512
710 if (dtimper > 1) 513 /* If the TIM IE is invalid, pretend the value is 1 */
514 if (!dtimper)
515 dtimper = 1;
516 else if (dtimper > 1)
711 maxslp = min_t(int, dtimper, 517 maxslp = min_t(int, dtimper,
712 latency / beaconint_us); 518 latency / beaconint_us);
713 519
714 local->hw.conf.max_sleep_period = maxslp; 520 local->hw.conf.max_sleep_period = maxslp;
521 local->hw.conf.ps_dtim_period = dtimper;
715 local->ps_sdata = found; 522 local->ps_sdata = found;
716 } 523 }
717 } else { 524 } else {
718 local->ps_sdata = NULL; 525 local->ps_sdata = NULL;
719 } 526 }
720 527
528 change:
721 ieee80211_change_ps(local); 529 ieee80211_change_ps(local);
722} 530}
723 531
@@ -742,6 +550,7 @@ void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
742 container_of(work, struct ieee80211_local, 550 container_of(work, struct ieee80211_local,
743 dynamic_ps_enable_work); 551 dynamic_ps_enable_work);
744 struct ieee80211_sub_if_data *sdata = local->ps_sdata; 552 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
553 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
745 554
746 /* can only happen when PS was just disabled anyway */ 555 /* can only happen when PS was just disabled anyway */
747 if (!sdata) 556 if (!sdata)
@@ -750,11 +559,17 @@ void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
750 if (local->hw.conf.flags & IEEE80211_CONF_PS) 559 if (local->hw.conf.flags & IEEE80211_CONF_PS)
751 return; 560 return;
752 561
753 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) 562 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
563 (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)))
754 ieee80211_send_nullfunc(local, sdata, 1); 564 ieee80211_send_nullfunc(local, sdata, 1);
755 565
756 local->hw.conf.flags |= IEEE80211_CONF_PS; 566 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
757 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 567 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
568 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
569 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
570 local->hw.conf.flags |= IEEE80211_CONF_PS;
571 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
572 }
758} 573}
759 574
760void ieee80211_dynamic_ps_timer(unsigned long data) 575void ieee80211_dynamic_ps_timer(unsigned long data)
@@ -775,9 +590,9 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
775 struct ieee80211_tx_queue_params params; 590 struct ieee80211_tx_queue_params params;
776 size_t left; 591 size_t left;
777 int count; 592 int count;
778 u8 *pos; 593 u8 *pos, uapsd_queues = 0;
779 594
780 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) 595 if (local->hw.queues < 4)
781 return; 596 return;
782 597
783 if (!wmm_param) 598 if (!wmm_param)
@@ -785,6 +600,10 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
785 600
786 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) 601 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
787 return; 602 return;
603
604 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
605 uapsd_queues = local->uapsd_queues;
606
788 count = wmm_param[6] & 0x0f; 607 count = wmm_param[6] & 0x0f;
789 if (count == ifmgd->wmm_last_param_set) 608 if (count == ifmgd->wmm_last_param_set)
790 return; 609 return;
@@ -799,6 +618,7 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
799 for (; left >= 4; left -= 4, pos += 4) { 618 for (; left >= 4; left -= 4, pos += 4) {
800 int aci = (pos[0] >> 5) & 0x03; 619 int aci = (pos[0] >> 5) & 0x03;
801 int acm = (pos[0] >> 4) & 0x01; 620 int acm = (pos[0] >> 4) & 0x01;
621 bool uapsd = false;
802 int queue; 622 int queue;
803 623
804 switch (aci) { 624 switch (aci) {
@@ -806,22 +626,30 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
806 queue = 3; 626 queue = 3;
807 if (acm) 627 if (acm)
808 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ 628 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
629 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
630 uapsd = true;
809 break; 631 break;
810 case 2: /* AC_VI */ 632 case 2: /* AC_VI */
811 queue = 1; 633 queue = 1;
812 if (acm) 634 if (acm)
813 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ 635 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
636 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
637 uapsd = true;
814 break; 638 break;
815 case 3: /* AC_VO */ 639 case 3: /* AC_VO */
816 queue = 0; 640 queue = 0;
817 if (acm) 641 if (acm)
818 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ 642 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
643 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
644 uapsd = true;
819 break; 645 break;
820 case 0: /* AC_BE */ 646 case 0: /* AC_BE */
821 default: 647 default:
822 queue = 2; 648 queue = 2;
823 if (acm) 649 if (acm)
824 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ 650 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
651 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
652 uapsd = true;
825 break; 653 break;
826 } 654 }
827 655
@@ -829,11 +657,14 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
829 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); 657 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
830 params.cw_min = ecw2cw(pos[1] & 0x0f); 658 params.cw_min = ecw2cw(pos[1] & 0x0f);
831 params.txop = get_unaligned_le16(pos + 2); 659 params.txop = get_unaligned_le16(pos + 2);
660 params.uapsd = uapsd;
661
832#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 662#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
833 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " 663 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
834 "cWmin=%d cWmax=%d txop=%d\n", 664 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
835 wiphy_name(local->hw.wiphy), queue, aci, acm, 665 wiphy_name(local->hw.wiphy), queue, aci, acm,
836 params.aifs, params.cw_min, params.cw_max, params.txop); 666 params.aifs, params.cw_min, params.cw_max, params.txop,
667 params.uapsd);
837#endif 668#endif
838 if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx) 669 if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx)
839 printk(KERN_DEBUG "%s: failed to set TX queue " 670 printk(KERN_DEBUG "%s: failed to set TX queue "
@@ -860,6 +691,8 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
860 } 691 }
861 692
862 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); 693 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
694 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
695 use_short_slot = true;
863 696
864 if (use_protection != bss_conf->use_cts_prot) { 697 if (use_protection != bss_conf->use_cts_prot) {
865 bss_conf->use_cts_prot = use_protection; 698 bss_conf->use_cts_prot = use_protection;
@@ -880,30 +713,36 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
880} 713}
881 714
882static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, 715static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
883 struct ieee80211_mgd_work *wk, 716 struct cfg80211_bss *cbss,
884 u32 bss_info_changed) 717 u32 bss_info_changed)
885{ 718{
719 struct ieee80211_bss *bss = (void *)cbss->priv;
886 struct ieee80211_local *local = sdata->local; 720 struct ieee80211_local *local = sdata->local;
887 struct ieee80211_bss *bss = wk->bss;
888 721
889 bss_info_changed |= BSS_CHANGED_ASSOC; 722 bss_info_changed |= BSS_CHANGED_ASSOC;
890 /* set timing information */ 723 /* set timing information */
891 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval; 724 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
892 sdata->vif.bss_conf.timestamp = bss->cbss.tsf; 725 sdata->vif.bss_conf.timestamp = cbss->tsf;
893 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
894 726
895 bss_info_changed |= BSS_CHANGED_BEACON_INT; 727 bss_info_changed |= BSS_CHANGED_BEACON_INT;
896 bss_info_changed |= ieee80211_handle_bss_capability(sdata, 728 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
897 bss->cbss.capability, bss->has_erp_value, bss->erp_value); 729 cbss->capability, bss->has_erp_value, bss->erp_value);
898 730
899 sdata->u.mgd.associated = bss; 731 sdata->u.mgd.associated = cbss;
900 sdata->u.mgd.old_associate_work = wk; 732 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
901 memcpy(sdata->u.mgd.bssid, bss->cbss.bssid, ETH_ALEN);
902 733
903 /* just to be sure */ 734 /* just to be sure */
904 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL | 735 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
905 IEEE80211_STA_BEACON_POLL); 736 IEEE80211_STA_BEACON_POLL);
906 737
738 /*
739 * Always handle WMM once after association regardless
740 * of the first value the AP uses. Setting -1 here has
741 * that effect because the AP values is an unsigned
742 * 4-bit value.
743 */
744 sdata->u.mgd.wmm_last_param_set = -1;
745
907 ieee80211_led_assoc(local, 1); 746 ieee80211_led_assoc(local, 1);
908 747
909 sdata->vif.bss_conf.assoc = 1; 748 sdata->vif.bss_conf.assoc = 1;
@@ -921,99 +760,14 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
921 760
922 mutex_lock(&local->iflist_mtx); 761 mutex_lock(&local->iflist_mtx);
923 ieee80211_recalc_ps(local, -1); 762 ieee80211_recalc_ps(local, -1);
763 ieee80211_recalc_smps(local, sdata);
924 mutex_unlock(&local->iflist_mtx); 764 mutex_unlock(&local->iflist_mtx);
925 765
926 netif_tx_start_all_queues(sdata->dev); 766 netif_tx_start_all_queues(sdata->dev);
927 netif_carrier_on(sdata->dev); 767 netif_carrier_on(sdata->dev);
928} 768}
929 769
930static enum rx_mgmt_action __must_check 770static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata)
931ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
932 struct ieee80211_mgd_work *wk)
933{
934 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
935 struct ieee80211_local *local = sdata->local;
936
937 wk->tries++;
938 if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
939 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
940 sdata->dev->name, wk->bss->cbss.bssid);
941
942 /*
943 * Most likely AP is not in the range so remove the
944 * bss struct for that AP.
945 */
946 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
947
948 /*
949 * We might have a pending scan which had no chance to run yet
950 * due to work needing to be done. Hence, queue the STAs work
951 * again for that.
952 */
953 ieee80211_queue_work(&local->hw, &ifmgd->work);
954 return RX_MGMT_CFG80211_AUTH_TO;
955 }
956
957 printk(KERN_DEBUG "%s: direct probe to AP %pM (try %d)\n",
958 sdata->dev->name, wk->bss->cbss.bssid,
959 wk->tries);
960
961 /*
962 * Direct probe is sent to broadcast address as some APs
963 * will not answer to direct packet in unassociated state.
964 */
965 ieee80211_send_probe_req(sdata, NULL, wk->ssid, wk->ssid_len, NULL, 0);
966
967 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
968 run_again(ifmgd, wk->timeout);
969
970 return RX_MGMT_NONE;
971}
972
973
974static enum rx_mgmt_action __must_check
975ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
976 struct ieee80211_mgd_work *wk)
977{
978 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
979 struct ieee80211_local *local = sdata->local;
980
981 wk->tries++;
982 if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
983 printk(KERN_DEBUG "%s: authentication with AP %pM"
984 " timed out\n",
985 sdata->dev->name, wk->bss->cbss.bssid);
986
987 /*
988 * Most likely AP is not in the range so remove the
989 * bss struct for that AP.
990 */
991 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
992
993 /*
994 * We might have a pending scan which had no chance to run yet
995 * due to work needing to be done. Hence, queue the STAs work
996 * again for that.
997 */
998 ieee80211_queue_work(&local->hw, &ifmgd->work);
999 return RX_MGMT_CFG80211_AUTH_TO;
1000 }
1001
1002 printk(KERN_DEBUG "%s: authenticate with AP %pM (try %d)\n",
1003 sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
1004
1005 ieee80211_send_auth(sdata, 1, wk->auth_alg, wk->ie, wk->ie_len,
1006 wk->bss->cbss.bssid, NULL, 0, 0);
1007 wk->auth_transaction = 2;
1008
1009 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
1010 run_again(ifmgd, wk->timeout);
1011
1012 return RX_MGMT_NONE;
1013}
1014
1015static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1016 bool deauth)
1017{ 771{
1018 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 772 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1019 struct ieee80211_local *local = sdata->local; 773 struct ieee80211_local *local = sdata->local;
@@ -1026,21 +780,11 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1026 if (WARN_ON(!ifmgd->associated)) 780 if (WARN_ON(!ifmgd->associated))
1027 return; 781 return;
1028 782
1029 memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN); 783 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1030 784
1031 ifmgd->associated = NULL; 785 ifmgd->associated = NULL;
1032 memset(ifmgd->bssid, 0, ETH_ALEN); 786 memset(ifmgd->bssid, 0, ETH_ALEN);
1033 787
1034 if (deauth) {
1035 kfree(ifmgd->old_associate_work);
1036 ifmgd->old_associate_work = NULL;
1037 } else {
1038 struct ieee80211_mgd_work *wk = ifmgd->old_associate_work;
1039
1040 wk->state = IEEE80211_MGD_STATE_IDLE;
1041 list_add(&wk->list, &ifmgd->work_list);
1042 }
1043
1044 /* 788 /*
1045 * we need to commit the associated = NULL change because the 789 * we need to commit the associated = NULL change because the
1046 * scan code uses that to determine whether this iface should 790 * scan code uses that to determine whether this iface should
@@ -1059,9 +803,11 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1059 netif_carrier_off(sdata->dev); 803 netif_carrier_off(sdata->dev);
1060 804
1061 rcu_read_lock(); 805 rcu_read_lock();
1062 sta = sta_info_get(local, bssid); 806 sta = sta_info_get(sdata, bssid);
1063 if (sta) 807 if (sta) {
808 set_sta_flags(sta, WLAN_STA_DISASSOC);
1064 ieee80211_sta_tear_down_BA_sessions(sta); 809 ieee80211_sta_tear_down_BA_sessions(sta);
810 }
1065 rcu_read_unlock(); 811 rcu_read_unlock();
1066 812
1067 changed |= ieee80211_reset_erp_info(sdata); 813 changed |= ieee80211_reset_erp_info(sdata);
@@ -1072,8 +818,6 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1072 818
1073 ieee80211_set_wmm_default(sdata); 819 ieee80211_set_wmm_default(sdata);
1074 820
1075 ieee80211_recalc_idle(local);
1076
1077 /* channel(_type) changes are handled by ieee80211_hw_config */ 821 /* channel(_type) changes are handled by ieee80211_hw_config */
1078 local->oper_channel_type = NL80211_CHAN_NO_HT; 822 local->oper_channel_type = NL80211_CHAN_NO_HT;
1079 823
@@ -1096,57 +840,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1096 changed |= BSS_CHANGED_BSSID; 840 changed |= BSS_CHANGED_BSSID;
1097 ieee80211_bss_info_change_notify(sdata, changed); 841 ieee80211_bss_info_change_notify(sdata, changed);
1098 842
1099 rcu_read_lock(); 843 sta_info_destroy_addr(sdata, bssid);
1100
1101 sta = sta_info_get(local, bssid);
1102 if (!sta) {
1103 rcu_read_unlock();
1104 return;
1105 }
1106
1107 sta_info_unlink(&sta);
1108
1109 rcu_read_unlock();
1110
1111 sta_info_destroy(sta);
1112}
1113
1114static enum rx_mgmt_action __must_check
1115ieee80211_associate(struct ieee80211_sub_if_data *sdata,
1116 struct ieee80211_mgd_work *wk)
1117{
1118 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1119 struct ieee80211_local *local = sdata->local;
1120
1121 wk->tries++;
1122 if (wk->tries > IEEE80211_ASSOC_MAX_TRIES) {
1123 printk(KERN_DEBUG "%s: association with AP %pM"
1124 " timed out\n",
1125 sdata->dev->name, wk->bss->cbss.bssid);
1126
1127 /*
1128 * Most likely AP is not in the range so remove the
1129 * bss struct for that AP.
1130 */
1131 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
1132
1133 /*
1134 * We might have a pending scan which had no chance to run yet
1135 * due to work needing to be done. Hence, queue the STAs work
1136 * again for that.
1137 */
1138 ieee80211_queue_work(&local->hw, &ifmgd->work);
1139 return RX_MGMT_CFG80211_ASSOC_TO;
1140 }
1141
1142 printk(KERN_DEBUG "%s: associate with AP %pM (try %d)\n",
1143 sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
1144 ieee80211_send_assoc(sdata, wk);
1145
1146 wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
1147 run_again(ifmgd, wk->timeout);
1148
1149 return RX_MGMT_NONE;
1150} 844}
1151 845
1152void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, 846void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
@@ -1172,8 +866,8 @@ static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1172 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 866 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1173 const u8 *ssid; 867 const u8 *ssid;
1174 868
1175 ssid = ieee80211_bss_get_ie(&ifmgd->associated->cbss, WLAN_EID_SSID); 869 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1176 ieee80211_send_probe_req(sdata, ifmgd->associated->cbss.bssid, 870 ieee80211_send_probe_req(sdata, ifmgd->associated->bssid,
1177 ssid + 2, ssid[1], NULL, 0); 871 ssid + 2, ssid[1], NULL, 0);
1178 872
1179 ifmgd->probe_send_count++; 873 ifmgd->probe_send_count++;
@@ -1187,12 +881,15 @@ static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1187 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 881 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1188 bool already = false; 882 bool already = false;
1189 883
1190 if (!netif_running(sdata->dev)) 884 if (!ieee80211_sdata_running(sdata))
1191 return; 885 return;
1192 886
1193 if (sdata->local->scanning) 887 if (sdata->local->scanning)
1194 return; 888 return;
1195 889
890 if (sdata->local->tmp_channel)
891 return;
892
1196 mutex_lock(&ifmgd->mtx); 893 mutex_lock(&ifmgd->mtx);
1197 894
1198 if (!ifmgd->associated) 895 if (!ifmgd->associated)
@@ -1201,7 +898,7 @@ static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1201#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 898#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1202 if (beacon && net_ratelimit()) 899 if (beacon && net_ratelimit())
1203 printk(KERN_DEBUG "%s: detected beacon loss from AP " 900 printk(KERN_DEBUG "%s: detected beacon loss from AP "
1204 "- sending probe request\n", sdata->dev->name); 901 "- sending probe request\n", sdata->name);
1205#endif 902#endif
1206 903
1207 /* 904 /*
@@ -1254,88 +951,8 @@ void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1254} 951}
1255EXPORT_SYMBOL(ieee80211_beacon_loss); 952EXPORT_SYMBOL(ieee80211_beacon_loss);
1256 953
1257static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
1258 struct ieee80211_mgd_work *wk)
1259{
1260 wk->state = IEEE80211_MGD_STATE_IDLE;
1261 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
1262}
1263
1264
1265static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1266 struct ieee80211_mgd_work *wk,
1267 struct ieee80211_mgmt *mgmt,
1268 size_t len)
1269{
1270 u8 *pos;
1271 struct ieee802_11_elems elems;
1272
1273 pos = mgmt->u.auth.variable;
1274 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1275 if (!elems.challenge)
1276 return;
1277 ieee80211_send_auth(sdata, 3, wk->auth_alg,
1278 elems.challenge - 2, elems.challenge_len + 2,
1279 wk->bss->cbss.bssid,
1280 wk->key, wk->key_len, wk->key_idx);
1281 wk->auth_transaction = 4;
1282}
1283
1284static enum rx_mgmt_action __must_check
1285ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1286 struct ieee80211_mgd_work *wk,
1287 struct ieee80211_mgmt *mgmt, size_t len)
1288{
1289 u16 auth_alg, auth_transaction, status_code;
1290
1291 if (wk->state != IEEE80211_MGD_STATE_AUTH)
1292 return RX_MGMT_NONE;
1293
1294 if (len < 24 + 6)
1295 return RX_MGMT_NONE;
1296
1297 if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
1298 return RX_MGMT_NONE;
1299
1300 if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
1301 return RX_MGMT_NONE;
1302
1303 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1304 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1305 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1306
1307 if (auth_alg != wk->auth_alg ||
1308 auth_transaction != wk->auth_transaction)
1309 return RX_MGMT_NONE;
1310
1311 if (status_code != WLAN_STATUS_SUCCESS) {
1312 list_del(&wk->list);
1313 kfree(wk);
1314 return RX_MGMT_CFG80211_AUTH;
1315 }
1316
1317 switch (wk->auth_alg) {
1318 case WLAN_AUTH_OPEN:
1319 case WLAN_AUTH_LEAP:
1320 case WLAN_AUTH_FT:
1321 ieee80211_auth_completed(sdata, wk);
1322 return RX_MGMT_CFG80211_AUTH;
1323 case WLAN_AUTH_SHARED_KEY:
1324 if (wk->auth_transaction == 4) {
1325 ieee80211_auth_completed(sdata, wk);
1326 return RX_MGMT_CFG80211_AUTH;
1327 } else
1328 ieee80211_auth_challenge(sdata, wk, mgmt, len);
1329 break;
1330 }
1331
1332 return RX_MGMT_NONE;
1333}
1334
1335
1336static enum rx_mgmt_action __must_check 954static enum rx_mgmt_action __must_check
1337ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, 955ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1338 struct ieee80211_mgd_work *wk,
1339 struct ieee80211_mgmt *mgmt, size_t len) 956 struct ieee80211_mgmt *mgmt, size_t len)
1340{ 957{
1341 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 958 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
@@ -1347,22 +964,15 @@ ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1347 964
1348 ASSERT_MGD_MTX(ifmgd); 965 ASSERT_MGD_MTX(ifmgd);
1349 966
1350 if (wk) 967 bssid = ifmgd->associated->bssid;
1351 bssid = wk->bss->cbss.bssid;
1352 else
1353 bssid = ifmgd->associated->cbss.bssid;
1354 968
1355 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); 969 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1356 970
1357 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n", 971 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
1358 sdata->dev->name, bssid, reason_code); 972 sdata->name, bssid, reason_code);
1359 973
1360 if (!wk) { 974 ieee80211_set_disassoc(sdata);
1361 ieee80211_set_disassoc(sdata, true); 975 ieee80211_recalc_idle(sdata->local);
1362 } else {
1363 list_del(&wk->list);
1364 kfree(wk);
1365 }
1366 976
1367 return RX_MGMT_CFG80211_DEAUTH; 977 return RX_MGMT_CFG80211_DEAUTH;
1368} 978}
@@ -1383,122 +993,72 @@ ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1383 if (WARN_ON(!ifmgd->associated)) 993 if (WARN_ON(!ifmgd->associated))
1384 return RX_MGMT_NONE; 994 return RX_MGMT_NONE;
1385 995
1386 if (WARN_ON(memcmp(ifmgd->associated->cbss.bssid, mgmt->sa, ETH_ALEN))) 996 if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
1387 return RX_MGMT_NONE; 997 return RX_MGMT_NONE;
1388 998
1389 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 999 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1390 1000
1391 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n", 1001 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
1392 sdata->dev->name, mgmt->sa, reason_code); 1002 sdata->name, mgmt->sa, reason_code);
1393 1003
1394 ieee80211_set_disassoc(sdata, false); 1004 ieee80211_set_disassoc(sdata);
1005 ieee80211_recalc_idle(sdata->local);
1395 return RX_MGMT_CFG80211_DISASSOC; 1006 return RX_MGMT_CFG80211_DISASSOC;
1396} 1007}
1397 1008
1398 1009
1399static enum rx_mgmt_action __must_check 1010static bool ieee80211_assoc_success(struct ieee80211_work *wk,
1400ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, 1011 struct ieee80211_mgmt *mgmt, size_t len)
1401 struct ieee80211_mgd_work *wk,
1402 struct ieee80211_mgmt *mgmt, size_t len,
1403 bool reassoc)
1404{ 1012{
1013 struct ieee80211_sub_if_data *sdata = wk->sdata;
1405 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1014 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1406 struct ieee80211_local *local = sdata->local; 1015 struct ieee80211_local *local = sdata->local;
1407 struct ieee80211_supported_band *sband; 1016 struct ieee80211_supported_band *sband;
1408 struct sta_info *sta; 1017 struct sta_info *sta;
1018 struct cfg80211_bss *cbss = wk->assoc.bss;
1019 u8 *pos;
1409 u32 rates, basic_rates; 1020 u32 rates, basic_rates;
1410 u16 capab_info, status_code, aid; 1021 u16 capab_info, aid;
1411 struct ieee802_11_elems elems; 1022 struct ieee802_11_elems elems;
1412 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; 1023 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1413 u8 *pos;
1414 u32 changed = 0; 1024 u32 changed = 0;
1415 int i, j; 1025 int i, j, err;
1416 bool have_higher_than_11mbit = false, newsta = false; 1026 bool have_higher_than_11mbit = false;
1417 u16 ap_ht_cap_flags; 1027 u16 ap_ht_cap_flags;
1418 1028
1419 /* 1029 /* AssocResp and ReassocResp have identical structure */
1420 * AssocResp and ReassocResp have identical structure, so process both
1421 * of them in this function.
1422 */
1423
1424 if (len < 24 + 6)
1425 return RX_MGMT_NONE;
1426
1427 if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
1428 return RX_MGMT_NONE;
1429 1030
1430 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1431 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1432 aid = le16_to_cpu(mgmt->u.assoc_resp.aid); 1031 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1433 1032 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1434 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
1435 "status=%d aid=%d)\n",
1436 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
1437 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1438
1439 pos = mgmt->u.assoc_resp.variable;
1440 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1441
1442 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
1443 elems.timeout_int && elems.timeout_int_len == 5 &&
1444 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
1445 u32 tu, ms;
1446 tu = get_unaligned_le32(elems.timeout_int + 1);
1447 ms = tu * 1024 / 1000;
1448 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1449 "comeback duration %u TU (%u ms)\n",
1450 sdata->dev->name, tu, ms);
1451 wk->timeout = jiffies + msecs_to_jiffies(ms);
1452 if (ms > IEEE80211_ASSOC_TIMEOUT)
1453 run_again(ifmgd, jiffies + msecs_to_jiffies(ms));
1454 return RX_MGMT_NONE;
1455 }
1456
1457 if (status_code != WLAN_STATUS_SUCCESS) {
1458 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1459 sdata->dev->name, status_code);
1460 wk->state = IEEE80211_MGD_STATE_IDLE;
1461 return RX_MGMT_CFG80211_ASSOC;
1462 }
1463 1033
1464 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) 1034 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1465 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " 1035 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1466 "set\n", sdata->dev->name, aid); 1036 "set\n", sdata->name, aid);
1467 aid &= ~(BIT(15) | BIT(14)); 1037 aid &= ~(BIT(15) | BIT(14));
1468 1038
1039 pos = mgmt->u.assoc_resp.variable;
1040 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1041
1469 if (!elems.supp_rates) { 1042 if (!elems.supp_rates) {
1470 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", 1043 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1471 sdata->dev->name); 1044 sdata->name);
1472 return RX_MGMT_NONE; 1045 return false;
1473 } 1046 }
1474 1047
1475 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
1476 ifmgd->aid = aid; 1048 ifmgd->aid = aid;
1477 1049
1478 rcu_read_lock(); 1050 sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
1479
1480 /* Add STA entry for the AP */
1481 sta = sta_info_get(local, wk->bss->cbss.bssid);
1482 if (!sta) { 1051 if (!sta) {
1483 newsta = true; 1052 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1484 1053 " the AP\n", sdata->name);
1485 rcu_read_unlock(); 1054 return false;
1486
1487 sta = sta_info_alloc(sdata, wk->bss->cbss.bssid, GFP_KERNEL);
1488 if (!sta) {
1489 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1490 " the AP\n", sdata->dev->name);
1491 return RX_MGMT_NONE;
1492 }
1493
1494 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1495 WLAN_STA_ASSOC_AP);
1496 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1497 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1498
1499 rcu_read_lock();
1500 } 1055 }
1501 1056
1057 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1058 WLAN_STA_ASSOC_AP);
1059 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1060 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1061
1502 rates = 0; 1062 rates = 0;
1503 basic_rates = 0; 1063 basic_rates = 0;
1504 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 1064 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
@@ -1561,40 +1121,40 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1561 if (elems.wmm_param) 1121 if (elems.wmm_param)
1562 set_sta_flags(sta, WLAN_STA_WME); 1122 set_sta_flags(sta, WLAN_STA_WME);
1563 1123
1564 if (newsta) { 1124 err = sta_info_insert(sta);
1565 int err = sta_info_insert(sta); 1125 sta = NULL;
1566 if (err) { 1126 if (err) {
1567 printk(KERN_DEBUG "%s: failed to insert STA entry for" 1127 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1568 " the AP (error %d)\n", sdata->dev->name, err); 1128 " the AP (error %d)\n", sdata->name, err);
1569 rcu_read_unlock(); 1129 return false;
1570 return RX_MGMT_NONE;
1571 }
1572 } 1130 }
1573 1131
1574 rcu_read_unlock();
1575
1576 if (elems.wmm_param) 1132 if (elems.wmm_param)
1577 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, 1133 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1578 elems.wmm_param_len); 1134 elems.wmm_param_len);
1579 else 1135 else
1580 ieee80211_set_wmm_default(sdata); 1136 ieee80211_set_wmm_default(sdata);
1581 1137
1138 local->oper_channel = wk->chan;
1139
1582 if (elems.ht_info_elem && elems.wmm_param && 1140 if (elems.ht_info_elem && elems.wmm_param &&
1583 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && 1141 (sdata->local->hw.queues >= 4) &&
1584 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) 1142 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
1585 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, 1143 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1586 wk->bss->cbss.bssid, 1144 cbss->bssid, ap_ht_cap_flags);
1587 ap_ht_cap_flags);
1588
1589 /* delete work item -- must be before set_associated for PS */
1590 list_del(&wk->list);
1591 1145
1592 /* set AID and assoc capability, 1146 /* set AID and assoc capability,
1593 * ieee80211_set_associated() will tell the driver */ 1147 * ieee80211_set_associated() will tell the driver */
1594 bss_conf->aid = aid; 1148 bss_conf->aid = aid;
1595 bss_conf->assoc_capability = capab_info; 1149 bss_conf->assoc_capability = capab_info;
1596 /* this will take ownership of wk */ 1150 ieee80211_set_associated(sdata, cbss, changed);
1597 ieee80211_set_associated(sdata, wk, changed); 1151
1152 /*
1153 * If we're using 4-addr mode, let the AP know that we're
1154 * doing so, so that it can create the STA VLAN on its side
1155 */
1156 if (ifmgd->use_4addr)
1157 ieee80211_send_4addr_nullfunc(local, sdata);
1598 1158
1599 /* 1159 /*
1600 * Start timer to probe the connection to the AP now. 1160 * Start timer to probe the connection to the AP now.
@@ -1603,7 +1163,7 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1603 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); 1163 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
1604 mod_beacon_timer(sdata); 1164 mod_beacon_timer(sdata);
1605 1165
1606 return RX_MGMT_CFG80211_ASSOC; 1166 return true;
1607} 1167}
1608 1168
1609 1169
@@ -1618,6 +1178,13 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1618 int freq; 1178 int freq;
1619 struct ieee80211_bss *bss; 1179 struct ieee80211_bss *bss;
1620 struct ieee80211_channel *channel; 1180 struct ieee80211_channel *channel;
1181 bool need_ps = false;
1182
1183 if (sdata->u.mgd.associated) {
1184 bss = (void *)sdata->u.mgd.associated->priv;
1185 /* not previously set so we may need to recalc */
1186 need_ps = !bss->dtim_period;
1187 }
1621 1188
1622 if (elems->ds_params && elems->ds_params_len == 1) 1189 if (elems->ds_params && elems->ds_params_len == 1)
1623 freq = ieee80211_channel_to_frequency(elems->ds_params[0]); 1190 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
@@ -1637,8 +1204,14 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1637 if (!sdata->u.mgd.associated) 1204 if (!sdata->u.mgd.associated)
1638 return; 1205 return;
1639 1206
1207 if (need_ps) {
1208 mutex_lock(&local->iflist_mtx);
1209 ieee80211_recalc_ps(local, -1);
1210 mutex_unlock(&local->iflist_mtx);
1211 }
1212
1640 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) && 1213 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
1641 (memcmp(mgmt->bssid, sdata->u.mgd.associated->cbss.bssid, 1214 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
1642 ETH_ALEN) == 0)) { 1215 ETH_ALEN) == 0)) {
1643 struct ieee80211_channel_sw_ie *sw_elem = 1216 struct ieee80211_channel_sw_ie *sw_elem =
1644 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem; 1217 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
@@ -1648,19 +1221,19 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1648 1221
1649 1222
1650static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, 1223static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1651 struct ieee80211_mgd_work *wk, 1224 struct sk_buff *skb)
1652 struct ieee80211_mgmt *mgmt, size_t len,
1653 struct ieee80211_rx_status *rx_status)
1654{ 1225{
1226 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1655 struct ieee80211_if_managed *ifmgd; 1227 struct ieee80211_if_managed *ifmgd;
1656 size_t baselen; 1228 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
1229 size_t baselen, len = skb->len;
1657 struct ieee802_11_elems elems; 1230 struct ieee802_11_elems elems;
1658 1231
1659 ifmgd = &sdata->u.mgd; 1232 ifmgd = &sdata->u.mgd;
1660 1233
1661 ASSERT_MGD_MTX(ifmgd); 1234 ASSERT_MGD_MTX(ifmgd);
1662 1235
1663 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) 1236 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
1664 return; /* ignore ProbeResp to foreign address */ 1237 return; /* ignore ProbeResp to foreign address */
1665 1238
1666 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; 1239 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
@@ -1672,17 +1245,8 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1672 1245
1673 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); 1246 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
1674 1247
1675 /* direct probe may be part of the association flow */
1676 if (wk && wk->state == IEEE80211_MGD_STATE_PROBE) {
1677 printk(KERN_DEBUG "%s: direct probe responded\n",
1678 sdata->dev->name);
1679 wk->tries = 0;
1680 wk->state = IEEE80211_MGD_STATE_AUTH;
1681 WARN_ON(ieee80211_authenticate(sdata, wk) != RX_MGMT_NONE);
1682 }
1683
1684 if (ifmgd->associated && 1248 if (ifmgd->associated &&
1685 memcmp(mgmt->bssid, ifmgd->associated->cbss.bssid, ETH_ALEN) == 0 && 1249 memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0 &&
1686 ifmgd->flags & (IEEE80211_STA_BEACON_POLL | 1250 ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1687 IEEE80211_STA_CONNECTION_POLL)) { 1251 IEEE80211_STA_CONNECTION_POLL)) {
1688 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL | 1252 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
@@ -1755,7 +1319,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1755 if (!ifmgd->associated) 1319 if (!ifmgd->associated)
1756 return; 1320 return;
1757 1321
1758 bssid = ifmgd->associated->cbss.bssid; 1322 bssid = ifmgd->associated->bssid;
1759 1323
1760 /* 1324 /*
1761 * And in theory even frames from a different AP we were just 1325 * And in theory even frames from a different AP we were just
@@ -1768,7 +1332,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1768#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1332#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1769 if (net_ratelimit()) { 1333 if (net_ratelimit()) {
1770 printk(KERN_DEBUG "%s: cancelling probereq poll due " 1334 printk(KERN_DEBUG "%s: cancelling probereq poll due "
1771 "to a received beacon\n", sdata->dev->name); 1335 "to a received beacon\n", sdata->name);
1772 } 1336 }
1773#endif 1337#endif
1774 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL; 1338 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
@@ -1846,7 +1410,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1846 1410
1847 rcu_read_lock(); 1411 rcu_read_lock();
1848 1412
1849 sta = sta_info_get(local, bssid); 1413 sta = sta_info_get(sdata, bssid);
1850 if (WARN_ON(!sta)) { 1414 if (WARN_ON(!sta)) {
1851 rcu_read_unlock(); 1415 rcu_read_unlock();
1852 return; 1416 return;
@@ -1892,12 +1456,8 @@ ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1892 fc = le16_to_cpu(mgmt->frame_control); 1456 fc = le16_to_cpu(mgmt->frame_control);
1893 1457
1894 switch (fc & IEEE80211_FCTL_STYPE) { 1458 switch (fc & IEEE80211_FCTL_STYPE) {
1895 case IEEE80211_STYPE_PROBE_REQ:
1896 case IEEE80211_STYPE_PROBE_RESP: 1459 case IEEE80211_STYPE_PROBE_RESP:
1897 case IEEE80211_STYPE_BEACON: 1460 case IEEE80211_STYPE_BEACON:
1898 case IEEE80211_STYPE_AUTH:
1899 case IEEE80211_STYPE_ASSOC_RESP:
1900 case IEEE80211_STYPE_REASSOC_RESP:
1901 case IEEE80211_STYPE_DEAUTH: 1461 case IEEE80211_STYPE_DEAUTH:
1902 case IEEE80211_STYPE_DISASSOC: 1462 case IEEE80211_STYPE_DISASSOC:
1903 case IEEE80211_STYPE_ACTION: 1463 case IEEE80211_STYPE_ACTION:
@@ -1915,7 +1475,6 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1915 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1475 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1916 struct ieee80211_rx_status *rx_status; 1476 struct ieee80211_rx_status *rx_status;
1917 struct ieee80211_mgmt *mgmt; 1477 struct ieee80211_mgmt *mgmt;
1918 struct ieee80211_mgd_work *wk;
1919 enum rx_mgmt_action rma = RX_MGMT_NONE; 1478 enum rx_mgmt_action rma = RX_MGMT_NONE;
1920 u16 fc; 1479 u16 fc;
1921 1480
@@ -1926,29 +1485,28 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1926 mutex_lock(&ifmgd->mtx); 1485 mutex_lock(&ifmgd->mtx);
1927 1486
1928 if (ifmgd->associated && 1487 if (ifmgd->associated &&
1929 memcmp(ifmgd->associated->cbss.bssid, mgmt->bssid, 1488 memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
1930 ETH_ALEN) == 0) {
1931 switch (fc & IEEE80211_FCTL_STYPE) { 1489 switch (fc & IEEE80211_FCTL_STYPE) {
1932 case IEEE80211_STYPE_BEACON: 1490 case IEEE80211_STYPE_BEACON:
1933 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, 1491 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1934 rx_status); 1492 rx_status);
1935 break; 1493 break;
1936 case IEEE80211_STYPE_PROBE_RESP: 1494 case IEEE80211_STYPE_PROBE_RESP:
1937 ieee80211_rx_mgmt_probe_resp(sdata, NULL, mgmt, 1495 ieee80211_rx_mgmt_probe_resp(sdata, skb);
1938 skb->len, rx_status);
1939 break; 1496 break;
1940 case IEEE80211_STYPE_DEAUTH: 1497 case IEEE80211_STYPE_DEAUTH:
1941 rma = ieee80211_rx_mgmt_deauth(sdata, NULL, 1498 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
1942 mgmt, skb->len);
1943 break; 1499 break;
1944 case IEEE80211_STYPE_DISASSOC: 1500 case IEEE80211_STYPE_DISASSOC:
1945 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); 1501 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1946 break; 1502 break;
1947 case IEEE80211_STYPE_ACTION: 1503 case IEEE80211_STYPE_ACTION:
1948 /* XXX: differentiate, can only happen for CSA now! */ 1504 if (mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
1505 break;
1506
1949 ieee80211_sta_process_chanswitch(sdata, 1507 ieee80211_sta_process_chanswitch(sdata,
1950 &mgmt->u.action.u.chan_switch.sw_elem, 1508 &mgmt->u.action.u.chan_switch.sw_elem,
1951 ifmgd->associated); 1509 (void *)ifmgd->associated->priv);
1952 break; 1510 break;
1953 } 1511 }
1954 mutex_unlock(&ifmgd->mtx); 1512 mutex_unlock(&ifmgd->mtx);
@@ -1958,12 +1516,10 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1958 /* no action */ 1516 /* no action */
1959 break; 1517 break;
1960 case RX_MGMT_CFG80211_DEAUTH: 1518 case RX_MGMT_CFG80211_DEAUTH:
1961 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len, 1519 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
1962 NULL);
1963 break; 1520 break;
1964 case RX_MGMT_CFG80211_DISASSOC: 1521 case RX_MGMT_CFG80211_DISASSOC:
1965 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len, 1522 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
1966 NULL);
1967 break; 1523 break;
1968 default: 1524 default:
1969 WARN(1, "unexpected: %d", rma); 1525 WARN(1, "unexpected: %d", rma);
@@ -1971,58 +1527,11 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1971 goto out; 1527 goto out;
1972 } 1528 }
1973 1529
1974 list_for_each_entry(wk, &ifmgd->work_list, list) {
1975 if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
1976 continue;
1977
1978 switch (fc & IEEE80211_FCTL_STYPE) {
1979 case IEEE80211_STYPE_PROBE_RESP:
1980 ieee80211_rx_mgmt_probe_resp(sdata, wk, mgmt, skb->len,
1981 rx_status);
1982 break;
1983 case IEEE80211_STYPE_AUTH:
1984 rma = ieee80211_rx_mgmt_auth(sdata, wk, mgmt, skb->len);
1985 break;
1986 case IEEE80211_STYPE_ASSOC_RESP:
1987 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
1988 skb->len, false);
1989 break;
1990 case IEEE80211_STYPE_REASSOC_RESP:
1991 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
1992 skb->len, true);
1993 break;
1994 case IEEE80211_STYPE_DEAUTH:
1995 rma = ieee80211_rx_mgmt_deauth(sdata, wk, mgmt,
1996 skb->len);
1997 break;
1998 }
1999 /*
2000 * We've processed this frame for that work, so it can't
2001 * belong to another work struct.
2002 * NB: this is also required for correctness because the
2003 * called functions can free 'wk', and for 'rma'!
2004 */
2005 break;
2006 }
2007
2008 mutex_unlock(&ifmgd->mtx); 1530 mutex_unlock(&ifmgd->mtx);
2009 1531
2010 switch (rma) { 1532 if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
2011 case RX_MGMT_NONE: 1533 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH)
2012 /* no action */ 1534 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
2013 break;
2014 case RX_MGMT_CFG80211_AUTH:
2015 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, skb->len);
2016 break;
2017 case RX_MGMT_CFG80211_ASSOC:
2018 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, skb->len);
2019 break;
2020 case RX_MGMT_CFG80211_DEAUTH:
2021 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len, NULL);
2022 break;
2023 default:
2024 WARN(1, "unexpected: %d", rma);
2025 }
2026 1535
2027 out: 1536 out:
2028 kfree_skb(skb); 1537 kfree_skb(skb);
@@ -2050,12 +1559,8 @@ static void ieee80211_sta_work(struct work_struct *work)
2050 struct ieee80211_local *local = sdata->local; 1559 struct ieee80211_local *local = sdata->local;
2051 struct ieee80211_if_managed *ifmgd; 1560 struct ieee80211_if_managed *ifmgd;
2052 struct sk_buff *skb; 1561 struct sk_buff *skb;
2053 struct ieee80211_mgd_work *wk, *tmp;
2054 LIST_HEAD(free_work);
2055 enum rx_mgmt_action rma;
2056 bool anybusy = false;
2057 1562
2058 if (!netif_running(sdata->dev)) 1563 if (!ieee80211_sdata_running(sdata))
2059 return; 1564 return;
2060 1565
2061 if (local->scanning) 1566 if (local->scanning)
@@ -2086,7 +1591,7 @@ static void ieee80211_sta_work(struct work_struct *work)
2086 ifmgd->associated) { 1591 ifmgd->associated) {
2087 u8 bssid[ETH_ALEN]; 1592 u8 bssid[ETH_ALEN];
2088 1593
2089 memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN); 1594 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
2090 if (time_is_after_jiffies(ifmgd->probe_timeout)) 1595 if (time_is_after_jiffies(ifmgd->probe_timeout))
2091 run_again(ifmgd, ifmgd->probe_timeout); 1596 run_again(ifmgd, ifmgd->probe_timeout);
2092 1597
@@ -2108,7 +1613,8 @@ static void ieee80211_sta_work(struct work_struct *work)
2108 printk(KERN_DEBUG "No probe response from AP %pM" 1613 printk(KERN_DEBUG "No probe response from AP %pM"
2109 " after %dms, disconnecting.\n", 1614 " after %dms, disconnecting.\n",
2110 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ); 1615 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
2111 ieee80211_set_disassoc(sdata, true); 1616 ieee80211_set_disassoc(sdata);
1617 ieee80211_recalc_idle(local);
2112 mutex_unlock(&ifmgd->mtx); 1618 mutex_unlock(&ifmgd->mtx);
2113 /* 1619 /*
2114 * must be outside lock due to cfg80211, 1620 * must be outside lock due to cfg80211,
@@ -2122,87 +1628,7 @@ static void ieee80211_sta_work(struct work_struct *work)
2122 } 1628 }
2123 } 1629 }
2124 1630
2125
2126 ieee80211_recalc_idle(local);
2127
2128 list_for_each_entry_safe(wk, tmp, &ifmgd->work_list, list) {
2129 if (time_is_after_jiffies(wk->timeout)) {
2130 /*
2131 * This work item isn't supposed to be worked on
2132 * right now, but take care to adjust the timer
2133 * properly.
2134 */
2135 run_again(ifmgd, wk->timeout);
2136 continue;
2137 }
2138
2139 switch (wk->state) {
2140 default:
2141 WARN_ON(1);
2142 /* fall through */
2143 case IEEE80211_MGD_STATE_IDLE:
2144 /* nothing */
2145 rma = RX_MGMT_NONE;
2146 break;
2147 case IEEE80211_MGD_STATE_PROBE:
2148 rma = ieee80211_direct_probe(sdata, wk);
2149 break;
2150 case IEEE80211_MGD_STATE_AUTH:
2151 rma = ieee80211_authenticate(sdata, wk);
2152 break;
2153 case IEEE80211_MGD_STATE_ASSOC:
2154 rma = ieee80211_associate(sdata, wk);
2155 break;
2156 }
2157
2158 switch (rma) {
2159 case RX_MGMT_NONE:
2160 /* no action required */
2161 break;
2162 case RX_MGMT_CFG80211_AUTH_TO:
2163 case RX_MGMT_CFG80211_ASSOC_TO:
2164 list_del(&wk->list);
2165 list_add(&wk->list, &free_work);
2166 wk->tries = rma; /* small abuse but only local */
2167 break;
2168 default:
2169 WARN(1, "unexpected: %d", rma);
2170 }
2171 }
2172
2173 list_for_each_entry(wk, &ifmgd->work_list, list) {
2174 if (wk->state != IEEE80211_MGD_STATE_IDLE) {
2175 anybusy = true;
2176 break;
2177 }
2178 }
2179 if (!anybusy &&
2180 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request))
2181 ieee80211_queue_delayed_work(&local->hw,
2182 &local->scan_work,
2183 round_jiffies_relative(0));
2184
2185 mutex_unlock(&ifmgd->mtx); 1631 mutex_unlock(&ifmgd->mtx);
2186
2187 list_for_each_entry_safe(wk, tmp, &free_work, list) {
2188 switch (wk->tries) {
2189 case RX_MGMT_CFG80211_AUTH_TO:
2190 cfg80211_send_auth_timeout(sdata->dev,
2191 wk->bss->cbss.bssid);
2192 break;
2193 case RX_MGMT_CFG80211_ASSOC_TO:
2194 cfg80211_send_assoc_timeout(sdata->dev,
2195 wk->bss->cbss.bssid);
2196 break;
2197 default:
2198 WARN(1, "unexpected: %d", wk->tries);
2199 }
2200
2201 list_del(&wk->list);
2202 kfree(wk);
2203 }
2204
2205 ieee80211_recalc_idle(local);
2206} 1632}
2207 1633
2208static void ieee80211_sta_bcn_mon_timer(unsigned long data) 1634static void ieee80211_sta_bcn_mon_timer(unsigned long data)
@@ -2311,14 +1737,14 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2311 (unsigned long) sdata); 1737 (unsigned long) sdata);
2312 skb_queue_head_init(&ifmgd->skb_queue); 1738 skb_queue_head_init(&ifmgd->skb_queue);
2313 1739
2314 INIT_LIST_HEAD(&ifmgd->work_list);
2315
2316 ifmgd->capab = WLAN_CAPABILITY_ESS;
2317 ifmgd->flags = 0; 1740 ifmgd->flags = 0;
2318 if (sdata->local->hw.queues >= 4)
2319 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
2320 1741
2321 mutex_init(&ifmgd->mtx); 1742 mutex_init(&ifmgd->mtx);
1743
1744 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
1745 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
1746 else
1747 ifmgd->req_smps = IEEE80211_SMPS_OFF;
2322} 1748}
2323 1749
2324/* scan finished notification */ 1750/* scan finished notification */
@@ -2349,12 +1775,34 @@ int ieee80211_max_network_latency(struct notifier_block *nb,
2349} 1775}
2350 1776
2351/* config hooks */ 1777/* config hooks */
1778static enum work_done_result
1779ieee80211_probe_auth_done(struct ieee80211_work *wk,
1780 struct sk_buff *skb)
1781{
1782 if (!skb) {
1783 cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
1784 return WORK_DONE_DESTROY;
1785 }
1786
1787 if (wk->type == IEEE80211_WORK_AUTH) {
1788 cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
1789 return WORK_DONE_DESTROY;
1790 }
1791
1792 mutex_lock(&wk->sdata->u.mgd.mtx);
1793 ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
1794 mutex_unlock(&wk->sdata->u.mgd.mtx);
1795
1796 wk->type = IEEE80211_WORK_AUTH;
1797 wk->probe_auth.tries = 0;
1798 return WORK_DONE_REQUEUE;
1799}
1800
2352int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, 1801int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2353 struct cfg80211_auth_request *req) 1802 struct cfg80211_auth_request *req)
2354{ 1803{
2355 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2356 const u8 *ssid; 1804 const u8 *ssid;
2357 struct ieee80211_mgd_work *wk; 1805 struct ieee80211_work *wk;
2358 u16 auth_alg; 1806 u16 auth_alg;
2359 1807
2360 switch (req->auth_type) { 1808 switch (req->auth_type) {
@@ -2378,7 +1826,7 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2378 if (!wk) 1826 if (!wk)
2379 return -ENOMEM; 1827 return -ENOMEM;
2380 1828
2381 wk->bss = (void *)req->bss; 1829 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
2382 1830
2383 if (req->ie && req->ie_len) { 1831 if (req->ie && req->ie_len) {
2384 memcpy(wk->ie, req->ie, req->ie_len); 1832 memcpy(wk->ie, req->ie, req->ie_len);
@@ -2386,68 +1834,95 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2386 } 1834 }
2387 1835
2388 if (req->key && req->key_len) { 1836 if (req->key && req->key_len) {
2389 wk->key_len = req->key_len; 1837 wk->probe_auth.key_len = req->key_len;
2390 wk->key_idx = req->key_idx; 1838 wk->probe_auth.key_idx = req->key_idx;
2391 memcpy(wk->key, req->key, req->key_len); 1839 memcpy(wk->probe_auth.key, req->key, req->key_len);
2392 } 1840 }
2393 1841
2394 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); 1842 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
2395 memcpy(wk->ssid, ssid + 2, ssid[1]); 1843 memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
2396 wk->ssid_len = ssid[1]; 1844 wk->probe_auth.ssid_len = ssid[1];
2397 1845
2398 wk->state = IEEE80211_MGD_STATE_PROBE; 1846 wk->probe_auth.algorithm = auth_alg;
2399 wk->auth_alg = auth_alg; 1847 wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
2400 wk->timeout = jiffies; /* run right away */
2401 1848
2402 /* 1849 /* if we already have a probe, don't probe again */
2403 * XXX: if still associated need to tell AP that we're going 1850 if (req->bss->proberesp_ies)
2404 * to sleep and then change channel etc. 1851 wk->type = IEEE80211_WORK_AUTH;
2405 */ 1852 else
2406 sdata->local->oper_channel = req->bss->channel; 1853 wk->type = IEEE80211_WORK_DIRECT_PROBE;
2407 ieee80211_hw_config(sdata->local, 0); 1854 wk->chan = req->bss->channel;
2408 1855 wk->sdata = sdata;
2409 mutex_lock(&ifmgd->mtx); 1856 wk->done = ieee80211_probe_auth_done;
2410 list_add(&wk->list, &sdata->u.mgd.work_list);
2411 mutex_unlock(&ifmgd->mtx);
2412 1857
2413 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work); 1858 ieee80211_add_work(wk);
2414 return 0; 1859 return 0;
2415} 1860}
2416 1861
2417int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, 1862static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
2418 struct cfg80211_assoc_request *req) 1863 struct sk_buff *skb)
2419{ 1864{
2420 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1865 struct ieee80211_mgmt *mgmt;
2421 struct ieee80211_mgd_work *wk, *found = NULL; 1866 u16 status;
2422 int i, err;
2423 1867
2424 mutex_lock(&ifmgd->mtx); 1868 if (!skb) {
1869 cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
1870 return WORK_DONE_DESTROY;
1871 }
2425 1872
2426 list_for_each_entry(wk, &ifmgd->work_list, list) { 1873 mgmt = (void *)skb->data;
2427 if (&wk->bss->cbss == req->bss && 1874 status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2428 wk->state == IEEE80211_MGD_STATE_IDLE) { 1875
2429 found = wk; 1876 if (status == WLAN_STATUS_SUCCESS) {
2430 break; 1877 mutex_lock(&wk->sdata->u.mgd.mtx);
1878 if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
1879 mutex_unlock(&wk->sdata->u.mgd.mtx);
1880 /* oops -- internal error -- send timeout for now */
1881 cfg80211_send_assoc_timeout(wk->sdata->dev,
1882 wk->filter_ta);
1883 return WORK_DONE_DESTROY;
2431 } 1884 }
1885 mutex_unlock(&wk->sdata->u.mgd.mtx);
2432 } 1886 }
2433 1887
2434 if (!found) { 1888 cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
2435 err = -ENOLINK; 1889 return WORK_DONE_DESTROY;
2436 goto out; 1890}
2437 }
2438 1891
2439 list_del(&found->list); 1892int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
1893 struct cfg80211_assoc_request *req)
1894{
1895 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1896 struct ieee80211_bss *bss = (void *)req->bss->priv;
1897 struct ieee80211_work *wk;
1898 const u8 *ssid;
1899 int i;
2440 1900
2441 wk = krealloc(found, sizeof(*wk) + req->ie_len, GFP_KERNEL); 1901 mutex_lock(&ifmgd->mtx);
2442 if (!wk) { 1902 if (ifmgd->associated) {
2443 list_add(&found->list, &ifmgd->work_list); 1903 if (!req->prev_bssid ||
2444 err = -ENOMEM; 1904 memcmp(req->prev_bssid, ifmgd->associated->bssid,
2445 goto out; 1905 ETH_ALEN)) {
1906 /*
1907 * We are already associated and the request was not a
1908 * reassociation request from the current BSS, so
1909 * reject it.
1910 */
1911 mutex_unlock(&ifmgd->mtx);
1912 return -EALREADY;
1913 }
1914
1915 /* Trying to reassociate - clear previous association state */
1916 ieee80211_set_disassoc(sdata);
2446 } 1917 }
1918 mutex_unlock(&ifmgd->mtx);
2447 1919
2448 list_add(&wk->list, &ifmgd->work_list); 1920 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
1921 if (!wk)
1922 return -ENOMEM;
2449 1923
2450 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N; 1924 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
1925 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
2451 1926
2452 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) 1927 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2453 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || 1928 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
@@ -2455,8 +1930,6 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2455 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) 1930 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2456 ifmgd->flags |= IEEE80211_STA_DISABLE_11N; 1931 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2457 1932
2458 sdata->local->oper_channel = req->bss->channel;
2459 ieee80211_hw_config(sdata->local, 0);
2460 1933
2461 if (req->ie && req->ie_len) { 1934 if (req->ie && req->ie_len) {
2462 memcpy(wk->ie, req->ie, req->ie_len); 1935 memcpy(wk->ie, req->ie, req->ie_len);
@@ -2464,12 +1937,55 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2464 } else 1937 } else
2465 wk->ie_len = 0; 1938 wk->ie_len = 0;
2466 1939
1940 wk->assoc.bss = req->bss;
1941
1942 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
1943
1944 /* new association always uses requested smps mode */
1945 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
1946 if (ifmgd->powersave)
1947 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
1948 else
1949 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
1950 } else
1951 ifmgd->ap_smps = ifmgd->req_smps;
1952
1953 wk->assoc.smps = ifmgd->ap_smps;
1954 /*
1955 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
1956 * We still associate in non-HT mode (11a/b/g) if any one of these
1957 * ciphers is configured as pairwise.
1958 * We can set this to true for non-11n hardware, that'll be checked
1959 * separately along with the peer capabilities.
1960 */
1961 wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
1962 wk->assoc.capability = req->bss->capability;
1963 wk->assoc.wmm_used = bss->wmm_used;
1964 wk->assoc.supp_rates = bss->supp_rates;
1965 wk->assoc.supp_rates_len = bss->supp_rates_len;
1966 wk->assoc.ht_information_ie =
1967 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
1968
1969 if (bss->wmm_used && bss->uapsd_supported &&
1970 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
1971 wk->assoc.uapsd_used = true;
1972 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
1973 } else {
1974 wk->assoc.uapsd_used = false;
1975 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
1976 }
1977
1978 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
1979 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
1980 wk->assoc.ssid_len = ssid[1];
1981
2467 if (req->prev_bssid) 1982 if (req->prev_bssid)
2468 memcpy(wk->prev_bssid, req->prev_bssid, ETH_ALEN); 1983 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
2469 1984
2470 wk->state = IEEE80211_MGD_STATE_ASSOC; 1985 wk->type = IEEE80211_WORK_ASSOC;
2471 wk->tries = 0; 1986 wk->chan = req->bss->channel;
2472 wk->timeout = jiffies; /* run right away */ 1987 wk->sdata = sdata;
1988 wk->done = ieee80211_assoc_done;
2473 1989
2474 if (req->use_mfp) { 1990 if (req->use_mfp) {
2475 ifmgd->mfp = IEEE80211_MFP_REQUIRED; 1991 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
@@ -2484,57 +2000,73 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2484 else 2000 else
2485 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; 2001 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2486 2002
2487 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work); 2003 ieee80211_add_work(wk);
2488 2004 return 0;
2489 err = 0;
2490
2491 out:
2492 mutex_unlock(&ifmgd->mtx);
2493 return err;
2494} 2005}
2495 2006
2496int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, 2007int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
2497 struct cfg80211_deauth_request *req, 2008 struct cfg80211_deauth_request *req,
2498 void *cookie) 2009 void *cookie)
2499{ 2010{
2011 struct ieee80211_local *local = sdata->local;
2500 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2012 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2501 struct ieee80211_mgd_work *wk; 2013 struct ieee80211_work *wk;
2502 const u8 *bssid = NULL; 2014 const u8 *bssid = req->bss->bssid;
2503 2015
2504 mutex_lock(&ifmgd->mtx); 2016 mutex_lock(&ifmgd->mtx);
2505 2017
2506 if (ifmgd->associated && &ifmgd->associated->cbss == req->bss) { 2018 if (ifmgd->associated == req->bss) {
2507 bssid = req->bss->bssid; 2019 bssid = req->bss->bssid;
2508 ieee80211_set_disassoc(sdata, true); 2020 ieee80211_set_disassoc(sdata);
2509 } else list_for_each_entry(wk, &ifmgd->work_list, list) { 2021 mutex_unlock(&ifmgd->mtx);
2510 if (&wk->bss->cbss == req->bss) { 2022 } else {
2511 bssid = req->bss->bssid; 2023 bool not_auth_yet = false;
2512 list_del(&wk->list); 2024
2513 kfree(wk); 2025 mutex_unlock(&ifmgd->mtx);
2026
2027 mutex_lock(&local->work_mtx);
2028 list_for_each_entry(wk, &local->work_list, list) {
2029 if (wk->sdata != sdata)
2030 continue;
2031
2032 if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
2033 wk->type != IEEE80211_WORK_AUTH &&
2034 wk->type != IEEE80211_WORK_ASSOC)
2035 continue;
2036
2037 if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
2038 continue;
2039
2040 not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
2041 list_del_rcu(&wk->list);
2042 free_work(wk);
2514 break; 2043 break;
2515 } 2044 }
2516 } 2045 mutex_unlock(&local->work_mtx);
2517 2046
2518 /* 2047 /*
2519 * cfg80211 should catch this ... but it's racy since 2048 * If somebody requests authentication and we haven't
2520 * we can receive a deauth frame, process it, hand it 2049 * sent out an auth frame yet there's no need to send
2521 * to cfg80211 while that's in a locked section already 2050 * out a deauth frame either. If the state was PROBE,
2522 * trying to tell us that the user wants to disconnect. 2051 * then this is the case. If it's AUTH we have sent a
2523 */ 2052 * frame, and if it's IDLE we have completed the auth
2524 if (!bssid) { 2053 * process already.
2525 mutex_unlock(&ifmgd->mtx); 2054 */
2526 return -ENOLINK; 2055 if (not_auth_yet) {
2056 __cfg80211_auth_canceled(sdata->dev, bssid);
2057 return 0;
2058 }
2527 } 2059 }
2528 2060
2529 mutex_unlock(&ifmgd->mtx);
2530
2531 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n", 2061 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
2532 sdata->dev->name, bssid, req->reason_code); 2062 sdata->name, bssid, req->reason_code);
2533 2063
2534 ieee80211_send_deauth_disassoc(sdata, bssid, 2064 ieee80211_send_deauth_disassoc(sdata, bssid,
2535 IEEE80211_STYPE_DEAUTH, req->reason_code, 2065 IEEE80211_STYPE_DEAUTH, req->reason_code,
2536 cookie); 2066 cookie);
2537 2067
2068 ieee80211_recalc_idle(sdata->local);
2069
2538 return 0; 2070 return 0;
2539} 2071}
2540 2072
@@ -2552,20 +2084,58 @@ int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
2552 * to cfg80211 while that's in a locked section already 2084 * to cfg80211 while that's in a locked section already
2553 * trying to tell us that the user wants to disconnect. 2085 * trying to tell us that the user wants to disconnect.
2554 */ 2086 */
2555 if (&ifmgd->associated->cbss != req->bss) { 2087 if (ifmgd->associated != req->bss) {
2556 mutex_unlock(&ifmgd->mtx); 2088 mutex_unlock(&ifmgd->mtx);
2557 return -ENOLINK; 2089 return -ENOLINK;
2558 } 2090 }
2559 2091
2560 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n", 2092 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
2561 sdata->dev->name, req->bss->bssid, req->reason_code); 2093 sdata->name, req->bss->bssid, req->reason_code);
2562 2094
2563 ieee80211_set_disassoc(sdata, false); 2095 ieee80211_set_disassoc(sdata);
2564 2096
2565 mutex_unlock(&ifmgd->mtx); 2097 mutex_unlock(&ifmgd->mtx);
2566 2098
2567 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid, 2099 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
2568 IEEE80211_STYPE_DISASSOC, req->reason_code, 2100 IEEE80211_STYPE_DISASSOC, req->reason_code,
2569 cookie); 2101 cookie);
2102
2103 ieee80211_recalc_idle(sdata->local);
2104
2105 return 0;
2106}
2107
2108int ieee80211_mgd_action(struct ieee80211_sub_if_data *sdata,
2109 struct ieee80211_channel *chan,
2110 enum nl80211_channel_type channel_type,
2111 const u8 *buf, size_t len, u64 *cookie)
2112{
2113 struct ieee80211_local *local = sdata->local;
2114 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2115 struct sk_buff *skb;
2116
2117 /* Check that we are on the requested channel for transmission */
2118 if ((chan != local->tmp_channel ||
2119 channel_type != local->tmp_channel_type) &&
2120 (chan != local->oper_channel ||
2121 channel_type != local->oper_channel_type))
2122 return -EBUSY;
2123
2124 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2125 if (!skb)
2126 return -ENOMEM;
2127 skb_reserve(skb, local->hw.extra_tx_headroom);
2128
2129 memcpy(skb_put(skb, len), buf, len);
2130
2131 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
2132 IEEE80211_SKB_CB(skb)->flags |=
2133 IEEE80211_TX_INTFL_DONT_ENCRYPT;
2134 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2135 IEEE80211_TX_CTL_REQ_TX_STATUS;
2136 skb->dev = sdata->dev;
2137 ieee80211_tx_skb(sdata, skb);
2138
2139 *cookie = (unsigned long) skb;
2570 return 0; 2140 return 0;
2571} 2141}