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 <linux/rtnetlink.h>
28 #include <net/iw_handler.h>
29 #include <asm/types.h>
31 #include <net/mac80211.h>
32 #include "ieee80211_i.h"
37 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
38 #define IEEE80211_AUTH_MAX_TRIES 3
39 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
40 #define IEEE80211_ASSOC_MAX_TRIES 3
41 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
42 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
43 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
44 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
45 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
46 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
47 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
49 #define IEEE80211_PROBE_DELAY (HZ / 33)
50 #define IEEE80211_CHANNEL_TIME (HZ / 33)
51 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
52 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
53 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
54 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
55 #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
57 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
60 #define ERP_INFO_USE_PROTECTION BIT(1)
62 /* mgmt header + 1 byte action code */
63 #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
65 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
66 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
67 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
68 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
69 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
71 /* next values represent the buffer size for A-MPDU frame.
72 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
73 #define IEEE80211_MIN_AMPDU_BUF 0x8
74 #define IEEE80211_MAX_AMPDU_BUF 0x40
76 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
77 u8 *ssid, size_t ssid_len);
78 static struct ieee80211_sta_bss *
79 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
80 u8 *ssid, u8 ssid_len);
81 static void ieee80211_rx_bss_put(struct net_device *dev,
82 struct ieee80211_sta_bss *bss);
83 static int ieee80211_sta_find_ibss(struct net_device *dev,
84 struct ieee80211_if_sta *ifsta);
85 static int ieee80211_sta_wep_configured(struct net_device *dev);
86 static int ieee80211_sta_start_scan(struct net_device *dev,
87 u8 *ssid, size_t ssid_len);
88 static int ieee80211_sta_config_auth(struct net_device *dev,
89 struct ieee80211_if_sta *ifsta);
92 void ieee802_11_parse_elems(u8 *start, size_t len,
93 struct ieee802_11_elems *elems)
98 memset(elems, 0, sizeof(*elems));
113 elems->ssid_len = elen;
115 case WLAN_EID_SUPP_RATES:
116 elems->supp_rates = pos;
117 elems->supp_rates_len = elen;
119 case WLAN_EID_FH_PARAMS:
120 elems->fh_params = pos;
121 elems->fh_params_len = elen;
123 case WLAN_EID_DS_PARAMS:
124 elems->ds_params = pos;
125 elems->ds_params_len = elen;
127 case WLAN_EID_CF_PARAMS:
128 elems->cf_params = pos;
129 elems->cf_params_len = elen;
133 elems->tim_len = elen;
135 case WLAN_EID_IBSS_PARAMS:
136 elems->ibss_params = pos;
137 elems->ibss_params_len = elen;
139 case WLAN_EID_CHALLENGE:
140 elems->challenge = pos;
141 elems->challenge_len = elen;
144 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
146 /* Microsoft OUI (00:50:F2) */
148 /* OUI Type 1 - WPA IE */
150 elems->wpa_len = elen;
151 } else if (elen >= 5 && pos[3] == 2) {
153 elems->wmm_info = pos;
154 elems->wmm_info_len = elen;
155 } else if (pos[4] == 1) {
156 elems->wmm_param = pos;
157 elems->wmm_param_len = elen;
164 elems->rsn_len = elen;
166 case WLAN_EID_ERP_INFO:
167 elems->erp_info = pos;
168 elems->erp_info_len = elen;
170 case WLAN_EID_EXT_SUPP_RATES:
171 elems->ext_supp_rates = pos;
172 elems->ext_supp_rates_len = elen;
174 case WLAN_EID_HT_CAPABILITY:
175 elems->ht_cap_elem = pos;
176 elems->ht_cap_elem_len = elen;
178 case WLAN_EID_HT_EXTRA_INFO:
179 elems->ht_info_elem = pos;
180 elems->ht_info_elem_len = elen;
182 case WLAN_EID_MESH_ID:
183 elems->mesh_id = pos;
184 elems->mesh_id_len = elen;
186 case WLAN_EID_MESH_CONFIG:
187 elems->mesh_config = pos;
188 elems->mesh_config_len = elen;
190 case WLAN_EID_PEER_LINK:
191 elems->peer_link = pos;
192 elems->peer_link_len = elen;
196 elems->preq_len = elen;
200 elems->prep_len = elen;
204 elems->perr_len = elen;
216 static int ecw2cw(int ecw)
218 return (1 << ecw) - 1;
222 static void ieee80211_sta_def_wmm_params(struct net_device *dev,
223 struct ieee80211_sta_bss *bss,
226 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
227 struct ieee80211_local *local = sdata->local;
228 int i, have_higher_than_11mbit = 0;
231 /* cf. IEEE 802.11 9.2.12 */
232 for (i = 0; i < bss->supp_rates_len; i++)
233 if ((bss->supp_rates[i] & 0x7f) * 5 > 110)
234 have_higher_than_11mbit = 1;
236 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
237 have_higher_than_11mbit)
238 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
240 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
243 if (local->ops->conf_tx) {
244 struct ieee80211_tx_queue_params qparam;
246 memset(&qparam, 0, sizeof(qparam));
250 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
251 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
256 qparam.cw_max = 1023;
259 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
260 local->ops->conf_tx(local_to_hw(local),
261 i + IEEE80211_TX_QUEUE_DATA0,
265 /* IBSS uses different parameters for Beacon sending */
269 local->ops->conf_tx(local_to_hw(local),
270 IEEE80211_TX_QUEUE_BEACON, &qparam);
275 static void ieee80211_sta_wmm_params(struct net_device *dev,
276 struct ieee80211_if_sta *ifsta,
277 u8 *wmm_param, size_t wmm_param_len)
279 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
280 struct ieee80211_tx_queue_params params;
285 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
287 count = wmm_param[6] & 0x0f;
288 if (count == ifsta->wmm_last_param_set)
290 ifsta->wmm_last_param_set = count;
293 left = wmm_param_len - 8;
295 memset(¶ms, 0, sizeof(params));
297 if (!local->ops->conf_tx)
301 for (; left >= 4; left -= 4, pos += 4) {
302 int aci = (pos[0] >> 5) & 0x03;
303 int acm = (pos[0] >> 4) & 0x01;
308 queue = IEEE80211_TX_QUEUE_DATA3;
310 local->wmm_acm |= BIT(0) | BIT(3);
314 queue = IEEE80211_TX_QUEUE_DATA1;
316 local->wmm_acm |= BIT(4) | BIT(5);
320 queue = IEEE80211_TX_QUEUE_DATA0;
322 local->wmm_acm |= BIT(6) | BIT(7);
327 queue = IEEE80211_TX_QUEUE_DATA2;
329 local->wmm_acm |= BIT(1) | BIT(2);
334 params.aifs = pos[0] & 0x0f;
335 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
336 params.cw_min = ecw2cw(pos[1] & 0x0f);
337 params.txop = pos[2] | (pos[3] << 8);
338 #ifdef CONFIG_MAC80211_DEBUG
339 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
340 "cWmin=%d cWmax=%d txop=%d\n",
341 dev->name, queue, aci, acm, params.aifs, params.cw_min,
342 params.cw_max, params.txop);
344 /* TODO: handle ACM (block TX, fallback to next lowest allowed
346 if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) {
347 printk(KERN_DEBUG "%s: failed to set TX queue "
348 "parameters for queue %d\n", dev->name, queue);
354 static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata,
357 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
358 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
359 bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
360 bool use_short_preamble = (erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0;
361 DECLARE_MAC_BUF(mac);
364 if (use_protection != bss_conf->use_cts_prot) {
365 if (net_ratelimit()) {
366 printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
369 use_protection ? "enabled" : "disabled",
370 print_mac(mac, ifsta->bssid));
372 bss_conf->use_cts_prot = use_protection;
373 changed |= BSS_CHANGED_ERP_CTS_PROT;
376 if (use_short_preamble != bss_conf->use_short_preamble) {
377 if (net_ratelimit()) {
378 printk(KERN_DEBUG "%s: switched to %s barker preamble"
381 use_short_preamble ? "short" : "long",
382 print_mac(mac, ifsta->bssid));
384 bss_conf->use_short_preamble = use_short_preamble;
385 changed |= BSS_CHANGED_ERP_PREAMBLE;
391 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
392 struct ieee80211_ht_info *ht_info)
398 memset(ht_info, 0, sizeof(*ht_info));
401 u8 ampdu_info = ht_cap_ie->ampdu_params_info;
403 ht_info->ht_supported = 1;
404 ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info);
405 ht_info->ampdu_factor =
406 ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR;
407 ht_info->ampdu_density =
408 (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
409 memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16);
411 ht_info->ht_supported = 0;
416 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
417 struct ieee80211_ht_addt_info *ht_add_info_ie,
418 struct ieee80211_ht_bss_info *bss_info)
420 if (bss_info == NULL)
423 memset(bss_info, 0, sizeof(*bss_info));
425 if (ht_add_info_ie) {
427 op_mode = le16_to_cpu(ht_add_info_ie->operation_mode);
429 bss_info->primary_channel = ht_add_info_ie->control_chan;
430 bss_info->bss_cap = ht_add_info_ie->ht_param;
431 bss_info->bss_op_mode = (u8)(op_mode & 0xff);
437 static void ieee80211_sta_send_associnfo(struct net_device *dev,
438 struct ieee80211_if_sta *ifsta)
443 union iwreq_data wrqu;
445 if (!ifsta->assocreq_ies && !ifsta->assocresp_ies)
448 buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
449 ifsta->assocresp_ies_len), GFP_KERNEL);
453 len = sprintf(buf, "ASSOCINFO(");
454 if (ifsta->assocreq_ies) {
455 len += sprintf(buf + len, "ReqIEs=");
456 for (i = 0; i < ifsta->assocreq_ies_len; i++) {
457 len += sprintf(buf + len, "%02x",
458 ifsta->assocreq_ies[i]);
461 if (ifsta->assocresp_ies) {
462 if (ifsta->assocreq_ies)
463 len += sprintf(buf + len, " ");
464 len += sprintf(buf + len, "RespIEs=");
465 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
466 len += sprintf(buf + len, "%02x",
467 ifsta->assocresp_ies[i]);
470 len += sprintf(buf + len, ")");
472 if (len > IW_CUSTOM_MAX) {
473 len = sprintf(buf, "ASSOCRESPIE=");
474 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
475 len += sprintf(buf + len, "%02x",
476 ifsta->assocresp_ies[i]);
480 memset(&wrqu, 0, sizeof(wrqu));
481 wrqu.data.length = len;
482 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
488 static void ieee80211_set_associated(struct net_device *dev,
489 struct ieee80211_if_sta *ifsta,
492 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
493 struct ieee80211_local *local = sdata->local;
494 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
495 union iwreq_data wrqu;
496 u32 changed = BSS_CHANGED_ASSOC;
499 struct ieee80211_sta_bss *bss;
501 ifsta->flags |= IEEE80211_STA_ASSOCIATED;
503 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
506 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
507 conf->channel->center_freq,
508 ifsta->ssid, ifsta->ssid_len);
510 /* set timing information */
511 sdata->bss_conf.beacon_int = bss->beacon_int;
512 sdata->bss_conf.timestamp = bss->timestamp;
514 if (bss->has_erp_value)
515 changed |= ieee80211_handle_erp_ie(
516 sdata, bss->erp_value);
518 ieee80211_rx_bss_put(dev, bss);
521 if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
522 changed |= BSS_CHANGED_HT;
523 sdata->bss_conf.assoc_ht = 1;
524 sdata->bss_conf.ht_conf = &conf->ht_conf;
525 sdata->bss_conf.ht_bss_conf = &conf->ht_bss_conf;
528 netif_carrier_on(dev);
529 ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
530 memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
531 memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
532 ieee80211_sta_send_associnfo(dev, ifsta);
534 ieee80211_sta_tear_down_BA_sessions(dev, ifsta->bssid);
535 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
536 netif_carrier_off(dev);
537 ieee80211_reset_erp_info(dev);
539 sdata->bss_conf.assoc_ht = 0;
540 sdata->bss_conf.ht_conf = NULL;
541 sdata->bss_conf.ht_bss_conf = NULL;
543 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
545 ifsta->last_probe = jiffies;
546 ieee80211_led_assoc(local, assoc);
548 sdata->bss_conf.assoc = assoc;
549 ieee80211_bss_info_change_notify(sdata, changed);
550 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
551 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
554 static void ieee80211_set_disassoc(struct net_device *dev,
555 struct ieee80211_if_sta *ifsta, int deauth)
558 ifsta->auth_tries = 0;
559 ifsta->assoc_tries = 0;
560 ieee80211_set_associated(dev, ifsta, 0);
563 void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
566 struct ieee80211_sub_if_data *sdata;
567 struct ieee80211_tx_packet_data *pkt_data;
569 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
570 skb->dev = sdata->local->mdev;
571 skb_set_mac_header(skb, 0);
572 skb_set_network_header(skb, 0);
573 skb_set_transport_header(skb, 0);
575 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
576 memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
577 pkt_data->ifindex = sdata->dev->ifindex;
579 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
585 static void ieee80211_send_auth(struct net_device *dev,
586 struct ieee80211_if_sta *ifsta,
587 int transaction, u8 *extra, size_t extra_len,
590 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
592 struct ieee80211_mgmt *mgmt;
594 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
595 sizeof(*mgmt) + 6 + extra_len);
597 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
598 "frame\n", dev->name);
601 skb_reserve(skb, local->hw.extra_tx_headroom);
603 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
604 memset(mgmt, 0, 24 + 6);
605 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
606 IEEE80211_STYPE_AUTH);
608 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
609 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
610 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
611 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
612 mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
613 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
614 ifsta->auth_transaction = transaction + 1;
615 mgmt->u.auth.status_code = cpu_to_le16(0);
617 memcpy(skb_put(skb, extra_len), extra, extra_len);
619 ieee80211_sta_tx(dev, skb, encrypt);
623 static void ieee80211_authenticate(struct net_device *dev,
624 struct ieee80211_if_sta *ifsta)
626 DECLARE_MAC_BUF(mac);
629 if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
630 printk(KERN_DEBUG "%s: authentication with AP %s"
632 dev->name, print_mac(mac, ifsta->bssid));
633 ifsta->state = IEEE80211_DISABLED;
637 ifsta->state = IEEE80211_AUTHENTICATE;
638 printk(KERN_DEBUG "%s: authenticate with AP %s\n",
639 dev->name, print_mac(mac, ifsta->bssid));
641 ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
643 mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
647 static void ieee80211_send_assoc(struct net_device *dev,
648 struct ieee80211_if_sta *ifsta)
650 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
652 struct ieee80211_mgmt *mgmt;
656 struct ieee80211_sta_bss *bss;
658 struct ieee80211_supported_band *sband;
660 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
661 sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
664 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
665 "frame\n", dev->name);
668 skb_reserve(skb, local->hw.extra_tx_headroom);
670 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
672 capab = ifsta->capab;
674 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
675 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
676 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
677 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
678 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
681 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
682 local->hw.conf.channel->center_freq,
683 ifsta->ssid, ifsta->ssid_len);
685 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
686 capab |= WLAN_CAPABILITY_PRIVACY;
690 ieee80211_rx_bss_put(dev, bss);
693 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
695 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
696 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
697 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
699 if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
701 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
702 IEEE80211_STYPE_REASSOC_REQ);
703 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
704 mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1);
705 memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
709 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
710 IEEE80211_STYPE_ASSOC_REQ);
711 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
712 mgmt->u.assoc_req.listen_interval = cpu_to_le16(1);
716 ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
717 *pos++ = WLAN_EID_SSID;
718 *pos++ = ifsta->ssid_len;
719 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
721 len = sband->n_bitrates;
724 pos = skb_put(skb, len + 2);
725 *pos++ = WLAN_EID_SUPP_RATES;
727 for (i = 0; i < len; i++) {
728 int rate = sband->bitrates[i].bitrate;
729 *pos++ = (u8) (rate / 5);
732 if (sband->n_bitrates > len) {
733 pos = skb_put(skb, sband->n_bitrates - len + 2);
734 *pos++ = WLAN_EID_EXT_SUPP_RATES;
735 *pos++ = sband->n_bitrates - len;
736 for (i = len; i < sband->n_bitrates; i++) {
737 int rate = sband->bitrates[i].bitrate;
738 *pos++ = (u8) (rate / 5);
742 if (ifsta->extra_ie) {
743 pos = skb_put(skb, ifsta->extra_ie_len);
744 memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
747 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
748 pos = skb_put(skb, 9);
749 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
750 *pos++ = 7; /* len */
751 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
754 *pos++ = 2; /* WME */
755 *pos++ = 0; /* WME info */
756 *pos++ = 1; /* WME ver */
759 /* wmm support is a must to HT */
760 if (wmm && sband->ht_info.ht_supported) {
761 __le16 tmp = cpu_to_le16(sband->ht_info.cap);
762 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
763 *pos++ = WLAN_EID_HT_CAPABILITY;
764 *pos++ = sizeof(struct ieee80211_ht_cap);
765 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
766 memcpy(pos, &tmp, sizeof(u16));
768 /* TODO: needs a define here for << 2 */
769 *pos++ = sband->ht_info.ampdu_factor |
770 (sband->ht_info.ampdu_density << 2);
771 memcpy(pos, sband->ht_info.supp_mcs_set, 16);
774 kfree(ifsta->assocreq_ies);
775 ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
776 ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
777 if (ifsta->assocreq_ies)
778 memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
780 ieee80211_sta_tx(dev, skb, 0);
784 static void ieee80211_send_deauth(struct net_device *dev,
785 struct ieee80211_if_sta *ifsta, u16 reason)
787 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
789 struct ieee80211_mgmt *mgmt;
791 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
793 printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
794 "frame\n", dev->name);
797 skb_reserve(skb, local->hw.extra_tx_headroom);
799 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
801 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
802 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
803 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
804 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
805 IEEE80211_STYPE_DEAUTH);
807 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
809 ieee80211_sta_tx(dev, skb, 0);
813 static void ieee80211_send_disassoc(struct net_device *dev,
814 struct ieee80211_if_sta *ifsta, u16 reason)
816 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
818 struct ieee80211_mgmt *mgmt;
820 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
822 printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
823 "frame\n", dev->name);
826 skb_reserve(skb, local->hw.extra_tx_headroom);
828 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
830 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
831 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
832 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
833 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
834 IEEE80211_STYPE_DISASSOC);
836 mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
838 ieee80211_sta_tx(dev, skb, 0);
842 static int ieee80211_privacy_mismatch(struct net_device *dev,
843 struct ieee80211_if_sta *ifsta)
845 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
846 struct ieee80211_sta_bss *bss;
851 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
854 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
855 local->hw.conf.channel->center_freq,
856 ifsta->ssid, ifsta->ssid_len);
860 bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
861 wep_privacy = !!ieee80211_sta_wep_configured(dev);
862 privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
864 ieee80211_rx_bss_put(dev, bss);
866 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
873 static void ieee80211_associate(struct net_device *dev,
874 struct ieee80211_if_sta *ifsta)
876 DECLARE_MAC_BUF(mac);
878 ifsta->assoc_tries++;
879 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
880 printk(KERN_DEBUG "%s: association with AP %s"
882 dev->name, print_mac(mac, ifsta->bssid));
883 ifsta->state = IEEE80211_DISABLED;
887 ifsta->state = IEEE80211_ASSOCIATE;
888 printk(KERN_DEBUG "%s: associate with AP %s\n",
889 dev->name, print_mac(mac, ifsta->bssid));
890 if (ieee80211_privacy_mismatch(dev, ifsta)) {
891 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
892 "mixed-cell disabled - abort association\n", dev->name);
893 ifsta->state = IEEE80211_DISABLED;
897 ieee80211_send_assoc(dev, ifsta);
899 mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
903 static void ieee80211_associated(struct net_device *dev,
904 struct ieee80211_if_sta *ifsta)
906 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
907 struct sta_info *sta;
909 DECLARE_MAC_BUF(mac);
911 /* TODO: start monitoring current AP signal quality and number of
912 * missed beacons. Scan other channels every now and then and search
914 /* TODO: remove expired BSSes */
916 ifsta->state = IEEE80211_ASSOCIATED;
920 sta = sta_info_get(local, ifsta->bssid);
922 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
923 dev->name, print_mac(mac, ifsta->bssid));
927 if (time_after(jiffies,
928 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
929 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
930 printk(KERN_DEBUG "%s: No ProbeResp from "
931 "current AP %s - assume out of "
933 dev->name, print_mac(mac, ifsta->bssid));
935 sta_info_unlink(&sta);
937 ieee80211_send_probe_req(dev, ifsta->bssid,
939 local->scan_ssid_len);
940 ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
942 ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
943 if (time_after(jiffies, ifsta->last_probe +
944 IEEE80211_PROBE_INTERVAL)) {
945 ifsta->last_probe = jiffies;
946 ieee80211_send_probe_req(dev, ifsta->bssid,
956 sta_info_destroy(sta);
959 ifsta->state = IEEE80211_DISABLED;
960 ieee80211_set_associated(dev, ifsta, 0);
962 mod_timer(&ifsta->timer, jiffies +
963 IEEE80211_MONITORING_INTERVAL);
968 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
969 u8 *ssid, size_t ssid_len)
971 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
972 struct ieee80211_supported_band *sband;
974 struct ieee80211_mgmt *mgmt;
975 u8 *pos, *supp_rates, *esupp_rates = NULL;
978 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
980 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
981 "request\n", dev->name);
984 skb_reserve(skb, local->hw.extra_tx_headroom);
986 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
988 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
989 IEEE80211_STYPE_PROBE_REQ);
990 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
992 memcpy(mgmt->da, dst, ETH_ALEN);
993 memcpy(mgmt->bssid, dst, ETH_ALEN);
995 memset(mgmt->da, 0xff, ETH_ALEN);
996 memset(mgmt->bssid, 0xff, ETH_ALEN);
998 pos = skb_put(skb, 2 + ssid_len);
999 *pos++ = WLAN_EID_SSID;
1001 memcpy(pos, ssid, ssid_len);
1003 supp_rates = skb_put(skb, 2);
1004 supp_rates[0] = WLAN_EID_SUPP_RATES;
1006 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1008 for (i = 0; i < sband->n_bitrates; i++) {
1009 struct ieee80211_rate *rate = &sband->bitrates[i];
1011 pos = skb_put(skb, 1);
1013 } else if (supp_rates[1] == 8) {
1014 esupp_rates = skb_put(skb, 3);
1015 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
1017 pos = &esupp_rates[2];
1019 pos = skb_put(skb, 1);
1022 *pos = rate->bitrate / 5;
1025 ieee80211_sta_tx(dev, skb, 0);
1029 static int ieee80211_sta_wep_configured(struct net_device *dev)
1031 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1032 if (!sdata || !sdata->default_key ||
1033 sdata->default_key->conf.alg != ALG_WEP)
1039 static void ieee80211_auth_completed(struct net_device *dev,
1040 struct ieee80211_if_sta *ifsta)
1042 printk(KERN_DEBUG "%s: authenticated\n", dev->name);
1043 ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
1044 ieee80211_associate(dev, ifsta);
1048 static void ieee80211_auth_challenge(struct net_device *dev,
1049 struct ieee80211_if_sta *ifsta,
1050 struct ieee80211_mgmt *mgmt,
1054 struct ieee802_11_elems elems;
1056 printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
1057 pos = mgmt->u.auth.variable;
1058 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1059 if (!elems.challenge) {
1060 printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
1061 "frame\n", dev->name);
1064 ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
1065 elems.challenge_len + 2, 1);
1068 static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
1069 u8 dialog_token, u16 status, u16 policy,
1070 u16 buf_size, u16 timeout)
1072 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1073 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1074 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1075 struct sk_buff *skb;
1076 struct ieee80211_mgmt *mgmt;
1079 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1080 sizeof(mgmt->u.action.u.addba_resp));
1082 printk(KERN_DEBUG "%s: failed to allocate buffer "
1083 "for addba resp frame\n", dev->name);
1087 skb_reserve(skb, local->hw.extra_tx_headroom);
1088 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1089 memset(mgmt, 0, 24);
1090 memcpy(mgmt->da, da, ETH_ALEN);
1091 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1092 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1093 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1095 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1096 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1097 IEEE80211_STYPE_ACTION);
1099 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
1100 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1101 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
1102 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
1104 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
1105 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1106 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
1108 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
1109 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
1110 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
1112 ieee80211_sta_tx(dev, skb, 0);
1117 void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
1118 u16 tid, u8 dialog_token, u16 start_seq_num,
1119 u16 agg_size, u16 timeout)
1121 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1122 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1123 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1124 struct sk_buff *skb;
1125 struct ieee80211_mgmt *mgmt;
1128 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1129 sizeof(mgmt->u.action.u.addba_req));
1133 printk(KERN_ERR "%s: failed to allocate buffer "
1134 "for addba request frame\n", dev->name);
1137 skb_reserve(skb, local->hw.extra_tx_headroom);
1138 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1139 memset(mgmt, 0, 24);
1140 memcpy(mgmt->da, da, ETH_ALEN);
1141 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1142 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1143 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1145 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1147 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1148 IEEE80211_STYPE_ACTION);
1150 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
1152 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1153 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
1155 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
1156 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
1157 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1158 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
1160 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
1162 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
1163 mgmt->u.action.u.addba_req.start_seq_num =
1164 cpu_to_le16(start_seq_num << 4);
1166 ieee80211_sta_tx(dev, skb, 0);
1169 static void ieee80211_sta_process_addba_request(struct net_device *dev,
1170 struct ieee80211_mgmt *mgmt,
1173 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1174 struct ieee80211_hw *hw = &local->hw;
1175 struct ieee80211_conf *conf = &hw->conf;
1176 struct sta_info *sta;
1177 struct tid_ampdu_rx *tid_agg_rx;
1178 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
1180 int ret = -EOPNOTSUPP;
1181 DECLARE_MAC_BUF(mac);
1185 sta = sta_info_get(local, mgmt->sa);
1191 /* extract session parameters from addba request frame */
1192 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
1193 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
1195 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
1197 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1198 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
1199 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1200 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
1202 status = WLAN_STATUS_REQUEST_DECLINED;
1204 /* sanity check for incoming parameters:
1205 * check if configuration can support the BA policy
1206 * and if buffer size does not exceeds max value */
1207 if (((ba_policy != 1)
1208 && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
1209 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
1210 status = WLAN_STATUS_INVALID_QOS_PARAM;
1211 #ifdef CONFIG_MAC80211_HT_DEBUG
1212 if (net_ratelimit())
1213 printk(KERN_DEBUG "AddBA Req with bad params from "
1214 "%s on tid %u. policy %d, buffer size %d\n",
1215 print_mac(mac, mgmt->sa), tid, ba_policy,
1217 #endif /* CONFIG_MAC80211_HT_DEBUG */
1220 /* determine default buffer size */
1221 if (buf_size == 0) {
1222 struct ieee80211_supported_band *sband;
1224 sband = local->hw.wiphy->bands[conf->channel->band];
1225 buf_size = IEEE80211_MIN_AMPDU_BUF;
1226 buf_size = buf_size << sband->ht_info.ampdu_factor;
1230 /* examine state machine */
1231 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1233 if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
1234 #ifdef CONFIG_MAC80211_HT_DEBUG
1235 if (net_ratelimit())
1236 printk(KERN_DEBUG "unexpected AddBA Req from "
1238 print_mac(mac, mgmt->sa), tid);
1239 #endif /* CONFIG_MAC80211_HT_DEBUG */
1243 /* prepare A-MPDU MLME for Rx aggregation */
1244 sta->ampdu_mlme.tid_rx[tid] =
1245 kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
1246 if (!sta->ampdu_mlme.tid_rx[tid]) {
1247 if (net_ratelimit())
1248 printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
1253 sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
1254 sta_rx_agg_session_timer_expired;
1255 sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
1256 (unsigned long)&sta->timer_to_tid[tid];
1257 init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
1259 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
1261 /* prepare reordering buffer */
1262 tid_agg_rx->reorder_buf =
1263 kmalloc(buf_size * sizeof(struct sk_buf *), GFP_ATOMIC);
1264 if (!tid_agg_rx->reorder_buf) {
1265 if (net_ratelimit())
1266 printk(KERN_ERR "can not allocate reordering buffer "
1267 "to tid %d\n", tid);
1268 kfree(sta->ampdu_mlme.tid_rx[tid]);
1271 memset(tid_agg_rx->reorder_buf, 0,
1272 buf_size * sizeof(struct sk_buf *));
1274 if (local->ops->ampdu_action)
1275 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
1276 sta->addr, tid, &start_seq_num);
1277 #ifdef CONFIG_MAC80211_HT_DEBUG
1278 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
1279 #endif /* CONFIG_MAC80211_HT_DEBUG */
1282 kfree(tid_agg_rx->reorder_buf);
1284 sta->ampdu_mlme.tid_rx[tid] = NULL;
1288 /* change state and send addba resp */
1289 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
1290 tid_agg_rx->dialog_token = dialog_token;
1291 tid_agg_rx->ssn = start_seq_num;
1292 tid_agg_rx->head_seq_num = start_seq_num;
1293 tid_agg_rx->buf_size = buf_size;
1294 tid_agg_rx->timeout = timeout;
1295 tid_agg_rx->stored_mpdu_num = 0;
1296 status = WLAN_STATUS_SUCCESS;
1298 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1301 ieee80211_send_addba_resp(sta->sdata->dev, sta->addr, tid,
1302 dialog_token, status, 1, buf_size, timeout);
1306 static void ieee80211_sta_process_addba_resp(struct net_device *dev,
1307 struct ieee80211_mgmt *mgmt,
1310 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1311 struct ieee80211_hw *hw = &local->hw;
1312 struct sta_info *sta;
1319 sta = sta_info_get(local, mgmt->sa);
1325 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
1326 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1328 state = &sta->ampdu_mlme.tid_state_tx[tid];
1330 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1332 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1333 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1334 printk(KERN_DEBUG "state not HT_ADDBA_REQUESTED_MSK:"
1336 goto addba_resp_exit;
1339 if (mgmt->u.action.u.addba_resp.dialog_token !=
1340 sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
1341 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1342 #ifdef CONFIG_MAC80211_HT_DEBUG
1343 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1344 #endif /* CONFIG_MAC80211_HT_DEBUG */
1345 goto addba_resp_exit;
1348 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
1349 #ifdef CONFIG_MAC80211_HT_DEBUG
1350 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1351 #endif /* CONFIG_MAC80211_HT_DEBUG */
1352 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1353 == WLAN_STATUS_SUCCESS) {
1354 if (*state & HT_ADDBA_RECEIVED_MSK)
1355 printk(KERN_DEBUG "double addBA response\n");
1357 *state |= HT_ADDBA_RECEIVED_MSK;
1358 sta->ampdu_mlme.addba_req_num[tid] = 0;
1360 if (*state == HT_AGG_STATE_OPERATIONAL) {
1361 printk(KERN_DEBUG "Aggregation on for tid %d \n", tid);
1362 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1365 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1366 printk(KERN_DEBUG "recipient accepted agg: tid %d \n", tid);
1368 printk(KERN_DEBUG "recipient rejected agg: tid %d \n", tid);
1370 sta->ampdu_mlme.addba_req_num[tid]++;
1371 /* this will allow the state check in stop_BA_session */
1372 *state = HT_AGG_STATE_OPERATIONAL;
1373 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1374 ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
1375 WLAN_BACK_INITIATOR);
1382 void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
1383 u16 initiator, u16 reason_code)
1385 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1386 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1387 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1388 struct sk_buff *skb;
1389 struct ieee80211_mgmt *mgmt;
1392 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1393 sizeof(mgmt->u.action.u.delba));
1396 printk(KERN_ERR "%s: failed to allocate buffer "
1397 "for delba frame\n", dev->name);
1401 skb_reserve(skb, local->hw.extra_tx_headroom);
1402 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1403 memset(mgmt, 0, 24);
1404 memcpy(mgmt->da, da, ETH_ALEN);
1405 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1406 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1407 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1409 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1410 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1411 IEEE80211_STYPE_ACTION);
1413 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
1415 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1416 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1417 params = (u16)(initiator << 11); /* bit 11 initiator */
1418 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1420 mgmt->u.action.u.delba.params = cpu_to_le16(params);
1421 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1423 ieee80211_sta_tx(dev, skb, 0);
1426 void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1427 u16 initiator, u16 reason)
1429 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1430 struct ieee80211_hw *hw = &local->hw;
1431 struct sta_info *sta;
1433 DECLARE_MAC_BUF(mac);
1437 sta = sta_info_get(local, ra);
1443 /* check if TID is in operational state */
1444 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1445 if (sta->ampdu_mlme.tid_state_rx[tid]
1446 != HT_AGG_STATE_OPERATIONAL) {
1447 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1451 sta->ampdu_mlme.tid_state_rx[tid] =
1452 HT_AGG_STATE_REQ_STOP_BA_MSK |
1453 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
1454 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1456 /* stop HW Rx aggregation. ampdu_action existence
1457 * already verified in session init so we add the BUG_ON */
1458 BUG_ON(!local->ops->ampdu_action);
1460 #ifdef CONFIG_MAC80211_HT_DEBUG
1461 printk(KERN_DEBUG "Rx BA session stop requested for %s tid %u\n",
1462 print_mac(mac, ra), tid);
1463 #endif /* CONFIG_MAC80211_HT_DEBUG */
1465 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
1468 printk(KERN_DEBUG "HW problem - can not stop rx "
1469 "aggergation for tid %d\n", tid);
1471 /* shutdown timer has not expired */
1472 if (initiator != WLAN_BACK_TIMER)
1473 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
1475 /* check if this is a self generated aggregation halt */
1476 if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
1477 ieee80211_send_delba(dev, ra, tid, 0, reason);
1479 /* free the reordering buffer */
1480 for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
1481 if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
1482 /* release the reordered frames */
1483 dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
1484 sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
1485 sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
1488 /* free resources */
1489 kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
1490 kfree(sta->ampdu_mlme.tid_rx[tid]);
1491 sta->ampdu_mlme.tid_rx[tid] = NULL;
1492 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
1498 static void ieee80211_sta_process_delba(struct net_device *dev,
1499 struct ieee80211_mgmt *mgmt, size_t len)
1501 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1502 struct sta_info *sta;
1505 DECLARE_MAC_BUF(mac);
1509 sta = sta_info_get(local, mgmt->sa);
1515 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1516 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1517 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1519 #ifdef CONFIG_MAC80211_HT_DEBUG
1520 if (net_ratelimit())
1521 printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
1522 print_mac(mac, mgmt->sa),
1523 initiator ? "initiator" : "recipient", tid,
1524 mgmt->u.action.u.delba.reason_code);
1525 #endif /* CONFIG_MAC80211_HT_DEBUG */
1527 if (initiator == WLAN_BACK_INITIATOR)
1528 ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
1529 WLAN_BACK_INITIATOR, 0);
1530 else { /* WLAN_BACK_RECIPIENT */
1531 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1532 sta->ampdu_mlme.tid_state_tx[tid] =
1533 HT_AGG_STATE_OPERATIONAL;
1534 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1535 ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
1536 WLAN_BACK_RECIPIENT);
1542 * After sending add Block Ack request we activated a timer until
1543 * add Block Ack response will arrive from the recipient.
1544 * If this timer expires sta_addba_resp_timer_expired will be executed.
1546 void sta_addba_resp_timer_expired(unsigned long data)
1548 /* not an elegant detour, but there is no choice as the timer passes
1549 * only one argument, and both sta_info and TID are needed, so init
1550 * flow in sta_info_create gives the TID as data, while the timer_to_id
1551 * array gives the sta through container_of */
1552 u16 tid = *(int *)data;
1553 struct sta_info *temp_sta = container_of((void *)data,
1554 struct sta_info, timer_to_tid[tid]);
1556 struct ieee80211_local *local = temp_sta->local;
1557 struct ieee80211_hw *hw = &local->hw;
1558 struct sta_info *sta;
1563 sta = sta_info_get(local, temp_sta->addr);
1569 state = &sta->ampdu_mlme.tid_state_tx[tid];
1570 /* check if the TID waits for addBA response */
1571 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1572 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1573 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1574 *state = HT_AGG_STATE_IDLE;
1575 printk(KERN_DEBUG "timer expired on tid %d but we are not "
1576 "expecting addBA response there", tid);
1577 goto timer_expired_exit;
1580 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
1582 /* go through the state check in stop_BA_session */
1583 *state = HT_AGG_STATE_OPERATIONAL;
1584 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1585 ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
1586 WLAN_BACK_INITIATOR);
1593 * After accepting the AddBA Request we activated a timer,
1594 * resetting it after each frame that arrives from the originator.
1595 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1597 void sta_rx_agg_session_timer_expired(unsigned long data)
1599 /* not an elegant detour, but there is no choice as the timer passes
1600 * only one argument, and verious sta_info are needed here, so init
1601 * flow in sta_info_create gives the TID as data, while the timer_to_id
1602 * array gives the sta through container_of */
1603 u8 *ptid = (u8 *)data;
1604 u8 *timer_to_id = ptid - *ptid;
1605 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
1608 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
1609 ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr,
1610 (u16)*ptid, WLAN_BACK_TIMER,
1611 WLAN_REASON_QSTA_TIMEOUT);
1614 void ieee80211_sta_tear_down_BA_sessions(struct net_device *dev, u8 *addr)
1616 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1619 for (i = 0; i < STA_TID_NUM; i++) {
1620 ieee80211_stop_tx_ba_session(&local->hw, addr, i,
1621 WLAN_BACK_INITIATOR);
1622 ieee80211_sta_stop_rx_ba_session(dev, addr, i,
1623 WLAN_BACK_RECIPIENT,
1624 WLAN_REASON_QSTA_LEAVE_QBSS);
1628 static void ieee80211_rx_mgmt_auth(struct net_device *dev,
1629 struct ieee80211_if_sta *ifsta,
1630 struct ieee80211_mgmt *mgmt,
1633 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1634 u16 auth_alg, auth_transaction, status_code;
1635 DECLARE_MAC_BUF(mac);
1637 if (ifsta->state != IEEE80211_AUTHENTICATE &&
1638 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
1639 printk(KERN_DEBUG "%s: authentication frame received from "
1640 "%s, but not in authenticate state - ignored\n",
1641 dev->name, print_mac(mac, mgmt->sa));
1646 printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
1647 "received from %s - ignored\n",
1648 dev->name, len, print_mac(mac, mgmt->sa));
1652 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
1653 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1654 printk(KERN_DEBUG "%s: authentication frame received from "
1655 "unknown AP (SA=%s BSSID=%s) - "
1656 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1657 print_mac(mac, mgmt->bssid));
1661 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
1662 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
1663 printk(KERN_DEBUG "%s: authentication frame received from "
1664 "unknown BSSID (SA=%s BSSID=%s) - "
1665 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1666 print_mac(mac, mgmt->bssid));
1670 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1671 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1672 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1674 printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d "
1675 "transaction=%d status=%d)\n",
1676 dev->name, print_mac(mac, mgmt->sa), auth_alg,
1677 auth_transaction, status_code);
1679 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
1680 /* IEEE 802.11 standard does not require authentication in IBSS
1681 * networks and most implementations do not seem to use it.
1682 * However, try to reply to authentication attempts if someone
1683 * has actually implemented this.
1684 * TODO: Could implement shared key authentication. */
1685 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
1686 printk(KERN_DEBUG "%s: unexpected IBSS authentication "
1687 "frame (alg=%d transaction=%d)\n",
1688 dev->name, auth_alg, auth_transaction);
1691 ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
1694 if (auth_alg != ifsta->auth_alg ||
1695 auth_transaction != ifsta->auth_transaction) {
1696 printk(KERN_DEBUG "%s: unexpected authentication frame "
1697 "(alg=%d transaction=%d)\n",
1698 dev->name, auth_alg, auth_transaction);
1702 if (status_code != WLAN_STATUS_SUCCESS) {
1703 printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
1704 "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
1705 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1707 const int num_algs = ARRAY_SIZE(algs);
1709 algs[0] = algs[1] = algs[2] = 0xff;
1710 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1711 algs[0] = WLAN_AUTH_OPEN;
1712 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1713 algs[1] = WLAN_AUTH_SHARED_KEY;
1714 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1715 algs[2] = WLAN_AUTH_LEAP;
1716 if (ifsta->auth_alg == WLAN_AUTH_OPEN)
1718 else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
1722 for (i = 0; i < num_algs; i++) {
1724 if (pos >= num_algs)
1726 if (algs[pos] == ifsta->auth_alg ||
1729 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1730 !ieee80211_sta_wep_configured(dev))
1732 ifsta->auth_alg = algs[pos];
1733 printk(KERN_DEBUG "%s: set auth_alg=%d for "
1735 dev->name, ifsta->auth_alg);
1742 switch (ifsta->auth_alg) {
1743 case WLAN_AUTH_OPEN:
1744 case WLAN_AUTH_LEAP:
1745 ieee80211_auth_completed(dev, ifsta);
1747 case WLAN_AUTH_SHARED_KEY:
1748 if (ifsta->auth_transaction == 4)
1749 ieee80211_auth_completed(dev, ifsta);
1751 ieee80211_auth_challenge(dev, ifsta, mgmt, len);
1757 static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
1758 struct ieee80211_if_sta *ifsta,
1759 struct ieee80211_mgmt *mgmt,
1763 DECLARE_MAC_BUF(mac);
1766 printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
1767 "received from %s - ignored\n",
1768 dev->name, len, print_mac(mac, mgmt->sa));
1772 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1773 printk(KERN_DEBUG "%s: deauthentication frame received from "
1774 "unknown AP (SA=%s BSSID=%s) - "
1775 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1776 print_mac(mac, mgmt->bssid));
1780 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1782 printk(KERN_DEBUG "%s: RX deauthentication from %s"
1784 dev->name, print_mac(mac, mgmt->sa), reason_code);
1786 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) {
1787 printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
1790 if (ifsta->state == IEEE80211_AUTHENTICATE ||
1791 ifsta->state == IEEE80211_ASSOCIATE ||
1792 ifsta->state == IEEE80211_ASSOCIATED) {
1793 ifsta->state = IEEE80211_AUTHENTICATE;
1794 mod_timer(&ifsta->timer, jiffies +
1795 IEEE80211_RETRY_AUTH_INTERVAL);
1798 ieee80211_set_disassoc(dev, ifsta, 1);
1799 ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
1803 static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
1804 struct ieee80211_if_sta *ifsta,
1805 struct ieee80211_mgmt *mgmt,
1809 DECLARE_MAC_BUF(mac);
1812 printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
1813 "received from %s - ignored\n",
1814 dev->name, len, print_mac(mac, mgmt->sa));
1818 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1819 printk(KERN_DEBUG "%s: disassociation frame received from "
1820 "unknown AP (SA=%s BSSID=%s) - "
1821 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1822 print_mac(mac, mgmt->bssid));
1826 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1828 printk(KERN_DEBUG "%s: RX disassociation from %s"
1830 dev->name, print_mac(mac, mgmt->sa), reason_code);
1832 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
1833 printk(KERN_DEBUG "%s: disassociated\n", dev->name);
1835 if (ifsta->state == IEEE80211_ASSOCIATED) {
1836 ifsta->state = IEEE80211_ASSOCIATE;
1837 mod_timer(&ifsta->timer, jiffies +
1838 IEEE80211_RETRY_AUTH_INTERVAL);
1841 ieee80211_set_disassoc(dev, ifsta, 0);
1845 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1846 struct ieee80211_if_sta *ifsta,
1847 struct ieee80211_mgmt *mgmt,
1851 struct ieee80211_local *local = sdata->local;
1852 struct net_device *dev = sdata->dev;
1853 struct ieee80211_supported_band *sband;
1854 struct sta_info *sta;
1855 u64 rates, basic_rates;
1856 u16 capab_info, status_code, aid;
1857 struct ieee802_11_elems elems;
1858 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
1861 DECLARE_MAC_BUF(mac);
1862 bool have_higher_than_11mbit = false;
1864 /* AssocResp and ReassocResp have identical structure, so process both
1865 * of them in this function. */
1867 if (ifsta->state != IEEE80211_ASSOCIATE) {
1868 printk(KERN_DEBUG "%s: association frame received from "
1869 "%s, but not in associate state - ignored\n",
1870 dev->name, print_mac(mac, mgmt->sa));
1875 printk(KERN_DEBUG "%s: too short (%zd) association frame "
1876 "received from %s - ignored\n",
1877 dev->name, len, print_mac(mac, mgmt->sa));
1881 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1882 printk(KERN_DEBUG "%s: association frame received from "
1883 "unknown AP (SA=%s BSSID=%s) - "
1884 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1885 print_mac(mac, mgmt->bssid));
1889 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1890 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1891 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1893 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
1894 "status=%d aid=%d)\n",
1895 dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
1896 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1898 if (status_code != WLAN_STATUS_SUCCESS) {
1899 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1900 dev->name, status_code);
1901 /* if this was a reassociation, ensure we try a "full"
1902 * association next time. This works around some broken APs
1903 * which do not correctly reject reassociation requests. */
1904 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1908 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1909 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1910 "set\n", dev->name, aid);
1911 aid &= ~(BIT(15) | BIT(14));
1913 pos = mgmt->u.assoc_resp.variable;
1914 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1916 if (!elems.supp_rates) {
1917 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1922 printk(KERN_DEBUG "%s: associated\n", dev->name);
1924 ifsta->ap_capab = capab_info;
1926 kfree(ifsta->assocresp_ies);
1927 ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1928 ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
1929 if (ifsta->assocresp_ies)
1930 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
1934 /* Add STA entry for the AP */
1935 sta = sta_info_get(local, ifsta->bssid);
1937 struct ieee80211_sta_bss *bss;
1940 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
1942 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1943 " the AP\n", dev->name);
1947 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
1948 local->hw.conf.channel->center_freq,
1949 ifsta->ssid, ifsta->ssid_len);
1951 sta->last_rssi = bss->rssi;
1952 sta->last_signal = bss->signal;
1953 sta->last_noise = bss->noise;
1954 ieee80211_rx_bss_put(dev, bss);
1957 err = sta_info_insert(sta);
1959 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1960 " the AP (error %d)\n", dev->name, err);
1967 * FIXME: Do we really need to update the sta_info's information here?
1968 * We already know about the AP (we found it in our list) so it
1969 * should already be filled with the right info, no?
1970 * As is stands, all this is racy because typically we assume
1971 * the information that is filled in here (except flags) doesn't
1972 * change while a STA structure is alive. As such, it should move
1973 * to between the sta_info_alloc() and sta_info_insert() above.
1976 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1977 WLAN_STA_AUTHORIZED;
1981 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1983 for (i = 0; i < elems.supp_rates_len; i++) {
1984 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1987 have_higher_than_11mbit = true;
1989 for (j = 0; j < sband->n_bitrates; j++) {
1990 if (sband->bitrates[j].bitrate == rate)
1992 if (elems.supp_rates[i] & 0x80)
1993 basic_rates |= BIT(j);
1997 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1998 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
2001 have_higher_than_11mbit = true;
2003 for (j = 0; j < sband->n_bitrates; j++) {
2004 if (sband->bitrates[j].bitrate == rate)
2006 if (elems.ext_supp_rates[i] & 0x80)
2007 basic_rates |= BIT(j);
2011 sta->supp_rates[local->hw.conf.channel->band] = rates;
2012 sdata->basic_rates = basic_rates;
2014 /* cf. IEEE 802.11 9.2.12 */
2015 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
2016 have_higher_than_11mbit)
2017 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
2019 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
2021 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param) {
2022 struct ieee80211_ht_bss_info bss_info;
2023 ieee80211_ht_cap_ie_to_ht_info(
2024 (struct ieee80211_ht_cap *)
2025 elems.ht_cap_elem, &sta->ht_info);
2026 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2027 (struct ieee80211_ht_addt_info *)
2028 elems.ht_info_elem, &bss_info);
2029 ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info);
2032 rate_control_rate_init(sta, local);
2034 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
2035 sta->flags |= WLAN_STA_WME;
2037 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2038 elems.wmm_param_len);
2042 /* set AID and assoc capability,
2043 * ieee80211_set_associated() will tell the driver */
2044 bss_conf->aid = aid;
2045 bss_conf->assoc_capability = capab_info;
2046 ieee80211_set_associated(dev, ifsta, 1);
2048 ieee80211_associated(dev, ifsta);
2052 /* Caller must hold local->sta_bss_lock */
2053 static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
2054 struct ieee80211_sta_bss *bss)
2056 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2059 if (bss_mesh_cfg(bss))
2060 hash_idx = mesh_id_hash(bss_mesh_id(bss),
2061 bss_mesh_id_len(bss));
2063 hash_idx = STA_HASH(bss->bssid);
2065 bss->hnext = local->sta_bss_hash[hash_idx];
2066 local->sta_bss_hash[hash_idx] = bss;
2070 /* Caller must hold local->sta_bss_lock */
2071 static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
2072 struct ieee80211_sta_bss *bss)
2074 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2075 struct ieee80211_sta_bss *b, *prev = NULL;
2076 b = local->sta_bss_hash[STA_HASH(bss->bssid)];
2080 local->sta_bss_hash[STA_HASH(bss->bssid)] =
2083 prev->hnext = bss->hnext;
2092 static struct ieee80211_sta_bss *
2093 ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
2094 u8 *ssid, u8 ssid_len)
2096 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2097 struct ieee80211_sta_bss *bss;
2099 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2102 atomic_inc(&bss->users);
2103 atomic_inc(&bss->users);
2104 memcpy(bss->bssid, bssid, ETH_ALEN);
2106 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
2107 memcpy(bss->ssid, ssid, ssid_len);
2108 bss->ssid_len = ssid_len;
2111 spin_lock_bh(&local->sta_bss_lock);
2112 /* TODO: order by RSSI? */
2113 list_add_tail(&bss->list, &local->sta_bss_list);
2114 __ieee80211_rx_bss_hash_add(dev, bss);
2115 spin_unlock_bh(&local->sta_bss_lock);
2119 static struct ieee80211_sta_bss *
2120 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
2121 u8 *ssid, u8 ssid_len)
2123 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2124 struct ieee80211_sta_bss *bss;
2126 spin_lock_bh(&local->sta_bss_lock);
2127 bss = local->sta_bss_hash[STA_HASH(bssid)];
2129 if (!bss_mesh_cfg(bss) &&
2130 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
2131 bss->freq == freq &&
2132 bss->ssid_len == ssid_len &&
2133 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
2134 atomic_inc(&bss->users);
2139 spin_unlock_bh(&local->sta_bss_lock);
2143 #ifdef CONFIG_MAC80211_MESH
2144 static struct ieee80211_sta_bss *
2145 ieee80211_rx_mesh_bss_get(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2146 u8 *mesh_cfg, int freq)
2148 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2149 struct ieee80211_sta_bss *bss;
2151 spin_lock_bh(&local->sta_bss_lock);
2152 bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
2154 if (bss_mesh_cfg(bss) &&
2155 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
2156 bss->freq == freq &&
2157 mesh_id_len == bss->mesh_id_len &&
2158 (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
2160 atomic_inc(&bss->users);
2165 spin_unlock_bh(&local->sta_bss_lock);
2169 static struct ieee80211_sta_bss *
2170 ieee80211_rx_mesh_bss_add(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2171 u8 *mesh_cfg, int mesh_config_len, int freq)
2173 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2174 struct ieee80211_sta_bss *bss;
2176 if (mesh_config_len != MESH_CFG_LEN)
2179 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2183 bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
2184 if (!bss->mesh_cfg) {
2189 if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
2190 bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
2191 if (!bss->mesh_id) {
2192 kfree(bss->mesh_cfg);
2196 memcpy(bss->mesh_id, mesh_id, mesh_id_len);
2199 atomic_inc(&bss->users);
2200 atomic_inc(&bss->users);
2201 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
2202 bss->mesh_id_len = mesh_id_len;
2204 spin_lock_bh(&local->sta_bss_lock);
2205 /* TODO: order by RSSI? */
2206 list_add_tail(&bss->list, &local->sta_bss_list);
2207 __ieee80211_rx_bss_hash_add(dev, bss);
2208 spin_unlock_bh(&local->sta_bss_lock);
2213 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
2219 kfree(bss_mesh_id(bss));
2220 kfree(bss_mesh_cfg(bss));
2225 static void ieee80211_rx_bss_put(struct net_device *dev,
2226 struct ieee80211_sta_bss *bss)
2228 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2229 if (!atomic_dec_and_test(&bss->users))
2232 spin_lock_bh(&local->sta_bss_lock);
2233 __ieee80211_rx_bss_hash_del(dev, bss);
2234 list_del(&bss->list);
2235 spin_unlock_bh(&local->sta_bss_lock);
2236 ieee80211_rx_bss_free(bss);
2240 void ieee80211_rx_bss_list_init(struct net_device *dev)
2242 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2243 spin_lock_init(&local->sta_bss_lock);
2244 INIT_LIST_HEAD(&local->sta_bss_list);
2248 void ieee80211_rx_bss_list_deinit(struct net_device *dev)
2250 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2251 struct ieee80211_sta_bss *bss, *tmp;
2253 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
2254 ieee80211_rx_bss_put(dev, bss);
2258 static int ieee80211_sta_join_ibss(struct net_device *dev,
2259 struct ieee80211_if_sta *ifsta,
2260 struct ieee80211_sta_bss *bss)
2262 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2263 int res, rates, i, j;
2264 struct sk_buff *skb;
2265 struct ieee80211_mgmt *mgmt;
2266 struct ieee80211_tx_control control;
2267 struct rate_selection ratesel;
2269 struct ieee80211_sub_if_data *sdata;
2270 struct ieee80211_supported_band *sband;
2272 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2274 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2276 /* Remove possible STA entries from other IBSS networks. */
2277 sta_info_flush_delayed(sdata);
2279 if (local->ops->reset_tsf) {
2280 /* Reset own TSF to allow time synchronization work. */
2281 local->ops->reset_tsf(local_to_hw(local));
2283 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2284 res = ieee80211_if_config(dev);
2288 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2290 sdata->drop_unencrypted = bss->capability &
2291 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2293 res = ieee80211_set_freq(local, bss->freq);
2295 if (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS) {
2296 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
2297 "%d MHz\n", dev->name, local->oper_channel->center_freq);
2301 /* Set beacon template */
2302 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2307 skb_reserve(skb, local->hw.extra_tx_headroom);
2309 mgmt = (struct ieee80211_mgmt *)
2310 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2311 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2312 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2313 IEEE80211_STYPE_BEACON);
2314 memset(mgmt->da, 0xff, ETH_ALEN);
2315 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2316 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2317 mgmt->u.beacon.beacon_int =
2318 cpu_to_le16(local->hw.conf.beacon_int);
2319 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2321 pos = skb_put(skb, 2 + ifsta->ssid_len);
2322 *pos++ = WLAN_EID_SSID;
2323 *pos++ = ifsta->ssid_len;
2324 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2326 rates = bss->supp_rates_len;
2329 pos = skb_put(skb, 2 + rates);
2330 *pos++ = WLAN_EID_SUPP_RATES;
2332 memcpy(pos, bss->supp_rates, rates);
2334 if (bss->band == IEEE80211_BAND_2GHZ) {
2335 pos = skb_put(skb, 2 + 1);
2336 *pos++ = WLAN_EID_DS_PARAMS;
2338 *pos++ = ieee80211_frequency_to_channel(bss->freq);
2341 pos = skb_put(skb, 2 + 2);
2342 *pos++ = WLAN_EID_IBSS_PARAMS;
2344 /* FIX: set ATIM window based on scan results */
2348 if (bss->supp_rates_len > 8) {
2349 rates = bss->supp_rates_len - 8;
2350 pos = skb_put(skb, 2 + rates);
2351 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2353 memcpy(pos, &bss->supp_rates[8], rates);
2356 memset(&control, 0, sizeof(control));
2357 rate_control_get_rate(dev, sband, skb, &ratesel);
2358 if (!ratesel.rate) {
2359 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2360 "for IBSS beacon\n", dev->name);
2363 control.vif = &sdata->vif;
2364 control.tx_rate = ratesel.rate;
2365 if (sdata->bss_conf.use_short_preamble &&
2366 ratesel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2367 control.flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
2368 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2369 control.flags |= IEEE80211_TXCTL_NO_ACK;
2370 control.retry_limit = 1;
2372 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2373 if (ifsta->probe_resp) {
2374 mgmt = (struct ieee80211_mgmt *)
2375 ifsta->probe_resp->data;
2376 mgmt->frame_control =
2377 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2378 IEEE80211_STYPE_PROBE_RESP);
2380 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2381 "template for IBSS\n", dev->name);
2384 if (local->ops->beacon_update &&
2385 local->ops->beacon_update(local_to_hw(local),
2386 skb, &control) == 0) {
2387 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2388 "template\n", dev->name);
2393 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2394 for (i = 0; i < bss->supp_rates_len; i++) {
2395 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2396 for (j = 0; j < sband->n_bitrates; j++)
2397 if (sband->bitrates[j].bitrate == bitrate)
2400 ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
2402 ieee80211_sta_def_wmm_params(dev, bss, 1);
2406 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2407 "template\n", dev->name);
2411 ifsta->state = IEEE80211_IBSS_JOINED;
2412 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2414 ieee80211_rx_bss_put(dev, bss);
2419 u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
2420 struct ieee802_11_elems *elems,
2421 enum ieee80211_band band)
2423 struct ieee80211_supported_band *sband;
2424 struct ieee80211_rate *bitrates;
2428 sband = local->hw.wiphy->bands[band];
2432 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2435 bitrates = sband->bitrates;
2436 num_rates = sband->n_bitrates;
2438 for (i = 0; i < elems->supp_rates_len +
2439 elems->ext_supp_rates_len; i++) {
2442 if (i < elems->supp_rates_len)
2443 rate = elems->supp_rates[i];
2444 else if (elems->ext_supp_rates)
2445 rate = elems->ext_supp_rates
2446 [i - elems->supp_rates_len];
2447 own_rate = 5 * (rate & 0x7f);
2448 for (j = 0; j < num_rates; j++)
2449 if (bitrates[j].bitrate == own_rate)
2450 supp_rates |= BIT(j);
2456 static void ieee80211_rx_bss_info(struct net_device *dev,
2457 struct ieee80211_mgmt *mgmt,
2459 struct ieee80211_rx_status *rx_status,
2462 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2463 struct ieee802_11_elems elems;
2466 struct ieee80211_sta_bss *bss;
2467 struct sta_info *sta;
2468 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2469 u64 beacon_timestamp, rx_timestamp;
2470 struct ieee80211_channel *channel;
2471 DECLARE_MAC_BUF(mac);
2472 DECLARE_MAC_BUF(mac2);
2474 if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
2475 return; /* ignore ProbeResp to foreign address */
2478 printk(KERN_DEBUG "%s: RX %s from %s to %s\n",
2479 dev->name, beacon ? "Beacon" : "Probe Response",
2480 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da));
2483 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2487 beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
2488 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
2490 if (ieee80211_vif_is_mesh(&sdata->vif) && elems.mesh_id &&
2491 elems.mesh_config && mesh_matches_local(&elems, dev)) {
2492 u64 rates = ieee80211_sta_get_rates(local, &elems,
2495 mesh_neighbour_update(mgmt->sa, rates, dev,
2496 mesh_peer_accepts_plinks(&elems, dev));
2501 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
2502 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
2503 (sta = sta_info_get(local, mgmt->sa))) {
2505 u64 supp_rates = ieee80211_sta_get_rates(local, &elems,
2508 prev_rates = sta->supp_rates[rx_status->band];
2509 sta->supp_rates[rx_status->band] &= supp_rates;
2510 if (sta->supp_rates[rx_status->band] == 0) {
2511 /* No matching rates - this should not really happen.
2512 * Make sure that at least one rate is marked
2513 * supported to avoid issues with TX rate ctrl. */
2514 sta->supp_rates[rx_status->band] =
2515 sdata->u.sta.supp_rates_bits[rx_status->band];
2517 if (sta->supp_rates[rx_status->band] != prev_rates) {
2518 printk(KERN_DEBUG "%s: updated supp_rates set for "
2519 "%s based on beacon info (0x%llx & 0x%llx -> "
2521 dev->name, print_mac(mac, sta->addr),
2522 (unsigned long long) prev_rates,
2523 (unsigned long long) supp_rates,
2524 (unsigned long long) sta->supp_rates[rx_status->band]);
2530 if (elems.ds_params && elems.ds_params_len == 1)
2531 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
2533 freq = rx_status->freq;
2535 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2537 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2540 #ifdef CONFIG_MAC80211_MESH
2541 if (elems.mesh_config)
2542 bss = ieee80211_rx_mesh_bss_get(dev, elems.mesh_id,
2543 elems.mesh_id_len, elems.mesh_config, freq);
2546 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
2547 elems.ssid, elems.ssid_len);
2549 #ifdef CONFIG_MAC80211_MESH
2550 if (elems.mesh_config)
2551 bss = ieee80211_rx_mesh_bss_add(dev, elems.mesh_id,
2552 elems.mesh_id_len, elems.mesh_config,
2553 elems.mesh_config_len, freq);
2556 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
2557 elems.ssid, elems.ssid_len);
2562 /* TODO: order by RSSI? */
2563 spin_lock_bh(&local->sta_bss_lock);
2564 list_move_tail(&bss->list, &local->sta_bss_list);
2565 spin_unlock_bh(&local->sta_bss_lock);
2569 bss->band = rx_status->band;
2571 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
2572 bss->probe_resp && beacon) {
2574 * Do not allow beacon to override data from Probe Response. */
2575 ieee80211_rx_bss_put(dev, bss);
2579 /* save the ERP value so that it is available at association time */
2580 if (elems.erp_info && elems.erp_info_len >= 1) {
2581 bss->erp_value = elems.erp_info[0];
2582 bss->has_erp_value = 1;
2585 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
2586 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
2588 bss->supp_rates_len = 0;
2589 if (elems.supp_rates) {
2590 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2591 if (clen > elems.supp_rates_len)
2592 clen = elems.supp_rates_len;
2593 memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
2595 bss->supp_rates_len += clen;
2597 if (elems.ext_supp_rates) {
2598 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2599 if (clen > elems.ext_supp_rates_len)
2600 clen = elems.ext_supp_rates_len;
2601 memcpy(&bss->supp_rates[bss->supp_rates_len],
2602 elems.ext_supp_rates, clen);
2603 bss->supp_rates_len += clen;
2607 (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len ||
2608 memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
2610 bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
2612 memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
2613 bss->wpa_ie_len = elems.wpa_len + 2;
2615 bss->wpa_ie_len = 0;
2616 } else if (!elems.wpa && bss->wpa_ie) {
2619 bss->wpa_ie_len = 0;
2623 (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len ||
2624 memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
2626 bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
2628 memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
2629 bss->rsn_ie_len = elems.rsn_len + 2;
2631 bss->rsn_ie_len = 0;
2632 } else if (!elems.rsn && bss->rsn_ie) {
2635 bss->rsn_ie_len = 0;
2638 if (elems.wmm_param &&
2639 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len ||
2640 memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
2642 bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
2644 memcpy(bss->wmm_ie, elems.wmm_param - 2,
2645 elems.wmm_param_len + 2);
2646 bss->wmm_ie_len = elems.wmm_param_len + 2;
2648 bss->wmm_ie_len = 0;
2649 } else if (!elems.wmm_param && bss->wmm_ie) {
2652 bss->wmm_ie_len = 0;
2654 if (elems.ht_cap_elem &&
2655 (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
2656 memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
2658 bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
2660 memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
2661 elems.ht_cap_elem_len + 2);
2662 bss->ht_ie_len = elems.ht_cap_elem_len + 2;
2665 } else if (!elems.ht_cap_elem && bss->ht_ie) {
2671 bss->timestamp = beacon_timestamp;
2672 bss->last_update = jiffies;
2673 bss->rssi = rx_status->ssi;
2674 bss->signal = rx_status->signal;
2675 bss->noise = rx_status->noise;
2679 /* check if we need to merge IBSS */
2680 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
2681 !local->sta_sw_scanning && !local->sta_hw_scanning &&
2682 bss->capability & WLAN_CAPABILITY_IBSS &&
2683 bss->freq == local->oper_channel->center_freq &&
2684 elems.ssid_len == sdata->u.sta.ssid_len &&
2685 memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) == 0) {
2686 if (rx_status->flag & RX_FLAG_TSFT) {
2687 /* in order for correct IBSS merging we need mactime
2689 * since mactime is defined as the time the first data
2690 * symbol of the frame hits the PHY, and the timestamp
2691 * of the beacon is defined as "the time that the data
2692 * symbol containing the first bit of the timestamp is
2693 * transmitted to the PHY plus the transmitting STA’s
2694 * delays through its local PHY from the MAC-PHY
2695 * interface to its interface with the WM"
2696 * (802.11 11.1.2) - equals the time this bit arrives at
2697 * the receiver - we have to take into account the
2698 * offset between the two.
2699 * e.g: at 1 MBit that means mactime is 192 usec earlier
2700 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2702 int rate = local->hw.wiphy->bands[rx_status->band]->
2703 bitrates[rx_status->rate_idx].bitrate;
2704 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
2705 } else if (local && local->ops && local->ops->get_tsf)
2706 /* second best option: get current TSF */
2707 rx_timestamp = local->ops->get_tsf(local_to_hw(local));
2709 /* can't merge without knowing the TSF */
2710 rx_timestamp = -1LLU;
2711 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2712 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
2713 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2714 print_mac(mac, mgmt->sa),
2715 print_mac(mac2, mgmt->bssid),
2716 (unsigned long long)rx_timestamp,
2717 (unsigned long long)beacon_timestamp,
2718 (unsigned long long)(rx_timestamp - beacon_timestamp),
2720 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2721 if (beacon_timestamp > rx_timestamp) {
2722 #ifndef CONFIG_MAC80211_IBSS_DEBUG
2723 if (net_ratelimit())
2725 printk(KERN_DEBUG "%s: beacon TSF higher than "
2726 "local TSF - IBSS merge with BSSID %s\n",
2727 dev->name, print_mac(mac, mgmt->bssid));
2728 ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
2729 ieee80211_ibss_add_sta(dev, NULL,
2730 mgmt->bssid, mgmt->sa);
2734 ieee80211_rx_bss_put(dev, bss);
2738 static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
2739 struct ieee80211_mgmt *mgmt,
2741 struct ieee80211_rx_status *rx_status)
2743 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
2747 static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
2748 struct ieee80211_mgmt *mgmt,
2750 struct ieee80211_rx_status *rx_status)
2752 struct ieee80211_sub_if_data *sdata;
2753 struct ieee80211_if_sta *ifsta;
2755 struct ieee802_11_elems elems;
2756 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2757 struct ieee80211_conf *conf = &local->hw.conf;
2760 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
2762 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2763 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
2765 ifsta = &sdata->u.sta;
2767 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
2768 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
2771 /* Process beacon from the current BSS */
2772 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2776 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
2778 if (elems.erp_info && elems.erp_info_len >= 1)
2779 changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
2781 if (elems.ht_cap_elem && elems.ht_info_elem &&
2782 elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
2783 struct ieee80211_ht_bss_info bss_info;
2785 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2786 (struct ieee80211_ht_addt_info *)
2787 elems.ht_info_elem, &bss_info);
2788 changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf,
2792 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
2793 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2794 elems.wmm_param_len);
2797 ieee80211_bss_info_change_notify(sdata, changed);
2801 static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
2802 struct ieee80211_if_sta *ifsta,
2803 struct ieee80211_mgmt *mgmt,
2805 struct ieee80211_rx_status *rx_status)
2807 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2808 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2810 struct sk_buff *skb;
2811 struct ieee80211_mgmt *resp;
2813 DECLARE_MAC_BUF(mac);
2814 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2815 DECLARE_MAC_BUF(mac2);
2816 DECLARE_MAC_BUF(mac3);
2819 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
2820 ifsta->state != IEEE80211_IBSS_JOINED ||
2821 len < 24 + 2 || !ifsta->probe_resp)
2824 if (local->ops->tx_last_beacon)
2825 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
2829 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2830 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
2831 "%s (tx_last_beacon=%d)\n",
2832 dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
2833 print_mac(mac3, mgmt->bssid), tx_last_beacon);
2834 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2836 if (!tx_last_beacon)
2839 if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
2840 memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
2843 end = ((u8 *) mgmt) + len;
2844 pos = mgmt->u.probe_req.variable;
2845 if (pos[0] != WLAN_EID_SSID ||
2846 pos + 2 + pos[1] > end) {
2847 if (net_ratelimit()) {
2848 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
2850 dev->name, print_mac(mac, mgmt->sa));
2855 (pos[1] != ifsta->ssid_len ||
2856 memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
2857 /* Ignore ProbeReq for foreign SSID */
2861 /* Reply with ProbeResp */
2862 skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
2866 resp = (struct ieee80211_mgmt *) skb->data;
2867 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2868 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2869 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
2870 dev->name, print_mac(mac, resp->da));
2871 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2872 ieee80211_sta_tx(dev, skb, 0);
2875 static void ieee80211_rx_mgmt_action(struct net_device *dev,
2876 struct ieee80211_if_sta *ifsta,
2877 struct ieee80211_mgmt *mgmt,
2879 struct ieee80211_rx_status *rx_status)
2881 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2883 if (len < IEEE80211_MIN_ACTION_SIZE)
2886 switch (mgmt->u.action.category) {
2887 case WLAN_CATEGORY_BACK:
2888 switch (mgmt->u.action.u.addba_req.action_code) {
2889 case WLAN_ACTION_ADDBA_REQ:
2890 if (len < (IEEE80211_MIN_ACTION_SIZE +
2891 sizeof(mgmt->u.action.u.addba_req)))
2893 ieee80211_sta_process_addba_request(dev, mgmt, len);
2895 case WLAN_ACTION_ADDBA_RESP:
2896 if (len < (IEEE80211_MIN_ACTION_SIZE +
2897 sizeof(mgmt->u.action.u.addba_resp)))
2899 ieee80211_sta_process_addba_resp(dev, mgmt, len);
2901 case WLAN_ACTION_DELBA:
2902 if (len < (IEEE80211_MIN_ACTION_SIZE +
2903 sizeof(mgmt->u.action.u.delba)))
2905 ieee80211_sta_process_delba(dev, mgmt, len);
2908 if (net_ratelimit())
2909 printk(KERN_DEBUG "%s: Rx unknown A-MPDU action\n",
2914 case PLINK_CATEGORY:
2915 if (ieee80211_vif_is_mesh(&sdata->vif))
2916 mesh_rx_plink_frame(dev, mgmt, len, rx_status);
2918 case MESH_PATH_SEL_CATEGORY:
2919 if (ieee80211_vif_is_mesh(&sdata->vif))
2920 mesh_rx_path_sel_frame(dev, mgmt, len);
2923 if (net_ratelimit())
2924 printk(KERN_DEBUG "%s: Rx unknown action frame - "
2925 "category=%d\n", dev->name, mgmt->u.action.category);
2930 void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
2931 struct ieee80211_rx_status *rx_status)
2933 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2934 struct ieee80211_sub_if_data *sdata;
2935 struct ieee80211_if_sta *ifsta;
2936 struct ieee80211_mgmt *mgmt;
2942 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2943 ifsta = &sdata->u.sta;
2945 mgmt = (struct ieee80211_mgmt *) skb->data;
2946 fc = le16_to_cpu(mgmt->frame_control);
2948 switch (fc & IEEE80211_FCTL_STYPE) {
2949 case IEEE80211_STYPE_PROBE_REQ:
2950 case IEEE80211_STYPE_PROBE_RESP:
2951 case IEEE80211_STYPE_BEACON:
2952 case IEEE80211_STYPE_ACTION:
2953 memcpy(skb->cb, rx_status, sizeof(*rx_status));
2954 case IEEE80211_STYPE_AUTH:
2955 case IEEE80211_STYPE_ASSOC_RESP:
2956 case IEEE80211_STYPE_REASSOC_RESP:
2957 case IEEE80211_STYPE_DEAUTH:
2958 case IEEE80211_STYPE_DISASSOC:
2959 skb_queue_tail(&ifsta->skb_queue, skb);
2960 queue_work(local->hw.workqueue, &ifsta->work);
2963 printk(KERN_DEBUG "%s: received unknown management frame - "
2964 "stype=%d\n", dev->name,
2965 (fc & IEEE80211_FCTL_STYPE) >> 4);
2974 static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
2975 struct sk_buff *skb)
2977 struct ieee80211_rx_status *rx_status;
2978 struct ieee80211_sub_if_data *sdata;
2979 struct ieee80211_if_sta *ifsta;
2980 struct ieee80211_mgmt *mgmt;
2983 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2984 ifsta = &sdata->u.sta;
2986 rx_status = (struct ieee80211_rx_status *) skb->cb;
2987 mgmt = (struct ieee80211_mgmt *) skb->data;
2988 fc = le16_to_cpu(mgmt->frame_control);
2990 switch (fc & IEEE80211_FCTL_STYPE) {
2991 case IEEE80211_STYPE_PROBE_REQ:
2992 ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
2995 case IEEE80211_STYPE_PROBE_RESP:
2996 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
2998 case IEEE80211_STYPE_BEACON:
2999 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
3001 case IEEE80211_STYPE_AUTH:
3002 ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len);
3004 case IEEE80211_STYPE_ASSOC_RESP:
3005 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
3007 case IEEE80211_STYPE_REASSOC_RESP:
3008 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
3010 case IEEE80211_STYPE_DEAUTH:
3011 ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len);
3013 case IEEE80211_STYPE_DISASSOC:
3014 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
3016 case IEEE80211_STYPE_ACTION:
3017 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len, rx_status);
3026 ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
3027 struct ieee80211_rx_status *rx_status)
3029 struct ieee80211_mgmt *mgmt;
3033 return RX_DROP_UNUSABLE;
3035 mgmt = (struct ieee80211_mgmt *) skb->data;
3036 fc = le16_to_cpu(mgmt->frame_control);
3038 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
3042 return RX_DROP_MONITOR;
3044 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
3045 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
3046 ieee80211_rx_mgmt_probe_resp(dev, mgmt,
3047 skb->len, rx_status);
3050 } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
3051 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
3061 static int ieee80211_sta_active_ibss(struct net_device *dev)
3063 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3065 struct sta_info *sta;
3066 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3070 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3071 if (sta->sdata == sdata &&
3072 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
3085 static void ieee80211_sta_expire(struct net_device *dev, unsigned long exp_time)
3087 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3088 struct sta_info *sta, *tmp;
3089 LIST_HEAD(tmp_list);
3090 DECLARE_MAC_BUF(mac);
3091 unsigned long flags;
3093 spin_lock_irqsave(&local->sta_lock, flags);
3094 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
3095 if (time_after(jiffies, sta->last_rx + exp_time)) {
3096 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
3097 dev->name, print_mac(mac, sta->addr));
3098 __sta_info_unlink(&sta);
3100 list_add(&sta->list, &tmp_list);
3102 spin_unlock_irqrestore(&local->sta_lock, flags);
3104 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
3105 sta_info_destroy(sta);
3109 static void ieee80211_sta_merge_ibss(struct net_device *dev,
3110 struct ieee80211_if_sta *ifsta)
3112 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
3114 ieee80211_sta_expire(dev, IEEE80211_IBSS_INACTIVITY_LIMIT);
3115 if (ieee80211_sta_active_ibss(dev))
3118 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
3119 "IBSS networks with same SSID (merge)\n", dev->name);
3120 ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
3124 #ifdef CONFIG_MAC80211_MESH
3125 static void ieee80211_mesh_housekeeping(struct net_device *dev,
3126 struct ieee80211_if_sta *ifsta)
3128 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3131 ieee80211_sta_expire(dev, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
3132 mesh_path_expire(dev);
3134 free_plinks = mesh_plink_availables(sdata);
3135 if (free_plinks != sdata->u.sta.accepting_plinks)
3136 ieee80211_if_config_beacon(dev);
3138 mod_timer(&ifsta->timer, jiffies +
3139 IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
3143 void ieee80211_start_mesh(struct net_device *dev)
3145 struct ieee80211_if_sta *ifsta;
3146 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3147 ifsta = &sdata->u.sta;
3148 ifsta->state = IEEE80211_MESH_UP;
3149 ieee80211_sta_timer((unsigned long)sdata);
3154 void ieee80211_sta_timer(unsigned long data)
3156 struct ieee80211_sub_if_data *sdata =
3157 (struct ieee80211_sub_if_data *) data;
3158 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3159 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
3161 set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3162 queue_work(local->hw.workqueue, &ifsta->work);
3165 void ieee80211_sta_work(struct work_struct *work)
3167 struct ieee80211_sub_if_data *sdata =
3168 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
3169 struct net_device *dev = sdata->dev;
3170 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3171 struct ieee80211_if_sta *ifsta;
3172 struct sk_buff *skb;
3174 if (!netif_running(dev))
3177 if (local->sta_sw_scanning || local->sta_hw_scanning)
3180 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
3181 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
3182 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) {
3183 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
3184 "(type=%d)\n", dev->name, sdata->vif.type);
3187 ifsta = &sdata->u.sta;
3189 while ((skb = skb_dequeue(&ifsta->skb_queue)))
3190 ieee80211_sta_rx_queued_mgmt(dev, skb);
3192 #ifdef CONFIG_MAC80211_MESH
3193 if (ifsta->preq_queue_len &&
3195 ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
3196 mesh_path_start_discovery(dev);
3199 if (ifsta->state != IEEE80211_AUTHENTICATE &&
3200 ifsta->state != IEEE80211_ASSOCIATE &&
3201 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
3202 if (ifsta->scan_ssid_len)
3203 ieee80211_sta_start_scan(dev, ifsta->scan_ssid, ifsta->scan_ssid_len);
3205 ieee80211_sta_start_scan(dev, NULL, 0);
3209 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
3210 if (ieee80211_sta_config_auth(dev, ifsta))
3212 clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3213 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
3216 switch (ifsta->state) {
3217 case IEEE80211_DISABLED:
3219 case IEEE80211_AUTHENTICATE:
3220 ieee80211_authenticate(dev, ifsta);
3222 case IEEE80211_ASSOCIATE:
3223 ieee80211_associate(dev, ifsta);
3225 case IEEE80211_ASSOCIATED:
3226 ieee80211_associated(dev, ifsta);
3228 case IEEE80211_IBSS_SEARCH:
3229 ieee80211_sta_find_ibss(dev, ifsta);
3231 case IEEE80211_IBSS_JOINED:
3232 ieee80211_sta_merge_ibss(dev, ifsta);
3234 #ifdef CONFIG_MAC80211_MESH
3235 case IEEE80211_MESH_UP:
3236 ieee80211_mesh_housekeeping(dev, ifsta);
3240 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
3245 if (ieee80211_privacy_mismatch(dev, ifsta)) {
3246 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
3247 "mixed-cell disabled - disassociate\n", dev->name);
3249 ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
3250 ieee80211_set_disassoc(dev, ifsta, 0);
3255 static void ieee80211_sta_reset_auth(struct net_device *dev,
3256 struct ieee80211_if_sta *ifsta)
3258 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3260 if (local->ops->reset_tsf) {
3261 /* Reset own TSF to allow time synchronization work. */
3262 local->ops->reset_tsf(local_to_hw(local));
3265 ifsta->wmm_last_param_set = -1; /* allow any WMM update */
3268 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
3269 ifsta->auth_alg = WLAN_AUTH_OPEN;
3270 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
3271 ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
3272 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
3273 ifsta->auth_alg = WLAN_AUTH_LEAP;
3275 ifsta->auth_alg = WLAN_AUTH_OPEN;
3276 printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
3278 ifsta->auth_transaction = -1;
3279 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
3280 ifsta->auth_tries = ifsta->assoc_tries = 0;
3281 netif_carrier_off(dev);
3285 void ieee80211_sta_req_auth(struct net_device *dev,
3286 struct ieee80211_if_sta *ifsta)
3288 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3289 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3291 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
3294 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
3295 IEEE80211_STA_AUTO_BSSID_SEL)) &&
3296 (ifsta->flags & (IEEE80211_STA_SSID_SET |
3297 IEEE80211_STA_AUTO_SSID_SEL))) {
3298 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3299 queue_work(local->hw.workqueue, &ifsta->work);
3303 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
3304 const char *ssid, int ssid_len)
3306 int tmp, hidden_ssid;
3308 if (ssid_len == ifsta->ssid_len &&
3309 !memcmp(ifsta->ssid, ssid, ssid_len))
3312 if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
3318 if (ssid[tmp] != '\0') {
3324 if (hidden_ssid && ifsta->ssid_len == ssid_len)
3327 if (ssid_len == 1 && ssid[0] == ' ')
3333 static int ieee80211_sta_config_auth(struct net_device *dev,
3334 struct ieee80211_if_sta *ifsta)
3336 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3337 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3338 struct ieee80211_sta_bss *bss, *selected = NULL;
3339 int top_rssi = 0, freq;
3341 if (!(ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
3342 IEEE80211_STA_AUTO_BSSID_SEL | IEEE80211_STA_AUTO_CHANNEL_SEL))) {
3343 ifsta->state = IEEE80211_AUTHENTICATE;
3344 ieee80211_sta_reset_auth(dev, ifsta);
3348 spin_lock_bh(&local->sta_bss_lock);
3349 freq = local->oper_channel->center_freq;
3350 list_for_each_entry(bss, &local->sta_bss_list, list) {
3351 if (!(bss->capability & WLAN_CAPABILITY_ESS))
3354 if (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
3355 !!sdata->default_key)
3358 if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
3362 if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
3363 memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
3366 if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
3367 !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
3370 if (!selected || top_rssi < bss->rssi) {
3372 top_rssi = bss->rssi;
3376 atomic_inc(&selected->users);
3377 spin_unlock_bh(&local->sta_bss_lock);
3380 ieee80211_set_freq(local, selected->freq);
3381 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
3382 ieee80211_sta_set_ssid(dev, selected->ssid,
3383 selected->ssid_len);
3384 ieee80211_sta_set_bssid(dev, selected->bssid);
3385 ieee80211_sta_def_wmm_params(dev, selected, 0);
3386 ieee80211_rx_bss_put(dev, selected);
3387 ifsta->state = IEEE80211_AUTHENTICATE;
3388 ieee80211_sta_reset_auth(dev, ifsta);
3391 if (ifsta->state != IEEE80211_AUTHENTICATE) {
3392 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
3393 ieee80211_sta_start_scan(dev, NULL, 0);
3395 ieee80211_sta_start_scan(dev, ifsta->ssid,
3397 ifsta->state = IEEE80211_AUTHENTICATE;
3398 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3400 ifsta->state = IEEE80211_DISABLED;
3406 static int ieee80211_sta_create_ibss(struct net_device *dev,
3407 struct ieee80211_if_sta *ifsta)
3409 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3410 struct ieee80211_sta_bss *bss;
3411 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3412 struct ieee80211_supported_band *sband;
3413 u8 bssid[ETH_ALEN], *pos;
3415 DECLARE_MAC_BUF(mac);
3418 /* Easier testing, use fixed BSSID. */
3419 memset(bssid, 0xfe, ETH_ALEN);
3421 /* Generate random, not broadcast, locally administered BSSID. Mix in
3422 * own MAC address to make sure that devices that do not have proper
3423 * random number generator get different BSSID. */
3424 get_random_bytes(bssid, ETH_ALEN);
3425 for (i = 0; i < ETH_ALEN; i++)
3426 bssid[i] ^= dev->dev_addr[i];
3431 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
3432 dev->name, print_mac(mac, bssid));
3434 bss = ieee80211_rx_bss_add(dev, bssid,
3435 local->hw.conf.channel->center_freq,
3436 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
3440 bss->band = local->hw.conf.channel->band;
3441 sband = local->hw.wiphy->bands[bss->band];
3443 if (local->hw.conf.beacon_int == 0)
3444 local->hw.conf.beacon_int = 10000;
3445 bss->beacon_int = local->hw.conf.beacon_int;
3446 bss->last_update = jiffies;
3447 bss->capability = WLAN_CAPABILITY_IBSS;
3448 if (sdata->default_key) {
3449 bss->capability |= WLAN_CAPABILITY_PRIVACY;
3451 sdata->drop_unencrypted = 0;
3452 bss->supp_rates_len = sband->n_bitrates;
3453 pos = bss->supp_rates;
3454 for (i = 0; i < sband->n_bitrates; i++) {
3455 int rate = sband->bitrates[i].bitrate;
3456 *pos++ = (u8) (rate / 5);
3459 return ieee80211_sta_join_ibss(dev, ifsta, bss);
3463 static int ieee80211_sta_find_ibss(struct net_device *dev,
3464 struct ieee80211_if_sta *ifsta)
3466 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3467 struct ieee80211_sta_bss *bss;
3471 DECLARE_MAC_BUF(mac);
3472 DECLARE_MAC_BUF(mac2);
3474 if (ifsta->ssid_len == 0)
3477 active_ibss = ieee80211_sta_active_ibss(dev);
3478 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3479 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
3480 dev->name, active_ibss);
3481 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3482 spin_lock_bh(&local->sta_bss_lock);
3483 list_for_each_entry(bss, &local->sta_bss_list, list) {
3484 if (ifsta->ssid_len != bss->ssid_len ||
3485 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
3486 || !(bss->capability & WLAN_CAPABILITY_IBSS))
3488 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3489 printk(KERN_DEBUG " bssid=%s found\n",
3490 print_mac(mac, bss->bssid));
3491 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3492 memcpy(bssid, bss->bssid, ETH_ALEN);
3494 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
3497 spin_unlock_bh(&local->sta_bss_lock);
3499 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3500 printk(KERN_DEBUG " sta_find_ibss: selected %s current "
3501 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
3502 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3503 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
3504 (bss = ieee80211_rx_bss_get(dev, bssid,
3505 local->hw.conf.channel->center_freq,
3506 ifsta->ssid, ifsta->ssid_len))) {
3507 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
3508 " based on configured SSID\n",
3509 dev->name, print_mac(mac, bssid));
3510 return ieee80211_sta_join_ibss(dev, ifsta, bss);
3512 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3513 printk(KERN_DEBUG " did not try to join ibss\n");
3514 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3516 /* Selected IBSS not found in current scan results - try to scan */
3517 if (ifsta->state == IEEE80211_IBSS_JOINED &&
3518 !ieee80211_sta_active_ibss(dev)) {
3519 mod_timer(&ifsta->timer, jiffies +
3520 IEEE80211_IBSS_MERGE_INTERVAL);
3521 } else if (time_after(jiffies, local->last_scan_completed +
3522 IEEE80211_SCAN_INTERVAL)) {
3523 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
3524 "join\n", dev->name);
3525 return ieee80211_sta_req_scan(dev, ifsta->ssid,
3527 } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
3528 int interval = IEEE80211_SCAN_INTERVAL;
3530 if (time_after(jiffies, ifsta->ibss_join_req +
3531 IEEE80211_IBSS_JOIN_TIMEOUT)) {
3532 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
3533 (!(local->oper_channel->flags &
3534 IEEE80211_CHAN_NO_IBSS)))
3535 return ieee80211_sta_create_ibss(dev, ifsta);
3536 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
3537 printk(KERN_DEBUG "%s: IBSS not allowed on"
3538 " %d MHz\n", dev->name,
3539 local->hw.conf.channel->center_freq);
3542 /* No IBSS found - decrease scan interval and continue
3544 interval = IEEE80211_SCAN_INTERVAL_SLOW;
3547 ifsta->state = IEEE80211_IBSS_SEARCH;
3548 mod_timer(&ifsta->timer, jiffies + interval);
3556 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3558 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3559 struct ieee80211_if_sta *ifsta;
3561 if (len > IEEE80211_MAX_SSID_LEN)
3564 ifsta = &sdata->u.sta;
3566 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
3567 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
3568 memcpy(ifsta->ssid, ssid, len);
3569 memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
3570 ifsta->ssid_len = len;
3573 ifsta->flags |= IEEE80211_STA_SSID_SET;
3575 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
3576 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3577 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
3578 ifsta->ibss_join_req = jiffies;
3579 ifsta->state = IEEE80211_IBSS_SEARCH;
3580 return ieee80211_sta_find_ibss(dev, ifsta);
3586 int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
3588 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3589 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3590 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
3591 *len = ifsta->ssid_len;
3596 int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
3598 struct ieee80211_sub_if_data *sdata;
3599 struct ieee80211_if_sta *ifsta;
3602 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3603 ifsta = &sdata->u.sta;
3605 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
3606 memcpy(ifsta->bssid, bssid, ETH_ALEN);
3607 res = ieee80211_if_config(dev);
3609 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
3610 "the low-level driver\n", dev->name);
3615 if (is_valid_ether_addr(bssid))
3616 ifsta->flags |= IEEE80211_STA_BSSID_SET;
3618 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
3624 static void ieee80211_send_nullfunc(struct ieee80211_local *local,
3625 struct ieee80211_sub_if_data *sdata,
3628 struct sk_buff *skb;
3629 struct ieee80211_hdr *nullfunc;
3632 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
3634 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
3635 "frame\n", sdata->dev->name);
3638 skb_reserve(skb, local->hw.extra_tx_headroom);
3640 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
3641 memset(nullfunc, 0, 24);
3642 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
3643 IEEE80211_FCTL_TODS;
3645 fc |= IEEE80211_FCTL_PM;
3646 nullfunc->frame_control = cpu_to_le16(fc);
3647 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
3648 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
3649 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
3651 ieee80211_sta_tx(sdata->dev, skb, 0);
3655 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3657 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
3658 ieee80211_vif_is_mesh(&sdata->vif))
3659 ieee80211_sta_timer((unsigned long)sdata);
3662 void ieee80211_scan_completed(struct ieee80211_hw *hw)
3664 struct ieee80211_local *local = hw_to_local(hw);
3665 struct net_device *dev = local->scan_dev;
3666 struct ieee80211_sub_if_data *sdata;
3667 union iwreq_data wrqu;
3669 local->last_scan_completed = jiffies;
3670 memset(&wrqu, 0, sizeof(wrqu));
3671 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
3673 if (local->sta_hw_scanning) {
3674 local->sta_hw_scanning = 0;
3675 if (ieee80211_hw_config(local))
3676 printk(KERN_DEBUG "%s: failed to restore operational "
3677 "channel after scan\n", dev->name);
3678 /* Restart STA timer for HW scan case */
3680 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3681 ieee80211_restart_sta_timer(sdata);
3687 local->sta_sw_scanning = 0;
3688 if (ieee80211_hw_config(local))
3689 printk(KERN_DEBUG "%s: failed to restore operational "
3690 "channel after scan\n", dev->name);
3693 netif_tx_lock_bh(local->mdev);
3694 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
3695 local->ops->configure_filter(local_to_hw(local),
3696 FIF_BCN_PRBRESP_PROMISC,
3697 &local->filter_flags,
3698 local->mdev->mc_count,
3699 local->mdev->mc_list);
3701 netif_tx_unlock_bh(local->mdev);
3704 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3706 /* No need to wake the master device. */
3707 if (sdata->dev == local->mdev)
3710 /* Tell AP we're back */
3711 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3712 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
3713 ieee80211_send_nullfunc(local, sdata, 0);
3715 ieee80211_restart_sta_timer(sdata);
3717 netif_wake_queue(sdata->dev);
3722 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3723 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
3724 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3725 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
3726 (!ifsta->state == IEEE80211_IBSS_JOINED &&
3727 !ieee80211_sta_active_ibss(dev)))
3728 ieee80211_sta_find_ibss(dev, ifsta);
3731 EXPORT_SYMBOL(ieee80211_scan_completed);
3733 void ieee80211_sta_scan_work(struct work_struct *work)
3735 struct ieee80211_local *local =
3736 container_of(work, struct ieee80211_local, scan_work.work);
3737 struct net_device *dev = local->scan_dev;
3738 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3739 struct ieee80211_supported_band *sband;
3740 struct ieee80211_channel *chan;
3742 unsigned long next_delay = 0;
3744 if (!local->sta_sw_scanning)
3747 switch (local->scan_state) {
3748 case SCAN_SET_CHANNEL:
3750 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3751 * after we successfully scanned the last channel of the last
3752 * band (and the last band is supported by the hw)
3754 if (local->scan_band < IEEE80211_NUM_BANDS)
3755 sband = local->hw.wiphy->bands[local->scan_band];
3760 * If we are at an unsupported band and have more bands
3761 * left to scan, advance to the next supported one.
3763 while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
3765 sband = local->hw.wiphy->bands[local->scan_band];
3766 local->scan_channel_idx = 0;
3769 /* if no more bands/channels left, complete scan */
3770 if (!sband || local->scan_channel_idx >= sband->n_channels) {
3771 ieee80211_scan_completed(local_to_hw(local));
3775 chan = &sband->channels[local->scan_channel_idx];
3777 if (chan->flags & IEEE80211_CHAN_DISABLED ||
3778 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3779 chan->flags & IEEE80211_CHAN_NO_IBSS))
3783 local->scan_channel = chan;
3784 if (ieee80211_hw_config(local)) {
3785 printk(KERN_DEBUG "%s: failed to set freq to "
3786 "%d MHz for scan\n", dev->name,
3792 /* advance state machine to next channel/band */
3793 local->scan_channel_idx++;
3794 if (local->scan_channel_idx >= sband->n_channels) {
3796 * scan_band may end up == IEEE80211_NUM_BANDS, but
3797 * we'll catch that case above and complete the scan
3798 * if that is the case.
3801 local->scan_channel_idx = 0;
3807 next_delay = IEEE80211_PROBE_DELAY +
3808 usecs_to_jiffies(local->hw.channel_change_time);
3809 local->scan_state = SCAN_SEND_PROBE;
3811 case SCAN_SEND_PROBE:
3812 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3813 local->scan_state = SCAN_SET_CHANNEL;
3815 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
3817 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3818 local->scan_ssid_len);
3819 next_delay = IEEE80211_CHANNEL_TIME;
3823 if (local->sta_sw_scanning)
3824 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3829 static int ieee80211_sta_start_scan(struct net_device *dev,
3830 u8 *ssid, size_t ssid_len)
3832 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3833 struct ieee80211_sub_if_data *sdata;
3835 if (ssid_len > IEEE80211_MAX_SSID_LEN)
3838 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3839 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3842 * ScanType: ACTIVE, PASSIVE
3843 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3844 * a Probe frame during active scanning
3846 * MinChannelTime (>= ProbeDelay), in TU
3847 * MaxChannelTime: (>= MinChannelTime), in TU
3850 /* MLME-SCAN.confirm
3852 * ResultCode: SUCCESS, INVALID_PARAMETERS
3855 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3856 if (local->scan_dev == dev)
3861 if (local->ops->hw_scan) {
3862 int rc = local->ops->hw_scan(local_to_hw(local),
3865 local->sta_hw_scanning = 1;
3866 local->scan_dev = dev;
3871 local->sta_sw_scanning = 1;
3874 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3876 /* Don't stop the master interface, otherwise we can't transmit
3878 if (sdata->dev == local->mdev)
3881 netif_stop_queue(sdata->dev);
3882 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3883 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
3884 ieee80211_send_nullfunc(local, sdata, 1);
3889 local->scan_ssid_len = ssid_len;
3890 memcpy(local->scan_ssid, ssid, ssid_len);
3892 local->scan_ssid_len = 0;
3893 local->scan_state = SCAN_SET_CHANNEL;
3894 local->scan_channel_idx = 0;
3895 local->scan_band = IEEE80211_BAND_2GHZ;
3896 local->scan_dev = dev;
3898 netif_tx_lock_bh(local->mdev);
3899 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
3900 local->ops->configure_filter(local_to_hw(local),
3901 FIF_BCN_PRBRESP_PROMISC,
3902 &local->filter_flags,
3903 local->mdev->mc_count,
3904 local->mdev->mc_list);
3905 netif_tx_unlock_bh(local->mdev);
3907 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3908 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3909 IEEE80211_CHANNEL_TIME);
3915 int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
3917 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3918 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3919 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3921 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
3922 return ieee80211_sta_start_scan(dev, ssid, ssid_len);
3924 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3925 if (local->scan_dev == dev)
3930 ifsta->scan_ssid_len = ssid_len;
3932 memcpy(ifsta->scan_ssid, ssid, ssid_len);
3933 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
3934 queue_work(local->hw.workqueue, &ifsta->work);
3939 ieee80211_sta_scan_result(struct net_device *dev,
3940 struct ieee80211_sta_bss *bss,
3941 char *current_ev, char *end_buf)
3943 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3944 struct iw_event iwe;
3946 if (time_after(jiffies,
3947 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
3950 memset(&iwe, 0, sizeof(iwe));
3951 iwe.cmd = SIOCGIWAP;
3952 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
3953 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
3954 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3957 memset(&iwe, 0, sizeof(iwe));
3958 iwe.cmd = SIOCGIWESSID;
3959 if (bss_mesh_cfg(bss)) {
3960 iwe.u.data.length = bss_mesh_id_len(bss);
3961 iwe.u.data.flags = 1;
3962 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3965 iwe.u.data.length = bss->ssid_len;
3966 iwe.u.data.flags = 1;
3967 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3971 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
3972 || bss_mesh_cfg(bss)) {
3973 memset(&iwe, 0, sizeof(iwe));
3974 iwe.cmd = SIOCGIWMODE;
3975 if (bss_mesh_cfg(bss))
3976 iwe.u.mode = IW_MODE_MESH;
3977 else if (bss->capability & WLAN_CAPABILITY_ESS)
3978 iwe.u.mode = IW_MODE_MASTER;
3980 iwe.u.mode = IW_MODE_ADHOC;
3981 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3985 memset(&iwe, 0, sizeof(iwe));
3986 iwe.cmd = SIOCGIWFREQ;
3987 iwe.u.freq.m = bss->freq;
3989 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3992 memset(&iwe, 0, sizeof(iwe));
3993 iwe.cmd = SIOCGIWFREQ;
3994 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
3996 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3999 memset(&iwe, 0, sizeof(iwe));
4001 iwe.u.qual.qual = bss->signal;
4002 iwe.u.qual.level = bss->rssi;
4003 iwe.u.qual.noise = bss->noise;
4004 iwe.u.qual.updated = local->wstats_flags;
4005 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
4008 memset(&iwe, 0, sizeof(iwe));
4009 iwe.cmd = SIOCGIWENCODE;
4010 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
4011 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4013 iwe.u.data.flags = IW_ENCODE_DISABLED;
4014 iwe.u.data.length = 0;
4015 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
4017 if (bss && bss->wpa_ie) {
4018 memset(&iwe, 0, sizeof(iwe));
4019 iwe.cmd = IWEVGENIE;
4020 iwe.u.data.length = bss->wpa_ie_len;
4021 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
4025 if (bss && bss->rsn_ie) {
4026 memset(&iwe, 0, sizeof(iwe));
4027 iwe.cmd = IWEVGENIE;
4028 iwe.u.data.length = bss->rsn_ie_len;
4029 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
4033 if (bss && bss->supp_rates_len > 0) {
4034 /* display all supported rates in readable format */
4035 char *p = current_ev + IW_EV_LCP_LEN;
4038 memset(&iwe, 0, sizeof(iwe));
4039 iwe.cmd = SIOCGIWRATE;
4040 /* Those two flags are ignored... */
4041 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4043 for (i = 0; i < bss->supp_rates_len; i++) {
4044 iwe.u.bitrate.value = ((bss->supp_rates[i] &
4046 p = iwe_stream_add_value(current_ev, p,
4047 end_buf, &iwe, IW_EV_PARAM_LEN);
4054 buf = kmalloc(30, GFP_ATOMIC);
4056 memset(&iwe, 0, sizeof(iwe));
4057 iwe.cmd = IWEVCUSTOM;
4058 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
4059 iwe.u.data.length = strlen(buf);
4060 current_ev = iwe_stream_add_point(current_ev, end_buf,
4066 if (bss_mesh_cfg(bss)) {
4068 u8 *cfg = bss_mesh_cfg(bss);
4069 buf = kmalloc(50, GFP_ATOMIC);
4071 memset(&iwe, 0, sizeof(iwe));
4072 iwe.cmd = IWEVCUSTOM;
4073 sprintf(buf, "Mesh network (version %d)", cfg[0]);
4074 iwe.u.data.length = strlen(buf);
4075 current_ev = iwe_stream_add_point(current_ev, end_buf,
4077 sprintf(buf, "Path Selection Protocol ID: "
4078 "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
4080 iwe.u.data.length = strlen(buf);
4081 current_ev = iwe_stream_add_point(current_ev, end_buf,
4083 sprintf(buf, "Path Selection Metric ID: "
4084 "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
4086 iwe.u.data.length = strlen(buf);
4087 current_ev = iwe_stream_add_point(current_ev, end_buf,
4089 sprintf(buf, "Congestion Control Mode ID: "
4090 "0x%02X%02X%02X%02X", cfg[9], cfg[10],
4092 iwe.u.data.length = strlen(buf);
4093 current_ev = iwe_stream_add_point(current_ev, end_buf,
4095 sprintf(buf, "Channel Precedence: "
4096 "0x%02X%02X%02X%02X", cfg[13], cfg[14],
4098 iwe.u.data.length = strlen(buf);
4099 current_ev = iwe_stream_add_point(current_ev, end_buf,
4109 int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
4111 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4112 char *current_ev = buf;
4113 char *end_buf = buf + len;
4114 struct ieee80211_sta_bss *bss;
4116 spin_lock_bh(&local->sta_bss_lock);
4117 list_for_each_entry(bss, &local->sta_bss_list, list) {
4118 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
4119 spin_unlock_bh(&local->sta_bss_lock);
4122 current_ev = ieee80211_sta_scan_result(dev, bss, current_ev,
4125 spin_unlock_bh(&local->sta_bss_lock);
4126 return current_ev - buf;
4130 int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
4132 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4133 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4134 kfree(ifsta->extra_ie);
4136 ifsta->extra_ie = NULL;
4137 ifsta->extra_ie_len = 0;
4140 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
4141 if (!ifsta->extra_ie) {
4142 ifsta->extra_ie_len = 0;
4145 memcpy(ifsta->extra_ie, ie, len);
4146 ifsta->extra_ie_len = len;
4151 struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
4152 struct sk_buff *skb, u8 *bssid,
4155 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4156 struct sta_info *sta;
4157 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4158 DECLARE_MAC_BUF(mac);
4160 /* TODO: Could consider removing the least recently used entry and
4161 * allow new one to be added. */
4162 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
4163 if (net_ratelimit()) {
4164 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
4165 "entry %s\n", dev->name, print_mac(mac, addr));
4170 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
4171 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
4173 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
4177 sta->flags |= WLAN_STA_AUTHORIZED;
4179 sta->supp_rates[local->hw.conf.channel->band] =
4180 sdata->u.sta.supp_rates_bits[local->hw.conf.channel->band];
4182 rate_control_rate_init(sta, local);
4184 if (sta_info_insert(sta))
4191 int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
4193 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4194 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4196 printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
4199 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
4200 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
4203 ieee80211_send_deauth(dev, ifsta, reason);
4204 ieee80211_set_disassoc(dev, ifsta, 1);
4209 int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
4211 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4212 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4214 printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
4217 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
4220 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
4223 ieee80211_send_disassoc(dev, ifsta, reason);
4224 ieee80211_set_disassoc(dev, ifsta, 0);
4228 void ieee80211_notify_mac(struct ieee80211_hw *hw,
4229 enum ieee80211_notification_types notif_type)
4231 struct ieee80211_local *local = hw_to_local(hw);
4232 struct ieee80211_sub_if_data *sdata;
4234 switch (notif_type) {
4235 case IEEE80211_NOTIFY_RE_ASSOC:
4237 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4239 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
4240 ieee80211_sta_req_auth(sdata->dev,
4249 EXPORT_SYMBOL(ieee80211_notify_mac);