2 * BSS client mode implementation
3 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 * order BSS list by RSSI(?) ("quality of AP")
16 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
19 #include <linux/delay.h>
20 #include <linux/if_ether.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/wireless.h>
25 #include <linux/random.h>
26 #include <linux/etherdevice.h>
27 #include <linux/rtnetlink.h>
28 #include <net/iw_handler.h>
29 #include <asm/types.h>
31 #include <net/mac80211.h>
32 #include "ieee80211_i.h"
33 #include "ieee80211_rate.h"
34 #include "ieee80211_led.h"
37 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
38 #define IEEE80211_AUTH_MAX_TRIES 3
39 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
40 #define IEEE80211_ASSOC_MAX_TRIES 3
41 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
42 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
43 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
44 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
45 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
46 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
47 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
49 #define IEEE80211_PROBE_DELAY (HZ / 33)
50 #define IEEE80211_CHANNEL_TIME (HZ / 33)
51 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
52 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
53 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
54 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
55 #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
57 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
60 #define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
62 #define ERP_INFO_USE_PROTECTION BIT(1)
64 /* mgmt header + 1 byte action code */
65 #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
67 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
68 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
69 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
70 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
71 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
73 /* next values represent the buffer size for A-MPDU frame.
74 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
75 #define IEEE80211_MIN_AMPDU_BUF 0x8
76 #define IEEE80211_MAX_AMPDU_BUF 0x40
78 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
79 u8
*ssid
, size_t ssid_len
);
80 static struct ieee80211_sta_bss
*
81 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int freq
,
82 u8
*ssid
, u8 ssid_len
);
83 static void ieee80211_rx_bss_put(struct net_device
*dev
,
84 struct ieee80211_sta_bss
*bss
);
85 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
86 struct ieee80211_if_sta
*ifsta
);
87 static int ieee80211_sta_wep_configured(struct net_device
*dev
);
88 static int ieee80211_sta_start_scan(struct net_device
*dev
,
89 u8
*ssid
, size_t ssid_len
);
90 static int ieee80211_sta_config_auth(struct net_device
*dev
,
91 struct ieee80211_if_sta
*ifsta
);
94 void ieee802_11_parse_elems(u8
*start
, size_t len
,
95 struct ieee802_11_elems
*elems
)
100 memset(elems
, 0, sizeof(*elems
));
115 elems
->ssid_len
= elen
;
117 case WLAN_EID_SUPP_RATES
:
118 elems
->supp_rates
= pos
;
119 elems
->supp_rates_len
= elen
;
121 case WLAN_EID_FH_PARAMS
:
122 elems
->fh_params
= pos
;
123 elems
->fh_params_len
= elen
;
125 case WLAN_EID_DS_PARAMS
:
126 elems
->ds_params
= pos
;
127 elems
->ds_params_len
= elen
;
129 case WLAN_EID_CF_PARAMS
:
130 elems
->cf_params
= pos
;
131 elems
->cf_params_len
= elen
;
135 elems
->tim_len
= elen
;
137 case WLAN_EID_IBSS_PARAMS
:
138 elems
->ibss_params
= pos
;
139 elems
->ibss_params_len
= elen
;
141 case WLAN_EID_CHALLENGE
:
142 elems
->challenge
= pos
;
143 elems
->challenge_len
= elen
;
146 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
148 /* Microsoft OUI (00:50:F2) */
150 /* OUI Type 1 - WPA IE */
152 elems
->wpa_len
= elen
;
153 } else if (elen
>= 5 && pos
[3] == 2) {
155 elems
->wmm_info
= pos
;
156 elems
->wmm_info_len
= elen
;
157 } else if (pos
[4] == 1) {
158 elems
->wmm_param
= pos
;
159 elems
->wmm_param_len
= elen
;
166 elems
->rsn_len
= elen
;
168 case WLAN_EID_ERP_INFO
:
169 elems
->erp_info
= pos
;
170 elems
->erp_info_len
= elen
;
172 case WLAN_EID_EXT_SUPP_RATES
:
173 elems
->ext_supp_rates
= pos
;
174 elems
->ext_supp_rates_len
= elen
;
176 case WLAN_EID_HT_CAPABILITY
:
177 elems
->ht_cap_elem
= pos
;
178 elems
->ht_cap_elem_len
= elen
;
180 case WLAN_EID_HT_EXTRA_INFO
:
181 elems
->ht_info_elem
= pos
;
182 elems
->ht_info_elem_len
= elen
;
184 case WLAN_EID_MESH_ID
:
185 elems
->mesh_id
= pos
;
186 elems
->mesh_id_len
= elen
;
188 case WLAN_EID_MESH_CONFIG
:
189 elems
->mesh_config
= pos
;
190 elems
->mesh_config_len
= elen
;
192 case WLAN_EID_PEER_LINK
:
193 elems
->peer_link
= pos
;
194 elems
->peer_link_len
= elen
;
198 elems
->preq_len
= elen
;
202 elems
->prep_len
= elen
;
206 elems
->perr_len
= elen
;
218 static int ecw2cw(int ecw
)
220 return (1 << ecw
) - 1;
223 static void ieee80211_sta_wmm_params(struct net_device
*dev
,
224 struct ieee80211_if_sta
*ifsta
,
225 u8
*wmm_param
, size_t wmm_param_len
)
227 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
228 struct ieee80211_tx_queue_params params
;
233 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
235 count
= wmm_param
[6] & 0x0f;
236 if (count
== ifsta
->wmm_last_param_set
)
238 ifsta
->wmm_last_param_set
= count
;
241 left
= wmm_param_len
- 8;
243 memset(¶ms
, 0, sizeof(params
));
245 if (!local
->ops
->conf_tx
)
249 for (; left
>= 4; left
-= 4, pos
+= 4) {
250 int aci
= (pos
[0] >> 5) & 0x03;
251 int acm
= (pos
[0] >> 4) & 0x01;
256 queue
= IEEE80211_TX_QUEUE_DATA3
;
258 local
->wmm_acm
|= BIT(0) | BIT(3);
262 queue
= IEEE80211_TX_QUEUE_DATA1
;
264 local
->wmm_acm
|= BIT(4) | BIT(5);
268 queue
= IEEE80211_TX_QUEUE_DATA0
;
270 local
->wmm_acm
|= BIT(6) | BIT(7);
275 queue
= IEEE80211_TX_QUEUE_DATA2
;
277 local
->wmm_acm
|= BIT(1) | BIT(2);
282 params
.aifs
= pos
[0] & 0x0f;
283 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
284 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
285 params
.txop
= pos
[2] | (pos
[3] << 8);
286 #ifdef CONFIG_MAC80211_DEBUG
287 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
288 "cWmin=%d cWmax=%d txop=%d\n",
289 dev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
290 params
.cw_max
, params
.txop
);
292 /* TODO: handle ACM (block TX, fallback to next lowest allowed
294 if (local
->ops
->conf_tx(local_to_hw(local
), queue
, ¶ms
)) {
295 printk(KERN_DEBUG
"%s: failed to set TX queue "
296 "parameters for queue %d\n", dev
->name
, queue
);
302 static u32
ieee80211_handle_erp_ie(struct ieee80211_sub_if_data
*sdata
,
305 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
306 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
307 bool use_protection
= (erp_value
& WLAN_ERP_USE_PROTECTION
) != 0;
308 bool preamble_mode
= (erp_value
& WLAN_ERP_BARKER_PREAMBLE
) != 0;
309 DECLARE_MAC_BUF(mac
);
312 if (use_protection
!= bss_conf
->use_cts_prot
) {
313 if (net_ratelimit()) {
314 printk(KERN_DEBUG
"%s: CTS protection %s (BSSID="
317 use_protection
? "enabled" : "disabled",
318 print_mac(mac
, ifsta
->bssid
));
320 bss_conf
->use_cts_prot
= use_protection
;
321 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
324 if (preamble_mode
!= bss_conf
->use_short_preamble
) {
325 if (net_ratelimit()) {
326 printk(KERN_DEBUG
"%s: switched to %s barker preamble"
329 (preamble_mode
== WLAN_ERP_PREAMBLE_SHORT
) ?
331 print_mac(mac
, ifsta
->bssid
));
333 bss_conf
->use_short_preamble
= preamble_mode
;
334 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
340 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap
*ht_cap_ie
,
341 struct ieee80211_ht_info
*ht_info
)
347 memset(ht_info
, 0, sizeof(*ht_info
));
350 u8 ampdu_info
= ht_cap_ie
->ampdu_params_info
;
352 ht_info
->ht_supported
= 1;
353 ht_info
->cap
= le16_to_cpu(ht_cap_ie
->cap_info
);
354 ht_info
->ampdu_factor
=
355 ampdu_info
& IEEE80211_HT_CAP_AMPDU_FACTOR
;
356 ht_info
->ampdu_density
=
357 (ampdu_info
& IEEE80211_HT_CAP_AMPDU_DENSITY
) >> 2;
358 memcpy(ht_info
->supp_mcs_set
, ht_cap_ie
->supp_mcs_set
, 16);
360 ht_info
->ht_supported
= 0;
365 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
366 struct ieee80211_ht_addt_info
*ht_add_info_ie
,
367 struct ieee80211_ht_bss_info
*bss_info
)
369 if (bss_info
== NULL
)
372 memset(bss_info
, 0, sizeof(*bss_info
));
374 if (ht_add_info_ie
) {
376 op_mode
= le16_to_cpu(ht_add_info_ie
->operation_mode
);
378 bss_info
->primary_channel
= ht_add_info_ie
->control_chan
;
379 bss_info
->bss_cap
= ht_add_info_ie
->ht_param
;
380 bss_info
->bss_op_mode
= (u8
)(op_mode
& 0xff);
386 static void ieee80211_sta_send_associnfo(struct net_device
*dev
,
387 struct ieee80211_if_sta
*ifsta
)
392 union iwreq_data wrqu
;
394 if (!ifsta
->assocreq_ies
&& !ifsta
->assocresp_ies
)
397 buf
= kmalloc(50 + 2 * (ifsta
->assocreq_ies_len
+
398 ifsta
->assocresp_ies_len
), GFP_KERNEL
);
402 len
= sprintf(buf
, "ASSOCINFO(");
403 if (ifsta
->assocreq_ies
) {
404 len
+= sprintf(buf
+ len
, "ReqIEs=");
405 for (i
= 0; i
< ifsta
->assocreq_ies_len
; i
++) {
406 len
+= sprintf(buf
+ len
, "%02x",
407 ifsta
->assocreq_ies
[i
]);
410 if (ifsta
->assocresp_ies
) {
411 if (ifsta
->assocreq_ies
)
412 len
+= sprintf(buf
+ len
, " ");
413 len
+= sprintf(buf
+ len
, "RespIEs=");
414 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
415 len
+= sprintf(buf
+ len
, "%02x",
416 ifsta
->assocresp_ies
[i
]);
419 len
+= sprintf(buf
+ len
, ")");
421 if (len
> IW_CUSTOM_MAX
) {
422 len
= sprintf(buf
, "ASSOCRESPIE=");
423 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
424 len
+= sprintf(buf
+ len
, "%02x",
425 ifsta
->assocresp_ies
[i
]);
429 memset(&wrqu
, 0, sizeof(wrqu
));
430 wrqu
.data
.length
= len
;
431 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
437 static void ieee80211_set_associated(struct net_device
*dev
,
438 struct ieee80211_if_sta
*ifsta
,
441 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
442 struct ieee80211_local
*local
= sdata
->local
;
443 union iwreq_data wrqu
;
444 u32 changed
= BSS_CHANGED_ASSOC
;
447 struct ieee80211_sta_bss
*bss
;
449 ifsta
->flags
|= IEEE80211_STA_ASSOCIATED
;
451 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
454 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
455 local
->hw
.conf
.channel
->center_freq
,
456 ifsta
->ssid
, ifsta
->ssid_len
);
458 if (bss
->has_erp_value
)
459 changed
|= ieee80211_handle_erp_ie(
460 sdata
, bss
->erp_value
);
461 ieee80211_rx_bss_put(dev
, bss
);
464 netif_carrier_on(dev
);
465 ifsta
->flags
|= IEEE80211_STA_PREV_BSSID_SET
;
466 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
467 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
468 ieee80211_sta_send_associnfo(dev
, ifsta
);
470 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
472 netif_carrier_off(dev
);
473 ieee80211_reset_erp_info(dev
);
474 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
476 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
477 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
478 ifsta
->last_probe
= jiffies
;
479 ieee80211_led_assoc(local
, assoc
);
481 sdata
->bss_conf
.assoc
= assoc
;
482 ieee80211_bss_info_change_notify(sdata
, changed
);
485 static void ieee80211_set_disassoc(struct net_device
*dev
,
486 struct ieee80211_if_sta
*ifsta
, int deauth
)
489 ifsta
->auth_tries
= 0;
490 ifsta
->assoc_tries
= 0;
491 ieee80211_set_associated(dev
, ifsta
, 0);
494 void ieee80211_sta_tx(struct net_device
*dev
, struct sk_buff
*skb
,
497 struct ieee80211_sub_if_data
*sdata
;
498 struct ieee80211_tx_packet_data
*pkt_data
;
500 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
501 skb
->dev
= sdata
->local
->mdev
;
502 skb_set_mac_header(skb
, 0);
503 skb_set_network_header(skb
, 0);
504 skb_set_transport_header(skb
, 0);
506 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
507 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
508 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
510 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
516 static void ieee80211_send_auth(struct net_device
*dev
,
517 struct ieee80211_if_sta
*ifsta
,
518 int transaction
, u8
*extra
, size_t extra_len
,
521 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
523 struct ieee80211_mgmt
*mgmt
;
525 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
526 sizeof(*mgmt
) + 6 + extra_len
);
528 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
529 "frame\n", dev
->name
);
532 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
534 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
535 memset(mgmt
, 0, 24 + 6);
536 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
537 IEEE80211_STYPE_AUTH
);
539 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
540 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
541 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
542 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
543 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
544 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
545 ifsta
->auth_transaction
= transaction
+ 1;
546 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
548 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
550 ieee80211_sta_tx(dev
, skb
, encrypt
);
554 static void ieee80211_authenticate(struct net_device
*dev
,
555 struct ieee80211_if_sta
*ifsta
)
557 DECLARE_MAC_BUF(mac
);
560 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
561 printk(KERN_DEBUG
"%s: authentication with AP %s"
563 dev
->name
, print_mac(mac
, ifsta
->bssid
));
564 ifsta
->state
= IEEE80211_DISABLED
;
568 ifsta
->state
= IEEE80211_AUTHENTICATE
;
569 printk(KERN_DEBUG
"%s: authenticate with AP %s\n",
570 dev
->name
, print_mac(mac
, ifsta
->bssid
));
572 ieee80211_send_auth(dev
, ifsta
, 1, NULL
, 0, 0);
574 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_AUTH_TIMEOUT
);
578 static void ieee80211_send_assoc(struct net_device
*dev
,
579 struct ieee80211_if_sta
*ifsta
)
581 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
583 struct ieee80211_mgmt
*mgmt
;
587 struct ieee80211_sta_bss
*bss
;
589 struct ieee80211_supported_band
*sband
;
591 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
592 sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
595 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
596 "frame\n", dev
->name
);
599 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
601 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
603 capab
= ifsta
->capab
;
605 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
) {
606 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
607 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
608 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
609 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
612 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
613 local
->hw
.conf
.channel
->center_freq
,
614 ifsta
->ssid
, ifsta
->ssid_len
);
616 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
617 capab
|= WLAN_CAPABILITY_PRIVACY
;
621 ieee80211_rx_bss_put(dev
, bss
);
624 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
626 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
627 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
628 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
630 if (ifsta
->flags
& IEEE80211_STA_PREV_BSSID_SET
) {
632 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
633 IEEE80211_STYPE_REASSOC_REQ
);
634 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
635 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
636 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
640 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
641 IEEE80211_STYPE_ASSOC_REQ
);
642 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
643 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
647 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
648 *pos
++ = WLAN_EID_SSID
;
649 *pos
++ = ifsta
->ssid_len
;
650 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
652 len
= sband
->n_bitrates
;
655 pos
= skb_put(skb
, len
+ 2);
656 *pos
++ = WLAN_EID_SUPP_RATES
;
658 for (i
= 0; i
< len
; i
++) {
659 int rate
= sband
->bitrates
[i
].bitrate
;
660 *pos
++ = (u8
) (rate
/ 5);
663 if (sband
->n_bitrates
> len
) {
664 pos
= skb_put(skb
, sband
->n_bitrates
- len
+ 2);
665 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
666 *pos
++ = sband
->n_bitrates
- len
;
667 for (i
= len
; i
< sband
->n_bitrates
; i
++) {
668 int rate
= sband
->bitrates
[i
].bitrate
;
669 *pos
++ = (u8
) (rate
/ 5);
673 if (ifsta
->extra_ie
) {
674 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
675 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
678 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
679 pos
= skb_put(skb
, 9);
680 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
681 *pos
++ = 7; /* len */
682 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
685 *pos
++ = 2; /* WME */
686 *pos
++ = 0; /* WME info */
687 *pos
++ = 1; /* WME ver */
690 /* wmm support is a must to HT */
691 if (wmm
&& sband
->ht_info
.ht_supported
) {
692 __le16 tmp
= cpu_to_le16(sband
->ht_info
.cap
);
693 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
)+2);
694 *pos
++ = WLAN_EID_HT_CAPABILITY
;
695 *pos
++ = sizeof(struct ieee80211_ht_cap
);
696 memset(pos
, 0, sizeof(struct ieee80211_ht_cap
));
697 memcpy(pos
, &tmp
, sizeof(u16
));
699 /* TODO: needs a define here for << 2 */
700 *pos
++ = sband
->ht_info
.ampdu_factor
|
701 (sband
->ht_info
.ampdu_density
<< 2);
702 memcpy(pos
, sband
->ht_info
.supp_mcs_set
, 16);
705 kfree(ifsta
->assocreq_ies
);
706 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
707 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_KERNEL
);
708 if (ifsta
->assocreq_ies
)
709 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
711 ieee80211_sta_tx(dev
, skb
, 0);
715 static void ieee80211_send_deauth(struct net_device
*dev
,
716 struct ieee80211_if_sta
*ifsta
, u16 reason
)
718 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
720 struct ieee80211_mgmt
*mgmt
;
722 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
724 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
725 "frame\n", dev
->name
);
728 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
730 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
732 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
733 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
734 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
735 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
736 IEEE80211_STYPE_DEAUTH
);
738 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
740 ieee80211_sta_tx(dev
, skb
, 0);
744 static void ieee80211_send_disassoc(struct net_device
*dev
,
745 struct ieee80211_if_sta
*ifsta
, u16 reason
)
747 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
749 struct ieee80211_mgmt
*mgmt
;
751 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
753 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
754 "frame\n", dev
->name
);
757 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
759 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
761 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
762 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
763 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
764 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
765 IEEE80211_STYPE_DISASSOC
);
767 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
769 ieee80211_sta_tx(dev
, skb
, 0);
773 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
774 struct ieee80211_if_sta
*ifsta
)
776 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
777 struct ieee80211_sta_bss
*bss
;
782 if (!ifsta
|| (ifsta
->flags
& IEEE80211_STA_MIXED_CELL
))
785 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
786 local
->hw
.conf
.channel
->center_freq
,
787 ifsta
->ssid
, ifsta
->ssid_len
);
791 bss_privacy
= !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
792 wep_privacy
= !!ieee80211_sta_wep_configured(dev
);
793 privacy_invoked
= !!(ifsta
->flags
& IEEE80211_STA_PRIVACY_INVOKED
);
795 ieee80211_rx_bss_put(dev
, bss
);
797 if ((bss_privacy
== wep_privacy
) || (bss_privacy
== privacy_invoked
))
804 static void ieee80211_associate(struct net_device
*dev
,
805 struct ieee80211_if_sta
*ifsta
)
807 DECLARE_MAC_BUF(mac
);
809 ifsta
->assoc_tries
++;
810 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
811 printk(KERN_DEBUG
"%s: association with AP %s"
813 dev
->name
, print_mac(mac
, ifsta
->bssid
));
814 ifsta
->state
= IEEE80211_DISABLED
;
818 ifsta
->state
= IEEE80211_ASSOCIATE
;
819 printk(KERN_DEBUG
"%s: associate with AP %s\n",
820 dev
->name
, print_mac(mac
, ifsta
->bssid
));
821 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
822 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
823 "mixed-cell disabled - abort association\n", dev
->name
);
824 ifsta
->state
= IEEE80211_DISABLED
;
828 ieee80211_send_assoc(dev
, ifsta
);
830 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_ASSOC_TIMEOUT
);
834 static void ieee80211_associated(struct net_device
*dev
,
835 struct ieee80211_if_sta
*ifsta
)
837 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
838 struct sta_info
*sta
;
840 DECLARE_MAC_BUF(mac
);
842 /* TODO: start monitoring current AP signal quality and number of
843 * missed beacons. Scan other channels every now and then and search
845 /* TODO: remove expired BSSes */
847 ifsta
->state
= IEEE80211_ASSOCIATED
;
851 sta
= sta_info_get(local
, ifsta
->bssid
);
853 printk(KERN_DEBUG
"%s: No STA entry for own AP %s\n",
854 dev
->name
, print_mac(mac
, ifsta
->bssid
));
858 if (time_after(jiffies
,
859 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
860 if (ifsta
->flags
& IEEE80211_STA_PROBEREQ_POLL
) {
861 printk(KERN_DEBUG
"%s: No ProbeResp from "
862 "current AP %s - assume out of "
864 dev
->name
, print_mac(mac
, ifsta
->bssid
));
866 sta_info_unlink(&sta
);
868 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
870 local
->scan_ssid_len
);
871 ifsta
->flags
^= IEEE80211_STA_PROBEREQ_POLL
;
873 ifsta
->flags
&= ~IEEE80211_STA_PROBEREQ_POLL
;
874 if (time_after(jiffies
, ifsta
->last_probe
+
875 IEEE80211_PROBE_INTERVAL
)) {
876 ifsta
->last_probe
= jiffies
;
877 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
886 if (disassoc
&& sta
) {
889 sta_info_destroy(sta
);
894 ifsta
->state
= IEEE80211_DISABLED
;
895 ieee80211_set_associated(dev
, ifsta
, 0);
897 mod_timer(&ifsta
->timer
, jiffies
+
898 IEEE80211_MONITORING_INTERVAL
);
903 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
904 u8
*ssid
, size_t ssid_len
)
906 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
907 struct ieee80211_supported_band
*sband
;
909 struct ieee80211_mgmt
*mgmt
;
910 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
913 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200);
915 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
916 "request\n", dev
->name
);
919 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
921 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
923 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
924 IEEE80211_STYPE_PROBE_REQ
);
925 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
927 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
928 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
930 memset(mgmt
->da
, 0xff, ETH_ALEN
);
931 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
933 pos
= skb_put(skb
, 2 + ssid_len
);
934 *pos
++ = WLAN_EID_SSID
;
936 memcpy(pos
, ssid
, ssid_len
);
938 supp_rates
= skb_put(skb
, 2);
939 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
941 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
943 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
944 struct ieee80211_rate
*rate
= &sband
->bitrates
[i
];
946 pos
= skb_put(skb
, 1);
948 } else if (supp_rates
[1] == 8) {
949 esupp_rates
= skb_put(skb
, 3);
950 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
952 pos
= &esupp_rates
[2];
954 pos
= skb_put(skb
, 1);
957 *pos
= rate
->bitrate
/ 5;
960 ieee80211_sta_tx(dev
, skb
, 0);
964 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
966 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
967 if (!sdata
|| !sdata
->default_key
||
968 sdata
->default_key
->conf
.alg
!= ALG_WEP
)
974 static void ieee80211_auth_completed(struct net_device
*dev
,
975 struct ieee80211_if_sta
*ifsta
)
977 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
978 ifsta
->flags
|= IEEE80211_STA_AUTHENTICATED
;
979 ieee80211_associate(dev
, ifsta
);
983 static void ieee80211_auth_challenge(struct net_device
*dev
,
984 struct ieee80211_if_sta
*ifsta
,
985 struct ieee80211_mgmt
*mgmt
,
989 struct ieee802_11_elems elems
;
991 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
992 pos
= mgmt
->u
.auth
.variable
;
993 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
994 if (!elems
.challenge
) {
995 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
996 "frame\n", dev
->name
);
999 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
1000 elems
.challenge_len
+ 2, 1);
1003 static void ieee80211_send_addba_resp(struct net_device
*dev
, u8
*da
, u16 tid
,
1004 u8 dialog_token
, u16 status
, u16 policy
,
1005 u16 buf_size
, u16 timeout
)
1007 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1008 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1009 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1010 struct sk_buff
*skb
;
1011 struct ieee80211_mgmt
*mgmt
;
1014 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1015 sizeof(mgmt
->u
.action
.u
.addba_resp
));
1017 printk(KERN_DEBUG
"%s: failed to allocate buffer "
1018 "for addba resp frame\n", dev
->name
);
1022 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1023 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1024 memset(mgmt
, 0, 24);
1025 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1026 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1027 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1028 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1030 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1031 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1032 IEEE80211_STYPE_ACTION
);
1034 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_resp
));
1035 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1036 mgmt
->u
.action
.u
.addba_resp
.action_code
= WLAN_ACTION_ADDBA_RESP
;
1037 mgmt
->u
.action
.u
.addba_resp
.dialog_token
= dialog_token
;
1039 capab
= (u16
)(policy
<< 1); /* bit 1 aggregation policy */
1040 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1041 capab
|= (u16
)(buf_size
<< 6); /* bit 15:6 max size of aggregation */
1043 mgmt
->u
.action
.u
.addba_resp
.capab
= cpu_to_le16(capab
);
1044 mgmt
->u
.action
.u
.addba_resp
.timeout
= cpu_to_le16(timeout
);
1045 mgmt
->u
.action
.u
.addba_resp
.status
= cpu_to_le16(status
);
1047 ieee80211_sta_tx(dev
, skb
, 0);
1052 void ieee80211_send_addba_request(struct net_device
*dev
, const u8
*da
,
1053 u16 tid
, u8 dialog_token
, u16 start_seq_num
,
1054 u16 agg_size
, u16 timeout
)
1056 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1057 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1058 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1059 struct sk_buff
*skb
;
1060 struct ieee80211_mgmt
*mgmt
;
1063 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1064 sizeof(mgmt
->u
.action
.u
.addba_req
));
1068 printk(KERN_ERR
"%s: failed to allocate buffer "
1069 "for addba request frame\n", dev
->name
);
1072 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1073 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1074 memset(mgmt
, 0, 24);
1075 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1076 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1077 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1078 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1080 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1082 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1083 IEEE80211_STYPE_ACTION
);
1085 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_req
));
1087 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1088 mgmt
->u
.action
.u
.addba_req
.action_code
= WLAN_ACTION_ADDBA_REQ
;
1090 mgmt
->u
.action
.u
.addba_req
.dialog_token
= dialog_token
;
1091 capab
= (u16
)(1 << 1); /* bit 1 aggregation policy */
1092 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1093 capab
|= (u16
)(agg_size
<< 6); /* bit 15:6 max size of aggergation */
1095 mgmt
->u
.action
.u
.addba_req
.capab
= cpu_to_le16(capab
);
1097 mgmt
->u
.action
.u
.addba_req
.timeout
= cpu_to_le16(timeout
);
1098 mgmt
->u
.action
.u
.addba_req
.start_seq_num
=
1099 cpu_to_le16(start_seq_num
<< 4);
1101 ieee80211_sta_tx(dev
, skb
, 0);
1104 static void ieee80211_sta_process_addba_request(struct net_device
*dev
,
1105 struct ieee80211_mgmt
*mgmt
,
1108 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1109 struct ieee80211_hw
*hw
= &local
->hw
;
1110 struct ieee80211_conf
*conf
= &hw
->conf
;
1111 struct sta_info
*sta
;
1112 struct tid_ampdu_rx
*tid_agg_rx
;
1113 u16 capab
, tid
, timeout
, ba_policy
, buf_size
, start_seq_num
, status
;
1115 int ret
= -EOPNOTSUPP
;
1116 DECLARE_MAC_BUF(mac
);
1120 sta
= sta_info_get(local
, mgmt
->sa
);
1126 /* extract session parameters from addba request frame */
1127 dialog_token
= mgmt
->u
.action
.u
.addba_req
.dialog_token
;
1128 timeout
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.timeout
);
1130 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.start_seq_num
) >> 4;
1132 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1133 ba_policy
= (capab
& IEEE80211_ADDBA_PARAM_POLICY_MASK
) >> 1;
1134 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1135 buf_size
= (capab
& IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
) >> 6;
1137 status
= WLAN_STATUS_REQUEST_DECLINED
;
1139 /* sanity check for incoming parameters:
1140 * check if configuration can support the BA policy
1141 * and if buffer size does not exceeds max value */
1142 if (((ba_policy
!= 1)
1143 && (!(conf
->ht_conf
.cap
& IEEE80211_HT_CAP_DELAY_BA
)))
1144 || (buf_size
> IEEE80211_MAX_AMPDU_BUF
)) {
1145 status
= WLAN_STATUS_INVALID_QOS_PARAM
;
1146 #ifdef CONFIG_MAC80211_HT_DEBUG
1147 if (net_ratelimit())
1148 printk(KERN_DEBUG
"Block Ack Req with bad params from "
1149 "%s on tid %u. policy %d, buffer size %d\n",
1150 print_mac(mac
, mgmt
->sa
), tid
, ba_policy
,
1152 #endif /* CONFIG_MAC80211_HT_DEBUG */
1155 /* determine default buffer size */
1156 if (buf_size
== 0) {
1157 struct ieee80211_supported_band
*sband
;
1159 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
1160 buf_size
= IEEE80211_MIN_AMPDU_BUF
;
1161 buf_size
= buf_size
<< sband
->ht_info
.ampdu_factor
;
1164 tid_agg_rx
= &sta
->ampdu_mlme
.tid_rx
[tid
];
1166 /* examine state machine */
1167 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1169 if (tid_agg_rx
->state
!= HT_AGG_STATE_IDLE
) {
1170 #ifdef CONFIG_MAC80211_HT_DEBUG
1171 if (net_ratelimit())
1172 printk(KERN_DEBUG
"unexpected Block Ack Req from "
1174 print_mac(mac
, mgmt
->sa
), tid
);
1175 #endif /* CONFIG_MAC80211_HT_DEBUG */
1179 /* prepare reordering buffer */
1180 tid_agg_rx
->reorder_buf
=
1181 kmalloc(buf_size
* sizeof(struct sk_buf
*), GFP_ATOMIC
);
1182 if (!tid_agg_rx
->reorder_buf
) {
1183 if (net_ratelimit())
1184 printk(KERN_ERR
"can not allocate reordering buffer "
1185 "to tid %d\n", tid
);
1188 memset(tid_agg_rx
->reorder_buf
, 0,
1189 buf_size
* sizeof(struct sk_buf
*));
1191 if (local
->ops
->ampdu_action
)
1192 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_START
,
1193 sta
->addr
, tid
, &start_seq_num
);
1194 #ifdef CONFIG_MAC80211_HT_DEBUG
1195 printk(KERN_DEBUG
"Rx A-MPDU on tid %d result %d", tid
, ret
);
1196 #endif /* CONFIG_MAC80211_HT_DEBUG */
1199 kfree(tid_agg_rx
->reorder_buf
);
1203 /* change state and send addba resp */
1204 tid_agg_rx
->state
= HT_AGG_STATE_OPERATIONAL
;
1205 tid_agg_rx
->dialog_token
= dialog_token
;
1206 tid_agg_rx
->ssn
= start_seq_num
;
1207 tid_agg_rx
->head_seq_num
= start_seq_num
;
1208 tid_agg_rx
->buf_size
= buf_size
;
1209 tid_agg_rx
->timeout
= timeout
;
1210 tid_agg_rx
->stored_mpdu_num
= 0;
1211 status
= WLAN_STATUS_SUCCESS
;
1213 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1216 ieee80211_send_addba_resp(sta
->sdata
->dev
, sta
->addr
, tid
,
1217 dialog_token
, status
, 1, buf_size
, timeout
);
1221 static void ieee80211_sta_process_addba_resp(struct net_device
*dev
,
1222 struct ieee80211_mgmt
*mgmt
,
1225 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1226 struct ieee80211_hw
*hw
= &local
->hw
;
1227 struct sta_info
*sta
;
1234 sta
= sta_info_get(local
, mgmt
->sa
);
1240 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.capab
);
1241 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1243 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
1245 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1247 if (mgmt
->u
.action
.u
.addba_resp
.dialog_token
!=
1248 sta
->ampdu_mlme
.tid_tx
[tid
].dialog_token
) {
1249 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1250 #ifdef CONFIG_MAC80211_HT_DEBUG
1251 printk(KERN_DEBUG
"wrong addBA response token, tid %d\n", tid
);
1252 #endif /* CONFIG_MAC80211_HT_DEBUG */
1257 del_timer_sync(&sta
->ampdu_mlme
.tid_tx
[tid
].addba_resp_timer
);
1258 #ifdef CONFIG_MAC80211_HT_DEBUG
1259 printk(KERN_DEBUG
"switched off addBA timer for tid %d \n", tid
);
1260 #endif /* CONFIG_MAC80211_HT_DEBUG */
1261 if (le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.status
)
1262 == WLAN_STATUS_SUCCESS
) {
1263 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1264 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1265 printk(KERN_DEBUG
"state not HT_ADDBA_REQUESTED_MSK:"
1271 if (*state
& HT_ADDBA_RECEIVED_MSK
)
1272 printk(KERN_DEBUG
"double addBA response\n");
1274 *state
|= HT_ADDBA_RECEIVED_MSK
;
1275 sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
= 0;
1277 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
1278 printk(KERN_DEBUG
"Aggregation on for tid %d \n", tid
);
1279 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
1282 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1283 printk(KERN_DEBUG
"recipient accepted agg: tid %d \n", tid
);
1285 printk(KERN_DEBUG
"recipient rejected agg: tid %d \n", tid
);
1287 sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
++;
1288 /* this will allow the state check in stop_BA_session */
1289 *state
= HT_AGG_STATE_OPERATIONAL
;
1290 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1291 ieee80211_stop_tx_ba_session(hw
, sta
->addr
, tid
,
1292 WLAN_BACK_INITIATOR
);
1297 void ieee80211_send_delba(struct net_device
*dev
, const u8
*da
, u16 tid
,
1298 u16 initiator
, u16 reason_code
)
1300 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1301 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1302 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1303 struct sk_buff
*skb
;
1304 struct ieee80211_mgmt
*mgmt
;
1307 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1308 sizeof(mgmt
->u
.action
.u
.delba
));
1311 printk(KERN_ERR
"%s: failed to allocate buffer "
1312 "for delba frame\n", dev
->name
);
1316 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1317 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1318 memset(mgmt
, 0, 24);
1319 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1320 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1321 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1322 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1324 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1325 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1326 IEEE80211_STYPE_ACTION
);
1328 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.delba
));
1330 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1331 mgmt
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
1332 params
= (u16
)(initiator
<< 11); /* bit 11 initiator */
1333 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
1335 mgmt
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
1336 mgmt
->u
.action
.u
.delba
.reason_code
= cpu_to_le16(reason_code
);
1338 ieee80211_sta_tx(dev
, skb
, 0);
1341 void ieee80211_sta_stop_rx_ba_session(struct net_device
*dev
, u8
*ra
, u16 tid
,
1342 u16 initiator
, u16 reason
)
1344 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1345 struct ieee80211_hw
*hw
= &local
->hw
;
1346 struct sta_info
*sta
;
1351 sta
= sta_info_get(local
, ra
);
1357 /* check if TID is in operational state */
1358 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1359 if (sta
->ampdu_mlme
.tid_rx
[tid
].state
1360 != HT_AGG_STATE_OPERATIONAL
) {
1361 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1365 sta
->ampdu_mlme
.tid_rx
[tid
].state
=
1366 HT_AGG_STATE_REQ_STOP_BA_MSK
|
1367 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
1368 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1370 /* stop HW Rx aggregation. ampdu_action existence
1371 * already verified in session init so we add the BUG_ON */
1372 BUG_ON(!local
->ops
->ampdu_action
);
1374 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_STOP
,
1377 printk(KERN_DEBUG
"HW problem - can not stop rx "
1378 "aggergation for tid %d\n", tid
);
1380 /* shutdown timer has not expired */
1381 if (initiator
!= WLAN_BACK_TIMER
)
1382 del_timer_sync(&sta
->ampdu_mlme
.tid_rx
[tid
].
1385 /* check if this is a self generated aggregation halt */
1386 if (initiator
== WLAN_BACK_RECIPIENT
|| initiator
== WLAN_BACK_TIMER
)
1387 ieee80211_send_delba(dev
, ra
, tid
, 0, reason
);
1389 /* free the reordering buffer */
1390 for (i
= 0; i
< sta
->ampdu_mlme
.tid_rx
[tid
].buf_size
; i
++) {
1391 if (sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
[i
]) {
1392 /* release the reordered frames */
1393 dev_kfree_skb(sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
[i
]);
1394 sta
->ampdu_mlme
.tid_rx
[tid
].stored_mpdu_num
--;
1395 sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
[i
] = NULL
;
1398 kfree(sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
);
1400 sta
->ampdu_mlme
.tid_rx
[tid
].state
= HT_AGG_STATE_IDLE
;
1405 static void ieee80211_sta_process_delba(struct net_device
*dev
,
1406 struct ieee80211_mgmt
*mgmt
, size_t len
)
1408 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1409 struct sta_info
*sta
;
1412 DECLARE_MAC_BUF(mac
);
1416 sta
= sta_info_get(local
, mgmt
->sa
);
1422 params
= le16_to_cpu(mgmt
->u
.action
.u
.delba
.params
);
1423 tid
= (params
& IEEE80211_DELBA_PARAM_TID_MASK
) >> 12;
1424 initiator
= (params
& IEEE80211_DELBA_PARAM_INITIATOR_MASK
) >> 11;
1426 #ifdef CONFIG_MAC80211_HT_DEBUG
1427 if (net_ratelimit())
1428 printk(KERN_DEBUG
"delba from %s (%s) tid %d reason code %d\n",
1429 print_mac(mac
, mgmt
->sa
),
1430 initiator
? "recipient" : "initiator", tid
,
1431 mgmt
->u
.action
.u
.delba
.reason_code
);
1432 #endif /* CONFIG_MAC80211_HT_DEBUG */
1434 if (initiator
== WLAN_BACK_INITIATOR
)
1435 ieee80211_sta_stop_rx_ba_session(dev
, sta
->addr
, tid
,
1436 WLAN_BACK_INITIATOR
, 0);
1437 else { /* WLAN_BACK_RECIPIENT */
1438 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1439 sta
->ampdu_mlme
.tid_tx
[tid
].state
=
1440 HT_AGG_STATE_OPERATIONAL
;
1441 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1442 ieee80211_stop_tx_ba_session(&local
->hw
, sta
->addr
, tid
,
1443 WLAN_BACK_RECIPIENT
);
1449 * After sending add Block Ack request we activated a timer until
1450 * add Block Ack response will arrive from the recipient.
1451 * If this timer expires sta_addba_resp_timer_expired will be executed.
1453 void sta_addba_resp_timer_expired(unsigned long data
)
1455 /* not an elegant detour, but there is no choice as the timer passes
1456 * only one argument, and both sta_info and TID are needed, so init
1457 * flow in sta_info_create gives the TID as data, while the timer_to_id
1458 * array gives the sta through container_of */
1459 u16 tid
= *(int *)data
;
1460 struct sta_info
*temp_sta
= container_of((void *)data
,
1461 struct sta_info
, timer_to_tid
[tid
]);
1463 struct ieee80211_local
*local
= temp_sta
->local
;
1464 struct ieee80211_hw
*hw
= &local
->hw
;
1465 struct sta_info
*sta
;
1470 sta
= sta_info_get(local
, temp_sta
->addr
);
1476 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
1477 /* check if the TID waits for addBA response */
1478 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1479 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1480 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1481 *state
= HT_AGG_STATE_IDLE
;
1482 printk(KERN_DEBUG
"timer expired on tid %d but we are not "
1483 "expecting addBA response there", tid
);
1484 goto timer_expired_exit
;
1487 printk(KERN_DEBUG
"addBA response timer expired on tid %d\n", tid
);
1489 /* go through the state check in stop_BA_session */
1490 *state
= HT_AGG_STATE_OPERATIONAL
;
1491 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1492 ieee80211_stop_tx_ba_session(hw
, temp_sta
->addr
, tid
,
1493 WLAN_BACK_INITIATOR
);
1500 * After receiving Block Ack Request (BAR) we activated a
1501 * timer after each frame arrives from the originator.
1502 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1504 void sta_rx_agg_session_timer_expired(unsigned long data
)
1506 /* not an elegant detour, but there is no choice as the timer passes
1507 * only one argument, and verious sta_info are needed here, so init
1508 * flow in sta_info_create gives the TID as data, while the timer_to_id
1509 * array gives the sta through container_of */
1510 u8
*ptid
= (u8
*)data
;
1511 u8
*timer_to_id
= ptid
- *ptid
;
1512 struct sta_info
*sta
= container_of(timer_to_id
, struct sta_info
,
1515 printk(KERN_DEBUG
"rx session timer expired on tid %d\n", (u16
)*ptid
);
1516 ieee80211_sta_stop_rx_ba_session(sta
->sdata
->dev
, sta
->addr
,
1517 (u16
)*ptid
, WLAN_BACK_TIMER
,
1518 WLAN_REASON_QSTA_TIMEOUT
);
1522 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
1523 struct ieee80211_if_sta
*ifsta
,
1524 struct ieee80211_mgmt
*mgmt
,
1527 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1528 u16 auth_alg
, auth_transaction
, status_code
;
1529 DECLARE_MAC_BUF(mac
);
1531 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
1532 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
) {
1533 printk(KERN_DEBUG
"%s: authentication frame received from "
1534 "%s, but not in authenticate state - ignored\n",
1535 dev
->name
, print_mac(mac
, mgmt
->sa
));
1540 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
1541 "received from %s - ignored\n",
1542 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1546 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1547 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1548 printk(KERN_DEBUG
"%s: authentication frame received from "
1549 "unknown AP (SA=%s BSSID=%s) - "
1550 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1551 print_mac(mac
, mgmt
->bssid
));
1555 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1556 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
1557 printk(KERN_DEBUG
"%s: authentication frame received from "
1558 "unknown BSSID (SA=%s BSSID=%s) - "
1559 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1560 print_mac(mac
, mgmt
->bssid
));
1564 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
1565 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
1566 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
1568 printk(KERN_DEBUG
"%s: RX authentication from %s (alg=%d "
1569 "transaction=%d status=%d)\n",
1570 dev
->name
, print_mac(mac
, mgmt
->sa
), auth_alg
,
1571 auth_transaction
, status_code
);
1573 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
1574 /* IEEE 802.11 standard does not require authentication in IBSS
1575 * networks and most implementations do not seem to use it.
1576 * However, try to reply to authentication attempts if someone
1577 * has actually implemented this.
1578 * TODO: Could implement shared key authentication. */
1579 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
1580 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
1581 "frame (alg=%d transaction=%d)\n",
1582 dev
->name
, auth_alg
, auth_transaction
);
1585 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
1588 if (auth_alg
!= ifsta
->auth_alg
||
1589 auth_transaction
!= ifsta
->auth_transaction
) {
1590 printk(KERN_DEBUG
"%s: unexpected authentication frame "
1591 "(alg=%d transaction=%d)\n",
1592 dev
->name
, auth_alg
, auth_transaction
);
1596 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1597 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
1598 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
1599 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
1601 const int num_algs
= ARRAY_SIZE(algs
);
1603 algs
[0] = algs
[1] = algs
[2] = 0xff;
1604 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1605 algs
[0] = WLAN_AUTH_OPEN
;
1606 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1607 algs
[1] = WLAN_AUTH_SHARED_KEY
;
1608 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1609 algs
[2] = WLAN_AUTH_LEAP
;
1610 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
1612 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
1616 for (i
= 0; i
< num_algs
; i
++) {
1618 if (pos
>= num_algs
)
1620 if (algs
[pos
] == ifsta
->auth_alg
||
1623 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
1624 !ieee80211_sta_wep_configured(dev
))
1626 ifsta
->auth_alg
= algs
[pos
];
1627 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
1629 dev
->name
, ifsta
->auth_alg
);
1636 switch (ifsta
->auth_alg
) {
1637 case WLAN_AUTH_OPEN
:
1638 case WLAN_AUTH_LEAP
:
1639 ieee80211_auth_completed(dev
, ifsta
);
1641 case WLAN_AUTH_SHARED_KEY
:
1642 if (ifsta
->auth_transaction
== 4)
1643 ieee80211_auth_completed(dev
, ifsta
);
1645 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
);
1651 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
1652 struct ieee80211_if_sta
*ifsta
,
1653 struct ieee80211_mgmt
*mgmt
,
1657 DECLARE_MAC_BUF(mac
);
1660 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
1661 "received from %s - ignored\n",
1662 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1666 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1667 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1668 "unknown AP (SA=%s BSSID=%s) - "
1669 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1670 print_mac(mac
, mgmt
->bssid
));
1674 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1676 printk(KERN_DEBUG
"%s: RX deauthentication from %s"
1678 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1680 if (ifsta
->flags
& IEEE80211_STA_AUTHENTICATED
) {
1681 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1684 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1685 ifsta
->state
== IEEE80211_ASSOCIATE
||
1686 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1687 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1688 mod_timer(&ifsta
->timer
, jiffies
+
1689 IEEE80211_RETRY_AUTH_INTERVAL
);
1692 ieee80211_set_disassoc(dev
, ifsta
, 1);
1693 ifsta
->flags
&= ~IEEE80211_STA_AUTHENTICATED
;
1697 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1698 struct ieee80211_if_sta
*ifsta
,
1699 struct ieee80211_mgmt
*mgmt
,
1703 DECLARE_MAC_BUF(mac
);
1706 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1707 "received from %s - ignored\n",
1708 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1712 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1713 printk(KERN_DEBUG
"%s: disassociation frame received from "
1714 "unknown AP (SA=%s BSSID=%s) - "
1715 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1716 print_mac(mac
, mgmt
->bssid
));
1720 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1722 printk(KERN_DEBUG
"%s: RX disassociation from %s"
1724 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1726 if (ifsta
->flags
& IEEE80211_STA_ASSOCIATED
)
1727 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1729 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1730 ifsta
->state
= IEEE80211_ASSOCIATE
;
1731 mod_timer(&ifsta
->timer
, jiffies
+
1732 IEEE80211_RETRY_AUTH_INTERVAL
);
1735 ieee80211_set_disassoc(dev
, ifsta
, 0);
1739 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
1740 struct ieee80211_if_sta
*ifsta
,
1741 struct ieee80211_mgmt
*mgmt
,
1745 struct ieee80211_local
*local
= sdata
->local
;
1746 struct net_device
*dev
= sdata
->dev
;
1747 struct ieee80211_supported_band
*sband
;
1748 struct sta_info
*sta
;
1749 u64 rates
, basic_rates
;
1750 u16 capab_info
, status_code
, aid
;
1751 struct ieee802_11_elems elems
;
1752 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
1755 DECLARE_MAC_BUF(mac
);
1756 bool have_higher_than_11mbit
= false;
1758 /* AssocResp and ReassocResp have identical structure, so process both
1759 * of them in this function. */
1761 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1762 printk(KERN_DEBUG
"%s: association frame received from "
1763 "%s, but not in associate state - ignored\n",
1764 dev
->name
, print_mac(mac
, mgmt
->sa
));
1769 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1770 "received from %s - ignored\n",
1771 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1775 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1776 printk(KERN_DEBUG
"%s: association frame received from "
1777 "unknown AP (SA=%s BSSID=%s) - "
1778 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1779 print_mac(mac
, mgmt
->bssid
));
1783 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1784 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1785 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1787 printk(KERN_DEBUG
"%s: RX %sssocResp from %s (capab=0x%x "
1788 "status=%d aid=%d)\n",
1789 dev
->name
, reassoc
? "Rea" : "A", print_mac(mac
, mgmt
->sa
),
1790 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
1792 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1793 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1794 dev
->name
, status_code
);
1795 /* if this was a reassociation, ensure we try a "full"
1796 * association next time. This works around some broken APs
1797 * which do not correctly reject reassociation requests. */
1798 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
1802 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1803 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1804 "set\n", dev
->name
, aid
);
1805 aid
&= ~(BIT(15) | BIT(14));
1807 pos
= mgmt
->u
.assoc_resp
.variable
;
1808 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1810 if (!elems
.supp_rates
) {
1811 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1816 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1818 ifsta
->ap_capab
= capab_info
;
1820 kfree(ifsta
->assocresp_ies
);
1821 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1822 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_KERNEL
);
1823 if (ifsta
->assocresp_ies
)
1824 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1828 /* Add STA entry for the AP */
1829 sta
= sta_info_get(local
, ifsta
->bssid
);
1831 struct ieee80211_sta_bss
*bss
;
1834 sta
= sta_info_alloc(sdata
, ifsta
->bssid
, GFP_ATOMIC
);
1836 printk(KERN_DEBUG
"%s: failed to alloc STA entry for"
1837 " the AP\n", dev
->name
);
1841 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
1842 local
->hw
.conf
.channel
->center_freq
,
1843 ifsta
->ssid
, ifsta
->ssid_len
);
1845 sta
->last_rssi
= bss
->rssi
;
1846 sta
->last_signal
= bss
->signal
;
1847 sta
->last_noise
= bss
->noise
;
1848 ieee80211_rx_bss_put(dev
, bss
);
1851 err
= sta_info_insert(sta
);
1853 printk(KERN_DEBUG
"%s: failed to insert STA entry for"
1854 " the AP (error %d)\n", dev
->name
, err
);
1855 sta_info_destroy(sta
);
1862 * FIXME: Do we really need to update the sta_info's information here?
1863 * We already know about the AP (we found it in our list) so it
1864 * should already be filled with the right info, no?
1865 * As is stands, all this is racy because typically we assume
1866 * the information that is filled in here (except flags) doesn't
1867 * change while a STA structure is alive. As such, it should move
1868 * to between the sta_info_alloc() and sta_info_insert() above.
1871 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
| WLAN_STA_ASSOC_AP
|
1872 WLAN_STA_AUTHORIZED
;
1876 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
1878 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
1879 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
1882 have_higher_than_11mbit
= true;
1884 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1885 if (sband
->bitrates
[j
].bitrate
== rate
)
1887 if (elems
.supp_rates
[i
] & 0x80)
1888 basic_rates
|= BIT(j
);
1892 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
1893 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
1896 have_higher_than_11mbit
= true;
1898 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1899 if (sband
->bitrates
[j
].bitrate
== rate
)
1901 if (elems
.ext_supp_rates
[i
] & 0x80)
1902 basic_rates
|= BIT(j
);
1906 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] = rates
;
1907 sdata
->basic_rates
= basic_rates
;
1909 /* cf. IEEE 802.11 9.2.12 */
1910 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
1911 have_higher_than_11mbit
)
1912 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
1914 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
1916 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&& elems
.wmm_param
&&
1917 local
->ops
->conf_ht
) {
1918 struct ieee80211_ht_bss_info bss_info
;
1920 ieee80211_ht_cap_ie_to_ht_info(
1921 (struct ieee80211_ht_cap
*)
1922 elems
.ht_cap_elem
, &sta
->ht_info
);
1923 ieee80211_ht_addt_info_ie_to_ht_bss_info(
1924 (struct ieee80211_ht_addt_info
*)
1925 elems
.ht_info_elem
, &bss_info
);
1926 ieee80211_hw_config_ht(local
, 1, &sta
->ht_info
, &bss_info
);
1929 rate_control_rate_init(sta
, local
);
1931 if (elems
.wmm_param
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
1932 sta
->flags
|= WLAN_STA_WME
;
1933 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
1934 elems
.wmm_param_len
);
1937 /* set AID, ieee80211_set_associated() will tell the driver */
1938 bss_conf
->aid
= aid
;
1939 ieee80211_set_associated(dev
, ifsta
, 1);
1943 ieee80211_associated(dev
, ifsta
);
1947 /* Caller must hold local->sta_bss_lock */
1948 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
1949 struct ieee80211_sta_bss
*bss
)
1951 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1954 if (bss_mesh_cfg(bss
))
1955 hash_idx
= mesh_id_hash(bss_mesh_id(bss
),
1956 bss_mesh_id_len(bss
));
1958 hash_idx
= STA_HASH(bss
->bssid
);
1960 bss
->hnext
= local
->sta_bss_hash
[hash_idx
];
1961 local
->sta_bss_hash
[hash_idx
] = bss
;
1965 /* Caller must hold local->sta_bss_lock */
1966 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
1967 struct ieee80211_sta_bss
*bss
)
1969 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1970 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
1971 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1975 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
1978 prev
->hnext
= bss
->hnext
;
1987 static struct ieee80211_sta_bss
*
1988 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
, int freq
,
1989 u8
*ssid
, u8 ssid_len
)
1991 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1992 struct ieee80211_sta_bss
*bss
;
1994 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
1997 atomic_inc(&bss
->users
);
1998 atomic_inc(&bss
->users
);
1999 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
2001 if (ssid
&& ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
2002 memcpy(bss
->ssid
, ssid
, ssid_len
);
2003 bss
->ssid_len
= ssid_len
;
2006 spin_lock_bh(&local
->sta_bss_lock
);
2007 /* TODO: order by RSSI? */
2008 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2009 __ieee80211_rx_bss_hash_add(dev
, bss
);
2010 spin_unlock_bh(&local
->sta_bss_lock
);
2014 static struct ieee80211_sta_bss
*
2015 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int freq
,
2016 u8
*ssid
, u8 ssid_len
)
2018 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2019 struct ieee80211_sta_bss
*bss
;
2021 spin_lock_bh(&local
->sta_bss_lock
);
2022 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
2024 if (!bss_mesh_cfg(bss
) &&
2025 !memcmp(bss
->bssid
, bssid
, ETH_ALEN
) &&
2026 bss
->freq
== freq
&&
2027 bss
->ssid_len
== ssid_len
&&
2028 (ssid_len
== 0 || !memcmp(bss
->ssid
, ssid
, ssid_len
))) {
2029 atomic_inc(&bss
->users
);
2034 spin_unlock_bh(&local
->sta_bss_lock
);
2038 #ifdef CONFIG_MAC80211_MESH
2039 static struct ieee80211_sta_bss
*
2040 ieee80211_rx_mesh_bss_get(struct net_device
*dev
, u8
*mesh_id
, int mesh_id_len
,
2041 u8
*mesh_cfg
, int freq
)
2043 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2044 struct ieee80211_sta_bss
*bss
;
2046 spin_lock_bh(&local
->sta_bss_lock
);
2047 bss
= local
->sta_bss_hash
[mesh_id_hash(mesh_id
, mesh_id_len
)];
2049 if (bss_mesh_cfg(bss
) &&
2050 !memcmp(bss_mesh_cfg(bss
), mesh_cfg
, MESH_CFG_CMP_LEN
) &&
2051 bss
->freq
== freq
&&
2052 mesh_id_len
== bss
->mesh_id_len
&&
2053 (mesh_id_len
== 0 || !memcmp(bss
->mesh_id
, mesh_id
,
2055 atomic_inc(&bss
->users
);
2060 spin_unlock_bh(&local
->sta_bss_lock
);
2064 static struct ieee80211_sta_bss
*
2065 ieee80211_rx_mesh_bss_add(struct net_device
*dev
, u8
*mesh_id
, int mesh_id_len
,
2066 u8
*mesh_cfg
, int freq
)
2068 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2069 struct ieee80211_sta_bss
*bss
;
2071 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2075 bss
->mesh_cfg
= kmalloc(MESH_CFG_CMP_LEN
, GFP_ATOMIC
);
2076 if (!bss
->mesh_cfg
) {
2081 if (mesh_id_len
&& mesh_id_len
<= IEEE80211_MAX_MESH_ID_LEN
) {
2082 bss
->mesh_id
= kmalloc(mesh_id_len
, GFP_ATOMIC
);
2083 if (!bss
->mesh_id
) {
2084 kfree(bss
->mesh_cfg
);
2088 memcpy(bss
->mesh_id
, mesh_id
, mesh_id_len
);
2091 atomic_inc(&bss
->users
);
2092 atomic_inc(&bss
->users
);
2093 memcpy(bss
->mesh_cfg
, mesh_cfg
, MESH_CFG_CMP_LEN
);
2094 bss
->mesh_id_len
= mesh_id_len
;
2096 spin_lock_bh(&local
->sta_bss_lock
);
2097 /* TODO: order by RSSI? */
2098 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2099 __ieee80211_rx_bss_hash_add(dev
, bss
);
2100 spin_unlock_bh(&local
->sta_bss_lock
);
2105 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
2111 kfree(bss_mesh_id(bss
));
2112 kfree(bss_mesh_cfg(bss
));
2117 static void ieee80211_rx_bss_put(struct net_device
*dev
,
2118 struct ieee80211_sta_bss
*bss
)
2120 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2121 if (!atomic_dec_and_test(&bss
->users
))
2124 spin_lock_bh(&local
->sta_bss_lock
);
2125 __ieee80211_rx_bss_hash_del(dev
, bss
);
2126 list_del(&bss
->list
);
2127 spin_unlock_bh(&local
->sta_bss_lock
);
2128 ieee80211_rx_bss_free(bss
);
2132 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
2134 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2135 spin_lock_init(&local
->sta_bss_lock
);
2136 INIT_LIST_HEAD(&local
->sta_bss_list
);
2140 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
2142 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2143 struct ieee80211_sta_bss
*bss
, *tmp
;
2145 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
2146 ieee80211_rx_bss_put(dev
, bss
);
2150 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
2151 struct ieee80211_if_sta
*ifsta
,
2152 struct ieee80211_sta_bss
*bss
)
2154 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2155 int res
, rates
, i
, j
;
2156 struct sk_buff
*skb
;
2157 struct ieee80211_mgmt
*mgmt
;
2158 struct ieee80211_tx_control control
;
2159 struct rate_selection ratesel
;
2161 struct ieee80211_sub_if_data
*sdata
;
2162 struct ieee80211_supported_band
*sband
;
2164 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2166 /* Remove possible STA entries from other IBSS networks. */
2167 sta_info_flush(local
, NULL
);
2169 if (local
->ops
->reset_tsf
) {
2170 /* Reset own TSF to allow time synchronization work. */
2171 local
->ops
->reset_tsf(local_to_hw(local
));
2173 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
2174 res
= ieee80211_if_config(dev
);
2178 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2180 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2181 sdata
->drop_unencrypted
= bss
->capability
&
2182 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
2184 res
= ieee80211_set_freq(local
, bss
->freq
);
2186 if (local
->oper_channel
->flags
& IEEE80211_CHAN_NO_IBSS
) {
2187 printk(KERN_DEBUG
"%s: IBSS not allowed on frequency "
2188 "%d MHz\n", dev
->name
, local
->oper_channel
->center_freq
);
2192 /* Set beacon template */
2193 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 400);
2198 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2200 mgmt
= (struct ieee80211_mgmt
*)
2201 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2202 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2203 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2204 IEEE80211_STYPE_BEACON
);
2205 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2206 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2207 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2208 mgmt
->u
.beacon
.beacon_int
=
2209 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2210 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2212 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2213 *pos
++ = WLAN_EID_SSID
;
2214 *pos
++ = ifsta
->ssid_len
;
2215 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2217 rates
= bss
->supp_rates_len
;
2220 pos
= skb_put(skb
, 2 + rates
);
2221 *pos
++ = WLAN_EID_SUPP_RATES
;
2223 memcpy(pos
, bss
->supp_rates
, rates
);
2225 if (bss
->band
== IEEE80211_BAND_2GHZ
) {
2226 pos
= skb_put(skb
, 2 + 1);
2227 *pos
++ = WLAN_EID_DS_PARAMS
;
2229 *pos
++ = ieee80211_frequency_to_channel(bss
->freq
);
2232 pos
= skb_put(skb
, 2 + 2);
2233 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2235 /* FIX: set ATIM window based on scan results */
2239 if (bss
->supp_rates_len
> 8) {
2240 rates
= bss
->supp_rates_len
- 8;
2241 pos
= skb_put(skb
, 2 + rates
);
2242 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2244 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2247 memset(&control
, 0, sizeof(control
));
2248 rate_control_get_rate(dev
, sband
, skb
, &ratesel
);
2249 if (!ratesel
.rate
) {
2250 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2251 "for IBSS beacon\n", dev
->name
);
2254 control
.vif
= &sdata
->vif
;
2255 control
.tx_rate
= ratesel
.rate
;
2256 if (sdata
->bss_conf
.use_short_preamble
&&
2257 ratesel
.rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
2258 control
.flags
|= IEEE80211_TXCTL_SHORT_PREAMBLE
;
2259 control
.antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
2260 control
.flags
|= IEEE80211_TXCTL_NO_ACK
;
2261 control
.retry_limit
= 1;
2263 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2264 if (ifsta
->probe_resp
) {
2265 mgmt
= (struct ieee80211_mgmt
*)
2266 ifsta
->probe_resp
->data
;
2267 mgmt
->frame_control
=
2268 IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2269 IEEE80211_STYPE_PROBE_RESP
);
2271 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2272 "template for IBSS\n", dev
->name
);
2275 if (local
->ops
->beacon_update
&&
2276 local
->ops
->beacon_update(local_to_hw(local
),
2277 skb
, &control
) == 0) {
2278 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2279 "template\n", dev
->name
);
2284 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2285 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2286 int bitrate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2287 for (j
= 0; j
< sband
->n_bitrates
; j
++)
2288 if (sband
->bitrates
[j
].bitrate
== bitrate
)
2291 ifsta
->supp_rates_bits
[local
->hw
.conf
.channel
->band
] = rates
;
2295 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2296 "template\n", dev
->name
);
2300 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2301 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2303 ieee80211_rx_bss_put(dev
, bss
);
2308 u64
ieee80211_sta_get_rates(struct ieee80211_local
*local
,
2309 struct ieee802_11_elems
*elems
,
2310 enum ieee80211_band band
)
2312 struct ieee80211_supported_band
*sband
;
2313 struct ieee80211_rate
*bitrates
;
2317 sband
= local
->hw
.wiphy
->bands
[band
];
2321 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2324 bitrates
= sband
->bitrates
;
2325 num_rates
= sband
->n_bitrates
;
2327 for (i
= 0; i
< elems
->supp_rates_len
+
2328 elems
->ext_supp_rates_len
; i
++) {
2331 if (i
< elems
->supp_rates_len
)
2332 rate
= elems
->supp_rates
[i
];
2333 else if (elems
->ext_supp_rates
)
2334 rate
= elems
->ext_supp_rates
2335 [i
- elems
->supp_rates_len
];
2336 own_rate
= 5 * (rate
& 0x7f);
2337 for (j
= 0; j
< num_rates
; j
++)
2338 if (bitrates
[j
].bitrate
== own_rate
)
2339 supp_rates
|= BIT(j
);
2345 static void ieee80211_rx_bss_info(struct net_device
*dev
,
2346 struct ieee80211_mgmt
*mgmt
,
2348 struct ieee80211_rx_status
*rx_status
,
2351 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2352 struct ieee802_11_elems elems
;
2355 struct ieee80211_sta_bss
*bss
;
2356 struct sta_info
*sta
;
2357 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2358 u64 beacon_timestamp
, rx_timestamp
;
2359 DECLARE_MAC_BUF(mac
);
2360 DECLARE_MAC_BUF(mac2
);
2362 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
2363 return; /* ignore ProbeResp to foreign address */
2366 printk(KERN_DEBUG
"%s: RX %s from %s to %s\n",
2367 dev
->name
, beacon
? "Beacon" : "Probe Response",
2368 print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
));
2371 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2375 beacon_timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
2376 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2378 if (ieee80211_vif_is_mesh(&sdata
->vif
) && elems
.mesh_id
&&
2379 elems
.mesh_config
&& mesh_matches_local(&elems
, dev
)) {
2380 u64 rates
= ieee80211_sta_get_rates(local
, &elems
,
2383 mesh_neighbour_update(mgmt
->sa
, rates
, dev
,
2384 mesh_peer_accepts_plinks(&elems
, dev
));
2389 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& elems
.supp_rates
&&
2390 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0 &&
2391 (sta
= sta_info_get(local
, mgmt
->sa
))) {
2393 u64 supp_rates
= ieee80211_sta_get_rates(local
, &elems
,
2396 prev_rates
= sta
->supp_rates
[rx_status
->band
];
2397 sta
->supp_rates
[rx_status
->band
] &= supp_rates
;
2398 if (sta
->supp_rates
[rx_status
->band
] == 0) {
2399 /* No matching rates - this should not really happen.
2400 * Make sure that at least one rate is marked
2401 * supported to avoid issues with TX rate ctrl. */
2402 sta
->supp_rates
[rx_status
->band
] =
2403 sdata
->u
.sta
.supp_rates_bits
[rx_status
->band
];
2405 if (sta
->supp_rates
[rx_status
->band
] != prev_rates
) {
2406 printk(KERN_DEBUG
"%s: updated supp_rates set for "
2407 "%s based on beacon info (0x%llx & 0x%llx -> "
2409 dev
->name
, print_mac(mac
, sta
->addr
),
2410 (unsigned long long) prev_rates
,
2411 (unsigned long long) supp_rates
,
2412 (unsigned long long) sta
->supp_rates
[rx_status
->band
]);
2418 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
2419 freq
= ieee80211_channel_to_frequency(elems
.ds_params
[0]);
2421 freq
= rx_status
->freq
;
2423 #ifdef CONFIG_MAC80211_MESH
2424 if (elems
.mesh_config
)
2425 bss
= ieee80211_rx_mesh_bss_get(dev
, elems
.mesh_id
,
2426 elems
.mesh_id_len
, elems
.mesh_config
, freq
);
2429 bss
= ieee80211_rx_bss_get(dev
, mgmt
->bssid
, freq
,
2430 elems
.ssid
, elems
.ssid_len
);
2432 #ifdef CONFIG_MAC80211_MESH
2433 if (elems
.mesh_config
)
2434 bss
= ieee80211_rx_mesh_bss_add(dev
, elems
.mesh_id
,
2435 elems
.mesh_id_len
, elems
.mesh_config
, freq
);
2438 bss
= ieee80211_rx_bss_add(dev
, mgmt
->bssid
, freq
,
2439 elems
.ssid
, elems
.ssid_len
);
2444 /* TODO: order by RSSI? */
2445 spin_lock_bh(&local
->sta_bss_lock
);
2446 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
2447 spin_unlock_bh(&local
->sta_bss_lock
);
2451 bss
->band
= rx_status
->band
;
2453 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
2454 bss
->probe_resp
&& beacon
) {
2456 * Do not allow beacon to override data from Probe Response. */
2457 ieee80211_rx_bss_put(dev
, bss
);
2461 /* save the ERP value so that it is available at association time */
2462 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
2463 bss
->erp_value
= elems
.erp_info
[0];
2464 bss
->has_erp_value
= 1;
2467 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
2468 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2470 bss
->supp_rates_len
= 0;
2471 if (elems
.supp_rates
) {
2472 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2473 if (clen
> elems
.supp_rates_len
)
2474 clen
= elems
.supp_rates_len
;
2475 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
.supp_rates
,
2477 bss
->supp_rates_len
+= clen
;
2479 if (elems
.ext_supp_rates
) {
2480 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2481 if (clen
> elems
.ext_supp_rates_len
)
2482 clen
= elems
.ext_supp_rates_len
;
2483 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
2484 elems
.ext_supp_rates
, clen
);
2485 bss
->supp_rates_len
+= clen
;
2489 (!bss
->wpa_ie
|| bss
->wpa_ie_len
!= elems
.wpa_len
||
2490 memcmp(bss
->wpa_ie
, elems
.wpa
, elems
.wpa_len
))) {
2492 bss
->wpa_ie
= kmalloc(elems
.wpa_len
+ 2, GFP_ATOMIC
);
2494 memcpy(bss
->wpa_ie
, elems
.wpa
- 2, elems
.wpa_len
+ 2);
2495 bss
->wpa_ie_len
= elems
.wpa_len
+ 2;
2497 bss
->wpa_ie_len
= 0;
2498 } else if (!elems
.wpa
&& bss
->wpa_ie
) {
2501 bss
->wpa_ie_len
= 0;
2505 (!bss
->rsn_ie
|| bss
->rsn_ie_len
!= elems
.rsn_len
||
2506 memcmp(bss
->rsn_ie
, elems
.rsn
, elems
.rsn_len
))) {
2508 bss
->rsn_ie
= kmalloc(elems
.rsn_len
+ 2, GFP_ATOMIC
);
2510 memcpy(bss
->rsn_ie
, elems
.rsn
- 2, elems
.rsn_len
+ 2);
2511 bss
->rsn_ie_len
= elems
.rsn_len
+ 2;
2513 bss
->rsn_ie_len
= 0;
2514 } else if (!elems
.rsn
&& bss
->rsn_ie
) {
2517 bss
->rsn_ie_len
= 0;
2520 if (elems
.wmm_param
&&
2521 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_param_len
||
2522 memcmp(bss
->wmm_ie
, elems
.wmm_param
, elems
.wmm_param_len
))) {
2524 bss
->wmm_ie
= kmalloc(elems
.wmm_param_len
+ 2, GFP_ATOMIC
);
2526 memcpy(bss
->wmm_ie
, elems
.wmm_param
- 2,
2527 elems
.wmm_param_len
+ 2);
2528 bss
->wmm_ie_len
= elems
.wmm_param_len
+ 2;
2530 bss
->wmm_ie_len
= 0;
2531 } else if (!elems
.wmm_param
&& bss
->wmm_ie
) {
2534 bss
->wmm_ie_len
= 0;
2536 if (elems
.ht_cap_elem
&&
2537 (!bss
->ht_ie
|| bss
->ht_ie_len
!= elems
.ht_cap_elem_len
||
2538 memcmp(bss
->ht_ie
, elems
.ht_cap_elem
, elems
.ht_cap_elem_len
))) {
2540 bss
->ht_ie
= kmalloc(elems
.ht_cap_elem_len
+ 2, GFP_ATOMIC
);
2542 memcpy(bss
->ht_ie
, elems
.ht_cap_elem
- 2,
2543 elems
.ht_cap_elem_len
+ 2);
2544 bss
->ht_ie_len
= elems
.ht_cap_elem_len
+ 2;
2547 } else if (!elems
.ht_cap_elem
&& bss
->ht_ie
) {
2553 bss
->timestamp
= beacon_timestamp
;
2554 bss
->last_update
= jiffies
;
2555 bss
->rssi
= rx_status
->ssi
;
2556 bss
->signal
= rx_status
->signal
;
2557 bss
->noise
= rx_status
->noise
;
2561 /* check if we need to merge IBSS */
2562 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
2563 !local
->sta_sw_scanning
&& !local
->sta_hw_scanning
&&
2564 bss
->capability
& WLAN_CAPABILITY_IBSS
&&
2565 bss
->freq
== local
->oper_channel
->center_freq
&&
2566 elems
.ssid_len
== sdata
->u
.sta
.ssid_len
&&
2567 memcmp(elems
.ssid
, sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
) == 0) {
2568 if (rx_status
->flag
& RX_FLAG_TSFT
) {
2569 /* in order for correct IBSS merging we need mactime
2571 * since mactime is defined as the time the first data
2572 * symbol of the frame hits the PHY, and the timestamp
2573 * of the beacon is defined as "the time that the data
2574 * symbol containing the first bit of the timestamp is
2575 * transmitted to the PHY plus the transmitting STA’s
2576 * delays through its local PHY from the MAC-PHY
2577 * interface to its interface with the WM"
2578 * (802.11 11.1.2) - equals the time this bit arrives at
2579 * the receiver - we have to take into account the
2580 * offset between the two.
2581 * e.g: at 1 MBit that means mactime is 192 usec earlier
2582 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2584 int rate
= local
->hw
.wiphy
->bands
[rx_status
->band
]->
2585 bitrates
[rx_status
->rate_idx
].bitrate
;
2586 rx_timestamp
= rx_status
->mactime
+ (24 * 8 * 10 / rate
);
2587 } else if (local
&& local
->ops
&& local
->ops
->get_tsf
)
2588 /* second best option: get current TSF */
2589 rx_timestamp
= local
->ops
->get_tsf(local_to_hw(local
));
2591 /* can't merge without knowing the TSF */
2592 rx_timestamp
= -1LLU;
2593 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2594 printk(KERN_DEBUG
"RX beacon SA=%s BSSID="
2595 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2596 print_mac(mac
, mgmt
->sa
),
2597 print_mac(mac2
, mgmt
->bssid
),
2598 (unsigned long long)rx_timestamp
,
2599 (unsigned long long)beacon_timestamp
,
2600 (unsigned long long)(rx_timestamp
- beacon_timestamp
),
2602 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2603 if (beacon_timestamp
> rx_timestamp
) {
2604 #ifndef CONFIG_MAC80211_IBSS_DEBUG
2605 if (net_ratelimit())
2607 printk(KERN_DEBUG
"%s: beacon TSF higher than "
2608 "local TSF - IBSS merge with BSSID %s\n",
2609 dev
->name
, print_mac(mac
, mgmt
->bssid
));
2610 ieee80211_sta_join_ibss(dev
, &sdata
->u
.sta
, bss
);
2611 ieee80211_ibss_add_sta(dev
, NULL
,
2612 mgmt
->bssid
, mgmt
->sa
);
2616 ieee80211_rx_bss_put(dev
, bss
);
2620 static void ieee80211_rx_mgmt_probe_resp(struct net_device
*dev
,
2621 struct ieee80211_mgmt
*mgmt
,
2623 struct ieee80211_rx_status
*rx_status
)
2625 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 0);
2629 static void ieee80211_rx_mgmt_beacon(struct net_device
*dev
,
2630 struct ieee80211_mgmt
*mgmt
,
2632 struct ieee80211_rx_status
*rx_status
)
2634 struct ieee80211_sub_if_data
*sdata
;
2635 struct ieee80211_if_sta
*ifsta
;
2637 struct ieee802_11_elems elems
;
2638 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2639 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
2642 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 1);
2644 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2645 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
2647 ifsta
= &sdata
->u
.sta
;
2649 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
) ||
2650 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
2653 /* Process beacon from the current BSS */
2654 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2658 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2660 if (elems
.erp_info
&& elems
.erp_info_len
>= 1)
2661 changed
|= ieee80211_handle_erp_ie(sdata
, elems
.erp_info
[0]);
2663 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&&
2664 elems
.wmm_param
&& local
->ops
->conf_ht
&&
2665 conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
2666 struct ieee80211_ht_bss_info bss_info
;
2668 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2669 (struct ieee80211_ht_addt_info
*)
2670 elems
.ht_info_elem
, &bss_info
);
2671 /* check if AP changed bss inforamation */
2672 if ((conf
->ht_bss_conf
.primary_channel
!=
2673 bss_info
.primary_channel
) ||
2674 (conf
->ht_bss_conf
.bss_cap
!= bss_info
.bss_cap
) ||
2675 (conf
->ht_bss_conf
.bss_op_mode
!= bss_info
.bss_op_mode
))
2676 ieee80211_hw_config_ht(local
, 1, &conf
->ht_conf
,
2680 if (elems
.wmm_param
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
2681 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2682 elems
.wmm_param_len
);
2685 ieee80211_bss_info_change_notify(sdata
, changed
);
2689 static void ieee80211_rx_mgmt_probe_req(struct net_device
*dev
,
2690 struct ieee80211_if_sta
*ifsta
,
2691 struct ieee80211_mgmt
*mgmt
,
2693 struct ieee80211_rx_status
*rx_status
)
2695 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2696 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2698 struct sk_buff
*skb
;
2699 struct ieee80211_mgmt
*resp
;
2701 DECLARE_MAC_BUF(mac
);
2702 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2703 DECLARE_MAC_BUF(mac2
);
2704 DECLARE_MAC_BUF(mac3
);
2707 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
||
2708 ifsta
->state
!= IEEE80211_IBSS_JOINED
||
2709 len
< 24 + 2 || !ifsta
->probe_resp
)
2712 if (local
->ops
->tx_last_beacon
)
2713 tx_last_beacon
= local
->ops
->tx_last_beacon(local_to_hw(local
));
2717 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2718 printk(KERN_DEBUG
"%s: RX ProbeReq SA=%s DA=%s BSSID="
2719 "%s (tx_last_beacon=%d)\n",
2720 dev
->name
, print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
),
2721 print_mac(mac3
, mgmt
->bssid
), tx_last_beacon
);
2722 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2724 if (!tx_last_beacon
)
2727 if (memcmp(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
) != 0 &&
2728 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
2731 end
= ((u8
*) mgmt
) + len
;
2732 pos
= mgmt
->u
.probe_req
.variable
;
2733 if (pos
[0] != WLAN_EID_SSID
||
2734 pos
+ 2 + pos
[1] > end
) {
2735 if (net_ratelimit()) {
2736 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
2738 dev
->name
, print_mac(mac
, mgmt
->sa
));
2743 (pos
[1] != ifsta
->ssid_len
||
2744 memcmp(pos
+ 2, ifsta
->ssid
, ifsta
->ssid_len
) != 0)) {
2745 /* Ignore ProbeReq for foreign SSID */
2749 /* Reply with ProbeResp */
2750 skb
= skb_copy(ifsta
->probe_resp
, GFP_KERNEL
);
2754 resp
= (struct ieee80211_mgmt
*) skb
->data
;
2755 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
2756 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2757 printk(KERN_DEBUG
"%s: Sending ProbeResp to %s\n",
2758 dev
->name
, print_mac(mac
, resp
->da
));
2759 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2760 ieee80211_sta_tx(dev
, skb
, 0);
2763 static void ieee80211_rx_mgmt_action(struct net_device
*dev
,
2764 struct ieee80211_if_sta
*ifsta
,
2765 struct ieee80211_mgmt
*mgmt
,
2767 struct ieee80211_rx_status
*rx_status
)
2769 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2771 if (len
< IEEE80211_MIN_ACTION_SIZE
)
2774 switch (mgmt
->u
.action
.category
) {
2775 case WLAN_CATEGORY_BACK
:
2776 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
2777 case WLAN_ACTION_ADDBA_REQ
:
2778 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2779 sizeof(mgmt
->u
.action
.u
.addba_req
)))
2781 ieee80211_sta_process_addba_request(dev
, mgmt
, len
);
2783 case WLAN_ACTION_ADDBA_RESP
:
2784 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2785 sizeof(mgmt
->u
.action
.u
.addba_resp
)))
2787 ieee80211_sta_process_addba_resp(dev
, mgmt
, len
);
2789 case WLAN_ACTION_DELBA
:
2790 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2791 sizeof(mgmt
->u
.action
.u
.delba
)))
2793 ieee80211_sta_process_delba(dev
, mgmt
, len
);
2796 if (net_ratelimit())
2797 printk(KERN_DEBUG
"%s: Rx unknown A-MPDU action\n",
2802 case PLINK_CATEGORY
:
2803 if (ieee80211_vif_is_mesh(&sdata
->vif
))
2804 mesh_rx_plink_frame(dev
, mgmt
, len
, rx_status
);
2806 case MESH_PATH_SEL_CATEGORY
:
2807 if (ieee80211_vif_is_mesh(&sdata
->vif
))
2808 mesh_rx_path_sel_frame(dev
, mgmt
, len
);
2811 if (net_ratelimit())
2812 printk(KERN_DEBUG
"%s: Rx unknown action frame - "
2813 "category=%d\n", dev
->name
, mgmt
->u
.action
.category
);
2818 void ieee80211_sta_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
2819 struct ieee80211_rx_status
*rx_status
)
2821 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2822 struct ieee80211_sub_if_data
*sdata
;
2823 struct ieee80211_if_sta
*ifsta
;
2824 struct ieee80211_mgmt
*mgmt
;
2830 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2831 ifsta
= &sdata
->u
.sta
;
2833 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2834 fc
= le16_to_cpu(mgmt
->frame_control
);
2836 switch (fc
& IEEE80211_FCTL_STYPE
) {
2837 case IEEE80211_STYPE_PROBE_REQ
:
2838 case IEEE80211_STYPE_PROBE_RESP
:
2839 case IEEE80211_STYPE_BEACON
:
2840 case IEEE80211_STYPE_ACTION
:
2841 memcpy(skb
->cb
, rx_status
, sizeof(*rx_status
));
2842 case IEEE80211_STYPE_AUTH
:
2843 case IEEE80211_STYPE_ASSOC_RESP
:
2844 case IEEE80211_STYPE_REASSOC_RESP
:
2845 case IEEE80211_STYPE_DEAUTH
:
2846 case IEEE80211_STYPE_DISASSOC
:
2847 skb_queue_tail(&ifsta
->skb_queue
, skb
);
2848 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2851 printk(KERN_DEBUG
"%s: received unknown management frame - "
2852 "stype=%d\n", dev
->name
,
2853 (fc
& IEEE80211_FCTL_STYPE
) >> 4);
2862 static void ieee80211_sta_rx_queued_mgmt(struct net_device
*dev
,
2863 struct sk_buff
*skb
)
2865 struct ieee80211_rx_status
*rx_status
;
2866 struct ieee80211_sub_if_data
*sdata
;
2867 struct ieee80211_if_sta
*ifsta
;
2868 struct ieee80211_mgmt
*mgmt
;
2871 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2872 ifsta
= &sdata
->u
.sta
;
2874 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
2875 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2876 fc
= le16_to_cpu(mgmt
->frame_control
);
2878 switch (fc
& IEEE80211_FCTL_STYPE
) {
2879 case IEEE80211_STYPE_PROBE_REQ
:
2880 ieee80211_rx_mgmt_probe_req(dev
, ifsta
, mgmt
, skb
->len
,
2883 case IEEE80211_STYPE_PROBE_RESP
:
2884 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
, skb
->len
, rx_status
);
2886 case IEEE80211_STYPE_BEACON
:
2887 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
, rx_status
);
2889 case IEEE80211_STYPE_AUTH
:
2890 ieee80211_rx_mgmt_auth(dev
, ifsta
, mgmt
, skb
->len
);
2892 case IEEE80211_STYPE_ASSOC_RESP
:
2893 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 0);
2895 case IEEE80211_STYPE_REASSOC_RESP
:
2896 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 1);
2898 case IEEE80211_STYPE_DEAUTH
:
2899 ieee80211_rx_mgmt_deauth(dev
, ifsta
, mgmt
, skb
->len
);
2901 case IEEE80211_STYPE_DISASSOC
:
2902 ieee80211_rx_mgmt_disassoc(dev
, ifsta
, mgmt
, skb
->len
);
2904 case IEEE80211_STYPE_ACTION
:
2905 ieee80211_rx_mgmt_action(dev
, ifsta
, mgmt
, skb
->len
, rx_status
);
2914 ieee80211_sta_rx_scan(struct net_device
*dev
, struct sk_buff
*skb
,
2915 struct ieee80211_rx_status
*rx_status
)
2917 struct ieee80211_mgmt
*mgmt
;
2921 return RX_DROP_UNUSABLE
;
2923 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2924 fc
= le16_to_cpu(mgmt
->frame_control
);
2926 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
)
2930 return RX_DROP_MONITOR
;
2932 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
2933 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
) {
2934 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
,
2935 skb
->len
, rx_status
);
2938 } else if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
) {
2939 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
,
2949 static int ieee80211_sta_active_ibss(struct net_device
*dev
)
2951 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2953 struct sta_info
*sta
;
2954 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2958 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
2959 if (sta
->sdata
== sdata
&&
2960 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
2973 static void ieee80211_sta_expire(struct net_device
*dev
, unsigned long exp_time
)
2975 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2976 struct sta_info
*sta
, *tmp
;
2977 LIST_HEAD(tmp_list
);
2978 DECLARE_MAC_BUF(mac
);
2979 unsigned long flags
;
2981 spin_lock_irqsave(&local
->sta_lock
, flags
);
2982 list_for_each_entry_safe(sta
, tmp
, &local
->sta_list
, list
)
2983 if (time_after(jiffies
, sta
->last_rx
+ exp_time
)) {
2984 printk(KERN_DEBUG
"%s: expiring inactive STA %s\n",
2985 dev
->name
, print_mac(mac
, sta
->addr
));
2986 sta_info_unlink(&sta
);
2988 list_add(&sta
->list
, &tmp_list
);
2990 spin_unlock_irqrestore(&local
->sta_lock
, flags
);
2995 list_for_each_entry_safe(sta
, tmp
, &tmp_list
, list
)
2996 sta_info_destroy(sta
);
3001 static void ieee80211_sta_merge_ibss(struct net_device
*dev
,
3002 struct ieee80211_if_sta
*ifsta
)
3004 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
3006 ieee80211_sta_expire(dev
, IEEE80211_IBSS_INACTIVITY_LIMIT
);
3007 if (ieee80211_sta_active_ibss(dev
))
3010 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
3011 "IBSS networks with same SSID (merge)\n", dev
->name
);
3012 ieee80211_sta_req_scan(dev
, ifsta
->ssid
, ifsta
->ssid_len
);
3016 #ifdef CONFIG_MAC80211_MESH
3017 static void ieee80211_mesh_housekeeping(struct net_device
*dev
,
3018 struct ieee80211_if_sta
*ifsta
)
3020 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3023 ieee80211_sta_expire(dev
, IEEE80211_MESH_PEER_INACTIVITY_LIMIT
);
3024 mesh_path_expire(dev
);
3026 free_plinks
= mesh_plink_availables(sdata
);
3027 if (free_plinks
!= sdata
->u
.sta
.accepting_plinks
)
3028 ieee80211_if_config_beacon(dev
);
3030 mod_timer(&ifsta
->timer
, jiffies
+
3031 IEEE80211_MESH_HOUSEKEEPING_INTERVAL
);
3035 void ieee80211_start_mesh(struct net_device
*dev
)
3037 struct ieee80211_if_sta
*ifsta
;
3038 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3039 ifsta
= &sdata
->u
.sta
;
3040 ifsta
->state
= IEEE80211_MESH_UP
;
3041 ieee80211_sta_timer((unsigned long)sdata
);
3046 void ieee80211_sta_timer(unsigned long data
)
3048 struct ieee80211_sub_if_data
*sdata
=
3049 (struct ieee80211_sub_if_data
*) data
;
3050 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3051 struct ieee80211_local
*local
= wdev_priv(&sdata
->wdev
);
3053 set_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3054 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3057 void ieee80211_sta_work(struct work_struct
*work
)
3059 struct ieee80211_sub_if_data
*sdata
=
3060 container_of(work
, struct ieee80211_sub_if_data
, u
.sta
.work
);
3061 struct net_device
*dev
= sdata
->dev
;
3062 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3063 struct ieee80211_if_sta
*ifsta
;
3064 struct sk_buff
*skb
;
3066 if (!netif_running(dev
))
3069 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
3072 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
3073 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
3074 sdata
->vif
.type
!= IEEE80211_IF_TYPE_MESH_POINT
) {
3075 printk(KERN_DEBUG
"%s: ieee80211_sta_work: non-STA interface "
3076 "(type=%d)\n", dev
->name
, sdata
->vif
.type
);
3079 ifsta
= &sdata
->u
.sta
;
3081 while ((skb
= skb_dequeue(&ifsta
->skb_queue
)))
3082 ieee80211_sta_rx_queued_mgmt(dev
, skb
);
3084 #ifdef CONFIG_MAC80211_MESH
3085 if (ifsta
->preq_queue_len
&&
3087 ifsta
->last_preq
+ msecs_to_jiffies(ifsta
->mshcfg
.dot11MeshHWMPpreqMinInterval
)))
3088 mesh_path_start_discovery(dev
);
3091 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
3092 ifsta
->state
!= IEEE80211_ASSOCIATE
&&
3093 test_and_clear_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
)) {
3094 if (ifsta
->scan_ssid_len
)
3095 ieee80211_sta_start_scan(dev
, ifsta
->scan_ssid
, ifsta
->scan_ssid_len
);
3097 ieee80211_sta_start_scan(dev
, NULL
, 0);
3101 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
)) {
3102 if (ieee80211_sta_config_auth(dev
, ifsta
))
3104 clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3105 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
))
3108 switch (ifsta
->state
) {
3109 case IEEE80211_DISABLED
:
3111 case IEEE80211_AUTHENTICATE
:
3112 ieee80211_authenticate(dev
, ifsta
);
3114 case IEEE80211_ASSOCIATE
:
3115 ieee80211_associate(dev
, ifsta
);
3117 case IEEE80211_ASSOCIATED
:
3118 ieee80211_associated(dev
, ifsta
);
3120 case IEEE80211_IBSS_SEARCH
:
3121 ieee80211_sta_find_ibss(dev
, ifsta
);
3123 case IEEE80211_IBSS_JOINED
:
3124 ieee80211_sta_merge_ibss(dev
, ifsta
);
3126 #ifdef CONFIG_MAC80211_MESH
3127 case IEEE80211_MESH_UP
:
3128 ieee80211_mesh_housekeeping(dev
, ifsta
);
3132 printk(KERN_DEBUG
"ieee80211_sta_work: Unknown state %d\n",
3137 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
3138 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
3139 "mixed-cell disabled - disassociate\n", dev
->name
);
3141 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
3142 ieee80211_set_disassoc(dev
, ifsta
, 0);
3147 static void ieee80211_sta_reset_auth(struct net_device
*dev
,
3148 struct ieee80211_if_sta
*ifsta
)
3150 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3152 if (local
->ops
->reset_tsf
) {
3153 /* Reset own TSF to allow time synchronization work. */
3154 local
->ops
->reset_tsf(local_to_hw(local
));
3157 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
3160 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
3161 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3162 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
3163 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
3164 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
3165 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
3167 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3168 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
3170 ifsta
->auth_transaction
= -1;
3171 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
3172 ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
3173 netif_carrier_off(dev
);
3177 void ieee80211_sta_req_auth(struct net_device
*dev
,
3178 struct ieee80211_if_sta
*ifsta
)
3180 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3181 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3183 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3186 if ((ifsta
->flags
& (IEEE80211_STA_BSSID_SET
|
3187 IEEE80211_STA_AUTO_BSSID_SEL
)) &&
3188 (ifsta
->flags
& (IEEE80211_STA_SSID_SET
|
3189 IEEE80211_STA_AUTO_SSID_SEL
))) {
3190 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3191 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3195 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta
*ifsta
,
3196 const char *ssid
, int ssid_len
)
3198 int tmp
, hidden_ssid
;
3200 if (ssid_len
== ifsta
->ssid_len
&&
3201 !memcmp(ifsta
->ssid
, ssid
, ssid_len
))
3204 if (ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
)
3210 if (ssid
[tmp
] != '\0') {
3216 if (hidden_ssid
&& ifsta
->ssid_len
== ssid_len
)
3219 if (ssid_len
== 1 && ssid
[0] == ' ')
3225 static int ieee80211_sta_config_auth(struct net_device
*dev
,
3226 struct ieee80211_if_sta
*ifsta
)
3228 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3229 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3230 struct ieee80211_sta_bss
*bss
, *selected
= NULL
;
3231 int top_rssi
= 0, freq
;
3233 if (!(ifsta
->flags
& (IEEE80211_STA_AUTO_SSID_SEL
|
3234 IEEE80211_STA_AUTO_BSSID_SEL
| IEEE80211_STA_AUTO_CHANNEL_SEL
))) {
3235 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3236 ieee80211_sta_reset_auth(dev
, ifsta
);
3240 spin_lock_bh(&local
->sta_bss_lock
);
3241 freq
= local
->oper_channel
->center_freq
;
3242 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3243 if (!(bss
->capability
& WLAN_CAPABILITY_ESS
))
3246 if (!!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
) ^
3247 !!sdata
->default_key
)
3250 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_CHANNEL_SEL
) &&
3254 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
) &&
3255 memcmp(bss
->bssid
, ifsta
->bssid
, ETH_ALEN
))
3258 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
) &&
3259 !ieee80211_sta_match_ssid(ifsta
, bss
->ssid
, bss
->ssid_len
))
3262 if (!selected
|| top_rssi
< bss
->rssi
) {
3264 top_rssi
= bss
->rssi
;
3268 atomic_inc(&selected
->users
);
3269 spin_unlock_bh(&local
->sta_bss_lock
);
3272 ieee80211_set_freq(local
, selected
->freq
);
3273 if (!(ifsta
->flags
& IEEE80211_STA_SSID_SET
))
3274 ieee80211_sta_set_ssid(dev
, selected
->ssid
,
3275 selected
->ssid_len
);
3276 ieee80211_sta_set_bssid(dev
, selected
->bssid
);
3277 ieee80211_rx_bss_put(dev
, selected
);
3278 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3279 ieee80211_sta_reset_auth(dev
, ifsta
);
3282 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
) {
3283 if (ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
)
3284 ieee80211_sta_start_scan(dev
, NULL
, 0);
3286 ieee80211_sta_start_scan(dev
, ifsta
->ssid
,
3288 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3289 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3291 ifsta
->state
= IEEE80211_DISABLED
;
3297 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
3298 struct ieee80211_if_sta
*ifsta
)
3300 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3301 struct ieee80211_sta_bss
*bss
;
3302 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3303 struct ieee80211_supported_band
*sband
;
3304 u8 bssid
[ETH_ALEN
], *pos
;
3306 DECLARE_MAC_BUF(mac
);
3309 /* Easier testing, use fixed BSSID. */
3310 memset(bssid
, 0xfe, ETH_ALEN
);
3312 /* Generate random, not broadcast, locally administered BSSID. Mix in
3313 * own MAC address to make sure that devices that do not have proper
3314 * random number generator get different BSSID. */
3315 get_random_bytes(bssid
, ETH_ALEN
);
3316 for (i
= 0; i
< ETH_ALEN
; i
++)
3317 bssid
[i
] ^= dev
->dev_addr
[i
];
3322 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID %s\n",
3323 dev
->name
, print_mac(mac
, bssid
));
3325 bss
= ieee80211_rx_bss_add(dev
, bssid
,
3326 local
->hw
.conf
.channel
->center_freq
,
3327 sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
);
3331 bss
->band
= local
->hw
.conf
.channel
->band
;
3332 sband
= local
->hw
.wiphy
->bands
[bss
->band
];
3334 if (local
->hw
.conf
.beacon_int
== 0)
3335 local
->hw
.conf
.beacon_int
= 10000;
3336 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
3337 bss
->last_update
= jiffies
;
3338 bss
->capability
= WLAN_CAPABILITY_IBSS
;
3339 if (sdata
->default_key
) {
3340 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
3342 sdata
->drop_unencrypted
= 0;
3343 bss
->supp_rates_len
= sband
->n_bitrates
;
3344 pos
= bss
->supp_rates
;
3345 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
3346 int rate
= sband
->bitrates
[i
].bitrate
;
3347 *pos
++ = (u8
) (rate
/ 5);
3350 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3354 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
3355 struct ieee80211_if_sta
*ifsta
)
3357 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3358 struct ieee80211_sta_bss
*bss
;
3362 DECLARE_MAC_BUF(mac
);
3363 DECLARE_MAC_BUF(mac2
);
3365 if (ifsta
->ssid_len
== 0)
3368 active_ibss
= ieee80211_sta_active_ibss(dev
);
3369 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3370 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
3371 dev
->name
, active_ibss
);
3372 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3373 spin_lock_bh(&local
->sta_bss_lock
);
3374 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3375 if (ifsta
->ssid_len
!= bss
->ssid_len
||
3376 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
3377 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
3379 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3380 printk(KERN_DEBUG
" bssid=%s found\n",
3381 print_mac(mac
, bss
->bssid
));
3382 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3383 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
3385 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
3388 spin_unlock_bh(&local
->sta_bss_lock
);
3390 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3391 printk(KERN_DEBUG
" sta_find_ibss: selected %s current "
3392 "%s\n", print_mac(mac
, bssid
), print_mac(mac2
, ifsta
->bssid
));
3393 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3394 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
3395 (bss
= ieee80211_rx_bss_get(dev
, bssid
,
3396 local
->hw
.conf
.channel
->center_freq
,
3397 ifsta
->ssid
, ifsta
->ssid_len
))) {
3398 printk(KERN_DEBUG
"%s: Selected IBSS BSSID %s"
3399 " based on configured SSID\n",
3400 dev
->name
, print_mac(mac
, bssid
));
3401 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3403 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3404 printk(KERN_DEBUG
" did not try to join ibss\n");
3405 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3407 /* Selected IBSS not found in current scan results - try to scan */
3408 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3409 !ieee80211_sta_active_ibss(dev
)) {
3410 mod_timer(&ifsta
->timer
, jiffies
+
3411 IEEE80211_IBSS_MERGE_INTERVAL
);
3412 } else if (time_after(jiffies
, local
->last_scan_completed
+
3413 IEEE80211_SCAN_INTERVAL
)) {
3414 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
3415 "join\n", dev
->name
);
3416 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
3418 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
3419 int interval
= IEEE80211_SCAN_INTERVAL
;
3421 if (time_after(jiffies
, ifsta
->ibss_join_req
+
3422 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
3423 if ((ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) &&
3424 (!(local
->oper_channel
->flags
&
3425 IEEE80211_CHAN_NO_IBSS
)))
3426 return ieee80211_sta_create_ibss(dev
, ifsta
);
3427 if (ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) {
3428 printk(KERN_DEBUG
"%s: IBSS not allowed on"
3429 " %d MHz\n", dev
->name
,
3430 local
->hw
.conf
.channel
->center_freq
);
3433 /* No IBSS found - decrease scan interval and continue
3435 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
3438 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3439 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
3447 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
3449 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3450 struct ieee80211_if_sta
*ifsta
;
3451 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3453 if (len
> IEEE80211_MAX_SSID_LEN
)
3456 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
3458 if (local
->ops
->conf_tx
) {
3459 struct ieee80211_tx_queue_params qparam
;
3462 memset(&qparam
, 0, sizeof(qparam
));
3466 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
3467 !(sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
))
3472 qparam
.cw_max
= 1023;
3475 for (i
= IEEE80211_TX_QUEUE_DATA0
; i
< NUM_TX_DATA_QUEUES
; i
++)
3476 local
->ops
->conf_tx(local_to_hw(local
),
3477 i
+ IEEE80211_TX_QUEUE_DATA0
,
3480 /* IBSS uses different parameters for Beacon sending */
3484 local
->ops
->conf_tx(local_to_hw(local
),
3485 IEEE80211_TX_QUEUE_BEACON
, &qparam
);
3488 ifsta
= &sdata
->u
.sta
;
3490 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
3491 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
3492 memcpy(ifsta
->ssid
, ssid
, len
);
3493 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
3494 ifsta
->ssid_len
= len
;
3497 ifsta
->flags
|= IEEE80211_STA_SSID_SET
;
3499 ifsta
->flags
&= ~IEEE80211_STA_SSID_SET
;
3500 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3501 !(ifsta
->flags
& IEEE80211_STA_BSSID_SET
)) {
3502 ifsta
->ibss_join_req
= jiffies
;
3503 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3504 return ieee80211_sta_find_ibss(dev
, ifsta
);
3510 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
3512 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3513 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3514 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
3515 *len
= ifsta
->ssid_len
;
3520 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
3522 struct ieee80211_sub_if_data
*sdata
;
3523 struct ieee80211_if_sta
*ifsta
;
3526 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3527 ifsta
= &sdata
->u
.sta
;
3529 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
3530 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
3531 res
= ieee80211_if_config(dev
);
3533 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
3534 "the low-level driver\n", dev
->name
);
3539 if (is_valid_ether_addr(bssid
))
3540 ifsta
->flags
|= IEEE80211_STA_BSSID_SET
;
3542 ifsta
->flags
&= ~IEEE80211_STA_BSSID_SET
;
3548 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
3549 struct ieee80211_sub_if_data
*sdata
,
3552 struct sk_buff
*skb
;
3553 struct ieee80211_hdr
*nullfunc
;
3556 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
3558 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
3559 "frame\n", sdata
->dev
->name
);
3562 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3564 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
3565 memset(nullfunc
, 0, 24);
3566 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
3567 IEEE80211_FCTL_TODS
;
3569 fc
|= IEEE80211_FCTL_PM
;
3570 nullfunc
->frame_control
= cpu_to_le16(fc
);
3571 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3572 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
3573 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3575 ieee80211_sta_tx(sdata
->dev
, skb
, 0);
3579 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
3581 struct ieee80211_local
*local
= hw_to_local(hw
);
3582 struct net_device
*dev
= local
->scan_dev
;
3583 struct ieee80211_sub_if_data
*sdata
;
3584 union iwreq_data wrqu
;
3586 local
->last_scan_completed
= jiffies
;
3587 memset(&wrqu
, 0, sizeof(wrqu
));
3588 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
3590 if (local
->sta_hw_scanning
) {
3591 local
->sta_hw_scanning
= 0;
3595 local
->sta_sw_scanning
= 0;
3596 if (ieee80211_hw_config(local
))
3597 printk(KERN_DEBUG
"%s: failed to restore operational "
3598 "channel after scan\n", dev
->name
);
3601 netif_tx_lock_bh(local
->mdev
);
3602 local
->filter_flags
&= ~FIF_BCN_PRBRESP_PROMISC
;
3603 local
->ops
->configure_filter(local_to_hw(local
),
3604 FIF_BCN_PRBRESP_PROMISC
,
3605 &local
->filter_flags
,
3606 local
->mdev
->mc_count
,
3607 local
->mdev
->mc_list
);
3609 netif_tx_unlock_bh(local
->mdev
);
3612 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3614 /* No need to wake the master device. */
3615 if (sdata
->dev
== local
->mdev
)
3618 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
) {
3619 if (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
)
3620 ieee80211_send_nullfunc(local
, sdata
, 0);
3621 ieee80211_sta_timer((unsigned long)sdata
);
3624 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_MESH_POINT
)
3625 ieee80211_sta_timer((unsigned long)sdata
);
3627 netif_wake_queue(sdata
->dev
);
3632 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3633 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
3634 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3635 if (!(ifsta
->flags
& IEEE80211_STA_BSSID_SET
) ||
3636 (!ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3637 !ieee80211_sta_active_ibss(dev
)))
3638 ieee80211_sta_find_ibss(dev
, ifsta
);
3641 EXPORT_SYMBOL(ieee80211_scan_completed
);
3643 void ieee80211_sta_scan_work(struct work_struct
*work
)
3645 struct ieee80211_local
*local
=
3646 container_of(work
, struct ieee80211_local
, scan_work
.work
);
3647 struct net_device
*dev
= local
->scan_dev
;
3648 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3649 struct ieee80211_supported_band
*sband
;
3650 struct ieee80211_channel
*chan
;
3652 unsigned long next_delay
= 0;
3654 if (!local
->sta_sw_scanning
)
3657 switch (local
->scan_state
) {
3658 case SCAN_SET_CHANNEL
:
3660 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3661 * after we successfully scanned the last channel of the last
3662 * band (and the last band is supported by the hw)
3664 if (local
->scan_band
< IEEE80211_NUM_BANDS
)
3665 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3670 * If we are at an unsupported band and have more bands
3671 * left to scan, advance to the next supported one.
3673 while (!sband
&& local
->scan_band
< IEEE80211_NUM_BANDS
- 1) {
3675 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3676 local
->scan_channel_idx
= 0;
3679 /* if no more bands/channels left, complete scan */
3680 if (!sband
|| local
->scan_channel_idx
>= sband
->n_channels
) {
3681 ieee80211_scan_completed(local_to_hw(local
));
3685 chan
= &sband
->channels
[local
->scan_channel_idx
];
3687 if (chan
->flags
& IEEE80211_CHAN_DISABLED
||
3688 (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3689 chan
->flags
& IEEE80211_CHAN_NO_IBSS
))
3693 local
->scan_channel
= chan
;
3694 if (ieee80211_hw_config(local
)) {
3695 printk(KERN_DEBUG
"%s: failed to set freq to "
3696 "%d MHz for scan\n", dev
->name
,
3702 /* advance state machine to next channel/band */
3703 local
->scan_channel_idx
++;
3704 if (local
->scan_channel_idx
>= sband
->n_channels
) {
3706 * scan_band may end up == IEEE80211_NUM_BANDS, but
3707 * we'll catch that case above and complete the scan
3708 * if that is the case.
3711 local
->scan_channel_idx
= 0;
3717 next_delay
= IEEE80211_PROBE_DELAY
+
3718 usecs_to_jiffies(local
->hw
.channel_change_time
);
3719 local
->scan_state
= SCAN_SEND_PROBE
;
3721 case SCAN_SEND_PROBE
:
3722 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
3723 local
->scan_state
= SCAN_SET_CHANNEL
;
3725 if (local
->scan_channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
3727 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
3728 local
->scan_ssid_len
);
3729 next_delay
= IEEE80211_CHANNEL_TIME
;
3733 if (local
->sta_sw_scanning
)
3734 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3739 static int ieee80211_sta_start_scan(struct net_device
*dev
,
3740 u8
*ssid
, size_t ssid_len
)
3742 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3743 struct ieee80211_sub_if_data
*sdata
;
3745 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
3748 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3749 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3752 * ScanType: ACTIVE, PASSIVE
3753 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3754 * a Probe frame during active scanning
3756 * MinChannelTime (>= ProbeDelay), in TU
3757 * MaxChannelTime: (>= MinChannelTime), in TU
3760 /* MLME-SCAN.confirm
3762 * ResultCode: SUCCESS, INVALID_PARAMETERS
3765 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3766 if (local
->scan_dev
== dev
)
3771 if (local
->ops
->hw_scan
) {
3772 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
3775 local
->sta_hw_scanning
= 1;
3776 local
->scan_dev
= dev
;
3781 local
->sta_sw_scanning
= 1;
3784 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3786 /* Don't stop the master interface, otherwise we can't transmit
3788 if (sdata
->dev
== local
->mdev
)
3791 netif_stop_queue(sdata
->dev
);
3792 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3793 (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
))
3794 ieee80211_send_nullfunc(local
, sdata
, 1);
3799 local
->scan_ssid_len
= ssid_len
;
3800 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
3802 local
->scan_ssid_len
= 0;
3803 local
->scan_state
= SCAN_SET_CHANNEL
;
3804 local
->scan_channel_idx
= 0;
3805 local
->scan_band
= IEEE80211_BAND_2GHZ
;
3806 local
->scan_dev
= dev
;
3808 netif_tx_lock_bh(local
->mdev
);
3809 local
->filter_flags
|= FIF_BCN_PRBRESP_PROMISC
;
3810 local
->ops
->configure_filter(local_to_hw(local
),
3811 FIF_BCN_PRBRESP_PROMISC
,
3812 &local
->filter_flags
,
3813 local
->mdev
->mc_count
,
3814 local
->mdev
->mc_list
);
3815 netif_tx_unlock_bh(local
->mdev
);
3817 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3818 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3819 IEEE80211_CHANNEL_TIME
);
3825 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
3827 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3828 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3829 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3831 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3832 return ieee80211_sta_start_scan(dev
, ssid
, ssid_len
);
3834 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3835 if (local
->scan_dev
== dev
)
3840 ifsta
->scan_ssid_len
= ssid_len
;
3842 memcpy(ifsta
->scan_ssid
, ssid
, ssid_len
);
3843 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
3844 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3849 ieee80211_sta_scan_result(struct net_device
*dev
,
3850 struct ieee80211_sta_bss
*bss
,
3851 char *current_ev
, char *end_buf
)
3853 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3854 struct iw_event iwe
;
3856 if (time_after(jiffies
,
3857 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
3860 memset(&iwe
, 0, sizeof(iwe
));
3861 iwe
.cmd
= SIOCGIWAP
;
3862 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3863 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
3864 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3867 memset(&iwe
, 0, sizeof(iwe
));
3868 iwe
.cmd
= SIOCGIWESSID
;
3869 if (bss_mesh_cfg(bss
)) {
3870 iwe
.u
.data
.length
= bss_mesh_id_len(bss
);
3871 iwe
.u
.data
.flags
= 1;
3872 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3875 iwe
.u
.data
.length
= bss
->ssid_len
;
3876 iwe
.u
.data
.flags
= 1;
3877 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3881 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
3882 || bss_mesh_cfg(bss
)) {
3883 memset(&iwe
, 0, sizeof(iwe
));
3884 iwe
.cmd
= SIOCGIWMODE
;
3885 if (bss_mesh_cfg(bss
))
3886 iwe
.u
.mode
= IW_MODE_MESH
;
3887 else if (bss
->capability
& WLAN_CAPABILITY_ESS
)
3888 iwe
.u
.mode
= IW_MODE_MASTER
;
3890 iwe
.u
.mode
= IW_MODE_ADHOC
;
3891 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3895 memset(&iwe
, 0, sizeof(iwe
));
3896 iwe
.cmd
= SIOCGIWFREQ
;
3897 iwe
.u
.freq
.m
= bss
->freq
;
3899 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3902 memset(&iwe
, 0, sizeof(iwe
));
3903 iwe
.cmd
= SIOCGIWFREQ
;
3904 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->freq
);
3906 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3909 memset(&iwe
, 0, sizeof(iwe
));
3911 iwe
.u
.qual
.qual
= bss
->signal
;
3912 iwe
.u
.qual
.level
= bss
->rssi
;
3913 iwe
.u
.qual
.noise
= bss
->noise
;
3914 iwe
.u
.qual
.updated
= local
->wstats_flags
;
3915 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3918 memset(&iwe
, 0, sizeof(iwe
));
3919 iwe
.cmd
= SIOCGIWENCODE
;
3920 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
3921 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
3923 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
3924 iwe
.u
.data
.length
= 0;
3925 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
3927 if (bss
&& bss
->wpa_ie
) {
3928 memset(&iwe
, 0, sizeof(iwe
));
3929 iwe
.cmd
= IWEVGENIE
;
3930 iwe
.u
.data
.length
= bss
->wpa_ie_len
;
3931 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3935 if (bss
&& bss
->rsn_ie
) {
3936 memset(&iwe
, 0, sizeof(iwe
));
3937 iwe
.cmd
= IWEVGENIE
;
3938 iwe
.u
.data
.length
= bss
->rsn_ie_len
;
3939 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3943 if (bss
&& bss
->supp_rates_len
> 0) {
3944 /* display all supported rates in readable format */
3945 char *p
= current_ev
+ IW_EV_LCP_LEN
;
3948 memset(&iwe
, 0, sizeof(iwe
));
3949 iwe
.cmd
= SIOCGIWRATE
;
3950 /* Those two flags are ignored... */
3951 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
3953 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
3954 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
3956 p
= iwe_stream_add_value(current_ev
, p
,
3957 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
3964 buf
= kmalloc(30, GFP_ATOMIC
);
3966 memset(&iwe
, 0, sizeof(iwe
));
3967 iwe
.cmd
= IWEVCUSTOM
;
3968 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
3969 iwe
.u
.data
.length
= strlen(buf
);
3970 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
3976 if (bss_mesh_cfg(bss
)) {
3978 u8
*cfg
= bss_mesh_cfg(bss
);
3979 buf
= kmalloc(50, GFP_ATOMIC
);
3981 memset(&iwe
, 0, sizeof(iwe
));
3982 iwe
.cmd
= IWEVCUSTOM
;
3983 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
3984 iwe
.u
.data
.length
= strlen(buf
);
3985 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
3987 sprintf(buf
, "Path Selection Protocol ID: "
3988 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
3990 iwe
.u
.data
.length
= strlen(buf
);
3991 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
3993 sprintf(buf
, "Path Selection Metric ID: "
3994 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
3996 iwe
.u
.data
.length
= strlen(buf
);
3997 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
3999 sprintf(buf
, "Congestion Control Mode ID: "
4000 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
4002 iwe
.u
.data
.length
= strlen(buf
);
4003 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4005 sprintf(buf
, "Channel Precedence: "
4006 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
4008 iwe
.u
.data
.length
= strlen(buf
);
4009 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4019 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
4021 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4022 char *current_ev
= buf
;
4023 char *end_buf
= buf
+ len
;
4024 struct ieee80211_sta_bss
*bss
;
4026 spin_lock_bh(&local
->sta_bss_lock
);
4027 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
4028 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
4029 spin_unlock_bh(&local
->sta_bss_lock
);
4032 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
4035 spin_unlock_bh(&local
->sta_bss_lock
);
4036 return current_ev
- buf
;
4040 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
4042 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4043 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4044 kfree(ifsta
->extra_ie
);
4046 ifsta
->extra_ie
= NULL
;
4047 ifsta
->extra_ie_len
= 0;
4050 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
4051 if (!ifsta
->extra_ie
) {
4052 ifsta
->extra_ie_len
= 0;
4055 memcpy(ifsta
->extra_ie
, ie
, len
);
4056 ifsta
->extra_ie_len
= len
;
4061 struct sta_info
* ieee80211_ibss_add_sta(struct net_device
*dev
,
4062 struct sk_buff
*skb
, u8
*bssid
,
4065 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4066 struct sta_info
*sta
;
4067 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4068 DECLARE_MAC_BUF(mac
);
4070 /* TODO: Could consider removing the least recently used entry and
4071 * allow new one to be added. */
4072 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
4073 if (net_ratelimit()) {
4074 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
4075 "entry %s\n", dev
->name
, print_mac(mac
, addr
));
4080 printk(KERN_DEBUG
"%s: Adding new IBSS station %s (dev=%s)\n",
4081 wiphy_name(local
->hw
.wiphy
), print_mac(mac
, addr
), dev
->name
);
4083 sta
= sta_info_alloc(sdata
, addr
, GFP_ATOMIC
);
4087 sta
->flags
|= WLAN_STA_AUTHORIZED
;
4089 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] =
4090 sdata
->u
.sta
.supp_rates_bits
[local
->hw
.conf
.channel
->band
];
4092 rate_control_rate_init(sta
, local
);
4094 if (sta_info_insert(sta
)) {
4095 sta_info_destroy(sta
);
4103 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
4105 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4106 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4108 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
4111 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
4112 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
4115 ieee80211_send_deauth(dev
, ifsta
, reason
);
4116 ieee80211_set_disassoc(dev
, ifsta
, 1);
4121 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
4123 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4124 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4126 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
4129 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
4132 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
))
4135 ieee80211_send_disassoc(dev
, ifsta
, reason
);
4136 ieee80211_set_disassoc(dev
, ifsta
, 0);