2 * BSS client mode implementation
3 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 * order BSS list by RSSI(?) ("quality of AP")
16 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
19 #include <linux/delay.h>
20 #include <linux/if_ether.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/wireless.h>
25 #include <linux/random.h>
26 #include <linux/etherdevice.h>
27 #include <linux/rtnetlink.h>
28 #include <net/iw_handler.h>
29 #include <asm/types.h>
31 #include <net/mac80211.h>
32 #include "ieee80211_i.h"
37 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
38 #define IEEE80211_AUTH_MAX_TRIES 3
39 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
40 #define IEEE80211_ASSOC_MAX_TRIES 3
41 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
42 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
43 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
44 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
45 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
46 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
47 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
49 #define IEEE80211_PROBE_DELAY (HZ / 33)
50 #define IEEE80211_CHANNEL_TIME (HZ / 33)
51 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
52 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
53 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
54 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
55 #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
57 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
60 #define ERP_INFO_USE_PROTECTION BIT(1)
62 /* mgmt header + 1 byte action code */
63 #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
65 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
66 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
67 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
68 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
69 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
71 /* next values represent the buffer size for A-MPDU frame.
72 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
73 #define IEEE80211_MIN_AMPDU_BUF 0x8
74 #define IEEE80211_MAX_AMPDU_BUF 0x40
76 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
77 u8
*ssid
, size_t ssid_len
);
78 static struct ieee80211_sta_bss
*
79 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int freq
,
80 u8
*ssid
, u8 ssid_len
);
81 static void ieee80211_rx_bss_put(struct net_device
*dev
,
82 struct ieee80211_sta_bss
*bss
);
83 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
84 struct ieee80211_if_sta
*ifsta
);
85 static int ieee80211_sta_wep_configured(struct net_device
*dev
);
86 static int ieee80211_sta_start_scan(struct net_device
*dev
,
87 u8
*ssid
, size_t ssid_len
);
88 static int ieee80211_sta_config_auth(struct net_device
*dev
,
89 struct ieee80211_if_sta
*ifsta
);
92 void ieee802_11_parse_elems(u8
*start
, size_t len
,
93 struct ieee802_11_elems
*elems
)
98 memset(elems
, 0, sizeof(*elems
));
113 elems
->ssid_len
= elen
;
115 case WLAN_EID_SUPP_RATES
:
116 elems
->supp_rates
= pos
;
117 elems
->supp_rates_len
= elen
;
119 case WLAN_EID_FH_PARAMS
:
120 elems
->fh_params
= pos
;
121 elems
->fh_params_len
= elen
;
123 case WLAN_EID_DS_PARAMS
:
124 elems
->ds_params
= pos
;
125 elems
->ds_params_len
= elen
;
127 case WLAN_EID_CF_PARAMS
:
128 elems
->cf_params
= pos
;
129 elems
->cf_params_len
= elen
;
133 elems
->tim_len
= elen
;
135 case WLAN_EID_IBSS_PARAMS
:
136 elems
->ibss_params
= pos
;
137 elems
->ibss_params_len
= elen
;
139 case WLAN_EID_CHALLENGE
:
140 elems
->challenge
= pos
;
141 elems
->challenge_len
= elen
;
144 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
146 /* Microsoft OUI (00:50:F2) */
148 /* OUI Type 1 - WPA IE */
150 elems
->wpa_len
= elen
;
151 } else if (elen
>= 5 && pos
[3] == 2) {
153 elems
->wmm_info
= pos
;
154 elems
->wmm_info_len
= elen
;
155 } else if (pos
[4] == 1) {
156 elems
->wmm_param
= pos
;
157 elems
->wmm_param_len
= elen
;
164 elems
->rsn_len
= elen
;
166 case WLAN_EID_ERP_INFO
:
167 elems
->erp_info
= pos
;
168 elems
->erp_info_len
= elen
;
170 case WLAN_EID_EXT_SUPP_RATES
:
171 elems
->ext_supp_rates
= pos
;
172 elems
->ext_supp_rates_len
= elen
;
174 case WLAN_EID_HT_CAPABILITY
:
175 elems
->ht_cap_elem
= pos
;
176 elems
->ht_cap_elem_len
= elen
;
178 case WLAN_EID_HT_EXTRA_INFO
:
179 elems
->ht_info_elem
= pos
;
180 elems
->ht_info_elem_len
= elen
;
182 case WLAN_EID_MESH_ID
:
183 elems
->mesh_id
= pos
;
184 elems
->mesh_id_len
= elen
;
186 case WLAN_EID_MESH_CONFIG
:
187 elems
->mesh_config
= pos
;
188 elems
->mesh_config_len
= elen
;
190 case WLAN_EID_PEER_LINK
:
191 elems
->peer_link
= pos
;
192 elems
->peer_link_len
= elen
;
196 elems
->preq_len
= elen
;
200 elems
->prep_len
= elen
;
204 elems
->perr_len
= elen
;
216 static int ecw2cw(int ecw
)
218 return (1 << ecw
) - 1;
222 static void ieee80211_sta_def_wmm_params(struct net_device
*dev
,
223 struct ieee80211_sta_bss
*bss
,
226 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
227 struct ieee80211_local
*local
= sdata
->local
;
228 int i
, have_higher_than_11mbit
= 0;
231 /* cf. IEEE 802.11 9.2.12 */
232 for (i
= 0; i
< bss
->supp_rates_len
; i
++)
233 if ((bss
->supp_rates
[i
] & 0x7f) * 5 > 110)
234 have_higher_than_11mbit
= 1;
236 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
237 have_higher_than_11mbit
)
238 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
240 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
243 if (local
->ops
->conf_tx
) {
244 struct ieee80211_tx_queue_params qparam
;
246 memset(&qparam
, 0, sizeof(qparam
));
250 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
251 !(sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
))
256 qparam
.cw_max
= 1023;
259 for (i
= IEEE80211_TX_QUEUE_DATA0
; i
< NUM_TX_DATA_QUEUES
; i
++)
260 local
->ops
->conf_tx(local_to_hw(local
),
261 i
+ IEEE80211_TX_QUEUE_DATA0
,
265 /* IBSS uses different parameters for Beacon sending */
269 local
->ops
->conf_tx(local_to_hw(local
),
270 IEEE80211_TX_QUEUE_BEACON
, &qparam
);
275 static void ieee80211_sta_wmm_params(struct net_device
*dev
,
276 struct ieee80211_if_sta
*ifsta
,
277 u8
*wmm_param
, size_t wmm_param_len
)
279 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
280 struct ieee80211_tx_queue_params params
;
285 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
287 count
= wmm_param
[6] & 0x0f;
288 if (count
== ifsta
->wmm_last_param_set
)
290 ifsta
->wmm_last_param_set
= count
;
293 left
= wmm_param_len
- 8;
295 memset(¶ms
, 0, sizeof(params
));
297 if (!local
->ops
->conf_tx
)
301 for (; left
>= 4; left
-= 4, pos
+= 4) {
302 int aci
= (pos
[0] >> 5) & 0x03;
303 int acm
= (pos
[0] >> 4) & 0x01;
308 queue
= IEEE80211_TX_QUEUE_DATA3
;
310 local
->wmm_acm
|= BIT(0) | BIT(3);
314 queue
= IEEE80211_TX_QUEUE_DATA1
;
316 local
->wmm_acm
|= BIT(4) | BIT(5);
320 queue
= IEEE80211_TX_QUEUE_DATA0
;
322 local
->wmm_acm
|= BIT(6) | BIT(7);
327 queue
= IEEE80211_TX_QUEUE_DATA2
;
329 local
->wmm_acm
|= BIT(1) | BIT(2);
334 params
.aifs
= pos
[0] & 0x0f;
335 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
336 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
337 params
.txop
= pos
[2] | (pos
[3] << 8);
338 #ifdef CONFIG_MAC80211_DEBUG
339 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
340 "cWmin=%d cWmax=%d txop=%d\n",
341 dev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
342 params
.cw_max
, params
.txop
);
344 /* TODO: handle ACM (block TX, fallback to next lowest allowed
346 if (local
->ops
->conf_tx(local_to_hw(local
), queue
, ¶ms
)) {
347 printk(KERN_DEBUG
"%s: failed to set TX queue "
348 "parameters for queue %d\n", dev
->name
, queue
);
353 static u32
ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data
*sdata
,
355 bool use_short_preamble
)
357 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
358 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
359 DECLARE_MAC_BUF(mac
);
362 if (use_protection
!= bss_conf
->use_cts_prot
) {
363 if (net_ratelimit()) {
364 printk(KERN_DEBUG
"%s: CTS protection %s (BSSID="
367 use_protection
? "enabled" : "disabled",
368 print_mac(mac
, ifsta
->bssid
));
370 bss_conf
->use_cts_prot
= use_protection
;
371 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
374 if (use_short_preamble
!= bss_conf
->use_short_preamble
) {
375 if (net_ratelimit()) {
376 printk(KERN_DEBUG
"%s: switched to %s barker preamble"
379 use_short_preamble
? "short" : "long",
380 print_mac(mac
, ifsta
->bssid
));
382 bss_conf
->use_short_preamble
= use_short_preamble
;
383 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
389 static u32
ieee80211_handle_erp_ie(struct ieee80211_sub_if_data
*sdata
,
392 bool use_protection
= (erp_value
& WLAN_ERP_USE_PROTECTION
) != 0;
393 bool use_short_preamble
= (erp_value
& WLAN_ERP_BARKER_PREAMBLE
) == 0;
395 return ieee80211_handle_protect_preamb(sdata
,
396 use_protection
, use_short_preamble
);
399 static u32
ieee80211_handle_bss_capability(struct ieee80211_sub_if_data
*sdata
,
400 struct ieee80211_sta_bss
*bss
)
404 if (bss
->has_erp_value
)
405 changed
|= ieee80211_handle_erp_ie(sdata
, bss
->erp_value
);
407 u16 capab
= bss
->capability
;
408 changed
|= ieee80211_handle_protect_preamb(sdata
, false,
409 (capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
) != 0);
415 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap
*ht_cap_ie
,
416 struct ieee80211_ht_info
*ht_info
)
422 memset(ht_info
, 0, sizeof(*ht_info
));
425 u8 ampdu_info
= ht_cap_ie
->ampdu_params_info
;
427 ht_info
->ht_supported
= 1;
428 ht_info
->cap
= le16_to_cpu(ht_cap_ie
->cap_info
);
429 ht_info
->ampdu_factor
=
430 ampdu_info
& IEEE80211_HT_CAP_AMPDU_FACTOR
;
431 ht_info
->ampdu_density
=
432 (ampdu_info
& IEEE80211_HT_CAP_AMPDU_DENSITY
) >> 2;
433 memcpy(ht_info
->supp_mcs_set
, ht_cap_ie
->supp_mcs_set
, 16);
435 ht_info
->ht_supported
= 0;
440 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
441 struct ieee80211_ht_addt_info
*ht_add_info_ie
,
442 struct ieee80211_ht_bss_info
*bss_info
)
444 if (bss_info
== NULL
)
447 memset(bss_info
, 0, sizeof(*bss_info
));
449 if (ht_add_info_ie
) {
451 op_mode
= le16_to_cpu(ht_add_info_ie
->operation_mode
);
453 bss_info
->primary_channel
= ht_add_info_ie
->control_chan
;
454 bss_info
->bss_cap
= ht_add_info_ie
->ht_param
;
455 bss_info
->bss_op_mode
= (u8
)(op_mode
& 0xff);
461 static void ieee80211_sta_send_associnfo(struct net_device
*dev
,
462 struct ieee80211_if_sta
*ifsta
)
467 union iwreq_data wrqu
;
469 if (!ifsta
->assocreq_ies
&& !ifsta
->assocresp_ies
)
472 buf
= kmalloc(50 + 2 * (ifsta
->assocreq_ies_len
+
473 ifsta
->assocresp_ies_len
), GFP_KERNEL
);
477 len
= sprintf(buf
, "ASSOCINFO(");
478 if (ifsta
->assocreq_ies
) {
479 len
+= sprintf(buf
+ len
, "ReqIEs=");
480 for (i
= 0; i
< ifsta
->assocreq_ies_len
; i
++) {
481 len
+= sprintf(buf
+ len
, "%02x",
482 ifsta
->assocreq_ies
[i
]);
485 if (ifsta
->assocresp_ies
) {
486 if (ifsta
->assocreq_ies
)
487 len
+= sprintf(buf
+ len
, " ");
488 len
+= sprintf(buf
+ len
, "RespIEs=");
489 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
490 len
+= sprintf(buf
+ len
, "%02x",
491 ifsta
->assocresp_ies
[i
]);
494 len
+= sprintf(buf
+ len
, ")");
496 if (len
> IW_CUSTOM_MAX
) {
497 len
= sprintf(buf
, "ASSOCRESPIE=");
498 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
499 len
+= sprintf(buf
+ len
, "%02x",
500 ifsta
->assocresp_ies
[i
]);
504 memset(&wrqu
, 0, sizeof(wrqu
));
505 wrqu
.data
.length
= len
;
506 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
512 static void ieee80211_set_associated(struct net_device
*dev
,
513 struct ieee80211_if_sta
*ifsta
,
516 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
517 struct ieee80211_local
*local
= sdata
->local
;
518 struct ieee80211_conf
*conf
= &local_to_hw(local
)->conf
;
519 union iwreq_data wrqu
;
520 u32 changed
= BSS_CHANGED_ASSOC
;
523 struct ieee80211_sta_bss
*bss
;
525 ifsta
->flags
|= IEEE80211_STA_ASSOCIATED
;
527 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
530 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
531 conf
->channel
->center_freq
,
532 ifsta
->ssid
, ifsta
->ssid_len
);
534 /* set timing information */
535 sdata
->bss_conf
.beacon_int
= bss
->beacon_int
;
536 sdata
->bss_conf
.timestamp
= bss
->timestamp
;
538 changed
|= ieee80211_handle_bss_capability(sdata
, bss
);
540 ieee80211_rx_bss_put(dev
, bss
);
543 if (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
544 changed
|= BSS_CHANGED_HT
;
545 sdata
->bss_conf
.assoc_ht
= 1;
546 sdata
->bss_conf
.ht_conf
= &conf
->ht_conf
;
547 sdata
->bss_conf
.ht_bss_conf
= &conf
->ht_bss_conf
;
550 netif_carrier_on(dev
);
551 ifsta
->flags
|= IEEE80211_STA_PREV_BSSID_SET
;
552 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
553 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
554 ieee80211_sta_send_associnfo(dev
, ifsta
);
556 ieee80211_sta_tear_down_BA_sessions(dev
, ifsta
->bssid
);
557 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
558 netif_carrier_off(dev
);
559 ieee80211_reset_erp_info(dev
);
561 sdata
->bss_conf
.assoc_ht
= 0;
562 sdata
->bss_conf
.ht_conf
= NULL
;
563 sdata
->bss_conf
.ht_bss_conf
= NULL
;
565 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
567 ifsta
->last_probe
= jiffies
;
568 ieee80211_led_assoc(local
, assoc
);
570 sdata
->bss_conf
.assoc
= assoc
;
571 ieee80211_bss_info_change_notify(sdata
, changed
);
572 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
573 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
576 static void ieee80211_set_disassoc(struct net_device
*dev
,
577 struct ieee80211_if_sta
*ifsta
, int deauth
)
580 ifsta
->auth_tries
= 0;
581 ifsta
->assoc_tries
= 0;
582 ieee80211_set_associated(dev
, ifsta
, 0);
585 void ieee80211_sta_tx(struct net_device
*dev
, struct sk_buff
*skb
,
588 struct ieee80211_sub_if_data
*sdata
;
589 struct ieee80211_tx_packet_data
*pkt_data
;
591 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
592 skb
->dev
= sdata
->local
->mdev
;
593 skb_set_mac_header(skb
, 0);
594 skb_set_network_header(skb
, 0);
595 skb_set_transport_header(skb
, 0);
597 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
598 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
599 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
601 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
607 static void ieee80211_send_auth(struct net_device
*dev
,
608 struct ieee80211_if_sta
*ifsta
,
609 int transaction
, u8
*extra
, size_t extra_len
,
612 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
614 struct ieee80211_mgmt
*mgmt
;
616 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
617 sizeof(*mgmt
) + 6 + extra_len
);
619 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
620 "frame\n", dev
->name
);
623 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
625 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
626 memset(mgmt
, 0, 24 + 6);
627 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
628 IEEE80211_STYPE_AUTH
);
630 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
631 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
632 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
633 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
634 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
635 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
636 ifsta
->auth_transaction
= transaction
+ 1;
637 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
639 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
641 ieee80211_sta_tx(dev
, skb
, encrypt
);
645 static void ieee80211_authenticate(struct net_device
*dev
,
646 struct ieee80211_if_sta
*ifsta
)
648 DECLARE_MAC_BUF(mac
);
651 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
652 printk(KERN_DEBUG
"%s: authentication with AP %s"
654 dev
->name
, print_mac(mac
, ifsta
->bssid
));
655 ifsta
->state
= IEEE80211_DISABLED
;
659 ifsta
->state
= IEEE80211_AUTHENTICATE
;
660 printk(KERN_DEBUG
"%s: authenticate with AP %s\n",
661 dev
->name
, print_mac(mac
, ifsta
->bssid
));
663 ieee80211_send_auth(dev
, ifsta
, 1, NULL
, 0, 0);
665 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_AUTH_TIMEOUT
);
668 static int ieee80211_compatible_rates(struct ieee80211_sta_bss
*bss
,
669 struct ieee80211_supported_band
*sband
,
675 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
676 int rate
= (bss
->supp_rates
[i
] & 0x7F) * 5;
678 for (j
= 0; j
< sband
->n_bitrates
; j
++)
679 if (sband
->bitrates
[j
].bitrate
== rate
) {
689 static void ieee80211_send_assoc(struct net_device
*dev
,
690 struct ieee80211_if_sta
*ifsta
)
692 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
694 struct ieee80211_mgmt
*mgmt
;
696 int i
, len
, count
, rates_len
, supp_rates_len
;
698 struct ieee80211_sta_bss
*bss
;
700 struct ieee80211_supported_band
*sband
;
703 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
704 sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
707 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
708 "frame\n", dev
->name
);
711 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
713 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
715 capab
= ifsta
->capab
;
717 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
) {
718 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
719 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
720 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
721 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
724 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
725 local
->hw
.conf
.channel
->center_freq
,
726 ifsta
->ssid
, ifsta
->ssid_len
);
728 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
729 capab
|= WLAN_CAPABILITY_PRIVACY
;
733 ieee80211_rx_bss_put(dev
, bss
);
736 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
738 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
739 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
740 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
742 if (ifsta
->flags
& IEEE80211_STA_PREV_BSSID_SET
) {
744 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
745 IEEE80211_STYPE_REASSOC_REQ
);
746 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
747 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
748 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
752 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
753 IEEE80211_STYPE_ASSOC_REQ
);
754 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
755 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
759 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
760 *pos
++ = WLAN_EID_SSID
;
761 *pos
++ = ifsta
->ssid_len
;
762 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
764 /* all supported rates should be added here but some APs
765 * (e.g. D-Link DAP 1353 in b-only mode) don't like that
766 * Therefore only add rates the AP supports */
767 rates_len
= ieee80211_compatible_rates(bss
, sband
, &rates
);
768 supp_rates_len
= rates_len
;
769 if (supp_rates_len
> 8)
772 len
= sband
->n_bitrates
;
773 pos
= skb_put(skb
, supp_rates_len
+ 2);
774 *pos
++ = WLAN_EID_SUPP_RATES
;
775 *pos
++ = supp_rates_len
;
778 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
779 if (BIT(i
) & rates
) {
780 int rate
= sband
->bitrates
[i
].bitrate
;
781 *pos
++ = (u8
) (rate
/ 5);
788 pos
= skb_put(skb
, rates_len
- count
+ 2);
789 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
790 *pos
++ = rates_len
- count
;
792 for (i
++; i
< sband
->n_bitrates
; i
++) {
793 if (BIT(i
) & rates
) {
794 int rate
= sband
->bitrates
[i
].bitrate
;
795 *pos
++ = (u8
) (rate
/ 5);
800 if (ifsta
->extra_ie
) {
801 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
802 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
805 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
806 pos
= skb_put(skb
, 9);
807 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
808 *pos
++ = 7; /* len */
809 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
812 *pos
++ = 2; /* WME */
813 *pos
++ = 0; /* WME info */
814 *pos
++ = 1; /* WME ver */
817 /* wmm support is a must to HT */
818 if (wmm
&& sband
->ht_info
.ht_supported
) {
819 __le16 tmp
= cpu_to_le16(sband
->ht_info
.cap
);
820 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
)+2);
821 *pos
++ = WLAN_EID_HT_CAPABILITY
;
822 *pos
++ = sizeof(struct ieee80211_ht_cap
);
823 memset(pos
, 0, sizeof(struct ieee80211_ht_cap
));
824 memcpy(pos
, &tmp
, sizeof(u16
));
826 /* TODO: needs a define here for << 2 */
827 *pos
++ = sband
->ht_info
.ampdu_factor
|
828 (sband
->ht_info
.ampdu_density
<< 2);
829 memcpy(pos
, sband
->ht_info
.supp_mcs_set
, 16);
832 kfree(ifsta
->assocreq_ies
);
833 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
834 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_KERNEL
);
835 if (ifsta
->assocreq_ies
)
836 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
838 ieee80211_sta_tx(dev
, skb
, 0);
842 static void ieee80211_send_deauth(struct net_device
*dev
,
843 struct ieee80211_if_sta
*ifsta
, u16 reason
)
845 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
847 struct ieee80211_mgmt
*mgmt
;
849 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
851 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
852 "frame\n", dev
->name
);
855 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
857 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
859 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
860 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
861 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
862 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
863 IEEE80211_STYPE_DEAUTH
);
865 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
867 ieee80211_sta_tx(dev
, skb
, 0);
871 static void ieee80211_send_disassoc(struct net_device
*dev
,
872 struct ieee80211_if_sta
*ifsta
, u16 reason
)
874 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
876 struct ieee80211_mgmt
*mgmt
;
878 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
880 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
881 "frame\n", dev
->name
);
884 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
886 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
888 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
889 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
890 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
891 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
892 IEEE80211_STYPE_DISASSOC
);
894 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
896 ieee80211_sta_tx(dev
, skb
, 0);
900 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
901 struct ieee80211_if_sta
*ifsta
)
903 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
904 struct ieee80211_sta_bss
*bss
;
909 if (!ifsta
|| (ifsta
->flags
& IEEE80211_STA_MIXED_CELL
))
912 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
913 local
->hw
.conf
.channel
->center_freq
,
914 ifsta
->ssid
, ifsta
->ssid_len
);
918 bss_privacy
= !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
919 wep_privacy
= !!ieee80211_sta_wep_configured(dev
);
920 privacy_invoked
= !!(ifsta
->flags
& IEEE80211_STA_PRIVACY_INVOKED
);
922 ieee80211_rx_bss_put(dev
, bss
);
924 if ((bss_privacy
== wep_privacy
) || (bss_privacy
== privacy_invoked
))
931 static void ieee80211_associate(struct net_device
*dev
,
932 struct ieee80211_if_sta
*ifsta
)
934 DECLARE_MAC_BUF(mac
);
936 ifsta
->assoc_tries
++;
937 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
938 printk(KERN_DEBUG
"%s: association with AP %s"
940 dev
->name
, print_mac(mac
, ifsta
->bssid
));
941 ifsta
->state
= IEEE80211_DISABLED
;
945 ifsta
->state
= IEEE80211_ASSOCIATE
;
946 printk(KERN_DEBUG
"%s: associate with AP %s\n",
947 dev
->name
, print_mac(mac
, ifsta
->bssid
));
948 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
949 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
950 "mixed-cell disabled - abort association\n", dev
->name
);
951 ifsta
->state
= IEEE80211_DISABLED
;
955 ieee80211_send_assoc(dev
, ifsta
);
957 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_ASSOC_TIMEOUT
);
961 static void ieee80211_associated(struct net_device
*dev
,
962 struct ieee80211_if_sta
*ifsta
)
964 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
965 struct sta_info
*sta
;
967 DECLARE_MAC_BUF(mac
);
969 /* TODO: start monitoring current AP signal quality and number of
970 * missed beacons. Scan other channels every now and then and search
972 /* TODO: remove expired BSSes */
974 ifsta
->state
= IEEE80211_ASSOCIATED
;
978 sta
= sta_info_get(local
, ifsta
->bssid
);
980 printk(KERN_DEBUG
"%s: No STA entry for own AP %s\n",
981 dev
->name
, print_mac(mac
, ifsta
->bssid
));
985 if (time_after(jiffies
,
986 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
987 if (ifsta
->flags
& IEEE80211_STA_PROBEREQ_POLL
) {
988 printk(KERN_DEBUG
"%s: No ProbeResp from "
989 "current AP %s - assume out of "
991 dev
->name
, print_mac(mac
, ifsta
->bssid
));
993 sta_info_unlink(&sta
);
995 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
997 local
->scan_ssid_len
);
998 ifsta
->flags
^= IEEE80211_STA_PROBEREQ_POLL
;
1000 ifsta
->flags
&= ~IEEE80211_STA_PROBEREQ_POLL
;
1001 if (time_after(jiffies
, ifsta
->last_probe
+
1002 IEEE80211_PROBE_INTERVAL
)) {
1003 ifsta
->last_probe
= jiffies
;
1004 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
1013 if (disassoc
&& sta
)
1014 sta_info_destroy(sta
);
1017 ifsta
->state
= IEEE80211_DISABLED
;
1018 ieee80211_set_associated(dev
, ifsta
, 0);
1020 mod_timer(&ifsta
->timer
, jiffies
+
1021 IEEE80211_MONITORING_INTERVAL
);
1026 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
1027 u8
*ssid
, size_t ssid_len
)
1029 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1030 struct ieee80211_supported_band
*sband
;
1031 struct sk_buff
*skb
;
1032 struct ieee80211_mgmt
*mgmt
;
1033 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
1036 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200);
1038 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
1039 "request\n", dev
->name
);
1042 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1044 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1045 memset(mgmt
, 0, 24);
1046 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1047 IEEE80211_STYPE_PROBE_REQ
);
1048 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1050 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
1051 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
1053 memset(mgmt
->da
, 0xff, ETH_ALEN
);
1054 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
1056 pos
= skb_put(skb
, 2 + ssid_len
);
1057 *pos
++ = WLAN_EID_SSID
;
1059 memcpy(pos
, ssid
, ssid_len
);
1061 supp_rates
= skb_put(skb
, 2);
1062 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
1064 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
1066 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1067 struct ieee80211_rate
*rate
= &sband
->bitrates
[i
];
1069 pos
= skb_put(skb
, 1);
1071 } else if (supp_rates
[1] == 8) {
1072 esupp_rates
= skb_put(skb
, 3);
1073 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
1075 pos
= &esupp_rates
[2];
1077 pos
= skb_put(skb
, 1);
1080 *pos
= rate
->bitrate
/ 5;
1083 ieee80211_sta_tx(dev
, skb
, 0);
1087 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
1089 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1090 if (!sdata
|| !sdata
->default_key
||
1091 sdata
->default_key
->conf
.alg
!= ALG_WEP
)
1097 static void ieee80211_auth_completed(struct net_device
*dev
,
1098 struct ieee80211_if_sta
*ifsta
)
1100 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
1101 ifsta
->flags
|= IEEE80211_STA_AUTHENTICATED
;
1102 ieee80211_associate(dev
, ifsta
);
1106 static void ieee80211_auth_challenge(struct net_device
*dev
,
1107 struct ieee80211_if_sta
*ifsta
,
1108 struct ieee80211_mgmt
*mgmt
,
1112 struct ieee802_11_elems elems
;
1114 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
1115 pos
= mgmt
->u
.auth
.variable
;
1116 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1117 if (!elems
.challenge
) {
1118 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
1119 "frame\n", dev
->name
);
1122 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
1123 elems
.challenge_len
+ 2, 1);
1126 static void ieee80211_send_addba_resp(struct net_device
*dev
, u8
*da
, u16 tid
,
1127 u8 dialog_token
, u16 status
, u16 policy
,
1128 u16 buf_size
, u16 timeout
)
1130 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1131 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1132 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1133 struct sk_buff
*skb
;
1134 struct ieee80211_mgmt
*mgmt
;
1137 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1138 sizeof(mgmt
->u
.action
.u
.addba_resp
));
1140 printk(KERN_DEBUG
"%s: failed to allocate buffer "
1141 "for addba resp frame\n", dev
->name
);
1145 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1146 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1147 memset(mgmt
, 0, 24);
1148 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1149 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1150 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1151 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1153 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1154 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1155 IEEE80211_STYPE_ACTION
);
1157 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_resp
));
1158 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1159 mgmt
->u
.action
.u
.addba_resp
.action_code
= WLAN_ACTION_ADDBA_RESP
;
1160 mgmt
->u
.action
.u
.addba_resp
.dialog_token
= dialog_token
;
1162 capab
= (u16
)(policy
<< 1); /* bit 1 aggregation policy */
1163 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1164 capab
|= (u16
)(buf_size
<< 6); /* bit 15:6 max size of aggregation */
1166 mgmt
->u
.action
.u
.addba_resp
.capab
= cpu_to_le16(capab
);
1167 mgmt
->u
.action
.u
.addba_resp
.timeout
= cpu_to_le16(timeout
);
1168 mgmt
->u
.action
.u
.addba_resp
.status
= cpu_to_le16(status
);
1170 ieee80211_sta_tx(dev
, skb
, 0);
1175 void ieee80211_send_addba_request(struct net_device
*dev
, const u8
*da
,
1176 u16 tid
, u8 dialog_token
, u16 start_seq_num
,
1177 u16 agg_size
, u16 timeout
)
1179 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1180 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1181 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1182 struct sk_buff
*skb
;
1183 struct ieee80211_mgmt
*mgmt
;
1186 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1187 sizeof(mgmt
->u
.action
.u
.addba_req
));
1191 printk(KERN_ERR
"%s: failed to allocate buffer "
1192 "for addba request frame\n", dev
->name
);
1195 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1196 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1197 memset(mgmt
, 0, 24);
1198 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1199 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1200 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1201 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1203 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1205 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1206 IEEE80211_STYPE_ACTION
);
1208 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_req
));
1210 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1211 mgmt
->u
.action
.u
.addba_req
.action_code
= WLAN_ACTION_ADDBA_REQ
;
1213 mgmt
->u
.action
.u
.addba_req
.dialog_token
= dialog_token
;
1214 capab
= (u16
)(1 << 1); /* bit 1 aggregation policy */
1215 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1216 capab
|= (u16
)(agg_size
<< 6); /* bit 15:6 max size of aggergation */
1218 mgmt
->u
.action
.u
.addba_req
.capab
= cpu_to_le16(capab
);
1220 mgmt
->u
.action
.u
.addba_req
.timeout
= cpu_to_le16(timeout
);
1221 mgmt
->u
.action
.u
.addba_req
.start_seq_num
=
1222 cpu_to_le16(start_seq_num
<< 4);
1224 ieee80211_sta_tx(dev
, skb
, 0);
1227 static void ieee80211_sta_process_addba_request(struct net_device
*dev
,
1228 struct ieee80211_mgmt
*mgmt
,
1231 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1232 struct ieee80211_hw
*hw
= &local
->hw
;
1233 struct ieee80211_conf
*conf
= &hw
->conf
;
1234 struct sta_info
*sta
;
1235 struct tid_ampdu_rx
*tid_agg_rx
;
1236 u16 capab
, tid
, timeout
, ba_policy
, buf_size
, start_seq_num
, status
;
1238 int ret
= -EOPNOTSUPP
;
1239 DECLARE_MAC_BUF(mac
);
1243 sta
= sta_info_get(local
, mgmt
->sa
);
1249 /* extract session parameters from addba request frame */
1250 dialog_token
= mgmt
->u
.action
.u
.addba_req
.dialog_token
;
1251 timeout
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.timeout
);
1253 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.start_seq_num
) >> 4;
1255 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1256 ba_policy
= (capab
& IEEE80211_ADDBA_PARAM_POLICY_MASK
) >> 1;
1257 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1258 buf_size
= (capab
& IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
) >> 6;
1260 status
= WLAN_STATUS_REQUEST_DECLINED
;
1262 /* sanity check for incoming parameters:
1263 * check if configuration can support the BA policy
1264 * and if buffer size does not exceeds max value */
1265 if (((ba_policy
!= 1)
1266 && (!(conf
->ht_conf
.cap
& IEEE80211_HT_CAP_DELAY_BA
)))
1267 || (buf_size
> IEEE80211_MAX_AMPDU_BUF
)) {
1268 status
= WLAN_STATUS_INVALID_QOS_PARAM
;
1269 #ifdef CONFIG_MAC80211_HT_DEBUG
1270 if (net_ratelimit())
1271 printk(KERN_DEBUG
"AddBA Req with bad params from "
1272 "%s on tid %u. policy %d, buffer size %d\n",
1273 print_mac(mac
, mgmt
->sa
), tid
, ba_policy
,
1275 #endif /* CONFIG_MAC80211_HT_DEBUG */
1278 /* determine default buffer size */
1279 if (buf_size
== 0) {
1280 struct ieee80211_supported_band
*sband
;
1282 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
1283 buf_size
= IEEE80211_MIN_AMPDU_BUF
;
1284 buf_size
= buf_size
<< sband
->ht_info
.ampdu_factor
;
1288 /* examine state machine */
1289 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1291 if (sta
->ampdu_mlme
.tid_state_rx
[tid
] != HT_AGG_STATE_IDLE
) {
1292 #ifdef CONFIG_MAC80211_HT_DEBUG
1293 if (net_ratelimit())
1294 printk(KERN_DEBUG
"unexpected AddBA Req from "
1296 print_mac(mac
, mgmt
->sa
), tid
);
1297 #endif /* CONFIG_MAC80211_HT_DEBUG */
1301 /* prepare A-MPDU MLME for Rx aggregation */
1302 sta
->ampdu_mlme
.tid_rx
[tid
] =
1303 kmalloc(sizeof(struct tid_ampdu_rx
), GFP_ATOMIC
);
1304 if (!sta
->ampdu_mlme
.tid_rx
[tid
]) {
1305 if (net_ratelimit())
1306 printk(KERN_ERR
"allocate rx mlme to tid %d failed\n",
1311 sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
.function
=
1312 sta_rx_agg_session_timer_expired
;
1313 sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
.data
=
1314 (unsigned long)&sta
->timer_to_tid
[tid
];
1315 init_timer(&sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
);
1317 tid_agg_rx
= sta
->ampdu_mlme
.tid_rx
[tid
];
1319 /* prepare reordering buffer */
1320 tid_agg_rx
->reorder_buf
=
1321 kmalloc(buf_size
* sizeof(struct sk_buf
*), GFP_ATOMIC
);
1322 if (!tid_agg_rx
->reorder_buf
) {
1323 if (net_ratelimit())
1324 printk(KERN_ERR
"can not allocate reordering buffer "
1325 "to tid %d\n", tid
);
1326 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]);
1329 memset(tid_agg_rx
->reorder_buf
, 0,
1330 buf_size
* sizeof(struct sk_buf
*));
1332 if (local
->ops
->ampdu_action
)
1333 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_START
,
1334 sta
->addr
, tid
, &start_seq_num
);
1335 #ifdef CONFIG_MAC80211_HT_DEBUG
1336 printk(KERN_DEBUG
"Rx A-MPDU request on tid %d result %d\n", tid
, ret
);
1337 #endif /* CONFIG_MAC80211_HT_DEBUG */
1340 kfree(tid_agg_rx
->reorder_buf
);
1342 sta
->ampdu_mlme
.tid_rx
[tid
] = NULL
;
1346 /* change state and send addba resp */
1347 sta
->ampdu_mlme
.tid_state_rx
[tid
] = HT_AGG_STATE_OPERATIONAL
;
1348 tid_agg_rx
->dialog_token
= dialog_token
;
1349 tid_agg_rx
->ssn
= start_seq_num
;
1350 tid_agg_rx
->head_seq_num
= start_seq_num
;
1351 tid_agg_rx
->buf_size
= buf_size
;
1352 tid_agg_rx
->timeout
= timeout
;
1353 tid_agg_rx
->stored_mpdu_num
= 0;
1354 status
= WLAN_STATUS_SUCCESS
;
1356 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1359 ieee80211_send_addba_resp(sta
->sdata
->dev
, sta
->addr
, tid
,
1360 dialog_token
, status
, 1, buf_size
, timeout
);
1364 static void ieee80211_sta_process_addba_resp(struct net_device
*dev
,
1365 struct ieee80211_mgmt
*mgmt
,
1368 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1369 struct ieee80211_hw
*hw
= &local
->hw
;
1370 struct sta_info
*sta
;
1377 sta
= sta_info_get(local
, mgmt
->sa
);
1383 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.capab
);
1384 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1386 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
1388 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1390 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1391 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1392 printk(KERN_DEBUG
"state not HT_ADDBA_REQUESTED_MSK:"
1394 goto addba_resp_exit
;
1397 if (mgmt
->u
.action
.u
.addba_resp
.dialog_token
!=
1398 sta
->ampdu_mlme
.tid_tx
[tid
]->dialog_token
) {
1399 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1400 #ifdef CONFIG_MAC80211_HT_DEBUG
1401 printk(KERN_DEBUG
"wrong addBA response token, tid %d\n", tid
);
1402 #endif /* CONFIG_MAC80211_HT_DEBUG */
1403 goto addba_resp_exit
;
1406 del_timer_sync(&sta
->ampdu_mlme
.tid_tx
[tid
]->addba_resp_timer
);
1407 #ifdef CONFIG_MAC80211_HT_DEBUG
1408 printk(KERN_DEBUG
"switched off addBA timer for tid %d \n", tid
);
1409 #endif /* CONFIG_MAC80211_HT_DEBUG */
1410 if (le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.status
)
1411 == WLAN_STATUS_SUCCESS
) {
1412 if (*state
& HT_ADDBA_RECEIVED_MSK
)
1413 printk(KERN_DEBUG
"double addBA response\n");
1415 *state
|= HT_ADDBA_RECEIVED_MSK
;
1416 sta
->ampdu_mlme
.addba_req_num
[tid
] = 0;
1418 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
1419 printk(KERN_DEBUG
"Aggregation on for tid %d \n", tid
);
1420 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
1423 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1424 printk(KERN_DEBUG
"recipient accepted agg: tid %d \n", tid
);
1426 printk(KERN_DEBUG
"recipient rejected agg: tid %d \n", tid
);
1428 sta
->ampdu_mlme
.addba_req_num
[tid
]++;
1429 /* this will allow the state check in stop_BA_session */
1430 *state
= HT_AGG_STATE_OPERATIONAL
;
1431 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1432 ieee80211_stop_tx_ba_session(hw
, sta
->addr
, tid
,
1433 WLAN_BACK_INITIATOR
);
1440 void ieee80211_send_delba(struct net_device
*dev
, const u8
*da
, u16 tid
,
1441 u16 initiator
, u16 reason_code
)
1443 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1444 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1445 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1446 struct sk_buff
*skb
;
1447 struct ieee80211_mgmt
*mgmt
;
1450 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1451 sizeof(mgmt
->u
.action
.u
.delba
));
1454 printk(KERN_ERR
"%s: failed to allocate buffer "
1455 "for delba frame\n", dev
->name
);
1459 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1460 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1461 memset(mgmt
, 0, 24);
1462 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1463 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1464 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1465 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1467 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1468 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1469 IEEE80211_STYPE_ACTION
);
1471 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.delba
));
1473 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1474 mgmt
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
1475 params
= (u16
)(initiator
<< 11); /* bit 11 initiator */
1476 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
1478 mgmt
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
1479 mgmt
->u
.action
.u
.delba
.reason_code
= cpu_to_le16(reason_code
);
1481 ieee80211_sta_tx(dev
, skb
, 0);
1484 void ieee80211_sta_stop_rx_ba_session(struct net_device
*dev
, u8
*ra
, u16 tid
,
1485 u16 initiator
, u16 reason
)
1487 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1488 struct ieee80211_hw
*hw
= &local
->hw
;
1489 struct sta_info
*sta
;
1491 DECLARE_MAC_BUF(mac
);
1495 sta
= sta_info_get(local
, ra
);
1501 /* check if TID is in operational state */
1502 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1503 if (sta
->ampdu_mlme
.tid_state_rx
[tid
]
1504 != HT_AGG_STATE_OPERATIONAL
) {
1505 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1509 sta
->ampdu_mlme
.tid_state_rx
[tid
] =
1510 HT_AGG_STATE_REQ_STOP_BA_MSK
|
1511 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
1512 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1514 /* stop HW Rx aggregation. ampdu_action existence
1515 * already verified in session init so we add the BUG_ON */
1516 BUG_ON(!local
->ops
->ampdu_action
);
1518 #ifdef CONFIG_MAC80211_HT_DEBUG
1519 printk(KERN_DEBUG
"Rx BA session stop requested for %s tid %u\n",
1520 print_mac(mac
, ra
), tid
);
1521 #endif /* CONFIG_MAC80211_HT_DEBUG */
1523 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_STOP
,
1526 printk(KERN_DEBUG
"HW problem - can not stop rx "
1527 "aggergation for tid %d\n", tid
);
1529 /* shutdown timer has not expired */
1530 if (initiator
!= WLAN_BACK_TIMER
)
1531 del_timer_sync(&sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
);
1533 /* check if this is a self generated aggregation halt */
1534 if (initiator
== WLAN_BACK_RECIPIENT
|| initiator
== WLAN_BACK_TIMER
)
1535 ieee80211_send_delba(dev
, ra
, tid
, 0, reason
);
1537 /* free the reordering buffer */
1538 for (i
= 0; i
< sta
->ampdu_mlme
.tid_rx
[tid
]->buf_size
; i
++) {
1539 if (sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
]) {
1540 /* release the reordered frames */
1541 dev_kfree_skb(sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
]);
1542 sta
->ampdu_mlme
.tid_rx
[tid
]->stored_mpdu_num
--;
1543 sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
] = NULL
;
1546 /* free resources */
1547 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
);
1548 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]);
1549 sta
->ampdu_mlme
.tid_rx
[tid
] = NULL
;
1550 sta
->ampdu_mlme
.tid_state_rx
[tid
] = HT_AGG_STATE_IDLE
;
1556 static void ieee80211_sta_process_delba(struct net_device
*dev
,
1557 struct ieee80211_mgmt
*mgmt
, size_t len
)
1559 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1560 struct sta_info
*sta
;
1563 DECLARE_MAC_BUF(mac
);
1567 sta
= sta_info_get(local
, mgmt
->sa
);
1573 params
= le16_to_cpu(mgmt
->u
.action
.u
.delba
.params
);
1574 tid
= (params
& IEEE80211_DELBA_PARAM_TID_MASK
) >> 12;
1575 initiator
= (params
& IEEE80211_DELBA_PARAM_INITIATOR_MASK
) >> 11;
1577 #ifdef CONFIG_MAC80211_HT_DEBUG
1578 if (net_ratelimit())
1579 printk(KERN_DEBUG
"delba from %s (%s) tid %d reason code %d\n",
1580 print_mac(mac
, mgmt
->sa
),
1581 initiator
? "initiator" : "recipient", tid
,
1582 mgmt
->u
.action
.u
.delba
.reason_code
);
1583 #endif /* CONFIG_MAC80211_HT_DEBUG */
1585 if (initiator
== WLAN_BACK_INITIATOR
)
1586 ieee80211_sta_stop_rx_ba_session(dev
, sta
->addr
, tid
,
1587 WLAN_BACK_INITIATOR
, 0);
1588 else { /* WLAN_BACK_RECIPIENT */
1589 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1590 sta
->ampdu_mlme
.tid_state_tx
[tid
] =
1591 HT_AGG_STATE_OPERATIONAL
;
1592 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1593 ieee80211_stop_tx_ba_session(&local
->hw
, sta
->addr
, tid
,
1594 WLAN_BACK_RECIPIENT
);
1600 * After sending add Block Ack request we activated a timer until
1601 * add Block Ack response will arrive from the recipient.
1602 * If this timer expires sta_addba_resp_timer_expired will be executed.
1604 void sta_addba_resp_timer_expired(unsigned long data
)
1606 /* not an elegant detour, but there is no choice as the timer passes
1607 * only one argument, and both sta_info and TID are needed, so init
1608 * flow in sta_info_create gives the TID as data, while the timer_to_id
1609 * array gives the sta through container_of */
1610 u16 tid
= *(int *)data
;
1611 struct sta_info
*temp_sta
= container_of((void *)data
,
1612 struct sta_info
, timer_to_tid
[tid
]);
1614 struct ieee80211_local
*local
= temp_sta
->local
;
1615 struct ieee80211_hw
*hw
= &local
->hw
;
1616 struct sta_info
*sta
;
1621 sta
= sta_info_get(local
, temp_sta
->addr
);
1627 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
1628 /* check if the TID waits for addBA response */
1629 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1630 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1631 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1632 *state
= HT_AGG_STATE_IDLE
;
1633 printk(KERN_DEBUG
"timer expired on tid %d but we are not "
1634 "expecting addBA response there", tid
);
1635 goto timer_expired_exit
;
1638 printk(KERN_DEBUG
"addBA response timer expired on tid %d\n", tid
);
1640 /* go through the state check in stop_BA_session */
1641 *state
= HT_AGG_STATE_OPERATIONAL
;
1642 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1643 ieee80211_stop_tx_ba_session(hw
, temp_sta
->addr
, tid
,
1644 WLAN_BACK_INITIATOR
);
1651 * After accepting the AddBA Request we activated a timer,
1652 * resetting it after each frame that arrives from the originator.
1653 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1655 void sta_rx_agg_session_timer_expired(unsigned long data
)
1657 /* not an elegant detour, but there is no choice as the timer passes
1658 * only one argument, and verious sta_info are needed here, so init
1659 * flow in sta_info_create gives the TID as data, while the timer_to_id
1660 * array gives the sta through container_of */
1661 u8
*ptid
= (u8
*)data
;
1662 u8
*timer_to_id
= ptid
- *ptid
;
1663 struct sta_info
*sta
= container_of(timer_to_id
, struct sta_info
,
1666 printk(KERN_DEBUG
"rx session timer expired on tid %d\n", (u16
)*ptid
);
1667 ieee80211_sta_stop_rx_ba_session(sta
->sdata
->dev
, sta
->addr
,
1668 (u16
)*ptid
, WLAN_BACK_TIMER
,
1669 WLAN_REASON_QSTA_TIMEOUT
);
1672 void ieee80211_sta_tear_down_BA_sessions(struct net_device
*dev
, u8
*addr
)
1674 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1677 for (i
= 0; i
< STA_TID_NUM
; i
++) {
1678 ieee80211_stop_tx_ba_session(&local
->hw
, addr
, i
,
1679 WLAN_BACK_INITIATOR
);
1680 ieee80211_sta_stop_rx_ba_session(dev
, addr
, i
,
1681 WLAN_BACK_RECIPIENT
,
1682 WLAN_REASON_QSTA_LEAVE_QBSS
);
1686 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
1687 struct ieee80211_if_sta
*ifsta
,
1688 struct ieee80211_mgmt
*mgmt
,
1691 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1692 u16 auth_alg
, auth_transaction
, status_code
;
1693 DECLARE_MAC_BUF(mac
);
1695 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
1696 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
) {
1697 printk(KERN_DEBUG
"%s: authentication frame received from "
1698 "%s, but not in authenticate state - ignored\n",
1699 dev
->name
, print_mac(mac
, mgmt
->sa
));
1704 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
1705 "received from %s - ignored\n",
1706 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1710 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1711 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1712 printk(KERN_DEBUG
"%s: authentication frame received from "
1713 "unknown AP (SA=%s BSSID=%s) - "
1714 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1715 print_mac(mac
, mgmt
->bssid
));
1719 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1720 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
1721 printk(KERN_DEBUG
"%s: authentication frame received from "
1722 "unknown BSSID (SA=%s BSSID=%s) - "
1723 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1724 print_mac(mac
, mgmt
->bssid
));
1728 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
1729 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
1730 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
1732 printk(KERN_DEBUG
"%s: RX authentication from %s (alg=%d "
1733 "transaction=%d status=%d)\n",
1734 dev
->name
, print_mac(mac
, mgmt
->sa
), auth_alg
,
1735 auth_transaction
, status_code
);
1737 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
1738 /* IEEE 802.11 standard does not require authentication in IBSS
1739 * networks and most implementations do not seem to use it.
1740 * However, try to reply to authentication attempts if someone
1741 * has actually implemented this.
1742 * TODO: Could implement shared key authentication. */
1743 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
1744 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
1745 "frame (alg=%d transaction=%d)\n",
1746 dev
->name
, auth_alg
, auth_transaction
);
1749 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
1752 if (auth_alg
!= ifsta
->auth_alg
||
1753 auth_transaction
!= ifsta
->auth_transaction
) {
1754 printk(KERN_DEBUG
"%s: unexpected authentication frame "
1755 "(alg=%d transaction=%d)\n",
1756 dev
->name
, auth_alg
, auth_transaction
);
1760 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1761 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
1762 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
1763 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
1765 const int num_algs
= ARRAY_SIZE(algs
);
1767 algs
[0] = algs
[1] = algs
[2] = 0xff;
1768 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1769 algs
[0] = WLAN_AUTH_OPEN
;
1770 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1771 algs
[1] = WLAN_AUTH_SHARED_KEY
;
1772 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1773 algs
[2] = WLAN_AUTH_LEAP
;
1774 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
1776 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
1780 for (i
= 0; i
< num_algs
; i
++) {
1782 if (pos
>= num_algs
)
1784 if (algs
[pos
] == ifsta
->auth_alg
||
1787 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
1788 !ieee80211_sta_wep_configured(dev
))
1790 ifsta
->auth_alg
= algs
[pos
];
1791 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
1793 dev
->name
, ifsta
->auth_alg
);
1800 switch (ifsta
->auth_alg
) {
1801 case WLAN_AUTH_OPEN
:
1802 case WLAN_AUTH_LEAP
:
1803 ieee80211_auth_completed(dev
, ifsta
);
1805 case WLAN_AUTH_SHARED_KEY
:
1806 if (ifsta
->auth_transaction
== 4)
1807 ieee80211_auth_completed(dev
, ifsta
);
1809 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
);
1815 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
1816 struct ieee80211_if_sta
*ifsta
,
1817 struct ieee80211_mgmt
*mgmt
,
1821 DECLARE_MAC_BUF(mac
);
1824 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
1825 "received from %s - ignored\n",
1826 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1830 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1831 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1832 "unknown AP (SA=%s BSSID=%s) - "
1833 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1834 print_mac(mac
, mgmt
->bssid
));
1838 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1840 printk(KERN_DEBUG
"%s: RX deauthentication from %s"
1842 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1844 if (ifsta
->flags
& IEEE80211_STA_AUTHENTICATED
) {
1845 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1848 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1849 ifsta
->state
== IEEE80211_ASSOCIATE
||
1850 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1851 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1852 mod_timer(&ifsta
->timer
, jiffies
+
1853 IEEE80211_RETRY_AUTH_INTERVAL
);
1856 ieee80211_set_disassoc(dev
, ifsta
, 1);
1857 ifsta
->flags
&= ~IEEE80211_STA_AUTHENTICATED
;
1861 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1862 struct ieee80211_if_sta
*ifsta
,
1863 struct ieee80211_mgmt
*mgmt
,
1867 DECLARE_MAC_BUF(mac
);
1870 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1871 "received from %s - ignored\n",
1872 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1876 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1877 printk(KERN_DEBUG
"%s: disassociation frame received from "
1878 "unknown AP (SA=%s BSSID=%s) - "
1879 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1880 print_mac(mac
, mgmt
->bssid
));
1884 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1886 printk(KERN_DEBUG
"%s: RX disassociation from %s"
1888 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1890 if (ifsta
->flags
& IEEE80211_STA_ASSOCIATED
)
1891 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1893 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1894 ifsta
->state
= IEEE80211_ASSOCIATE
;
1895 mod_timer(&ifsta
->timer
, jiffies
+
1896 IEEE80211_RETRY_AUTH_INTERVAL
);
1899 ieee80211_set_disassoc(dev
, ifsta
, 0);
1903 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
1904 struct ieee80211_if_sta
*ifsta
,
1905 struct ieee80211_mgmt
*mgmt
,
1909 struct ieee80211_local
*local
= sdata
->local
;
1910 struct net_device
*dev
= sdata
->dev
;
1911 struct ieee80211_supported_band
*sband
;
1912 struct sta_info
*sta
;
1913 u64 rates
, basic_rates
;
1914 u16 capab_info
, status_code
, aid
;
1915 struct ieee802_11_elems elems
;
1916 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
1919 DECLARE_MAC_BUF(mac
);
1920 bool have_higher_than_11mbit
= false;
1922 /* AssocResp and ReassocResp have identical structure, so process both
1923 * of them in this function. */
1925 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1926 printk(KERN_DEBUG
"%s: association frame received from "
1927 "%s, but not in associate state - ignored\n",
1928 dev
->name
, print_mac(mac
, mgmt
->sa
));
1933 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1934 "received from %s - ignored\n",
1935 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1939 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1940 printk(KERN_DEBUG
"%s: association frame received from "
1941 "unknown AP (SA=%s BSSID=%s) - "
1942 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1943 print_mac(mac
, mgmt
->bssid
));
1947 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1948 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1949 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1951 printk(KERN_DEBUG
"%s: RX %sssocResp from %s (capab=0x%x "
1952 "status=%d aid=%d)\n",
1953 dev
->name
, reassoc
? "Rea" : "A", print_mac(mac
, mgmt
->sa
),
1954 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
1956 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1957 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1958 dev
->name
, status_code
);
1959 /* if this was a reassociation, ensure we try a "full"
1960 * association next time. This works around some broken APs
1961 * which do not correctly reject reassociation requests. */
1962 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
1966 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1967 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1968 "set\n", dev
->name
, aid
);
1969 aid
&= ~(BIT(15) | BIT(14));
1971 pos
= mgmt
->u
.assoc_resp
.variable
;
1972 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1974 if (!elems
.supp_rates
) {
1975 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1980 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1982 ifsta
->ap_capab
= capab_info
;
1984 kfree(ifsta
->assocresp_ies
);
1985 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1986 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_KERNEL
);
1987 if (ifsta
->assocresp_ies
)
1988 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1992 /* Add STA entry for the AP */
1993 sta
= sta_info_get(local
, ifsta
->bssid
);
1995 struct ieee80211_sta_bss
*bss
;
1998 sta
= sta_info_alloc(sdata
, ifsta
->bssid
, GFP_ATOMIC
);
2000 printk(KERN_DEBUG
"%s: failed to alloc STA entry for"
2001 " the AP\n", dev
->name
);
2005 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
2006 local
->hw
.conf
.channel
->center_freq
,
2007 ifsta
->ssid
, ifsta
->ssid_len
);
2009 sta
->last_rssi
= bss
->rssi
;
2010 sta
->last_signal
= bss
->signal
;
2011 sta
->last_noise
= bss
->noise
;
2012 ieee80211_rx_bss_put(dev
, bss
);
2015 err
= sta_info_insert(sta
);
2017 printk(KERN_DEBUG
"%s: failed to insert STA entry for"
2018 " the AP (error %d)\n", dev
->name
, err
);
2025 * FIXME: Do we really need to update the sta_info's information here?
2026 * We already know about the AP (we found it in our list) so it
2027 * should already be filled with the right info, no?
2028 * As is stands, all this is racy because typically we assume
2029 * the information that is filled in here (except flags) doesn't
2030 * change while a STA structure is alive. As such, it should move
2031 * to between the sta_info_alloc() and sta_info_insert() above.
2034 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
| WLAN_STA_ASSOC_AP
|
2035 WLAN_STA_AUTHORIZED
;
2039 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2041 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
2042 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
2045 have_higher_than_11mbit
= true;
2047 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2048 if (sband
->bitrates
[j
].bitrate
== rate
)
2050 if (elems
.supp_rates
[i
] & 0x80)
2051 basic_rates
|= BIT(j
);
2055 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
2056 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
2059 have_higher_than_11mbit
= true;
2061 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2062 if (sband
->bitrates
[j
].bitrate
== rate
)
2064 if (elems
.ext_supp_rates
[i
] & 0x80)
2065 basic_rates
|= BIT(j
);
2069 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] = rates
;
2070 sdata
->basic_rates
= basic_rates
;
2072 /* cf. IEEE 802.11 9.2.12 */
2073 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
2074 have_higher_than_11mbit
)
2075 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
2077 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
2079 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&& elems
.wmm_param
) {
2080 struct ieee80211_ht_bss_info bss_info
;
2081 ieee80211_ht_cap_ie_to_ht_info(
2082 (struct ieee80211_ht_cap
*)
2083 elems
.ht_cap_elem
, &sta
->ht_info
);
2084 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2085 (struct ieee80211_ht_addt_info
*)
2086 elems
.ht_info_elem
, &bss_info
);
2087 ieee80211_handle_ht(local
, 1, &sta
->ht_info
, &bss_info
);
2090 rate_control_rate_init(sta
, local
);
2092 if (elems
.wmm_param
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
2093 sta
->flags
|= WLAN_STA_WME
;
2095 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2096 elems
.wmm_param_len
);
2100 /* set AID and assoc capability,
2101 * ieee80211_set_associated() will tell the driver */
2102 bss_conf
->aid
= aid
;
2103 bss_conf
->assoc_capability
= capab_info
;
2104 ieee80211_set_associated(dev
, ifsta
, 1);
2106 ieee80211_associated(dev
, ifsta
);
2110 /* Caller must hold local->sta_bss_lock */
2111 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
2112 struct ieee80211_sta_bss
*bss
)
2114 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2117 if (bss_mesh_cfg(bss
))
2118 hash_idx
= mesh_id_hash(bss_mesh_id(bss
),
2119 bss_mesh_id_len(bss
));
2121 hash_idx
= STA_HASH(bss
->bssid
);
2123 bss
->hnext
= local
->sta_bss_hash
[hash_idx
];
2124 local
->sta_bss_hash
[hash_idx
] = bss
;
2128 /* Caller must hold local->sta_bss_lock */
2129 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
2130 struct ieee80211_sta_bss
*bss
)
2132 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2133 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
2134 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
2138 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
2141 prev
->hnext
= bss
->hnext
;
2150 static struct ieee80211_sta_bss
*
2151 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
, int freq
,
2152 u8
*ssid
, u8 ssid_len
)
2154 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2155 struct ieee80211_sta_bss
*bss
;
2157 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2160 atomic_inc(&bss
->users
);
2161 atomic_inc(&bss
->users
);
2162 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
2164 if (ssid
&& ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
2165 memcpy(bss
->ssid
, ssid
, ssid_len
);
2166 bss
->ssid_len
= ssid_len
;
2169 spin_lock_bh(&local
->sta_bss_lock
);
2170 /* TODO: order by RSSI? */
2171 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2172 __ieee80211_rx_bss_hash_add(dev
, bss
);
2173 spin_unlock_bh(&local
->sta_bss_lock
);
2177 static struct ieee80211_sta_bss
*
2178 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int freq
,
2179 u8
*ssid
, u8 ssid_len
)
2181 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2182 struct ieee80211_sta_bss
*bss
;
2184 spin_lock_bh(&local
->sta_bss_lock
);
2185 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
2187 if (!bss_mesh_cfg(bss
) &&
2188 !memcmp(bss
->bssid
, bssid
, ETH_ALEN
) &&
2189 bss
->freq
== freq
&&
2190 bss
->ssid_len
== ssid_len
&&
2191 (ssid_len
== 0 || !memcmp(bss
->ssid
, ssid
, ssid_len
))) {
2192 atomic_inc(&bss
->users
);
2197 spin_unlock_bh(&local
->sta_bss_lock
);
2201 #ifdef CONFIG_MAC80211_MESH
2202 static struct ieee80211_sta_bss
*
2203 ieee80211_rx_mesh_bss_get(struct net_device
*dev
, u8
*mesh_id
, int mesh_id_len
,
2204 u8
*mesh_cfg
, int freq
)
2206 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2207 struct ieee80211_sta_bss
*bss
;
2209 spin_lock_bh(&local
->sta_bss_lock
);
2210 bss
= local
->sta_bss_hash
[mesh_id_hash(mesh_id
, mesh_id_len
)];
2212 if (bss_mesh_cfg(bss
) &&
2213 !memcmp(bss_mesh_cfg(bss
), mesh_cfg
, MESH_CFG_CMP_LEN
) &&
2214 bss
->freq
== freq
&&
2215 mesh_id_len
== bss
->mesh_id_len
&&
2216 (mesh_id_len
== 0 || !memcmp(bss
->mesh_id
, mesh_id
,
2218 atomic_inc(&bss
->users
);
2223 spin_unlock_bh(&local
->sta_bss_lock
);
2227 static struct ieee80211_sta_bss
*
2228 ieee80211_rx_mesh_bss_add(struct net_device
*dev
, u8
*mesh_id
, int mesh_id_len
,
2229 u8
*mesh_cfg
, int mesh_config_len
, int freq
)
2231 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2232 struct ieee80211_sta_bss
*bss
;
2234 if (mesh_config_len
!= MESH_CFG_LEN
)
2237 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2241 bss
->mesh_cfg
= kmalloc(MESH_CFG_CMP_LEN
, GFP_ATOMIC
);
2242 if (!bss
->mesh_cfg
) {
2247 if (mesh_id_len
&& mesh_id_len
<= IEEE80211_MAX_MESH_ID_LEN
) {
2248 bss
->mesh_id
= kmalloc(mesh_id_len
, GFP_ATOMIC
);
2249 if (!bss
->mesh_id
) {
2250 kfree(bss
->mesh_cfg
);
2254 memcpy(bss
->mesh_id
, mesh_id
, mesh_id_len
);
2257 atomic_inc(&bss
->users
);
2258 atomic_inc(&bss
->users
);
2259 memcpy(bss
->mesh_cfg
, mesh_cfg
, MESH_CFG_CMP_LEN
);
2260 bss
->mesh_id_len
= mesh_id_len
;
2262 spin_lock_bh(&local
->sta_bss_lock
);
2263 /* TODO: order by RSSI? */
2264 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2265 __ieee80211_rx_bss_hash_add(dev
, bss
);
2266 spin_unlock_bh(&local
->sta_bss_lock
);
2271 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
2277 kfree(bss_mesh_id(bss
));
2278 kfree(bss_mesh_cfg(bss
));
2283 static void ieee80211_rx_bss_put(struct net_device
*dev
,
2284 struct ieee80211_sta_bss
*bss
)
2286 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2289 if (!atomic_dec_and_lock(&bss
->users
, &local
->sta_bss_lock
)) {
2294 __ieee80211_rx_bss_hash_del(dev
, bss
);
2295 list_del(&bss
->list
);
2296 spin_unlock_bh(&local
->sta_bss_lock
);
2297 ieee80211_rx_bss_free(bss
);
2301 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
2303 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2304 spin_lock_init(&local
->sta_bss_lock
);
2305 INIT_LIST_HEAD(&local
->sta_bss_list
);
2309 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
2311 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2312 struct ieee80211_sta_bss
*bss
, *tmp
;
2314 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
2315 ieee80211_rx_bss_put(dev
, bss
);
2319 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
2320 struct ieee80211_if_sta
*ifsta
,
2321 struct ieee80211_sta_bss
*bss
)
2323 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2324 int res
, rates
, i
, j
;
2325 struct sk_buff
*skb
;
2326 struct ieee80211_mgmt
*mgmt
;
2327 struct ieee80211_tx_control control
;
2328 struct rate_selection ratesel
;
2330 struct ieee80211_sub_if_data
*sdata
;
2331 struct ieee80211_supported_band
*sband
;
2333 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2335 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2337 /* Remove possible STA entries from other IBSS networks. */
2338 sta_info_flush_delayed(sdata
);
2340 if (local
->ops
->reset_tsf
) {
2341 /* Reset own TSF to allow time synchronization work. */
2342 local
->ops
->reset_tsf(local_to_hw(local
));
2344 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
2345 res
= ieee80211_if_config(dev
);
2349 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2351 sdata
->drop_unencrypted
= bss
->capability
&
2352 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
2354 res
= ieee80211_set_freq(local
, bss
->freq
);
2356 if (local
->oper_channel
->flags
& IEEE80211_CHAN_NO_IBSS
) {
2357 printk(KERN_DEBUG
"%s: IBSS not allowed on frequency "
2358 "%d MHz\n", dev
->name
, local
->oper_channel
->center_freq
);
2362 /* Set beacon template */
2363 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 400);
2368 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2370 mgmt
= (struct ieee80211_mgmt
*)
2371 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2372 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2373 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2374 IEEE80211_STYPE_BEACON
);
2375 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2376 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2377 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2378 mgmt
->u
.beacon
.beacon_int
=
2379 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2380 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2382 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2383 *pos
++ = WLAN_EID_SSID
;
2384 *pos
++ = ifsta
->ssid_len
;
2385 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2387 rates
= bss
->supp_rates_len
;
2390 pos
= skb_put(skb
, 2 + rates
);
2391 *pos
++ = WLAN_EID_SUPP_RATES
;
2393 memcpy(pos
, bss
->supp_rates
, rates
);
2395 if (bss
->band
== IEEE80211_BAND_2GHZ
) {
2396 pos
= skb_put(skb
, 2 + 1);
2397 *pos
++ = WLAN_EID_DS_PARAMS
;
2399 *pos
++ = ieee80211_frequency_to_channel(bss
->freq
);
2402 pos
= skb_put(skb
, 2 + 2);
2403 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2405 /* FIX: set ATIM window based on scan results */
2409 if (bss
->supp_rates_len
> 8) {
2410 rates
= bss
->supp_rates_len
- 8;
2411 pos
= skb_put(skb
, 2 + rates
);
2412 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2414 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2417 memset(&control
, 0, sizeof(control
));
2418 rate_control_get_rate(dev
, sband
, skb
, &ratesel
);
2419 if (!ratesel
.rate
) {
2420 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2421 "for IBSS beacon\n", dev
->name
);
2424 control
.vif
= &sdata
->vif
;
2425 control
.tx_rate
= ratesel
.rate
;
2426 if (sdata
->bss_conf
.use_short_preamble
&&
2427 ratesel
.rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
2428 control
.flags
|= IEEE80211_TXCTL_SHORT_PREAMBLE
;
2429 control
.antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
2430 control
.flags
|= IEEE80211_TXCTL_NO_ACK
;
2431 control
.retry_limit
= 1;
2433 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2434 if (ifsta
->probe_resp
) {
2435 mgmt
= (struct ieee80211_mgmt
*)
2436 ifsta
->probe_resp
->data
;
2437 mgmt
->frame_control
=
2438 IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2439 IEEE80211_STYPE_PROBE_RESP
);
2441 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2442 "template for IBSS\n", dev
->name
);
2445 if (local
->ops
->beacon_update
&&
2446 local
->ops
->beacon_update(local_to_hw(local
),
2447 skb
, &control
) == 0) {
2448 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2449 "template\n", dev
->name
);
2454 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2455 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2456 int bitrate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2457 for (j
= 0; j
< sband
->n_bitrates
; j
++)
2458 if (sband
->bitrates
[j
].bitrate
== bitrate
)
2461 ifsta
->supp_rates_bits
[local
->hw
.conf
.channel
->band
] = rates
;
2463 ieee80211_sta_def_wmm_params(dev
, bss
, 1);
2467 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2468 "template\n", dev
->name
);
2472 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2473 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2475 ieee80211_rx_bss_put(dev
, bss
);
2480 u64
ieee80211_sta_get_rates(struct ieee80211_local
*local
,
2481 struct ieee802_11_elems
*elems
,
2482 enum ieee80211_band band
)
2484 struct ieee80211_supported_band
*sband
;
2485 struct ieee80211_rate
*bitrates
;
2489 sband
= local
->hw
.wiphy
->bands
[band
];
2493 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2496 bitrates
= sband
->bitrates
;
2497 num_rates
= sband
->n_bitrates
;
2499 for (i
= 0; i
< elems
->supp_rates_len
+
2500 elems
->ext_supp_rates_len
; i
++) {
2503 if (i
< elems
->supp_rates_len
)
2504 rate
= elems
->supp_rates
[i
];
2505 else if (elems
->ext_supp_rates
)
2506 rate
= elems
->ext_supp_rates
2507 [i
- elems
->supp_rates_len
];
2508 own_rate
= 5 * (rate
& 0x7f);
2509 for (j
= 0; j
< num_rates
; j
++)
2510 if (bitrates
[j
].bitrate
== own_rate
)
2511 supp_rates
|= BIT(j
);
2517 static void ieee80211_rx_bss_info(struct net_device
*dev
,
2518 struct ieee80211_mgmt
*mgmt
,
2520 struct ieee80211_rx_status
*rx_status
,
2523 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2524 struct ieee802_11_elems elems
;
2527 struct ieee80211_sta_bss
*bss
;
2528 struct sta_info
*sta
;
2529 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2530 u64 beacon_timestamp
, rx_timestamp
;
2531 struct ieee80211_channel
*channel
;
2532 DECLARE_MAC_BUF(mac
);
2533 DECLARE_MAC_BUF(mac2
);
2535 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
2536 return; /* ignore ProbeResp to foreign address */
2539 printk(KERN_DEBUG
"%s: RX %s from %s to %s\n",
2540 dev
->name
, beacon
? "Beacon" : "Probe Response",
2541 print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
));
2544 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2548 beacon_timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
2549 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2551 if (ieee80211_vif_is_mesh(&sdata
->vif
) && elems
.mesh_id
&&
2552 elems
.mesh_config
&& mesh_matches_local(&elems
, dev
)) {
2553 u64 rates
= ieee80211_sta_get_rates(local
, &elems
,
2556 mesh_neighbour_update(mgmt
->sa
, rates
, dev
,
2557 mesh_peer_accepts_plinks(&elems
, dev
));
2562 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& elems
.supp_rates
&&
2563 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0 &&
2564 (sta
= sta_info_get(local
, mgmt
->sa
))) {
2566 u64 supp_rates
= ieee80211_sta_get_rates(local
, &elems
,
2569 prev_rates
= sta
->supp_rates
[rx_status
->band
];
2570 sta
->supp_rates
[rx_status
->band
] &= supp_rates
;
2571 if (sta
->supp_rates
[rx_status
->band
] == 0) {
2572 /* No matching rates - this should not really happen.
2573 * Make sure that at least one rate is marked
2574 * supported to avoid issues with TX rate ctrl. */
2575 sta
->supp_rates
[rx_status
->band
] =
2576 sdata
->u
.sta
.supp_rates_bits
[rx_status
->band
];
2578 if (sta
->supp_rates
[rx_status
->band
] != prev_rates
) {
2579 printk(KERN_DEBUG
"%s: updated supp_rates set for "
2580 "%s based on beacon info (0x%llx & 0x%llx -> "
2582 dev
->name
, print_mac(mac
, sta
->addr
),
2583 (unsigned long long) prev_rates
,
2584 (unsigned long long) supp_rates
,
2585 (unsigned long long) sta
->supp_rates
[rx_status
->band
]);
2591 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
2592 freq
= ieee80211_channel_to_frequency(elems
.ds_params
[0]);
2594 freq
= rx_status
->freq
;
2596 channel
= ieee80211_get_channel(local
->hw
.wiphy
, freq
);
2598 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
2601 #ifdef CONFIG_MAC80211_MESH
2602 if (elems
.mesh_config
)
2603 bss
= ieee80211_rx_mesh_bss_get(dev
, elems
.mesh_id
,
2604 elems
.mesh_id_len
, elems
.mesh_config
, freq
);
2607 bss
= ieee80211_rx_bss_get(dev
, mgmt
->bssid
, freq
,
2608 elems
.ssid
, elems
.ssid_len
);
2610 #ifdef CONFIG_MAC80211_MESH
2611 if (elems
.mesh_config
)
2612 bss
= ieee80211_rx_mesh_bss_add(dev
, elems
.mesh_id
,
2613 elems
.mesh_id_len
, elems
.mesh_config
,
2614 elems
.mesh_config_len
, freq
);
2617 bss
= ieee80211_rx_bss_add(dev
, mgmt
->bssid
, freq
,
2618 elems
.ssid
, elems
.ssid_len
);
2623 /* TODO: order by RSSI? */
2624 spin_lock_bh(&local
->sta_bss_lock
);
2625 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
2626 spin_unlock_bh(&local
->sta_bss_lock
);
2630 /* save the ERP value so that it is available at association time */
2631 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
2632 bss
->erp_value
= elems
.erp_info
[0];
2633 bss
->has_erp_value
= 1;
2636 if (elems
.ht_cap_elem
&&
2637 (!bss
->ht_ie
|| bss
->ht_ie_len
!= elems
.ht_cap_elem_len
||
2638 memcmp(bss
->ht_ie
, elems
.ht_cap_elem
, elems
.ht_cap_elem_len
))) {
2640 bss
->ht_ie
= kmalloc(elems
.ht_cap_elem_len
+ 2, GFP_ATOMIC
);
2642 memcpy(bss
->ht_ie
, elems
.ht_cap_elem
- 2,
2643 elems
.ht_cap_elem_len
+ 2);
2644 bss
->ht_ie_len
= elems
.ht_cap_elem_len
+ 2;
2647 } else if (!elems
.ht_cap_elem
&& bss
->ht_ie
) {
2653 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
2654 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2656 bss
->supp_rates_len
= 0;
2657 if (elems
.supp_rates
) {
2658 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2659 if (clen
> elems
.supp_rates_len
)
2660 clen
= elems
.supp_rates_len
;
2661 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
.supp_rates
,
2663 bss
->supp_rates_len
+= clen
;
2665 if (elems
.ext_supp_rates
) {
2666 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2667 if (clen
> elems
.ext_supp_rates_len
)
2668 clen
= elems
.ext_supp_rates_len
;
2669 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
2670 elems
.ext_supp_rates
, clen
);
2671 bss
->supp_rates_len
+= clen
;
2674 bss
->band
= rx_status
->band
;
2676 bss
->timestamp
= beacon_timestamp
;
2677 bss
->last_update
= jiffies
;
2678 bss
->rssi
= rx_status
->ssi
;
2679 bss
->signal
= rx_status
->signal
;
2680 bss
->noise
= rx_status
->noise
;
2681 if (!beacon
&& !bss
->probe_resp
)
2682 bss
->probe_resp
= true;
2685 * In STA mode, the remaining parameters should not be overridden
2686 * by beacons because they're not necessarily accurate there.
2688 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
2689 bss
->probe_resp
&& beacon
) {
2690 ieee80211_rx_bss_put(dev
, bss
);
2695 (!bss
->wpa_ie
|| bss
->wpa_ie_len
!= elems
.wpa_len
||
2696 memcmp(bss
->wpa_ie
, elems
.wpa
, elems
.wpa_len
))) {
2698 bss
->wpa_ie
= kmalloc(elems
.wpa_len
+ 2, GFP_ATOMIC
);
2700 memcpy(bss
->wpa_ie
, elems
.wpa
- 2, elems
.wpa_len
+ 2);
2701 bss
->wpa_ie_len
= elems
.wpa_len
+ 2;
2703 bss
->wpa_ie_len
= 0;
2704 } else if (!elems
.wpa
&& bss
->wpa_ie
) {
2707 bss
->wpa_ie_len
= 0;
2711 (!bss
->rsn_ie
|| bss
->rsn_ie_len
!= elems
.rsn_len
||
2712 memcmp(bss
->rsn_ie
, elems
.rsn
, elems
.rsn_len
))) {
2714 bss
->rsn_ie
= kmalloc(elems
.rsn_len
+ 2, GFP_ATOMIC
);
2716 memcpy(bss
->rsn_ie
, elems
.rsn
- 2, elems
.rsn_len
+ 2);
2717 bss
->rsn_ie_len
= elems
.rsn_len
+ 2;
2719 bss
->rsn_ie_len
= 0;
2720 } else if (!elems
.rsn
&& bss
->rsn_ie
) {
2723 bss
->rsn_ie_len
= 0;
2728 * http://www.wipo.int/pctdb/en/wo.jsp?wo=2007047181&IA=WO2007047181&DISPLAY=DESC
2732 * In particular, "Wi-Fi CERTIFIED for WMM - Support for Multimedia
2733 * Applications with Quality of Service in Wi-Fi Networks," Wi- Fi
2734 * Alliance (September 1, 2004) is incorporated by reference herein.
2735 * The inclusion of the WMM Parameters in probe responses and
2736 * association responses is mandatory for WMM enabled networks. The
2737 * inclusion of the WMM Parameters in beacons, however, is optional.
2740 if (elems
.wmm_param
&&
2741 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_param_len
||
2742 memcmp(bss
->wmm_ie
, elems
.wmm_param
, elems
.wmm_param_len
))) {
2744 bss
->wmm_ie
= kmalloc(elems
.wmm_param_len
+ 2, GFP_ATOMIC
);
2746 memcpy(bss
->wmm_ie
, elems
.wmm_param
- 2,
2747 elems
.wmm_param_len
+ 2);
2748 bss
->wmm_ie_len
= elems
.wmm_param_len
+ 2;
2750 bss
->wmm_ie_len
= 0;
2751 } else if (elems
.wmm_info
&&
2752 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_info_len
||
2753 memcmp(bss
->wmm_ie
, elems
.wmm_info
, elems
.wmm_info_len
))) {
2754 /* As for certain AP's Fifth bit is not set in WMM IE in
2755 * beacon frames.So while parsing the beacon frame the
2756 * wmm_info structure is used instead of wmm_param.
2757 * wmm_info structure was never used to set bss->wmm_ie.
2758 * This code fixes this problem by copying the WME
2759 * information from wmm_info to bss->wmm_ie and enabling
2760 * n-band association.
2763 bss
->wmm_ie
= kmalloc(elems
.wmm_info_len
+ 2, GFP_ATOMIC
);
2765 memcpy(bss
->wmm_ie
, elems
.wmm_info
- 2,
2766 elems
.wmm_info_len
+ 2);
2767 bss
->wmm_ie_len
= elems
.wmm_info_len
+ 2;
2769 bss
->wmm_ie_len
= 0;
2770 } else if (!elems
.wmm_param
&& !elems
.wmm_info
&& bss
->wmm_ie
) {
2773 bss
->wmm_ie_len
= 0;
2776 /* check if we need to merge IBSS */
2777 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
2778 !local
->sta_sw_scanning
&& !local
->sta_hw_scanning
&&
2779 bss
->capability
& WLAN_CAPABILITY_IBSS
&&
2780 bss
->freq
== local
->oper_channel
->center_freq
&&
2781 elems
.ssid_len
== sdata
->u
.sta
.ssid_len
&&
2782 memcmp(elems
.ssid
, sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
) == 0) {
2783 if (rx_status
->flag
& RX_FLAG_TSFT
) {
2784 /* in order for correct IBSS merging we need mactime
2786 * since mactime is defined as the time the first data
2787 * symbol of the frame hits the PHY, and the timestamp
2788 * of the beacon is defined as "the time that the data
2789 * symbol containing the first bit of the timestamp is
2790 * transmitted to the PHY plus the transmitting STA’s
2791 * delays through its local PHY from the MAC-PHY
2792 * interface to its interface with the WM"
2793 * (802.11 11.1.2) - equals the time this bit arrives at
2794 * the receiver - we have to take into account the
2795 * offset between the two.
2796 * e.g: at 1 MBit that means mactime is 192 usec earlier
2797 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2799 int rate
= local
->hw
.wiphy
->bands
[rx_status
->band
]->
2800 bitrates
[rx_status
->rate_idx
].bitrate
;
2801 rx_timestamp
= rx_status
->mactime
+ (24 * 8 * 10 / rate
);
2802 } else if (local
&& local
->ops
&& local
->ops
->get_tsf
)
2803 /* second best option: get current TSF */
2804 rx_timestamp
= local
->ops
->get_tsf(local_to_hw(local
));
2806 /* can't merge without knowing the TSF */
2807 rx_timestamp
= -1LLU;
2808 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2809 printk(KERN_DEBUG
"RX beacon SA=%s BSSID="
2810 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2811 print_mac(mac
, mgmt
->sa
),
2812 print_mac(mac2
, mgmt
->bssid
),
2813 (unsigned long long)rx_timestamp
,
2814 (unsigned long long)beacon_timestamp
,
2815 (unsigned long long)(rx_timestamp
- beacon_timestamp
),
2817 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2818 if (beacon_timestamp
> rx_timestamp
) {
2819 #ifndef CONFIG_MAC80211_IBSS_DEBUG
2820 if (net_ratelimit())
2822 printk(KERN_DEBUG
"%s: beacon TSF higher than "
2823 "local TSF - IBSS merge with BSSID %s\n",
2824 dev
->name
, print_mac(mac
, mgmt
->bssid
));
2825 ieee80211_sta_join_ibss(dev
, &sdata
->u
.sta
, bss
);
2826 ieee80211_ibss_add_sta(dev
, NULL
,
2827 mgmt
->bssid
, mgmt
->sa
);
2831 ieee80211_rx_bss_put(dev
, bss
);
2835 static void ieee80211_rx_mgmt_probe_resp(struct net_device
*dev
,
2836 struct ieee80211_mgmt
*mgmt
,
2838 struct ieee80211_rx_status
*rx_status
)
2840 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 0);
2844 static void ieee80211_rx_mgmt_beacon(struct net_device
*dev
,
2845 struct ieee80211_mgmt
*mgmt
,
2847 struct ieee80211_rx_status
*rx_status
)
2849 struct ieee80211_sub_if_data
*sdata
;
2850 struct ieee80211_if_sta
*ifsta
;
2852 struct ieee802_11_elems elems
;
2853 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2854 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
2857 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 1);
2859 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2860 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
2862 ifsta
= &sdata
->u
.sta
;
2864 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
) ||
2865 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
2868 /* Process beacon from the current BSS */
2869 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2873 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2875 if (elems
.wmm_param
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
2876 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2877 elems
.wmm_param_len
);
2880 /* Do not send changes to driver if we are scanning. This removes
2881 * requirement that driver's bss_info_changed function needs to be
2883 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
2886 if (elems
.erp_info
&& elems
.erp_info_len
>= 1)
2887 changed
|= ieee80211_handle_erp_ie(sdata
, elems
.erp_info
[0]);
2889 u16 capab
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2890 changed
|= ieee80211_handle_protect_preamb(sdata
, false,
2891 (capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
) != 0);
2894 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&&
2895 elems
.wmm_param
&& conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
2896 struct ieee80211_ht_bss_info bss_info
;
2898 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2899 (struct ieee80211_ht_addt_info
*)
2900 elems
.ht_info_elem
, &bss_info
);
2901 changed
|= ieee80211_handle_ht(local
, 1, &conf
->ht_conf
,
2905 ieee80211_bss_info_change_notify(sdata
, changed
);
2909 static void ieee80211_rx_mgmt_probe_req(struct net_device
*dev
,
2910 struct ieee80211_if_sta
*ifsta
,
2911 struct ieee80211_mgmt
*mgmt
,
2913 struct ieee80211_rx_status
*rx_status
)
2915 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2916 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2918 struct sk_buff
*skb
;
2919 struct ieee80211_mgmt
*resp
;
2921 DECLARE_MAC_BUF(mac
);
2922 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2923 DECLARE_MAC_BUF(mac2
);
2924 DECLARE_MAC_BUF(mac3
);
2927 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
||
2928 ifsta
->state
!= IEEE80211_IBSS_JOINED
||
2929 len
< 24 + 2 || !ifsta
->probe_resp
)
2932 if (local
->ops
->tx_last_beacon
)
2933 tx_last_beacon
= local
->ops
->tx_last_beacon(local_to_hw(local
));
2937 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2938 printk(KERN_DEBUG
"%s: RX ProbeReq SA=%s DA=%s BSSID="
2939 "%s (tx_last_beacon=%d)\n",
2940 dev
->name
, print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
),
2941 print_mac(mac3
, mgmt
->bssid
), tx_last_beacon
);
2942 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2944 if (!tx_last_beacon
)
2947 if (memcmp(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
) != 0 &&
2948 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
2951 end
= ((u8
*) mgmt
) + len
;
2952 pos
= mgmt
->u
.probe_req
.variable
;
2953 if (pos
[0] != WLAN_EID_SSID
||
2954 pos
+ 2 + pos
[1] > end
) {
2955 if (net_ratelimit()) {
2956 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
2958 dev
->name
, print_mac(mac
, mgmt
->sa
));
2963 (pos
[1] != ifsta
->ssid_len
||
2964 memcmp(pos
+ 2, ifsta
->ssid
, ifsta
->ssid_len
) != 0)) {
2965 /* Ignore ProbeReq for foreign SSID */
2969 /* Reply with ProbeResp */
2970 skb
= skb_copy(ifsta
->probe_resp
, GFP_KERNEL
);
2974 resp
= (struct ieee80211_mgmt
*) skb
->data
;
2975 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
2976 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2977 printk(KERN_DEBUG
"%s: Sending ProbeResp to %s\n",
2978 dev
->name
, print_mac(mac
, resp
->da
));
2979 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2980 ieee80211_sta_tx(dev
, skb
, 0);
2983 static void ieee80211_rx_mgmt_action(struct net_device
*dev
,
2984 struct ieee80211_if_sta
*ifsta
,
2985 struct ieee80211_mgmt
*mgmt
,
2987 struct ieee80211_rx_status
*rx_status
)
2989 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2991 if (len
< IEEE80211_MIN_ACTION_SIZE
)
2994 switch (mgmt
->u
.action
.category
) {
2995 case WLAN_CATEGORY_BACK
:
2996 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
2997 case WLAN_ACTION_ADDBA_REQ
:
2998 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2999 sizeof(mgmt
->u
.action
.u
.addba_req
)))
3001 ieee80211_sta_process_addba_request(dev
, mgmt
, len
);
3003 case WLAN_ACTION_ADDBA_RESP
:
3004 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3005 sizeof(mgmt
->u
.action
.u
.addba_resp
)))
3007 ieee80211_sta_process_addba_resp(dev
, mgmt
, len
);
3009 case WLAN_ACTION_DELBA
:
3010 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3011 sizeof(mgmt
->u
.action
.u
.delba
)))
3013 ieee80211_sta_process_delba(dev
, mgmt
, len
);
3016 if (net_ratelimit())
3017 printk(KERN_DEBUG
"%s: Rx unknown A-MPDU action\n",
3022 case PLINK_CATEGORY
:
3023 if (ieee80211_vif_is_mesh(&sdata
->vif
))
3024 mesh_rx_plink_frame(dev
, mgmt
, len
, rx_status
);
3026 case MESH_PATH_SEL_CATEGORY
:
3027 if (ieee80211_vif_is_mesh(&sdata
->vif
))
3028 mesh_rx_path_sel_frame(dev
, mgmt
, len
);
3031 if (net_ratelimit())
3032 printk(KERN_DEBUG
"%s: Rx unknown action frame - "
3033 "category=%d\n", dev
->name
, mgmt
->u
.action
.category
);
3038 void ieee80211_sta_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
3039 struct ieee80211_rx_status
*rx_status
)
3041 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3042 struct ieee80211_sub_if_data
*sdata
;
3043 struct ieee80211_if_sta
*ifsta
;
3044 struct ieee80211_mgmt
*mgmt
;
3050 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3051 ifsta
= &sdata
->u
.sta
;
3053 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3054 fc
= le16_to_cpu(mgmt
->frame_control
);
3056 switch (fc
& IEEE80211_FCTL_STYPE
) {
3057 case IEEE80211_STYPE_PROBE_REQ
:
3058 case IEEE80211_STYPE_PROBE_RESP
:
3059 case IEEE80211_STYPE_BEACON
:
3060 case IEEE80211_STYPE_ACTION
:
3061 memcpy(skb
->cb
, rx_status
, sizeof(*rx_status
));
3062 case IEEE80211_STYPE_AUTH
:
3063 case IEEE80211_STYPE_ASSOC_RESP
:
3064 case IEEE80211_STYPE_REASSOC_RESP
:
3065 case IEEE80211_STYPE_DEAUTH
:
3066 case IEEE80211_STYPE_DISASSOC
:
3067 skb_queue_tail(&ifsta
->skb_queue
, skb
);
3068 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3071 printk(KERN_DEBUG
"%s: received unknown management frame - "
3072 "stype=%d\n", dev
->name
,
3073 (fc
& IEEE80211_FCTL_STYPE
) >> 4);
3082 static void ieee80211_sta_rx_queued_mgmt(struct net_device
*dev
,
3083 struct sk_buff
*skb
)
3085 struct ieee80211_rx_status
*rx_status
;
3086 struct ieee80211_sub_if_data
*sdata
;
3087 struct ieee80211_if_sta
*ifsta
;
3088 struct ieee80211_mgmt
*mgmt
;
3091 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3092 ifsta
= &sdata
->u
.sta
;
3094 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
3095 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3096 fc
= le16_to_cpu(mgmt
->frame_control
);
3098 switch (fc
& IEEE80211_FCTL_STYPE
) {
3099 case IEEE80211_STYPE_PROBE_REQ
:
3100 ieee80211_rx_mgmt_probe_req(dev
, ifsta
, mgmt
, skb
->len
,
3103 case IEEE80211_STYPE_PROBE_RESP
:
3104 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
, skb
->len
, rx_status
);
3106 case IEEE80211_STYPE_BEACON
:
3107 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
, rx_status
);
3109 case IEEE80211_STYPE_AUTH
:
3110 ieee80211_rx_mgmt_auth(dev
, ifsta
, mgmt
, skb
->len
);
3112 case IEEE80211_STYPE_ASSOC_RESP
:
3113 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 0);
3115 case IEEE80211_STYPE_REASSOC_RESP
:
3116 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 1);
3118 case IEEE80211_STYPE_DEAUTH
:
3119 ieee80211_rx_mgmt_deauth(dev
, ifsta
, mgmt
, skb
->len
);
3121 case IEEE80211_STYPE_DISASSOC
:
3122 ieee80211_rx_mgmt_disassoc(dev
, ifsta
, mgmt
, skb
->len
);
3124 case IEEE80211_STYPE_ACTION
:
3125 ieee80211_rx_mgmt_action(dev
, ifsta
, mgmt
, skb
->len
, rx_status
);
3134 ieee80211_sta_rx_scan(struct net_device
*dev
, struct sk_buff
*skb
,
3135 struct ieee80211_rx_status
*rx_status
)
3137 struct ieee80211_mgmt
*mgmt
;
3141 return RX_DROP_UNUSABLE
;
3143 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3144 fc
= le16_to_cpu(mgmt
->frame_control
);
3146 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
)
3150 return RX_DROP_MONITOR
;
3152 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
3153 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
) {
3154 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
,
3155 skb
->len
, rx_status
);
3158 } else if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
) {
3159 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
,
3169 static int ieee80211_sta_active_ibss(struct net_device
*dev
)
3171 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3173 struct sta_info
*sta
;
3174 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3178 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
3179 if (sta
->sdata
== sdata
&&
3180 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
3193 static void ieee80211_sta_expire(struct net_device
*dev
, unsigned long exp_time
)
3195 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3196 struct sta_info
*sta
, *tmp
;
3197 LIST_HEAD(tmp_list
);
3198 DECLARE_MAC_BUF(mac
);
3199 unsigned long flags
;
3201 spin_lock_irqsave(&local
->sta_lock
, flags
);
3202 list_for_each_entry_safe(sta
, tmp
, &local
->sta_list
, list
)
3203 if (time_after(jiffies
, sta
->last_rx
+ exp_time
)) {
3204 printk(KERN_DEBUG
"%s: expiring inactive STA %s\n",
3205 dev
->name
, print_mac(mac
, sta
->addr
));
3206 __sta_info_unlink(&sta
);
3208 list_add(&sta
->list
, &tmp_list
);
3210 spin_unlock_irqrestore(&local
->sta_lock
, flags
);
3212 list_for_each_entry_safe(sta
, tmp
, &tmp_list
, list
)
3213 sta_info_destroy(sta
);
3217 static void ieee80211_sta_merge_ibss(struct net_device
*dev
,
3218 struct ieee80211_if_sta
*ifsta
)
3220 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
3222 ieee80211_sta_expire(dev
, IEEE80211_IBSS_INACTIVITY_LIMIT
);
3223 if (ieee80211_sta_active_ibss(dev
))
3226 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
3227 "IBSS networks with same SSID (merge)\n", dev
->name
);
3228 ieee80211_sta_req_scan(dev
, ifsta
->ssid
, ifsta
->ssid_len
);
3232 #ifdef CONFIG_MAC80211_MESH
3233 static void ieee80211_mesh_housekeeping(struct net_device
*dev
,
3234 struct ieee80211_if_sta
*ifsta
)
3236 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3239 ieee80211_sta_expire(dev
, IEEE80211_MESH_PEER_INACTIVITY_LIMIT
);
3240 mesh_path_expire(dev
);
3242 free_plinks
= mesh_plink_availables(sdata
);
3243 if (free_plinks
!= sdata
->u
.sta
.accepting_plinks
)
3244 ieee80211_if_config_beacon(dev
);
3246 mod_timer(&ifsta
->timer
, jiffies
+
3247 IEEE80211_MESH_HOUSEKEEPING_INTERVAL
);
3251 void ieee80211_start_mesh(struct net_device
*dev
)
3253 struct ieee80211_if_sta
*ifsta
;
3254 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3255 ifsta
= &sdata
->u
.sta
;
3256 ifsta
->state
= IEEE80211_MESH_UP
;
3257 ieee80211_sta_timer((unsigned long)sdata
);
3262 void ieee80211_sta_timer(unsigned long data
)
3264 struct ieee80211_sub_if_data
*sdata
=
3265 (struct ieee80211_sub_if_data
*) data
;
3266 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3267 struct ieee80211_local
*local
= wdev_priv(&sdata
->wdev
);
3269 set_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3270 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3273 void ieee80211_sta_work(struct work_struct
*work
)
3275 struct ieee80211_sub_if_data
*sdata
=
3276 container_of(work
, struct ieee80211_sub_if_data
, u
.sta
.work
);
3277 struct net_device
*dev
= sdata
->dev
;
3278 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3279 struct ieee80211_if_sta
*ifsta
;
3280 struct sk_buff
*skb
;
3282 if (!netif_running(dev
))
3285 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
3288 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
3289 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
3290 sdata
->vif
.type
!= IEEE80211_IF_TYPE_MESH_POINT
) {
3291 printk(KERN_DEBUG
"%s: ieee80211_sta_work: non-STA interface "
3292 "(type=%d)\n", dev
->name
, sdata
->vif
.type
);
3295 ifsta
= &sdata
->u
.sta
;
3297 while ((skb
= skb_dequeue(&ifsta
->skb_queue
)))
3298 ieee80211_sta_rx_queued_mgmt(dev
, skb
);
3300 #ifdef CONFIG_MAC80211_MESH
3301 if (ifsta
->preq_queue_len
&&
3303 ifsta
->last_preq
+ msecs_to_jiffies(ifsta
->mshcfg
.dot11MeshHWMPpreqMinInterval
)))
3304 mesh_path_start_discovery(dev
);
3307 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
3308 ifsta
->state
!= IEEE80211_ASSOCIATE
&&
3309 test_and_clear_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
)) {
3310 if (ifsta
->scan_ssid_len
)
3311 ieee80211_sta_start_scan(dev
, ifsta
->scan_ssid
, ifsta
->scan_ssid_len
);
3313 ieee80211_sta_start_scan(dev
, NULL
, 0);
3317 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
)) {
3318 if (ieee80211_sta_config_auth(dev
, ifsta
))
3320 clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3321 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
))
3324 switch (ifsta
->state
) {
3325 case IEEE80211_DISABLED
:
3327 case IEEE80211_AUTHENTICATE
:
3328 ieee80211_authenticate(dev
, ifsta
);
3330 case IEEE80211_ASSOCIATE
:
3331 ieee80211_associate(dev
, ifsta
);
3333 case IEEE80211_ASSOCIATED
:
3334 ieee80211_associated(dev
, ifsta
);
3336 case IEEE80211_IBSS_SEARCH
:
3337 ieee80211_sta_find_ibss(dev
, ifsta
);
3339 case IEEE80211_IBSS_JOINED
:
3340 ieee80211_sta_merge_ibss(dev
, ifsta
);
3342 #ifdef CONFIG_MAC80211_MESH
3343 case IEEE80211_MESH_UP
:
3344 ieee80211_mesh_housekeeping(dev
, ifsta
);
3348 printk(KERN_DEBUG
"ieee80211_sta_work: Unknown state %d\n",
3353 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
3354 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
3355 "mixed-cell disabled - disassociate\n", dev
->name
);
3357 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
3358 ieee80211_set_disassoc(dev
, ifsta
, 0);
3363 static void ieee80211_sta_reset_auth(struct net_device
*dev
,
3364 struct ieee80211_if_sta
*ifsta
)
3366 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3368 if (local
->ops
->reset_tsf
) {
3369 /* Reset own TSF to allow time synchronization work. */
3370 local
->ops
->reset_tsf(local_to_hw(local
));
3373 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
3376 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
3377 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3378 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
3379 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
3380 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
3381 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
3383 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3384 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
3386 ifsta
->auth_transaction
= -1;
3387 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
3388 ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
3389 netif_carrier_off(dev
);
3393 void ieee80211_sta_req_auth(struct net_device
*dev
,
3394 struct ieee80211_if_sta
*ifsta
)
3396 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3397 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3399 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3402 if ((ifsta
->flags
& (IEEE80211_STA_BSSID_SET
|
3403 IEEE80211_STA_AUTO_BSSID_SEL
)) &&
3404 (ifsta
->flags
& (IEEE80211_STA_SSID_SET
|
3405 IEEE80211_STA_AUTO_SSID_SEL
))) {
3406 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3407 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3411 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta
*ifsta
,
3412 const char *ssid
, int ssid_len
)
3414 int tmp
, hidden_ssid
;
3416 if (ssid_len
== ifsta
->ssid_len
&&
3417 !memcmp(ifsta
->ssid
, ssid
, ssid_len
))
3420 if (ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
)
3426 if (ssid
[tmp
] != '\0') {
3432 if (hidden_ssid
&& ifsta
->ssid_len
== ssid_len
)
3435 if (ssid_len
== 1 && ssid
[0] == ' ')
3441 static int ieee80211_sta_config_auth(struct net_device
*dev
,
3442 struct ieee80211_if_sta
*ifsta
)
3444 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3445 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3446 struct ieee80211_sta_bss
*bss
, *selected
= NULL
;
3447 int top_rssi
= 0, freq
;
3449 if (!(ifsta
->flags
& (IEEE80211_STA_AUTO_SSID_SEL
|
3450 IEEE80211_STA_AUTO_BSSID_SEL
| IEEE80211_STA_AUTO_CHANNEL_SEL
))) {
3451 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3452 ieee80211_sta_reset_auth(dev
, ifsta
);
3456 spin_lock_bh(&local
->sta_bss_lock
);
3457 freq
= local
->oper_channel
->center_freq
;
3458 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3459 if (!(bss
->capability
& WLAN_CAPABILITY_ESS
))
3462 if (!!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
) ^
3463 !!sdata
->default_key
)
3466 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_CHANNEL_SEL
) &&
3470 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
) &&
3471 memcmp(bss
->bssid
, ifsta
->bssid
, ETH_ALEN
))
3474 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
) &&
3475 !ieee80211_sta_match_ssid(ifsta
, bss
->ssid
, bss
->ssid_len
))
3478 if (!selected
|| top_rssi
< bss
->rssi
) {
3480 top_rssi
= bss
->rssi
;
3484 atomic_inc(&selected
->users
);
3485 spin_unlock_bh(&local
->sta_bss_lock
);
3488 ieee80211_set_freq(local
, selected
->freq
);
3489 if (!(ifsta
->flags
& IEEE80211_STA_SSID_SET
))
3490 ieee80211_sta_set_ssid(dev
, selected
->ssid
,
3491 selected
->ssid_len
);
3492 ieee80211_sta_set_bssid(dev
, selected
->bssid
);
3493 ieee80211_sta_def_wmm_params(dev
, selected
, 0);
3494 ieee80211_rx_bss_put(dev
, selected
);
3495 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3496 ieee80211_sta_reset_auth(dev
, ifsta
);
3499 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
) {
3500 if (ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
)
3501 ieee80211_sta_start_scan(dev
, NULL
, 0);
3503 ieee80211_sta_start_scan(dev
, ifsta
->ssid
,
3505 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3506 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3508 ifsta
->state
= IEEE80211_DISABLED
;
3514 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
3515 struct ieee80211_if_sta
*ifsta
)
3517 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3518 struct ieee80211_sta_bss
*bss
;
3519 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3520 struct ieee80211_supported_band
*sband
;
3521 u8 bssid
[ETH_ALEN
], *pos
;
3523 DECLARE_MAC_BUF(mac
);
3526 /* Easier testing, use fixed BSSID. */
3527 memset(bssid
, 0xfe, ETH_ALEN
);
3529 /* Generate random, not broadcast, locally administered BSSID. Mix in
3530 * own MAC address to make sure that devices that do not have proper
3531 * random number generator get different BSSID. */
3532 get_random_bytes(bssid
, ETH_ALEN
);
3533 for (i
= 0; i
< ETH_ALEN
; i
++)
3534 bssid
[i
] ^= dev
->dev_addr
[i
];
3539 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID %s\n",
3540 dev
->name
, print_mac(mac
, bssid
));
3542 bss
= ieee80211_rx_bss_add(dev
, bssid
,
3543 local
->hw
.conf
.channel
->center_freq
,
3544 sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
);
3548 bss
->band
= local
->hw
.conf
.channel
->band
;
3549 sband
= local
->hw
.wiphy
->bands
[bss
->band
];
3551 if (local
->hw
.conf
.beacon_int
== 0)
3552 local
->hw
.conf
.beacon_int
= 10000;
3553 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
3554 bss
->last_update
= jiffies
;
3555 bss
->capability
= WLAN_CAPABILITY_IBSS
;
3556 if (sdata
->default_key
) {
3557 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
3559 sdata
->drop_unencrypted
= 0;
3560 bss
->supp_rates_len
= sband
->n_bitrates
;
3561 pos
= bss
->supp_rates
;
3562 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
3563 int rate
= sband
->bitrates
[i
].bitrate
;
3564 *pos
++ = (u8
) (rate
/ 5);
3567 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3571 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
3572 struct ieee80211_if_sta
*ifsta
)
3574 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3575 struct ieee80211_sta_bss
*bss
;
3579 DECLARE_MAC_BUF(mac
);
3580 DECLARE_MAC_BUF(mac2
);
3582 if (ifsta
->ssid_len
== 0)
3585 active_ibss
= ieee80211_sta_active_ibss(dev
);
3586 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3587 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
3588 dev
->name
, active_ibss
);
3589 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3590 spin_lock_bh(&local
->sta_bss_lock
);
3591 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3592 if (ifsta
->ssid_len
!= bss
->ssid_len
||
3593 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
3594 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
3596 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3597 printk(KERN_DEBUG
" bssid=%s found\n",
3598 print_mac(mac
, bss
->bssid
));
3599 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3600 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
3602 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
3605 spin_unlock_bh(&local
->sta_bss_lock
);
3607 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3608 printk(KERN_DEBUG
" sta_find_ibss: selected %s current "
3609 "%s\n", print_mac(mac
, bssid
), print_mac(mac2
, ifsta
->bssid
));
3610 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3611 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
3612 (bss
= ieee80211_rx_bss_get(dev
, bssid
,
3613 local
->hw
.conf
.channel
->center_freq
,
3614 ifsta
->ssid
, ifsta
->ssid_len
))) {
3615 printk(KERN_DEBUG
"%s: Selected IBSS BSSID %s"
3616 " based on configured SSID\n",
3617 dev
->name
, print_mac(mac
, bssid
));
3618 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3620 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3621 printk(KERN_DEBUG
" did not try to join ibss\n");
3622 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3624 /* Selected IBSS not found in current scan results - try to scan */
3625 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3626 !ieee80211_sta_active_ibss(dev
)) {
3627 mod_timer(&ifsta
->timer
, jiffies
+
3628 IEEE80211_IBSS_MERGE_INTERVAL
);
3629 } else if (time_after(jiffies
, local
->last_scan_completed
+
3630 IEEE80211_SCAN_INTERVAL
)) {
3631 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
3632 "join\n", dev
->name
);
3633 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
3635 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
3636 int interval
= IEEE80211_SCAN_INTERVAL
;
3638 if (time_after(jiffies
, ifsta
->ibss_join_req
+
3639 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
3640 if ((ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) &&
3641 (!(local
->oper_channel
->flags
&
3642 IEEE80211_CHAN_NO_IBSS
)))
3643 return ieee80211_sta_create_ibss(dev
, ifsta
);
3644 if (ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) {
3645 printk(KERN_DEBUG
"%s: IBSS not allowed on"
3646 " %d MHz\n", dev
->name
,
3647 local
->hw
.conf
.channel
->center_freq
);
3650 /* No IBSS found - decrease scan interval and continue
3652 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
3655 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3656 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
3664 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
3666 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3667 struct ieee80211_if_sta
*ifsta
;
3669 if (len
> IEEE80211_MAX_SSID_LEN
)
3672 ifsta
= &sdata
->u
.sta
;
3674 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
3675 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
3676 memcpy(ifsta
->ssid
, ssid
, len
);
3677 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
3678 ifsta
->ssid_len
= len
;
3681 ifsta
->flags
|= IEEE80211_STA_SSID_SET
;
3683 ifsta
->flags
&= ~IEEE80211_STA_SSID_SET
;
3684 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3685 !(ifsta
->flags
& IEEE80211_STA_BSSID_SET
)) {
3686 ifsta
->ibss_join_req
= jiffies
;
3687 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3688 return ieee80211_sta_find_ibss(dev
, ifsta
);
3694 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
3696 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3697 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3698 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
3699 *len
= ifsta
->ssid_len
;
3704 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
3706 struct ieee80211_sub_if_data
*sdata
;
3707 struct ieee80211_if_sta
*ifsta
;
3710 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3711 ifsta
= &sdata
->u
.sta
;
3713 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
3714 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
3715 res
= ieee80211_if_config(dev
);
3717 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
3718 "the low-level driver\n", dev
->name
);
3723 if (is_valid_ether_addr(bssid
))
3724 ifsta
->flags
|= IEEE80211_STA_BSSID_SET
;
3726 ifsta
->flags
&= ~IEEE80211_STA_BSSID_SET
;
3732 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
3733 struct ieee80211_sub_if_data
*sdata
,
3736 struct sk_buff
*skb
;
3737 struct ieee80211_hdr
*nullfunc
;
3740 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
3742 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
3743 "frame\n", sdata
->dev
->name
);
3746 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3748 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
3749 memset(nullfunc
, 0, 24);
3750 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
3751 IEEE80211_FCTL_TODS
;
3753 fc
|= IEEE80211_FCTL_PM
;
3754 nullfunc
->frame_control
= cpu_to_le16(fc
);
3755 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3756 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
3757 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3759 ieee80211_sta_tx(sdata
->dev
, skb
, 0);
3763 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
3765 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
3766 ieee80211_vif_is_mesh(&sdata
->vif
))
3767 ieee80211_sta_timer((unsigned long)sdata
);
3770 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
3772 struct ieee80211_local
*local
= hw_to_local(hw
);
3773 struct net_device
*dev
= local
->scan_dev
;
3774 struct ieee80211_sub_if_data
*sdata
;
3775 union iwreq_data wrqu
;
3777 local
->last_scan_completed
= jiffies
;
3778 memset(&wrqu
, 0, sizeof(wrqu
));
3779 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
3781 if (local
->sta_hw_scanning
) {
3782 local
->sta_hw_scanning
= 0;
3783 if (ieee80211_hw_config(local
))
3784 printk(KERN_DEBUG
"%s: failed to restore operational "
3785 "channel after scan\n", dev
->name
);
3786 /* Restart STA timer for HW scan case */
3788 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
)
3789 ieee80211_restart_sta_timer(sdata
);
3795 local
->sta_sw_scanning
= 0;
3796 if (ieee80211_hw_config(local
))
3797 printk(KERN_DEBUG
"%s: failed to restore operational "
3798 "channel after scan\n", dev
->name
);
3801 netif_tx_lock_bh(local
->mdev
);
3802 local
->filter_flags
&= ~FIF_BCN_PRBRESP_PROMISC
;
3803 local
->ops
->configure_filter(local_to_hw(local
),
3804 FIF_BCN_PRBRESP_PROMISC
,
3805 &local
->filter_flags
,
3806 local
->mdev
->mc_count
,
3807 local
->mdev
->mc_list
);
3809 netif_tx_unlock_bh(local
->mdev
);
3812 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3814 /* No need to wake the master device. */
3815 if (sdata
->dev
== local
->mdev
)
3818 /* Tell AP we're back */
3819 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3820 sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
)
3821 ieee80211_send_nullfunc(local
, sdata
, 0);
3823 ieee80211_restart_sta_timer(sdata
);
3825 netif_wake_queue(sdata
->dev
);
3830 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3831 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
3832 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3833 if (!(ifsta
->flags
& IEEE80211_STA_BSSID_SET
) ||
3834 (!ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3835 !ieee80211_sta_active_ibss(dev
)))
3836 ieee80211_sta_find_ibss(dev
, ifsta
);
3839 EXPORT_SYMBOL(ieee80211_scan_completed
);
3841 void ieee80211_sta_scan_work(struct work_struct
*work
)
3843 struct ieee80211_local
*local
=
3844 container_of(work
, struct ieee80211_local
, scan_work
.work
);
3845 struct net_device
*dev
= local
->scan_dev
;
3846 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3847 struct ieee80211_supported_band
*sband
;
3848 struct ieee80211_channel
*chan
;
3850 unsigned long next_delay
= 0;
3852 if (!local
->sta_sw_scanning
)
3855 switch (local
->scan_state
) {
3856 case SCAN_SET_CHANNEL
:
3858 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3859 * after we successfully scanned the last channel of the last
3860 * band (and the last band is supported by the hw)
3862 if (local
->scan_band
< IEEE80211_NUM_BANDS
)
3863 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3868 * If we are at an unsupported band and have more bands
3869 * left to scan, advance to the next supported one.
3871 while (!sband
&& local
->scan_band
< IEEE80211_NUM_BANDS
- 1) {
3873 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3874 local
->scan_channel_idx
= 0;
3877 /* if no more bands/channels left, complete scan */
3878 if (!sband
|| local
->scan_channel_idx
>= sband
->n_channels
) {
3879 ieee80211_scan_completed(local_to_hw(local
));
3883 chan
= &sband
->channels
[local
->scan_channel_idx
];
3885 if (chan
->flags
& IEEE80211_CHAN_DISABLED
||
3886 (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3887 chan
->flags
& IEEE80211_CHAN_NO_IBSS
))
3891 local
->scan_channel
= chan
;
3892 if (ieee80211_hw_config(local
)) {
3893 printk(KERN_DEBUG
"%s: failed to set freq to "
3894 "%d MHz for scan\n", dev
->name
,
3900 /* advance state machine to next channel/band */
3901 local
->scan_channel_idx
++;
3902 if (local
->scan_channel_idx
>= sband
->n_channels
) {
3904 * scan_band may end up == IEEE80211_NUM_BANDS, but
3905 * we'll catch that case above and complete the scan
3906 * if that is the case.
3909 local
->scan_channel_idx
= 0;
3915 next_delay
= IEEE80211_PROBE_DELAY
+
3916 usecs_to_jiffies(local
->hw
.channel_change_time
);
3917 local
->scan_state
= SCAN_SEND_PROBE
;
3919 case SCAN_SEND_PROBE
:
3920 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
3921 local
->scan_state
= SCAN_SET_CHANNEL
;
3923 if (local
->scan_channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
3925 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
3926 local
->scan_ssid_len
);
3927 next_delay
= IEEE80211_CHANNEL_TIME
;
3931 if (local
->sta_sw_scanning
)
3932 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3937 static int ieee80211_sta_start_scan(struct net_device
*dev
,
3938 u8
*ssid
, size_t ssid_len
)
3940 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3941 struct ieee80211_sub_if_data
*sdata
;
3943 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
3946 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3947 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3950 * ScanType: ACTIVE, PASSIVE
3951 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3952 * a Probe frame during active scanning
3954 * MinChannelTime (>= ProbeDelay), in TU
3955 * MaxChannelTime: (>= MinChannelTime), in TU
3958 /* MLME-SCAN.confirm
3960 * ResultCode: SUCCESS, INVALID_PARAMETERS
3963 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3964 if (local
->scan_dev
== dev
)
3969 if (local
->ops
->hw_scan
) {
3970 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
3973 local
->sta_hw_scanning
= 1;
3974 local
->scan_dev
= dev
;
3979 local
->sta_sw_scanning
= 1;
3982 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3984 /* Don't stop the master interface, otherwise we can't transmit
3986 if (sdata
->dev
== local
->mdev
)
3989 netif_stop_queue(sdata
->dev
);
3990 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3991 (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
))
3992 ieee80211_send_nullfunc(local
, sdata
, 1);
3997 local
->scan_ssid_len
= ssid_len
;
3998 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
4000 local
->scan_ssid_len
= 0;
4001 local
->scan_state
= SCAN_SET_CHANNEL
;
4002 local
->scan_channel_idx
= 0;
4003 local
->scan_band
= IEEE80211_BAND_2GHZ
;
4004 local
->scan_dev
= dev
;
4006 netif_tx_lock_bh(local
->mdev
);
4007 local
->filter_flags
|= FIF_BCN_PRBRESP_PROMISC
;
4008 local
->ops
->configure_filter(local_to_hw(local
),
4009 FIF_BCN_PRBRESP_PROMISC
,
4010 &local
->filter_flags
,
4011 local
->mdev
->mc_count
,
4012 local
->mdev
->mc_list
);
4013 netif_tx_unlock_bh(local
->mdev
);
4015 /* TODO: start scan as soon as all nullfunc frames are ACKed */
4016 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
4017 IEEE80211_CHANNEL_TIME
);
4023 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
4025 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4026 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4027 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4029 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
4030 return ieee80211_sta_start_scan(dev
, ssid
, ssid_len
);
4032 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
4033 if (local
->scan_dev
== dev
)
4038 ifsta
->scan_ssid_len
= ssid_len
;
4040 memcpy(ifsta
->scan_ssid
, ssid
, ssid_len
);
4041 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
4042 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
4047 ieee80211_sta_scan_result(struct net_device
*dev
,
4048 struct ieee80211_sta_bss
*bss
,
4049 char *current_ev
, char *end_buf
)
4051 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4052 struct iw_event iwe
;
4054 if (time_after(jiffies
,
4055 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
4058 memset(&iwe
, 0, sizeof(iwe
));
4059 iwe
.cmd
= SIOCGIWAP
;
4060 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
4061 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
4062 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4065 memset(&iwe
, 0, sizeof(iwe
));
4066 iwe
.cmd
= SIOCGIWESSID
;
4067 if (bss_mesh_cfg(bss
)) {
4068 iwe
.u
.data
.length
= bss_mesh_id_len(bss
);
4069 iwe
.u
.data
.flags
= 1;
4070 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4073 iwe
.u
.data
.length
= bss
->ssid_len
;
4074 iwe
.u
.data
.flags
= 1;
4075 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4079 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
4080 || bss_mesh_cfg(bss
)) {
4081 memset(&iwe
, 0, sizeof(iwe
));
4082 iwe
.cmd
= SIOCGIWMODE
;
4083 if (bss_mesh_cfg(bss
))
4084 iwe
.u
.mode
= IW_MODE_MESH
;
4085 else if (bss
->capability
& WLAN_CAPABILITY_ESS
)
4086 iwe
.u
.mode
= IW_MODE_MASTER
;
4088 iwe
.u
.mode
= IW_MODE_ADHOC
;
4089 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4093 memset(&iwe
, 0, sizeof(iwe
));
4094 iwe
.cmd
= SIOCGIWFREQ
;
4095 iwe
.u
.freq
.m
= bss
->freq
;
4097 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4100 memset(&iwe
, 0, sizeof(iwe
));
4101 iwe
.cmd
= SIOCGIWFREQ
;
4102 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->freq
);
4104 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4107 memset(&iwe
, 0, sizeof(iwe
));
4109 iwe
.u
.qual
.qual
= bss
->signal
;
4110 iwe
.u
.qual
.level
= bss
->rssi
;
4111 iwe
.u
.qual
.noise
= bss
->noise
;
4112 iwe
.u
.qual
.updated
= local
->wstats_flags
;
4113 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4116 memset(&iwe
, 0, sizeof(iwe
));
4117 iwe
.cmd
= SIOCGIWENCODE
;
4118 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
4119 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
4121 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
4122 iwe
.u
.data
.length
= 0;
4123 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
4125 if (bss
&& bss
->wpa_ie
) {
4126 memset(&iwe
, 0, sizeof(iwe
));
4127 iwe
.cmd
= IWEVGENIE
;
4128 iwe
.u
.data
.length
= bss
->wpa_ie_len
;
4129 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4133 if (bss
&& bss
->rsn_ie
) {
4134 memset(&iwe
, 0, sizeof(iwe
));
4135 iwe
.cmd
= IWEVGENIE
;
4136 iwe
.u
.data
.length
= bss
->rsn_ie_len
;
4137 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4141 if (bss
&& bss
->supp_rates_len
> 0) {
4142 /* display all supported rates in readable format */
4143 char *p
= current_ev
+ IW_EV_LCP_LEN
;
4146 memset(&iwe
, 0, sizeof(iwe
));
4147 iwe
.cmd
= SIOCGIWRATE
;
4148 /* Those two flags are ignored... */
4149 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
4151 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
4152 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
4154 p
= iwe_stream_add_value(current_ev
, p
,
4155 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
4162 buf
= kmalloc(30, GFP_ATOMIC
);
4164 memset(&iwe
, 0, sizeof(iwe
));
4165 iwe
.cmd
= IWEVCUSTOM
;
4166 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
4167 iwe
.u
.data
.length
= strlen(buf
);
4168 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4174 if (bss_mesh_cfg(bss
)) {
4176 u8
*cfg
= bss_mesh_cfg(bss
);
4177 buf
= kmalloc(50, GFP_ATOMIC
);
4179 memset(&iwe
, 0, sizeof(iwe
));
4180 iwe
.cmd
= IWEVCUSTOM
;
4181 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
4182 iwe
.u
.data
.length
= strlen(buf
);
4183 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4185 sprintf(buf
, "Path Selection Protocol ID: "
4186 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
4188 iwe
.u
.data
.length
= strlen(buf
);
4189 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4191 sprintf(buf
, "Path Selection Metric ID: "
4192 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
4194 iwe
.u
.data
.length
= strlen(buf
);
4195 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4197 sprintf(buf
, "Congestion Control Mode ID: "
4198 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
4200 iwe
.u
.data
.length
= strlen(buf
);
4201 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4203 sprintf(buf
, "Channel Precedence: "
4204 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
4206 iwe
.u
.data
.length
= strlen(buf
);
4207 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4217 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
4219 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4220 char *current_ev
= buf
;
4221 char *end_buf
= buf
+ len
;
4222 struct ieee80211_sta_bss
*bss
;
4224 spin_lock_bh(&local
->sta_bss_lock
);
4225 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
4226 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
4227 spin_unlock_bh(&local
->sta_bss_lock
);
4230 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
4233 spin_unlock_bh(&local
->sta_bss_lock
);
4234 return current_ev
- buf
;
4238 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
4240 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4241 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4242 kfree(ifsta
->extra_ie
);
4244 ifsta
->extra_ie
= NULL
;
4245 ifsta
->extra_ie_len
= 0;
4248 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
4249 if (!ifsta
->extra_ie
) {
4250 ifsta
->extra_ie_len
= 0;
4253 memcpy(ifsta
->extra_ie
, ie
, len
);
4254 ifsta
->extra_ie_len
= len
;
4259 struct sta_info
* ieee80211_ibss_add_sta(struct net_device
*dev
,
4260 struct sk_buff
*skb
, u8
*bssid
,
4263 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4264 struct sta_info
*sta
;
4265 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4266 DECLARE_MAC_BUF(mac
);
4268 /* TODO: Could consider removing the least recently used entry and
4269 * allow new one to be added. */
4270 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
4271 if (net_ratelimit()) {
4272 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
4273 "entry %s\n", dev
->name
, print_mac(mac
, addr
));
4278 printk(KERN_DEBUG
"%s: Adding new IBSS station %s (dev=%s)\n",
4279 wiphy_name(local
->hw
.wiphy
), print_mac(mac
, addr
), dev
->name
);
4281 sta
= sta_info_alloc(sdata
, addr
, GFP_ATOMIC
);
4285 sta
->flags
|= WLAN_STA_AUTHORIZED
;
4287 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] =
4288 sdata
->u
.sta
.supp_rates_bits
[local
->hw
.conf
.channel
->band
];
4290 rate_control_rate_init(sta
, local
);
4292 if (sta_info_insert(sta
))
4299 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
4301 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4302 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4304 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
4307 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
4308 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
4311 ieee80211_send_deauth(dev
, ifsta
, reason
);
4312 ieee80211_set_disassoc(dev
, ifsta
, 1);
4317 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
4319 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4320 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4322 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
4325 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
4328 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
))
4331 ieee80211_send_disassoc(dev
, ifsta
, reason
);
4332 ieee80211_set_disassoc(dev
, ifsta
, 0);
4336 void ieee80211_notify_mac(struct ieee80211_hw
*hw
,
4337 enum ieee80211_notification_types notif_type
)
4339 struct ieee80211_local
*local
= hw_to_local(hw
);
4340 struct ieee80211_sub_if_data
*sdata
;
4342 switch (notif_type
) {
4343 case IEEE80211_NOTIFY_RE_ASSOC
:
4345 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4347 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
) {
4348 ieee80211_sta_req_auth(sdata
->dev
,
4357 EXPORT_SYMBOL(ieee80211_notify_mac
);