2 * BSS client mode implementation
3 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 * order BSS list by RSSI(?) ("quality of AP")
16 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
19 #include <linux/delay.h>
20 #include <linux/if_ether.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/wireless.h>
25 #include <linux/random.h>
26 #include <linux/etherdevice.h>
27 #include <net/iw_handler.h>
28 #include <asm/types.h>
30 #include <net/mac80211.h>
31 #include "ieee80211_i.h"
32 #include "ieee80211_rate.h"
33 #include "ieee80211_led.h"
35 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
36 #define IEEE80211_AUTH_MAX_TRIES 3
37 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
38 #define IEEE80211_ASSOC_MAX_TRIES 3
39 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
40 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
41 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
42 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
43 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
44 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
46 #define IEEE80211_PROBE_DELAY (HZ / 33)
47 #define IEEE80211_CHANNEL_TIME (HZ / 33)
48 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
49 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
50 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
51 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
53 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
56 #define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
58 #define ERP_INFO_USE_PROTECTION BIT(1)
60 /* mgmt header + 1 byte action code */
61 #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
63 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
64 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
65 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
66 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
67 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
69 /* next values represent the buffer size for A-MPDU frame.
70 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
71 #define IEEE80211_MIN_AMPDU_BUF 0x8
72 #define IEEE80211_MAX_AMPDU_BUF 0x40
74 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
75 u8
*ssid
, size_t ssid_len
);
76 static struct ieee80211_sta_bss
*
77 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int channel
,
78 u8
*ssid
, u8 ssid_len
);
79 static void ieee80211_rx_bss_put(struct net_device
*dev
,
80 struct ieee80211_sta_bss
*bss
);
81 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
82 struct ieee80211_if_sta
*ifsta
);
83 static int ieee80211_sta_wep_configured(struct net_device
*dev
);
84 static int ieee80211_sta_start_scan(struct net_device
*dev
,
85 u8
*ssid
, size_t ssid_len
);
86 static int ieee80211_sta_config_auth(struct net_device
*dev
,
87 struct ieee80211_if_sta
*ifsta
);
90 /* Parsed Information Elements */
91 struct ieee802_11_elems
{
109 /* length of them, respectively */
121 u8 ext_supp_rates_len
;
128 static void ieee802_11_parse_elems(u8
*start
, size_t len
,
129 struct ieee802_11_elems
*elems
)
134 memset(elems
, 0, sizeof(*elems
));
149 elems
->ssid_len
= elen
;
151 case WLAN_EID_SUPP_RATES
:
152 elems
->supp_rates
= pos
;
153 elems
->supp_rates_len
= elen
;
155 case WLAN_EID_FH_PARAMS
:
156 elems
->fh_params
= pos
;
157 elems
->fh_params_len
= elen
;
159 case WLAN_EID_DS_PARAMS
:
160 elems
->ds_params
= pos
;
161 elems
->ds_params_len
= elen
;
163 case WLAN_EID_CF_PARAMS
:
164 elems
->cf_params
= pos
;
165 elems
->cf_params_len
= elen
;
169 elems
->tim_len
= elen
;
171 case WLAN_EID_IBSS_PARAMS
:
172 elems
->ibss_params
= pos
;
173 elems
->ibss_params_len
= elen
;
175 case WLAN_EID_CHALLENGE
:
176 elems
->challenge
= pos
;
177 elems
->challenge_len
= elen
;
180 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
182 /* Microsoft OUI (00:50:F2) */
184 /* OUI Type 1 - WPA IE */
186 elems
->wpa_len
= elen
;
187 } else if (elen
>= 5 && pos
[3] == 2) {
189 elems
->wmm_info
= pos
;
190 elems
->wmm_info_len
= elen
;
191 } else if (pos
[4] == 1) {
192 elems
->wmm_param
= pos
;
193 elems
->wmm_param_len
= elen
;
200 elems
->rsn_len
= elen
;
202 case WLAN_EID_ERP_INFO
:
203 elems
->erp_info
= pos
;
204 elems
->erp_info_len
= elen
;
206 case WLAN_EID_EXT_SUPP_RATES
:
207 elems
->ext_supp_rates
= pos
;
208 elems
->ext_supp_rates_len
= elen
;
210 case WLAN_EID_HT_CAPABILITY
:
211 elems
->ht_cap_elem
= pos
;
212 elems
->ht_cap_elem_len
= elen
;
214 case WLAN_EID_HT_EXTRA_INFO
:
215 elems
->ht_info_elem
= pos
;
216 elems
->ht_info_elem_len
= elen
;
228 static int ecw2cw(int ecw
)
238 static void ieee80211_sta_wmm_params(struct net_device
*dev
,
239 struct ieee80211_if_sta
*ifsta
,
240 u8
*wmm_param
, size_t wmm_param_len
)
242 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
243 struct ieee80211_tx_queue_params params
;
248 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
250 count
= wmm_param
[6] & 0x0f;
251 if (count
== ifsta
->wmm_last_param_set
)
253 ifsta
->wmm_last_param_set
= count
;
256 left
= wmm_param_len
- 8;
258 memset(¶ms
, 0, sizeof(params
));
260 if (!local
->ops
->conf_tx
)
264 for (; left
>= 4; left
-= 4, pos
+= 4) {
265 int aci
= (pos
[0] >> 5) & 0x03;
266 int acm
= (pos
[0] >> 4) & 0x01;
271 queue
= IEEE80211_TX_QUEUE_DATA3
;
273 local
->wmm_acm
|= BIT(0) | BIT(3);
277 queue
= IEEE80211_TX_QUEUE_DATA1
;
279 local
->wmm_acm
|= BIT(4) | BIT(5);
283 queue
= IEEE80211_TX_QUEUE_DATA0
;
285 local
->wmm_acm
|= BIT(6) | BIT(7);
290 queue
= IEEE80211_TX_QUEUE_DATA2
;
292 local
->wmm_acm
|= BIT(1) | BIT(2);
297 params
.aifs
= pos
[0] & 0x0f;
298 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
299 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
300 /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
301 params
.burst_time
= (pos
[2] | (pos
[3] << 8)) * 32 / 100;
302 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
303 "cWmin=%d cWmax=%d burst=%d\n",
304 dev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
305 params
.cw_max
, params
.burst_time
);
306 /* TODO: handle ACM (block TX, fallback to next lowest allowed
308 if (local
->ops
->conf_tx(local_to_hw(local
), queue
, ¶ms
)) {
309 printk(KERN_DEBUG
"%s: failed to set TX queue "
310 "parameters for queue %d\n", dev
->name
, queue
);
316 static u32
ieee80211_handle_erp_ie(struct ieee80211_sub_if_data
*sdata
,
319 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
320 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
321 bool use_protection
= (erp_value
& WLAN_ERP_USE_PROTECTION
) != 0;
322 bool preamble_mode
= (erp_value
& WLAN_ERP_BARKER_PREAMBLE
) != 0;
323 DECLARE_MAC_BUF(mac
);
326 if (use_protection
!= bss_conf
->use_cts_prot
) {
327 if (net_ratelimit()) {
328 printk(KERN_DEBUG
"%s: CTS protection %s (BSSID="
331 use_protection
? "enabled" : "disabled",
332 print_mac(mac
, ifsta
->bssid
));
334 bss_conf
->use_cts_prot
= use_protection
;
335 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
338 if (preamble_mode
!= bss_conf
->use_short_preamble
) {
339 if (net_ratelimit()) {
340 printk(KERN_DEBUG
"%s: switched to %s barker preamble"
343 (preamble_mode
== WLAN_ERP_PREAMBLE_SHORT
) ?
345 print_mac(mac
, ifsta
->bssid
));
347 bss_conf
->use_short_preamble
= preamble_mode
;
348 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
354 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap
*ht_cap_ie
,
355 struct ieee80211_ht_info
*ht_info
)
361 memset(ht_info
, 0, sizeof(*ht_info
));
364 u8 ampdu_info
= ht_cap_ie
->ampdu_params_info
;
366 ht_info
->ht_supported
= 1;
367 ht_info
->cap
= le16_to_cpu(ht_cap_ie
->cap_info
);
368 ht_info
->ampdu_factor
=
369 ampdu_info
& IEEE80211_HT_CAP_AMPDU_FACTOR
;
370 ht_info
->ampdu_density
=
371 (ampdu_info
& IEEE80211_HT_CAP_AMPDU_DENSITY
) >> 2;
372 memcpy(ht_info
->supp_mcs_set
, ht_cap_ie
->supp_mcs_set
, 16);
374 ht_info
->ht_supported
= 0;
379 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
380 struct ieee80211_ht_addt_info
*ht_add_info_ie
,
381 struct ieee80211_ht_bss_info
*bss_info
)
383 if (bss_info
== NULL
)
386 memset(bss_info
, 0, sizeof(*bss_info
));
388 if (ht_add_info_ie
) {
390 op_mode
= le16_to_cpu(ht_add_info_ie
->operation_mode
);
392 bss_info
->primary_channel
= ht_add_info_ie
->control_chan
;
393 bss_info
->bss_cap
= ht_add_info_ie
->ht_param
;
394 bss_info
->bss_op_mode
= (u8
)(op_mode
& 0xff);
400 static void ieee80211_sta_send_associnfo(struct net_device
*dev
,
401 struct ieee80211_if_sta
*ifsta
)
406 union iwreq_data wrqu
;
408 if (!ifsta
->assocreq_ies
&& !ifsta
->assocresp_ies
)
411 buf
= kmalloc(50 + 2 * (ifsta
->assocreq_ies_len
+
412 ifsta
->assocresp_ies_len
), GFP_KERNEL
);
416 len
= sprintf(buf
, "ASSOCINFO(");
417 if (ifsta
->assocreq_ies
) {
418 len
+= sprintf(buf
+ len
, "ReqIEs=");
419 for (i
= 0; i
< ifsta
->assocreq_ies_len
; i
++) {
420 len
+= sprintf(buf
+ len
, "%02x",
421 ifsta
->assocreq_ies
[i
]);
424 if (ifsta
->assocresp_ies
) {
425 if (ifsta
->assocreq_ies
)
426 len
+= sprintf(buf
+ len
, " ");
427 len
+= sprintf(buf
+ len
, "RespIEs=");
428 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
429 len
+= sprintf(buf
+ len
, "%02x",
430 ifsta
->assocresp_ies
[i
]);
433 len
+= sprintf(buf
+ len
, ")");
435 if (len
> IW_CUSTOM_MAX
) {
436 len
= sprintf(buf
, "ASSOCRESPIE=");
437 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
438 len
+= sprintf(buf
+ len
, "%02x",
439 ifsta
->assocresp_ies
[i
]);
443 memset(&wrqu
, 0, sizeof(wrqu
));
444 wrqu
.data
.length
= len
;
445 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
451 static void ieee80211_set_associated(struct net_device
*dev
,
452 struct ieee80211_if_sta
*ifsta
,
455 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
456 struct ieee80211_local
*local
= sdata
->local
;
457 union iwreq_data wrqu
;
458 u32 changed
= BSS_CHANGED_ASSOC
;
461 struct ieee80211_sta_bss
*bss
;
463 ifsta
->flags
|= IEEE80211_STA_ASSOCIATED
;
465 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
468 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
469 local
->hw
.conf
.channel
,
470 ifsta
->ssid
, ifsta
->ssid_len
);
472 if (bss
->has_erp_value
)
473 changed
|= ieee80211_handle_erp_ie(
474 sdata
, bss
->erp_value
);
475 ieee80211_rx_bss_put(dev
, bss
);
478 netif_carrier_on(dev
);
479 ifsta
->flags
|= IEEE80211_STA_PREV_BSSID_SET
;
480 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
481 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
482 ieee80211_sta_send_associnfo(dev
, ifsta
);
484 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
486 netif_carrier_off(dev
);
487 ieee80211_reset_erp_info(dev
);
488 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
490 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
491 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
492 ifsta
->last_probe
= jiffies
;
493 ieee80211_led_assoc(local
, assoc
);
495 ieee80211_bss_info_change_notify(sdata
, changed
);
498 static void ieee80211_set_disassoc(struct net_device
*dev
,
499 struct ieee80211_if_sta
*ifsta
, int deauth
)
502 ifsta
->auth_tries
= 0;
503 ifsta
->assoc_tries
= 0;
504 ieee80211_set_associated(dev
, ifsta
, 0);
507 static void ieee80211_sta_tx(struct net_device
*dev
, struct sk_buff
*skb
,
510 struct ieee80211_sub_if_data
*sdata
;
511 struct ieee80211_tx_packet_data
*pkt_data
;
513 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
514 skb
->dev
= sdata
->local
->mdev
;
515 skb_set_mac_header(skb
, 0);
516 skb_set_network_header(skb
, 0);
517 skb_set_transport_header(skb
, 0);
519 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
520 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
521 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
523 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
529 static void ieee80211_send_auth(struct net_device
*dev
,
530 struct ieee80211_if_sta
*ifsta
,
531 int transaction
, u8
*extra
, size_t extra_len
,
534 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
536 struct ieee80211_mgmt
*mgmt
;
538 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
539 sizeof(*mgmt
) + 6 + extra_len
);
541 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
542 "frame\n", dev
->name
);
545 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
547 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
548 memset(mgmt
, 0, 24 + 6);
549 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
550 IEEE80211_STYPE_AUTH
);
552 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
553 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
554 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
555 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
556 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
557 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
558 ifsta
->auth_transaction
= transaction
+ 1;
559 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
561 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
563 ieee80211_sta_tx(dev
, skb
, encrypt
);
567 static void ieee80211_authenticate(struct net_device
*dev
,
568 struct ieee80211_if_sta
*ifsta
)
570 DECLARE_MAC_BUF(mac
);
573 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
574 printk(KERN_DEBUG
"%s: authentication with AP %s"
576 dev
->name
, print_mac(mac
, ifsta
->bssid
));
577 ifsta
->state
= IEEE80211_DISABLED
;
581 ifsta
->state
= IEEE80211_AUTHENTICATE
;
582 printk(KERN_DEBUG
"%s: authenticate with AP %s\n",
583 dev
->name
, print_mac(mac
, ifsta
->bssid
));
585 ieee80211_send_auth(dev
, ifsta
, 1, NULL
, 0, 0);
587 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_AUTH_TIMEOUT
);
591 static void ieee80211_send_assoc(struct net_device
*dev
,
592 struct ieee80211_if_sta
*ifsta
)
594 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
595 struct ieee80211_hw_mode
*mode
;
597 struct ieee80211_mgmt
*mgmt
;
601 struct ieee80211_sta_bss
*bss
;
604 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
605 sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
608 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
609 "frame\n", dev
->name
);
612 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
614 mode
= local
->oper_hw_mode
;
615 capab
= ifsta
->capab
;
616 if (mode
->mode
== MODE_IEEE80211G
) {
617 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
|
618 WLAN_CAPABILITY_SHORT_PREAMBLE
;
620 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
, local
->hw
.conf
.channel
,
621 ifsta
->ssid
, ifsta
->ssid_len
);
623 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
624 capab
|= WLAN_CAPABILITY_PRIVACY
;
628 ieee80211_rx_bss_put(dev
, bss
);
631 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
633 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
634 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
635 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
637 if (ifsta
->flags
& IEEE80211_STA_PREV_BSSID_SET
) {
639 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
640 IEEE80211_STYPE_REASSOC_REQ
);
641 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
642 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
643 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
647 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
648 IEEE80211_STYPE_ASSOC_REQ
);
649 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
650 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
654 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
655 *pos
++ = WLAN_EID_SSID
;
656 *pos
++ = ifsta
->ssid_len
;
657 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
659 len
= mode
->num_rates
;
662 pos
= skb_put(skb
, len
+ 2);
663 *pos
++ = WLAN_EID_SUPP_RATES
;
665 for (i
= 0; i
< len
; i
++) {
666 int rate
= mode
->rates
[i
].rate
;
667 *pos
++ = (u8
) (rate
/ 5);
670 if (mode
->num_rates
> len
) {
671 pos
= skb_put(skb
, mode
->num_rates
- len
+ 2);
672 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
673 *pos
++ = mode
->num_rates
- len
;
674 for (i
= len
; i
< mode
->num_rates
; i
++) {
675 int rate
= mode
->rates
[i
].rate
;
676 *pos
++ = (u8
) (rate
/ 5);
680 if (ifsta
->extra_ie
) {
681 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
682 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
685 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
686 pos
= skb_put(skb
, 9);
687 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
688 *pos
++ = 7; /* len */
689 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
692 *pos
++ = 2; /* WME */
693 *pos
++ = 0; /* WME info */
694 *pos
++ = 1; /* WME ver */
697 /* wmm support is a must to HT */
698 if (wmm
&& mode
->ht_info
.ht_supported
) {
699 __le16 tmp
= cpu_to_le16(mode
->ht_info
.cap
);
700 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
)+2);
701 *pos
++ = WLAN_EID_HT_CAPABILITY
;
702 *pos
++ = sizeof(struct ieee80211_ht_cap
);
703 memset(pos
, 0, sizeof(struct ieee80211_ht_cap
));
704 memcpy(pos
, &tmp
, sizeof(u16
));
706 *pos
++ = (mode
->ht_info
.ampdu_factor
|
707 (mode
->ht_info
.ampdu_density
<< 2));
708 memcpy(pos
, mode
->ht_info
.supp_mcs_set
, 16);
711 kfree(ifsta
->assocreq_ies
);
712 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
713 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_KERNEL
);
714 if (ifsta
->assocreq_ies
)
715 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
717 ieee80211_sta_tx(dev
, skb
, 0);
721 static void ieee80211_send_deauth(struct net_device
*dev
,
722 struct ieee80211_if_sta
*ifsta
, u16 reason
)
724 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
726 struct ieee80211_mgmt
*mgmt
;
728 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
730 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
731 "frame\n", dev
->name
);
734 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
736 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
738 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
739 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
740 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
741 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
742 IEEE80211_STYPE_DEAUTH
);
744 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
746 ieee80211_sta_tx(dev
, skb
, 0);
750 static void ieee80211_send_disassoc(struct net_device
*dev
,
751 struct ieee80211_if_sta
*ifsta
, u16 reason
)
753 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
755 struct ieee80211_mgmt
*mgmt
;
757 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
759 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
760 "frame\n", dev
->name
);
763 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
765 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
767 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
768 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
769 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
770 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
771 IEEE80211_STYPE_DISASSOC
);
773 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
775 ieee80211_sta_tx(dev
, skb
, 0);
779 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
780 struct ieee80211_if_sta
*ifsta
)
782 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
783 struct ieee80211_sta_bss
*bss
;
788 if (!ifsta
|| (ifsta
->flags
& IEEE80211_STA_MIXED_CELL
))
791 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
, local
->hw
.conf
.channel
,
792 ifsta
->ssid
, ifsta
->ssid_len
);
796 bss_privacy
= !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
797 wep_privacy
= !!ieee80211_sta_wep_configured(dev
);
798 privacy_invoked
= !!(ifsta
->flags
& IEEE80211_STA_PRIVACY_INVOKED
);
800 ieee80211_rx_bss_put(dev
, bss
);
802 if ((bss_privacy
== wep_privacy
) || (bss_privacy
== privacy_invoked
))
809 static void ieee80211_associate(struct net_device
*dev
,
810 struct ieee80211_if_sta
*ifsta
)
812 DECLARE_MAC_BUF(mac
);
814 ifsta
->assoc_tries
++;
815 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
816 printk(KERN_DEBUG
"%s: association with AP %s"
818 dev
->name
, print_mac(mac
, ifsta
->bssid
));
819 ifsta
->state
= IEEE80211_DISABLED
;
823 ifsta
->state
= IEEE80211_ASSOCIATE
;
824 printk(KERN_DEBUG
"%s: associate with AP %s\n",
825 dev
->name
, print_mac(mac
, ifsta
->bssid
));
826 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
827 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
828 "mixed-cell disabled - abort association\n", dev
->name
);
829 ifsta
->state
= IEEE80211_DISABLED
;
833 ieee80211_send_assoc(dev
, ifsta
);
835 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_ASSOC_TIMEOUT
);
839 static void ieee80211_associated(struct net_device
*dev
,
840 struct ieee80211_if_sta
*ifsta
)
842 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
843 struct sta_info
*sta
;
845 DECLARE_MAC_BUF(mac
);
847 /* TODO: start monitoring current AP signal quality and number of
848 * missed beacons. Scan other channels every now and then and search
850 /* TODO: remove expired BSSes */
852 ifsta
->state
= IEEE80211_ASSOCIATED
;
854 sta
= sta_info_get(local
, ifsta
->bssid
);
856 printk(KERN_DEBUG
"%s: No STA entry for own AP %s\n",
857 dev
->name
, print_mac(mac
, ifsta
->bssid
));
861 if (time_after(jiffies
,
862 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
863 if (ifsta
->flags
& IEEE80211_STA_PROBEREQ_POLL
) {
864 printk(KERN_DEBUG
"%s: No ProbeResp from "
865 "current AP %s - assume out of "
867 dev
->name
, print_mac(mac
, ifsta
->bssid
));
871 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
873 local
->scan_ssid_len
);
874 ifsta
->flags
^= IEEE80211_STA_PROBEREQ_POLL
;
876 ifsta
->flags
&= ~IEEE80211_STA_PROBEREQ_POLL
;
877 if (time_after(jiffies
, ifsta
->last_probe
+
878 IEEE80211_PROBE_INTERVAL
)) {
879 ifsta
->last_probe
= jiffies
;
880 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
888 ifsta
->state
= IEEE80211_DISABLED
;
889 ieee80211_set_associated(dev
, ifsta
, 0);
891 mod_timer(&ifsta
->timer
, jiffies
+
892 IEEE80211_MONITORING_INTERVAL
);
897 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
898 u8
*ssid
, size_t ssid_len
)
900 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
901 struct ieee80211_hw_mode
*mode
;
903 struct ieee80211_mgmt
*mgmt
;
904 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
907 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200);
909 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
910 "request\n", dev
->name
);
913 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
915 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
917 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
918 IEEE80211_STYPE_PROBE_REQ
);
919 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
921 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
922 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
924 memset(mgmt
->da
, 0xff, ETH_ALEN
);
925 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
927 pos
= skb_put(skb
, 2 + ssid_len
);
928 *pos
++ = WLAN_EID_SSID
;
930 memcpy(pos
, ssid
, ssid_len
);
932 supp_rates
= skb_put(skb
, 2);
933 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
935 mode
= local
->oper_hw_mode
;
936 for (i
= 0; i
< mode
->num_rates
; i
++) {
937 struct ieee80211_rate
*rate
= &mode
->rates
[i
];
938 if (!(rate
->flags
& IEEE80211_RATE_SUPPORTED
))
941 pos
= skb_put(skb
, 1);
943 } else if (supp_rates
[1] == 8) {
944 esupp_rates
= skb_put(skb
, 3);
945 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
947 pos
= &esupp_rates
[2];
949 pos
= skb_put(skb
, 1);
952 *pos
= rate
->rate
/ 5;
955 ieee80211_sta_tx(dev
, skb
, 0);
959 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
961 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
962 if (!sdata
|| !sdata
->default_key
||
963 sdata
->default_key
->conf
.alg
!= ALG_WEP
)
969 static void ieee80211_auth_completed(struct net_device
*dev
,
970 struct ieee80211_if_sta
*ifsta
)
972 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
973 ifsta
->flags
|= IEEE80211_STA_AUTHENTICATED
;
974 ieee80211_associate(dev
, ifsta
);
978 static void ieee80211_auth_challenge(struct net_device
*dev
,
979 struct ieee80211_if_sta
*ifsta
,
980 struct ieee80211_mgmt
*mgmt
,
984 struct ieee802_11_elems elems
;
986 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
987 pos
= mgmt
->u
.auth
.variable
;
988 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
989 if (!elems
.challenge
) {
990 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
991 "frame\n", dev
->name
);
994 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
995 elems
.challenge_len
+ 2, 1);
998 static void ieee80211_send_addba_resp(struct net_device
*dev
, u8
*da
, u16 tid
,
999 u8 dialog_token
, u16 status
, u16 policy
,
1000 u16 buf_size
, u16 timeout
)
1002 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1003 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1004 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1005 struct sk_buff
*skb
;
1006 struct ieee80211_mgmt
*mgmt
;
1009 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1010 sizeof(mgmt
->u
.action
.u
.addba_resp
));
1012 printk(KERN_DEBUG
"%s: failed to allocate buffer "
1013 "for addba resp frame\n", dev
->name
);
1017 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1018 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1019 memset(mgmt
, 0, 24);
1020 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1021 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1022 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1023 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1025 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1026 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1027 IEEE80211_STYPE_ACTION
);
1029 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_resp
));
1030 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1031 mgmt
->u
.action
.u
.addba_resp
.action_code
= WLAN_ACTION_ADDBA_RESP
;
1032 mgmt
->u
.action
.u
.addba_resp
.dialog_token
= dialog_token
;
1034 capab
= (u16
)(policy
<< 1); /* bit 1 aggregation policy */
1035 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1036 capab
|= (u16
)(buf_size
<< 6); /* bit 15:6 max size of aggregation */
1038 mgmt
->u
.action
.u
.addba_resp
.capab
= cpu_to_le16(capab
);
1039 mgmt
->u
.action
.u
.addba_resp
.timeout
= cpu_to_le16(timeout
);
1040 mgmt
->u
.action
.u
.addba_resp
.status
= cpu_to_le16(status
);
1042 ieee80211_sta_tx(dev
, skb
, 0);
1047 static void ieee80211_sta_process_addba_request(struct net_device
*dev
,
1048 struct ieee80211_mgmt
*mgmt
,
1051 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1052 struct ieee80211_hw
*hw
= &local
->hw
;
1053 struct ieee80211_conf
*conf
= &hw
->conf
;
1054 struct sta_info
*sta
;
1055 struct tid_ampdu_rx
*tid_agg_rx
;
1056 u16 capab
, tid
, timeout
, ba_policy
, buf_size
, start_seq_num
, status
;
1058 int ret
= -EOPNOTSUPP
;
1059 DECLARE_MAC_BUF(mac
);
1061 sta
= sta_info_get(local
, mgmt
->sa
);
1065 /* extract session parameters from addba request frame */
1066 dialog_token
= mgmt
->u
.action
.u
.addba_req
.dialog_token
;
1067 timeout
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.timeout
);
1069 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.start_seq_num
) >> 4;
1071 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1072 ba_policy
= (capab
& IEEE80211_ADDBA_PARAM_POLICY_MASK
) >> 1;
1073 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1074 buf_size
= (capab
& IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
) >> 6;
1076 status
= WLAN_STATUS_REQUEST_DECLINED
;
1078 /* sanity check for incoming parameters:
1079 * check if configuration can support the BA policy
1080 * and if buffer size does not exceeds max value */
1081 if (((ba_policy
!= 1)
1082 && (!(conf
->ht_conf
.cap
& IEEE80211_HT_CAP_DELAY_BA
)))
1083 || (buf_size
> IEEE80211_MAX_AMPDU_BUF
)) {
1084 status
= WLAN_STATUS_INVALID_QOS_PARAM
;
1085 #ifdef CONFIG_MAC80211_HT_DEBUG
1086 if (net_ratelimit())
1087 printk(KERN_DEBUG
"Block Ack Req with bad params from "
1088 "%s on tid %u. policy %d, buffer size %d\n",
1089 print_mac(mac
, mgmt
->sa
), tid
, ba_policy
,
1091 #endif /* CONFIG_MAC80211_HT_DEBUG */
1094 /* determine default buffer size */
1095 if (buf_size
== 0) {
1096 struct ieee80211_hw_mode
*mode
= conf
->mode
;
1097 buf_size
= IEEE80211_MIN_AMPDU_BUF
;
1098 buf_size
= buf_size
<< mode
->ht_info
.ampdu_factor
;
1101 tid_agg_rx
= &sta
->ampdu_mlme
.tid_rx
[tid
];
1103 /* examine state machine */
1104 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1106 if (tid_agg_rx
->state
!= HT_AGG_STATE_IDLE
) {
1107 #ifdef CONFIG_MAC80211_HT_DEBUG
1108 if (net_ratelimit())
1109 printk(KERN_DEBUG
"unexpected Block Ack Req from "
1111 print_mac(mac
, mgmt
->sa
), tid
);
1112 #endif /* CONFIG_MAC80211_HT_DEBUG */
1116 /* prepare reordering buffer */
1117 tid_agg_rx
->reorder_buf
=
1118 kmalloc(buf_size
* sizeof(struct sk_buf
*), GFP_ATOMIC
);
1119 if (!tid_agg_rx
->reorder_buf
) {
1120 if (net_ratelimit())
1121 printk(KERN_ERR
"can not allocate reordering buffer "
1122 "to tid %d\n", tid
);
1125 memset(tid_agg_rx
->reorder_buf
, 0,
1126 buf_size
* sizeof(struct sk_buf
*));
1128 if (local
->ops
->ampdu_action
)
1129 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_START
,
1130 sta
->addr
, tid
, start_seq_num
);
1131 #ifdef CONFIG_MAC80211_HT_DEBUG
1132 printk(KERN_DEBUG
"Rx A-MPDU on tid %d result %d", tid
, ret
);
1133 #endif /* CONFIG_MAC80211_HT_DEBUG */
1136 kfree(tid_agg_rx
->reorder_buf
);
1140 /* change state and send addba resp */
1141 tid_agg_rx
->state
= HT_AGG_STATE_OPERATIONAL
;
1142 tid_agg_rx
->dialog_token
= dialog_token
;
1143 tid_agg_rx
->ssn
= start_seq_num
;
1144 tid_agg_rx
->head_seq_num
= start_seq_num
;
1145 tid_agg_rx
->buf_size
= buf_size
;
1146 tid_agg_rx
->timeout
= timeout
;
1147 tid_agg_rx
->stored_mpdu_num
= 0;
1148 status
= WLAN_STATUS_SUCCESS
;
1150 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1153 ieee80211_send_addba_resp(sta
->dev
, sta
->addr
, tid
, dialog_token
,
1154 status
, 1, buf_size
, timeout
);
1158 static void ieee80211_send_delba(struct net_device
*dev
, const u8
*da
, u16 tid
,
1159 u16 initiator
, u16 reason_code
)
1161 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1162 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1163 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1164 struct sk_buff
*skb
;
1165 struct ieee80211_mgmt
*mgmt
;
1168 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1169 sizeof(mgmt
->u
.action
.u
.delba
));
1172 printk(KERN_ERR
"%s: failed to allocate buffer "
1173 "for delba frame\n", dev
->name
);
1177 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1178 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1179 memset(mgmt
, 0, 24);
1180 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1181 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1182 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1183 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1185 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1186 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1187 IEEE80211_STYPE_ACTION
);
1189 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.delba
));
1191 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1192 mgmt
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
1193 params
= (u16
)(initiator
<< 11); /* bit 11 initiator */
1194 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
1196 mgmt
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
1197 mgmt
->u
.action
.u
.delba
.reason_code
= cpu_to_le16(reason_code
);
1199 ieee80211_sta_tx(dev
, skb
, 0);
1202 void ieee80211_sta_stop_rx_ba_session(struct net_device
*dev
, u8
*ra
, u16 tid
,
1203 u16 initiator
, u16 reason
)
1205 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1206 struct ieee80211_hw
*hw
= &local
->hw
;
1207 struct sta_info
*sta
;
1210 sta
= sta_info_get(local
, ra
);
1214 /* check if TID is in operational state */
1215 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1216 if (sta
->ampdu_mlme
.tid_rx
[tid
].state
1217 != HT_AGG_STATE_OPERATIONAL
) {
1218 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1222 sta
->ampdu_mlme
.tid_rx
[tid
].state
=
1223 HT_AGG_STATE_REQ_STOP_BA_MSK
|
1224 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
1225 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1227 /* stop HW Rx aggregation. ampdu_action existence
1228 * already verified in session init so we add the BUG_ON */
1229 BUG_ON(!local
->ops
->ampdu_action
);
1231 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_STOP
,
1234 printk(KERN_DEBUG
"HW problem - can not stop rx "
1235 "aggergation for tid %d\n", tid
);
1237 /* shutdown timer has not expired */
1238 if (initiator
!= WLAN_BACK_TIMER
)
1239 del_timer_sync(&sta
->ampdu_mlme
.tid_rx
[tid
].
1242 /* check if this is a self generated aggregation halt */
1243 if (initiator
== WLAN_BACK_RECIPIENT
|| initiator
== WLAN_BACK_TIMER
)
1244 ieee80211_send_delba(dev
, ra
, tid
, 0, reason
);
1246 /* free the reordering buffer */
1247 for (i
= 0; i
< sta
->ampdu_mlme
.tid_rx
[tid
].buf_size
; i
++) {
1248 if (sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
[i
]) {
1249 /* release the reordered frames */
1250 dev_kfree_skb(sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
[i
]);
1251 sta
->ampdu_mlme
.tid_rx
[tid
].stored_mpdu_num
--;
1252 sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
[i
] = NULL
;
1255 kfree(sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
);
1257 sta
->ampdu_mlme
.tid_rx
[tid
].state
= HT_AGG_STATE_IDLE
;
1261 static void ieee80211_sta_process_delba(struct net_device
*dev
,
1262 struct ieee80211_mgmt
*mgmt
, size_t len
)
1264 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1265 struct sta_info
*sta
;
1268 DECLARE_MAC_BUF(mac
);
1270 sta
= sta_info_get(local
, mgmt
->sa
);
1274 params
= le16_to_cpu(mgmt
->u
.action
.u
.delba
.params
);
1275 tid
= (params
& IEEE80211_DELBA_PARAM_TID_MASK
) >> 12;
1276 initiator
= (params
& IEEE80211_DELBA_PARAM_INITIATOR_MASK
) >> 11;
1278 #ifdef CONFIG_MAC80211_HT_DEBUG
1279 if (net_ratelimit())
1280 printk(KERN_DEBUG
"delba from %s on tid %d reason code %d\n",
1281 print_mac(mac
, mgmt
->sa
), tid
,
1282 mgmt
->u
.action
.u
.delba
.reason_code
);
1283 #endif /* CONFIG_MAC80211_HT_DEBUG */
1285 if (initiator
== WLAN_BACK_INITIATOR
)
1286 ieee80211_sta_stop_rx_ba_session(dev
, sta
->addr
, tid
,
1287 WLAN_BACK_INITIATOR
, 0);
1292 * After receiving Block Ack Request (BAR) we activated a
1293 * timer after each frame arrives from the originator.
1294 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1296 void sta_rx_agg_session_timer_expired(unsigned long data
)
1298 /* not an elegant detour, but there is no choice as the timer passes
1299 * only one argument, and verious sta_info are needed here, so init
1300 * flow in sta_info_add gives the TID as data, while the timer_to_id
1301 * array gives the sta through container_of */
1302 u8
*ptid
= (u8
*)data
;
1303 u8
*timer_to_id
= ptid
- *ptid
;
1304 struct sta_info
*sta
= container_of(timer_to_id
, struct sta_info
,
1307 printk(KERN_DEBUG
"rx session timer expired on tid %d\n", (u16
)*ptid
);
1308 ieee80211_sta_stop_rx_ba_session(sta
->dev
, sta
->addr
, (u16
)*ptid
,
1310 WLAN_REASON_QSTA_TIMEOUT
);
1314 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
1315 struct ieee80211_if_sta
*ifsta
,
1316 struct ieee80211_mgmt
*mgmt
,
1319 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1320 u16 auth_alg
, auth_transaction
, status_code
;
1321 DECLARE_MAC_BUF(mac
);
1323 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
1324 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
) {
1325 printk(KERN_DEBUG
"%s: authentication frame received from "
1326 "%s, but not in authenticate state - ignored\n",
1327 dev
->name
, print_mac(mac
, mgmt
->sa
));
1332 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
1333 "received from %s - ignored\n",
1334 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1338 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1339 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1340 printk(KERN_DEBUG
"%s: authentication frame received from "
1341 "unknown AP (SA=%s BSSID=%s) - "
1342 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1343 print_mac(mac
, mgmt
->bssid
));
1347 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1348 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
1349 printk(KERN_DEBUG
"%s: authentication frame received from "
1350 "unknown BSSID (SA=%s BSSID=%s) - "
1351 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1352 print_mac(mac
, mgmt
->bssid
));
1356 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
1357 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
1358 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
1360 printk(KERN_DEBUG
"%s: RX authentication from %s (alg=%d "
1361 "transaction=%d status=%d)\n",
1362 dev
->name
, print_mac(mac
, mgmt
->sa
), auth_alg
,
1363 auth_transaction
, status_code
);
1365 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
1366 /* IEEE 802.11 standard does not require authentication in IBSS
1367 * networks and most implementations do not seem to use it.
1368 * However, try to reply to authentication attempts if someone
1369 * has actually implemented this.
1370 * TODO: Could implement shared key authentication. */
1371 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
1372 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
1373 "frame (alg=%d transaction=%d)\n",
1374 dev
->name
, auth_alg
, auth_transaction
);
1377 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
1380 if (auth_alg
!= ifsta
->auth_alg
||
1381 auth_transaction
!= ifsta
->auth_transaction
) {
1382 printk(KERN_DEBUG
"%s: unexpected authentication frame "
1383 "(alg=%d transaction=%d)\n",
1384 dev
->name
, auth_alg
, auth_transaction
);
1388 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1389 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
1390 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
1391 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
1393 const int num_algs
= ARRAY_SIZE(algs
);
1395 algs
[0] = algs
[1] = algs
[2] = 0xff;
1396 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1397 algs
[0] = WLAN_AUTH_OPEN
;
1398 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1399 algs
[1] = WLAN_AUTH_SHARED_KEY
;
1400 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1401 algs
[2] = WLAN_AUTH_LEAP
;
1402 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
1404 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
1408 for (i
= 0; i
< num_algs
; i
++) {
1410 if (pos
>= num_algs
)
1412 if (algs
[pos
] == ifsta
->auth_alg
||
1415 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
1416 !ieee80211_sta_wep_configured(dev
))
1418 ifsta
->auth_alg
= algs
[pos
];
1419 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
1421 dev
->name
, ifsta
->auth_alg
);
1428 switch (ifsta
->auth_alg
) {
1429 case WLAN_AUTH_OPEN
:
1430 case WLAN_AUTH_LEAP
:
1431 ieee80211_auth_completed(dev
, ifsta
);
1433 case WLAN_AUTH_SHARED_KEY
:
1434 if (ifsta
->auth_transaction
== 4)
1435 ieee80211_auth_completed(dev
, ifsta
);
1437 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
);
1443 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
1444 struct ieee80211_if_sta
*ifsta
,
1445 struct ieee80211_mgmt
*mgmt
,
1449 DECLARE_MAC_BUF(mac
);
1452 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
1453 "received from %s - ignored\n",
1454 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1458 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1459 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1460 "unknown AP (SA=%s BSSID=%s) - "
1461 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1462 print_mac(mac
, mgmt
->bssid
));
1466 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1468 printk(KERN_DEBUG
"%s: RX deauthentication from %s"
1470 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1472 if (ifsta
->flags
& IEEE80211_STA_AUTHENTICATED
) {
1473 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1476 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1477 ifsta
->state
== IEEE80211_ASSOCIATE
||
1478 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1479 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1480 mod_timer(&ifsta
->timer
, jiffies
+
1481 IEEE80211_RETRY_AUTH_INTERVAL
);
1484 ieee80211_set_disassoc(dev
, ifsta
, 1);
1485 ifsta
->flags
&= ~IEEE80211_STA_AUTHENTICATED
;
1489 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1490 struct ieee80211_if_sta
*ifsta
,
1491 struct ieee80211_mgmt
*mgmt
,
1495 DECLARE_MAC_BUF(mac
);
1498 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1499 "received from %s - ignored\n",
1500 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1504 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1505 printk(KERN_DEBUG
"%s: disassociation frame received from "
1506 "unknown AP (SA=%s BSSID=%s) - "
1507 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1508 print_mac(mac
, mgmt
->bssid
));
1512 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1514 printk(KERN_DEBUG
"%s: RX disassociation from %s"
1516 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1518 if (ifsta
->flags
& IEEE80211_STA_ASSOCIATED
)
1519 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1521 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1522 ifsta
->state
= IEEE80211_ASSOCIATE
;
1523 mod_timer(&ifsta
->timer
, jiffies
+
1524 IEEE80211_RETRY_AUTH_INTERVAL
);
1527 ieee80211_set_disassoc(dev
, ifsta
, 0);
1531 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
1532 struct ieee80211_if_sta
*ifsta
,
1533 struct ieee80211_mgmt
*mgmt
,
1537 struct ieee80211_local
*local
= sdata
->local
;
1538 struct net_device
*dev
= sdata
->dev
;
1539 struct ieee80211_hw_mode
*mode
;
1540 struct sta_info
*sta
;
1542 u16 capab_info
, status_code
, aid
;
1543 struct ieee802_11_elems elems
;
1544 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
1547 DECLARE_MAC_BUF(mac
);
1549 /* AssocResp and ReassocResp have identical structure, so process both
1550 * of them in this function. */
1552 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1553 printk(KERN_DEBUG
"%s: association frame received from "
1554 "%s, but not in associate state - ignored\n",
1555 dev
->name
, print_mac(mac
, mgmt
->sa
));
1560 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1561 "received from %s - ignored\n",
1562 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1566 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1567 printk(KERN_DEBUG
"%s: association frame received from "
1568 "unknown AP (SA=%s BSSID=%s) - "
1569 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1570 print_mac(mac
, mgmt
->bssid
));
1574 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1575 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1576 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1578 printk(KERN_DEBUG
"%s: RX %sssocResp from %s (capab=0x%x "
1579 "status=%d aid=%d)\n",
1580 dev
->name
, reassoc
? "Rea" : "A", print_mac(mac
, mgmt
->sa
),
1581 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
1583 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1584 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1585 dev
->name
, status_code
);
1586 /* if this was a reassociation, ensure we try a "full"
1587 * association next time. This works around some broken APs
1588 * which do not correctly reject reassociation requests. */
1589 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
1593 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1594 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1595 "set\n", dev
->name
, aid
);
1596 aid
&= ~(BIT(15) | BIT(14));
1598 pos
= mgmt
->u
.assoc_resp
.variable
;
1599 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1601 if (!elems
.supp_rates
) {
1602 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1607 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1609 ifsta
->ap_capab
= capab_info
;
1611 kfree(ifsta
->assocresp_ies
);
1612 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1613 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_KERNEL
);
1614 if (ifsta
->assocresp_ies
)
1615 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1617 /* set AID, ieee80211_set_associated() will tell the driver */
1618 bss_conf
->aid
= aid
;
1619 ieee80211_set_associated(dev
, ifsta
, 1);
1621 /* Add STA entry for the AP */
1622 sta
= sta_info_get(local
, ifsta
->bssid
);
1624 struct ieee80211_sta_bss
*bss
;
1625 sta
= sta_info_add(local
, dev
, ifsta
->bssid
, GFP_KERNEL
);
1627 printk(KERN_DEBUG
"%s: failed to add STA entry for the"
1628 " AP\n", dev
->name
);
1631 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
1632 local
->hw
.conf
.channel
,
1633 ifsta
->ssid
, ifsta
->ssid_len
);
1635 sta
->last_rssi
= bss
->rssi
;
1636 sta
->last_signal
= bss
->signal
;
1637 sta
->last_noise
= bss
->noise
;
1638 ieee80211_rx_bss_put(dev
, bss
);
1643 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
| WLAN_STA_ASSOC_AP
;
1646 mode
= local
->oper_hw_mode
;
1647 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
1648 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
1649 for (j
= 0; j
< mode
->num_rates
; j
++)
1650 if (mode
->rates
[j
].rate
== rate
)
1653 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
1654 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
1655 for (j
= 0; j
< mode
->num_rates
; j
++)
1656 if (mode
->rates
[j
].rate
== rate
)
1659 sta
->supp_rates
= rates
;
1661 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&& elems
.wmm_param
&&
1662 local
->ops
->conf_ht
) {
1663 struct ieee80211_ht_bss_info bss_info
;
1665 ieee80211_ht_cap_ie_to_ht_info(
1666 (struct ieee80211_ht_cap
*)
1667 elems
.ht_cap_elem
, &sta
->ht_info
);
1668 ieee80211_ht_addt_info_ie_to_ht_bss_info(
1669 (struct ieee80211_ht_addt_info
*)
1670 elems
.ht_info_elem
, &bss_info
);
1671 ieee80211_hw_config_ht(local
, 1, &sta
->ht_info
, &bss_info
);
1674 rate_control_rate_init(sta
, local
);
1676 if (elems
.wmm_param
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
1677 sta
->flags
|= WLAN_STA_WME
;
1678 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
1679 elems
.wmm_param_len
);
1685 ieee80211_associated(dev
, ifsta
);
1689 /* Caller must hold local->sta_bss_lock */
1690 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
1691 struct ieee80211_sta_bss
*bss
)
1693 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1694 bss
->hnext
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1695 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] = bss
;
1699 /* Caller must hold local->sta_bss_lock */
1700 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
1701 struct ieee80211_sta_bss
*bss
)
1703 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1704 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
1705 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1709 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
1712 prev
->hnext
= bss
->hnext
;
1721 static struct ieee80211_sta_bss
*
1722 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
, int channel
,
1723 u8
*ssid
, u8 ssid_len
)
1725 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1726 struct ieee80211_sta_bss
*bss
;
1728 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
1731 atomic_inc(&bss
->users
);
1732 atomic_inc(&bss
->users
);
1733 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
1734 bss
->channel
= channel
;
1735 if (ssid
&& ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
1736 memcpy(bss
->ssid
, ssid
, ssid_len
);
1737 bss
->ssid_len
= ssid_len
;
1740 spin_lock_bh(&local
->sta_bss_lock
);
1741 /* TODO: order by RSSI? */
1742 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
1743 __ieee80211_rx_bss_hash_add(dev
, bss
);
1744 spin_unlock_bh(&local
->sta_bss_lock
);
1749 static struct ieee80211_sta_bss
*
1750 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int channel
,
1751 u8
*ssid
, u8 ssid_len
)
1753 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1754 struct ieee80211_sta_bss
*bss
;
1756 spin_lock_bh(&local
->sta_bss_lock
);
1757 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
1759 if (!memcmp(bss
->bssid
, bssid
, ETH_ALEN
) &&
1760 bss
->channel
== channel
&&
1761 bss
->ssid_len
== ssid_len
&&
1762 (ssid_len
== 0 || !memcmp(bss
->ssid
, ssid
, ssid_len
))) {
1763 atomic_inc(&bss
->users
);
1768 spin_unlock_bh(&local
->sta_bss_lock
);
1773 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
1783 static void ieee80211_rx_bss_put(struct net_device
*dev
,
1784 struct ieee80211_sta_bss
*bss
)
1786 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1787 if (!atomic_dec_and_test(&bss
->users
))
1790 spin_lock_bh(&local
->sta_bss_lock
);
1791 __ieee80211_rx_bss_hash_del(dev
, bss
);
1792 list_del(&bss
->list
);
1793 spin_unlock_bh(&local
->sta_bss_lock
);
1794 ieee80211_rx_bss_free(bss
);
1798 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
1800 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1801 spin_lock_init(&local
->sta_bss_lock
);
1802 INIT_LIST_HEAD(&local
->sta_bss_list
);
1806 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
1808 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1809 struct ieee80211_sta_bss
*bss
, *tmp
;
1811 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
1812 ieee80211_rx_bss_put(dev
, bss
);
1816 static void ieee80211_rx_bss_info(struct net_device
*dev
,
1817 struct ieee80211_mgmt
*mgmt
,
1819 struct ieee80211_rx_status
*rx_status
,
1822 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1823 struct ieee802_11_elems elems
;
1826 struct ieee80211_sta_bss
*bss
;
1827 struct sta_info
*sta
;
1828 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1830 DECLARE_MAC_BUF(mac
);
1831 DECLARE_MAC_BUF(mac2
);
1833 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
1834 return; /* ignore ProbeResp to foreign address */
1837 printk(KERN_DEBUG
"%s: RX %s from %s to %s\n",
1838 dev
->name
, beacon
? "Beacon" : "Probe Response",
1839 print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
));
1842 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1846 timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
1848 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
1849 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0) {
1850 #ifdef CONFIG_MAC80211_IBSS_DEBUG
1851 static unsigned long last_tsf_debug
= 0;
1853 if (local
->ops
->get_tsf
)
1854 tsf
= local
->ops
->get_tsf(local_to_hw(local
));
1857 if (time_after(jiffies
, last_tsf_debug
+ 5 * HZ
)) {
1858 printk(KERN_DEBUG
"RX beacon SA=%s BSSID="
1859 "%s TSF=0x%llx BCN=0x%llx diff=%lld "
1861 print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->bssid
),
1862 (unsigned long long)tsf
,
1863 (unsigned long long)timestamp
,
1864 (unsigned long long)(tsf
- timestamp
),
1866 last_tsf_debug
= jiffies
;
1868 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
1871 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
1873 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& elems
.supp_rates
&&
1874 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0 &&
1875 (sta
= sta_info_get(local
, mgmt
->sa
))) {
1876 struct ieee80211_hw_mode
*mode
;
1877 struct ieee80211_rate
*rates
;
1879 u32 supp_rates
, prev_rates
;
1882 mode
= local
->sta_sw_scanning
?
1883 local
->scan_hw_mode
: local
->oper_hw_mode
;
1885 if (local
->sta_hw_scanning
) {
1886 /* search for the correct mode matches the beacon */
1887 list_for_each_entry(mode
, &local
->modes_list
, list
)
1888 if (mode
->mode
== rx_status
->phymode
)
1892 mode
= local
->oper_hw_mode
;
1894 rates
= mode
->rates
;
1895 num_rates
= mode
->num_rates
;
1898 for (i
= 0; i
< elems
.supp_rates_len
+
1899 elems
.ext_supp_rates_len
; i
++) {
1902 if (i
< elems
.supp_rates_len
)
1903 rate
= elems
.supp_rates
[i
];
1904 else if (elems
.ext_supp_rates
)
1905 rate
= elems
.ext_supp_rates
1906 [i
- elems
.supp_rates_len
];
1907 own_rate
= 5 * (rate
& 0x7f);
1908 for (j
= 0; j
< num_rates
; j
++)
1909 if (rates
[j
].rate
== own_rate
)
1910 supp_rates
|= BIT(j
);
1913 prev_rates
= sta
->supp_rates
;
1914 sta
->supp_rates
&= supp_rates
;
1915 if (sta
->supp_rates
== 0) {
1916 /* No matching rates - this should not really happen.
1917 * Make sure that at least one rate is marked
1918 * supported to avoid issues with TX rate ctrl. */
1919 sta
->supp_rates
= sdata
->u
.sta
.supp_rates_bits
;
1921 if (sta
->supp_rates
!= prev_rates
) {
1922 printk(KERN_DEBUG
"%s: updated supp_rates set for "
1923 "%s based on beacon info (0x%x & 0x%x -> "
1925 dev
->name
, print_mac(mac
, sta
->addr
), prev_rates
,
1926 supp_rates
, sta
->supp_rates
);
1934 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
1935 channel
= elems
.ds_params
[0];
1937 channel
= rx_status
->channel
;
1939 bss
= ieee80211_rx_bss_get(dev
, mgmt
->bssid
, channel
,
1940 elems
.ssid
, elems
.ssid_len
);
1942 bss
= ieee80211_rx_bss_add(dev
, mgmt
->bssid
, channel
,
1943 elems
.ssid
, elems
.ssid_len
);
1948 /* TODO: order by RSSI? */
1949 spin_lock_bh(&local
->sta_bss_lock
);
1950 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
1951 spin_unlock_bh(&local
->sta_bss_lock
);
1955 if (bss
->probe_resp
&& beacon
) {
1956 /* Do not allow beacon to override data from Probe Response. */
1957 ieee80211_rx_bss_put(dev
, bss
);
1961 /* save the ERP value so that it is available at association time */
1962 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
1963 bss
->erp_value
= elems
.erp_info
[0];
1964 bss
->has_erp_value
= 1;
1967 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
1968 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
1970 bss
->supp_rates_len
= 0;
1971 if (elems
.supp_rates
) {
1972 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
1973 if (clen
> elems
.supp_rates_len
)
1974 clen
= elems
.supp_rates_len
;
1975 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
.supp_rates
,
1977 bss
->supp_rates_len
+= clen
;
1979 if (elems
.ext_supp_rates
) {
1980 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
1981 if (clen
> elems
.ext_supp_rates_len
)
1982 clen
= elems
.ext_supp_rates_len
;
1983 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
1984 elems
.ext_supp_rates
, clen
);
1985 bss
->supp_rates_len
+= clen
;
1989 (!bss
->wpa_ie
|| bss
->wpa_ie_len
!= elems
.wpa_len
||
1990 memcmp(bss
->wpa_ie
, elems
.wpa
, elems
.wpa_len
))) {
1992 bss
->wpa_ie
= kmalloc(elems
.wpa_len
+ 2, GFP_ATOMIC
);
1994 memcpy(bss
->wpa_ie
, elems
.wpa
- 2, elems
.wpa_len
+ 2);
1995 bss
->wpa_ie_len
= elems
.wpa_len
+ 2;
1997 bss
->wpa_ie_len
= 0;
1998 } else if (!elems
.wpa
&& bss
->wpa_ie
) {
2001 bss
->wpa_ie_len
= 0;
2005 (!bss
->rsn_ie
|| bss
->rsn_ie_len
!= elems
.rsn_len
||
2006 memcmp(bss
->rsn_ie
, elems
.rsn
, elems
.rsn_len
))) {
2008 bss
->rsn_ie
= kmalloc(elems
.rsn_len
+ 2, GFP_ATOMIC
);
2010 memcpy(bss
->rsn_ie
, elems
.rsn
- 2, elems
.rsn_len
+ 2);
2011 bss
->rsn_ie_len
= elems
.rsn_len
+ 2;
2013 bss
->rsn_ie_len
= 0;
2014 } else if (!elems
.rsn
&& bss
->rsn_ie
) {
2017 bss
->rsn_ie_len
= 0;
2020 if (elems
.wmm_param
&&
2021 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_param_len
||
2022 memcmp(bss
->wmm_ie
, elems
.wmm_param
, elems
.wmm_param_len
))) {
2024 bss
->wmm_ie
= kmalloc(elems
.wmm_param_len
+ 2, GFP_ATOMIC
);
2026 memcpy(bss
->wmm_ie
, elems
.wmm_param
- 2,
2027 elems
.wmm_param_len
+ 2);
2028 bss
->wmm_ie_len
= elems
.wmm_param_len
+ 2;
2030 bss
->wmm_ie_len
= 0;
2031 } else if (!elems
.wmm_param
&& bss
->wmm_ie
) {
2034 bss
->wmm_ie_len
= 0;
2036 if (elems
.ht_cap_elem
&&
2037 (!bss
->ht_ie
|| bss
->ht_ie_len
!= elems
.ht_cap_elem_len
||
2038 memcmp(bss
->ht_ie
, elems
.ht_cap_elem
, elems
.ht_cap_elem_len
))) {
2040 bss
->ht_ie
= kmalloc(elems
.ht_cap_elem_len
+ 2, GFP_ATOMIC
);
2042 memcpy(bss
->ht_ie
, elems
.ht_cap_elem
- 2,
2043 elems
.ht_cap_elem_len
+ 2);
2044 bss
->ht_ie_len
= elems
.ht_cap_elem_len
+ 2;
2047 } else if (!elems
.ht_cap_elem
&& bss
->ht_ie
) {
2053 bss
->hw_mode
= rx_status
->phymode
;
2054 bss
->freq
= rx_status
->freq
;
2055 if (channel
!= rx_status
->channel
&&
2056 (bss
->hw_mode
== MODE_IEEE80211G
||
2057 bss
->hw_mode
== MODE_IEEE80211B
) &&
2058 channel
>= 1 && channel
<= 14) {
2059 static const int freq_list
[] = {
2060 2412, 2417, 2422, 2427, 2432, 2437, 2442,
2061 2447, 2452, 2457, 2462, 2467, 2472, 2484
2063 /* IEEE 802.11g/b mode can receive packets from neighboring
2064 * channels, so map the channel into frequency. */
2065 bss
->freq
= freq_list
[channel
- 1];
2067 bss
->timestamp
= timestamp
;
2068 bss
->last_update
= jiffies
;
2069 bss
->rssi
= rx_status
->ssi
;
2070 bss
->signal
= rx_status
->signal
;
2071 bss
->noise
= rx_status
->noise
;
2074 ieee80211_rx_bss_put(dev
, bss
);
2078 static void ieee80211_rx_mgmt_probe_resp(struct net_device
*dev
,
2079 struct ieee80211_mgmt
*mgmt
,
2081 struct ieee80211_rx_status
*rx_status
)
2083 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 0);
2087 static void ieee80211_rx_mgmt_beacon(struct net_device
*dev
,
2088 struct ieee80211_mgmt
*mgmt
,
2090 struct ieee80211_rx_status
*rx_status
)
2092 struct ieee80211_sub_if_data
*sdata
;
2093 struct ieee80211_if_sta
*ifsta
;
2095 struct ieee802_11_elems elems
;
2096 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2097 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
2100 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 1);
2102 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2103 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
2105 ifsta
= &sdata
->u
.sta
;
2107 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
) ||
2108 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
2111 /* Process beacon from the current BSS */
2112 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2116 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2118 if (elems
.erp_info
&& elems
.erp_info_len
>= 1)
2119 changed
|= ieee80211_handle_erp_ie(sdata
, elems
.erp_info
[0]);
2121 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&&
2122 elems
.wmm_param
&& local
->ops
->conf_ht
&&
2123 conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
2124 struct ieee80211_ht_bss_info bss_info
;
2126 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2127 (struct ieee80211_ht_addt_info
*)
2128 elems
.ht_info_elem
, &bss_info
);
2129 /* check if AP changed bss inforamation */
2130 if ((conf
->ht_bss_conf
.primary_channel
!=
2131 bss_info
.primary_channel
) ||
2132 (conf
->ht_bss_conf
.bss_cap
!= bss_info
.bss_cap
) ||
2133 (conf
->ht_bss_conf
.bss_op_mode
!= bss_info
.bss_op_mode
))
2134 ieee80211_hw_config_ht(local
, 1, &conf
->ht_conf
,
2138 if (elems
.wmm_param
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
2139 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2140 elems
.wmm_param_len
);
2143 ieee80211_bss_info_change_notify(sdata
, changed
);
2147 static void ieee80211_rx_mgmt_probe_req(struct net_device
*dev
,
2148 struct ieee80211_if_sta
*ifsta
,
2149 struct ieee80211_mgmt
*mgmt
,
2151 struct ieee80211_rx_status
*rx_status
)
2153 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2154 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2156 struct sk_buff
*skb
;
2157 struct ieee80211_mgmt
*resp
;
2159 DECLARE_MAC_BUF(mac
);
2160 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2161 DECLARE_MAC_BUF(mac2
);
2162 DECLARE_MAC_BUF(mac3
);
2165 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
||
2166 ifsta
->state
!= IEEE80211_IBSS_JOINED
||
2167 len
< 24 + 2 || !ifsta
->probe_resp
)
2170 if (local
->ops
->tx_last_beacon
)
2171 tx_last_beacon
= local
->ops
->tx_last_beacon(local_to_hw(local
));
2175 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2176 printk(KERN_DEBUG
"%s: RX ProbeReq SA=%s DA=%s BSSID="
2177 "%s (tx_last_beacon=%d)\n",
2178 dev
->name
, print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
),
2179 print_mac(mac3
, mgmt
->bssid
), tx_last_beacon
);
2180 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2182 if (!tx_last_beacon
)
2185 if (memcmp(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
) != 0 &&
2186 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
2189 end
= ((u8
*) mgmt
) + len
;
2190 pos
= mgmt
->u
.probe_req
.variable
;
2191 if (pos
[0] != WLAN_EID_SSID
||
2192 pos
+ 2 + pos
[1] > end
) {
2193 if (net_ratelimit()) {
2194 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
2196 dev
->name
, print_mac(mac
, mgmt
->sa
));
2201 (pos
[1] != ifsta
->ssid_len
||
2202 memcmp(pos
+ 2, ifsta
->ssid
, ifsta
->ssid_len
) != 0)) {
2203 /* Ignore ProbeReq for foreign SSID */
2207 /* Reply with ProbeResp */
2208 skb
= skb_copy(ifsta
->probe_resp
, GFP_KERNEL
);
2212 resp
= (struct ieee80211_mgmt
*) skb
->data
;
2213 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
2214 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2215 printk(KERN_DEBUG
"%s: Sending ProbeResp to %s\n",
2216 dev
->name
, print_mac(mac
, resp
->da
));
2217 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2218 ieee80211_sta_tx(dev
, skb
, 0);
2221 static void ieee80211_rx_mgmt_action(struct net_device
*dev
,
2222 struct ieee80211_if_sta
*ifsta
,
2223 struct ieee80211_mgmt
*mgmt
,
2226 if (len
< IEEE80211_MIN_ACTION_SIZE
)
2229 switch (mgmt
->u
.action
.category
) {
2230 case WLAN_CATEGORY_BACK
:
2231 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
2232 case WLAN_ACTION_ADDBA_REQ
:
2233 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2234 sizeof(mgmt
->u
.action
.u
.addba_req
)))
2236 ieee80211_sta_process_addba_request(dev
, mgmt
, len
);
2238 case WLAN_ACTION_DELBA
:
2239 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2240 sizeof(mgmt
->u
.action
.u
.delba
)))
2242 ieee80211_sta_process_delba(dev
, mgmt
, len
);
2245 if (net_ratelimit())
2246 printk(KERN_DEBUG
"%s: Rx unknown A-MPDU action\n",
2256 void ieee80211_sta_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
2257 struct ieee80211_rx_status
*rx_status
)
2259 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2260 struct ieee80211_sub_if_data
*sdata
;
2261 struct ieee80211_if_sta
*ifsta
;
2262 struct ieee80211_mgmt
*mgmt
;
2268 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2269 ifsta
= &sdata
->u
.sta
;
2271 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2272 fc
= le16_to_cpu(mgmt
->frame_control
);
2274 switch (fc
& IEEE80211_FCTL_STYPE
) {
2275 case IEEE80211_STYPE_PROBE_REQ
:
2276 case IEEE80211_STYPE_PROBE_RESP
:
2277 case IEEE80211_STYPE_BEACON
:
2278 memcpy(skb
->cb
, rx_status
, sizeof(*rx_status
));
2279 case IEEE80211_STYPE_AUTH
:
2280 case IEEE80211_STYPE_ASSOC_RESP
:
2281 case IEEE80211_STYPE_REASSOC_RESP
:
2282 case IEEE80211_STYPE_DEAUTH
:
2283 case IEEE80211_STYPE_DISASSOC
:
2284 case IEEE80211_STYPE_ACTION
:
2285 skb_queue_tail(&ifsta
->skb_queue
, skb
);
2286 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2289 printk(KERN_DEBUG
"%s: received unknown management frame - "
2290 "stype=%d\n", dev
->name
,
2291 (fc
& IEEE80211_FCTL_STYPE
) >> 4);
2300 static void ieee80211_sta_rx_queued_mgmt(struct net_device
*dev
,
2301 struct sk_buff
*skb
)
2303 struct ieee80211_rx_status
*rx_status
;
2304 struct ieee80211_sub_if_data
*sdata
;
2305 struct ieee80211_if_sta
*ifsta
;
2306 struct ieee80211_mgmt
*mgmt
;
2309 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2310 ifsta
= &sdata
->u
.sta
;
2312 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
2313 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2314 fc
= le16_to_cpu(mgmt
->frame_control
);
2316 switch (fc
& IEEE80211_FCTL_STYPE
) {
2317 case IEEE80211_STYPE_PROBE_REQ
:
2318 ieee80211_rx_mgmt_probe_req(dev
, ifsta
, mgmt
, skb
->len
,
2321 case IEEE80211_STYPE_PROBE_RESP
:
2322 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
, skb
->len
, rx_status
);
2324 case IEEE80211_STYPE_BEACON
:
2325 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
, rx_status
);
2327 case IEEE80211_STYPE_AUTH
:
2328 ieee80211_rx_mgmt_auth(dev
, ifsta
, mgmt
, skb
->len
);
2330 case IEEE80211_STYPE_ASSOC_RESP
:
2331 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 0);
2333 case IEEE80211_STYPE_REASSOC_RESP
:
2334 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 1);
2336 case IEEE80211_STYPE_DEAUTH
:
2337 ieee80211_rx_mgmt_deauth(dev
, ifsta
, mgmt
, skb
->len
);
2339 case IEEE80211_STYPE_DISASSOC
:
2340 ieee80211_rx_mgmt_disassoc(dev
, ifsta
, mgmt
, skb
->len
);
2342 case IEEE80211_STYPE_ACTION
:
2343 ieee80211_rx_mgmt_action(dev
, ifsta
, mgmt
, skb
->len
);
2351 ieee80211_txrx_result
2352 ieee80211_sta_rx_scan(struct net_device
*dev
, struct sk_buff
*skb
,
2353 struct ieee80211_rx_status
*rx_status
)
2355 struct ieee80211_mgmt
*mgmt
;
2361 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2362 fc
= le16_to_cpu(mgmt
->frame_control
);
2364 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
)
2365 return TXRX_CONTINUE
;
2370 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
2371 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
) {
2372 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
,
2373 skb
->len
, rx_status
);
2376 } else if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
) {
2377 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
,
2383 return TXRX_CONTINUE
;
2387 static int ieee80211_sta_active_ibss(struct net_device
*dev
)
2389 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2391 struct sta_info
*sta
;
2393 read_lock_bh(&local
->sta_lock
);
2394 list_for_each_entry(sta
, &local
->sta_list
, list
) {
2395 if (sta
->dev
== dev
&&
2396 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
2402 read_unlock_bh(&local
->sta_lock
);
2408 static void ieee80211_sta_expire(struct net_device
*dev
)
2410 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2411 struct sta_info
*sta
, *tmp
;
2412 LIST_HEAD(tmp_list
);
2413 DECLARE_MAC_BUF(mac
);
2415 write_lock_bh(&local
->sta_lock
);
2416 list_for_each_entry_safe(sta
, tmp
, &local
->sta_list
, list
)
2417 if (time_after(jiffies
, sta
->last_rx
+
2418 IEEE80211_IBSS_INACTIVITY_LIMIT
)) {
2419 printk(KERN_DEBUG
"%s: expiring inactive STA %s\n",
2420 dev
->name
, print_mac(mac
, sta
->addr
));
2421 __sta_info_get(sta
);
2422 sta_info_remove(sta
);
2423 list_add(&sta
->list
, &tmp_list
);
2425 write_unlock_bh(&local
->sta_lock
);
2427 list_for_each_entry_safe(sta
, tmp
, &tmp_list
, list
) {
2434 static void ieee80211_sta_merge_ibss(struct net_device
*dev
,
2435 struct ieee80211_if_sta
*ifsta
)
2437 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2439 ieee80211_sta_expire(dev
);
2440 if (ieee80211_sta_active_ibss(dev
))
2443 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
2444 "IBSS networks with same SSID (merge)\n", dev
->name
);
2445 ieee80211_sta_req_scan(dev
, ifsta
->ssid
, ifsta
->ssid_len
);
2449 void ieee80211_sta_timer(unsigned long data
)
2451 struct ieee80211_sub_if_data
*sdata
=
2452 (struct ieee80211_sub_if_data
*) data
;
2453 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2454 struct ieee80211_local
*local
= wdev_priv(&sdata
->wdev
);
2456 set_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
2457 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2461 void ieee80211_sta_work(struct work_struct
*work
)
2463 struct ieee80211_sub_if_data
*sdata
=
2464 container_of(work
, struct ieee80211_sub_if_data
, u
.sta
.work
);
2465 struct net_device
*dev
= sdata
->dev
;
2466 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2467 struct ieee80211_if_sta
*ifsta
;
2468 struct sk_buff
*skb
;
2470 if (!netif_running(dev
))
2473 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
2476 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
2477 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
) {
2478 printk(KERN_DEBUG
"%s: ieee80211_sta_work: non-STA interface "
2479 "(type=%d)\n", dev
->name
, sdata
->vif
.type
);
2482 ifsta
= &sdata
->u
.sta
;
2484 while ((skb
= skb_dequeue(&ifsta
->skb_queue
)))
2485 ieee80211_sta_rx_queued_mgmt(dev
, skb
);
2487 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
2488 ifsta
->state
!= IEEE80211_ASSOCIATE
&&
2489 test_and_clear_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
)) {
2490 if (ifsta
->scan_ssid_len
)
2491 ieee80211_sta_start_scan(dev
, ifsta
->scan_ssid
, ifsta
->scan_ssid_len
);
2493 ieee80211_sta_start_scan(dev
, NULL
, 0);
2497 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
)) {
2498 if (ieee80211_sta_config_auth(dev
, ifsta
))
2500 clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
2501 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
))
2504 switch (ifsta
->state
) {
2505 case IEEE80211_DISABLED
:
2507 case IEEE80211_AUTHENTICATE
:
2508 ieee80211_authenticate(dev
, ifsta
);
2510 case IEEE80211_ASSOCIATE
:
2511 ieee80211_associate(dev
, ifsta
);
2513 case IEEE80211_ASSOCIATED
:
2514 ieee80211_associated(dev
, ifsta
);
2516 case IEEE80211_IBSS_SEARCH
:
2517 ieee80211_sta_find_ibss(dev
, ifsta
);
2519 case IEEE80211_IBSS_JOINED
:
2520 ieee80211_sta_merge_ibss(dev
, ifsta
);
2523 printk(KERN_DEBUG
"ieee80211_sta_work: Unknown state %d\n",
2528 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
2529 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
2530 "mixed-cell disabled - disassociate\n", dev
->name
);
2532 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
2533 ieee80211_set_disassoc(dev
, ifsta
, 0);
2538 static void ieee80211_sta_reset_auth(struct net_device
*dev
,
2539 struct ieee80211_if_sta
*ifsta
)
2541 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2543 if (local
->ops
->reset_tsf
) {
2544 /* Reset own TSF to allow time synchronization work. */
2545 local
->ops
->reset_tsf(local_to_hw(local
));
2548 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
2551 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
2552 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
2553 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
2554 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
2555 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
2556 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
2558 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
2559 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
2561 ifsta
->auth_transaction
= -1;
2562 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
2563 ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
2564 netif_carrier_off(dev
);
2568 void ieee80211_sta_req_auth(struct net_device
*dev
,
2569 struct ieee80211_if_sta
*ifsta
)
2571 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2572 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2574 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
2577 if ((ifsta
->flags
& (IEEE80211_STA_BSSID_SET
|
2578 IEEE80211_STA_AUTO_BSSID_SEL
)) &&
2579 (ifsta
->flags
& (IEEE80211_STA_SSID_SET
|
2580 IEEE80211_STA_AUTO_SSID_SEL
))) {
2581 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
2582 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2586 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta
*ifsta
,
2587 const char *ssid
, int ssid_len
)
2589 int tmp
, hidden_ssid
;
2591 if (ssid_len
== ifsta
->ssid_len
&&
2592 !memcmp(ifsta
->ssid
, ssid
, ssid_len
))
2595 if (ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
)
2601 if (ssid
[tmp
] != '\0') {
2607 if (hidden_ssid
&& ifsta
->ssid_len
== ssid_len
)
2610 if (ssid_len
== 1 && ssid
[0] == ' ')
2616 static int ieee80211_sta_config_auth(struct net_device
*dev
,
2617 struct ieee80211_if_sta
*ifsta
)
2619 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2620 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2621 struct ieee80211_sta_bss
*bss
, *selected
= NULL
;
2622 int top_rssi
= 0, freq
;
2624 if (!(ifsta
->flags
& (IEEE80211_STA_AUTO_SSID_SEL
|
2625 IEEE80211_STA_AUTO_BSSID_SEL
| IEEE80211_STA_AUTO_CHANNEL_SEL
))) {
2626 ifsta
->state
= IEEE80211_AUTHENTICATE
;
2627 ieee80211_sta_reset_auth(dev
, ifsta
);
2631 spin_lock_bh(&local
->sta_bss_lock
);
2632 freq
= local
->oper_channel
->freq
;
2633 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
2634 if (!(bss
->capability
& WLAN_CAPABILITY_ESS
))
2637 if (!!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
) ^
2638 !!sdata
->default_key
)
2641 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_CHANNEL_SEL
) &&
2645 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
) &&
2646 memcmp(bss
->bssid
, ifsta
->bssid
, ETH_ALEN
))
2649 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
) &&
2650 !ieee80211_sta_match_ssid(ifsta
, bss
->ssid
, bss
->ssid_len
))
2653 if (!selected
|| top_rssi
< bss
->rssi
) {
2655 top_rssi
= bss
->rssi
;
2659 atomic_inc(&selected
->users
);
2660 spin_unlock_bh(&local
->sta_bss_lock
);
2663 ieee80211_set_channel(local
, -1, selected
->freq
);
2664 if (!(ifsta
->flags
& IEEE80211_STA_SSID_SET
))
2665 ieee80211_sta_set_ssid(dev
, selected
->ssid
,
2666 selected
->ssid_len
);
2667 ieee80211_sta_set_bssid(dev
, selected
->bssid
);
2668 ieee80211_rx_bss_put(dev
, selected
);
2669 ifsta
->state
= IEEE80211_AUTHENTICATE
;
2670 ieee80211_sta_reset_auth(dev
, ifsta
);
2673 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
) {
2674 if (ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
)
2675 ieee80211_sta_start_scan(dev
, NULL
, 0);
2677 ieee80211_sta_start_scan(dev
, ifsta
->ssid
,
2679 ifsta
->state
= IEEE80211_AUTHENTICATE
;
2680 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
2682 ifsta
->state
= IEEE80211_DISABLED
;
2687 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
2688 struct ieee80211_if_sta
*ifsta
,
2689 struct ieee80211_sta_bss
*bss
)
2691 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2692 int res
, rates
, i
, j
;
2693 struct sk_buff
*skb
;
2694 struct ieee80211_mgmt
*mgmt
;
2695 struct ieee80211_tx_control control
;
2696 struct ieee80211_hw_mode
*mode
;
2697 struct rate_selection ratesel
;
2699 struct ieee80211_sub_if_data
*sdata
;
2701 /* Remove possible STA entries from other IBSS networks. */
2702 sta_info_flush(local
, NULL
);
2704 if (local
->ops
->reset_tsf
) {
2705 /* Reset own TSF to allow time synchronization work. */
2706 local
->ops
->reset_tsf(local_to_hw(local
));
2708 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
2709 res
= ieee80211_if_config(dev
);
2713 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2715 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2716 sdata
->drop_unencrypted
= bss
->capability
&
2717 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
2719 res
= ieee80211_set_channel(local
, -1, bss
->freq
);
2721 if (!(local
->oper_channel
->flag
& IEEE80211_CHAN_W_IBSS
)) {
2722 printk(KERN_DEBUG
"%s: IBSS not allowed on channel %d "
2723 "(%d MHz)\n", dev
->name
, local
->hw
.conf
.channel
,
2724 local
->hw
.conf
.freq
);
2728 /* Set beacon template based on scan results */
2729 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 400);
2734 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2736 mgmt
= (struct ieee80211_mgmt
*)
2737 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2738 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2739 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2740 IEEE80211_STYPE_BEACON
);
2741 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2742 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2743 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2744 mgmt
->u
.beacon
.beacon_int
=
2745 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2746 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2748 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2749 *pos
++ = WLAN_EID_SSID
;
2750 *pos
++ = ifsta
->ssid_len
;
2751 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2753 rates
= bss
->supp_rates_len
;
2756 pos
= skb_put(skb
, 2 + rates
);
2757 *pos
++ = WLAN_EID_SUPP_RATES
;
2759 memcpy(pos
, bss
->supp_rates
, rates
);
2761 pos
= skb_put(skb
, 2 + 1);
2762 *pos
++ = WLAN_EID_DS_PARAMS
;
2764 *pos
++ = bss
->channel
;
2766 pos
= skb_put(skb
, 2 + 2);
2767 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2769 /* FIX: set ATIM window based on scan results */
2773 if (bss
->supp_rates_len
> 8) {
2774 rates
= bss
->supp_rates_len
- 8;
2775 pos
= skb_put(skb
, 2 + rates
);
2776 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2778 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2781 memset(&control
, 0, sizeof(control
));
2782 rate_control_get_rate(dev
, local
->oper_hw_mode
, skb
, &ratesel
);
2783 if (!ratesel
.rate
) {
2784 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2785 "for IBSS beacon\n", dev
->name
);
2788 control
.vif
= &sdata
->vif
;
2790 (sdata
->bss_conf
.use_short_preamble
&&
2791 (ratesel
.rate
->flags
& IEEE80211_RATE_PREAMBLE2
)) ?
2792 ratesel
.rate
->val2
: ratesel
.rate
->val
;
2793 control
.antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
2794 control
.power_level
= local
->hw
.conf
.power_level
;
2795 control
.flags
|= IEEE80211_TXCTL_NO_ACK
;
2796 control
.retry_limit
= 1;
2798 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2799 if (ifsta
->probe_resp
) {
2800 mgmt
= (struct ieee80211_mgmt
*)
2801 ifsta
->probe_resp
->data
;
2802 mgmt
->frame_control
=
2803 IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2804 IEEE80211_STYPE_PROBE_RESP
);
2806 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2807 "template for IBSS\n", dev
->name
);
2810 if (local
->ops
->beacon_update
&&
2811 local
->ops
->beacon_update(local_to_hw(local
),
2812 skb
, &control
) == 0) {
2813 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2814 "template based on scan results\n", dev
->name
);
2819 mode
= local
->oper_hw_mode
;
2820 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2821 int bitrate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2822 for (j
= 0; j
< mode
->num_rates
; j
++)
2823 if (mode
->rates
[j
].rate
== bitrate
)
2826 ifsta
->supp_rates_bits
= rates
;
2830 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2831 "template\n", dev
->name
);
2835 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2836 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2838 ieee80211_rx_bss_put(dev
, bss
);
2844 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
2845 struct ieee80211_if_sta
*ifsta
)
2847 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2848 struct ieee80211_sta_bss
*bss
;
2849 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2850 struct ieee80211_hw_mode
*mode
;
2851 u8 bssid
[ETH_ALEN
], *pos
;
2853 DECLARE_MAC_BUF(mac
);
2856 /* Easier testing, use fixed BSSID. */
2857 memset(bssid
, 0xfe, ETH_ALEN
);
2859 /* Generate random, not broadcast, locally administered BSSID. Mix in
2860 * own MAC address to make sure that devices that do not have proper
2861 * random number generator get different BSSID. */
2862 get_random_bytes(bssid
, ETH_ALEN
);
2863 for (i
= 0; i
< ETH_ALEN
; i
++)
2864 bssid
[i
] ^= dev
->dev_addr
[i
];
2869 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID %s\n",
2870 dev
->name
, print_mac(mac
, bssid
));
2872 bss
= ieee80211_rx_bss_add(dev
, bssid
, local
->hw
.conf
.channel
,
2873 sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
);
2877 mode
= local
->oper_hw_mode
;
2879 if (local
->hw
.conf
.beacon_int
== 0)
2880 local
->hw
.conf
.beacon_int
= 100;
2881 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
2882 bss
->hw_mode
= local
->hw
.conf
.phymode
;
2883 bss
->freq
= local
->hw
.conf
.freq
;
2884 bss
->last_update
= jiffies
;
2885 bss
->capability
= WLAN_CAPABILITY_IBSS
;
2886 if (sdata
->default_key
) {
2887 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
2889 sdata
->drop_unencrypted
= 0;
2890 bss
->supp_rates_len
= mode
->num_rates
;
2891 pos
= bss
->supp_rates
;
2892 for (i
= 0; i
< mode
->num_rates
; i
++) {
2893 int rate
= mode
->rates
[i
].rate
;
2894 *pos
++ = (u8
) (rate
/ 5);
2897 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
2901 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
2902 struct ieee80211_if_sta
*ifsta
)
2904 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2905 struct ieee80211_sta_bss
*bss
;
2909 DECLARE_MAC_BUF(mac
);
2910 DECLARE_MAC_BUF(mac2
);
2912 if (ifsta
->ssid_len
== 0)
2915 active_ibss
= ieee80211_sta_active_ibss(dev
);
2916 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2917 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
2918 dev
->name
, active_ibss
);
2919 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2920 spin_lock_bh(&local
->sta_bss_lock
);
2921 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
2922 if (ifsta
->ssid_len
!= bss
->ssid_len
||
2923 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
2924 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
2926 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2927 printk(KERN_DEBUG
" bssid=%s found\n",
2928 print_mac(mac
, bss
->bssid
));
2929 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2930 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
2932 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
2935 spin_unlock_bh(&local
->sta_bss_lock
);
2937 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2938 printk(KERN_DEBUG
" sta_find_ibss: selected %s current "
2939 "%s\n", print_mac(mac
, bssid
), print_mac(mac2
, ifsta
->bssid
));
2940 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2941 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
2942 (bss
= ieee80211_rx_bss_get(dev
, bssid
, local
->hw
.conf
.channel
,
2943 ifsta
->ssid
, ifsta
->ssid_len
))) {
2944 printk(KERN_DEBUG
"%s: Selected IBSS BSSID %s"
2945 " based on configured SSID\n",
2946 dev
->name
, print_mac(mac
, bssid
));
2947 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
2949 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2950 printk(KERN_DEBUG
" did not try to join ibss\n");
2951 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2953 /* Selected IBSS not found in current scan results - try to scan */
2954 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
2955 !ieee80211_sta_active_ibss(dev
)) {
2956 mod_timer(&ifsta
->timer
, jiffies
+
2957 IEEE80211_IBSS_MERGE_INTERVAL
);
2958 } else if (time_after(jiffies
, local
->last_scan_completed
+
2959 IEEE80211_SCAN_INTERVAL
)) {
2960 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
2961 "join\n", dev
->name
);
2962 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
2964 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
2965 int interval
= IEEE80211_SCAN_INTERVAL
;
2967 if (time_after(jiffies
, ifsta
->ibss_join_req
+
2968 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
2969 if ((ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) &&
2970 local
->oper_channel
->flag
& IEEE80211_CHAN_W_IBSS
)
2971 return ieee80211_sta_create_ibss(dev
, ifsta
);
2972 if (ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) {
2973 printk(KERN_DEBUG
"%s: IBSS not allowed on the"
2974 " configured channel %d (%d MHz)\n",
2975 dev
->name
, local
->hw
.conf
.channel
,
2976 local
->hw
.conf
.freq
);
2979 /* No IBSS found - decrease scan interval and continue
2981 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
2984 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
2985 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
2993 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
2995 struct ieee80211_sub_if_data
*sdata
;
2996 struct ieee80211_if_sta
*ifsta
;
2997 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2999 if (len
> IEEE80211_MAX_SSID_LEN
)
3002 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
3004 if (local
->ops
->conf_tx
) {
3005 struct ieee80211_tx_queue_params qparam
;
3008 memset(&qparam
, 0, sizeof(qparam
));
3009 /* TODO: are these ok defaults for all hw_modes? */
3012 local
->hw
.conf
.phymode
== MODE_IEEE80211B
? 31 : 15;
3013 qparam
.cw_max
= 1023;
3014 qparam
.burst_time
= 0;
3015 for (i
= IEEE80211_TX_QUEUE_DATA0
; i
< NUM_TX_DATA_QUEUES
; i
++)
3017 local
->ops
->conf_tx(local_to_hw(local
),
3018 i
+ IEEE80211_TX_QUEUE_DATA0
,
3021 /* IBSS uses different parameters for Beacon sending */
3025 local
->ops
->conf_tx(local_to_hw(local
),
3026 IEEE80211_TX_QUEUE_BEACON
, &qparam
);
3029 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3030 ifsta
= &sdata
->u
.sta
;
3032 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
3033 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
3034 memcpy(ifsta
->ssid
, ssid
, len
);
3035 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
3036 ifsta
->ssid_len
= len
;
3039 ifsta
->flags
|= IEEE80211_STA_SSID_SET
;
3041 ifsta
->flags
&= ~IEEE80211_STA_SSID_SET
;
3042 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3043 !(ifsta
->flags
& IEEE80211_STA_BSSID_SET
)) {
3044 ifsta
->ibss_join_req
= jiffies
;
3045 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3046 return ieee80211_sta_find_ibss(dev
, ifsta
);
3052 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
3054 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3055 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3056 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
3057 *len
= ifsta
->ssid_len
;
3062 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
3064 struct ieee80211_sub_if_data
*sdata
;
3065 struct ieee80211_if_sta
*ifsta
;
3068 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3069 ifsta
= &sdata
->u
.sta
;
3071 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
3072 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
3073 res
= ieee80211_if_config(dev
);
3075 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
3076 "the low-level driver\n", dev
->name
);
3081 if (is_valid_ether_addr(bssid
))
3082 ifsta
->flags
|= IEEE80211_STA_BSSID_SET
;
3084 ifsta
->flags
&= ~IEEE80211_STA_BSSID_SET
;
3090 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
3091 struct ieee80211_sub_if_data
*sdata
,
3094 struct sk_buff
*skb
;
3095 struct ieee80211_hdr
*nullfunc
;
3098 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
3100 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
3101 "frame\n", sdata
->dev
->name
);
3104 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3106 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
3107 memset(nullfunc
, 0, 24);
3108 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
3109 IEEE80211_FCTL_TODS
;
3111 fc
|= IEEE80211_FCTL_PM
;
3112 nullfunc
->frame_control
= cpu_to_le16(fc
);
3113 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3114 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
3115 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3117 ieee80211_sta_tx(sdata
->dev
, skb
, 0);
3121 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
3123 struct ieee80211_local
*local
= hw_to_local(hw
);
3124 struct net_device
*dev
= local
->scan_dev
;
3125 struct ieee80211_sub_if_data
*sdata
;
3126 union iwreq_data wrqu
;
3128 local
->last_scan_completed
= jiffies
;
3129 memset(&wrqu
, 0, sizeof(wrqu
));
3130 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
3132 if (local
->sta_hw_scanning
) {
3133 local
->sta_hw_scanning
= 0;
3137 local
->sta_sw_scanning
= 0;
3138 if (ieee80211_hw_config(local
))
3139 printk(KERN_DEBUG
"%s: failed to restore operational "
3140 "channel after scan\n", dev
->name
);
3143 netif_tx_lock_bh(local
->mdev
);
3144 local
->filter_flags
&= ~FIF_BCN_PRBRESP_PROMISC
;
3145 local
->ops
->configure_filter(local_to_hw(local
),
3146 FIF_BCN_PRBRESP_PROMISC
,
3147 &local
->filter_flags
,
3148 local
->mdev
->mc_count
,
3149 local
->mdev
->mc_list
);
3151 netif_tx_unlock_bh(local
->mdev
);
3154 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3156 /* No need to wake the master device. */
3157 if (sdata
->dev
== local
->mdev
)
3160 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
) {
3161 if (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
)
3162 ieee80211_send_nullfunc(local
, sdata
, 0);
3163 ieee80211_sta_timer((unsigned long)sdata
);
3166 netif_wake_queue(sdata
->dev
);
3171 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3172 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
3173 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3174 if (!(ifsta
->flags
& IEEE80211_STA_BSSID_SET
) ||
3175 (!ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3176 !ieee80211_sta_active_ibss(dev
)))
3177 ieee80211_sta_find_ibss(dev
, ifsta
);
3180 EXPORT_SYMBOL(ieee80211_scan_completed
);
3182 void ieee80211_sta_scan_work(struct work_struct
*work
)
3184 struct ieee80211_local
*local
=
3185 container_of(work
, struct ieee80211_local
, scan_work
.work
);
3186 struct net_device
*dev
= local
->scan_dev
;
3187 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3188 struct ieee80211_hw_mode
*mode
;
3189 struct ieee80211_channel
*chan
;
3191 unsigned long next_delay
= 0;
3193 if (!local
->sta_sw_scanning
)
3196 switch (local
->scan_state
) {
3197 case SCAN_SET_CHANNEL
:
3198 mode
= local
->scan_hw_mode
;
3199 if (local
->scan_hw_mode
->list
.next
== &local
->modes_list
&&
3200 local
->scan_channel_idx
>= mode
->num_channels
) {
3201 ieee80211_scan_completed(local_to_hw(local
));
3204 skip
= !(local
->enabled_modes
& (1 << mode
->mode
));
3205 chan
= &mode
->channels
[local
->scan_channel_idx
];
3206 if (!(chan
->flag
& IEEE80211_CHAN_W_SCAN
) ||
3207 (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3208 !(chan
->flag
& IEEE80211_CHAN_W_IBSS
)) ||
3209 (local
->hw_modes
& local
->enabled_modes
&
3210 (1 << MODE_IEEE80211G
) && mode
->mode
== MODE_IEEE80211B
))
3215 printk(KERN_DEBUG
"%s: scan channel %d (%d MHz)\n",
3216 dev
->name
, chan
->chan
, chan
->freq
);
3219 local
->scan_channel
= chan
;
3220 if (ieee80211_hw_config(local
)) {
3221 printk(KERN_DEBUG
"%s: failed to set channel "
3222 "%d (%d MHz) for scan\n", dev
->name
,
3223 chan
->chan
, chan
->freq
);
3228 local
->scan_channel_idx
++;
3229 if (local
->scan_channel_idx
>= local
->scan_hw_mode
->num_channels
) {
3230 if (local
->scan_hw_mode
->list
.next
!= &local
->modes_list
) {
3231 local
->scan_hw_mode
= list_entry(local
->scan_hw_mode
->list
.next
,
3232 struct ieee80211_hw_mode
,
3234 local
->scan_channel_idx
= 0;
3241 next_delay
= IEEE80211_PROBE_DELAY
+
3242 usecs_to_jiffies(local
->hw
.channel_change_time
);
3243 local
->scan_state
= SCAN_SEND_PROBE
;
3245 case SCAN_SEND_PROBE
:
3246 if (local
->scan_channel
->flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
) {
3247 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
3248 local
->scan_ssid_len
);
3249 next_delay
= IEEE80211_CHANNEL_TIME
;
3251 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
3252 local
->scan_state
= SCAN_SET_CHANNEL
;
3256 if (local
->sta_sw_scanning
)
3257 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3262 static int ieee80211_sta_start_scan(struct net_device
*dev
,
3263 u8
*ssid
, size_t ssid_len
)
3265 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3266 struct ieee80211_sub_if_data
*sdata
;
3268 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
3271 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3272 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3275 * ScanType: ACTIVE, PASSIVE
3276 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3277 * a Probe frame during active scanning
3279 * MinChannelTime (>= ProbeDelay), in TU
3280 * MaxChannelTime: (>= MinChannelTime), in TU
3283 /* MLME-SCAN.confirm
3285 * ResultCode: SUCCESS, INVALID_PARAMETERS
3288 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3289 if (local
->scan_dev
== dev
)
3294 if (local
->ops
->hw_scan
) {
3295 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
3298 local
->sta_hw_scanning
= 1;
3299 local
->scan_dev
= dev
;
3304 local
->sta_sw_scanning
= 1;
3307 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3309 /* Don't stop the master interface, otherwise we can't transmit
3311 if (sdata
->dev
== local
->mdev
)
3314 netif_stop_queue(sdata
->dev
);
3315 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3316 (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
))
3317 ieee80211_send_nullfunc(local
, sdata
, 1);
3322 local
->scan_ssid_len
= ssid_len
;
3323 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
3325 local
->scan_ssid_len
= 0;
3326 local
->scan_state
= SCAN_SET_CHANNEL
;
3327 local
->scan_hw_mode
= list_entry(local
->modes_list
.next
,
3328 struct ieee80211_hw_mode
,
3330 local
->scan_channel_idx
= 0;
3331 local
->scan_dev
= dev
;
3333 netif_tx_lock_bh(local
->mdev
);
3334 local
->filter_flags
|= FIF_BCN_PRBRESP_PROMISC
;
3335 local
->ops
->configure_filter(local_to_hw(local
),
3336 FIF_BCN_PRBRESP_PROMISC
,
3337 &local
->filter_flags
,
3338 local
->mdev
->mc_count
,
3339 local
->mdev
->mc_list
);
3340 netif_tx_unlock_bh(local
->mdev
);
3342 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3343 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3344 IEEE80211_CHANNEL_TIME
);
3350 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
3352 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3353 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3354 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3356 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3357 return ieee80211_sta_start_scan(dev
, ssid
, ssid_len
);
3359 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3360 if (local
->scan_dev
== dev
)
3365 ifsta
->scan_ssid_len
= ssid_len
;
3367 memcpy(ifsta
->scan_ssid
, ssid
, ssid_len
);
3368 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
3369 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3374 ieee80211_sta_scan_result(struct net_device
*dev
,
3375 struct ieee80211_sta_bss
*bss
,
3376 char *current_ev
, char *end_buf
)
3378 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3379 struct iw_event iwe
;
3381 if (time_after(jiffies
,
3382 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
3385 if (!(local
->enabled_modes
& (1 << bss
->hw_mode
)))
3388 memset(&iwe
, 0, sizeof(iwe
));
3389 iwe
.cmd
= SIOCGIWAP
;
3390 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3391 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
3392 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3395 memset(&iwe
, 0, sizeof(iwe
));
3396 iwe
.cmd
= SIOCGIWESSID
;
3397 iwe
.u
.data
.length
= bss
->ssid_len
;
3398 iwe
.u
.data
.flags
= 1;
3399 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3402 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
3403 memset(&iwe
, 0, sizeof(iwe
));
3404 iwe
.cmd
= SIOCGIWMODE
;
3405 if (bss
->capability
& WLAN_CAPABILITY_ESS
)
3406 iwe
.u
.mode
= IW_MODE_MASTER
;
3408 iwe
.u
.mode
= IW_MODE_ADHOC
;
3409 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3413 memset(&iwe
, 0, sizeof(iwe
));
3414 iwe
.cmd
= SIOCGIWFREQ
;
3415 iwe
.u
.freq
.m
= bss
->channel
;
3417 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3419 iwe
.u
.freq
.m
= bss
->freq
* 100000;
3421 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3424 memset(&iwe
, 0, sizeof(iwe
));
3426 iwe
.u
.qual
.qual
= bss
->signal
;
3427 iwe
.u
.qual
.level
= bss
->rssi
;
3428 iwe
.u
.qual
.noise
= bss
->noise
;
3429 iwe
.u
.qual
.updated
= local
->wstats_flags
;
3430 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3433 memset(&iwe
, 0, sizeof(iwe
));
3434 iwe
.cmd
= SIOCGIWENCODE
;
3435 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
3436 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
3438 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
3439 iwe
.u
.data
.length
= 0;
3440 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
3442 if (bss
&& bss
->wpa_ie
) {
3443 memset(&iwe
, 0, sizeof(iwe
));
3444 iwe
.cmd
= IWEVGENIE
;
3445 iwe
.u
.data
.length
= bss
->wpa_ie_len
;
3446 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3450 if (bss
&& bss
->rsn_ie
) {
3451 memset(&iwe
, 0, sizeof(iwe
));
3452 iwe
.cmd
= IWEVGENIE
;
3453 iwe
.u
.data
.length
= bss
->rsn_ie_len
;
3454 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3458 if (bss
&& bss
->supp_rates_len
> 0) {
3459 /* display all supported rates in readable format */
3460 char *p
= current_ev
+ IW_EV_LCP_LEN
;
3463 memset(&iwe
, 0, sizeof(iwe
));
3464 iwe
.cmd
= SIOCGIWRATE
;
3465 /* Those two flags are ignored... */
3466 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
3468 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
3469 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
3471 p
= iwe_stream_add_value(current_ev
, p
,
3472 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
3479 buf
= kmalloc(30, GFP_ATOMIC
);
3481 memset(&iwe
, 0, sizeof(iwe
));
3482 iwe
.cmd
= IWEVCUSTOM
;
3483 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
3484 iwe
.u
.data
.length
= strlen(buf
);
3485 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
3495 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
3497 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3498 char *current_ev
= buf
;
3499 char *end_buf
= buf
+ len
;
3500 struct ieee80211_sta_bss
*bss
;
3502 spin_lock_bh(&local
->sta_bss_lock
);
3503 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3504 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
3505 spin_unlock_bh(&local
->sta_bss_lock
);
3508 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
3511 spin_unlock_bh(&local
->sta_bss_lock
);
3512 return current_ev
- buf
;
3516 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
3518 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3519 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3520 kfree(ifsta
->extra_ie
);
3522 ifsta
->extra_ie
= NULL
;
3523 ifsta
->extra_ie_len
= 0;
3526 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
3527 if (!ifsta
->extra_ie
) {
3528 ifsta
->extra_ie_len
= 0;
3531 memcpy(ifsta
->extra_ie
, ie
, len
);
3532 ifsta
->extra_ie_len
= len
;
3537 struct sta_info
* ieee80211_ibss_add_sta(struct net_device
*dev
,
3538 struct sk_buff
*skb
, u8
*bssid
,
3541 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3542 struct sta_info
*sta
;
3543 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3544 DECLARE_MAC_BUF(mac
);
3546 /* TODO: Could consider removing the least recently used entry and
3547 * allow new one to be added. */
3548 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
3549 if (net_ratelimit()) {
3550 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
3551 "entry %s\n", dev
->name
, print_mac(mac
, addr
));
3556 printk(KERN_DEBUG
"%s: Adding new IBSS station %s (dev=%s)\n",
3557 wiphy_name(local
->hw
.wiphy
), print_mac(mac
, addr
), dev
->name
);
3559 sta
= sta_info_add(local
, dev
, addr
, GFP_ATOMIC
);
3563 sta
->supp_rates
= sdata
->u
.sta
.supp_rates_bits
;
3565 rate_control_rate_init(sta
, local
);
3567 return sta
; /* caller will call sta_info_put() */
3571 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
3573 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3574 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3576 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
3579 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
3580 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
3583 ieee80211_send_deauth(dev
, ifsta
, reason
);
3584 ieee80211_set_disassoc(dev
, ifsta
, 1);
3589 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
3591 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3592 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3594 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
3597 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3600 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
))
3603 ieee80211_send_disassoc(dev
, ifsta
, reason
);
3604 ieee80211_set_disassoc(dev
, ifsta
, 0);