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 freq
,
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
)
230 return (1 << ecw
) - 1;
233 static void ieee80211_sta_wmm_params(struct net_device
*dev
,
234 struct ieee80211_if_sta
*ifsta
,
235 u8
*wmm_param
, size_t wmm_param_len
)
237 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
238 struct ieee80211_tx_queue_params params
;
243 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
245 count
= wmm_param
[6] & 0x0f;
246 if (count
== ifsta
->wmm_last_param_set
)
248 ifsta
->wmm_last_param_set
= count
;
251 left
= wmm_param_len
- 8;
253 memset(¶ms
, 0, sizeof(params
));
255 if (!local
->ops
->conf_tx
)
259 for (; left
>= 4; left
-= 4, pos
+= 4) {
260 int aci
= (pos
[0] >> 5) & 0x03;
261 int acm
= (pos
[0] >> 4) & 0x01;
266 queue
= IEEE80211_TX_QUEUE_DATA3
;
268 local
->wmm_acm
|= BIT(0) | BIT(3);
272 queue
= IEEE80211_TX_QUEUE_DATA1
;
274 local
->wmm_acm
|= BIT(4) | BIT(5);
278 queue
= IEEE80211_TX_QUEUE_DATA0
;
280 local
->wmm_acm
|= BIT(6) | BIT(7);
285 queue
= IEEE80211_TX_QUEUE_DATA2
;
287 local
->wmm_acm
|= BIT(1) | BIT(2);
292 params
.aifs
= pos
[0] & 0x0f;
293 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
294 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
295 params
.txop
= pos
[2] | (pos
[3] << 8);
296 #ifdef CONFIG_MAC80211_DEBUG
297 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
298 "cWmin=%d cWmax=%d txop=%d\n",
299 dev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
300 params
.cw_max
, params
.txop
);
302 /* TODO: handle ACM (block TX, fallback to next lowest allowed
304 if (local
->ops
->conf_tx(local_to_hw(local
), queue
, ¶ms
)) {
305 printk(KERN_DEBUG
"%s: failed to set TX queue "
306 "parameters for queue %d\n", dev
->name
, queue
);
312 static u32
ieee80211_handle_erp_ie(struct ieee80211_sub_if_data
*sdata
,
315 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
316 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
317 bool use_protection
= (erp_value
& WLAN_ERP_USE_PROTECTION
) != 0;
318 bool preamble_mode
= (erp_value
& WLAN_ERP_BARKER_PREAMBLE
) != 0;
319 DECLARE_MAC_BUF(mac
);
322 if (use_protection
!= bss_conf
->use_cts_prot
) {
323 if (net_ratelimit()) {
324 printk(KERN_DEBUG
"%s: CTS protection %s (BSSID="
327 use_protection
? "enabled" : "disabled",
328 print_mac(mac
, ifsta
->bssid
));
330 bss_conf
->use_cts_prot
= use_protection
;
331 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
334 if (preamble_mode
!= bss_conf
->use_short_preamble
) {
335 if (net_ratelimit()) {
336 printk(KERN_DEBUG
"%s: switched to %s barker preamble"
339 (preamble_mode
== WLAN_ERP_PREAMBLE_SHORT
) ?
341 print_mac(mac
, ifsta
->bssid
));
343 bss_conf
->use_short_preamble
= preamble_mode
;
344 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
350 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap
*ht_cap_ie
,
351 struct ieee80211_ht_info
*ht_info
)
357 memset(ht_info
, 0, sizeof(*ht_info
));
360 u8 ampdu_info
= ht_cap_ie
->ampdu_params_info
;
362 ht_info
->ht_supported
= 1;
363 ht_info
->cap
= le16_to_cpu(ht_cap_ie
->cap_info
);
364 ht_info
->ampdu_factor
=
365 ampdu_info
& IEEE80211_HT_CAP_AMPDU_FACTOR
;
366 ht_info
->ampdu_density
=
367 (ampdu_info
& IEEE80211_HT_CAP_AMPDU_DENSITY
) >> 2;
368 memcpy(ht_info
->supp_mcs_set
, ht_cap_ie
->supp_mcs_set
, 16);
370 ht_info
->ht_supported
= 0;
375 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
376 struct ieee80211_ht_addt_info
*ht_add_info_ie
,
377 struct ieee80211_ht_bss_info
*bss_info
)
379 if (bss_info
== NULL
)
382 memset(bss_info
, 0, sizeof(*bss_info
));
384 if (ht_add_info_ie
) {
386 op_mode
= le16_to_cpu(ht_add_info_ie
->operation_mode
);
388 bss_info
->primary_channel
= ht_add_info_ie
->control_chan
;
389 bss_info
->bss_cap
= ht_add_info_ie
->ht_param
;
390 bss_info
->bss_op_mode
= (u8
)(op_mode
& 0xff);
396 static void ieee80211_sta_send_associnfo(struct net_device
*dev
,
397 struct ieee80211_if_sta
*ifsta
)
402 union iwreq_data wrqu
;
404 if (!ifsta
->assocreq_ies
&& !ifsta
->assocresp_ies
)
407 buf
= kmalloc(50 + 2 * (ifsta
->assocreq_ies_len
+
408 ifsta
->assocresp_ies_len
), GFP_KERNEL
);
412 len
= sprintf(buf
, "ASSOCINFO(");
413 if (ifsta
->assocreq_ies
) {
414 len
+= sprintf(buf
+ len
, "ReqIEs=");
415 for (i
= 0; i
< ifsta
->assocreq_ies_len
; i
++) {
416 len
+= sprintf(buf
+ len
, "%02x",
417 ifsta
->assocreq_ies
[i
]);
420 if (ifsta
->assocresp_ies
) {
421 if (ifsta
->assocreq_ies
)
422 len
+= sprintf(buf
+ len
, " ");
423 len
+= sprintf(buf
+ len
, "RespIEs=");
424 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
425 len
+= sprintf(buf
+ len
, "%02x",
426 ifsta
->assocresp_ies
[i
]);
429 len
+= sprintf(buf
+ len
, ")");
431 if (len
> IW_CUSTOM_MAX
) {
432 len
= sprintf(buf
, "ASSOCRESPIE=");
433 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
434 len
+= sprintf(buf
+ len
, "%02x",
435 ifsta
->assocresp_ies
[i
]);
439 memset(&wrqu
, 0, sizeof(wrqu
));
440 wrqu
.data
.length
= len
;
441 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
447 static void ieee80211_set_associated(struct net_device
*dev
,
448 struct ieee80211_if_sta
*ifsta
,
451 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
452 struct ieee80211_local
*local
= sdata
->local
;
453 union iwreq_data wrqu
;
454 u32 changed
= BSS_CHANGED_ASSOC
;
457 struct ieee80211_sta_bss
*bss
;
459 ifsta
->flags
|= IEEE80211_STA_ASSOCIATED
;
461 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
464 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
465 local
->hw
.conf
.channel
->center_freq
,
466 ifsta
->ssid
, ifsta
->ssid_len
);
468 if (bss
->has_erp_value
)
469 changed
|= ieee80211_handle_erp_ie(
470 sdata
, bss
->erp_value
);
471 ieee80211_rx_bss_put(dev
, bss
);
474 netif_carrier_on(dev
);
475 ifsta
->flags
|= IEEE80211_STA_PREV_BSSID_SET
;
476 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
477 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
478 ieee80211_sta_send_associnfo(dev
, ifsta
);
480 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
482 netif_carrier_off(dev
);
483 ieee80211_reset_erp_info(dev
);
484 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
486 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
487 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
488 ifsta
->last_probe
= jiffies
;
489 ieee80211_led_assoc(local
, assoc
);
491 sdata
->bss_conf
.assoc
= assoc
;
492 ieee80211_bss_info_change_notify(sdata
, changed
);
495 static void ieee80211_set_disassoc(struct net_device
*dev
,
496 struct ieee80211_if_sta
*ifsta
, int deauth
)
499 ifsta
->auth_tries
= 0;
500 ifsta
->assoc_tries
= 0;
501 ieee80211_set_associated(dev
, ifsta
, 0);
504 static void ieee80211_sta_tx(struct net_device
*dev
, struct sk_buff
*skb
,
507 struct ieee80211_sub_if_data
*sdata
;
508 struct ieee80211_tx_packet_data
*pkt_data
;
510 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
511 skb
->dev
= sdata
->local
->mdev
;
512 skb_set_mac_header(skb
, 0);
513 skb_set_network_header(skb
, 0);
514 skb_set_transport_header(skb
, 0);
516 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
517 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
518 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
520 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
526 static void ieee80211_send_auth(struct net_device
*dev
,
527 struct ieee80211_if_sta
*ifsta
,
528 int transaction
, u8
*extra
, size_t extra_len
,
531 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
533 struct ieee80211_mgmt
*mgmt
;
535 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
536 sizeof(*mgmt
) + 6 + extra_len
);
538 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
539 "frame\n", dev
->name
);
542 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
544 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
545 memset(mgmt
, 0, 24 + 6);
546 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
547 IEEE80211_STYPE_AUTH
);
549 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
550 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
551 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
552 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
553 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
554 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
555 ifsta
->auth_transaction
= transaction
+ 1;
556 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
558 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
560 ieee80211_sta_tx(dev
, skb
, encrypt
);
564 static void ieee80211_authenticate(struct net_device
*dev
,
565 struct ieee80211_if_sta
*ifsta
)
567 DECLARE_MAC_BUF(mac
);
570 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
571 printk(KERN_DEBUG
"%s: authentication with AP %s"
573 dev
->name
, print_mac(mac
, ifsta
->bssid
));
574 ifsta
->state
= IEEE80211_DISABLED
;
578 ifsta
->state
= IEEE80211_AUTHENTICATE
;
579 printk(KERN_DEBUG
"%s: authenticate with AP %s\n",
580 dev
->name
, print_mac(mac
, ifsta
->bssid
));
582 ieee80211_send_auth(dev
, ifsta
, 1, NULL
, 0, 0);
584 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_AUTH_TIMEOUT
);
588 static void ieee80211_send_assoc(struct net_device
*dev
,
589 struct ieee80211_if_sta
*ifsta
)
591 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
593 struct ieee80211_mgmt
*mgmt
;
597 struct ieee80211_sta_bss
*bss
;
599 struct ieee80211_supported_band
*sband
;
601 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
602 sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
605 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
606 "frame\n", dev
->name
);
609 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
611 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
613 capab
= ifsta
->capab
;
615 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
) {
616 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
617 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
618 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
619 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
622 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
623 local
->hw
.conf
.channel
->center_freq
,
624 ifsta
->ssid
, ifsta
->ssid_len
);
626 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
627 capab
|= WLAN_CAPABILITY_PRIVACY
;
631 ieee80211_rx_bss_put(dev
, bss
);
634 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
636 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
637 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
638 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
640 if (ifsta
->flags
& IEEE80211_STA_PREV_BSSID_SET
) {
642 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
643 IEEE80211_STYPE_REASSOC_REQ
);
644 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
645 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
646 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
650 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
651 IEEE80211_STYPE_ASSOC_REQ
);
652 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
653 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
657 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
658 *pos
++ = WLAN_EID_SSID
;
659 *pos
++ = ifsta
->ssid_len
;
660 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
662 len
= sband
->n_bitrates
;
665 pos
= skb_put(skb
, len
+ 2);
666 *pos
++ = WLAN_EID_SUPP_RATES
;
668 for (i
= 0; i
< len
; i
++) {
669 int rate
= sband
->bitrates
[i
].bitrate
;
670 *pos
++ = (u8
) (rate
/ 5);
673 if (sband
->n_bitrates
> len
) {
674 pos
= skb_put(skb
, sband
->n_bitrates
- len
+ 2);
675 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
676 *pos
++ = sband
->n_bitrates
- len
;
677 for (i
= len
; i
< sband
->n_bitrates
; i
++) {
678 int rate
= sband
->bitrates
[i
].bitrate
;
679 *pos
++ = (u8
) (rate
/ 5);
683 if (ifsta
->extra_ie
) {
684 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
685 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
688 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
689 pos
= skb_put(skb
, 9);
690 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
691 *pos
++ = 7; /* len */
692 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
695 *pos
++ = 2; /* WME */
696 *pos
++ = 0; /* WME info */
697 *pos
++ = 1; /* WME ver */
700 /* wmm support is a must to HT */
701 if (wmm
&& sband
->ht_info
.ht_supported
) {
702 __le16 tmp
= cpu_to_le16(sband
->ht_info
.cap
);
703 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
)+2);
704 *pos
++ = WLAN_EID_HT_CAPABILITY
;
705 *pos
++ = sizeof(struct ieee80211_ht_cap
);
706 memset(pos
, 0, sizeof(struct ieee80211_ht_cap
));
707 memcpy(pos
, &tmp
, sizeof(u16
));
709 /* TODO: needs a define here for << 2 */
710 *pos
++ = sband
->ht_info
.ampdu_factor
|
711 (sband
->ht_info
.ampdu_density
<< 2);
712 memcpy(pos
, sband
->ht_info
.supp_mcs_set
, 16);
715 kfree(ifsta
->assocreq_ies
);
716 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
717 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_KERNEL
);
718 if (ifsta
->assocreq_ies
)
719 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
721 ieee80211_sta_tx(dev
, skb
, 0);
725 static void ieee80211_send_deauth(struct net_device
*dev
,
726 struct ieee80211_if_sta
*ifsta
, u16 reason
)
728 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
730 struct ieee80211_mgmt
*mgmt
;
732 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
734 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
735 "frame\n", dev
->name
);
738 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
740 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
742 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
743 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
744 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
745 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
746 IEEE80211_STYPE_DEAUTH
);
748 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
750 ieee80211_sta_tx(dev
, skb
, 0);
754 static void ieee80211_send_disassoc(struct net_device
*dev
,
755 struct ieee80211_if_sta
*ifsta
, u16 reason
)
757 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
759 struct ieee80211_mgmt
*mgmt
;
761 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
763 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
764 "frame\n", dev
->name
);
767 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
769 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
771 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
772 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
773 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
774 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
775 IEEE80211_STYPE_DISASSOC
);
777 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
779 ieee80211_sta_tx(dev
, skb
, 0);
783 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
784 struct ieee80211_if_sta
*ifsta
)
786 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
787 struct ieee80211_sta_bss
*bss
;
792 if (!ifsta
|| (ifsta
->flags
& IEEE80211_STA_MIXED_CELL
))
795 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
796 local
->hw
.conf
.channel
->center_freq
,
797 ifsta
->ssid
, ifsta
->ssid_len
);
801 bss_privacy
= !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
802 wep_privacy
= !!ieee80211_sta_wep_configured(dev
);
803 privacy_invoked
= !!(ifsta
->flags
& IEEE80211_STA_PRIVACY_INVOKED
);
805 ieee80211_rx_bss_put(dev
, bss
);
807 if ((bss_privacy
== wep_privacy
) || (bss_privacy
== privacy_invoked
))
814 static void ieee80211_associate(struct net_device
*dev
,
815 struct ieee80211_if_sta
*ifsta
)
817 DECLARE_MAC_BUF(mac
);
819 ifsta
->assoc_tries
++;
820 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
821 printk(KERN_DEBUG
"%s: association with AP %s"
823 dev
->name
, print_mac(mac
, ifsta
->bssid
));
824 ifsta
->state
= IEEE80211_DISABLED
;
828 ifsta
->state
= IEEE80211_ASSOCIATE
;
829 printk(KERN_DEBUG
"%s: associate with AP %s\n",
830 dev
->name
, print_mac(mac
, ifsta
->bssid
));
831 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
832 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
833 "mixed-cell disabled - abort association\n", dev
->name
);
834 ifsta
->state
= IEEE80211_DISABLED
;
838 ieee80211_send_assoc(dev
, ifsta
);
840 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_ASSOC_TIMEOUT
);
844 static void ieee80211_associated(struct net_device
*dev
,
845 struct ieee80211_if_sta
*ifsta
)
847 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
848 struct sta_info
*sta
;
850 DECLARE_MAC_BUF(mac
);
852 /* TODO: start monitoring current AP signal quality and number of
853 * missed beacons. Scan other channels every now and then and search
855 /* TODO: remove expired BSSes */
857 ifsta
->state
= IEEE80211_ASSOCIATED
;
859 sta
= sta_info_get(local
, ifsta
->bssid
);
861 printk(KERN_DEBUG
"%s: No STA entry for own AP %s\n",
862 dev
->name
, print_mac(mac
, ifsta
->bssid
));
866 if (time_after(jiffies
,
867 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
868 if (ifsta
->flags
& IEEE80211_STA_PROBEREQ_POLL
) {
869 printk(KERN_DEBUG
"%s: No ProbeResp from "
870 "current AP %s - assume out of "
872 dev
->name
, print_mac(mac
, ifsta
->bssid
));
876 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
878 local
->scan_ssid_len
);
879 ifsta
->flags
^= IEEE80211_STA_PROBEREQ_POLL
;
881 ifsta
->flags
&= ~IEEE80211_STA_PROBEREQ_POLL
;
882 if (time_after(jiffies
, ifsta
->last_probe
+
883 IEEE80211_PROBE_INTERVAL
)) {
884 ifsta
->last_probe
= jiffies
;
885 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
893 ifsta
->state
= IEEE80211_DISABLED
;
894 ieee80211_set_associated(dev
, ifsta
, 0);
896 mod_timer(&ifsta
->timer
, jiffies
+
897 IEEE80211_MONITORING_INTERVAL
);
902 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
903 u8
*ssid
, size_t ssid_len
)
905 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
906 struct ieee80211_supported_band
*sband
;
908 struct ieee80211_mgmt
*mgmt
;
909 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
912 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200);
914 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
915 "request\n", dev
->name
);
918 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
920 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
922 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
923 IEEE80211_STYPE_PROBE_REQ
);
924 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
926 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
927 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
929 memset(mgmt
->da
, 0xff, ETH_ALEN
);
930 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
932 pos
= skb_put(skb
, 2 + ssid_len
);
933 *pos
++ = WLAN_EID_SSID
;
935 memcpy(pos
, ssid
, ssid_len
);
937 supp_rates
= skb_put(skb
, 2);
938 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
940 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
942 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
943 struct ieee80211_rate
*rate
= &sband
->bitrates
[i
];
945 pos
= skb_put(skb
, 1);
947 } else if (supp_rates
[1] == 8) {
948 esupp_rates
= skb_put(skb
, 3);
949 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
951 pos
= &esupp_rates
[2];
953 pos
= skb_put(skb
, 1);
956 *pos
= rate
->bitrate
/ 5;
959 ieee80211_sta_tx(dev
, skb
, 0);
963 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
965 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
966 if (!sdata
|| !sdata
->default_key
||
967 sdata
->default_key
->conf
.alg
!= ALG_WEP
)
973 static void ieee80211_auth_completed(struct net_device
*dev
,
974 struct ieee80211_if_sta
*ifsta
)
976 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
977 ifsta
->flags
|= IEEE80211_STA_AUTHENTICATED
;
978 ieee80211_associate(dev
, ifsta
);
982 static void ieee80211_auth_challenge(struct net_device
*dev
,
983 struct ieee80211_if_sta
*ifsta
,
984 struct ieee80211_mgmt
*mgmt
,
988 struct ieee802_11_elems elems
;
990 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
991 pos
= mgmt
->u
.auth
.variable
;
992 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
993 if (!elems
.challenge
) {
994 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
995 "frame\n", dev
->name
);
998 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
999 elems
.challenge_len
+ 2, 1);
1002 static void ieee80211_send_addba_resp(struct net_device
*dev
, u8
*da
, u16 tid
,
1003 u8 dialog_token
, u16 status
, u16 policy
,
1004 u16 buf_size
, u16 timeout
)
1006 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1007 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1008 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1009 struct sk_buff
*skb
;
1010 struct ieee80211_mgmt
*mgmt
;
1013 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1014 sizeof(mgmt
->u
.action
.u
.addba_resp
));
1016 printk(KERN_DEBUG
"%s: failed to allocate buffer "
1017 "for addba resp frame\n", dev
->name
);
1021 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1022 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1023 memset(mgmt
, 0, 24);
1024 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1025 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1026 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1027 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1029 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1030 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1031 IEEE80211_STYPE_ACTION
);
1033 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_resp
));
1034 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1035 mgmt
->u
.action
.u
.addba_resp
.action_code
= WLAN_ACTION_ADDBA_RESP
;
1036 mgmt
->u
.action
.u
.addba_resp
.dialog_token
= dialog_token
;
1038 capab
= (u16
)(policy
<< 1); /* bit 1 aggregation policy */
1039 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1040 capab
|= (u16
)(buf_size
<< 6); /* bit 15:6 max size of aggregation */
1042 mgmt
->u
.action
.u
.addba_resp
.capab
= cpu_to_le16(capab
);
1043 mgmt
->u
.action
.u
.addba_resp
.timeout
= cpu_to_le16(timeout
);
1044 mgmt
->u
.action
.u
.addba_resp
.status
= cpu_to_le16(status
);
1046 ieee80211_sta_tx(dev
, skb
, 0);
1051 void ieee80211_send_addba_request(struct net_device
*dev
, const u8
*da
,
1052 u16 tid
, u8 dialog_token
, u16 start_seq_num
,
1053 u16 agg_size
, u16 timeout
)
1055 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1056 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1057 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1058 struct sk_buff
*skb
;
1059 struct ieee80211_mgmt
*mgmt
;
1062 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1063 sizeof(mgmt
->u
.action
.u
.addba_req
));
1067 printk(KERN_ERR
"%s: failed to allocate buffer "
1068 "for addba request frame\n", dev
->name
);
1071 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1072 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1073 memset(mgmt
, 0, 24);
1074 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1075 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1076 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1077 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1079 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1081 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1082 IEEE80211_STYPE_ACTION
);
1084 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_req
));
1086 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1087 mgmt
->u
.action
.u
.addba_req
.action_code
= WLAN_ACTION_ADDBA_REQ
;
1089 mgmt
->u
.action
.u
.addba_req
.dialog_token
= dialog_token
;
1090 capab
= (u16
)(1 << 1); /* bit 1 aggregation policy */
1091 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1092 capab
|= (u16
)(agg_size
<< 6); /* bit 15:6 max size of aggergation */
1094 mgmt
->u
.action
.u
.addba_req
.capab
= cpu_to_le16(capab
);
1096 mgmt
->u
.action
.u
.addba_req
.timeout
= cpu_to_le16(timeout
);
1097 mgmt
->u
.action
.u
.addba_req
.start_seq_num
=
1098 cpu_to_le16(start_seq_num
<< 4);
1100 ieee80211_sta_tx(dev
, skb
, 0);
1103 static void ieee80211_sta_process_addba_request(struct net_device
*dev
,
1104 struct ieee80211_mgmt
*mgmt
,
1107 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1108 struct ieee80211_hw
*hw
= &local
->hw
;
1109 struct ieee80211_conf
*conf
= &hw
->conf
;
1110 struct sta_info
*sta
;
1111 struct tid_ampdu_rx
*tid_agg_rx
;
1112 u16 capab
, tid
, timeout
, ba_policy
, buf_size
, start_seq_num
, status
;
1114 int ret
= -EOPNOTSUPP
;
1115 DECLARE_MAC_BUF(mac
);
1117 sta
= sta_info_get(local
, mgmt
->sa
);
1121 /* extract session parameters from addba request frame */
1122 dialog_token
= mgmt
->u
.action
.u
.addba_req
.dialog_token
;
1123 timeout
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.timeout
);
1125 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.start_seq_num
) >> 4;
1127 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1128 ba_policy
= (capab
& IEEE80211_ADDBA_PARAM_POLICY_MASK
) >> 1;
1129 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1130 buf_size
= (capab
& IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
) >> 6;
1132 status
= WLAN_STATUS_REQUEST_DECLINED
;
1134 /* sanity check for incoming parameters:
1135 * check if configuration can support the BA policy
1136 * and if buffer size does not exceeds max value */
1137 if (((ba_policy
!= 1)
1138 && (!(conf
->ht_conf
.cap
& IEEE80211_HT_CAP_DELAY_BA
)))
1139 || (buf_size
> IEEE80211_MAX_AMPDU_BUF
)) {
1140 status
= WLAN_STATUS_INVALID_QOS_PARAM
;
1141 #ifdef CONFIG_MAC80211_HT_DEBUG
1142 if (net_ratelimit())
1143 printk(KERN_DEBUG
"Block Ack Req with bad params from "
1144 "%s on tid %u. policy %d, buffer size %d\n",
1145 print_mac(mac
, mgmt
->sa
), tid
, ba_policy
,
1147 #endif /* CONFIG_MAC80211_HT_DEBUG */
1150 /* determine default buffer size */
1151 if (buf_size
== 0) {
1152 struct ieee80211_supported_band
*sband
;
1154 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
1155 buf_size
= IEEE80211_MIN_AMPDU_BUF
;
1156 buf_size
= buf_size
<< sband
->ht_info
.ampdu_factor
;
1159 tid_agg_rx
= &sta
->ampdu_mlme
.tid_rx
[tid
];
1161 /* examine state machine */
1162 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1164 if (tid_agg_rx
->state
!= HT_AGG_STATE_IDLE
) {
1165 #ifdef CONFIG_MAC80211_HT_DEBUG
1166 if (net_ratelimit())
1167 printk(KERN_DEBUG
"unexpected Block Ack Req from "
1169 print_mac(mac
, mgmt
->sa
), tid
);
1170 #endif /* CONFIG_MAC80211_HT_DEBUG */
1174 /* prepare reordering buffer */
1175 tid_agg_rx
->reorder_buf
=
1176 kmalloc(buf_size
* sizeof(struct sk_buf
*), GFP_ATOMIC
);
1177 if (!tid_agg_rx
->reorder_buf
) {
1178 if (net_ratelimit())
1179 printk(KERN_ERR
"can not allocate reordering buffer "
1180 "to tid %d\n", tid
);
1183 memset(tid_agg_rx
->reorder_buf
, 0,
1184 buf_size
* sizeof(struct sk_buf
*));
1186 if (local
->ops
->ampdu_action
)
1187 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_START
,
1188 sta
->addr
, tid
, &start_seq_num
);
1189 #ifdef CONFIG_MAC80211_HT_DEBUG
1190 printk(KERN_DEBUG
"Rx A-MPDU on tid %d result %d", tid
, ret
);
1191 #endif /* CONFIG_MAC80211_HT_DEBUG */
1194 kfree(tid_agg_rx
->reorder_buf
);
1198 /* change state and send addba resp */
1199 tid_agg_rx
->state
= HT_AGG_STATE_OPERATIONAL
;
1200 tid_agg_rx
->dialog_token
= dialog_token
;
1201 tid_agg_rx
->ssn
= start_seq_num
;
1202 tid_agg_rx
->head_seq_num
= start_seq_num
;
1203 tid_agg_rx
->buf_size
= buf_size
;
1204 tid_agg_rx
->timeout
= timeout
;
1205 tid_agg_rx
->stored_mpdu_num
= 0;
1206 status
= WLAN_STATUS_SUCCESS
;
1208 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1211 ieee80211_send_addba_resp(sta
->dev
, sta
->addr
, tid
, dialog_token
,
1212 status
, 1, buf_size
, timeout
);
1216 static void ieee80211_sta_process_addba_resp(struct net_device
*dev
,
1217 struct ieee80211_mgmt
*mgmt
,
1220 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1221 struct ieee80211_hw
*hw
= &local
->hw
;
1222 struct sta_info
*sta
;
1227 sta
= sta_info_get(local
, mgmt
->sa
);
1231 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.capab
);
1232 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1234 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
1236 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1238 if (mgmt
->u
.action
.u
.addba_resp
.dialog_token
!=
1239 sta
->ampdu_mlme
.tid_tx
[tid
].dialog_token
) {
1240 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1241 #ifdef CONFIG_MAC80211_HT_DEBUG
1242 printk(KERN_DEBUG
"wrong addBA response token, tid %d\n", tid
);
1243 #endif /* CONFIG_MAC80211_HT_DEBUG */
1248 del_timer_sync(&sta
->ampdu_mlme
.tid_tx
[tid
].addba_resp_timer
);
1249 #ifdef CONFIG_MAC80211_HT_DEBUG
1250 printk(KERN_DEBUG
"switched off addBA timer for tid %d \n", tid
);
1251 #endif /* CONFIG_MAC80211_HT_DEBUG */
1252 if (le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.status
)
1253 == WLAN_STATUS_SUCCESS
) {
1254 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1255 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1256 printk(KERN_DEBUG
"state not HT_ADDBA_REQUESTED_MSK:"
1262 if (*state
& HT_ADDBA_RECEIVED_MSK
)
1263 printk(KERN_DEBUG
"double addBA response\n");
1265 *state
|= HT_ADDBA_RECEIVED_MSK
;
1266 sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
= 0;
1268 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
1269 printk(KERN_DEBUG
"Aggregation on for tid %d \n", tid
);
1270 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
1273 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1274 printk(KERN_DEBUG
"recipient accepted agg: tid %d \n", tid
);
1276 printk(KERN_DEBUG
"recipient rejected agg: tid %d \n", tid
);
1278 sta
->ampdu_mlme
.tid_tx
[tid
].addba_req_num
++;
1279 /* this will allow the state check in stop_BA_session */
1280 *state
= HT_AGG_STATE_OPERATIONAL
;
1281 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1282 ieee80211_stop_tx_ba_session(hw
, sta
->addr
, tid
,
1283 WLAN_BACK_INITIATOR
);
1288 void ieee80211_send_delba(struct net_device
*dev
, const u8
*da
, u16 tid
,
1289 u16 initiator
, u16 reason_code
)
1291 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1292 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1293 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1294 struct sk_buff
*skb
;
1295 struct ieee80211_mgmt
*mgmt
;
1298 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1299 sizeof(mgmt
->u
.action
.u
.delba
));
1302 printk(KERN_ERR
"%s: failed to allocate buffer "
1303 "for delba frame\n", dev
->name
);
1307 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1308 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1309 memset(mgmt
, 0, 24);
1310 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1311 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1312 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1313 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1315 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1316 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1317 IEEE80211_STYPE_ACTION
);
1319 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.delba
));
1321 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1322 mgmt
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
1323 params
= (u16
)(initiator
<< 11); /* bit 11 initiator */
1324 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
1326 mgmt
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
1327 mgmt
->u
.action
.u
.delba
.reason_code
= cpu_to_le16(reason_code
);
1329 ieee80211_sta_tx(dev
, skb
, 0);
1332 void ieee80211_sta_stop_rx_ba_session(struct net_device
*dev
, u8
*ra
, u16 tid
,
1333 u16 initiator
, u16 reason
)
1335 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1336 struct ieee80211_hw
*hw
= &local
->hw
;
1337 struct sta_info
*sta
;
1340 sta
= sta_info_get(local
, ra
);
1344 /* check if TID is in operational state */
1345 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1346 if (sta
->ampdu_mlme
.tid_rx
[tid
].state
1347 != HT_AGG_STATE_OPERATIONAL
) {
1348 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1352 sta
->ampdu_mlme
.tid_rx
[tid
].state
=
1353 HT_AGG_STATE_REQ_STOP_BA_MSK
|
1354 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
1355 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1357 /* stop HW Rx aggregation. ampdu_action existence
1358 * already verified in session init so we add the BUG_ON */
1359 BUG_ON(!local
->ops
->ampdu_action
);
1361 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_STOP
,
1364 printk(KERN_DEBUG
"HW problem - can not stop rx "
1365 "aggergation for tid %d\n", tid
);
1367 /* shutdown timer has not expired */
1368 if (initiator
!= WLAN_BACK_TIMER
)
1369 del_timer_sync(&sta
->ampdu_mlme
.tid_rx
[tid
].
1372 /* check if this is a self generated aggregation halt */
1373 if (initiator
== WLAN_BACK_RECIPIENT
|| initiator
== WLAN_BACK_TIMER
)
1374 ieee80211_send_delba(dev
, ra
, tid
, 0, reason
);
1376 /* free the reordering buffer */
1377 for (i
= 0; i
< sta
->ampdu_mlme
.tid_rx
[tid
].buf_size
; i
++) {
1378 if (sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
[i
]) {
1379 /* release the reordered frames */
1380 dev_kfree_skb(sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
[i
]);
1381 sta
->ampdu_mlme
.tid_rx
[tid
].stored_mpdu_num
--;
1382 sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
[i
] = NULL
;
1385 kfree(sta
->ampdu_mlme
.tid_rx
[tid
].reorder_buf
);
1387 sta
->ampdu_mlme
.tid_rx
[tid
].state
= HT_AGG_STATE_IDLE
;
1392 static void ieee80211_sta_process_delba(struct net_device
*dev
,
1393 struct ieee80211_mgmt
*mgmt
, size_t len
)
1395 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1396 struct sta_info
*sta
;
1399 DECLARE_MAC_BUF(mac
);
1401 sta
= sta_info_get(local
, mgmt
->sa
);
1405 params
= le16_to_cpu(mgmt
->u
.action
.u
.delba
.params
);
1406 tid
= (params
& IEEE80211_DELBA_PARAM_TID_MASK
) >> 12;
1407 initiator
= (params
& IEEE80211_DELBA_PARAM_INITIATOR_MASK
) >> 11;
1409 #ifdef CONFIG_MAC80211_HT_DEBUG
1410 if (net_ratelimit())
1411 printk(KERN_DEBUG
"delba from %s (%s) tid %d reason code %d\n",
1412 print_mac(mac
, mgmt
->sa
),
1413 initiator
? "recipient" : "initiator", tid
,
1414 mgmt
->u
.action
.u
.delba
.reason_code
);
1415 #endif /* CONFIG_MAC80211_HT_DEBUG */
1417 if (initiator
== WLAN_BACK_INITIATOR
)
1418 ieee80211_sta_stop_rx_ba_session(dev
, sta
->addr
, tid
,
1419 WLAN_BACK_INITIATOR
, 0);
1420 else { /* WLAN_BACK_RECIPIENT */
1421 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1422 sta
->ampdu_mlme
.tid_tx
[tid
].state
=
1423 HT_AGG_STATE_OPERATIONAL
;
1424 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1425 ieee80211_stop_tx_ba_session(&local
->hw
, sta
->addr
, tid
,
1426 WLAN_BACK_RECIPIENT
);
1432 * After sending add Block Ack request we activated a timer until
1433 * add Block Ack response will arrive from the recipient.
1434 * If this timer expires sta_addba_resp_timer_expired will be executed.
1436 void sta_addba_resp_timer_expired(unsigned long data
)
1438 /* not an elegant detour, but there is no choice as the timer passes
1439 * only one argument, and both sta_info and TID are needed, so init
1440 * flow in sta_info_add gives the TID as data, while the timer_to_id
1441 * array gives the sta through container_of */
1442 u16 tid
= *(int *)data
;
1443 struct sta_info
*temp_sta
= container_of((void *)data
,
1444 struct sta_info
, timer_to_tid
[tid
]);
1446 struct ieee80211_local
*local
= temp_sta
->local
;
1447 struct ieee80211_hw
*hw
= &local
->hw
;
1448 struct sta_info
*sta
;
1451 sta
= sta_info_get(local
, temp_sta
->addr
);
1455 state
= &sta
->ampdu_mlme
.tid_tx
[tid
].state
;
1456 /* check if the TID waits for addBA response */
1457 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1458 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1459 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1460 *state
= HT_AGG_STATE_IDLE
;
1461 printk(KERN_DEBUG
"timer expired on tid %d but we are not "
1462 "expecting addBA response there", tid
);
1463 goto timer_expired_exit
;
1466 printk(KERN_DEBUG
"addBA response timer expired on tid %d\n", tid
);
1468 /* go through the state check in stop_BA_session */
1469 *state
= HT_AGG_STATE_OPERATIONAL
;
1470 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1471 ieee80211_stop_tx_ba_session(hw
, temp_sta
->addr
, tid
,
1472 WLAN_BACK_INITIATOR
);
1479 * After receiving Block Ack Request (BAR) we activated a
1480 * timer after each frame arrives from the originator.
1481 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1483 void sta_rx_agg_session_timer_expired(unsigned long data
)
1485 /* not an elegant detour, but there is no choice as the timer passes
1486 * only one argument, and verious sta_info are needed here, so init
1487 * flow in sta_info_add gives the TID as data, while the timer_to_id
1488 * array gives the sta through container_of */
1489 u8
*ptid
= (u8
*)data
;
1490 u8
*timer_to_id
= ptid
- *ptid
;
1491 struct sta_info
*sta
= container_of(timer_to_id
, struct sta_info
,
1494 printk(KERN_DEBUG
"rx session timer expired on tid %d\n", (u16
)*ptid
);
1495 ieee80211_sta_stop_rx_ba_session(sta
->dev
, sta
->addr
, (u16
)*ptid
,
1497 WLAN_REASON_QSTA_TIMEOUT
);
1501 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
1502 struct ieee80211_if_sta
*ifsta
,
1503 struct ieee80211_mgmt
*mgmt
,
1506 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1507 u16 auth_alg
, auth_transaction
, status_code
;
1508 DECLARE_MAC_BUF(mac
);
1510 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
1511 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
) {
1512 printk(KERN_DEBUG
"%s: authentication frame received from "
1513 "%s, but not in authenticate state - ignored\n",
1514 dev
->name
, print_mac(mac
, mgmt
->sa
));
1519 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
1520 "received from %s - ignored\n",
1521 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1525 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1526 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1527 printk(KERN_DEBUG
"%s: authentication frame received from "
1528 "unknown AP (SA=%s BSSID=%s) - "
1529 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1530 print_mac(mac
, mgmt
->bssid
));
1534 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1535 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
1536 printk(KERN_DEBUG
"%s: authentication frame received from "
1537 "unknown BSSID (SA=%s BSSID=%s) - "
1538 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1539 print_mac(mac
, mgmt
->bssid
));
1543 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
1544 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
1545 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
1547 printk(KERN_DEBUG
"%s: RX authentication from %s (alg=%d "
1548 "transaction=%d status=%d)\n",
1549 dev
->name
, print_mac(mac
, mgmt
->sa
), auth_alg
,
1550 auth_transaction
, status_code
);
1552 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
1553 /* IEEE 802.11 standard does not require authentication in IBSS
1554 * networks and most implementations do not seem to use it.
1555 * However, try to reply to authentication attempts if someone
1556 * has actually implemented this.
1557 * TODO: Could implement shared key authentication. */
1558 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
1559 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
1560 "frame (alg=%d transaction=%d)\n",
1561 dev
->name
, auth_alg
, auth_transaction
);
1564 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
1567 if (auth_alg
!= ifsta
->auth_alg
||
1568 auth_transaction
!= ifsta
->auth_transaction
) {
1569 printk(KERN_DEBUG
"%s: unexpected authentication frame "
1570 "(alg=%d transaction=%d)\n",
1571 dev
->name
, auth_alg
, auth_transaction
);
1575 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1576 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
1577 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
1578 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
1580 const int num_algs
= ARRAY_SIZE(algs
);
1582 algs
[0] = algs
[1] = algs
[2] = 0xff;
1583 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1584 algs
[0] = WLAN_AUTH_OPEN
;
1585 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1586 algs
[1] = WLAN_AUTH_SHARED_KEY
;
1587 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1588 algs
[2] = WLAN_AUTH_LEAP
;
1589 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
1591 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
1595 for (i
= 0; i
< num_algs
; i
++) {
1597 if (pos
>= num_algs
)
1599 if (algs
[pos
] == ifsta
->auth_alg
||
1602 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
1603 !ieee80211_sta_wep_configured(dev
))
1605 ifsta
->auth_alg
= algs
[pos
];
1606 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
1608 dev
->name
, ifsta
->auth_alg
);
1615 switch (ifsta
->auth_alg
) {
1616 case WLAN_AUTH_OPEN
:
1617 case WLAN_AUTH_LEAP
:
1618 ieee80211_auth_completed(dev
, ifsta
);
1620 case WLAN_AUTH_SHARED_KEY
:
1621 if (ifsta
->auth_transaction
== 4)
1622 ieee80211_auth_completed(dev
, ifsta
);
1624 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
);
1630 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
1631 struct ieee80211_if_sta
*ifsta
,
1632 struct ieee80211_mgmt
*mgmt
,
1636 DECLARE_MAC_BUF(mac
);
1639 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
1640 "received from %s - ignored\n",
1641 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1645 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1646 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1647 "unknown AP (SA=%s BSSID=%s) - "
1648 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1649 print_mac(mac
, mgmt
->bssid
));
1653 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1655 printk(KERN_DEBUG
"%s: RX deauthentication from %s"
1657 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1659 if (ifsta
->flags
& IEEE80211_STA_AUTHENTICATED
) {
1660 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1663 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1664 ifsta
->state
== IEEE80211_ASSOCIATE
||
1665 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1666 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1667 mod_timer(&ifsta
->timer
, jiffies
+
1668 IEEE80211_RETRY_AUTH_INTERVAL
);
1671 ieee80211_set_disassoc(dev
, ifsta
, 1);
1672 ifsta
->flags
&= ~IEEE80211_STA_AUTHENTICATED
;
1676 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1677 struct ieee80211_if_sta
*ifsta
,
1678 struct ieee80211_mgmt
*mgmt
,
1682 DECLARE_MAC_BUF(mac
);
1685 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1686 "received from %s - ignored\n",
1687 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1691 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1692 printk(KERN_DEBUG
"%s: disassociation frame received from "
1693 "unknown AP (SA=%s BSSID=%s) - "
1694 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1695 print_mac(mac
, mgmt
->bssid
));
1699 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1701 printk(KERN_DEBUG
"%s: RX disassociation from %s"
1703 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1705 if (ifsta
->flags
& IEEE80211_STA_ASSOCIATED
)
1706 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1708 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1709 ifsta
->state
= IEEE80211_ASSOCIATE
;
1710 mod_timer(&ifsta
->timer
, jiffies
+
1711 IEEE80211_RETRY_AUTH_INTERVAL
);
1714 ieee80211_set_disassoc(dev
, ifsta
, 0);
1718 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
1719 struct ieee80211_if_sta
*ifsta
,
1720 struct ieee80211_mgmt
*mgmt
,
1724 struct ieee80211_local
*local
= sdata
->local
;
1725 struct net_device
*dev
= sdata
->dev
;
1726 struct ieee80211_supported_band
*sband
;
1727 struct sta_info
*sta
;
1728 u64 rates
, basic_rates
;
1729 u16 capab_info
, status_code
, aid
;
1730 struct ieee802_11_elems elems
;
1731 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
1734 DECLARE_MAC_BUF(mac
);
1735 bool have_higher_than_11mbit
= false;
1737 /* AssocResp and ReassocResp have identical structure, so process both
1738 * of them in this function. */
1740 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1741 printk(KERN_DEBUG
"%s: association frame received from "
1742 "%s, but not in associate state - ignored\n",
1743 dev
->name
, print_mac(mac
, mgmt
->sa
));
1748 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1749 "received from %s - ignored\n",
1750 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1754 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1755 printk(KERN_DEBUG
"%s: association frame received from "
1756 "unknown AP (SA=%s BSSID=%s) - "
1757 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1758 print_mac(mac
, mgmt
->bssid
));
1762 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1763 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1764 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1766 printk(KERN_DEBUG
"%s: RX %sssocResp from %s (capab=0x%x "
1767 "status=%d aid=%d)\n",
1768 dev
->name
, reassoc
? "Rea" : "A", print_mac(mac
, mgmt
->sa
),
1769 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
1771 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1772 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1773 dev
->name
, status_code
);
1774 /* if this was a reassociation, ensure we try a "full"
1775 * association next time. This works around some broken APs
1776 * which do not correctly reject reassociation requests. */
1777 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
1781 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1782 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1783 "set\n", dev
->name
, aid
);
1784 aid
&= ~(BIT(15) | BIT(14));
1786 pos
= mgmt
->u
.assoc_resp
.variable
;
1787 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1789 if (!elems
.supp_rates
) {
1790 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1795 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1797 ifsta
->ap_capab
= capab_info
;
1799 kfree(ifsta
->assocresp_ies
);
1800 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1801 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_KERNEL
);
1802 if (ifsta
->assocresp_ies
)
1803 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1805 /* Add STA entry for the AP */
1806 sta
= sta_info_get(local
, ifsta
->bssid
);
1808 struct ieee80211_sta_bss
*bss
;
1809 sta
= sta_info_add(local
, dev
, ifsta
->bssid
, GFP_KERNEL
);
1811 printk(KERN_DEBUG
"%s: failed to add STA entry for the"
1812 " AP\n", dev
->name
);
1815 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
1816 local
->hw
.conf
.channel
->center_freq
,
1817 ifsta
->ssid
, ifsta
->ssid_len
);
1819 sta
->last_rssi
= bss
->rssi
;
1820 sta
->last_signal
= bss
->signal
;
1821 sta
->last_noise
= bss
->noise
;
1822 ieee80211_rx_bss_put(dev
, bss
);
1827 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
| WLAN_STA_ASSOC_AP
|
1828 WLAN_STA_AUTHORIZED
;
1832 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
1834 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
1835 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
1838 have_higher_than_11mbit
= true;
1840 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1841 if (sband
->bitrates
[j
].bitrate
== rate
)
1843 if (elems
.supp_rates
[i
] & 0x80)
1844 basic_rates
|= BIT(j
);
1848 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
1849 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
1852 have_higher_than_11mbit
= true;
1854 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1855 if (sband
->bitrates
[j
].bitrate
== rate
)
1857 if (elems
.ext_supp_rates
[i
] & 0x80)
1858 basic_rates
|= BIT(j
);
1862 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] = rates
;
1863 sdata
->basic_rates
= basic_rates
;
1865 /* cf. IEEE 802.11 9.2.12 */
1866 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
1867 have_higher_than_11mbit
)
1868 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
1870 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
1872 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&& elems
.wmm_param
&&
1873 local
->ops
->conf_ht
) {
1874 struct ieee80211_ht_bss_info bss_info
;
1876 ieee80211_ht_cap_ie_to_ht_info(
1877 (struct ieee80211_ht_cap
*)
1878 elems
.ht_cap_elem
, &sta
->ht_info
);
1879 ieee80211_ht_addt_info_ie_to_ht_bss_info(
1880 (struct ieee80211_ht_addt_info
*)
1881 elems
.ht_info_elem
, &bss_info
);
1882 ieee80211_hw_config_ht(local
, 1, &sta
->ht_info
, &bss_info
);
1885 rate_control_rate_init(sta
, local
);
1887 if (elems
.wmm_param
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
1888 sta
->flags
|= WLAN_STA_WME
;
1889 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
1890 elems
.wmm_param_len
);
1893 /* set AID, ieee80211_set_associated() will tell the driver */
1894 bss_conf
->aid
= aid
;
1895 ieee80211_set_associated(dev
, ifsta
, 1);
1899 ieee80211_associated(dev
, ifsta
);
1903 /* Caller must hold local->sta_bss_lock */
1904 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
1905 struct ieee80211_sta_bss
*bss
)
1907 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1908 bss
->hnext
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1909 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] = bss
;
1913 /* Caller must hold local->sta_bss_lock */
1914 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
1915 struct ieee80211_sta_bss
*bss
)
1917 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1918 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
1919 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1923 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
1926 prev
->hnext
= bss
->hnext
;
1935 static struct ieee80211_sta_bss
*
1936 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
, int freq
,
1937 u8
*ssid
, u8 ssid_len
)
1939 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1940 struct ieee80211_sta_bss
*bss
;
1942 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
1945 atomic_inc(&bss
->users
);
1946 atomic_inc(&bss
->users
);
1947 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
1949 if (ssid
&& ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
1950 memcpy(bss
->ssid
, ssid
, ssid_len
);
1951 bss
->ssid_len
= ssid_len
;
1954 spin_lock_bh(&local
->sta_bss_lock
);
1955 /* TODO: order by RSSI? */
1956 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
1957 __ieee80211_rx_bss_hash_add(dev
, bss
);
1958 spin_unlock_bh(&local
->sta_bss_lock
);
1963 static struct ieee80211_sta_bss
*
1964 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int freq
,
1965 u8
*ssid
, u8 ssid_len
)
1967 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1968 struct ieee80211_sta_bss
*bss
;
1970 spin_lock_bh(&local
->sta_bss_lock
);
1971 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
1973 if (!memcmp(bss
->bssid
, bssid
, ETH_ALEN
) &&
1974 bss
->freq
== freq
&&
1975 bss
->ssid_len
== ssid_len
&&
1976 (ssid_len
== 0 || !memcmp(bss
->ssid
, ssid
, ssid_len
))) {
1977 atomic_inc(&bss
->users
);
1982 spin_unlock_bh(&local
->sta_bss_lock
);
1987 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
1997 static void ieee80211_rx_bss_put(struct net_device
*dev
,
1998 struct ieee80211_sta_bss
*bss
)
2000 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2001 if (!atomic_dec_and_test(&bss
->users
))
2004 spin_lock_bh(&local
->sta_bss_lock
);
2005 __ieee80211_rx_bss_hash_del(dev
, bss
);
2006 list_del(&bss
->list
);
2007 spin_unlock_bh(&local
->sta_bss_lock
);
2008 ieee80211_rx_bss_free(bss
);
2012 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
2014 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2015 spin_lock_init(&local
->sta_bss_lock
);
2016 INIT_LIST_HEAD(&local
->sta_bss_list
);
2020 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
2022 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2023 struct ieee80211_sta_bss
*bss
, *tmp
;
2025 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
2026 ieee80211_rx_bss_put(dev
, bss
);
2030 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
2031 struct ieee80211_if_sta
*ifsta
,
2032 struct ieee80211_sta_bss
*bss
)
2034 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2035 int res
, rates
, i
, j
;
2036 struct sk_buff
*skb
;
2037 struct ieee80211_mgmt
*mgmt
;
2038 struct ieee80211_tx_control control
;
2039 struct rate_selection ratesel
;
2041 struct ieee80211_sub_if_data
*sdata
;
2042 struct ieee80211_supported_band
*sband
;
2044 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2046 /* Remove possible STA entries from other IBSS networks. */
2047 sta_info_flush(local
, NULL
);
2049 if (local
->ops
->reset_tsf
) {
2050 /* Reset own TSF to allow time synchronization work. */
2051 local
->ops
->reset_tsf(local_to_hw(local
));
2053 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
2054 res
= ieee80211_if_config(dev
);
2058 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2060 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2061 sdata
->drop_unencrypted
= bss
->capability
&
2062 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
2064 res
= ieee80211_set_freq(local
, bss
->freq
);
2066 if (local
->oper_channel
->flags
& IEEE80211_CHAN_NO_IBSS
) {
2067 printk(KERN_DEBUG
"%s: IBSS not allowed on frequency "
2068 "%d MHz\n", dev
->name
, local
->oper_channel
->center_freq
);
2072 /* Set beacon template */
2073 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 400);
2078 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2080 mgmt
= (struct ieee80211_mgmt
*)
2081 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2082 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2083 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2084 IEEE80211_STYPE_BEACON
);
2085 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2086 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2087 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2088 mgmt
->u
.beacon
.beacon_int
=
2089 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2090 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2092 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2093 *pos
++ = WLAN_EID_SSID
;
2094 *pos
++ = ifsta
->ssid_len
;
2095 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2097 rates
= bss
->supp_rates_len
;
2100 pos
= skb_put(skb
, 2 + rates
);
2101 *pos
++ = WLAN_EID_SUPP_RATES
;
2103 memcpy(pos
, bss
->supp_rates
, rates
);
2105 if (bss
->band
== IEEE80211_BAND_2GHZ
) {
2106 pos
= skb_put(skb
, 2 + 1);
2107 *pos
++ = WLAN_EID_DS_PARAMS
;
2109 *pos
++ = ieee80211_frequency_to_channel(bss
->freq
);
2112 pos
= skb_put(skb
, 2 + 2);
2113 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2115 /* FIX: set ATIM window based on scan results */
2119 if (bss
->supp_rates_len
> 8) {
2120 rates
= bss
->supp_rates_len
- 8;
2121 pos
= skb_put(skb
, 2 + rates
);
2122 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2124 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2127 memset(&control
, 0, sizeof(control
));
2128 rate_control_get_rate(dev
, sband
, skb
, &ratesel
);
2129 if (!ratesel
.rate
) {
2130 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2131 "for IBSS beacon\n", dev
->name
);
2134 control
.vif
= &sdata
->vif
;
2135 control
.tx_rate
= ratesel
.rate
;
2136 if (sdata
->bss_conf
.use_short_preamble
&&
2137 ratesel
.rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
2138 control
.flags
|= IEEE80211_TXCTL_SHORT_PREAMBLE
;
2139 control
.antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
2140 control
.flags
|= IEEE80211_TXCTL_NO_ACK
;
2141 control
.retry_limit
= 1;
2143 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2144 if (ifsta
->probe_resp
) {
2145 mgmt
= (struct ieee80211_mgmt
*)
2146 ifsta
->probe_resp
->data
;
2147 mgmt
->frame_control
=
2148 IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2149 IEEE80211_STYPE_PROBE_RESP
);
2151 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2152 "template for IBSS\n", dev
->name
);
2155 if (local
->ops
->beacon_update
&&
2156 local
->ops
->beacon_update(local_to_hw(local
),
2157 skb
, &control
) == 0) {
2158 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2159 "template\n", dev
->name
);
2164 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2165 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2166 int bitrate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2167 for (j
= 0; j
< sband
->n_bitrates
; j
++)
2168 if (sband
->bitrates
[j
].bitrate
== bitrate
)
2171 ifsta
->supp_rates_bits
[local
->hw
.conf
.channel
->band
] = rates
;
2175 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2176 "template\n", dev
->name
);
2180 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2181 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2183 ieee80211_rx_bss_put(dev
, bss
);
2189 static void ieee80211_rx_bss_info(struct net_device
*dev
,
2190 struct ieee80211_mgmt
*mgmt
,
2192 struct ieee80211_rx_status
*rx_status
,
2195 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2196 struct ieee802_11_elems elems
;
2199 struct ieee80211_sta_bss
*bss
;
2200 struct sta_info
*sta
;
2201 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2202 u64 beacon_timestamp
, rx_timestamp
;
2203 DECLARE_MAC_BUF(mac
);
2204 DECLARE_MAC_BUF(mac2
);
2206 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
2207 return; /* ignore ProbeResp to foreign address */
2210 printk(KERN_DEBUG
"%s: RX %s from %s to %s\n",
2211 dev
->name
, beacon
? "Beacon" : "Probe Response",
2212 print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
));
2215 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2219 beacon_timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
2220 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2222 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& elems
.supp_rates
&&
2223 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0 &&
2224 (sta
= sta_info_get(local
, mgmt
->sa
))) {
2225 struct ieee80211_supported_band
*sband
;
2226 struct ieee80211_rate
*bitrates
;
2228 u64 supp_rates
, prev_rates
;
2231 sband
= local
->hw
.wiphy
->bands
[rx_status
->band
];
2235 sband
= local
->hw
.wiphy
->bands
[
2236 local
->hw
.conf
.channel
->band
];
2239 bitrates
= sband
->bitrates
;
2240 num_rates
= sband
->n_bitrates
;
2243 for (i
= 0; i
< elems
.supp_rates_len
+
2244 elems
.ext_supp_rates_len
; i
++) {
2247 if (i
< elems
.supp_rates_len
)
2248 rate
= elems
.supp_rates
[i
];
2249 else if (elems
.ext_supp_rates
)
2250 rate
= elems
.ext_supp_rates
2251 [i
- elems
.supp_rates_len
];
2252 own_rate
= 5 * (rate
& 0x7f);
2253 for (j
= 0; j
< num_rates
; j
++)
2254 if (bitrates
[j
].bitrate
== own_rate
)
2255 supp_rates
|= BIT(j
);
2258 prev_rates
= sta
->supp_rates
[rx_status
->band
];
2259 sta
->supp_rates
[rx_status
->band
] &= supp_rates
;
2260 if (sta
->supp_rates
[rx_status
->band
] == 0) {
2261 /* No matching rates - this should not really happen.
2262 * Make sure that at least one rate is marked
2263 * supported to avoid issues with TX rate ctrl. */
2264 sta
->supp_rates
[rx_status
->band
] =
2265 sdata
->u
.sta
.supp_rates_bits
[rx_status
->band
];
2267 if (sta
->supp_rates
[rx_status
->band
] != prev_rates
) {
2268 printk(KERN_DEBUG
"%s: updated supp_rates set for "
2269 "%s based on beacon info (0x%llx & 0x%llx -> "
2271 dev
->name
, print_mac(mac
, sta
->addr
),
2272 (unsigned long long) prev_rates
,
2273 (unsigned long long) supp_rates
,
2274 (unsigned long long) sta
->supp_rates
[rx_status
->band
]);
2282 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
2283 freq
= ieee80211_channel_to_frequency(elems
.ds_params
[0]);
2285 freq
= rx_status
->freq
;
2287 bss
= ieee80211_rx_bss_get(dev
, mgmt
->bssid
, freq
,
2288 elems
.ssid
, elems
.ssid_len
);
2290 bss
= ieee80211_rx_bss_add(dev
, mgmt
->bssid
, freq
,
2291 elems
.ssid
, elems
.ssid_len
);
2296 /* TODO: order by RSSI? */
2297 spin_lock_bh(&local
->sta_bss_lock
);
2298 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
2299 spin_unlock_bh(&local
->sta_bss_lock
);
2303 bss
->band
= rx_status
->band
;
2305 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
2306 bss
->probe_resp
&& beacon
) {
2308 * Do not allow beacon to override data from Probe Response. */
2309 ieee80211_rx_bss_put(dev
, bss
);
2313 /* save the ERP value so that it is available at association time */
2314 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
2315 bss
->erp_value
= elems
.erp_info
[0];
2316 bss
->has_erp_value
= 1;
2319 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
2320 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2322 bss
->supp_rates_len
= 0;
2323 if (elems
.supp_rates
) {
2324 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2325 if (clen
> elems
.supp_rates_len
)
2326 clen
= elems
.supp_rates_len
;
2327 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
.supp_rates
,
2329 bss
->supp_rates_len
+= clen
;
2331 if (elems
.ext_supp_rates
) {
2332 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2333 if (clen
> elems
.ext_supp_rates_len
)
2334 clen
= elems
.ext_supp_rates_len
;
2335 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
2336 elems
.ext_supp_rates
, clen
);
2337 bss
->supp_rates_len
+= clen
;
2341 (!bss
->wpa_ie
|| bss
->wpa_ie_len
!= elems
.wpa_len
||
2342 memcmp(bss
->wpa_ie
, elems
.wpa
, elems
.wpa_len
))) {
2344 bss
->wpa_ie
= kmalloc(elems
.wpa_len
+ 2, GFP_ATOMIC
);
2346 memcpy(bss
->wpa_ie
, elems
.wpa
- 2, elems
.wpa_len
+ 2);
2347 bss
->wpa_ie_len
= elems
.wpa_len
+ 2;
2349 bss
->wpa_ie_len
= 0;
2350 } else if (!elems
.wpa
&& bss
->wpa_ie
) {
2353 bss
->wpa_ie_len
= 0;
2357 (!bss
->rsn_ie
|| bss
->rsn_ie_len
!= elems
.rsn_len
||
2358 memcmp(bss
->rsn_ie
, elems
.rsn
, elems
.rsn_len
))) {
2360 bss
->rsn_ie
= kmalloc(elems
.rsn_len
+ 2, GFP_ATOMIC
);
2362 memcpy(bss
->rsn_ie
, elems
.rsn
- 2, elems
.rsn_len
+ 2);
2363 bss
->rsn_ie_len
= elems
.rsn_len
+ 2;
2365 bss
->rsn_ie_len
= 0;
2366 } else if (!elems
.rsn
&& bss
->rsn_ie
) {
2369 bss
->rsn_ie_len
= 0;
2372 if (elems
.wmm_param
&&
2373 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_param_len
||
2374 memcmp(bss
->wmm_ie
, elems
.wmm_param
, elems
.wmm_param_len
))) {
2376 bss
->wmm_ie
= kmalloc(elems
.wmm_param_len
+ 2, GFP_ATOMIC
);
2378 memcpy(bss
->wmm_ie
, elems
.wmm_param
- 2,
2379 elems
.wmm_param_len
+ 2);
2380 bss
->wmm_ie_len
= elems
.wmm_param_len
+ 2;
2382 bss
->wmm_ie_len
= 0;
2383 } else if (!elems
.wmm_param
&& bss
->wmm_ie
) {
2386 bss
->wmm_ie_len
= 0;
2388 if (elems
.ht_cap_elem
&&
2389 (!bss
->ht_ie
|| bss
->ht_ie_len
!= elems
.ht_cap_elem_len
||
2390 memcmp(bss
->ht_ie
, elems
.ht_cap_elem
, elems
.ht_cap_elem_len
))) {
2392 bss
->ht_ie
= kmalloc(elems
.ht_cap_elem_len
+ 2, GFP_ATOMIC
);
2394 memcpy(bss
->ht_ie
, elems
.ht_cap_elem
- 2,
2395 elems
.ht_cap_elem_len
+ 2);
2396 bss
->ht_ie_len
= elems
.ht_cap_elem_len
+ 2;
2399 } else if (!elems
.ht_cap_elem
&& bss
->ht_ie
) {
2405 bss
->timestamp
= beacon_timestamp
;
2406 bss
->last_update
= jiffies
;
2407 bss
->rssi
= rx_status
->ssi
;
2408 bss
->signal
= rx_status
->signal
;
2409 bss
->noise
= rx_status
->noise
;
2413 /* check if we need to merge IBSS */
2414 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
2415 !local
->sta_sw_scanning
&& !local
->sta_hw_scanning
&&
2416 mgmt
->u
.beacon
.capab_info
& WLAN_CAPABILITY_IBSS
&&
2417 bss
->freq
== local
->oper_channel
->center_freq
&&
2418 elems
.ssid_len
== sdata
->u
.sta
.ssid_len
&&
2419 memcmp(elems
.ssid
, sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
) == 0) {
2420 if (rx_status
->flag
& RX_FLAG_TSFT
) {
2421 /* in order for correct IBSS merging we need mactime
2423 * since mactime is defined as the time the first data
2424 * symbol of the frame hits the PHY, and the timestamp
2425 * of the beacon is defined as "the time that the data
2426 * symbol containing the first bit of the timestamp is
2427 * transmitted to the PHY plus the transmitting STA’s
2428 * delays through its local PHY from the MAC-PHY
2429 * interface to its interface with the WM"
2430 * (802.11 11.1.2) - equals the time this bit arrives at
2431 * the receiver - we have to take into account the
2432 * offset between the two.
2433 * e.g: at 1 MBit that means mactime is 192 usec earlier
2434 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2436 int rate
= local
->hw
.wiphy
->bands
[rx_status
->band
]->
2437 bitrates
[rx_status
->rate_idx
].bitrate
;
2438 rx_timestamp
= rx_status
->mactime
+ (24 * 8 * 10 / rate
);
2439 } else if (local
&& local
->ops
&& local
->ops
->get_tsf
)
2440 /* second best option: get current TSF */
2441 rx_timestamp
= local
->ops
->get_tsf(local_to_hw(local
));
2443 /* can't merge without knowing the TSF */
2444 rx_timestamp
= -1LLU;
2445 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2446 printk(KERN_DEBUG
"RX beacon SA=%s BSSID="
2447 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2448 print_mac(mac
, mgmt
->sa
),
2449 print_mac(mac2
, mgmt
->bssid
),
2450 (unsigned long long)rx_timestamp
,
2451 (unsigned long long)beacon_timestamp
,
2452 (unsigned long long)(rx_timestamp
- beacon_timestamp
),
2454 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2455 if (beacon_timestamp
> rx_timestamp
) {
2456 if (CONFIG_MAC80211_IBSS_DEBUG
|| net_ratelimit())
2457 printk(KERN_DEBUG
"%s: beacon TSF higher than "
2458 "local TSF - IBSS merge with BSSID %s\n",
2459 dev
->name
, print_mac(mac
, mgmt
->bssid
));
2460 ieee80211_sta_join_ibss(dev
, &sdata
->u
.sta
, bss
);
2461 ieee80211_ibss_add_sta(dev
, NULL
,
2462 mgmt
->bssid
, mgmt
->sa
);
2466 ieee80211_rx_bss_put(dev
, bss
);
2470 static void ieee80211_rx_mgmt_probe_resp(struct net_device
*dev
,
2471 struct ieee80211_mgmt
*mgmt
,
2473 struct ieee80211_rx_status
*rx_status
)
2475 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 0);
2479 static void ieee80211_rx_mgmt_beacon(struct net_device
*dev
,
2480 struct ieee80211_mgmt
*mgmt
,
2482 struct ieee80211_rx_status
*rx_status
)
2484 struct ieee80211_sub_if_data
*sdata
;
2485 struct ieee80211_if_sta
*ifsta
;
2487 struct ieee802_11_elems elems
;
2488 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2489 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
2492 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 1);
2494 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2495 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
2497 ifsta
= &sdata
->u
.sta
;
2499 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
) ||
2500 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
2503 /* Process beacon from the current BSS */
2504 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2508 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2510 if (elems
.erp_info
&& elems
.erp_info_len
>= 1)
2511 changed
|= ieee80211_handle_erp_ie(sdata
, elems
.erp_info
[0]);
2513 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&&
2514 elems
.wmm_param
&& local
->ops
->conf_ht
&&
2515 conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
2516 struct ieee80211_ht_bss_info bss_info
;
2518 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2519 (struct ieee80211_ht_addt_info
*)
2520 elems
.ht_info_elem
, &bss_info
);
2521 /* check if AP changed bss inforamation */
2522 if ((conf
->ht_bss_conf
.primary_channel
!=
2523 bss_info
.primary_channel
) ||
2524 (conf
->ht_bss_conf
.bss_cap
!= bss_info
.bss_cap
) ||
2525 (conf
->ht_bss_conf
.bss_op_mode
!= bss_info
.bss_op_mode
))
2526 ieee80211_hw_config_ht(local
, 1, &conf
->ht_conf
,
2530 if (elems
.wmm_param
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
2531 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2532 elems
.wmm_param_len
);
2535 ieee80211_bss_info_change_notify(sdata
, changed
);
2539 static void ieee80211_rx_mgmt_probe_req(struct net_device
*dev
,
2540 struct ieee80211_if_sta
*ifsta
,
2541 struct ieee80211_mgmt
*mgmt
,
2543 struct ieee80211_rx_status
*rx_status
)
2545 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2546 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2548 struct sk_buff
*skb
;
2549 struct ieee80211_mgmt
*resp
;
2551 DECLARE_MAC_BUF(mac
);
2552 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2553 DECLARE_MAC_BUF(mac2
);
2554 DECLARE_MAC_BUF(mac3
);
2557 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
||
2558 ifsta
->state
!= IEEE80211_IBSS_JOINED
||
2559 len
< 24 + 2 || !ifsta
->probe_resp
)
2562 if (local
->ops
->tx_last_beacon
)
2563 tx_last_beacon
= local
->ops
->tx_last_beacon(local_to_hw(local
));
2567 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2568 printk(KERN_DEBUG
"%s: RX ProbeReq SA=%s DA=%s BSSID="
2569 "%s (tx_last_beacon=%d)\n",
2570 dev
->name
, print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
),
2571 print_mac(mac3
, mgmt
->bssid
), tx_last_beacon
);
2572 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2574 if (!tx_last_beacon
)
2577 if (memcmp(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
) != 0 &&
2578 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
2581 end
= ((u8
*) mgmt
) + len
;
2582 pos
= mgmt
->u
.probe_req
.variable
;
2583 if (pos
[0] != WLAN_EID_SSID
||
2584 pos
+ 2 + pos
[1] > end
) {
2585 if (net_ratelimit()) {
2586 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
2588 dev
->name
, print_mac(mac
, mgmt
->sa
));
2593 (pos
[1] != ifsta
->ssid_len
||
2594 memcmp(pos
+ 2, ifsta
->ssid
, ifsta
->ssid_len
) != 0)) {
2595 /* Ignore ProbeReq for foreign SSID */
2599 /* Reply with ProbeResp */
2600 skb
= skb_copy(ifsta
->probe_resp
, GFP_KERNEL
);
2604 resp
= (struct ieee80211_mgmt
*) skb
->data
;
2605 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
2606 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2607 printk(KERN_DEBUG
"%s: Sending ProbeResp to %s\n",
2608 dev
->name
, print_mac(mac
, resp
->da
));
2609 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2610 ieee80211_sta_tx(dev
, skb
, 0);
2613 static void ieee80211_rx_mgmt_action(struct net_device
*dev
,
2614 struct ieee80211_if_sta
*ifsta
,
2615 struct ieee80211_mgmt
*mgmt
,
2618 if (len
< IEEE80211_MIN_ACTION_SIZE
)
2621 switch (mgmt
->u
.action
.category
) {
2622 case WLAN_CATEGORY_BACK
:
2623 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
2624 case WLAN_ACTION_ADDBA_REQ
:
2625 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2626 sizeof(mgmt
->u
.action
.u
.addba_req
)))
2628 ieee80211_sta_process_addba_request(dev
, mgmt
, len
);
2630 case WLAN_ACTION_ADDBA_RESP
:
2631 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2632 sizeof(mgmt
->u
.action
.u
.addba_resp
)))
2634 ieee80211_sta_process_addba_resp(dev
, mgmt
, len
);
2636 case WLAN_ACTION_DELBA
:
2637 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2638 sizeof(mgmt
->u
.action
.u
.delba
)))
2640 ieee80211_sta_process_delba(dev
, mgmt
, len
);
2643 if (net_ratelimit())
2644 printk(KERN_DEBUG
"%s: Rx unknown A-MPDU action\n",
2654 void ieee80211_sta_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
2655 struct ieee80211_rx_status
*rx_status
)
2657 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2658 struct ieee80211_sub_if_data
*sdata
;
2659 struct ieee80211_if_sta
*ifsta
;
2660 struct ieee80211_mgmt
*mgmt
;
2666 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2667 ifsta
= &sdata
->u
.sta
;
2669 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2670 fc
= le16_to_cpu(mgmt
->frame_control
);
2672 switch (fc
& IEEE80211_FCTL_STYPE
) {
2673 case IEEE80211_STYPE_PROBE_REQ
:
2674 case IEEE80211_STYPE_PROBE_RESP
:
2675 case IEEE80211_STYPE_BEACON
:
2676 memcpy(skb
->cb
, rx_status
, sizeof(*rx_status
));
2677 case IEEE80211_STYPE_AUTH
:
2678 case IEEE80211_STYPE_ASSOC_RESP
:
2679 case IEEE80211_STYPE_REASSOC_RESP
:
2680 case IEEE80211_STYPE_DEAUTH
:
2681 case IEEE80211_STYPE_DISASSOC
:
2682 case IEEE80211_STYPE_ACTION
:
2683 skb_queue_tail(&ifsta
->skb_queue
, skb
);
2684 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2687 printk(KERN_DEBUG
"%s: received unknown management frame - "
2688 "stype=%d\n", dev
->name
,
2689 (fc
& IEEE80211_FCTL_STYPE
) >> 4);
2698 static void ieee80211_sta_rx_queued_mgmt(struct net_device
*dev
,
2699 struct sk_buff
*skb
)
2701 struct ieee80211_rx_status
*rx_status
;
2702 struct ieee80211_sub_if_data
*sdata
;
2703 struct ieee80211_if_sta
*ifsta
;
2704 struct ieee80211_mgmt
*mgmt
;
2707 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2708 ifsta
= &sdata
->u
.sta
;
2710 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
2711 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2712 fc
= le16_to_cpu(mgmt
->frame_control
);
2714 switch (fc
& IEEE80211_FCTL_STYPE
) {
2715 case IEEE80211_STYPE_PROBE_REQ
:
2716 ieee80211_rx_mgmt_probe_req(dev
, ifsta
, mgmt
, skb
->len
,
2719 case IEEE80211_STYPE_PROBE_RESP
:
2720 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
, skb
->len
, rx_status
);
2722 case IEEE80211_STYPE_BEACON
:
2723 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
, rx_status
);
2725 case IEEE80211_STYPE_AUTH
:
2726 ieee80211_rx_mgmt_auth(dev
, ifsta
, mgmt
, skb
->len
);
2728 case IEEE80211_STYPE_ASSOC_RESP
:
2729 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 0);
2731 case IEEE80211_STYPE_REASSOC_RESP
:
2732 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 1);
2734 case IEEE80211_STYPE_DEAUTH
:
2735 ieee80211_rx_mgmt_deauth(dev
, ifsta
, mgmt
, skb
->len
);
2737 case IEEE80211_STYPE_DISASSOC
:
2738 ieee80211_rx_mgmt_disassoc(dev
, ifsta
, mgmt
, skb
->len
);
2740 case IEEE80211_STYPE_ACTION
:
2741 ieee80211_rx_mgmt_action(dev
, ifsta
, mgmt
, skb
->len
);
2750 ieee80211_sta_rx_scan(struct net_device
*dev
, struct sk_buff
*skb
,
2751 struct ieee80211_rx_status
*rx_status
)
2753 struct ieee80211_mgmt
*mgmt
;
2757 return RX_DROP_UNUSABLE
;
2759 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2760 fc
= le16_to_cpu(mgmt
->frame_control
);
2762 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
)
2766 return RX_DROP_MONITOR
;
2768 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
2769 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
) {
2770 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
,
2771 skb
->len
, rx_status
);
2774 } else if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
) {
2775 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
,
2785 static int ieee80211_sta_active_ibss(struct net_device
*dev
)
2787 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2789 struct sta_info
*sta
;
2791 read_lock_bh(&local
->sta_lock
);
2792 list_for_each_entry(sta
, &local
->sta_list
, list
) {
2793 if (sta
->dev
== dev
&&
2794 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
2800 read_unlock_bh(&local
->sta_lock
);
2806 static void ieee80211_sta_expire(struct net_device
*dev
)
2808 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2809 struct sta_info
*sta
, *tmp
;
2810 LIST_HEAD(tmp_list
);
2811 DECLARE_MAC_BUF(mac
);
2813 write_lock_bh(&local
->sta_lock
);
2814 list_for_each_entry_safe(sta
, tmp
, &local
->sta_list
, list
)
2815 if (time_after(jiffies
, sta
->last_rx
+
2816 IEEE80211_IBSS_INACTIVITY_LIMIT
)) {
2817 printk(KERN_DEBUG
"%s: expiring inactive STA %s\n",
2818 dev
->name
, print_mac(mac
, sta
->addr
));
2819 __sta_info_get(sta
);
2820 sta_info_remove(sta
);
2821 list_add(&sta
->list
, &tmp_list
);
2823 write_unlock_bh(&local
->sta_lock
);
2825 list_for_each_entry_safe(sta
, tmp
, &tmp_list
, list
) {
2832 static void ieee80211_sta_merge_ibss(struct net_device
*dev
,
2833 struct ieee80211_if_sta
*ifsta
)
2835 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2837 ieee80211_sta_expire(dev
);
2838 if (ieee80211_sta_active_ibss(dev
))
2841 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
2842 "IBSS networks with same SSID (merge)\n", dev
->name
);
2843 ieee80211_sta_req_scan(dev
, ifsta
->ssid
, ifsta
->ssid_len
);
2847 void ieee80211_sta_timer(unsigned long data
)
2849 struct ieee80211_sub_if_data
*sdata
=
2850 (struct ieee80211_sub_if_data
*) data
;
2851 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2852 struct ieee80211_local
*local
= wdev_priv(&sdata
->wdev
);
2854 set_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
2855 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2859 void ieee80211_sta_work(struct work_struct
*work
)
2861 struct ieee80211_sub_if_data
*sdata
=
2862 container_of(work
, struct ieee80211_sub_if_data
, u
.sta
.work
);
2863 struct net_device
*dev
= sdata
->dev
;
2864 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2865 struct ieee80211_if_sta
*ifsta
;
2866 struct sk_buff
*skb
;
2868 if (!netif_running(dev
))
2871 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
2874 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
2875 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
) {
2876 printk(KERN_DEBUG
"%s: ieee80211_sta_work: non-STA interface "
2877 "(type=%d)\n", dev
->name
, sdata
->vif
.type
);
2880 ifsta
= &sdata
->u
.sta
;
2882 while ((skb
= skb_dequeue(&ifsta
->skb_queue
)))
2883 ieee80211_sta_rx_queued_mgmt(dev
, skb
);
2885 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
2886 ifsta
->state
!= IEEE80211_ASSOCIATE
&&
2887 test_and_clear_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
)) {
2888 if (ifsta
->scan_ssid_len
)
2889 ieee80211_sta_start_scan(dev
, ifsta
->scan_ssid
, ifsta
->scan_ssid_len
);
2891 ieee80211_sta_start_scan(dev
, NULL
, 0);
2895 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
)) {
2896 if (ieee80211_sta_config_auth(dev
, ifsta
))
2898 clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
2899 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
))
2902 switch (ifsta
->state
) {
2903 case IEEE80211_DISABLED
:
2905 case IEEE80211_AUTHENTICATE
:
2906 ieee80211_authenticate(dev
, ifsta
);
2908 case IEEE80211_ASSOCIATE
:
2909 ieee80211_associate(dev
, ifsta
);
2911 case IEEE80211_ASSOCIATED
:
2912 ieee80211_associated(dev
, ifsta
);
2914 case IEEE80211_IBSS_SEARCH
:
2915 ieee80211_sta_find_ibss(dev
, ifsta
);
2917 case IEEE80211_IBSS_JOINED
:
2918 ieee80211_sta_merge_ibss(dev
, ifsta
);
2921 printk(KERN_DEBUG
"ieee80211_sta_work: Unknown state %d\n",
2926 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
2927 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
2928 "mixed-cell disabled - disassociate\n", dev
->name
);
2930 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
2931 ieee80211_set_disassoc(dev
, ifsta
, 0);
2936 static void ieee80211_sta_reset_auth(struct net_device
*dev
,
2937 struct ieee80211_if_sta
*ifsta
)
2939 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2941 if (local
->ops
->reset_tsf
) {
2942 /* Reset own TSF to allow time synchronization work. */
2943 local
->ops
->reset_tsf(local_to_hw(local
));
2946 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
2949 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
2950 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
2951 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
2952 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
2953 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
2954 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
2956 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
2957 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
2959 ifsta
->auth_transaction
= -1;
2960 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
2961 ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
2962 netif_carrier_off(dev
);
2966 void ieee80211_sta_req_auth(struct net_device
*dev
,
2967 struct ieee80211_if_sta
*ifsta
)
2969 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2970 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2972 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
2975 if ((ifsta
->flags
& (IEEE80211_STA_BSSID_SET
|
2976 IEEE80211_STA_AUTO_BSSID_SEL
)) &&
2977 (ifsta
->flags
& (IEEE80211_STA_SSID_SET
|
2978 IEEE80211_STA_AUTO_SSID_SEL
))) {
2979 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
2980 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2984 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta
*ifsta
,
2985 const char *ssid
, int ssid_len
)
2987 int tmp
, hidden_ssid
;
2989 if (ssid_len
== ifsta
->ssid_len
&&
2990 !memcmp(ifsta
->ssid
, ssid
, ssid_len
))
2993 if (ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
)
2999 if (ssid
[tmp
] != '\0') {
3005 if (hidden_ssid
&& ifsta
->ssid_len
== ssid_len
)
3008 if (ssid_len
== 1 && ssid
[0] == ' ')
3014 static int ieee80211_sta_config_auth(struct net_device
*dev
,
3015 struct ieee80211_if_sta
*ifsta
)
3017 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3018 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3019 struct ieee80211_sta_bss
*bss
, *selected
= NULL
;
3020 int top_rssi
= 0, freq
;
3022 if (!(ifsta
->flags
& (IEEE80211_STA_AUTO_SSID_SEL
|
3023 IEEE80211_STA_AUTO_BSSID_SEL
| IEEE80211_STA_AUTO_CHANNEL_SEL
))) {
3024 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3025 ieee80211_sta_reset_auth(dev
, ifsta
);
3029 spin_lock_bh(&local
->sta_bss_lock
);
3030 freq
= local
->oper_channel
->center_freq
;
3031 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3032 if (!(bss
->capability
& WLAN_CAPABILITY_ESS
))
3035 if (!!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
) ^
3036 !!sdata
->default_key
)
3039 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_CHANNEL_SEL
) &&
3043 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
) &&
3044 memcmp(bss
->bssid
, ifsta
->bssid
, ETH_ALEN
))
3047 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
) &&
3048 !ieee80211_sta_match_ssid(ifsta
, bss
->ssid
, bss
->ssid_len
))
3051 if (!selected
|| top_rssi
< bss
->rssi
) {
3053 top_rssi
= bss
->rssi
;
3057 atomic_inc(&selected
->users
);
3058 spin_unlock_bh(&local
->sta_bss_lock
);
3061 ieee80211_set_freq(local
, selected
->freq
);
3062 if (!(ifsta
->flags
& IEEE80211_STA_SSID_SET
))
3063 ieee80211_sta_set_ssid(dev
, selected
->ssid
,
3064 selected
->ssid_len
);
3065 ieee80211_sta_set_bssid(dev
, selected
->bssid
);
3066 ieee80211_rx_bss_put(dev
, selected
);
3067 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3068 ieee80211_sta_reset_auth(dev
, ifsta
);
3071 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
) {
3072 if (ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
)
3073 ieee80211_sta_start_scan(dev
, NULL
, 0);
3075 ieee80211_sta_start_scan(dev
, ifsta
->ssid
,
3077 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3078 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3080 ifsta
->state
= IEEE80211_DISABLED
;
3086 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
3087 struct ieee80211_if_sta
*ifsta
)
3089 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3090 struct ieee80211_sta_bss
*bss
;
3091 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3092 struct ieee80211_supported_band
*sband
;
3093 u8 bssid
[ETH_ALEN
], *pos
;
3095 DECLARE_MAC_BUF(mac
);
3098 /* Easier testing, use fixed BSSID. */
3099 memset(bssid
, 0xfe, ETH_ALEN
);
3101 /* Generate random, not broadcast, locally administered BSSID. Mix in
3102 * own MAC address to make sure that devices that do not have proper
3103 * random number generator get different BSSID. */
3104 get_random_bytes(bssid
, ETH_ALEN
);
3105 for (i
= 0; i
< ETH_ALEN
; i
++)
3106 bssid
[i
] ^= dev
->dev_addr
[i
];
3111 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID %s\n",
3112 dev
->name
, print_mac(mac
, bssid
));
3114 bss
= ieee80211_rx_bss_add(dev
, bssid
,
3115 local
->hw
.conf
.channel
->center_freq
,
3116 sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
);
3120 bss
->band
= local
->hw
.conf
.channel
->band
;
3121 sband
= local
->hw
.wiphy
->bands
[bss
->band
];
3123 if (local
->hw
.conf
.beacon_int
== 0)
3124 local
->hw
.conf
.beacon_int
= 100;
3125 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
3126 bss
->last_update
= jiffies
;
3127 bss
->capability
= WLAN_CAPABILITY_IBSS
;
3128 if (sdata
->default_key
) {
3129 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
3131 sdata
->drop_unencrypted
= 0;
3132 bss
->supp_rates_len
= sband
->n_bitrates
;
3133 pos
= bss
->supp_rates
;
3134 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
3135 int rate
= sband
->bitrates
[i
].bitrate
;
3136 *pos
++ = (u8
) (rate
/ 5);
3139 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3143 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
3144 struct ieee80211_if_sta
*ifsta
)
3146 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3147 struct ieee80211_sta_bss
*bss
;
3151 DECLARE_MAC_BUF(mac
);
3152 DECLARE_MAC_BUF(mac2
);
3154 if (ifsta
->ssid_len
== 0)
3157 active_ibss
= ieee80211_sta_active_ibss(dev
);
3158 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3159 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
3160 dev
->name
, active_ibss
);
3161 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3162 spin_lock_bh(&local
->sta_bss_lock
);
3163 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3164 if (ifsta
->ssid_len
!= bss
->ssid_len
||
3165 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
3166 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
3168 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3169 printk(KERN_DEBUG
" bssid=%s found\n",
3170 print_mac(mac
, bss
->bssid
));
3171 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3172 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
3174 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
3177 spin_unlock_bh(&local
->sta_bss_lock
);
3179 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3180 printk(KERN_DEBUG
" sta_find_ibss: selected %s current "
3181 "%s\n", print_mac(mac
, bssid
), print_mac(mac2
, ifsta
->bssid
));
3182 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3183 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
3184 (bss
= ieee80211_rx_bss_get(dev
, bssid
,
3185 local
->hw
.conf
.channel
->center_freq
,
3186 ifsta
->ssid
, ifsta
->ssid_len
))) {
3187 printk(KERN_DEBUG
"%s: Selected IBSS BSSID %s"
3188 " based on configured SSID\n",
3189 dev
->name
, print_mac(mac
, bssid
));
3190 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3192 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3193 printk(KERN_DEBUG
" did not try to join ibss\n");
3194 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3196 /* Selected IBSS not found in current scan results - try to scan */
3197 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3198 !ieee80211_sta_active_ibss(dev
)) {
3199 mod_timer(&ifsta
->timer
, jiffies
+
3200 IEEE80211_IBSS_MERGE_INTERVAL
);
3201 } else if (time_after(jiffies
, local
->last_scan_completed
+
3202 IEEE80211_SCAN_INTERVAL
)) {
3203 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
3204 "join\n", dev
->name
);
3205 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
3207 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
3208 int interval
= IEEE80211_SCAN_INTERVAL
;
3210 if (time_after(jiffies
, ifsta
->ibss_join_req
+
3211 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
3212 if ((ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) &&
3213 (!(local
->oper_channel
->flags
&
3214 IEEE80211_CHAN_NO_IBSS
)))
3215 return ieee80211_sta_create_ibss(dev
, ifsta
);
3216 if (ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) {
3217 printk(KERN_DEBUG
"%s: IBSS not allowed on"
3218 " %d MHz\n", dev
->name
,
3219 local
->hw
.conf
.channel
->center_freq
);
3222 /* No IBSS found - decrease scan interval and continue
3224 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
3227 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3228 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
3236 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
3238 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3239 struct ieee80211_if_sta
*ifsta
;
3240 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3242 if (len
> IEEE80211_MAX_SSID_LEN
)
3245 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
3247 if (local
->ops
->conf_tx
) {
3248 struct ieee80211_tx_queue_params qparam
;
3251 memset(&qparam
, 0, sizeof(qparam
));
3255 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
3256 !(sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
))
3261 qparam
.cw_max
= 1023;
3264 for (i
= IEEE80211_TX_QUEUE_DATA0
; i
< NUM_TX_DATA_QUEUES
; i
++)
3265 local
->ops
->conf_tx(local_to_hw(local
),
3266 i
+ IEEE80211_TX_QUEUE_DATA0
,
3269 /* IBSS uses different parameters for Beacon sending */
3273 local
->ops
->conf_tx(local_to_hw(local
),
3274 IEEE80211_TX_QUEUE_BEACON
, &qparam
);
3277 ifsta
= &sdata
->u
.sta
;
3279 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
3280 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
3281 memcpy(ifsta
->ssid
, ssid
, len
);
3282 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
3283 ifsta
->ssid_len
= len
;
3286 ifsta
->flags
|= IEEE80211_STA_SSID_SET
;
3288 ifsta
->flags
&= ~IEEE80211_STA_SSID_SET
;
3289 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3290 !(ifsta
->flags
& IEEE80211_STA_BSSID_SET
)) {
3291 ifsta
->ibss_join_req
= jiffies
;
3292 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3293 return ieee80211_sta_find_ibss(dev
, ifsta
);
3299 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
3301 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3302 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3303 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
3304 *len
= ifsta
->ssid_len
;
3309 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
3311 struct ieee80211_sub_if_data
*sdata
;
3312 struct ieee80211_if_sta
*ifsta
;
3315 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3316 ifsta
= &sdata
->u
.sta
;
3318 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
3319 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
3320 res
= ieee80211_if_config(dev
);
3322 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
3323 "the low-level driver\n", dev
->name
);
3328 if (is_valid_ether_addr(bssid
))
3329 ifsta
->flags
|= IEEE80211_STA_BSSID_SET
;
3331 ifsta
->flags
&= ~IEEE80211_STA_BSSID_SET
;
3337 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
3338 struct ieee80211_sub_if_data
*sdata
,
3341 struct sk_buff
*skb
;
3342 struct ieee80211_hdr
*nullfunc
;
3345 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
3347 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
3348 "frame\n", sdata
->dev
->name
);
3351 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3353 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
3354 memset(nullfunc
, 0, 24);
3355 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
3356 IEEE80211_FCTL_TODS
;
3358 fc
|= IEEE80211_FCTL_PM
;
3359 nullfunc
->frame_control
= cpu_to_le16(fc
);
3360 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3361 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
3362 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3364 ieee80211_sta_tx(sdata
->dev
, skb
, 0);
3368 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
3370 struct ieee80211_local
*local
= hw_to_local(hw
);
3371 struct net_device
*dev
= local
->scan_dev
;
3372 struct ieee80211_sub_if_data
*sdata
;
3373 union iwreq_data wrqu
;
3375 local
->last_scan_completed
= jiffies
;
3376 memset(&wrqu
, 0, sizeof(wrqu
));
3377 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
3379 if (local
->sta_hw_scanning
) {
3380 local
->sta_hw_scanning
= 0;
3384 local
->sta_sw_scanning
= 0;
3385 if (ieee80211_hw_config(local
))
3386 printk(KERN_DEBUG
"%s: failed to restore operational "
3387 "channel after scan\n", dev
->name
);
3390 netif_tx_lock_bh(local
->mdev
);
3391 local
->filter_flags
&= ~FIF_BCN_PRBRESP_PROMISC
;
3392 local
->ops
->configure_filter(local_to_hw(local
),
3393 FIF_BCN_PRBRESP_PROMISC
,
3394 &local
->filter_flags
,
3395 local
->mdev
->mc_count
,
3396 local
->mdev
->mc_list
);
3398 netif_tx_unlock_bh(local
->mdev
);
3401 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3403 /* No need to wake the master device. */
3404 if (sdata
->dev
== local
->mdev
)
3407 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
) {
3408 if (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
)
3409 ieee80211_send_nullfunc(local
, sdata
, 0);
3410 ieee80211_sta_timer((unsigned long)sdata
);
3413 netif_wake_queue(sdata
->dev
);
3418 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3419 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
3420 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3421 if (!(ifsta
->flags
& IEEE80211_STA_BSSID_SET
) ||
3422 (!ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3423 !ieee80211_sta_active_ibss(dev
)))
3424 ieee80211_sta_find_ibss(dev
, ifsta
);
3427 EXPORT_SYMBOL(ieee80211_scan_completed
);
3429 void ieee80211_sta_scan_work(struct work_struct
*work
)
3431 struct ieee80211_local
*local
=
3432 container_of(work
, struct ieee80211_local
, scan_work
.work
);
3433 struct net_device
*dev
= local
->scan_dev
;
3434 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3435 struct ieee80211_supported_band
*sband
;
3436 struct ieee80211_channel
*chan
;
3438 unsigned long next_delay
= 0;
3440 if (!local
->sta_sw_scanning
)
3443 switch (local
->scan_state
) {
3444 case SCAN_SET_CHANNEL
:
3446 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3447 * after we successfully scanned the last channel of the last
3448 * band (and the last band is supported by the hw)
3450 if (local
->scan_band
< IEEE80211_NUM_BANDS
)
3451 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3456 * If we are at an unsupported band and have more bands
3457 * left to scan, advance to the next supported one.
3459 while (!sband
&& local
->scan_band
< IEEE80211_NUM_BANDS
- 1) {
3461 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3462 local
->scan_channel_idx
= 0;
3465 /* if no more bands/channels left, complete scan */
3466 if (!sband
|| local
->scan_channel_idx
>= sband
->n_channels
) {
3467 ieee80211_scan_completed(local_to_hw(local
));
3471 chan
= &sband
->channels
[local
->scan_channel_idx
];
3473 if (chan
->flags
& IEEE80211_CHAN_DISABLED
||
3474 (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3475 chan
->flags
& IEEE80211_CHAN_NO_IBSS
))
3479 local
->scan_channel
= chan
;
3480 if (ieee80211_hw_config(local
)) {
3481 printk(KERN_DEBUG
"%s: failed to set freq to "
3482 "%d MHz for scan\n", dev
->name
,
3488 /* advance state machine to next channel/band */
3489 local
->scan_channel_idx
++;
3490 if (local
->scan_channel_idx
>= sband
->n_channels
) {
3492 * scan_band may end up == IEEE80211_NUM_BANDS, but
3493 * we'll catch that case above and complete the scan
3494 * if that is the case.
3497 local
->scan_channel_idx
= 0;
3503 next_delay
= IEEE80211_PROBE_DELAY
+
3504 usecs_to_jiffies(local
->hw
.channel_change_time
);
3505 local
->scan_state
= SCAN_SEND_PROBE
;
3507 case SCAN_SEND_PROBE
:
3508 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
3509 local
->scan_state
= SCAN_SET_CHANNEL
;
3511 if (local
->scan_channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
3513 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
3514 local
->scan_ssid_len
);
3515 next_delay
= IEEE80211_CHANNEL_TIME
;
3519 if (local
->sta_sw_scanning
)
3520 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3525 static int ieee80211_sta_start_scan(struct net_device
*dev
,
3526 u8
*ssid
, size_t ssid_len
)
3528 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3529 struct ieee80211_sub_if_data
*sdata
;
3531 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
3534 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3535 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3538 * ScanType: ACTIVE, PASSIVE
3539 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3540 * a Probe frame during active scanning
3542 * MinChannelTime (>= ProbeDelay), in TU
3543 * MaxChannelTime: (>= MinChannelTime), in TU
3546 /* MLME-SCAN.confirm
3548 * ResultCode: SUCCESS, INVALID_PARAMETERS
3551 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3552 if (local
->scan_dev
== dev
)
3557 if (local
->ops
->hw_scan
) {
3558 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
3561 local
->sta_hw_scanning
= 1;
3562 local
->scan_dev
= dev
;
3567 local
->sta_sw_scanning
= 1;
3570 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3572 /* Don't stop the master interface, otherwise we can't transmit
3574 if (sdata
->dev
== local
->mdev
)
3577 netif_stop_queue(sdata
->dev
);
3578 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3579 (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
))
3580 ieee80211_send_nullfunc(local
, sdata
, 1);
3585 local
->scan_ssid_len
= ssid_len
;
3586 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
3588 local
->scan_ssid_len
= 0;
3589 local
->scan_state
= SCAN_SET_CHANNEL
;
3590 local
->scan_channel_idx
= 0;
3591 local
->scan_band
= IEEE80211_BAND_2GHZ
;
3592 local
->scan_dev
= dev
;
3594 netif_tx_lock_bh(local
->mdev
);
3595 local
->filter_flags
|= FIF_BCN_PRBRESP_PROMISC
;
3596 local
->ops
->configure_filter(local_to_hw(local
),
3597 FIF_BCN_PRBRESP_PROMISC
,
3598 &local
->filter_flags
,
3599 local
->mdev
->mc_count
,
3600 local
->mdev
->mc_list
);
3601 netif_tx_unlock_bh(local
->mdev
);
3603 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3604 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3605 IEEE80211_CHANNEL_TIME
);
3611 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
3613 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3614 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3615 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3617 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3618 return ieee80211_sta_start_scan(dev
, ssid
, ssid_len
);
3620 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3621 if (local
->scan_dev
== dev
)
3626 ifsta
->scan_ssid_len
= ssid_len
;
3628 memcpy(ifsta
->scan_ssid
, ssid
, ssid_len
);
3629 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
3630 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3635 ieee80211_sta_scan_result(struct net_device
*dev
,
3636 struct ieee80211_sta_bss
*bss
,
3637 char *current_ev
, char *end_buf
)
3639 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3640 struct iw_event iwe
;
3642 if (time_after(jiffies
,
3643 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
3646 memset(&iwe
, 0, sizeof(iwe
));
3647 iwe
.cmd
= SIOCGIWAP
;
3648 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3649 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
3650 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3653 memset(&iwe
, 0, sizeof(iwe
));
3654 iwe
.cmd
= SIOCGIWESSID
;
3655 iwe
.u
.data
.length
= bss
->ssid_len
;
3656 iwe
.u
.data
.flags
= 1;
3657 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3660 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
3661 memset(&iwe
, 0, sizeof(iwe
));
3662 iwe
.cmd
= SIOCGIWMODE
;
3663 if (bss
->capability
& WLAN_CAPABILITY_ESS
)
3664 iwe
.u
.mode
= IW_MODE_MASTER
;
3666 iwe
.u
.mode
= IW_MODE_ADHOC
;
3667 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3671 memset(&iwe
, 0, sizeof(iwe
));
3672 iwe
.cmd
= SIOCGIWFREQ
;
3673 iwe
.u
.freq
.m
= bss
->freq
;
3675 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3678 memset(&iwe
, 0, sizeof(iwe
));
3679 iwe
.cmd
= SIOCGIWFREQ
;
3680 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->freq
);
3682 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3685 memset(&iwe
, 0, sizeof(iwe
));
3687 iwe
.u
.qual
.qual
= bss
->signal
;
3688 iwe
.u
.qual
.level
= bss
->rssi
;
3689 iwe
.u
.qual
.noise
= bss
->noise
;
3690 iwe
.u
.qual
.updated
= local
->wstats_flags
;
3691 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3694 memset(&iwe
, 0, sizeof(iwe
));
3695 iwe
.cmd
= SIOCGIWENCODE
;
3696 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
3697 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
3699 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
3700 iwe
.u
.data
.length
= 0;
3701 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
3703 if (bss
&& bss
->wpa_ie
) {
3704 memset(&iwe
, 0, sizeof(iwe
));
3705 iwe
.cmd
= IWEVGENIE
;
3706 iwe
.u
.data
.length
= bss
->wpa_ie_len
;
3707 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3711 if (bss
&& bss
->rsn_ie
) {
3712 memset(&iwe
, 0, sizeof(iwe
));
3713 iwe
.cmd
= IWEVGENIE
;
3714 iwe
.u
.data
.length
= bss
->rsn_ie_len
;
3715 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3719 if (bss
&& bss
->supp_rates_len
> 0) {
3720 /* display all supported rates in readable format */
3721 char *p
= current_ev
+ IW_EV_LCP_LEN
;
3724 memset(&iwe
, 0, sizeof(iwe
));
3725 iwe
.cmd
= SIOCGIWRATE
;
3726 /* Those two flags are ignored... */
3727 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
3729 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
3730 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
3732 p
= iwe_stream_add_value(current_ev
, p
,
3733 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
3740 buf
= kmalloc(30, GFP_ATOMIC
);
3742 memset(&iwe
, 0, sizeof(iwe
));
3743 iwe
.cmd
= IWEVCUSTOM
;
3744 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
3745 iwe
.u
.data
.length
= strlen(buf
);
3746 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
3756 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
3758 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3759 char *current_ev
= buf
;
3760 char *end_buf
= buf
+ len
;
3761 struct ieee80211_sta_bss
*bss
;
3763 spin_lock_bh(&local
->sta_bss_lock
);
3764 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3765 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
3766 spin_unlock_bh(&local
->sta_bss_lock
);
3769 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
3772 spin_unlock_bh(&local
->sta_bss_lock
);
3773 return current_ev
- buf
;
3777 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
3779 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3780 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3781 kfree(ifsta
->extra_ie
);
3783 ifsta
->extra_ie
= NULL
;
3784 ifsta
->extra_ie_len
= 0;
3787 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
3788 if (!ifsta
->extra_ie
) {
3789 ifsta
->extra_ie_len
= 0;
3792 memcpy(ifsta
->extra_ie
, ie
, len
);
3793 ifsta
->extra_ie_len
= len
;
3798 struct sta_info
* ieee80211_ibss_add_sta(struct net_device
*dev
,
3799 struct sk_buff
*skb
, u8
*bssid
,
3802 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3803 struct sta_info
*sta
;
3804 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3805 DECLARE_MAC_BUF(mac
);
3807 /* TODO: Could consider removing the least recently used entry and
3808 * allow new one to be added. */
3809 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
3810 if (net_ratelimit()) {
3811 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
3812 "entry %s\n", dev
->name
, print_mac(mac
, addr
));
3817 printk(KERN_DEBUG
"%s: Adding new IBSS station %s (dev=%s)\n",
3818 wiphy_name(local
->hw
.wiphy
), print_mac(mac
, addr
), dev
->name
);
3820 sta
= sta_info_add(local
, dev
, addr
, GFP_ATOMIC
);
3824 sta
->flags
|= WLAN_STA_AUTHORIZED
;
3826 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] =
3827 sdata
->u
.sta
.supp_rates_bits
[local
->hw
.conf
.channel
->band
];
3829 rate_control_rate_init(sta
, local
);
3831 return sta
; /* caller will call sta_info_put() */
3835 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
3837 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3838 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3840 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
3843 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
3844 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
3847 ieee80211_send_deauth(dev
, ifsta
, reason
);
3848 ieee80211_set_disassoc(dev
, ifsta
, 1);
3853 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
3855 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3856 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3858 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
3861 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3864 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
))
3867 ieee80211_send_disassoc(dev
, ifsta
, reason
);
3868 ieee80211_set_disassoc(dev
, ifsta
, 0);