2 * BSS client mode implementation
3 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.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.
15 * order BSS list by RSSI(?) ("quality of AP")
16 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
19 #include <linux/delay.h>
20 #include <linux/if_ether.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/wireless.h>
25 #include <linux/random.h>
26 #include <linux/etherdevice.h>
27 #include <net/iw_handler.h>
28 #include <asm/types.h>
30 #include <net/mac80211.h>
31 #include "ieee80211_i.h"
32 #include "ieee80211_rate.h"
33 #include "ieee80211_led.h"
35 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
36 #define IEEE80211_AUTH_MAX_TRIES 3
37 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
38 #define IEEE80211_ASSOC_MAX_TRIES 3
39 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
40 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
41 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
42 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
43 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
44 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
46 #define IEEE80211_PROBE_DELAY (HZ / 33)
47 #define IEEE80211_CHANNEL_TIME (HZ / 33)
48 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
49 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
50 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
51 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
53 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
56 #define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
58 #define ERP_INFO_USE_PROTECTION BIT(1)
60 /* mgmt header + 1 byte action code */
61 #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
63 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
64 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
65 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
67 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
68 u8 *ssid, size_t ssid_len);
69 static struct ieee80211_sta_bss *
70 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
71 u8 *ssid, u8 ssid_len);
72 static void ieee80211_rx_bss_put(struct net_device *dev,
73 struct ieee80211_sta_bss *bss);
74 static int ieee80211_sta_find_ibss(struct net_device *dev,
75 struct ieee80211_if_sta *ifsta);
76 static int ieee80211_sta_wep_configured(struct net_device *dev);
77 static int ieee80211_sta_start_scan(struct net_device *dev,
78 u8 *ssid, size_t ssid_len);
79 static int ieee80211_sta_config_auth(struct net_device *dev,
80 struct ieee80211_if_sta *ifsta);
83 /* Parsed Information Elements */
84 struct ieee802_11_elems {
102 /* length of them, respectively */
114 u8 ext_supp_rates_len;
121 static void ieee802_11_parse_elems(u8 *start, size_t len,
122 struct ieee802_11_elems *elems)
127 memset(elems, 0, sizeof(*elems));
142 elems->ssid_len = elen;
144 case WLAN_EID_SUPP_RATES:
145 elems->supp_rates = pos;
146 elems->supp_rates_len = elen;
148 case WLAN_EID_FH_PARAMS:
149 elems->fh_params = pos;
150 elems->fh_params_len = elen;
152 case WLAN_EID_DS_PARAMS:
153 elems->ds_params = pos;
154 elems->ds_params_len = elen;
156 case WLAN_EID_CF_PARAMS:
157 elems->cf_params = pos;
158 elems->cf_params_len = elen;
162 elems->tim_len = elen;
164 case WLAN_EID_IBSS_PARAMS:
165 elems->ibss_params = pos;
166 elems->ibss_params_len = elen;
168 case WLAN_EID_CHALLENGE:
169 elems->challenge = pos;
170 elems->challenge_len = elen;
173 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
175 /* Microsoft OUI (00:50:F2) */
177 /* OUI Type 1 - WPA IE */
179 elems->wpa_len = elen;
180 } else if (elen >= 5 && pos[3] == 2) {
182 elems->wmm_info = pos;
183 elems->wmm_info_len = elen;
184 } else if (pos[4] == 1) {
185 elems->wmm_param = pos;
186 elems->wmm_param_len = elen;
193 elems->rsn_len = elen;
195 case WLAN_EID_ERP_INFO:
196 elems->erp_info = pos;
197 elems->erp_info_len = elen;
199 case WLAN_EID_EXT_SUPP_RATES:
200 elems->ext_supp_rates = pos;
201 elems->ext_supp_rates_len = elen;
203 case WLAN_EID_HT_CAPABILITY:
204 elems->ht_cap_elem = pos;
205 elems->ht_cap_elem_len = elen;
207 case WLAN_EID_HT_EXTRA_INFO:
208 elems->ht_info_elem = pos;
209 elems->ht_info_elem_len = elen;
221 static int ecw2cw(int ecw)
231 static void ieee80211_sta_wmm_params(struct net_device *dev,
232 struct ieee80211_if_sta *ifsta,
233 u8 *wmm_param, size_t wmm_param_len)
235 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
236 struct ieee80211_tx_queue_params params;
241 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
243 count = wmm_param[6] & 0x0f;
244 if (count == ifsta->wmm_last_param_set)
246 ifsta->wmm_last_param_set = count;
249 left = wmm_param_len - 8;
251 memset(¶ms, 0, sizeof(params));
253 if (!local->ops->conf_tx)
257 for (; left >= 4; left -= 4, pos += 4) {
258 int aci = (pos[0] >> 5) & 0x03;
259 int acm = (pos[0] >> 4) & 0x01;
264 queue = IEEE80211_TX_QUEUE_DATA3;
266 local->wmm_acm |= BIT(0) | BIT(3);
270 queue = IEEE80211_TX_QUEUE_DATA1;
272 local->wmm_acm |= BIT(4) | BIT(5);
276 queue = IEEE80211_TX_QUEUE_DATA0;
278 local->wmm_acm |= BIT(6) | BIT(7);
283 queue = IEEE80211_TX_QUEUE_DATA2;
285 local->wmm_acm |= BIT(1) | BIT(2);
290 params.aifs = pos[0] & 0x0f;
291 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
292 params.cw_min = ecw2cw(pos[1] & 0x0f);
293 /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
294 params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100;
295 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
296 "cWmin=%d cWmax=%d burst=%d\n",
297 dev->name, queue, aci, acm, params.aifs, params.cw_min,
298 params.cw_max, params.burst_time);
299 /* TODO: handle ACM (block TX, fallback to next lowest allowed
301 if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) {
302 printk(KERN_DEBUG "%s: failed to set TX queue "
303 "parameters for queue %d\n", dev->name, queue);
309 static void ieee80211_handle_erp_ie(struct net_device *dev, u8 erp_value)
311 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
312 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
313 int use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
314 int preamble_mode = (erp_value & WLAN_ERP_BARKER_PREAMBLE) != 0;
316 DECLARE_MAC_BUF(mac);
318 if (use_protection != !!(sdata->flags & IEEE80211_SDATA_USE_PROTECTION)) {
319 if (net_ratelimit()) {
320 printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
323 use_protection ? "enabled" : "disabled",
324 print_mac(mac, ifsta->bssid));
327 sdata->flags |= IEEE80211_SDATA_USE_PROTECTION;
329 sdata->flags &= ~IEEE80211_SDATA_USE_PROTECTION;
330 changes |= IEEE80211_ERP_CHANGE_PROTECTION;
333 if (preamble_mode != !(sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE)) {
334 if (net_ratelimit()) {
335 printk(KERN_DEBUG "%s: switched to %s barker preamble"
338 (preamble_mode == WLAN_ERP_PREAMBLE_SHORT) ?
340 print_mac(mac, ifsta->bssid));
343 sdata->flags &= ~IEEE80211_SDATA_SHORT_PREAMBLE;
345 sdata->flags |= IEEE80211_SDATA_SHORT_PREAMBLE;
346 changes |= IEEE80211_ERP_CHANGE_PREAMBLE;
350 ieee80211_erp_info_change_notify(dev, changes);
353 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
354 struct ieee80211_ht_info *ht_info)
360 memset(ht_info, 0, sizeof(*ht_info));
363 u8 ampdu_info = ht_cap_ie->ampdu_params_info;
365 ht_info->ht_supported = 1;
366 ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info);
367 ht_info->ampdu_factor =
368 ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR;
369 ht_info->ampdu_density =
370 (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
371 memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16);
373 ht_info->ht_supported = 0;
378 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
379 struct ieee80211_ht_addt_info *ht_add_info_ie,
380 struct ieee80211_ht_bss_info *bss_info)
382 if (bss_info == NULL)
385 memset(bss_info, 0, sizeof(*bss_info));
387 if (ht_add_info_ie) {
389 op_mode = le16_to_cpu(ht_add_info_ie->operation_mode);
391 bss_info->primary_channel = ht_add_info_ie->control_chan;
392 bss_info->bss_cap = ht_add_info_ie->ht_param;
393 bss_info->bss_op_mode = (u8)(op_mode & 0xff);
399 static void ieee80211_sta_send_associnfo(struct net_device *dev,
400 struct ieee80211_if_sta *ifsta)
405 union iwreq_data wrqu;
407 if (!ifsta->assocreq_ies && !ifsta->assocresp_ies)
410 buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
411 ifsta->assocresp_ies_len), GFP_KERNEL);
415 len = sprintf(buf, "ASSOCINFO(");
416 if (ifsta->assocreq_ies) {
417 len += sprintf(buf + len, "ReqIEs=");
418 for (i = 0; i < ifsta->assocreq_ies_len; i++) {
419 len += sprintf(buf + len, "%02x",
420 ifsta->assocreq_ies[i]);
423 if (ifsta->assocresp_ies) {
424 if (ifsta->assocreq_ies)
425 len += sprintf(buf + len, " ");
426 len += sprintf(buf + len, "RespIEs=");
427 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
428 len += sprintf(buf + len, "%02x",
429 ifsta->assocresp_ies[i]);
432 len += sprintf(buf + len, ")");
434 if (len > IW_CUSTOM_MAX) {
435 len = sprintf(buf, "ASSOCRESPIE=");
436 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
437 len += sprintf(buf + len, "%02x",
438 ifsta->assocresp_ies[i]);
442 memset(&wrqu, 0, sizeof(wrqu));
443 wrqu.data.length = len;
444 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
450 static void ieee80211_set_associated(struct net_device *dev,
451 struct ieee80211_if_sta *ifsta,
454 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
455 union iwreq_data wrqu;
457 if (!!(ifsta->flags & IEEE80211_STA_ASSOCIATED) == assoc)
461 struct ieee80211_sub_if_data *sdata;
462 struct ieee80211_sta_bss *bss;
464 ifsta->flags |= IEEE80211_STA_ASSOCIATED;
466 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
467 if (sdata->type != IEEE80211_IF_TYPE_STA)
470 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
471 local->hw.conf.channel,
472 ifsta->ssid, ifsta->ssid_len);
474 if (bss->has_erp_value)
475 ieee80211_handle_erp_ie(dev, bss->erp_value);
476 ieee80211_rx_bss_put(dev, bss);
479 netif_carrier_on(dev);
480 ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
481 memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
482 memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
483 ieee80211_sta_send_associnfo(dev, ifsta);
485 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
487 netif_carrier_off(dev);
488 ieee80211_reset_erp_info(dev);
489 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
491 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
492 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
493 ifsta->last_probe = jiffies;
494 ieee80211_led_assoc(local, assoc);
497 static void ieee80211_set_disassoc(struct net_device *dev,
498 struct ieee80211_if_sta *ifsta, int deauth)
501 ifsta->auth_tries = 0;
502 ifsta->assoc_tries = 0;
503 ieee80211_set_associated(dev, ifsta, 0);
506 static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
509 struct ieee80211_sub_if_data *sdata;
510 struct ieee80211_tx_packet_data *pkt_data;
512 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
513 skb->dev = sdata->local->mdev;
514 skb_set_mac_header(skb, 0);
515 skb_set_network_header(skb, 0);
516 skb_set_transport_header(skb, 0);
518 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
519 memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
520 pkt_data->ifindex = sdata->dev->ifindex;
522 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
528 static void ieee80211_send_auth(struct net_device *dev,
529 struct ieee80211_if_sta *ifsta,
530 int transaction, u8 *extra, size_t extra_len,
533 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
535 struct ieee80211_mgmt *mgmt;
537 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
538 sizeof(*mgmt) + 6 + extra_len);
540 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
541 "frame\n", dev->name);
544 skb_reserve(skb, local->hw.extra_tx_headroom);
546 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
547 memset(mgmt, 0, 24 + 6);
548 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
549 IEEE80211_STYPE_AUTH);
551 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
552 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
553 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
554 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
555 mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
556 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
557 ifsta->auth_transaction = transaction + 1;
558 mgmt->u.auth.status_code = cpu_to_le16(0);
560 memcpy(skb_put(skb, extra_len), extra, extra_len);
562 ieee80211_sta_tx(dev, skb, encrypt);
566 static void ieee80211_authenticate(struct net_device *dev,
567 struct ieee80211_if_sta *ifsta)
569 DECLARE_MAC_BUF(mac);
572 if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
573 printk(KERN_DEBUG "%s: authentication with AP %s"
575 dev->name, print_mac(mac, ifsta->bssid));
576 ifsta->state = IEEE80211_DISABLED;
580 ifsta->state = IEEE80211_AUTHENTICATE;
581 printk(KERN_DEBUG "%s: authenticate with AP %s\n",
582 dev->name, print_mac(mac, ifsta->bssid));
584 ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
586 mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
590 static void ieee80211_send_assoc(struct net_device *dev,
591 struct ieee80211_if_sta *ifsta)
593 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
594 struct ieee80211_hw_mode *mode;
596 struct ieee80211_mgmt *mgmt;
600 struct ieee80211_sta_bss *bss;
603 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
604 sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
607 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
608 "frame\n", dev->name);
611 skb_reserve(skb, local->hw.extra_tx_headroom);
613 mode = local->oper_hw_mode;
614 capab = ifsta->capab;
615 if (mode->mode == MODE_IEEE80211G) {
616 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
617 WLAN_CAPABILITY_SHORT_PREAMBLE;
619 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel,
620 ifsta->ssid, ifsta->ssid_len);
622 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
623 capab |= WLAN_CAPABILITY_PRIVACY;
627 ieee80211_rx_bss_put(dev, bss);
630 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
632 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
633 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
634 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
636 if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
638 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
639 IEEE80211_STYPE_REASSOC_REQ);
640 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
641 mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1);
642 memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
646 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
647 IEEE80211_STYPE_ASSOC_REQ);
648 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
649 mgmt->u.assoc_req.listen_interval = cpu_to_le16(1);
653 ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
654 *pos++ = WLAN_EID_SSID;
655 *pos++ = ifsta->ssid_len;
656 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
658 len = mode->num_rates;
661 pos = skb_put(skb, len + 2);
662 *pos++ = WLAN_EID_SUPP_RATES;
664 for (i = 0; i < len; i++) {
665 int rate = mode->rates[i].rate;
666 *pos++ = (u8) (rate / 5);
669 if (mode->num_rates > len) {
670 pos = skb_put(skb, mode->num_rates - len + 2);
671 *pos++ = WLAN_EID_EXT_SUPP_RATES;
672 *pos++ = mode->num_rates - len;
673 for (i = len; i < mode->num_rates; i++) {
674 int rate = mode->rates[i].rate;
675 *pos++ = (u8) (rate / 5);
679 if (ifsta->extra_ie) {
680 pos = skb_put(skb, ifsta->extra_ie_len);
681 memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
684 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
685 pos = skb_put(skb, 9);
686 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
687 *pos++ = 7; /* len */
688 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
691 *pos++ = 2; /* WME */
692 *pos++ = 0; /* WME info */
693 *pos++ = 1; /* WME ver */
696 /* wmm support is a must to HT */
697 if (wmm && mode->ht_info.ht_supported) {
698 __le16 tmp = cpu_to_le16(mode->ht_info.cap);
699 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
700 *pos++ = WLAN_EID_HT_CAPABILITY;
701 *pos++ = sizeof(struct ieee80211_ht_cap);
702 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
703 memcpy(pos, &tmp, sizeof(u16));
705 *pos++ = (mode->ht_info.ampdu_factor |
706 (mode->ht_info.ampdu_density << 2));
707 memcpy(pos, mode->ht_info.supp_mcs_set, 16);
710 kfree(ifsta->assocreq_ies);
711 ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
712 ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
713 if (ifsta->assocreq_ies)
714 memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
716 ieee80211_sta_tx(dev, skb, 0);
720 static void ieee80211_send_deauth(struct net_device *dev,
721 struct ieee80211_if_sta *ifsta, u16 reason)
723 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
725 struct ieee80211_mgmt *mgmt;
727 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
729 printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
730 "frame\n", dev->name);
733 skb_reserve(skb, local->hw.extra_tx_headroom);
735 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
737 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
738 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
739 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
740 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
741 IEEE80211_STYPE_DEAUTH);
743 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
745 ieee80211_sta_tx(dev, skb, 0);
749 static void ieee80211_send_disassoc(struct net_device *dev,
750 struct ieee80211_if_sta *ifsta, u16 reason)
752 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
754 struct ieee80211_mgmt *mgmt;
756 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
758 printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
759 "frame\n", dev->name);
762 skb_reserve(skb, local->hw.extra_tx_headroom);
764 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
766 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
767 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
768 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
769 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
770 IEEE80211_STYPE_DISASSOC);
772 mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
774 ieee80211_sta_tx(dev, skb, 0);
778 static int ieee80211_privacy_mismatch(struct net_device *dev,
779 struct ieee80211_if_sta *ifsta)
781 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
782 struct ieee80211_sta_bss *bss;
787 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
790 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel,
791 ifsta->ssid, ifsta->ssid_len);
795 bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
796 wep_privacy = !!ieee80211_sta_wep_configured(dev);
797 privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
799 ieee80211_rx_bss_put(dev, bss);
801 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
808 static void ieee80211_associate(struct net_device *dev,
809 struct ieee80211_if_sta *ifsta)
811 DECLARE_MAC_BUF(mac);
813 ifsta->assoc_tries++;
814 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
815 printk(KERN_DEBUG "%s: association with AP %s"
817 dev->name, print_mac(mac, ifsta->bssid));
818 ifsta->state = IEEE80211_DISABLED;
822 ifsta->state = IEEE80211_ASSOCIATE;
823 printk(KERN_DEBUG "%s: associate with AP %s\n",
824 dev->name, print_mac(mac, ifsta->bssid));
825 if (ieee80211_privacy_mismatch(dev, ifsta)) {
826 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
827 "mixed-cell disabled - abort association\n", dev->name);
828 ifsta->state = IEEE80211_DISABLED;
832 ieee80211_send_assoc(dev, ifsta);
834 mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
838 static void ieee80211_associated(struct net_device *dev,
839 struct ieee80211_if_sta *ifsta)
841 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
842 struct sta_info *sta;
844 DECLARE_MAC_BUF(mac);
846 /* TODO: start monitoring current AP signal quality and number of
847 * missed beacons. Scan other channels every now and then and search
849 /* TODO: remove expired BSSes */
851 ifsta->state = IEEE80211_ASSOCIATED;
853 sta = sta_info_get(local, ifsta->bssid);
855 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
856 dev->name, print_mac(mac, ifsta->bssid));
860 if (time_after(jiffies,
861 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
862 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
863 printk(KERN_DEBUG "%s: No ProbeResp from "
864 "current AP %s - assume out of "
866 dev->name, print_mac(mac, ifsta->bssid));
870 ieee80211_send_probe_req(dev, ifsta->bssid,
872 local->scan_ssid_len);
873 ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
875 ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
876 if (time_after(jiffies, ifsta->last_probe +
877 IEEE80211_PROBE_INTERVAL)) {
878 ifsta->last_probe = jiffies;
879 ieee80211_send_probe_req(dev, ifsta->bssid,
887 ifsta->state = IEEE80211_DISABLED;
888 ieee80211_set_associated(dev, ifsta, 0);
890 mod_timer(&ifsta->timer, jiffies +
891 IEEE80211_MONITORING_INTERVAL);
896 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
897 u8 *ssid, size_t ssid_len)
899 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
900 struct ieee80211_hw_mode *mode;
902 struct ieee80211_mgmt *mgmt;
903 u8 *pos, *supp_rates, *esupp_rates = NULL;
906 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
908 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
909 "request\n", dev->name);
912 skb_reserve(skb, local->hw.extra_tx_headroom);
914 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
916 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
917 IEEE80211_STYPE_PROBE_REQ);
918 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
920 memcpy(mgmt->da, dst, ETH_ALEN);
921 memcpy(mgmt->bssid, dst, ETH_ALEN);
923 memset(mgmt->da, 0xff, ETH_ALEN);
924 memset(mgmt->bssid, 0xff, ETH_ALEN);
926 pos = skb_put(skb, 2 + ssid_len);
927 *pos++ = WLAN_EID_SSID;
929 memcpy(pos, ssid, ssid_len);
931 supp_rates = skb_put(skb, 2);
932 supp_rates[0] = WLAN_EID_SUPP_RATES;
934 mode = local->oper_hw_mode;
935 for (i = 0; i < mode->num_rates; i++) {
936 struct ieee80211_rate *rate = &mode->rates[i];
937 if (!(rate->flags & IEEE80211_RATE_SUPPORTED))
940 pos = skb_put(skb, 1);
942 } else if (supp_rates[1] == 8) {
943 esupp_rates = skb_put(skb, 3);
944 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
946 pos = &esupp_rates[2];
948 pos = skb_put(skb, 1);
951 *pos = rate->rate / 5;
954 ieee80211_sta_tx(dev, skb, 0);
958 static int ieee80211_sta_wep_configured(struct net_device *dev)
960 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
961 if (!sdata || !sdata->default_key ||
962 sdata->default_key->conf.alg != ALG_WEP)
968 static void ieee80211_auth_completed(struct net_device *dev,
969 struct ieee80211_if_sta *ifsta)
971 printk(KERN_DEBUG "%s: authenticated\n", dev->name);
972 ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
973 ieee80211_associate(dev, ifsta);
977 static void ieee80211_auth_challenge(struct net_device *dev,
978 struct ieee80211_if_sta *ifsta,
979 struct ieee80211_mgmt *mgmt,
983 struct ieee802_11_elems elems;
985 printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
986 pos = mgmt->u.auth.variable;
987 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
988 if (!elems.challenge) {
989 printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
990 "frame\n", dev->name);
993 ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
994 elems.challenge_len + 2, 1);
997 static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
998 u8 dialog_token, u16 status, u16 policy,
999 u16 buf_size, u16 timeout)
1001 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1002 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1003 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1004 struct sk_buff *skb;
1005 struct ieee80211_mgmt *mgmt;
1008 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
1010 printk(KERN_DEBUG "%s: failed to allocate buffer "
1011 "for addba resp frame\n", dev->name);
1015 skb_reserve(skb, local->hw.extra_tx_headroom);
1016 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1017 memset(mgmt, 0, 24);
1018 memcpy(mgmt->da, da, ETH_ALEN);
1019 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1020 if (sdata->type == IEEE80211_IF_TYPE_AP)
1021 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1023 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1024 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1025 IEEE80211_STYPE_ACTION);
1027 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
1028 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1029 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
1030 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
1032 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
1033 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1034 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
1036 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
1037 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
1038 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
1040 ieee80211_sta_tx(dev, skb, 0);
1045 static void ieee80211_sta_process_addba_request(struct net_device *dev,
1046 struct ieee80211_mgmt *mgmt,
1049 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1050 struct sta_info *sta;
1051 u16 capab, tid, timeout, ba_policy, buf_size, status;
1054 sta = sta_info_get(local, mgmt->sa);
1058 /* extract session parameters from addba request frame */
1059 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
1060 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
1062 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1063 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
1064 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1065 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
1067 /* TODO - currently aggregation is declined (A-MPDU add BA request
1068 * acceptance is not obligatory by 802.11n draft), but here is
1069 * the entry point for dealing with it */
1070 #ifdef MAC80211_HT_DEBUG
1071 if (net_ratelimit())
1072 printk(KERN_DEBUG "Add Block Ack request arrived,"
1073 " currently denying it\n");
1074 #endif /* MAC80211_HT_DEBUG */
1076 status = WLAN_STATUS_REQUEST_DECLINED;
1078 ieee80211_send_addba_resp(sta->dev, sta->addr, tid, dialog_token,
1079 status, 1, buf_size, timeout);
1083 static void ieee80211_rx_mgmt_auth(struct net_device *dev,
1084 struct ieee80211_if_sta *ifsta,
1085 struct ieee80211_mgmt *mgmt,
1088 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1089 u16 auth_alg, auth_transaction, status_code;
1090 DECLARE_MAC_BUF(mac);
1092 if (ifsta->state != IEEE80211_AUTHENTICATE &&
1093 sdata->type != IEEE80211_IF_TYPE_IBSS) {
1094 printk(KERN_DEBUG "%s: authentication frame received from "
1095 "%s, but not in authenticate state - ignored\n",
1096 dev->name, print_mac(mac, mgmt->sa));
1101 printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
1102 "received from %s - ignored\n",
1103 dev->name, len, print_mac(mac, mgmt->sa));
1107 if (sdata->type != IEEE80211_IF_TYPE_IBSS &&
1108 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1109 printk(KERN_DEBUG "%s: authentication frame received from "
1110 "unknown AP (SA=%s BSSID=%s) - "
1111 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1112 print_mac(mac, mgmt->bssid));
1116 if (sdata->type != IEEE80211_IF_TYPE_IBSS &&
1117 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
1118 printk(KERN_DEBUG "%s: authentication frame received from "
1119 "unknown BSSID (SA=%s BSSID=%s) - "
1120 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1121 print_mac(mac, mgmt->bssid));
1125 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1126 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1127 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1129 printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d "
1130 "transaction=%d status=%d)\n",
1131 dev->name, print_mac(mac, mgmt->sa), auth_alg,
1132 auth_transaction, status_code);
1134 if (sdata->type == IEEE80211_IF_TYPE_IBSS) {
1135 /* IEEE 802.11 standard does not require authentication in IBSS
1136 * networks and most implementations do not seem to use it.
1137 * However, try to reply to authentication attempts if someone
1138 * has actually implemented this.
1139 * TODO: Could implement shared key authentication. */
1140 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
1141 printk(KERN_DEBUG "%s: unexpected IBSS authentication "
1142 "frame (alg=%d transaction=%d)\n",
1143 dev->name, auth_alg, auth_transaction);
1146 ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
1149 if (auth_alg != ifsta->auth_alg ||
1150 auth_transaction != ifsta->auth_transaction) {
1151 printk(KERN_DEBUG "%s: unexpected authentication frame "
1152 "(alg=%d transaction=%d)\n",
1153 dev->name, auth_alg, auth_transaction);
1157 if (status_code != WLAN_STATUS_SUCCESS) {
1158 printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
1159 "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
1160 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1162 const int num_algs = ARRAY_SIZE(algs);
1164 algs[0] = algs[1] = algs[2] = 0xff;
1165 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1166 algs[0] = WLAN_AUTH_OPEN;
1167 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1168 algs[1] = WLAN_AUTH_SHARED_KEY;
1169 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1170 algs[2] = WLAN_AUTH_LEAP;
1171 if (ifsta->auth_alg == WLAN_AUTH_OPEN)
1173 else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
1177 for (i = 0; i < num_algs; i++) {
1179 if (pos >= num_algs)
1181 if (algs[pos] == ifsta->auth_alg ||
1184 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1185 !ieee80211_sta_wep_configured(dev))
1187 ifsta->auth_alg = algs[pos];
1188 printk(KERN_DEBUG "%s: set auth_alg=%d for "
1190 dev->name, ifsta->auth_alg);
1197 switch (ifsta->auth_alg) {
1198 case WLAN_AUTH_OPEN:
1199 case WLAN_AUTH_LEAP:
1200 ieee80211_auth_completed(dev, ifsta);
1202 case WLAN_AUTH_SHARED_KEY:
1203 if (ifsta->auth_transaction == 4)
1204 ieee80211_auth_completed(dev, ifsta);
1206 ieee80211_auth_challenge(dev, ifsta, mgmt, len);
1212 static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
1213 struct ieee80211_if_sta *ifsta,
1214 struct ieee80211_mgmt *mgmt,
1218 DECLARE_MAC_BUF(mac);
1221 printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
1222 "received from %s - ignored\n",
1223 dev->name, len, print_mac(mac, mgmt->sa));
1227 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1228 printk(KERN_DEBUG "%s: deauthentication frame received from "
1229 "unknown AP (SA=%s BSSID=%s) - "
1230 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1231 print_mac(mac, mgmt->bssid));
1235 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1237 printk(KERN_DEBUG "%s: RX deauthentication from %s"
1239 dev->name, print_mac(mac, mgmt->sa), reason_code);
1241 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) {
1242 printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
1245 if (ifsta->state == IEEE80211_AUTHENTICATE ||
1246 ifsta->state == IEEE80211_ASSOCIATE ||
1247 ifsta->state == IEEE80211_ASSOCIATED) {
1248 ifsta->state = IEEE80211_AUTHENTICATE;
1249 mod_timer(&ifsta->timer, jiffies +
1250 IEEE80211_RETRY_AUTH_INTERVAL);
1253 ieee80211_set_disassoc(dev, ifsta, 1);
1254 ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
1258 static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
1259 struct ieee80211_if_sta *ifsta,
1260 struct ieee80211_mgmt *mgmt,
1264 DECLARE_MAC_BUF(mac);
1267 printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
1268 "received from %s - ignored\n",
1269 dev->name, len, print_mac(mac, mgmt->sa));
1273 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1274 printk(KERN_DEBUG "%s: disassociation frame received from "
1275 "unknown AP (SA=%s BSSID=%s) - "
1276 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1277 print_mac(mac, mgmt->bssid));
1281 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1283 printk(KERN_DEBUG "%s: RX disassociation from %s"
1285 dev->name, print_mac(mac, mgmt->sa), reason_code);
1287 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
1288 printk(KERN_DEBUG "%s: disassociated\n", dev->name);
1290 if (ifsta->state == IEEE80211_ASSOCIATED) {
1291 ifsta->state = IEEE80211_ASSOCIATE;
1292 mod_timer(&ifsta->timer, jiffies +
1293 IEEE80211_RETRY_AUTH_INTERVAL);
1296 ieee80211_set_disassoc(dev, ifsta, 0);
1300 static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
1301 struct ieee80211_if_sta *ifsta,
1302 struct ieee80211_mgmt *mgmt,
1306 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1307 struct ieee80211_hw_mode *mode;
1308 struct sta_info *sta;
1310 u16 capab_info, status_code, aid;
1311 struct ieee802_11_elems elems;
1314 DECLARE_MAC_BUF(mac);
1316 /* AssocResp and ReassocResp have identical structure, so process both
1317 * of them in this function. */
1319 if (ifsta->state != IEEE80211_ASSOCIATE) {
1320 printk(KERN_DEBUG "%s: association frame received from "
1321 "%s, but not in associate state - ignored\n",
1322 dev->name, print_mac(mac, mgmt->sa));
1327 printk(KERN_DEBUG "%s: too short (%zd) association frame "
1328 "received from %s - ignored\n",
1329 dev->name, len, print_mac(mac, mgmt->sa));
1333 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1334 printk(KERN_DEBUG "%s: association frame received from "
1335 "unknown AP (SA=%s BSSID=%s) - "
1336 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1337 print_mac(mac, mgmt->bssid));
1341 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1342 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1343 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1345 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
1346 "status=%d aid=%d)\n",
1347 dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
1348 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1350 if (status_code != WLAN_STATUS_SUCCESS) {
1351 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1352 dev->name, status_code);
1353 /* if this was a reassociation, ensure we try a "full"
1354 * association next time. This works around some broken APs
1355 * which do not correctly reject reassociation requests. */
1356 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1360 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1361 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1362 "set\n", dev->name, aid);
1363 aid &= ~(BIT(15) | BIT(14));
1365 pos = mgmt->u.assoc_resp.variable;
1366 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1368 if (!elems.supp_rates) {
1369 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1374 /* it probably doesn't, but if the frame includes an ERP value then
1375 * update our stored copy */
1376 if (elems.erp_info && elems.erp_info_len >= 1) {
1377 struct ieee80211_sta_bss *bss
1378 = ieee80211_rx_bss_get(dev, ifsta->bssid,
1379 local->hw.conf.channel,
1380 ifsta->ssid, ifsta->ssid_len);
1382 bss->erp_value = elems.erp_info[0];
1383 bss->has_erp_value = 1;
1384 ieee80211_rx_bss_put(dev, bss);
1388 printk(KERN_DEBUG "%s: associated\n", dev->name);
1390 ifsta->ap_capab = capab_info;
1392 kfree(ifsta->assocresp_ies);
1393 ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1394 ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
1395 if (ifsta->assocresp_ies)
1396 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
1398 ieee80211_set_associated(dev, ifsta, 1);
1400 /* Add STA entry for the AP */
1401 sta = sta_info_get(local, ifsta->bssid);
1403 struct ieee80211_sta_bss *bss;
1404 sta = sta_info_add(local, dev, ifsta->bssid, GFP_KERNEL);
1406 printk(KERN_DEBUG "%s: failed to add STA entry for the"
1407 " AP\n", dev->name);
1410 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
1411 local->hw.conf.channel,
1412 ifsta->ssid, ifsta->ssid_len);
1414 sta->last_rssi = bss->rssi;
1415 sta->last_signal = bss->signal;
1416 sta->last_noise = bss->noise;
1417 ieee80211_rx_bss_put(dev, bss);
1422 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP;
1425 mode = local->oper_hw_mode;
1426 for (i = 0; i < elems.supp_rates_len; i++) {
1427 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1428 for (j = 0; j < mode->num_rates; j++)
1429 if (mode->rates[j].rate == rate)
1432 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1433 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1434 for (j = 0; j < mode->num_rates; j++)
1435 if (mode->rates[j].rate == rate)
1438 sta->supp_rates = rates;
1440 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
1441 local->ops->conf_ht) {
1442 struct ieee80211_ht_bss_info bss_info;
1444 ieee80211_ht_cap_ie_to_ht_info(
1445 (struct ieee80211_ht_cap *)
1446 elems.ht_cap_elem, &sta->ht_info);
1447 ieee80211_ht_addt_info_ie_to_ht_bss_info(
1448 (struct ieee80211_ht_addt_info *)
1449 elems.ht_info_elem, &bss_info);
1450 ieee80211_hw_config_ht(local, 1, &sta->ht_info, &bss_info);
1453 rate_control_rate_init(sta, local);
1455 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
1456 sta->flags |= WLAN_STA_WME;
1457 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
1458 elems.wmm_param_len);
1464 ieee80211_associated(dev, ifsta);
1468 /* Caller must hold local->sta_bss_lock */
1469 static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
1470 struct ieee80211_sta_bss *bss)
1472 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1473 bss->hnext = local->sta_bss_hash[STA_HASH(bss->bssid)];
1474 local->sta_bss_hash[STA_HASH(bss->bssid)] = bss;
1478 /* Caller must hold local->sta_bss_lock */
1479 static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
1480 struct ieee80211_sta_bss *bss)
1482 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1483 struct ieee80211_sta_bss *b, *prev = NULL;
1484 b = local->sta_bss_hash[STA_HASH(bss->bssid)];
1488 local->sta_bss_hash[STA_HASH(bss->bssid)] =
1491 prev->hnext = bss->hnext;
1500 static struct ieee80211_sta_bss *
1501 ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
1502 u8 *ssid, u8 ssid_len)
1504 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1505 struct ieee80211_sta_bss *bss;
1507 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
1510 atomic_inc(&bss->users);
1511 atomic_inc(&bss->users);
1512 memcpy(bss->bssid, bssid, ETH_ALEN);
1513 bss->channel = channel;
1514 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
1515 memcpy(bss->ssid, ssid, ssid_len);
1516 bss->ssid_len = ssid_len;
1519 spin_lock_bh(&local->sta_bss_lock);
1520 /* TODO: order by RSSI? */
1521 list_add_tail(&bss->list, &local->sta_bss_list);
1522 __ieee80211_rx_bss_hash_add(dev, bss);
1523 spin_unlock_bh(&local->sta_bss_lock);
1528 static struct ieee80211_sta_bss *
1529 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
1530 u8 *ssid, u8 ssid_len)
1532 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1533 struct ieee80211_sta_bss *bss;
1535 spin_lock_bh(&local->sta_bss_lock);
1536 bss = local->sta_bss_hash[STA_HASH(bssid)];
1538 if (!memcmp(bss->bssid, bssid, ETH_ALEN) &&
1539 bss->channel == channel &&
1540 bss->ssid_len == ssid_len &&
1541 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
1542 atomic_inc(&bss->users);
1547 spin_unlock_bh(&local->sta_bss_lock);
1552 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
1562 static void ieee80211_rx_bss_put(struct net_device *dev,
1563 struct ieee80211_sta_bss *bss)
1565 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1566 if (!atomic_dec_and_test(&bss->users))
1569 spin_lock_bh(&local->sta_bss_lock);
1570 __ieee80211_rx_bss_hash_del(dev, bss);
1571 list_del(&bss->list);
1572 spin_unlock_bh(&local->sta_bss_lock);
1573 ieee80211_rx_bss_free(bss);
1577 void ieee80211_rx_bss_list_init(struct net_device *dev)
1579 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1580 spin_lock_init(&local->sta_bss_lock);
1581 INIT_LIST_HEAD(&local->sta_bss_list);
1585 void ieee80211_rx_bss_list_deinit(struct net_device *dev)
1587 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1588 struct ieee80211_sta_bss *bss, *tmp;
1590 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
1591 ieee80211_rx_bss_put(dev, bss);
1595 static void ieee80211_rx_bss_info(struct net_device *dev,
1596 struct ieee80211_mgmt *mgmt,
1598 struct ieee80211_rx_status *rx_status,
1601 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1602 struct ieee802_11_elems elems;
1605 struct ieee80211_sta_bss *bss;
1606 struct sta_info *sta;
1607 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1609 DECLARE_MAC_BUF(mac);
1610 DECLARE_MAC_BUF(mac2);
1612 if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
1613 return; /* ignore ProbeResp to foreign address */
1616 printk(KERN_DEBUG "%s: RX %s from %s to %s\n",
1617 dev->name, beacon ? "Beacon" : "Probe Response",
1618 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da));
1621 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1625 timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
1627 if (sdata->type == IEEE80211_IF_TYPE_IBSS && beacon &&
1628 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
1629 #ifdef CONFIG_MAC80211_IBSS_DEBUG
1630 static unsigned long last_tsf_debug = 0;
1632 if (local->ops->get_tsf)
1633 tsf = local->ops->get_tsf(local_to_hw(local));
1636 if (time_after(jiffies, last_tsf_debug + 5 * HZ)) {
1637 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
1638 "%s TSF=0x%llx BCN=0x%llx diff=%lld "
1640 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->bssid),
1641 (unsigned long long)tsf,
1642 (unsigned long long)timestamp,
1643 (unsigned long long)(tsf - timestamp),
1645 last_tsf_debug = jiffies;
1647 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
1650 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
1652 if (sdata->type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
1653 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
1654 (sta = sta_info_get(local, mgmt->sa))) {
1655 struct ieee80211_hw_mode *mode;
1656 struct ieee80211_rate *rates;
1658 u32 supp_rates, prev_rates;
1661 mode = local->sta_sw_scanning ?
1662 local->scan_hw_mode : local->oper_hw_mode;
1664 if (local->sta_hw_scanning) {
1665 /* search for the correct mode matches the beacon */
1666 list_for_each_entry(mode, &local->modes_list, list)
1667 if (mode->mode == rx_status->phymode)
1671 mode = local->oper_hw_mode;
1673 rates = mode->rates;
1674 num_rates = mode->num_rates;
1677 for (i = 0; i < elems.supp_rates_len +
1678 elems.ext_supp_rates_len; i++) {
1681 if (i < elems.supp_rates_len)
1682 rate = elems.supp_rates[i];
1683 else if (elems.ext_supp_rates)
1684 rate = elems.ext_supp_rates
1685 [i - elems.supp_rates_len];
1686 own_rate = 5 * (rate & 0x7f);
1687 for (j = 0; j < num_rates; j++)
1688 if (rates[j].rate == own_rate)
1689 supp_rates |= BIT(j);
1692 prev_rates = sta->supp_rates;
1693 sta->supp_rates &= supp_rates;
1694 if (sta->supp_rates == 0) {
1695 /* No matching rates - this should not really happen.
1696 * Make sure that at least one rate is marked
1697 * supported to avoid issues with TX rate ctrl. */
1698 sta->supp_rates = sdata->u.sta.supp_rates_bits;
1700 if (sta->supp_rates != prev_rates) {
1701 printk(KERN_DEBUG "%s: updated supp_rates set for "
1702 "%s based on beacon info (0x%x & 0x%x -> "
1704 dev->name, print_mac(mac, sta->addr), prev_rates,
1705 supp_rates, sta->supp_rates);
1713 if (elems.ds_params && elems.ds_params_len == 1)
1714 channel = elems.ds_params[0];
1716 channel = rx_status->channel;
1718 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, channel,
1719 elems.ssid, elems.ssid_len);
1721 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, channel,
1722 elems.ssid, elems.ssid_len);
1727 /* TODO: order by RSSI? */
1728 spin_lock_bh(&local->sta_bss_lock);
1729 list_move_tail(&bss->list, &local->sta_bss_list);
1730 spin_unlock_bh(&local->sta_bss_lock);
1734 if (bss->probe_resp && beacon) {
1735 /* Do not allow beacon to override data from Probe Response. */
1736 ieee80211_rx_bss_put(dev, bss);
1740 /* save the ERP value so that it is available at association time */
1741 if (elems.erp_info && elems.erp_info_len >= 1) {
1742 bss->erp_value = elems.erp_info[0];
1743 bss->has_erp_value = 1;
1746 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
1747 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
1749 bss->supp_rates_len = 0;
1750 if (elems.supp_rates) {
1751 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
1752 if (clen > elems.supp_rates_len)
1753 clen = elems.supp_rates_len;
1754 memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
1756 bss->supp_rates_len += clen;
1758 if (elems.ext_supp_rates) {
1759 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
1760 if (clen > elems.ext_supp_rates_len)
1761 clen = elems.ext_supp_rates_len;
1762 memcpy(&bss->supp_rates[bss->supp_rates_len],
1763 elems.ext_supp_rates, clen);
1764 bss->supp_rates_len += clen;
1768 (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len ||
1769 memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
1771 bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
1773 memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
1774 bss->wpa_ie_len = elems.wpa_len + 2;
1776 bss->wpa_ie_len = 0;
1777 } else if (!elems.wpa && bss->wpa_ie) {
1780 bss->wpa_ie_len = 0;
1784 (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len ||
1785 memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
1787 bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
1789 memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
1790 bss->rsn_ie_len = elems.rsn_len + 2;
1792 bss->rsn_ie_len = 0;
1793 } else if (!elems.rsn && bss->rsn_ie) {
1796 bss->rsn_ie_len = 0;
1799 if (elems.wmm_param &&
1800 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len ||
1801 memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
1803 bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
1805 memcpy(bss->wmm_ie, elems.wmm_param - 2,
1806 elems.wmm_param_len + 2);
1807 bss->wmm_ie_len = elems.wmm_param_len + 2;
1809 bss->wmm_ie_len = 0;
1810 } else if (!elems.wmm_param && bss->wmm_ie) {
1813 bss->wmm_ie_len = 0;
1815 if (elems.ht_cap_elem &&
1816 (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
1817 memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
1819 bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
1821 memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
1822 elems.ht_cap_elem_len + 2);
1823 bss->ht_ie_len = elems.ht_cap_elem_len + 2;
1826 } else if (!elems.ht_cap_elem && bss->ht_ie) {
1832 bss->hw_mode = rx_status->phymode;
1833 bss->freq = rx_status->freq;
1834 if (channel != rx_status->channel &&
1835 (bss->hw_mode == MODE_IEEE80211G ||
1836 bss->hw_mode == MODE_IEEE80211B) &&
1837 channel >= 1 && channel <= 14) {
1838 static const int freq_list[] = {
1839 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1840 2447, 2452, 2457, 2462, 2467, 2472, 2484
1842 /* IEEE 802.11g/b mode can receive packets from neighboring
1843 * channels, so map the channel into frequency. */
1844 bss->freq = freq_list[channel - 1];
1846 bss->timestamp = timestamp;
1847 bss->last_update = jiffies;
1848 bss->rssi = rx_status->ssi;
1849 bss->signal = rx_status->signal;
1850 bss->noise = rx_status->noise;
1853 ieee80211_rx_bss_put(dev, bss);
1857 static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
1858 struct ieee80211_mgmt *mgmt,
1860 struct ieee80211_rx_status *rx_status)
1862 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
1866 static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
1867 struct ieee80211_mgmt *mgmt,
1869 struct ieee80211_rx_status *rx_status)
1871 struct ieee80211_sub_if_data *sdata;
1872 struct ieee80211_if_sta *ifsta;
1874 struct ieee802_11_elems elems;
1875 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1876 struct ieee80211_conf *conf = &local->hw.conf;
1878 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
1880 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1881 if (sdata->type != IEEE80211_IF_TYPE_STA)
1883 ifsta = &sdata->u.sta;
1885 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
1886 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
1889 /* Process beacon from the current BSS */
1890 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1894 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
1896 if (elems.erp_info && elems.erp_info_len >= 1)
1897 ieee80211_handle_erp_ie(dev, elems.erp_info[0]);
1899 if (elems.ht_cap_elem && elems.ht_info_elem &&
1900 elems.wmm_param && local->ops->conf_ht &&
1901 conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
1902 struct ieee80211_ht_bss_info bss_info;
1904 ieee80211_ht_addt_info_ie_to_ht_bss_info(
1905 (struct ieee80211_ht_addt_info *)
1906 elems.ht_info_elem, &bss_info);
1907 /* check if AP changed bss inforamation */
1908 if ((conf->ht_bss_conf.primary_channel !=
1909 bss_info.primary_channel) ||
1910 (conf->ht_bss_conf.bss_cap != bss_info.bss_cap) ||
1911 (conf->ht_bss_conf.bss_op_mode != bss_info.bss_op_mode))
1912 ieee80211_hw_config_ht(local, 1, &conf->ht_conf,
1916 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
1917 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
1918 elems.wmm_param_len);
1923 static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
1924 struct ieee80211_if_sta *ifsta,
1925 struct ieee80211_mgmt *mgmt,
1927 struct ieee80211_rx_status *rx_status)
1929 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1930 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1932 struct sk_buff *skb;
1933 struct ieee80211_mgmt *resp;
1935 DECLARE_MAC_BUF(mac);
1936 #ifdef CONFIG_MAC80211_IBSS_DEBUG
1937 DECLARE_MAC_BUF(mac2);
1938 DECLARE_MAC_BUF(mac3);
1941 if (sdata->type != IEEE80211_IF_TYPE_IBSS ||
1942 ifsta->state != IEEE80211_IBSS_JOINED ||
1943 len < 24 + 2 || !ifsta->probe_resp)
1946 if (local->ops->tx_last_beacon)
1947 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
1951 #ifdef CONFIG_MAC80211_IBSS_DEBUG
1952 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
1953 "%s (tx_last_beacon=%d)\n",
1954 dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
1955 print_mac(mac3, mgmt->bssid), tx_last_beacon);
1956 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
1958 if (!tx_last_beacon)
1961 if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
1962 memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
1965 end = ((u8 *) mgmt) + len;
1966 pos = mgmt->u.probe_req.variable;
1967 if (pos[0] != WLAN_EID_SSID ||
1968 pos + 2 + pos[1] > end) {
1969 if (net_ratelimit()) {
1970 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
1972 dev->name, print_mac(mac, mgmt->sa));
1977 (pos[1] != ifsta->ssid_len ||
1978 memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
1979 /* Ignore ProbeReq for foreign SSID */
1983 /* Reply with ProbeResp */
1984 skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
1988 resp = (struct ieee80211_mgmt *) skb->data;
1989 memcpy(resp->da, mgmt->sa, ETH_ALEN);
1990 #ifdef CONFIG_MAC80211_IBSS_DEBUG
1991 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
1992 dev->name, print_mac(mac, resp->da));
1993 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
1994 ieee80211_sta_tx(dev, skb, 0);
1997 static void ieee80211_rx_mgmt_action(struct net_device *dev,
1998 struct ieee80211_if_sta *ifsta,
1999 struct ieee80211_mgmt *mgmt,
2002 if (len < IEEE80211_MIN_ACTION_SIZE)
2005 switch (mgmt->u.action.category) {
2006 case WLAN_CATEGORY_BACK:
2007 switch (mgmt->u.action.u.addba_req.action_code) {
2008 case WLAN_ACTION_ADDBA_REQ:
2009 if (len < (IEEE80211_MIN_ACTION_SIZE +
2010 sizeof(mgmt->u.action.u.addba_req)))
2012 ieee80211_sta_process_addba_request(dev, mgmt, len);
2015 if (net_ratelimit())
2016 printk(KERN_DEBUG "%s: received unsupported BACK\n",
2026 void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
2027 struct ieee80211_rx_status *rx_status)
2029 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2030 struct ieee80211_sub_if_data *sdata;
2031 struct ieee80211_if_sta *ifsta;
2032 struct ieee80211_mgmt *mgmt;
2038 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2039 ifsta = &sdata->u.sta;
2041 mgmt = (struct ieee80211_mgmt *) skb->data;
2042 fc = le16_to_cpu(mgmt->frame_control);
2044 switch (fc & IEEE80211_FCTL_STYPE) {
2045 case IEEE80211_STYPE_PROBE_REQ:
2046 case IEEE80211_STYPE_PROBE_RESP:
2047 case IEEE80211_STYPE_BEACON:
2048 memcpy(skb->cb, rx_status, sizeof(*rx_status));
2049 case IEEE80211_STYPE_AUTH:
2050 case IEEE80211_STYPE_ASSOC_RESP:
2051 case IEEE80211_STYPE_REASSOC_RESP:
2052 case IEEE80211_STYPE_DEAUTH:
2053 case IEEE80211_STYPE_DISASSOC:
2054 case IEEE80211_STYPE_ACTION:
2055 skb_queue_tail(&ifsta->skb_queue, skb);
2056 queue_work(local->hw.workqueue, &ifsta->work);
2059 printk(KERN_DEBUG "%s: received unknown management frame - "
2060 "stype=%d\n", dev->name,
2061 (fc & IEEE80211_FCTL_STYPE) >> 4);
2070 static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
2071 struct sk_buff *skb)
2073 struct ieee80211_rx_status *rx_status;
2074 struct ieee80211_sub_if_data *sdata;
2075 struct ieee80211_if_sta *ifsta;
2076 struct ieee80211_mgmt *mgmt;
2079 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2080 ifsta = &sdata->u.sta;
2082 rx_status = (struct ieee80211_rx_status *) skb->cb;
2083 mgmt = (struct ieee80211_mgmt *) skb->data;
2084 fc = le16_to_cpu(mgmt->frame_control);
2086 switch (fc & IEEE80211_FCTL_STYPE) {
2087 case IEEE80211_STYPE_PROBE_REQ:
2088 ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
2091 case IEEE80211_STYPE_PROBE_RESP:
2092 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
2094 case IEEE80211_STYPE_BEACON:
2095 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
2097 case IEEE80211_STYPE_AUTH:
2098 ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len);
2100 case IEEE80211_STYPE_ASSOC_RESP:
2101 ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len, 0);
2103 case IEEE80211_STYPE_REASSOC_RESP:
2104 ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len, 1);
2106 case IEEE80211_STYPE_DEAUTH:
2107 ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len);
2109 case IEEE80211_STYPE_DISASSOC:
2110 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
2112 case IEEE80211_STYPE_ACTION:
2113 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len);
2121 ieee80211_txrx_result
2122 ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
2123 struct ieee80211_rx_status *rx_status)
2125 struct ieee80211_mgmt *mgmt;
2131 mgmt = (struct ieee80211_mgmt *) skb->data;
2132 fc = le16_to_cpu(mgmt->frame_control);
2134 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
2135 return TXRX_CONTINUE;
2140 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2141 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
2142 ieee80211_rx_mgmt_probe_resp(dev, mgmt,
2143 skb->len, rx_status);
2146 } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
2147 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
2153 return TXRX_CONTINUE;
2157 static int ieee80211_sta_active_ibss(struct net_device *dev)
2159 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2161 struct sta_info *sta;
2163 read_lock_bh(&local->sta_lock);
2164 list_for_each_entry(sta, &local->sta_list, list) {
2165 if (sta->dev == dev &&
2166 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
2172 read_unlock_bh(&local->sta_lock);
2178 static void ieee80211_sta_expire(struct net_device *dev)
2180 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2181 struct sta_info *sta, *tmp;
2182 LIST_HEAD(tmp_list);
2183 DECLARE_MAC_BUF(mac);
2185 write_lock_bh(&local->sta_lock);
2186 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
2187 if (time_after(jiffies, sta->last_rx +
2188 IEEE80211_IBSS_INACTIVITY_LIMIT)) {
2189 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
2190 dev->name, print_mac(mac, sta->addr));
2191 __sta_info_get(sta);
2192 sta_info_remove(sta);
2193 list_add(&sta->list, &tmp_list);
2195 write_unlock_bh(&local->sta_lock);
2197 list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
2204 static void ieee80211_sta_merge_ibss(struct net_device *dev,
2205 struct ieee80211_if_sta *ifsta)
2207 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2209 ieee80211_sta_expire(dev);
2210 if (ieee80211_sta_active_ibss(dev))
2213 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
2214 "IBSS networks with same SSID (merge)\n", dev->name);
2215 ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
2219 void ieee80211_sta_timer(unsigned long data)
2221 struct ieee80211_sub_if_data *sdata =
2222 (struct ieee80211_sub_if_data *) data;
2223 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2224 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
2226 set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
2227 queue_work(local->hw.workqueue, &ifsta->work);
2231 void ieee80211_sta_work(struct work_struct *work)
2233 struct ieee80211_sub_if_data *sdata =
2234 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
2235 struct net_device *dev = sdata->dev;
2236 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2237 struct ieee80211_if_sta *ifsta;
2238 struct sk_buff *skb;
2240 if (!netif_running(dev))
2243 if (local->sta_sw_scanning || local->sta_hw_scanning)
2246 if (sdata->type != IEEE80211_IF_TYPE_STA &&
2247 sdata->type != IEEE80211_IF_TYPE_IBSS) {
2248 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
2249 "(type=%d)\n", dev->name, sdata->type);
2252 ifsta = &sdata->u.sta;
2254 while ((skb = skb_dequeue(&ifsta->skb_queue)))
2255 ieee80211_sta_rx_queued_mgmt(dev, skb);
2257 if (ifsta->state != IEEE80211_AUTHENTICATE &&
2258 ifsta->state != IEEE80211_ASSOCIATE &&
2259 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
2260 if (ifsta->scan_ssid_len)
2261 ieee80211_sta_start_scan(dev, ifsta->scan_ssid, ifsta->scan_ssid_len);
2263 ieee80211_sta_start_scan(dev, NULL, 0);
2267 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
2268 if (ieee80211_sta_config_auth(dev, ifsta))
2270 clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
2271 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
2274 switch (ifsta->state) {
2275 case IEEE80211_DISABLED:
2277 case IEEE80211_AUTHENTICATE:
2278 ieee80211_authenticate(dev, ifsta);
2280 case IEEE80211_ASSOCIATE:
2281 ieee80211_associate(dev, ifsta);
2283 case IEEE80211_ASSOCIATED:
2284 ieee80211_associated(dev, ifsta);
2286 case IEEE80211_IBSS_SEARCH:
2287 ieee80211_sta_find_ibss(dev, ifsta);
2289 case IEEE80211_IBSS_JOINED:
2290 ieee80211_sta_merge_ibss(dev, ifsta);
2293 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
2298 if (ieee80211_privacy_mismatch(dev, ifsta)) {
2299 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
2300 "mixed-cell disabled - disassociate\n", dev->name);
2302 ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
2303 ieee80211_set_disassoc(dev, ifsta, 0);
2308 static void ieee80211_sta_reset_auth(struct net_device *dev,
2309 struct ieee80211_if_sta *ifsta)
2311 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2313 if (local->ops->reset_tsf) {
2314 /* Reset own TSF to allow time synchronization work. */
2315 local->ops->reset_tsf(local_to_hw(local));
2318 ifsta->wmm_last_param_set = -1; /* allow any WMM update */
2321 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
2322 ifsta->auth_alg = WLAN_AUTH_OPEN;
2323 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
2324 ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
2325 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
2326 ifsta->auth_alg = WLAN_AUTH_LEAP;
2328 ifsta->auth_alg = WLAN_AUTH_OPEN;
2329 printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
2331 ifsta->auth_transaction = -1;
2332 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
2333 ifsta->auth_tries = ifsta->assoc_tries = 0;
2334 netif_carrier_off(dev);
2338 void ieee80211_sta_req_auth(struct net_device *dev,
2339 struct ieee80211_if_sta *ifsta)
2341 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2342 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2344 if (sdata->type != IEEE80211_IF_TYPE_STA)
2347 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
2348 IEEE80211_STA_AUTO_BSSID_SEL)) &&
2349 (ifsta->flags & (IEEE80211_STA_SSID_SET |
2350 IEEE80211_STA_AUTO_SSID_SEL))) {
2351 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
2352 queue_work(local->hw.workqueue, &ifsta->work);
2356 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
2357 const char *ssid, int ssid_len)
2359 int tmp, hidden_ssid;
2361 if (ssid_len == ifsta->ssid_len &&
2362 !memcmp(ifsta->ssid, ssid, ssid_len))
2365 if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
2371 if (ssid[tmp] != '\0') {
2377 if (hidden_ssid && ifsta->ssid_len == ssid_len)
2380 if (ssid_len == 1 && ssid[0] == ' ')
2386 static int ieee80211_sta_config_auth(struct net_device *dev,
2387 struct ieee80211_if_sta *ifsta)
2389 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2390 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2391 struct ieee80211_sta_bss *bss, *selected = NULL;
2392 int top_rssi = 0, freq;
2394 if (!(ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
2395 IEEE80211_STA_AUTO_BSSID_SEL | IEEE80211_STA_AUTO_CHANNEL_SEL))) {
2396 ifsta->state = IEEE80211_AUTHENTICATE;
2397 ieee80211_sta_reset_auth(dev, ifsta);
2401 spin_lock_bh(&local->sta_bss_lock);
2402 freq = local->oper_channel->freq;
2403 list_for_each_entry(bss, &local->sta_bss_list, list) {
2404 if (!(bss->capability & WLAN_CAPABILITY_ESS))
2407 if (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
2408 !!sdata->default_key)
2411 if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
2415 if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
2416 memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
2419 if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
2420 !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
2423 if (!selected || top_rssi < bss->rssi) {
2425 top_rssi = bss->rssi;
2429 atomic_inc(&selected->users);
2430 spin_unlock_bh(&local->sta_bss_lock);
2433 ieee80211_set_channel(local, -1, selected->freq);
2434 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
2435 ieee80211_sta_set_ssid(dev, selected->ssid,
2436 selected->ssid_len);
2437 ieee80211_sta_set_bssid(dev, selected->bssid);
2438 ieee80211_rx_bss_put(dev, selected);
2439 ifsta->state = IEEE80211_AUTHENTICATE;
2440 ieee80211_sta_reset_auth(dev, ifsta);
2443 if (ifsta->state != IEEE80211_AUTHENTICATE) {
2444 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
2445 ieee80211_sta_start_scan(dev, NULL, 0);
2447 ieee80211_sta_start_scan(dev, ifsta->ssid,
2449 ifsta->state = IEEE80211_AUTHENTICATE;
2450 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
2452 ifsta->state = IEEE80211_DISABLED;
2457 static int ieee80211_sta_join_ibss(struct net_device *dev,
2458 struct ieee80211_if_sta *ifsta,
2459 struct ieee80211_sta_bss *bss)
2461 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2462 int res, rates, i, j;
2463 struct sk_buff *skb;
2464 struct ieee80211_mgmt *mgmt;
2465 struct ieee80211_tx_control control;
2466 struct ieee80211_hw_mode *mode;
2467 struct rate_selection ratesel;
2469 struct ieee80211_sub_if_data *sdata;
2471 /* Remove possible STA entries from other IBSS networks. */
2472 sta_info_flush(local, NULL);
2474 if (local->ops->reset_tsf) {
2475 /* Reset own TSF to allow time synchronization work. */
2476 local->ops->reset_tsf(local_to_hw(local));
2478 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2479 res = ieee80211_if_config(dev);
2483 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2485 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2486 sdata->drop_unencrypted = bss->capability &
2487 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2489 res = ieee80211_set_channel(local, -1, bss->freq);
2491 if (!(local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)) {
2492 printk(KERN_DEBUG "%s: IBSS not allowed on channel %d "
2493 "(%d MHz)\n", dev->name, local->hw.conf.channel,
2494 local->hw.conf.freq);
2498 /* Set beacon template based on scan results */
2499 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2504 skb_reserve(skb, local->hw.extra_tx_headroom);
2506 mgmt = (struct ieee80211_mgmt *)
2507 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2508 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2509 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2510 IEEE80211_STYPE_BEACON);
2511 memset(mgmt->da, 0xff, ETH_ALEN);
2512 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2513 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2514 mgmt->u.beacon.beacon_int =
2515 cpu_to_le16(local->hw.conf.beacon_int);
2516 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2518 pos = skb_put(skb, 2 + ifsta->ssid_len);
2519 *pos++ = WLAN_EID_SSID;
2520 *pos++ = ifsta->ssid_len;
2521 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2523 rates = bss->supp_rates_len;
2526 pos = skb_put(skb, 2 + rates);
2527 *pos++ = WLAN_EID_SUPP_RATES;
2529 memcpy(pos, bss->supp_rates, rates);
2531 pos = skb_put(skb, 2 + 1);
2532 *pos++ = WLAN_EID_DS_PARAMS;
2534 *pos++ = bss->channel;
2536 pos = skb_put(skb, 2 + 2);
2537 *pos++ = WLAN_EID_IBSS_PARAMS;
2539 /* FIX: set ATIM window based on scan results */
2543 if (bss->supp_rates_len > 8) {
2544 rates = bss->supp_rates_len - 8;
2545 pos = skb_put(skb, 2 + rates);
2546 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2548 memcpy(pos, &bss->supp_rates[8], rates);
2551 memset(&control, 0, sizeof(control));
2552 rate_control_get_rate(dev, local->oper_hw_mode, skb, &ratesel);
2553 if (!ratesel.rate) {
2554 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2555 "for IBSS beacon\n", dev->name);
2559 ((sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE) &&
2560 (ratesel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
2561 ratesel.rate->val2 : ratesel.rate->val;
2562 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2563 control.power_level = local->hw.conf.power_level;
2564 control.flags |= IEEE80211_TXCTL_NO_ACK;
2565 control.retry_limit = 1;
2567 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2568 if (ifsta->probe_resp) {
2569 mgmt = (struct ieee80211_mgmt *)
2570 ifsta->probe_resp->data;
2571 mgmt->frame_control =
2572 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2573 IEEE80211_STYPE_PROBE_RESP);
2575 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2576 "template for IBSS\n", dev->name);
2579 if (local->ops->beacon_update &&
2580 local->ops->beacon_update(local_to_hw(local),
2581 skb, &control) == 0) {
2582 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2583 "template based on scan results\n", dev->name);
2588 mode = local->oper_hw_mode;
2589 for (i = 0; i < bss->supp_rates_len; i++) {
2590 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2591 for (j = 0; j < mode->num_rates; j++)
2592 if (mode->rates[j].rate == bitrate)
2595 ifsta->supp_rates_bits = rates;
2599 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2600 "template\n", dev->name);
2604 ifsta->state = IEEE80211_IBSS_JOINED;
2605 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2607 ieee80211_rx_bss_put(dev, bss);
2613 static int ieee80211_sta_create_ibss(struct net_device *dev,
2614 struct ieee80211_if_sta *ifsta)
2616 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2617 struct ieee80211_sta_bss *bss;
2618 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2619 struct ieee80211_hw_mode *mode;
2620 u8 bssid[ETH_ALEN], *pos;
2622 DECLARE_MAC_BUF(mac);
2625 /* Easier testing, use fixed BSSID. */
2626 memset(bssid, 0xfe, ETH_ALEN);
2628 /* Generate random, not broadcast, locally administered BSSID. Mix in
2629 * own MAC address to make sure that devices that do not have proper
2630 * random number generator get different BSSID. */
2631 get_random_bytes(bssid, ETH_ALEN);
2632 for (i = 0; i < ETH_ALEN; i++)
2633 bssid[i] ^= dev->dev_addr[i];
2638 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
2639 dev->name, print_mac(mac, bssid));
2641 bss = ieee80211_rx_bss_add(dev, bssid, local->hw.conf.channel,
2642 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
2646 mode = local->oper_hw_mode;
2648 if (local->hw.conf.beacon_int == 0)
2649 local->hw.conf.beacon_int = 100;
2650 bss->beacon_int = local->hw.conf.beacon_int;
2651 bss->hw_mode = local->hw.conf.phymode;
2652 bss->freq = local->hw.conf.freq;
2653 bss->last_update = jiffies;
2654 bss->capability = WLAN_CAPABILITY_IBSS;
2655 if (sdata->default_key) {
2656 bss->capability |= WLAN_CAPABILITY_PRIVACY;
2658 sdata->drop_unencrypted = 0;
2659 bss->supp_rates_len = mode->num_rates;
2660 pos = bss->supp_rates;
2661 for (i = 0; i < mode->num_rates; i++) {
2662 int rate = mode->rates[i].rate;
2663 *pos++ = (u8) (rate / 5);
2666 return ieee80211_sta_join_ibss(dev, ifsta, bss);
2670 static int ieee80211_sta_find_ibss(struct net_device *dev,
2671 struct ieee80211_if_sta *ifsta)
2673 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2674 struct ieee80211_sta_bss *bss;
2678 DECLARE_MAC_BUF(mac);
2679 DECLARE_MAC_BUF(mac2);
2681 if (ifsta->ssid_len == 0)
2684 active_ibss = ieee80211_sta_active_ibss(dev);
2685 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2686 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
2687 dev->name, active_ibss);
2688 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2689 spin_lock_bh(&local->sta_bss_lock);
2690 list_for_each_entry(bss, &local->sta_bss_list, list) {
2691 if (ifsta->ssid_len != bss->ssid_len ||
2692 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
2693 || !(bss->capability & WLAN_CAPABILITY_IBSS))
2695 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2696 printk(KERN_DEBUG " bssid=%s found\n",
2697 print_mac(mac, bss->bssid));
2698 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2699 memcpy(bssid, bss->bssid, ETH_ALEN);
2701 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
2704 spin_unlock_bh(&local->sta_bss_lock);
2706 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2707 printk(KERN_DEBUG " sta_find_ibss: selected %s current "
2708 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
2709 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2710 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
2711 (bss = ieee80211_rx_bss_get(dev, bssid, local->hw.conf.channel,
2712 ifsta->ssid, ifsta->ssid_len))) {
2713 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
2714 " based on configured SSID\n",
2715 dev->name, print_mac(mac, bssid));
2716 return ieee80211_sta_join_ibss(dev, ifsta, bss);
2718 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2719 printk(KERN_DEBUG " did not try to join ibss\n");
2720 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2722 /* Selected IBSS not found in current scan results - try to scan */
2723 if (ifsta->state == IEEE80211_IBSS_JOINED &&
2724 !ieee80211_sta_active_ibss(dev)) {
2725 mod_timer(&ifsta->timer, jiffies +
2726 IEEE80211_IBSS_MERGE_INTERVAL);
2727 } else if (time_after(jiffies, local->last_scan_completed +
2728 IEEE80211_SCAN_INTERVAL)) {
2729 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
2730 "join\n", dev->name);
2731 return ieee80211_sta_req_scan(dev, ifsta->ssid,
2733 } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
2734 int interval = IEEE80211_SCAN_INTERVAL;
2736 if (time_after(jiffies, ifsta->ibss_join_req +
2737 IEEE80211_IBSS_JOIN_TIMEOUT)) {
2738 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
2739 local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)
2740 return ieee80211_sta_create_ibss(dev, ifsta);
2741 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
2742 printk(KERN_DEBUG "%s: IBSS not allowed on the"
2743 " configured channel %d (%d MHz)\n",
2744 dev->name, local->hw.conf.channel,
2745 local->hw.conf.freq);
2748 /* No IBSS found - decrease scan interval and continue
2750 interval = IEEE80211_SCAN_INTERVAL_SLOW;
2753 ifsta->state = IEEE80211_IBSS_SEARCH;
2754 mod_timer(&ifsta->timer, jiffies + interval);
2762 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
2764 struct ieee80211_sub_if_data *sdata;
2765 struct ieee80211_if_sta *ifsta;
2766 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2768 if (len > IEEE80211_MAX_SSID_LEN)
2771 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
2773 if (local->ops->conf_tx) {
2774 struct ieee80211_tx_queue_params qparam;
2777 memset(&qparam, 0, sizeof(qparam));
2778 /* TODO: are these ok defaults for all hw_modes? */
2781 local->hw.conf.phymode == MODE_IEEE80211B ? 31 : 15;
2782 qparam.cw_max = 1023;
2783 qparam.burst_time = 0;
2784 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
2786 local->ops->conf_tx(local_to_hw(local),
2787 i + IEEE80211_TX_QUEUE_DATA0,
2790 /* IBSS uses different parameters for Beacon sending */
2794 local->ops->conf_tx(local_to_hw(local),
2795 IEEE80211_TX_QUEUE_BEACON, &qparam);
2798 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2799 ifsta = &sdata->u.sta;
2801 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
2802 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
2803 memcpy(ifsta->ssid, ssid, len);
2804 memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
2805 ifsta->ssid_len = len;
2808 ifsta->flags |= IEEE80211_STA_SSID_SET;
2810 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
2811 if (sdata->type == IEEE80211_IF_TYPE_IBSS &&
2812 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
2813 ifsta->ibss_join_req = jiffies;
2814 ifsta->state = IEEE80211_IBSS_SEARCH;
2815 return ieee80211_sta_find_ibss(dev, ifsta);
2821 int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
2823 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2824 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2825 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
2826 *len = ifsta->ssid_len;
2831 int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
2833 struct ieee80211_sub_if_data *sdata;
2834 struct ieee80211_if_sta *ifsta;
2837 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2838 ifsta = &sdata->u.sta;
2840 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
2841 memcpy(ifsta->bssid, bssid, ETH_ALEN);
2842 res = ieee80211_if_config(dev);
2844 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
2845 "the low-level driver\n", dev->name);
2850 if (is_valid_ether_addr(bssid))
2851 ifsta->flags |= IEEE80211_STA_BSSID_SET;
2853 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
2859 static void ieee80211_send_nullfunc(struct ieee80211_local *local,
2860 struct ieee80211_sub_if_data *sdata,
2863 struct sk_buff *skb;
2864 struct ieee80211_hdr *nullfunc;
2867 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
2869 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
2870 "frame\n", sdata->dev->name);
2873 skb_reserve(skb, local->hw.extra_tx_headroom);
2875 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
2876 memset(nullfunc, 0, 24);
2877 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
2878 IEEE80211_FCTL_TODS;
2880 fc |= IEEE80211_FCTL_PM;
2881 nullfunc->frame_control = cpu_to_le16(fc);
2882 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
2883 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
2884 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
2886 ieee80211_sta_tx(sdata->dev, skb, 0);
2890 void ieee80211_scan_completed(struct ieee80211_hw *hw)
2892 struct ieee80211_local *local = hw_to_local(hw);
2893 struct net_device *dev = local->scan_dev;
2894 struct ieee80211_sub_if_data *sdata;
2895 union iwreq_data wrqu;
2897 local->last_scan_completed = jiffies;
2898 memset(&wrqu, 0, sizeof(wrqu));
2899 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
2901 if (local->sta_hw_scanning) {
2902 local->sta_hw_scanning = 0;
2906 local->sta_sw_scanning = 0;
2907 if (ieee80211_hw_config(local))
2908 printk(KERN_DEBUG "%s: failed to restore operational "
2909 "channel after scan\n", dev->name);
2912 netif_tx_lock_bh(local->mdev);
2913 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
2914 local->ops->configure_filter(local_to_hw(local),
2915 FIF_BCN_PRBRESP_PROMISC,
2916 &local->filter_flags,
2917 local->mdev->mc_count,
2918 local->mdev->mc_list);
2920 netif_tx_unlock_bh(local->mdev);
2923 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2925 /* No need to wake the master device. */
2926 if (sdata->dev == local->mdev)
2929 if (sdata->type == IEEE80211_IF_TYPE_STA) {
2930 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
2931 ieee80211_send_nullfunc(local, sdata, 0);
2932 ieee80211_sta_timer((unsigned long)sdata);
2935 netif_wake_queue(sdata->dev);
2940 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2941 if (sdata->type == IEEE80211_IF_TYPE_IBSS) {
2942 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2943 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
2944 (!ifsta->state == IEEE80211_IBSS_JOINED &&
2945 !ieee80211_sta_active_ibss(dev)))
2946 ieee80211_sta_find_ibss(dev, ifsta);
2949 EXPORT_SYMBOL(ieee80211_scan_completed);
2951 void ieee80211_sta_scan_work(struct work_struct *work)
2953 struct ieee80211_local *local =
2954 container_of(work, struct ieee80211_local, scan_work.work);
2955 struct net_device *dev = local->scan_dev;
2956 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2957 struct ieee80211_hw_mode *mode;
2958 struct ieee80211_channel *chan;
2960 unsigned long next_delay = 0;
2962 if (!local->sta_sw_scanning)
2965 switch (local->scan_state) {
2966 case SCAN_SET_CHANNEL:
2967 mode = local->scan_hw_mode;
2968 if (local->scan_hw_mode->list.next == &local->modes_list &&
2969 local->scan_channel_idx >= mode->num_channels) {
2970 ieee80211_scan_completed(local_to_hw(local));
2973 skip = !(local->enabled_modes & (1 << mode->mode));
2974 chan = &mode->channels[local->scan_channel_idx];
2975 if (!(chan->flag & IEEE80211_CHAN_W_SCAN) ||
2976 (sdata->type == IEEE80211_IF_TYPE_IBSS &&
2977 !(chan->flag & IEEE80211_CHAN_W_IBSS)) ||
2978 (local->hw_modes & local->enabled_modes &
2979 (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
2984 printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n",
2985 dev->name, chan->chan, chan->freq);
2988 local->scan_channel = chan;
2989 if (ieee80211_hw_config(local)) {
2990 printk(KERN_DEBUG "%s: failed to set channel "
2991 "%d (%d MHz) for scan\n", dev->name,
2992 chan->chan, chan->freq);
2997 local->scan_channel_idx++;
2998 if (local->scan_channel_idx >= local->scan_hw_mode->num_channels) {
2999 if (local->scan_hw_mode->list.next != &local->modes_list) {
3000 local->scan_hw_mode = list_entry(local->scan_hw_mode->list.next,
3001 struct ieee80211_hw_mode,
3003 local->scan_channel_idx = 0;
3010 next_delay = IEEE80211_PROBE_DELAY +
3011 usecs_to_jiffies(local->hw.channel_change_time);
3012 local->scan_state = SCAN_SEND_PROBE;
3014 case SCAN_SEND_PROBE:
3015 if (local->scan_channel->flag & IEEE80211_CHAN_W_ACTIVE_SCAN) {
3016 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3017 local->scan_ssid_len);
3018 next_delay = IEEE80211_CHANNEL_TIME;
3020 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3021 local->scan_state = SCAN_SET_CHANNEL;
3025 if (local->sta_sw_scanning)
3026 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3031 static int ieee80211_sta_start_scan(struct net_device *dev,
3032 u8 *ssid, size_t ssid_len)
3034 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3035 struct ieee80211_sub_if_data *sdata;
3037 if (ssid_len > IEEE80211_MAX_SSID_LEN)
3040 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3041 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3044 * ScanType: ACTIVE, PASSIVE
3045 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3046 * a Probe frame during active scanning
3048 * MinChannelTime (>= ProbeDelay), in TU
3049 * MaxChannelTime: (>= MinChannelTime), in TU
3052 /* MLME-SCAN.confirm
3054 * ResultCode: SUCCESS, INVALID_PARAMETERS
3057 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3058 if (local->scan_dev == dev)
3063 if (local->ops->hw_scan) {
3064 int rc = local->ops->hw_scan(local_to_hw(local),
3067 local->sta_hw_scanning = 1;
3068 local->scan_dev = dev;
3073 local->sta_sw_scanning = 1;
3076 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3078 /* Don't stop the master interface, otherwise we can't transmit
3080 if (sdata->dev == local->mdev)
3083 netif_stop_queue(sdata->dev);
3084 if (sdata->type == IEEE80211_IF_TYPE_STA &&
3085 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
3086 ieee80211_send_nullfunc(local, sdata, 1);
3091 local->scan_ssid_len = ssid_len;
3092 memcpy(local->scan_ssid, ssid, ssid_len);
3094 local->scan_ssid_len = 0;
3095 local->scan_state = SCAN_SET_CHANNEL;
3096 local->scan_hw_mode = list_entry(local->modes_list.next,
3097 struct ieee80211_hw_mode,
3099 local->scan_channel_idx = 0;
3100 local->scan_dev = dev;
3102 netif_tx_lock_bh(local->mdev);
3103 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
3104 local->ops->configure_filter(local_to_hw(local),
3105 FIF_BCN_PRBRESP_PROMISC,
3106 &local->filter_flags,
3107 local->mdev->mc_count,
3108 local->mdev->mc_list);
3109 netif_tx_unlock_bh(local->mdev);
3111 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3112 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3113 IEEE80211_CHANNEL_TIME);
3119 int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
3121 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3122 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3123 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3125 if (sdata->type != IEEE80211_IF_TYPE_STA)
3126 return ieee80211_sta_start_scan(dev, ssid, ssid_len);
3128 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3129 if (local->scan_dev == dev)
3134 ifsta->scan_ssid_len = ssid_len;
3136 memcpy(ifsta->scan_ssid, ssid, ssid_len);
3137 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
3138 queue_work(local->hw.workqueue, &ifsta->work);
3143 ieee80211_sta_scan_result(struct net_device *dev,
3144 struct ieee80211_sta_bss *bss,
3145 char *current_ev, char *end_buf)
3147 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3148 struct iw_event iwe;
3150 if (time_after(jiffies,
3151 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
3154 if (!(local->enabled_modes & (1 << bss->hw_mode)))
3157 memset(&iwe, 0, sizeof(iwe));
3158 iwe.cmd = SIOCGIWAP;
3159 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
3160 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
3161 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3164 memset(&iwe, 0, sizeof(iwe));
3165 iwe.cmd = SIOCGIWESSID;
3166 iwe.u.data.length = bss->ssid_len;
3167 iwe.u.data.flags = 1;
3168 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3171 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
3172 memset(&iwe, 0, sizeof(iwe));
3173 iwe.cmd = SIOCGIWMODE;
3174 if (bss->capability & WLAN_CAPABILITY_ESS)
3175 iwe.u.mode = IW_MODE_MASTER;
3177 iwe.u.mode = IW_MODE_ADHOC;
3178 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3182 memset(&iwe, 0, sizeof(iwe));
3183 iwe.cmd = SIOCGIWFREQ;
3184 iwe.u.freq.m = bss->channel;
3186 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3188 iwe.u.freq.m = bss->freq * 100000;
3190 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3193 memset(&iwe, 0, sizeof(iwe));
3195 iwe.u.qual.qual = bss->signal;
3196 iwe.u.qual.level = bss->rssi;
3197 iwe.u.qual.noise = bss->noise;
3198 iwe.u.qual.updated = local->wstats_flags;
3199 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3202 memset(&iwe, 0, sizeof(iwe));
3203 iwe.cmd = SIOCGIWENCODE;
3204 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
3205 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
3207 iwe.u.data.flags = IW_ENCODE_DISABLED;
3208 iwe.u.data.length = 0;
3209 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
3211 if (bss && bss->wpa_ie) {
3212 memset(&iwe, 0, sizeof(iwe));
3213 iwe.cmd = IWEVGENIE;
3214 iwe.u.data.length = bss->wpa_ie_len;
3215 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3219 if (bss && bss->rsn_ie) {
3220 memset(&iwe, 0, sizeof(iwe));
3221 iwe.cmd = IWEVGENIE;
3222 iwe.u.data.length = bss->rsn_ie_len;
3223 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3227 if (bss && bss->supp_rates_len > 0) {
3228 /* display all supported rates in readable format */
3229 char *p = current_ev + IW_EV_LCP_LEN;
3232 memset(&iwe, 0, sizeof(iwe));
3233 iwe.cmd = SIOCGIWRATE;
3234 /* Those two flags are ignored... */
3235 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
3237 for (i = 0; i < bss->supp_rates_len; i++) {
3238 iwe.u.bitrate.value = ((bss->supp_rates[i] &
3240 p = iwe_stream_add_value(current_ev, p,
3241 end_buf, &iwe, IW_EV_PARAM_LEN);
3248 buf = kmalloc(30, GFP_ATOMIC);
3250 memset(&iwe, 0, sizeof(iwe));
3251 iwe.cmd = IWEVCUSTOM;
3252 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
3253 iwe.u.data.length = strlen(buf);
3254 current_ev = iwe_stream_add_point(current_ev, end_buf,
3264 int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
3266 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3267 char *current_ev = buf;
3268 char *end_buf = buf + len;
3269 struct ieee80211_sta_bss *bss;
3271 spin_lock_bh(&local->sta_bss_lock);
3272 list_for_each_entry(bss, &local->sta_bss_list, list) {
3273 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
3274 spin_unlock_bh(&local->sta_bss_lock);
3277 current_ev = ieee80211_sta_scan_result(dev, bss, current_ev,
3280 spin_unlock_bh(&local->sta_bss_lock);
3281 return current_ev - buf;
3285 int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
3287 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3288 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3289 kfree(ifsta->extra_ie);
3291 ifsta->extra_ie = NULL;
3292 ifsta->extra_ie_len = 0;
3295 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
3296 if (!ifsta->extra_ie) {
3297 ifsta->extra_ie_len = 0;
3300 memcpy(ifsta->extra_ie, ie, len);
3301 ifsta->extra_ie_len = len;
3306 struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
3307 struct sk_buff *skb, u8 *bssid,
3310 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3311 struct sta_info *sta;
3312 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3313 DECLARE_MAC_BUF(mac);
3315 /* TODO: Could consider removing the least recently used entry and
3316 * allow new one to be added. */
3317 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
3318 if (net_ratelimit()) {
3319 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
3320 "entry %s\n", dev->name, print_mac(mac, addr));
3325 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
3326 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
3328 sta = sta_info_add(local, dev, addr, GFP_ATOMIC);
3332 sta->supp_rates = sdata->u.sta.supp_rates_bits;
3334 rate_control_rate_init(sta, local);
3336 return sta; /* caller will call sta_info_put() */
3340 int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
3342 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3343 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3345 printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
3348 if (sdata->type != IEEE80211_IF_TYPE_STA &&
3349 sdata->type != IEEE80211_IF_TYPE_IBSS)
3352 ieee80211_send_deauth(dev, ifsta, reason);
3353 ieee80211_set_disassoc(dev, ifsta, 1);
3358 int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
3360 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3361 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3363 printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
3366 if (sdata->type != IEEE80211_IF_TYPE_STA)
3369 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
3372 ieee80211_send_disassoc(dev, ifsta, reason);
3373 ieee80211_set_disassoc(dev, ifsta, 0);