2 * BSS client mode implementation
3 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 * order BSS list by RSSI(?) ("quality of AP")
16 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
19 #include <linux/delay.h>
20 #include <linux/if_ether.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/wireless.h>
25 #include <linux/random.h>
26 #include <linux/etherdevice.h>
27 #include <net/iw_handler.h>
28 #include <asm/types.h>
30 #include <net/mac80211.h>
31 #include "ieee80211_i.h"
32 #include "ieee80211_rate.h"
33 #include "ieee80211_led.h"
36 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
37 #define IEEE80211_AUTH_MAX_TRIES 3
38 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
39 #define IEEE80211_ASSOC_MAX_TRIES 3
40 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
41 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
42 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
43 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
44 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
45 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
46 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
48 #define IEEE80211_PROBE_DELAY (HZ / 33)
49 #define IEEE80211_CHANNEL_TIME (HZ / 33)
50 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
51 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
52 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
53 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
54 #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
56 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
59 #define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
61 #define ERP_INFO_USE_PROTECTION BIT(1)
63 /* mgmt header + 1 byte action code */
64 #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
66 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
67 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
68 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
69 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
70 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
72 /* next values represent the buffer size for A-MPDU frame.
73 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
74 #define IEEE80211_MIN_AMPDU_BUF 0x8
75 #define IEEE80211_MAX_AMPDU_BUF 0x40
77 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
78 u8 *ssid, size_t ssid_len);
79 static struct ieee80211_sta_bss *
80 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
81 u8 *ssid, u8 ssid_len);
82 static void ieee80211_rx_bss_put(struct net_device *dev,
83 struct ieee80211_sta_bss *bss);
84 static int ieee80211_sta_find_ibss(struct net_device *dev,
85 struct ieee80211_if_sta *ifsta);
86 static int ieee80211_sta_wep_configured(struct net_device *dev);
87 static int ieee80211_sta_start_scan(struct net_device *dev,
88 u8 *ssid, size_t ssid_len);
89 static int ieee80211_sta_config_auth(struct net_device *dev,
90 struct ieee80211_if_sta *ifsta);
93 void ieee802_11_parse_elems(u8 *start, size_t len,
94 struct ieee802_11_elems *elems)
99 memset(elems, 0, sizeof(*elems));
114 elems->ssid_len = elen;
116 case WLAN_EID_SUPP_RATES:
117 elems->supp_rates = pos;
118 elems->supp_rates_len = elen;
120 case WLAN_EID_FH_PARAMS:
121 elems->fh_params = pos;
122 elems->fh_params_len = elen;
124 case WLAN_EID_DS_PARAMS:
125 elems->ds_params = pos;
126 elems->ds_params_len = elen;
128 case WLAN_EID_CF_PARAMS:
129 elems->cf_params = pos;
130 elems->cf_params_len = elen;
134 elems->tim_len = elen;
136 case WLAN_EID_IBSS_PARAMS:
137 elems->ibss_params = pos;
138 elems->ibss_params_len = elen;
140 case WLAN_EID_CHALLENGE:
141 elems->challenge = pos;
142 elems->challenge_len = elen;
145 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
147 /* Microsoft OUI (00:50:F2) */
149 /* OUI Type 1 - WPA IE */
151 elems->wpa_len = elen;
152 } else if (elen >= 5 && pos[3] == 2) {
154 elems->wmm_info = pos;
155 elems->wmm_info_len = elen;
156 } else if (pos[4] == 1) {
157 elems->wmm_param = pos;
158 elems->wmm_param_len = elen;
165 elems->rsn_len = elen;
167 case WLAN_EID_ERP_INFO:
168 elems->erp_info = pos;
169 elems->erp_info_len = elen;
171 case WLAN_EID_EXT_SUPP_RATES:
172 elems->ext_supp_rates = pos;
173 elems->ext_supp_rates_len = elen;
175 case WLAN_EID_HT_CAPABILITY:
176 elems->ht_cap_elem = pos;
177 elems->ht_cap_elem_len = elen;
179 case WLAN_EID_HT_EXTRA_INFO:
180 elems->ht_info_elem = pos;
181 elems->ht_info_elem_len = elen;
183 case WLAN_EID_MESH_ID:
184 elems->mesh_id = pos;
185 elems->mesh_id_len = elen;
187 case WLAN_EID_MESH_CONFIG:
188 elems->mesh_config = pos;
189 elems->mesh_config_len = elen;
191 case WLAN_EID_PEER_LINK:
192 elems->peer_link = pos;
193 elems->peer_link_len = elen;
197 elems->preq_len = elen;
201 elems->prep_len = elen;
205 elems->perr_len = elen;
217 static int ecw2cw(int ecw)
219 return (1 << ecw) - 1;
222 static void ieee80211_sta_wmm_params(struct net_device *dev,
223 struct ieee80211_if_sta *ifsta,
224 u8 *wmm_param, size_t wmm_param_len)
226 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
227 struct ieee80211_tx_queue_params params;
232 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
234 count = wmm_param[6] & 0x0f;
235 if (count == ifsta->wmm_last_param_set)
237 ifsta->wmm_last_param_set = count;
240 left = wmm_param_len - 8;
242 memset(¶ms, 0, sizeof(params));
244 if (!local->ops->conf_tx)
248 for (; left >= 4; left -= 4, pos += 4) {
249 int aci = (pos[0] >> 5) & 0x03;
250 int acm = (pos[0] >> 4) & 0x01;
255 queue = IEEE80211_TX_QUEUE_DATA3;
257 local->wmm_acm |= BIT(0) | BIT(3);
261 queue = IEEE80211_TX_QUEUE_DATA1;
263 local->wmm_acm |= BIT(4) | BIT(5);
267 queue = IEEE80211_TX_QUEUE_DATA0;
269 local->wmm_acm |= BIT(6) | BIT(7);
274 queue = IEEE80211_TX_QUEUE_DATA2;
276 local->wmm_acm |= BIT(1) | BIT(2);
281 params.aifs = pos[0] & 0x0f;
282 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
283 params.cw_min = ecw2cw(pos[1] & 0x0f);
284 params.txop = pos[2] | (pos[3] << 8);
285 #ifdef CONFIG_MAC80211_DEBUG
286 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
287 "cWmin=%d cWmax=%d txop=%d\n",
288 dev->name, queue, aci, acm, params.aifs, params.cw_min,
289 params.cw_max, params.txop);
291 /* TODO: handle ACM (block TX, fallback to next lowest allowed
293 if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) {
294 printk(KERN_DEBUG "%s: failed to set TX queue "
295 "parameters for queue %d\n", dev->name, queue);
301 static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata,
304 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
305 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
306 bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
307 bool preamble_mode = (erp_value & WLAN_ERP_BARKER_PREAMBLE) != 0;
308 DECLARE_MAC_BUF(mac);
311 if (use_protection != bss_conf->use_cts_prot) {
312 if (net_ratelimit()) {
313 printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
316 use_protection ? "enabled" : "disabled",
317 print_mac(mac, ifsta->bssid));
319 bss_conf->use_cts_prot = use_protection;
320 changed |= BSS_CHANGED_ERP_CTS_PROT;
323 if (preamble_mode != bss_conf->use_short_preamble) {
324 if (net_ratelimit()) {
325 printk(KERN_DEBUG "%s: switched to %s barker preamble"
328 (preamble_mode == WLAN_ERP_PREAMBLE_SHORT) ?
330 print_mac(mac, ifsta->bssid));
332 bss_conf->use_short_preamble = preamble_mode;
333 changed |= BSS_CHANGED_ERP_PREAMBLE;
339 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
340 struct ieee80211_ht_info *ht_info)
346 memset(ht_info, 0, sizeof(*ht_info));
349 u8 ampdu_info = ht_cap_ie->ampdu_params_info;
351 ht_info->ht_supported = 1;
352 ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info);
353 ht_info->ampdu_factor =
354 ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR;
355 ht_info->ampdu_density =
356 (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
357 memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16);
359 ht_info->ht_supported = 0;
364 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
365 struct ieee80211_ht_addt_info *ht_add_info_ie,
366 struct ieee80211_ht_bss_info *bss_info)
368 if (bss_info == NULL)
371 memset(bss_info, 0, sizeof(*bss_info));
373 if (ht_add_info_ie) {
375 op_mode = le16_to_cpu(ht_add_info_ie->operation_mode);
377 bss_info->primary_channel = ht_add_info_ie->control_chan;
378 bss_info->bss_cap = ht_add_info_ie->ht_param;
379 bss_info->bss_op_mode = (u8)(op_mode & 0xff);
385 static void ieee80211_sta_send_associnfo(struct net_device *dev,
386 struct ieee80211_if_sta *ifsta)
391 union iwreq_data wrqu;
393 if (!ifsta->assocreq_ies && !ifsta->assocresp_ies)
396 buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
397 ifsta->assocresp_ies_len), GFP_KERNEL);
401 len = sprintf(buf, "ASSOCINFO(");
402 if (ifsta->assocreq_ies) {
403 len += sprintf(buf + len, "ReqIEs=");
404 for (i = 0; i < ifsta->assocreq_ies_len; i++) {
405 len += sprintf(buf + len, "%02x",
406 ifsta->assocreq_ies[i]);
409 if (ifsta->assocresp_ies) {
410 if (ifsta->assocreq_ies)
411 len += sprintf(buf + len, " ");
412 len += sprintf(buf + len, "RespIEs=");
413 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
414 len += sprintf(buf + len, "%02x",
415 ifsta->assocresp_ies[i]);
418 len += sprintf(buf + len, ")");
420 if (len > IW_CUSTOM_MAX) {
421 len = sprintf(buf, "ASSOCRESPIE=");
422 for (i = 0; i < ifsta->assocresp_ies_len; i++) {
423 len += sprintf(buf + len, "%02x",
424 ifsta->assocresp_ies[i]);
428 memset(&wrqu, 0, sizeof(wrqu));
429 wrqu.data.length = len;
430 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
436 static void ieee80211_set_associated(struct net_device *dev,
437 struct ieee80211_if_sta *ifsta,
440 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
441 struct ieee80211_local *local = sdata->local;
442 union iwreq_data wrqu;
443 u32 changed = BSS_CHANGED_ASSOC;
446 struct ieee80211_sta_bss *bss;
448 ifsta->flags |= IEEE80211_STA_ASSOCIATED;
450 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
453 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
454 local->hw.conf.channel->center_freq,
455 ifsta->ssid, ifsta->ssid_len);
457 if (bss->has_erp_value)
458 changed |= ieee80211_handle_erp_ie(
459 sdata, bss->erp_value);
460 ieee80211_rx_bss_put(dev, bss);
463 netif_carrier_on(dev);
464 ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
465 memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
466 memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
467 ieee80211_sta_send_associnfo(dev, ifsta);
469 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
471 netif_carrier_off(dev);
472 ieee80211_reset_erp_info(dev);
473 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
475 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
476 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
477 ifsta->last_probe = jiffies;
478 ieee80211_led_assoc(local, assoc);
480 sdata->bss_conf.assoc = assoc;
481 ieee80211_bss_info_change_notify(sdata, changed);
484 static void ieee80211_set_disassoc(struct net_device *dev,
485 struct ieee80211_if_sta *ifsta, int deauth)
488 ifsta->auth_tries = 0;
489 ifsta->assoc_tries = 0;
490 ieee80211_set_associated(dev, ifsta, 0);
493 void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
496 struct ieee80211_sub_if_data *sdata;
497 struct ieee80211_tx_packet_data *pkt_data;
499 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
500 skb->dev = sdata->local->mdev;
501 skb_set_mac_header(skb, 0);
502 skb_set_network_header(skb, 0);
503 skb_set_transport_header(skb, 0);
505 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
506 memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
507 pkt_data->ifindex = sdata->dev->ifindex;
509 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
515 static void ieee80211_send_auth(struct net_device *dev,
516 struct ieee80211_if_sta *ifsta,
517 int transaction, u8 *extra, size_t extra_len,
520 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
522 struct ieee80211_mgmt *mgmt;
524 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
525 sizeof(*mgmt) + 6 + extra_len);
527 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
528 "frame\n", dev->name);
531 skb_reserve(skb, local->hw.extra_tx_headroom);
533 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
534 memset(mgmt, 0, 24 + 6);
535 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
536 IEEE80211_STYPE_AUTH);
538 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
539 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
540 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
541 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
542 mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
543 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
544 ifsta->auth_transaction = transaction + 1;
545 mgmt->u.auth.status_code = cpu_to_le16(0);
547 memcpy(skb_put(skb, extra_len), extra, extra_len);
549 ieee80211_sta_tx(dev, skb, encrypt);
553 static void ieee80211_authenticate(struct net_device *dev,
554 struct ieee80211_if_sta *ifsta)
556 DECLARE_MAC_BUF(mac);
559 if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
560 printk(KERN_DEBUG "%s: authentication with AP %s"
562 dev->name, print_mac(mac, ifsta->bssid));
563 ifsta->state = IEEE80211_DISABLED;
567 ifsta->state = IEEE80211_AUTHENTICATE;
568 printk(KERN_DEBUG "%s: authenticate with AP %s\n",
569 dev->name, print_mac(mac, ifsta->bssid));
571 ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
573 mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
577 static void ieee80211_send_assoc(struct net_device *dev,
578 struct ieee80211_if_sta *ifsta)
580 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
582 struct ieee80211_mgmt *mgmt;
586 struct ieee80211_sta_bss *bss;
588 struct ieee80211_supported_band *sband;
590 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
591 sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
594 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
595 "frame\n", dev->name);
598 skb_reserve(skb, local->hw.extra_tx_headroom);
600 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
602 capab = ifsta->capab;
604 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
605 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
606 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
607 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
608 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
611 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
612 local->hw.conf.channel->center_freq,
613 ifsta->ssid, ifsta->ssid_len);
615 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
616 capab |= WLAN_CAPABILITY_PRIVACY;
620 ieee80211_rx_bss_put(dev, bss);
623 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
625 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
626 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
627 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
629 if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
631 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
632 IEEE80211_STYPE_REASSOC_REQ);
633 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
634 mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1);
635 memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
639 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
640 IEEE80211_STYPE_ASSOC_REQ);
641 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
642 mgmt->u.assoc_req.listen_interval = cpu_to_le16(1);
646 ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
647 *pos++ = WLAN_EID_SSID;
648 *pos++ = ifsta->ssid_len;
649 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
651 len = sband->n_bitrates;
654 pos = skb_put(skb, len + 2);
655 *pos++ = WLAN_EID_SUPP_RATES;
657 for (i = 0; i < len; i++) {
658 int rate = sband->bitrates[i].bitrate;
659 *pos++ = (u8) (rate / 5);
662 if (sband->n_bitrates > len) {
663 pos = skb_put(skb, sband->n_bitrates - len + 2);
664 *pos++ = WLAN_EID_EXT_SUPP_RATES;
665 *pos++ = sband->n_bitrates - len;
666 for (i = len; i < sband->n_bitrates; i++) {
667 int rate = sband->bitrates[i].bitrate;
668 *pos++ = (u8) (rate / 5);
672 if (ifsta->extra_ie) {
673 pos = skb_put(skb, ifsta->extra_ie_len);
674 memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
677 if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
678 pos = skb_put(skb, 9);
679 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
680 *pos++ = 7; /* len */
681 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
684 *pos++ = 2; /* WME */
685 *pos++ = 0; /* WME info */
686 *pos++ = 1; /* WME ver */
689 /* wmm support is a must to HT */
690 if (wmm && sband->ht_info.ht_supported) {
691 __le16 tmp = cpu_to_le16(sband->ht_info.cap);
692 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
693 *pos++ = WLAN_EID_HT_CAPABILITY;
694 *pos++ = sizeof(struct ieee80211_ht_cap);
695 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
696 memcpy(pos, &tmp, sizeof(u16));
698 /* TODO: needs a define here for << 2 */
699 *pos++ = sband->ht_info.ampdu_factor |
700 (sband->ht_info.ampdu_density << 2);
701 memcpy(pos, sband->ht_info.supp_mcs_set, 16);
704 kfree(ifsta->assocreq_ies);
705 ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
706 ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
707 if (ifsta->assocreq_ies)
708 memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
710 ieee80211_sta_tx(dev, skb, 0);
714 static void ieee80211_send_deauth(struct net_device *dev,
715 struct ieee80211_if_sta *ifsta, u16 reason)
717 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
719 struct ieee80211_mgmt *mgmt;
721 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
723 printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
724 "frame\n", dev->name);
727 skb_reserve(skb, local->hw.extra_tx_headroom);
729 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
731 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
732 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
733 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
734 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
735 IEEE80211_STYPE_DEAUTH);
737 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
739 ieee80211_sta_tx(dev, skb, 0);
743 static void ieee80211_send_disassoc(struct net_device *dev,
744 struct ieee80211_if_sta *ifsta, u16 reason)
746 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
748 struct ieee80211_mgmt *mgmt;
750 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
752 printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
753 "frame\n", dev->name);
756 skb_reserve(skb, local->hw.extra_tx_headroom);
758 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
760 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
761 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
762 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
763 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
764 IEEE80211_STYPE_DISASSOC);
766 mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
768 ieee80211_sta_tx(dev, skb, 0);
772 static int ieee80211_privacy_mismatch(struct net_device *dev,
773 struct ieee80211_if_sta *ifsta)
775 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
776 struct ieee80211_sta_bss *bss;
781 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
784 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
785 local->hw.conf.channel->center_freq,
786 ifsta->ssid, ifsta->ssid_len);
790 bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
791 wep_privacy = !!ieee80211_sta_wep_configured(dev);
792 privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
794 ieee80211_rx_bss_put(dev, bss);
796 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
803 static void ieee80211_associate(struct net_device *dev,
804 struct ieee80211_if_sta *ifsta)
806 DECLARE_MAC_BUF(mac);
808 ifsta->assoc_tries++;
809 if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
810 printk(KERN_DEBUG "%s: association with AP %s"
812 dev->name, print_mac(mac, ifsta->bssid));
813 ifsta->state = IEEE80211_DISABLED;
817 ifsta->state = IEEE80211_ASSOCIATE;
818 printk(KERN_DEBUG "%s: associate with AP %s\n",
819 dev->name, print_mac(mac, ifsta->bssid));
820 if (ieee80211_privacy_mismatch(dev, ifsta)) {
821 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
822 "mixed-cell disabled - abort association\n", dev->name);
823 ifsta->state = IEEE80211_DISABLED;
827 ieee80211_send_assoc(dev, ifsta);
829 mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
833 static void ieee80211_associated(struct net_device *dev,
834 struct ieee80211_if_sta *ifsta)
836 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
837 struct sta_info *sta;
839 DECLARE_MAC_BUF(mac);
841 /* TODO: start monitoring current AP signal quality and number of
842 * missed beacons. Scan other channels every now and then and search
844 /* TODO: remove expired BSSes */
846 ifsta->state = IEEE80211_ASSOCIATED;
848 sta = sta_info_get(local, ifsta->bssid);
850 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
851 dev->name, print_mac(mac, ifsta->bssid));
855 if (time_after(jiffies,
856 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
857 if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
858 printk(KERN_DEBUG "%s: No ProbeResp from "
859 "current AP %s - assume out of "
861 dev->name, print_mac(mac, ifsta->bssid));
865 ieee80211_send_probe_req(dev, ifsta->bssid,
867 local->scan_ssid_len);
868 ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
870 ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
871 if (time_after(jiffies, ifsta->last_probe +
872 IEEE80211_PROBE_INTERVAL)) {
873 ifsta->last_probe = jiffies;
874 ieee80211_send_probe_req(dev, ifsta->bssid,
882 ifsta->state = IEEE80211_DISABLED;
883 ieee80211_set_associated(dev, ifsta, 0);
885 mod_timer(&ifsta->timer, jiffies +
886 IEEE80211_MONITORING_INTERVAL);
891 static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
892 u8 *ssid, size_t ssid_len)
894 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
895 struct ieee80211_supported_band *sband;
897 struct ieee80211_mgmt *mgmt;
898 u8 *pos, *supp_rates, *esupp_rates = NULL;
901 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
903 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
904 "request\n", dev->name);
907 skb_reserve(skb, local->hw.extra_tx_headroom);
909 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
911 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
912 IEEE80211_STYPE_PROBE_REQ);
913 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
915 memcpy(mgmt->da, dst, ETH_ALEN);
916 memcpy(mgmt->bssid, dst, ETH_ALEN);
918 memset(mgmt->da, 0xff, ETH_ALEN);
919 memset(mgmt->bssid, 0xff, ETH_ALEN);
921 pos = skb_put(skb, 2 + ssid_len);
922 *pos++ = WLAN_EID_SSID;
924 memcpy(pos, ssid, ssid_len);
926 supp_rates = skb_put(skb, 2);
927 supp_rates[0] = WLAN_EID_SUPP_RATES;
929 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
931 for (i = 0; i < sband->n_bitrates; i++) {
932 struct ieee80211_rate *rate = &sband->bitrates[i];
934 pos = skb_put(skb, 1);
936 } else if (supp_rates[1] == 8) {
937 esupp_rates = skb_put(skb, 3);
938 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
940 pos = &esupp_rates[2];
942 pos = skb_put(skb, 1);
945 *pos = rate->bitrate / 5;
948 ieee80211_sta_tx(dev, skb, 0);
952 static int ieee80211_sta_wep_configured(struct net_device *dev)
954 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
955 if (!sdata || !sdata->default_key ||
956 sdata->default_key->conf.alg != ALG_WEP)
962 static void ieee80211_auth_completed(struct net_device *dev,
963 struct ieee80211_if_sta *ifsta)
965 printk(KERN_DEBUG "%s: authenticated\n", dev->name);
966 ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
967 ieee80211_associate(dev, ifsta);
971 static void ieee80211_auth_challenge(struct net_device *dev,
972 struct ieee80211_if_sta *ifsta,
973 struct ieee80211_mgmt *mgmt,
977 struct ieee802_11_elems elems;
979 printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
980 pos = mgmt->u.auth.variable;
981 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
982 if (!elems.challenge) {
983 printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
984 "frame\n", dev->name);
987 ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
988 elems.challenge_len + 2, 1);
991 static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
992 u8 dialog_token, u16 status, u16 policy,
993 u16 buf_size, u16 timeout)
995 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
996 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
997 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
999 struct ieee80211_mgmt *mgmt;
1002 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1003 sizeof(mgmt->u.action.u.addba_resp));
1005 printk(KERN_DEBUG "%s: failed to allocate buffer "
1006 "for addba resp frame\n", dev->name);
1010 skb_reserve(skb, local->hw.extra_tx_headroom);
1011 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1012 memset(mgmt, 0, 24);
1013 memcpy(mgmt->da, da, ETH_ALEN);
1014 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1015 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1016 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1018 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1019 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1020 IEEE80211_STYPE_ACTION);
1022 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
1023 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1024 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
1025 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
1027 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
1028 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1029 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
1031 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
1032 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
1033 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
1035 ieee80211_sta_tx(dev, skb, 0);
1040 void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
1041 u16 tid, u8 dialog_token, u16 start_seq_num,
1042 u16 agg_size, u16 timeout)
1044 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1045 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1046 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1047 struct sk_buff *skb;
1048 struct ieee80211_mgmt *mgmt;
1051 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1052 sizeof(mgmt->u.action.u.addba_req));
1056 printk(KERN_ERR "%s: failed to allocate buffer "
1057 "for addba request frame\n", dev->name);
1060 skb_reserve(skb, local->hw.extra_tx_headroom);
1061 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1062 memset(mgmt, 0, 24);
1063 memcpy(mgmt->da, da, ETH_ALEN);
1064 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1065 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1066 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1068 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1070 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1071 IEEE80211_STYPE_ACTION);
1073 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
1075 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1076 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
1078 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
1079 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
1080 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1081 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
1083 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
1085 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
1086 mgmt->u.action.u.addba_req.start_seq_num =
1087 cpu_to_le16(start_seq_num << 4);
1089 ieee80211_sta_tx(dev, skb, 0);
1092 static void ieee80211_sta_process_addba_request(struct net_device *dev,
1093 struct ieee80211_mgmt *mgmt,
1096 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1097 struct ieee80211_hw *hw = &local->hw;
1098 struct ieee80211_conf *conf = &hw->conf;
1099 struct sta_info *sta;
1100 struct tid_ampdu_rx *tid_agg_rx;
1101 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
1103 int ret = -EOPNOTSUPP;
1104 DECLARE_MAC_BUF(mac);
1106 sta = sta_info_get(local, mgmt->sa);
1110 /* extract session parameters from addba request frame */
1111 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
1112 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
1114 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
1116 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1117 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
1118 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1119 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
1121 status = WLAN_STATUS_REQUEST_DECLINED;
1123 /* sanity check for incoming parameters:
1124 * check if configuration can support the BA policy
1125 * and if buffer size does not exceeds max value */
1126 if (((ba_policy != 1)
1127 && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
1128 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
1129 status = WLAN_STATUS_INVALID_QOS_PARAM;
1130 #ifdef CONFIG_MAC80211_HT_DEBUG
1131 if (net_ratelimit())
1132 printk(KERN_DEBUG "Block Ack Req with bad params from "
1133 "%s on tid %u. policy %d, buffer size %d\n",
1134 print_mac(mac, mgmt->sa), tid, ba_policy,
1136 #endif /* CONFIG_MAC80211_HT_DEBUG */
1139 /* determine default buffer size */
1140 if (buf_size == 0) {
1141 struct ieee80211_supported_band *sband;
1143 sband = local->hw.wiphy->bands[conf->channel->band];
1144 buf_size = IEEE80211_MIN_AMPDU_BUF;
1145 buf_size = buf_size << sband->ht_info.ampdu_factor;
1148 tid_agg_rx = &sta->ampdu_mlme.tid_rx[tid];
1150 /* examine state machine */
1151 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1153 if (tid_agg_rx->state != HT_AGG_STATE_IDLE) {
1154 #ifdef CONFIG_MAC80211_HT_DEBUG
1155 if (net_ratelimit())
1156 printk(KERN_DEBUG "unexpected Block Ack Req from "
1158 print_mac(mac, mgmt->sa), tid);
1159 #endif /* CONFIG_MAC80211_HT_DEBUG */
1163 /* prepare reordering buffer */
1164 tid_agg_rx->reorder_buf =
1165 kmalloc(buf_size * sizeof(struct sk_buf *), GFP_ATOMIC);
1166 if (!tid_agg_rx->reorder_buf) {
1167 if (net_ratelimit())
1168 printk(KERN_ERR "can not allocate reordering buffer "
1169 "to tid %d\n", tid);
1172 memset(tid_agg_rx->reorder_buf, 0,
1173 buf_size * sizeof(struct sk_buf *));
1175 if (local->ops->ampdu_action)
1176 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
1177 sta->addr, tid, &start_seq_num);
1178 #ifdef CONFIG_MAC80211_HT_DEBUG
1179 printk(KERN_DEBUG "Rx A-MPDU on tid %d result %d", tid, ret);
1180 #endif /* CONFIG_MAC80211_HT_DEBUG */
1183 kfree(tid_agg_rx->reorder_buf);
1187 /* change state and send addba resp */
1188 tid_agg_rx->state = HT_AGG_STATE_OPERATIONAL;
1189 tid_agg_rx->dialog_token = dialog_token;
1190 tid_agg_rx->ssn = start_seq_num;
1191 tid_agg_rx->head_seq_num = start_seq_num;
1192 tid_agg_rx->buf_size = buf_size;
1193 tid_agg_rx->timeout = timeout;
1194 tid_agg_rx->stored_mpdu_num = 0;
1195 status = WLAN_STATUS_SUCCESS;
1197 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1200 ieee80211_send_addba_resp(sta->dev, sta->addr, tid, dialog_token,
1201 status, 1, buf_size, timeout);
1205 static void ieee80211_sta_process_addba_resp(struct net_device *dev,
1206 struct ieee80211_mgmt *mgmt,
1209 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1210 struct ieee80211_hw *hw = &local->hw;
1211 struct sta_info *sta;
1216 sta = sta_info_get(local, mgmt->sa);
1220 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
1221 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1223 state = &sta->ampdu_mlme.tid_tx[tid].state;
1225 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1227 if (mgmt->u.action.u.addba_resp.dialog_token !=
1228 sta->ampdu_mlme.tid_tx[tid].dialog_token) {
1229 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1230 #ifdef CONFIG_MAC80211_HT_DEBUG
1231 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1232 #endif /* CONFIG_MAC80211_HT_DEBUG */
1237 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
1238 #ifdef CONFIG_MAC80211_HT_DEBUG
1239 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1240 #endif /* CONFIG_MAC80211_HT_DEBUG */
1241 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1242 == WLAN_STATUS_SUCCESS) {
1243 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1244 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1245 printk(KERN_DEBUG "state not HT_ADDBA_REQUESTED_MSK:"
1251 if (*state & HT_ADDBA_RECEIVED_MSK)
1252 printk(KERN_DEBUG "double addBA response\n");
1254 *state |= HT_ADDBA_RECEIVED_MSK;
1255 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
1257 if (*state == HT_AGG_STATE_OPERATIONAL) {
1258 printk(KERN_DEBUG "Aggregation on for tid %d \n", tid);
1259 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1262 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1263 printk(KERN_DEBUG "recipient accepted agg: tid %d \n", tid);
1265 printk(KERN_DEBUG "recipient rejected agg: tid %d \n", tid);
1267 sta->ampdu_mlme.tid_tx[tid].addba_req_num++;
1268 /* this will allow the state check in stop_BA_session */
1269 *state = HT_AGG_STATE_OPERATIONAL;
1270 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1271 ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
1272 WLAN_BACK_INITIATOR);
1277 void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
1278 u16 initiator, u16 reason_code)
1280 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1281 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1282 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1283 struct sk_buff *skb;
1284 struct ieee80211_mgmt *mgmt;
1287 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1288 sizeof(mgmt->u.action.u.delba));
1291 printk(KERN_ERR "%s: failed to allocate buffer "
1292 "for delba frame\n", dev->name);
1296 skb_reserve(skb, local->hw.extra_tx_headroom);
1297 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1298 memset(mgmt, 0, 24);
1299 memcpy(mgmt->da, da, ETH_ALEN);
1300 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1301 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1302 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1304 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1305 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1306 IEEE80211_STYPE_ACTION);
1308 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
1310 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1311 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1312 params = (u16)(initiator << 11); /* bit 11 initiator */
1313 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1315 mgmt->u.action.u.delba.params = cpu_to_le16(params);
1316 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1318 ieee80211_sta_tx(dev, skb, 0);
1321 void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1322 u16 initiator, u16 reason)
1324 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1325 struct ieee80211_hw *hw = &local->hw;
1326 struct sta_info *sta;
1329 sta = sta_info_get(local, ra);
1333 /* check if TID is in operational state */
1334 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1335 if (sta->ampdu_mlme.tid_rx[tid].state
1336 != HT_AGG_STATE_OPERATIONAL) {
1337 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1341 sta->ampdu_mlme.tid_rx[tid].state =
1342 HT_AGG_STATE_REQ_STOP_BA_MSK |
1343 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
1344 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1346 /* stop HW Rx aggregation. ampdu_action existence
1347 * already verified in session init so we add the BUG_ON */
1348 BUG_ON(!local->ops->ampdu_action);
1350 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
1353 printk(KERN_DEBUG "HW problem - can not stop rx "
1354 "aggergation for tid %d\n", tid);
1356 /* shutdown timer has not expired */
1357 if (initiator != WLAN_BACK_TIMER)
1358 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid].
1361 /* check if this is a self generated aggregation halt */
1362 if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
1363 ieee80211_send_delba(dev, ra, tid, 0, reason);
1365 /* free the reordering buffer */
1366 for (i = 0; i < sta->ampdu_mlme.tid_rx[tid].buf_size; i++) {
1367 if (sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]) {
1368 /* release the reordered frames */
1369 dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]);
1370 sta->ampdu_mlme.tid_rx[tid].stored_mpdu_num--;
1371 sta->ampdu_mlme.tid_rx[tid].reorder_buf[i] = NULL;
1374 kfree(sta->ampdu_mlme.tid_rx[tid].reorder_buf);
1376 sta->ampdu_mlme.tid_rx[tid].state = HT_AGG_STATE_IDLE;
1381 static void ieee80211_sta_process_delba(struct net_device *dev,
1382 struct ieee80211_mgmt *mgmt, size_t len)
1384 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1385 struct sta_info *sta;
1388 DECLARE_MAC_BUF(mac);
1390 sta = sta_info_get(local, mgmt->sa);
1394 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1395 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1396 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1398 #ifdef CONFIG_MAC80211_HT_DEBUG
1399 if (net_ratelimit())
1400 printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
1401 print_mac(mac, mgmt->sa),
1402 initiator ? "recipient" : "initiator", tid,
1403 mgmt->u.action.u.delba.reason_code);
1404 #endif /* CONFIG_MAC80211_HT_DEBUG */
1406 if (initiator == WLAN_BACK_INITIATOR)
1407 ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
1408 WLAN_BACK_INITIATOR, 0);
1409 else { /* WLAN_BACK_RECIPIENT */
1410 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1411 sta->ampdu_mlme.tid_tx[tid].state =
1412 HT_AGG_STATE_OPERATIONAL;
1413 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1414 ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
1415 WLAN_BACK_RECIPIENT);
1421 * After sending add Block Ack request we activated a timer until
1422 * add Block Ack response will arrive from the recipient.
1423 * If this timer expires sta_addba_resp_timer_expired will be executed.
1425 void sta_addba_resp_timer_expired(unsigned long data)
1427 /* not an elegant detour, but there is no choice as the timer passes
1428 * only one argument, and both sta_info and TID are needed, so init
1429 * flow in sta_info_add gives the TID as data, while the timer_to_id
1430 * array gives the sta through container_of */
1431 u16 tid = *(int *)data;
1432 struct sta_info *temp_sta = container_of((void *)data,
1433 struct sta_info, timer_to_tid[tid]);
1435 struct ieee80211_local *local = temp_sta->local;
1436 struct ieee80211_hw *hw = &local->hw;
1437 struct sta_info *sta;
1440 sta = sta_info_get(local, temp_sta->addr);
1444 state = &sta->ampdu_mlme.tid_tx[tid].state;
1445 /* check if the TID waits for addBA response */
1446 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1447 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1448 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1449 *state = HT_AGG_STATE_IDLE;
1450 printk(KERN_DEBUG "timer expired on tid %d but we are not "
1451 "expecting addBA response there", tid);
1452 goto timer_expired_exit;
1455 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
1457 /* go through the state check in stop_BA_session */
1458 *state = HT_AGG_STATE_OPERATIONAL;
1459 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1460 ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
1461 WLAN_BACK_INITIATOR);
1468 * After receiving Block Ack Request (BAR) we activated a
1469 * timer after each frame arrives from the originator.
1470 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1472 void sta_rx_agg_session_timer_expired(unsigned long data)
1474 /* not an elegant detour, but there is no choice as the timer passes
1475 * only one argument, and verious sta_info are needed here, so init
1476 * flow in sta_info_add gives the TID as data, while the timer_to_id
1477 * array gives the sta through container_of */
1478 u8 *ptid = (u8 *)data;
1479 u8 *timer_to_id = ptid - *ptid;
1480 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
1483 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
1484 ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr, (u16)*ptid,
1486 WLAN_REASON_QSTA_TIMEOUT);
1490 static void ieee80211_rx_mgmt_auth(struct net_device *dev,
1491 struct ieee80211_if_sta *ifsta,
1492 struct ieee80211_mgmt *mgmt,
1495 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1496 u16 auth_alg, auth_transaction, status_code;
1497 DECLARE_MAC_BUF(mac);
1499 if (ifsta->state != IEEE80211_AUTHENTICATE &&
1500 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
1501 printk(KERN_DEBUG "%s: authentication frame received from "
1502 "%s, but not in authenticate state - ignored\n",
1503 dev->name, print_mac(mac, mgmt->sa));
1508 printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
1509 "received from %s - ignored\n",
1510 dev->name, len, print_mac(mac, mgmt->sa));
1514 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
1515 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1516 printk(KERN_DEBUG "%s: authentication frame received from "
1517 "unknown AP (SA=%s BSSID=%s) - "
1518 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1519 print_mac(mac, mgmt->bssid));
1523 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
1524 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
1525 printk(KERN_DEBUG "%s: authentication frame received from "
1526 "unknown BSSID (SA=%s BSSID=%s) - "
1527 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1528 print_mac(mac, mgmt->bssid));
1532 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1533 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1534 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1536 printk(KERN_DEBUG "%s: RX authentication from %s (alg=%d "
1537 "transaction=%d status=%d)\n",
1538 dev->name, print_mac(mac, mgmt->sa), auth_alg,
1539 auth_transaction, status_code);
1541 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
1542 /* IEEE 802.11 standard does not require authentication in IBSS
1543 * networks and most implementations do not seem to use it.
1544 * However, try to reply to authentication attempts if someone
1545 * has actually implemented this.
1546 * TODO: Could implement shared key authentication. */
1547 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
1548 printk(KERN_DEBUG "%s: unexpected IBSS authentication "
1549 "frame (alg=%d transaction=%d)\n",
1550 dev->name, auth_alg, auth_transaction);
1553 ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
1556 if (auth_alg != ifsta->auth_alg ||
1557 auth_transaction != ifsta->auth_transaction) {
1558 printk(KERN_DEBUG "%s: unexpected authentication frame "
1559 "(alg=%d transaction=%d)\n",
1560 dev->name, auth_alg, auth_transaction);
1564 if (status_code != WLAN_STATUS_SUCCESS) {
1565 printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
1566 "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
1567 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1569 const int num_algs = ARRAY_SIZE(algs);
1571 algs[0] = algs[1] = algs[2] = 0xff;
1572 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1573 algs[0] = WLAN_AUTH_OPEN;
1574 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1575 algs[1] = WLAN_AUTH_SHARED_KEY;
1576 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1577 algs[2] = WLAN_AUTH_LEAP;
1578 if (ifsta->auth_alg == WLAN_AUTH_OPEN)
1580 else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
1584 for (i = 0; i < num_algs; i++) {
1586 if (pos >= num_algs)
1588 if (algs[pos] == ifsta->auth_alg ||
1591 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1592 !ieee80211_sta_wep_configured(dev))
1594 ifsta->auth_alg = algs[pos];
1595 printk(KERN_DEBUG "%s: set auth_alg=%d for "
1597 dev->name, ifsta->auth_alg);
1604 switch (ifsta->auth_alg) {
1605 case WLAN_AUTH_OPEN:
1606 case WLAN_AUTH_LEAP:
1607 ieee80211_auth_completed(dev, ifsta);
1609 case WLAN_AUTH_SHARED_KEY:
1610 if (ifsta->auth_transaction == 4)
1611 ieee80211_auth_completed(dev, ifsta);
1613 ieee80211_auth_challenge(dev, ifsta, mgmt, len);
1619 static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
1620 struct ieee80211_if_sta *ifsta,
1621 struct ieee80211_mgmt *mgmt,
1625 DECLARE_MAC_BUF(mac);
1628 printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
1629 "received from %s - ignored\n",
1630 dev->name, len, print_mac(mac, mgmt->sa));
1634 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1635 printk(KERN_DEBUG "%s: deauthentication frame received from "
1636 "unknown AP (SA=%s BSSID=%s) - "
1637 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1638 print_mac(mac, mgmt->bssid));
1642 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1644 printk(KERN_DEBUG "%s: RX deauthentication from %s"
1646 dev->name, print_mac(mac, mgmt->sa), reason_code);
1648 if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) {
1649 printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
1652 if (ifsta->state == IEEE80211_AUTHENTICATE ||
1653 ifsta->state == IEEE80211_ASSOCIATE ||
1654 ifsta->state == IEEE80211_ASSOCIATED) {
1655 ifsta->state = IEEE80211_AUTHENTICATE;
1656 mod_timer(&ifsta->timer, jiffies +
1657 IEEE80211_RETRY_AUTH_INTERVAL);
1660 ieee80211_set_disassoc(dev, ifsta, 1);
1661 ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
1665 static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
1666 struct ieee80211_if_sta *ifsta,
1667 struct ieee80211_mgmt *mgmt,
1671 DECLARE_MAC_BUF(mac);
1674 printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
1675 "received from %s - ignored\n",
1676 dev->name, len, print_mac(mac, mgmt->sa));
1680 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1681 printk(KERN_DEBUG "%s: disassociation frame received from "
1682 "unknown AP (SA=%s BSSID=%s) - "
1683 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1684 print_mac(mac, mgmt->bssid));
1688 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1690 printk(KERN_DEBUG "%s: RX disassociation from %s"
1692 dev->name, print_mac(mac, mgmt->sa), reason_code);
1694 if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
1695 printk(KERN_DEBUG "%s: disassociated\n", dev->name);
1697 if (ifsta->state == IEEE80211_ASSOCIATED) {
1698 ifsta->state = IEEE80211_ASSOCIATE;
1699 mod_timer(&ifsta->timer, jiffies +
1700 IEEE80211_RETRY_AUTH_INTERVAL);
1703 ieee80211_set_disassoc(dev, ifsta, 0);
1707 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1708 struct ieee80211_if_sta *ifsta,
1709 struct ieee80211_mgmt *mgmt,
1713 struct ieee80211_local *local = sdata->local;
1714 struct net_device *dev = sdata->dev;
1715 struct ieee80211_supported_band *sband;
1716 struct sta_info *sta;
1717 u64 rates, basic_rates;
1718 u16 capab_info, status_code, aid;
1719 struct ieee802_11_elems elems;
1720 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
1723 DECLARE_MAC_BUF(mac);
1724 bool have_higher_than_11mbit = false;
1726 /* AssocResp and ReassocResp have identical structure, so process both
1727 * of them in this function. */
1729 if (ifsta->state != IEEE80211_ASSOCIATE) {
1730 printk(KERN_DEBUG "%s: association frame received from "
1731 "%s, but not in associate state - ignored\n",
1732 dev->name, print_mac(mac, mgmt->sa));
1737 printk(KERN_DEBUG "%s: too short (%zd) association frame "
1738 "received from %s - ignored\n",
1739 dev->name, len, print_mac(mac, mgmt->sa));
1743 if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
1744 printk(KERN_DEBUG "%s: association frame received from "
1745 "unknown AP (SA=%s BSSID=%s) - "
1746 "ignored\n", dev->name, print_mac(mac, mgmt->sa),
1747 print_mac(mac, mgmt->bssid));
1751 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1752 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1753 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1755 printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
1756 "status=%d aid=%d)\n",
1757 dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
1758 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1760 if (status_code != WLAN_STATUS_SUCCESS) {
1761 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1762 dev->name, status_code);
1763 /* if this was a reassociation, ensure we try a "full"
1764 * association next time. This works around some broken APs
1765 * which do not correctly reject reassociation requests. */
1766 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1770 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1771 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1772 "set\n", dev->name, aid);
1773 aid &= ~(BIT(15) | BIT(14));
1775 pos = mgmt->u.assoc_resp.variable;
1776 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1778 if (!elems.supp_rates) {
1779 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1784 printk(KERN_DEBUG "%s: associated\n", dev->name);
1786 ifsta->ap_capab = capab_info;
1788 kfree(ifsta->assocresp_ies);
1789 ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1790 ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
1791 if (ifsta->assocresp_ies)
1792 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
1794 /* Add STA entry for the AP */
1795 sta = sta_info_get(local, ifsta->bssid);
1797 struct ieee80211_sta_bss *bss;
1798 sta = sta_info_add(local, dev, ifsta->bssid, GFP_KERNEL);
1800 printk(KERN_DEBUG "%s: failed to add STA entry for the"
1801 " AP (error %ld)\n", dev->name, PTR_ERR(sta));
1804 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
1805 local->hw.conf.channel->center_freq,
1806 ifsta->ssid, ifsta->ssid_len);
1808 sta->last_rssi = bss->rssi;
1809 sta->last_signal = bss->signal;
1810 sta->last_noise = bss->noise;
1811 ieee80211_rx_bss_put(dev, bss);
1816 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1817 WLAN_STA_AUTHORIZED;
1821 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1823 for (i = 0; i < elems.supp_rates_len; i++) {
1824 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1827 have_higher_than_11mbit = true;
1829 for (j = 0; j < sband->n_bitrates; j++) {
1830 if (sband->bitrates[j].bitrate == rate)
1832 if (elems.supp_rates[i] & 0x80)
1833 basic_rates |= BIT(j);
1837 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1838 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1841 have_higher_than_11mbit = true;
1843 for (j = 0; j < sband->n_bitrates; j++) {
1844 if (sband->bitrates[j].bitrate == rate)
1846 if (elems.ext_supp_rates[i] & 0x80)
1847 basic_rates |= BIT(j);
1851 sta->supp_rates[local->hw.conf.channel->band] = rates;
1852 sdata->basic_rates = basic_rates;
1854 /* cf. IEEE 802.11 9.2.12 */
1855 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1856 have_higher_than_11mbit)
1857 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1859 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
1861 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
1862 local->ops->conf_ht) {
1863 struct ieee80211_ht_bss_info bss_info;
1865 ieee80211_ht_cap_ie_to_ht_info(
1866 (struct ieee80211_ht_cap *)
1867 elems.ht_cap_elem, &sta->ht_info);
1868 ieee80211_ht_addt_info_ie_to_ht_bss_info(
1869 (struct ieee80211_ht_addt_info *)
1870 elems.ht_info_elem, &bss_info);
1871 ieee80211_hw_config_ht(local, 1, &sta->ht_info, &bss_info);
1874 rate_control_rate_init(sta, local);
1876 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
1877 sta->flags |= WLAN_STA_WME;
1878 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
1879 elems.wmm_param_len);
1882 /* set AID, ieee80211_set_associated() will tell the driver */
1883 bss_conf->aid = aid;
1884 ieee80211_set_associated(dev, ifsta, 1);
1888 ieee80211_associated(dev, ifsta);
1892 /* Caller must hold local->sta_bss_lock */
1893 static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
1894 struct ieee80211_sta_bss *bss)
1896 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1899 if (bss_mesh_cfg(bss))
1900 hash_idx = mesh_id_hash(bss_mesh_id(bss),
1901 bss_mesh_id_len(bss));
1903 hash_idx = STA_HASH(bss->bssid);
1905 bss->hnext = local->sta_bss_hash[hash_idx];
1906 local->sta_bss_hash[hash_idx] = bss;
1910 /* Caller must hold local->sta_bss_lock */
1911 static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
1912 struct ieee80211_sta_bss *bss)
1914 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1915 struct ieee80211_sta_bss *b, *prev = NULL;
1916 b = local->sta_bss_hash[STA_HASH(bss->bssid)];
1920 local->sta_bss_hash[STA_HASH(bss->bssid)] =
1923 prev->hnext = bss->hnext;
1932 static struct ieee80211_sta_bss *
1933 ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
1934 u8 *ssid, u8 ssid_len)
1936 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1937 struct ieee80211_sta_bss *bss;
1939 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
1942 atomic_inc(&bss->users);
1943 atomic_inc(&bss->users);
1944 memcpy(bss->bssid, bssid, ETH_ALEN);
1946 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
1947 memcpy(bss->ssid, ssid, ssid_len);
1948 bss->ssid_len = ssid_len;
1951 spin_lock_bh(&local->sta_bss_lock);
1952 /* TODO: order by RSSI? */
1953 list_add_tail(&bss->list, &local->sta_bss_list);
1954 __ieee80211_rx_bss_hash_add(dev, bss);
1955 spin_unlock_bh(&local->sta_bss_lock);
1959 static struct ieee80211_sta_bss *
1960 ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
1961 u8 *ssid, u8 ssid_len)
1963 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1964 struct ieee80211_sta_bss *bss;
1966 spin_lock_bh(&local->sta_bss_lock);
1967 bss = local->sta_bss_hash[STA_HASH(bssid)];
1969 if (!bss_mesh_cfg(bss) &&
1970 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
1971 bss->freq == freq &&
1972 bss->ssid_len == ssid_len &&
1973 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
1974 atomic_inc(&bss->users);
1979 spin_unlock_bh(&local->sta_bss_lock);
1983 #ifdef CONFIG_MAC80211_MESH
1984 static struct ieee80211_sta_bss *
1985 ieee80211_rx_mesh_bss_get(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
1986 u8 *mesh_cfg, int freq)
1988 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1989 struct ieee80211_sta_bss *bss;
1991 spin_lock_bh(&local->sta_bss_lock);
1992 bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
1994 if (bss_mesh_cfg(bss) &&
1995 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
1996 bss->freq == freq &&
1997 mesh_id_len == bss->mesh_id_len &&
1998 (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
2000 atomic_inc(&bss->users);
2005 spin_unlock_bh(&local->sta_bss_lock);
2009 static struct ieee80211_sta_bss *
2010 ieee80211_rx_mesh_bss_add(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2011 u8 *mesh_cfg, int freq)
2013 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2014 struct ieee80211_sta_bss *bss;
2016 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2020 bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
2021 if (!bss->mesh_cfg) {
2026 if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
2027 bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
2028 if (!bss->mesh_id) {
2029 kfree(bss->mesh_cfg);
2033 memcpy(bss->mesh_id, mesh_id, mesh_id_len);
2036 atomic_inc(&bss->users);
2037 atomic_inc(&bss->users);
2038 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
2039 bss->mesh_id_len = mesh_id_len;
2041 spin_lock_bh(&local->sta_bss_lock);
2042 /* TODO: order by RSSI? */
2043 list_add_tail(&bss->list, &local->sta_bss_list);
2044 __ieee80211_rx_bss_hash_add(dev, bss);
2045 spin_unlock_bh(&local->sta_bss_lock);
2050 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
2056 kfree(bss_mesh_id(bss));
2057 kfree(bss_mesh_cfg(bss));
2062 static void ieee80211_rx_bss_put(struct net_device *dev,
2063 struct ieee80211_sta_bss *bss)
2065 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2066 if (!atomic_dec_and_test(&bss->users))
2069 spin_lock_bh(&local->sta_bss_lock);
2070 __ieee80211_rx_bss_hash_del(dev, bss);
2071 list_del(&bss->list);
2072 spin_unlock_bh(&local->sta_bss_lock);
2073 ieee80211_rx_bss_free(bss);
2077 void ieee80211_rx_bss_list_init(struct net_device *dev)
2079 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2080 spin_lock_init(&local->sta_bss_lock);
2081 INIT_LIST_HEAD(&local->sta_bss_list);
2085 void ieee80211_rx_bss_list_deinit(struct net_device *dev)
2087 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2088 struct ieee80211_sta_bss *bss, *tmp;
2090 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
2091 ieee80211_rx_bss_put(dev, bss);
2095 static int ieee80211_sta_join_ibss(struct net_device *dev,
2096 struct ieee80211_if_sta *ifsta,
2097 struct ieee80211_sta_bss *bss)
2099 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2100 int res, rates, i, j;
2101 struct sk_buff *skb;
2102 struct ieee80211_mgmt *mgmt;
2103 struct ieee80211_tx_control control;
2104 struct rate_selection ratesel;
2106 struct ieee80211_sub_if_data *sdata;
2107 struct ieee80211_supported_band *sband;
2109 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2111 /* Remove possible STA entries from other IBSS networks. */
2112 sta_info_flush(local, NULL);
2114 if (local->ops->reset_tsf) {
2115 /* Reset own TSF to allow time synchronization work. */
2116 local->ops->reset_tsf(local_to_hw(local));
2118 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2119 res = ieee80211_if_config(dev);
2123 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2125 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2126 sdata->drop_unencrypted = bss->capability &
2127 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2129 res = ieee80211_set_freq(local, bss->freq);
2131 if (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS) {
2132 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
2133 "%d MHz\n", dev->name, local->oper_channel->center_freq);
2137 /* Set beacon template */
2138 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2143 skb_reserve(skb, local->hw.extra_tx_headroom);
2145 mgmt = (struct ieee80211_mgmt *)
2146 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2147 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2148 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2149 IEEE80211_STYPE_BEACON);
2150 memset(mgmt->da, 0xff, ETH_ALEN);
2151 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2152 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2153 mgmt->u.beacon.beacon_int =
2154 cpu_to_le16(local->hw.conf.beacon_int);
2155 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2157 pos = skb_put(skb, 2 + ifsta->ssid_len);
2158 *pos++ = WLAN_EID_SSID;
2159 *pos++ = ifsta->ssid_len;
2160 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2162 rates = bss->supp_rates_len;
2165 pos = skb_put(skb, 2 + rates);
2166 *pos++ = WLAN_EID_SUPP_RATES;
2168 memcpy(pos, bss->supp_rates, rates);
2170 if (bss->band == IEEE80211_BAND_2GHZ) {
2171 pos = skb_put(skb, 2 + 1);
2172 *pos++ = WLAN_EID_DS_PARAMS;
2174 *pos++ = ieee80211_frequency_to_channel(bss->freq);
2177 pos = skb_put(skb, 2 + 2);
2178 *pos++ = WLAN_EID_IBSS_PARAMS;
2180 /* FIX: set ATIM window based on scan results */
2184 if (bss->supp_rates_len > 8) {
2185 rates = bss->supp_rates_len - 8;
2186 pos = skb_put(skb, 2 + rates);
2187 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2189 memcpy(pos, &bss->supp_rates[8], rates);
2192 memset(&control, 0, sizeof(control));
2193 rate_control_get_rate(dev, sband, skb, &ratesel);
2194 if (!ratesel.rate) {
2195 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2196 "for IBSS beacon\n", dev->name);
2199 control.vif = &sdata->vif;
2200 control.tx_rate = ratesel.rate;
2201 if (sdata->bss_conf.use_short_preamble &&
2202 ratesel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2203 control.flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
2204 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2205 control.flags |= IEEE80211_TXCTL_NO_ACK;
2206 control.retry_limit = 1;
2208 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2209 if (ifsta->probe_resp) {
2210 mgmt = (struct ieee80211_mgmt *)
2211 ifsta->probe_resp->data;
2212 mgmt->frame_control =
2213 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2214 IEEE80211_STYPE_PROBE_RESP);
2216 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2217 "template for IBSS\n", dev->name);
2220 if (local->ops->beacon_update &&
2221 local->ops->beacon_update(local_to_hw(local),
2222 skb, &control) == 0) {
2223 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2224 "template\n", dev->name);
2229 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2230 for (i = 0; i < bss->supp_rates_len; i++) {
2231 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2232 for (j = 0; j < sband->n_bitrates; j++)
2233 if (sband->bitrates[j].bitrate == bitrate)
2236 ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
2240 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2241 "template\n", dev->name);
2245 ifsta->state = IEEE80211_IBSS_JOINED;
2246 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2248 ieee80211_rx_bss_put(dev, bss);
2253 u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
2254 struct ieee802_11_elems *elems,
2255 enum ieee80211_band band)
2257 struct ieee80211_supported_band *sband;
2258 struct ieee80211_rate *bitrates;
2262 sband = local->hw.wiphy->bands[band];
2266 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2269 bitrates = sband->bitrates;
2270 num_rates = sband->n_bitrates;
2272 for (i = 0; i < elems->supp_rates_len +
2273 elems->ext_supp_rates_len; i++) {
2276 if (i < elems->supp_rates_len)
2277 rate = elems->supp_rates[i];
2278 else if (elems->ext_supp_rates)
2279 rate = elems->ext_supp_rates
2280 [i - elems->supp_rates_len];
2281 own_rate = 5 * (rate & 0x7f);
2282 for (j = 0; j < num_rates; j++)
2283 if (bitrates[j].bitrate == own_rate)
2284 supp_rates |= BIT(j);
2290 static void ieee80211_rx_bss_info(struct net_device *dev,
2291 struct ieee80211_mgmt *mgmt,
2293 struct ieee80211_rx_status *rx_status,
2296 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2297 struct ieee802_11_elems elems;
2300 struct ieee80211_sta_bss *bss;
2301 struct sta_info *sta;
2302 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2303 u64 beacon_timestamp, rx_timestamp;
2304 DECLARE_MAC_BUF(mac);
2305 DECLARE_MAC_BUF(mac2);
2307 if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
2308 return; /* ignore ProbeResp to foreign address */
2311 printk(KERN_DEBUG "%s: RX %s from %s to %s\n",
2312 dev->name, beacon ? "Beacon" : "Probe Response",
2313 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da));
2316 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2320 beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
2321 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
2323 if (ieee80211_vif_is_mesh(&sdata->vif) && elems.mesh_id &&
2324 elems.mesh_config && mesh_matches_local(&elems, dev)) {
2325 u64 rates = ieee80211_sta_get_rates(local, &elems,
2328 mesh_neighbour_update(mgmt->sa, rates, dev,
2329 mesh_peer_accepts_plinks(&elems, dev));
2332 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
2333 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
2334 (sta = sta_info_get(local, mgmt->sa))) {
2336 u64 supp_rates = ieee80211_sta_get_rates(local, &elems,
2339 prev_rates = sta->supp_rates[rx_status->band];
2340 sta->supp_rates[rx_status->band] &= supp_rates;
2341 if (sta->supp_rates[rx_status->band] == 0) {
2342 /* No matching rates - this should not really happen.
2343 * Make sure that at least one rate is marked
2344 * supported to avoid issues with TX rate ctrl. */
2345 sta->supp_rates[rx_status->band] =
2346 sdata->u.sta.supp_rates_bits[rx_status->band];
2348 if (sta->supp_rates[rx_status->band] != prev_rates) {
2349 printk(KERN_DEBUG "%s: updated supp_rates set for "
2350 "%s based on beacon info (0x%llx & 0x%llx -> "
2352 dev->name, print_mac(mac, sta->addr),
2353 (unsigned long long) prev_rates,
2354 (unsigned long long) supp_rates,
2355 (unsigned long long) sta->supp_rates[rx_status->band]);
2360 if (elems.ds_params && elems.ds_params_len == 1)
2361 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
2363 freq = rx_status->freq;
2365 #ifdef CONFIG_MAC80211_MESH
2366 if (elems.mesh_config)
2367 bss = ieee80211_rx_mesh_bss_get(dev, elems.mesh_id,
2368 elems.mesh_id_len, elems.mesh_config, freq);
2371 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
2372 elems.ssid, elems.ssid_len);
2374 #ifdef CONFIG_MAC80211_MESH
2375 if (elems.mesh_config)
2376 bss = ieee80211_rx_mesh_bss_add(dev, elems.mesh_id,
2377 elems.mesh_id_len, elems.mesh_config, freq);
2380 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
2381 elems.ssid, elems.ssid_len);
2386 /* TODO: order by RSSI? */
2387 spin_lock_bh(&local->sta_bss_lock);
2388 list_move_tail(&bss->list, &local->sta_bss_list);
2389 spin_unlock_bh(&local->sta_bss_lock);
2393 bss->band = rx_status->band;
2395 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
2396 bss->probe_resp && beacon) {
2398 * Do not allow beacon to override data from Probe Response. */
2399 ieee80211_rx_bss_put(dev, bss);
2403 /* save the ERP value so that it is available at association time */
2404 if (elems.erp_info && elems.erp_info_len >= 1) {
2405 bss->erp_value = elems.erp_info[0];
2406 bss->has_erp_value = 1;
2409 bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
2410 bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
2412 bss->supp_rates_len = 0;
2413 if (elems.supp_rates) {
2414 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2415 if (clen > elems.supp_rates_len)
2416 clen = elems.supp_rates_len;
2417 memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
2419 bss->supp_rates_len += clen;
2421 if (elems.ext_supp_rates) {
2422 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
2423 if (clen > elems.ext_supp_rates_len)
2424 clen = elems.ext_supp_rates_len;
2425 memcpy(&bss->supp_rates[bss->supp_rates_len],
2426 elems.ext_supp_rates, clen);
2427 bss->supp_rates_len += clen;
2431 (!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len ||
2432 memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
2434 bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
2436 memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
2437 bss->wpa_ie_len = elems.wpa_len + 2;
2439 bss->wpa_ie_len = 0;
2440 } else if (!elems.wpa && bss->wpa_ie) {
2443 bss->wpa_ie_len = 0;
2447 (!bss->rsn_ie || bss->rsn_ie_len != elems.rsn_len ||
2448 memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
2450 bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
2452 memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
2453 bss->rsn_ie_len = elems.rsn_len + 2;
2455 bss->rsn_ie_len = 0;
2456 } else if (!elems.rsn && bss->rsn_ie) {
2459 bss->rsn_ie_len = 0;
2462 if (elems.wmm_param &&
2463 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len ||
2464 memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
2466 bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
2468 memcpy(bss->wmm_ie, elems.wmm_param - 2,
2469 elems.wmm_param_len + 2);
2470 bss->wmm_ie_len = elems.wmm_param_len + 2;
2472 bss->wmm_ie_len = 0;
2473 } else if (!elems.wmm_param && bss->wmm_ie) {
2476 bss->wmm_ie_len = 0;
2478 if (elems.ht_cap_elem &&
2479 (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
2480 memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
2482 bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
2484 memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
2485 elems.ht_cap_elem_len + 2);
2486 bss->ht_ie_len = elems.ht_cap_elem_len + 2;
2489 } else if (!elems.ht_cap_elem && bss->ht_ie) {
2495 bss->timestamp = beacon_timestamp;
2496 bss->last_update = jiffies;
2497 bss->rssi = rx_status->ssi;
2498 bss->signal = rx_status->signal;
2499 bss->noise = rx_status->noise;
2503 /* check if we need to merge IBSS */
2504 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
2505 !local->sta_sw_scanning && !local->sta_hw_scanning &&
2506 bss->capability & WLAN_CAPABILITY_IBSS &&
2507 bss->freq == local->oper_channel->center_freq &&
2508 elems.ssid_len == sdata->u.sta.ssid_len &&
2509 memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) == 0) {
2510 if (rx_status->flag & RX_FLAG_TSFT) {
2511 /* in order for correct IBSS merging we need mactime
2513 * since mactime is defined as the time the first data
2514 * symbol of the frame hits the PHY, and the timestamp
2515 * of the beacon is defined as "the time that the data
2516 * symbol containing the first bit of the timestamp is
2517 * transmitted to the PHY plus the transmitting STA’s
2518 * delays through its local PHY from the MAC-PHY
2519 * interface to its interface with the WM"
2520 * (802.11 11.1.2) - equals the time this bit arrives at
2521 * the receiver - we have to take into account the
2522 * offset between the two.
2523 * e.g: at 1 MBit that means mactime is 192 usec earlier
2524 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2526 int rate = local->hw.wiphy->bands[rx_status->band]->
2527 bitrates[rx_status->rate_idx].bitrate;
2528 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
2529 } else if (local && local->ops && local->ops->get_tsf)
2530 /* second best option: get current TSF */
2531 rx_timestamp = local->ops->get_tsf(local_to_hw(local));
2533 /* can't merge without knowing the TSF */
2534 rx_timestamp = -1LLU;
2535 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2536 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
2537 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2538 print_mac(mac, mgmt->sa),
2539 print_mac(mac2, mgmt->bssid),
2540 (unsigned long long)rx_timestamp,
2541 (unsigned long long)beacon_timestamp,
2542 (unsigned long long)(rx_timestamp - beacon_timestamp),
2544 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2545 if (beacon_timestamp > rx_timestamp) {
2546 #ifndef CONFIG_MAC80211_IBSS_DEBUG
2547 if (net_ratelimit())
2549 printk(KERN_DEBUG "%s: beacon TSF higher than "
2550 "local TSF - IBSS merge with BSSID %s\n",
2551 dev->name, print_mac(mac, mgmt->bssid));
2552 ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
2553 ieee80211_ibss_add_sta(dev, NULL,
2554 mgmt->bssid, mgmt->sa);
2558 ieee80211_rx_bss_put(dev, bss);
2562 static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
2563 struct ieee80211_mgmt *mgmt,
2565 struct ieee80211_rx_status *rx_status)
2567 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
2571 static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
2572 struct ieee80211_mgmt *mgmt,
2574 struct ieee80211_rx_status *rx_status)
2576 struct ieee80211_sub_if_data *sdata;
2577 struct ieee80211_if_sta *ifsta;
2579 struct ieee802_11_elems elems;
2580 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2581 struct ieee80211_conf *conf = &local->hw.conf;
2584 ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
2586 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2587 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
2589 ifsta = &sdata->u.sta;
2591 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
2592 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
2595 /* Process beacon from the current BSS */
2596 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
2600 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
2602 if (elems.erp_info && elems.erp_info_len >= 1)
2603 changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
2605 if (elems.ht_cap_elem && elems.ht_info_elem &&
2606 elems.wmm_param && local->ops->conf_ht &&
2607 conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
2608 struct ieee80211_ht_bss_info bss_info;
2610 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2611 (struct ieee80211_ht_addt_info *)
2612 elems.ht_info_elem, &bss_info);
2613 /* check if AP changed bss inforamation */
2614 if ((conf->ht_bss_conf.primary_channel !=
2615 bss_info.primary_channel) ||
2616 (conf->ht_bss_conf.bss_cap != bss_info.bss_cap) ||
2617 (conf->ht_bss_conf.bss_op_mode != bss_info.bss_op_mode))
2618 ieee80211_hw_config_ht(local, 1, &conf->ht_conf,
2622 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
2623 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
2624 elems.wmm_param_len);
2627 ieee80211_bss_info_change_notify(sdata, changed);
2631 static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
2632 struct ieee80211_if_sta *ifsta,
2633 struct ieee80211_mgmt *mgmt,
2635 struct ieee80211_rx_status *rx_status)
2637 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2638 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2640 struct sk_buff *skb;
2641 struct ieee80211_mgmt *resp;
2643 DECLARE_MAC_BUF(mac);
2644 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2645 DECLARE_MAC_BUF(mac2);
2646 DECLARE_MAC_BUF(mac3);
2649 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
2650 ifsta->state != IEEE80211_IBSS_JOINED ||
2651 len < 24 + 2 || !ifsta->probe_resp)
2654 if (local->ops->tx_last_beacon)
2655 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
2659 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2660 printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
2661 "%s (tx_last_beacon=%d)\n",
2662 dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
2663 print_mac(mac3, mgmt->bssid), tx_last_beacon);
2664 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2666 if (!tx_last_beacon)
2669 if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
2670 memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
2673 end = ((u8 *) mgmt) + len;
2674 pos = mgmt->u.probe_req.variable;
2675 if (pos[0] != WLAN_EID_SSID ||
2676 pos + 2 + pos[1] > end) {
2677 if (net_ratelimit()) {
2678 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
2680 dev->name, print_mac(mac, mgmt->sa));
2685 (pos[1] != ifsta->ssid_len ||
2686 memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
2687 /* Ignore ProbeReq for foreign SSID */
2691 /* Reply with ProbeResp */
2692 skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
2696 resp = (struct ieee80211_mgmt *) skb->data;
2697 memcpy(resp->da, mgmt->sa, ETH_ALEN);
2698 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2699 printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
2700 dev->name, print_mac(mac, resp->da));
2701 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2702 ieee80211_sta_tx(dev, skb, 0);
2705 static void ieee80211_rx_mgmt_action(struct net_device *dev,
2706 struct ieee80211_if_sta *ifsta,
2707 struct ieee80211_mgmt *mgmt,
2709 struct ieee80211_rx_status *rx_status)
2711 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2713 if (len < IEEE80211_MIN_ACTION_SIZE)
2716 switch (mgmt->u.action.category) {
2717 case WLAN_CATEGORY_BACK:
2718 switch (mgmt->u.action.u.addba_req.action_code) {
2719 case WLAN_ACTION_ADDBA_REQ:
2720 if (len < (IEEE80211_MIN_ACTION_SIZE +
2721 sizeof(mgmt->u.action.u.addba_req)))
2723 ieee80211_sta_process_addba_request(dev, mgmt, len);
2725 case WLAN_ACTION_ADDBA_RESP:
2726 if (len < (IEEE80211_MIN_ACTION_SIZE +
2727 sizeof(mgmt->u.action.u.addba_resp)))
2729 ieee80211_sta_process_addba_resp(dev, mgmt, len);
2731 case WLAN_ACTION_DELBA:
2732 if (len < (IEEE80211_MIN_ACTION_SIZE +
2733 sizeof(mgmt->u.action.u.delba)))
2735 ieee80211_sta_process_delba(dev, mgmt, len);
2738 if (net_ratelimit())
2739 printk(KERN_DEBUG "%s: Rx unknown A-MPDU action\n",
2744 case PLINK_CATEGORY:
2745 if (ieee80211_vif_is_mesh(&sdata->vif))
2746 mesh_rx_plink_frame(dev, mgmt, len, rx_status);
2748 case MESH_PATH_SEL_CATEGORY:
2749 if (ieee80211_vif_is_mesh(&sdata->vif))
2750 mesh_rx_path_sel_frame(dev, mgmt, len);
2753 if (net_ratelimit())
2754 printk(KERN_DEBUG "%s: Rx unknown action frame - "
2755 "category=%d\n", dev->name, mgmt->u.action.category);
2760 void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
2761 struct ieee80211_rx_status *rx_status)
2763 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2764 struct ieee80211_sub_if_data *sdata;
2765 struct ieee80211_if_sta *ifsta;
2766 struct ieee80211_mgmt *mgmt;
2772 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2773 ifsta = &sdata->u.sta;
2775 mgmt = (struct ieee80211_mgmt *) skb->data;
2776 fc = le16_to_cpu(mgmt->frame_control);
2778 switch (fc & IEEE80211_FCTL_STYPE) {
2779 case IEEE80211_STYPE_PROBE_REQ:
2780 case IEEE80211_STYPE_PROBE_RESP:
2781 case IEEE80211_STYPE_BEACON:
2782 case IEEE80211_STYPE_ACTION:
2783 memcpy(skb->cb, rx_status, sizeof(*rx_status));
2784 case IEEE80211_STYPE_AUTH:
2785 case IEEE80211_STYPE_ASSOC_RESP:
2786 case IEEE80211_STYPE_REASSOC_RESP:
2787 case IEEE80211_STYPE_DEAUTH:
2788 case IEEE80211_STYPE_DISASSOC:
2789 skb_queue_tail(&ifsta->skb_queue, skb);
2790 queue_work(local->hw.workqueue, &ifsta->work);
2793 printk(KERN_DEBUG "%s: received unknown management frame - "
2794 "stype=%d\n", dev->name,
2795 (fc & IEEE80211_FCTL_STYPE) >> 4);
2804 static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
2805 struct sk_buff *skb)
2807 struct ieee80211_rx_status *rx_status;
2808 struct ieee80211_sub_if_data *sdata;
2809 struct ieee80211_if_sta *ifsta;
2810 struct ieee80211_mgmt *mgmt;
2813 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2814 ifsta = &sdata->u.sta;
2816 rx_status = (struct ieee80211_rx_status *) skb->cb;
2817 mgmt = (struct ieee80211_mgmt *) skb->data;
2818 fc = le16_to_cpu(mgmt->frame_control);
2820 switch (fc & IEEE80211_FCTL_STYPE) {
2821 case IEEE80211_STYPE_PROBE_REQ:
2822 ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
2825 case IEEE80211_STYPE_PROBE_RESP:
2826 ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
2828 case IEEE80211_STYPE_BEACON:
2829 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
2831 case IEEE80211_STYPE_AUTH:
2832 ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len);
2834 case IEEE80211_STYPE_ASSOC_RESP:
2835 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
2837 case IEEE80211_STYPE_REASSOC_RESP:
2838 ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
2840 case IEEE80211_STYPE_DEAUTH:
2841 ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len);
2843 case IEEE80211_STYPE_DISASSOC:
2844 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
2846 case IEEE80211_STYPE_ACTION:
2847 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len, rx_status);
2856 ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
2857 struct ieee80211_rx_status *rx_status)
2859 struct ieee80211_mgmt *mgmt;
2863 return RX_DROP_UNUSABLE;
2865 mgmt = (struct ieee80211_mgmt *) skb->data;
2866 fc = le16_to_cpu(mgmt->frame_control);
2868 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
2872 return RX_DROP_MONITOR;
2874 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2875 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
2876 ieee80211_rx_mgmt_probe_resp(dev, mgmt,
2877 skb->len, rx_status);
2880 } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
2881 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
2891 static int ieee80211_sta_active_ibss(struct net_device *dev)
2893 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2895 struct sta_info *sta;
2897 read_lock_bh(&local->sta_lock);
2898 list_for_each_entry(sta, &local->sta_list, list) {
2899 if (sta->dev == dev &&
2900 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
2906 read_unlock_bh(&local->sta_lock);
2912 static void ieee80211_sta_expire(struct net_device *dev, unsigned long exp_time)
2914 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2915 struct sta_info *sta, *tmp;
2916 LIST_HEAD(tmp_list);
2917 DECLARE_MAC_BUF(mac);
2919 write_lock_bh(&local->sta_lock);
2920 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
2921 if (time_after(jiffies, sta->last_rx + exp_time)) {
2922 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
2923 dev->name, print_mac(mac, sta->addr));
2924 __sta_info_get(sta);
2925 sta_info_remove(sta);
2926 list_add(&sta->list, &tmp_list);
2928 write_unlock_bh(&local->sta_lock);
2930 list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
2937 static void ieee80211_sta_merge_ibss(struct net_device *dev,
2938 struct ieee80211_if_sta *ifsta)
2940 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2942 ieee80211_sta_expire(dev, IEEE80211_IBSS_INACTIVITY_LIMIT);
2943 if (ieee80211_sta_active_ibss(dev))
2946 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
2947 "IBSS networks with same SSID (merge)\n", dev->name);
2948 ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
2952 #ifdef CONFIG_MAC80211_MESH
2953 static void ieee80211_mesh_housekeeping(struct net_device *dev,
2954 struct ieee80211_if_sta *ifsta)
2956 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2959 ieee80211_sta_expire(dev, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
2960 mesh_path_expire(dev);
2962 free_plinks = mesh_plink_availables(sdata);
2963 if (free_plinks != sdata->u.sta.accepting_plinks)
2964 ieee80211_if_config_beacon(dev);
2966 mod_timer(&ifsta->timer, jiffies +
2967 IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
2971 void ieee80211_start_mesh(struct net_device *dev)
2973 struct ieee80211_if_sta *ifsta;
2974 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2975 ifsta = &sdata->u.sta;
2976 ifsta->state = IEEE80211_MESH_UP;
2977 ieee80211_sta_timer((unsigned long)sdata);
2982 void ieee80211_sta_timer(unsigned long data)
2984 struct ieee80211_sub_if_data *sdata =
2985 (struct ieee80211_sub_if_data *) data;
2986 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2987 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
2989 set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
2990 queue_work(local->hw.workqueue, &ifsta->work);
2993 void ieee80211_sta_work(struct work_struct *work)
2995 struct ieee80211_sub_if_data *sdata =
2996 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
2997 struct net_device *dev = sdata->dev;
2998 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2999 struct ieee80211_if_sta *ifsta;
3000 struct sk_buff *skb;
3002 if (!netif_running(dev))
3005 if (local->sta_sw_scanning || local->sta_hw_scanning)
3008 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
3009 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
3010 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) {
3011 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
3012 "(type=%d)\n", dev->name, sdata->vif.type);
3015 ifsta = &sdata->u.sta;
3017 while ((skb = skb_dequeue(&ifsta->skb_queue)))
3018 ieee80211_sta_rx_queued_mgmt(dev, skb);
3020 #ifdef CONFIG_MAC80211_MESH
3021 if (ifsta->preq_queue_len &&
3023 ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
3024 mesh_path_start_discovery(dev);
3027 if (ifsta->state != IEEE80211_AUTHENTICATE &&
3028 ifsta->state != IEEE80211_ASSOCIATE &&
3029 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
3030 if (ifsta->scan_ssid_len)
3031 ieee80211_sta_start_scan(dev, ifsta->scan_ssid, ifsta->scan_ssid_len);
3033 ieee80211_sta_start_scan(dev, NULL, 0);
3037 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
3038 if (ieee80211_sta_config_auth(dev, ifsta))
3040 clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
3041 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
3044 switch (ifsta->state) {
3045 case IEEE80211_DISABLED:
3047 case IEEE80211_AUTHENTICATE:
3048 ieee80211_authenticate(dev, ifsta);
3050 case IEEE80211_ASSOCIATE:
3051 ieee80211_associate(dev, ifsta);
3053 case IEEE80211_ASSOCIATED:
3054 ieee80211_associated(dev, ifsta);
3056 case IEEE80211_IBSS_SEARCH:
3057 ieee80211_sta_find_ibss(dev, ifsta);
3059 case IEEE80211_IBSS_JOINED:
3060 ieee80211_sta_merge_ibss(dev, ifsta);
3062 #ifdef CONFIG_MAC80211_MESH
3063 case IEEE80211_MESH_UP:
3064 ieee80211_mesh_housekeeping(dev, ifsta);
3068 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
3073 if (ieee80211_privacy_mismatch(dev, ifsta)) {
3074 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
3075 "mixed-cell disabled - disassociate\n", dev->name);
3077 ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
3078 ieee80211_set_disassoc(dev, ifsta, 0);
3083 static void ieee80211_sta_reset_auth(struct net_device *dev,
3084 struct ieee80211_if_sta *ifsta)
3086 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3088 if (local->ops->reset_tsf) {
3089 /* Reset own TSF to allow time synchronization work. */
3090 local->ops->reset_tsf(local_to_hw(local));
3093 ifsta->wmm_last_param_set = -1; /* allow any WMM update */
3096 if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
3097 ifsta->auth_alg = WLAN_AUTH_OPEN;
3098 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
3099 ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
3100 else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
3101 ifsta->auth_alg = WLAN_AUTH_LEAP;
3103 ifsta->auth_alg = WLAN_AUTH_OPEN;
3104 printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
3106 ifsta->auth_transaction = -1;
3107 ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
3108 ifsta->auth_tries = ifsta->assoc_tries = 0;
3109 netif_carrier_off(dev);
3113 void ieee80211_sta_req_auth(struct net_device *dev,
3114 struct ieee80211_if_sta *ifsta)
3116 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3117 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3119 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
3122 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
3123 IEEE80211_STA_AUTO_BSSID_SEL)) &&
3124 (ifsta->flags & (IEEE80211_STA_SSID_SET |
3125 IEEE80211_STA_AUTO_SSID_SEL))) {
3126 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3127 queue_work(local->hw.workqueue, &ifsta->work);
3131 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
3132 const char *ssid, int ssid_len)
3134 int tmp, hidden_ssid;
3136 if (ssid_len == ifsta->ssid_len &&
3137 !memcmp(ifsta->ssid, ssid, ssid_len))
3140 if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
3146 if (ssid[tmp] != '\0') {
3152 if (hidden_ssid && ifsta->ssid_len == ssid_len)
3155 if (ssid_len == 1 && ssid[0] == ' ')
3161 static int ieee80211_sta_config_auth(struct net_device *dev,
3162 struct ieee80211_if_sta *ifsta)
3164 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3165 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3166 struct ieee80211_sta_bss *bss, *selected = NULL;
3167 int top_rssi = 0, freq;
3169 if (!(ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
3170 IEEE80211_STA_AUTO_BSSID_SEL | IEEE80211_STA_AUTO_CHANNEL_SEL))) {
3171 ifsta->state = IEEE80211_AUTHENTICATE;
3172 ieee80211_sta_reset_auth(dev, ifsta);
3176 spin_lock_bh(&local->sta_bss_lock);
3177 freq = local->oper_channel->center_freq;
3178 list_for_each_entry(bss, &local->sta_bss_list, list) {
3179 if (!(bss->capability & WLAN_CAPABILITY_ESS))
3182 if (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
3183 !!sdata->default_key)
3186 if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
3190 if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
3191 memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
3194 if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
3195 !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
3198 if (!selected || top_rssi < bss->rssi) {
3200 top_rssi = bss->rssi;
3204 atomic_inc(&selected->users);
3205 spin_unlock_bh(&local->sta_bss_lock);
3208 ieee80211_set_freq(local, selected->freq);
3209 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
3210 ieee80211_sta_set_ssid(dev, selected->ssid,
3211 selected->ssid_len);
3212 ieee80211_sta_set_bssid(dev, selected->bssid);
3213 ieee80211_rx_bss_put(dev, selected);
3214 ifsta->state = IEEE80211_AUTHENTICATE;
3215 ieee80211_sta_reset_auth(dev, ifsta);
3218 if (ifsta->state != IEEE80211_AUTHENTICATE) {
3219 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
3220 ieee80211_sta_start_scan(dev, NULL, 0);
3222 ieee80211_sta_start_scan(dev, ifsta->ssid,
3224 ifsta->state = IEEE80211_AUTHENTICATE;
3225 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
3227 ifsta->state = IEEE80211_DISABLED;
3233 static int ieee80211_sta_create_ibss(struct net_device *dev,
3234 struct ieee80211_if_sta *ifsta)
3236 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3237 struct ieee80211_sta_bss *bss;
3238 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3239 struct ieee80211_supported_band *sband;
3240 u8 bssid[ETH_ALEN], *pos;
3242 DECLARE_MAC_BUF(mac);
3245 /* Easier testing, use fixed BSSID. */
3246 memset(bssid, 0xfe, ETH_ALEN);
3248 /* Generate random, not broadcast, locally administered BSSID. Mix in
3249 * own MAC address to make sure that devices that do not have proper
3250 * random number generator get different BSSID. */
3251 get_random_bytes(bssid, ETH_ALEN);
3252 for (i = 0; i < ETH_ALEN; i++)
3253 bssid[i] ^= dev->dev_addr[i];
3258 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
3259 dev->name, print_mac(mac, bssid));
3261 bss = ieee80211_rx_bss_add(dev, bssid,
3262 local->hw.conf.channel->center_freq,
3263 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
3267 bss->band = local->hw.conf.channel->band;
3268 sband = local->hw.wiphy->bands[bss->band];
3270 if (local->hw.conf.beacon_int == 0)
3271 local->hw.conf.beacon_int = 10000;
3272 bss->beacon_int = local->hw.conf.beacon_int;
3273 bss->last_update = jiffies;
3274 bss->capability = WLAN_CAPABILITY_IBSS;
3275 if (sdata->default_key) {
3276 bss->capability |= WLAN_CAPABILITY_PRIVACY;
3278 sdata->drop_unencrypted = 0;
3279 bss->supp_rates_len = sband->n_bitrates;
3280 pos = bss->supp_rates;
3281 for (i = 0; i < sband->n_bitrates; i++) {
3282 int rate = sband->bitrates[i].bitrate;
3283 *pos++ = (u8) (rate / 5);
3286 return ieee80211_sta_join_ibss(dev, ifsta, bss);
3290 static int ieee80211_sta_find_ibss(struct net_device *dev,
3291 struct ieee80211_if_sta *ifsta)
3293 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3294 struct ieee80211_sta_bss *bss;
3298 DECLARE_MAC_BUF(mac);
3299 DECLARE_MAC_BUF(mac2);
3301 if (ifsta->ssid_len == 0)
3304 active_ibss = ieee80211_sta_active_ibss(dev);
3305 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3306 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
3307 dev->name, active_ibss);
3308 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3309 spin_lock_bh(&local->sta_bss_lock);
3310 list_for_each_entry(bss, &local->sta_bss_list, list) {
3311 if (ifsta->ssid_len != bss->ssid_len ||
3312 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
3313 || !(bss->capability & WLAN_CAPABILITY_IBSS))
3315 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3316 printk(KERN_DEBUG " bssid=%s found\n",
3317 print_mac(mac, bss->bssid));
3318 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3319 memcpy(bssid, bss->bssid, ETH_ALEN);
3321 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
3324 spin_unlock_bh(&local->sta_bss_lock);
3326 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3327 printk(KERN_DEBUG " sta_find_ibss: selected %s current "
3328 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
3329 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3330 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
3331 (bss = ieee80211_rx_bss_get(dev, bssid,
3332 local->hw.conf.channel->center_freq,
3333 ifsta->ssid, ifsta->ssid_len))) {
3334 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
3335 " based on configured SSID\n",
3336 dev->name, print_mac(mac, bssid));
3337 return ieee80211_sta_join_ibss(dev, ifsta, bss);
3339 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3340 printk(KERN_DEBUG " did not try to join ibss\n");
3341 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3343 /* Selected IBSS not found in current scan results - try to scan */
3344 if (ifsta->state == IEEE80211_IBSS_JOINED &&
3345 !ieee80211_sta_active_ibss(dev)) {
3346 mod_timer(&ifsta->timer, jiffies +
3347 IEEE80211_IBSS_MERGE_INTERVAL);
3348 } else if (time_after(jiffies, local->last_scan_completed +
3349 IEEE80211_SCAN_INTERVAL)) {
3350 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
3351 "join\n", dev->name);
3352 return ieee80211_sta_req_scan(dev, ifsta->ssid,
3354 } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
3355 int interval = IEEE80211_SCAN_INTERVAL;
3357 if (time_after(jiffies, ifsta->ibss_join_req +
3358 IEEE80211_IBSS_JOIN_TIMEOUT)) {
3359 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
3360 (!(local->oper_channel->flags &
3361 IEEE80211_CHAN_NO_IBSS)))
3362 return ieee80211_sta_create_ibss(dev, ifsta);
3363 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
3364 printk(KERN_DEBUG "%s: IBSS not allowed on"
3365 " %d MHz\n", dev->name,
3366 local->hw.conf.channel->center_freq);
3369 /* No IBSS found - decrease scan interval and continue
3371 interval = IEEE80211_SCAN_INTERVAL_SLOW;
3374 ifsta->state = IEEE80211_IBSS_SEARCH;
3375 mod_timer(&ifsta->timer, jiffies + interval);
3383 int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3385 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3386 struct ieee80211_if_sta *ifsta;
3387 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3389 if (len > IEEE80211_MAX_SSID_LEN)
3392 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
3394 if (local->ops->conf_tx) {
3395 struct ieee80211_tx_queue_params qparam;
3398 memset(&qparam, 0, sizeof(qparam));
3402 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
3403 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
3408 qparam.cw_max = 1023;
3411 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
3412 local->ops->conf_tx(local_to_hw(local),
3413 i + IEEE80211_TX_QUEUE_DATA0,
3416 /* IBSS uses different parameters for Beacon sending */
3420 local->ops->conf_tx(local_to_hw(local),
3421 IEEE80211_TX_QUEUE_BEACON, &qparam);
3424 ifsta = &sdata->u.sta;
3426 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
3427 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
3428 memcpy(ifsta->ssid, ssid, len);
3429 memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
3430 ifsta->ssid_len = len;
3433 ifsta->flags |= IEEE80211_STA_SSID_SET;
3435 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
3436 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3437 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
3438 ifsta->ibss_join_req = jiffies;
3439 ifsta->state = IEEE80211_IBSS_SEARCH;
3440 return ieee80211_sta_find_ibss(dev, ifsta);
3446 int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
3448 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3449 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3450 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
3451 *len = ifsta->ssid_len;
3456 int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
3458 struct ieee80211_sub_if_data *sdata;
3459 struct ieee80211_if_sta *ifsta;
3462 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3463 ifsta = &sdata->u.sta;
3465 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
3466 memcpy(ifsta->bssid, bssid, ETH_ALEN);
3467 res = ieee80211_if_config(dev);
3469 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
3470 "the low-level driver\n", dev->name);
3475 if (is_valid_ether_addr(bssid))
3476 ifsta->flags |= IEEE80211_STA_BSSID_SET;
3478 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
3484 static void ieee80211_send_nullfunc(struct ieee80211_local *local,
3485 struct ieee80211_sub_if_data *sdata,
3488 struct sk_buff *skb;
3489 struct ieee80211_hdr *nullfunc;
3492 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
3494 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
3495 "frame\n", sdata->dev->name);
3498 skb_reserve(skb, local->hw.extra_tx_headroom);
3500 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
3501 memset(nullfunc, 0, 24);
3502 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
3503 IEEE80211_FCTL_TODS;
3505 fc |= IEEE80211_FCTL_PM;
3506 nullfunc->frame_control = cpu_to_le16(fc);
3507 memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN);
3508 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
3509 memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN);
3511 ieee80211_sta_tx(sdata->dev, skb, 0);
3515 void ieee80211_scan_completed(struct ieee80211_hw *hw)
3517 struct ieee80211_local *local = hw_to_local(hw);
3518 struct net_device *dev = local->scan_dev;
3519 struct ieee80211_sub_if_data *sdata;
3520 union iwreq_data wrqu;
3522 local->last_scan_completed = jiffies;
3523 memset(&wrqu, 0, sizeof(wrqu));
3524 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
3526 if (local->sta_hw_scanning) {
3527 local->sta_hw_scanning = 0;
3531 local->sta_sw_scanning = 0;
3532 if (ieee80211_hw_config(local))
3533 printk(KERN_DEBUG "%s: failed to restore operational "
3534 "channel after scan\n", dev->name);
3537 netif_tx_lock_bh(local->mdev);
3538 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
3539 local->ops->configure_filter(local_to_hw(local),
3540 FIF_BCN_PRBRESP_PROMISC,
3541 &local->filter_flags,
3542 local->mdev->mc_count,
3543 local->mdev->mc_list);
3545 netif_tx_unlock_bh(local->mdev);
3548 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3550 /* No need to wake the master device. */
3551 if (sdata->dev == local->mdev)
3554 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
3555 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
3556 ieee80211_send_nullfunc(local, sdata, 0);
3557 ieee80211_sta_timer((unsigned long)sdata);
3560 if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
3561 ieee80211_sta_timer((unsigned long)sdata);
3563 netif_wake_queue(sdata->dev);
3568 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3569 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
3570 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3571 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
3572 (!ifsta->state == IEEE80211_IBSS_JOINED &&
3573 !ieee80211_sta_active_ibss(dev)))
3574 ieee80211_sta_find_ibss(dev, ifsta);
3577 EXPORT_SYMBOL(ieee80211_scan_completed);
3579 void ieee80211_sta_scan_work(struct work_struct *work)
3581 struct ieee80211_local *local =
3582 container_of(work, struct ieee80211_local, scan_work.work);
3583 struct net_device *dev = local->scan_dev;
3584 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3585 struct ieee80211_supported_band *sband;
3586 struct ieee80211_channel *chan;
3588 unsigned long next_delay = 0;
3590 if (!local->sta_sw_scanning)
3593 switch (local->scan_state) {
3594 case SCAN_SET_CHANNEL:
3596 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3597 * after we successfully scanned the last channel of the last
3598 * band (and the last band is supported by the hw)
3600 if (local->scan_band < IEEE80211_NUM_BANDS)
3601 sband = local->hw.wiphy->bands[local->scan_band];
3606 * If we are at an unsupported band and have more bands
3607 * left to scan, advance to the next supported one.
3609 while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
3611 sband = local->hw.wiphy->bands[local->scan_band];
3612 local->scan_channel_idx = 0;
3615 /* if no more bands/channels left, complete scan */
3616 if (!sband || local->scan_channel_idx >= sband->n_channels) {
3617 ieee80211_scan_completed(local_to_hw(local));
3621 chan = &sband->channels[local->scan_channel_idx];
3623 if (chan->flags & IEEE80211_CHAN_DISABLED ||
3624 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3625 chan->flags & IEEE80211_CHAN_NO_IBSS))
3629 local->scan_channel = chan;
3630 if (ieee80211_hw_config(local)) {
3631 printk(KERN_DEBUG "%s: failed to set freq to "
3632 "%d MHz for scan\n", dev->name,
3638 /* advance state machine to next channel/band */
3639 local->scan_channel_idx++;
3640 if (local->scan_channel_idx >= sband->n_channels) {
3642 * scan_band may end up == IEEE80211_NUM_BANDS, but
3643 * we'll catch that case above and complete the scan
3644 * if that is the case.
3647 local->scan_channel_idx = 0;
3653 next_delay = IEEE80211_PROBE_DELAY +
3654 usecs_to_jiffies(local->hw.channel_change_time);
3655 local->scan_state = SCAN_SEND_PROBE;
3657 case SCAN_SEND_PROBE:
3658 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3659 local->scan_state = SCAN_SET_CHANNEL;
3661 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
3663 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3664 local->scan_ssid_len);
3665 next_delay = IEEE80211_CHANNEL_TIME;
3669 if (local->sta_sw_scanning)
3670 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3675 static int ieee80211_sta_start_scan(struct net_device *dev,
3676 u8 *ssid, size_t ssid_len)
3678 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3679 struct ieee80211_sub_if_data *sdata;
3681 if (ssid_len > IEEE80211_MAX_SSID_LEN)
3684 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3685 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3688 * ScanType: ACTIVE, PASSIVE
3689 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3690 * a Probe frame during active scanning
3692 * MinChannelTime (>= ProbeDelay), in TU
3693 * MaxChannelTime: (>= MinChannelTime), in TU
3696 /* MLME-SCAN.confirm
3698 * ResultCode: SUCCESS, INVALID_PARAMETERS
3701 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3702 if (local->scan_dev == dev)
3707 if (local->ops->hw_scan) {
3708 int rc = local->ops->hw_scan(local_to_hw(local),
3711 local->sta_hw_scanning = 1;
3712 local->scan_dev = dev;
3717 local->sta_sw_scanning = 1;
3720 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3722 /* Don't stop the master interface, otherwise we can't transmit
3724 if (sdata->dev == local->mdev)
3727 netif_stop_queue(sdata->dev);
3728 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3729 (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED))
3730 ieee80211_send_nullfunc(local, sdata, 1);
3735 local->scan_ssid_len = ssid_len;
3736 memcpy(local->scan_ssid, ssid, ssid_len);
3738 local->scan_ssid_len = 0;
3739 local->scan_state = SCAN_SET_CHANNEL;
3740 local->scan_channel_idx = 0;
3741 local->scan_band = IEEE80211_BAND_2GHZ;
3742 local->scan_dev = dev;
3744 netif_tx_lock_bh(local->mdev);
3745 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
3746 local->ops->configure_filter(local_to_hw(local),
3747 FIF_BCN_PRBRESP_PROMISC,
3748 &local->filter_flags,
3749 local->mdev->mc_count,
3750 local->mdev->mc_list);
3751 netif_tx_unlock_bh(local->mdev);
3753 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3754 queue_delayed_work(local->hw.workqueue, &local->scan_work,
3755 IEEE80211_CHANNEL_TIME);
3761 int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
3763 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3764 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3765 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3767 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
3768 return ieee80211_sta_start_scan(dev, ssid, ssid_len);
3770 if (local->sta_sw_scanning || local->sta_hw_scanning) {
3771 if (local->scan_dev == dev)
3776 ifsta->scan_ssid_len = ssid_len;
3778 memcpy(ifsta->scan_ssid, ssid, ssid_len);
3779 set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request);
3780 queue_work(local->hw.workqueue, &ifsta->work);
3785 ieee80211_sta_scan_result(struct net_device *dev,
3786 struct ieee80211_sta_bss *bss,
3787 char *current_ev, char *end_buf)
3789 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3790 struct iw_event iwe;
3792 if (time_after(jiffies,
3793 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
3796 memset(&iwe, 0, sizeof(iwe));
3797 iwe.cmd = SIOCGIWAP;
3798 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
3799 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
3800 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3803 memset(&iwe, 0, sizeof(iwe));
3804 iwe.cmd = SIOCGIWESSID;
3805 if (bss_mesh_cfg(bss)) {
3806 iwe.u.data.length = bss_mesh_id_len(bss);
3807 iwe.u.data.flags = 1;
3808 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3811 iwe.u.data.length = bss->ssid_len;
3812 iwe.u.data.flags = 1;
3813 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3817 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS
3818 || bss_mesh_cfg(bss))) {
3819 memset(&iwe, 0, sizeof(iwe));
3820 iwe.cmd = SIOCGIWMODE;
3821 if (bss_mesh_cfg(bss))
3822 iwe.u.mode = IW_MODE_MESH;
3823 else if (bss->capability & WLAN_CAPABILITY_ESS)
3824 iwe.u.mode = IW_MODE_MASTER;
3826 iwe.u.mode = IW_MODE_ADHOC;
3827 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3831 memset(&iwe, 0, sizeof(iwe));
3832 iwe.cmd = SIOCGIWFREQ;
3833 iwe.u.freq.m = bss->freq;
3835 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3838 memset(&iwe, 0, sizeof(iwe));
3839 iwe.cmd = SIOCGIWFREQ;
3840 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
3842 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3845 memset(&iwe, 0, sizeof(iwe));
3847 iwe.u.qual.qual = bss->signal;
3848 iwe.u.qual.level = bss->rssi;
3849 iwe.u.qual.noise = bss->noise;
3850 iwe.u.qual.updated = local->wstats_flags;
3851 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3854 memset(&iwe, 0, sizeof(iwe));
3855 iwe.cmd = SIOCGIWENCODE;
3856 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
3857 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
3859 iwe.u.data.flags = IW_ENCODE_DISABLED;
3860 iwe.u.data.length = 0;
3861 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
3863 if (bss && bss->wpa_ie) {
3864 memset(&iwe, 0, sizeof(iwe));
3865 iwe.cmd = IWEVGENIE;
3866 iwe.u.data.length = bss->wpa_ie_len;
3867 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3871 if (bss && bss->rsn_ie) {
3872 memset(&iwe, 0, sizeof(iwe));
3873 iwe.cmd = IWEVGENIE;
3874 iwe.u.data.length = bss->rsn_ie_len;
3875 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3879 if (bss && bss->supp_rates_len > 0) {
3880 /* display all supported rates in readable format */
3881 char *p = current_ev + IW_EV_LCP_LEN;
3884 memset(&iwe, 0, sizeof(iwe));
3885 iwe.cmd = SIOCGIWRATE;
3886 /* Those two flags are ignored... */
3887 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
3889 for (i = 0; i < bss->supp_rates_len; i++) {
3890 iwe.u.bitrate.value = ((bss->supp_rates[i] &
3892 p = iwe_stream_add_value(current_ev, p,
3893 end_buf, &iwe, IW_EV_PARAM_LEN);
3900 buf = kmalloc(30, GFP_ATOMIC);
3902 memset(&iwe, 0, sizeof(iwe));
3903 iwe.cmd = IWEVCUSTOM;
3904 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp));
3905 iwe.u.data.length = strlen(buf);
3906 current_ev = iwe_stream_add_point(current_ev, end_buf,
3912 if (bss_mesh_cfg(bss)) {
3914 u8 *cfg = bss_mesh_cfg(bss);
3915 buf = kmalloc(200, GFP_ATOMIC);
3917 memset(&iwe, 0, sizeof(iwe));
3918 iwe.cmd = IWEVCUSTOM;
3919 sprintf(buf, "Mesh network (version %d)\n"
3920 "\t\t\tPath Selection Protocol ID: 0x%02X%02X%02X%02X\n"
3921 "\t\t\tPath Selection Metric ID: 0x%02X%02X%02X%02X\n"
3922 "\t\t\tCongestion Control Mode ID: 0x%02X%02X%02X%02X\n"
3923 "\t\t\tChannel Precedence: 0x%02X%02X%02X%02X",
3924 cfg[0], cfg[1], cfg[2], cfg[3], cfg[4], cfg[5], cfg[6],
3925 cfg[7], cfg[8], cfg[9], cfg[10], cfg[11], cfg[12],
3926 cfg[13], cfg[14], cfg[15], cfg[16]);
3927 iwe.u.data.length = strlen(buf);
3928 current_ev = iwe_stream_add_point(current_ev, end_buf,
3938 int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
3940 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3941 char *current_ev = buf;
3942 char *end_buf = buf + len;
3943 struct ieee80211_sta_bss *bss;
3945 spin_lock_bh(&local->sta_bss_lock);
3946 list_for_each_entry(bss, &local->sta_bss_list, list) {
3947 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
3948 spin_unlock_bh(&local->sta_bss_lock);
3951 current_ev = ieee80211_sta_scan_result(dev, bss, current_ev,
3954 spin_unlock_bh(&local->sta_bss_lock);
3955 return current_ev - buf;
3959 int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
3961 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3962 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
3963 kfree(ifsta->extra_ie);
3965 ifsta->extra_ie = NULL;
3966 ifsta->extra_ie_len = 0;
3969 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
3970 if (!ifsta->extra_ie) {
3971 ifsta->extra_ie_len = 0;
3974 memcpy(ifsta->extra_ie, ie, len);
3975 ifsta->extra_ie_len = len;
3980 struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
3981 struct sk_buff *skb, u8 *bssid,
3984 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3985 struct sta_info *sta;
3986 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3987 DECLARE_MAC_BUF(mac);
3989 /* TODO: Could consider removing the least recently used entry and
3990 * allow new one to be added. */
3991 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
3992 if (net_ratelimit()) {
3993 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
3994 "entry %s\n", dev->name, print_mac(mac, addr));
3999 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
4000 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
4002 sta = sta_info_add(local, dev, addr, GFP_ATOMIC);
4006 sta->flags |= WLAN_STA_AUTHORIZED;
4008 sta->supp_rates[local->hw.conf.channel->band] =
4009 sdata->u.sta.supp_rates_bits[local->hw.conf.channel->band];
4011 rate_control_rate_init(sta, local);
4013 return sta; /* caller will call sta_info_put() */
4017 int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
4019 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4020 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4022 printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
4025 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
4026 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
4029 ieee80211_send_deauth(dev, ifsta, reason);
4030 ieee80211_set_disassoc(dev, ifsta, 1);
4035 int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
4037 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4038 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
4040 printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
4043 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
4046 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
4049 ieee80211_send_disassoc(dev, ifsta, reason);
4050 ieee80211_set_disassoc(dev, ifsta, 0);