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) {
944 sta_info_destroy(sta);
949 ifsta->state = IEEE80211_DISABLED;
950 ieee80211_set_associated(dev, ifsta, 0);
952 mod_timer(&ifsta->timer, jiffies +
953 IEEE80211_MONITORING_INTERVAL);
958 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
959 u8 *ssid, size_t ssid_len)
961 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
962 struct ieee80211_supported_band *sband;
964 struct ieee80211_mgmt *mgmt;
965 u8 *pos, *supp_rates, *esupp_rates = NULL;
968 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
970 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
971 "request\n", dev->name);
974 skb_reserve(skb, local->hw.extra_tx_headroom);
976 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
978 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
979 IEEE80211_STYPE_PROBE_REQ);
980 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
982 memcpy(mgmt->da, dst, ETH_ALEN);
983 memcpy(mgmt->bssid, dst, ETH_ALEN);
985 memset(mgmt->da, 0xff, ETH_ALEN);
986 memset(mgmt->bssid, 0xff, ETH_ALEN);
988 pos = skb_put(skb, 2 + ssid_len);
989 *pos++ = WLAN_EID_SSID;
991 memcpy(pos, ssid, ssid_len);
993 supp_rates = skb_put(skb, 2);
994 supp_rates[0] = WLAN_EID_SUPP_RATES;
996 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
998 for (i = 0; i < sband->n_bitrates; i++) {
999 struct ieee80211_rate *rate = &sband->bitrates[i];
1001 pos = skb_put(skb, 1);
1003 } else if (supp_rates[1] == 8) {
1004 esupp_rates = skb_put(skb, 3);
1005 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
1007 pos = &esupp_rates[2];
1009 pos = skb_put(skb, 1);
1012 *pos = rate->bitrate / 5;
1015 ieee80211_sta_tx(dev, skb, 0);
1019 static int ieee80211_sta_wep_configured(struct net_device *dev)
1021 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1022 if (!sdata || !sdata->default_key ||
1023 sdata->default_key->conf.alg != ALG_WEP)
1029 static void ieee80211_auth_completed(struct net_device *dev,
1030 struct ieee80211_if_sta *ifsta)
1032 printk(KERN_DEBUG "%s: authenticated\n", dev->name);
1033 ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
1034 ieee80211_associate(dev, ifsta);
1038 static void ieee80211_auth_challenge(struct net_device *dev,
1039 struct ieee80211_if_sta *ifsta,
1040 struct ieee80211_mgmt *mgmt,
1044 struct ieee802_11_elems elems;
1046 printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
1047 pos = mgmt->u.auth.variable;
1048 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1049 if (!elems.challenge) {
1050 printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
1051 "frame\n", dev->name);
1054 ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
1055 elems.challenge_len + 2, 1);
1058 static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
1059 u8 dialog_token, u16 status, u16 policy,
1060 u16 buf_size, u16 timeout)
1062 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1063 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1064 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1065 struct sk_buff *skb;
1066 struct ieee80211_mgmt *mgmt;
1069 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1070 sizeof(mgmt->u.action.u.addba_resp));
1072 printk(KERN_DEBUG "%s: failed to allocate buffer "
1073 "for addba resp frame\n", dev->name);
1077 skb_reserve(skb, local->hw.extra_tx_headroom);
1078 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1079 memset(mgmt, 0, 24);
1080 memcpy(mgmt->da, da, ETH_ALEN);
1081 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1082 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1083 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1085 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1086 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1087 IEEE80211_STYPE_ACTION);
1089 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
1090 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1091 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
1092 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
1094 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
1095 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1096 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
1098 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
1099 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
1100 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
1102 ieee80211_sta_tx(dev, skb, 0);
1107 void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
1108 u16 tid, u8 dialog_token, u16 start_seq_num,
1109 u16 agg_size, u16 timeout)
1111 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1112 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1113 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1114 struct sk_buff *skb;
1115 struct ieee80211_mgmt *mgmt;
1118 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1119 sizeof(mgmt->u.action.u.addba_req));
1123 printk(KERN_ERR "%s: failed to allocate buffer "
1124 "for addba request frame\n", dev->name);
1127 skb_reserve(skb, local->hw.extra_tx_headroom);
1128 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1129 memset(mgmt, 0, 24);
1130 memcpy(mgmt->da, da, ETH_ALEN);
1131 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1132 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1133 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1135 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1137 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1138 IEEE80211_STYPE_ACTION);
1140 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
1142 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1143 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
1145 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
1146 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
1147 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1148 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
1150 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
1152 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
1153 mgmt->u.action.u.addba_req.start_seq_num =
1154 cpu_to_le16(start_seq_num << 4);
1156 ieee80211_sta_tx(dev, skb, 0);
1159 static void ieee80211_sta_process_addba_request(struct net_device *dev,
1160 struct ieee80211_mgmt *mgmt,
1163 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1164 struct ieee80211_hw *hw = &local->hw;
1165 struct ieee80211_conf *conf = &hw->conf;
1166 struct sta_info *sta;
1167 struct tid_ampdu_rx *tid_agg_rx;
1168 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
1170 int ret = -EOPNOTSUPP;
1171 DECLARE_MAC_BUF(mac);
1175 sta = sta_info_get(local, mgmt->sa);
1181 /* extract session parameters from addba request frame */
1182 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
1183 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
1185 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
1187 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1188 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
1189 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1190 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
1192 status = WLAN_STATUS_REQUEST_DECLINED;
1194 /* sanity check for incoming parameters:
1195 * check if configuration can support the BA policy
1196 * and if buffer size does not exceeds max value */
1197 if (((ba_policy != 1)
1198 && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
1199 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
1200 status = WLAN_STATUS_INVALID_QOS_PARAM;
1201 #ifdef CONFIG_MAC80211_HT_DEBUG
1202 if (net_ratelimit())
1203 printk(KERN_DEBUG "AddBA Req with bad params from "
1204 "%s on tid %u. policy %d, buffer size %d\n",
1205 print_mac(mac, mgmt->sa), tid, ba_policy,
1207 #endif /* CONFIG_MAC80211_HT_DEBUG */
1210 /* determine default buffer size */
1211 if (buf_size == 0) {
1212 struct ieee80211_supported_band *sband;
1214 sband = local->hw.wiphy->bands[conf->channel->band];
1215 buf_size = IEEE80211_MIN_AMPDU_BUF;
1216 buf_size = buf_size << sband->ht_info.ampdu_factor;
1219 tid_agg_rx = &sta->ampdu_mlme.tid_rx[tid];
1221 /* examine state machine */
1222 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1224 if (tid_agg_rx->state != HT_AGG_STATE_IDLE) {
1225 #ifdef CONFIG_MAC80211_HT_DEBUG
1226 if (net_ratelimit())
1227 printk(KERN_DEBUG "unexpected AddBA Req from "
1229 print_mac(mac, mgmt->sa), tid);
1230 #endif /* CONFIG_MAC80211_HT_DEBUG */
1234 /* prepare reordering buffer */
1235 tid_agg_rx->reorder_buf =
1236 kmalloc(buf_size * sizeof(struct sk_buf *), GFP_ATOMIC);
1237 if (!tid_agg_rx->reorder_buf) {
1238 if (net_ratelimit())
1239 printk(KERN_ERR "can not allocate reordering buffer "
1240 "to tid %d\n", tid);
1243 memset(tid_agg_rx->reorder_buf, 0,
1244 buf_size * sizeof(struct sk_buf *));
1246 if (local->ops->ampdu_action)
1247 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
1248 sta->addr, tid, &start_seq_num);
1249 #ifdef CONFIG_MAC80211_HT_DEBUG
1250 printk(KERN_DEBUG "Rx A-MPDU on tid %d result %d", tid, ret);
1251 #endif /* CONFIG_MAC80211_HT_DEBUG */
1254 kfree(tid_agg_rx->reorder_buf);
1258 /* change state and send addba resp */
1259 tid_agg_rx->state = HT_AGG_STATE_OPERATIONAL;
1260 tid_agg_rx->dialog_token = dialog_token;
1261 tid_agg_rx->ssn = start_seq_num;
1262 tid_agg_rx->head_seq_num = start_seq_num;
1263 tid_agg_rx->buf_size = buf_size;
1264 tid_agg_rx->timeout = timeout;
1265 tid_agg_rx->stored_mpdu_num = 0;
1266 status = WLAN_STATUS_SUCCESS;
1268 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1271 ieee80211_send_addba_resp(sta->sdata->dev, sta->addr, tid,
1272 dialog_token, status, 1, buf_size, timeout);
1276 static void ieee80211_sta_process_addba_resp(struct net_device *dev,
1277 struct ieee80211_mgmt *mgmt,
1280 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1281 struct ieee80211_hw *hw = &local->hw;
1282 struct sta_info *sta;
1289 sta = sta_info_get(local, mgmt->sa);
1295 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
1296 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1298 state = &sta->ampdu_mlme.tid_tx[tid].state;
1300 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1302 if (mgmt->u.action.u.addba_resp.dialog_token !=
1303 sta->ampdu_mlme.tid_tx[tid].dialog_token) {
1304 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1305 #ifdef CONFIG_MAC80211_HT_DEBUG
1306 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1307 #endif /* CONFIG_MAC80211_HT_DEBUG */
1312 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
1313 #ifdef CONFIG_MAC80211_HT_DEBUG
1314 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1315 #endif /* CONFIG_MAC80211_HT_DEBUG */
1316 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1317 == WLAN_STATUS_SUCCESS) {
1318 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1319 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1320 printk(KERN_DEBUG "state not HT_ADDBA_REQUESTED_MSK:"
1326 if (*state & HT_ADDBA_RECEIVED_MSK)
1327 printk(KERN_DEBUG "double addBA response\n");
1329 *state |= HT_ADDBA_RECEIVED_MSK;
1330 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
1332 if (*state == HT_AGG_STATE_OPERATIONAL) {
1333 printk(KERN_DEBUG "Aggregation on for tid %d \n", tid);
1334 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1337 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1338 printk(KERN_DEBUG "recipient accepted agg: tid %d \n", tid);
1340 printk(KERN_DEBUG "recipient rejected agg: tid %d \n", tid);
1342 sta->ampdu_mlme.tid_tx[tid].addba_req_num++;
1343 /* this will allow the state check in stop_BA_session */
1344 *state = HT_AGG_STATE_OPERATIONAL;
1345 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1346 ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
1347 WLAN_BACK_INITIATOR);
1352 void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
1353 u16 initiator, u16 reason_code)
1355 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1356 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1357 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1358 struct sk_buff *skb;
1359 struct ieee80211_mgmt *mgmt;
1362 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1363 sizeof(mgmt->u.action.u.delba));
1366 printk(KERN_ERR "%s: failed to allocate buffer "
1367 "for delba frame\n", dev->name);
1371 skb_reserve(skb, local->hw.extra_tx_headroom);
1372 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1373 memset(mgmt, 0, 24);
1374 memcpy(mgmt->da, da, ETH_ALEN);
1375 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1376 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1377 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1379 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1380 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1381 IEEE80211_STYPE_ACTION);
1383 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
1385 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1386 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1387 params = (u16)(initiator << 11); /* bit 11 initiator */
1388 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1390 mgmt->u.action.u.delba.params = cpu_to_le16(params);
1391 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1393 ieee80211_sta_tx(dev, skb, 0);
1396 void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1397 u16 initiator, u16 reason)
1399 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1400 struct ieee80211_hw *hw = &local->hw;
1401 struct sta_info *sta;
1406 sta = sta_info_get(local, ra);
1412 /* check if TID is in operational state */
1413 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1414 if (sta->ampdu_mlme.tid_rx[tid].state
1415 != HT_AGG_STATE_OPERATIONAL) {
1416 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1420 sta->ampdu_mlme.tid_rx[tid].state =
1421 HT_AGG_STATE_REQ_STOP_BA_MSK |
1422 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
1423 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1425 /* stop HW Rx aggregation. ampdu_action existence
1426 * already verified in session init so we add the BUG_ON */
1427 BUG_ON(!local->ops->ampdu_action);
1429 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
1432 printk(KERN_DEBUG "HW problem - can not stop rx "
1433 "aggergation for tid %d\n", tid);
1435 /* shutdown timer has not expired */
1436 if (initiator != WLAN_BACK_TIMER)
1437 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid].
1440 /* check if this is a self generated aggregation halt */
1441 if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
1442 ieee80211_send_delba(dev, ra, tid, 0, reason);
1444 /* free the reordering buffer */
1445 for (i = 0; i < sta->ampdu_mlme.tid_rx[tid].buf_size; i++) {
1446 if (sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]) {
1447 /* release the reordered frames */
1448 dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]);
1449 sta->ampdu_mlme.tid_rx[tid].stored_mpdu_num--;
1450 sta->ampdu_mlme.tid_rx[tid].reorder_buf[i] = NULL;
1453 kfree(sta->ampdu_mlme.tid_rx[tid].reorder_buf);
1455 sta->ampdu_mlme.tid_rx[tid].state = HT_AGG_STATE_IDLE;
1460 static void ieee80211_sta_process_delba(struct net_device *dev,
1461 struct ieee80211_mgmt *mgmt, size_t len)
1463 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1464 struct sta_info *sta;
1467 DECLARE_MAC_BUF(mac);
1471 sta = sta_info_get(local, mgmt->sa);
1477 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1478 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1479 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1481 #ifdef CONFIG_MAC80211_HT_DEBUG
1482 if (net_ratelimit())
1483 printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
1484 print_mac(mac, mgmt->sa),
1485 initiator ? "initiator" : "recipient", tid,
1486 mgmt->u.action.u.delba.reason_code);
1487 #endif /* CONFIG_MAC80211_HT_DEBUG */
1489 if (initiator == WLAN_BACK_INITIATOR)
1490 ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
1491 WLAN_BACK_INITIATOR, 0);
1492 else { /* WLAN_BACK_RECIPIENT */
1493 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1494 sta->ampdu_mlme.tid_tx[tid].state =
1495 HT_AGG_STATE_OPERATIONAL;
1496 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1497 ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
1498 WLAN_BACK_RECIPIENT);
1504 * After sending add Block Ack request we activated a timer until
1505 * add Block Ack response will arrive from the recipient.
1506 * If this timer expires sta_addba_resp_timer_expired will be executed.
1508 void sta_addba_resp_timer_expired(unsigned long data)
1510 /* not an elegant detour, but there is no choice as the timer passes
1511 * only one argument, and both sta_info and TID are needed, so init
1512 * flow in sta_info_create gives the TID as data, while the timer_to_id
1513 * array gives the sta through container_of */
1514 u16 tid = *(int *)data;
1515 struct sta_info *temp_sta = container_of((void *)data,
1516 struct sta_info, timer_to_tid[tid]);
1518 struct ieee80211_local *local = temp_sta->local;
1519 struct ieee80211_hw *hw = &local->hw;
1520 struct sta_info *sta;
1525 sta = sta_info_get(local, temp_sta->addr);
1531 state = &sta->ampdu_mlme.tid_tx[tid].state;
1532 /* check if the TID waits for addBA response */
1533 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1534 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1535 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1536 *state = HT_AGG_STATE_IDLE;
1537 printk(KERN_DEBUG "timer expired on tid %d but we are not "
1538 "expecting addBA response there", tid);
1539 goto timer_expired_exit;
1542 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
1544 /* go through the state check in stop_BA_session */
1545 *state = HT_AGG_STATE_OPERATIONAL;
1546 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1547 ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
1548 WLAN_BACK_INITIATOR);
1555 * After accepting the AddBA Request we activated a timer,
1556 * resetting it after each frame that arrives from the originator.
1557 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1559 void sta_rx_agg_session_timer_expired(unsigned long data)
1561 /* not an elegant detour, but there is no choice as the timer passes
1562 * only one argument, and verious sta_info are needed here, so init
1563 * flow in sta_info_create gives the TID as data, while the timer_to_id
1564 * array gives the sta through container_of */
1565 u8 *ptid = (u8 *)data;
1566 u8 *timer_to_id = ptid - *ptid;
1567 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
1570 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
1571 ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr,
1572 (u16)*ptid, WLAN_BACK_TIMER,
1573 WLAN_REASON_QSTA_TIMEOUT);
1576 void ieee80211_sta_tear_down_BA_sessions(struct net_device *dev, u8 *addr)
1578 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1581 for (i = 0; i < STA_TID_NUM; i++) {
1582 ieee80211_stop_tx_ba_session(&local->hw, addr, i,
1583 WLAN_BACK_INITIATOR);
1584 ieee80211_sta_stop_rx_ba_session(dev, addr, i,
1585 WLAN_BACK_RECIPIENT,
1586 WLAN_REASON_QSTA_LEAVE_QBSS);
1590 static void ieee80211_rx_mgmt_auth(struct net_device *dev,
1591 struct ieee80211_if_sta *ifsta,
1592 struct ieee80211_mgmt *mgmt,
1595 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1596 u16 auth_alg, auth_transaction, status_code;
1597 DECLARE_MAC_BUF(mac);
1599 if (ifsta->state != IEEE80211_AUTHENTICATE &&
1600 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
1601 printk(KERN_DEBUG "%s: authentication frame received from "
1602 "%s, but not in authenticate state - ignored\n",
1603 dev->name, print_mac(mac, mgmt->sa));
1608 printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
1609 "received from %s - ignored\n",
1610 dev->name, len, print_mac(mac, mgmt->sa));
1614 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
1615 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1616 printk(KERN_DEBUG "%s: authentication frame received from "
1617 "unknown AP (SA=%s BSSID=%s) - "
1618 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1619 print_mac(mac, mgmt->bssid));
1623 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
1624 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
1625 printk(KERN_DEBUG "%s: authentication frame received from "
1626 "unknown BSSID (SA=%s BSSID=%s) - "
1627 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1628 print_mac(mac, mgmt->bssid));
1632 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1633 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1634 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1636 printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d "
1637 "transaction=%d status=%d)\n",
1638 dev->name, print_mac(mac, mgmt->sa), auth_alg,
1639 auth_transaction, status_code);
1641 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
1642 /* IEEE 802.11 standard does not require authentication in IBSS
1643 * networks and most implementations do not seem to use it.
1644 * However, try to reply to authentication attempts if someone
1645 * has actually implemented this.
1646 * TODO: Could implement shared key authentication. */
1647 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
1648 printk(KERN_DEBUG "%s: unexpected IBSS authentication "
1649 "frame (alg=%d transaction=%d)\n",
1650 dev->name, auth_alg, auth_transaction);
1653 ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
1656 if (auth_alg != ifsta->auth_alg ||
1657 auth_transaction != ifsta->auth_transaction) {
1658 printk(KERN_DEBUG "%s: unexpected authentication frame "
1659 "(alg=%d transaction=%d)\n",
1660 dev->name, auth_alg, auth_transaction);
1664 if (status_code != WLAN_STATUS_SUCCESS) {
1665 printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
1666 "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
1667 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1669 const int num_algs = ARRAY_SIZE(algs);
1671 algs[0] = algs[1] = algs[2] = 0xff;
1672 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1673 algs[0] = WLAN_AUTH_OPEN;
1674 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1675 algs[1] = WLAN_AUTH_SHARED_KEY;
1676 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1677 algs[2] = WLAN_AUTH_LEAP;
1678 if (ifsta->auth_alg == WLAN_AUTH_OPEN)
1680 else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
1684 for (i = 0; i < num_algs; i++) {
1686 if (pos >= num_algs)
1688 if (algs[pos] == ifsta->auth_alg ||
1691 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1692 !ieee80211_sta_wep_configured(dev))
1694 ifsta->auth_alg = algs[pos];
1695 printk(KERN_DEBUG "%s: set auth_alg=%d for "
1697 dev->name, ifsta->auth_alg);
1704 switch (ifsta->auth_alg) {
1705 case WLAN_AUTH_OPEN:
1706 case WLAN_AUTH_LEAP:
1707 ieee80211_auth_completed(dev, ifsta);
1709 case WLAN_AUTH_SHARED_KEY:
1710 if (ifsta->auth_transaction == 4)
1711 ieee80211_auth_completed(dev, ifsta);
1713 ieee80211_auth_challenge(dev, ifsta, mgmt, len);
1719 static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
1720 struct ieee80211_if_sta *ifsta,
1721 struct ieee80211_mgmt *mgmt,
1725 DECLARE_MAC_BUF(mac);
1728 printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
1729 "received from %s - ignored\n",
1730 dev->name, len, print_mac(mac, mgmt->sa));
1734 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1735 printk(KERN_DEBUG "%s: deauthentication frame received from "
1736 "unknown AP (SA=%s BSSID=%s) - "
1737 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1738 print_mac(mac, mgmt->bssid));
1742 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1744 printk(KERN_DEBUG "%s: RX deauthentication from %s"
1746 dev->name, print_mac(mac, mgmt->sa), reason_code);
1748 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) {
1749 printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
1752 if (ifsta->state == IEEE80211_AUTHENTICATE ||
1753 ifsta->state == IEEE80211_ASSOCIATE ||
1754 ifsta->state == IEEE80211_ASSOCIATED) {
1755 ifsta->state = IEEE80211_AUTHENTICATE;
1756 mod_timer(&ifsta->timer, jiffies +
1757 IEEE80211_RETRY_AUTH_INTERVAL);
1760 ieee80211_set_disassoc(dev, ifsta, 1);
1761 ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
1765 static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
1766 struct ieee80211_if_sta *ifsta,
1767 struct ieee80211_mgmt *mgmt,
1771 DECLARE_MAC_BUF(mac);
1774 printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
1775 "received from %s - ignored\n",
1776 dev->name, len, print_mac(mac, mgmt->sa));
1780 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1781 printk(KERN_DEBUG "%s: disassociation frame received from "
1782 "unknown AP (SA=%s BSSID=%s) - "
1783 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1784 print_mac(mac, mgmt->bssid));
1788 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1790 printk(KERN_DEBUG "%s: RX disassociation from %s"
1792 dev->name, print_mac(mac, mgmt->sa), reason_code);
1794 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
1795 printk(KERN_DEBUG "%s: disassociated\n", dev->name);
1797 if (ifsta->state == IEEE80211_ASSOCIATED) {
1798 ifsta->state = IEEE80211_ASSOCIATE;
1799 mod_timer(&ifsta->timer, jiffies +
1800 IEEE80211_RETRY_AUTH_INTERVAL);
1803 ieee80211_set_disassoc(dev, ifsta, 0);
1807 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1808 struct ieee80211_if_sta *ifsta,
1809 struct ieee80211_mgmt *mgmt,
1813 struct ieee80211_local *local = sdata->local;
1814 struct net_device *dev = sdata->dev;
1815 struct ieee80211_supported_band *sband;
1816 struct sta_info *sta;
1817 u64 rates, basic_rates;
1818 u16 capab_info, status_code, aid;
1819 struct ieee802_11_elems elems;
1820 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
1823 DECLARE_MAC_BUF(mac);
1824 bool have_higher_than_11mbit = false;
1826 /* AssocResp and ReassocResp have identical structure, so process both
1827 * of them in this function. */
1829 if (ifsta->state != IEEE80211_ASSOCIATE) {
1830 printk(KERN_DEBUG "%s: association frame received from "
1831 "%s, but not in associate state - ignored\n",
1832 dev->name, print_mac(mac, mgmt->sa));
1837 printk(KERN_DEBUG "%s: too short (%zd) association frame "
1838 "received from %s - ignored\n",
1839 dev->name, len, print_mac(mac, mgmt->sa));
1843 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1844 printk(KERN_DEBUG "%s: association frame received from "
1845 "unknown AP (SA=%s BSSID=%s) - "
1846 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1847 print_mac(mac, mgmt->bssid));
1851 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1852 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1853 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1855 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
1856 "status=%d aid=%d)\n",
1857 dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
1858 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1860 if (status_code != WLAN_STATUS_SUCCESS) {
1861 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1862 dev->name, status_code);
1863 /* if this was a reassociation, ensure we try a "full"
1864 * association next time. This works around some broken APs
1865 * which do not correctly reject reassociation requests. */
1866 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1870 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1871 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1872 "set\n", dev->name, aid);
1873 aid &= ~(BIT(15) | BIT(14));
1875 pos = mgmt->u.assoc_resp.variable;
1876 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1878 if (!elems.supp_rates) {
1879 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1884 printk(KERN_DEBUG "%s: associated\n", dev->name);
1886 ifsta->ap_capab = capab_info;
1888 kfree(ifsta->assocresp_ies);
1889 ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1890 ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
1891 if (ifsta->assocresp_ies)
1892 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
1896 /* Add STA entry for the AP */
1897 sta = sta_info_get(local, ifsta->bssid);
1899 struct ieee80211_sta_bss *bss;
1902 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
1904 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1905 " the AP\n", dev->name);
1909 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
1910 local->hw.conf.channel->center_freq,
1911 ifsta->ssid, ifsta->ssid_len);
1913 sta->last_rssi = bss->rssi;
1914 sta->last_signal = bss->signal;
1915 sta->last_noise = bss->noise;
1916 ieee80211_rx_bss_put(dev, bss);
1919 err = sta_info_insert(sta);
1921 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1922 " the AP (error %d)\n", dev->name, err);
1923 sta_info_destroy(sta);
1930 * FIXME: Do we really need to update the sta_info's information here?
1931 * We already know about the AP (we found it in our list) so it
1932 * should already be filled with the right info, no?
1933 * As is stands, all this is racy because typically we assume
1934 * the information that is filled in here (except flags) doesn't
1935 * change while a STA structure is alive. As such, it should move
1936 * to between the sta_info_alloc() and sta_info_insert() above.
1939 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1940 WLAN_STA_AUTHORIZED;
1944 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1946 for (i = 0; i < elems.supp_rates_len; i++) {
1947 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1950 have_higher_than_11mbit = true;
1952 for (j = 0; j < sband->n_bitrates; j++) {
1953 if (sband->bitrates[j].bitrate == rate)
1955 if (elems.supp_rates[i] & 0x80)
1956 basic_rates |= BIT(j);
1960 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1961 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1964 have_higher_than_11mbit = true;
1966 for (j = 0; j < sband->n_bitrates; j++) {
1967 if (sband->bitrates[j].bitrate == rate)
1969 if (elems.ext_supp_rates[i] & 0x80)
1970 basic_rates |= BIT(j);
1974 sta->supp_rates[local->hw.conf.channel->band] = rates;
1975 sdata->basic_rates = basic_rates;
1977 /* cf. IEEE 802.11 9.2.12 */
1978 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1979 have_higher_than_11mbit)
1980 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1982 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
1984 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
1985 local->ops->conf_ht) {
1986 struct ieee80211_ht_bss_info bss_info;
1988 ieee80211_ht_cap_ie_to_ht_info(
1989 (struct ieee80211_ht_cap *)
1990 elems.ht_cap_elem, &sta->ht_info);
1991 ieee80211_ht_addt_info_ie_to_ht_bss_info(
1992 (struct ieee80211_ht_addt_info *)
1993 elems.ht_info_elem, &bss_info);
1994 ieee80211_hw_config_ht(local, 1, &sta->ht_info, &bss_info);
1997 rate_control_rate_init(sta, local);
1999 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
2000 sta->flags |= WLAN_STA_WME;
2002 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2003 elems.wmm_param_len);
2007 /* set AID, ieee80211_set_associated() will tell the driver */
2008 bss_conf->aid = aid;
2009 ieee80211_set_associated(dev, ifsta, 1);
2011 ieee80211_associated(dev, ifsta);
2015 /* Caller must hold local->sta_bss_lock */
2016 static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
2017 struct ieee80211_sta_bss *bss)
2019 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2022 if (bss_mesh_cfg(bss))
2023 hash_idx = mesh_id_hash(bss_mesh_id(bss),
2024 bss_mesh_id_len(bss));
2026 hash_idx = STA_HASH(bss->bssid);
2028 bss->hnext = local->sta_bss_hash[hash_idx];
2029 local->sta_bss_hash[hash_idx] = bss;
2033 /* Caller must hold local->sta_bss_lock */
2034 static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
2035 struct ieee80211_sta_bss *bss)
2037 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2038 struct ieee80211_sta_bss *b, *prev = NULL;
2039 b = local->sta_bss_hash[STA_HASH(bss->bssid)];
2043 local->sta_bss_hash[STA_HASH(bss->bssid)] =
2046 prev->hnext = bss->hnext;
2055 static struct ieee80211_sta_bss *
2056 ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
2057 u8 *ssid, u8 ssid_len)
2059 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2060 struct ieee80211_sta_bss *bss;
2062 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2065 atomic_inc(&bss->users);
2066 atomic_inc(&bss->users);
2067 memcpy(bss->bssid, bssid, ETH_ALEN);
2069 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
2070 memcpy(bss->ssid, ssid, ssid_len);
2071 bss->ssid_len = ssid_len;
2074 spin_lock_bh(&local->sta_bss_lock);
2075 /* TODO: order by RSSI? */
2076 list_add_tail(&bss->list, &local->sta_bss_list);
2077 __ieee80211_rx_bss_hash_add(dev, bss);
2078 spin_unlock_bh(&local->sta_bss_lock);
2082 static struct ieee80211_sta_bss *
2083 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
2084 u8 *ssid, u8 ssid_len)
2086 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2087 struct ieee80211_sta_bss *bss;
2089 spin_lock_bh(&local->sta_bss_lock);
2090 bss = local->sta_bss_hash[STA_HASH(bssid)];
2092 if (!bss_mesh_cfg(bss) &&
2093 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
2094 bss->freq == freq &&
2095 bss->ssid_len == ssid_len &&
2096 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
2097 atomic_inc(&bss->users);
2102 spin_unlock_bh(&local->sta_bss_lock);
2106 #ifdef CONFIG_MAC80211_MESH
2107 static struct ieee80211_sta_bss *
2108 ieee80211_rx_mesh_bss_get(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2109 u8 *mesh_cfg, int freq)
2111 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2112 struct ieee80211_sta_bss *bss;
2114 spin_lock_bh(&local->sta_bss_lock);
2115 bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
2117 if (bss_mesh_cfg(bss) &&
2118 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
2119 bss->freq == freq &&
2120 mesh_id_len == bss->mesh_id_len &&
2121 (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
2123 atomic_inc(&bss->users);
2128 spin_unlock_bh(&local->sta_bss_lock);
2132 static struct ieee80211_sta_bss *
2133 ieee80211_rx_mesh_bss_add(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2134 u8 *mesh_cfg, int freq)
2136 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2137 struct ieee80211_sta_bss *bss;
2139 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2143 bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
2144 if (!bss->mesh_cfg) {
2149 if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
2150 bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
2151 if (!bss->mesh_id) {
2152 kfree(bss->mesh_cfg);
2156 memcpy(bss->mesh_id, mesh_id, mesh_id_len);
2159 atomic_inc(&bss->users);
2160 atomic_inc(&bss->users);
2161 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
2162 bss->mesh_id_len = mesh_id_len;
2164 spin_lock_bh(&local->sta_bss_lock);
2165 /* TODO: order by RSSI? */
2166 list_add_tail(&bss->list, &local->sta_bss_list);
2167 __ieee80211_rx_bss_hash_add(dev, bss);
2168 spin_unlock_bh(&local->sta_bss_lock);
2173 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
2179 kfree(bss_mesh_id(bss));
2180 kfree(bss_mesh_cfg(bss));
2185 static void ieee80211_rx_bss_put(struct net_device *dev,
2186 struct ieee80211_sta_bss *bss)
2188 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2189 if (!atomic_dec_and_test(&bss->users))
2192 spin_lock_bh(&local->sta_bss_lock);
2193 __ieee80211_rx_bss_hash_del(dev, bss);
2194 list_del(&bss->list);
2195 spin_unlock_bh(&local->sta_bss_lock);
2196 ieee80211_rx_bss_free(bss);
2200 void ieee80211_rx_bss_list_init(struct net_device *dev)
2202 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2203 spin_lock_init(&local->sta_bss_lock);
2204 INIT_LIST_HEAD(&local->sta_bss_list);
2208 void ieee80211_rx_bss_list_deinit(struct net_device *dev)
2210 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2211 struct ieee80211_sta_bss *bss, *tmp;
2213 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
2214 ieee80211_rx_bss_put(dev, bss);
2218 static int ieee80211_sta_join_ibss(struct net_device *dev,
2219 struct ieee80211_if_sta *ifsta,
2220 struct ieee80211_sta_bss *bss)
2222 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2223 int res, rates, i, j;
2224 struct sk_buff *skb;
2225 struct ieee80211_mgmt *mgmt;
2226 struct ieee80211_tx_control control;
2227 struct rate_selection ratesel;
2229 struct ieee80211_sub_if_data *sdata;
2230 struct ieee80211_supported_band *sband;
2232 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2234 /* Remove possible STA entries from other IBSS networks. */
2235 sta_info_flush(local, NULL);
2237 if (local->ops->reset_tsf) {
2238 /* Reset own TSF to allow time synchronization work. */
2239 local->ops->reset_tsf(local_to_hw(local));
2241 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2242 res = ieee80211_if_config(dev);
2246 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2248 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2249 sdata->drop_unencrypted = bss->capability &
2250 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2252 res = ieee80211_set_freq(local, bss->freq);
2254 if (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS) {
2255 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
2256 "%d MHz\n", dev->name, local->oper_channel->center_freq);
2260 /* Set beacon template */
2261 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2266 skb_reserve(skb, local->hw.extra_tx_headroom);
2268 mgmt = (struct ieee80211_mgmt *)
2269 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2270 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2271 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2272 IEEE80211_STYPE_BEACON);
2273 memset(mgmt->da, 0xff, ETH_ALEN);
2274 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2275 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2276 mgmt->u.beacon.beacon_int =
2277 cpu_to_le16(local->hw.conf.beacon_int);
2278 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2280 pos = skb_put(skb, 2 + ifsta->ssid_len);
2281 *pos++ = WLAN_EID_SSID;
2282 *pos++ = ifsta->ssid_len;
2283 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2285 rates = bss->supp_rates_len;
2288 pos = skb_put(skb, 2 + rates);
2289 *pos++ = WLAN_EID_SUPP_RATES;
2291 memcpy(pos, bss->supp_rates, rates);
2293 if (bss->band == IEEE80211_BAND_2GHZ) {
2294 pos = skb_put(skb, 2 + 1);
2295 *pos++ = WLAN_EID_DS_PARAMS;
2297 *pos++ = ieee80211_frequency_to_channel(bss->freq);
2300 pos = skb_put(skb, 2 + 2);
2301 *pos++ = WLAN_EID_IBSS_PARAMS;
2303 /* FIX: set ATIM window based on scan results */
2307 if (bss->supp_rates_len > 8) {
2308 rates = bss->supp_rates_len - 8;
2309 pos = skb_put(skb, 2 + rates);
2310 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2312 memcpy(pos, &bss->supp_rates[8], rates);
2315 memset(&control, 0, sizeof(control));
2316 rate_control_get_rate(dev, sband, skb, &ratesel);
2317 if (!ratesel.rate) {
2318 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2319 "for IBSS beacon\n", dev->name);
2322 control.vif = &sdata->vif;
2323 control.tx_rate = ratesel.rate;
2324 if (sdata->bss_conf.use_short_preamble &&
2325 ratesel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2326 control.flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
2327 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2328 control.flags |= IEEE80211_TXCTL_NO_ACK;
2329 control.retry_limit = 1;
2331 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2332 if (ifsta->probe_resp) {
2333 mgmt = (struct ieee80211_mgmt *)
2334 ifsta->probe_resp->data;
2335 mgmt->frame_control =
2336 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2337 IEEE80211_STYPE_PROBE_RESP);
2339 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2340 "template for IBSS\n", dev->name);
2343 if (local->ops->beacon_update &&
2344 local->ops->beacon_update(local_to_hw(local),
2345 skb, &control) == 0) {
2346 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2347 "template\n", dev->name);
2352 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2353 for (i = 0; i < bss->supp_rates_len; i++) {
2354 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2355 for (j = 0; j < sband->n_bitrates; j++)
2356 if (sband->bitrates[j].bitrate == bitrate)
2359 ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
2361 ieee80211_sta_def_wmm_params(dev, bss, 1);
2365 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2366 "template\n", dev->name);
2370 ifsta->state = IEEE80211_IBSS_JOINED;
2371 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2373 ieee80211_rx_bss_put(dev, bss);
2378 u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
2379 struct ieee802_11_elems *elems,
2380 enum ieee80211_band band)
2382 struct ieee80211_supported_band *sband;
2383 struct ieee80211_rate *bitrates;
2387 sband = local->hw.wiphy->bands[band];
2391 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2394 bitrates = sband->bitrates;
2395 num_rates = sband->n_bitrates;
2397 for (i = 0; i < elems->supp_rates_len +
2398 elems->ext_supp_rates_len; i++) {
2401 if (i < elems->supp_rates_len)
2402 rate = elems->supp_rates[i];
2403 else if (elems->ext_supp_rates)
2404 rate = elems->ext_supp_rates
2405 [i - elems->supp_rates_len];
2406 own_rate = 5 * (rate & 0x7f);
2407 for (j = 0; j < num_rates; j++)
2408 if (bitrates[j].bitrate == own_rate)
2409 supp_rates |= BIT(j);
2415 static void ieee80211_rx_bss_info(struct net_device *dev,
2416 struct ieee80211_mgmt *mgmt,
2418 struct ieee80211_rx_status *rx_status,
2421 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2422 struct ieee802_11_elems elems;
2425 struct ieee80211_sta_bss *bss;
2426 struct sta_info *sta;
2427 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2428 u64 beacon_timestamp, rx_timestamp;
2429 struct ieee80211_channel *channel;
2430 DECLARE_MAC_BUF(mac);
2431 DECLARE_MAC_BUF(mac2);
2433 if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
2434 return; /* ignore ProbeResp to foreign address */
2437 printk(KERN_DEBUG "%s: RX %s from %s to %s\n",
2438 dev->name, beacon ? "Beacon" : "Probe Response",
2439 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da));
2442 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2446 beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
2447 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
2449 if (ieee80211_vif_is_mesh(&sdata->vif) && elems.mesh_id &&
2450 elems.mesh_config && mesh_matches_local(&elems, dev)) {
2451 u64 rates = ieee80211_sta_get_rates(local, &elems,
2454 mesh_neighbour_update(mgmt->sa, rates, dev,
2455 mesh_peer_accepts_plinks(&elems, dev));
2460 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
2461 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
2462 (sta = sta_info_get(local, mgmt->sa))) {
2464 u64 supp_rates = ieee80211_sta_get_rates(local, &elems,
2467 prev_rates = sta->supp_rates[rx_status->band];
2468 sta->supp_rates[rx_status->band] &= supp_rates;
2469 if (sta->supp_rates[rx_status->band] == 0) {
2470 /* No matching rates - this should not really happen.
2471 * Make sure that at least one rate is marked
2472 * supported to avoid issues with TX rate ctrl. */
2473 sta->supp_rates[rx_status->band] =
2474 sdata->u.sta.supp_rates_bits[rx_status->band];
2476 if (sta->supp_rates[rx_status->band] != prev_rates) {
2477 printk(KERN_DEBUG "%s: updated supp_rates set for "
2478 "%s based on beacon info (0x%llx & 0x%llx -> "
2480 dev->name, print_mac(mac, sta->addr),
2481 (unsigned long long) prev_rates,
2482 (unsigned long long) supp_rates,
2483 (unsigned long long) sta->supp_rates[rx_status->band]);
2489 if (elems.ds_params && elems.ds_params_len == 1)
2490 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
2492 freq = rx_status->freq;
2494 channel = ieee80211_get_channel(local->hw.wiphy, freq);
2496 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
2499 #ifdef CONFIG_MAC80211_MESH
2500 if (elems.mesh_config)
2501 bss = ieee80211_rx_mesh_bss_get(dev, elems.mesh_id,
2502 elems.mesh_id_len, elems.mesh_config, freq);
2505 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
2506 elems.ssid, elems.ssid_len);
2508 #ifdef CONFIG_MAC80211_MESH
2509 if (elems.mesh_config)
2510 bss = ieee80211_rx_mesh_bss_add(dev, elems.mesh_id,
2511 elems.mesh_id_len, elems.mesh_config, freq);
2514 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
2515 elems.ssid, elems.ssid_len);
2520 /* TODO: order by RSSI? */
2521 spin_lock_bh(&local->sta_bss_lock);
2522 list_move_tail(&bss->list, &local->sta_bss_list);
2523 spin_unlock_bh(&local->sta_bss_lock);
2527 bss->band = rx_status->band;
2529 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
2530 bss->probe_resp && beacon) {
2532 * Do not allow beacon to override data from Probe Response. */
2533 ieee80211_rx_bss_put(dev, bss);
2537 /* save the ERP value so that it is available at association time */
2538 if (elems.erp_info && elems.erp_info_len >= 1) {
2539 bss->erp_value = elems.erp_info[0];
2540 bss->has_erp_value = 1;
2543 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
2544 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
2546 bss->supp_rates_len = 0;
2547 if (elems.supp_rates) {
2548 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2549 if (clen > elems.supp_rates_len)
2550 clen = elems.supp_rates_len;
2551 memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
2553 bss->supp_rates_len += clen;
2555 if (elems.ext_supp_rates) {
2556 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2557 if (clen > elems.ext_supp_rates_len)
2558 clen = elems.ext_supp_rates_len;
2559 memcpy(&bss->supp_rates[bss->supp_rates_len],
2560 elems.ext_supp_rates, clen);
2561 bss->supp_rates_len += clen;
2565 (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len ||
2566 memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
2568 bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
2570 memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
2571 bss->wpa_ie_len = elems.wpa_len + 2;
2573 bss->wpa_ie_len = 0;
2574 } else if (!elems.wpa && bss->wpa_ie) {
2577 bss->wpa_ie_len = 0;
2581 (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len ||
2582 memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
2584 bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
2586 memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
2587 bss->rsn_ie_len = elems.rsn_len + 2;
2589 bss->rsn_ie_len = 0;
2590 } else if (!elems.rsn && bss->rsn_ie) {
2593 bss->rsn_ie_len = 0;
2596 if (elems.wmm_param &&
2597 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len ||
2598 memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
2600 bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
2602 memcpy(bss->wmm_ie, elems.wmm_param - 2,
2603 elems.wmm_param_len + 2);
2604 bss->wmm_ie_len = elems.wmm_param_len + 2;
2606 bss->wmm_ie_len = 0;
2607 } else if (!elems.wmm_param && bss->wmm_ie) {
2610 bss->wmm_ie_len = 0;
2612 if (elems.ht_cap_elem &&
2613 (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
2614 memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
2616 bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
2618 memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
2619 elems.ht_cap_elem_len + 2);
2620 bss->ht_ie_len = elems.ht_cap_elem_len + 2;
2623 } else if (!elems.ht_cap_elem && bss->ht_ie) {
2629 bss->timestamp = beacon_timestamp;
2630 bss->last_update = jiffies;
2631 bss->rssi = rx_status->ssi;
2632 bss->signal = rx_status->signal;
2633 bss->noise = rx_status->noise;
2637 /* check if we need to merge IBSS */
2638 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
2639 !local->sta_sw_scanning && !local->sta_hw_scanning &&
2640 bss->capability & WLAN_CAPABILITY_IBSS &&
2641 bss->freq == local->oper_channel->center_freq &&
2642 elems.ssid_len == sdata->u.sta.ssid_len &&
2643 memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) == 0) {
2644 if (rx_status->flag & RX_FLAG_TSFT) {
2645 /* in order for correct IBSS merging we need mactime
2647 * since mactime is defined as the time the first data
2648 * symbol of the frame hits the PHY, and the timestamp
2649 * of the beacon is defined as "the time that the data
2650 * symbol containing the first bit of the timestamp is
2651 * transmitted to the PHY plus the transmitting STA’s
2652 * delays through its local PHY from the MAC-PHY
2653 * interface to its interface with the WM"
2654 * (802.11 11.1.2) - equals the time this bit arrives at
2655 * the receiver - we have to take into account the
2656 * offset between the two.
2657 * e.g: at 1 MBit that means mactime is 192 usec earlier
2658 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2660 int rate = local->hw.wiphy->bands[rx_status->band]->
2661 bitrates[rx_status->rate_idx].bitrate;
2662 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
2663 } else if (local && local->ops && local->ops->get_tsf)
2664 /* second best option: get current TSF */
2665 rx_timestamp = local->ops->get_tsf(local_to_hw(local));
2667 /* can't merge without knowing the TSF */
2668 rx_timestamp = -1LLU;
2669 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2670 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
2671 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2672 print_mac(mac, mgmt->sa),
2673 print_mac(mac2, mgmt->bssid),
2674 (unsigned long long)rx_timestamp,
2675 (unsigned long long)beacon_timestamp,
2676 (unsigned long long)(rx_timestamp - beacon_timestamp),
2678 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2679 if (beacon_timestamp > rx_timestamp) {
2680 #ifndef CONFIG_MAC80211_IBSS_DEBUG
2681 if (net_ratelimit())
2683 printk(KERN_DEBUG "%s: beacon TSF higher than "
2684 "local TSF - IBSS merge with BSSID %s\n",
2685 dev->name, print_mac(mac, mgmt->bssid));
2686 ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
2687 ieee80211_ibss_add_sta(dev, NULL,
2688 mgmt->bssid, mgmt->sa);
2692 ieee80211_rx_bss_put(dev, bss);
2696 static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
2697 struct ieee80211_mgmt *mgmt,
2699 struct ieee80211_rx_status *rx_status)
2701 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
2705 static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
2706 struct ieee80211_mgmt *mgmt,
2708 struct ieee80211_rx_status *rx_status)
2710 struct ieee80211_sub_if_data *sdata;
2711 struct ieee80211_if_sta *ifsta;
2713 struct ieee802_11_elems elems;
2714 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2715 struct ieee80211_conf *conf = &local->hw.conf;
2718 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
2720 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2721 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
2723 ifsta = &sdata->u.sta;
2725 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
2726 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
2729 /* Process beacon from the current BSS */
2730 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2734 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
2736 if (elems.erp_info && elems.erp_info_len >= 1)
2737 changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
2739 if (elems.ht_cap_elem && elems.ht_info_elem &&
2740 elems.wmm_param && local->ops->conf_ht &&
2741 conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
2742 struct ieee80211_ht_bss_info bss_info;
2744 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2745 (struct ieee80211_ht_addt_info *)
2746 elems.ht_info_elem, &bss_info);
2747 /* check if AP changed bss inforamation */
2748 if ((conf->ht_bss_conf.primary_channel !=
2749 bss_info.primary_channel) ||
2750 (conf->ht_bss_conf.bss_cap != bss_info.bss_cap) ||
2751 (conf->ht_bss_conf.bss_op_mode != bss_info.bss_op_mode))
2752 ieee80211_hw_config_ht(local, 1, &conf->ht_conf,
2756 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
2757 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2758 elems.wmm_param_len);
2761 ieee80211_bss_info_change_notify(sdata, changed);
2765 static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
2766 struct ieee80211_if_sta *ifsta,
2767 struct ieee80211_mgmt *mgmt,
2769 struct ieee80211_rx_status *rx_status)
2771 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2772 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2774 struct sk_buff *skb;
2775 struct ieee80211_mgmt *resp;
2777 DECLARE_MAC_BUF(mac);
2778 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2779 DECLARE_MAC_BUF(mac2);
2780 DECLARE_MAC_BUF(mac3);
2783 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
2784 ifsta->state != IEEE80211_IBSS_JOINED ||
2785 len < 24 + 2 || !ifsta->probe_resp)
2788 if (local->ops->tx_last_beacon)
2789 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
2793 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2794 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
2795 "%s (tx_last_beacon=%d)\n",
2796 dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
2797 print_mac(mac3, mgmt->bssid), tx_last_beacon);
2798 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2800 if (!tx_last_beacon)
2803 if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
2804 memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
2807 end = ((u8 *) mgmt) + len;
2808 pos = mgmt->u.probe_req.variable;
2809 if (pos[0] != WLAN_EID_SSID ||
2810 pos + 2 + pos[1] > end) {
2811 if (net_ratelimit()) {
2812 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
2814 dev->name, print_mac(mac, mgmt->sa));
2819 (pos[1] != ifsta->ssid_len ||
2820 memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
2821 /* Ignore ProbeReq for foreign SSID */
2825 /* Reply with ProbeResp */
2826 skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
2830 resp = (struct ieee80211_mgmt *) skb->data;
2831 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2832 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2833 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
2834 dev->name, print_mac(mac, resp->da));
2835 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2836 ieee80211_sta_tx(dev, skb, 0);
2839 static void ieee80211_rx_mgmt_action(struct net_device *dev,
2840 struct ieee80211_if_sta *ifsta,
2841 struct ieee80211_mgmt *mgmt,
2843 struct ieee80211_rx_status *rx_status)
2845 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2847 if (len < IEEE80211_MIN_ACTION_SIZE)
2850 switch (mgmt->u.action.category) {
2851 case WLAN_CATEGORY_BACK:
2852 switch (mgmt->u.action.u.addba_req.action_code) {
2853 case WLAN_ACTION_ADDBA_REQ:
2854 if (len < (IEEE80211_MIN_ACTION_SIZE +
2855 sizeof(mgmt->u.action.u.addba_req)))
2857 ieee80211_sta_process_addba_request(dev, mgmt, len);
2859 case WLAN_ACTION_ADDBA_RESP:
2860 if (len < (IEEE80211_MIN_ACTION_SIZE +
2861 sizeof(mgmt->u.action.u.addba_resp)))
2863 ieee80211_sta_process_addba_resp(dev, mgmt, len);
2865 case WLAN_ACTION_DELBA:
2866 if (len < (IEEE80211_MIN_ACTION_SIZE +
2867 sizeof(mgmt->u.action.u.delba)))
2869 ieee80211_sta_process_delba(dev, mgmt, len);
2872 if (net_ratelimit())
2873 printk(KERN_DEBUG "%s: Rx unknown A-MPDU action\n",
2878 case PLINK_CATEGORY:
2879 if (ieee80211_vif_is_mesh(&sdata->vif))
2880 mesh_rx_plink_frame(dev, mgmt, len, rx_status);
2882 case MESH_PATH_SEL_CATEGORY:
2883 if (ieee80211_vif_is_mesh(&sdata->vif))
2884 mesh_rx_path_sel_frame(dev, mgmt, len);
2887 if (net_ratelimit())
2888 printk(KERN_DEBUG "%s: Rx unknown action frame - "
2889 "category=%d\n", dev->name, mgmt->u.action.category);
2894 void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
2895 struct ieee80211_rx_status *rx_status)
2897 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2898 struct ieee80211_sub_if_data *sdata;
2899 struct ieee80211_if_sta *ifsta;
2900 struct ieee80211_mgmt *mgmt;
2906 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2907 ifsta = &sdata->u.sta;
2909 mgmt = (struct ieee80211_mgmt *) skb->data;
2910 fc = le16_to_cpu(mgmt->frame_control);
2912 switch (fc & IEEE80211_FCTL_STYPE) {
2913 case IEEE80211_STYPE_PROBE_REQ:
2914 case IEEE80211_STYPE_PROBE_RESP:
2915 case IEEE80211_STYPE_BEACON:
2916 case IEEE80211_STYPE_ACTION:
2917 memcpy(skb->cb, rx_status, sizeof(*rx_status));
2918 case IEEE80211_STYPE_AUTH:
2919 case IEEE80211_STYPE_ASSOC_RESP:
2920 case IEEE80211_STYPE_REASSOC_RESP:
2921 case IEEE80211_STYPE_DEAUTH:
2922 case IEEE80211_STYPE_DISASSOC:
2923 skb_queue_tail(&ifsta->skb_queue, skb);
2924 queue_work(local->hw.workqueue, &ifsta->work);
2927 printk(KERN_DEBUG "%s: received unknown management frame - "
2928 "stype=%d\n", dev->name,
2929 (fc & IEEE80211_FCTL_STYPE) >> 4);
2938 static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
2939 struct sk_buff *skb)
2941 struct ieee80211_rx_status *rx_status;
2942 struct ieee80211_sub_if_data *sdata;
2943 struct ieee80211_if_sta *ifsta;
2944 struct ieee80211_mgmt *mgmt;
2947 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2948 ifsta = &sdata->u.sta;
2950 rx_status = (struct ieee80211_rx_status *) skb->cb;
2951 mgmt = (struct ieee80211_mgmt *) skb->data;
2952 fc = le16_to_cpu(mgmt->frame_control);
2954 switch (fc & IEEE80211_FCTL_STYPE) {
2955 case IEEE80211_STYPE_PROBE_REQ:
2956 ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
2959 case IEEE80211_STYPE_PROBE_RESP:
2960 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
2962 case IEEE80211_STYPE_BEACON:
2963 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
2965 case IEEE80211_STYPE_AUTH:
2966 ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len);
2968 case IEEE80211_STYPE_ASSOC_RESP:
2969 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
2971 case IEEE80211_STYPE_REASSOC_RESP:
2972 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
2974 case IEEE80211_STYPE_DEAUTH:
2975 ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len);
2977 case IEEE80211_STYPE_DISASSOC:
2978 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
2980 case IEEE80211_STYPE_ACTION:
2981 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len, rx_status);
2990 ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
2991 struct ieee80211_rx_status *rx_status)
2993 struct ieee80211_mgmt *mgmt;
2997 return RX_DROP_UNUSABLE;
2999 mgmt = (struct ieee80211_mgmt *) skb->data;
3000 fc = le16_to_cpu(mgmt->frame_control);
3002 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
3006 return RX_DROP_MONITOR;
3008 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
3009 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
3010 ieee80211_rx_mgmt_probe_resp(dev, mgmt,
3011 skb->len, rx_status);
3014 } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
3015 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
3025 static int ieee80211_sta_active_ibss(struct net_device *dev)
3027 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3029 struct sta_info *sta;
3030 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3034 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3035 if (sta->sdata == sdata &&
3036 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
3049 static void ieee80211_sta_expire(struct net_device *dev, unsigned long exp_time)
3051 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3052 struct sta_info *sta, *tmp;
3053 LIST_HEAD(tmp_list);
3054 DECLARE_MAC_BUF(mac);
3055 unsigned long flags;
3057 spin_lock_irqsave(&local->sta_lock, flags);
3058 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
3059 if (time_after(jiffies, sta->last_rx + exp_time)) {
3060 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
3061 dev->name, print_mac(mac, sta->addr));
3062 sta_info_unlink(&sta);
3064 list_add(&sta->list, &tmp_list);
3066 spin_unlock_irqrestore(&local->sta_lock, flags);
3071 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
3072 sta_info_destroy(sta);
3077 static void ieee80211_sta_merge_ibss(struct net_device *dev,
3078 struct ieee80211_if_sta *ifsta)
3080 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
3082 ieee80211_sta_expire(dev, IEEE80211_IBSS_INACTIVITY_LIMIT);
3083 if (ieee80211_sta_active_ibss(dev))
3086 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
3087 "IBSS networks with same SSID (merge)\n", dev->name);
3088 ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
3092 #ifdef CONFIG_MAC80211_MESH
3093 static void ieee80211_mesh_housekeeping(struct net_device *dev,
3094 struct ieee80211_if_sta *ifsta)
3096 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3099 ieee80211_sta_expire(dev, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
3100 mesh_path_expire(dev);
3102 free_plinks = mesh_plink_availables(sdata);
3103 if (free_plinks != sdata->u.sta.accepting_plinks)
3104 ieee80211_if_config_beacon(dev);
3106 mod_timer(&ifsta->timer, jiffies +
3107 IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
3111 void ieee80211_start_mesh(struct net_device *dev)
3113 struct ieee80211_if_sta *ifsta;
3114 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3115 ifsta = &sdata->u.sta;
3116 ifsta->state = IEEE80211_MESH_UP;
3117 ieee80211_sta_timer((unsigned long)sdata);
3122 void ieee80211_sta_timer(unsigned long data)
3124 struct ieee80211_sub_if_data *sdata =
3125 (struct ieee80211_sub_if_data *) data;
3126 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3127 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
3129 set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3130 queue_work(local->hw.workqueue, &ifsta->work);
3133 void ieee80211_sta_work(struct work_struct *work)
3135 struct ieee80211_sub_if_data *sdata =
3136 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
3137 struct net_device *dev = sdata->dev;
3138 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3139 struct ieee80211_if_sta *ifsta;
3140 struct sk_buff *skb;
3142 if (!netif_running(dev))
3145 if (local->sta_sw_scanning || local->sta_hw_scanning)
3148 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
3149 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
3150 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) {
3151 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
3152 "(type=%d)\n", dev->name, sdata->vif.type);
3155 ifsta = &sdata->u.sta;
3157 while ((skb = skb_dequeue(&ifsta->skb_queue)))
3158 ieee80211_sta_rx_queued_mgmt(dev, skb);
3160 #ifdef CONFIG_MAC80211_MESH
3161 if (ifsta->preq_queue_len &&
3163 ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
3164 mesh_path_start_discovery(dev);
3167 if (ifsta->state != IEEE80211_AUTHENTICATE &&
3168 ifsta->state != IEEE80211_ASSOCIATE &&
3169 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
3170 if (ifsta->scan_ssid_len)
3171 ieee80211_sta_start_scan(dev, ifsta->scan_ssid, ifsta->scan_ssid_len);
3173 ieee80211_sta_start_scan(dev, NULL, 0);
3177 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
3178 if (ieee80211_sta_config_auth(dev, ifsta))
3180 clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3181 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
3184 switch (ifsta->state) {
3185 case IEEE80211_DISABLED:
3187 case IEEE80211_AUTHENTICATE:
3188 ieee80211_authenticate(dev, ifsta);
3190 case IEEE80211_ASSOCIATE:
3191 ieee80211_associate(dev, ifsta);
3193 case IEEE80211_ASSOCIATED:
3194 ieee80211_associated(dev, ifsta);
3196 case IEEE80211_IBSS_SEARCH:
3197 ieee80211_sta_find_ibss(dev, ifsta);
3199 case IEEE80211_IBSS_JOINED:
3200 ieee80211_sta_merge_ibss(dev, ifsta);
3202 #ifdef CONFIG_MAC80211_MESH
3203 case IEEE80211_MESH_UP:
3204 ieee80211_mesh_housekeeping(dev, ifsta);
3208 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
3213 if (ieee80211_privacy_mismatch(dev, ifsta)) {
3214 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
3215 "mixed-cell disabled - disassociate\n", dev->name);
3217 ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
3218 ieee80211_set_disassoc(dev, ifsta, 0);
3223 static void ieee80211_sta_reset_auth(struct net_device *dev,
3224 struct ieee80211_if_sta *ifsta)
3226 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3228 if (local->ops->reset_tsf) {
3229 /* Reset own TSF to allow time synchronization work. */
3230 local->ops->reset_tsf(local_to_hw(local));
3233 ifsta->wmm_last_param_set = -1; /* allow any WMM update */
3236 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
3237 ifsta->auth_alg = WLAN_AUTH_OPEN;
3238 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
3239 ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
3240 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
3241 ifsta->auth_alg = WLAN_AUTH_LEAP;
3243 ifsta->auth_alg = WLAN_AUTH_OPEN;
3244 printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
3246 ifsta->auth_transaction = -1;
3247 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
3248 ifsta->auth_tries = ifsta->assoc_tries = 0;
3249 netif_carrier_off(dev);
3253 void ieee80211_sta_req_auth(struct net_device *dev,
3254 struct ieee80211_if_sta *ifsta)
3256 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3257 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3259 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
3262 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
3263 IEEE80211_STA_AUTO_BSSID_SEL)) &&
3264 (ifsta->flags & (IEEE80211_STA_SSID_SET |
3265 IEEE80211_STA_AUTO_SSID_SEL))) {
3266 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3267 queue_work(local->hw.workqueue, &ifsta->work);
3271 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
3272 const char *ssid, int ssid_len)
3274 int tmp, hidden_ssid;
3276 if (ssid_len == ifsta->ssid_len &&
3277 !memcmp(ifsta->ssid, ssid, ssid_len))
3280 if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
3286 if (ssid[tmp] != '\0') {
3292 if (hidden_ssid && ifsta->ssid_len == ssid_len)
3295 if (ssid_len == 1 && ssid[0] == ' ')
3301 static int ieee80211_sta_config_auth(struct net_device *dev,
3302 struct ieee80211_if_sta *ifsta)
3304 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3305 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3306 struct ieee80211_sta_bss *bss, *selected = NULL;
3307 int top_rssi = 0, freq;
3309 if (!(ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
3310 IEEE80211_STA_AUTO_BSSID_SEL | IEEE80211_STA_AUTO_CHANNEL_SEL))) {
3311 ifsta->state = IEEE80211_AUTHENTICATE;
3312 ieee80211_sta_reset_auth(dev, ifsta);
3316 spin_lock_bh(&local->sta_bss_lock);
3317 freq = local->oper_channel->center_freq;
3318 list_for_each_entry(bss, &local->sta_bss_list, list) {
3319 if (!(bss->capability & WLAN_CAPABILITY_ESS))
3322 if (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
3323 !!sdata->default_key)
3326 if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
3330 if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
3331 memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
3334 if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
3335 !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
3338 if (!selected || top_rssi < bss->rssi) {
3340 top_rssi = bss->rssi;
3344 atomic_inc(&selected->users);
3345 spin_unlock_bh(&local->sta_bss_lock);
3348 ieee80211_set_freq(local, selected->freq);
3349 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
3350 ieee80211_sta_set_ssid(dev, selected->ssid,
3351 selected->ssid_len);
3352 ieee80211_sta_set_bssid(dev, selected->bssid);
3353 ieee80211_sta_def_wmm_params(dev, selected, 0);
3354 ieee80211_rx_bss_put(dev, selected);
3355 ifsta->state = IEEE80211_AUTHENTICATE;
3356 ieee80211_sta_reset_auth(dev, ifsta);
3359 if (ifsta->state != IEEE80211_AUTHENTICATE) {
3360 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
3361 ieee80211_sta_start_scan(dev, NULL, 0);
3363 ieee80211_sta_start_scan(dev, ifsta->ssid,
3365 ifsta->state = IEEE80211_AUTHENTICATE;
3366 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3368 ifsta->state = IEEE80211_DISABLED;
3374 static int ieee80211_sta_create_ibss(struct net_device *dev,
3375 struct ieee80211_if_sta *ifsta)
3377 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3378 struct ieee80211_sta_bss *bss;
3379 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3380 struct ieee80211_supported_band *sband;
3381 u8 bssid[ETH_ALEN], *pos;
3383 DECLARE_MAC_BUF(mac);
3386 /* Easier testing, use fixed BSSID. */
3387 memset(bssid, 0xfe, ETH_ALEN);
3389 /* Generate random, not broadcast, locally administered BSSID. Mix in
3390 * own MAC address to make sure that devices that do not have proper
3391 * random number generator get different BSSID. */
3392 get_random_bytes(bssid, ETH_ALEN);
3393 for (i = 0; i < ETH_ALEN; i++)
3394 bssid[i] ^= dev->dev_addr[i];
3399 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
3400 dev->name, print_mac(mac, bssid));
3402 bss = ieee80211_rx_bss_add(dev, bssid,
3403 local->hw.conf.channel->center_freq,
3404 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
3408 bss->band = local->hw.conf.channel->band;
3409 sband = local->hw.wiphy->bands[bss->band];
3411 if (local->hw.conf.beacon_int == 0)
3412 local->hw.conf.beacon_int = 10000;
3413 bss->beacon_int = local->hw.conf.beacon_int;
3414 bss->last_update = jiffies;
3415 bss->capability = WLAN_CAPABILITY_IBSS;
3416 if (sdata->default_key) {
3417 bss->capability |= WLAN_CAPABILITY_PRIVACY;
3419 sdata->drop_unencrypted = 0;
3420 bss->supp_rates_len = sband->n_bitrates;
3421 pos = bss->supp_rates;
3422 for (i = 0; i < sband->n_bitrates; i++) {
3423 int rate = sband->bitrates[i].bitrate;
3424 *pos++ = (u8) (rate / 5);
3427 return ieee80211_sta_join_ibss(dev, ifsta, bss);
3431 static int ieee80211_sta_find_ibss(struct net_device *dev,
3432 struct ieee80211_if_sta *ifsta)
3434 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3435 struct ieee80211_sta_bss *bss;
3439 DECLARE_MAC_BUF(mac);
3440 DECLARE_MAC_BUF(mac2);
3442 if (ifsta->ssid_len == 0)
3445 active_ibss = ieee80211_sta_active_ibss(dev);
3446 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3447 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
3448 dev->name, active_ibss);
3449 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3450 spin_lock_bh(&local->sta_bss_lock);
3451 list_for_each_entry(bss, &local->sta_bss_list, list) {
3452 if (ifsta->ssid_len != bss->ssid_len ||
3453 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
3454 || !(bss->capability & WLAN_CAPABILITY_IBSS))
3456 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3457 printk(KERN_DEBUG " bssid=%s found\n",
3458 print_mac(mac, bss->bssid));
3459 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3460 memcpy(bssid, bss->bssid, ETH_ALEN);
3462 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
3465 spin_unlock_bh(&local->sta_bss_lock);
3467 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3468 printk(KERN_DEBUG " sta_find_ibss: selected %s current "
3469 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
3470 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3471 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
3472 (bss = ieee80211_rx_bss_get(dev, bssid,
3473 local->hw.conf.channel->center_freq,
3474 ifsta->ssid, ifsta->ssid_len))) {
3475 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
3476 " based on configured SSID\n",
3477 dev->name, print_mac(mac, bssid));
3478 return ieee80211_sta_join_ibss(dev, ifsta, bss);
3480 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3481 printk(KERN_DEBUG " did not try to join ibss\n");
3482 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3484 /* Selected IBSS not found in current scan results - try to scan */
3485 if (ifsta->state == IEEE80211_IBSS_JOINED &&
3486 !ieee80211_sta_active_ibss(dev)) {
3487 mod_timer(&ifsta->timer, jiffies +
3488 IEEE80211_IBSS_MERGE_INTERVAL);
3489 } else if (time_after(jiffies, local->last_scan_completed +
3490 IEEE80211_SCAN_INTERVAL)) {
3491 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
3492 "join\n", dev->name);
3493 return ieee80211_sta_req_scan(dev, ifsta->ssid,
3495 } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
3496 int interval = IEEE80211_SCAN_INTERVAL;
3498 if (time_after(jiffies, ifsta->ibss_join_req +
3499 IEEE80211_IBSS_JOIN_TIMEOUT)) {
3500 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
3501 (!(local->oper_channel->flags &
3502 IEEE80211_CHAN_NO_IBSS)))
3503 return ieee80211_sta_create_ibss(dev, ifsta);
3504 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
3505 printk(KERN_DEBUG "%s: IBSS not allowed on"
3506 " %d MHz\n", dev->name,
3507 local->hw.conf.channel->center_freq);
3510 /* No IBSS found - decrease scan interval and continue
3512 interval = IEEE80211_SCAN_INTERVAL_SLOW;
3515 ifsta->state = IEEE80211_IBSS_SEARCH;
3516 mod_timer(&ifsta->timer, jiffies + interval);
3524 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3526 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3527 struct ieee80211_if_sta *ifsta;
3529 if (len > IEEE80211_MAX_SSID_LEN)
3532 ifsta = &sdata->u.sta;
3534 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
3535 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
3536 memcpy(ifsta->ssid, ssid, len);
3537 memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
3538 ifsta->ssid_len = len;
3541 ifsta->flags |= IEEE80211_STA_SSID_SET;
3543 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
3544 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3545 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
3546 ifsta->ibss_join_req = jiffies;
3547 ifsta->state = IEEE80211_IBSS_SEARCH;
3548 return ieee80211_sta_find_ibss(dev, ifsta);
3554 int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
3556 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3557 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3558 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
3559 *len = ifsta->ssid_len;
3564 int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
3566 struct ieee80211_sub_if_data *sdata;
3567 struct ieee80211_if_sta *ifsta;
3570 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3571 ifsta = &sdata->u.sta;
3573 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
3574 memcpy(ifsta->bssid, bssid, ETH_ALEN);
3575 res = ieee80211_if_config(dev);
3577 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
3578 "the low-level driver\n", dev->name);
3583 if (is_valid_ether_addr(bssid))
3584 ifsta->flags |= IEEE80211_STA_BSSID_SET;
3586 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
3592 static void ieee80211_send_nullfunc(struct ieee80211_local *local,
3593 struct ieee80211_sub_if_data *sdata,
3596 struct sk_buff *skb;
3597 struct ieee80211_hdr *nullfunc;
3600 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
3602 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
3603 "frame\n", sdata->dev->name);
3606 skb_reserve(skb, local->hw.extra_tx_headroom);
3608 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
3609 memset(nullfunc, 0, 24);
3610 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
3611 IEEE80211_FCTL_TODS;
3613 fc |= IEEE80211_FCTL_PM;
3614 nullfunc->frame_control = cpu_to_le16(fc);
3615 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
3616 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
3617 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
3619 ieee80211_sta_tx(sdata->dev, skb, 0);
3623 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3625 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
3626 ieee80211_vif_is_mesh(&sdata->vif))
3627 ieee80211_sta_timer((unsigned long)sdata);
3630 void ieee80211_scan_completed(struct ieee80211_hw *hw)
3632 struct ieee80211_local *local = hw_to_local(hw);
3633 struct net_device *dev = local->scan_dev;
3634 struct ieee80211_sub_if_data *sdata;
3635 union iwreq_data wrqu;
3637 local->last_scan_completed = jiffies;
3638 memset(&wrqu, 0, sizeof(wrqu));
3639 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
3641 if (local->sta_hw_scanning) {
3642 local->sta_hw_scanning = 0;
3643 if (ieee80211_hw_config(local))
3644 printk(KERN_DEBUG "%s: failed to restore operational "
3645 "channel after scan\n", dev->name);
3646 /* Restart STA timer for HW scan case */
3648 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3649 ieee80211_restart_sta_timer(sdata);
3655 local->sta_sw_scanning = 0;
3656 if (ieee80211_hw_config(local))
3657 printk(KERN_DEBUG "%s: failed to restore operational "
3658 "channel after scan\n", dev->name);
3661 netif_tx_lock_bh(local->mdev);
3662 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
3663 local->ops->configure_filter(local_to_hw(local),
3664 FIF_BCN_PRBRESP_PROMISC,
3665 &local->filter_flags,
3666 local->mdev->mc_count,
3667 local->mdev->mc_list);
3669 netif_tx_unlock_bh(local->mdev);
3672 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3674 /* No need to wake the master device. */
3675 if (sdata->dev == local->mdev)
3678 /* Tell AP we're back */
3679 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3680 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
3681 ieee80211_send_nullfunc(local, sdata, 0);
3683 ieee80211_restart_sta_timer(sdata);
3685 netif_wake_queue(sdata->dev);
3690 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3691 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
3692 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3693 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
3694 (!ifsta->state == IEEE80211_IBSS_JOINED &&
3695 !ieee80211_sta_active_ibss(dev)))
3696 ieee80211_sta_find_ibss(dev, ifsta);
3699 EXPORT_SYMBOL(ieee80211_scan_completed);
3701 void ieee80211_sta_scan_work(struct work_struct *work)
3703 struct ieee80211_local *local =
3704 container_of(work, struct ieee80211_local, scan_work.work);
3705 struct net_device *dev = local->scan_dev;
3706 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3707 struct ieee80211_supported_band *sband;
3708 struct ieee80211_channel *chan;
3710 unsigned long next_delay = 0;
3712 if (!local->sta_sw_scanning)
3715 switch (local->scan_state) {
3716 case SCAN_SET_CHANNEL:
3718 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3719 * after we successfully scanned the last channel of the last
3720 * band (and the last band is supported by the hw)
3722 if (local->scan_band < IEEE80211_NUM_BANDS)
3723 sband = local->hw.wiphy->bands[local->scan_band];
3728 * If we are at an unsupported band and have more bands
3729 * left to scan, advance to the next supported one.
3731 while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
3733 sband = local->hw.wiphy->bands[local->scan_band];
3734 local->scan_channel_idx = 0;
3737 /* if no more bands/channels left, complete scan */
3738 if (!sband || local->scan_channel_idx >= sband->n_channels) {
3739 ieee80211_scan_completed(local_to_hw(local));
3743 chan = &sband->channels[local->scan_channel_idx];
3745 if (chan->flags & IEEE80211_CHAN_DISABLED ||
3746 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3747 chan->flags & IEEE80211_CHAN_NO_IBSS))
3751 local->scan_channel = chan;
3752 if (ieee80211_hw_config(local)) {
3753 printk(KERN_DEBUG "%s: failed to set freq to "
3754 "%d MHz for scan\n", dev->name,
3760 /* advance state machine to next channel/band */
3761 local->scan_channel_idx++;
3762 if (local->scan_channel_idx >= sband->n_channels) {
3764 * scan_band may end up == IEEE80211_NUM_BANDS, but
3765 * we'll catch that case above and complete the scan
3766 * if that is the case.
3769 local->scan_channel_idx = 0;
3775 next_delay = IEEE80211_PROBE_DELAY +
3776 usecs_to_jiffies(local->hw.channel_change_time);
3777 local->scan_state = SCAN_SEND_PROBE;
3779 case SCAN_SEND_PROBE:
3780 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3781 local->scan_state = SCAN_SET_CHANNEL;
3783 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
3785 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3786 local->scan_ssid_len);
3787 next_delay = IEEE80211_CHANNEL_TIME;
3791 if (local->sta_sw_scanning)
3792 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3797 static int ieee80211_sta_start_scan(struct net_device *dev,
3798 u8 *ssid, size_t ssid_len)
3800 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3801 struct ieee80211_sub_if_data *sdata;
3803 if (ssid_len > IEEE80211_MAX_SSID_LEN)
3806 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3807 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3810 * ScanType: ACTIVE, PASSIVE
3811 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3812 * a Probe frame during active scanning
3814 * MinChannelTime (>= ProbeDelay), in TU
3815 * MaxChannelTime: (>= MinChannelTime), in TU
3818 /* MLME-SCAN.confirm
3820 * ResultCode: SUCCESS, INVALID_PARAMETERS
3823 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3824 if (local->scan_dev == dev)
3829 if (local->ops->hw_scan) {
3830 int rc = local->ops->hw_scan(local_to_hw(local),
3833 local->sta_hw_scanning = 1;
3834 local->scan_dev = dev;
3839 local->sta_sw_scanning = 1;
3842 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3844 /* Don't stop the master interface, otherwise we can't transmit
3846 if (sdata->dev == local->mdev)
3849 netif_stop_queue(sdata->dev);
3850 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3851 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
3852 ieee80211_send_nullfunc(local, sdata, 1);
3857 local->scan_ssid_len = ssid_len;
3858 memcpy(local->scan_ssid, ssid, ssid_len);
3860 local->scan_ssid_len = 0;
3861 local->scan_state = SCAN_SET_CHANNEL;
3862 local->scan_channel_idx = 0;
3863 local->scan_band = IEEE80211_BAND_2GHZ;
3864 local->scan_dev = dev;
3866 netif_tx_lock_bh(local->mdev);
3867 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
3868 local->ops->configure_filter(local_to_hw(local),
3869 FIF_BCN_PRBRESP_PROMISC,
3870 &local->filter_flags,
3871 local->mdev->mc_count,
3872 local->mdev->mc_list);
3873 netif_tx_unlock_bh(local->mdev);
3875 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3876 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3877 IEEE80211_CHANNEL_TIME);
3883 int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
3885 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3886 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3887 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3889 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
3890 return ieee80211_sta_start_scan(dev, ssid, ssid_len);
3892 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3893 if (local->scan_dev == dev)
3898 ifsta->scan_ssid_len = ssid_len;
3900 memcpy(ifsta->scan_ssid, ssid, ssid_len);
3901 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
3902 queue_work(local->hw.workqueue, &ifsta->work);
3907 ieee80211_sta_scan_result(struct net_device *dev,
3908 struct ieee80211_sta_bss *bss,
3909 char *current_ev, char *end_buf)
3911 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3912 struct iw_event iwe;
3914 if (time_after(jiffies,
3915 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
3918 memset(&iwe, 0, sizeof(iwe));
3919 iwe.cmd = SIOCGIWAP;
3920 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
3921 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
3922 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3925 memset(&iwe, 0, sizeof(iwe));
3926 iwe.cmd = SIOCGIWESSID;
3927 if (bss_mesh_cfg(bss)) {
3928 iwe.u.data.length = bss_mesh_id_len(bss);
3929 iwe.u.data.flags = 1;
3930 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3933 iwe.u.data.length = bss->ssid_len;
3934 iwe.u.data.flags = 1;
3935 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3939 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
3940 || bss_mesh_cfg(bss)) {
3941 memset(&iwe, 0, sizeof(iwe));
3942 iwe.cmd = SIOCGIWMODE;
3943 if (bss_mesh_cfg(bss))
3944 iwe.u.mode = IW_MODE_MESH;
3945 else if (bss->capability & WLAN_CAPABILITY_ESS)
3946 iwe.u.mode = IW_MODE_MASTER;
3948 iwe.u.mode = IW_MODE_ADHOC;
3949 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3953 memset(&iwe, 0, sizeof(iwe));
3954 iwe.cmd = SIOCGIWFREQ;
3955 iwe.u.freq.m = bss->freq;
3957 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3960 memset(&iwe, 0, sizeof(iwe));
3961 iwe.cmd = SIOCGIWFREQ;
3962 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
3964 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3967 memset(&iwe, 0, sizeof(iwe));
3969 iwe.u.qual.qual = bss->signal;
3970 iwe.u.qual.level = bss->rssi;
3971 iwe.u.qual.noise = bss->noise;
3972 iwe.u.qual.updated = local->wstats_flags;
3973 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3976 memset(&iwe, 0, sizeof(iwe));
3977 iwe.cmd = SIOCGIWENCODE;
3978 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
3979 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
3981 iwe.u.data.flags = IW_ENCODE_DISABLED;
3982 iwe.u.data.length = 0;
3983 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
3985 if (bss && bss->wpa_ie) {
3986 memset(&iwe, 0, sizeof(iwe));
3987 iwe.cmd = IWEVGENIE;
3988 iwe.u.data.length = bss->wpa_ie_len;
3989 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3993 if (bss && bss->rsn_ie) {
3994 memset(&iwe, 0, sizeof(iwe));
3995 iwe.cmd = IWEVGENIE;
3996 iwe.u.data.length = bss->rsn_ie_len;
3997 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
4001 if (bss && bss->supp_rates_len > 0) {
4002 /* display all supported rates in readable format */
4003 char *p = current_ev + IW_EV_LCP_LEN;
4006 memset(&iwe, 0, sizeof(iwe));
4007 iwe.cmd = SIOCGIWRATE;
4008 /* Those two flags are ignored... */
4009 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4011 for (i = 0; i < bss->supp_rates_len; i++) {
4012 iwe.u.bitrate.value = ((bss->supp_rates[i] &
4014 p = iwe_stream_add_value(current_ev, p,
4015 end_buf, &iwe, IW_EV_PARAM_LEN);
4022 buf = kmalloc(30, GFP_ATOMIC);
4024 memset(&iwe, 0, sizeof(iwe));
4025 iwe.cmd = IWEVCUSTOM;
4026 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
4027 iwe.u.data.length = strlen(buf);
4028 current_ev = iwe_stream_add_point(current_ev, end_buf,
4034 if (bss_mesh_cfg(bss)) {
4036 u8 *cfg = bss_mesh_cfg(bss);
4037 buf = kmalloc(50, GFP_ATOMIC);
4039 memset(&iwe, 0, sizeof(iwe));
4040 iwe.cmd = IWEVCUSTOM;
4041 sprintf(buf, "Mesh network (version %d)", cfg[0]);
4042 iwe.u.data.length = strlen(buf);
4043 current_ev = iwe_stream_add_point(current_ev, end_buf,
4045 sprintf(buf, "Path Selection Protocol ID: "
4046 "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
4048 iwe.u.data.length = strlen(buf);
4049 current_ev = iwe_stream_add_point(current_ev, end_buf,
4051 sprintf(buf, "Path Selection Metric ID: "
4052 "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
4054 iwe.u.data.length = strlen(buf);
4055 current_ev = iwe_stream_add_point(current_ev, end_buf,
4057 sprintf(buf, "Congestion Control Mode ID: "
4058 "0x%02X%02X%02X%02X", cfg[9], cfg[10],
4060 iwe.u.data.length = strlen(buf);
4061 current_ev = iwe_stream_add_point(current_ev, end_buf,
4063 sprintf(buf, "Channel Precedence: "
4064 "0x%02X%02X%02X%02X", cfg[13], cfg[14],
4066 iwe.u.data.length = strlen(buf);
4067 current_ev = iwe_stream_add_point(current_ev, end_buf,
4077 int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
4079 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4080 char *current_ev = buf;
4081 char *end_buf = buf + len;
4082 struct ieee80211_sta_bss *bss;
4084 spin_lock_bh(&local->sta_bss_lock);
4085 list_for_each_entry(bss, &local->sta_bss_list, list) {
4086 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
4087 spin_unlock_bh(&local->sta_bss_lock);
4090 current_ev = ieee80211_sta_scan_result(dev, bss, current_ev,
4093 spin_unlock_bh(&local->sta_bss_lock);
4094 return current_ev - buf;
4098 int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
4100 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4101 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4102 kfree(ifsta->extra_ie);
4104 ifsta->extra_ie = NULL;
4105 ifsta->extra_ie_len = 0;
4108 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
4109 if (!ifsta->extra_ie) {
4110 ifsta->extra_ie_len = 0;
4113 memcpy(ifsta->extra_ie, ie, len);
4114 ifsta->extra_ie_len = len;
4119 struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
4120 struct sk_buff *skb, u8 *bssid,
4123 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4124 struct sta_info *sta;
4125 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4126 DECLARE_MAC_BUF(mac);
4128 /* TODO: Could consider removing the least recently used entry and
4129 * allow new one to be added. */
4130 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
4131 if (net_ratelimit()) {
4132 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
4133 "entry %s\n", dev->name, print_mac(mac, addr));
4138 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
4139 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
4141 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
4145 sta->flags |= WLAN_STA_AUTHORIZED;
4147 sta->supp_rates[local->hw.conf.channel->band] =
4148 sdata->u.sta.supp_rates_bits[local->hw.conf.channel->band];
4150 rate_control_rate_init(sta, local);
4152 if (sta_info_insert(sta)) {
4153 sta_info_destroy(sta);
4161 int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
4163 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4164 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4166 printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
4169 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
4170 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
4173 ieee80211_send_deauth(dev, ifsta, reason);
4174 ieee80211_set_disassoc(dev, ifsta, 1);
4179 int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
4181 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4182 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4184 printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
4187 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
4190 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
4193 ieee80211_send_disassoc(dev, ifsta, reason);
4194 ieee80211_set_disassoc(dev, ifsta, 0);