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_ASSOC_SCANS_MAX_TRIES 2
38 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
39 #define IEEE80211_AUTH_MAX_TRIES 3
40 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
41 #define IEEE80211_ASSOC_MAX_TRIES 3
42 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
43 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
44 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
45 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
46 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
47 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
48 #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
50 #define IEEE80211_PROBE_DELAY (HZ / 33)
51 #define IEEE80211_CHANNEL_TIME (HZ / 33)
52 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
53 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
54 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
55 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
56 #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
58 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
61 #define ERP_INFO_USE_PROTECTION BIT(1)
63 /* mgmt header + 1 byte category code */
64 #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
66 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
67 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
68 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
69 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
70 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
72 /* next values represent the buffer size for A-MPDU frame.
73 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
74 #define IEEE80211_MIN_AMPDU_BUF 0x8
75 #define IEEE80211_MAX_AMPDU_BUF 0x40
77 static void ieee80211_send_probe_req(struct ieee80211_sub_if_data
*sdata
, u8
*dst
,
78 u8
*ssid
, size_t ssid_len
);
79 static struct ieee80211_sta_bss
*
80 ieee80211_rx_bss_get(struct ieee80211_local
*local
, u8
*bssid
, int freq
,
81 u8
*ssid
, u8 ssid_len
);
82 static void ieee80211_rx_bss_put(struct ieee80211_local
*local
,
83 struct ieee80211_sta_bss
*bss
);
84 static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data
*sdata
,
85 struct ieee80211_if_sta
*ifsta
);
86 static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data
*sdata
);
87 static int ieee80211_sta_start_scan(struct ieee80211_sub_if_data
*sdata
,
88 u8
*ssid
, size_t ssid_len
);
89 static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data
*sdata
,
90 struct ieee80211_if_sta
*ifsta
);
91 static void sta_rx_agg_session_timer_expired(unsigned long data
);
94 void ieee802_11_parse_elems(u8
*start
, size_t len
,
95 struct ieee802_11_elems
*elems
)
100 memset(elems
, 0, sizeof(*elems
));
101 elems
->ie_start
= start
;
102 elems
->total_len
= len
;
117 elems
->ssid_len
= elen
;
119 case WLAN_EID_SUPP_RATES
:
120 elems
->supp_rates
= pos
;
121 elems
->supp_rates_len
= elen
;
123 case WLAN_EID_FH_PARAMS
:
124 elems
->fh_params
= pos
;
125 elems
->fh_params_len
= elen
;
127 case WLAN_EID_DS_PARAMS
:
128 elems
->ds_params
= pos
;
129 elems
->ds_params_len
= elen
;
131 case WLAN_EID_CF_PARAMS
:
132 elems
->cf_params
= pos
;
133 elems
->cf_params_len
= elen
;
137 elems
->tim_len
= elen
;
139 case WLAN_EID_IBSS_PARAMS
:
140 elems
->ibss_params
= pos
;
141 elems
->ibss_params_len
= elen
;
143 case WLAN_EID_CHALLENGE
:
144 elems
->challenge
= pos
;
145 elems
->challenge_len
= elen
;
148 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
150 /* Microsoft OUI (00:50:F2) */
152 /* OUI Type 1 - WPA IE */
154 elems
->wpa_len
= elen
;
155 } else if (elen
>= 5 && pos
[3] == 2) {
157 elems
->wmm_info
= pos
;
158 elems
->wmm_info_len
= elen
;
159 } else if (pos
[4] == 1) {
160 elems
->wmm_param
= pos
;
161 elems
->wmm_param_len
= elen
;
168 elems
->rsn_len
= elen
;
170 case WLAN_EID_ERP_INFO
:
171 elems
->erp_info
= pos
;
172 elems
->erp_info_len
= elen
;
174 case WLAN_EID_EXT_SUPP_RATES
:
175 elems
->ext_supp_rates
= pos
;
176 elems
->ext_supp_rates_len
= elen
;
178 case WLAN_EID_HT_CAPABILITY
:
179 elems
->ht_cap_elem
= pos
;
180 elems
->ht_cap_elem_len
= elen
;
182 case WLAN_EID_HT_EXTRA_INFO
:
183 elems
->ht_info_elem
= pos
;
184 elems
->ht_info_elem_len
= elen
;
186 case WLAN_EID_MESH_ID
:
187 elems
->mesh_id
= pos
;
188 elems
->mesh_id_len
= elen
;
190 case WLAN_EID_MESH_CONFIG
:
191 elems
->mesh_config
= pos
;
192 elems
->mesh_config_len
= elen
;
194 case WLAN_EID_PEER_LINK
:
195 elems
->peer_link
= pos
;
196 elems
->peer_link_len
= elen
;
200 elems
->preq_len
= elen
;
204 elems
->prep_len
= elen
;
208 elems
->perr_len
= elen
;
210 case WLAN_EID_CHANNEL_SWITCH
:
211 elems
->ch_switch_elem
= pos
;
212 elems
->ch_switch_elem_len
= elen
;
215 if (!elems
->quiet_elem
) {
216 elems
->quiet_elem
= pos
;
217 elems
->quiet_elem_len
= elen
;
219 elems
->num_of_quiet_elem
++;
221 case WLAN_EID_COUNTRY
:
222 elems
->country_elem
= pos
;
223 elems
->country_elem_len
= elen
;
225 case WLAN_EID_PWR_CONSTRAINT
:
226 elems
->pwr_constr_elem
= pos
;
227 elems
->pwr_constr_elem_len
= elen
;
239 static u8
* ieee80211_bss_get_ie(struct ieee80211_sta_bss
*bss
, u8 ie
)
246 end
= pos
+ bss
->ies_len
;
248 while (pos
+ 1 < end
) {
249 if (pos
+ 2 + pos
[1] > end
)
260 static int ecw2cw(int ecw
)
262 return (1 << ecw
) - 1;
266 static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data
*sdata
,
267 struct ieee80211_sta_bss
*bss
,
270 struct ieee80211_local
*local
= sdata
->local
;
271 int i
, have_higher_than_11mbit
= 0;
274 /* cf. IEEE 802.11 9.2.12 */
275 for (i
= 0; i
< bss
->supp_rates_len
; i
++)
276 if ((bss
->supp_rates
[i
] & 0x7f) * 5 > 110)
277 have_higher_than_11mbit
= 1;
279 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
280 have_higher_than_11mbit
)
281 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
283 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
286 if (local
->ops
->conf_tx
) {
287 struct ieee80211_tx_queue_params qparam
;
289 memset(&qparam
, 0, sizeof(qparam
));
293 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
294 !(sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
))
299 qparam
.cw_max
= 1023;
302 for (i
= 0; i
< local_to_hw(local
)->queues
; i
++)
303 local
->ops
->conf_tx(local_to_hw(local
), i
, &qparam
);
307 static void ieee80211_sta_wmm_params(struct ieee80211_local
*local
,
308 struct ieee80211_if_sta
*ifsta
,
309 u8
*wmm_param
, size_t wmm_param_len
)
311 struct ieee80211_tx_queue_params params
;
316 if (!(ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
))
322 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
324 count
= wmm_param
[6] & 0x0f;
325 if (count
== ifsta
->wmm_last_param_set
)
327 ifsta
->wmm_last_param_set
= count
;
330 left
= wmm_param_len
- 8;
332 memset(¶ms
, 0, sizeof(params
));
334 if (!local
->ops
->conf_tx
)
338 for (; left
>= 4; left
-= 4, pos
+= 4) {
339 int aci
= (pos
[0] >> 5) & 0x03;
340 int acm
= (pos
[0] >> 4) & 0x01;
347 local
->wmm_acm
|= BIT(0) | BIT(3);
352 local
->wmm_acm
|= BIT(4) | BIT(5);
357 local
->wmm_acm
|= BIT(6) | BIT(7);
363 local
->wmm_acm
|= BIT(1) | BIT(2);
367 params
.aifs
= pos
[0] & 0x0f;
368 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
369 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
370 params
.txop
= get_unaligned_le16(pos
+ 2);
371 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
372 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
373 "cWmin=%d cWmax=%d txop=%d\n",
374 local
->mdev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
375 params
.cw_max
, params
.txop
);
377 /* TODO: handle ACM (block TX, fallback to next lowest allowed
379 if (local
->ops
->conf_tx(local_to_hw(local
), queue
, ¶ms
)) {
380 printk(KERN_DEBUG
"%s: failed to set TX queue "
381 "parameters for queue %d\n", local
->mdev
->name
, queue
);
386 static u32
ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data
*sdata
,
388 bool use_short_preamble
)
390 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
391 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
392 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
393 DECLARE_MAC_BUF(mac
);
397 if (use_protection
!= bss_conf
->use_cts_prot
) {
398 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
399 if (net_ratelimit()) {
400 printk(KERN_DEBUG
"%s: CTS protection %s (BSSID="
403 use_protection
? "enabled" : "disabled",
404 print_mac(mac
, ifsta
->bssid
));
407 bss_conf
->use_cts_prot
= use_protection
;
408 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
411 if (use_short_preamble
!= bss_conf
->use_short_preamble
) {
412 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
413 if (net_ratelimit()) {
414 printk(KERN_DEBUG
"%s: switched to %s barker preamble"
417 use_short_preamble
? "short" : "long",
418 print_mac(mac
, ifsta
->bssid
));
421 bss_conf
->use_short_preamble
= use_short_preamble
;
422 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
428 static u32
ieee80211_handle_erp_ie(struct ieee80211_sub_if_data
*sdata
,
431 bool use_protection
= (erp_value
& WLAN_ERP_USE_PROTECTION
) != 0;
432 bool use_short_preamble
= (erp_value
& WLAN_ERP_BARKER_PREAMBLE
) == 0;
434 return ieee80211_handle_protect_preamb(sdata
,
435 use_protection
, use_short_preamble
);
438 static u32
ieee80211_handle_bss_capability(struct ieee80211_sub_if_data
*sdata
,
439 struct ieee80211_sta_bss
*bss
)
443 if (bss
->has_erp_value
)
444 changed
|= ieee80211_handle_erp_ie(sdata
, bss
->erp_value
);
446 u16 capab
= bss
->capability
;
447 changed
|= ieee80211_handle_protect_preamb(sdata
, false,
448 (capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
) != 0);
454 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap
*ht_cap_ie
,
455 struct ieee80211_ht_info
*ht_info
)
461 memset(ht_info
, 0, sizeof(*ht_info
));
464 u8 ampdu_info
= ht_cap_ie
->ampdu_params_info
;
466 ht_info
->ht_supported
= 1;
467 ht_info
->cap
= le16_to_cpu(ht_cap_ie
->cap_info
);
468 ht_info
->ampdu_factor
=
469 ampdu_info
& IEEE80211_HT_CAP_AMPDU_FACTOR
;
470 ht_info
->ampdu_density
=
471 (ampdu_info
& IEEE80211_HT_CAP_AMPDU_DENSITY
) >> 2;
472 memcpy(ht_info
->supp_mcs_set
, ht_cap_ie
->supp_mcs_set
, 16);
474 ht_info
->ht_supported
= 0;
479 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
480 struct ieee80211_ht_addt_info
*ht_add_info_ie
,
481 struct ieee80211_ht_bss_info
*bss_info
)
483 if (bss_info
== NULL
)
486 memset(bss_info
, 0, sizeof(*bss_info
));
488 if (ht_add_info_ie
) {
490 op_mode
= le16_to_cpu(ht_add_info_ie
->operation_mode
);
492 bss_info
->primary_channel
= ht_add_info_ie
->control_chan
;
493 bss_info
->bss_cap
= ht_add_info_ie
->ht_param
;
494 bss_info
->bss_op_mode
= (u8
)(op_mode
& 0xff);
500 static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data
*sdata
,
501 struct ieee80211_if_sta
*ifsta
)
503 union iwreq_data wrqu
;
505 if (ifsta
->assocreq_ies
) {
506 memset(&wrqu
, 0, sizeof(wrqu
));
507 wrqu
.data
.length
= ifsta
->assocreq_ies_len
;
508 wireless_send_event(sdata
->dev
, IWEVASSOCREQIE
, &wrqu
,
509 ifsta
->assocreq_ies
);
511 if (ifsta
->assocresp_ies
) {
512 memset(&wrqu
, 0, sizeof(wrqu
));
513 wrqu
.data
.length
= ifsta
->assocresp_ies_len
;
514 wireless_send_event(sdata
->dev
, IWEVASSOCRESPIE
, &wrqu
,
515 ifsta
->assocresp_ies
);
520 static void ieee80211_set_associated(struct ieee80211_sub_if_data
*sdata
,
521 struct ieee80211_if_sta
*ifsta
,
524 struct ieee80211_local
*local
= sdata
->local
;
525 struct ieee80211_conf
*conf
= &local_to_hw(local
)->conf
;
526 union iwreq_data wrqu
;
527 u32 changed
= BSS_CHANGED_ASSOC
;
530 struct ieee80211_sta_bss
*bss
;
532 ifsta
->flags
|= IEEE80211_STA_ASSOCIATED
;
534 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
537 bss
= ieee80211_rx_bss_get(local
, ifsta
->bssid
,
538 conf
->channel
->center_freq
,
539 ifsta
->ssid
, ifsta
->ssid_len
);
541 /* set timing information */
542 sdata
->bss_conf
.beacon_int
= bss
->beacon_int
;
543 sdata
->bss_conf
.timestamp
= bss
->timestamp
;
544 sdata
->bss_conf
.dtim_period
= bss
->dtim_period
;
546 changed
|= ieee80211_handle_bss_capability(sdata
, bss
);
548 ieee80211_rx_bss_put(local
, bss
);
551 if (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
552 changed
|= BSS_CHANGED_HT
;
553 sdata
->bss_conf
.assoc_ht
= 1;
554 sdata
->bss_conf
.ht_conf
= &conf
->ht_conf
;
555 sdata
->bss_conf
.ht_bss_conf
= &conf
->ht_bss_conf
;
558 ifsta
->flags
|= IEEE80211_STA_PREV_BSSID_SET
;
559 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
560 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
561 ieee80211_sta_send_associnfo(sdata
, ifsta
);
563 netif_carrier_off(sdata
->dev
);
564 ieee80211_sta_tear_down_BA_sessions(sdata
, ifsta
->bssid
);
565 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
566 changed
|= ieee80211_reset_erp_info(sdata
);
568 sdata
->bss_conf
.assoc_ht
= 0;
569 sdata
->bss_conf
.ht_conf
= NULL
;
570 sdata
->bss_conf
.ht_bss_conf
= NULL
;
572 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
574 ifsta
->last_probe
= jiffies
;
575 ieee80211_led_assoc(local
, assoc
);
577 sdata
->bss_conf
.assoc
= assoc
;
578 ieee80211_bss_info_change_notify(sdata
, changed
);
581 netif_carrier_on(sdata
->dev
);
583 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
584 wireless_send_event(sdata
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
587 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data
*sdata
,
588 struct ieee80211_if_sta
*ifsta
, int deauth
)
591 ifsta
->direct_probe_tries
= 0;
592 ifsta
->auth_tries
= 0;
594 ifsta
->assoc_scan_tries
= 0;
595 ifsta
->assoc_tries
= 0;
596 ieee80211_set_associated(sdata
, ifsta
, 0);
599 void ieee80211_sta_tx(struct ieee80211_sub_if_data
*sdata
, struct sk_buff
*skb
,
602 skb
->dev
= sdata
->local
->mdev
;
603 skb_set_mac_header(skb
, 0);
604 skb_set_network_header(skb
, 0);
605 skb_set_transport_header(skb
, 0);
607 skb
->iif
= sdata
->dev
->ifindex
;
608 skb
->do_not_encrypt
= !encrypt
;
614 static void ieee80211_send_auth(struct ieee80211_sub_if_data
*sdata
,
615 struct ieee80211_if_sta
*ifsta
,
616 int transaction
, u8
*extra
, size_t extra_len
,
619 struct ieee80211_local
*local
= sdata
->local
;
621 struct ieee80211_mgmt
*mgmt
;
623 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
624 sizeof(*mgmt
) + 6 + extra_len
);
626 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
627 "frame\n", sdata
->dev
->name
);
630 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
632 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
633 memset(mgmt
, 0, 24 + 6);
634 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
635 IEEE80211_STYPE_AUTH
);
637 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
638 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
639 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
640 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
641 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
642 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
643 ifsta
->auth_transaction
= transaction
+ 1;
644 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
646 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
648 ieee80211_sta_tx(sdata
, skb
, encrypt
);
651 static void ieee80211_direct_probe(struct ieee80211_sub_if_data
*sdata
,
652 struct ieee80211_if_sta
*ifsta
)
654 DECLARE_MAC_BUF(mac
);
656 ifsta
->direct_probe_tries
++;
657 if (ifsta
->direct_probe_tries
> IEEE80211_AUTH_MAX_TRIES
) {
658 printk(KERN_DEBUG
"%s: direct probe to AP %s timed out\n",
659 sdata
->dev
->name
, print_mac(mac
, ifsta
->bssid
));
660 ifsta
->state
= IEEE80211_STA_MLME_DISABLED
;
664 printk(KERN_DEBUG
"%s: direct probe to AP %s try %d\n",
665 sdata
->dev
->name
, print_mac(mac
, ifsta
->bssid
),
666 ifsta
->direct_probe_tries
);
668 ifsta
->state
= IEEE80211_STA_MLME_DIRECT_PROBE
;
670 set_bit(IEEE80211_STA_REQ_DIRECT_PROBE
, &ifsta
->request
);
672 /* Direct probe is sent to broadcast address as some APs
673 * will not answer to direct packet in unassociated state.
675 ieee80211_send_probe_req(sdata
, NULL
,
676 ifsta
->ssid
, ifsta
->ssid_len
);
678 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_AUTH_TIMEOUT
);
682 static void ieee80211_authenticate(struct ieee80211_sub_if_data
*sdata
,
683 struct ieee80211_if_sta
*ifsta
)
685 DECLARE_MAC_BUF(mac
);
688 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
689 printk(KERN_DEBUG
"%s: authentication with AP %s"
691 sdata
->dev
->name
, print_mac(mac
, ifsta
->bssid
));
692 ifsta
->state
= IEEE80211_STA_MLME_DISABLED
;
696 ifsta
->state
= IEEE80211_STA_MLME_AUTHENTICATE
;
697 printk(KERN_DEBUG
"%s: authenticate with AP %s\n",
698 sdata
->dev
->name
, print_mac(mac
, ifsta
->bssid
));
700 ieee80211_send_auth(sdata
, ifsta
, 1, NULL
, 0, 0);
702 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_AUTH_TIMEOUT
);
705 static int ieee80211_compatible_rates(struct ieee80211_sta_bss
*bss
,
706 struct ieee80211_supported_band
*sband
,
712 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
713 int rate
= (bss
->supp_rates
[i
] & 0x7F) * 5;
715 for (j
= 0; j
< sband
->n_bitrates
; j
++)
716 if (sband
->bitrates
[j
].bitrate
== rate
) {
726 static void ieee80211_send_assoc(struct ieee80211_sub_if_data
*sdata
,
727 struct ieee80211_if_sta
*ifsta
)
729 struct ieee80211_local
*local
= sdata
->local
;
731 struct ieee80211_mgmt
*mgmt
;
732 u8
*pos
, *ies
, *ht_add_ie
;
733 int i
, len
, count
, rates_len
, supp_rates_len
;
735 struct ieee80211_sta_bss
*bss
;
737 struct ieee80211_supported_band
*sband
;
740 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
741 sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
744 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
745 "frame\n", sdata
->dev
->name
);
748 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
750 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
752 capab
= ifsta
->capab
;
754 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
) {
755 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
756 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
757 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
758 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
761 bss
= ieee80211_rx_bss_get(local
, ifsta
->bssid
,
762 local
->hw
.conf
.channel
->center_freq
,
763 ifsta
->ssid
, ifsta
->ssid_len
);
765 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
766 capab
|= WLAN_CAPABILITY_PRIVACY
;
770 /* get all rates supported by the device and the AP as
771 * some APs don't like getting a superset of their rates
772 * in the association request (e.g. D-Link DAP 1353 in
774 rates_len
= ieee80211_compatible_rates(bss
, sband
, &rates
);
776 if ((bss
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
) &&
777 (local
->hw
.flags
& IEEE80211_HW_SPECTRUM_MGMT
))
778 capab
|= WLAN_CAPABILITY_SPECTRUM_MGMT
;
780 ieee80211_rx_bss_put(local
, bss
);
783 rates_len
= sband
->n_bitrates
;
786 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
788 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
789 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
790 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
792 if (ifsta
->flags
& IEEE80211_STA_PREV_BSSID_SET
) {
794 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
795 IEEE80211_STYPE_REASSOC_REQ
);
796 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
797 mgmt
->u
.reassoc_req
.listen_interval
=
798 cpu_to_le16(local
->hw
.conf
.listen_interval
);
799 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
803 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
804 IEEE80211_STYPE_ASSOC_REQ
);
805 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
806 mgmt
->u
.reassoc_req
.listen_interval
=
807 cpu_to_le16(local
->hw
.conf
.listen_interval
);
811 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
812 *pos
++ = WLAN_EID_SSID
;
813 *pos
++ = ifsta
->ssid_len
;
814 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
816 /* add all rates which were marked to be used above */
817 supp_rates_len
= rates_len
;
818 if (supp_rates_len
> 8)
821 len
= sband
->n_bitrates
;
822 pos
= skb_put(skb
, supp_rates_len
+ 2);
823 *pos
++ = WLAN_EID_SUPP_RATES
;
824 *pos
++ = supp_rates_len
;
827 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
828 if (BIT(i
) & rates
) {
829 int rate
= sband
->bitrates
[i
].bitrate
;
830 *pos
++ = (u8
) (rate
/ 5);
836 if (rates_len
> count
) {
837 pos
= skb_put(skb
, rates_len
- count
+ 2);
838 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
839 *pos
++ = rates_len
- count
;
841 for (i
++; i
< sband
->n_bitrates
; i
++) {
842 if (BIT(i
) & rates
) {
843 int rate
= sband
->bitrates
[i
].bitrate
;
844 *pos
++ = (u8
) (rate
/ 5);
849 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
) {
850 /* 1. power capabilities */
851 pos
= skb_put(skb
, 4);
852 *pos
++ = WLAN_EID_PWR_CAPABILITY
;
854 *pos
++ = 0; /* min tx power */
855 *pos
++ = local
->hw
.conf
.channel
->max_power
; /* max tx power */
857 /* 2. supported channels */
858 /* TODO: get this in reg domain format */
859 pos
= skb_put(skb
, 2 * sband
->n_channels
+ 2);
860 *pos
++ = WLAN_EID_SUPPORTED_CHANNELS
;
861 *pos
++ = 2 * sband
->n_channels
;
862 for (i
= 0; i
< sband
->n_channels
; i
++) {
863 *pos
++ = ieee80211_frequency_to_channel(
864 sband
->channels
[i
].center_freq
);
865 *pos
++ = 1; /* one channel in the subband*/
869 if (ifsta
->extra_ie
) {
870 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
871 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
874 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
875 pos
= skb_put(skb
, 9);
876 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
877 *pos
++ = 7; /* len */
878 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
881 *pos
++ = 2; /* WME */
882 *pos
++ = 0; /* WME info */
883 *pos
++ = 1; /* WME ver */
887 /* wmm support is a must to HT */
888 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
) &&
889 sband
->ht_info
.ht_supported
&&
890 (ht_add_ie
= ieee80211_bss_get_ie(bss
, WLAN_EID_HT_EXTRA_INFO
))) {
891 struct ieee80211_ht_addt_info
*ht_add_info
=
892 (struct ieee80211_ht_addt_info
*)ht_add_ie
;
893 u16 cap
= sband
->ht_info
.cap
;
895 u32 flags
= local
->hw
.conf
.channel
->flags
;
897 switch (ht_add_info
->ht_param
& IEEE80211_HT_IE_CHA_SEC_OFFSET
) {
898 case IEEE80211_HT_IE_CHA_SEC_ABOVE
:
899 if (flags
& IEEE80211_CHAN_NO_FAT_ABOVE
) {
900 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH
;
901 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
904 case IEEE80211_HT_IE_CHA_SEC_BELOW
:
905 if (flags
& IEEE80211_CHAN_NO_FAT_BELOW
) {
906 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH
;
907 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
912 tmp
= cpu_to_le16(cap
);
913 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
)+2);
914 *pos
++ = WLAN_EID_HT_CAPABILITY
;
915 *pos
++ = sizeof(struct ieee80211_ht_cap
);
916 memset(pos
, 0, sizeof(struct ieee80211_ht_cap
));
917 memcpy(pos
, &tmp
, sizeof(u16
));
919 /* TODO: needs a define here for << 2 */
920 *pos
++ = sband
->ht_info
.ampdu_factor
|
921 (sband
->ht_info
.ampdu_density
<< 2);
922 memcpy(pos
, sband
->ht_info
.supp_mcs_set
, 16);
925 kfree(ifsta
->assocreq_ies
);
926 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
927 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_KERNEL
);
928 if (ifsta
->assocreq_ies
)
929 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
931 ieee80211_sta_tx(sdata
, skb
, 0);
935 static void ieee80211_send_deauth(struct ieee80211_sub_if_data
*sdata
,
936 struct ieee80211_if_sta
*ifsta
, u16 reason
)
938 struct ieee80211_local
*local
= sdata
->local
;
940 struct ieee80211_mgmt
*mgmt
;
942 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
944 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
945 "frame\n", sdata
->dev
->name
);
948 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
950 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
952 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
953 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
954 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
955 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
956 IEEE80211_STYPE_DEAUTH
);
958 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
960 ieee80211_sta_tx(sdata
, skb
, 0);
964 static void ieee80211_send_disassoc(struct ieee80211_sub_if_data
*sdata
,
965 struct ieee80211_if_sta
*ifsta
, u16 reason
)
967 struct ieee80211_local
*local
= sdata
->local
;
969 struct ieee80211_mgmt
*mgmt
;
971 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
973 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
974 "frame\n", sdata
->dev
->name
);
977 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
979 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
981 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
982 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
983 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
984 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
985 IEEE80211_STYPE_DISASSOC
);
987 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
989 ieee80211_sta_tx(sdata
, skb
, 0);
993 static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data
*sdata
,
994 struct ieee80211_if_sta
*ifsta
)
996 struct ieee80211_local
*local
= sdata
->local
;
997 struct ieee80211_sta_bss
*bss
;
1000 int privacy_invoked
;
1002 if (!ifsta
|| (ifsta
->flags
& IEEE80211_STA_MIXED_CELL
))
1005 bss
= ieee80211_rx_bss_get(local
, ifsta
->bssid
,
1006 local
->hw
.conf
.channel
->center_freq
,
1007 ifsta
->ssid
, ifsta
->ssid_len
);
1011 bss_privacy
= !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
1012 wep_privacy
= !!ieee80211_sta_wep_configured(sdata
);
1013 privacy_invoked
= !!(ifsta
->flags
& IEEE80211_STA_PRIVACY_INVOKED
);
1015 ieee80211_rx_bss_put(local
, bss
);
1017 if ((bss_privacy
== wep_privacy
) || (bss_privacy
== privacy_invoked
))
1024 static void ieee80211_associate(struct ieee80211_sub_if_data
*sdata
,
1025 struct ieee80211_if_sta
*ifsta
)
1027 DECLARE_MAC_BUF(mac
);
1029 ifsta
->assoc_tries
++;
1030 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
1031 printk(KERN_DEBUG
"%s: association with AP %s"
1033 sdata
->dev
->name
, print_mac(mac
, ifsta
->bssid
));
1034 ifsta
->state
= IEEE80211_STA_MLME_DISABLED
;
1038 ifsta
->state
= IEEE80211_STA_MLME_ASSOCIATE
;
1039 printk(KERN_DEBUG
"%s: associate with AP %s\n",
1040 sdata
->dev
->name
, print_mac(mac
, ifsta
->bssid
));
1041 if (ieee80211_privacy_mismatch(sdata
, ifsta
)) {
1042 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
1043 "mixed-cell disabled - abort association\n", sdata
->dev
->name
);
1044 ifsta
->state
= IEEE80211_STA_MLME_DISABLED
;
1048 ieee80211_send_assoc(sdata
, ifsta
);
1050 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_ASSOC_TIMEOUT
);
1054 static void ieee80211_associated(struct ieee80211_sub_if_data
*sdata
,
1055 struct ieee80211_if_sta
*ifsta
)
1057 struct ieee80211_local
*local
= sdata
->local
;
1058 struct sta_info
*sta
;
1060 DECLARE_MAC_BUF(mac
);
1062 /* TODO: start monitoring current AP signal quality and number of
1063 * missed beacons. Scan other channels every now and then and search
1064 * for better APs. */
1065 /* TODO: remove expired BSSes */
1067 ifsta
->state
= IEEE80211_STA_MLME_ASSOCIATED
;
1071 sta
= sta_info_get(local
, ifsta
->bssid
);
1073 printk(KERN_DEBUG
"%s: No STA entry for own AP %s\n",
1074 sdata
->dev
->name
, print_mac(mac
, ifsta
->bssid
));
1078 if (time_after(jiffies
,
1079 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
1080 if (ifsta
->flags
& IEEE80211_STA_PROBEREQ_POLL
) {
1081 printk(KERN_DEBUG
"%s: No ProbeResp from "
1082 "current AP %s - assume out of "
1084 sdata
->dev
->name
, print_mac(mac
, ifsta
->bssid
));
1086 sta_info_unlink(&sta
);
1088 ieee80211_send_probe_req(sdata
, ifsta
->bssid
,
1090 local
->scan_ssid_len
);
1091 ifsta
->flags
^= IEEE80211_STA_PROBEREQ_POLL
;
1093 ifsta
->flags
&= ~IEEE80211_STA_PROBEREQ_POLL
;
1094 if (time_after(jiffies
, ifsta
->last_probe
+
1095 IEEE80211_PROBE_INTERVAL
)) {
1096 ifsta
->last_probe
= jiffies
;
1097 ieee80211_send_probe_req(sdata
, ifsta
->bssid
,
1106 if (disassoc
&& sta
)
1107 sta_info_destroy(sta
);
1110 ifsta
->state
= IEEE80211_STA_MLME_DISABLED
;
1111 ieee80211_set_associated(sdata
, ifsta
, 0);
1113 mod_timer(&ifsta
->timer
, jiffies
+
1114 IEEE80211_MONITORING_INTERVAL
);
1119 static void ieee80211_send_probe_req(struct ieee80211_sub_if_data
*sdata
, u8
*dst
,
1120 u8
*ssid
, size_t ssid_len
)
1122 struct ieee80211_local
*local
= sdata
->local
;
1123 struct ieee80211_supported_band
*sband
;
1124 struct sk_buff
*skb
;
1125 struct ieee80211_mgmt
*mgmt
;
1126 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
1129 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200);
1131 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
1132 "request\n", sdata
->dev
->name
);
1135 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1137 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1138 memset(mgmt
, 0, 24);
1139 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1140 IEEE80211_STYPE_PROBE_REQ
);
1141 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1143 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
1144 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
1146 memset(mgmt
->da
, 0xff, ETH_ALEN
);
1147 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
1149 pos
= skb_put(skb
, 2 + ssid_len
);
1150 *pos
++ = WLAN_EID_SSID
;
1152 memcpy(pos
, ssid
, ssid_len
);
1154 supp_rates
= skb_put(skb
, 2);
1155 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
1157 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
1159 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1160 struct ieee80211_rate
*rate
= &sband
->bitrates
[i
];
1162 pos
= skb_put(skb
, 1);
1164 } else if (supp_rates
[1] == 8) {
1165 esupp_rates
= skb_put(skb
, 3);
1166 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
1168 pos
= &esupp_rates
[2];
1170 pos
= skb_put(skb
, 1);
1173 *pos
= rate
->bitrate
/ 5;
1176 ieee80211_sta_tx(sdata
, skb
, 0);
1180 static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data
*sdata
)
1182 if (!sdata
|| !sdata
->default_key
||
1183 sdata
->default_key
->conf
.alg
!= ALG_WEP
)
1189 static void ieee80211_auth_completed(struct ieee80211_sub_if_data
*sdata
,
1190 struct ieee80211_if_sta
*ifsta
)
1192 printk(KERN_DEBUG
"%s: authenticated\n", sdata
->dev
->name
);
1193 ifsta
->flags
|= IEEE80211_STA_AUTHENTICATED
;
1194 ieee80211_associate(sdata
, ifsta
);
1198 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data
*sdata
,
1199 struct ieee80211_if_sta
*ifsta
,
1200 struct ieee80211_mgmt
*mgmt
,
1204 struct ieee802_11_elems elems
;
1206 pos
= mgmt
->u
.auth
.variable
;
1207 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1208 if (!elems
.challenge
)
1210 ieee80211_send_auth(sdata
, ifsta
, 3, elems
.challenge
- 2,
1211 elems
.challenge_len
+ 2, 1);
1214 static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data
*sdata
, u8
*da
, u16 tid
,
1215 u8 dialog_token
, u16 status
, u16 policy
,
1216 u16 buf_size
, u16 timeout
)
1218 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1219 struct ieee80211_local
*local
= sdata
->local
;
1220 struct sk_buff
*skb
;
1221 struct ieee80211_mgmt
*mgmt
;
1224 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
);
1227 printk(KERN_DEBUG
"%s: failed to allocate buffer "
1228 "for addba resp frame\n", sdata
->dev
->name
);
1232 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1233 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1234 memset(mgmt
, 0, 24);
1235 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1236 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1237 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1238 memcpy(mgmt
->bssid
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1240 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1241 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1242 IEEE80211_STYPE_ACTION
);
1244 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_resp
));
1245 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1246 mgmt
->u
.action
.u
.addba_resp
.action_code
= WLAN_ACTION_ADDBA_RESP
;
1247 mgmt
->u
.action
.u
.addba_resp
.dialog_token
= dialog_token
;
1249 capab
= (u16
)(policy
<< 1); /* bit 1 aggregation policy */
1250 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1251 capab
|= (u16
)(buf_size
<< 6); /* bit 15:6 max size of aggregation */
1253 mgmt
->u
.action
.u
.addba_resp
.capab
= cpu_to_le16(capab
);
1254 mgmt
->u
.action
.u
.addba_resp
.timeout
= cpu_to_le16(timeout
);
1255 mgmt
->u
.action
.u
.addba_resp
.status
= cpu_to_le16(status
);
1257 ieee80211_sta_tx(sdata
, skb
, 0);
1262 void ieee80211_send_addba_request(struct ieee80211_sub_if_data
*sdata
, const u8
*da
,
1263 u16 tid
, u8 dialog_token
, u16 start_seq_num
,
1264 u16 agg_size
, u16 timeout
)
1266 struct ieee80211_local
*local
= sdata
->local
;
1267 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1268 struct sk_buff
*skb
;
1269 struct ieee80211_mgmt
*mgmt
;
1272 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
);
1275 printk(KERN_ERR
"%s: failed to allocate buffer "
1276 "for addba request frame\n", sdata
->dev
->name
);
1279 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1280 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1281 memset(mgmt
, 0, 24);
1282 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1283 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1284 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1285 memcpy(mgmt
->bssid
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1287 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1289 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1290 IEEE80211_STYPE_ACTION
);
1292 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_req
));
1294 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1295 mgmt
->u
.action
.u
.addba_req
.action_code
= WLAN_ACTION_ADDBA_REQ
;
1297 mgmt
->u
.action
.u
.addba_req
.dialog_token
= dialog_token
;
1298 capab
= (u16
)(1 << 1); /* bit 1 aggregation policy */
1299 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1300 capab
|= (u16
)(agg_size
<< 6); /* bit 15:6 max size of aggergation */
1302 mgmt
->u
.action
.u
.addba_req
.capab
= cpu_to_le16(capab
);
1304 mgmt
->u
.action
.u
.addba_req
.timeout
= cpu_to_le16(timeout
);
1305 mgmt
->u
.action
.u
.addba_req
.start_seq_num
=
1306 cpu_to_le16(start_seq_num
<< 4);
1308 ieee80211_sta_tx(sdata
, skb
, 0);
1311 static void ieee80211_sta_process_addba_request(struct ieee80211_local
*local
,
1312 struct ieee80211_mgmt
*mgmt
,
1315 struct ieee80211_hw
*hw
= &local
->hw
;
1316 struct ieee80211_conf
*conf
= &hw
->conf
;
1317 struct sta_info
*sta
;
1318 struct tid_ampdu_rx
*tid_agg_rx
;
1319 u16 capab
, tid
, timeout
, ba_policy
, buf_size
, start_seq_num
, status
;
1321 int ret
= -EOPNOTSUPP
;
1322 DECLARE_MAC_BUF(mac
);
1326 sta
= sta_info_get(local
, mgmt
->sa
);
1332 /* extract session parameters from addba request frame */
1333 dialog_token
= mgmt
->u
.action
.u
.addba_req
.dialog_token
;
1334 timeout
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.timeout
);
1336 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.start_seq_num
) >> 4;
1338 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1339 ba_policy
= (capab
& IEEE80211_ADDBA_PARAM_POLICY_MASK
) >> 1;
1340 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1341 buf_size
= (capab
& IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
) >> 6;
1343 status
= WLAN_STATUS_REQUEST_DECLINED
;
1345 /* sanity check for incoming parameters:
1346 * check if configuration can support the BA policy
1347 * and if buffer size does not exceeds max value */
1348 if (((ba_policy
!= 1)
1349 && (!(conf
->ht_conf
.cap
& IEEE80211_HT_CAP_DELAY_BA
)))
1350 || (buf_size
> IEEE80211_MAX_AMPDU_BUF
)) {
1351 status
= WLAN_STATUS_INVALID_QOS_PARAM
;
1352 #ifdef CONFIG_MAC80211_HT_DEBUG
1353 if (net_ratelimit())
1354 printk(KERN_DEBUG
"AddBA Req with bad params from "
1355 "%s on tid %u. policy %d, buffer size %d\n",
1356 print_mac(mac
, mgmt
->sa
), tid
, ba_policy
,
1358 #endif /* CONFIG_MAC80211_HT_DEBUG */
1361 /* determine default buffer size */
1362 if (buf_size
== 0) {
1363 struct ieee80211_supported_band
*sband
;
1365 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
1366 buf_size
= IEEE80211_MIN_AMPDU_BUF
;
1367 buf_size
= buf_size
<< sband
->ht_info
.ampdu_factor
;
1371 /* examine state machine */
1372 spin_lock_bh(&sta
->lock
);
1374 if (sta
->ampdu_mlme
.tid_state_rx
[tid
] != HT_AGG_STATE_IDLE
) {
1375 #ifdef CONFIG_MAC80211_HT_DEBUG
1376 if (net_ratelimit())
1377 printk(KERN_DEBUG
"unexpected AddBA Req from "
1379 print_mac(mac
, mgmt
->sa
), tid
);
1380 #endif /* CONFIG_MAC80211_HT_DEBUG */
1384 /* prepare A-MPDU MLME for Rx aggregation */
1385 sta
->ampdu_mlme
.tid_rx
[tid
] =
1386 kmalloc(sizeof(struct tid_ampdu_rx
), GFP_ATOMIC
);
1387 if (!sta
->ampdu_mlme
.tid_rx
[tid
]) {
1388 #ifdef CONFIG_MAC80211_HT_DEBUG
1389 if (net_ratelimit())
1390 printk(KERN_ERR
"allocate rx mlme to tid %d failed\n",
1396 sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
.function
=
1397 sta_rx_agg_session_timer_expired
;
1398 sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
.data
=
1399 (unsigned long)&sta
->timer_to_tid
[tid
];
1400 init_timer(&sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
);
1402 tid_agg_rx
= sta
->ampdu_mlme
.tid_rx
[tid
];
1404 /* prepare reordering buffer */
1405 tid_agg_rx
->reorder_buf
=
1406 kmalloc(buf_size
* sizeof(struct sk_buff
*), GFP_ATOMIC
);
1407 if (!tid_agg_rx
->reorder_buf
) {
1408 #ifdef CONFIG_MAC80211_HT_DEBUG
1409 if (net_ratelimit())
1410 printk(KERN_ERR
"can not allocate reordering buffer "
1411 "to tid %d\n", tid
);
1413 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]);
1416 memset(tid_agg_rx
->reorder_buf
, 0,
1417 buf_size
* sizeof(struct sk_buff
*));
1419 if (local
->ops
->ampdu_action
)
1420 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_START
,
1421 sta
->addr
, tid
, &start_seq_num
);
1422 #ifdef CONFIG_MAC80211_HT_DEBUG
1423 printk(KERN_DEBUG
"Rx A-MPDU request on tid %d result %d\n", tid
, ret
);
1424 #endif /* CONFIG_MAC80211_HT_DEBUG */
1427 kfree(tid_agg_rx
->reorder_buf
);
1429 sta
->ampdu_mlme
.tid_rx
[tid
] = NULL
;
1433 /* change state and send addba resp */
1434 sta
->ampdu_mlme
.tid_state_rx
[tid
] = HT_AGG_STATE_OPERATIONAL
;
1435 tid_agg_rx
->dialog_token
= dialog_token
;
1436 tid_agg_rx
->ssn
= start_seq_num
;
1437 tid_agg_rx
->head_seq_num
= start_seq_num
;
1438 tid_agg_rx
->buf_size
= buf_size
;
1439 tid_agg_rx
->timeout
= timeout
;
1440 tid_agg_rx
->stored_mpdu_num
= 0;
1441 status
= WLAN_STATUS_SUCCESS
;
1443 spin_unlock_bh(&sta
->lock
);
1446 ieee80211_send_addba_resp(sta
->sdata
, sta
->addr
, tid
,
1447 dialog_token
, status
, 1, buf_size
, timeout
);
1451 static void ieee80211_sta_process_addba_resp(struct ieee80211_local
*local
,
1452 struct ieee80211_mgmt
*mgmt
,
1455 struct ieee80211_hw
*hw
= &local
->hw
;
1456 struct sta_info
*sta
;
1463 sta
= sta_info_get(local
, mgmt
->sa
);
1469 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.capab
);
1470 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1472 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
1474 spin_lock_bh(&sta
->lock
);
1476 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1477 spin_unlock_bh(&sta
->lock
);
1478 goto addba_resp_exit
;
1481 if (mgmt
->u
.action
.u
.addba_resp
.dialog_token
!=
1482 sta
->ampdu_mlme
.tid_tx
[tid
]->dialog_token
) {
1483 spin_unlock_bh(&sta
->lock
);
1484 #ifdef CONFIG_MAC80211_HT_DEBUG
1485 printk(KERN_DEBUG
"wrong addBA response token, tid %d\n", tid
);
1486 #endif /* CONFIG_MAC80211_HT_DEBUG */
1487 goto addba_resp_exit
;
1490 del_timer_sync(&sta
->ampdu_mlme
.tid_tx
[tid
]->addba_resp_timer
);
1491 #ifdef CONFIG_MAC80211_HT_DEBUG
1492 printk(KERN_DEBUG
"switched off addBA timer for tid %d \n", tid
);
1493 #endif /* CONFIG_MAC80211_HT_DEBUG */
1494 if (le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.status
)
1495 == WLAN_STATUS_SUCCESS
) {
1496 *state
|= HT_ADDBA_RECEIVED_MSK
;
1497 sta
->ampdu_mlme
.addba_req_num
[tid
] = 0;
1499 if (*state
== HT_AGG_STATE_OPERATIONAL
)
1500 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
1502 spin_unlock_bh(&sta
->lock
);
1504 sta
->ampdu_mlme
.addba_req_num
[tid
]++;
1505 /* this will allow the state check in stop_BA_session */
1506 *state
= HT_AGG_STATE_OPERATIONAL
;
1507 spin_unlock_bh(&sta
->lock
);
1508 ieee80211_stop_tx_ba_session(hw
, sta
->addr
, tid
,
1509 WLAN_BACK_INITIATOR
);
1516 void ieee80211_send_delba(struct ieee80211_sub_if_data
*sdata
, const u8
*da
, u16 tid
,
1517 u16 initiator
, u16 reason_code
)
1519 struct ieee80211_local
*local
= sdata
->local
;
1520 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1521 struct sk_buff
*skb
;
1522 struct ieee80211_mgmt
*mgmt
;
1525 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
);
1528 printk(KERN_ERR
"%s: failed to allocate buffer "
1529 "for delba frame\n", sdata
->dev
->name
);
1533 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1534 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1535 memset(mgmt
, 0, 24);
1536 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1537 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1538 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1539 memcpy(mgmt
->bssid
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1541 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1542 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1543 IEEE80211_STYPE_ACTION
);
1545 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.delba
));
1547 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1548 mgmt
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
1549 params
= (u16
)(initiator
<< 11); /* bit 11 initiator */
1550 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
1552 mgmt
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
1553 mgmt
->u
.action
.u
.delba
.reason_code
= cpu_to_le16(reason_code
);
1555 ieee80211_sta_tx(sdata
, skb
, 0);
1558 void ieee80211_send_bar(struct ieee80211_sub_if_data
*sdata
, u8
*ra
, u16 tid
, u16 ssn
)
1560 struct ieee80211_local
*local
= sdata
->local
;
1561 struct sk_buff
*skb
;
1562 struct ieee80211_bar
*bar
;
1563 u16 bar_control
= 0;
1565 skb
= dev_alloc_skb(sizeof(*bar
) + local
->hw
.extra_tx_headroom
);
1567 printk(KERN_ERR
"%s: failed to allocate buffer for "
1568 "bar frame\n", sdata
->dev
->name
);
1571 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1572 bar
= (struct ieee80211_bar
*)skb_put(skb
, sizeof(*bar
));
1573 memset(bar
, 0, sizeof(*bar
));
1574 bar
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_CTL
|
1575 IEEE80211_STYPE_BACK_REQ
);
1576 memcpy(bar
->ra
, ra
, ETH_ALEN
);
1577 memcpy(bar
->ta
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1578 bar_control
|= (u16
)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL
;
1579 bar_control
|= (u16
)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA
;
1580 bar_control
|= (u16
)(tid
<< 12);
1581 bar
->control
= cpu_to_le16(bar_control
);
1582 bar
->start_seq_num
= cpu_to_le16(ssn
);
1584 ieee80211_sta_tx(sdata
, skb
, 0);
1587 void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data
*sdata
, u8
*ra
, u16 tid
,
1588 u16 initiator
, u16 reason
)
1590 struct ieee80211_local
*local
= sdata
->local
;
1591 struct ieee80211_hw
*hw
= &local
->hw
;
1592 struct sta_info
*sta
;
1594 DECLARE_MAC_BUF(mac
);
1598 sta
= sta_info_get(local
, ra
);
1604 /* check if TID is in operational state */
1605 spin_lock_bh(&sta
->lock
);
1606 if (sta
->ampdu_mlme
.tid_state_rx
[tid
]
1607 != HT_AGG_STATE_OPERATIONAL
) {
1608 spin_unlock_bh(&sta
->lock
);
1612 sta
->ampdu_mlme
.tid_state_rx
[tid
] =
1613 HT_AGG_STATE_REQ_STOP_BA_MSK
|
1614 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
1615 spin_unlock_bh(&sta
->lock
);
1617 /* stop HW Rx aggregation. ampdu_action existence
1618 * already verified in session init so we add the BUG_ON */
1619 BUG_ON(!local
->ops
->ampdu_action
);
1621 #ifdef CONFIG_MAC80211_HT_DEBUG
1622 printk(KERN_DEBUG
"Rx BA session stop requested for %s tid %u\n",
1623 print_mac(mac
, ra
), tid
);
1624 #endif /* CONFIG_MAC80211_HT_DEBUG */
1626 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_STOP
,
1629 printk(KERN_DEBUG
"HW problem - can not stop rx "
1630 "aggregation for tid %d\n", tid
);
1632 /* shutdown timer has not expired */
1633 if (initiator
!= WLAN_BACK_TIMER
)
1634 del_timer_sync(&sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
);
1636 /* check if this is a self generated aggregation halt */
1637 if (initiator
== WLAN_BACK_RECIPIENT
|| initiator
== WLAN_BACK_TIMER
)
1638 ieee80211_send_delba(sdata
, ra
, tid
, 0, reason
);
1640 /* free the reordering buffer */
1641 for (i
= 0; i
< sta
->ampdu_mlme
.tid_rx
[tid
]->buf_size
; i
++) {
1642 if (sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
]) {
1643 /* release the reordered frames */
1644 dev_kfree_skb(sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
]);
1645 sta
->ampdu_mlme
.tid_rx
[tid
]->stored_mpdu_num
--;
1646 sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
] = NULL
;
1649 /* free resources */
1650 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
);
1651 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]);
1652 sta
->ampdu_mlme
.tid_rx
[tid
] = NULL
;
1653 sta
->ampdu_mlme
.tid_state_rx
[tid
] = HT_AGG_STATE_IDLE
;
1659 static void ieee80211_sta_process_delba(struct ieee80211_sub_if_data
*sdata
,
1660 struct ieee80211_mgmt
*mgmt
, size_t len
)
1662 struct ieee80211_local
*local
= sdata
->local
;
1663 struct sta_info
*sta
;
1666 DECLARE_MAC_BUF(mac
);
1670 sta
= sta_info_get(local
, mgmt
->sa
);
1676 params
= le16_to_cpu(mgmt
->u
.action
.u
.delba
.params
);
1677 tid
= (params
& IEEE80211_DELBA_PARAM_TID_MASK
) >> 12;
1678 initiator
= (params
& IEEE80211_DELBA_PARAM_INITIATOR_MASK
) >> 11;
1680 #ifdef CONFIG_MAC80211_HT_DEBUG
1681 if (net_ratelimit())
1682 printk(KERN_DEBUG
"delba from %s (%s) tid %d reason code %d\n",
1683 print_mac(mac
, mgmt
->sa
),
1684 initiator
? "initiator" : "recipient", tid
,
1685 mgmt
->u
.action
.u
.delba
.reason_code
);
1686 #endif /* CONFIG_MAC80211_HT_DEBUG */
1688 if (initiator
== WLAN_BACK_INITIATOR
)
1689 ieee80211_sta_stop_rx_ba_session(sdata
, sta
->addr
, tid
,
1690 WLAN_BACK_INITIATOR
, 0);
1691 else { /* WLAN_BACK_RECIPIENT */
1692 spin_lock_bh(&sta
->lock
);
1693 sta
->ampdu_mlme
.tid_state_tx
[tid
] =
1694 HT_AGG_STATE_OPERATIONAL
;
1695 spin_unlock_bh(&sta
->lock
);
1696 ieee80211_stop_tx_ba_session(&local
->hw
, sta
->addr
, tid
,
1697 WLAN_BACK_RECIPIENT
);
1703 * After sending add Block Ack request we activated a timer until
1704 * add Block Ack response will arrive from the recipient.
1705 * If this timer expires sta_addba_resp_timer_expired will be executed.
1707 void sta_addba_resp_timer_expired(unsigned long data
)
1709 /* not an elegant detour, but there is no choice as the timer passes
1710 * only one argument, and both sta_info and TID are needed, so init
1711 * flow in sta_info_create gives the TID as data, while the timer_to_id
1712 * array gives the sta through container_of */
1713 u16 tid
= *(u8
*)data
;
1714 struct sta_info
*temp_sta
= container_of((void *)data
,
1715 struct sta_info
, timer_to_tid
[tid
]);
1717 struct ieee80211_local
*local
= temp_sta
->local
;
1718 struct ieee80211_hw
*hw
= &local
->hw
;
1719 struct sta_info
*sta
;
1724 sta
= sta_info_get(local
, temp_sta
->addr
);
1730 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
1731 /* check if the TID waits for addBA response */
1732 spin_lock_bh(&sta
->lock
);
1733 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1734 spin_unlock_bh(&sta
->lock
);
1735 *state
= HT_AGG_STATE_IDLE
;
1736 #ifdef CONFIG_MAC80211_HT_DEBUG
1737 printk(KERN_DEBUG
"timer expired on tid %d but we are not "
1738 "expecting addBA response there", tid
);
1740 goto timer_expired_exit
;
1743 #ifdef CONFIG_MAC80211_HT_DEBUG
1744 printk(KERN_DEBUG
"addBA response timer expired on tid %d\n", tid
);
1747 /* go through the state check in stop_BA_session */
1748 *state
= HT_AGG_STATE_OPERATIONAL
;
1749 spin_unlock_bh(&sta
->lock
);
1750 ieee80211_stop_tx_ba_session(hw
, temp_sta
->addr
, tid
,
1751 WLAN_BACK_INITIATOR
);
1758 * After accepting the AddBA Request we activated a timer,
1759 * resetting it after each frame that arrives from the originator.
1760 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1762 static void sta_rx_agg_session_timer_expired(unsigned long data
)
1764 /* not an elegant detour, but there is no choice as the timer passes
1765 * only one argument, and various sta_info are needed here, so init
1766 * flow in sta_info_create gives the TID as data, while the timer_to_id
1767 * array gives the sta through container_of */
1768 u8
*ptid
= (u8
*)data
;
1769 u8
*timer_to_id
= ptid
- *ptid
;
1770 struct sta_info
*sta
= container_of(timer_to_id
, struct sta_info
,
1773 #ifdef CONFIG_MAC80211_HT_DEBUG
1774 printk(KERN_DEBUG
"rx session timer expired on tid %d\n", (u16
)*ptid
);
1776 ieee80211_sta_stop_rx_ba_session(sta
->sdata
, sta
->addr
,
1777 (u16
)*ptid
, WLAN_BACK_TIMER
,
1778 WLAN_REASON_QSTA_TIMEOUT
);
1781 void ieee80211_sta_tear_down_BA_sessions(struct ieee80211_sub_if_data
*sdata
, u8
*addr
)
1783 struct ieee80211_local
*local
= sdata
->local
;
1786 for (i
= 0; i
< STA_TID_NUM
; i
++) {
1787 ieee80211_stop_tx_ba_session(&local
->hw
, addr
, i
,
1788 WLAN_BACK_INITIATOR
);
1789 ieee80211_sta_stop_rx_ba_session(sdata
, addr
, i
,
1790 WLAN_BACK_RECIPIENT
,
1791 WLAN_REASON_QSTA_LEAVE_QBSS
);
1795 static void ieee80211_send_refuse_measurement_request(struct ieee80211_sub_if_data
*sdata
,
1796 struct ieee80211_msrment_ie
*request_ie
,
1797 const u8
*da
, const u8
*bssid
,
1800 struct ieee80211_local
*local
= sdata
->local
;
1801 struct sk_buff
*skb
;
1802 struct ieee80211_mgmt
*msr_report
;
1804 skb
= dev_alloc_skb(sizeof(*msr_report
) + local
->hw
.extra_tx_headroom
+
1805 sizeof(struct ieee80211_msrment_ie
));
1808 printk(KERN_ERR
"%s: failed to allocate buffer for "
1809 "measurement report frame\n", sdata
->dev
->name
);
1813 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1814 msr_report
= (struct ieee80211_mgmt
*)skb_put(skb
, 24);
1815 memset(msr_report
, 0, 24);
1816 memcpy(msr_report
->da
, da
, ETH_ALEN
);
1817 memcpy(msr_report
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
1818 memcpy(msr_report
->bssid
, bssid
, ETH_ALEN
);
1819 msr_report
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1820 IEEE80211_STYPE_ACTION
);
1822 skb_put(skb
, 1 + sizeof(msr_report
->u
.action
.u
.measurement
));
1823 msr_report
->u
.action
.category
= WLAN_CATEGORY_SPECTRUM_MGMT
;
1824 msr_report
->u
.action
.u
.measurement
.action_code
=
1825 WLAN_ACTION_SPCT_MSR_RPRT
;
1826 msr_report
->u
.action
.u
.measurement
.dialog_token
= dialog_token
;
1828 msr_report
->u
.action
.u
.measurement
.element_id
= WLAN_EID_MEASURE_REPORT
;
1829 msr_report
->u
.action
.u
.measurement
.length
=
1830 sizeof(struct ieee80211_msrment_ie
);
1832 memset(&msr_report
->u
.action
.u
.measurement
.msr_elem
, 0,
1833 sizeof(struct ieee80211_msrment_ie
));
1834 msr_report
->u
.action
.u
.measurement
.msr_elem
.token
= request_ie
->token
;
1835 msr_report
->u
.action
.u
.measurement
.msr_elem
.mode
|=
1836 IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED
;
1837 msr_report
->u
.action
.u
.measurement
.msr_elem
.type
= request_ie
->type
;
1839 ieee80211_sta_tx(sdata
, skb
, 0);
1842 static void ieee80211_sta_process_measurement_req(struct ieee80211_sub_if_data
*sdata
,
1843 struct ieee80211_mgmt
*mgmt
,
1847 * Ignoring measurement request is spec violation.
1848 * Mandatory measurements must be reported optional
1849 * measurements might be refused or reported incapable
1850 * For now just refuse
1851 * TODO: Answer basic measurement as unmeasured
1853 ieee80211_send_refuse_measurement_request(sdata
,
1854 &mgmt
->u
.action
.u
.measurement
.msr_elem
,
1855 mgmt
->sa
, mgmt
->bssid
,
1856 mgmt
->u
.action
.u
.measurement
.dialog_token
);
1860 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data
*sdata
,
1861 struct ieee80211_if_sta
*ifsta
,
1862 struct ieee80211_mgmt
*mgmt
,
1865 u16 auth_alg
, auth_transaction
, status_code
;
1866 DECLARE_MAC_BUF(mac
);
1868 if (ifsta
->state
!= IEEE80211_STA_MLME_AUTHENTICATE
&&
1869 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
1875 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1876 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0)
1879 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1880 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
1883 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
1884 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
1885 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
1887 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
1889 * IEEE 802.11 standard does not require authentication in IBSS
1890 * networks and most implementations do not seem to use it.
1891 * However, try to reply to authentication attempts if someone
1892 * has actually implemented this.
1894 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1)
1896 ieee80211_send_auth(sdata
, ifsta
, 2, NULL
, 0, 0);
1899 if (auth_alg
!= ifsta
->auth_alg
||
1900 auth_transaction
!= ifsta
->auth_transaction
)
1903 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1904 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
1906 const int num_algs
= ARRAY_SIZE(algs
);
1908 algs
[0] = algs
[1] = algs
[2] = 0xff;
1909 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1910 algs
[0] = WLAN_AUTH_OPEN
;
1911 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1912 algs
[1] = WLAN_AUTH_SHARED_KEY
;
1913 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1914 algs
[2] = WLAN_AUTH_LEAP
;
1915 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
1917 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
1921 for (i
= 0; i
< num_algs
; i
++) {
1923 if (pos
>= num_algs
)
1925 if (algs
[pos
] == ifsta
->auth_alg
||
1928 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
1929 !ieee80211_sta_wep_configured(sdata
))
1931 ifsta
->auth_alg
= algs
[pos
];
1938 switch (ifsta
->auth_alg
) {
1939 case WLAN_AUTH_OPEN
:
1940 case WLAN_AUTH_LEAP
:
1941 ieee80211_auth_completed(sdata
, ifsta
);
1943 case WLAN_AUTH_SHARED_KEY
:
1944 if (ifsta
->auth_transaction
== 4)
1945 ieee80211_auth_completed(sdata
, ifsta
);
1947 ieee80211_auth_challenge(sdata
, ifsta
, mgmt
, len
);
1953 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data
*sdata
,
1954 struct ieee80211_if_sta
*ifsta
,
1955 struct ieee80211_mgmt
*mgmt
,
1959 DECLARE_MAC_BUF(mac
);
1964 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
))
1967 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1969 if (ifsta
->flags
& IEEE80211_STA_AUTHENTICATED
)
1970 printk(KERN_DEBUG
"%s: deauthenticated\n", sdata
->dev
->name
);
1972 if (ifsta
->state
== IEEE80211_STA_MLME_AUTHENTICATE
||
1973 ifsta
->state
== IEEE80211_STA_MLME_ASSOCIATE
||
1974 ifsta
->state
== IEEE80211_STA_MLME_ASSOCIATED
) {
1975 ifsta
->state
= IEEE80211_STA_MLME_DIRECT_PROBE
;
1976 mod_timer(&ifsta
->timer
, jiffies
+
1977 IEEE80211_RETRY_AUTH_INTERVAL
);
1980 ieee80211_set_disassoc(sdata
, ifsta
, 1);
1981 ifsta
->flags
&= ~IEEE80211_STA_AUTHENTICATED
;
1985 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data
*sdata
,
1986 struct ieee80211_if_sta
*ifsta
,
1987 struct ieee80211_mgmt
*mgmt
,
1991 DECLARE_MAC_BUF(mac
);
1996 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
))
1999 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
2001 if (ifsta
->flags
& IEEE80211_STA_ASSOCIATED
)
2002 printk(KERN_DEBUG
"%s: disassociated\n", sdata
->dev
->name
);
2004 if (ifsta
->state
== IEEE80211_STA_MLME_ASSOCIATED
) {
2005 ifsta
->state
= IEEE80211_STA_MLME_ASSOCIATE
;
2006 mod_timer(&ifsta
->timer
, jiffies
+
2007 IEEE80211_RETRY_AUTH_INTERVAL
);
2010 ieee80211_set_disassoc(sdata
, ifsta
, 0);
2014 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
2015 struct ieee80211_if_sta
*ifsta
,
2016 struct ieee80211_mgmt
*mgmt
,
2020 struct ieee80211_local
*local
= sdata
->local
;
2021 struct ieee80211_supported_band
*sband
;
2022 struct sta_info
*sta
;
2023 u64 rates
, basic_rates
;
2024 u16 capab_info
, status_code
, aid
;
2025 struct ieee802_11_elems elems
;
2026 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
2029 DECLARE_MAC_BUF(mac
);
2030 bool have_higher_than_11mbit
= false;
2032 /* AssocResp and ReassocResp have identical structure, so process both
2033 * of them in this function. */
2035 if (ifsta
->state
!= IEEE80211_STA_MLME_ASSOCIATE
)
2041 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0)
2044 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
2045 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
2046 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
2048 printk(KERN_DEBUG
"%s: RX %sssocResp from %s (capab=0x%x "
2049 "status=%d aid=%d)\n",
2050 sdata
->dev
->name
, reassoc
? "Rea" : "A", print_mac(mac
, mgmt
->sa
),
2051 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
2053 if (status_code
!= WLAN_STATUS_SUCCESS
) {
2054 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
2055 sdata
->dev
->name
, status_code
);
2056 /* if this was a reassociation, ensure we try a "full"
2057 * association next time. This works around some broken APs
2058 * which do not correctly reject reassociation requests. */
2059 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
2063 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2064 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
2065 "set\n", sdata
->dev
->name
, aid
);
2066 aid
&= ~(BIT(15) | BIT(14));
2068 pos
= mgmt
->u
.assoc_resp
.variable
;
2069 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
2071 if (!elems
.supp_rates
) {
2072 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
2077 printk(KERN_DEBUG
"%s: associated\n", sdata
->dev
->name
);
2079 ifsta
->ap_capab
= capab_info
;
2081 kfree(ifsta
->assocresp_ies
);
2082 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
2083 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_KERNEL
);
2084 if (ifsta
->assocresp_ies
)
2085 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
2089 /* Add STA entry for the AP */
2090 sta
= sta_info_get(local
, ifsta
->bssid
);
2092 struct ieee80211_sta_bss
*bss
;
2095 sta
= sta_info_alloc(sdata
, ifsta
->bssid
, GFP_ATOMIC
);
2097 printk(KERN_DEBUG
"%s: failed to alloc STA entry for"
2098 " the AP\n", sdata
->dev
->name
);
2102 bss
= ieee80211_rx_bss_get(local
, ifsta
->bssid
,
2103 local
->hw
.conf
.channel
->center_freq
,
2104 ifsta
->ssid
, ifsta
->ssid_len
);
2106 sta
->last_signal
= bss
->signal
;
2107 sta
->last_qual
= bss
->qual
;
2108 sta
->last_noise
= bss
->noise
;
2109 ieee80211_rx_bss_put(local
, bss
);
2112 err
= sta_info_insert(sta
);
2114 printk(KERN_DEBUG
"%s: failed to insert STA entry for"
2115 " the AP (error %d)\n", sdata
->dev
->name
, err
);
2119 /* update new sta with its last rx activity */
2120 sta
->last_rx
= jiffies
;
2124 * FIXME: Do we really need to update the sta_info's information here?
2125 * We already know about the AP (we found it in our list) so it
2126 * should already be filled with the right info, no?
2127 * As is stands, all this is racy because typically we assume
2128 * the information that is filled in here (except flags) doesn't
2129 * change while a STA structure is alive. As such, it should move
2130 * to between the sta_info_alloc() and sta_info_insert() above.
2133 set_sta_flags(sta
, WLAN_STA_AUTH
| WLAN_STA_ASSOC
| WLAN_STA_ASSOC_AP
|
2134 WLAN_STA_AUTHORIZED
);
2138 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2140 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
2141 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
2144 have_higher_than_11mbit
= true;
2146 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2147 if (sband
->bitrates
[j
].bitrate
== rate
)
2149 if (elems
.supp_rates
[i
] & 0x80)
2150 basic_rates
|= BIT(j
);
2154 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
2155 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
2158 have_higher_than_11mbit
= true;
2160 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2161 if (sband
->bitrates
[j
].bitrate
== rate
)
2163 if (elems
.ext_supp_rates
[i
] & 0x80)
2164 basic_rates
|= BIT(j
);
2168 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] = rates
;
2169 sdata
->basic_rates
= basic_rates
;
2171 /* cf. IEEE 802.11 9.2.12 */
2172 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
2173 have_higher_than_11mbit
)
2174 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
2176 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
2178 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&& elems
.wmm_param
&&
2179 (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
2180 struct ieee80211_ht_bss_info bss_info
;
2181 ieee80211_ht_cap_ie_to_ht_info(
2182 (struct ieee80211_ht_cap
*)
2183 elems
.ht_cap_elem
, &sta
->ht_info
);
2184 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2185 (struct ieee80211_ht_addt_info
*)
2186 elems
.ht_info_elem
, &bss_info
);
2187 ieee80211_handle_ht(local
, 1, &sta
->ht_info
, &bss_info
);
2190 rate_control_rate_init(sta
, local
);
2192 if (elems
.wmm_param
) {
2193 set_sta_flags(sta
, WLAN_STA_WME
);
2195 ieee80211_sta_wmm_params(local
, ifsta
, elems
.wmm_param
,
2196 elems
.wmm_param_len
);
2200 /* set AID and assoc capability,
2201 * ieee80211_set_associated() will tell the driver */
2202 bss_conf
->aid
= aid
;
2203 bss_conf
->assoc_capability
= capab_info
;
2204 ieee80211_set_associated(sdata
, ifsta
, 1);
2206 ieee80211_associated(sdata
, ifsta
);
2210 /* Caller must hold local->sta_bss_lock */
2211 static void __ieee80211_rx_bss_hash_add(struct ieee80211_local
*local
,
2212 struct ieee80211_sta_bss
*bss
)
2216 if (bss_mesh_cfg(bss
))
2217 hash_idx
= mesh_id_hash(bss_mesh_id(bss
),
2218 bss_mesh_id_len(bss
));
2220 hash_idx
= STA_HASH(bss
->bssid
);
2222 bss
->hnext
= local
->sta_bss_hash
[hash_idx
];
2223 local
->sta_bss_hash
[hash_idx
] = bss
;
2227 /* Caller must hold local->sta_bss_lock */
2228 static void __ieee80211_rx_bss_hash_del(struct ieee80211_local
*local
,
2229 struct ieee80211_sta_bss
*bss
)
2231 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
2232 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
2236 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
2239 prev
->hnext
= bss
->hnext
;
2248 static struct ieee80211_sta_bss
*
2249 ieee80211_rx_bss_add(struct ieee80211_sub_if_data
*sdata
, u8
*bssid
, int freq
,
2250 u8
*ssid
, u8 ssid_len
)
2252 struct ieee80211_local
*local
= sdata
->local
;
2253 struct ieee80211_sta_bss
*bss
;
2255 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2258 atomic_inc(&bss
->users
);
2259 atomic_inc(&bss
->users
);
2260 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
2262 if (ssid
&& ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
2263 memcpy(bss
->ssid
, ssid
, ssid_len
);
2264 bss
->ssid_len
= ssid_len
;
2267 spin_lock_bh(&local
->sta_bss_lock
);
2268 /* TODO: order by RSSI? */
2269 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2270 __ieee80211_rx_bss_hash_add(local
, bss
);
2271 spin_unlock_bh(&local
->sta_bss_lock
);
2275 static struct ieee80211_sta_bss
*
2276 ieee80211_rx_bss_get(struct ieee80211_local
*local
, u8
*bssid
, int freq
,
2277 u8
*ssid
, u8 ssid_len
)
2279 struct ieee80211_sta_bss
*bss
;
2281 spin_lock_bh(&local
->sta_bss_lock
);
2282 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
2284 if (!bss_mesh_cfg(bss
) &&
2285 !memcmp(bss
->bssid
, bssid
, ETH_ALEN
) &&
2286 bss
->freq
== freq
&&
2287 bss
->ssid_len
== ssid_len
&&
2288 (ssid_len
== 0 || !memcmp(bss
->ssid
, ssid
, ssid_len
))) {
2289 atomic_inc(&bss
->users
);
2294 spin_unlock_bh(&local
->sta_bss_lock
);
2298 #ifdef CONFIG_MAC80211_MESH
2299 static struct ieee80211_sta_bss
*
2300 ieee80211_rx_mesh_bss_get(struct ieee80211_local
*local
, u8
*mesh_id
, int mesh_id_len
,
2301 u8
*mesh_cfg
, int freq
)
2303 struct ieee80211_sta_bss
*bss
;
2305 spin_lock_bh(&local
->sta_bss_lock
);
2306 bss
= local
->sta_bss_hash
[mesh_id_hash(mesh_id
, mesh_id_len
)];
2308 if (bss_mesh_cfg(bss
) &&
2309 !memcmp(bss_mesh_cfg(bss
), mesh_cfg
, MESH_CFG_CMP_LEN
) &&
2310 bss
->freq
== freq
&&
2311 mesh_id_len
== bss
->mesh_id_len
&&
2312 (mesh_id_len
== 0 || !memcmp(bss
->mesh_id
, mesh_id
,
2314 atomic_inc(&bss
->users
);
2319 spin_unlock_bh(&local
->sta_bss_lock
);
2323 static struct ieee80211_sta_bss
*
2324 ieee80211_rx_mesh_bss_add(struct ieee80211_local
*local
, u8
*mesh_id
, int mesh_id_len
,
2325 u8
*mesh_cfg
, int mesh_config_len
, int freq
)
2327 struct ieee80211_sta_bss
*bss
;
2329 if (mesh_config_len
!= MESH_CFG_LEN
)
2332 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2336 bss
->mesh_cfg
= kmalloc(MESH_CFG_CMP_LEN
, GFP_ATOMIC
);
2337 if (!bss
->mesh_cfg
) {
2342 if (mesh_id_len
&& mesh_id_len
<= IEEE80211_MAX_MESH_ID_LEN
) {
2343 bss
->mesh_id
= kmalloc(mesh_id_len
, GFP_ATOMIC
);
2344 if (!bss
->mesh_id
) {
2345 kfree(bss
->mesh_cfg
);
2349 memcpy(bss
->mesh_id
, mesh_id
, mesh_id_len
);
2352 atomic_inc(&bss
->users
);
2353 atomic_inc(&bss
->users
);
2354 memcpy(bss
->mesh_cfg
, mesh_cfg
, MESH_CFG_CMP_LEN
);
2355 bss
->mesh_id_len
= mesh_id_len
;
2357 spin_lock_bh(&local
->sta_bss_lock
);
2358 /* TODO: order by RSSI? */
2359 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2360 __ieee80211_rx_bss_hash_add(local
, bss
);
2361 spin_unlock_bh(&local
->sta_bss_lock
);
2366 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
2369 kfree(bss_mesh_id(bss
));
2370 kfree(bss_mesh_cfg(bss
));
2375 static void ieee80211_rx_bss_put(struct ieee80211_local
*local
,
2376 struct ieee80211_sta_bss
*bss
)
2379 if (!atomic_dec_and_lock(&bss
->users
, &local
->sta_bss_lock
)) {
2384 __ieee80211_rx_bss_hash_del(local
, bss
);
2385 list_del(&bss
->list
);
2386 spin_unlock_bh(&local
->sta_bss_lock
);
2387 ieee80211_rx_bss_free(bss
);
2391 void ieee80211_rx_bss_list_init(struct ieee80211_local
*local
)
2393 spin_lock_init(&local
->sta_bss_lock
);
2394 INIT_LIST_HEAD(&local
->sta_bss_list
);
2398 void ieee80211_rx_bss_list_deinit(struct ieee80211_local
*local
)
2400 struct ieee80211_sta_bss
*bss
, *tmp
;
2402 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
2403 ieee80211_rx_bss_put(local
, bss
);
2407 static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data
*sdata
,
2408 struct ieee80211_if_sta
*ifsta
,
2409 struct ieee80211_sta_bss
*bss
)
2411 struct ieee80211_local
*local
= sdata
->local
;
2412 int res
, rates
, i
, j
;
2413 struct sk_buff
*skb
;
2414 struct ieee80211_mgmt
*mgmt
;
2416 struct ieee80211_supported_band
*sband
;
2417 union iwreq_data wrqu
;
2419 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2421 /* Remove possible STA entries from other IBSS networks. */
2422 sta_info_flush_delayed(sdata
);
2424 if (local
->ops
->reset_tsf
) {
2425 /* Reset own TSF to allow time synchronization work. */
2426 local
->ops
->reset_tsf(local_to_hw(local
));
2428 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
2429 res
= ieee80211_if_config(sdata
, IEEE80211_IFCC_BSSID
);
2433 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2435 sdata
->drop_unencrypted
= bss
->capability
&
2436 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
2438 res
= ieee80211_set_freq(sdata
, bss
->freq
);
2443 /* Build IBSS probe response */
2444 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 400);
2446 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2448 mgmt
= (struct ieee80211_mgmt
*)
2449 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2450 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2451 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
2452 IEEE80211_STYPE_PROBE_RESP
);
2453 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2454 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
2455 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2456 mgmt
->u
.beacon
.beacon_int
=
2457 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2458 mgmt
->u
.beacon
.timestamp
= cpu_to_le64(bss
->timestamp
);
2459 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2461 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2462 *pos
++ = WLAN_EID_SSID
;
2463 *pos
++ = ifsta
->ssid_len
;
2464 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2466 rates
= bss
->supp_rates_len
;
2469 pos
= skb_put(skb
, 2 + rates
);
2470 *pos
++ = WLAN_EID_SUPP_RATES
;
2472 memcpy(pos
, bss
->supp_rates
, rates
);
2474 if (bss
->band
== IEEE80211_BAND_2GHZ
) {
2475 pos
= skb_put(skb
, 2 + 1);
2476 *pos
++ = WLAN_EID_DS_PARAMS
;
2478 *pos
++ = ieee80211_frequency_to_channel(bss
->freq
);
2481 pos
= skb_put(skb
, 2 + 2);
2482 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2484 /* FIX: set ATIM window based on scan results */
2488 if (bss
->supp_rates_len
> 8) {
2489 rates
= bss
->supp_rates_len
- 8;
2490 pos
= skb_put(skb
, 2 + rates
);
2491 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2493 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2496 ifsta
->probe_resp
= skb
;
2498 ieee80211_if_config(sdata
, IEEE80211_IFCC_BEACON
);
2502 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2503 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2504 int bitrate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2505 for (j
= 0; j
< sband
->n_bitrates
; j
++)
2506 if (sband
->bitrates
[j
].bitrate
== bitrate
)
2509 ifsta
->supp_rates_bits
[local
->hw
.conf
.channel
->band
] = rates
;
2511 ieee80211_sta_def_wmm_params(sdata
, bss
, 1);
2513 ifsta
->state
= IEEE80211_STA_MLME_IBSS_JOINED
;
2514 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2516 memset(&wrqu
, 0, sizeof(wrqu
));
2517 memcpy(wrqu
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
2518 wireless_send_event(sdata
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
2523 u64
ieee80211_sta_get_rates(struct ieee80211_local
*local
,
2524 struct ieee802_11_elems
*elems
,
2525 enum ieee80211_band band
)
2527 struct ieee80211_supported_band
*sband
;
2528 struct ieee80211_rate
*bitrates
;
2532 sband
= local
->hw
.wiphy
->bands
[band
];
2536 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2539 bitrates
= sband
->bitrates
;
2540 num_rates
= sband
->n_bitrates
;
2542 for (i
= 0; i
< elems
->supp_rates_len
+
2543 elems
->ext_supp_rates_len
; i
++) {
2546 if (i
< elems
->supp_rates_len
)
2547 rate
= elems
->supp_rates
[i
];
2548 else if (elems
->ext_supp_rates
)
2549 rate
= elems
->ext_supp_rates
2550 [i
- elems
->supp_rates_len
];
2551 own_rate
= 5 * (rate
& 0x7f);
2552 for (j
= 0; j
< num_rates
; j
++)
2553 if (bitrates
[j
].bitrate
== own_rate
)
2554 supp_rates
|= BIT(j
);
2559 static u64
ieee80211_sta_get_mandatory_rates(struct ieee80211_local
*local
,
2560 enum ieee80211_band band
)
2562 struct ieee80211_supported_band
*sband
;
2563 struct ieee80211_rate
*bitrates
;
2564 u64 mandatory_rates
;
2565 enum ieee80211_rate_flags mandatory_flag
;
2568 sband
= local
->hw
.wiphy
->bands
[band
];
2571 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2574 if (band
== IEEE80211_BAND_2GHZ
)
2575 mandatory_flag
= IEEE80211_RATE_MANDATORY_B
;
2577 mandatory_flag
= IEEE80211_RATE_MANDATORY_A
;
2579 bitrates
= sband
->bitrates
;
2580 mandatory_rates
= 0;
2581 for (i
= 0; i
< sband
->n_bitrates
; i
++)
2582 if (bitrates
[i
].flags
& mandatory_flag
)
2583 mandatory_rates
|= BIT(i
);
2584 return mandatory_rates
;
2587 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data
*sdata
,
2588 struct ieee80211_mgmt
*mgmt
,
2590 struct ieee80211_rx_status
*rx_status
,
2591 struct ieee802_11_elems
*elems
)
2593 struct ieee80211_local
*local
= sdata
->local
;
2595 struct ieee80211_sta_bss
*bss
;
2596 struct sta_info
*sta
;
2597 struct ieee80211_channel
*channel
;
2598 u64 beacon_timestamp
, rx_timestamp
;
2600 bool beacon
= ieee80211_is_beacon(mgmt
->frame_control
);
2601 enum ieee80211_band band
= rx_status
->band
;
2602 DECLARE_MAC_BUF(mac
);
2603 DECLARE_MAC_BUF(mac2
);
2605 if (elems
->ds_params
&& elems
->ds_params_len
== 1)
2606 freq
= ieee80211_channel_to_frequency(elems
->ds_params
[0]);
2608 freq
= rx_status
->freq
;
2610 channel
= ieee80211_get_channel(local
->hw
.wiphy
, freq
);
2612 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
2615 if (ieee80211_vif_is_mesh(&sdata
->vif
) && elems
->mesh_id
&&
2616 elems
->mesh_config
&& mesh_matches_local(elems
, sdata
)) {
2617 supp_rates
= ieee80211_sta_get_rates(local
, elems
, band
);
2619 mesh_neighbour_update(mgmt
->sa
, supp_rates
, sdata
,
2620 mesh_peer_accepts_plinks(elems
));
2623 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& elems
->supp_rates
&&
2624 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0) {
2625 supp_rates
= ieee80211_sta_get_rates(local
, elems
, band
);
2629 sta
= sta_info_get(local
, mgmt
->sa
);
2633 prev_rates
= sta
->supp_rates
[band
];
2634 /* make sure mandatory rates are always added */
2635 sta
->supp_rates
[band
] = supp_rates
|
2636 ieee80211_sta_get_mandatory_rates(local
, band
);
2638 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2639 if (sta
->supp_rates
[band
] != prev_rates
)
2640 printk(KERN_DEBUG
"%s: updated supp_rates set "
2641 "for %s based on beacon info (0x%llx | "
2642 "0x%llx -> 0x%llx)\n",
2643 sdata
->dev
->name
, print_mac(mac
, sta
->addr
),
2644 (unsigned long long) prev_rates
,
2645 (unsigned long long) supp_rates
,
2646 (unsigned long long) sta
->supp_rates
[band
]);
2649 ieee80211_ibss_add_sta(sdata
, NULL
, mgmt
->bssid
,
2650 mgmt
->sa
, supp_rates
);
2656 #ifdef CONFIG_MAC80211_MESH
2657 if (elems
->mesh_config
)
2658 bss
= ieee80211_rx_mesh_bss_get(local
, elems
->mesh_id
,
2659 elems
->mesh_id_len
, elems
->mesh_config
, freq
);
2662 bss
= ieee80211_rx_bss_get(local
, mgmt
->bssid
, freq
,
2663 elems
->ssid
, elems
->ssid_len
);
2665 #ifdef CONFIG_MAC80211_MESH
2666 if (elems
->mesh_config
)
2667 bss
= ieee80211_rx_mesh_bss_add(local
, elems
->mesh_id
,
2668 elems
->mesh_id_len
, elems
->mesh_config
,
2669 elems
->mesh_config_len
, freq
);
2672 bss
= ieee80211_rx_bss_add(sdata
, mgmt
->bssid
, freq
,
2673 elems
->ssid
, elems
->ssid_len
);
2678 /* TODO: order by RSSI? */
2679 spin_lock_bh(&local
->sta_bss_lock
);
2680 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
2681 spin_unlock_bh(&local
->sta_bss_lock
);
2685 /* save the ERP value so that it is available at association time */
2686 if (elems
->erp_info
&& elems
->erp_info_len
>= 1) {
2687 bss
->erp_value
= elems
->erp_info
[0];
2688 bss
->has_erp_value
= 1;
2691 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
2692 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2695 struct ieee80211_tim_ie
*tim_ie
=
2696 (struct ieee80211_tim_ie
*)elems
->tim
;
2697 bss
->dtim_period
= tim_ie
->dtim_period
;
2700 /* set default value for buggy APs */
2701 if (!elems
->tim
|| bss
->dtim_period
== 0)
2702 bss
->dtim_period
= 1;
2704 bss
->supp_rates_len
= 0;
2705 if (elems
->supp_rates
) {
2706 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2707 if (clen
> elems
->supp_rates_len
)
2708 clen
= elems
->supp_rates_len
;
2709 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
->supp_rates
,
2711 bss
->supp_rates_len
+= clen
;
2713 if (elems
->ext_supp_rates
) {
2714 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2715 if (clen
> elems
->ext_supp_rates_len
)
2716 clen
= elems
->ext_supp_rates_len
;
2717 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
2718 elems
->ext_supp_rates
, clen
);
2719 bss
->supp_rates_len
+= clen
;
2724 beacon_timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
2726 bss
->timestamp
= beacon_timestamp
;
2727 bss
->last_update
= jiffies
;
2728 bss
->signal
= rx_status
->signal
;
2729 bss
->noise
= rx_status
->noise
;
2730 bss
->qual
= rx_status
->qual
;
2732 bss
->last_probe_resp
= jiffies
;
2734 * In STA mode, the remaining parameters should not be overridden
2735 * by beacons because they're not necessarily accurate there.
2737 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
2738 bss
->last_probe_resp
&& beacon
) {
2739 ieee80211_rx_bss_put(local
, bss
);
2743 if (bss
->ies
== NULL
|| bss
->ies_len
< elems
->total_len
) {
2745 bss
->ies
= kmalloc(elems
->total_len
, GFP_ATOMIC
);
2748 memcpy(bss
->ies
, elems
->ie_start
, elems
->total_len
);
2749 bss
->ies_len
= elems
->total_len
;
2753 bss
->wmm_used
= elems
->wmm_param
|| elems
->wmm_info
;
2755 /* check if we need to merge IBSS */
2756 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
2757 !local
->sta_sw_scanning
&& !local
->sta_hw_scanning
&&
2758 bss
->capability
& WLAN_CAPABILITY_IBSS
&&
2759 bss
->freq
== local
->oper_channel
->center_freq
&&
2760 elems
->ssid_len
== sdata
->u
.sta
.ssid_len
&&
2761 memcmp(elems
->ssid
, sdata
->u
.sta
.ssid
,
2762 sdata
->u
.sta
.ssid_len
) == 0) {
2763 if (rx_status
->flag
& RX_FLAG_TSFT
) {
2764 /* in order for correct IBSS merging we need mactime
2766 * since mactime is defined as the time the first data
2767 * symbol of the frame hits the PHY, and the timestamp
2768 * of the beacon is defined as "the time that the data
2769 * symbol containing the first bit of the timestamp is
2770 * transmitted to the PHY plus the transmitting STA’s
2771 * delays through its local PHY from the MAC-PHY
2772 * interface to its interface with the WM"
2773 * (802.11 11.1.2) - equals the time this bit arrives at
2774 * the receiver - we have to take into account the
2775 * offset between the two.
2776 * e.g: at 1 MBit that means mactime is 192 usec earlier
2777 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2779 int rate
= local
->hw
.wiphy
->bands
[band
]->
2780 bitrates
[rx_status
->rate_idx
].bitrate
;
2781 rx_timestamp
= rx_status
->mactime
+ (24 * 8 * 10 / rate
);
2782 } else if (local
&& local
->ops
&& local
->ops
->get_tsf
)
2783 /* second best option: get current TSF */
2784 rx_timestamp
= local
->ops
->get_tsf(local_to_hw(local
));
2786 /* can't merge without knowing the TSF */
2787 rx_timestamp
= -1LLU;
2788 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2789 printk(KERN_DEBUG
"RX beacon SA=%s BSSID="
2790 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2791 print_mac(mac
, mgmt
->sa
),
2792 print_mac(mac2
, mgmt
->bssid
),
2793 (unsigned long long)rx_timestamp
,
2794 (unsigned long long)beacon_timestamp
,
2795 (unsigned long long)(rx_timestamp
- beacon_timestamp
),
2797 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2798 if (beacon_timestamp
> rx_timestamp
) {
2799 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2800 printk(KERN_DEBUG
"%s: beacon TSF higher than "
2801 "local TSF - IBSS merge with BSSID %s\n",
2802 sdata
->dev
->name
, print_mac(mac
, mgmt
->bssid
));
2804 ieee80211_sta_join_ibss(sdata
, &sdata
->u
.sta
, bss
);
2805 ieee80211_ibss_add_sta(sdata
, NULL
,
2806 mgmt
->bssid
, mgmt
->sa
,
2811 ieee80211_rx_bss_put(local
, bss
);
2815 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data
*sdata
,
2816 struct ieee80211_mgmt
*mgmt
,
2818 struct ieee80211_rx_status
*rx_status
)
2821 struct ieee802_11_elems elems
;
2822 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2824 if (memcmp(mgmt
->da
, sdata
->dev
->dev_addr
, ETH_ALEN
))
2825 return; /* ignore ProbeResp to foreign address */
2827 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
2831 ieee802_11_parse_elems(mgmt
->u
.probe_resp
.variable
, len
- baselen
,
2834 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
2836 /* direct probe may be part of the association flow */
2837 if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE
,
2839 printk(KERN_DEBUG
"%s direct probe responded\n",
2841 ieee80211_authenticate(sdata
, ifsta
);
2846 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data
*sdata
,
2847 struct ieee80211_mgmt
*mgmt
,
2849 struct ieee80211_rx_status
*rx_status
)
2851 struct ieee80211_if_sta
*ifsta
;
2853 struct ieee802_11_elems elems
;
2854 struct ieee80211_local
*local
= sdata
->local
;
2855 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
2858 /* Process beacon from the current BSS */
2859 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2863 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2865 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
2867 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
2869 ifsta
= &sdata
->u
.sta
;
2871 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
) ||
2872 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
2875 /* Do not send changes to driver if we are scanning. This removes
2876 * requirement that a driver's bss_info_changed/conf_tx functions
2877 * need to be atomic.
2878 * This is really ugly code, we should rewrite scanning and make
2879 * all this more understandable for humans.
2881 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
2884 ieee80211_sta_wmm_params(local
, ifsta
, elems
.wmm_param
,
2885 elems
.wmm_param_len
);
2887 if (elems
.erp_info
&& elems
.erp_info_len
>= 1)
2888 changed
|= ieee80211_handle_erp_ie(sdata
, elems
.erp_info
[0]);
2890 u16 capab
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2891 changed
|= ieee80211_handle_protect_preamb(sdata
, false,
2892 (capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
) != 0);
2895 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&&
2896 elems
.wmm_param
&& conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
2897 struct ieee80211_ht_bss_info bss_info
;
2899 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2900 (struct ieee80211_ht_addt_info
*)
2901 elems
.ht_info_elem
, &bss_info
);
2902 changed
|= ieee80211_handle_ht(local
, 1, &conf
->ht_conf
,
2906 ieee80211_bss_info_change_notify(sdata
, changed
);
2910 static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data
*sdata
,
2911 struct ieee80211_if_sta
*ifsta
,
2912 struct ieee80211_mgmt
*mgmt
,
2914 struct ieee80211_rx_status
*rx_status
)
2916 struct ieee80211_local
*local
= sdata
->local
;
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_STA_MLME_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 sdata
->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 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2956 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
2958 sdata
->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 sdata
->dev
->name
, print_mac(mac
, resp
->da
));
2979 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2980 ieee80211_sta_tx(sdata
, skb
, 0);
2983 static void ieee80211_rx_mgmt_action(struct ieee80211_sub_if_data
*sdata
,
2984 struct ieee80211_if_sta
*ifsta
,
2985 struct ieee80211_mgmt
*mgmt
,
2987 struct ieee80211_rx_status
*rx_status
)
2989 struct ieee80211_local
*local
= sdata
->local
;
2991 /* all categories we currently handle have action_code */
2992 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 1)
2995 switch (mgmt
->u
.action
.category
) {
2996 case WLAN_CATEGORY_SPECTRUM_MGMT
:
2997 if (local
->hw
.conf
.channel
->band
!= IEEE80211_BAND_5GHZ
)
2999 switch (mgmt
->u
.action
.u
.chan_switch
.action_code
) {
3000 case WLAN_ACTION_SPCT_MSR_REQ
:
3001 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3002 sizeof(mgmt
->u
.action
.u
.measurement
)))
3004 ieee80211_sta_process_measurement_req(sdata
, mgmt
, len
);
3008 case WLAN_CATEGORY_BACK
:
3009 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
3010 case WLAN_ACTION_ADDBA_REQ
:
3011 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3012 sizeof(mgmt
->u
.action
.u
.addba_req
)))
3014 ieee80211_sta_process_addba_request(local
, mgmt
, len
);
3016 case WLAN_ACTION_ADDBA_RESP
:
3017 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3018 sizeof(mgmt
->u
.action
.u
.addba_resp
)))
3020 ieee80211_sta_process_addba_resp(local
, mgmt
, len
);
3022 case WLAN_ACTION_DELBA
:
3023 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3024 sizeof(mgmt
->u
.action
.u
.delba
)))
3026 ieee80211_sta_process_delba(sdata
, mgmt
, len
);
3030 case PLINK_CATEGORY
:
3031 if (ieee80211_vif_is_mesh(&sdata
->vif
))
3032 mesh_rx_plink_frame(sdata
, mgmt
, len
, rx_status
);
3034 case MESH_PATH_SEL_CATEGORY
:
3035 if (ieee80211_vif_is_mesh(&sdata
->vif
))
3036 mesh_rx_path_sel_frame(sdata
, mgmt
, len
);
3041 void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data
*sdata
, struct sk_buff
*skb
,
3042 struct ieee80211_rx_status
*rx_status
)
3044 struct ieee80211_local
*local
= sdata
->local
;
3045 struct ieee80211_if_sta
*ifsta
;
3046 struct ieee80211_mgmt
*mgmt
;
3052 ifsta
= &sdata
->u
.sta
;
3054 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3055 fc
= le16_to_cpu(mgmt
->frame_control
);
3057 switch (fc
& IEEE80211_FCTL_STYPE
) {
3058 case IEEE80211_STYPE_PROBE_REQ
:
3059 case IEEE80211_STYPE_PROBE_RESP
:
3060 case IEEE80211_STYPE_BEACON
:
3061 case IEEE80211_STYPE_ACTION
:
3062 memcpy(skb
->cb
, rx_status
, sizeof(*rx_status
));
3063 case IEEE80211_STYPE_AUTH
:
3064 case IEEE80211_STYPE_ASSOC_RESP
:
3065 case IEEE80211_STYPE_REASSOC_RESP
:
3066 case IEEE80211_STYPE_DEAUTH
:
3067 case IEEE80211_STYPE_DISASSOC
:
3068 skb_queue_tail(&ifsta
->skb_queue
, skb
);
3069 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3077 static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data
*sdata
,
3078 struct sk_buff
*skb
)
3080 struct ieee80211_rx_status
*rx_status
;
3081 struct ieee80211_if_sta
*ifsta
;
3082 struct ieee80211_mgmt
*mgmt
;
3085 ifsta
= &sdata
->u
.sta
;
3087 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
3088 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3089 fc
= le16_to_cpu(mgmt
->frame_control
);
3091 switch (fc
& IEEE80211_FCTL_STYPE
) {
3092 case IEEE80211_STYPE_PROBE_REQ
:
3093 ieee80211_rx_mgmt_probe_req(sdata
, ifsta
, mgmt
, skb
->len
,
3096 case IEEE80211_STYPE_PROBE_RESP
:
3097 ieee80211_rx_mgmt_probe_resp(sdata
, mgmt
, skb
->len
, rx_status
);
3099 case IEEE80211_STYPE_BEACON
:
3100 ieee80211_rx_mgmt_beacon(sdata
, mgmt
, skb
->len
, rx_status
);
3102 case IEEE80211_STYPE_AUTH
:
3103 ieee80211_rx_mgmt_auth(sdata
, ifsta
, mgmt
, skb
->len
);
3105 case IEEE80211_STYPE_ASSOC_RESP
:
3106 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 0);
3108 case IEEE80211_STYPE_REASSOC_RESP
:
3109 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 1);
3111 case IEEE80211_STYPE_DEAUTH
:
3112 ieee80211_rx_mgmt_deauth(sdata
, ifsta
, mgmt
, skb
->len
);
3114 case IEEE80211_STYPE_DISASSOC
:
3115 ieee80211_rx_mgmt_disassoc(sdata
, ifsta
, mgmt
, skb
->len
);
3117 case IEEE80211_STYPE_ACTION
:
3118 ieee80211_rx_mgmt_action(sdata
, ifsta
, mgmt
, skb
->len
, rx_status
);
3127 ieee80211_sta_rx_scan(struct ieee80211_sub_if_data
*sdata
, struct sk_buff
*skb
,
3128 struct ieee80211_rx_status
*rx_status
)
3130 struct ieee80211_mgmt
*mgmt
;
3134 return RX_DROP_UNUSABLE
;
3136 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3137 fc
= mgmt
->frame_control
;
3139 if (ieee80211_is_ctl(fc
))
3143 return RX_DROP_MONITOR
;
3145 if (ieee80211_is_probe_resp(fc
)) {
3146 ieee80211_rx_mgmt_probe_resp(sdata
, mgmt
, skb
->len
, rx_status
);
3151 if (ieee80211_is_beacon(fc
)) {
3152 ieee80211_rx_mgmt_beacon(sdata
, mgmt
, skb
->len
, rx_status
);
3161 static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data
*sdata
)
3163 struct ieee80211_local
*local
= sdata
->local
;
3165 struct sta_info
*sta
;
3169 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
3170 if (sta
->sdata
== sdata
&&
3171 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
3184 static void ieee80211_sta_expire(struct ieee80211_sub_if_data
*sdata
, unsigned long exp_time
)
3186 struct ieee80211_local
*local
= sdata
->local
;
3187 struct sta_info
*sta
, *tmp
;
3188 LIST_HEAD(tmp_list
);
3189 DECLARE_MAC_BUF(mac
);
3190 unsigned long flags
;
3192 spin_lock_irqsave(&local
->sta_lock
, flags
);
3193 list_for_each_entry_safe(sta
, tmp
, &local
->sta_list
, list
)
3194 if (time_after(jiffies
, sta
->last_rx
+ exp_time
)) {
3195 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3196 printk(KERN_DEBUG
"%s: expiring inactive STA %s\n",
3197 sdata
->dev
->name
, print_mac(mac
, sta
->addr
));
3199 __sta_info_unlink(&sta
);
3201 list_add(&sta
->list
, &tmp_list
);
3203 spin_unlock_irqrestore(&local
->sta_lock
, flags
);
3205 list_for_each_entry_safe(sta
, tmp
, &tmp_list
, list
)
3206 sta_info_destroy(sta
);
3210 static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data
*sdata
,
3211 struct ieee80211_if_sta
*ifsta
)
3213 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
3215 ieee80211_sta_expire(sdata
, IEEE80211_IBSS_INACTIVITY_LIMIT
);
3216 if (ieee80211_sta_active_ibss(sdata
))
3219 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
3220 "IBSS networks with same SSID (merge)\n", sdata
->dev
->name
);
3221 ieee80211_sta_req_scan(sdata
, ifsta
->ssid
, ifsta
->ssid_len
);
3225 #ifdef CONFIG_MAC80211_MESH
3226 static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data
*sdata
,
3227 struct ieee80211_if_sta
*ifsta
)
3231 ieee80211_sta_expire(sdata
, IEEE80211_MESH_PEER_INACTIVITY_LIMIT
);
3232 mesh_path_expire(sdata
);
3234 free_plinks
= mesh_plink_availables(sdata
);
3235 if (free_plinks
!= sdata
->u
.sta
.accepting_plinks
)
3236 ieee80211_if_config(sdata
, IEEE80211_IFCC_BEACON
);
3238 mod_timer(&ifsta
->timer
, jiffies
+
3239 IEEE80211_MESH_HOUSEKEEPING_INTERVAL
);
3243 void ieee80211_start_mesh(struct ieee80211_sub_if_data
*sdata
)
3245 struct ieee80211_if_sta
*ifsta
;
3246 ifsta
= &sdata
->u
.sta
;
3247 ifsta
->state
= IEEE80211_STA_MLME_MESH_UP
;
3248 ieee80211_sta_timer((unsigned long)sdata
);
3249 ieee80211_if_config(sdata
, IEEE80211_IFCC_BEACON
);
3254 void ieee80211_sta_timer(unsigned long data
)
3256 struct ieee80211_sub_if_data
*sdata
=
3257 (struct ieee80211_sub_if_data
*) data
;
3258 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3259 struct ieee80211_local
*local
= sdata
->local
;
3261 set_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3262 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3265 void ieee80211_sta_work(struct work_struct
*work
)
3267 struct ieee80211_sub_if_data
*sdata
=
3268 container_of(work
, struct ieee80211_sub_if_data
, u
.sta
.work
);
3269 struct ieee80211_local
*local
= sdata
->local
;
3270 struct ieee80211_if_sta
*ifsta
;
3271 struct sk_buff
*skb
;
3273 if (!netif_running(sdata
->dev
))
3276 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
3279 if (WARN_ON(sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
3280 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
3281 sdata
->vif
.type
!= IEEE80211_IF_TYPE_MESH_POINT
))
3283 ifsta
= &sdata
->u
.sta
;
3285 while ((skb
= skb_dequeue(&ifsta
->skb_queue
)))
3286 ieee80211_sta_rx_queued_mgmt(sdata
, skb
);
3288 #ifdef CONFIG_MAC80211_MESH
3289 if (ifsta
->preq_queue_len
&&
3291 ifsta
->last_preq
+ msecs_to_jiffies(ifsta
->mshcfg
.dot11MeshHWMPpreqMinInterval
)))
3292 mesh_path_start_discovery(sdata
);
3295 if (ifsta
->state
!= IEEE80211_STA_MLME_DIRECT_PROBE
&&
3296 ifsta
->state
!= IEEE80211_STA_MLME_AUTHENTICATE
&&
3297 ifsta
->state
!= IEEE80211_STA_MLME_ASSOCIATE
&&
3298 test_and_clear_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
)) {
3299 if (ifsta
->scan_ssid_len
)
3300 ieee80211_sta_start_scan(sdata
, ifsta
->scan_ssid
, ifsta
->scan_ssid_len
);
3302 ieee80211_sta_start_scan(sdata
, NULL
, 0);
3306 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
)) {
3307 if (ieee80211_sta_config_auth(sdata
, ifsta
))
3309 clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3310 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
))
3313 switch (ifsta
->state
) {
3314 case IEEE80211_STA_MLME_DISABLED
:
3316 case IEEE80211_STA_MLME_DIRECT_PROBE
:
3317 ieee80211_direct_probe(sdata
, ifsta
);
3319 case IEEE80211_STA_MLME_AUTHENTICATE
:
3320 ieee80211_authenticate(sdata
, ifsta
);
3322 case IEEE80211_STA_MLME_ASSOCIATE
:
3323 ieee80211_associate(sdata
, ifsta
);
3325 case IEEE80211_STA_MLME_ASSOCIATED
:
3326 ieee80211_associated(sdata
, ifsta
);
3328 case IEEE80211_STA_MLME_IBSS_SEARCH
:
3329 ieee80211_sta_find_ibss(sdata
, ifsta
);
3331 case IEEE80211_STA_MLME_IBSS_JOINED
:
3332 ieee80211_sta_merge_ibss(sdata
, ifsta
);
3334 #ifdef CONFIG_MAC80211_MESH
3335 case IEEE80211_STA_MLME_MESH_UP
:
3336 ieee80211_mesh_housekeeping(sdata
, ifsta
);
3344 if (ieee80211_privacy_mismatch(sdata
, ifsta
)) {
3345 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
3346 "mixed-cell disabled - disassociate\n", sdata
->dev
->name
);
3348 ieee80211_send_disassoc(sdata
, ifsta
, WLAN_REASON_UNSPECIFIED
);
3349 ieee80211_set_disassoc(sdata
, ifsta
, 0);
3354 static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data
*sdata
,
3355 struct ieee80211_if_sta
*ifsta
)
3357 struct ieee80211_local
*local
= sdata
->local
;
3359 if (local
->ops
->reset_tsf
) {
3360 /* Reset own TSF to allow time synchronization work. */
3361 local
->ops
->reset_tsf(local_to_hw(local
));
3364 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
3367 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
3368 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3369 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
3370 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
3371 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
3372 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
3374 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3375 ifsta
->auth_transaction
= -1;
3376 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
3377 ifsta
->assoc_scan_tries
= 0;
3378 ifsta
->direct_probe_tries
= 0;
3379 ifsta
->auth_tries
= 0;
3380 ifsta
->assoc_tries
= 0;
3381 netif_carrier_off(sdata
->dev
);
3385 void ieee80211_sta_req_auth(struct ieee80211_sub_if_data
*sdata
,
3386 struct ieee80211_if_sta
*ifsta
)
3388 struct ieee80211_local
*local
= sdata
->local
;
3390 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3393 if ((ifsta
->flags
& (IEEE80211_STA_BSSID_SET
|
3394 IEEE80211_STA_AUTO_BSSID_SEL
)) &&
3395 (ifsta
->flags
& (IEEE80211_STA_SSID_SET
|
3396 IEEE80211_STA_AUTO_SSID_SEL
))) {
3397 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3398 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3402 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta
*ifsta
,
3403 const char *ssid
, int ssid_len
)
3405 int tmp
, hidden_ssid
;
3407 if (ssid_len
== ifsta
->ssid_len
&&
3408 !memcmp(ifsta
->ssid
, ssid
, ssid_len
))
3411 if (ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
)
3417 if (ssid
[tmp
] != '\0') {
3423 if (hidden_ssid
&& ifsta
->ssid_len
== ssid_len
)
3426 if (ssid_len
== 1 && ssid
[0] == ' ')
3432 static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data
*sdata
,
3433 struct ieee80211_if_sta
*ifsta
)
3435 struct ieee80211_local
*local
= sdata
->local
;
3436 struct ieee80211_sta_bss
*bss
, *selected
= NULL
;
3437 int top_rssi
= 0, freq
;
3439 spin_lock_bh(&local
->sta_bss_lock
);
3440 freq
= local
->oper_channel
->center_freq
;
3441 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3442 if (!(bss
->capability
& WLAN_CAPABILITY_ESS
))
3445 if ((ifsta
->flags
& (IEEE80211_STA_AUTO_SSID_SEL
|
3446 IEEE80211_STA_AUTO_BSSID_SEL
|
3447 IEEE80211_STA_AUTO_CHANNEL_SEL
)) &&
3448 (!!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
) ^
3449 !!sdata
->default_key
))
3452 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_CHANNEL_SEL
) &&
3456 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
) &&
3457 memcmp(bss
->bssid
, ifsta
->bssid
, ETH_ALEN
))
3460 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
) &&
3461 !ieee80211_sta_match_ssid(ifsta
, bss
->ssid
, bss
->ssid_len
))
3464 if (!selected
|| top_rssi
< bss
->signal
) {
3466 top_rssi
= bss
->signal
;
3470 atomic_inc(&selected
->users
);
3471 spin_unlock_bh(&local
->sta_bss_lock
);
3474 ieee80211_set_freq(sdata
, selected
->freq
);
3475 if (!(ifsta
->flags
& IEEE80211_STA_SSID_SET
))
3476 ieee80211_sta_set_ssid(sdata
, selected
->ssid
,
3477 selected
->ssid_len
);
3478 ieee80211_sta_set_bssid(sdata
, selected
->bssid
);
3479 ieee80211_sta_def_wmm_params(sdata
, selected
, 0);
3481 /* Send out direct probe if no probe resp was received or
3482 * the one we have is outdated
3484 if (!selected
->last_probe_resp
||
3485 time_after(jiffies
, selected
->last_probe_resp
3486 + IEEE80211_SCAN_RESULT_EXPIRE
))
3487 ifsta
->state
= IEEE80211_STA_MLME_DIRECT_PROBE
;
3489 ifsta
->state
= IEEE80211_STA_MLME_AUTHENTICATE
;
3491 ieee80211_rx_bss_put(local
, selected
);
3492 ieee80211_sta_reset_auth(sdata
, ifsta
);
3495 if (ifsta
->assoc_scan_tries
< IEEE80211_ASSOC_SCANS_MAX_TRIES
) {
3496 ifsta
->assoc_scan_tries
++;
3497 if (ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
)
3498 ieee80211_sta_start_scan(sdata
, NULL
, 0);
3500 ieee80211_sta_start_scan(sdata
, ifsta
->ssid
,
3502 ifsta
->state
= IEEE80211_STA_MLME_AUTHENTICATE
;
3503 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3505 ifsta
->state
= IEEE80211_STA_MLME_DISABLED
;
3511 static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data
*sdata
,
3512 struct ieee80211_if_sta
*ifsta
)
3514 struct ieee80211_local
*local
= sdata
->local
;
3515 struct ieee80211_sta_bss
*bss
;
3516 struct ieee80211_supported_band
*sband
;
3517 u8 bssid
[ETH_ALEN
], *pos
;
3520 DECLARE_MAC_BUF(mac
);
3523 /* Easier testing, use fixed BSSID. */
3524 memset(bssid
, 0xfe, ETH_ALEN
);
3526 /* Generate random, not broadcast, locally administered BSSID. Mix in
3527 * own MAC address to make sure that devices that do not have proper
3528 * random number generator get different BSSID. */
3529 get_random_bytes(bssid
, ETH_ALEN
);
3530 for (i
= 0; i
< ETH_ALEN
; i
++)
3531 bssid
[i
] ^= sdata
->dev
->dev_addr
[i
];
3536 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID %s\n",
3537 sdata
->dev
->name
, print_mac(mac
, bssid
));
3539 bss
= ieee80211_rx_bss_add(sdata
, bssid
,
3540 local
->hw
.conf
.channel
->center_freq
,
3541 sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
);
3545 bss
->band
= local
->hw
.conf
.channel
->band
;
3546 sband
= local
->hw
.wiphy
->bands
[bss
->band
];
3548 if (local
->hw
.conf
.beacon_int
== 0)
3549 local
->hw
.conf
.beacon_int
= 100;
3550 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
3551 bss
->last_update
= jiffies
;
3552 bss
->capability
= WLAN_CAPABILITY_IBSS
;
3554 if (sdata
->default_key
)
3555 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
3557 sdata
->drop_unencrypted
= 0;
3559 bss
->supp_rates_len
= sband
->n_bitrates
;
3560 pos
= bss
->supp_rates
;
3561 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
3562 int rate
= sband
->bitrates
[i
].bitrate
;
3563 *pos
++ = (u8
) (rate
/ 5);
3566 ret
= ieee80211_sta_join_ibss(sdata
, ifsta
, bss
);
3567 ieee80211_rx_bss_put(local
, bss
);
3572 static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data
*sdata
,
3573 struct ieee80211_if_sta
*ifsta
)
3575 struct ieee80211_local
*local
= sdata
->local
;
3576 struct ieee80211_sta_bss
*bss
;
3580 DECLARE_MAC_BUF(mac
);
3581 DECLARE_MAC_BUF(mac2
);
3583 if (ifsta
->ssid_len
== 0)
3586 active_ibss
= ieee80211_sta_active_ibss(sdata
);
3587 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3588 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
3589 sdata
->dev
->name
, active_ibss
);
3590 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3591 spin_lock_bh(&local
->sta_bss_lock
);
3592 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3593 if (ifsta
->ssid_len
!= bss
->ssid_len
||
3594 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
3595 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
3597 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3598 printk(KERN_DEBUG
" bssid=%s found\n",
3599 print_mac(mac
, bss
->bssid
));
3600 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3601 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
3603 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
3606 spin_unlock_bh(&local
->sta_bss_lock
);
3608 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3610 printk(KERN_DEBUG
" sta_find_ibss: selected %s current "
3611 "%s\n", print_mac(mac
, bssid
),
3612 print_mac(mac2
, ifsta
->bssid
));
3613 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3615 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
3619 if (ifsta
->flags
& IEEE80211_STA_AUTO_CHANNEL_SEL
)
3620 search_freq
= bss
->freq
;
3622 search_freq
= local
->hw
.conf
.channel
->center_freq
;
3624 bss
= ieee80211_rx_bss_get(local
, bssid
, search_freq
,
3625 ifsta
->ssid
, ifsta
->ssid_len
);
3629 printk(KERN_DEBUG
"%s: Selected IBSS BSSID %s"
3630 " based on configured SSID\n",
3631 sdata
->dev
->name
, print_mac(mac
, bssid
));
3632 ret
= ieee80211_sta_join_ibss(sdata
, ifsta
, bss
);
3633 ieee80211_rx_bss_put(local
, bss
);
3638 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3639 printk(KERN_DEBUG
" did not try to join ibss\n");
3640 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3642 /* Selected IBSS not found in current scan results - try to scan */
3643 if (ifsta
->state
== IEEE80211_STA_MLME_IBSS_JOINED
&&
3644 !ieee80211_sta_active_ibss(sdata
)) {
3645 mod_timer(&ifsta
->timer
, jiffies
+
3646 IEEE80211_IBSS_MERGE_INTERVAL
);
3647 } else if (time_after(jiffies
, local
->last_scan_completed
+
3648 IEEE80211_SCAN_INTERVAL
)) {
3649 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
3650 "join\n", sdata
->dev
->name
);
3651 return ieee80211_sta_req_scan(sdata
, ifsta
->ssid
,
3653 } else if (ifsta
->state
!= IEEE80211_STA_MLME_IBSS_JOINED
) {
3654 int interval
= IEEE80211_SCAN_INTERVAL
;
3656 if (time_after(jiffies
, ifsta
->ibss_join_req
+
3657 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
3658 if ((ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) &&
3659 (!(local
->oper_channel
->flags
&
3660 IEEE80211_CHAN_NO_IBSS
)))
3661 return ieee80211_sta_create_ibss(sdata
, ifsta
);
3662 if (ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) {
3663 printk(KERN_DEBUG
"%s: IBSS not allowed on"
3664 " %d MHz\n", sdata
->dev
->name
,
3665 local
->hw
.conf
.channel
->center_freq
);
3668 /* No IBSS found - decrease scan interval and continue
3670 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
3673 ifsta
->state
= IEEE80211_STA_MLME_IBSS_SEARCH
;
3674 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
3682 int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data
*sdata
, char *ssid
, size_t len
)
3684 struct ieee80211_if_sta
*ifsta
;
3687 if (len
> IEEE80211_MAX_SSID_LEN
)
3690 ifsta
= &sdata
->u
.sta
;
3692 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0) {
3693 memset(ifsta
->ssid
, 0, sizeof(ifsta
->ssid
));
3694 memcpy(ifsta
->ssid
, ssid
, len
);
3695 ifsta
->ssid_len
= len
;
3696 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
3700 * Hack! MLME code needs to be cleaned up to have different
3701 * entry points for configuration and internal selection change
3703 if (netif_running(sdata
->dev
))
3704 res
= ieee80211_if_config(sdata
, IEEE80211_IFCC_SSID
);
3706 printk(KERN_DEBUG
"%s: Failed to config new SSID to "
3707 "the low-level driver\n", sdata
->dev
->name
);
3713 ifsta
->flags
|= IEEE80211_STA_SSID_SET
;
3715 ifsta
->flags
&= ~IEEE80211_STA_SSID_SET
;
3717 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3718 !(ifsta
->flags
& IEEE80211_STA_BSSID_SET
)) {
3719 ifsta
->ibss_join_req
= jiffies
;
3720 ifsta
->state
= IEEE80211_STA_MLME_IBSS_SEARCH
;
3721 return ieee80211_sta_find_ibss(sdata
, ifsta
);
3728 int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data
*sdata
, char *ssid
, size_t *len
)
3730 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3731 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
3732 *len
= ifsta
->ssid_len
;
3737 int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data
*sdata
, u8
*bssid
)
3739 struct ieee80211_if_sta
*ifsta
;
3742 ifsta
= &sdata
->u
.sta
;
3744 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
3745 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
3748 * Hack! See also ieee80211_sta_set_ssid.
3750 if (netif_running(sdata
->dev
))
3751 res
= ieee80211_if_config(sdata
, IEEE80211_IFCC_BSSID
);
3753 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
3754 "the low-level driver\n", sdata
->dev
->name
);
3759 if (is_valid_ether_addr(bssid
))
3760 ifsta
->flags
|= IEEE80211_STA_BSSID_SET
;
3762 ifsta
->flags
&= ~IEEE80211_STA_BSSID_SET
;
3768 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
3769 struct ieee80211_sub_if_data
*sdata
,
3772 struct sk_buff
*skb
;
3773 struct ieee80211_hdr
*nullfunc
;
3776 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
3778 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
3779 "frame\n", sdata
->dev
->name
);
3782 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3784 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
3785 memset(nullfunc
, 0, 24);
3786 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
3787 IEEE80211_FCTL_TODS
);
3789 fc
|= cpu_to_le16(IEEE80211_FCTL_PM
);
3790 nullfunc
->frame_control
= fc
;
3791 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3792 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
3793 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3795 ieee80211_sta_tx(sdata
, skb
, 0);
3799 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
3801 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
3802 ieee80211_vif_is_mesh(&sdata
->vif
))
3803 ieee80211_sta_timer((unsigned long)sdata
);
3806 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
3808 struct ieee80211_local
*local
= hw_to_local(hw
);
3809 struct net_device
*dev
= local
->scan_dev
;
3810 struct ieee80211_sub_if_data
*sdata
;
3811 union iwreq_data wrqu
;
3813 local
->last_scan_completed
= jiffies
;
3814 memset(&wrqu
, 0, sizeof(wrqu
));
3815 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
3817 if (local
->sta_hw_scanning
) {
3818 local
->sta_hw_scanning
= 0;
3819 if (ieee80211_hw_config(local
))
3820 printk(KERN_DEBUG
"%s: failed to restore operational "
3821 "channel after scan\n", dev
->name
);
3822 /* Restart STA timer for HW scan case */
3824 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
)
3825 ieee80211_restart_sta_timer(sdata
);
3831 local
->sta_sw_scanning
= 0;
3832 if (ieee80211_hw_config(local
))
3833 printk(KERN_DEBUG
"%s: failed to restore operational "
3834 "channel after scan\n", dev
->name
);
3837 netif_tx_lock_bh(local
->mdev
);
3838 netif_addr_lock(local
->mdev
);
3839 local
->filter_flags
&= ~FIF_BCN_PRBRESP_PROMISC
;
3840 local
->ops
->configure_filter(local_to_hw(local
),
3841 FIF_BCN_PRBRESP_PROMISC
,
3842 &local
->filter_flags
,
3843 local
->mdev
->mc_count
,
3844 local
->mdev
->mc_list
);
3846 netif_addr_unlock(local
->mdev
);
3847 netif_tx_unlock_bh(local
->mdev
);
3850 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3851 /* Tell AP we're back */
3852 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3853 sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
)
3854 ieee80211_send_nullfunc(local
, sdata
, 0);
3856 ieee80211_restart_sta_timer(sdata
);
3858 netif_wake_queue(sdata
->dev
);
3863 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3864 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
3865 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3866 if (!(ifsta
->flags
& IEEE80211_STA_BSSID_SET
) ||
3867 (!(ifsta
->state
== IEEE80211_STA_MLME_IBSS_JOINED
) &&
3868 !ieee80211_sta_active_ibss(sdata
)))
3869 ieee80211_sta_find_ibss(sdata
, ifsta
);
3872 EXPORT_SYMBOL(ieee80211_scan_completed
);
3874 void ieee80211_sta_scan_work(struct work_struct
*work
)
3876 struct ieee80211_local
*local
=
3877 container_of(work
, struct ieee80211_local
, scan_work
.work
);
3878 struct net_device
*dev
= local
->scan_dev
;
3879 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3880 struct ieee80211_supported_band
*sband
;
3881 struct ieee80211_channel
*chan
;
3883 unsigned long next_delay
= 0;
3885 if (!local
->sta_sw_scanning
)
3888 switch (local
->scan_state
) {
3889 case SCAN_SET_CHANNEL
:
3891 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3892 * after we successfully scanned the last channel of the last
3893 * band (and the last band is supported by the hw)
3895 if (local
->scan_band
< IEEE80211_NUM_BANDS
)
3896 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3901 * If we are at an unsupported band and have more bands
3902 * left to scan, advance to the next supported one.
3904 while (!sband
&& local
->scan_band
< IEEE80211_NUM_BANDS
- 1) {
3906 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3907 local
->scan_channel_idx
= 0;
3910 /* if no more bands/channels left, complete scan */
3911 if (!sband
|| local
->scan_channel_idx
>= sband
->n_channels
) {
3912 ieee80211_scan_completed(local_to_hw(local
));
3916 chan
= &sband
->channels
[local
->scan_channel_idx
];
3918 if (chan
->flags
& IEEE80211_CHAN_DISABLED
||
3919 (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3920 chan
->flags
& IEEE80211_CHAN_NO_IBSS
))
3924 local
->scan_channel
= chan
;
3925 if (ieee80211_hw_config(local
)) {
3926 printk(KERN_DEBUG
"%s: failed to set freq to "
3927 "%d MHz for scan\n", dev
->name
,
3933 /* advance state machine to next channel/band */
3934 local
->scan_channel_idx
++;
3935 if (local
->scan_channel_idx
>= sband
->n_channels
) {
3937 * scan_band may end up == IEEE80211_NUM_BANDS, but
3938 * we'll catch that case above and complete the scan
3939 * if that is the case.
3942 local
->scan_channel_idx
= 0;
3948 next_delay
= IEEE80211_PROBE_DELAY
+
3949 usecs_to_jiffies(local
->hw
.channel_change_time
);
3950 local
->scan_state
= SCAN_SEND_PROBE
;
3952 case SCAN_SEND_PROBE
:
3953 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
3954 local
->scan_state
= SCAN_SET_CHANNEL
;
3956 if (local
->scan_channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
3958 ieee80211_send_probe_req(sdata
, NULL
, local
->scan_ssid
,
3959 local
->scan_ssid_len
);
3960 next_delay
= IEEE80211_CHANNEL_TIME
;
3964 if (local
->sta_sw_scanning
)
3965 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3970 static int ieee80211_sta_start_scan(struct ieee80211_sub_if_data
*scan_sdata
,
3971 u8
*ssid
, size_t ssid_len
)
3973 struct ieee80211_local
*local
= scan_sdata
->local
;
3974 struct ieee80211_sub_if_data
*sdata
;
3976 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
3979 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3980 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3983 * ScanType: ACTIVE, PASSIVE
3984 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3985 * a Probe frame during active scanning
3987 * MinChannelTime (>= ProbeDelay), in TU
3988 * MaxChannelTime: (>= MinChannelTime), in TU
3991 /* MLME-SCAN.confirm
3993 * ResultCode: SUCCESS, INVALID_PARAMETERS
3996 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3997 if (local
->scan_dev
== scan_sdata
->dev
)
4002 if (local
->ops
->hw_scan
) {
4003 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
4006 local
->sta_hw_scanning
= 1;
4007 local
->scan_dev
= scan_sdata
->dev
;
4012 local
->sta_sw_scanning
= 1;
4015 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4016 netif_stop_queue(sdata
->dev
);
4017 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
4018 (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
))
4019 ieee80211_send_nullfunc(local
, sdata
, 1);
4024 local
->scan_ssid_len
= ssid_len
;
4025 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
4027 local
->scan_ssid_len
= 0;
4028 local
->scan_state
= SCAN_SET_CHANNEL
;
4029 local
->scan_channel_idx
= 0;
4030 local
->scan_band
= IEEE80211_BAND_2GHZ
;
4031 local
->scan_dev
= scan_sdata
->dev
;
4033 netif_addr_lock_bh(local
->mdev
);
4034 local
->filter_flags
|= FIF_BCN_PRBRESP_PROMISC
;
4035 local
->ops
->configure_filter(local_to_hw(local
),
4036 FIF_BCN_PRBRESP_PROMISC
,
4037 &local
->filter_flags
,
4038 local
->mdev
->mc_count
,
4039 local
->mdev
->mc_list
);
4040 netif_addr_unlock_bh(local
->mdev
);
4042 /* TODO: start scan as soon as all nullfunc frames are ACKed */
4043 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
4044 IEEE80211_CHANNEL_TIME
);
4050 int ieee80211_sta_req_scan(struct ieee80211_sub_if_data
*sdata
, u8
*ssid
, size_t ssid_len
)
4052 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4053 struct ieee80211_local
*local
= sdata
->local
;
4055 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
4056 return ieee80211_sta_start_scan(sdata
, ssid
, ssid_len
);
4058 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
4059 if (local
->scan_dev
== sdata
->dev
)
4064 ifsta
->scan_ssid_len
= ssid_len
;
4066 memcpy(ifsta
->scan_ssid
, ssid
, ssid_len
);
4067 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
4068 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
4073 static void ieee80211_sta_add_scan_ies(struct iw_request_info
*info
,
4074 struct ieee80211_sta_bss
*bss
,
4075 char **current_ev
, char *end_buf
)
4077 u8
*pos
, *end
, *next
;
4078 struct iw_event iwe
;
4080 if (bss
== NULL
|| bss
->ies
== NULL
)
4084 * If needed, fragment the IEs buffer (at IE boundaries) into short
4085 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
4088 end
= pos
+ bss
->ies_len
;
4090 while (end
- pos
> IW_GENERIC_IE_MAX
) {
4091 next
= pos
+ 2 + pos
[1];
4092 while (next
+ 2 + next
[1] - pos
< IW_GENERIC_IE_MAX
)
4093 next
= next
+ 2 + next
[1];
4095 memset(&iwe
, 0, sizeof(iwe
));
4096 iwe
.cmd
= IWEVGENIE
;
4097 iwe
.u
.data
.length
= next
- pos
;
4098 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
4099 end_buf
, &iwe
, pos
);
4105 memset(&iwe
, 0, sizeof(iwe
));
4106 iwe
.cmd
= IWEVGENIE
;
4107 iwe
.u
.data
.length
= end
- pos
;
4108 *current_ev
= iwe_stream_add_point(info
, *current_ev
,
4109 end_buf
, &iwe
, pos
);
4115 ieee80211_sta_scan_result(struct ieee80211_local
*local
,
4116 struct iw_request_info
*info
,
4117 struct ieee80211_sta_bss
*bss
,
4118 char *current_ev
, char *end_buf
)
4120 struct iw_event iwe
;
4122 if (time_after(jiffies
,
4123 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
4126 memset(&iwe
, 0, sizeof(iwe
));
4127 iwe
.cmd
= SIOCGIWAP
;
4128 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
4129 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
4130 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
4133 memset(&iwe
, 0, sizeof(iwe
));
4134 iwe
.cmd
= SIOCGIWESSID
;
4135 if (bss_mesh_cfg(bss
)) {
4136 iwe
.u
.data
.length
= bss_mesh_id_len(bss
);
4137 iwe
.u
.data
.flags
= 1;
4138 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
4139 &iwe
, bss_mesh_id(bss
));
4141 iwe
.u
.data
.length
= bss
->ssid_len
;
4142 iwe
.u
.data
.flags
= 1;
4143 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
4147 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
4148 || bss_mesh_cfg(bss
)) {
4149 memset(&iwe
, 0, sizeof(iwe
));
4150 iwe
.cmd
= SIOCGIWMODE
;
4151 if (bss_mesh_cfg(bss
))
4152 iwe
.u
.mode
= IW_MODE_MESH
;
4153 else if (bss
->capability
& WLAN_CAPABILITY_ESS
)
4154 iwe
.u
.mode
= IW_MODE_MASTER
;
4156 iwe
.u
.mode
= IW_MODE_ADHOC
;
4157 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
4158 &iwe
, IW_EV_UINT_LEN
);
4161 memset(&iwe
, 0, sizeof(iwe
));
4162 iwe
.cmd
= SIOCGIWFREQ
;
4163 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->freq
);
4165 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
4168 memset(&iwe
, 0, sizeof(iwe
));
4169 iwe
.cmd
= SIOCGIWFREQ
;
4170 iwe
.u
.freq
.m
= bss
->freq
;
4172 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
4174 memset(&iwe
, 0, sizeof(iwe
));
4176 iwe
.u
.qual
.qual
= bss
->qual
;
4177 iwe
.u
.qual
.level
= bss
->signal
;
4178 iwe
.u
.qual
.noise
= bss
->noise
;
4179 iwe
.u
.qual
.updated
= local
->wstats_flags
;
4180 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
,
4183 memset(&iwe
, 0, sizeof(iwe
));
4184 iwe
.cmd
= SIOCGIWENCODE
;
4185 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
4186 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
4188 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
4189 iwe
.u
.data
.length
= 0;
4190 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
4193 ieee80211_sta_add_scan_ies(info
, bss
, ¤t_ev
, end_buf
);
4195 if (bss
&& bss
->supp_rates_len
> 0) {
4196 /* display all supported rates in readable format */
4197 char *p
= current_ev
+ iwe_stream_lcp_len(info
);
4200 memset(&iwe
, 0, sizeof(iwe
));
4201 iwe
.cmd
= SIOCGIWRATE
;
4202 /* Those two flags are ignored... */
4203 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
4205 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
4206 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
4208 p
= iwe_stream_add_value(info
, current_ev
, p
,
4209 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
4216 buf
= kmalloc(30, GFP_ATOMIC
);
4218 memset(&iwe
, 0, sizeof(iwe
));
4219 iwe
.cmd
= IWEVCUSTOM
;
4220 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
4221 iwe
.u
.data
.length
= strlen(buf
);
4222 current_ev
= iwe_stream_add_point(info
, current_ev
,
4225 memset(&iwe
, 0, sizeof(iwe
));
4226 iwe
.cmd
= IWEVCUSTOM
;
4227 sprintf(buf
, " Last beacon: %dms ago",
4228 jiffies_to_msecs(jiffies
- bss
->last_update
));
4229 iwe
.u
.data
.length
= strlen(buf
);
4230 current_ev
= iwe_stream_add_point(info
, current_ev
,
4231 end_buf
, &iwe
, buf
);
4236 if (bss_mesh_cfg(bss
)) {
4238 u8
*cfg
= bss_mesh_cfg(bss
);
4239 buf
= kmalloc(50, GFP_ATOMIC
);
4241 memset(&iwe
, 0, sizeof(iwe
));
4242 iwe
.cmd
= IWEVCUSTOM
;
4243 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
4244 iwe
.u
.data
.length
= strlen(buf
);
4245 current_ev
= iwe_stream_add_point(info
, current_ev
,
4248 sprintf(buf
, "Path Selection Protocol ID: "
4249 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
4251 iwe
.u
.data
.length
= strlen(buf
);
4252 current_ev
= iwe_stream_add_point(info
, current_ev
,
4255 sprintf(buf
, "Path Selection Metric ID: "
4256 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
4258 iwe
.u
.data
.length
= strlen(buf
);
4259 current_ev
= iwe_stream_add_point(info
, current_ev
,
4262 sprintf(buf
, "Congestion Control Mode ID: "
4263 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
4265 iwe
.u
.data
.length
= strlen(buf
);
4266 current_ev
= iwe_stream_add_point(info
, current_ev
,
4269 sprintf(buf
, "Channel Precedence: "
4270 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
4272 iwe
.u
.data
.length
= strlen(buf
);
4273 current_ev
= iwe_stream_add_point(info
, current_ev
,
4284 int ieee80211_sta_scan_results(struct ieee80211_local
*local
,
4285 struct iw_request_info
*info
,
4286 char *buf
, size_t len
)
4288 char *current_ev
= buf
;
4289 char *end_buf
= buf
+ len
;
4290 struct ieee80211_sta_bss
*bss
;
4292 spin_lock_bh(&local
->sta_bss_lock
);
4293 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
4294 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
4295 spin_unlock_bh(&local
->sta_bss_lock
);
4298 current_ev
= ieee80211_sta_scan_result(local
, info
, bss
,
4299 current_ev
, end_buf
);
4301 spin_unlock_bh(&local
->sta_bss_lock
);
4302 return current_ev
- buf
;
4306 int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data
*sdata
, char *ie
, size_t len
)
4308 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4310 kfree(ifsta
->extra_ie
);
4312 ifsta
->extra_ie
= NULL
;
4313 ifsta
->extra_ie_len
= 0;
4316 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
4317 if (!ifsta
->extra_ie
) {
4318 ifsta
->extra_ie_len
= 0;
4321 memcpy(ifsta
->extra_ie
, ie
, len
);
4322 ifsta
->extra_ie_len
= len
;
4327 struct sta_info
*ieee80211_ibss_add_sta(struct ieee80211_sub_if_data
*sdata
,
4328 struct sk_buff
*skb
, u8
*bssid
,
4329 u8
*addr
, u64 supp_rates
)
4331 struct ieee80211_local
*local
= sdata
->local
;
4332 struct sta_info
*sta
;
4333 DECLARE_MAC_BUF(mac
);
4334 int band
= local
->hw
.conf
.channel
->band
;
4336 /* TODO: Could consider removing the least recently used entry and
4337 * allow new one to be added. */
4338 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
4339 if (net_ratelimit()) {
4340 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
4341 "entry %s\n", sdata
->dev
->name
, print_mac(mac
, addr
));
4346 if (compare_ether_addr(bssid
, sdata
->u
.sta
.bssid
))
4349 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
4350 printk(KERN_DEBUG
"%s: Adding new IBSS station %s (dev=%s)\n",
4351 wiphy_name(local
->hw
.wiphy
), print_mac(mac
, addr
), sdata
->dev
->name
);
4354 sta
= sta_info_alloc(sdata
, addr
, GFP_ATOMIC
);
4358 set_sta_flags(sta
, WLAN_STA_AUTHORIZED
);
4360 /* make sure mandatory rates are always added */
4361 sta
->supp_rates
[band
] = supp_rates
|
4362 ieee80211_sta_get_mandatory_rates(local
, band
);
4364 rate_control_rate_init(sta
, local
);
4366 if (sta_info_insert(sta
))
4373 int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data
*sdata
, u16 reason
)
4375 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4377 printk(KERN_DEBUG
"%s: deauthenticating by local choice (reason=%d)\n",
4378 sdata
->dev
->name
, reason
);
4380 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
4381 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
4384 ieee80211_send_deauth(sdata
, ifsta
, reason
);
4385 ieee80211_set_disassoc(sdata
, ifsta
, 1);
4390 int ieee80211_sta_disassociate(struct ieee80211_sub_if_data
*sdata
, u16 reason
)
4392 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4394 printk(KERN_DEBUG
"%s: disassociating by local choice (reason=%d)\n",
4395 sdata
->dev
->name
, reason
);
4397 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
4400 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
))
4403 ieee80211_send_disassoc(sdata
, ifsta
, reason
);
4404 ieee80211_set_disassoc(sdata
, ifsta
, 0);
4408 void ieee80211_notify_mac(struct ieee80211_hw
*hw
,
4409 enum ieee80211_notification_types notif_type
)
4411 struct ieee80211_local
*local
= hw_to_local(hw
);
4412 struct ieee80211_sub_if_data
*sdata
;
4414 switch (notif_type
) {
4415 case IEEE80211_NOTIFY_RE_ASSOC
:
4417 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4418 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
4421 ieee80211_sta_req_auth(sdata
, &sdata
->u
.sta
);
4427 EXPORT_SYMBOL(ieee80211_notify_mac
);