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
66 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
67 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
69 /* next values represent the buffer size for A-MPDU frame.
70 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
71 #define IEEE80211_MIN_AMPDU_BUF 0x8
72 #define IEEE80211_MAX_AMPDU_BUF 0x40
74 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
75 u8 *ssid, size_t ssid_len);
76 static struct ieee80211_sta_bss *
77 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
78 u8 *ssid, u8 ssid_len);
79 static void ieee80211_rx_bss_put(struct net_device *dev,
80 struct ieee80211_sta_bss *bss);
81 static int ieee80211_sta_find_ibss(struct net_device *dev,
82 struct ieee80211_if_sta *ifsta);
83 static int ieee80211_sta_wep_configured(struct net_device *dev);
84 static int ieee80211_sta_start_scan(struct net_device *dev,
85 u8 *ssid, size_t ssid_len);
86 static int ieee80211_sta_config_auth(struct net_device *dev,
87 struct ieee80211_if_sta *ifsta);
90 /* Parsed Information Elements */
91 struct ieee802_11_elems {
109 /* length of them, respectively */
121 u8 ext_supp_rates_len;
128 static void ieee802_11_parse_elems(u8 *start, size_t len,
129 struct ieee802_11_elems *elems)
134 memset(elems, 0, sizeof(*elems));
149 elems->ssid_len = elen;
151 case WLAN_EID_SUPP_RATES:
152 elems->supp_rates = pos;
153 elems->supp_rates_len = elen;
155 case WLAN_EID_FH_PARAMS:
156 elems->fh_params = pos;
157 elems->fh_params_len = elen;
159 case WLAN_EID_DS_PARAMS:
160 elems->ds_params = pos;
161 elems->ds_params_len = elen;
163 case WLAN_EID_CF_PARAMS:
164 elems->cf_params = pos;
165 elems->cf_params_len = elen;
169 elems->tim_len = elen;
171 case WLAN_EID_IBSS_PARAMS:
172 elems->ibss_params = pos;
173 elems->ibss_params_len = elen;
175 case WLAN_EID_CHALLENGE:
176 elems->challenge = pos;
177 elems->challenge_len = elen;
180 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
182 /* Microsoft OUI (00:50:F2) */
184 /* OUI Type 1 - WPA IE */
186 elems->wpa_len = elen;
187 } else if (elen >= 5 && pos[3] == 2) {
189 elems->wmm_info = pos;
190 elems->wmm_info_len = elen;
191 } else if (pos[4] == 1) {
192 elems->wmm_param = pos;
193 elems->wmm_param_len = elen;
200 elems->rsn_len = elen;
202 case WLAN_EID_ERP_INFO:
203 elems->erp_info = pos;
204 elems->erp_info_len = elen;
206 case WLAN_EID_EXT_SUPP_RATES:
207 elems->ext_supp_rates = pos;
208 elems->ext_supp_rates_len = elen;
210 case WLAN_EID_HT_CAPABILITY:
211 elems->ht_cap_elem = pos;
212 elems->ht_cap_elem_len = elen;
214 case WLAN_EID_HT_EXTRA_INFO:
215 elems->ht_info_elem = pos;
216 elems->ht_info_elem_len = elen;
228 static int ecw2cw(int ecw)
238 static void ieee80211_sta_wmm_params(struct net_device *dev,
239 struct ieee80211_if_sta *ifsta,
240 u8 *wmm_param, size_t wmm_param_len)
242 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
243 struct ieee80211_tx_queue_params params;
248 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
250 count = wmm_param[6] & 0x0f;
251 if (count == ifsta->wmm_last_param_set)
253 ifsta->wmm_last_param_set = count;
256 left = wmm_param_len - 8;
258 memset(¶ms, 0, sizeof(params));
260 if (!local->ops->conf_tx)
264 for (; left >= 4; left -= 4, pos += 4) {
265 int aci = (pos[0] >> 5) & 0x03;
266 int acm = (pos[0] >> 4) & 0x01;
271 queue = IEEE80211_TX_QUEUE_DATA3;
273 local->wmm_acm |= BIT(0) | BIT(3);
277 queue = IEEE80211_TX_QUEUE_DATA1;
279 local->wmm_acm |= BIT(4) | BIT(5);
283 queue = IEEE80211_TX_QUEUE_DATA0;
285 local->wmm_acm |= BIT(6) | BIT(7);
290 queue = IEEE80211_TX_QUEUE_DATA2;
292 local->wmm_acm |= BIT(1) | BIT(2);
297 params.aifs = pos[0] & 0x0f;
298 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
299 params.cw_min = ecw2cw(pos[1] & 0x0f);
300 /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
301 params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100;
302 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
303 "cWmin=%d cWmax=%d burst=%d\n",
304 dev->name, queue, aci, acm, params.aifs, params.cw_min,
305 params.cw_max, params.burst_time);
306 /* TODO: handle ACM (block TX, fallback to next lowest allowed
308 if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) {
309 printk(KERN_DEBUG "%s: failed to set TX queue "
310 "parameters for queue %d\n", dev->name, queue);
316 static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata,
319 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
320 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
321 bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
322 bool preamble_mode = (erp_value & WLAN_ERP_BARKER_PREAMBLE) != 0;
323 DECLARE_MAC_BUF(mac);
326 if (use_protection != bss_conf->use_cts_prot) {
327 if (net_ratelimit()) {
328 printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
331 use_protection ? "enabled" : "disabled",
332 print_mac(mac, ifsta->bssid));
334 bss_conf->use_cts_prot = use_protection;
335 changed |= BSS_CHANGED_ERP_CTS_PROT;
338 if (preamble_mode != bss_conf->use_short_preamble) {
339 if (net_ratelimit()) {
340 printk(KERN_DEBUG "%s: switched to %s barker preamble"
343 (preamble_mode == WLAN_ERP_PREAMBLE_SHORT) ?
345 print_mac(mac, ifsta->bssid));
347 bss_conf->use_short_preamble = preamble_mode;
348 changed |= BSS_CHANGED_ERP_PREAMBLE;
354 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
355 struct ieee80211_ht_info *ht_info)
361 memset(ht_info, 0, sizeof(*ht_info));
364 u8 ampdu_info = ht_cap_ie->ampdu_params_info;
366 ht_info->ht_supported = 1;
367 ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info);
368 ht_info->ampdu_factor =
369 ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR;
370 ht_info->ampdu_density =
371 (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
372 memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16);
374 ht_info->ht_supported = 0;
379 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
380 struct ieee80211_ht_addt_info *ht_add_info_ie,
381 struct ieee80211_ht_bss_info *bss_info)
383 if (bss_info == NULL)
386 memset(bss_info, 0, sizeof(*bss_info));
388 if (ht_add_info_ie) {
390 op_mode = le16_to_cpu(ht_add_info_ie->operation_mode);
392 bss_info->primary_channel = ht_add_info_ie->control_chan;
393 bss_info->bss_cap = ht_add_info_ie->ht_param;
394 bss_info->bss_op_mode = (u8)(op_mode & 0xff);
400 static void ieee80211_sta_send_associnfo(struct net_device *dev,
401 struct ieee80211_if_sta *ifsta)
406 union iwreq_data wrqu;
408 if (!ifsta->assocreq_ies && !ifsta->assocresp_ies)
411 buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
412 ifsta->assocresp_ies_len), GFP_KERNEL);
416 len = sprintf(buf, "ASSOCINFO(");
417 if (ifsta->assocreq_ies) {
418 len += sprintf(buf + len, "ReqIEs=");
419 for (i = 0; i < ifsta->assocreq_ies_len; i++) {
420 len += sprintf(buf + len, "%02x",
421 ifsta->assocreq_ies[i]);
424 if (ifsta->assocresp_ies) {
425 if (ifsta->assocreq_ies)
426 len += sprintf(buf + len, " ");
427 len += sprintf(buf + len, "RespIEs=");
428 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
429 len += sprintf(buf + len, "%02x",
430 ifsta->assocresp_ies[i]);
433 len += sprintf(buf + len, ")");
435 if (len > IW_CUSTOM_MAX) {
436 len = sprintf(buf, "ASSOCRESPIE=");
437 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
438 len += sprintf(buf + len, "%02x",
439 ifsta->assocresp_ies[i]);
443 memset(&wrqu, 0, sizeof(wrqu));
444 wrqu.data.length = len;
445 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
451 static void ieee80211_set_associated(struct net_device *dev,
452 struct ieee80211_if_sta *ifsta,
455 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
456 struct ieee80211_local *local = sdata->local;
457 union iwreq_data wrqu;
458 u32 changed = BSS_CHANGED_ASSOC;
461 struct ieee80211_sta_bss *bss;
463 ifsta->flags |= IEEE80211_STA_ASSOCIATED;
465 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
468 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
469 local->hw.conf.channel,
470 ifsta->ssid, ifsta->ssid_len);
472 if (bss->has_erp_value)
473 changed |= ieee80211_handle_erp_ie(
474 sdata, bss->erp_value);
475 ieee80211_rx_bss_put(dev, bss);
478 netif_carrier_on(dev);
479 ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
480 memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
481 memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
482 ieee80211_sta_send_associnfo(dev, ifsta);
484 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
486 netif_carrier_off(dev);
487 ieee80211_reset_erp_info(dev);
488 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
490 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
491 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
492 ifsta->last_probe = jiffies;
493 ieee80211_led_assoc(local, assoc);
495 ieee80211_bss_info_change_notify(sdata, changed);
498 static void ieee80211_set_disassoc(struct net_device *dev,
499 struct ieee80211_if_sta *ifsta, int deauth)
502 ifsta->auth_tries = 0;
503 ifsta->assoc_tries = 0;
504 ieee80211_set_associated(dev, ifsta, 0);
507 static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
510 struct ieee80211_sub_if_data *sdata;
511 struct ieee80211_tx_packet_data *pkt_data;
513 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
514 skb->dev = sdata->local->mdev;
515 skb_set_mac_header(skb, 0);
516 skb_set_network_header(skb, 0);
517 skb_set_transport_header(skb, 0);
519 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
520 memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
521 pkt_data->ifindex = sdata->dev->ifindex;
523 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
529 static void ieee80211_send_auth(struct net_device *dev,
530 struct ieee80211_if_sta *ifsta,
531 int transaction, u8 *extra, size_t extra_len,
534 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
536 struct ieee80211_mgmt *mgmt;
538 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
539 sizeof(*mgmt) + 6 + extra_len);
541 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
542 "frame\n", dev->name);
545 skb_reserve(skb, local->hw.extra_tx_headroom);
547 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
548 memset(mgmt, 0, 24 + 6);
549 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
550 IEEE80211_STYPE_AUTH);
552 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
553 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
554 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
555 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
556 mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
557 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
558 ifsta->auth_transaction = transaction + 1;
559 mgmt->u.auth.status_code = cpu_to_le16(0);
561 memcpy(skb_put(skb, extra_len), extra, extra_len);
563 ieee80211_sta_tx(dev, skb, encrypt);
567 static void ieee80211_authenticate(struct net_device *dev,
568 struct ieee80211_if_sta *ifsta)
570 DECLARE_MAC_BUF(mac);
573 if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
574 printk(KERN_DEBUG "%s: authentication with AP %s"
576 dev->name, print_mac(mac, ifsta->bssid));
577 ifsta->state = IEEE80211_DISABLED;
581 ifsta->state = IEEE80211_AUTHENTICATE;
582 printk(KERN_DEBUG "%s: authenticate with AP %s\n",
583 dev->name, print_mac(mac, ifsta->bssid));
585 ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
587 mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
591 static void ieee80211_send_assoc(struct net_device *dev,
592 struct ieee80211_if_sta *ifsta)
594 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
595 struct ieee80211_hw_mode *mode;
597 struct ieee80211_mgmt *mgmt;
601 struct ieee80211_sta_bss *bss;
604 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
605 sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
608 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
609 "frame\n", dev->name);
612 skb_reserve(skb, local->hw.extra_tx_headroom);
614 mode = local->oper_hw_mode;
615 capab = ifsta->capab;
616 if (mode->mode == MODE_IEEE80211G) {
617 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
618 WLAN_CAPABILITY_SHORT_PREAMBLE;
620 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel,
621 ifsta->ssid, ifsta->ssid_len);
623 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
624 capab |= WLAN_CAPABILITY_PRIVACY;
628 ieee80211_rx_bss_put(dev, bss);
631 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
633 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
634 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
635 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
637 if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
639 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
640 IEEE80211_STYPE_REASSOC_REQ);
641 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
642 mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1);
643 memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
647 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
648 IEEE80211_STYPE_ASSOC_REQ);
649 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
650 mgmt->u.assoc_req.listen_interval = cpu_to_le16(1);
654 ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
655 *pos++ = WLAN_EID_SSID;
656 *pos++ = ifsta->ssid_len;
657 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
659 len = mode->num_rates;
662 pos = skb_put(skb, len + 2);
663 *pos++ = WLAN_EID_SUPP_RATES;
665 for (i = 0; i < len; i++) {
666 int rate = mode->rates[i].rate;
667 *pos++ = (u8) (rate / 5);
670 if (mode->num_rates > len) {
671 pos = skb_put(skb, mode->num_rates - len + 2);
672 *pos++ = WLAN_EID_EXT_SUPP_RATES;
673 *pos++ = mode->num_rates - len;
674 for (i = len; i < mode->num_rates; i++) {
675 int rate = mode->rates[i].rate;
676 *pos++ = (u8) (rate / 5);
680 if (ifsta->extra_ie) {
681 pos = skb_put(skb, ifsta->extra_ie_len);
682 memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
685 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
686 pos = skb_put(skb, 9);
687 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
688 *pos++ = 7; /* len */
689 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
692 *pos++ = 2; /* WME */
693 *pos++ = 0; /* WME info */
694 *pos++ = 1; /* WME ver */
697 /* wmm support is a must to HT */
698 if (wmm && mode->ht_info.ht_supported) {
699 __le16 tmp = cpu_to_le16(mode->ht_info.cap);
700 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
701 *pos++ = WLAN_EID_HT_CAPABILITY;
702 *pos++ = sizeof(struct ieee80211_ht_cap);
703 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
704 memcpy(pos, &tmp, sizeof(u16));
706 *pos++ = (mode->ht_info.ampdu_factor |
707 (mode->ht_info.ampdu_density << 2));
708 memcpy(pos, mode->ht_info.supp_mcs_set, 16);
711 kfree(ifsta->assocreq_ies);
712 ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
713 ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
714 if (ifsta->assocreq_ies)
715 memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
717 ieee80211_sta_tx(dev, skb, 0);
721 static void ieee80211_send_deauth(struct net_device *dev,
722 struct ieee80211_if_sta *ifsta, u16 reason)
724 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
726 struct ieee80211_mgmt *mgmt;
728 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
730 printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
731 "frame\n", dev->name);
734 skb_reserve(skb, local->hw.extra_tx_headroom);
736 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
738 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
739 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
740 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
741 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
742 IEEE80211_STYPE_DEAUTH);
744 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
746 ieee80211_sta_tx(dev, skb, 0);
750 static void ieee80211_send_disassoc(struct net_device *dev,
751 struct ieee80211_if_sta *ifsta, u16 reason)
753 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
755 struct ieee80211_mgmt *mgmt;
757 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
759 printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
760 "frame\n", dev->name);
763 skb_reserve(skb, local->hw.extra_tx_headroom);
765 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
767 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
768 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
769 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
770 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
771 IEEE80211_STYPE_DISASSOC);
773 mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
775 ieee80211_sta_tx(dev, skb, 0);
779 static int ieee80211_privacy_mismatch(struct net_device *dev,
780 struct ieee80211_if_sta *ifsta)
782 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
783 struct ieee80211_sta_bss *bss;
788 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
791 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel,
792 ifsta->ssid, ifsta->ssid_len);
796 bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
797 wep_privacy = !!ieee80211_sta_wep_configured(dev);
798 privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
800 ieee80211_rx_bss_put(dev, bss);
802 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
809 static void ieee80211_associate(struct net_device *dev,
810 struct ieee80211_if_sta *ifsta)
812 DECLARE_MAC_BUF(mac);
814 ifsta->assoc_tries++;
815 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
816 printk(KERN_DEBUG "%s: association with AP %s"
818 dev->name, print_mac(mac, ifsta->bssid));
819 ifsta->state = IEEE80211_DISABLED;
823 ifsta->state = IEEE80211_ASSOCIATE;
824 printk(KERN_DEBUG "%s: associate with AP %s\n",
825 dev->name, print_mac(mac, ifsta->bssid));
826 if (ieee80211_privacy_mismatch(dev, ifsta)) {
827 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
828 "mixed-cell disabled - abort association\n", dev->name);
829 ifsta->state = IEEE80211_DISABLED;
833 ieee80211_send_assoc(dev, ifsta);
835 mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
839 static void ieee80211_associated(struct net_device *dev,
840 struct ieee80211_if_sta *ifsta)
842 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
843 struct sta_info *sta;
845 DECLARE_MAC_BUF(mac);
847 /* TODO: start monitoring current AP signal quality and number of
848 * missed beacons. Scan other channels every now and then and search
850 /* TODO: remove expired BSSes */
852 ifsta->state = IEEE80211_ASSOCIATED;
854 sta = sta_info_get(local, ifsta->bssid);
856 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
857 dev->name, print_mac(mac, ifsta->bssid));
861 if (time_after(jiffies,
862 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
863 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
864 printk(KERN_DEBUG "%s: No ProbeResp from "
865 "current AP %s - assume out of "
867 dev->name, print_mac(mac, ifsta->bssid));
871 ieee80211_send_probe_req(dev, ifsta->bssid,
873 local->scan_ssid_len);
874 ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
876 ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
877 if (time_after(jiffies, ifsta->last_probe +
878 IEEE80211_PROBE_INTERVAL)) {
879 ifsta->last_probe = jiffies;
880 ieee80211_send_probe_req(dev, ifsta->bssid,
888 ifsta->state = IEEE80211_DISABLED;
889 ieee80211_set_associated(dev, ifsta, 0);
891 mod_timer(&ifsta->timer, jiffies +
892 IEEE80211_MONITORING_INTERVAL);
897 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
898 u8 *ssid, size_t ssid_len)
900 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
901 struct ieee80211_hw_mode *mode;
903 struct ieee80211_mgmt *mgmt;
904 u8 *pos, *supp_rates, *esupp_rates = NULL;
907 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
909 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
910 "request\n", dev->name);
913 skb_reserve(skb, local->hw.extra_tx_headroom);
915 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
917 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
918 IEEE80211_STYPE_PROBE_REQ);
919 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
921 memcpy(mgmt->da, dst, ETH_ALEN);
922 memcpy(mgmt->bssid, dst, ETH_ALEN);
924 memset(mgmt->da, 0xff, ETH_ALEN);
925 memset(mgmt->bssid, 0xff, ETH_ALEN);
927 pos = skb_put(skb, 2 + ssid_len);
928 *pos++ = WLAN_EID_SSID;
930 memcpy(pos, ssid, ssid_len);
932 supp_rates = skb_put(skb, 2);
933 supp_rates[0] = WLAN_EID_SUPP_RATES;
935 mode = local->oper_hw_mode;
936 for (i = 0; i < mode->num_rates; i++) {
937 struct ieee80211_rate *rate = &mode->rates[i];
938 if (!(rate->flags & IEEE80211_RATE_SUPPORTED))
941 pos = skb_put(skb, 1);
943 } else if (supp_rates[1] == 8) {
944 esupp_rates = skb_put(skb, 3);
945 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
947 pos = &esupp_rates[2];
949 pos = skb_put(skb, 1);
952 *pos = rate->rate / 5;
955 ieee80211_sta_tx(dev, skb, 0);
959 static int ieee80211_sta_wep_configured(struct net_device *dev)
961 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
962 if (!sdata || !sdata->default_key ||
963 sdata->default_key->conf.alg != ALG_WEP)
969 static void ieee80211_auth_completed(struct net_device *dev,
970 struct ieee80211_if_sta *ifsta)
972 printk(KERN_DEBUG "%s: authenticated\n", dev->name);
973 ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
974 ieee80211_associate(dev, ifsta);
978 static void ieee80211_auth_challenge(struct net_device *dev,
979 struct ieee80211_if_sta *ifsta,
980 struct ieee80211_mgmt *mgmt,
984 struct ieee802_11_elems elems;
986 printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
987 pos = mgmt->u.auth.variable;
988 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
989 if (!elems.challenge) {
990 printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
991 "frame\n", dev->name);
994 ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
995 elems.challenge_len + 2, 1);
998 static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
999 u8 dialog_token, u16 status, u16 policy,
1000 u16 buf_size, u16 timeout)
1002 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1003 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1004 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1005 struct sk_buff *skb;
1006 struct ieee80211_mgmt *mgmt;
1009 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1010 sizeof(mgmt->u.action.u.addba_resp));
1012 printk(KERN_DEBUG "%s: failed to allocate buffer "
1013 "for addba resp frame\n", dev->name);
1017 skb_reserve(skb, local->hw.extra_tx_headroom);
1018 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1019 memset(mgmt, 0, 24);
1020 memcpy(mgmt->da, da, ETH_ALEN);
1021 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1022 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1023 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1025 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1026 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1027 IEEE80211_STYPE_ACTION);
1029 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
1030 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1031 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
1032 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
1034 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
1035 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1036 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
1038 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
1039 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
1040 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
1042 ieee80211_sta_tx(dev, skb, 0);
1047 static void ieee80211_sta_process_addba_request(struct net_device *dev,
1048 struct ieee80211_mgmt *mgmt,
1051 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1052 struct ieee80211_hw *hw = &local->hw;
1053 struct ieee80211_conf *conf = &hw->conf;
1054 struct sta_info *sta;
1055 struct tid_ampdu_rx *tid_agg_rx;
1056 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
1058 int ret = -EOPNOTSUPP;
1059 DECLARE_MAC_BUF(mac);
1061 sta = sta_info_get(local, mgmt->sa);
1065 /* extract session parameters from addba request frame */
1066 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
1067 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
1069 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
1071 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1072 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
1073 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1074 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
1076 status = WLAN_STATUS_REQUEST_DECLINED;
1078 /* sanity check for incoming parameters:
1079 * check if configuration can support the BA policy
1080 * and if buffer size does not exceeds max value */
1081 if (((ba_policy != 1)
1082 && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
1083 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
1084 status = WLAN_STATUS_INVALID_QOS_PARAM;
1085 #ifdef CONFIG_MAC80211_HT_DEBUG
1086 if (net_ratelimit())
1087 printk(KERN_DEBUG "Block Ack Req with bad params from "
1088 "%s on tid %u. policy %d, buffer size %d\n",
1089 print_mac(mac, mgmt->sa), tid, ba_policy,
1091 #endif /* CONFIG_MAC80211_HT_DEBUG */
1094 /* determine default buffer size */
1095 if (buf_size == 0) {
1096 struct ieee80211_hw_mode *mode = conf->mode;
1097 buf_size = IEEE80211_MIN_AMPDU_BUF;
1098 buf_size = buf_size << mode->ht_info.ampdu_factor;
1101 tid_agg_rx = &sta->ampdu_mlme.tid_rx[tid];
1103 /* examine state machine */
1104 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1106 if (tid_agg_rx->state != HT_AGG_STATE_IDLE) {
1107 #ifdef CONFIG_MAC80211_HT_DEBUG
1108 if (net_ratelimit())
1109 printk(KERN_DEBUG "unexpected Block Ack Req from "
1111 print_mac(mac, mgmt->sa), tid);
1112 #endif /* CONFIG_MAC80211_HT_DEBUG */
1116 /* prepare reordering buffer */
1117 tid_agg_rx->reorder_buf =
1118 kmalloc(buf_size * sizeof(struct sk_buf *), GFP_ATOMIC);
1119 if ((!tid_agg_rx->reorder_buf) && net_ratelimit()) {
1120 printk(KERN_ERR "can not allocate reordering buffer "
1121 "to tid %d\n", tid);
1124 memset(tid_agg_rx->reorder_buf, 0,
1125 buf_size * sizeof(struct sk_buf *));
1127 if (local->ops->ampdu_action)
1128 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
1129 sta->addr, tid, start_seq_num);
1130 #ifdef CONFIG_MAC80211_HT_DEBUG
1131 printk(KERN_DEBUG "Rx A-MPDU on tid %d result %d", tid, ret);
1132 #endif /* CONFIG_MAC80211_HT_DEBUG */
1135 kfree(tid_agg_rx->reorder_buf);
1139 /* change state and send addba resp */
1140 tid_agg_rx->state = HT_AGG_STATE_OPERATIONAL;
1141 tid_agg_rx->dialog_token = dialog_token;
1142 tid_agg_rx->ssn = start_seq_num;
1143 tid_agg_rx->head_seq_num = start_seq_num;
1144 tid_agg_rx->buf_size = buf_size;
1145 tid_agg_rx->timeout = timeout;
1146 tid_agg_rx->stored_mpdu_num = 0;
1147 status = WLAN_STATUS_SUCCESS;
1149 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1152 ieee80211_send_addba_resp(sta->dev, sta->addr, tid, dialog_token,
1153 status, 1, buf_size, timeout);
1157 void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
1158 u16 initiator, u16 reason_code)
1160 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1161 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1162 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1163 struct sk_buff *skb;
1164 struct ieee80211_mgmt *mgmt;
1167 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1168 sizeof(mgmt->u.action.u.delba));
1171 printk(KERN_ERR "%s: failed to allocate buffer "
1172 "for delba frame\n", dev->name);
1176 skb_reserve(skb, local->hw.extra_tx_headroom);
1177 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1178 memset(mgmt, 0, 24);
1179 memcpy(mgmt->da, da, ETH_ALEN);
1180 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1181 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1182 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1184 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1185 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1186 IEEE80211_STYPE_ACTION);
1188 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
1190 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1191 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1192 params = (u16)(initiator << 11); /* bit 11 initiator */
1193 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1195 mgmt->u.action.u.delba.params = cpu_to_le16(params);
1196 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1198 ieee80211_sta_tx(dev, skb, 0);
1201 void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1202 u16 initiator, u16 reason)
1204 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1205 struct ieee80211_hw *hw = &local->hw;
1206 struct sta_info *sta;
1209 sta = sta_info_get(local, ra);
1213 /* check if TID is in operational state */
1214 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1215 if (sta->ampdu_mlme.tid_rx[tid].state
1216 != HT_AGG_STATE_OPERATIONAL) {
1217 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1218 if (net_ratelimit())
1219 printk(KERN_DEBUG "rx BA session requested to stop on "
1220 "inactive tid %d\n", tid);
1224 sta->ampdu_mlme.tid_rx[tid].state =
1225 HT_AGG_STATE_REQ_STOP_BA_MSK |
1226 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
1227 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1229 /* stop HW Rx aggregation. ampdu_action existence
1230 * already verified in session init so we add the BUG_ON */
1231 BUG_ON(!local->ops->ampdu_action);
1233 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
1236 printk(KERN_DEBUG "HW problem - can not stop rx "
1237 "aggergation for tid %d\n", tid);
1239 /* shutdown timer has not expired */
1240 if (initiator != WLAN_BACK_TIMER)
1241 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid].
1244 /* check if this is a self generated aggregation halt */
1245 if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
1246 ieee80211_send_delba(dev, ra, tid, 0, reason);
1248 /* free the reordering buffer */
1249 for (i = 0; i < sta->ampdu_mlme.tid_rx[tid].buf_size; i++) {
1250 if (sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]) {
1251 /* release the reordered frames */
1252 dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]);
1253 sta->ampdu_mlme.tid_rx[tid].stored_mpdu_num--;
1254 sta->ampdu_mlme.tid_rx[tid].reorder_buf[i] = NULL;
1257 kfree(sta->ampdu_mlme.tid_rx[tid].reorder_buf);
1259 sta->ampdu_mlme.tid_rx[tid].state = HT_AGG_STATE_IDLE;
1263 static void ieee80211_sta_process_delba(struct net_device *dev,
1264 struct ieee80211_mgmt *mgmt, size_t len)
1266 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1267 struct sta_info *sta;
1270 DECLARE_MAC_BUF(mac);
1272 sta = sta_info_get(local, mgmt->sa);
1276 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1277 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1278 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1280 #ifdef CONFIG_MAC80211_HT_DEBUG
1281 if (net_ratelimit())
1282 printk(KERN_DEBUG "delba from %s on tid %d reason code %d\n",
1283 print_mac(mac, mgmt->sa), tid,
1284 mgmt->u.action.u.delba.reason_code);
1285 #endif /* CONFIG_MAC80211_HT_DEBUG */
1287 if (initiator == WLAN_BACK_INITIATOR)
1288 ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
1289 WLAN_BACK_INITIATOR, 0);
1294 * After receiving Block Ack Request (BAR) we activated a
1295 * timer after each frame arrives from the originator.
1296 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1298 void sta_rx_agg_session_timer_expired(unsigned long data)
1300 /* not an elegant detour, but there is no choice as the timer passes
1301 * only one argument, and verious sta_info are needed here, so init
1302 * flow in sta_info_add gives the TID as data, while the timer_to_id
1303 * array gives the sta through container_of */
1304 u8 *ptid = (u8 *)data;
1305 u8 *timer_to_id = ptid - *ptid;
1306 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
1309 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
1310 ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr, (u16)*ptid,
1312 WLAN_REASON_QSTA_TIMEOUT);
1316 static void ieee80211_rx_mgmt_auth(struct net_device *dev,
1317 struct ieee80211_if_sta *ifsta,
1318 struct ieee80211_mgmt *mgmt,
1321 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1322 u16 auth_alg, auth_transaction, status_code;
1323 DECLARE_MAC_BUF(mac);
1325 if (ifsta->state != IEEE80211_AUTHENTICATE &&
1326 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
1327 printk(KERN_DEBUG "%s: authentication frame received from "
1328 "%s, but not in authenticate state - ignored\n",
1329 dev->name, print_mac(mac, mgmt->sa));
1334 printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
1335 "received from %s - ignored\n",
1336 dev->name, len, print_mac(mac, mgmt->sa));
1340 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
1341 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1342 printk(KERN_DEBUG "%s: authentication frame received from "
1343 "unknown AP (SA=%s BSSID=%s) - "
1344 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1345 print_mac(mac, mgmt->bssid));
1349 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
1350 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
1351 printk(KERN_DEBUG "%s: authentication frame received from "
1352 "unknown BSSID (SA=%s BSSID=%s) - "
1353 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1354 print_mac(mac, mgmt->bssid));
1358 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1359 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1360 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1362 printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d "
1363 "transaction=%d status=%d)\n",
1364 dev->name, print_mac(mac, mgmt->sa), auth_alg,
1365 auth_transaction, status_code);
1367 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
1368 /* IEEE 802.11 standard does not require authentication in IBSS
1369 * networks and most implementations do not seem to use it.
1370 * However, try to reply to authentication attempts if someone
1371 * has actually implemented this.
1372 * TODO: Could implement shared key authentication. */
1373 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
1374 printk(KERN_DEBUG "%s: unexpected IBSS authentication "
1375 "frame (alg=%d transaction=%d)\n",
1376 dev->name, auth_alg, auth_transaction);
1379 ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
1382 if (auth_alg != ifsta->auth_alg ||
1383 auth_transaction != ifsta->auth_transaction) {
1384 printk(KERN_DEBUG "%s: unexpected authentication frame "
1385 "(alg=%d transaction=%d)\n",
1386 dev->name, auth_alg, auth_transaction);
1390 if (status_code != WLAN_STATUS_SUCCESS) {
1391 printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
1392 "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
1393 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1395 const int num_algs = ARRAY_SIZE(algs);
1397 algs[0] = algs[1] = algs[2] = 0xff;
1398 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1399 algs[0] = WLAN_AUTH_OPEN;
1400 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1401 algs[1] = WLAN_AUTH_SHARED_KEY;
1402 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1403 algs[2] = WLAN_AUTH_LEAP;
1404 if (ifsta->auth_alg == WLAN_AUTH_OPEN)
1406 else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
1410 for (i = 0; i < num_algs; i++) {
1412 if (pos >= num_algs)
1414 if (algs[pos] == ifsta->auth_alg ||
1417 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1418 !ieee80211_sta_wep_configured(dev))
1420 ifsta->auth_alg = algs[pos];
1421 printk(KERN_DEBUG "%s: set auth_alg=%d for "
1423 dev->name, ifsta->auth_alg);
1430 switch (ifsta->auth_alg) {
1431 case WLAN_AUTH_OPEN:
1432 case WLAN_AUTH_LEAP:
1433 ieee80211_auth_completed(dev, ifsta);
1435 case WLAN_AUTH_SHARED_KEY:
1436 if (ifsta->auth_transaction == 4)
1437 ieee80211_auth_completed(dev, ifsta);
1439 ieee80211_auth_challenge(dev, ifsta, mgmt, len);
1445 static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
1446 struct ieee80211_if_sta *ifsta,
1447 struct ieee80211_mgmt *mgmt,
1451 DECLARE_MAC_BUF(mac);
1454 printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
1455 "received from %s - ignored\n",
1456 dev->name, len, print_mac(mac, mgmt->sa));
1460 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1461 printk(KERN_DEBUG "%s: deauthentication frame received from "
1462 "unknown AP (SA=%s BSSID=%s) - "
1463 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1464 print_mac(mac, mgmt->bssid));
1468 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1470 printk(KERN_DEBUG "%s: RX deauthentication from %s"
1472 dev->name, print_mac(mac, mgmt->sa), reason_code);
1474 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) {
1475 printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
1478 if (ifsta->state == IEEE80211_AUTHENTICATE ||
1479 ifsta->state == IEEE80211_ASSOCIATE ||
1480 ifsta->state == IEEE80211_ASSOCIATED) {
1481 ifsta->state = IEEE80211_AUTHENTICATE;
1482 mod_timer(&ifsta->timer, jiffies +
1483 IEEE80211_RETRY_AUTH_INTERVAL);
1486 ieee80211_set_disassoc(dev, ifsta, 1);
1487 ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
1491 static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
1492 struct ieee80211_if_sta *ifsta,
1493 struct ieee80211_mgmt *mgmt,
1497 DECLARE_MAC_BUF(mac);
1500 printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
1501 "received from %s - ignored\n",
1502 dev->name, len, print_mac(mac, mgmt->sa));
1506 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1507 printk(KERN_DEBUG "%s: disassociation frame received from "
1508 "unknown AP (SA=%s BSSID=%s) - "
1509 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1510 print_mac(mac, mgmt->bssid));
1514 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1516 printk(KERN_DEBUG "%s: RX disassociation from %s"
1518 dev->name, print_mac(mac, mgmt->sa), reason_code);
1520 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
1521 printk(KERN_DEBUG "%s: disassociated\n", dev->name);
1523 if (ifsta->state == IEEE80211_ASSOCIATED) {
1524 ifsta->state = IEEE80211_ASSOCIATE;
1525 mod_timer(&ifsta->timer, jiffies +
1526 IEEE80211_RETRY_AUTH_INTERVAL);
1529 ieee80211_set_disassoc(dev, ifsta, 0);
1533 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1534 struct ieee80211_if_sta *ifsta,
1535 struct ieee80211_mgmt *mgmt,
1539 struct ieee80211_local *local = sdata->local;
1540 struct net_device *dev = sdata->dev;
1541 struct ieee80211_hw_mode *mode;
1542 struct sta_info *sta;
1544 u16 capab_info, status_code, aid;
1545 struct ieee802_11_elems elems;
1546 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
1549 DECLARE_MAC_BUF(mac);
1551 /* AssocResp and ReassocResp have identical structure, so process both
1552 * of them in this function. */
1554 if (ifsta->state != IEEE80211_ASSOCIATE) {
1555 printk(KERN_DEBUG "%s: association frame received from "
1556 "%s, but not in associate state - ignored\n",
1557 dev->name, print_mac(mac, mgmt->sa));
1562 printk(KERN_DEBUG "%s: too short (%zd) association frame "
1563 "received from %s - ignored\n",
1564 dev->name, len, print_mac(mac, mgmt->sa));
1568 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1569 printk(KERN_DEBUG "%s: association frame received from "
1570 "unknown AP (SA=%s BSSID=%s) - "
1571 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1572 print_mac(mac, mgmt->bssid));
1576 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1577 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1578 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1580 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
1581 "status=%d aid=%d)\n",
1582 dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
1583 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1585 if (status_code != WLAN_STATUS_SUCCESS) {
1586 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1587 dev->name, status_code);
1588 /* if this was a reassociation, ensure we try a "full"
1589 * association next time. This works around some broken APs
1590 * which do not correctly reject reassociation requests. */
1591 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1595 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1596 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1597 "set\n", dev->name, aid);
1598 aid &= ~(BIT(15) | BIT(14));
1600 pos = mgmt->u.assoc_resp.variable;
1601 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1603 if (!elems.supp_rates) {
1604 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1609 printk(KERN_DEBUG "%s: associated\n", dev->name);
1611 ifsta->ap_capab = capab_info;
1613 kfree(ifsta->assocresp_ies);
1614 ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1615 ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
1616 if (ifsta->assocresp_ies)
1617 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
1619 /* set AID, ieee80211_set_associated() will tell the driver */
1620 bss_conf->aid = aid;
1621 ieee80211_set_associated(dev, ifsta, 1);
1623 /* Add STA entry for the AP */
1624 sta = sta_info_get(local, ifsta->bssid);
1626 struct ieee80211_sta_bss *bss;
1627 sta = sta_info_add(local, dev, ifsta->bssid, GFP_KERNEL);
1629 printk(KERN_DEBUG "%s: failed to add STA entry for the"
1630 " AP\n", dev->name);
1633 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
1634 local->hw.conf.channel,
1635 ifsta->ssid, ifsta->ssid_len);
1637 sta->last_rssi = bss->rssi;
1638 sta->last_signal = bss->signal;
1639 sta->last_noise = bss->noise;
1640 ieee80211_rx_bss_put(dev, bss);
1645 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP;
1648 mode = local->oper_hw_mode;
1649 for (i = 0; i < elems.supp_rates_len; i++) {
1650 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1651 for (j = 0; j < mode->num_rates; j++)
1652 if (mode->rates[j].rate == rate)
1655 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1656 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1657 for (j = 0; j < mode->num_rates; j++)
1658 if (mode->rates[j].rate == rate)
1661 sta->supp_rates = rates;
1663 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
1664 local->ops->conf_ht) {
1665 struct ieee80211_ht_bss_info bss_info;
1667 ieee80211_ht_cap_ie_to_ht_info(
1668 (struct ieee80211_ht_cap *)
1669 elems.ht_cap_elem, &sta->ht_info);
1670 ieee80211_ht_addt_info_ie_to_ht_bss_info(
1671 (struct ieee80211_ht_addt_info *)
1672 elems.ht_info_elem, &bss_info);
1673 ieee80211_hw_config_ht(local, 1, &sta->ht_info, &bss_info);
1676 rate_control_rate_init(sta, local);
1678 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
1679 sta->flags |= WLAN_STA_WME;
1680 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
1681 elems.wmm_param_len);
1687 ieee80211_associated(dev, ifsta);
1691 /* Caller must hold local->sta_bss_lock */
1692 static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
1693 struct ieee80211_sta_bss *bss)
1695 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1696 bss->hnext = local->sta_bss_hash[STA_HASH(bss->bssid)];
1697 local->sta_bss_hash[STA_HASH(bss->bssid)] = bss;
1701 /* Caller must hold local->sta_bss_lock */
1702 static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
1703 struct ieee80211_sta_bss *bss)
1705 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1706 struct ieee80211_sta_bss *b, *prev = NULL;
1707 b = local->sta_bss_hash[STA_HASH(bss->bssid)];
1711 local->sta_bss_hash[STA_HASH(bss->bssid)] =
1714 prev->hnext = bss->hnext;
1723 static struct ieee80211_sta_bss *
1724 ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
1725 u8 *ssid, u8 ssid_len)
1727 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1728 struct ieee80211_sta_bss *bss;
1730 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
1733 atomic_inc(&bss->users);
1734 atomic_inc(&bss->users);
1735 memcpy(bss->bssid, bssid, ETH_ALEN);
1736 bss->channel = channel;
1737 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
1738 memcpy(bss->ssid, ssid, ssid_len);
1739 bss->ssid_len = ssid_len;
1742 spin_lock_bh(&local->sta_bss_lock);
1743 /* TODO: order by RSSI? */
1744 list_add_tail(&bss->list, &local->sta_bss_list);
1745 __ieee80211_rx_bss_hash_add(dev, bss);
1746 spin_unlock_bh(&local->sta_bss_lock);
1751 static struct ieee80211_sta_bss *
1752 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
1753 u8 *ssid, u8 ssid_len)
1755 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1756 struct ieee80211_sta_bss *bss;
1758 spin_lock_bh(&local->sta_bss_lock);
1759 bss = local->sta_bss_hash[STA_HASH(bssid)];
1761 if (!memcmp(bss->bssid, bssid, ETH_ALEN) &&
1762 bss->channel == channel &&
1763 bss->ssid_len == ssid_len &&
1764 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
1765 atomic_inc(&bss->users);
1770 spin_unlock_bh(&local->sta_bss_lock);
1775 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
1785 static void ieee80211_rx_bss_put(struct net_device *dev,
1786 struct ieee80211_sta_bss *bss)
1788 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1789 if (!atomic_dec_and_test(&bss->users))
1792 spin_lock_bh(&local->sta_bss_lock);
1793 __ieee80211_rx_bss_hash_del(dev, bss);
1794 list_del(&bss->list);
1795 spin_unlock_bh(&local->sta_bss_lock);
1796 ieee80211_rx_bss_free(bss);
1800 void ieee80211_rx_bss_list_init(struct net_device *dev)
1802 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1803 spin_lock_init(&local->sta_bss_lock);
1804 INIT_LIST_HEAD(&local->sta_bss_list);
1808 void ieee80211_rx_bss_list_deinit(struct net_device *dev)
1810 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1811 struct ieee80211_sta_bss *bss, *tmp;
1813 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
1814 ieee80211_rx_bss_put(dev, bss);
1818 static void ieee80211_rx_bss_info(struct net_device *dev,
1819 struct ieee80211_mgmt *mgmt,
1821 struct ieee80211_rx_status *rx_status,
1824 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1825 struct ieee802_11_elems elems;
1828 struct ieee80211_sta_bss *bss;
1829 struct sta_info *sta;
1830 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1832 DECLARE_MAC_BUF(mac);
1833 DECLARE_MAC_BUF(mac2);
1835 if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
1836 return; /* ignore ProbeResp to foreign address */
1839 printk(KERN_DEBUG "%s: RX %s from %s to %s\n",
1840 dev->name, beacon ? "Beacon" : "Probe Response",
1841 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da));
1844 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1848 timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
1850 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
1851 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
1852 #ifdef CONFIG_MAC80211_IBSS_DEBUG
1853 static unsigned long last_tsf_debug = 0;
1855 if (local->ops->get_tsf)
1856 tsf = local->ops->get_tsf(local_to_hw(local));
1859 if (time_after(jiffies, last_tsf_debug + 5 * HZ)) {
1860 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
1861 "%s TSF=0x%llx BCN=0x%llx diff=%lld "
1863 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->bssid),
1864 (unsigned long long)tsf,
1865 (unsigned long long)timestamp,
1866 (unsigned long long)(tsf - timestamp),
1868 last_tsf_debug = jiffies;
1870 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
1873 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
1875 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
1876 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
1877 (sta = sta_info_get(local, mgmt->sa))) {
1878 struct ieee80211_hw_mode *mode;
1879 struct ieee80211_rate *rates;
1881 u32 supp_rates, prev_rates;
1884 mode = local->sta_sw_scanning ?
1885 local->scan_hw_mode : local->oper_hw_mode;
1887 if (local->sta_hw_scanning) {
1888 /* search for the correct mode matches the beacon */
1889 list_for_each_entry(mode, &local->modes_list, list)
1890 if (mode->mode == rx_status->phymode)
1894 mode = local->oper_hw_mode;
1896 rates = mode->rates;
1897 num_rates = mode->num_rates;
1900 for (i = 0; i < elems.supp_rates_len +
1901 elems.ext_supp_rates_len; i++) {
1904 if (i < elems.supp_rates_len)
1905 rate = elems.supp_rates[i];
1906 else if (elems.ext_supp_rates)
1907 rate = elems.ext_supp_rates
1908 [i - elems.supp_rates_len];
1909 own_rate = 5 * (rate & 0x7f);
1910 for (j = 0; j < num_rates; j++)
1911 if (rates[j].rate == own_rate)
1912 supp_rates |= BIT(j);
1915 prev_rates = sta->supp_rates;
1916 sta->supp_rates &= supp_rates;
1917 if (sta->supp_rates == 0) {
1918 /* No matching rates - this should not really happen.
1919 * Make sure that at least one rate is marked
1920 * supported to avoid issues with TX rate ctrl. */
1921 sta->supp_rates = sdata->u.sta.supp_rates_bits;
1923 if (sta->supp_rates != prev_rates) {
1924 printk(KERN_DEBUG "%s: updated supp_rates set for "
1925 "%s based on beacon info (0x%x & 0x%x -> "
1927 dev->name, print_mac(mac, sta->addr), prev_rates,
1928 supp_rates, sta->supp_rates);
1936 if (elems.ds_params && elems.ds_params_len == 1)
1937 channel = elems.ds_params[0];
1939 channel = rx_status->channel;
1941 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, channel,
1942 elems.ssid, elems.ssid_len);
1944 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, channel,
1945 elems.ssid, elems.ssid_len);
1950 /* TODO: order by RSSI? */
1951 spin_lock_bh(&local->sta_bss_lock);
1952 list_move_tail(&bss->list, &local->sta_bss_list);
1953 spin_unlock_bh(&local->sta_bss_lock);
1957 if (bss->probe_resp && beacon) {
1958 /* Do not allow beacon to override data from Probe Response. */
1959 ieee80211_rx_bss_put(dev, bss);
1963 /* save the ERP value so that it is available at association time */
1964 if (elems.erp_info && elems.erp_info_len >= 1) {
1965 bss->erp_value = elems.erp_info[0];
1966 bss->has_erp_value = 1;
1969 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
1970 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
1972 bss->supp_rates_len = 0;
1973 if (elems.supp_rates) {
1974 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
1975 if (clen > elems.supp_rates_len)
1976 clen = elems.supp_rates_len;
1977 memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
1979 bss->supp_rates_len += clen;
1981 if (elems.ext_supp_rates) {
1982 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
1983 if (clen > elems.ext_supp_rates_len)
1984 clen = elems.ext_supp_rates_len;
1985 memcpy(&bss->supp_rates[bss->supp_rates_len],
1986 elems.ext_supp_rates, clen);
1987 bss->supp_rates_len += clen;
1991 (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len ||
1992 memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
1994 bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
1996 memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
1997 bss->wpa_ie_len = elems.wpa_len + 2;
1999 bss->wpa_ie_len = 0;
2000 } else if (!elems.wpa && bss->wpa_ie) {
2003 bss->wpa_ie_len = 0;
2007 (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len ||
2008 memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
2010 bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
2012 memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
2013 bss->rsn_ie_len = elems.rsn_len + 2;
2015 bss->rsn_ie_len = 0;
2016 } else if (!elems.rsn && bss->rsn_ie) {
2019 bss->rsn_ie_len = 0;
2022 if (elems.wmm_param &&
2023 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len ||
2024 memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
2026 bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
2028 memcpy(bss->wmm_ie, elems.wmm_param - 2,
2029 elems.wmm_param_len + 2);
2030 bss->wmm_ie_len = elems.wmm_param_len + 2;
2032 bss->wmm_ie_len = 0;
2033 } else if (!elems.wmm_param && bss->wmm_ie) {
2036 bss->wmm_ie_len = 0;
2038 if (elems.ht_cap_elem &&
2039 (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
2040 memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
2042 bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
2044 memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
2045 elems.ht_cap_elem_len + 2);
2046 bss->ht_ie_len = elems.ht_cap_elem_len + 2;
2049 } else if (!elems.ht_cap_elem && bss->ht_ie) {
2055 bss->hw_mode = rx_status->phymode;
2056 bss->freq = rx_status->freq;
2057 if (channel != rx_status->channel &&
2058 (bss->hw_mode == MODE_IEEE80211G ||
2059 bss->hw_mode == MODE_IEEE80211B) &&
2060 channel >= 1 && channel <= 14) {
2061 static const int freq_list[] = {
2062 2412, 2417, 2422, 2427, 2432, 2437, 2442,
2063 2447, 2452, 2457, 2462, 2467, 2472, 2484
2065 /* IEEE 802.11g/b mode can receive packets from neighboring
2066 * channels, so map the channel into frequency. */
2067 bss->freq = freq_list[channel - 1];
2069 bss->timestamp = timestamp;
2070 bss->last_update = jiffies;
2071 bss->rssi = rx_status->ssi;
2072 bss->signal = rx_status->signal;
2073 bss->noise = rx_status->noise;
2076 ieee80211_rx_bss_put(dev, bss);
2080 static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
2081 struct ieee80211_mgmt *mgmt,
2083 struct ieee80211_rx_status *rx_status)
2085 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
2089 static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
2090 struct ieee80211_mgmt *mgmt,
2092 struct ieee80211_rx_status *rx_status)
2094 struct ieee80211_sub_if_data *sdata;
2095 struct ieee80211_if_sta *ifsta;
2097 struct ieee802_11_elems elems;
2098 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2099 struct ieee80211_conf *conf = &local->hw.conf;
2102 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
2104 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2105 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
2107 ifsta = &sdata->u.sta;
2109 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
2110 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
2113 /* Process beacon from the current BSS */
2114 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2118 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
2120 if (elems.erp_info && elems.erp_info_len >= 1)
2121 changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
2123 if (elems.ht_cap_elem && elems.ht_info_elem &&
2124 elems.wmm_param && local->ops->conf_ht &&
2125 conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
2126 struct ieee80211_ht_bss_info bss_info;
2128 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2129 (struct ieee80211_ht_addt_info *)
2130 elems.ht_info_elem, &bss_info);
2131 /* check if AP changed bss inforamation */
2132 if ((conf->ht_bss_conf.primary_channel !=
2133 bss_info.primary_channel) ||
2134 (conf->ht_bss_conf.bss_cap != bss_info.bss_cap) ||
2135 (conf->ht_bss_conf.bss_op_mode != bss_info.bss_op_mode))
2136 ieee80211_hw_config_ht(local, 1, &conf->ht_conf,
2140 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
2141 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2142 elems.wmm_param_len);
2145 ieee80211_bss_info_change_notify(sdata, changed);
2149 static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
2150 struct ieee80211_if_sta *ifsta,
2151 struct ieee80211_mgmt *mgmt,
2153 struct ieee80211_rx_status *rx_status)
2155 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2156 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2158 struct sk_buff *skb;
2159 struct ieee80211_mgmt *resp;
2161 DECLARE_MAC_BUF(mac);
2162 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2163 DECLARE_MAC_BUF(mac2);
2164 DECLARE_MAC_BUF(mac3);
2167 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
2168 ifsta->state != IEEE80211_IBSS_JOINED ||
2169 len < 24 + 2 || !ifsta->probe_resp)
2172 if (local->ops->tx_last_beacon)
2173 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
2177 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2178 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
2179 "%s (tx_last_beacon=%d)\n",
2180 dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
2181 print_mac(mac3, mgmt->bssid), tx_last_beacon);
2182 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2184 if (!tx_last_beacon)
2187 if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
2188 memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
2191 end = ((u8 *) mgmt) + len;
2192 pos = mgmt->u.probe_req.variable;
2193 if (pos[0] != WLAN_EID_SSID ||
2194 pos + 2 + pos[1] > end) {
2195 if (net_ratelimit()) {
2196 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
2198 dev->name, print_mac(mac, mgmt->sa));
2203 (pos[1] != ifsta->ssid_len ||
2204 memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
2205 /* Ignore ProbeReq for foreign SSID */
2209 /* Reply with ProbeResp */
2210 skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
2214 resp = (struct ieee80211_mgmt *) skb->data;
2215 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2216 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2217 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
2218 dev->name, print_mac(mac, resp->da));
2219 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2220 ieee80211_sta_tx(dev, skb, 0);
2223 static void ieee80211_rx_mgmt_action(struct net_device *dev,
2224 struct ieee80211_if_sta *ifsta,
2225 struct ieee80211_mgmt *mgmt,
2228 if (len < IEEE80211_MIN_ACTION_SIZE)
2231 switch (mgmt->u.action.category) {
2232 case WLAN_CATEGORY_BACK:
2233 switch (mgmt->u.action.u.addba_req.action_code) {
2234 case WLAN_ACTION_ADDBA_REQ:
2235 if (len < (IEEE80211_MIN_ACTION_SIZE +
2236 sizeof(mgmt->u.action.u.addba_req)))
2238 ieee80211_sta_process_addba_request(dev, mgmt, len);
2240 case WLAN_ACTION_DELBA:
2241 if (len < (IEEE80211_MIN_ACTION_SIZE +
2242 sizeof(mgmt->u.action.u.delba)))
2244 ieee80211_sta_process_delba(dev, mgmt, len);
2247 if (net_ratelimit())
2248 printk(KERN_DEBUG "%s: Rx unknown A-MPDU action\n",
2258 void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
2259 struct ieee80211_rx_status *rx_status)
2261 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2262 struct ieee80211_sub_if_data *sdata;
2263 struct ieee80211_if_sta *ifsta;
2264 struct ieee80211_mgmt *mgmt;
2270 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2271 ifsta = &sdata->u.sta;
2273 mgmt = (struct ieee80211_mgmt *) skb->data;
2274 fc = le16_to_cpu(mgmt->frame_control);
2276 switch (fc & IEEE80211_FCTL_STYPE) {
2277 case IEEE80211_STYPE_PROBE_REQ:
2278 case IEEE80211_STYPE_PROBE_RESP:
2279 case IEEE80211_STYPE_BEACON:
2280 memcpy(skb->cb, rx_status, sizeof(*rx_status));
2281 case IEEE80211_STYPE_AUTH:
2282 case IEEE80211_STYPE_ASSOC_RESP:
2283 case IEEE80211_STYPE_REASSOC_RESP:
2284 case IEEE80211_STYPE_DEAUTH:
2285 case IEEE80211_STYPE_DISASSOC:
2286 case IEEE80211_STYPE_ACTION:
2287 skb_queue_tail(&ifsta->skb_queue, skb);
2288 queue_work(local->hw.workqueue, &ifsta->work);
2291 printk(KERN_DEBUG "%s: received unknown management frame - "
2292 "stype=%d\n", dev->name,
2293 (fc & IEEE80211_FCTL_STYPE) >> 4);
2302 static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
2303 struct sk_buff *skb)
2305 struct ieee80211_rx_status *rx_status;
2306 struct ieee80211_sub_if_data *sdata;
2307 struct ieee80211_if_sta *ifsta;
2308 struct ieee80211_mgmt *mgmt;
2311 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2312 ifsta = &sdata->u.sta;
2314 rx_status = (struct ieee80211_rx_status *) skb->cb;
2315 mgmt = (struct ieee80211_mgmt *) skb->data;
2316 fc = le16_to_cpu(mgmt->frame_control);
2318 switch (fc & IEEE80211_FCTL_STYPE) {
2319 case IEEE80211_STYPE_PROBE_REQ:
2320 ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
2323 case IEEE80211_STYPE_PROBE_RESP:
2324 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
2326 case IEEE80211_STYPE_BEACON:
2327 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
2329 case IEEE80211_STYPE_AUTH:
2330 ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len);
2332 case IEEE80211_STYPE_ASSOC_RESP:
2333 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
2335 case IEEE80211_STYPE_REASSOC_RESP:
2336 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
2338 case IEEE80211_STYPE_DEAUTH:
2339 ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len);
2341 case IEEE80211_STYPE_DISASSOC:
2342 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
2344 case IEEE80211_STYPE_ACTION:
2345 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len);
2353 ieee80211_txrx_result
2354 ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
2355 struct ieee80211_rx_status *rx_status)
2357 struct ieee80211_mgmt *mgmt;
2363 mgmt = (struct ieee80211_mgmt *) skb->data;
2364 fc = le16_to_cpu(mgmt->frame_control);
2366 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
2367 return TXRX_CONTINUE;
2372 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2373 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
2374 ieee80211_rx_mgmt_probe_resp(dev, mgmt,
2375 skb->len, rx_status);
2378 } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
2379 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
2385 return TXRX_CONTINUE;
2389 static int ieee80211_sta_active_ibss(struct net_device *dev)
2391 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2393 struct sta_info *sta;
2395 read_lock_bh(&local->sta_lock);
2396 list_for_each_entry(sta, &local->sta_list, list) {
2397 if (sta->dev == dev &&
2398 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
2404 read_unlock_bh(&local->sta_lock);
2410 static void ieee80211_sta_expire(struct net_device *dev)
2412 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2413 struct sta_info *sta, *tmp;
2414 LIST_HEAD(tmp_list);
2415 DECLARE_MAC_BUF(mac);
2417 write_lock_bh(&local->sta_lock);
2418 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
2419 if (time_after(jiffies, sta->last_rx +
2420 IEEE80211_IBSS_INACTIVITY_LIMIT)) {
2421 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
2422 dev->name, print_mac(mac, sta->addr));
2423 __sta_info_get(sta);
2424 sta_info_remove(sta);
2425 list_add(&sta->list, &tmp_list);
2427 write_unlock_bh(&local->sta_lock);
2429 list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
2436 static void ieee80211_sta_merge_ibss(struct net_device *dev,
2437 struct ieee80211_if_sta *ifsta)
2439 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2441 ieee80211_sta_expire(dev);
2442 if (ieee80211_sta_active_ibss(dev))
2445 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
2446 "IBSS networks with same SSID (merge)\n", dev->name);
2447 ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
2451 void ieee80211_sta_timer(unsigned long data)
2453 struct ieee80211_sub_if_data *sdata =
2454 (struct ieee80211_sub_if_data *) data;
2455 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2456 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
2458 set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
2459 queue_work(local->hw.workqueue, &ifsta->work);
2463 void ieee80211_sta_work(struct work_struct *work)
2465 struct ieee80211_sub_if_data *sdata =
2466 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
2467 struct net_device *dev = sdata->dev;
2468 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2469 struct ieee80211_if_sta *ifsta;
2470 struct sk_buff *skb;
2472 if (!netif_running(dev))
2475 if (local->sta_sw_scanning || local->sta_hw_scanning)
2478 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
2479 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
2480 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
2481 "(type=%d)\n", dev->name, sdata->vif.type);
2484 ifsta = &sdata->u.sta;
2486 while ((skb = skb_dequeue(&ifsta->skb_queue)))
2487 ieee80211_sta_rx_queued_mgmt(dev, skb);
2489 if (ifsta->state != IEEE80211_AUTHENTICATE &&
2490 ifsta->state != IEEE80211_ASSOCIATE &&
2491 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
2492 if (ifsta->scan_ssid_len)
2493 ieee80211_sta_start_scan(dev, ifsta->scan_ssid, ifsta->scan_ssid_len);
2495 ieee80211_sta_start_scan(dev, NULL, 0);
2499 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
2500 if (ieee80211_sta_config_auth(dev, ifsta))
2502 clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
2503 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
2506 switch (ifsta->state) {
2507 case IEEE80211_DISABLED:
2509 case IEEE80211_AUTHENTICATE:
2510 ieee80211_authenticate(dev, ifsta);
2512 case IEEE80211_ASSOCIATE:
2513 ieee80211_associate(dev, ifsta);
2515 case IEEE80211_ASSOCIATED:
2516 ieee80211_associated(dev, ifsta);
2518 case IEEE80211_IBSS_SEARCH:
2519 ieee80211_sta_find_ibss(dev, ifsta);
2521 case IEEE80211_IBSS_JOINED:
2522 ieee80211_sta_merge_ibss(dev, ifsta);
2525 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
2530 if (ieee80211_privacy_mismatch(dev, ifsta)) {
2531 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
2532 "mixed-cell disabled - disassociate\n", dev->name);
2534 ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
2535 ieee80211_set_disassoc(dev, ifsta, 0);
2540 static void ieee80211_sta_reset_auth(struct net_device *dev,
2541 struct ieee80211_if_sta *ifsta)
2543 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2545 if (local->ops->reset_tsf) {
2546 /* Reset own TSF to allow time synchronization work. */
2547 local->ops->reset_tsf(local_to_hw(local));
2550 ifsta->wmm_last_param_set = -1; /* allow any WMM update */
2553 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
2554 ifsta->auth_alg = WLAN_AUTH_OPEN;
2555 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
2556 ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
2557 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
2558 ifsta->auth_alg = WLAN_AUTH_LEAP;
2560 ifsta->auth_alg = WLAN_AUTH_OPEN;
2561 printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
2563 ifsta->auth_transaction = -1;
2564 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
2565 ifsta->auth_tries = ifsta->assoc_tries = 0;
2566 netif_carrier_off(dev);
2570 void ieee80211_sta_req_auth(struct net_device *dev,
2571 struct ieee80211_if_sta *ifsta)
2573 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2574 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2576 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
2579 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
2580 IEEE80211_STA_AUTO_BSSID_SEL)) &&
2581 (ifsta->flags & (IEEE80211_STA_SSID_SET |
2582 IEEE80211_STA_AUTO_SSID_SEL))) {
2583 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
2584 queue_work(local->hw.workqueue, &ifsta->work);
2588 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
2589 const char *ssid, int ssid_len)
2591 int tmp, hidden_ssid;
2593 if (ssid_len == ifsta->ssid_len &&
2594 !memcmp(ifsta->ssid, ssid, ssid_len))
2597 if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
2603 if (ssid[tmp] != '\0') {
2609 if (hidden_ssid && ifsta->ssid_len == ssid_len)
2612 if (ssid_len == 1 && ssid[0] == ' ')
2618 static int ieee80211_sta_config_auth(struct net_device *dev,
2619 struct ieee80211_if_sta *ifsta)
2621 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2622 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2623 struct ieee80211_sta_bss *bss, *selected = NULL;
2624 int top_rssi = 0, freq;
2626 if (!(ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
2627 IEEE80211_STA_AUTO_BSSID_SEL | IEEE80211_STA_AUTO_CHANNEL_SEL))) {
2628 ifsta->state = IEEE80211_AUTHENTICATE;
2629 ieee80211_sta_reset_auth(dev, ifsta);
2633 spin_lock_bh(&local->sta_bss_lock);
2634 freq = local->oper_channel->freq;
2635 list_for_each_entry(bss, &local->sta_bss_list, list) {
2636 if (!(bss->capability & WLAN_CAPABILITY_ESS))
2639 if (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
2640 !!sdata->default_key)
2643 if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
2647 if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
2648 memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
2651 if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
2652 !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
2655 if (!selected || top_rssi < bss->rssi) {
2657 top_rssi = bss->rssi;
2661 atomic_inc(&selected->users);
2662 spin_unlock_bh(&local->sta_bss_lock);
2665 ieee80211_set_channel(local, -1, selected->freq);
2666 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
2667 ieee80211_sta_set_ssid(dev, selected->ssid,
2668 selected->ssid_len);
2669 ieee80211_sta_set_bssid(dev, selected->bssid);
2670 ieee80211_rx_bss_put(dev, selected);
2671 ifsta->state = IEEE80211_AUTHENTICATE;
2672 ieee80211_sta_reset_auth(dev, ifsta);
2675 if (ifsta->state != IEEE80211_AUTHENTICATE) {
2676 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
2677 ieee80211_sta_start_scan(dev, NULL, 0);
2679 ieee80211_sta_start_scan(dev, ifsta->ssid,
2681 ifsta->state = IEEE80211_AUTHENTICATE;
2682 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
2684 ifsta->state = IEEE80211_DISABLED;
2689 static int ieee80211_sta_join_ibss(struct net_device *dev,
2690 struct ieee80211_if_sta *ifsta,
2691 struct ieee80211_sta_bss *bss)
2693 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2694 int res, rates, i, j;
2695 struct sk_buff *skb;
2696 struct ieee80211_mgmt *mgmt;
2697 struct ieee80211_tx_control control;
2698 struct ieee80211_hw_mode *mode;
2699 struct rate_selection ratesel;
2701 struct ieee80211_sub_if_data *sdata;
2703 /* Remove possible STA entries from other IBSS networks. */
2704 sta_info_flush(local, NULL);
2706 if (local->ops->reset_tsf) {
2707 /* Reset own TSF to allow time synchronization work. */
2708 local->ops->reset_tsf(local_to_hw(local));
2710 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2711 res = ieee80211_if_config(dev);
2715 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2717 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2718 sdata->drop_unencrypted = bss->capability &
2719 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2721 res = ieee80211_set_channel(local, -1, bss->freq);
2723 if (!(local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)) {
2724 printk(KERN_DEBUG "%s: IBSS not allowed on channel %d "
2725 "(%d MHz)\n", dev->name, local->hw.conf.channel,
2726 local->hw.conf.freq);
2730 /* Set beacon template based on scan results */
2731 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2736 skb_reserve(skb, local->hw.extra_tx_headroom);
2738 mgmt = (struct ieee80211_mgmt *)
2739 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2740 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2741 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2742 IEEE80211_STYPE_BEACON);
2743 memset(mgmt->da, 0xff, ETH_ALEN);
2744 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2745 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2746 mgmt->u.beacon.beacon_int =
2747 cpu_to_le16(local->hw.conf.beacon_int);
2748 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2750 pos = skb_put(skb, 2 + ifsta->ssid_len);
2751 *pos++ = WLAN_EID_SSID;
2752 *pos++ = ifsta->ssid_len;
2753 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2755 rates = bss->supp_rates_len;
2758 pos = skb_put(skb, 2 + rates);
2759 *pos++ = WLAN_EID_SUPP_RATES;
2761 memcpy(pos, bss->supp_rates, rates);
2763 pos = skb_put(skb, 2 + 1);
2764 *pos++ = WLAN_EID_DS_PARAMS;
2766 *pos++ = bss->channel;
2768 pos = skb_put(skb, 2 + 2);
2769 *pos++ = WLAN_EID_IBSS_PARAMS;
2771 /* FIX: set ATIM window based on scan results */
2775 if (bss->supp_rates_len > 8) {
2776 rates = bss->supp_rates_len - 8;
2777 pos = skb_put(skb, 2 + rates);
2778 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2780 memcpy(pos, &bss->supp_rates[8], rates);
2783 memset(&control, 0, sizeof(control));
2784 rate_control_get_rate(dev, local->oper_hw_mode, skb, &ratesel);
2785 if (!ratesel.rate) {
2786 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2787 "for IBSS beacon\n", dev->name);
2790 control.vif = &sdata->vif;
2792 (sdata->bss_conf.use_short_preamble &&
2793 (ratesel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
2794 ratesel.rate->val2 : ratesel.rate->val;
2795 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2796 control.power_level = local->hw.conf.power_level;
2797 control.flags |= IEEE80211_TXCTL_NO_ACK;
2798 control.retry_limit = 1;
2800 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2801 if (ifsta->probe_resp) {
2802 mgmt = (struct ieee80211_mgmt *)
2803 ifsta->probe_resp->data;
2804 mgmt->frame_control =
2805 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2806 IEEE80211_STYPE_PROBE_RESP);
2808 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2809 "template for IBSS\n", dev->name);
2812 if (local->ops->beacon_update &&
2813 local->ops->beacon_update(local_to_hw(local),
2814 skb, &control) == 0) {
2815 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2816 "template based on scan results\n", dev->name);
2821 mode = local->oper_hw_mode;
2822 for (i = 0; i < bss->supp_rates_len; i++) {
2823 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2824 for (j = 0; j < mode->num_rates; j++)
2825 if (mode->rates[j].rate == bitrate)
2828 ifsta->supp_rates_bits = rates;
2832 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2833 "template\n", dev->name);
2837 ifsta->state = IEEE80211_IBSS_JOINED;
2838 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2840 ieee80211_rx_bss_put(dev, bss);
2846 static int ieee80211_sta_create_ibss(struct net_device *dev,
2847 struct ieee80211_if_sta *ifsta)
2849 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2850 struct ieee80211_sta_bss *bss;
2851 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2852 struct ieee80211_hw_mode *mode;
2853 u8 bssid[ETH_ALEN], *pos;
2855 DECLARE_MAC_BUF(mac);
2858 /* Easier testing, use fixed BSSID. */
2859 memset(bssid, 0xfe, ETH_ALEN);
2861 /* Generate random, not broadcast, locally administered BSSID. Mix in
2862 * own MAC address to make sure that devices that do not have proper
2863 * random number generator get different BSSID. */
2864 get_random_bytes(bssid, ETH_ALEN);
2865 for (i = 0; i < ETH_ALEN; i++)
2866 bssid[i] ^= dev->dev_addr[i];
2871 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
2872 dev->name, print_mac(mac, bssid));
2874 bss = ieee80211_rx_bss_add(dev, bssid, local->hw.conf.channel,
2875 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
2879 mode = local->oper_hw_mode;
2881 if (local->hw.conf.beacon_int == 0)
2882 local->hw.conf.beacon_int = 100;
2883 bss->beacon_int = local->hw.conf.beacon_int;
2884 bss->hw_mode = local->hw.conf.phymode;
2885 bss->freq = local->hw.conf.freq;
2886 bss->last_update = jiffies;
2887 bss->capability = WLAN_CAPABILITY_IBSS;
2888 if (sdata->default_key) {
2889 bss->capability |= WLAN_CAPABILITY_PRIVACY;
2891 sdata->drop_unencrypted = 0;
2892 bss->supp_rates_len = mode->num_rates;
2893 pos = bss->supp_rates;
2894 for (i = 0; i < mode->num_rates; i++) {
2895 int rate = mode->rates[i].rate;
2896 *pos++ = (u8) (rate / 5);
2899 return ieee80211_sta_join_ibss(dev, ifsta, bss);
2903 static int ieee80211_sta_find_ibss(struct net_device *dev,
2904 struct ieee80211_if_sta *ifsta)
2906 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2907 struct ieee80211_sta_bss *bss;
2911 DECLARE_MAC_BUF(mac);
2912 DECLARE_MAC_BUF(mac2);
2914 if (ifsta->ssid_len == 0)
2917 active_ibss = ieee80211_sta_active_ibss(dev);
2918 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2919 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
2920 dev->name, active_ibss);
2921 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2922 spin_lock_bh(&local->sta_bss_lock);
2923 list_for_each_entry(bss, &local->sta_bss_list, list) {
2924 if (ifsta->ssid_len != bss->ssid_len ||
2925 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
2926 || !(bss->capability & WLAN_CAPABILITY_IBSS))
2928 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2929 printk(KERN_DEBUG " bssid=%s found\n",
2930 print_mac(mac, bss->bssid));
2931 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2932 memcpy(bssid, bss->bssid, ETH_ALEN);
2934 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
2937 spin_unlock_bh(&local->sta_bss_lock);
2939 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2940 printk(KERN_DEBUG " sta_find_ibss: selected %s current "
2941 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
2942 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2943 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
2944 (bss = ieee80211_rx_bss_get(dev, bssid, local->hw.conf.channel,
2945 ifsta->ssid, ifsta->ssid_len))) {
2946 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
2947 " based on configured SSID\n",
2948 dev->name, print_mac(mac, bssid));
2949 return ieee80211_sta_join_ibss(dev, ifsta, bss);
2951 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2952 printk(KERN_DEBUG " did not try to join ibss\n");
2953 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2955 /* Selected IBSS not found in current scan results - try to scan */
2956 if (ifsta->state == IEEE80211_IBSS_JOINED &&
2957 !ieee80211_sta_active_ibss(dev)) {
2958 mod_timer(&ifsta->timer, jiffies +
2959 IEEE80211_IBSS_MERGE_INTERVAL);
2960 } else if (time_after(jiffies, local->last_scan_completed +
2961 IEEE80211_SCAN_INTERVAL)) {
2962 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
2963 "join\n", dev->name);
2964 return ieee80211_sta_req_scan(dev, ifsta->ssid,
2966 } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
2967 int interval = IEEE80211_SCAN_INTERVAL;
2969 if (time_after(jiffies, ifsta->ibss_join_req +
2970 IEEE80211_IBSS_JOIN_TIMEOUT)) {
2971 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
2972 local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)
2973 return ieee80211_sta_create_ibss(dev, ifsta);
2974 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
2975 printk(KERN_DEBUG "%s: IBSS not allowed on the"
2976 " configured channel %d (%d MHz)\n",
2977 dev->name, local->hw.conf.channel,
2978 local->hw.conf.freq);
2981 /* No IBSS found - decrease scan interval and continue
2983 interval = IEEE80211_SCAN_INTERVAL_SLOW;
2986 ifsta->state = IEEE80211_IBSS_SEARCH;
2987 mod_timer(&ifsta->timer, jiffies + interval);
2995 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
2997 struct ieee80211_sub_if_data *sdata;
2998 struct ieee80211_if_sta *ifsta;
2999 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3001 if (len > IEEE80211_MAX_SSID_LEN)
3004 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
3006 if (local->ops->conf_tx) {
3007 struct ieee80211_tx_queue_params qparam;
3010 memset(&qparam, 0, sizeof(qparam));
3011 /* TODO: are these ok defaults for all hw_modes? */
3014 local->hw.conf.phymode == MODE_IEEE80211B ? 31 : 15;
3015 qparam.cw_max = 1023;
3016 qparam.burst_time = 0;
3017 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
3019 local->ops->conf_tx(local_to_hw(local),
3020 i + IEEE80211_TX_QUEUE_DATA0,
3023 /* IBSS uses different parameters for Beacon sending */
3027 local->ops->conf_tx(local_to_hw(local),
3028 IEEE80211_TX_QUEUE_BEACON, &qparam);
3031 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3032 ifsta = &sdata->u.sta;
3034 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
3035 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
3036 memcpy(ifsta->ssid, ssid, len);
3037 memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
3038 ifsta->ssid_len = len;
3041 ifsta->flags |= IEEE80211_STA_SSID_SET;
3043 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
3044 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3045 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
3046 ifsta->ibss_join_req = jiffies;
3047 ifsta->state = IEEE80211_IBSS_SEARCH;
3048 return ieee80211_sta_find_ibss(dev, ifsta);
3054 int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
3056 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3057 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3058 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
3059 *len = ifsta->ssid_len;
3064 int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
3066 struct ieee80211_sub_if_data *sdata;
3067 struct ieee80211_if_sta *ifsta;
3070 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3071 ifsta = &sdata->u.sta;
3073 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
3074 memcpy(ifsta->bssid, bssid, ETH_ALEN);
3075 res = ieee80211_if_config(dev);
3077 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
3078 "the low-level driver\n", dev->name);
3083 if (is_valid_ether_addr(bssid))
3084 ifsta->flags |= IEEE80211_STA_BSSID_SET;
3086 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
3092 static void ieee80211_send_nullfunc(struct ieee80211_local *local,
3093 struct ieee80211_sub_if_data *sdata,
3096 struct sk_buff *skb;
3097 struct ieee80211_hdr *nullfunc;
3100 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
3102 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
3103 "frame\n", sdata->dev->name);
3106 skb_reserve(skb, local->hw.extra_tx_headroom);
3108 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
3109 memset(nullfunc, 0, 24);
3110 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
3111 IEEE80211_FCTL_TODS;
3113 fc |= IEEE80211_FCTL_PM;
3114 nullfunc->frame_control = cpu_to_le16(fc);
3115 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
3116 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
3117 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
3119 ieee80211_sta_tx(sdata->dev, skb, 0);
3123 void ieee80211_scan_completed(struct ieee80211_hw *hw)
3125 struct ieee80211_local *local = hw_to_local(hw);
3126 struct net_device *dev = local->scan_dev;
3127 struct ieee80211_sub_if_data *sdata;
3128 union iwreq_data wrqu;
3130 local->last_scan_completed = jiffies;
3131 memset(&wrqu, 0, sizeof(wrqu));
3132 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
3134 if (local->sta_hw_scanning) {
3135 local->sta_hw_scanning = 0;
3139 local->sta_sw_scanning = 0;
3140 if (ieee80211_hw_config(local))
3141 printk(KERN_DEBUG "%s: failed to restore operational "
3142 "channel after scan\n", dev->name);
3145 netif_tx_lock_bh(local->mdev);
3146 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
3147 local->ops->configure_filter(local_to_hw(local),
3148 FIF_BCN_PRBRESP_PROMISC,
3149 &local->filter_flags,
3150 local->mdev->mc_count,
3151 local->mdev->mc_list);
3153 netif_tx_unlock_bh(local->mdev);
3156 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3158 /* No need to wake the master device. */
3159 if (sdata->dev == local->mdev)
3162 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
3163 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
3164 ieee80211_send_nullfunc(local, sdata, 0);
3165 ieee80211_sta_timer((unsigned long)sdata);
3168 netif_wake_queue(sdata->dev);
3173 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3174 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
3175 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3176 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
3177 (!ifsta->state == IEEE80211_IBSS_JOINED &&
3178 !ieee80211_sta_active_ibss(dev)))
3179 ieee80211_sta_find_ibss(dev, ifsta);
3182 EXPORT_SYMBOL(ieee80211_scan_completed);
3184 void ieee80211_sta_scan_work(struct work_struct *work)
3186 struct ieee80211_local *local =
3187 container_of(work, struct ieee80211_local, scan_work.work);
3188 struct net_device *dev = local->scan_dev;
3189 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3190 struct ieee80211_hw_mode *mode;
3191 struct ieee80211_channel *chan;
3193 unsigned long next_delay = 0;
3195 if (!local->sta_sw_scanning)
3198 switch (local->scan_state) {
3199 case SCAN_SET_CHANNEL:
3200 mode = local->scan_hw_mode;
3201 if (local->scan_hw_mode->list.next == &local->modes_list &&
3202 local->scan_channel_idx >= mode->num_channels) {
3203 ieee80211_scan_completed(local_to_hw(local));
3206 skip = !(local->enabled_modes & (1 << mode->mode));
3207 chan = &mode->channels[local->scan_channel_idx];
3208 if (!(chan->flag & IEEE80211_CHAN_W_SCAN) ||
3209 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3210 !(chan->flag & IEEE80211_CHAN_W_IBSS)) ||
3211 (local->hw_modes & local->enabled_modes &
3212 (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
3217 printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n",
3218 dev->name, chan->chan, chan->freq);
3221 local->scan_channel = chan;
3222 if (ieee80211_hw_config(local)) {
3223 printk(KERN_DEBUG "%s: failed to set channel "
3224 "%d (%d MHz) for scan\n", dev->name,
3225 chan->chan, chan->freq);
3230 local->scan_channel_idx++;
3231 if (local->scan_channel_idx >= local->scan_hw_mode->num_channels) {
3232 if (local->scan_hw_mode->list.next != &local->modes_list) {
3233 local->scan_hw_mode = list_entry(local->scan_hw_mode->list.next,
3234 struct ieee80211_hw_mode,
3236 local->scan_channel_idx = 0;
3243 next_delay = IEEE80211_PROBE_DELAY +
3244 usecs_to_jiffies(local->hw.channel_change_time);
3245 local->scan_state = SCAN_SEND_PROBE;
3247 case SCAN_SEND_PROBE:
3248 if (local->scan_channel->flag & IEEE80211_CHAN_W_ACTIVE_SCAN) {
3249 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3250 local->scan_ssid_len);
3251 next_delay = IEEE80211_CHANNEL_TIME;
3253 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3254 local->scan_state = SCAN_SET_CHANNEL;
3258 if (local->sta_sw_scanning)
3259 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3264 static int ieee80211_sta_start_scan(struct net_device *dev,
3265 u8 *ssid, size_t ssid_len)
3267 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3268 struct ieee80211_sub_if_data *sdata;
3270 if (ssid_len > IEEE80211_MAX_SSID_LEN)
3273 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3274 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3277 * ScanType: ACTIVE, PASSIVE
3278 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3279 * a Probe frame during active scanning
3281 * MinChannelTime (>= ProbeDelay), in TU
3282 * MaxChannelTime: (>= MinChannelTime), in TU
3285 /* MLME-SCAN.confirm
3287 * ResultCode: SUCCESS, INVALID_PARAMETERS
3290 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3291 if (local->scan_dev == dev)
3296 if (local->ops->hw_scan) {
3297 int rc = local->ops->hw_scan(local_to_hw(local),
3300 local->sta_hw_scanning = 1;
3301 local->scan_dev = dev;
3306 local->sta_sw_scanning = 1;
3309 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3311 /* Don't stop the master interface, otherwise we can't transmit
3313 if (sdata->dev == local->mdev)
3316 netif_stop_queue(sdata->dev);
3317 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3318 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
3319 ieee80211_send_nullfunc(local, sdata, 1);
3324 local->scan_ssid_len = ssid_len;
3325 memcpy(local->scan_ssid, ssid, ssid_len);
3327 local->scan_ssid_len = 0;
3328 local->scan_state = SCAN_SET_CHANNEL;
3329 local->scan_hw_mode = list_entry(local->modes_list.next,
3330 struct ieee80211_hw_mode,
3332 local->scan_channel_idx = 0;
3333 local->scan_dev = dev;
3335 netif_tx_lock_bh(local->mdev);
3336 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
3337 local->ops->configure_filter(local_to_hw(local),
3338 FIF_BCN_PRBRESP_PROMISC,
3339 &local->filter_flags,
3340 local->mdev->mc_count,
3341 local->mdev->mc_list);
3342 netif_tx_unlock_bh(local->mdev);
3344 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3345 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3346 IEEE80211_CHANNEL_TIME);
3352 int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
3354 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3355 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3356 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3358 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
3359 return ieee80211_sta_start_scan(dev, ssid, ssid_len);
3361 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3362 if (local->scan_dev == dev)
3367 ifsta->scan_ssid_len = ssid_len;
3369 memcpy(ifsta->scan_ssid, ssid, ssid_len);
3370 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
3371 queue_work(local->hw.workqueue, &ifsta->work);
3376 ieee80211_sta_scan_result(struct net_device *dev,
3377 struct ieee80211_sta_bss *bss,
3378 char *current_ev, char *end_buf)
3380 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3381 struct iw_event iwe;
3383 if (time_after(jiffies,
3384 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
3387 if (!(local->enabled_modes & (1 << bss->hw_mode)))
3390 memset(&iwe, 0, sizeof(iwe));
3391 iwe.cmd = SIOCGIWAP;
3392 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
3393 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
3394 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3397 memset(&iwe, 0, sizeof(iwe));
3398 iwe.cmd = SIOCGIWESSID;
3399 iwe.u.data.length = bss->ssid_len;
3400 iwe.u.data.flags = 1;
3401 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3404 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
3405 memset(&iwe, 0, sizeof(iwe));
3406 iwe.cmd = SIOCGIWMODE;
3407 if (bss->capability & WLAN_CAPABILITY_ESS)
3408 iwe.u.mode = IW_MODE_MASTER;
3410 iwe.u.mode = IW_MODE_ADHOC;
3411 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3415 memset(&iwe, 0, sizeof(iwe));
3416 iwe.cmd = SIOCGIWFREQ;
3417 iwe.u.freq.m = bss->channel;
3419 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3421 iwe.u.freq.m = bss->freq * 100000;
3423 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3426 memset(&iwe, 0, sizeof(iwe));
3428 iwe.u.qual.qual = bss->signal;
3429 iwe.u.qual.level = bss->rssi;
3430 iwe.u.qual.noise = bss->noise;
3431 iwe.u.qual.updated = local->wstats_flags;
3432 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3435 memset(&iwe, 0, sizeof(iwe));
3436 iwe.cmd = SIOCGIWENCODE;
3437 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
3438 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
3440 iwe.u.data.flags = IW_ENCODE_DISABLED;
3441 iwe.u.data.length = 0;
3442 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
3444 if (bss && bss->wpa_ie) {
3445 memset(&iwe, 0, sizeof(iwe));
3446 iwe.cmd = IWEVGENIE;
3447 iwe.u.data.length = bss->wpa_ie_len;
3448 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3452 if (bss && bss->rsn_ie) {
3453 memset(&iwe, 0, sizeof(iwe));
3454 iwe.cmd = IWEVGENIE;
3455 iwe.u.data.length = bss->rsn_ie_len;
3456 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3460 if (bss && bss->supp_rates_len > 0) {
3461 /* display all supported rates in readable format */
3462 char *p = current_ev + IW_EV_LCP_LEN;
3465 memset(&iwe, 0, sizeof(iwe));
3466 iwe.cmd = SIOCGIWRATE;
3467 /* Those two flags are ignored... */
3468 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
3470 for (i = 0; i < bss->supp_rates_len; i++) {
3471 iwe.u.bitrate.value = ((bss->supp_rates[i] &
3473 p = iwe_stream_add_value(current_ev, p,
3474 end_buf, &iwe, IW_EV_PARAM_LEN);
3481 buf = kmalloc(30, GFP_ATOMIC);
3483 memset(&iwe, 0, sizeof(iwe));
3484 iwe.cmd = IWEVCUSTOM;
3485 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
3486 iwe.u.data.length = strlen(buf);
3487 current_ev = iwe_stream_add_point(current_ev, end_buf,
3497 int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
3499 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3500 char *current_ev = buf;
3501 char *end_buf = buf + len;
3502 struct ieee80211_sta_bss *bss;
3504 spin_lock_bh(&local->sta_bss_lock);
3505 list_for_each_entry(bss, &local->sta_bss_list, list) {
3506 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
3507 spin_unlock_bh(&local->sta_bss_lock);
3510 current_ev = ieee80211_sta_scan_result(dev, bss, current_ev,
3513 spin_unlock_bh(&local->sta_bss_lock);
3514 return current_ev - buf;
3518 int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
3520 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3521 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3522 kfree(ifsta->extra_ie);
3524 ifsta->extra_ie = NULL;
3525 ifsta->extra_ie_len = 0;
3528 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
3529 if (!ifsta->extra_ie) {
3530 ifsta->extra_ie_len = 0;
3533 memcpy(ifsta->extra_ie, ie, len);
3534 ifsta->extra_ie_len = len;
3539 struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
3540 struct sk_buff *skb, u8 *bssid,
3543 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3544 struct sta_info *sta;
3545 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3546 DECLARE_MAC_BUF(mac);
3548 /* TODO: Could consider removing the least recently used entry and
3549 * allow new one to be added. */
3550 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
3551 if (net_ratelimit()) {
3552 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
3553 "entry %s\n", dev->name, print_mac(mac, addr));
3558 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
3559 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
3561 sta = sta_info_add(local, dev, addr, GFP_ATOMIC);
3565 sta->supp_rates = sdata->u.sta.supp_rates_bits;
3567 rate_control_rate_init(sta, local);
3569 return sta; /* caller will call sta_info_put() */
3573 int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
3575 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3576 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3578 printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
3581 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
3582 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
3585 ieee80211_send_deauth(dev, ifsta, reason);
3586 ieee80211_set_disassoc(dev, ifsta, 1);
3591 int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
3593 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3594 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3596 printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
3599 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
3602 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
3605 ieee80211_send_disassoc(dev, ifsta, reason);
3606 ieee80211_set_disassoc(dev, ifsta, 0);