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.c1317
1 files changed, 413 insertions, 904 deletions
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 05a18f43e1bf..41812a15eea0 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -27,10 +27,6 @@
27#include "rate.h" 27#include "rate.h"
28#include "led.h" 28#include "led.h"
29 29
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 30#define IEEE80211_MAX_PROBE_TRIES 5
35 31
36/* 32/*
@@ -75,11 +71,8 @@ enum rx_mgmt_action {
75 /* caller must call cfg80211_send_disassoc() */ 71 /* caller must call cfg80211_send_disassoc() */
76 RX_MGMT_CFG80211_DISASSOC, 72 RX_MGMT_CFG80211_DISASSOC,
77 73
78 /* caller must call cfg80211_auth_timeout() & free work */ 74 /* caller must tell cfg80211 about internal error */
79 RX_MGMT_CFG80211_AUTH_TO, 75 RX_MGMT_CFG80211_ASSOC_ERROR,
80
81 /* caller must call cfg80211_assoc_timeout() & free work */
82 RX_MGMT_CFG80211_ASSOC_TO,
83}; 76};
84 77
85/* utils */ 78/* utils */
@@ -122,27 +115,6 @@ static int ecw2cw(int ecw)
122 return (1 << ecw) - 1; 115 return (1 << ecw) - 1;
123} 116}
124 117
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/* 118/*
147 * ieee80211_enable_ht should be called only after the operating band 119 * ieee80211_enable_ht should be called only after the operating band
148 * has been determined as ht configuration depends on the hw's 120 * has been determined as ht configuration depends on the hw's
@@ -202,7 +174,7 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
202 ieee80211_hw_config(local, 0); 174 ieee80211_hw_config(local, 0);
203 175
204 rcu_read_lock(); 176 rcu_read_lock();
205 sta = sta_info_get(local, bssid); 177 sta = sta_info_get(sdata, bssid);
206 if (sta) 178 if (sta)
207 rate_control_rate_update(local, sband, sta, 179 rate_control_rate_update(local, sband, sta,
208 IEEE80211_RC_HT_CHANGED); 180 IEEE80211_RC_HT_CHANGED);
@@ -228,209 +200,6 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
228 200
229/* frame sending functions */ 201/* frame sending functions */
230 202
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_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
430 ieee80211_tx_skb(sdata, skb);
431}
432
433
434static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, 203static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
435 const u8 *bssid, u16 stype, u16 reason, 204 const u8 *bssid, u16 stype, u16 reason,
436 void *cookie) 205 void *cookie)
@@ -443,7 +212,7 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
443 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); 212 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
444 if (!skb) { 213 if (!skb) {
445 printk(KERN_DEBUG "%s: failed to allocate buffer for " 214 printk(KERN_DEBUG "%s: failed to allocate buffer for "
446 "deauth/disassoc frame\n", sdata->dev->name); 215 "deauth/disassoc frame\n", sdata->name);
447 return; 216 return;
448 } 217 }
449 skb_reserve(skb, local->hw.extra_tx_headroom); 218 skb_reserve(skb, local->hw.extra_tx_headroom);
@@ -451,7 +220,7 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
451 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 220 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
452 memset(mgmt, 0, 24); 221 memset(mgmt, 0, 24);
453 memcpy(mgmt->da, bssid, ETH_ALEN); 222 memcpy(mgmt->da, bssid, ETH_ALEN);
454 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 223 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
455 memcpy(mgmt->bssid, bssid, ETH_ALEN); 224 memcpy(mgmt->bssid, bssid, ETH_ALEN);
456 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); 225 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
457 skb_put(skb, 2); 226 skb_put(skb, 2);
@@ -476,30 +245,15 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
476void ieee80211_send_pspoll(struct ieee80211_local *local, 245void ieee80211_send_pspoll(struct ieee80211_local *local,
477 struct ieee80211_sub_if_data *sdata) 246 struct ieee80211_sub_if_data *sdata)
478{ 247{
479 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
480 struct ieee80211_pspoll *pspoll; 248 struct ieee80211_pspoll *pspoll;
481 struct sk_buff *skb; 249 struct sk_buff *skb;
482 u16 fc;
483 250
484 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll)); 251 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
485 if (!skb) { 252 if (!skb)
486 printk(KERN_DEBUG "%s: failed to allocate buffer for "
487 "pspoll frame\n", sdata->dev->name);
488 return; 253 return;
489 }
490 skb_reserve(skb, local->hw.extra_tx_headroom);
491
492 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
493 memset(pspoll, 0, sizeof(*pspoll));
494 fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
495 pspoll->frame_control = cpu_to_le16(fc);
496 pspoll->aid = cpu_to_le16(ifmgd->aid);
497
498 /* aid in PS-Poll has its two MSBs each set to 1 */
499 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
500 254
501 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN); 255 pspoll = (struct ieee80211_pspoll *) skb->data;
502 memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN); 256 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
503 257
504 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 258 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
505 ieee80211_tx_skb(sdata, skb); 259 ieee80211_tx_skb(sdata, skb);
@@ -510,30 +264,47 @@ void ieee80211_send_nullfunc(struct ieee80211_local *local,
510 int powersave) 264 int powersave)
511{ 265{
512 struct sk_buff *skb; 266 struct sk_buff *skb;
267 struct ieee80211_hdr_3addr *nullfunc;
268
269 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
270 if (!skb)
271 return;
272
273 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
274 if (powersave)
275 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
276
277 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
278 ieee80211_tx_skb(sdata, skb);
279}
280
281static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
282 struct ieee80211_sub_if_data *sdata)
283{
284 struct sk_buff *skb;
513 struct ieee80211_hdr *nullfunc; 285 struct ieee80211_hdr *nullfunc;
514 __le16 fc; 286 __le16 fc;
515 287
516 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 288 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
517 return; 289 return;
518 290
519 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); 291 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
520 if (!skb) { 292 if (!skb) {
521 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " 293 printk(KERN_DEBUG "%s: failed to allocate buffer for 4addr "
522 "frame\n", sdata->dev->name); 294 "nullfunc frame\n", sdata->name);
523 return; 295 return;
524 } 296 }
525 skb_reserve(skb, local->hw.extra_tx_headroom); 297 skb_reserve(skb, local->hw.extra_tx_headroom);
526 298
527 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); 299 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
528 memset(nullfunc, 0, 24); 300 memset(nullfunc, 0, 30);
529 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | 301 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
530 IEEE80211_FCTL_TODS); 302 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
531 if (powersave)
532 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
533 nullfunc->frame_control = fc; 303 nullfunc->frame_control = fc;
534 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); 304 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
535 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); 305 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
536 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); 306 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
307 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
537 308
538 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 309 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
539 ieee80211_tx_skb(sdata, skb); 310 ieee80211_tx_skb(sdata, skb);
@@ -546,7 +317,7 @@ static void ieee80211_chswitch_work(struct work_struct *work)
546 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); 317 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
547 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 318 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
548 319
549 if (!netif_running(sdata->dev)) 320 if (!ieee80211_sdata_running(sdata))
550 return; 321 return;
551 322
552 mutex_lock(&ifmgd->mtx); 323 mutex_lock(&ifmgd->mtx);
@@ -557,7 +328,7 @@ static void ieee80211_chswitch_work(struct work_struct *work)
557 ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL); 328 ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL);
558 329
559 /* XXX: shouldn't really modify cfg80211-owned data! */ 330 /* XXX: shouldn't really modify cfg80211-owned data! */
560 ifmgd->associated->cbss.channel = sdata->local->oper_channel; 331 ifmgd->associated->channel = sdata->local->oper_channel;
561 332
562 ieee80211_wake_queues_by_reason(&sdata->local->hw, 333 ieee80211_wake_queues_by_reason(&sdata->local->hw,
563 IEEE80211_QUEUE_STOP_REASON_CSA); 334 IEEE80211_QUEUE_STOP_REASON_CSA);
@@ -584,6 +355,8 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
584 struct ieee80211_channel_sw_ie *sw_elem, 355 struct ieee80211_channel_sw_ie *sw_elem,
585 struct ieee80211_bss *bss) 356 struct ieee80211_bss *bss)
586{ 357{
358 struct cfg80211_bss *cbss =
359 container_of((void *)bss, struct cfg80211_bss, priv);
587 struct ieee80211_channel *new_ch; 360 struct ieee80211_channel *new_ch;
588 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 361 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
589 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num); 362 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
@@ -617,7 +390,7 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
617 mod_timer(&ifmgd->chswitch_timer, 390 mod_timer(&ifmgd->chswitch_timer,
618 jiffies + 391 jiffies +
619 msecs_to_jiffies(sw_elem->count * 392 msecs_to_jiffies(sw_elem->count *
620 bss->cbss.beacon_interval)); 393 cbss->beacon_interval));
621 } 394 }
622} 395}
623 396
@@ -661,8 +434,11 @@ static void ieee80211_enable_ps(struct ieee80211_local *local,
661 } else { 434 } else {
662 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) 435 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
663 ieee80211_send_nullfunc(local, sdata, 1); 436 ieee80211_send_nullfunc(local, sdata, 1);
664 conf->flags |= IEEE80211_CONF_PS; 437
665 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 438 if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
439 conf->flags |= IEEE80211_CONF_PS;
440 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
441 }
666 } 442 }
667} 443}
668 444
@@ -691,8 +467,13 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
691 return; 467 return;
692 } 468 }
693 469
470 if (!list_empty(&local->work_list)) {
471 local->ps_sdata = NULL;
472 goto change;
473 }
474
694 list_for_each_entry(sdata, &local->interfaces, list) { 475 list_for_each_entry(sdata, &local->interfaces, list) {
695 if (!netif_running(sdata->dev)) 476 if (!ieee80211_sdata_running(sdata))
696 continue; 477 continue;
697 if (sdata->vif.type != NL80211_IFTYPE_STATION) 478 if (sdata->vif.type != NL80211_IFTYPE_STATION)
698 continue; 479 continue;
@@ -701,7 +482,8 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
701 } 482 }
702 483
703 if (count == 1 && found->u.mgd.powersave && 484 if (count == 1 && found->u.mgd.powersave &&
704 found->u.mgd.associated && list_empty(&found->u.mgd.work_list) && 485 found->u.mgd.associated &&
486 found->u.mgd.associated->beacon_ies &&
705 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL | 487 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
706 IEEE80211_STA_CONNECTION_POLL))) { 488 IEEE80211_STA_CONNECTION_POLL))) {
707 s32 beaconint_us; 489 s32 beaconint_us;
@@ -715,20 +497,29 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
715 if (beaconint_us > latency) { 497 if (beaconint_us > latency) {
716 local->ps_sdata = NULL; 498 local->ps_sdata = NULL;
717 } else { 499 } else {
718 u8 dtimper = found->vif.bss_conf.dtim_period; 500 struct ieee80211_bss *bss;
719 int maxslp = 1; 501 int maxslp = 1;
502 u8 dtimper;
503
504 bss = (void *)found->u.mgd.associated->priv;
505 dtimper = bss->dtim_period;
720 506
721 if (dtimper > 1) 507 /* If the TIM IE is invalid, pretend the value is 1 */
508 if (!dtimper)
509 dtimper = 1;
510 else if (dtimper > 1)
722 maxslp = min_t(int, dtimper, 511 maxslp = min_t(int, dtimper,
723 latency / beaconint_us); 512 latency / beaconint_us);
724 513
725 local->hw.conf.max_sleep_period = maxslp; 514 local->hw.conf.max_sleep_period = maxslp;
515 local->hw.conf.ps_dtim_period = dtimper;
726 local->ps_sdata = found; 516 local->ps_sdata = found;
727 } 517 }
728 } else { 518 } else {
729 local->ps_sdata = NULL; 519 local->ps_sdata = NULL;
730 } 520 }
731 521
522 change:
732 ieee80211_change_ps(local); 523 ieee80211_change_ps(local);
733} 524}
734 525
@@ -753,6 +544,7 @@ void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
753 container_of(work, struct ieee80211_local, 544 container_of(work, struct ieee80211_local,
754 dynamic_ps_enable_work); 545 dynamic_ps_enable_work);
755 struct ieee80211_sub_if_data *sdata = local->ps_sdata; 546 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
547 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
756 548
757 /* can only happen when PS was just disabled anyway */ 549 /* can only happen when PS was just disabled anyway */
758 if (!sdata) 550 if (!sdata)
@@ -761,11 +553,16 @@ void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
761 if (local->hw.conf.flags & IEEE80211_CONF_PS) 553 if (local->hw.conf.flags & IEEE80211_CONF_PS)
762 return; 554 return;
763 555
764 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) 556 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
557 (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)))
765 ieee80211_send_nullfunc(local, sdata, 1); 558 ieee80211_send_nullfunc(local, sdata, 1);
766 559
767 local->hw.conf.flags |= IEEE80211_CONF_PS; 560 if (!(local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) ||
768 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 561 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
562 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
563 local->hw.conf.flags |= IEEE80211_CONF_PS;
564 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
565 }
769} 566}
770 567
771void ieee80211_dynamic_ps_timer(unsigned long data) 568void ieee80211_dynamic_ps_timer(unsigned long data)
@@ -786,9 +583,9 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
786 struct ieee80211_tx_queue_params params; 583 struct ieee80211_tx_queue_params params;
787 size_t left; 584 size_t left;
788 int count; 585 int count;
789 u8 *pos; 586 u8 *pos, uapsd_queues = 0;
790 587
791 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) 588 if (local->hw.queues < 4)
792 return; 589 return;
793 590
794 if (!wmm_param) 591 if (!wmm_param)
@@ -796,6 +593,10 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
796 593
797 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) 594 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
798 return; 595 return;
596
597 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
598 uapsd_queues = local->uapsd_queues;
599
799 count = wmm_param[6] & 0x0f; 600 count = wmm_param[6] & 0x0f;
800 if (count == ifmgd->wmm_last_param_set) 601 if (count == ifmgd->wmm_last_param_set)
801 return; 602 return;
@@ -810,6 +611,7 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
810 for (; left >= 4; left -= 4, pos += 4) { 611 for (; left >= 4; left -= 4, pos += 4) {
811 int aci = (pos[0] >> 5) & 0x03; 612 int aci = (pos[0] >> 5) & 0x03;
812 int acm = (pos[0] >> 4) & 0x01; 613 int acm = (pos[0] >> 4) & 0x01;
614 bool uapsd = false;
813 int queue; 615 int queue;
814 616
815 switch (aci) { 617 switch (aci) {
@@ -817,22 +619,30 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
817 queue = 3; 619 queue = 3;
818 if (acm) 620 if (acm)
819 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ 621 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
622 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
623 uapsd = true;
820 break; 624 break;
821 case 2: /* AC_VI */ 625 case 2: /* AC_VI */
822 queue = 1; 626 queue = 1;
823 if (acm) 627 if (acm)
824 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ 628 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
629 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
630 uapsd = true;
825 break; 631 break;
826 case 3: /* AC_VO */ 632 case 3: /* AC_VO */
827 queue = 0; 633 queue = 0;
828 if (acm) 634 if (acm)
829 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ 635 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
636 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
637 uapsd = true;
830 break; 638 break;
831 case 0: /* AC_BE */ 639 case 0: /* AC_BE */
832 default: 640 default:
833 queue = 2; 641 queue = 2;
834 if (acm) 642 if (acm)
835 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ 643 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
644 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
645 uapsd = true;
836 break; 646 break;
837 } 647 }
838 648
@@ -840,11 +650,14 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
840 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); 650 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
841 params.cw_min = ecw2cw(pos[1] & 0x0f); 651 params.cw_min = ecw2cw(pos[1] & 0x0f);
842 params.txop = get_unaligned_le16(pos + 2); 652 params.txop = get_unaligned_le16(pos + 2);
653 params.uapsd = uapsd;
654
843#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 655#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
844 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " 656 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
845 "cWmin=%d cWmax=%d txop=%d\n", 657 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
846 wiphy_name(local->hw.wiphy), queue, aci, acm, 658 wiphy_name(local->hw.wiphy), queue, aci, acm,
847 params.aifs, params.cw_min, params.cw_max, params.txop); 659 params.aifs, params.cw_min, params.cw_max, params.txop,
660 params.uapsd);
848#endif 661#endif
849 if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx) 662 if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx)
850 printk(KERN_DEBUG "%s: failed to set TX queue " 663 printk(KERN_DEBUG "%s: failed to set TX queue "
@@ -871,6 +684,8 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
871 } 684 }
872 685
873 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); 686 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
687 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
688 use_short_slot = true;
874 689
875 if (use_protection != bss_conf->use_cts_prot) { 690 if (use_protection != bss_conf->use_cts_prot) {
876 bss_conf->use_cts_prot = use_protection; 691 bss_conf->use_cts_prot = use_protection;
@@ -891,25 +706,23 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
891} 706}
892 707
893static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, 708static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
894 struct ieee80211_mgd_work *wk, 709 struct cfg80211_bss *cbss,
895 u32 bss_info_changed) 710 u32 bss_info_changed)
896{ 711{
712 struct ieee80211_bss *bss = (void *)cbss->priv;
897 struct ieee80211_local *local = sdata->local; 713 struct ieee80211_local *local = sdata->local;
898 struct ieee80211_bss *bss = wk->bss;
899 714
900 bss_info_changed |= BSS_CHANGED_ASSOC; 715 bss_info_changed |= BSS_CHANGED_ASSOC;
901 /* set timing information */ 716 /* set timing information */
902 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval; 717 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
903 sdata->vif.bss_conf.timestamp = bss->cbss.tsf; 718 sdata->vif.bss_conf.timestamp = cbss->tsf;
904 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
905 719
906 bss_info_changed |= BSS_CHANGED_BEACON_INT; 720 bss_info_changed |= BSS_CHANGED_BEACON_INT;
907 bss_info_changed |= ieee80211_handle_bss_capability(sdata, 721 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
908 bss->cbss.capability, bss->has_erp_value, bss->erp_value); 722 cbss->capability, bss->has_erp_value, bss->erp_value);
909 723
910 sdata->u.mgd.associated = bss; 724 sdata->u.mgd.associated = cbss;
911 sdata->u.mgd.old_associate_work = wk; 725 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
912 memcpy(sdata->u.mgd.bssid, bss->cbss.bssid, ETH_ALEN);
913 726
914 /* just to be sure */ 727 /* just to be sure */
915 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL | 728 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
@@ -940,99 +753,14 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
940 753
941 mutex_lock(&local->iflist_mtx); 754 mutex_lock(&local->iflist_mtx);
942 ieee80211_recalc_ps(local, -1); 755 ieee80211_recalc_ps(local, -1);
756 ieee80211_recalc_smps(local, sdata);
943 mutex_unlock(&local->iflist_mtx); 757 mutex_unlock(&local->iflist_mtx);
944 758
945 netif_tx_start_all_queues(sdata->dev); 759 netif_tx_start_all_queues(sdata->dev);
946 netif_carrier_on(sdata->dev); 760 netif_carrier_on(sdata->dev);
947} 761}
948 762
949static enum rx_mgmt_action __must_check 763static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata)
950ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
951 struct ieee80211_mgd_work *wk)
952{
953 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
954 struct ieee80211_local *local = sdata->local;
955
956 wk->tries++;
957 if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
958 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
959 sdata->dev->name, wk->bss->cbss.bssid);
960
961 /*
962 * Most likely AP is not in the range so remove the
963 * bss struct for that AP.
964 */
965 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
966
967 /*
968 * We might have a pending scan which had no chance to run yet
969 * due to work needing to be done. Hence, queue the STAs work
970 * again for that.
971 */
972 ieee80211_queue_work(&local->hw, &ifmgd->work);
973 return RX_MGMT_CFG80211_AUTH_TO;
974 }
975
976 printk(KERN_DEBUG "%s: direct probe to AP %pM (try %d)\n",
977 sdata->dev->name, wk->bss->cbss.bssid,
978 wk->tries);
979
980 /*
981 * Direct probe is sent to broadcast address as some APs
982 * will not answer to direct packet in unassociated state.
983 */
984 ieee80211_send_probe_req(sdata, NULL, wk->ssid, wk->ssid_len, NULL, 0);
985
986 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
987 run_again(ifmgd, wk->timeout);
988
989 return RX_MGMT_NONE;
990}
991
992
993static enum rx_mgmt_action __must_check
994ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
995 struct ieee80211_mgd_work *wk)
996{
997 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
998 struct ieee80211_local *local = sdata->local;
999
1000 wk->tries++;
1001 if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
1002 printk(KERN_DEBUG "%s: authentication with AP %pM"
1003 " timed out\n",
1004 sdata->dev->name, wk->bss->cbss.bssid);
1005
1006 /*
1007 * Most likely AP is not in the range so remove the
1008 * bss struct for that AP.
1009 */
1010 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
1011
1012 /*
1013 * We might have a pending scan which had no chance to run yet
1014 * due to work needing to be done. Hence, queue the STAs work
1015 * again for that.
1016 */
1017 ieee80211_queue_work(&local->hw, &ifmgd->work);
1018 return RX_MGMT_CFG80211_AUTH_TO;
1019 }
1020
1021 printk(KERN_DEBUG "%s: authenticate with AP %pM (try %d)\n",
1022 sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
1023
1024 ieee80211_send_auth(sdata, 1, wk->auth_alg, wk->ie, wk->ie_len,
1025 wk->bss->cbss.bssid, NULL, 0, 0);
1026 wk->auth_transaction = 2;
1027
1028 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
1029 run_again(ifmgd, wk->timeout);
1030
1031 return RX_MGMT_NONE;
1032}
1033
1034static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1035 bool deauth)
1036{ 764{
1037 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 765 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1038 struct ieee80211_local *local = sdata->local; 766 struct ieee80211_local *local = sdata->local;
@@ -1045,21 +773,11 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1045 if (WARN_ON(!ifmgd->associated)) 773 if (WARN_ON(!ifmgd->associated))
1046 return; 774 return;
1047 775
1048 memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN); 776 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1049 777
1050 ifmgd->associated = NULL; 778 ifmgd->associated = NULL;
1051 memset(ifmgd->bssid, 0, ETH_ALEN); 779 memset(ifmgd->bssid, 0, ETH_ALEN);
1052 780
1053 if (deauth) {
1054 kfree(ifmgd->old_associate_work);
1055 ifmgd->old_associate_work = NULL;
1056 } else {
1057 struct ieee80211_mgd_work *wk = ifmgd->old_associate_work;
1058
1059 wk->state = IEEE80211_MGD_STATE_IDLE;
1060 list_add(&wk->list, &ifmgd->work_list);
1061 }
1062
1063 /* 781 /*
1064 * we need to commit the associated = NULL change because the 782 * we need to commit the associated = NULL change because the
1065 * scan code uses that to determine whether this iface should 783 * scan code uses that to determine whether this iface should
@@ -1078,9 +796,11 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1078 netif_carrier_off(sdata->dev); 796 netif_carrier_off(sdata->dev);
1079 797
1080 rcu_read_lock(); 798 rcu_read_lock();
1081 sta = sta_info_get(local, bssid); 799 sta = sta_info_get(sdata, bssid);
1082 if (sta) 800 if (sta) {
801 set_sta_flags(sta, WLAN_STA_DISASSOC);
1083 ieee80211_sta_tear_down_BA_sessions(sta); 802 ieee80211_sta_tear_down_BA_sessions(sta);
803 }
1084 rcu_read_unlock(); 804 rcu_read_unlock();
1085 805
1086 changed |= ieee80211_reset_erp_info(sdata); 806 changed |= ieee80211_reset_erp_info(sdata);
@@ -1113,57 +833,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1113 changed |= BSS_CHANGED_BSSID; 833 changed |= BSS_CHANGED_BSSID;
1114 ieee80211_bss_info_change_notify(sdata, changed); 834 ieee80211_bss_info_change_notify(sdata, changed);
1115 835
1116 rcu_read_lock(); 836 sta_info_destroy_addr(sdata, bssid);
1117
1118 sta = sta_info_get(local, bssid);
1119 if (!sta) {
1120 rcu_read_unlock();
1121 return;
1122 }
1123
1124 sta_info_unlink(&sta);
1125
1126 rcu_read_unlock();
1127
1128 sta_info_destroy(sta);
1129}
1130
1131static enum rx_mgmt_action __must_check
1132ieee80211_associate(struct ieee80211_sub_if_data *sdata,
1133 struct ieee80211_mgd_work *wk)
1134{
1135 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1136 struct ieee80211_local *local = sdata->local;
1137
1138 wk->tries++;
1139 if (wk->tries > IEEE80211_ASSOC_MAX_TRIES) {
1140 printk(KERN_DEBUG "%s: association with AP %pM"
1141 " timed out\n",
1142 sdata->dev->name, wk->bss->cbss.bssid);
1143
1144 /*
1145 * Most likely AP is not in the range so remove the
1146 * bss struct for that AP.
1147 */
1148 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
1149
1150 /*
1151 * We might have a pending scan which had no chance to run yet
1152 * due to work needing to be done. Hence, queue the STAs work
1153 * again for that.
1154 */
1155 ieee80211_queue_work(&local->hw, &ifmgd->work);
1156 return RX_MGMT_CFG80211_ASSOC_TO;
1157 }
1158
1159 printk(KERN_DEBUG "%s: associate with AP %pM (try %d)\n",
1160 sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
1161 ieee80211_send_assoc(sdata, wk);
1162
1163 wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
1164 run_again(ifmgd, wk->timeout);
1165
1166 return RX_MGMT_NONE;
1167} 837}
1168 838
1169void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, 839void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
@@ -1189,8 +859,8 @@ static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1189 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 859 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1190 const u8 *ssid; 860 const u8 *ssid;
1191 861
1192 ssid = ieee80211_bss_get_ie(&ifmgd->associated->cbss, WLAN_EID_SSID); 862 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1193 ieee80211_send_probe_req(sdata, ifmgd->associated->cbss.bssid, 863 ieee80211_send_probe_req(sdata, ifmgd->associated->bssid,
1194 ssid + 2, ssid[1], NULL, 0); 864 ssid + 2, ssid[1], NULL, 0);
1195 865
1196 ifmgd->probe_send_count++; 866 ifmgd->probe_send_count++;
@@ -1204,12 +874,15 @@ static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1204 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 874 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1205 bool already = false; 875 bool already = false;
1206 876
1207 if (!netif_running(sdata->dev)) 877 if (!ieee80211_sdata_running(sdata))
1208 return; 878 return;
1209 879
1210 if (sdata->local->scanning) 880 if (sdata->local->scanning)
1211 return; 881 return;
1212 882
883 if (sdata->local->tmp_channel)
884 return;
885
1213 mutex_lock(&ifmgd->mtx); 886 mutex_lock(&ifmgd->mtx);
1214 887
1215 if (!ifmgd->associated) 888 if (!ifmgd->associated)
@@ -1218,7 +891,7 @@ static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1218#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 891#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1219 if (beacon && net_ratelimit()) 892 if (beacon && net_ratelimit())
1220 printk(KERN_DEBUG "%s: detected beacon loss from AP " 893 printk(KERN_DEBUG "%s: detected beacon loss from AP "
1221 "- sending probe request\n", sdata->dev->name); 894 "- sending probe request\n", sdata->name);
1222#endif 895#endif
1223 896
1224 /* 897 /*
@@ -1271,88 +944,8 @@ void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1271} 944}
1272EXPORT_SYMBOL(ieee80211_beacon_loss); 945EXPORT_SYMBOL(ieee80211_beacon_loss);
1273 946
1274static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
1275 struct ieee80211_mgd_work *wk)
1276{
1277 wk->state = IEEE80211_MGD_STATE_IDLE;
1278 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
1279}
1280
1281
1282static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1283 struct ieee80211_mgd_work *wk,
1284 struct ieee80211_mgmt *mgmt,
1285 size_t len)
1286{
1287 u8 *pos;
1288 struct ieee802_11_elems elems;
1289
1290 pos = mgmt->u.auth.variable;
1291 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1292 if (!elems.challenge)
1293 return;
1294 ieee80211_send_auth(sdata, 3, wk->auth_alg,
1295 elems.challenge - 2, elems.challenge_len + 2,
1296 wk->bss->cbss.bssid,
1297 wk->key, wk->key_len, wk->key_idx);
1298 wk->auth_transaction = 4;
1299}
1300
1301static enum rx_mgmt_action __must_check
1302ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1303 struct ieee80211_mgd_work *wk,
1304 struct ieee80211_mgmt *mgmt, size_t len)
1305{
1306 u16 auth_alg, auth_transaction, status_code;
1307
1308 if (wk->state != IEEE80211_MGD_STATE_AUTH)
1309 return RX_MGMT_NONE;
1310
1311 if (len < 24 + 6)
1312 return RX_MGMT_NONE;
1313
1314 if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
1315 return RX_MGMT_NONE;
1316
1317 if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
1318 return RX_MGMT_NONE;
1319
1320 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1321 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1322 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1323
1324 if (auth_alg != wk->auth_alg ||
1325 auth_transaction != wk->auth_transaction)
1326 return RX_MGMT_NONE;
1327
1328 if (status_code != WLAN_STATUS_SUCCESS) {
1329 list_del(&wk->list);
1330 kfree(wk);
1331 return RX_MGMT_CFG80211_AUTH;
1332 }
1333
1334 switch (wk->auth_alg) {
1335 case WLAN_AUTH_OPEN:
1336 case WLAN_AUTH_LEAP:
1337 case WLAN_AUTH_FT:
1338 ieee80211_auth_completed(sdata, wk);
1339 return RX_MGMT_CFG80211_AUTH;
1340 case WLAN_AUTH_SHARED_KEY:
1341 if (wk->auth_transaction == 4) {
1342 ieee80211_auth_completed(sdata, wk);
1343 return RX_MGMT_CFG80211_AUTH;
1344 } else
1345 ieee80211_auth_challenge(sdata, wk, mgmt, len);
1346 break;
1347 }
1348
1349 return RX_MGMT_NONE;
1350}
1351
1352
1353static enum rx_mgmt_action __must_check 947static enum rx_mgmt_action __must_check
1354ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, 948ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1355 struct ieee80211_mgd_work *wk,
1356 struct ieee80211_mgmt *mgmt, size_t len) 949 struct ieee80211_mgmt *mgmt, size_t len)
1357{ 950{
1358 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 951 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
@@ -1364,23 +957,15 @@ ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1364 957
1365 ASSERT_MGD_MTX(ifmgd); 958 ASSERT_MGD_MTX(ifmgd);
1366 959
1367 if (wk) 960 bssid = ifmgd->associated->bssid;
1368 bssid = wk->bss->cbss.bssid;
1369 else
1370 bssid = ifmgd->associated->cbss.bssid;
1371 961
1372 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); 962 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1373 963
1374 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n", 964 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
1375 sdata->dev->name, bssid, reason_code); 965 sdata->name, bssid, reason_code);
1376 966
1377 if (!wk) { 967 ieee80211_set_disassoc(sdata);
1378 ieee80211_set_disassoc(sdata, true); 968 ieee80211_recalc_idle(sdata->local);
1379 ieee80211_recalc_idle(sdata->local);
1380 } else {
1381 list_del(&wk->list);
1382 kfree(wk);
1383 }
1384 969
1385 return RX_MGMT_CFG80211_DEAUTH; 970 return RX_MGMT_CFG80211_DEAUTH;
1386} 971}
@@ -1401,123 +986,72 @@ ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1401 if (WARN_ON(!ifmgd->associated)) 986 if (WARN_ON(!ifmgd->associated))
1402 return RX_MGMT_NONE; 987 return RX_MGMT_NONE;
1403 988
1404 if (WARN_ON(memcmp(ifmgd->associated->cbss.bssid, mgmt->sa, ETH_ALEN))) 989 if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
1405 return RX_MGMT_NONE; 990 return RX_MGMT_NONE;
1406 991
1407 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 992 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1408 993
1409 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n", 994 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
1410 sdata->dev->name, mgmt->sa, reason_code); 995 sdata->name, mgmt->sa, reason_code);
1411 996
1412 ieee80211_set_disassoc(sdata, false); 997 ieee80211_set_disassoc(sdata);
1413 ieee80211_recalc_idle(sdata->local); 998 ieee80211_recalc_idle(sdata->local);
1414 return RX_MGMT_CFG80211_DISASSOC; 999 return RX_MGMT_CFG80211_DISASSOC;
1415} 1000}
1416 1001
1417 1002
1418static enum rx_mgmt_action __must_check 1003static bool ieee80211_assoc_success(struct ieee80211_work *wk,
1419ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, 1004 struct ieee80211_mgmt *mgmt, size_t len)
1420 struct ieee80211_mgd_work *wk,
1421 struct ieee80211_mgmt *mgmt, size_t len,
1422 bool reassoc)
1423{ 1005{
1006 struct ieee80211_sub_if_data *sdata = wk->sdata;
1424 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1007 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1425 struct ieee80211_local *local = sdata->local; 1008 struct ieee80211_local *local = sdata->local;
1426 struct ieee80211_supported_band *sband; 1009 struct ieee80211_supported_band *sband;
1427 struct sta_info *sta; 1010 struct sta_info *sta;
1011 struct cfg80211_bss *cbss = wk->assoc.bss;
1012 u8 *pos;
1428 u32 rates, basic_rates; 1013 u32 rates, basic_rates;
1429 u16 capab_info, status_code, aid; 1014 u16 capab_info, aid;
1430 struct ieee802_11_elems elems; 1015 struct ieee802_11_elems elems;
1431 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; 1016 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1432 u8 *pos;
1433 u32 changed = 0; 1017 u32 changed = 0;
1434 int i, j; 1018 int i, j, err;
1435 bool have_higher_than_11mbit = false, newsta = false; 1019 bool have_higher_than_11mbit = false;
1436 u16 ap_ht_cap_flags; 1020 u16 ap_ht_cap_flags;
1437 1021
1438 /* 1022 /* AssocResp and ReassocResp have identical structure */
1439 * AssocResp and ReassocResp have identical structure, so process both
1440 * of them in this function.
1441 */
1442
1443 if (len < 24 + 6)
1444 return RX_MGMT_NONE;
1445
1446 if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
1447 return RX_MGMT_NONE;
1448 1023
1449 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1450 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1451 aid = le16_to_cpu(mgmt->u.assoc_resp.aid); 1024 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1452 1025 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1453 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
1454 "status=%d aid=%d)\n",
1455 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
1456 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1457
1458 pos = mgmt->u.assoc_resp.variable;
1459 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1460
1461 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
1462 elems.timeout_int && elems.timeout_int_len == 5 &&
1463 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
1464 u32 tu, ms;
1465 tu = get_unaligned_le32(elems.timeout_int + 1);
1466 ms = tu * 1024 / 1000;
1467 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1468 "comeback duration %u TU (%u ms)\n",
1469 sdata->dev->name, tu, ms);
1470 wk->timeout = jiffies + msecs_to_jiffies(ms);
1471 if (ms > IEEE80211_ASSOC_TIMEOUT)
1472 run_again(ifmgd, jiffies + msecs_to_jiffies(ms));
1473 return RX_MGMT_NONE;
1474 }
1475
1476 if (status_code != WLAN_STATUS_SUCCESS) {
1477 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1478 sdata->dev->name, status_code);
1479 wk->state = IEEE80211_MGD_STATE_IDLE;
1480 return RX_MGMT_CFG80211_ASSOC;
1481 }
1482 1026
1483 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) 1027 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1484 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " 1028 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1485 "set\n", sdata->dev->name, aid); 1029 "set\n", sdata->name, aid);
1486 aid &= ~(BIT(15) | BIT(14)); 1030 aid &= ~(BIT(15) | BIT(14));
1487 1031
1032 pos = mgmt->u.assoc_resp.variable;
1033 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1034
1488 if (!elems.supp_rates) { 1035 if (!elems.supp_rates) {
1489 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", 1036 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1490 sdata->dev->name); 1037 sdata->name);
1491 return RX_MGMT_NONE; 1038 return false;
1492 } 1039 }
1493 1040
1494 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
1495 ifmgd->aid = aid; 1041 ifmgd->aid = aid;
1496 1042
1497 rcu_read_lock(); 1043 sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
1498
1499 /* Add STA entry for the AP */
1500 sta = sta_info_get(local, wk->bss->cbss.bssid);
1501 if (!sta) { 1044 if (!sta) {
1502 newsta = true; 1045 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1503 1046 " the AP\n", sdata->name);
1504 rcu_read_unlock(); 1047 return false;
1505
1506 sta = sta_info_alloc(sdata, wk->bss->cbss.bssid, GFP_KERNEL);
1507 if (!sta) {
1508 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1509 " the AP\n", sdata->dev->name);
1510 return RX_MGMT_NONE;
1511 }
1512
1513 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1514 WLAN_STA_ASSOC_AP);
1515 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1516 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1517
1518 rcu_read_lock();
1519 } 1048 }
1520 1049
1050 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1051 WLAN_STA_ASSOC_AP);
1052 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1053 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1054
1521 rates = 0; 1055 rates = 0;
1522 basic_rates = 0; 1056 basic_rates = 0;
1523 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 1057 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
@@ -1580,40 +1114,40 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1580 if (elems.wmm_param) 1114 if (elems.wmm_param)
1581 set_sta_flags(sta, WLAN_STA_WME); 1115 set_sta_flags(sta, WLAN_STA_WME);
1582 1116
1583 if (newsta) { 1117 err = sta_info_insert(sta);
1584 int err = sta_info_insert(sta); 1118 sta = NULL;
1585 if (err) { 1119 if (err) {
1586 printk(KERN_DEBUG "%s: failed to insert STA entry for" 1120 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1587 " the AP (error %d)\n", sdata->dev->name, err); 1121 " the AP (error %d)\n", sdata->name, err);
1588 rcu_read_unlock(); 1122 return false;
1589 return RX_MGMT_NONE;
1590 }
1591 } 1123 }
1592 1124
1593 rcu_read_unlock();
1594
1595 if (elems.wmm_param) 1125 if (elems.wmm_param)
1596 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, 1126 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1597 elems.wmm_param_len); 1127 elems.wmm_param_len);
1598 else 1128 else
1599 ieee80211_set_wmm_default(sdata); 1129 ieee80211_set_wmm_default(sdata);
1600 1130
1131 local->oper_channel = wk->chan;
1132
1601 if (elems.ht_info_elem && elems.wmm_param && 1133 if (elems.ht_info_elem && elems.wmm_param &&
1602 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && 1134 (sdata->local->hw.queues >= 4) &&
1603 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) 1135 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
1604 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, 1136 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1605 wk->bss->cbss.bssid, 1137 cbss->bssid, ap_ht_cap_flags);
1606 ap_ht_cap_flags);
1607
1608 /* delete work item -- must be before set_associated for PS */
1609 list_del(&wk->list);
1610 1138
1611 /* set AID and assoc capability, 1139 /* set AID and assoc capability,
1612 * ieee80211_set_associated() will tell the driver */ 1140 * ieee80211_set_associated() will tell the driver */
1613 bss_conf->aid = aid; 1141 bss_conf->aid = aid;
1614 bss_conf->assoc_capability = capab_info; 1142 bss_conf->assoc_capability = capab_info;
1615 /* this will take ownership of wk */ 1143 ieee80211_set_associated(sdata, cbss, changed);
1616 ieee80211_set_associated(sdata, wk, changed); 1144
1145 /*
1146 * If we're using 4-addr mode, let the AP know that we're
1147 * doing so, so that it can create the STA VLAN on its side
1148 */
1149 if (ifmgd->use_4addr)
1150 ieee80211_send_4addr_nullfunc(local, sdata);
1617 1151
1618 /* 1152 /*
1619 * Start timer to probe the connection to the AP now. 1153 * Start timer to probe the connection to the AP now.
@@ -1622,7 +1156,7 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1622 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); 1156 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
1623 mod_beacon_timer(sdata); 1157 mod_beacon_timer(sdata);
1624 1158
1625 return RX_MGMT_CFG80211_ASSOC; 1159 return true;
1626} 1160}
1627 1161
1628 1162
@@ -1637,6 +1171,13 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1637 int freq; 1171 int freq;
1638 struct ieee80211_bss *bss; 1172 struct ieee80211_bss *bss;
1639 struct ieee80211_channel *channel; 1173 struct ieee80211_channel *channel;
1174 bool need_ps = false;
1175
1176 if (sdata->u.mgd.associated) {
1177 bss = (void *)sdata->u.mgd.associated->priv;
1178 /* not previously set so we may need to recalc */
1179 need_ps = !bss->dtim_period;
1180 }
1640 1181
1641 if (elems->ds_params && elems->ds_params_len == 1) 1182 if (elems->ds_params && elems->ds_params_len == 1)
1642 freq = ieee80211_channel_to_frequency(elems->ds_params[0]); 1183 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
@@ -1656,8 +1197,14 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1656 if (!sdata->u.mgd.associated) 1197 if (!sdata->u.mgd.associated)
1657 return; 1198 return;
1658 1199
1200 if (need_ps) {
1201 mutex_lock(&local->iflist_mtx);
1202 ieee80211_recalc_ps(local, -1);
1203 mutex_unlock(&local->iflist_mtx);
1204 }
1205
1659 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) && 1206 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
1660 (memcmp(mgmt->bssid, sdata->u.mgd.associated->cbss.bssid, 1207 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
1661 ETH_ALEN) == 0)) { 1208 ETH_ALEN) == 0)) {
1662 struct ieee80211_channel_sw_ie *sw_elem = 1209 struct ieee80211_channel_sw_ie *sw_elem =
1663 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem; 1210 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
@@ -1667,19 +1214,19 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1667 1214
1668 1215
1669static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, 1216static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1670 struct ieee80211_mgd_work *wk, 1217 struct sk_buff *skb)
1671 struct ieee80211_mgmt *mgmt, size_t len,
1672 struct ieee80211_rx_status *rx_status)
1673{ 1218{
1219 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1674 struct ieee80211_if_managed *ifmgd; 1220 struct ieee80211_if_managed *ifmgd;
1675 size_t baselen; 1221 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
1222 size_t baselen, len = skb->len;
1676 struct ieee802_11_elems elems; 1223 struct ieee802_11_elems elems;
1677 1224
1678 ifmgd = &sdata->u.mgd; 1225 ifmgd = &sdata->u.mgd;
1679 1226
1680 ASSERT_MGD_MTX(ifmgd); 1227 ASSERT_MGD_MTX(ifmgd);
1681 1228
1682 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) 1229 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
1683 return; /* ignore ProbeResp to foreign address */ 1230 return; /* ignore ProbeResp to foreign address */
1684 1231
1685 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; 1232 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
@@ -1691,17 +1238,8 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1691 1238
1692 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); 1239 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
1693 1240
1694 /* direct probe may be part of the association flow */
1695 if (wk && wk->state == IEEE80211_MGD_STATE_PROBE) {
1696 printk(KERN_DEBUG "%s: direct probe responded\n",
1697 sdata->dev->name);
1698 wk->tries = 0;
1699 wk->state = IEEE80211_MGD_STATE_AUTH;
1700 WARN_ON(ieee80211_authenticate(sdata, wk) != RX_MGMT_NONE);
1701 }
1702
1703 if (ifmgd->associated && 1241 if (ifmgd->associated &&
1704 memcmp(mgmt->bssid, ifmgd->associated->cbss.bssid, ETH_ALEN) == 0 && 1242 memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0 &&
1705 ifmgd->flags & (IEEE80211_STA_BEACON_POLL | 1243 ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1706 IEEE80211_STA_CONNECTION_POLL)) { 1244 IEEE80211_STA_CONNECTION_POLL)) {
1707 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL | 1245 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
@@ -1774,7 +1312,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1774 if (!ifmgd->associated) 1312 if (!ifmgd->associated)
1775 return; 1313 return;
1776 1314
1777 bssid = ifmgd->associated->cbss.bssid; 1315 bssid = ifmgd->associated->bssid;
1778 1316
1779 /* 1317 /*
1780 * And in theory even frames from a different AP we were just 1318 * And in theory even frames from a different AP we were just
@@ -1787,7 +1325,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1787#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1325#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1788 if (net_ratelimit()) { 1326 if (net_ratelimit()) {
1789 printk(KERN_DEBUG "%s: cancelling probereq poll due " 1327 printk(KERN_DEBUG "%s: cancelling probereq poll due "
1790 "to a received beacon\n", sdata->dev->name); 1328 "to a received beacon\n", sdata->name);
1791 } 1329 }
1792#endif 1330#endif
1793 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL; 1331 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
@@ -1865,7 +1403,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1865 1403
1866 rcu_read_lock(); 1404 rcu_read_lock();
1867 1405
1868 sta = sta_info_get(local, bssid); 1406 sta = sta_info_get(sdata, bssid);
1869 if (WARN_ON(!sta)) { 1407 if (WARN_ON(!sta)) {
1870 rcu_read_unlock(); 1408 rcu_read_unlock();
1871 return; 1409 return;
@@ -1913,9 +1451,6 @@ ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1913 switch (fc & IEEE80211_FCTL_STYPE) { 1451 switch (fc & IEEE80211_FCTL_STYPE) {
1914 case IEEE80211_STYPE_PROBE_RESP: 1452 case IEEE80211_STYPE_PROBE_RESP:
1915 case IEEE80211_STYPE_BEACON: 1453 case IEEE80211_STYPE_BEACON:
1916 case IEEE80211_STYPE_AUTH:
1917 case IEEE80211_STYPE_ASSOC_RESP:
1918 case IEEE80211_STYPE_REASSOC_RESP:
1919 case IEEE80211_STYPE_DEAUTH: 1454 case IEEE80211_STYPE_DEAUTH:
1920 case IEEE80211_STYPE_DISASSOC: 1455 case IEEE80211_STYPE_DISASSOC:
1921 case IEEE80211_STYPE_ACTION: 1456 case IEEE80211_STYPE_ACTION:
@@ -1933,7 +1468,6 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1933 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1468 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1934 struct ieee80211_rx_status *rx_status; 1469 struct ieee80211_rx_status *rx_status;
1935 struct ieee80211_mgmt *mgmt; 1470 struct ieee80211_mgmt *mgmt;
1936 struct ieee80211_mgd_work *wk;
1937 enum rx_mgmt_action rma = RX_MGMT_NONE; 1471 enum rx_mgmt_action rma = RX_MGMT_NONE;
1938 u16 fc; 1472 u16 fc;
1939 1473
@@ -1944,20 +1478,17 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1944 mutex_lock(&ifmgd->mtx); 1478 mutex_lock(&ifmgd->mtx);
1945 1479
1946 if (ifmgd->associated && 1480 if (ifmgd->associated &&
1947 memcmp(ifmgd->associated->cbss.bssid, mgmt->bssid, 1481 memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
1948 ETH_ALEN) == 0) {
1949 switch (fc & IEEE80211_FCTL_STYPE) { 1482 switch (fc & IEEE80211_FCTL_STYPE) {
1950 case IEEE80211_STYPE_BEACON: 1483 case IEEE80211_STYPE_BEACON:
1951 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, 1484 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1952 rx_status); 1485 rx_status);
1953 break; 1486 break;
1954 case IEEE80211_STYPE_PROBE_RESP: 1487 case IEEE80211_STYPE_PROBE_RESP:
1955 ieee80211_rx_mgmt_probe_resp(sdata, NULL, mgmt, 1488 ieee80211_rx_mgmt_probe_resp(sdata, skb);
1956 skb->len, rx_status);
1957 break; 1489 break;
1958 case IEEE80211_STYPE_DEAUTH: 1490 case IEEE80211_STYPE_DEAUTH:
1959 rma = ieee80211_rx_mgmt_deauth(sdata, NULL, 1491 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
1960 mgmt, skb->len);
1961 break; 1492 break;
1962 case IEEE80211_STYPE_DISASSOC: 1493 case IEEE80211_STYPE_DISASSOC:
1963 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); 1494 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
@@ -1968,7 +1499,7 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1968 1499
1969 ieee80211_sta_process_chanswitch(sdata, 1500 ieee80211_sta_process_chanswitch(sdata,
1970 &mgmt->u.action.u.chan_switch.sw_elem, 1501 &mgmt->u.action.u.chan_switch.sw_elem,
1971 ifmgd->associated); 1502 (void *)ifmgd->associated->priv);
1972 break; 1503 break;
1973 } 1504 }
1974 mutex_unlock(&ifmgd->mtx); 1505 mutex_unlock(&ifmgd->mtx);
@@ -1989,58 +1520,11 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1989 goto out; 1520 goto out;
1990 } 1521 }
1991 1522
1992 list_for_each_entry(wk, &ifmgd->work_list, list) {
1993 if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
1994 continue;
1995
1996 switch (fc & IEEE80211_FCTL_STYPE) {
1997 case IEEE80211_STYPE_PROBE_RESP:
1998 ieee80211_rx_mgmt_probe_resp(sdata, wk, mgmt, skb->len,
1999 rx_status);
2000 break;
2001 case IEEE80211_STYPE_AUTH:
2002 rma = ieee80211_rx_mgmt_auth(sdata, wk, mgmt, skb->len);
2003 break;
2004 case IEEE80211_STYPE_ASSOC_RESP:
2005 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
2006 skb->len, false);
2007 break;
2008 case IEEE80211_STYPE_REASSOC_RESP:
2009 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
2010 skb->len, true);
2011 break;
2012 case IEEE80211_STYPE_DEAUTH:
2013 rma = ieee80211_rx_mgmt_deauth(sdata, wk, mgmt,
2014 skb->len);
2015 break;
2016 }
2017 /*
2018 * We've processed this frame for that work, so it can't
2019 * belong to another work struct.
2020 * NB: this is also required for correctness because the
2021 * called functions can free 'wk', and for 'rma'!
2022 */
2023 break;
2024 }
2025
2026 mutex_unlock(&ifmgd->mtx); 1523 mutex_unlock(&ifmgd->mtx);
2027 1524
2028 switch (rma) { 1525 if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
2029 case RX_MGMT_NONE: 1526 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH)
2030 /* no action */
2031 break;
2032 case RX_MGMT_CFG80211_AUTH:
2033 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, skb->len);
2034 break;
2035 case RX_MGMT_CFG80211_ASSOC:
2036 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, skb->len);
2037 break;
2038 case RX_MGMT_CFG80211_DEAUTH:
2039 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); 1527 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
2040 break;
2041 default:
2042 WARN(1, "unexpected: %d", rma);
2043 }
2044 1528
2045 out: 1529 out:
2046 kfree_skb(skb); 1530 kfree_skb(skb);
@@ -2068,12 +1552,8 @@ static void ieee80211_sta_work(struct work_struct *work)
2068 struct ieee80211_local *local = sdata->local; 1552 struct ieee80211_local *local = sdata->local;
2069 struct ieee80211_if_managed *ifmgd; 1553 struct ieee80211_if_managed *ifmgd;
2070 struct sk_buff *skb; 1554 struct sk_buff *skb;
2071 struct ieee80211_mgd_work *wk, *tmp;
2072 LIST_HEAD(free_work);
2073 enum rx_mgmt_action rma;
2074 bool anybusy = false;
2075 1555
2076 if (!netif_running(sdata->dev)) 1556 if (!ieee80211_sdata_running(sdata))
2077 return; 1557 return;
2078 1558
2079 if (local->scanning) 1559 if (local->scanning)
@@ -2104,7 +1584,7 @@ static void ieee80211_sta_work(struct work_struct *work)
2104 ifmgd->associated) { 1584 ifmgd->associated) {
2105 u8 bssid[ETH_ALEN]; 1585 u8 bssid[ETH_ALEN];
2106 1586
2107 memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN); 1587 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
2108 if (time_is_after_jiffies(ifmgd->probe_timeout)) 1588 if (time_is_after_jiffies(ifmgd->probe_timeout))
2109 run_again(ifmgd, ifmgd->probe_timeout); 1589 run_again(ifmgd, ifmgd->probe_timeout);
2110 1590
@@ -2126,7 +1606,7 @@ static void ieee80211_sta_work(struct work_struct *work)
2126 printk(KERN_DEBUG "No probe response from AP %pM" 1606 printk(KERN_DEBUG "No probe response from AP %pM"
2127 " after %dms, disconnecting.\n", 1607 " after %dms, disconnecting.\n",
2128 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ); 1608 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
2129 ieee80211_set_disassoc(sdata, true); 1609 ieee80211_set_disassoc(sdata);
2130 ieee80211_recalc_idle(local); 1610 ieee80211_recalc_idle(local);
2131 mutex_unlock(&ifmgd->mtx); 1611 mutex_unlock(&ifmgd->mtx);
2132 /* 1612 /*
@@ -2141,87 +1621,7 @@ static void ieee80211_sta_work(struct work_struct *work)
2141 } 1621 }
2142 } 1622 }
2143 1623
2144
2145 ieee80211_recalc_idle(local);
2146
2147 list_for_each_entry_safe(wk, tmp, &ifmgd->work_list, list) {
2148 if (time_is_after_jiffies(wk->timeout)) {
2149 /*
2150 * This work item isn't supposed to be worked on
2151 * right now, but take care to adjust the timer
2152 * properly.
2153 */
2154 run_again(ifmgd, wk->timeout);
2155 continue;
2156 }
2157
2158 switch (wk->state) {
2159 default:
2160 WARN_ON(1);
2161 /* fall through */
2162 case IEEE80211_MGD_STATE_IDLE:
2163 /* nothing */
2164 rma = RX_MGMT_NONE;
2165 break;
2166 case IEEE80211_MGD_STATE_PROBE:
2167 rma = ieee80211_direct_probe(sdata, wk);
2168 break;
2169 case IEEE80211_MGD_STATE_AUTH:
2170 rma = ieee80211_authenticate(sdata, wk);
2171 break;
2172 case IEEE80211_MGD_STATE_ASSOC:
2173 rma = ieee80211_associate(sdata, wk);
2174 break;
2175 }
2176
2177 switch (rma) {
2178 case RX_MGMT_NONE:
2179 /* no action required */
2180 break;
2181 case RX_MGMT_CFG80211_AUTH_TO:
2182 case RX_MGMT_CFG80211_ASSOC_TO:
2183 list_del(&wk->list);
2184 list_add(&wk->list, &free_work);
2185 wk->tries = rma; /* small abuse but only local */
2186 break;
2187 default:
2188 WARN(1, "unexpected: %d", rma);
2189 }
2190 }
2191
2192 list_for_each_entry(wk, &ifmgd->work_list, list) {
2193 if (wk->state != IEEE80211_MGD_STATE_IDLE) {
2194 anybusy = true;
2195 break;
2196 }
2197 }
2198 if (!anybusy &&
2199 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request))
2200 ieee80211_queue_delayed_work(&local->hw,
2201 &local->scan_work,
2202 round_jiffies_relative(0));
2203
2204 mutex_unlock(&ifmgd->mtx); 1624 mutex_unlock(&ifmgd->mtx);
2205
2206 list_for_each_entry_safe(wk, tmp, &free_work, list) {
2207 switch (wk->tries) {
2208 case RX_MGMT_CFG80211_AUTH_TO:
2209 cfg80211_send_auth_timeout(sdata->dev,
2210 wk->bss->cbss.bssid);
2211 break;
2212 case RX_MGMT_CFG80211_ASSOC_TO:
2213 cfg80211_send_assoc_timeout(sdata->dev,
2214 wk->bss->cbss.bssid);
2215 break;
2216 default:
2217 WARN(1, "unexpected: %d", wk->tries);
2218 }
2219
2220 list_del(&wk->list);
2221 kfree(wk);
2222 }
2223
2224 ieee80211_recalc_idle(local);
2225} 1625}
2226 1626
2227static void ieee80211_sta_bcn_mon_timer(unsigned long data) 1627static void ieee80211_sta_bcn_mon_timer(unsigned long data)
@@ -2330,14 +1730,14 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2330 (unsigned long) sdata); 1730 (unsigned long) sdata);
2331 skb_queue_head_init(&ifmgd->skb_queue); 1731 skb_queue_head_init(&ifmgd->skb_queue);
2332 1732
2333 INIT_LIST_HEAD(&ifmgd->work_list);
2334
2335 ifmgd->capab = WLAN_CAPABILITY_ESS;
2336 ifmgd->flags = 0; 1733 ifmgd->flags = 0;
2337 if (sdata->local->hw.queues >= 4)
2338 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
2339 1734
2340 mutex_init(&ifmgd->mtx); 1735 mutex_init(&ifmgd->mtx);
1736
1737 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
1738 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
1739 else
1740 ifmgd->req_smps = IEEE80211_SMPS_OFF;
2341} 1741}
2342 1742
2343/* scan finished notification */ 1743/* scan finished notification */
@@ -2368,12 +1768,34 @@ int ieee80211_max_network_latency(struct notifier_block *nb,
2368} 1768}
2369 1769
2370/* config hooks */ 1770/* config hooks */
1771static enum work_done_result
1772ieee80211_probe_auth_done(struct ieee80211_work *wk,
1773 struct sk_buff *skb)
1774{
1775 if (!skb) {
1776 cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
1777 return WORK_DONE_DESTROY;
1778 }
1779
1780 if (wk->type == IEEE80211_WORK_AUTH) {
1781 cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
1782 return WORK_DONE_DESTROY;
1783 }
1784
1785 mutex_lock(&wk->sdata->u.mgd.mtx);
1786 ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
1787 mutex_unlock(&wk->sdata->u.mgd.mtx);
1788
1789 wk->type = IEEE80211_WORK_AUTH;
1790 wk->probe_auth.tries = 0;
1791 return WORK_DONE_REQUEUE;
1792}
1793
2371int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, 1794int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2372 struct cfg80211_auth_request *req) 1795 struct cfg80211_auth_request *req)
2373{ 1796{
2374 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2375 const u8 *ssid; 1797 const u8 *ssid;
2376 struct ieee80211_mgd_work *wk; 1798 struct ieee80211_work *wk;
2377 u16 auth_alg; 1799 u16 auth_alg;
2378 1800
2379 switch (req->auth_type) { 1801 switch (req->auth_type) {
@@ -2397,7 +1819,7 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2397 if (!wk) 1819 if (!wk)
2398 return -ENOMEM; 1820 return -ENOMEM;
2399 1821
2400 wk->bss = (void *)req->bss; 1822 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
2401 1823
2402 if (req->ie && req->ie_len) { 1824 if (req->ie && req->ie_len) {
2403 memcpy(wk->ie, req->ie, req->ie_len); 1825 memcpy(wk->ie, req->ie, req->ie_len);
@@ -2405,68 +1827,83 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2405 } 1827 }
2406 1828
2407 if (req->key && req->key_len) { 1829 if (req->key && req->key_len) {
2408 wk->key_len = req->key_len; 1830 wk->probe_auth.key_len = req->key_len;
2409 wk->key_idx = req->key_idx; 1831 wk->probe_auth.key_idx = req->key_idx;
2410 memcpy(wk->key, req->key, req->key_len); 1832 memcpy(wk->probe_auth.key, req->key, req->key_len);
2411 } 1833 }
2412 1834
2413 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); 1835 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
2414 memcpy(wk->ssid, ssid + 2, ssid[1]); 1836 memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
2415 wk->ssid_len = ssid[1]; 1837 wk->probe_auth.ssid_len = ssid[1];
2416
2417 wk->state = IEEE80211_MGD_STATE_PROBE;
2418 wk->auth_alg = auth_alg;
2419 wk->timeout = jiffies; /* run right away */
2420 1838
2421 /* 1839 wk->probe_auth.algorithm = auth_alg;
2422 * XXX: if still associated need to tell AP that we're going 1840 wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
2423 * to sleep and then change channel etc.
2424 */
2425 sdata->local->oper_channel = req->bss->channel;
2426 ieee80211_hw_config(sdata->local, 0);
2427 1841
2428 mutex_lock(&ifmgd->mtx); 1842 /* if we already have a probe, don't probe again */
2429 list_add(&wk->list, &sdata->u.mgd.work_list); 1843 if (req->bss->proberesp_ies)
2430 mutex_unlock(&ifmgd->mtx); 1844 wk->type = IEEE80211_WORK_AUTH;
1845 else
1846 wk->type = IEEE80211_WORK_DIRECT_PROBE;
1847 wk->chan = req->bss->channel;
1848 wk->sdata = sdata;
1849 wk->done = ieee80211_probe_auth_done;
2431 1850
2432 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work); 1851 ieee80211_add_work(wk);
2433 return 0; 1852 return 0;
2434} 1853}
2435 1854
2436int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, 1855static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
2437 struct cfg80211_assoc_request *req) 1856 struct sk_buff *skb)
2438{ 1857{
2439 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1858 struct ieee80211_mgmt *mgmt;
2440 struct ieee80211_mgd_work *wk, *found = NULL; 1859 u16 status;
2441 int i, err;
2442 1860
2443 mutex_lock(&ifmgd->mtx); 1861 if (!skb) {
1862 cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
1863 return WORK_DONE_DESTROY;
1864 }
2444 1865
2445 list_for_each_entry(wk, &ifmgd->work_list, list) { 1866 mgmt = (void *)skb->data;
2446 if (&wk->bss->cbss == req->bss && 1867 status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2447 wk->state == IEEE80211_MGD_STATE_IDLE) { 1868
2448 found = wk; 1869 if (status == WLAN_STATUS_SUCCESS) {
2449 break; 1870 mutex_lock(&wk->sdata->u.mgd.mtx);
1871 if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
1872 mutex_unlock(&wk->sdata->u.mgd.mtx);
1873 /* oops -- internal error -- send timeout for now */
1874 cfg80211_send_assoc_timeout(wk->sdata->dev,
1875 wk->filter_ta);
1876 return WORK_DONE_DESTROY;
2450 } 1877 }
1878 mutex_unlock(&wk->sdata->u.mgd.mtx);
2451 } 1879 }
2452 1880
2453 if (!found) { 1881 cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
2454 err = -ENOLINK; 1882 return WORK_DONE_DESTROY;
2455 goto out; 1883}
2456 }
2457 1884
2458 list_del(&found->list); 1885int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
1886 struct cfg80211_assoc_request *req)
1887{
1888 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1889 struct ieee80211_bss *bss = (void *)req->bss->priv;
1890 struct ieee80211_work *wk;
1891 const u8 *ssid;
1892 int i;
2459 1893
2460 wk = krealloc(found, sizeof(*wk) + req->ie_len, GFP_KERNEL); 1894 mutex_lock(&ifmgd->mtx);
2461 if (!wk) { 1895 if (ifmgd->associated) {
2462 list_add(&found->list, &ifmgd->work_list); 1896 mutex_unlock(&ifmgd->mtx);
2463 err = -ENOMEM; 1897 return -EALREADY;
2464 goto out;
2465 } 1898 }
1899 mutex_unlock(&ifmgd->mtx);
2466 1900
2467 list_add(&wk->list, &ifmgd->work_list); 1901 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
1902 if (!wk)
1903 return -ENOMEM;
2468 1904
2469 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N; 1905 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
1906 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
2470 1907
2471 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) 1908 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2472 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || 1909 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
@@ -2474,8 +1911,6 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2474 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) 1911 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2475 ifmgd->flags |= IEEE80211_STA_DISABLE_11N; 1912 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2476 1913
2477 sdata->local->oper_channel = req->bss->channel;
2478 ieee80211_hw_config(sdata->local, 0);
2479 1914
2480 if (req->ie && req->ie_len) { 1915 if (req->ie && req->ie_len) {
2481 memcpy(wk->ie, req->ie, req->ie_len); 1916 memcpy(wk->ie, req->ie, req->ie_len);
@@ -2483,12 +1918,55 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2483 } else 1918 } else
2484 wk->ie_len = 0; 1919 wk->ie_len = 0;
2485 1920
1921 wk->assoc.bss = req->bss;
1922
1923 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
1924
1925 /* new association always uses requested smps mode */
1926 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
1927 if (ifmgd->powersave)
1928 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
1929 else
1930 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
1931 } else
1932 ifmgd->ap_smps = ifmgd->req_smps;
1933
1934 wk->assoc.smps = ifmgd->ap_smps;
1935 /*
1936 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
1937 * We still associate in non-HT mode (11a/b/g) if any one of these
1938 * ciphers is configured as pairwise.
1939 * We can set this to true for non-11n hardware, that'll be checked
1940 * separately along with the peer capabilities.
1941 */
1942 wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
1943 wk->assoc.capability = req->bss->capability;
1944 wk->assoc.wmm_used = bss->wmm_used;
1945 wk->assoc.supp_rates = bss->supp_rates;
1946 wk->assoc.supp_rates_len = bss->supp_rates_len;
1947 wk->assoc.ht_information_ie =
1948 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
1949
1950 if (bss->wmm_used && bss->uapsd_supported &&
1951 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
1952 wk->assoc.uapsd_used = true;
1953 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
1954 } else {
1955 wk->assoc.uapsd_used = false;
1956 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
1957 }
1958
1959 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
1960 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
1961 wk->assoc.ssid_len = ssid[1];
1962
2486 if (req->prev_bssid) 1963 if (req->prev_bssid)
2487 memcpy(wk->prev_bssid, req->prev_bssid, ETH_ALEN); 1964 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
2488 1965
2489 wk->state = IEEE80211_MGD_STATE_ASSOC; 1966 wk->type = IEEE80211_WORK_ASSOC;
2490 wk->tries = 0; 1967 wk->chan = req->bss->channel;
2491 wk->timeout = jiffies; /* run right away */ 1968 wk->sdata = sdata;
1969 wk->done = ieee80211_assoc_done;
2492 1970
2493 if (req->use_mfp) { 1971 if (req->use_mfp) {
2494 ifmgd->mfp = IEEE80211_MFP_REQUIRED; 1972 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
@@ -2503,69 +1981,65 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2503 else 1981 else
2504 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; 1982 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2505 1983
2506 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work); 1984 ieee80211_add_work(wk);
2507 1985 return 0;
2508 err = 0;
2509
2510 out:
2511 mutex_unlock(&ifmgd->mtx);
2512 return err;
2513} 1986}
2514 1987
2515int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, 1988int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
2516 struct cfg80211_deauth_request *req, 1989 struct cfg80211_deauth_request *req,
2517 void *cookie) 1990 void *cookie)
2518{ 1991{
1992 struct ieee80211_local *local = sdata->local;
2519 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1993 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2520 struct ieee80211_mgd_work *wk; 1994 struct ieee80211_work *wk;
2521 const u8 *bssid = NULL; 1995 const u8 *bssid = req->bss->bssid;
2522 bool not_auth_yet = false;
2523 1996
2524 mutex_lock(&ifmgd->mtx); 1997 mutex_lock(&ifmgd->mtx);
2525 1998
2526 if (ifmgd->associated && &ifmgd->associated->cbss == req->bss) { 1999 if (ifmgd->associated == req->bss) {
2527 bssid = req->bss->bssid; 2000 bssid = req->bss->bssid;
2528 ieee80211_set_disassoc(sdata, true); 2001 ieee80211_set_disassoc(sdata);
2529 } else list_for_each_entry(wk, &ifmgd->work_list, list) {
2530 if (&wk->bss->cbss == req->bss) {
2531 bssid = req->bss->bssid;
2532 if (wk->state == IEEE80211_MGD_STATE_PROBE)
2533 not_auth_yet = true;
2534 list_del(&wk->list);
2535 kfree(wk);
2536 break;
2537 }
2538 }
2539
2540 /*
2541 * If somebody requests authentication and we haven't
2542 * sent out an auth frame yet there's no need to send
2543 * out a deauth frame either. If the state was PROBE,
2544 * then this is the case. If it's AUTH we have sent a
2545 * frame, and if it's IDLE we have completed the auth
2546 * process already.
2547 */
2548 if (not_auth_yet) {
2549 mutex_unlock(&ifmgd->mtx); 2002 mutex_unlock(&ifmgd->mtx);
2550 __cfg80211_auth_canceled(sdata->dev, bssid); 2003 } else {
2551 return 0; 2004 bool not_auth_yet = false;
2552 }
2553 2005
2554 /*
2555 * cfg80211 should catch this ... but it's racy since
2556 * we can receive a deauth frame, process it, hand it
2557 * to cfg80211 while that's in a locked section already
2558 * trying to tell us that the user wants to disconnect.
2559 */
2560 if (!bssid) {
2561 mutex_unlock(&ifmgd->mtx); 2006 mutex_unlock(&ifmgd->mtx);
2562 return -ENOLINK;
2563 }
2564 2007
2565 mutex_unlock(&ifmgd->mtx); 2008 mutex_lock(&local->work_mtx);
2009 list_for_each_entry(wk, &local->work_list, list) {
2010 if (wk->sdata != sdata)
2011 continue;
2012
2013 if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
2014 wk->type != IEEE80211_WORK_AUTH)
2015 continue;
2016
2017 if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
2018 continue;
2019
2020 not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
2021 list_del_rcu(&wk->list);
2022 free_work(wk);
2023 break;
2024 }
2025 mutex_unlock(&local->work_mtx);
2026
2027 /*
2028 * If somebody requests authentication and we haven't
2029 * sent out an auth frame yet there's no need to send
2030 * out a deauth frame either. If the state was PROBE,
2031 * then this is the case. If it's AUTH we have sent a
2032 * frame, and if it's IDLE we have completed the auth
2033 * process already.
2034 */
2035 if (not_auth_yet) {
2036 __cfg80211_auth_canceled(sdata->dev, bssid);
2037 return 0;
2038 }
2039 }
2566 2040
2567 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n", 2041 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
2568 sdata->dev->name, bssid, req->reason_code); 2042 sdata->name, bssid, req->reason_code);
2569 2043
2570 ieee80211_send_deauth_disassoc(sdata, bssid, 2044 ieee80211_send_deauth_disassoc(sdata, bssid,
2571 IEEE80211_STYPE_DEAUTH, req->reason_code, 2045 IEEE80211_STYPE_DEAUTH, req->reason_code,
@@ -2590,15 +2064,15 @@ int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
2590 * to cfg80211 while that's in a locked section already 2064 * to cfg80211 while that's in a locked section already
2591 * trying to tell us that the user wants to disconnect. 2065 * trying to tell us that the user wants to disconnect.
2592 */ 2066 */
2593 if (&ifmgd->associated->cbss != req->bss) { 2067 if (ifmgd->associated != req->bss) {
2594 mutex_unlock(&ifmgd->mtx); 2068 mutex_unlock(&ifmgd->mtx);
2595 return -ENOLINK; 2069 return -ENOLINK;
2596 } 2070 }
2597 2071
2598 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n", 2072 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
2599 sdata->dev->name, req->bss->bssid, req->reason_code); 2073 sdata->name, req->bss->bssid, req->reason_code);
2600 2074
2601 ieee80211_set_disassoc(sdata, false); 2075 ieee80211_set_disassoc(sdata);
2602 2076
2603 mutex_unlock(&ifmgd->mtx); 2077 mutex_unlock(&ifmgd->mtx);
2604 2078
@@ -2610,3 +2084,38 @@ int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
2610 2084
2611 return 0; 2085 return 0;
2612} 2086}
2087
2088int ieee80211_mgd_action(struct ieee80211_sub_if_data *sdata,
2089 struct ieee80211_channel *chan,
2090 enum nl80211_channel_type channel_type,
2091 const u8 *buf, size_t len, u64 *cookie)
2092{
2093 struct ieee80211_local *local = sdata->local;
2094 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2095 struct sk_buff *skb;
2096
2097 /* Check that we are on the requested channel for transmission */
2098 if ((chan != local->tmp_channel ||
2099 channel_type != local->tmp_channel_type) &&
2100 (chan != local->oper_channel ||
2101 channel_type != local->oper_channel_type))
2102 return -EBUSY;
2103
2104 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2105 if (!skb)
2106 return -ENOMEM;
2107 skb_reserve(skb, local->hw.extra_tx_headroom);
2108
2109 memcpy(skb_put(skb, len), buf, len);
2110
2111 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
2112 IEEE80211_SKB_CB(skb)->flags |=
2113 IEEE80211_TX_INTFL_DONT_ENCRYPT;
2114 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2115 IEEE80211_TX_CTL_REQ_TX_STATUS;
2116 skb->dev = sdata->dev;
2117 ieee80211_tx_skb(sdata, skb);
2118
2119 *cookie = (unsigned long) skb;
2120 return 0;
2121}