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"
33 #include "ieee80211_rate.h"
34 #include "ieee80211_led.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 IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
62 #define ERP_INFO_USE_PROTECTION BIT(1)
64 /* mgmt header + 1 byte action code */
65 #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
67 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
68 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
69 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
70 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
71 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
73 /* next values represent the buffer size for A-MPDU frame.
74 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
75 #define IEEE80211_MIN_AMPDU_BUF 0x8
76 #define IEEE80211_MAX_AMPDU_BUF 0x40
78 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
79 u8 *ssid, size_t ssid_len);
80 static struct ieee80211_sta_bss *
81 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
82 u8 *ssid, u8 ssid_len);
83 static void ieee80211_rx_bss_put(struct net_device *dev,
84 struct ieee80211_sta_bss *bss);
85 static int ieee80211_sta_find_ibss(struct net_device *dev,
86 struct ieee80211_if_sta *ifsta);
87 static int ieee80211_sta_wep_configured(struct net_device *dev);
88 static int ieee80211_sta_start_scan(struct net_device *dev,
89 u8 *ssid, size_t ssid_len);
90 static int ieee80211_sta_config_auth(struct net_device *dev,
91 struct ieee80211_if_sta *ifsta);
94 void ieee802_11_parse_elems(u8 *start, size_t len,
95 struct ieee802_11_elems *elems)
100 memset(elems, 0, sizeof(*elems));
115 elems->ssid_len = elen;
117 case WLAN_EID_SUPP_RATES:
118 elems->supp_rates = pos;
119 elems->supp_rates_len = elen;
121 case WLAN_EID_FH_PARAMS:
122 elems->fh_params = pos;
123 elems->fh_params_len = elen;
125 case WLAN_EID_DS_PARAMS:
126 elems->ds_params = pos;
127 elems->ds_params_len = elen;
129 case WLAN_EID_CF_PARAMS:
130 elems->cf_params = pos;
131 elems->cf_params_len = elen;
135 elems->tim_len = elen;
137 case WLAN_EID_IBSS_PARAMS:
138 elems->ibss_params = pos;
139 elems->ibss_params_len = elen;
141 case WLAN_EID_CHALLENGE:
142 elems->challenge = pos;
143 elems->challenge_len = elen;
146 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
148 /* Microsoft OUI (00:50:F2) */
150 /* OUI Type 1 - WPA IE */
152 elems->wpa_len = elen;
153 } else if (elen >= 5 && pos[3] == 2) {
155 elems->wmm_info = pos;
156 elems->wmm_info_len = elen;
157 } else if (pos[4] == 1) {
158 elems->wmm_param = pos;
159 elems->wmm_param_len = elen;
166 elems->rsn_len = elen;
168 case WLAN_EID_ERP_INFO:
169 elems->erp_info = pos;
170 elems->erp_info_len = elen;
172 case WLAN_EID_EXT_SUPP_RATES:
173 elems->ext_supp_rates = pos;
174 elems->ext_supp_rates_len = elen;
176 case WLAN_EID_HT_CAPABILITY:
177 elems->ht_cap_elem = pos;
178 elems->ht_cap_elem_len = elen;
180 case WLAN_EID_HT_EXTRA_INFO:
181 elems->ht_info_elem = pos;
182 elems->ht_info_elem_len = elen;
184 case WLAN_EID_MESH_ID:
185 elems->mesh_id = pos;
186 elems->mesh_id_len = elen;
188 case WLAN_EID_MESH_CONFIG:
189 elems->mesh_config = pos;
190 elems->mesh_config_len = elen;
192 case WLAN_EID_PEER_LINK:
193 elems->peer_link = pos;
194 elems->peer_link_len = elen;
198 elems->preq_len = elen;
202 elems->prep_len = elen;
206 elems->perr_len = elen;
218 static int ecw2cw(int ecw)
220 return (1 << ecw) - 1;
224 static void ieee80211_sta_def_wmm_params(struct net_device *dev,
225 struct ieee80211_sta_bss *bss,
228 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
229 struct ieee80211_local *local = sdata->local;
230 int i, have_higher_than_11mbit = 0;
233 /* cf. IEEE 802.11 9.2.12 */
234 for (i = 0; i < bss->supp_rates_len; i++)
235 if ((bss->supp_rates[i] & 0x7f) * 5 > 110)
236 have_higher_than_11mbit = 1;
238 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
239 have_higher_than_11mbit)
240 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
242 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
245 if (local->ops->conf_tx) {
246 struct ieee80211_tx_queue_params qparam;
249 memset(&qparam, 0, sizeof(qparam));
253 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
254 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
259 qparam.cw_max = 1023;
262 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
263 local->ops->conf_tx(local_to_hw(local),
264 i + IEEE80211_TX_QUEUE_DATA0,
268 /* IBSS uses different parameters for Beacon sending */
272 local->ops->conf_tx(local_to_hw(local),
273 IEEE80211_TX_QUEUE_BEACON, &qparam);
278 static void ieee80211_sta_wmm_params(struct net_device *dev,
279 struct ieee80211_if_sta *ifsta,
280 u8 *wmm_param, size_t wmm_param_len)
282 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
283 struct ieee80211_tx_queue_params params;
288 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
290 count = wmm_param[6] & 0x0f;
291 if (count == ifsta->wmm_last_param_set)
293 ifsta->wmm_last_param_set = count;
296 left = wmm_param_len - 8;
298 memset(¶ms, 0, sizeof(params));
300 if (!local->ops->conf_tx)
304 for (; left >= 4; left -= 4, pos += 4) {
305 int aci = (pos[0] >> 5) & 0x03;
306 int acm = (pos[0] >> 4) & 0x01;
311 queue = IEEE80211_TX_QUEUE_DATA3;
313 local->wmm_acm |= BIT(0) | BIT(3);
317 queue = IEEE80211_TX_QUEUE_DATA1;
319 local->wmm_acm |= BIT(4) | BIT(5);
323 queue = IEEE80211_TX_QUEUE_DATA0;
325 local->wmm_acm |= BIT(6) | BIT(7);
330 queue = IEEE80211_TX_QUEUE_DATA2;
332 local->wmm_acm |= BIT(1) | BIT(2);
337 params.aifs = pos[0] & 0x0f;
338 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
339 params.cw_min = ecw2cw(pos[1] & 0x0f);
340 params.txop = pos[2] | (pos[3] << 8);
341 #ifdef CONFIG_MAC80211_DEBUG
342 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
343 "cWmin=%d cWmax=%d txop=%d\n",
344 dev->name, queue, aci, acm, params.aifs, params.cw_min,
345 params.cw_max, params.txop);
347 /* TODO: handle ACM (block TX, fallback to next lowest allowed
349 if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) {
350 printk(KERN_DEBUG "%s: failed to set TX queue "
351 "parameters for queue %d\n", dev->name, queue);
357 static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata,
360 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
361 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
362 bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
363 bool preamble_mode = (erp_value & WLAN_ERP_BARKER_PREAMBLE) != 0;
364 DECLARE_MAC_BUF(mac);
367 if (use_protection != bss_conf->use_cts_prot) {
368 if (net_ratelimit()) {
369 printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
372 use_protection ? "enabled" : "disabled",
373 print_mac(mac, ifsta->bssid));
375 bss_conf->use_cts_prot = use_protection;
376 changed |= BSS_CHANGED_ERP_CTS_PROT;
379 if (preamble_mode != bss_conf->use_short_preamble) {
380 if (net_ratelimit()) {
381 printk(KERN_DEBUG "%s: switched to %s barker preamble"
384 (preamble_mode == WLAN_ERP_PREAMBLE_SHORT) ?
386 print_mac(mac, ifsta->bssid));
388 bss_conf->use_short_preamble = preamble_mode;
389 changed |= BSS_CHANGED_ERP_PREAMBLE;
395 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
396 struct ieee80211_ht_info *ht_info)
402 memset(ht_info, 0, sizeof(*ht_info));
405 u8 ampdu_info = ht_cap_ie->ampdu_params_info;
407 ht_info->ht_supported = 1;
408 ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info);
409 ht_info->ampdu_factor =
410 ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR;
411 ht_info->ampdu_density =
412 (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
413 memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16);
415 ht_info->ht_supported = 0;
420 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
421 struct ieee80211_ht_addt_info *ht_add_info_ie,
422 struct ieee80211_ht_bss_info *bss_info)
424 if (bss_info == NULL)
427 memset(bss_info, 0, sizeof(*bss_info));
429 if (ht_add_info_ie) {
431 op_mode = le16_to_cpu(ht_add_info_ie->operation_mode);
433 bss_info->primary_channel = ht_add_info_ie->control_chan;
434 bss_info->bss_cap = ht_add_info_ie->ht_param;
435 bss_info->bss_op_mode = (u8)(op_mode & 0xff);
441 static void ieee80211_sta_send_associnfo(struct net_device *dev,
442 struct ieee80211_if_sta *ifsta)
447 union iwreq_data wrqu;
449 if (!ifsta->assocreq_ies && !ifsta->assocresp_ies)
452 buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
453 ifsta->assocresp_ies_len), GFP_KERNEL);
457 len = sprintf(buf, "ASSOCINFO(");
458 if (ifsta->assocreq_ies) {
459 len += sprintf(buf + len, "ReqIEs=");
460 for (i = 0; i < ifsta->assocreq_ies_len; i++) {
461 len += sprintf(buf + len, "%02x",
462 ifsta->assocreq_ies[i]);
465 if (ifsta->assocresp_ies) {
466 if (ifsta->assocreq_ies)
467 len += sprintf(buf + len, " ");
468 len += sprintf(buf + len, "RespIEs=");
469 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
470 len += sprintf(buf + len, "%02x",
471 ifsta->assocresp_ies[i]);
474 len += sprintf(buf + len, ")");
476 if (len > IW_CUSTOM_MAX) {
477 len = sprintf(buf, "ASSOCRESPIE=");
478 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
479 len += sprintf(buf + len, "%02x",
480 ifsta->assocresp_ies[i]);
484 memset(&wrqu, 0, sizeof(wrqu));
485 wrqu.data.length = len;
486 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
492 static void ieee80211_set_associated(struct net_device *dev,
493 struct ieee80211_if_sta *ifsta,
496 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
497 struct ieee80211_local *local = sdata->local;
498 union iwreq_data wrqu;
499 u32 changed = BSS_CHANGED_ASSOC;
502 struct ieee80211_sta_bss *bss;
504 ifsta->flags |= IEEE80211_STA_ASSOCIATED;
506 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
509 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
510 local->hw.conf.channel->center_freq,
511 ifsta->ssid, ifsta->ssid_len);
513 if (bss->has_erp_value)
514 changed |= ieee80211_handle_erp_ie(
515 sdata, bss->erp_value);
516 ieee80211_rx_bss_put(dev, bss);
519 netif_carrier_on(dev);
520 ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
521 memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
522 memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
523 ieee80211_sta_send_associnfo(dev, ifsta);
525 ieee80211_sta_tear_down_BA_sessions(dev, ifsta->bssid);
526 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
527 netif_carrier_off(dev);
528 ieee80211_reset_erp_info(dev);
529 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
531 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
532 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
533 ifsta->last_probe = jiffies;
534 ieee80211_led_assoc(local, assoc);
536 sdata->bss_conf.assoc = assoc;
537 ieee80211_bss_info_change_notify(sdata, changed);
540 static void ieee80211_set_disassoc(struct net_device *dev,
541 struct ieee80211_if_sta *ifsta, int deauth)
544 ifsta->auth_tries = 0;
545 ifsta->assoc_tries = 0;
546 ieee80211_set_associated(dev, ifsta, 0);
549 void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
552 struct ieee80211_sub_if_data *sdata;
553 struct ieee80211_tx_packet_data *pkt_data;
555 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
556 skb->dev = sdata->local->mdev;
557 skb_set_mac_header(skb, 0);
558 skb_set_network_header(skb, 0);
559 skb_set_transport_header(skb, 0);
561 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
562 memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
563 pkt_data->ifindex = sdata->dev->ifindex;
565 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
571 static void ieee80211_send_auth(struct net_device *dev,
572 struct ieee80211_if_sta *ifsta,
573 int transaction, u8 *extra, size_t extra_len,
576 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
578 struct ieee80211_mgmt *mgmt;
580 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
581 sizeof(*mgmt) + 6 + extra_len);
583 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
584 "frame\n", dev->name);
587 skb_reserve(skb, local->hw.extra_tx_headroom);
589 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
590 memset(mgmt, 0, 24 + 6);
591 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
592 IEEE80211_STYPE_AUTH);
594 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
595 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
596 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
597 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
598 mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
599 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
600 ifsta->auth_transaction = transaction + 1;
601 mgmt->u.auth.status_code = cpu_to_le16(0);
603 memcpy(skb_put(skb, extra_len), extra, extra_len);
605 ieee80211_sta_tx(dev, skb, encrypt);
609 static void ieee80211_authenticate(struct net_device *dev,
610 struct ieee80211_if_sta *ifsta)
612 DECLARE_MAC_BUF(mac);
615 if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
616 printk(KERN_DEBUG "%s: authentication with AP %s"
618 dev->name, print_mac(mac, ifsta->bssid));
619 ifsta->state = IEEE80211_DISABLED;
623 ifsta->state = IEEE80211_AUTHENTICATE;
624 printk(KERN_DEBUG "%s: authenticate with AP %s\n",
625 dev->name, print_mac(mac, ifsta->bssid));
627 ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
629 mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
633 static void ieee80211_send_assoc(struct net_device *dev,
634 struct ieee80211_if_sta *ifsta)
636 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
638 struct ieee80211_mgmt *mgmt;
642 struct ieee80211_sta_bss *bss;
644 struct ieee80211_supported_band *sband;
646 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
647 sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
650 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
651 "frame\n", dev->name);
654 skb_reserve(skb, local->hw.extra_tx_headroom);
656 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
658 capab = ifsta->capab;
660 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
661 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
662 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
663 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
664 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
667 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
668 local->hw.conf.channel->center_freq,
669 ifsta->ssid, ifsta->ssid_len);
671 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
672 capab |= WLAN_CAPABILITY_PRIVACY;
676 ieee80211_rx_bss_put(dev, bss);
679 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
681 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
682 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
683 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
685 if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
687 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
688 IEEE80211_STYPE_REASSOC_REQ);
689 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
690 mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1);
691 memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
695 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
696 IEEE80211_STYPE_ASSOC_REQ);
697 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
698 mgmt->u.assoc_req.listen_interval = cpu_to_le16(1);
702 ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
703 *pos++ = WLAN_EID_SSID;
704 *pos++ = ifsta->ssid_len;
705 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
707 len = sband->n_bitrates;
710 pos = skb_put(skb, len + 2);
711 *pos++ = WLAN_EID_SUPP_RATES;
713 for (i = 0; i < len; i++) {
714 int rate = sband->bitrates[i].bitrate;
715 *pos++ = (u8) (rate / 5);
718 if (sband->n_bitrates > len) {
719 pos = skb_put(skb, sband->n_bitrates - len + 2);
720 *pos++ = WLAN_EID_EXT_SUPP_RATES;
721 *pos++ = sband->n_bitrates - len;
722 for (i = len; i < sband->n_bitrates; i++) {
723 int rate = sband->bitrates[i].bitrate;
724 *pos++ = (u8) (rate / 5);
728 if (ifsta->extra_ie) {
729 pos = skb_put(skb, ifsta->extra_ie_len);
730 memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
733 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
734 pos = skb_put(skb, 9);
735 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
736 *pos++ = 7; /* len */
737 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
740 *pos++ = 2; /* WME */
741 *pos++ = 0; /* WME info */
742 *pos++ = 1; /* WME ver */
745 /* wmm support is a must to HT */
746 if (wmm && sband->ht_info.ht_supported) {
747 __le16 tmp = cpu_to_le16(sband->ht_info.cap);
748 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
749 *pos++ = WLAN_EID_HT_CAPABILITY;
750 *pos++ = sizeof(struct ieee80211_ht_cap);
751 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
752 memcpy(pos, &tmp, sizeof(u16));
754 /* TODO: needs a define here for << 2 */
755 *pos++ = sband->ht_info.ampdu_factor |
756 (sband->ht_info.ampdu_density << 2);
757 memcpy(pos, sband->ht_info.supp_mcs_set, 16);
760 kfree(ifsta->assocreq_ies);
761 ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
762 ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
763 if (ifsta->assocreq_ies)
764 memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
766 ieee80211_sta_tx(dev, skb, 0);
770 static void ieee80211_send_deauth(struct net_device *dev,
771 struct ieee80211_if_sta *ifsta, u16 reason)
773 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
775 struct ieee80211_mgmt *mgmt;
777 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
779 printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
780 "frame\n", dev->name);
783 skb_reserve(skb, local->hw.extra_tx_headroom);
785 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
787 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
788 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
789 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
790 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
791 IEEE80211_STYPE_DEAUTH);
793 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
795 ieee80211_sta_tx(dev, skb, 0);
799 static void ieee80211_send_disassoc(struct net_device *dev,
800 struct ieee80211_if_sta *ifsta, u16 reason)
802 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
804 struct ieee80211_mgmt *mgmt;
806 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
808 printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
809 "frame\n", dev->name);
812 skb_reserve(skb, local->hw.extra_tx_headroom);
814 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
816 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
817 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
818 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
819 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
820 IEEE80211_STYPE_DISASSOC);
822 mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
824 ieee80211_sta_tx(dev, skb, 0);
828 static int ieee80211_privacy_mismatch(struct net_device *dev,
829 struct ieee80211_if_sta *ifsta)
831 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
832 struct ieee80211_sta_bss *bss;
837 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
840 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
841 local->hw.conf.channel->center_freq,
842 ifsta->ssid, ifsta->ssid_len);
846 bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
847 wep_privacy = !!ieee80211_sta_wep_configured(dev);
848 privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
850 ieee80211_rx_bss_put(dev, bss);
852 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
859 static void ieee80211_associate(struct net_device *dev,
860 struct ieee80211_if_sta *ifsta)
862 DECLARE_MAC_BUF(mac);
864 ifsta->assoc_tries++;
865 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
866 printk(KERN_DEBUG "%s: association with AP %s"
868 dev->name, print_mac(mac, ifsta->bssid));
869 ifsta->state = IEEE80211_DISABLED;
873 ifsta->state = IEEE80211_ASSOCIATE;
874 printk(KERN_DEBUG "%s: associate with AP %s\n",
875 dev->name, print_mac(mac, ifsta->bssid));
876 if (ieee80211_privacy_mismatch(dev, ifsta)) {
877 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
878 "mixed-cell disabled - abort association\n", dev->name);
879 ifsta->state = IEEE80211_DISABLED;
883 ieee80211_send_assoc(dev, ifsta);
885 mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
889 static void ieee80211_associated(struct net_device *dev,
890 struct ieee80211_if_sta *ifsta)
892 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
893 struct sta_info *sta;
895 DECLARE_MAC_BUF(mac);
897 /* TODO: start monitoring current AP signal quality and number of
898 * missed beacons. Scan other channels every now and then and search
900 /* TODO: remove expired BSSes */
902 ifsta->state = IEEE80211_ASSOCIATED;
906 sta = sta_info_get(local, ifsta->bssid);
908 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
909 dev->name, print_mac(mac, ifsta->bssid));
913 if (time_after(jiffies,
914 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
915 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
916 printk(KERN_DEBUG "%s: No ProbeResp from "
917 "current AP %s - assume out of "
919 dev->name, print_mac(mac, ifsta->bssid));
921 sta_info_unlink(&sta);
923 ieee80211_send_probe_req(dev, ifsta->bssid,
925 local->scan_ssid_len);
926 ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
928 ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
929 if (time_after(jiffies, ifsta->last_probe +
930 IEEE80211_PROBE_INTERVAL)) {
931 ifsta->last_probe = jiffies;
932 ieee80211_send_probe_req(dev, ifsta->bssid,
941 if (disassoc && sta) {
943 sta_info_destroy(sta);
948 ifsta->state = IEEE80211_DISABLED;
949 ieee80211_set_associated(dev, ifsta, 0);
951 mod_timer(&ifsta->timer, jiffies +
952 IEEE80211_MONITORING_INTERVAL);
957 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
958 u8 *ssid, size_t ssid_len)
960 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
961 struct ieee80211_supported_band *sband;
963 struct ieee80211_mgmt *mgmt;
964 u8 *pos, *supp_rates, *esupp_rates = NULL;
967 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
969 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
970 "request\n", dev->name);
973 skb_reserve(skb, local->hw.extra_tx_headroom);
975 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
977 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
978 IEEE80211_STYPE_PROBE_REQ);
979 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
981 memcpy(mgmt->da, dst, ETH_ALEN);
982 memcpy(mgmt->bssid, dst, ETH_ALEN);
984 memset(mgmt->da, 0xff, ETH_ALEN);
985 memset(mgmt->bssid, 0xff, ETH_ALEN);
987 pos = skb_put(skb, 2 + ssid_len);
988 *pos++ = WLAN_EID_SSID;
990 memcpy(pos, ssid, ssid_len);
992 supp_rates = skb_put(skb, 2);
993 supp_rates[0] = WLAN_EID_SUPP_RATES;
995 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
997 for (i = 0; i < sband->n_bitrates; i++) {
998 struct ieee80211_rate *rate = &sband->bitrates[i];
1000 pos = skb_put(skb, 1);
1002 } else if (supp_rates[1] == 8) {
1003 esupp_rates = skb_put(skb, 3);
1004 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
1006 pos = &esupp_rates[2];
1008 pos = skb_put(skb, 1);
1011 *pos = rate->bitrate / 5;
1014 ieee80211_sta_tx(dev, skb, 0);
1018 static int ieee80211_sta_wep_configured(struct net_device *dev)
1020 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1021 if (!sdata || !sdata->default_key ||
1022 sdata->default_key->conf.alg != ALG_WEP)
1028 static void ieee80211_auth_completed(struct net_device *dev,
1029 struct ieee80211_if_sta *ifsta)
1031 printk(KERN_DEBUG "%s: authenticated\n", dev->name);
1032 ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
1033 ieee80211_associate(dev, ifsta);
1037 static void ieee80211_auth_challenge(struct net_device *dev,
1038 struct ieee80211_if_sta *ifsta,
1039 struct ieee80211_mgmt *mgmt,
1043 struct ieee802_11_elems elems;
1045 printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
1046 pos = mgmt->u.auth.variable;
1047 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1048 if (!elems.challenge) {
1049 printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
1050 "frame\n", dev->name);
1053 ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
1054 elems.challenge_len + 2, 1);
1057 static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
1058 u8 dialog_token, u16 status, u16 policy,
1059 u16 buf_size, u16 timeout)
1061 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1062 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1063 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1064 struct sk_buff *skb;
1065 struct ieee80211_mgmt *mgmt;
1068 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1069 sizeof(mgmt->u.action.u.addba_resp));
1071 printk(KERN_DEBUG "%s: failed to allocate buffer "
1072 "for addba resp frame\n", dev->name);
1076 skb_reserve(skb, local->hw.extra_tx_headroom);
1077 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1078 memset(mgmt, 0, 24);
1079 memcpy(mgmt->da, da, ETH_ALEN);
1080 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1081 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1082 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1084 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1085 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1086 IEEE80211_STYPE_ACTION);
1088 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
1089 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1090 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
1091 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
1093 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
1094 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1095 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
1097 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
1098 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
1099 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
1101 ieee80211_sta_tx(dev, skb, 0);
1106 void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
1107 u16 tid, u8 dialog_token, u16 start_seq_num,
1108 u16 agg_size, u16 timeout)
1110 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1111 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1112 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1113 struct sk_buff *skb;
1114 struct ieee80211_mgmt *mgmt;
1117 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1118 sizeof(mgmt->u.action.u.addba_req));
1122 printk(KERN_ERR "%s: failed to allocate buffer "
1123 "for addba request frame\n", dev->name);
1126 skb_reserve(skb, local->hw.extra_tx_headroom);
1127 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1128 memset(mgmt, 0, 24);
1129 memcpy(mgmt->da, da, ETH_ALEN);
1130 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1131 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1132 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1134 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1136 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1137 IEEE80211_STYPE_ACTION);
1139 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
1141 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1142 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
1144 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
1145 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
1146 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1147 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
1149 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
1151 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
1152 mgmt->u.action.u.addba_req.start_seq_num =
1153 cpu_to_le16(start_seq_num << 4);
1155 ieee80211_sta_tx(dev, skb, 0);
1158 static void ieee80211_sta_process_addba_request(struct net_device *dev,
1159 struct ieee80211_mgmt *mgmt,
1162 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1163 struct ieee80211_hw *hw = &local->hw;
1164 struct ieee80211_conf *conf = &hw->conf;
1165 struct sta_info *sta;
1166 struct tid_ampdu_rx *tid_agg_rx;
1167 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
1169 int ret = -EOPNOTSUPP;
1170 DECLARE_MAC_BUF(mac);
1174 sta = sta_info_get(local, mgmt->sa);
1180 /* extract session parameters from addba request frame */
1181 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
1182 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
1184 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
1186 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1187 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
1188 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1189 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
1191 status = WLAN_STATUS_REQUEST_DECLINED;
1193 /* sanity check for incoming parameters:
1194 * check if configuration can support the BA policy
1195 * and if buffer size does not exceeds max value */
1196 if (((ba_policy != 1)
1197 && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
1198 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
1199 status = WLAN_STATUS_INVALID_QOS_PARAM;
1200 #ifdef CONFIG_MAC80211_HT_DEBUG
1201 if (net_ratelimit())
1202 printk(KERN_DEBUG "AddBA Req with bad params from "
1203 "%s on tid %u. policy %d, buffer size %d\n",
1204 print_mac(mac, mgmt->sa), tid, ba_policy,
1206 #endif /* CONFIG_MAC80211_HT_DEBUG */
1209 /* determine default buffer size */
1210 if (buf_size == 0) {
1211 struct ieee80211_supported_band *sband;
1213 sband = local->hw.wiphy->bands[conf->channel->band];
1214 buf_size = IEEE80211_MIN_AMPDU_BUF;
1215 buf_size = buf_size << sband->ht_info.ampdu_factor;
1219 /* examine state machine */
1220 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1222 if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
1223 #ifdef CONFIG_MAC80211_HT_DEBUG
1224 if (net_ratelimit())
1225 printk(KERN_DEBUG "unexpected AddBA Req from "
1227 print_mac(mac, mgmt->sa), tid);
1228 #endif /* CONFIG_MAC80211_HT_DEBUG */
1232 /* prepare A-MPDU MLME for Rx aggregation */
1233 sta->ampdu_mlme.tid_rx[tid] =
1234 kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
1235 if (!sta->ampdu_mlme.tid_rx[tid]) {
1236 if (net_ratelimit())
1237 printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
1242 sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
1243 sta_rx_agg_session_timer_expired;
1244 sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
1245 (unsigned long)&sta->timer_to_tid[tid];
1246 init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
1248 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
1250 /* prepare reordering buffer */
1251 tid_agg_rx->reorder_buf =
1252 kmalloc(buf_size * sizeof(struct sk_buf *), GFP_ATOMIC);
1253 if (!tid_agg_rx->reorder_buf) {
1254 if (net_ratelimit())
1255 printk(KERN_ERR "can not allocate reordering buffer "
1256 "to tid %d\n", tid);
1257 kfree(sta->ampdu_mlme.tid_rx[tid]);
1260 memset(tid_agg_rx->reorder_buf, 0,
1261 buf_size * sizeof(struct sk_buf *));
1263 if (local->ops->ampdu_action)
1264 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
1265 sta->addr, tid, &start_seq_num);
1266 #ifdef CONFIG_MAC80211_HT_DEBUG
1267 printk(KERN_DEBUG "Rx A-MPDU on tid %d result %d", tid, ret);
1268 #endif /* CONFIG_MAC80211_HT_DEBUG */
1271 kfree(tid_agg_rx->reorder_buf);
1273 sta->ampdu_mlme.tid_rx[tid] = NULL;
1277 /* change state and send addba resp */
1278 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
1279 tid_agg_rx->dialog_token = dialog_token;
1280 tid_agg_rx->ssn = start_seq_num;
1281 tid_agg_rx->head_seq_num = start_seq_num;
1282 tid_agg_rx->buf_size = buf_size;
1283 tid_agg_rx->timeout = timeout;
1284 tid_agg_rx->stored_mpdu_num = 0;
1285 status = WLAN_STATUS_SUCCESS;
1287 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1290 ieee80211_send_addba_resp(sta->sdata->dev, sta->addr, tid,
1291 dialog_token, status, 1, buf_size, timeout);
1295 static void ieee80211_sta_process_addba_resp(struct net_device *dev,
1296 struct ieee80211_mgmt *mgmt,
1299 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1300 struct ieee80211_hw *hw = &local->hw;
1301 struct sta_info *sta;
1308 sta = sta_info_get(local, mgmt->sa);
1314 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
1315 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1317 state = &sta->ampdu_mlme.tid_state_tx[tid];
1319 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1321 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1322 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1323 printk(KERN_DEBUG "state not HT_ADDBA_REQUESTED_MSK:"
1325 goto addba_resp_exit;
1328 if (mgmt->u.action.u.addba_resp.dialog_token !=
1329 sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
1330 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1331 #ifdef CONFIG_MAC80211_HT_DEBUG
1332 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1333 #endif /* CONFIG_MAC80211_HT_DEBUG */
1334 goto addba_resp_exit;
1337 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
1338 #ifdef CONFIG_MAC80211_HT_DEBUG
1339 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1340 #endif /* CONFIG_MAC80211_HT_DEBUG */
1341 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1342 == WLAN_STATUS_SUCCESS) {
1343 if (*state & HT_ADDBA_RECEIVED_MSK)
1344 printk(KERN_DEBUG "double addBA response\n");
1346 *state |= HT_ADDBA_RECEIVED_MSK;
1347 sta->ampdu_mlme.addba_req_num[tid] = 0;
1349 if (*state == HT_AGG_STATE_OPERATIONAL) {
1350 printk(KERN_DEBUG "Aggregation on for tid %d \n", tid);
1351 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1354 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1355 printk(KERN_DEBUG "recipient accepted agg: tid %d \n", tid);
1357 printk(KERN_DEBUG "recipient rejected agg: tid %d \n", tid);
1359 sta->ampdu_mlme.addba_req_num[tid]++;
1360 /* this will allow the state check in stop_BA_session */
1361 *state = HT_AGG_STATE_OPERATIONAL;
1362 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1363 ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
1364 WLAN_BACK_INITIATOR);
1371 void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
1372 u16 initiator, u16 reason_code)
1374 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1375 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1376 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1377 struct sk_buff *skb;
1378 struct ieee80211_mgmt *mgmt;
1381 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1382 sizeof(mgmt->u.action.u.delba));
1385 printk(KERN_ERR "%s: failed to allocate buffer "
1386 "for delba frame\n", dev->name);
1390 skb_reserve(skb, local->hw.extra_tx_headroom);
1391 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1392 memset(mgmt, 0, 24);
1393 memcpy(mgmt->da, da, ETH_ALEN);
1394 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1395 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1396 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1398 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1399 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1400 IEEE80211_STYPE_ACTION);
1402 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
1404 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1405 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1406 params = (u16)(initiator << 11); /* bit 11 initiator */
1407 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1409 mgmt->u.action.u.delba.params = cpu_to_le16(params);
1410 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1412 ieee80211_sta_tx(dev, skb, 0);
1415 void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1416 u16 initiator, u16 reason)
1418 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1419 struct ieee80211_hw *hw = &local->hw;
1420 struct sta_info *sta;
1425 sta = sta_info_get(local, ra);
1431 /* check if TID is in operational state */
1432 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1433 if (sta->ampdu_mlme.tid_state_rx[tid]
1434 != HT_AGG_STATE_OPERATIONAL) {
1435 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1439 sta->ampdu_mlme.tid_state_rx[tid] =
1440 HT_AGG_STATE_REQ_STOP_BA_MSK |
1441 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
1442 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1444 /* stop HW Rx aggregation. ampdu_action existence
1445 * already verified in session init so we add the BUG_ON */
1446 BUG_ON(!local->ops->ampdu_action);
1448 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
1451 printk(KERN_DEBUG "HW problem - can not stop rx "
1452 "aggergation for tid %d\n", tid);
1454 /* shutdown timer has not expired */
1455 if (initiator != WLAN_BACK_TIMER)
1456 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
1458 /* check if this is a self generated aggregation halt */
1459 if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
1460 ieee80211_send_delba(dev, ra, tid, 0, reason);
1462 /* free the reordering buffer */
1463 for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
1464 if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
1465 /* release the reordered frames */
1466 dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
1467 sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
1468 sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
1471 /* free resources */
1472 kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
1473 kfree(sta->ampdu_mlme.tid_rx[tid]);
1474 sta->ampdu_mlme.tid_rx[tid] = NULL;
1475 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
1481 static void ieee80211_sta_process_delba(struct net_device *dev,
1482 struct ieee80211_mgmt *mgmt, size_t len)
1484 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1485 struct sta_info *sta;
1488 DECLARE_MAC_BUF(mac);
1492 sta = sta_info_get(local, mgmt->sa);
1498 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1499 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1500 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1502 #ifdef CONFIG_MAC80211_HT_DEBUG
1503 if (net_ratelimit())
1504 printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
1505 print_mac(mac, mgmt->sa),
1506 initiator ? "initiator" : "recipient", tid,
1507 mgmt->u.action.u.delba.reason_code);
1508 #endif /* CONFIG_MAC80211_HT_DEBUG */
1510 if (initiator == WLAN_BACK_INITIATOR)
1511 ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
1512 WLAN_BACK_INITIATOR, 0);
1513 else { /* WLAN_BACK_RECIPIENT */
1514 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1515 sta->ampdu_mlme.tid_state_tx[tid] =
1516 HT_AGG_STATE_OPERATIONAL;
1517 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1518 ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
1519 WLAN_BACK_RECIPIENT);
1525 * After sending add Block Ack request we activated a timer until
1526 * add Block Ack response will arrive from the recipient.
1527 * If this timer expires sta_addba_resp_timer_expired will be executed.
1529 void sta_addba_resp_timer_expired(unsigned long data)
1531 /* not an elegant detour, but there is no choice as the timer passes
1532 * only one argument, and both sta_info and TID are needed, so init
1533 * flow in sta_info_create gives the TID as data, while the timer_to_id
1534 * array gives the sta through container_of */
1535 u16 tid = *(int *)data;
1536 struct sta_info *temp_sta = container_of((void *)data,
1537 struct sta_info, timer_to_tid[tid]);
1539 struct ieee80211_local *local = temp_sta->local;
1540 struct ieee80211_hw *hw = &local->hw;
1541 struct sta_info *sta;
1546 sta = sta_info_get(local, temp_sta->addr);
1552 state = &sta->ampdu_mlme.tid_state_tx[tid];
1553 /* check if the TID waits for addBA response */
1554 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1555 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1556 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1557 *state = HT_AGG_STATE_IDLE;
1558 printk(KERN_DEBUG "timer expired on tid %d but we are not "
1559 "expecting addBA response there", tid);
1560 goto timer_expired_exit;
1563 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
1565 /* go through the state check in stop_BA_session */
1566 *state = HT_AGG_STATE_OPERATIONAL;
1567 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1568 ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
1569 WLAN_BACK_INITIATOR);
1576 * After accepting the AddBA Request we activated a timer,
1577 * resetting it after each frame that arrives from the originator.
1578 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1580 void sta_rx_agg_session_timer_expired(unsigned long data)
1582 /* not an elegant detour, but there is no choice as the timer passes
1583 * only one argument, and verious sta_info are needed here, so init
1584 * flow in sta_info_create gives the TID as data, while the timer_to_id
1585 * array gives the sta through container_of */
1586 u8 *ptid = (u8 *)data;
1587 u8 *timer_to_id = ptid - *ptid;
1588 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
1591 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
1592 ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr,
1593 (u16)*ptid, WLAN_BACK_TIMER,
1594 WLAN_REASON_QSTA_TIMEOUT);
1597 void ieee80211_sta_tear_down_BA_sessions(struct net_device *dev, u8 *addr)
1599 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1602 for (i = 0; i < STA_TID_NUM; i++) {
1603 ieee80211_stop_tx_ba_session(&local->hw, addr, i,
1604 WLAN_BACK_INITIATOR);
1605 ieee80211_sta_stop_rx_ba_session(dev, addr, i,
1606 WLAN_BACK_RECIPIENT,
1607 WLAN_REASON_QSTA_LEAVE_QBSS);
1611 static void ieee80211_rx_mgmt_auth(struct net_device *dev,
1612 struct ieee80211_if_sta *ifsta,
1613 struct ieee80211_mgmt *mgmt,
1616 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1617 u16 auth_alg, auth_transaction, status_code;
1618 DECLARE_MAC_BUF(mac);
1620 if (ifsta->state != IEEE80211_AUTHENTICATE &&
1621 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
1622 printk(KERN_DEBUG "%s: authentication frame received from "
1623 "%s, but not in authenticate state - ignored\n",
1624 dev->name, print_mac(mac, mgmt->sa));
1629 printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
1630 "received from %s - ignored\n",
1631 dev->name, len, print_mac(mac, mgmt->sa));
1635 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
1636 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1637 printk(KERN_DEBUG "%s: authentication frame received from "
1638 "unknown AP (SA=%s BSSID=%s) - "
1639 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1640 print_mac(mac, mgmt->bssid));
1644 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
1645 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
1646 printk(KERN_DEBUG "%s: authentication frame received from "
1647 "unknown BSSID (SA=%s BSSID=%s) - "
1648 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1649 print_mac(mac, mgmt->bssid));
1653 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1654 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1655 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1657 printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d "
1658 "transaction=%d status=%d)\n",
1659 dev->name, print_mac(mac, mgmt->sa), auth_alg,
1660 auth_transaction, status_code);
1662 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
1663 /* IEEE 802.11 standard does not require authentication in IBSS
1664 * networks and most implementations do not seem to use it.
1665 * However, try to reply to authentication attempts if someone
1666 * has actually implemented this.
1667 * TODO: Could implement shared key authentication. */
1668 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
1669 printk(KERN_DEBUG "%s: unexpected IBSS authentication "
1670 "frame (alg=%d transaction=%d)\n",
1671 dev->name, auth_alg, auth_transaction);
1674 ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
1677 if (auth_alg != ifsta->auth_alg ||
1678 auth_transaction != ifsta->auth_transaction) {
1679 printk(KERN_DEBUG "%s: unexpected authentication frame "
1680 "(alg=%d transaction=%d)\n",
1681 dev->name, auth_alg, auth_transaction);
1685 if (status_code != WLAN_STATUS_SUCCESS) {
1686 printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
1687 "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
1688 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1690 const int num_algs = ARRAY_SIZE(algs);
1692 algs[0] = algs[1] = algs[2] = 0xff;
1693 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1694 algs[0] = WLAN_AUTH_OPEN;
1695 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1696 algs[1] = WLAN_AUTH_SHARED_KEY;
1697 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1698 algs[2] = WLAN_AUTH_LEAP;
1699 if (ifsta->auth_alg == WLAN_AUTH_OPEN)
1701 else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
1705 for (i = 0; i < num_algs; i++) {
1707 if (pos >= num_algs)
1709 if (algs[pos] == ifsta->auth_alg ||
1712 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1713 !ieee80211_sta_wep_configured(dev))
1715 ifsta->auth_alg = algs[pos];
1716 printk(KERN_DEBUG "%s: set auth_alg=%d for "
1718 dev->name, ifsta->auth_alg);
1725 switch (ifsta->auth_alg) {
1726 case WLAN_AUTH_OPEN:
1727 case WLAN_AUTH_LEAP:
1728 ieee80211_auth_completed(dev, ifsta);
1730 case WLAN_AUTH_SHARED_KEY:
1731 if (ifsta->auth_transaction == 4)
1732 ieee80211_auth_completed(dev, ifsta);
1734 ieee80211_auth_challenge(dev, ifsta, mgmt, len);
1740 static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
1741 struct ieee80211_if_sta *ifsta,
1742 struct ieee80211_mgmt *mgmt,
1746 DECLARE_MAC_BUF(mac);
1749 printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
1750 "received from %s - ignored\n",
1751 dev->name, len, print_mac(mac, mgmt->sa));
1755 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1756 printk(KERN_DEBUG "%s: deauthentication frame received from "
1757 "unknown AP (SA=%s BSSID=%s) - "
1758 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1759 print_mac(mac, mgmt->bssid));
1763 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1765 printk(KERN_DEBUG "%s: RX deauthentication from %s"
1767 dev->name, print_mac(mac, mgmt->sa), reason_code);
1769 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) {
1770 printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
1773 if (ifsta->state == IEEE80211_AUTHENTICATE ||
1774 ifsta->state == IEEE80211_ASSOCIATE ||
1775 ifsta->state == IEEE80211_ASSOCIATED) {
1776 ifsta->state = IEEE80211_AUTHENTICATE;
1777 mod_timer(&ifsta->timer, jiffies +
1778 IEEE80211_RETRY_AUTH_INTERVAL);
1781 ieee80211_set_disassoc(dev, ifsta, 1);
1782 ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
1786 static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
1787 struct ieee80211_if_sta *ifsta,
1788 struct ieee80211_mgmt *mgmt,
1792 DECLARE_MAC_BUF(mac);
1795 printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
1796 "received from %s - ignored\n",
1797 dev->name, len, print_mac(mac, mgmt->sa));
1801 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1802 printk(KERN_DEBUG "%s: disassociation frame received from "
1803 "unknown AP (SA=%s BSSID=%s) - "
1804 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1805 print_mac(mac, mgmt->bssid));
1809 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1811 printk(KERN_DEBUG "%s: RX disassociation from %s"
1813 dev->name, print_mac(mac, mgmt->sa), reason_code);
1815 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
1816 printk(KERN_DEBUG "%s: disassociated\n", dev->name);
1818 if (ifsta->state == IEEE80211_ASSOCIATED) {
1819 ifsta->state = IEEE80211_ASSOCIATE;
1820 mod_timer(&ifsta->timer, jiffies +
1821 IEEE80211_RETRY_AUTH_INTERVAL);
1824 ieee80211_set_disassoc(dev, ifsta, 0);
1828 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1829 struct ieee80211_if_sta *ifsta,
1830 struct ieee80211_mgmt *mgmt,
1834 struct ieee80211_local *local = sdata->local;
1835 struct net_device *dev = sdata->dev;
1836 struct ieee80211_supported_band *sband;
1837 struct sta_info *sta;
1838 u64 rates, basic_rates;
1839 u16 capab_info, status_code, aid;
1840 struct ieee802_11_elems elems;
1841 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
1844 DECLARE_MAC_BUF(mac);
1845 bool have_higher_than_11mbit = false;
1847 /* AssocResp and ReassocResp have identical structure, so process both
1848 * of them in this function. */
1850 if (ifsta->state != IEEE80211_ASSOCIATE) {
1851 printk(KERN_DEBUG "%s: association frame received from "
1852 "%s, but not in associate state - ignored\n",
1853 dev->name, print_mac(mac, mgmt->sa));
1858 printk(KERN_DEBUG "%s: too short (%zd) association frame "
1859 "received from %s - ignored\n",
1860 dev->name, len, print_mac(mac, mgmt->sa));
1864 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1865 printk(KERN_DEBUG "%s: association frame received from "
1866 "unknown AP (SA=%s BSSID=%s) - "
1867 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1868 print_mac(mac, mgmt->bssid));
1872 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1873 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1874 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1876 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
1877 "status=%d aid=%d)\n",
1878 dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
1879 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1881 if (status_code != WLAN_STATUS_SUCCESS) {
1882 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1883 dev->name, status_code);
1884 /* if this was a reassociation, ensure we try a "full"
1885 * association next time. This works around some broken APs
1886 * which do not correctly reject reassociation requests. */
1887 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1891 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1892 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1893 "set\n", dev->name, aid);
1894 aid &= ~(BIT(15) | BIT(14));
1896 pos = mgmt->u.assoc_resp.variable;
1897 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1899 if (!elems.supp_rates) {
1900 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1905 printk(KERN_DEBUG "%s: associated\n", dev->name);
1907 ifsta->ap_capab = capab_info;
1909 kfree(ifsta->assocresp_ies);
1910 ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1911 ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
1912 if (ifsta->assocresp_ies)
1913 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
1917 /* Add STA entry for the AP */
1918 sta = sta_info_get(local, ifsta->bssid);
1920 struct ieee80211_sta_bss *bss;
1923 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
1925 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1926 " the AP\n", dev->name);
1930 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
1931 local->hw.conf.channel->center_freq,
1932 ifsta->ssid, ifsta->ssid_len);
1934 sta->last_rssi = bss->rssi;
1935 sta->last_signal = bss->signal;
1936 sta->last_noise = bss->noise;
1937 ieee80211_rx_bss_put(dev, bss);
1940 err = sta_info_insert(sta);
1942 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1943 " the AP (error %d)\n", dev->name, err);
1950 * FIXME: Do we really need to update the sta_info's information here?
1951 * We already know about the AP (we found it in our list) so it
1952 * should already be filled with the right info, no?
1953 * As is stands, all this is racy because typically we assume
1954 * the information that is filled in here (except flags) doesn't
1955 * change while a STA structure is alive. As such, it should move
1956 * to between the sta_info_alloc() and sta_info_insert() above.
1959 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1960 WLAN_STA_AUTHORIZED;
1964 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1966 for (i = 0; i < elems.supp_rates_len; i++) {
1967 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1970 have_higher_than_11mbit = true;
1972 for (j = 0; j < sband->n_bitrates; j++) {
1973 if (sband->bitrates[j].bitrate == rate)
1975 if (elems.supp_rates[i] & 0x80)
1976 basic_rates |= BIT(j);
1980 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1981 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1984 have_higher_than_11mbit = true;
1986 for (j = 0; j < sband->n_bitrates; j++) {
1987 if (sband->bitrates[j].bitrate == rate)
1989 if (elems.ext_supp_rates[i] & 0x80)
1990 basic_rates |= BIT(j);
1994 sta->supp_rates[local->hw.conf.channel->band] = rates;
1995 sdata->basic_rates = basic_rates;
1997 /* cf. IEEE 802.11 9.2.12 */
1998 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1999 have_higher_than_11mbit)
2000 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
2002 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
2004 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
2005 local->ops->conf_ht) {
2006 struct ieee80211_ht_bss_info bss_info;
2008 ieee80211_ht_cap_ie_to_ht_info(
2009 (struct ieee80211_ht_cap *)
2010 elems.ht_cap_elem, &sta->ht_info);
2011 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2012 (struct ieee80211_ht_addt_info *)
2013 elems.ht_info_elem, &bss_info);
2014 ieee80211_hw_config_ht(local, 1, &sta->ht_info, &bss_info);
2017 rate_control_rate_init(sta, local);
2019 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
2020 sta->flags |= WLAN_STA_WME;
2022 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2023 elems.wmm_param_len);
2027 /* set AID, ieee80211_set_associated() will tell the driver */
2028 bss_conf->aid = aid;
2029 ieee80211_set_associated(dev, ifsta, 1);
2031 ieee80211_associated(dev, ifsta);
2035 /* Caller must hold local->sta_bss_lock */
2036 static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
2037 struct ieee80211_sta_bss *bss)
2039 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2042 if (bss_mesh_cfg(bss))
2043 hash_idx = mesh_id_hash(bss_mesh_id(bss),
2044 bss_mesh_id_len(bss));
2046 hash_idx = STA_HASH(bss->bssid);
2048 bss->hnext = local->sta_bss_hash[hash_idx];
2049 local->sta_bss_hash[hash_idx] = bss;
2053 /* Caller must hold local->sta_bss_lock */
2054 static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
2055 struct ieee80211_sta_bss *bss)
2057 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2058 struct ieee80211_sta_bss *b, *prev = NULL;
2059 b = local->sta_bss_hash[STA_HASH(bss->bssid)];
2063 local->sta_bss_hash[STA_HASH(bss->bssid)] =
2066 prev->hnext = bss->hnext;
2075 static struct ieee80211_sta_bss *
2076 ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
2077 u8 *ssid, u8 ssid_len)
2079 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2080 struct ieee80211_sta_bss *bss;
2082 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2085 atomic_inc(&bss->users);
2086 atomic_inc(&bss->users);
2087 memcpy(bss->bssid, bssid, ETH_ALEN);
2089 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
2090 memcpy(bss->ssid, ssid, ssid_len);
2091 bss->ssid_len = ssid_len;
2094 spin_lock_bh(&local->sta_bss_lock);
2095 /* TODO: order by RSSI? */
2096 list_add_tail(&bss->list, &local->sta_bss_list);
2097 __ieee80211_rx_bss_hash_add(dev, bss);
2098 spin_unlock_bh(&local->sta_bss_lock);
2102 static struct ieee80211_sta_bss *
2103 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
2104 u8 *ssid, u8 ssid_len)
2106 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2107 struct ieee80211_sta_bss *bss;
2109 spin_lock_bh(&local->sta_bss_lock);
2110 bss = local->sta_bss_hash[STA_HASH(bssid)];
2112 if (!bss_mesh_cfg(bss) &&
2113 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
2114 bss->freq == freq &&
2115 bss->ssid_len == ssid_len &&
2116 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
2117 atomic_inc(&bss->users);
2122 spin_unlock_bh(&local->sta_bss_lock);
2126 #ifdef CONFIG_MAC80211_MESH
2127 static struct ieee80211_sta_bss *
2128 ieee80211_rx_mesh_bss_get(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2129 u8 *mesh_cfg, int freq)
2131 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2132 struct ieee80211_sta_bss *bss;
2134 spin_lock_bh(&local->sta_bss_lock);
2135 bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
2137 if (bss_mesh_cfg(bss) &&
2138 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
2139 bss->freq == freq &&
2140 mesh_id_len == bss->mesh_id_len &&
2141 (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
2143 atomic_inc(&bss->users);
2148 spin_unlock_bh(&local->sta_bss_lock);
2152 static struct ieee80211_sta_bss *
2153 ieee80211_rx_mesh_bss_add(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2154 u8 *mesh_cfg, int freq)
2156 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2157 struct ieee80211_sta_bss *bss;
2159 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2163 bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
2164 if (!bss->mesh_cfg) {
2169 if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
2170 bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
2171 if (!bss->mesh_id) {
2172 kfree(bss->mesh_cfg);
2176 memcpy(bss->mesh_id, mesh_id, mesh_id_len);
2179 atomic_inc(&bss->users);
2180 atomic_inc(&bss->users);
2181 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
2182 bss->mesh_id_len = mesh_id_len;
2184 spin_lock_bh(&local->sta_bss_lock);
2185 /* TODO: order by RSSI? */
2186 list_add_tail(&bss->list, &local->sta_bss_list);
2187 __ieee80211_rx_bss_hash_add(dev, bss);
2188 spin_unlock_bh(&local->sta_bss_lock);
2193 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
2199 kfree(bss_mesh_id(bss));
2200 kfree(bss_mesh_cfg(bss));
2205 static void ieee80211_rx_bss_put(struct net_device *dev,
2206 struct ieee80211_sta_bss *bss)
2208 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2209 if (!atomic_dec_and_test(&bss->users))
2212 spin_lock_bh(&local->sta_bss_lock);
2213 __ieee80211_rx_bss_hash_del(dev, bss);
2214 list_del(&bss->list);
2215 spin_unlock_bh(&local->sta_bss_lock);
2216 ieee80211_rx_bss_free(bss);
2220 void ieee80211_rx_bss_list_init(struct net_device *dev)
2222 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2223 spin_lock_init(&local->sta_bss_lock);
2224 INIT_LIST_HEAD(&local->sta_bss_list);
2228 void ieee80211_rx_bss_list_deinit(struct net_device *dev)
2230 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2231 struct ieee80211_sta_bss *bss, *tmp;
2233 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
2234 ieee80211_rx_bss_put(dev, bss);
2238 static int ieee80211_sta_join_ibss(struct net_device *dev,
2239 struct ieee80211_if_sta *ifsta,
2240 struct ieee80211_sta_bss *bss)
2242 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2243 int res, rates, i, j;
2244 struct sk_buff *skb;
2245 struct ieee80211_mgmt *mgmt;
2246 struct ieee80211_tx_control control;
2247 struct rate_selection ratesel;
2249 struct ieee80211_sub_if_data *sdata;
2250 struct ieee80211_supported_band *sband;
2252 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2254 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2256 /* Remove possible STA entries from other IBSS networks. */
2257 sta_info_flush(local, sdata);
2259 if (local->ops->reset_tsf) {
2260 /* Reset own TSF to allow time synchronization work. */
2261 local->ops->reset_tsf(local_to_hw(local));
2263 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2264 res = ieee80211_if_config(dev);
2268 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2270 sdata->drop_unencrypted = bss->capability &
2271 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2273 res = ieee80211_set_freq(local, bss->freq);
2275 if (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS) {
2276 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
2277 "%d MHz\n", dev->name, local->oper_channel->center_freq);
2281 /* Set beacon template */
2282 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2287 skb_reserve(skb, local->hw.extra_tx_headroom);
2289 mgmt = (struct ieee80211_mgmt *)
2290 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2291 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2292 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2293 IEEE80211_STYPE_BEACON);
2294 memset(mgmt->da, 0xff, ETH_ALEN);
2295 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2296 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2297 mgmt->u.beacon.beacon_int =
2298 cpu_to_le16(local->hw.conf.beacon_int);
2299 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2301 pos = skb_put(skb, 2 + ifsta->ssid_len);
2302 *pos++ = WLAN_EID_SSID;
2303 *pos++ = ifsta->ssid_len;
2304 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2306 rates = bss->supp_rates_len;
2309 pos = skb_put(skb, 2 + rates);
2310 *pos++ = WLAN_EID_SUPP_RATES;
2312 memcpy(pos, bss->supp_rates, rates);
2314 if (bss->band == IEEE80211_BAND_2GHZ) {
2315 pos = skb_put(skb, 2 + 1);
2316 *pos++ = WLAN_EID_DS_PARAMS;
2318 *pos++ = ieee80211_frequency_to_channel(bss->freq);
2321 pos = skb_put(skb, 2 + 2);
2322 *pos++ = WLAN_EID_IBSS_PARAMS;
2324 /* FIX: set ATIM window based on scan results */
2328 if (bss->supp_rates_len > 8) {
2329 rates = bss->supp_rates_len - 8;
2330 pos = skb_put(skb, 2 + rates);
2331 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2333 memcpy(pos, &bss->supp_rates[8], rates);
2336 memset(&control, 0, sizeof(control));
2337 rate_control_get_rate(dev, sband, skb, &ratesel);
2338 if (!ratesel.rate) {
2339 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2340 "for IBSS beacon\n", dev->name);
2343 control.vif = &sdata->vif;
2344 control.tx_rate = ratesel.rate;
2345 if (sdata->bss_conf.use_short_preamble &&
2346 ratesel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2347 control.flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
2348 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2349 control.flags |= IEEE80211_TXCTL_NO_ACK;
2350 control.retry_limit = 1;
2352 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2353 if (ifsta->probe_resp) {
2354 mgmt = (struct ieee80211_mgmt *)
2355 ifsta->probe_resp->data;
2356 mgmt->frame_control =
2357 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2358 IEEE80211_STYPE_PROBE_RESP);
2360 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2361 "template for IBSS\n", dev->name);
2364 if (local->ops->beacon_update &&
2365 local->ops->beacon_update(local_to_hw(local),
2366 skb, &control) == 0) {
2367 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2368 "template\n", dev->name);
2373 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2374 for (i = 0; i < bss->supp_rates_len; i++) {
2375 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2376 for (j = 0; j < sband->n_bitrates; j++)
2377 if (sband->bitrates[j].bitrate == bitrate)
2380 ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
2382 ieee80211_sta_def_wmm_params(dev, bss, 1);
2386 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2387 "template\n", dev->name);
2391 ifsta->state = IEEE80211_IBSS_JOINED;
2392 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2394 ieee80211_rx_bss_put(dev, bss);
2399 u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
2400 struct ieee802_11_elems *elems,
2401 enum ieee80211_band band)
2403 struct ieee80211_supported_band *sband;
2404 struct ieee80211_rate *bitrates;
2408 sband = local->hw.wiphy->bands[band];
2412 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2415 bitrates = sband->bitrates;
2416 num_rates = sband->n_bitrates;
2418 for (i = 0; i < elems->supp_rates_len +
2419 elems->ext_supp_rates_len; i++) {
2422 if (i < elems->supp_rates_len)
2423 rate = elems->supp_rates[i];
2424 else if (elems->ext_supp_rates)
2425 rate = elems->ext_supp_rates
2426 [i - elems->supp_rates_len];
2427 own_rate = 5 * (rate & 0x7f);
2428 for (j = 0; j < num_rates; j++)
2429 if (bitrates[j].bitrate == own_rate)
2430 supp_rates |= BIT(j);
2436 static void ieee80211_rx_bss_info(struct net_device *dev,
2437 struct ieee80211_mgmt *mgmt,
2439 struct ieee80211_rx_status *rx_status,
2442 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2443 struct ieee802_11_elems elems;
2446 struct ieee80211_sta_bss *bss;
2447 struct sta_info *sta;
2448 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2449 u64 beacon_timestamp, rx_timestamp;
2450 struct ieee80211_channel *channel;
2451 DECLARE_MAC_BUF(mac);
2452 DECLARE_MAC_BUF(mac2);
2454 if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
2455 return; /* ignore ProbeResp to foreign address */
2458 printk(KERN_DEBUG "%s: RX %s from %s to %s\n",
2459 dev->name, beacon ? "Beacon" : "Probe Response",
2460 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da));
2463 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2467 beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
2468 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
2470 if (ieee80211_vif_is_mesh(&sdata->vif) && elems.mesh_id &&
2471 elems.mesh_config && mesh_matches_local(&elems, dev)) {
2472 u64 rates = ieee80211_sta_get_rates(local, &elems,
2475 mesh_neighbour_update(mgmt->sa, rates, dev,
2476 mesh_peer_accepts_plinks(&elems, dev));
2481 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
2482 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
2483 (sta = sta_info_get(local, mgmt->sa))) {
2485 u64 supp_rates = ieee80211_sta_get_rates(local, &elems,
2488 prev_rates = sta->supp_rates[rx_status->band];
2489 sta->supp_rates[rx_status->band] &= supp_rates;
2490 if (sta->supp_rates[rx_status->band] == 0) {
2491 /* No matching rates - this should not really happen.
2492 * Make sure that at least one rate is marked
2493 * supported to avoid issues with TX rate ctrl. */
2494 sta->supp_rates[rx_status->band] =
2495 sdata->u.sta.supp_rates_bits[rx_status->band];
2497 if (sta->supp_rates[rx_status->band] != prev_rates) {
2498 printk(KERN_DEBUG "%s: updated supp_rates set for "
2499 "%s based on beacon info (0x%llx & 0x%llx -> "
2501 dev->name, print_mac(mac, sta->addr),
2502 (unsigned long long) prev_rates,
2503 (unsigned long long) supp_rates,
2504 (unsigned long long) sta->supp_rates[rx_status->band]);
2510 if (elems.ds_params && elems.ds_params_len == 1)
2511 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
2513 freq = rx_status->freq;
2515 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2517 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2520 #ifdef CONFIG_MAC80211_MESH
2521 if (elems.mesh_config)
2522 bss = ieee80211_rx_mesh_bss_get(dev, elems.mesh_id,
2523 elems.mesh_id_len, elems.mesh_config, freq);
2526 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
2527 elems.ssid, elems.ssid_len);
2529 #ifdef CONFIG_MAC80211_MESH
2530 if (elems.mesh_config)
2531 bss = ieee80211_rx_mesh_bss_add(dev, elems.mesh_id,
2532 elems.mesh_id_len, elems.mesh_config, freq);
2535 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
2536 elems.ssid, elems.ssid_len);
2541 /* TODO: order by RSSI? */
2542 spin_lock_bh(&local->sta_bss_lock);
2543 list_move_tail(&bss->list, &local->sta_bss_list);
2544 spin_unlock_bh(&local->sta_bss_lock);
2548 bss->band = rx_status->band;
2550 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
2551 bss->probe_resp && beacon) {
2553 * Do not allow beacon to override data from Probe Response. */
2554 ieee80211_rx_bss_put(dev, bss);
2558 /* save the ERP value so that it is available at association time */
2559 if (elems.erp_info && elems.erp_info_len >= 1) {
2560 bss->erp_value = elems.erp_info[0];
2561 bss->has_erp_value = 1;
2564 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
2565 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
2567 bss->supp_rates_len = 0;
2568 if (elems.supp_rates) {
2569 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2570 if (clen > elems.supp_rates_len)
2571 clen = elems.supp_rates_len;
2572 memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
2574 bss->supp_rates_len += clen;
2576 if (elems.ext_supp_rates) {
2577 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2578 if (clen > elems.ext_supp_rates_len)
2579 clen = elems.ext_supp_rates_len;
2580 memcpy(&bss->supp_rates[bss->supp_rates_len],
2581 elems.ext_supp_rates, clen);
2582 bss->supp_rates_len += clen;
2586 (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len ||
2587 memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
2589 bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
2591 memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
2592 bss->wpa_ie_len = elems.wpa_len + 2;
2594 bss->wpa_ie_len = 0;
2595 } else if (!elems.wpa && bss->wpa_ie) {
2598 bss->wpa_ie_len = 0;
2602 (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len ||
2603 memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
2605 bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
2607 memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
2608 bss->rsn_ie_len = elems.rsn_len + 2;
2610 bss->rsn_ie_len = 0;
2611 } else if (!elems.rsn && bss->rsn_ie) {
2614 bss->rsn_ie_len = 0;
2617 if (elems.wmm_param &&
2618 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len ||
2619 memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
2621 bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
2623 memcpy(bss->wmm_ie, elems.wmm_param - 2,
2624 elems.wmm_param_len + 2);
2625 bss->wmm_ie_len = elems.wmm_param_len + 2;
2627 bss->wmm_ie_len = 0;
2628 } else if (!elems.wmm_param && bss->wmm_ie) {
2631 bss->wmm_ie_len = 0;
2633 if (elems.ht_cap_elem &&
2634 (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
2635 memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
2637 bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
2639 memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
2640 elems.ht_cap_elem_len + 2);
2641 bss->ht_ie_len = elems.ht_cap_elem_len + 2;
2644 } else if (!elems.ht_cap_elem && bss->ht_ie) {
2650 bss->timestamp = beacon_timestamp;
2651 bss->last_update = jiffies;
2652 bss->rssi = rx_status->ssi;
2653 bss->signal = rx_status->signal;
2654 bss->noise = rx_status->noise;
2658 /* check if we need to merge IBSS */
2659 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
2660 !local->sta_sw_scanning && !local->sta_hw_scanning &&
2661 bss->capability & WLAN_CAPABILITY_IBSS &&
2662 bss->freq == local->oper_channel->center_freq &&
2663 elems.ssid_len == sdata->u.sta.ssid_len &&
2664 memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) == 0) {
2665 if (rx_status->flag & RX_FLAG_TSFT) {
2666 /* in order for correct IBSS merging we need mactime
2668 * since mactime is defined as the time the first data
2669 * symbol of the frame hits the PHY, and the timestamp
2670 * of the beacon is defined as "the time that the data
2671 * symbol containing the first bit of the timestamp is
2672 * transmitted to the PHY plus the transmitting STA’s
2673 * delays through its local PHY from the MAC-PHY
2674 * interface to its interface with the WM"
2675 * (802.11 11.1.2) - equals the time this bit arrives at
2676 * the receiver - we have to take into account the
2677 * offset between the two.
2678 * e.g: at 1 MBit that means mactime is 192 usec earlier
2679 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2681 int rate = local->hw.wiphy->bands[rx_status->band]->
2682 bitrates[rx_status->rate_idx].bitrate;
2683 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
2684 } else if (local && local->ops && local->ops->get_tsf)
2685 /* second best option: get current TSF */
2686 rx_timestamp = local->ops->get_tsf(local_to_hw(local));
2688 /* can't merge without knowing the TSF */
2689 rx_timestamp = -1LLU;
2690 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2691 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
2692 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2693 print_mac(mac, mgmt->sa),
2694 print_mac(mac2, mgmt->bssid),
2695 (unsigned long long)rx_timestamp,
2696 (unsigned long long)beacon_timestamp,
2697 (unsigned long long)(rx_timestamp - beacon_timestamp),
2699 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2700 if (beacon_timestamp > rx_timestamp) {
2701 #ifndef CONFIG_MAC80211_IBSS_DEBUG
2702 if (net_ratelimit())
2704 printk(KERN_DEBUG "%s: beacon TSF higher than "
2705 "local TSF - IBSS merge with BSSID %s\n",
2706 dev->name, print_mac(mac, mgmt->bssid));
2707 ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
2708 ieee80211_ibss_add_sta(dev, NULL,
2709 mgmt->bssid, mgmt->sa);
2713 ieee80211_rx_bss_put(dev, bss);
2717 static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
2718 struct ieee80211_mgmt *mgmt,
2720 struct ieee80211_rx_status *rx_status)
2722 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
2726 static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
2727 struct ieee80211_mgmt *mgmt,
2729 struct ieee80211_rx_status *rx_status)
2731 struct ieee80211_sub_if_data *sdata;
2732 struct ieee80211_if_sta *ifsta;
2734 struct ieee802_11_elems elems;
2735 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2736 struct ieee80211_conf *conf = &local->hw.conf;
2739 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
2741 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2742 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
2744 ifsta = &sdata->u.sta;
2746 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
2747 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
2750 /* Process beacon from the current BSS */
2751 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2755 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
2757 if (elems.erp_info && elems.erp_info_len >= 1)
2758 changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
2760 if (elems.ht_cap_elem && elems.ht_info_elem &&
2761 elems.wmm_param && local->ops->conf_ht &&
2762 conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
2763 struct ieee80211_ht_bss_info bss_info;
2765 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2766 (struct ieee80211_ht_addt_info *)
2767 elems.ht_info_elem, &bss_info);
2768 /* check if AP changed bss inforamation */
2769 if ((conf->ht_bss_conf.primary_channel !=
2770 bss_info.primary_channel) ||
2771 (conf->ht_bss_conf.bss_cap != bss_info.bss_cap) ||
2772 (conf->ht_bss_conf.bss_op_mode != bss_info.bss_op_mode))
2773 ieee80211_hw_config_ht(local, 1, &conf->ht_conf,
2777 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
2778 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2779 elems.wmm_param_len);
2782 ieee80211_bss_info_change_notify(sdata, changed);
2786 static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
2787 struct ieee80211_if_sta *ifsta,
2788 struct ieee80211_mgmt *mgmt,
2790 struct ieee80211_rx_status *rx_status)
2792 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2793 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2795 struct sk_buff *skb;
2796 struct ieee80211_mgmt *resp;
2798 DECLARE_MAC_BUF(mac);
2799 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2800 DECLARE_MAC_BUF(mac2);
2801 DECLARE_MAC_BUF(mac3);
2804 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
2805 ifsta->state != IEEE80211_IBSS_JOINED ||
2806 len < 24 + 2 || !ifsta->probe_resp)
2809 if (local->ops->tx_last_beacon)
2810 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
2814 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2815 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
2816 "%s (tx_last_beacon=%d)\n",
2817 dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
2818 print_mac(mac3, mgmt->bssid), tx_last_beacon);
2819 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2821 if (!tx_last_beacon)
2824 if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
2825 memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
2828 end = ((u8 *) mgmt) + len;
2829 pos = mgmt->u.probe_req.variable;
2830 if (pos[0] != WLAN_EID_SSID ||
2831 pos + 2 + pos[1] > end) {
2832 if (net_ratelimit()) {
2833 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
2835 dev->name, print_mac(mac, mgmt->sa));
2840 (pos[1] != ifsta->ssid_len ||
2841 memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
2842 /* Ignore ProbeReq for foreign SSID */
2846 /* Reply with ProbeResp */
2847 skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
2851 resp = (struct ieee80211_mgmt *) skb->data;
2852 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2853 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2854 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
2855 dev->name, print_mac(mac, resp->da));
2856 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2857 ieee80211_sta_tx(dev, skb, 0);
2860 static void ieee80211_rx_mgmt_action(struct net_device *dev,
2861 struct ieee80211_if_sta *ifsta,
2862 struct ieee80211_mgmt *mgmt,
2864 struct ieee80211_rx_status *rx_status)
2866 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2868 if (len < IEEE80211_MIN_ACTION_SIZE)
2871 switch (mgmt->u.action.category) {
2872 case WLAN_CATEGORY_BACK:
2873 switch (mgmt->u.action.u.addba_req.action_code) {
2874 case WLAN_ACTION_ADDBA_REQ:
2875 if (len < (IEEE80211_MIN_ACTION_SIZE +
2876 sizeof(mgmt->u.action.u.addba_req)))
2878 ieee80211_sta_process_addba_request(dev, mgmt, len);
2880 case WLAN_ACTION_ADDBA_RESP:
2881 if (len < (IEEE80211_MIN_ACTION_SIZE +
2882 sizeof(mgmt->u.action.u.addba_resp)))
2884 ieee80211_sta_process_addba_resp(dev, mgmt, len);
2886 case WLAN_ACTION_DELBA:
2887 if (len < (IEEE80211_MIN_ACTION_SIZE +
2888 sizeof(mgmt->u.action.u.delba)))
2890 ieee80211_sta_process_delba(dev, mgmt, len);
2893 if (net_ratelimit())
2894 printk(KERN_DEBUG "%s: Rx unknown A-MPDU action\n",
2899 case PLINK_CATEGORY:
2900 if (ieee80211_vif_is_mesh(&sdata->vif))
2901 mesh_rx_plink_frame(dev, mgmt, len, rx_status);
2903 case MESH_PATH_SEL_CATEGORY:
2904 if (ieee80211_vif_is_mesh(&sdata->vif))
2905 mesh_rx_path_sel_frame(dev, mgmt, len);
2908 if (net_ratelimit())
2909 printk(KERN_DEBUG "%s: Rx unknown action frame - "
2910 "category=%d\n", dev->name, mgmt->u.action.category);
2915 void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
2916 struct ieee80211_rx_status *rx_status)
2918 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2919 struct ieee80211_sub_if_data *sdata;
2920 struct ieee80211_if_sta *ifsta;
2921 struct ieee80211_mgmt *mgmt;
2927 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2928 ifsta = &sdata->u.sta;
2930 mgmt = (struct ieee80211_mgmt *) skb->data;
2931 fc = le16_to_cpu(mgmt->frame_control);
2933 switch (fc & IEEE80211_FCTL_STYPE) {
2934 case IEEE80211_STYPE_PROBE_REQ:
2935 case IEEE80211_STYPE_PROBE_RESP:
2936 case IEEE80211_STYPE_BEACON:
2937 case IEEE80211_STYPE_ACTION:
2938 memcpy(skb->cb, rx_status, sizeof(*rx_status));
2939 case IEEE80211_STYPE_AUTH:
2940 case IEEE80211_STYPE_ASSOC_RESP:
2941 case IEEE80211_STYPE_REASSOC_RESP:
2942 case IEEE80211_STYPE_DEAUTH:
2943 case IEEE80211_STYPE_DISASSOC:
2944 skb_queue_tail(&ifsta->skb_queue, skb);
2945 queue_work(local->hw.workqueue, &ifsta->work);
2948 printk(KERN_DEBUG "%s: received unknown management frame - "
2949 "stype=%d\n", dev->name,
2950 (fc & IEEE80211_FCTL_STYPE) >> 4);
2959 static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
2960 struct sk_buff *skb)
2962 struct ieee80211_rx_status *rx_status;
2963 struct ieee80211_sub_if_data *sdata;
2964 struct ieee80211_if_sta *ifsta;
2965 struct ieee80211_mgmt *mgmt;
2968 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2969 ifsta = &sdata->u.sta;
2971 rx_status = (struct ieee80211_rx_status *) skb->cb;
2972 mgmt = (struct ieee80211_mgmt *) skb->data;
2973 fc = le16_to_cpu(mgmt->frame_control);
2975 switch (fc & IEEE80211_FCTL_STYPE) {
2976 case IEEE80211_STYPE_PROBE_REQ:
2977 ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
2980 case IEEE80211_STYPE_PROBE_RESP:
2981 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
2983 case IEEE80211_STYPE_BEACON:
2984 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
2986 case IEEE80211_STYPE_AUTH:
2987 ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len);
2989 case IEEE80211_STYPE_ASSOC_RESP:
2990 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
2992 case IEEE80211_STYPE_REASSOC_RESP:
2993 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
2995 case IEEE80211_STYPE_DEAUTH:
2996 ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len);
2998 case IEEE80211_STYPE_DISASSOC:
2999 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
3001 case IEEE80211_STYPE_ACTION:
3002 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len, rx_status);
3011 ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
3012 struct ieee80211_rx_status *rx_status)
3014 struct ieee80211_mgmt *mgmt;
3018 return RX_DROP_UNUSABLE;
3020 mgmt = (struct ieee80211_mgmt *) skb->data;
3021 fc = le16_to_cpu(mgmt->frame_control);
3023 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
3027 return RX_DROP_MONITOR;
3029 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
3030 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
3031 ieee80211_rx_mgmt_probe_resp(dev, mgmt,
3032 skb->len, rx_status);
3035 } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
3036 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
3046 static int ieee80211_sta_active_ibss(struct net_device *dev)
3048 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3050 struct sta_info *sta;
3051 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3055 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3056 if (sta->sdata == sdata &&
3057 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
3070 static void ieee80211_sta_expire(struct net_device *dev, unsigned long exp_time)
3072 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3073 struct sta_info *sta, *tmp;
3074 LIST_HEAD(tmp_list);
3075 DECLARE_MAC_BUF(mac);
3076 unsigned long flags;
3078 spin_lock_irqsave(&local->sta_lock, flags);
3079 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
3080 if (time_after(jiffies, sta->last_rx + exp_time)) {
3081 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
3082 dev->name, print_mac(mac, sta->addr));
3083 sta_info_unlink(&sta);
3085 list_add(&sta->list, &tmp_list);
3087 spin_unlock_irqrestore(&local->sta_lock, flags);
3092 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
3093 sta_info_destroy(sta);
3098 static void ieee80211_sta_merge_ibss(struct net_device *dev,
3099 struct ieee80211_if_sta *ifsta)
3101 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
3103 ieee80211_sta_expire(dev, IEEE80211_IBSS_INACTIVITY_LIMIT);
3104 if (ieee80211_sta_active_ibss(dev))
3107 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
3108 "IBSS networks with same SSID (merge)\n", dev->name);
3109 ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
3113 #ifdef CONFIG_MAC80211_MESH
3114 static void ieee80211_mesh_housekeeping(struct net_device *dev,
3115 struct ieee80211_if_sta *ifsta)
3117 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3120 ieee80211_sta_expire(dev, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
3121 mesh_path_expire(dev);
3123 free_plinks = mesh_plink_availables(sdata);
3124 if (free_plinks != sdata->u.sta.accepting_plinks)
3125 ieee80211_if_config_beacon(dev);
3127 mod_timer(&ifsta->timer, jiffies +
3128 IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
3132 void ieee80211_start_mesh(struct net_device *dev)
3134 struct ieee80211_if_sta *ifsta;
3135 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3136 ifsta = &sdata->u.sta;
3137 ifsta->state = IEEE80211_MESH_UP;
3138 ieee80211_sta_timer((unsigned long)sdata);
3143 void ieee80211_sta_timer(unsigned long data)
3145 struct ieee80211_sub_if_data *sdata =
3146 (struct ieee80211_sub_if_data *) data;
3147 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3148 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
3150 set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3151 queue_work(local->hw.workqueue, &ifsta->work);
3154 void ieee80211_sta_work(struct work_struct *work)
3156 struct ieee80211_sub_if_data *sdata =
3157 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
3158 struct net_device *dev = sdata->dev;
3159 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3160 struct ieee80211_if_sta *ifsta;
3161 struct sk_buff *skb;
3163 if (!netif_running(dev))
3166 if (local->sta_sw_scanning || local->sta_hw_scanning)
3169 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
3170 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
3171 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) {
3172 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
3173 "(type=%d)\n", dev->name, sdata->vif.type);
3176 ifsta = &sdata->u.sta;
3178 while ((skb = skb_dequeue(&ifsta->skb_queue)))
3179 ieee80211_sta_rx_queued_mgmt(dev, skb);
3181 #ifdef CONFIG_MAC80211_MESH
3182 if (ifsta->preq_queue_len &&
3184 ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
3185 mesh_path_start_discovery(dev);
3188 if (ifsta->state != IEEE80211_AUTHENTICATE &&
3189 ifsta->state != IEEE80211_ASSOCIATE &&
3190 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
3191 if (ifsta->scan_ssid_len)
3192 ieee80211_sta_start_scan(dev, ifsta->scan_ssid, ifsta->scan_ssid_len);
3194 ieee80211_sta_start_scan(dev, NULL, 0);
3198 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
3199 if (ieee80211_sta_config_auth(dev, ifsta))
3201 clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3202 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
3205 switch (ifsta->state) {
3206 case IEEE80211_DISABLED:
3208 case IEEE80211_AUTHENTICATE:
3209 ieee80211_authenticate(dev, ifsta);
3211 case IEEE80211_ASSOCIATE:
3212 ieee80211_associate(dev, ifsta);
3214 case IEEE80211_ASSOCIATED:
3215 ieee80211_associated(dev, ifsta);
3217 case IEEE80211_IBSS_SEARCH:
3218 ieee80211_sta_find_ibss(dev, ifsta);
3220 case IEEE80211_IBSS_JOINED:
3221 ieee80211_sta_merge_ibss(dev, ifsta);
3223 #ifdef CONFIG_MAC80211_MESH
3224 case IEEE80211_MESH_UP:
3225 ieee80211_mesh_housekeeping(dev, ifsta);
3229 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
3234 if (ieee80211_privacy_mismatch(dev, ifsta)) {
3235 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
3236 "mixed-cell disabled - disassociate\n", dev->name);
3238 ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
3239 ieee80211_set_disassoc(dev, ifsta, 0);
3244 static void ieee80211_sta_reset_auth(struct net_device *dev,
3245 struct ieee80211_if_sta *ifsta)
3247 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3249 if (local->ops->reset_tsf) {
3250 /* Reset own TSF to allow time synchronization work. */
3251 local->ops->reset_tsf(local_to_hw(local));
3254 ifsta->wmm_last_param_set = -1; /* allow any WMM update */
3257 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
3258 ifsta->auth_alg = WLAN_AUTH_OPEN;
3259 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
3260 ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
3261 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
3262 ifsta->auth_alg = WLAN_AUTH_LEAP;
3264 ifsta->auth_alg = WLAN_AUTH_OPEN;
3265 printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
3267 ifsta->auth_transaction = -1;
3268 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
3269 ifsta->auth_tries = ifsta->assoc_tries = 0;
3270 netif_carrier_off(dev);
3274 void ieee80211_sta_req_auth(struct net_device *dev,
3275 struct ieee80211_if_sta *ifsta)
3277 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3278 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3280 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
3283 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
3284 IEEE80211_STA_AUTO_BSSID_SEL)) &&
3285 (ifsta->flags & (IEEE80211_STA_SSID_SET |
3286 IEEE80211_STA_AUTO_SSID_SEL))) {
3287 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3288 queue_work(local->hw.workqueue, &ifsta->work);
3292 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
3293 const char *ssid, int ssid_len)
3295 int tmp, hidden_ssid;
3297 if (ssid_len == ifsta->ssid_len &&
3298 !memcmp(ifsta->ssid, ssid, ssid_len))
3301 if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
3307 if (ssid[tmp] != '\0') {
3313 if (hidden_ssid && ifsta->ssid_len == ssid_len)
3316 if (ssid_len == 1 && ssid[0] == ' ')
3322 static int ieee80211_sta_config_auth(struct net_device *dev,
3323 struct ieee80211_if_sta *ifsta)
3325 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3326 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3327 struct ieee80211_sta_bss *bss, *selected = NULL;
3328 int top_rssi = 0, freq;
3330 if (!(ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
3331 IEEE80211_STA_AUTO_BSSID_SEL | IEEE80211_STA_AUTO_CHANNEL_SEL))) {
3332 ifsta->state = IEEE80211_AUTHENTICATE;
3333 ieee80211_sta_reset_auth(dev, ifsta);
3337 spin_lock_bh(&local->sta_bss_lock);
3338 freq = local->oper_channel->center_freq;
3339 list_for_each_entry(bss, &local->sta_bss_list, list) {
3340 if (!(bss->capability & WLAN_CAPABILITY_ESS))
3343 if (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
3344 !!sdata->default_key)
3347 if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
3351 if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
3352 memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
3355 if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
3356 !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
3359 if (!selected || top_rssi < bss->rssi) {
3361 top_rssi = bss->rssi;
3365 atomic_inc(&selected->users);
3366 spin_unlock_bh(&local->sta_bss_lock);
3369 ieee80211_set_freq(local, selected->freq);
3370 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
3371 ieee80211_sta_set_ssid(dev, selected->ssid,
3372 selected->ssid_len);
3373 ieee80211_sta_set_bssid(dev, selected->bssid);
3374 ieee80211_sta_def_wmm_params(dev, selected, 0);
3375 ieee80211_rx_bss_put(dev, selected);
3376 ifsta->state = IEEE80211_AUTHENTICATE;
3377 ieee80211_sta_reset_auth(dev, ifsta);
3380 if (ifsta->state != IEEE80211_AUTHENTICATE) {
3381 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
3382 ieee80211_sta_start_scan(dev, NULL, 0);
3384 ieee80211_sta_start_scan(dev, ifsta->ssid,
3386 ifsta->state = IEEE80211_AUTHENTICATE;
3387 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3389 ifsta->state = IEEE80211_DISABLED;
3395 static int ieee80211_sta_create_ibss(struct net_device *dev,
3396 struct ieee80211_if_sta *ifsta)
3398 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3399 struct ieee80211_sta_bss *bss;
3400 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3401 struct ieee80211_supported_band *sband;
3402 u8 bssid[ETH_ALEN], *pos;
3404 DECLARE_MAC_BUF(mac);
3407 /* Easier testing, use fixed BSSID. */
3408 memset(bssid, 0xfe, ETH_ALEN);
3410 /* Generate random, not broadcast, locally administered BSSID. Mix in
3411 * own MAC address to make sure that devices that do not have proper
3412 * random number generator get different BSSID. */
3413 get_random_bytes(bssid, ETH_ALEN);
3414 for (i = 0; i < ETH_ALEN; i++)
3415 bssid[i] ^= dev->dev_addr[i];
3420 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
3421 dev->name, print_mac(mac, bssid));
3423 bss = ieee80211_rx_bss_add(dev, bssid,
3424 local->hw.conf.channel->center_freq,
3425 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
3429 bss->band = local->hw.conf.channel->band;
3430 sband = local->hw.wiphy->bands[bss->band];
3432 if (local->hw.conf.beacon_int == 0)
3433 local->hw.conf.beacon_int = 10000;
3434 bss->beacon_int = local->hw.conf.beacon_int;
3435 bss->last_update = jiffies;
3436 bss->capability = WLAN_CAPABILITY_IBSS;
3437 if (sdata->default_key) {
3438 bss->capability |= WLAN_CAPABILITY_PRIVACY;
3440 sdata->drop_unencrypted = 0;
3441 bss->supp_rates_len = sband->n_bitrates;
3442 pos = bss->supp_rates;
3443 for (i = 0; i < sband->n_bitrates; i++) {
3444 int rate = sband->bitrates[i].bitrate;
3445 *pos++ = (u8) (rate / 5);
3448 return ieee80211_sta_join_ibss(dev, ifsta, bss);
3452 static int ieee80211_sta_find_ibss(struct net_device *dev,
3453 struct ieee80211_if_sta *ifsta)
3455 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3456 struct ieee80211_sta_bss *bss;
3460 DECLARE_MAC_BUF(mac);
3461 DECLARE_MAC_BUF(mac2);
3463 if (ifsta->ssid_len == 0)
3466 active_ibss = ieee80211_sta_active_ibss(dev);
3467 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3468 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
3469 dev->name, active_ibss);
3470 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3471 spin_lock_bh(&local->sta_bss_lock);
3472 list_for_each_entry(bss, &local->sta_bss_list, list) {
3473 if (ifsta->ssid_len != bss->ssid_len ||
3474 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
3475 || !(bss->capability & WLAN_CAPABILITY_IBSS))
3477 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3478 printk(KERN_DEBUG " bssid=%s found\n",
3479 print_mac(mac, bss->bssid));
3480 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3481 memcpy(bssid, bss->bssid, ETH_ALEN);
3483 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
3486 spin_unlock_bh(&local->sta_bss_lock);
3488 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3489 printk(KERN_DEBUG " sta_find_ibss: selected %s current "
3490 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
3491 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3492 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
3493 (bss = ieee80211_rx_bss_get(dev, bssid,
3494 local->hw.conf.channel->center_freq,
3495 ifsta->ssid, ifsta->ssid_len))) {
3496 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
3497 " based on configured SSID\n",
3498 dev->name, print_mac(mac, bssid));
3499 return ieee80211_sta_join_ibss(dev, ifsta, bss);
3501 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3502 printk(KERN_DEBUG " did not try to join ibss\n");
3503 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3505 /* Selected IBSS not found in current scan results - try to scan */
3506 if (ifsta->state == IEEE80211_IBSS_JOINED &&
3507 !ieee80211_sta_active_ibss(dev)) {
3508 mod_timer(&ifsta->timer, jiffies +
3509 IEEE80211_IBSS_MERGE_INTERVAL);
3510 } else if (time_after(jiffies, local->last_scan_completed +
3511 IEEE80211_SCAN_INTERVAL)) {
3512 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
3513 "join\n", dev->name);
3514 return ieee80211_sta_req_scan(dev, ifsta->ssid,
3516 } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
3517 int interval = IEEE80211_SCAN_INTERVAL;
3519 if (time_after(jiffies, ifsta->ibss_join_req +
3520 IEEE80211_IBSS_JOIN_TIMEOUT)) {
3521 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
3522 (!(local->oper_channel->flags &
3523 IEEE80211_CHAN_NO_IBSS)))
3524 return ieee80211_sta_create_ibss(dev, ifsta);
3525 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
3526 printk(KERN_DEBUG "%s: IBSS not allowed on"
3527 " %d MHz\n", dev->name,
3528 local->hw.conf.channel->center_freq);
3531 /* No IBSS found - decrease scan interval and continue
3533 interval = IEEE80211_SCAN_INTERVAL_SLOW;
3536 ifsta->state = IEEE80211_IBSS_SEARCH;
3537 mod_timer(&ifsta->timer, jiffies + interval);
3545 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3547 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3548 struct ieee80211_if_sta *ifsta;
3550 if (len > IEEE80211_MAX_SSID_LEN)
3553 ifsta = &sdata->u.sta;
3555 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
3556 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
3557 memcpy(ifsta->ssid, ssid, len);
3558 memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
3559 ifsta->ssid_len = len;
3562 ifsta->flags |= IEEE80211_STA_SSID_SET;
3564 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
3565 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3566 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
3567 ifsta->ibss_join_req = jiffies;
3568 ifsta->state = IEEE80211_IBSS_SEARCH;
3569 return ieee80211_sta_find_ibss(dev, ifsta);
3575 int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
3577 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3578 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3579 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
3580 *len = ifsta->ssid_len;
3585 int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
3587 struct ieee80211_sub_if_data *sdata;
3588 struct ieee80211_if_sta *ifsta;
3591 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3592 ifsta = &sdata->u.sta;
3594 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
3595 memcpy(ifsta->bssid, bssid, ETH_ALEN);
3596 res = ieee80211_if_config(dev);
3598 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
3599 "the low-level driver\n", dev->name);
3604 if (is_valid_ether_addr(bssid))
3605 ifsta->flags |= IEEE80211_STA_BSSID_SET;
3607 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
3613 static void ieee80211_send_nullfunc(struct ieee80211_local *local,
3614 struct ieee80211_sub_if_data *sdata,
3617 struct sk_buff *skb;
3618 struct ieee80211_hdr *nullfunc;
3621 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
3623 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
3624 "frame\n", sdata->dev->name);
3627 skb_reserve(skb, local->hw.extra_tx_headroom);
3629 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
3630 memset(nullfunc, 0, 24);
3631 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
3632 IEEE80211_FCTL_TODS;
3634 fc |= IEEE80211_FCTL_PM;
3635 nullfunc->frame_control = cpu_to_le16(fc);
3636 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
3637 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
3638 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
3640 ieee80211_sta_tx(sdata->dev, skb, 0);
3644 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3646 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
3647 ieee80211_vif_is_mesh(&sdata->vif))
3648 ieee80211_sta_timer((unsigned long)sdata);
3651 void ieee80211_scan_completed(struct ieee80211_hw *hw)
3653 struct ieee80211_local *local = hw_to_local(hw);
3654 struct net_device *dev = local->scan_dev;
3655 struct ieee80211_sub_if_data *sdata;
3656 union iwreq_data wrqu;
3658 local->last_scan_completed = jiffies;
3659 memset(&wrqu, 0, sizeof(wrqu));
3660 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
3662 if (local->sta_hw_scanning) {
3663 local->sta_hw_scanning = 0;
3664 if (ieee80211_hw_config(local))
3665 printk(KERN_DEBUG "%s: failed to restore operational "
3666 "channel after scan\n", dev->name);
3667 /* Restart STA timer for HW scan case */
3669 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3670 ieee80211_restart_sta_timer(sdata);
3676 local->sta_sw_scanning = 0;
3677 if (ieee80211_hw_config(local))
3678 printk(KERN_DEBUG "%s: failed to restore operational "
3679 "channel after scan\n", dev->name);
3682 netif_tx_lock_bh(local->mdev);
3683 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
3684 local->ops->configure_filter(local_to_hw(local),
3685 FIF_BCN_PRBRESP_PROMISC,
3686 &local->filter_flags,
3687 local->mdev->mc_count,
3688 local->mdev->mc_list);
3690 netif_tx_unlock_bh(local->mdev);
3693 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3695 /* No need to wake the master device. */
3696 if (sdata->dev == local->mdev)
3699 /* Tell AP we're back */
3700 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3701 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
3702 ieee80211_send_nullfunc(local, sdata, 0);
3704 ieee80211_restart_sta_timer(sdata);
3706 netif_wake_queue(sdata->dev);
3711 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3712 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
3713 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3714 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
3715 (!ifsta->state == IEEE80211_IBSS_JOINED &&
3716 !ieee80211_sta_active_ibss(dev)))
3717 ieee80211_sta_find_ibss(dev, ifsta);
3720 EXPORT_SYMBOL(ieee80211_scan_completed);
3722 void ieee80211_sta_scan_work(struct work_struct *work)
3724 struct ieee80211_local *local =
3725 container_of(work, struct ieee80211_local, scan_work.work);
3726 struct net_device *dev = local->scan_dev;
3727 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3728 struct ieee80211_supported_band *sband;
3729 struct ieee80211_channel *chan;
3731 unsigned long next_delay = 0;
3733 if (!local->sta_sw_scanning)
3736 switch (local->scan_state) {
3737 case SCAN_SET_CHANNEL:
3739 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3740 * after we successfully scanned the last channel of the last
3741 * band (and the last band is supported by the hw)
3743 if (local->scan_band < IEEE80211_NUM_BANDS)
3744 sband = local->hw.wiphy->bands[local->scan_band];
3749 * If we are at an unsupported band and have more bands
3750 * left to scan, advance to the next supported one.
3752 while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
3754 sband = local->hw.wiphy->bands[local->scan_band];
3755 local->scan_channel_idx = 0;
3758 /* if no more bands/channels left, complete scan */
3759 if (!sband || local->scan_channel_idx >= sband->n_channels) {
3760 ieee80211_scan_completed(local_to_hw(local));
3764 chan = &sband->channels[local->scan_channel_idx];
3766 if (chan->flags & IEEE80211_CHAN_DISABLED ||
3767 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3768 chan->flags & IEEE80211_CHAN_NO_IBSS))
3772 local->scan_channel = chan;
3773 if (ieee80211_hw_config(local)) {
3774 printk(KERN_DEBUG "%s: failed to set freq to "
3775 "%d MHz for scan\n", dev->name,
3781 /* advance state machine to next channel/band */
3782 local->scan_channel_idx++;
3783 if (local->scan_channel_idx >= sband->n_channels) {
3785 * scan_band may end up == IEEE80211_NUM_BANDS, but
3786 * we'll catch that case above and complete the scan
3787 * if that is the case.
3790 local->scan_channel_idx = 0;
3796 next_delay = IEEE80211_PROBE_DELAY +
3797 usecs_to_jiffies(local->hw.channel_change_time);
3798 local->scan_state = SCAN_SEND_PROBE;
3800 case SCAN_SEND_PROBE:
3801 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3802 local->scan_state = SCAN_SET_CHANNEL;
3804 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
3806 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3807 local->scan_ssid_len);
3808 next_delay = IEEE80211_CHANNEL_TIME;
3812 if (local->sta_sw_scanning)
3813 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3818 static int ieee80211_sta_start_scan(struct net_device *dev,
3819 u8 *ssid, size_t ssid_len)
3821 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3822 struct ieee80211_sub_if_data *sdata;
3824 if (ssid_len > IEEE80211_MAX_SSID_LEN)
3827 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3828 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3831 * ScanType: ACTIVE, PASSIVE
3832 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3833 * a Probe frame during active scanning
3835 * MinChannelTime (>= ProbeDelay), in TU
3836 * MaxChannelTime: (>= MinChannelTime), in TU
3839 /* MLME-SCAN.confirm
3841 * ResultCode: SUCCESS, INVALID_PARAMETERS
3844 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3845 if (local->scan_dev == dev)
3850 if (local->ops->hw_scan) {
3851 int rc = local->ops->hw_scan(local_to_hw(local),
3854 local->sta_hw_scanning = 1;
3855 local->scan_dev = dev;
3860 local->sta_sw_scanning = 1;
3863 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3865 /* Don't stop the master interface, otherwise we can't transmit
3867 if (sdata->dev == local->mdev)
3870 netif_stop_queue(sdata->dev);
3871 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3872 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
3873 ieee80211_send_nullfunc(local, sdata, 1);
3878 local->scan_ssid_len = ssid_len;
3879 memcpy(local->scan_ssid, ssid, ssid_len);
3881 local->scan_ssid_len = 0;
3882 local->scan_state = SCAN_SET_CHANNEL;
3883 local->scan_channel_idx = 0;
3884 local->scan_band = IEEE80211_BAND_2GHZ;
3885 local->scan_dev = dev;
3887 netif_tx_lock_bh(local->mdev);
3888 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
3889 local->ops->configure_filter(local_to_hw(local),
3890 FIF_BCN_PRBRESP_PROMISC,
3891 &local->filter_flags,
3892 local->mdev->mc_count,
3893 local->mdev->mc_list);
3894 netif_tx_unlock_bh(local->mdev);
3896 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3897 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3898 IEEE80211_CHANNEL_TIME);
3904 int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
3906 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3907 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3908 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3910 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
3911 return ieee80211_sta_start_scan(dev, ssid, ssid_len);
3913 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3914 if (local->scan_dev == dev)
3919 ifsta->scan_ssid_len = ssid_len;
3921 memcpy(ifsta->scan_ssid, ssid, ssid_len);
3922 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
3923 queue_work(local->hw.workqueue, &ifsta->work);
3928 ieee80211_sta_scan_result(struct net_device *dev,
3929 struct ieee80211_sta_bss *bss,
3930 char *current_ev, char *end_buf)
3932 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3933 struct iw_event iwe;
3935 if (time_after(jiffies,
3936 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
3939 memset(&iwe, 0, sizeof(iwe));
3940 iwe.cmd = SIOCGIWAP;
3941 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
3942 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
3943 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3946 memset(&iwe, 0, sizeof(iwe));
3947 iwe.cmd = SIOCGIWESSID;
3948 if (bss_mesh_cfg(bss)) {
3949 iwe.u.data.length = bss_mesh_id_len(bss);
3950 iwe.u.data.flags = 1;
3951 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3954 iwe.u.data.length = bss->ssid_len;
3955 iwe.u.data.flags = 1;
3956 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3960 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
3961 || bss_mesh_cfg(bss)) {
3962 memset(&iwe, 0, sizeof(iwe));
3963 iwe.cmd = SIOCGIWMODE;
3964 if (bss_mesh_cfg(bss))
3965 iwe.u.mode = IW_MODE_MESH;
3966 else if (bss->capability & WLAN_CAPABILITY_ESS)
3967 iwe.u.mode = IW_MODE_MASTER;
3969 iwe.u.mode = IW_MODE_ADHOC;
3970 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3974 memset(&iwe, 0, sizeof(iwe));
3975 iwe.cmd = SIOCGIWFREQ;
3976 iwe.u.freq.m = bss->freq;
3978 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3981 memset(&iwe, 0, sizeof(iwe));
3982 iwe.cmd = SIOCGIWFREQ;
3983 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
3985 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3988 memset(&iwe, 0, sizeof(iwe));
3990 iwe.u.qual.qual = bss->signal;
3991 iwe.u.qual.level = bss->rssi;
3992 iwe.u.qual.noise = bss->noise;
3993 iwe.u.qual.updated = local->wstats_flags;
3994 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3997 memset(&iwe, 0, sizeof(iwe));
3998 iwe.cmd = SIOCGIWENCODE;
3999 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
4000 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4002 iwe.u.data.flags = IW_ENCODE_DISABLED;
4003 iwe.u.data.length = 0;
4004 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
4006 if (bss && bss->wpa_ie) {
4007 memset(&iwe, 0, sizeof(iwe));
4008 iwe.cmd = IWEVGENIE;
4009 iwe.u.data.length = bss->wpa_ie_len;
4010 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
4014 if (bss && bss->rsn_ie) {
4015 memset(&iwe, 0, sizeof(iwe));
4016 iwe.cmd = IWEVGENIE;
4017 iwe.u.data.length = bss->rsn_ie_len;
4018 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
4022 if (bss && bss->supp_rates_len > 0) {
4023 /* display all supported rates in readable format */
4024 char *p = current_ev + IW_EV_LCP_LEN;
4027 memset(&iwe, 0, sizeof(iwe));
4028 iwe.cmd = SIOCGIWRATE;
4029 /* Those two flags are ignored... */
4030 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4032 for (i = 0; i < bss->supp_rates_len; i++) {
4033 iwe.u.bitrate.value = ((bss->supp_rates[i] &
4035 p = iwe_stream_add_value(current_ev, p,
4036 end_buf, &iwe, IW_EV_PARAM_LEN);
4043 buf = kmalloc(30, GFP_ATOMIC);
4045 memset(&iwe, 0, sizeof(iwe));
4046 iwe.cmd = IWEVCUSTOM;
4047 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
4048 iwe.u.data.length = strlen(buf);
4049 current_ev = iwe_stream_add_point(current_ev, end_buf,
4055 if (bss_mesh_cfg(bss)) {
4057 u8 *cfg = bss_mesh_cfg(bss);
4058 buf = kmalloc(50, GFP_ATOMIC);
4060 memset(&iwe, 0, sizeof(iwe));
4061 iwe.cmd = IWEVCUSTOM;
4062 sprintf(buf, "Mesh network (version %d)", cfg[0]);
4063 iwe.u.data.length = strlen(buf);
4064 current_ev = iwe_stream_add_point(current_ev, end_buf,
4066 sprintf(buf, "Path Selection Protocol ID: "
4067 "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
4069 iwe.u.data.length = strlen(buf);
4070 current_ev = iwe_stream_add_point(current_ev, end_buf,
4072 sprintf(buf, "Path Selection Metric ID: "
4073 "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
4075 iwe.u.data.length = strlen(buf);
4076 current_ev = iwe_stream_add_point(current_ev, end_buf,
4078 sprintf(buf, "Congestion Control Mode ID: "
4079 "0x%02X%02X%02X%02X", cfg[9], cfg[10],
4081 iwe.u.data.length = strlen(buf);
4082 current_ev = iwe_stream_add_point(current_ev, end_buf,
4084 sprintf(buf, "Channel Precedence: "
4085 "0x%02X%02X%02X%02X", cfg[13], cfg[14],
4087 iwe.u.data.length = strlen(buf);
4088 current_ev = iwe_stream_add_point(current_ev, end_buf,
4098 int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
4100 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4101 char *current_ev = buf;
4102 char *end_buf = buf + len;
4103 struct ieee80211_sta_bss *bss;
4105 spin_lock_bh(&local->sta_bss_lock);
4106 list_for_each_entry(bss, &local->sta_bss_list, list) {
4107 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
4108 spin_unlock_bh(&local->sta_bss_lock);
4111 current_ev = ieee80211_sta_scan_result(dev, bss, current_ev,
4114 spin_unlock_bh(&local->sta_bss_lock);
4115 return current_ev - buf;
4119 int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
4121 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4122 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4123 kfree(ifsta->extra_ie);
4125 ifsta->extra_ie = NULL;
4126 ifsta->extra_ie_len = 0;
4129 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
4130 if (!ifsta->extra_ie) {
4131 ifsta->extra_ie_len = 0;
4134 memcpy(ifsta->extra_ie, ie, len);
4135 ifsta->extra_ie_len = len;
4140 struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
4141 struct sk_buff *skb, u8 *bssid,
4144 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4145 struct sta_info *sta;
4146 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4147 DECLARE_MAC_BUF(mac);
4149 /* TODO: Could consider removing the least recently used entry and
4150 * allow new one to be added. */
4151 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
4152 if (net_ratelimit()) {
4153 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
4154 "entry %s\n", dev->name, print_mac(mac, addr));
4159 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
4160 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
4162 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
4166 sta->flags |= WLAN_STA_AUTHORIZED;
4168 sta->supp_rates[local->hw.conf.channel->band] =
4169 sdata->u.sta.supp_rates_bits[local->hw.conf.channel->band];
4171 rate_control_rate_init(sta, local);
4173 if (sta_info_insert(sta))
4180 int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
4182 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4183 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4185 printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
4188 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
4189 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
4192 ieee80211_send_deauth(dev, ifsta, reason);
4193 ieee80211_set_disassoc(dev, ifsta, 1);
4198 int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
4200 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4201 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4203 printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
4206 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
4209 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
4212 ieee80211_send_disassoc(dev, ifsta, reason);
4213 ieee80211_set_disassoc(dev, ifsta, 0);