2 * BSS client mode implementation
3 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/delay.h>
15 #include <linux/if_ether.h>
16 #include <linux/skbuff.h>
17 #include <linux/if_arp.h>
18 #include <linux/etherdevice.h>
19 #include <linux/rtnetlink.h>
20 #include <linux/pm_qos_params.h>
21 #include <net/mac80211.h>
22 #include <asm/unaligned.h>
24 #include "ieee80211_i.h"
28 #define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
29 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
30 #define IEEE80211_AUTH_MAX_TRIES 3
31 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
32 #define IEEE80211_ASSOC_MAX_TRIES 3
33 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
34 #define IEEE80211_PROBE_IDLE_TIME (60 * HZ)
35 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
38 static int ecw2cw(int ecw)
40 return (1 << ecw) - 1;
43 static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
47 pos = bss->cbss.information_elements;
50 end = pos + bss->cbss.len_information_elements;
52 while (pos + 1 < end) {
53 if (pos + 2 + pos[1] > end)
63 static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
64 struct ieee80211_supported_band *sband,
70 for (i = 0; i < bss->supp_rates_len; i++) {
71 int rate = (bss->supp_rates[i] & 0x7F) * 5;
73 for (j = 0; j < sband->n_bitrates; j++)
74 if (sband->bitrates[j].bitrate == rate) {
85 * ieee80211_enable_ht should be called only after the operating band
86 * has been determined as ht configuration depends on the hw's
87 * HT abilities for a specific band.
89 static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
90 struct ieee80211_ht_info *hti,
93 struct ieee80211_local *local = sdata->local;
94 struct ieee80211_supported_band *sband;
95 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
96 struct ieee80211_bss_ht_conf ht;
99 bool enable_ht = true, ht_changed;
100 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
102 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
104 memset(&ht, 0, sizeof(ht));
106 /* HT is not supported */
107 if (!sband->ht_cap.ht_supported)
110 /* check that channel matches the right operating channel */
111 if (local->hw.conf.channel->center_freq !=
112 ieee80211_channel_to_frequency(hti->control_chan))
116 channel_type = NL80211_CHAN_HT20;
118 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
119 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
120 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
121 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
122 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
123 channel_type = NL80211_CHAN_HT40PLUS;
125 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
126 channel_type = NL80211_CHAN_HT40MINUS;
132 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
133 channel_type != local->hw.conf.channel_type;
135 local->oper_channel_type = channel_type;
138 /* channel_type change automatically detected */
139 ieee80211_hw_config(local, 0);
143 sta = sta_info_get(local, ifmgd->bssid);
145 rate_control_rate_update(local, sband, sta,
146 IEEE80211_RC_HT_CHANGED);
156 ht.operation_mode = le16_to_cpu(hti->operation_mode);
158 /* if bss configuration changed store the new one */
159 if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
160 changed |= BSS_CHANGED_HT;
161 sdata->vif.bss_conf.ht = ht;
167 /* frame sending functions */
169 static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
171 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
172 struct ieee80211_local *local = sdata->local;
174 struct ieee80211_mgmt *mgmt;
175 u8 *pos, *ies, *ht_ie;
176 int i, len, count, rates_len, supp_rates_len;
178 struct ieee80211_bss *bss;
180 struct ieee80211_supported_band *sband;
183 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
184 sizeof(*mgmt) + 200 + ifmgd->extra_ie_len +
187 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
188 "frame\n", sdata->dev->name);
191 skb_reserve(skb, local->hw.extra_tx_headroom);
193 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
195 capab = ifmgd->capab;
197 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
198 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
199 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
200 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
201 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
204 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
205 local->hw.conf.channel->center_freq,
206 ifmgd->ssid, ifmgd->ssid_len);
208 if (bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
209 capab |= WLAN_CAPABILITY_PRIVACY;
213 /* get all rates supported by the device and the AP as
214 * some APs don't like getting a superset of their rates
215 * in the association request (e.g. D-Link DAP 1353 in
217 rates_len = ieee80211_compatible_rates(bss, sband, &rates);
219 if ((bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
220 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
221 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
223 ieee80211_rx_bss_put(local, bss);
226 rates_len = sband->n_bitrates;
229 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
231 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
232 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
233 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
235 if (ifmgd->flags & IEEE80211_STA_PREV_BSSID_SET) {
237 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
238 IEEE80211_STYPE_REASSOC_REQ);
239 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
240 mgmt->u.reassoc_req.listen_interval =
241 cpu_to_le16(local->hw.conf.listen_interval);
242 memcpy(mgmt->u.reassoc_req.current_ap, ifmgd->prev_bssid,
246 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
247 IEEE80211_STYPE_ASSOC_REQ);
248 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
249 mgmt->u.assoc_req.listen_interval =
250 cpu_to_le16(local->hw.conf.listen_interval);
254 ies = pos = skb_put(skb, 2 + ifmgd->ssid_len);
255 *pos++ = WLAN_EID_SSID;
256 *pos++ = ifmgd->ssid_len;
257 memcpy(pos, ifmgd->ssid, ifmgd->ssid_len);
259 /* add all rates which were marked to be used above */
260 supp_rates_len = rates_len;
261 if (supp_rates_len > 8)
264 len = sband->n_bitrates;
265 pos = skb_put(skb, supp_rates_len + 2);
266 *pos++ = WLAN_EID_SUPP_RATES;
267 *pos++ = supp_rates_len;
270 for (i = 0; i < sband->n_bitrates; i++) {
271 if (BIT(i) & rates) {
272 int rate = sband->bitrates[i].bitrate;
273 *pos++ = (u8) (rate / 5);
279 if (rates_len > count) {
280 pos = skb_put(skb, rates_len - count + 2);
281 *pos++ = WLAN_EID_EXT_SUPP_RATES;
282 *pos++ = rates_len - count;
284 for (i++; i < sband->n_bitrates; i++) {
285 if (BIT(i) & rates) {
286 int rate = sband->bitrates[i].bitrate;
287 *pos++ = (u8) (rate / 5);
292 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
293 /* 1. power capabilities */
294 pos = skb_put(skb, 4);
295 *pos++ = WLAN_EID_PWR_CAPABILITY;
297 *pos++ = 0; /* min tx power */
298 *pos++ = local->hw.conf.channel->max_power; /* max tx power */
300 /* 2. supported channels */
301 /* TODO: get this in reg domain format */
302 pos = skb_put(skb, 2 * sband->n_channels + 2);
303 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
304 *pos++ = 2 * sband->n_channels;
305 for (i = 0; i < sband->n_channels; i++) {
306 *pos++ = ieee80211_frequency_to_channel(
307 sband->channels[i].center_freq);
308 *pos++ = 1; /* one channel in the subband*/
312 if (ifmgd->extra_ie) {
313 pos = skb_put(skb, ifmgd->extra_ie_len);
314 memcpy(pos, ifmgd->extra_ie, ifmgd->extra_ie_len);
317 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
318 pos = skb_put(skb, 9);
319 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
320 *pos++ = 7; /* len */
321 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
324 *pos++ = 2; /* WME */
325 *pos++ = 0; /* WME info */
326 *pos++ = 1; /* WME ver */
330 /* wmm support is a must to HT */
332 * IEEE802.11n does not allow TKIP/WEP as pairwise
333 * ciphers in HT mode. We still associate in non-ht
334 * mode (11a/b/g) if any one of these ciphers is
335 * configured as pairwise.
337 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
338 sband->ht_cap.ht_supported &&
339 (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) &&
340 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
341 (!(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))) {
342 struct ieee80211_ht_info *ht_info =
343 (struct ieee80211_ht_info *)(ht_ie + 2);
344 u16 cap = sband->ht_cap.cap;
346 u32 flags = local->hw.conf.channel->flags;
348 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
349 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
350 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
351 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
352 cap &= ~IEEE80211_HT_CAP_SGI_40;
355 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
356 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
357 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
358 cap &= ~IEEE80211_HT_CAP_SGI_40;
363 tmp = cpu_to_le16(cap);
364 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
365 *pos++ = WLAN_EID_HT_CAPABILITY;
366 *pos++ = sizeof(struct ieee80211_ht_cap);
367 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
368 memcpy(pos, &tmp, sizeof(u16));
370 /* TODO: needs a define here for << 2 */
371 *pos++ = sband->ht_cap.ampdu_factor |
372 (sband->ht_cap.ampdu_density << 2);
373 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
376 kfree(ifmgd->assocreq_ies);
377 ifmgd->assocreq_ies_len = (skb->data + skb->len) - ies;
378 ifmgd->assocreq_ies = kmalloc(ifmgd->assocreq_ies_len, GFP_KERNEL);
379 if (ifmgd->assocreq_ies)
380 memcpy(ifmgd->assocreq_ies, ies, ifmgd->assocreq_ies_len);
382 ieee80211_tx_skb(sdata, skb, 0);
386 static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
387 u16 stype, u16 reason)
389 struct ieee80211_local *local = sdata->local;
390 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
392 struct ieee80211_mgmt *mgmt;
394 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
396 printk(KERN_DEBUG "%s: failed to allocate buffer for "
397 "deauth/disassoc frame\n", sdata->dev->name);
400 skb_reserve(skb, local->hw.extra_tx_headroom);
402 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
404 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
405 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
406 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
407 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
409 /* u.deauth.reason_code == u.disassoc.reason_code */
410 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
412 if (stype == IEEE80211_STYPE_DEAUTH)
413 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len);
415 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len);
416 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
419 void ieee80211_send_pspoll(struct ieee80211_local *local,
420 struct ieee80211_sub_if_data *sdata)
422 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
423 struct ieee80211_pspoll *pspoll;
427 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
429 printk(KERN_DEBUG "%s: failed to allocate buffer for "
430 "pspoll frame\n", sdata->dev->name);
433 skb_reserve(skb, local->hw.extra_tx_headroom);
435 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
436 memset(pspoll, 0, sizeof(*pspoll));
437 fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
438 pspoll->frame_control = cpu_to_le16(fc);
439 pspoll->aid = cpu_to_le16(ifmgd->aid);
441 /* aid in PS-Poll has its two MSBs each set to 1 */
442 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
444 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
445 memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN);
447 ieee80211_tx_skb(sdata, skb, 0);
450 void ieee80211_send_nullfunc(struct ieee80211_local *local,
451 struct ieee80211_sub_if_data *sdata,
455 struct ieee80211_hdr *nullfunc;
458 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
461 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
463 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
464 "frame\n", sdata->dev->name);
467 skb_reserve(skb, local->hw.extra_tx_headroom);
469 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
470 memset(nullfunc, 0, 24);
471 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
472 IEEE80211_FCTL_TODS);
474 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
475 nullfunc->frame_control = fc;
476 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
477 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
478 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
480 ieee80211_tx_skb(sdata, skb, 0);
484 static void ieee80211_enable_ps(struct ieee80211_local *local,
485 struct ieee80211_sub_if_data *sdata)
487 struct ieee80211_conf *conf = &local->hw.conf;
489 if (conf->dynamic_ps_timeout > 0 &&
490 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
491 mod_timer(&local->dynamic_ps_timer, jiffies +
492 msecs_to_jiffies(conf->dynamic_ps_timeout));
494 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
495 ieee80211_send_nullfunc(local, sdata, 1);
496 conf->flags |= IEEE80211_CONF_PS;
497 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
501 static void ieee80211_change_ps(struct ieee80211_local *local)
503 struct ieee80211_conf *conf = &local->hw.conf;
505 if (local->ps_sdata) {
506 if (!(local->ps_sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
509 ieee80211_enable_ps(local, local->ps_sdata);
510 } else if (conf->flags & IEEE80211_CONF_PS) {
511 conf->flags &= ~IEEE80211_CONF_PS;
512 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
513 del_timer_sync(&local->dynamic_ps_timer);
514 cancel_work_sync(&local->dynamic_ps_enable_work);
518 /* need to hold RTNL or interface lock */
519 void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
521 struct ieee80211_sub_if_data *sdata, *found = NULL;
524 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
525 local->ps_sdata = NULL;
529 list_for_each_entry(sdata, &local->interfaces, list) {
530 if (!netif_running(sdata->dev))
532 if (sdata->vif.type != NL80211_IFTYPE_STATION)
538 if (count == 1 && found->u.mgd.powersave) {
542 latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY);
544 beaconint_us = ieee80211_tu_to_usec(
545 found->vif.bss_conf.beacon_int);
547 if (beaconint_us > latency)
548 local->ps_sdata = NULL;
550 local->ps_sdata = found;
552 local->ps_sdata = NULL;
555 ieee80211_change_ps(local);
558 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
560 struct ieee80211_local *local =
561 container_of(work, struct ieee80211_local,
562 dynamic_ps_disable_work);
564 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
565 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
566 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
569 ieee80211_wake_queues_by_reason(&local->hw,
570 IEEE80211_QUEUE_STOP_REASON_PS);
573 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
575 struct ieee80211_local *local =
576 container_of(work, struct ieee80211_local,
577 dynamic_ps_enable_work);
578 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
580 /* can only happen when PS was just disabled anyway */
584 if (local->hw.conf.flags & IEEE80211_CONF_PS)
587 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
588 ieee80211_send_nullfunc(local, sdata, 1);
590 local->hw.conf.flags |= IEEE80211_CONF_PS;
591 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
594 void ieee80211_dynamic_ps_timer(unsigned long data)
596 struct ieee80211_local *local = (void *) data;
598 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
602 static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
603 struct ieee80211_if_managed *ifmgd,
604 u8 *wmm_param, size_t wmm_param_len)
606 struct ieee80211_tx_queue_params params;
611 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED))
617 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
619 count = wmm_param[6] & 0x0f;
620 if (count == ifmgd->wmm_last_param_set)
622 ifmgd->wmm_last_param_set = count;
625 left = wmm_param_len - 8;
627 memset(¶ms, 0, sizeof(params));
630 for (; left >= 4; left -= 4, pos += 4) {
631 int aci = (pos[0] >> 5) & 0x03;
632 int acm = (pos[0] >> 4) & 0x01;
639 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
644 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
649 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
655 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
659 params.aifs = pos[0] & 0x0f;
660 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
661 params.cw_min = ecw2cw(pos[1] & 0x0f);
662 params.txop = get_unaligned_le16(pos + 2);
663 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
664 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
665 "cWmin=%d cWmax=%d txop=%d\n",
666 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
667 params.cw_max, params.txop);
669 if (local->ops->conf_tx &&
670 local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) {
671 printk(KERN_DEBUG "%s: failed to set TX queue "
672 "parameters for queue %d\n", local->mdev->name, queue);
677 static bool ieee80211_check_tim(struct ieee802_11_elems *elems, u16 aid)
680 u8 index, indexn1, indexn2;
681 struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
683 if (unlikely(!tim || elems->tim_len < 4))
688 mask = 1 << (aid & 7);
690 indexn1 = tim->bitmap_ctrl & 0xfe;
691 indexn2 = elems->tim_len + indexn1 - 4;
693 if (index < indexn1 || index > indexn2)
698 return !!(tim->virtual_map[index] & mask);
701 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
702 u16 capab, bool erp_valid, u8 erp)
704 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
705 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
706 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
710 bool use_short_preamble;
714 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
715 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
717 use_protection = false;
718 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
721 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
723 if (use_protection != bss_conf->use_cts_prot) {
724 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
725 if (net_ratelimit()) {
726 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
728 use_protection ? "enabled" : "disabled",
732 bss_conf->use_cts_prot = use_protection;
733 changed |= BSS_CHANGED_ERP_CTS_PROT;
736 if (use_short_preamble != bss_conf->use_short_preamble) {
737 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
738 if (net_ratelimit()) {
739 printk(KERN_DEBUG "%s: switched to %s barker preamble"
742 use_short_preamble ? "short" : "long",
746 bss_conf->use_short_preamble = use_short_preamble;
747 changed |= BSS_CHANGED_ERP_PREAMBLE;
750 if (use_short_slot != bss_conf->use_short_slot) {
751 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
752 if (net_ratelimit()) {
753 printk(KERN_DEBUG "%s: switched to %s slot time"
756 use_short_slot ? "short" : "long",
760 bss_conf->use_short_slot = use_short_slot;
761 changed |= BSS_CHANGED_ERP_SLOT;
767 static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
769 union iwreq_data wrqu;
771 memset(&wrqu, 0, sizeof(wrqu));
772 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
773 memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
774 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
775 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
778 static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
780 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
784 union iwreq_data wrqu;
786 if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
789 buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
790 ifmgd->assocresp_ies_len), GFP_KERNEL);
794 len = sprintf(buf, "ASSOCINFO(");
795 if (ifmgd->assocreq_ies) {
796 len += sprintf(buf + len, "ReqIEs=");
797 for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
798 len += sprintf(buf + len, "%02x",
799 ifmgd->assocreq_ies[i]);
802 if (ifmgd->assocresp_ies) {
803 if (ifmgd->assocreq_ies)
804 len += sprintf(buf + len, " ");
805 len += sprintf(buf + len, "RespIEs=");
806 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
807 len += sprintf(buf + len, "%02x",
808 ifmgd->assocresp_ies[i]);
811 len += sprintf(buf + len, ")");
813 if (len > IW_CUSTOM_MAX) {
814 len = sprintf(buf, "ASSOCRESPIE=");
815 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
816 len += sprintf(buf + len, "%02x",
817 ifmgd->assocresp_ies[i]);
821 if (len <= IW_CUSTOM_MAX) {
822 memset(&wrqu, 0, sizeof(wrqu));
823 wrqu.data.length = len;
824 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
831 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
832 u32 bss_info_changed)
834 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
835 struct ieee80211_local *local = sdata->local;
836 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
838 struct ieee80211_bss *bss;
840 bss_info_changed |= BSS_CHANGED_ASSOC;
841 ifmgd->flags |= IEEE80211_STA_ASSOCIATED;
843 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
844 conf->channel->center_freq,
845 ifmgd->ssid, ifmgd->ssid_len);
847 /* set timing information */
848 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
849 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
850 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
852 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
853 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
855 cfg80211_hold_bss(&bss->cbss);
857 ieee80211_rx_bss_put(local, bss);
860 ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
861 memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
862 ieee80211_sta_send_associnfo(sdata);
864 ifmgd->last_probe = jiffies;
865 ieee80211_led_assoc(local, 1);
867 sdata->vif.bss_conf.assoc = 1;
869 * For now just always ask the driver to update the basic rateset
870 * when we have associated, we aren't checking whether it actually
873 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
874 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
876 /* will be same as sdata */
878 ieee80211_enable_ps(local, sdata);
880 netif_tx_start_all_queues(sdata->dev);
881 netif_carrier_on(sdata->dev);
883 ieee80211_sta_send_apinfo(sdata);
886 static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
888 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
889 struct ieee80211_local *local = sdata->local;
891 ifmgd->direct_probe_tries++;
892 if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
893 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
894 sdata->dev->name, ifmgd->bssid);
895 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
896 ieee80211_sta_send_apinfo(sdata);
899 * Most likely AP is not in the range so remove the
900 * bss information associated to the AP
902 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
903 sdata->local->hw.conf.channel->center_freq,
904 ifmgd->ssid, ifmgd->ssid_len);
907 * We might have a pending scan which had no chance to run yet
908 * due to state == IEEE80211_STA_MLME_DIRECT_PROBE.
909 * Hence, queue the STAs work again
911 queue_work(local->hw.workqueue, &ifmgd->work);
915 printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
916 sdata->dev->name, ifmgd->bssid,
917 ifmgd->direct_probe_tries);
919 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
921 set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifmgd->request);
923 /* Direct probe is sent to broadcast address as some APs
924 * will not answer to direct packet in unassociated state.
926 ieee80211_send_probe_req(sdata, NULL,
927 ifmgd->ssid, ifmgd->ssid_len, NULL, 0);
929 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
933 static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
935 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
936 struct ieee80211_local *local = sdata->local;
941 if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
942 printk(KERN_DEBUG "%s: authentication with AP %pM"
944 sdata->dev->name, ifmgd->bssid);
945 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
946 ieee80211_sta_send_apinfo(sdata);
947 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
948 sdata->local->hw.conf.channel->center_freq,
949 ifmgd->ssid, ifmgd->ssid_len);
952 * We might have a pending scan which had no chance to run yet
953 * due to state == IEEE80211_STA_MLME_AUTHENTICATE.
954 * Hence, queue the STAs work again
956 queue_work(local->hw.workqueue, &ifmgd->work);
960 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
961 printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
962 sdata->dev->name, ifmgd->bssid);
964 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
965 ies = ifmgd->sme_auth_ie;
966 ies_len = ifmgd->sme_auth_ie_len;
971 ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len,
973 ifmgd->auth_transaction = 2;
975 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
979 * The disassoc 'reason' argument can be either our own reason
980 * if self disconnected or a reason code from the AP.
982 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
983 bool deauth, bool self_disconnected,
986 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
987 struct ieee80211_local *local = sdata->local;
988 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
989 struct ieee80211_bss *bss;
990 struct sta_info *sta;
991 u32 changed = 0, config_changed = 0;
995 sta = sta_info_get(local, ifmgd->bssid);
1002 ifmgd->direct_probe_tries = 0;
1003 ifmgd->auth_tries = 0;
1005 ifmgd->assoc_scan_tries = 0;
1006 ifmgd->assoc_tries = 0;
1008 netif_tx_stop_all_queues(sdata->dev);
1009 netif_carrier_off(sdata->dev);
1011 ieee80211_sta_tear_down_BA_sessions(sta);
1013 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
1014 conf->channel->center_freq,
1015 ifmgd->ssid, ifmgd->ssid_len);
1018 cfg80211_unhold_bss(&bss->cbss);
1019 ieee80211_rx_bss_put(local, bss);
1022 if (self_disconnected) {
1024 ieee80211_send_deauth_disassoc(sdata,
1025 IEEE80211_STYPE_DEAUTH, reason);
1027 ieee80211_send_deauth_disassoc(sdata,
1028 IEEE80211_STYPE_DISASSOC, reason);
1031 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
1032 changed |= ieee80211_reset_erp_info(sdata);
1034 ieee80211_led_assoc(local, 0);
1035 changed |= BSS_CHANGED_ASSOC;
1036 sdata->vif.bss_conf.assoc = false;
1038 ieee80211_sta_send_apinfo(sdata);
1040 if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
1041 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1042 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
1043 sdata->local->hw.conf.channel->center_freq,
1044 ifmgd->ssid, ifmgd->ssid_len);
1049 /* channel(_type) changes are handled by ieee80211_hw_config */
1050 local->oper_channel_type = NL80211_CHAN_NO_HT;
1052 local->power_constr_level = 0;
1054 del_timer_sync(&local->dynamic_ps_timer);
1055 cancel_work_sync(&local->dynamic_ps_enable_work);
1057 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1058 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1059 config_changed |= IEEE80211_CONF_CHANGE_PS;
1062 ieee80211_hw_config(local, config_changed);
1063 ieee80211_bss_info_change_notify(sdata, changed);
1067 sta = sta_info_get(local, ifmgd->bssid);
1073 sta_info_unlink(&sta);
1077 sta_info_destroy(sta);
1080 static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
1082 if (!sdata || !sdata->default_key ||
1083 sdata->default_key->conf.alg != ALG_WEP)
1088 static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
1090 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1091 struct ieee80211_local *local = sdata->local;
1092 struct ieee80211_bss *bss;
1095 int privacy_invoked;
1097 if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
1100 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
1101 local->hw.conf.channel->center_freq,
1102 ifmgd->ssid, ifmgd->ssid_len);
1106 bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
1107 wep_privacy = !!ieee80211_sta_wep_configured(sdata);
1108 privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
1110 ieee80211_rx_bss_put(local, bss);
1112 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
1118 static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
1120 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1121 struct ieee80211_local *local = sdata->local;
1123 ifmgd->assoc_tries++;
1124 if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
1125 printk(KERN_DEBUG "%s: association with AP %pM"
1127 sdata->dev->name, ifmgd->bssid);
1128 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1129 ieee80211_sta_send_apinfo(sdata);
1130 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
1131 sdata->local->hw.conf.channel->center_freq,
1132 ifmgd->ssid, ifmgd->ssid_len);
1134 * We might have a pending scan which had no chance to run yet
1135 * due to state == IEEE80211_STA_MLME_ASSOCIATE.
1136 * Hence, queue the STAs work again
1138 queue_work(local->hw.workqueue, &ifmgd->work);
1142 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
1143 printk(KERN_DEBUG "%s: associate with AP %pM\n",
1144 sdata->dev->name, ifmgd->bssid);
1145 if (ieee80211_privacy_mismatch(sdata)) {
1146 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
1147 "mixed-cell disabled - abort association\n", sdata->dev->name);
1148 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1152 ieee80211_send_assoc(sdata);
1154 mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
1157 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1158 struct ieee80211_hdr *hdr)
1161 * We can postpone the mgd.timer whenever receiving unicast frames
1162 * from AP because we know that the connection is working both ways
1163 * at that time. But multicast frames (and hence also beacons) must
1164 * be ignored here, because we need to trigger the timer during
1165 * data idle periods for sending the periodical probe request to
1168 if (!is_multicast_ether_addr(hdr->addr1))
1169 mod_timer(&sdata->u.mgd.timer,
1170 jiffies + IEEE80211_MONITORING_INTERVAL);
1173 void ieee80211_beacon_loss_work(struct work_struct *work)
1175 struct ieee80211_sub_if_data *sdata =
1176 container_of(work, struct ieee80211_sub_if_data,
1177 u.mgd.beacon_loss_work);
1178 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1180 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1181 if (net_ratelimit()) {
1182 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
1183 "- sending probe request\n", sdata->dev->name,
1184 sdata->u.mgd.bssid);
1188 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1189 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1190 ifmgd->ssid_len, NULL, 0);
1192 mod_timer(&ifmgd->timer, jiffies + IEEE80211_MONITORING_INTERVAL);
1195 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1197 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1199 queue_work(sdata->local->hw.workqueue,
1200 &sdata->u.mgd.beacon_loss_work);
1202 EXPORT_SYMBOL(ieee80211_beacon_loss);
1204 static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
1206 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1207 struct ieee80211_local *local = sdata->local;
1208 struct sta_info *sta;
1209 bool disassoc = false;
1211 /* TODO: start monitoring current AP signal quality and number of
1212 * missed beacons. Scan other channels every now and then and search
1213 * for better APs. */
1214 /* TODO: remove expired BSSes */
1216 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED;
1220 sta = sta_info_get(local, ifmgd->bssid);
1222 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
1223 sdata->dev->name, ifmgd->bssid);
1228 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
1229 time_after(jiffies, sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
1230 printk(KERN_DEBUG "%s: no probe response from AP %pM "
1231 "- disassociating\n",
1232 sdata->dev->name, ifmgd->bssid);
1234 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1239 * Beacon filtering is only enabled with power save and then the
1240 * stack should not check for beacon loss.
1242 if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) &&
1243 (local->hw.conf.flags & IEEE80211_CONF_PS)) &&
1245 ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
1246 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1247 if (net_ratelimit()) {
1248 printk(KERN_DEBUG "%s: beacon loss from AP %pM "
1249 "- sending probe request\n",
1250 sdata->dev->name, ifmgd->bssid);
1253 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1254 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1255 ifmgd->ssid_len, NULL, 0);
1260 if (time_after(jiffies, sta->last_rx + IEEE80211_PROBE_IDLE_TIME)) {
1261 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1262 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1263 ifmgd->ssid_len, NULL, 0);
1270 ieee80211_set_disassoc(sdata, true, true,
1271 WLAN_REASON_PREV_AUTH_NOT_VALID);
1273 mod_timer(&ifmgd->timer, jiffies +
1274 IEEE80211_MONITORING_INTERVAL);
1278 static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
1280 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1282 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
1283 ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
1284 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1285 /* Wait for SME to request association */
1286 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1288 ieee80211_associate(sdata);
1292 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1293 struct ieee80211_mgmt *mgmt,
1297 struct ieee802_11_elems elems;
1299 pos = mgmt->u.auth.variable;
1300 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1301 if (!elems.challenge)
1303 ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg,
1304 elems.challenge - 2, elems.challenge_len + 2,
1305 sdata->u.mgd.bssid, 1);
1306 sdata->u.mgd.auth_transaction = 4;
1309 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1310 struct ieee80211_mgmt *mgmt,
1313 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1314 u16 auth_alg, auth_transaction, status_code;
1316 if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE)
1322 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
1325 if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
1328 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1329 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1330 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1332 if (auth_alg != ifmgd->auth_alg ||
1333 auth_transaction != ifmgd->auth_transaction)
1336 if (status_code != WLAN_STATUS_SUCCESS) {
1337 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1339 const int num_algs = ARRAY_SIZE(algs);
1341 algs[0] = algs[1] = algs[2] = 0xff;
1342 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1343 algs[0] = WLAN_AUTH_OPEN;
1344 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1345 algs[1] = WLAN_AUTH_SHARED_KEY;
1346 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1347 algs[2] = WLAN_AUTH_LEAP;
1348 if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
1350 else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
1354 for (i = 0; i < num_algs; i++) {
1356 if (pos >= num_algs)
1358 if (algs[pos] == ifmgd->auth_alg ||
1361 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1362 !ieee80211_sta_wep_configured(sdata))
1364 ifmgd->auth_alg = algs[pos];
1371 switch (ifmgd->auth_alg) {
1372 case WLAN_AUTH_OPEN:
1373 case WLAN_AUTH_LEAP:
1375 ieee80211_auth_completed(sdata);
1376 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
1378 case WLAN_AUTH_SHARED_KEY:
1379 if (ifmgd->auth_transaction == 4) {
1380 ieee80211_auth_completed(sdata);
1381 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
1383 ieee80211_auth_challenge(sdata, mgmt, len);
1389 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1390 struct ieee80211_mgmt *mgmt,
1393 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1399 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
1402 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1404 if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED)
1405 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
1406 sdata->dev->name, reason_code);
1408 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1409 (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
1410 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE ||
1411 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) {
1412 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
1413 mod_timer(&ifmgd->timer, jiffies +
1414 IEEE80211_RETRY_AUTH_INTERVAL);
1417 ieee80211_set_disassoc(sdata, true, false, 0);
1418 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
1419 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
1423 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1424 struct ieee80211_mgmt *mgmt,
1427 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1433 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
1436 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1438 if (ifmgd->flags & IEEE80211_STA_ASSOCIATED)
1439 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1440 sdata->dev->name, reason_code);
1442 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1443 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) {
1444 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
1445 mod_timer(&ifmgd->timer, jiffies +
1446 IEEE80211_RETRY_AUTH_INTERVAL);
1449 ieee80211_set_disassoc(sdata, false, false, reason_code);
1450 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
1454 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1455 struct ieee80211_mgmt *mgmt,
1459 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1460 struct ieee80211_local *local = sdata->local;
1461 struct ieee80211_supported_band *sband;
1462 struct sta_info *sta;
1463 u32 rates, basic_rates;
1464 u16 capab_info, status_code, aid;
1465 struct ieee802_11_elems elems;
1466 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1470 bool have_higher_than_11mbit = false, newsta = false;
1471 u16 ap_ht_cap_flags;
1473 /* AssocResp and ReassocResp have identical structure, so process both
1474 * of them in this function. */
1476 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
1482 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
1485 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1486 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1487 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1489 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
1490 "status=%d aid=%d)\n",
1491 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
1492 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1494 pos = mgmt->u.assoc_resp.variable;
1495 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1497 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
1498 elems.timeout_int && elems.timeout_int_len == 5 &&
1499 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
1501 tu = get_unaligned_le32(elems.timeout_int + 1);
1502 ms = tu * 1024 / 1000;
1503 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1504 "comeback duration %u TU (%u ms)\n",
1505 sdata->dev->name, tu, ms);
1506 if (ms > IEEE80211_ASSOC_TIMEOUT)
1507 mod_timer(&ifmgd->timer,
1508 jiffies + msecs_to_jiffies(ms));
1512 if (status_code != WLAN_STATUS_SUCCESS) {
1513 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1514 sdata->dev->name, status_code);
1515 /* if this was a reassociation, ensure we try a "full"
1516 * association next time. This works around some broken APs
1517 * which do not correctly reject reassociation requests. */
1518 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1519 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1520 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1521 /* Wait for SME to decide what to do next */
1522 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1527 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1528 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1529 "set\n", sdata->dev->name, aid);
1530 aid &= ~(BIT(15) | BIT(14));
1532 if (!elems.supp_rates) {
1533 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1538 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
1540 ifmgd->ap_capab = capab_info;
1542 kfree(ifmgd->assocresp_ies);
1543 ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1544 ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
1545 if (ifmgd->assocresp_ies)
1546 memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
1550 /* Add STA entry for the AP */
1551 sta = sta_info_get(local, ifmgd->bssid);
1555 sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC);
1557 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1558 " the AP\n", sdata->dev->name);
1563 /* update new sta with its last rx activity */
1564 sta->last_rx = jiffies;
1568 * FIXME: Do we really need to update the sta_info's information here?
1569 * We already know about the AP (we found it in our list) so it
1570 * should already be filled with the right info, no?
1571 * As is stands, all this is racy because typically we assume
1572 * the information that is filled in here (except flags) doesn't
1573 * change while a STA structure is alive. As such, it should move
1574 * to between the sta_info_alloc() and sta_info_insert() above.
1577 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1578 WLAN_STA_AUTHORIZED);
1582 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1584 for (i = 0; i < elems.supp_rates_len; i++) {
1585 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1586 bool is_basic = !!(elems.supp_rates[i] & 0x80);
1589 have_higher_than_11mbit = true;
1591 for (j = 0; j < sband->n_bitrates; j++) {
1592 if (sband->bitrates[j].bitrate == rate) {
1595 basic_rates |= BIT(j);
1601 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1602 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1603 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
1606 have_higher_than_11mbit = true;
1608 for (j = 0; j < sband->n_bitrates; j++) {
1609 if (sband->bitrates[j].bitrate == rate) {
1612 basic_rates |= BIT(j);
1618 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
1619 sdata->vif.bss_conf.basic_rates = basic_rates;
1621 /* cf. IEEE 802.11 9.2.12 */
1622 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1623 have_higher_than_11mbit)
1624 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1626 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
1628 /* If TKIP/WEP is used, no need to parse AP's HT capabilities */
1629 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
1630 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1631 elems.ht_cap_elem, &sta->sta.ht_cap);
1633 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1635 rate_control_rate_init(sta);
1637 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
1638 set_sta_flags(sta, WLAN_STA_MFP);
1640 if (elems.wmm_param)
1641 set_sta_flags(sta, WLAN_STA_WME);
1644 int err = sta_info_insert(sta);
1646 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1647 " the AP (error %d)\n", sdata->dev->name, err);
1655 if (elems.wmm_param)
1656 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1657 elems.wmm_param_len);
1659 if (elems.ht_info_elem && elems.wmm_param &&
1660 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
1661 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
1662 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1665 /* set AID and assoc capability,
1666 * ieee80211_set_associated() will tell the driver */
1667 bss_conf->aid = aid;
1668 bss_conf->assoc_capability = capab_info;
1669 ieee80211_set_associated(sdata, changed);
1672 * initialise the time of last beacon to be the association time,
1673 * otherwise beacon loss check will trigger immediately
1675 ifmgd->last_beacon = jiffies;
1677 ieee80211_associated(sdata);
1678 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1682 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1683 struct ieee80211_mgmt *mgmt,
1685 struct ieee80211_rx_status *rx_status,
1686 struct ieee802_11_elems *elems,
1689 struct ieee80211_local *local = sdata->local;
1691 struct ieee80211_bss *bss;
1692 struct ieee80211_channel *channel;
1694 if (elems->ds_params && elems->ds_params_len == 1)
1695 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
1697 freq = rx_status->freq;
1699 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1701 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1704 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
1709 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
1710 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
1711 struct ieee80211_channel_sw_ie *sw_elem =
1712 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
1713 ieee80211_process_chanswitch(sdata, sw_elem, bss);
1716 ieee80211_rx_bss_put(local, bss);
1720 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1721 struct ieee80211_mgmt *mgmt,
1723 struct ieee80211_rx_status *rx_status)
1725 struct ieee80211_if_managed *ifmgd;
1727 struct ieee802_11_elems elems;
1729 ifmgd = &sdata->u.mgd;
1731 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
1732 return; /* ignore ProbeResp to foreign address */
1734 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1738 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1741 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
1743 /* direct probe may be part of the association flow */
1744 if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
1746 printk(KERN_DEBUG "%s direct probe responded\n",
1748 ieee80211_authenticate(sdata);
1751 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1752 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1755 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1756 struct ieee80211_mgmt *mgmt,
1758 struct ieee80211_rx_status *rx_status)
1760 struct ieee80211_if_managed *ifmgd;
1762 struct ieee802_11_elems elems;
1763 struct ieee80211_local *local = sdata->local;
1765 bool erp_valid, directed_tim;
1768 /* Process beacon from the current BSS */
1769 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1773 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
1775 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
1777 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1780 ifmgd = &sdata->u.mgd;
1782 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
1783 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
1786 if (rx_status->freq != local->hw.conf.channel->center_freq)
1789 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1790 elems.wmm_param_len);
1792 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
1793 directed_tim = ieee80211_check_tim(&elems, ifmgd->aid);
1796 if (local->hw.conf.dynamic_ps_timeout > 0) {
1797 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1798 ieee80211_hw_config(local,
1799 IEEE80211_CONF_CHANGE_PS);
1800 ieee80211_send_nullfunc(local, sdata, 0);
1802 local->pspolling = true;
1805 * Here is assumed that the driver will be
1806 * able to send ps-poll frame and receive a
1807 * response even though power save mode is
1808 * enabled, but some drivers might require
1809 * to disable power save here. This needs
1810 * to be investigated.
1812 ieee80211_send_pspoll(local, sdata);
1817 if (elems.erp_info && elems.erp_info_len >= 1) {
1819 erp_value = elems.erp_info[0];
1823 changed |= ieee80211_handle_bss_capability(sdata,
1824 le16_to_cpu(mgmt->u.beacon.capab_info),
1825 erp_valid, erp_value);
1828 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
1829 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) {
1830 struct sta_info *sta;
1831 struct ieee80211_supported_band *sband;
1832 u16 ap_ht_cap_flags;
1836 sta = sta_info_get(local, ifmgd->bssid);
1842 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1844 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1845 elems.ht_cap_elem, &sta->sta.ht_cap);
1847 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1851 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1855 if (elems.country_elem) {
1856 /* Note we are only reviewing this on beacons
1857 * for the BSSID we are associated to */
1858 regulatory_hint_11d(local->hw.wiphy,
1859 elems.country_elem, elems.country_elem_len);
1861 /* TODO: IBSS also needs this */
1862 if (elems.pwr_constr_elem)
1863 ieee80211_handle_pwr_constr(sdata,
1864 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1865 elems.pwr_constr_elem,
1866 elems.pwr_constr_elem_len);
1869 ieee80211_bss_info_change_notify(sdata, changed);
1872 ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1873 struct sk_buff *skb,
1874 struct ieee80211_rx_status *rx_status)
1876 struct ieee80211_local *local = sdata->local;
1877 struct ieee80211_mgmt *mgmt;
1881 return RX_DROP_MONITOR;
1883 mgmt = (struct ieee80211_mgmt *) skb->data;
1884 fc = le16_to_cpu(mgmt->frame_control);
1886 switch (fc & IEEE80211_FCTL_STYPE) {
1887 case IEEE80211_STYPE_PROBE_REQ:
1888 case IEEE80211_STYPE_PROBE_RESP:
1889 case IEEE80211_STYPE_BEACON:
1890 memcpy(skb->cb, rx_status, sizeof(*rx_status));
1891 case IEEE80211_STYPE_AUTH:
1892 case IEEE80211_STYPE_ASSOC_RESP:
1893 case IEEE80211_STYPE_REASSOC_RESP:
1894 case IEEE80211_STYPE_DEAUTH:
1895 case IEEE80211_STYPE_DISASSOC:
1896 skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
1897 queue_work(local->hw.workqueue, &sdata->u.mgd.work);
1901 return RX_DROP_MONITOR;
1904 static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1905 struct sk_buff *skb)
1907 struct ieee80211_rx_status *rx_status;
1908 struct ieee80211_mgmt *mgmt;
1911 rx_status = (struct ieee80211_rx_status *) skb->cb;
1912 mgmt = (struct ieee80211_mgmt *) skb->data;
1913 fc = le16_to_cpu(mgmt->frame_control);
1915 switch (fc & IEEE80211_FCTL_STYPE) {
1916 case IEEE80211_STYPE_PROBE_RESP:
1917 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
1920 case IEEE80211_STYPE_BEACON:
1921 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1924 case IEEE80211_STYPE_AUTH:
1925 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
1927 case IEEE80211_STYPE_ASSOC_RESP:
1928 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0);
1930 case IEEE80211_STYPE_REASSOC_RESP:
1931 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1);
1933 case IEEE80211_STYPE_DEAUTH:
1934 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
1936 case IEEE80211_STYPE_DISASSOC:
1937 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1944 static void ieee80211_sta_timer(unsigned long data)
1946 struct ieee80211_sub_if_data *sdata =
1947 (struct ieee80211_sub_if_data *) data;
1948 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1949 struct ieee80211_local *local = sdata->local;
1951 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
1952 queue_work(local->hw.workqueue, &ifmgd->work);
1955 static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
1957 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1958 struct ieee80211_local *local = sdata->local;
1960 if (local->ops->reset_tsf) {
1961 /* Reset own TSF to allow time synchronization work. */
1962 local->ops->reset_tsf(local_to_hw(local));
1965 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
1968 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1969 ifmgd->auth_alg = WLAN_AUTH_OPEN;
1970 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1971 ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY;
1972 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1973 ifmgd->auth_alg = WLAN_AUTH_LEAP;
1974 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
1975 ifmgd->auth_alg = WLAN_AUTH_FT;
1977 ifmgd->auth_alg = WLAN_AUTH_OPEN;
1978 ifmgd->auth_transaction = -1;
1979 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
1980 ifmgd->assoc_scan_tries = 0;
1981 ifmgd->direct_probe_tries = 0;
1982 ifmgd->auth_tries = 0;
1983 ifmgd->assoc_tries = 0;
1984 netif_tx_stop_all_queues(sdata->dev);
1985 netif_carrier_off(sdata->dev);
1988 static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
1990 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1991 struct ieee80211_local *local = sdata->local;
1992 struct ieee80211_bss *bss;
1993 u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
1994 u8 ssid_len = ifmgd->ssid_len;
1995 u16 capa_mask = WLAN_CAPABILITY_ESS;
1996 u16 capa_val = WLAN_CAPABILITY_ESS;
1997 struct ieee80211_channel *chan = local->oper_channel;
1999 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
2000 ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
2001 IEEE80211_STA_AUTO_BSSID_SEL |
2002 IEEE80211_STA_AUTO_CHANNEL_SEL)) {
2003 capa_mask |= WLAN_CAPABILITY_PRIVACY;
2004 if (sdata->default_key)
2005 capa_val |= WLAN_CAPABILITY_PRIVACY;
2008 if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
2011 if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
2014 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
2019 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan,
2020 bssid, ssid, ssid_len,
2021 capa_mask, capa_val);
2024 ieee80211_set_freq(sdata, bss->cbss.channel->center_freq);
2025 if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
2026 ieee80211_sta_set_ssid(sdata, bss->ssid,
2028 ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
2029 ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
2031 if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
2032 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
2034 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
2036 /* Send out direct probe if no probe resp was received or
2037 * the one we have is outdated
2039 if (!bss->last_probe_resp ||
2040 time_after(jiffies, bss->last_probe_resp
2041 + IEEE80211_SCAN_RESULT_EXPIRE))
2042 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
2044 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
2046 ieee80211_rx_bss_put(local, bss);
2047 ieee80211_sta_reset_auth(sdata);
2050 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
2051 ifmgd->assoc_scan_tries++;
2052 /* XXX maybe racy? */
2053 if (local->scan_req)
2055 memcpy(local->int_scan_req.ssids[0].ssid,
2056 ifmgd->ssid, IEEE80211_MAX_SSID_LEN);
2057 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL)
2058 local->int_scan_req.ssids[0].ssid_len = 0;
2060 local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
2062 if (ieee80211_start_scan(sdata, &local->int_scan_req))
2063 ieee80211_scan_failed(local);
2065 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
2066 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
2068 ifmgd->assoc_scan_tries = 0;
2069 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
2076 static void ieee80211_sta_work(struct work_struct *work)
2078 struct ieee80211_sub_if_data *sdata =
2079 container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
2080 struct ieee80211_local *local = sdata->local;
2081 struct ieee80211_if_managed *ifmgd;
2082 struct sk_buff *skb;
2084 if (!netif_running(sdata->dev))
2087 if (local->sw_scanning || local->hw_scanning)
2090 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2092 ifmgd = &sdata->u.mgd;
2094 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
2095 ieee80211_sta_rx_queued_mgmt(sdata, skb);
2097 if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
2098 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
2099 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
2100 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
2102 * The call to ieee80211_start_scan can fail but ieee80211_request_scan
2103 * (which queued ieee80211_sta_work) did not return an error. Thus, call
2104 * ieee80211_scan_failed here if ieee80211_start_scan fails in order to
2105 * notify the scan requester.
2107 if (ieee80211_start_scan(sdata, local->scan_req))
2108 ieee80211_scan_failed(local);
2112 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) {
2113 if (ieee80211_sta_config_auth(sdata))
2115 clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
2116 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
2119 switch (ifmgd->state) {
2120 case IEEE80211_STA_MLME_DISABLED:
2122 case IEEE80211_STA_MLME_DIRECT_PROBE:
2123 ieee80211_direct_probe(sdata);
2125 case IEEE80211_STA_MLME_AUTHENTICATE:
2126 ieee80211_authenticate(sdata);
2128 case IEEE80211_STA_MLME_ASSOCIATE:
2129 ieee80211_associate(sdata);
2131 case IEEE80211_STA_MLME_ASSOCIATED:
2132 ieee80211_associated(sdata);
2139 if (ieee80211_privacy_mismatch(sdata)) {
2140 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
2141 "mixed-cell disabled - disassociate\n", sdata->dev->name);
2143 ieee80211_set_disassoc(sdata, false, true,
2144 WLAN_REASON_UNSPECIFIED);
2148 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2150 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2152 * Need to update last_beacon to avoid beacon loss
2155 sdata->u.mgd.last_beacon = jiffies;
2158 queue_work(sdata->local->hw.workqueue,
2159 &sdata->u.mgd.work);
2163 /* interface setup */
2164 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2166 struct ieee80211_if_managed *ifmgd;
2168 ifmgd = &sdata->u.mgd;
2169 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
2170 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
2171 INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
2172 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
2173 (unsigned long) sdata);
2174 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
2175 (unsigned long) sdata);
2176 skb_queue_head_init(&ifmgd->skb_queue);
2178 ifmgd->capab = WLAN_CAPABILITY_ESS;
2179 ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN |
2180 IEEE80211_AUTH_ALG_SHARED_KEY;
2181 ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
2182 IEEE80211_STA_AUTO_BSSID_SEL |
2183 IEEE80211_STA_AUTO_CHANNEL_SEL;
2184 if (sdata->local->hw.queues >= 4)
2185 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
2188 /* configuration hooks */
2189 void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata)
2191 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2192 struct ieee80211_local *local = sdata->local;
2194 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2197 if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
2198 IEEE80211_STA_AUTO_BSSID_SEL)) &&
2199 (ifmgd->flags & (IEEE80211_STA_SSID_SET |
2200 IEEE80211_STA_AUTO_SSID_SEL))) {
2202 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2203 ieee80211_set_disassoc(sdata, true, true,
2204 WLAN_REASON_DEAUTH_LEAVING);
2206 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) ||
2207 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
2208 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
2209 else if (ifmgd->flags & IEEE80211_STA_EXT_SME)
2210 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
2211 queue_work(local->hw.workqueue, &ifmgd->work);
2215 int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata)
2217 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2219 if (ifmgd->ssid_len)
2220 ifmgd->flags |= IEEE80211_STA_SSID_SET;
2222 ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
2227 int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
2229 struct ieee80211_if_managed *ifmgd;
2231 if (len > IEEE80211_MAX_SSID_LEN)
2234 ifmgd = &sdata->u.mgd;
2236 if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) {
2238 * Do not use reassociation if SSID is changed (different ESS).
2240 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
2241 memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
2242 memcpy(ifmgd->ssid, ssid, len);
2243 ifmgd->ssid_len = len;
2246 return ieee80211_sta_commit(sdata);
2249 int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
2251 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2252 memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len);
2253 *len = ifmgd->ssid_len;
2257 int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2259 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2261 if (is_valid_ether_addr(bssid)) {
2262 memcpy(ifmgd->bssid, bssid, ETH_ALEN);
2263 ifmgd->flags |= IEEE80211_STA_BSSID_SET;
2265 memset(ifmgd->bssid, 0, ETH_ALEN);
2266 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
2269 if (netif_running(sdata->dev)) {
2270 if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
2271 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
2272 "the low-level driver\n", sdata->dev->name);
2276 return ieee80211_sta_commit(sdata);
2279 int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
2280 const char *ie, size_t len)
2282 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2284 kfree(ifmgd->extra_ie);
2286 ifmgd->extra_ie = NULL;
2287 ifmgd->extra_ie_len = 0;
2290 ifmgd->extra_ie = kmalloc(len, GFP_KERNEL);
2291 if (!ifmgd->extra_ie) {
2292 ifmgd->extra_ie_len = 0;
2295 memcpy(ifmgd->extra_ie, ie, len);
2296 ifmgd->extra_ie_len = len;
2300 int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
2302 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2303 sdata->dev->name, reason);
2305 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2308 ieee80211_set_disassoc(sdata, true, true, reason);
2312 int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
2314 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2316 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2317 sdata->dev->name, reason);
2319 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2322 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
2325 ieee80211_set_disassoc(sdata, false, true, reason);
2329 /* scan finished notification */
2330 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2332 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
2334 /* Restart STA timers */
2336 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2337 ieee80211_restart_sta_timer(sdata);
2341 int ieee80211_max_network_latency(struct notifier_block *nb,
2342 unsigned long data, void *dummy)
2344 s32 latency_usec = (s32) data;
2345 struct ieee80211_local *local =
2346 container_of(nb, struct ieee80211_local,
2347 network_latency_notifier);
2349 mutex_lock(&local->iflist_mtx);
2350 ieee80211_recalc_ps(local, latency_usec);
2351 mutex_unlock(&local->iflist_mtx);