2 * BSS client mode implementation
3 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 * order BSS list by RSSI(?) ("quality of AP")
16 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
19 #include <linux/delay.h>
20 #include <linux/if_ether.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/wireless.h>
25 #include <linux/random.h>
26 #include <linux/etherdevice.h>
27 #include <linux/rtnetlink.h>
28 #include <net/iw_handler.h>
29 #include <asm/types.h>
31 #include <net/mac80211.h>
32 #include "ieee80211_i.h"
37 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
38 #define IEEE80211_AUTH_MAX_TRIES 3
39 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
40 #define IEEE80211_ASSOC_MAX_TRIES 3
41 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
42 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
43 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
44 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
45 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
46 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
47 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
49 #define IEEE80211_PROBE_DELAY (HZ / 33)
50 #define IEEE80211_CHANNEL_TIME (HZ / 33)
51 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
52 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
53 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
54 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
55 #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
57 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
60 #define ERP_INFO_USE_PROTECTION BIT(1)
62 /* mgmt header + 1 byte action code */
63 #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
65 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
66 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
67 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
68 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
69 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
71 /* next values represent the buffer size for A-MPDU frame.
72 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
73 #define IEEE80211_MIN_AMPDU_BUF 0x8
74 #define IEEE80211_MAX_AMPDU_BUF 0x40
76 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
77 u8
*ssid
, size_t ssid_len
);
78 static struct ieee80211_sta_bss
*
79 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int freq
,
80 u8
*ssid
, u8 ssid_len
);
81 static void ieee80211_rx_bss_put(struct net_device
*dev
,
82 struct ieee80211_sta_bss
*bss
);
83 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
84 struct ieee80211_if_sta
*ifsta
);
85 static int ieee80211_sta_wep_configured(struct net_device
*dev
);
86 static int ieee80211_sta_start_scan(struct net_device
*dev
,
87 u8
*ssid
, size_t ssid_len
);
88 static int ieee80211_sta_config_auth(struct net_device
*dev
,
89 struct ieee80211_if_sta
*ifsta
);
90 static void sta_rx_agg_session_timer_expired(unsigned long data
);
93 void ieee802_11_parse_elems(u8
*start
, size_t len
,
94 struct ieee802_11_elems
*elems
)
99 memset(elems
, 0, sizeof(*elems
));
114 elems
->ssid_len
= elen
;
116 case WLAN_EID_SUPP_RATES
:
117 elems
->supp_rates
= pos
;
118 elems
->supp_rates_len
= elen
;
120 case WLAN_EID_FH_PARAMS
:
121 elems
->fh_params
= pos
;
122 elems
->fh_params_len
= elen
;
124 case WLAN_EID_DS_PARAMS
:
125 elems
->ds_params
= pos
;
126 elems
->ds_params_len
= elen
;
128 case WLAN_EID_CF_PARAMS
:
129 elems
->cf_params
= pos
;
130 elems
->cf_params_len
= elen
;
134 elems
->tim_len
= elen
;
136 case WLAN_EID_IBSS_PARAMS
:
137 elems
->ibss_params
= pos
;
138 elems
->ibss_params_len
= elen
;
140 case WLAN_EID_CHALLENGE
:
141 elems
->challenge
= pos
;
142 elems
->challenge_len
= elen
;
145 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
147 /* Microsoft OUI (00:50:F2) */
149 /* OUI Type 1 - WPA IE */
151 elems
->wpa_len
= elen
;
152 } else if (elen
>= 5 && pos
[3] == 2) {
154 elems
->wmm_info
= pos
;
155 elems
->wmm_info_len
= elen
;
156 } else if (pos
[4] == 1) {
157 elems
->wmm_param
= pos
;
158 elems
->wmm_param_len
= elen
;
165 elems
->rsn_len
= elen
;
167 case WLAN_EID_ERP_INFO
:
168 elems
->erp_info
= pos
;
169 elems
->erp_info_len
= elen
;
171 case WLAN_EID_EXT_SUPP_RATES
:
172 elems
->ext_supp_rates
= pos
;
173 elems
->ext_supp_rates_len
= elen
;
175 case WLAN_EID_HT_CAPABILITY
:
176 elems
->ht_cap_elem
= pos
;
177 elems
->ht_cap_elem_len
= elen
;
179 case WLAN_EID_HT_EXTRA_INFO
:
180 elems
->ht_info_elem
= pos
;
181 elems
->ht_info_elem_len
= elen
;
183 case WLAN_EID_MESH_ID
:
184 elems
->mesh_id
= pos
;
185 elems
->mesh_id_len
= elen
;
187 case WLAN_EID_MESH_CONFIG
:
188 elems
->mesh_config
= pos
;
189 elems
->mesh_config_len
= elen
;
191 case WLAN_EID_PEER_LINK
:
192 elems
->peer_link
= pos
;
193 elems
->peer_link_len
= elen
;
197 elems
->preq_len
= elen
;
201 elems
->prep_len
= elen
;
205 elems
->perr_len
= elen
;
217 static int ecw2cw(int ecw
)
219 return (1 << ecw
) - 1;
223 static void ieee80211_sta_def_wmm_params(struct net_device
*dev
,
224 struct ieee80211_sta_bss
*bss
,
227 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
228 struct ieee80211_local
*local
= sdata
->local
;
229 int i
, have_higher_than_11mbit
= 0;
232 /* cf. IEEE 802.11 9.2.12 */
233 for (i
= 0; i
< bss
->supp_rates_len
; i
++)
234 if ((bss
->supp_rates
[i
] & 0x7f) * 5 > 110)
235 have_higher_than_11mbit
= 1;
237 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
238 have_higher_than_11mbit
)
239 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
241 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
244 if (local
->ops
->conf_tx
) {
245 struct ieee80211_tx_queue_params qparam
;
247 memset(&qparam
, 0, sizeof(qparam
));
251 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
252 !(sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
))
257 qparam
.cw_max
= 1023;
260 for (i
= 0; i
< local_to_hw(local
)->queues
; i
++)
261 local
->ops
->conf_tx(local_to_hw(local
), i
, &qparam
);
265 static void ieee80211_sta_wmm_params(struct net_device
*dev
,
266 struct ieee80211_if_sta
*ifsta
,
267 u8
*wmm_param
, size_t wmm_param_len
)
269 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
270 struct ieee80211_tx_queue_params params
;
275 if (!(ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
))
281 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
283 count
= wmm_param
[6] & 0x0f;
284 if (count
== ifsta
->wmm_last_param_set
)
286 ifsta
->wmm_last_param_set
= count
;
289 left
= wmm_param_len
- 8;
291 memset(¶ms
, 0, sizeof(params
));
293 if (!local
->ops
->conf_tx
)
297 for (; left
>= 4; left
-= 4, pos
+= 4) {
298 int aci
= (pos
[0] >> 5) & 0x03;
299 int acm
= (pos
[0] >> 4) & 0x01;
306 local
->wmm_acm
|= BIT(0) | BIT(3);
311 local
->wmm_acm
|= BIT(4) | BIT(5);
316 local
->wmm_acm
|= BIT(6) | BIT(7);
322 local
->wmm_acm
|= BIT(1) | BIT(2);
326 params
.aifs
= pos
[0] & 0x0f;
327 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
328 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
329 params
.txop
= pos
[2] | (pos
[3] << 8);
330 #ifdef CONFIG_MAC80211_DEBUG
331 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
332 "cWmin=%d cWmax=%d txop=%d\n",
333 dev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
334 params
.cw_max
, params
.txop
);
336 /* TODO: handle ACM (block TX, fallback to next lowest allowed
338 if (local
->ops
->conf_tx(local_to_hw(local
), queue
, ¶ms
)) {
339 printk(KERN_DEBUG
"%s: failed to set TX queue "
340 "parameters for queue %d\n", dev
->name
, queue
);
345 static u32
ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data
*sdata
,
347 bool use_short_preamble
)
349 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
350 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
351 DECLARE_MAC_BUF(mac
);
354 if (use_protection
!= bss_conf
->use_cts_prot
) {
355 if (net_ratelimit()) {
356 printk(KERN_DEBUG
"%s: CTS protection %s (BSSID="
359 use_protection
? "enabled" : "disabled",
360 print_mac(mac
, ifsta
->bssid
));
362 bss_conf
->use_cts_prot
= use_protection
;
363 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
366 if (use_short_preamble
!= bss_conf
->use_short_preamble
) {
367 if (net_ratelimit()) {
368 printk(KERN_DEBUG
"%s: switched to %s barker preamble"
371 use_short_preamble
? "short" : "long",
372 print_mac(mac
, ifsta
->bssid
));
374 bss_conf
->use_short_preamble
= use_short_preamble
;
375 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
381 static u32
ieee80211_handle_erp_ie(struct ieee80211_sub_if_data
*sdata
,
384 bool use_protection
= (erp_value
& WLAN_ERP_USE_PROTECTION
) != 0;
385 bool use_short_preamble
= (erp_value
& WLAN_ERP_BARKER_PREAMBLE
) == 0;
387 return ieee80211_handle_protect_preamb(sdata
,
388 use_protection
, use_short_preamble
);
391 static u32
ieee80211_handle_bss_capability(struct ieee80211_sub_if_data
*sdata
,
392 struct ieee80211_sta_bss
*bss
)
396 if (bss
->has_erp_value
)
397 changed
|= ieee80211_handle_erp_ie(sdata
, bss
->erp_value
);
399 u16 capab
= bss
->capability
;
400 changed
|= ieee80211_handle_protect_preamb(sdata
, false,
401 (capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
) != 0);
407 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap
*ht_cap_ie
,
408 struct ieee80211_ht_info
*ht_info
)
414 memset(ht_info
, 0, sizeof(*ht_info
));
417 u8 ampdu_info
= ht_cap_ie
->ampdu_params_info
;
419 ht_info
->ht_supported
= 1;
420 ht_info
->cap
= le16_to_cpu(ht_cap_ie
->cap_info
);
421 ht_info
->ampdu_factor
=
422 ampdu_info
& IEEE80211_HT_CAP_AMPDU_FACTOR
;
423 ht_info
->ampdu_density
=
424 (ampdu_info
& IEEE80211_HT_CAP_AMPDU_DENSITY
) >> 2;
425 memcpy(ht_info
->supp_mcs_set
, ht_cap_ie
->supp_mcs_set
, 16);
427 ht_info
->ht_supported
= 0;
432 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
433 struct ieee80211_ht_addt_info
*ht_add_info_ie
,
434 struct ieee80211_ht_bss_info
*bss_info
)
436 if (bss_info
== NULL
)
439 memset(bss_info
, 0, sizeof(*bss_info
));
441 if (ht_add_info_ie
) {
443 op_mode
= le16_to_cpu(ht_add_info_ie
->operation_mode
);
445 bss_info
->primary_channel
= ht_add_info_ie
->control_chan
;
446 bss_info
->bss_cap
= ht_add_info_ie
->ht_param
;
447 bss_info
->bss_op_mode
= (u8
)(op_mode
& 0xff);
453 static void ieee80211_sta_send_associnfo(struct net_device
*dev
,
454 struct ieee80211_if_sta
*ifsta
)
459 union iwreq_data wrqu
;
461 if (!ifsta
->assocreq_ies
&& !ifsta
->assocresp_ies
)
464 buf
= kmalloc(50 + 2 * (ifsta
->assocreq_ies_len
+
465 ifsta
->assocresp_ies_len
), GFP_KERNEL
);
469 len
= sprintf(buf
, "ASSOCINFO(");
470 if (ifsta
->assocreq_ies
) {
471 len
+= sprintf(buf
+ len
, "ReqIEs=");
472 for (i
= 0; i
< ifsta
->assocreq_ies_len
; i
++) {
473 len
+= sprintf(buf
+ len
, "%02x",
474 ifsta
->assocreq_ies
[i
]);
477 if (ifsta
->assocresp_ies
) {
478 if (ifsta
->assocreq_ies
)
479 len
+= sprintf(buf
+ len
, " ");
480 len
+= sprintf(buf
+ len
, "RespIEs=");
481 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
482 len
+= sprintf(buf
+ len
, "%02x",
483 ifsta
->assocresp_ies
[i
]);
486 len
+= sprintf(buf
+ len
, ")");
488 if (len
> IW_CUSTOM_MAX
) {
489 len
= sprintf(buf
, "ASSOCRESPIE=");
490 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
491 len
+= sprintf(buf
+ len
, "%02x",
492 ifsta
->assocresp_ies
[i
]);
496 memset(&wrqu
, 0, sizeof(wrqu
));
497 wrqu
.data
.length
= len
;
498 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
504 static void ieee80211_set_associated(struct net_device
*dev
,
505 struct ieee80211_if_sta
*ifsta
,
508 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
509 struct ieee80211_local
*local
= sdata
->local
;
510 struct ieee80211_conf
*conf
= &local_to_hw(local
)->conf
;
511 union iwreq_data wrqu
;
512 u32 changed
= BSS_CHANGED_ASSOC
;
515 struct ieee80211_sta_bss
*bss
;
517 ifsta
->flags
|= IEEE80211_STA_ASSOCIATED
;
519 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
522 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
523 conf
->channel
->center_freq
,
524 ifsta
->ssid
, ifsta
->ssid_len
);
526 /* set timing information */
527 sdata
->bss_conf
.beacon_int
= bss
->beacon_int
;
528 sdata
->bss_conf
.timestamp
= bss
->timestamp
;
530 changed
|= ieee80211_handle_bss_capability(sdata
, bss
);
532 ieee80211_rx_bss_put(dev
, bss
);
535 if (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
536 changed
|= BSS_CHANGED_HT
;
537 sdata
->bss_conf
.assoc_ht
= 1;
538 sdata
->bss_conf
.ht_conf
= &conf
->ht_conf
;
539 sdata
->bss_conf
.ht_bss_conf
= &conf
->ht_bss_conf
;
542 netif_carrier_on(dev
);
543 ifsta
->flags
|= IEEE80211_STA_PREV_BSSID_SET
;
544 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
545 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
546 ieee80211_sta_send_associnfo(dev
, ifsta
);
548 ieee80211_sta_tear_down_BA_sessions(dev
, ifsta
->bssid
);
549 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
550 netif_carrier_off(dev
);
551 ieee80211_reset_erp_info(dev
);
553 sdata
->bss_conf
.assoc_ht
= 0;
554 sdata
->bss_conf
.ht_conf
= NULL
;
555 sdata
->bss_conf
.ht_bss_conf
= NULL
;
557 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
559 ifsta
->last_probe
= jiffies
;
560 ieee80211_led_assoc(local
, assoc
);
562 sdata
->bss_conf
.assoc
= assoc
;
563 ieee80211_bss_info_change_notify(sdata
, changed
);
564 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
565 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
568 static void ieee80211_set_disassoc(struct net_device
*dev
,
569 struct ieee80211_if_sta
*ifsta
, int deauth
)
572 ifsta
->auth_tries
= 0;
573 ifsta
->assoc_tries
= 0;
574 ieee80211_set_associated(dev
, ifsta
, 0);
577 void ieee80211_sta_tx(struct net_device
*dev
, struct sk_buff
*skb
,
580 struct ieee80211_sub_if_data
*sdata
;
581 struct ieee80211_tx_packet_data
*pkt_data
;
583 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
584 skb
->dev
= sdata
->local
->mdev
;
585 skb_set_mac_header(skb
, 0);
586 skb_set_network_header(skb
, 0);
587 skb_set_transport_header(skb
, 0);
589 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
590 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
591 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
593 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
599 static void ieee80211_send_auth(struct net_device
*dev
,
600 struct ieee80211_if_sta
*ifsta
,
601 int transaction
, u8
*extra
, size_t extra_len
,
604 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
606 struct ieee80211_mgmt
*mgmt
;
608 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
609 sizeof(*mgmt
) + 6 + extra_len
);
611 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
612 "frame\n", dev
->name
);
615 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
617 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
618 memset(mgmt
, 0, 24 + 6);
619 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
620 IEEE80211_STYPE_AUTH
);
622 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
623 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
624 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
625 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
626 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
627 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
628 ifsta
->auth_transaction
= transaction
+ 1;
629 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
631 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
633 ieee80211_sta_tx(dev
, skb
, encrypt
);
637 static void ieee80211_authenticate(struct net_device
*dev
,
638 struct ieee80211_if_sta
*ifsta
)
640 DECLARE_MAC_BUF(mac
);
643 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
644 printk(KERN_DEBUG
"%s: authentication with AP %s"
646 dev
->name
, print_mac(mac
, ifsta
->bssid
));
647 ifsta
->state
= IEEE80211_DISABLED
;
651 ifsta
->state
= IEEE80211_AUTHENTICATE
;
652 printk(KERN_DEBUG
"%s: authenticate with AP %s\n",
653 dev
->name
, print_mac(mac
, ifsta
->bssid
));
655 ieee80211_send_auth(dev
, ifsta
, 1, NULL
, 0, 0);
657 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_AUTH_TIMEOUT
);
660 static int ieee80211_compatible_rates(struct ieee80211_sta_bss
*bss
,
661 struct ieee80211_supported_band
*sband
,
667 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
668 int rate
= (bss
->supp_rates
[i
] & 0x7F) * 5;
670 for (j
= 0; j
< sband
->n_bitrates
; j
++)
671 if (sband
->bitrates
[j
].bitrate
== rate
) {
681 static void ieee80211_send_assoc(struct net_device
*dev
,
682 struct ieee80211_if_sta
*ifsta
)
684 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
686 struct ieee80211_mgmt
*mgmt
;
688 int i
, len
, count
, rates_len
, supp_rates_len
;
690 struct ieee80211_sta_bss
*bss
;
692 struct ieee80211_supported_band
*sband
;
695 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
696 sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
699 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
700 "frame\n", dev
->name
);
703 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
705 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
707 capab
= ifsta
->capab
;
709 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
) {
710 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
711 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
712 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
713 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
716 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
717 local
->hw
.conf
.channel
->center_freq
,
718 ifsta
->ssid
, ifsta
->ssid_len
);
720 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
721 capab
|= WLAN_CAPABILITY_PRIVACY
;
725 /* get all rates supported by the device and the AP as
726 * some APs don't like getting a superset of their rates
727 * in the association request (e.g. D-Link DAP 1353 in
729 rates_len
= ieee80211_compatible_rates(bss
, sband
, &rates
);
731 ieee80211_rx_bss_put(dev
, bss
);
734 rates_len
= sband
->n_bitrates
;
737 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
739 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
740 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
741 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
743 if (ifsta
->flags
& IEEE80211_STA_PREV_BSSID_SET
) {
745 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
746 IEEE80211_STYPE_REASSOC_REQ
);
747 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
748 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
749 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
753 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
754 IEEE80211_STYPE_ASSOC_REQ
);
755 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
756 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
760 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
761 *pos
++ = WLAN_EID_SSID
;
762 *pos
++ = ifsta
->ssid_len
;
763 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
765 /* add all rates which were marked to be used above */
766 supp_rates_len
= rates_len
;
767 if (supp_rates_len
> 8)
770 len
= sband
->n_bitrates
;
771 pos
= skb_put(skb
, supp_rates_len
+ 2);
772 *pos
++ = WLAN_EID_SUPP_RATES
;
773 *pos
++ = supp_rates_len
;
776 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
777 if (BIT(i
) & rates
) {
778 int rate
= sband
->bitrates
[i
].bitrate
;
779 *pos
++ = (u8
) (rate
/ 5);
786 pos
= skb_put(skb
, rates_len
- count
+ 2);
787 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
788 *pos
++ = rates_len
- count
;
790 for (i
++; i
< sband
->n_bitrates
; i
++) {
791 if (BIT(i
) & rates
) {
792 int rate
= sband
->bitrates
[i
].bitrate
;
793 *pos
++ = (u8
) (rate
/ 5);
798 if (ifsta
->extra_ie
) {
799 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
800 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
803 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
804 pos
= skb_put(skb
, 9);
805 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
806 *pos
++ = 7; /* len */
807 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
810 *pos
++ = 2; /* WME */
811 *pos
++ = 0; /* WME info */
812 *pos
++ = 1; /* WME ver */
816 /* wmm support is a must to HT */
817 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
) &&
818 sband
->ht_info
.ht_supported
) {
819 __le16 tmp
= cpu_to_le16(sband
->ht_info
.cap
);
820 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
)+2);
821 *pos
++ = WLAN_EID_HT_CAPABILITY
;
822 *pos
++ = sizeof(struct ieee80211_ht_cap
);
823 memset(pos
, 0, sizeof(struct ieee80211_ht_cap
));
824 memcpy(pos
, &tmp
, sizeof(u16
));
826 /* TODO: needs a define here for << 2 */
827 *pos
++ = sband
->ht_info
.ampdu_factor
|
828 (sband
->ht_info
.ampdu_density
<< 2);
829 memcpy(pos
, sband
->ht_info
.supp_mcs_set
, 16);
832 kfree(ifsta
->assocreq_ies
);
833 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
834 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_KERNEL
);
835 if (ifsta
->assocreq_ies
)
836 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
838 ieee80211_sta_tx(dev
, skb
, 0);
842 static void ieee80211_send_deauth(struct net_device
*dev
,
843 struct ieee80211_if_sta
*ifsta
, u16 reason
)
845 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
847 struct ieee80211_mgmt
*mgmt
;
849 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
851 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
852 "frame\n", dev
->name
);
855 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
857 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
859 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
860 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
861 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
862 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
863 IEEE80211_STYPE_DEAUTH
);
865 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
867 ieee80211_sta_tx(dev
, skb
, 0);
871 static void ieee80211_send_disassoc(struct net_device
*dev
,
872 struct ieee80211_if_sta
*ifsta
, u16 reason
)
874 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
876 struct ieee80211_mgmt
*mgmt
;
878 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
880 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
881 "frame\n", dev
->name
);
884 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
886 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
888 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
889 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
890 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
891 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
892 IEEE80211_STYPE_DISASSOC
);
894 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
896 ieee80211_sta_tx(dev
, skb
, 0);
900 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
901 struct ieee80211_if_sta
*ifsta
)
903 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
904 struct ieee80211_sta_bss
*bss
;
909 if (!ifsta
|| (ifsta
->flags
& IEEE80211_STA_MIXED_CELL
))
912 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
913 local
->hw
.conf
.channel
->center_freq
,
914 ifsta
->ssid
, ifsta
->ssid_len
);
918 bss_privacy
= !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
919 wep_privacy
= !!ieee80211_sta_wep_configured(dev
);
920 privacy_invoked
= !!(ifsta
->flags
& IEEE80211_STA_PRIVACY_INVOKED
);
922 ieee80211_rx_bss_put(dev
, bss
);
924 if ((bss_privacy
== wep_privacy
) || (bss_privacy
== privacy_invoked
))
931 static void ieee80211_associate(struct net_device
*dev
,
932 struct ieee80211_if_sta
*ifsta
)
934 DECLARE_MAC_BUF(mac
);
936 ifsta
->assoc_tries
++;
937 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
938 printk(KERN_DEBUG
"%s: association with AP %s"
940 dev
->name
, print_mac(mac
, ifsta
->bssid
));
941 ifsta
->state
= IEEE80211_DISABLED
;
945 ifsta
->state
= IEEE80211_ASSOCIATE
;
946 printk(KERN_DEBUG
"%s: associate with AP %s\n",
947 dev
->name
, print_mac(mac
, ifsta
->bssid
));
948 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
949 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
950 "mixed-cell disabled - abort association\n", dev
->name
);
951 ifsta
->state
= IEEE80211_DISABLED
;
955 ieee80211_send_assoc(dev
, ifsta
);
957 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_ASSOC_TIMEOUT
);
961 static void ieee80211_associated(struct net_device
*dev
,
962 struct ieee80211_if_sta
*ifsta
)
964 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
965 struct sta_info
*sta
;
967 DECLARE_MAC_BUF(mac
);
969 /* TODO: start monitoring current AP signal quality and number of
970 * missed beacons. Scan other channels every now and then and search
972 /* TODO: remove expired BSSes */
974 ifsta
->state
= IEEE80211_ASSOCIATED
;
978 sta
= sta_info_get(local
, ifsta
->bssid
);
980 printk(KERN_DEBUG
"%s: No STA entry for own AP %s\n",
981 dev
->name
, print_mac(mac
, ifsta
->bssid
));
985 if (time_after(jiffies
,
986 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
987 if (ifsta
->flags
& IEEE80211_STA_PROBEREQ_POLL
) {
988 printk(KERN_DEBUG
"%s: No ProbeResp from "
989 "current AP %s - assume out of "
991 dev
->name
, print_mac(mac
, ifsta
->bssid
));
993 sta_info_unlink(&sta
);
995 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
997 local
->scan_ssid_len
);
998 ifsta
->flags
^= IEEE80211_STA_PROBEREQ_POLL
;
1000 ifsta
->flags
&= ~IEEE80211_STA_PROBEREQ_POLL
;
1001 if (time_after(jiffies
, ifsta
->last_probe
+
1002 IEEE80211_PROBE_INTERVAL
)) {
1003 ifsta
->last_probe
= jiffies
;
1004 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
1013 if (disassoc
&& sta
)
1014 sta_info_destroy(sta
);
1017 ifsta
->state
= IEEE80211_DISABLED
;
1018 ieee80211_set_associated(dev
, ifsta
, 0);
1020 mod_timer(&ifsta
->timer
, jiffies
+
1021 IEEE80211_MONITORING_INTERVAL
);
1026 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
1027 u8
*ssid
, size_t ssid_len
)
1029 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1030 struct ieee80211_supported_band
*sband
;
1031 struct sk_buff
*skb
;
1032 struct ieee80211_mgmt
*mgmt
;
1033 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
1036 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200);
1038 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
1039 "request\n", dev
->name
);
1042 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1044 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1045 memset(mgmt
, 0, 24);
1046 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1047 IEEE80211_STYPE_PROBE_REQ
);
1048 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1050 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
1051 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
1053 memset(mgmt
->da
, 0xff, ETH_ALEN
);
1054 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
1056 pos
= skb_put(skb
, 2 + ssid_len
);
1057 *pos
++ = WLAN_EID_SSID
;
1059 memcpy(pos
, ssid
, ssid_len
);
1061 supp_rates
= skb_put(skb
, 2);
1062 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
1064 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
1066 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1067 struct ieee80211_rate
*rate
= &sband
->bitrates
[i
];
1069 pos
= skb_put(skb
, 1);
1071 } else if (supp_rates
[1] == 8) {
1072 esupp_rates
= skb_put(skb
, 3);
1073 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
1075 pos
= &esupp_rates
[2];
1077 pos
= skb_put(skb
, 1);
1080 *pos
= rate
->bitrate
/ 5;
1083 ieee80211_sta_tx(dev
, skb
, 0);
1087 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
1089 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1090 if (!sdata
|| !sdata
->default_key
||
1091 sdata
->default_key
->conf
.alg
!= ALG_WEP
)
1097 static void ieee80211_auth_completed(struct net_device
*dev
,
1098 struct ieee80211_if_sta
*ifsta
)
1100 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
1101 ifsta
->flags
|= IEEE80211_STA_AUTHENTICATED
;
1102 ieee80211_associate(dev
, ifsta
);
1106 static void ieee80211_auth_challenge(struct net_device
*dev
,
1107 struct ieee80211_if_sta
*ifsta
,
1108 struct ieee80211_mgmt
*mgmt
,
1112 struct ieee802_11_elems elems
;
1114 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
1115 pos
= mgmt
->u
.auth
.variable
;
1116 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1117 if (!elems
.challenge
) {
1118 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
1119 "frame\n", dev
->name
);
1122 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
1123 elems
.challenge_len
+ 2, 1);
1126 static void ieee80211_send_addba_resp(struct net_device
*dev
, u8
*da
, u16 tid
,
1127 u8 dialog_token
, u16 status
, u16 policy
,
1128 u16 buf_size
, u16 timeout
)
1130 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1131 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1132 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1133 struct sk_buff
*skb
;
1134 struct ieee80211_mgmt
*mgmt
;
1137 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
);
1140 printk(KERN_DEBUG
"%s: failed to allocate buffer "
1141 "for addba resp frame\n", dev
->name
);
1145 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1146 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1147 memset(mgmt
, 0, 24);
1148 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1149 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1150 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1151 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1153 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1154 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1155 IEEE80211_STYPE_ACTION
);
1157 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_resp
));
1158 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1159 mgmt
->u
.action
.u
.addba_resp
.action_code
= WLAN_ACTION_ADDBA_RESP
;
1160 mgmt
->u
.action
.u
.addba_resp
.dialog_token
= dialog_token
;
1162 capab
= (u16
)(policy
<< 1); /* bit 1 aggregation policy */
1163 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1164 capab
|= (u16
)(buf_size
<< 6); /* bit 15:6 max size of aggregation */
1166 mgmt
->u
.action
.u
.addba_resp
.capab
= cpu_to_le16(capab
);
1167 mgmt
->u
.action
.u
.addba_resp
.timeout
= cpu_to_le16(timeout
);
1168 mgmt
->u
.action
.u
.addba_resp
.status
= cpu_to_le16(status
);
1170 ieee80211_sta_tx(dev
, skb
, 0);
1175 void ieee80211_send_addba_request(struct net_device
*dev
, const u8
*da
,
1176 u16 tid
, u8 dialog_token
, u16 start_seq_num
,
1177 u16 agg_size
, u16 timeout
)
1179 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1180 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1181 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1182 struct sk_buff
*skb
;
1183 struct ieee80211_mgmt
*mgmt
;
1186 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
);
1189 printk(KERN_ERR
"%s: failed to allocate buffer "
1190 "for addba request frame\n", dev
->name
);
1193 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1194 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1195 memset(mgmt
, 0, 24);
1196 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1197 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1198 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1199 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1201 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1203 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1204 IEEE80211_STYPE_ACTION
);
1206 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_req
));
1208 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1209 mgmt
->u
.action
.u
.addba_req
.action_code
= WLAN_ACTION_ADDBA_REQ
;
1211 mgmt
->u
.action
.u
.addba_req
.dialog_token
= dialog_token
;
1212 capab
= (u16
)(1 << 1); /* bit 1 aggregation policy */
1213 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1214 capab
|= (u16
)(agg_size
<< 6); /* bit 15:6 max size of aggergation */
1216 mgmt
->u
.action
.u
.addba_req
.capab
= cpu_to_le16(capab
);
1218 mgmt
->u
.action
.u
.addba_req
.timeout
= cpu_to_le16(timeout
);
1219 mgmt
->u
.action
.u
.addba_req
.start_seq_num
=
1220 cpu_to_le16(start_seq_num
<< 4);
1222 ieee80211_sta_tx(dev
, skb
, 0);
1225 static void ieee80211_sta_process_addba_request(struct net_device
*dev
,
1226 struct ieee80211_mgmt
*mgmt
,
1229 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1230 struct ieee80211_hw
*hw
= &local
->hw
;
1231 struct ieee80211_conf
*conf
= &hw
->conf
;
1232 struct sta_info
*sta
;
1233 struct tid_ampdu_rx
*tid_agg_rx
;
1234 u16 capab
, tid
, timeout
, ba_policy
, buf_size
, start_seq_num
, status
;
1236 int ret
= -EOPNOTSUPP
;
1237 DECLARE_MAC_BUF(mac
);
1241 sta
= sta_info_get(local
, mgmt
->sa
);
1247 /* extract session parameters from addba request frame */
1248 dialog_token
= mgmt
->u
.action
.u
.addba_req
.dialog_token
;
1249 timeout
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.timeout
);
1251 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.start_seq_num
) >> 4;
1253 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1254 ba_policy
= (capab
& IEEE80211_ADDBA_PARAM_POLICY_MASK
) >> 1;
1255 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1256 buf_size
= (capab
& IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
) >> 6;
1258 status
= WLAN_STATUS_REQUEST_DECLINED
;
1260 /* sanity check for incoming parameters:
1261 * check if configuration can support the BA policy
1262 * and if buffer size does not exceeds max value */
1263 if (((ba_policy
!= 1)
1264 && (!(conf
->ht_conf
.cap
& IEEE80211_HT_CAP_DELAY_BA
)))
1265 || (buf_size
> IEEE80211_MAX_AMPDU_BUF
)) {
1266 status
= WLAN_STATUS_INVALID_QOS_PARAM
;
1267 #ifdef CONFIG_MAC80211_HT_DEBUG
1268 if (net_ratelimit())
1269 printk(KERN_DEBUG
"AddBA Req with bad params from "
1270 "%s on tid %u. policy %d, buffer size %d\n",
1271 print_mac(mac
, mgmt
->sa
), tid
, ba_policy
,
1273 #endif /* CONFIG_MAC80211_HT_DEBUG */
1276 /* determine default buffer size */
1277 if (buf_size
== 0) {
1278 struct ieee80211_supported_band
*sband
;
1280 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
1281 buf_size
= IEEE80211_MIN_AMPDU_BUF
;
1282 buf_size
= buf_size
<< sband
->ht_info
.ampdu_factor
;
1286 /* examine state machine */
1287 spin_lock_bh(&sta
->lock
);
1289 if (sta
->ampdu_mlme
.tid_state_rx
[tid
] != HT_AGG_STATE_IDLE
) {
1290 #ifdef CONFIG_MAC80211_HT_DEBUG
1291 if (net_ratelimit())
1292 printk(KERN_DEBUG
"unexpected AddBA Req from "
1294 print_mac(mac
, mgmt
->sa
), tid
);
1295 #endif /* CONFIG_MAC80211_HT_DEBUG */
1299 /* prepare A-MPDU MLME for Rx aggregation */
1300 sta
->ampdu_mlme
.tid_rx
[tid
] =
1301 kmalloc(sizeof(struct tid_ampdu_rx
), GFP_ATOMIC
);
1302 if (!sta
->ampdu_mlme
.tid_rx
[tid
]) {
1303 if (net_ratelimit())
1304 printk(KERN_ERR
"allocate rx mlme to tid %d failed\n",
1309 sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
.function
=
1310 sta_rx_agg_session_timer_expired
;
1311 sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
.data
=
1312 (unsigned long)&sta
->timer_to_tid
[tid
];
1313 init_timer(&sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
);
1315 tid_agg_rx
= sta
->ampdu_mlme
.tid_rx
[tid
];
1317 /* prepare reordering buffer */
1318 tid_agg_rx
->reorder_buf
=
1319 kmalloc(buf_size
* sizeof(struct sk_buf
*), GFP_ATOMIC
);
1320 if (!tid_agg_rx
->reorder_buf
) {
1321 if (net_ratelimit())
1322 printk(KERN_ERR
"can not allocate reordering buffer "
1323 "to tid %d\n", tid
);
1324 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]);
1327 memset(tid_agg_rx
->reorder_buf
, 0,
1328 buf_size
* sizeof(struct sk_buf
*));
1330 if (local
->ops
->ampdu_action
)
1331 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_START
,
1332 sta
->addr
, tid
, &start_seq_num
);
1333 #ifdef CONFIG_MAC80211_HT_DEBUG
1334 printk(KERN_DEBUG
"Rx A-MPDU request on tid %d result %d\n", tid
, ret
);
1335 #endif /* CONFIG_MAC80211_HT_DEBUG */
1338 kfree(tid_agg_rx
->reorder_buf
);
1340 sta
->ampdu_mlme
.tid_rx
[tid
] = NULL
;
1344 /* change state and send addba resp */
1345 sta
->ampdu_mlme
.tid_state_rx
[tid
] = HT_AGG_STATE_OPERATIONAL
;
1346 tid_agg_rx
->dialog_token
= dialog_token
;
1347 tid_agg_rx
->ssn
= start_seq_num
;
1348 tid_agg_rx
->head_seq_num
= start_seq_num
;
1349 tid_agg_rx
->buf_size
= buf_size
;
1350 tid_agg_rx
->timeout
= timeout
;
1351 tid_agg_rx
->stored_mpdu_num
= 0;
1352 status
= WLAN_STATUS_SUCCESS
;
1354 spin_unlock_bh(&sta
->lock
);
1357 ieee80211_send_addba_resp(sta
->sdata
->dev
, sta
->addr
, tid
,
1358 dialog_token
, status
, 1, buf_size
, timeout
);
1362 static void ieee80211_sta_process_addba_resp(struct net_device
*dev
,
1363 struct ieee80211_mgmt
*mgmt
,
1366 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1367 struct ieee80211_hw
*hw
= &local
->hw
;
1368 struct sta_info
*sta
;
1375 sta
= sta_info_get(local
, mgmt
->sa
);
1381 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.capab
);
1382 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1384 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
1386 spin_lock_bh(&sta
->lock
);
1388 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1389 spin_unlock_bh(&sta
->lock
);
1390 printk(KERN_DEBUG
"state not HT_ADDBA_REQUESTED_MSK:"
1392 goto addba_resp_exit
;
1395 if (mgmt
->u
.action
.u
.addba_resp
.dialog_token
!=
1396 sta
->ampdu_mlme
.tid_tx
[tid
]->dialog_token
) {
1397 spin_unlock_bh(&sta
->lock
);
1398 #ifdef CONFIG_MAC80211_HT_DEBUG
1399 printk(KERN_DEBUG
"wrong addBA response token, tid %d\n", tid
);
1400 #endif /* CONFIG_MAC80211_HT_DEBUG */
1401 goto addba_resp_exit
;
1404 del_timer_sync(&sta
->ampdu_mlme
.tid_tx
[tid
]->addba_resp_timer
);
1405 #ifdef CONFIG_MAC80211_HT_DEBUG
1406 printk(KERN_DEBUG
"switched off addBA timer for tid %d \n", tid
);
1407 #endif /* CONFIG_MAC80211_HT_DEBUG */
1408 if (le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.status
)
1409 == WLAN_STATUS_SUCCESS
) {
1410 if (*state
& HT_ADDBA_RECEIVED_MSK
)
1411 printk(KERN_DEBUG
"double addBA response\n");
1413 *state
|= HT_ADDBA_RECEIVED_MSK
;
1414 sta
->ampdu_mlme
.addba_req_num
[tid
] = 0;
1416 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
1417 printk(KERN_DEBUG
"Aggregation on for tid %d \n", tid
);
1418 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
1421 spin_unlock_bh(&sta
->lock
);
1422 printk(KERN_DEBUG
"recipient accepted agg: tid %d \n", tid
);
1424 printk(KERN_DEBUG
"recipient rejected agg: tid %d \n", tid
);
1426 sta
->ampdu_mlme
.addba_req_num
[tid
]++;
1427 /* this will allow the state check in stop_BA_session */
1428 *state
= HT_AGG_STATE_OPERATIONAL
;
1429 spin_unlock_bh(&sta
->lock
);
1430 ieee80211_stop_tx_ba_session(hw
, sta
->addr
, tid
,
1431 WLAN_BACK_INITIATOR
);
1438 void ieee80211_send_delba(struct net_device
*dev
, const u8
*da
, u16 tid
,
1439 u16 initiator
, u16 reason_code
)
1441 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1442 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1443 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1444 struct sk_buff
*skb
;
1445 struct ieee80211_mgmt
*mgmt
;
1448 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
);
1451 printk(KERN_ERR
"%s: failed to allocate buffer "
1452 "for delba frame\n", dev
->name
);
1456 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1457 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1458 memset(mgmt
, 0, 24);
1459 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1460 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1461 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1462 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1464 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1465 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1466 IEEE80211_STYPE_ACTION
);
1468 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.delba
));
1470 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1471 mgmt
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
1472 params
= (u16
)(initiator
<< 11); /* bit 11 initiator */
1473 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
1475 mgmt
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
1476 mgmt
->u
.action
.u
.delba
.reason_code
= cpu_to_le16(reason_code
);
1478 ieee80211_sta_tx(dev
, skb
, 0);
1481 void ieee80211_sta_stop_rx_ba_session(struct net_device
*dev
, u8
*ra
, u16 tid
,
1482 u16 initiator
, u16 reason
)
1484 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1485 struct ieee80211_hw
*hw
= &local
->hw
;
1486 struct sta_info
*sta
;
1488 DECLARE_MAC_BUF(mac
);
1492 sta
= sta_info_get(local
, ra
);
1498 /* check if TID is in operational state */
1499 spin_lock_bh(&sta
->lock
);
1500 if (sta
->ampdu_mlme
.tid_state_rx
[tid
]
1501 != HT_AGG_STATE_OPERATIONAL
) {
1502 spin_unlock_bh(&sta
->lock
);
1506 sta
->ampdu_mlme
.tid_state_rx
[tid
] =
1507 HT_AGG_STATE_REQ_STOP_BA_MSK
|
1508 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
1509 spin_unlock_bh(&sta
->lock
);
1511 /* stop HW Rx aggregation. ampdu_action existence
1512 * already verified in session init so we add the BUG_ON */
1513 BUG_ON(!local
->ops
->ampdu_action
);
1515 #ifdef CONFIG_MAC80211_HT_DEBUG
1516 printk(KERN_DEBUG
"Rx BA session stop requested for %s tid %u\n",
1517 print_mac(mac
, ra
), tid
);
1518 #endif /* CONFIG_MAC80211_HT_DEBUG */
1520 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_STOP
,
1523 printk(KERN_DEBUG
"HW problem - can not stop rx "
1524 "aggergation for tid %d\n", tid
);
1526 /* shutdown timer has not expired */
1527 if (initiator
!= WLAN_BACK_TIMER
)
1528 del_timer_sync(&sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
);
1530 /* check if this is a self generated aggregation halt */
1531 if (initiator
== WLAN_BACK_RECIPIENT
|| initiator
== WLAN_BACK_TIMER
)
1532 ieee80211_send_delba(dev
, ra
, tid
, 0, reason
);
1534 /* free the reordering buffer */
1535 for (i
= 0; i
< sta
->ampdu_mlme
.tid_rx
[tid
]->buf_size
; i
++) {
1536 if (sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
]) {
1537 /* release the reordered frames */
1538 dev_kfree_skb(sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
]);
1539 sta
->ampdu_mlme
.tid_rx
[tid
]->stored_mpdu_num
--;
1540 sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
] = NULL
;
1543 /* free resources */
1544 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
);
1545 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]);
1546 sta
->ampdu_mlme
.tid_rx
[tid
] = NULL
;
1547 sta
->ampdu_mlme
.tid_state_rx
[tid
] = HT_AGG_STATE_IDLE
;
1553 static void ieee80211_sta_process_delba(struct net_device
*dev
,
1554 struct ieee80211_mgmt
*mgmt
, size_t len
)
1556 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1557 struct sta_info
*sta
;
1560 DECLARE_MAC_BUF(mac
);
1564 sta
= sta_info_get(local
, mgmt
->sa
);
1570 params
= le16_to_cpu(mgmt
->u
.action
.u
.delba
.params
);
1571 tid
= (params
& IEEE80211_DELBA_PARAM_TID_MASK
) >> 12;
1572 initiator
= (params
& IEEE80211_DELBA_PARAM_INITIATOR_MASK
) >> 11;
1574 #ifdef CONFIG_MAC80211_HT_DEBUG
1575 if (net_ratelimit())
1576 printk(KERN_DEBUG
"delba from %s (%s) tid %d reason code %d\n",
1577 print_mac(mac
, mgmt
->sa
),
1578 initiator
? "initiator" : "recipient", tid
,
1579 mgmt
->u
.action
.u
.delba
.reason_code
);
1580 #endif /* CONFIG_MAC80211_HT_DEBUG */
1582 if (initiator
== WLAN_BACK_INITIATOR
)
1583 ieee80211_sta_stop_rx_ba_session(dev
, sta
->addr
, tid
,
1584 WLAN_BACK_INITIATOR
, 0);
1585 else { /* WLAN_BACK_RECIPIENT */
1586 spin_lock_bh(&sta
->lock
);
1587 sta
->ampdu_mlme
.tid_state_tx
[tid
] =
1588 HT_AGG_STATE_OPERATIONAL
;
1589 spin_unlock_bh(&sta
->lock
);
1590 ieee80211_stop_tx_ba_session(&local
->hw
, sta
->addr
, tid
,
1591 WLAN_BACK_RECIPIENT
);
1597 * After sending add Block Ack request we activated a timer until
1598 * add Block Ack response will arrive from the recipient.
1599 * If this timer expires sta_addba_resp_timer_expired will be executed.
1601 void sta_addba_resp_timer_expired(unsigned long data
)
1603 /* not an elegant detour, but there is no choice as the timer passes
1604 * only one argument, and both sta_info and TID are needed, so init
1605 * flow in sta_info_create gives the TID as data, while the timer_to_id
1606 * array gives the sta through container_of */
1607 u16 tid
= *(int *)data
;
1608 struct sta_info
*temp_sta
= container_of((void *)data
,
1609 struct sta_info
, timer_to_tid
[tid
]);
1611 struct ieee80211_local
*local
= temp_sta
->local
;
1612 struct ieee80211_hw
*hw
= &local
->hw
;
1613 struct sta_info
*sta
;
1618 sta
= sta_info_get(local
, temp_sta
->addr
);
1624 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
1625 /* check if the TID waits for addBA response */
1626 spin_lock_bh(&sta
->lock
);
1627 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1628 spin_unlock_bh(&sta
->lock
);
1629 *state
= HT_AGG_STATE_IDLE
;
1630 printk(KERN_DEBUG
"timer expired on tid %d but we are not "
1631 "expecting addBA response there", tid
);
1632 goto timer_expired_exit
;
1635 printk(KERN_DEBUG
"addBA response timer expired on tid %d\n", tid
);
1637 /* go through the state check in stop_BA_session */
1638 *state
= HT_AGG_STATE_OPERATIONAL
;
1639 spin_unlock_bh(&sta
->lock
);
1640 ieee80211_stop_tx_ba_session(hw
, temp_sta
->addr
, tid
,
1641 WLAN_BACK_INITIATOR
);
1648 * After accepting the AddBA Request we activated a timer,
1649 * resetting it after each frame that arrives from the originator.
1650 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1652 static void sta_rx_agg_session_timer_expired(unsigned long data
)
1654 /* not an elegant detour, but there is no choice as the timer passes
1655 * only one argument, and verious sta_info are needed here, so init
1656 * flow in sta_info_create gives the TID as data, while the timer_to_id
1657 * array gives the sta through container_of */
1658 u8
*ptid
= (u8
*)data
;
1659 u8
*timer_to_id
= ptid
- *ptid
;
1660 struct sta_info
*sta
= container_of(timer_to_id
, struct sta_info
,
1663 printk(KERN_DEBUG
"rx session timer expired on tid %d\n", (u16
)*ptid
);
1664 ieee80211_sta_stop_rx_ba_session(sta
->sdata
->dev
, sta
->addr
,
1665 (u16
)*ptid
, WLAN_BACK_TIMER
,
1666 WLAN_REASON_QSTA_TIMEOUT
);
1669 void ieee80211_sta_tear_down_BA_sessions(struct net_device
*dev
, u8
*addr
)
1671 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1674 for (i
= 0; i
< STA_TID_NUM
; i
++) {
1675 ieee80211_stop_tx_ba_session(&local
->hw
, addr
, i
,
1676 WLAN_BACK_INITIATOR
);
1677 ieee80211_sta_stop_rx_ba_session(dev
, addr
, i
,
1678 WLAN_BACK_RECIPIENT
,
1679 WLAN_REASON_QSTA_LEAVE_QBSS
);
1683 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
1684 struct ieee80211_if_sta
*ifsta
,
1685 struct ieee80211_mgmt
*mgmt
,
1688 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1689 u16 auth_alg
, auth_transaction
, status_code
;
1690 DECLARE_MAC_BUF(mac
);
1692 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
1693 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
) {
1694 printk(KERN_DEBUG
"%s: authentication frame received from "
1695 "%s, but not in authenticate state - ignored\n",
1696 dev
->name
, print_mac(mac
, mgmt
->sa
));
1701 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
1702 "received from %s - ignored\n",
1703 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1707 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1708 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1709 printk(KERN_DEBUG
"%s: authentication frame received from "
1710 "unknown AP (SA=%s BSSID=%s) - "
1711 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1712 print_mac(mac
, mgmt
->bssid
));
1716 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1717 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
1718 printk(KERN_DEBUG
"%s: authentication frame received from "
1719 "unknown BSSID (SA=%s BSSID=%s) - "
1720 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1721 print_mac(mac
, mgmt
->bssid
));
1725 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
1726 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
1727 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
1729 printk(KERN_DEBUG
"%s: RX authentication from %s (alg=%d "
1730 "transaction=%d status=%d)\n",
1731 dev
->name
, print_mac(mac
, mgmt
->sa
), auth_alg
,
1732 auth_transaction
, status_code
);
1734 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
1735 /* IEEE 802.11 standard does not require authentication in IBSS
1736 * networks and most implementations do not seem to use it.
1737 * However, try to reply to authentication attempts if someone
1738 * has actually implemented this.
1739 * TODO: Could implement shared key authentication. */
1740 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
1741 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
1742 "frame (alg=%d transaction=%d)\n",
1743 dev
->name
, auth_alg
, auth_transaction
);
1746 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
1749 if (auth_alg
!= ifsta
->auth_alg
||
1750 auth_transaction
!= ifsta
->auth_transaction
) {
1751 printk(KERN_DEBUG
"%s: unexpected authentication frame "
1752 "(alg=%d transaction=%d)\n",
1753 dev
->name
, auth_alg
, auth_transaction
);
1757 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1758 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
1759 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
1760 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
1762 const int num_algs
= ARRAY_SIZE(algs
);
1764 algs
[0] = algs
[1] = algs
[2] = 0xff;
1765 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1766 algs
[0] = WLAN_AUTH_OPEN
;
1767 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1768 algs
[1] = WLAN_AUTH_SHARED_KEY
;
1769 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1770 algs
[2] = WLAN_AUTH_LEAP
;
1771 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
1773 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
1777 for (i
= 0; i
< num_algs
; i
++) {
1779 if (pos
>= num_algs
)
1781 if (algs
[pos
] == ifsta
->auth_alg
||
1784 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
1785 !ieee80211_sta_wep_configured(dev
))
1787 ifsta
->auth_alg
= algs
[pos
];
1788 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
1790 dev
->name
, ifsta
->auth_alg
);
1797 switch (ifsta
->auth_alg
) {
1798 case WLAN_AUTH_OPEN
:
1799 case WLAN_AUTH_LEAP
:
1800 ieee80211_auth_completed(dev
, ifsta
);
1802 case WLAN_AUTH_SHARED_KEY
:
1803 if (ifsta
->auth_transaction
== 4)
1804 ieee80211_auth_completed(dev
, ifsta
);
1806 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
);
1812 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
1813 struct ieee80211_if_sta
*ifsta
,
1814 struct ieee80211_mgmt
*mgmt
,
1818 DECLARE_MAC_BUF(mac
);
1821 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
1822 "received from %s - ignored\n",
1823 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1827 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1828 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1829 "unknown AP (SA=%s BSSID=%s) - "
1830 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1831 print_mac(mac
, mgmt
->bssid
));
1835 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1837 printk(KERN_DEBUG
"%s: RX deauthentication from %s"
1839 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1841 if (ifsta
->flags
& IEEE80211_STA_AUTHENTICATED
)
1842 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1844 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1845 ifsta
->state
== IEEE80211_ASSOCIATE
||
1846 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1847 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1848 mod_timer(&ifsta
->timer
, jiffies
+
1849 IEEE80211_RETRY_AUTH_INTERVAL
);
1852 ieee80211_set_disassoc(dev
, ifsta
, 1);
1853 ifsta
->flags
&= ~IEEE80211_STA_AUTHENTICATED
;
1857 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1858 struct ieee80211_if_sta
*ifsta
,
1859 struct ieee80211_mgmt
*mgmt
,
1863 DECLARE_MAC_BUF(mac
);
1866 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1867 "received from %s - ignored\n",
1868 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1872 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1873 printk(KERN_DEBUG
"%s: disassociation frame received from "
1874 "unknown AP (SA=%s BSSID=%s) - "
1875 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1876 print_mac(mac
, mgmt
->bssid
));
1880 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1882 printk(KERN_DEBUG
"%s: RX disassociation from %s"
1884 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1886 if (ifsta
->flags
& IEEE80211_STA_ASSOCIATED
)
1887 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1889 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1890 ifsta
->state
= IEEE80211_ASSOCIATE
;
1891 mod_timer(&ifsta
->timer
, jiffies
+
1892 IEEE80211_RETRY_AUTH_INTERVAL
);
1895 ieee80211_set_disassoc(dev
, ifsta
, 0);
1899 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
1900 struct ieee80211_if_sta
*ifsta
,
1901 struct ieee80211_mgmt
*mgmt
,
1905 struct ieee80211_local
*local
= sdata
->local
;
1906 struct net_device
*dev
= sdata
->dev
;
1907 struct ieee80211_supported_band
*sband
;
1908 struct sta_info
*sta
;
1909 u64 rates
, basic_rates
;
1910 u16 capab_info
, status_code
, aid
;
1911 struct ieee802_11_elems elems
;
1912 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
1915 DECLARE_MAC_BUF(mac
);
1916 bool have_higher_than_11mbit
= false;
1918 /* AssocResp and ReassocResp have identical structure, so process both
1919 * of them in this function. */
1921 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1922 printk(KERN_DEBUG
"%s: association frame received from "
1923 "%s, but not in associate state - ignored\n",
1924 dev
->name
, print_mac(mac
, mgmt
->sa
));
1929 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1930 "received from %s - ignored\n",
1931 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1935 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1936 printk(KERN_DEBUG
"%s: association frame received from "
1937 "unknown AP (SA=%s BSSID=%s) - "
1938 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1939 print_mac(mac
, mgmt
->bssid
));
1943 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1944 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1945 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1947 printk(KERN_DEBUG
"%s: RX %sssocResp from %s (capab=0x%x "
1948 "status=%d aid=%d)\n",
1949 dev
->name
, reassoc
? "Rea" : "A", print_mac(mac
, mgmt
->sa
),
1950 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
1952 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1953 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1954 dev
->name
, status_code
);
1955 /* if this was a reassociation, ensure we try a "full"
1956 * association next time. This works around some broken APs
1957 * which do not correctly reject reassociation requests. */
1958 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
1962 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1963 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1964 "set\n", dev
->name
, aid
);
1965 aid
&= ~(BIT(15) | BIT(14));
1967 pos
= mgmt
->u
.assoc_resp
.variable
;
1968 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1970 if (!elems
.supp_rates
) {
1971 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1976 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1978 ifsta
->ap_capab
= capab_info
;
1980 kfree(ifsta
->assocresp_ies
);
1981 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1982 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_KERNEL
);
1983 if (ifsta
->assocresp_ies
)
1984 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1988 /* Add STA entry for the AP */
1989 sta
= sta_info_get(local
, ifsta
->bssid
);
1991 struct ieee80211_sta_bss
*bss
;
1994 sta
= sta_info_alloc(sdata
, ifsta
->bssid
, GFP_ATOMIC
);
1996 printk(KERN_DEBUG
"%s: failed to alloc STA entry for"
1997 " the AP\n", dev
->name
);
2001 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
2002 local
->hw
.conf
.channel
->center_freq
,
2003 ifsta
->ssid
, ifsta
->ssid_len
);
2005 sta
->last_signal
= bss
->signal
;
2006 sta
->last_qual
= bss
->qual
;
2007 sta
->last_noise
= bss
->noise
;
2008 ieee80211_rx_bss_put(dev
, bss
);
2011 err
= sta_info_insert(sta
);
2013 printk(KERN_DEBUG
"%s: failed to insert STA entry for"
2014 " the AP (error %d)\n", dev
->name
, err
);
2021 * FIXME: Do we really need to update the sta_info's information here?
2022 * We already know about the AP (we found it in our list) so it
2023 * should already be filled with the right info, no?
2024 * As is stands, all this is racy because typically we assume
2025 * the information that is filled in here (except flags) doesn't
2026 * change while a STA structure is alive. As such, it should move
2027 * to between the sta_info_alloc() and sta_info_insert() above.
2030 set_sta_flags(sta
, WLAN_STA_AUTH
| WLAN_STA_ASSOC
| WLAN_STA_ASSOC_AP
|
2031 WLAN_STA_AUTHORIZED
);
2035 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2037 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
2038 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
2041 have_higher_than_11mbit
= true;
2043 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2044 if (sband
->bitrates
[j
].bitrate
== rate
)
2046 if (elems
.supp_rates
[i
] & 0x80)
2047 basic_rates
|= BIT(j
);
2051 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
2052 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
2055 have_higher_than_11mbit
= true;
2057 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2058 if (sband
->bitrates
[j
].bitrate
== rate
)
2060 if (elems
.ext_supp_rates
[i
] & 0x80)
2061 basic_rates
|= BIT(j
);
2065 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] = rates
;
2066 sdata
->basic_rates
= basic_rates
;
2068 /* cf. IEEE 802.11 9.2.12 */
2069 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
2070 have_higher_than_11mbit
)
2071 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
2073 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
2075 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&& elems
.wmm_param
&&
2076 (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
2077 struct ieee80211_ht_bss_info bss_info
;
2078 ieee80211_ht_cap_ie_to_ht_info(
2079 (struct ieee80211_ht_cap
*)
2080 elems
.ht_cap_elem
, &sta
->ht_info
);
2081 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2082 (struct ieee80211_ht_addt_info
*)
2083 elems
.ht_info_elem
, &bss_info
);
2084 ieee80211_handle_ht(local
, 1, &sta
->ht_info
, &bss_info
);
2087 rate_control_rate_init(sta
, local
);
2089 if (elems
.wmm_param
) {
2090 set_sta_flags(sta
, WLAN_STA_WME
);
2092 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2093 elems
.wmm_param_len
);
2097 /* set AID and assoc capability,
2098 * ieee80211_set_associated() will tell the driver */
2099 bss_conf
->aid
= aid
;
2100 bss_conf
->assoc_capability
= capab_info
;
2101 ieee80211_set_associated(dev
, ifsta
, 1);
2103 ieee80211_associated(dev
, ifsta
);
2107 /* Caller must hold local->sta_bss_lock */
2108 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
2109 struct ieee80211_sta_bss
*bss
)
2111 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2114 if (bss_mesh_cfg(bss
))
2115 hash_idx
= mesh_id_hash(bss_mesh_id(bss
),
2116 bss_mesh_id_len(bss
));
2118 hash_idx
= STA_HASH(bss
->bssid
);
2120 bss
->hnext
= local
->sta_bss_hash
[hash_idx
];
2121 local
->sta_bss_hash
[hash_idx
] = bss
;
2125 /* Caller must hold local->sta_bss_lock */
2126 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
2127 struct ieee80211_sta_bss
*bss
)
2129 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2130 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
2131 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
2135 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
2138 prev
->hnext
= bss
->hnext
;
2147 static struct ieee80211_sta_bss
*
2148 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
, int freq
,
2149 u8
*ssid
, u8 ssid_len
)
2151 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2152 struct ieee80211_sta_bss
*bss
;
2154 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2157 atomic_inc(&bss
->users
);
2158 atomic_inc(&bss
->users
);
2159 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
2161 if (ssid
&& ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
2162 memcpy(bss
->ssid
, ssid
, ssid_len
);
2163 bss
->ssid_len
= ssid_len
;
2166 spin_lock_bh(&local
->sta_bss_lock
);
2167 /* TODO: order by RSSI? */
2168 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2169 __ieee80211_rx_bss_hash_add(dev
, bss
);
2170 spin_unlock_bh(&local
->sta_bss_lock
);
2174 static struct ieee80211_sta_bss
*
2175 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int freq
,
2176 u8
*ssid
, u8 ssid_len
)
2178 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2179 struct ieee80211_sta_bss
*bss
;
2181 spin_lock_bh(&local
->sta_bss_lock
);
2182 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
2184 if (!bss_mesh_cfg(bss
) &&
2185 !memcmp(bss
->bssid
, bssid
, ETH_ALEN
) &&
2186 bss
->freq
== freq
&&
2187 bss
->ssid_len
== ssid_len
&&
2188 (ssid_len
== 0 || !memcmp(bss
->ssid
, ssid
, ssid_len
))) {
2189 atomic_inc(&bss
->users
);
2194 spin_unlock_bh(&local
->sta_bss_lock
);
2198 #ifdef CONFIG_MAC80211_MESH
2199 static struct ieee80211_sta_bss
*
2200 ieee80211_rx_mesh_bss_get(struct net_device
*dev
, u8
*mesh_id
, int mesh_id_len
,
2201 u8
*mesh_cfg
, int freq
)
2203 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2204 struct ieee80211_sta_bss
*bss
;
2206 spin_lock_bh(&local
->sta_bss_lock
);
2207 bss
= local
->sta_bss_hash
[mesh_id_hash(mesh_id
, mesh_id_len
)];
2209 if (bss_mesh_cfg(bss
) &&
2210 !memcmp(bss_mesh_cfg(bss
), mesh_cfg
, MESH_CFG_CMP_LEN
) &&
2211 bss
->freq
== freq
&&
2212 mesh_id_len
== bss
->mesh_id_len
&&
2213 (mesh_id_len
== 0 || !memcmp(bss
->mesh_id
, mesh_id
,
2215 atomic_inc(&bss
->users
);
2220 spin_unlock_bh(&local
->sta_bss_lock
);
2224 static struct ieee80211_sta_bss
*
2225 ieee80211_rx_mesh_bss_add(struct net_device
*dev
, u8
*mesh_id
, int mesh_id_len
,
2226 u8
*mesh_cfg
, int mesh_config_len
, int freq
)
2228 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2229 struct ieee80211_sta_bss
*bss
;
2231 if (mesh_config_len
!= MESH_CFG_LEN
)
2234 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2238 bss
->mesh_cfg
= kmalloc(MESH_CFG_CMP_LEN
, GFP_ATOMIC
);
2239 if (!bss
->mesh_cfg
) {
2244 if (mesh_id_len
&& mesh_id_len
<= IEEE80211_MAX_MESH_ID_LEN
) {
2245 bss
->mesh_id
= kmalloc(mesh_id_len
, GFP_ATOMIC
);
2246 if (!bss
->mesh_id
) {
2247 kfree(bss
->mesh_cfg
);
2251 memcpy(bss
->mesh_id
, mesh_id
, mesh_id_len
);
2254 atomic_inc(&bss
->users
);
2255 atomic_inc(&bss
->users
);
2256 memcpy(bss
->mesh_cfg
, mesh_cfg
, MESH_CFG_CMP_LEN
);
2257 bss
->mesh_id_len
= mesh_id_len
;
2259 spin_lock_bh(&local
->sta_bss_lock
);
2260 /* TODO: order by RSSI? */
2261 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2262 __ieee80211_rx_bss_hash_add(dev
, bss
);
2263 spin_unlock_bh(&local
->sta_bss_lock
);
2268 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
2274 kfree(bss_mesh_id(bss
));
2275 kfree(bss_mesh_cfg(bss
));
2280 static void ieee80211_rx_bss_put(struct net_device
*dev
,
2281 struct ieee80211_sta_bss
*bss
)
2283 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2286 if (!atomic_dec_and_lock(&bss
->users
, &local
->sta_bss_lock
)) {
2291 __ieee80211_rx_bss_hash_del(dev
, bss
);
2292 list_del(&bss
->list
);
2293 spin_unlock_bh(&local
->sta_bss_lock
);
2294 ieee80211_rx_bss_free(bss
);
2298 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
2300 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2301 spin_lock_init(&local
->sta_bss_lock
);
2302 INIT_LIST_HEAD(&local
->sta_bss_list
);
2306 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
2308 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2309 struct ieee80211_sta_bss
*bss
, *tmp
;
2311 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
2312 ieee80211_rx_bss_put(dev
, bss
);
2316 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
2317 struct ieee80211_if_sta
*ifsta
,
2318 struct ieee80211_sta_bss
*bss
)
2320 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2321 int res
, rates
, i
, j
;
2322 struct sk_buff
*skb
;
2323 struct ieee80211_mgmt
*mgmt
;
2324 struct ieee80211_tx_control control
;
2325 struct rate_selection ratesel
;
2327 struct ieee80211_sub_if_data
*sdata
;
2328 struct ieee80211_supported_band
*sband
;
2330 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2332 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2334 /* Remove possible STA entries from other IBSS networks. */
2335 sta_info_flush_delayed(sdata
);
2337 if (local
->ops
->reset_tsf
) {
2338 /* Reset own TSF to allow time synchronization work. */
2339 local
->ops
->reset_tsf(local_to_hw(local
));
2341 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
2342 res
= ieee80211_if_config(dev
);
2346 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2348 sdata
->drop_unencrypted
= bss
->capability
&
2349 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
2351 res
= ieee80211_set_freq(local
, bss
->freq
);
2353 if (local
->oper_channel
->flags
& IEEE80211_CHAN_NO_IBSS
) {
2354 printk(KERN_DEBUG
"%s: IBSS not allowed on frequency "
2355 "%d MHz\n", dev
->name
, local
->oper_channel
->center_freq
);
2359 /* Set beacon template */
2360 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 400);
2365 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2367 mgmt
= (struct ieee80211_mgmt
*)
2368 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2369 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2370 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2371 IEEE80211_STYPE_BEACON
);
2372 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2373 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2374 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2375 mgmt
->u
.beacon
.beacon_int
=
2376 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2377 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2379 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2380 *pos
++ = WLAN_EID_SSID
;
2381 *pos
++ = ifsta
->ssid_len
;
2382 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2384 rates
= bss
->supp_rates_len
;
2387 pos
= skb_put(skb
, 2 + rates
);
2388 *pos
++ = WLAN_EID_SUPP_RATES
;
2390 memcpy(pos
, bss
->supp_rates
, rates
);
2392 if (bss
->band
== IEEE80211_BAND_2GHZ
) {
2393 pos
= skb_put(skb
, 2 + 1);
2394 *pos
++ = WLAN_EID_DS_PARAMS
;
2396 *pos
++ = ieee80211_frequency_to_channel(bss
->freq
);
2399 pos
= skb_put(skb
, 2 + 2);
2400 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2402 /* FIX: set ATIM window based on scan results */
2406 if (bss
->supp_rates_len
> 8) {
2407 rates
= bss
->supp_rates_len
- 8;
2408 pos
= skb_put(skb
, 2 + rates
);
2409 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2411 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2414 memset(&control
, 0, sizeof(control
));
2415 rate_control_get_rate(dev
, sband
, skb
, &ratesel
);
2416 if (!ratesel
.rate
) {
2417 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2418 "for IBSS beacon\n", dev
->name
);
2421 control
.vif
= &sdata
->vif
;
2422 control
.tx_rate
= ratesel
.rate
;
2423 if (sdata
->bss_conf
.use_short_preamble
&&
2424 ratesel
.rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
2425 control
.flags
|= IEEE80211_TXCTL_SHORT_PREAMBLE
;
2426 control
.antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
2427 control
.flags
|= IEEE80211_TXCTL_NO_ACK
;
2428 control
.retry_limit
= 1;
2430 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2431 if (ifsta
->probe_resp
) {
2432 mgmt
= (struct ieee80211_mgmt
*)
2433 ifsta
->probe_resp
->data
;
2434 mgmt
->frame_control
=
2435 IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2436 IEEE80211_STYPE_PROBE_RESP
);
2438 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2439 "template for IBSS\n", dev
->name
);
2442 if (local
->ops
->beacon_update
&&
2443 local
->ops
->beacon_update(local_to_hw(local
),
2444 skb
, &control
) == 0) {
2445 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2446 "template\n", dev
->name
);
2451 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2452 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2453 int bitrate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2454 for (j
= 0; j
< sband
->n_bitrates
; j
++)
2455 if (sband
->bitrates
[j
].bitrate
== bitrate
)
2458 ifsta
->supp_rates_bits
[local
->hw
.conf
.channel
->band
] = rates
;
2460 ieee80211_sta_def_wmm_params(dev
, bss
, 1);
2464 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2465 "template\n", dev
->name
);
2469 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2470 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2472 ieee80211_rx_bss_put(dev
, bss
);
2477 u64
ieee80211_sta_get_rates(struct ieee80211_local
*local
,
2478 struct ieee802_11_elems
*elems
,
2479 enum ieee80211_band band
)
2481 struct ieee80211_supported_band
*sband
;
2482 struct ieee80211_rate
*bitrates
;
2486 sband
= local
->hw
.wiphy
->bands
[band
];
2490 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2493 bitrates
= sband
->bitrates
;
2494 num_rates
= sband
->n_bitrates
;
2496 for (i
= 0; i
< elems
->supp_rates_len
+
2497 elems
->ext_supp_rates_len
; i
++) {
2500 if (i
< elems
->supp_rates_len
)
2501 rate
= elems
->supp_rates
[i
];
2502 else if (elems
->ext_supp_rates
)
2503 rate
= elems
->ext_supp_rates
2504 [i
- elems
->supp_rates_len
];
2505 own_rate
= 5 * (rate
& 0x7f);
2506 for (j
= 0; j
< num_rates
; j
++)
2507 if (bitrates
[j
].bitrate
== own_rate
)
2508 supp_rates
|= BIT(j
);
2514 static void ieee80211_rx_bss_info(struct net_device
*dev
,
2515 struct ieee80211_mgmt
*mgmt
,
2517 struct ieee80211_rx_status
*rx_status
,
2520 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2521 struct ieee802_11_elems elems
;
2524 struct ieee80211_sta_bss
*bss
;
2525 struct sta_info
*sta
;
2526 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2527 u64 beacon_timestamp
, rx_timestamp
;
2528 struct ieee80211_channel
*channel
;
2529 DECLARE_MAC_BUF(mac
);
2530 DECLARE_MAC_BUF(mac2
);
2532 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
2533 return; /* ignore ProbeResp to foreign address */
2536 printk(KERN_DEBUG
"%s: RX %s from %s to %s\n",
2537 dev
->name
, beacon
? "Beacon" : "Probe Response",
2538 print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
));
2541 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2545 beacon_timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
2546 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2548 if (ieee80211_vif_is_mesh(&sdata
->vif
) && elems
.mesh_id
&&
2549 elems
.mesh_config
&& mesh_matches_local(&elems
, dev
)) {
2550 u64 rates
= ieee80211_sta_get_rates(local
, &elems
,
2553 mesh_neighbour_update(mgmt
->sa
, rates
, dev
,
2554 mesh_peer_accepts_plinks(&elems
, dev
));
2559 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& elems
.supp_rates
&&
2560 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0 &&
2561 (sta
= sta_info_get(local
, mgmt
->sa
))) {
2563 u64 supp_rates
= ieee80211_sta_get_rates(local
, &elems
,
2566 prev_rates
= sta
->supp_rates
[rx_status
->band
];
2567 sta
->supp_rates
[rx_status
->band
] &= supp_rates
;
2568 if (sta
->supp_rates
[rx_status
->band
] == 0) {
2569 /* No matching rates - this should not really happen.
2570 * Make sure that at least one rate is marked
2571 * supported to avoid issues with TX rate ctrl. */
2572 sta
->supp_rates
[rx_status
->band
] =
2573 sdata
->u
.sta
.supp_rates_bits
[rx_status
->band
];
2575 if (sta
->supp_rates
[rx_status
->band
] != prev_rates
) {
2576 printk(KERN_DEBUG
"%s: updated supp_rates set for "
2577 "%s based on beacon info (0x%llx & 0x%llx -> "
2579 dev
->name
, print_mac(mac
, sta
->addr
),
2580 (unsigned long long) prev_rates
,
2581 (unsigned long long) supp_rates
,
2582 (unsigned long long) sta
->supp_rates
[rx_status
->band
]);
2588 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
2589 freq
= ieee80211_channel_to_frequency(elems
.ds_params
[0]);
2591 freq
= rx_status
->freq
;
2593 channel
= ieee80211_get_channel(local
->hw
.wiphy
, freq
);
2595 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
2598 #ifdef CONFIG_MAC80211_MESH
2599 if (elems
.mesh_config
)
2600 bss
= ieee80211_rx_mesh_bss_get(dev
, elems
.mesh_id
,
2601 elems
.mesh_id_len
, elems
.mesh_config
, freq
);
2604 bss
= ieee80211_rx_bss_get(dev
, mgmt
->bssid
, freq
,
2605 elems
.ssid
, elems
.ssid_len
);
2607 #ifdef CONFIG_MAC80211_MESH
2608 if (elems
.mesh_config
)
2609 bss
= ieee80211_rx_mesh_bss_add(dev
, elems
.mesh_id
,
2610 elems
.mesh_id_len
, elems
.mesh_config
,
2611 elems
.mesh_config_len
, freq
);
2614 bss
= ieee80211_rx_bss_add(dev
, mgmt
->bssid
, freq
,
2615 elems
.ssid
, elems
.ssid_len
);
2620 /* TODO: order by RSSI? */
2621 spin_lock_bh(&local
->sta_bss_lock
);
2622 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
2623 spin_unlock_bh(&local
->sta_bss_lock
);
2627 /* save the ERP value so that it is available at association time */
2628 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
2629 bss
->erp_value
= elems
.erp_info
[0];
2630 bss
->has_erp_value
= 1;
2633 if (elems
.ht_cap_elem
&&
2634 (!bss
->ht_ie
|| bss
->ht_ie_len
!= elems
.ht_cap_elem_len
||
2635 memcmp(bss
->ht_ie
, elems
.ht_cap_elem
, elems
.ht_cap_elem_len
))) {
2637 bss
->ht_ie
= kmalloc(elems
.ht_cap_elem_len
+ 2, GFP_ATOMIC
);
2639 memcpy(bss
->ht_ie
, elems
.ht_cap_elem
- 2,
2640 elems
.ht_cap_elem_len
+ 2);
2641 bss
->ht_ie_len
= elems
.ht_cap_elem_len
+ 2;
2644 } else if (!elems
.ht_cap_elem
&& bss
->ht_ie
) {
2650 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
2651 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2653 bss
->supp_rates_len
= 0;
2654 if (elems
.supp_rates
) {
2655 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2656 if (clen
> elems
.supp_rates_len
)
2657 clen
= elems
.supp_rates_len
;
2658 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
.supp_rates
,
2660 bss
->supp_rates_len
+= clen
;
2662 if (elems
.ext_supp_rates
) {
2663 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2664 if (clen
> elems
.ext_supp_rates_len
)
2665 clen
= elems
.ext_supp_rates_len
;
2666 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
2667 elems
.ext_supp_rates
, clen
);
2668 bss
->supp_rates_len
+= clen
;
2671 bss
->band
= rx_status
->band
;
2673 bss
->timestamp
= beacon_timestamp
;
2674 bss
->last_update
= jiffies
;
2675 bss
->signal
= rx_status
->signal
;
2676 bss
->noise
= rx_status
->noise
;
2677 bss
->qual
= rx_status
->qual
;
2678 if (!beacon
&& !bss
->probe_resp
)
2679 bss
->probe_resp
= true;
2682 * In STA mode, the remaining parameters should not be overridden
2683 * by beacons because they're not necessarily accurate there.
2685 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
2686 bss
->probe_resp
&& beacon
) {
2687 ieee80211_rx_bss_put(dev
, bss
);
2692 (!bss
->wpa_ie
|| bss
->wpa_ie_len
!= elems
.wpa_len
||
2693 memcmp(bss
->wpa_ie
, elems
.wpa
, elems
.wpa_len
))) {
2695 bss
->wpa_ie
= kmalloc(elems
.wpa_len
+ 2, GFP_ATOMIC
);
2697 memcpy(bss
->wpa_ie
, elems
.wpa
- 2, elems
.wpa_len
+ 2);
2698 bss
->wpa_ie_len
= elems
.wpa_len
+ 2;
2700 bss
->wpa_ie_len
= 0;
2701 } else if (!elems
.wpa
&& bss
->wpa_ie
) {
2704 bss
->wpa_ie_len
= 0;
2708 (!bss
->rsn_ie
|| bss
->rsn_ie_len
!= elems
.rsn_len
||
2709 memcmp(bss
->rsn_ie
, elems
.rsn
, elems
.rsn_len
))) {
2711 bss
->rsn_ie
= kmalloc(elems
.rsn_len
+ 2, GFP_ATOMIC
);
2713 memcpy(bss
->rsn_ie
, elems
.rsn
- 2, elems
.rsn_len
+ 2);
2714 bss
->rsn_ie_len
= elems
.rsn_len
+ 2;
2716 bss
->rsn_ie_len
= 0;
2717 } else if (!elems
.rsn
&& bss
->rsn_ie
) {
2720 bss
->rsn_ie_len
= 0;
2725 * http://www.wipo.int/pctdb/en/wo.jsp?wo=2007047181&IA=WO2007047181&DISPLAY=DESC
2729 * In particular, "Wi-Fi CERTIFIED for WMM - Support for Multimedia
2730 * Applications with Quality of Service in Wi-Fi Networks," Wi- Fi
2731 * Alliance (September 1, 2004) is incorporated by reference herein.
2732 * The inclusion of the WMM Parameters in probe responses and
2733 * association responses is mandatory for WMM enabled networks. The
2734 * inclusion of the WMM Parameters in beacons, however, is optional.
2737 if (elems
.wmm_param
&&
2738 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_param_len
||
2739 memcmp(bss
->wmm_ie
, elems
.wmm_param
, elems
.wmm_param_len
))) {
2741 bss
->wmm_ie
= kmalloc(elems
.wmm_param_len
+ 2, GFP_ATOMIC
);
2743 memcpy(bss
->wmm_ie
, elems
.wmm_param
- 2,
2744 elems
.wmm_param_len
+ 2);
2745 bss
->wmm_ie_len
= elems
.wmm_param_len
+ 2;
2747 bss
->wmm_ie_len
= 0;
2748 } else if (elems
.wmm_info
&&
2749 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_info_len
||
2750 memcmp(bss
->wmm_ie
, elems
.wmm_info
, elems
.wmm_info_len
))) {
2751 /* As for certain AP's Fifth bit is not set in WMM IE in
2752 * beacon frames.So while parsing the beacon frame the
2753 * wmm_info structure is used instead of wmm_param.
2754 * wmm_info structure was never used to set bss->wmm_ie.
2755 * This code fixes this problem by copying the WME
2756 * information from wmm_info to bss->wmm_ie and enabling
2757 * n-band association.
2760 bss
->wmm_ie
= kmalloc(elems
.wmm_info_len
+ 2, GFP_ATOMIC
);
2762 memcpy(bss
->wmm_ie
, elems
.wmm_info
- 2,
2763 elems
.wmm_info_len
+ 2);
2764 bss
->wmm_ie_len
= elems
.wmm_info_len
+ 2;
2766 bss
->wmm_ie_len
= 0;
2767 } else if (!elems
.wmm_param
&& !elems
.wmm_info
&& bss
->wmm_ie
) {
2770 bss
->wmm_ie_len
= 0;
2773 /* check if we need to merge IBSS */
2774 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
2775 !local
->sta_sw_scanning
&& !local
->sta_hw_scanning
&&
2776 bss
->capability
& WLAN_CAPABILITY_IBSS
&&
2777 bss
->freq
== local
->oper_channel
->center_freq
&&
2778 elems
.ssid_len
== sdata
->u
.sta
.ssid_len
&&
2779 memcmp(elems
.ssid
, sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
) == 0) {
2780 if (rx_status
->flag
& RX_FLAG_TSFT
) {
2781 /* in order for correct IBSS merging we need mactime
2783 * since mactime is defined as the time the first data
2784 * symbol of the frame hits the PHY, and the timestamp
2785 * of the beacon is defined as "the time that the data
2786 * symbol containing the first bit of the timestamp is
2787 * transmitted to the PHY plus the transmitting STA’s
2788 * delays through its local PHY from the MAC-PHY
2789 * interface to its interface with the WM"
2790 * (802.11 11.1.2) - equals the time this bit arrives at
2791 * the receiver - we have to take into account the
2792 * offset between the two.
2793 * e.g: at 1 MBit that means mactime is 192 usec earlier
2794 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2796 int rate
= local
->hw
.wiphy
->bands
[rx_status
->band
]->
2797 bitrates
[rx_status
->rate_idx
].bitrate
;
2798 rx_timestamp
= rx_status
->mactime
+ (24 * 8 * 10 / rate
);
2799 } else if (local
&& local
->ops
&& local
->ops
->get_tsf
)
2800 /* second best option: get current TSF */
2801 rx_timestamp
= local
->ops
->get_tsf(local_to_hw(local
));
2803 /* can't merge without knowing the TSF */
2804 rx_timestamp
= -1LLU;
2805 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2806 printk(KERN_DEBUG
"RX beacon SA=%s BSSID="
2807 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2808 print_mac(mac
, mgmt
->sa
),
2809 print_mac(mac2
, mgmt
->bssid
),
2810 (unsigned long long)rx_timestamp
,
2811 (unsigned long long)beacon_timestamp
,
2812 (unsigned long long)(rx_timestamp
- beacon_timestamp
),
2814 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2815 if (beacon_timestamp
> rx_timestamp
) {
2816 #ifndef CONFIG_MAC80211_IBSS_DEBUG
2817 if (net_ratelimit())
2819 printk(KERN_DEBUG
"%s: beacon TSF higher than "
2820 "local TSF - IBSS merge with BSSID %s\n",
2821 dev
->name
, print_mac(mac
, mgmt
->bssid
));
2822 ieee80211_sta_join_ibss(dev
, &sdata
->u
.sta
, bss
);
2823 ieee80211_ibss_add_sta(dev
, NULL
,
2824 mgmt
->bssid
, mgmt
->sa
);
2828 ieee80211_rx_bss_put(dev
, bss
);
2832 static void ieee80211_rx_mgmt_probe_resp(struct net_device
*dev
,
2833 struct ieee80211_mgmt
*mgmt
,
2835 struct ieee80211_rx_status
*rx_status
)
2837 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 0);
2841 static void ieee80211_rx_mgmt_beacon(struct net_device
*dev
,
2842 struct ieee80211_mgmt
*mgmt
,
2844 struct ieee80211_rx_status
*rx_status
)
2846 struct ieee80211_sub_if_data
*sdata
;
2847 struct ieee80211_if_sta
*ifsta
;
2849 struct ieee802_11_elems elems
;
2850 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2851 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
2854 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 1);
2856 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2857 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
2859 ifsta
= &sdata
->u
.sta
;
2861 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
) ||
2862 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
2865 /* Process beacon from the current BSS */
2866 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2870 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2872 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2873 elems
.wmm_param_len
);
2875 /* Do not send changes to driver if we are scanning. This removes
2876 * requirement that driver's bss_info_changed function needs to be
2878 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
2881 if (elems
.erp_info
&& elems
.erp_info_len
>= 1)
2882 changed
|= ieee80211_handle_erp_ie(sdata
, elems
.erp_info
[0]);
2884 u16 capab
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2885 changed
|= ieee80211_handle_protect_preamb(sdata
, false,
2886 (capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
) != 0);
2889 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&&
2890 elems
.wmm_param
&& conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
2891 struct ieee80211_ht_bss_info bss_info
;
2893 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2894 (struct ieee80211_ht_addt_info
*)
2895 elems
.ht_info_elem
, &bss_info
);
2896 changed
|= ieee80211_handle_ht(local
, 1, &conf
->ht_conf
,
2900 ieee80211_bss_info_change_notify(sdata
, changed
);
2904 static void ieee80211_rx_mgmt_probe_req(struct net_device
*dev
,
2905 struct ieee80211_if_sta
*ifsta
,
2906 struct ieee80211_mgmt
*mgmt
,
2908 struct ieee80211_rx_status
*rx_status
)
2910 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2911 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2913 struct sk_buff
*skb
;
2914 struct ieee80211_mgmt
*resp
;
2916 DECLARE_MAC_BUF(mac
);
2917 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2918 DECLARE_MAC_BUF(mac2
);
2919 DECLARE_MAC_BUF(mac3
);
2922 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
||
2923 ifsta
->state
!= IEEE80211_IBSS_JOINED
||
2924 len
< 24 + 2 || !ifsta
->probe_resp
)
2927 if (local
->ops
->tx_last_beacon
)
2928 tx_last_beacon
= local
->ops
->tx_last_beacon(local_to_hw(local
));
2932 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2933 printk(KERN_DEBUG
"%s: RX ProbeReq SA=%s DA=%s BSSID="
2934 "%s (tx_last_beacon=%d)\n",
2935 dev
->name
, print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
),
2936 print_mac(mac3
, mgmt
->bssid
), tx_last_beacon
);
2937 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2939 if (!tx_last_beacon
)
2942 if (memcmp(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
) != 0 &&
2943 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
2946 end
= ((u8
*) mgmt
) + len
;
2947 pos
= mgmt
->u
.probe_req
.variable
;
2948 if (pos
[0] != WLAN_EID_SSID
||
2949 pos
+ 2 + pos
[1] > end
) {
2950 if (net_ratelimit()) {
2951 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
2953 dev
->name
, print_mac(mac
, mgmt
->sa
));
2958 (pos
[1] != ifsta
->ssid_len
||
2959 memcmp(pos
+ 2, ifsta
->ssid
, ifsta
->ssid_len
) != 0)) {
2960 /* Ignore ProbeReq for foreign SSID */
2964 /* Reply with ProbeResp */
2965 skb
= skb_copy(ifsta
->probe_resp
, GFP_KERNEL
);
2969 resp
= (struct ieee80211_mgmt
*) skb
->data
;
2970 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
2971 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2972 printk(KERN_DEBUG
"%s: Sending ProbeResp to %s\n",
2973 dev
->name
, print_mac(mac
, resp
->da
));
2974 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2975 ieee80211_sta_tx(dev
, skb
, 0);
2978 static void ieee80211_rx_mgmt_action(struct net_device
*dev
,
2979 struct ieee80211_if_sta
*ifsta
,
2980 struct ieee80211_mgmt
*mgmt
,
2982 struct ieee80211_rx_status
*rx_status
)
2984 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2986 if (len
< IEEE80211_MIN_ACTION_SIZE
)
2989 switch (mgmt
->u
.action
.category
) {
2990 case WLAN_CATEGORY_BACK
:
2991 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
2992 case WLAN_ACTION_ADDBA_REQ
:
2993 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2994 sizeof(mgmt
->u
.action
.u
.addba_req
)))
2996 ieee80211_sta_process_addba_request(dev
, mgmt
, len
);
2998 case WLAN_ACTION_ADDBA_RESP
:
2999 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3000 sizeof(mgmt
->u
.action
.u
.addba_resp
)))
3002 ieee80211_sta_process_addba_resp(dev
, mgmt
, len
);
3004 case WLAN_ACTION_DELBA
:
3005 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
3006 sizeof(mgmt
->u
.action
.u
.delba
)))
3008 ieee80211_sta_process_delba(dev
, mgmt
, len
);
3011 if (net_ratelimit())
3012 printk(KERN_DEBUG
"%s: Rx unknown A-MPDU action\n",
3017 case PLINK_CATEGORY
:
3018 if (ieee80211_vif_is_mesh(&sdata
->vif
))
3019 mesh_rx_plink_frame(dev
, mgmt
, len
, rx_status
);
3021 case MESH_PATH_SEL_CATEGORY
:
3022 if (ieee80211_vif_is_mesh(&sdata
->vif
))
3023 mesh_rx_path_sel_frame(dev
, mgmt
, len
);
3026 if (net_ratelimit())
3027 printk(KERN_DEBUG
"%s: Rx unknown action frame - "
3028 "category=%d\n", dev
->name
, mgmt
->u
.action
.category
);
3033 void ieee80211_sta_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
3034 struct ieee80211_rx_status
*rx_status
)
3036 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3037 struct ieee80211_sub_if_data
*sdata
;
3038 struct ieee80211_if_sta
*ifsta
;
3039 struct ieee80211_mgmt
*mgmt
;
3045 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3046 ifsta
= &sdata
->u
.sta
;
3048 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3049 fc
= le16_to_cpu(mgmt
->frame_control
);
3051 switch (fc
& IEEE80211_FCTL_STYPE
) {
3052 case IEEE80211_STYPE_PROBE_REQ
:
3053 case IEEE80211_STYPE_PROBE_RESP
:
3054 case IEEE80211_STYPE_BEACON
:
3055 case IEEE80211_STYPE_ACTION
:
3056 memcpy(skb
->cb
, rx_status
, sizeof(*rx_status
));
3057 case IEEE80211_STYPE_AUTH
:
3058 case IEEE80211_STYPE_ASSOC_RESP
:
3059 case IEEE80211_STYPE_REASSOC_RESP
:
3060 case IEEE80211_STYPE_DEAUTH
:
3061 case IEEE80211_STYPE_DISASSOC
:
3062 skb_queue_tail(&ifsta
->skb_queue
, skb
);
3063 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3066 printk(KERN_DEBUG
"%s: received unknown management frame - "
3067 "stype=%d\n", dev
->name
,
3068 (fc
& IEEE80211_FCTL_STYPE
) >> 4);
3077 static void ieee80211_sta_rx_queued_mgmt(struct net_device
*dev
,
3078 struct sk_buff
*skb
)
3080 struct ieee80211_rx_status
*rx_status
;
3081 struct ieee80211_sub_if_data
*sdata
;
3082 struct ieee80211_if_sta
*ifsta
;
3083 struct ieee80211_mgmt
*mgmt
;
3086 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3087 ifsta
= &sdata
->u
.sta
;
3089 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
3090 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3091 fc
= le16_to_cpu(mgmt
->frame_control
);
3093 switch (fc
& IEEE80211_FCTL_STYPE
) {
3094 case IEEE80211_STYPE_PROBE_REQ
:
3095 ieee80211_rx_mgmt_probe_req(dev
, ifsta
, mgmt
, skb
->len
,
3098 case IEEE80211_STYPE_PROBE_RESP
:
3099 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
, skb
->len
, rx_status
);
3101 case IEEE80211_STYPE_BEACON
:
3102 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
, rx_status
);
3104 case IEEE80211_STYPE_AUTH
:
3105 ieee80211_rx_mgmt_auth(dev
, ifsta
, mgmt
, skb
->len
);
3107 case IEEE80211_STYPE_ASSOC_RESP
:
3108 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 0);
3110 case IEEE80211_STYPE_REASSOC_RESP
:
3111 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 1);
3113 case IEEE80211_STYPE_DEAUTH
:
3114 ieee80211_rx_mgmt_deauth(dev
, ifsta
, mgmt
, skb
->len
);
3116 case IEEE80211_STYPE_DISASSOC
:
3117 ieee80211_rx_mgmt_disassoc(dev
, ifsta
, mgmt
, skb
->len
);
3119 case IEEE80211_STYPE_ACTION
:
3120 ieee80211_rx_mgmt_action(dev
, ifsta
, mgmt
, skb
->len
, rx_status
);
3129 ieee80211_sta_rx_scan(struct net_device
*dev
, struct sk_buff
*skb
,
3130 struct ieee80211_rx_status
*rx_status
)
3132 struct ieee80211_mgmt
*mgmt
;
3136 return RX_DROP_UNUSABLE
;
3138 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3139 fc
= le16_to_cpu(mgmt
->frame_control
);
3141 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
)
3145 return RX_DROP_MONITOR
;
3147 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
3148 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
) {
3149 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
,
3150 skb
->len
, rx_status
);
3153 } else if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
) {
3154 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
,
3164 static int ieee80211_sta_active_ibss(struct net_device
*dev
)
3166 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3168 struct sta_info
*sta
;
3169 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3173 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
3174 if (sta
->sdata
== sdata
&&
3175 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
3188 static void ieee80211_sta_expire(struct net_device
*dev
, unsigned long exp_time
)
3190 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3191 struct sta_info
*sta
, *tmp
;
3192 LIST_HEAD(tmp_list
);
3193 DECLARE_MAC_BUF(mac
);
3194 unsigned long flags
;
3196 spin_lock_irqsave(&local
->sta_lock
, flags
);
3197 list_for_each_entry_safe(sta
, tmp
, &local
->sta_list
, list
)
3198 if (time_after(jiffies
, sta
->last_rx
+ exp_time
)) {
3199 printk(KERN_DEBUG
"%s: expiring inactive STA %s\n",
3200 dev
->name
, print_mac(mac
, sta
->addr
));
3201 __sta_info_unlink(&sta
);
3203 list_add(&sta
->list
, &tmp_list
);
3205 spin_unlock_irqrestore(&local
->sta_lock
, flags
);
3207 list_for_each_entry_safe(sta
, tmp
, &tmp_list
, list
)
3208 sta_info_destroy(sta
);
3212 static void ieee80211_sta_merge_ibss(struct net_device
*dev
,
3213 struct ieee80211_if_sta
*ifsta
)
3215 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
3217 ieee80211_sta_expire(dev
, IEEE80211_IBSS_INACTIVITY_LIMIT
);
3218 if (ieee80211_sta_active_ibss(dev
))
3221 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
3222 "IBSS networks with same SSID (merge)\n", dev
->name
);
3223 ieee80211_sta_req_scan(dev
, ifsta
->ssid
, ifsta
->ssid_len
);
3227 #ifdef CONFIG_MAC80211_MESH
3228 static void ieee80211_mesh_housekeeping(struct net_device
*dev
,
3229 struct ieee80211_if_sta
*ifsta
)
3231 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3234 ieee80211_sta_expire(dev
, IEEE80211_MESH_PEER_INACTIVITY_LIMIT
);
3235 mesh_path_expire(dev
);
3237 free_plinks
= mesh_plink_availables(sdata
);
3238 if (free_plinks
!= sdata
->u
.sta
.accepting_plinks
)
3239 ieee80211_if_config_beacon(dev
);
3241 mod_timer(&ifsta
->timer
, jiffies
+
3242 IEEE80211_MESH_HOUSEKEEPING_INTERVAL
);
3246 void ieee80211_start_mesh(struct net_device
*dev
)
3248 struct ieee80211_if_sta
*ifsta
;
3249 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3250 ifsta
= &sdata
->u
.sta
;
3251 ifsta
->state
= IEEE80211_MESH_UP
;
3252 ieee80211_sta_timer((unsigned long)sdata
);
3257 void ieee80211_sta_timer(unsigned long data
)
3259 struct ieee80211_sub_if_data
*sdata
=
3260 (struct ieee80211_sub_if_data
*) data
;
3261 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3262 struct ieee80211_local
*local
= wdev_priv(&sdata
->wdev
);
3264 set_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3265 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3268 void ieee80211_sta_work(struct work_struct
*work
)
3270 struct ieee80211_sub_if_data
*sdata
=
3271 container_of(work
, struct ieee80211_sub_if_data
, u
.sta
.work
);
3272 struct net_device
*dev
= sdata
->dev
;
3273 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3274 struct ieee80211_if_sta
*ifsta
;
3275 struct sk_buff
*skb
;
3277 if (!netif_running(dev
))
3280 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
3283 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
3284 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
3285 sdata
->vif
.type
!= IEEE80211_IF_TYPE_MESH_POINT
) {
3286 printk(KERN_DEBUG
"%s: ieee80211_sta_work: non-STA interface "
3287 "(type=%d)\n", dev
->name
, sdata
->vif
.type
);
3290 ifsta
= &sdata
->u
.sta
;
3292 while ((skb
= skb_dequeue(&ifsta
->skb_queue
)))
3293 ieee80211_sta_rx_queued_mgmt(dev
, skb
);
3295 #ifdef CONFIG_MAC80211_MESH
3296 if (ifsta
->preq_queue_len
&&
3298 ifsta
->last_preq
+ msecs_to_jiffies(ifsta
->mshcfg
.dot11MeshHWMPpreqMinInterval
)))
3299 mesh_path_start_discovery(dev
);
3302 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
3303 ifsta
->state
!= IEEE80211_ASSOCIATE
&&
3304 test_and_clear_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
)) {
3305 if (ifsta
->scan_ssid_len
)
3306 ieee80211_sta_start_scan(dev
, ifsta
->scan_ssid
, ifsta
->scan_ssid_len
);
3308 ieee80211_sta_start_scan(dev
, NULL
, 0);
3312 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
)) {
3313 if (ieee80211_sta_config_auth(dev
, ifsta
))
3315 clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3316 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
))
3319 switch (ifsta
->state
) {
3320 case IEEE80211_DISABLED
:
3322 case IEEE80211_AUTHENTICATE
:
3323 ieee80211_authenticate(dev
, ifsta
);
3325 case IEEE80211_ASSOCIATE
:
3326 ieee80211_associate(dev
, ifsta
);
3328 case IEEE80211_ASSOCIATED
:
3329 ieee80211_associated(dev
, ifsta
);
3331 case IEEE80211_IBSS_SEARCH
:
3332 ieee80211_sta_find_ibss(dev
, ifsta
);
3334 case IEEE80211_IBSS_JOINED
:
3335 ieee80211_sta_merge_ibss(dev
, ifsta
);
3337 #ifdef CONFIG_MAC80211_MESH
3338 case IEEE80211_MESH_UP
:
3339 ieee80211_mesh_housekeeping(dev
, ifsta
);
3343 printk(KERN_DEBUG
"ieee80211_sta_work: Unknown state %d\n",
3348 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
3349 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
3350 "mixed-cell disabled - disassociate\n", dev
->name
);
3352 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
3353 ieee80211_set_disassoc(dev
, ifsta
, 0);
3358 static void ieee80211_sta_reset_auth(struct net_device
*dev
,
3359 struct ieee80211_if_sta
*ifsta
)
3361 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3363 if (local
->ops
->reset_tsf
) {
3364 /* Reset own TSF to allow time synchronization work. */
3365 local
->ops
->reset_tsf(local_to_hw(local
));
3368 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
3371 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
3372 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3373 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
3374 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
3375 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
3376 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
3378 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3379 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
3381 ifsta
->auth_transaction
= -1;
3382 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
3383 ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
3384 netif_carrier_off(dev
);
3388 void ieee80211_sta_req_auth(struct net_device
*dev
,
3389 struct ieee80211_if_sta
*ifsta
)
3391 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3392 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3394 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3397 if ((ifsta
->flags
& (IEEE80211_STA_BSSID_SET
|
3398 IEEE80211_STA_AUTO_BSSID_SEL
)) &&
3399 (ifsta
->flags
& (IEEE80211_STA_SSID_SET
|
3400 IEEE80211_STA_AUTO_SSID_SEL
))) {
3401 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3402 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3406 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta
*ifsta
,
3407 const char *ssid
, int ssid_len
)
3409 int tmp
, hidden_ssid
;
3411 if (ssid_len
== ifsta
->ssid_len
&&
3412 !memcmp(ifsta
->ssid
, ssid
, ssid_len
))
3415 if (ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
)
3421 if (ssid
[tmp
] != '\0') {
3427 if (hidden_ssid
&& ifsta
->ssid_len
== ssid_len
)
3430 if (ssid_len
== 1 && ssid
[0] == ' ')
3436 static int ieee80211_sta_config_auth(struct net_device
*dev
,
3437 struct ieee80211_if_sta
*ifsta
)
3439 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3440 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3441 struct ieee80211_sta_bss
*bss
, *selected
= NULL
;
3442 int top_rssi
= 0, freq
;
3444 spin_lock_bh(&local
->sta_bss_lock
);
3445 freq
= local
->oper_channel
->center_freq
;
3446 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3447 if (!(bss
->capability
& WLAN_CAPABILITY_ESS
))
3450 if ((ifsta
->flags
& (IEEE80211_STA_AUTO_SSID_SEL
|
3451 IEEE80211_STA_AUTO_BSSID_SEL
|
3452 IEEE80211_STA_AUTO_CHANNEL_SEL
)) &&
3453 (!!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
) ^
3454 !!sdata
->default_key
))
3457 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_CHANNEL_SEL
) &&
3461 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
) &&
3462 memcmp(bss
->bssid
, ifsta
->bssid
, ETH_ALEN
))
3465 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
) &&
3466 !ieee80211_sta_match_ssid(ifsta
, bss
->ssid
, bss
->ssid_len
))
3469 if (!selected
|| top_rssi
< bss
->signal
) {
3471 top_rssi
= bss
->signal
;
3475 atomic_inc(&selected
->users
);
3476 spin_unlock_bh(&local
->sta_bss_lock
);
3479 ieee80211_set_freq(local
, selected
->freq
);
3480 if (!(ifsta
->flags
& IEEE80211_STA_SSID_SET
))
3481 ieee80211_sta_set_ssid(dev
, selected
->ssid
,
3482 selected
->ssid_len
);
3483 ieee80211_sta_set_bssid(dev
, selected
->bssid
);
3484 ieee80211_sta_def_wmm_params(dev
, selected
, 0);
3485 ieee80211_rx_bss_put(dev
, selected
);
3486 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3487 ieee80211_sta_reset_auth(dev
, ifsta
);
3490 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
) {
3491 if (ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
)
3492 ieee80211_sta_start_scan(dev
, NULL
, 0);
3494 ieee80211_sta_start_scan(dev
, ifsta
->ssid
,
3496 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3497 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3499 ifsta
->state
= IEEE80211_DISABLED
;
3505 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
3506 struct ieee80211_if_sta
*ifsta
)
3508 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3509 struct ieee80211_sta_bss
*bss
;
3510 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3511 struct ieee80211_supported_band
*sband
;
3512 u8 bssid
[ETH_ALEN
], *pos
;
3514 DECLARE_MAC_BUF(mac
);
3517 /* Easier testing, use fixed BSSID. */
3518 memset(bssid
, 0xfe, ETH_ALEN
);
3520 /* Generate random, not broadcast, locally administered BSSID. Mix in
3521 * own MAC address to make sure that devices that do not have proper
3522 * random number generator get different BSSID. */
3523 get_random_bytes(bssid
, ETH_ALEN
);
3524 for (i
= 0; i
< ETH_ALEN
; i
++)
3525 bssid
[i
] ^= dev
->dev_addr
[i
];
3530 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID %s\n",
3531 dev
->name
, print_mac(mac
, bssid
));
3533 bss
= ieee80211_rx_bss_add(dev
, bssid
,
3534 local
->hw
.conf
.channel
->center_freq
,
3535 sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
);
3539 bss
->band
= local
->hw
.conf
.channel
->band
;
3540 sband
= local
->hw
.wiphy
->bands
[bss
->band
];
3542 if (local
->hw
.conf
.beacon_int
== 0)
3543 local
->hw
.conf
.beacon_int
= 10000;
3544 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
3545 bss
->last_update
= jiffies
;
3546 bss
->capability
= WLAN_CAPABILITY_IBSS
;
3548 if (sdata
->default_key
)
3549 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
3551 sdata
->drop_unencrypted
= 0;
3553 bss
->supp_rates_len
= sband
->n_bitrates
;
3554 pos
= bss
->supp_rates
;
3555 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
3556 int rate
= sband
->bitrates
[i
].bitrate
;
3557 *pos
++ = (u8
) (rate
/ 5);
3560 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3564 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
3565 struct ieee80211_if_sta
*ifsta
)
3567 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3568 struct ieee80211_sta_bss
*bss
;
3572 DECLARE_MAC_BUF(mac
);
3573 DECLARE_MAC_BUF(mac2
);
3575 if (ifsta
->ssid_len
== 0)
3578 active_ibss
= ieee80211_sta_active_ibss(dev
);
3579 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3580 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
3581 dev
->name
, active_ibss
);
3582 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3583 spin_lock_bh(&local
->sta_bss_lock
);
3584 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3585 if (ifsta
->ssid_len
!= bss
->ssid_len
||
3586 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
3587 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
3589 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3590 printk(KERN_DEBUG
" bssid=%s found\n",
3591 print_mac(mac
, bss
->bssid
));
3592 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3593 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
3595 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
3598 spin_unlock_bh(&local
->sta_bss_lock
);
3600 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3601 printk(KERN_DEBUG
" sta_find_ibss: selected %s current "
3602 "%s\n", print_mac(mac
, bssid
), print_mac(mac2
, ifsta
->bssid
));
3603 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3604 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
3605 (bss
= ieee80211_rx_bss_get(dev
, bssid
,
3606 local
->hw
.conf
.channel
->center_freq
,
3607 ifsta
->ssid
, ifsta
->ssid_len
))) {
3608 printk(KERN_DEBUG
"%s: Selected IBSS BSSID %s"
3609 " based on configured SSID\n",
3610 dev
->name
, print_mac(mac
, bssid
));
3611 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3613 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3614 printk(KERN_DEBUG
" did not try to join ibss\n");
3615 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3617 /* Selected IBSS not found in current scan results - try to scan */
3618 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3619 !ieee80211_sta_active_ibss(dev
)) {
3620 mod_timer(&ifsta
->timer
, jiffies
+
3621 IEEE80211_IBSS_MERGE_INTERVAL
);
3622 } else if (time_after(jiffies
, local
->last_scan_completed
+
3623 IEEE80211_SCAN_INTERVAL
)) {
3624 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
3625 "join\n", dev
->name
);
3626 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
3628 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
3629 int interval
= IEEE80211_SCAN_INTERVAL
;
3631 if (time_after(jiffies
, ifsta
->ibss_join_req
+
3632 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
3633 if ((ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) &&
3634 (!(local
->oper_channel
->flags
&
3635 IEEE80211_CHAN_NO_IBSS
)))
3636 return ieee80211_sta_create_ibss(dev
, ifsta
);
3637 if (ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) {
3638 printk(KERN_DEBUG
"%s: IBSS not allowed on"
3639 " %d MHz\n", dev
->name
,
3640 local
->hw
.conf
.channel
->center_freq
);
3643 /* No IBSS found - decrease scan interval and continue
3645 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
3648 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3649 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
3657 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
3659 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3660 struct ieee80211_if_sta
*ifsta
;
3662 if (len
> IEEE80211_MAX_SSID_LEN
)
3665 ifsta
= &sdata
->u
.sta
;
3667 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
3668 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
3669 memcpy(ifsta
->ssid
, ssid
, len
);
3670 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
3671 ifsta
->ssid_len
= len
;
3674 ifsta
->flags
|= IEEE80211_STA_SSID_SET
;
3676 ifsta
->flags
&= ~IEEE80211_STA_SSID_SET
;
3677 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3678 !(ifsta
->flags
& IEEE80211_STA_BSSID_SET
)) {
3679 ifsta
->ibss_join_req
= jiffies
;
3680 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3681 return ieee80211_sta_find_ibss(dev
, ifsta
);
3687 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
3689 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3690 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3691 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
3692 *len
= ifsta
->ssid_len
;
3697 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
3699 struct ieee80211_sub_if_data
*sdata
;
3700 struct ieee80211_if_sta
*ifsta
;
3703 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3704 ifsta
= &sdata
->u
.sta
;
3706 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
3707 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
3708 res
= ieee80211_if_config(dev
);
3710 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
3711 "the low-level driver\n", dev
->name
);
3716 if (is_valid_ether_addr(bssid
))
3717 ifsta
->flags
|= IEEE80211_STA_BSSID_SET
;
3719 ifsta
->flags
&= ~IEEE80211_STA_BSSID_SET
;
3725 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
3726 struct ieee80211_sub_if_data
*sdata
,
3729 struct sk_buff
*skb
;
3730 struct ieee80211_hdr
*nullfunc
;
3733 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
3735 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
3736 "frame\n", sdata
->dev
->name
);
3739 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3741 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
3742 memset(nullfunc
, 0, 24);
3743 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
3744 IEEE80211_FCTL_TODS
;
3746 fc
|= IEEE80211_FCTL_PM
;
3747 nullfunc
->frame_control
= cpu_to_le16(fc
);
3748 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3749 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
3750 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3752 ieee80211_sta_tx(sdata
->dev
, skb
, 0);
3756 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
3758 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
3759 ieee80211_vif_is_mesh(&sdata
->vif
))
3760 ieee80211_sta_timer((unsigned long)sdata
);
3763 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
3765 struct ieee80211_local
*local
= hw_to_local(hw
);
3766 struct net_device
*dev
= local
->scan_dev
;
3767 struct ieee80211_sub_if_data
*sdata
;
3768 union iwreq_data wrqu
;
3770 local
->last_scan_completed
= jiffies
;
3771 memset(&wrqu
, 0, sizeof(wrqu
));
3772 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
3774 if (local
->sta_hw_scanning
) {
3775 local
->sta_hw_scanning
= 0;
3776 if (ieee80211_hw_config(local
))
3777 printk(KERN_DEBUG
"%s: failed to restore operational "
3778 "channel after scan\n", dev
->name
);
3779 /* Restart STA timer for HW scan case */
3781 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
)
3782 ieee80211_restart_sta_timer(sdata
);
3788 local
->sta_sw_scanning
= 0;
3789 if (ieee80211_hw_config(local
))
3790 printk(KERN_DEBUG
"%s: failed to restore operational "
3791 "channel after scan\n", dev
->name
);
3794 netif_tx_lock_bh(local
->mdev
);
3795 local
->filter_flags
&= ~FIF_BCN_PRBRESP_PROMISC
;
3796 local
->ops
->configure_filter(local_to_hw(local
),
3797 FIF_BCN_PRBRESP_PROMISC
,
3798 &local
->filter_flags
,
3799 local
->mdev
->mc_count
,
3800 local
->mdev
->mc_list
);
3802 netif_tx_unlock_bh(local
->mdev
);
3805 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3807 /* No need to wake the master device. */
3808 if (sdata
->dev
== local
->mdev
)
3811 /* Tell AP we're back */
3812 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3813 sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
)
3814 ieee80211_send_nullfunc(local
, sdata
, 0);
3816 ieee80211_restart_sta_timer(sdata
);
3818 netif_wake_queue(sdata
->dev
);
3823 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3824 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
3825 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3826 if (!(ifsta
->flags
& IEEE80211_STA_BSSID_SET
) ||
3827 (!ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3828 !ieee80211_sta_active_ibss(dev
)))
3829 ieee80211_sta_find_ibss(dev
, ifsta
);
3832 EXPORT_SYMBOL(ieee80211_scan_completed
);
3834 void ieee80211_sta_scan_work(struct work_struct
*work
)
3836 struct ieee80211_local
*local
=
3837 container_of(work
, struct ieee80211_local
, scan_work
.work
);
3838 struct net_device
*dev
= local
->scan_dev
;
3839 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3840 struct ieee80211_supported_band
*sband
;
3841 struct ieee80211_channel
*chan
;
3843 unsigned long next_delay
= 0;
3845 if (!local
->sta_sw_scanning
)
3848 switch (local
->scan_state
) {
3849 case SCAN_SET_CHANNEL
:
3851 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3852 * after we successfully scanned the last channel of the last
3853 * band (and the last band is supported by the hw)
3855 if (local
->scan_band
< IEEE80211_NUM_BANDS
)
3856 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3861 * If we are at an unsupported band and have more bands
3862 * left to scan, advance to the next supported one.
3864 while (!sband
&& local
->scan_band
< IEEE80211_NUM_BANDS
- 1) {
3866 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3867 local
->scan_channel_idx
= 0;
3870 /* if no more bands/channels left, complete scan */
3871 if (!sband
|| local
->scan_channel_idx
>= sband
->n_channels
) {
3872 ieee80211_scan_completed(local_to_hw(local
));
3876 chan
= &sband
->channels
[local
->scan_channel_idx
];
3878 if (chan
->flags
& IEEE80211_CHAN_DISABLED
||
3879 (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3880 chan
->flags
& IEEE80211_CHAN_NO_IBSS
))
3884 local
->scan_channel
= chan
;
3885 if (ieee80211_hw_config(local
)) {
3886 printk(KERN_DEBUG
"%s: failed to set freq to "
3887 "%d MHz for scan\n", dev
->name
,
3893 /* advance state machine to next channel/band */
3894 local
->scan_channel_idx
++;
3895 if (local
->scan_channel_idx
>= sband
->n_channels
) {
3897 * scan_band may end up == IEEE80211_NUM_BANDS, but
3898 * we'll catch that case above and complete the scan
3899 * if that is the case.
3902 local
->scan_channel_idx
= 0;
3908 next_delay
= IEEE80211_PROBE_DELAY
+
3909 usecs_to_jiffies(local
->hw
.channel_change_time
);
3910 local
->scan_state
= SCAN_SEND_PROBE
;
3912 case SCAN_SEND_PROBE
:
3913 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
3914 local
->scan_state
= SCAN_SET_CHANNEL
;
3916 if (local
->scan_channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
3918 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
3919 local
->scan_ssid_len
);
3920 next_delay
= IEEE80211_CHANNEL_TIME
;
3924 if (local
->sta_sw_scanning
)
3925 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3930 static int ieee80211_sta_start_scan(struct net_device
*dev
,
3931 u8
*ssid
, size_t ssid_len
)
3933 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3934 struct ieee80211_sub_if_data
*sdata
;
3936 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
3939 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3940 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3943 * ScanType: ACTIVE, PASSIVE
3944 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3945 * a Probe frame during active scanning
3947 * MinChannelTime (>= ProbeDelay), in TU
3948 * MaxChannelTime: (>= MinChannelTime), in TU
3951 /* MLME-SCAN.confirm
3953 * ResultCode: SUCCESS, INVALID_PARAMETERS
3956 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3957 if (local
->scan_dev
== dev
)
3962 if (local
->ops
->hw_scan
) {
3963 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
3966 local
->sta_hw_scanning
= 1;
3967 local
->scan_dev
= dev
;
3972 local
->sta_sw_scanning
= 1;
3975 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3977 /* Don't stop the master interface, otherwise we can't transmit
3979 if (sdata
->dev
== local
->mdev
)
3982 netif_stop_queue(sdata
->dev
);
3983 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3984 (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
))
3985 ieee80211_send_nullfunc(local
, sdata
, 1);
3990 local
->scan_ssid_len
= ssid_len
;
3991 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
3993 local
->scan_ssid_len
= 0;
3994 local
->scan_state
= SCAN_SET_CHANNEL
;
3995 local
->scan_channel_idx
= 0;
3996 local
->scan_band
= IEEE80211_BAND_2GHZ
;
3997 local
->scan_dev
= dev
;
3999 netif_tx_lock_bh(local
->mdev
);
4000 local
->filter_flags
|= FIF_BCN_PRBRESP_PROMISC
;
4001 local
->ops
->configure_filter(local_to_hw(local
),
4002 FIF_BCN_PRBRESP_PROMISC
,
4003 &local
->filter_flags
,
4004 local
->mdev
->mc_count
,
4005 local
->mdev
->mc_list
);
4006 netif_tx_unlock_bh(local
->mdev
);
4008 /* TODO: start scan as soon as all nullfunc frames are ACKed */
4009 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
4010 IEEE80211_CHANNEL_TIME
);
4016 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
4018 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4019 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4020 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4022 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
4023 return ieee80211_sta_start_scan(dev
, ssid
, ssid_len
);
4025 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
4026 if (local
->scan_dev
== dev
)
4031 ifsta
->scan_ssid_len
= ssid_len
;
4033 memcpy(ifsta
->scan_ssid
, ssid
, ssid_len
);
4034 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
4035 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
4040 ieee80211_sta_scan_result(struct net_device
*dev
,
4041 struct ieee80211_sta_bss
*bss
,
4042 char *current_ev
, char *end_buf
)
4044 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4045 struct iw_event iwe
;
4047 if (time_after(jiffies
,
4048 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
4051 memset(&iwe
, 0, sizeof(iwe
));
4052 iwe
.cmd
= SIOCGIWAP
;
4053 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
4054 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
4055 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4058 memset(&iwe
, 0, sizeof(iwe
));
4059 iwe
.cmd
= SIOCGIWESSID
;
4060 if (bss_mesh_cfg(bss
)) {
4061 iwe
.u
.data
.length
= bss_mesh_id_len(bss
);
4062 iwe
.u
.data
.flags
= 1;
4063 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4066 iwe
.u
.data
.length
= bss
->ssid_len
;
4067 iwe
.u
.data
.flags
= 1;
4068 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4072 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
4073 || bss_mesh_cfg(bss
)) {
4074 memset(&iwe
, 0, sizeof(iwe
));
4075 iwe
.cmd
= SIOCGIWMODE
;
4076 if (bss_mesh_cfg(bss
))
4077 iwe
.u
.mode
= IW_MODE_MESH
;
4078 else if (bss
->capability
& WLAN_CAPABILITY_ESS
)
4079 iwe
.u
.mode
= IW_MODE_MASTER
;
4081 iwe
.u
.mode
= IW_MODE_ADHOC
;
4082 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4086 memset(&iwe
, 0, sizeof(iwe
));
4087 iwe
.cmd
= SIOCGIWFREQ
;
4088 iwe
.u
.freq
.m
= bss
->freq
;
4090 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4093 memset(&iwe
, 0, sizeof(iwe
));
4094 iwe
.cmd
= SIOCGIWFREQ
;
4095 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->freq
);
4097 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4100 memset(&iwe
, 0, sizeof(iwe
));
4102 iwe
.u
.qual
.qual
= bss
->qual
;
4103 iwe
.u
.qual
.level
= bss
->signal
;
4104 iwe
.u
.qual
.noise
= bss
->noise
;
4105 iwe
.u
.qual
.updated
= local
->wstats_flags
;
4106 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4109 memset(&iwe
, 0, sizeof(iwe
));
4110 iwe
.cmd
= SIOCGIWENCODE
;
4111 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
4112 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
4114 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
4115 iwe
.u
.data
.length
= 0;
4116 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
4118 if (bss
&& bss
->wpa_ie
) {
4119 memset(&iwe
, 0, sizeof(iwe
));
4120 iwe
.cmd
= IWEVGENIE
;
4121 iwe
.u
.data
.length
= bss
->wpa_ie_len
;
4122 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4126 if (bss
&& bss
->rsn_ie
) {
4127 memset(&iwe
, 0, sizeof(iwe
));
4128 iwe
.cmd
= IWEVGENIE
;
4129 iwe
.u
.data
.length
= bss
->rsn_ie_len
;
4130 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4134 if (bss
&& bss
->supp_rates_len
> 0) {
4135 /* display all supported rates in readable format */
4136 char *p
= current_ev
+ IW_EV_LCP_LEN
;
4139 memset(&iwe
, 0, sizeof(iwe
));
4140 iwe
.cmd
= SIOCGIWRATE
;
4141 /* Those two flags are ignored... */
4142 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
4144 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
4145 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
4147 p
= iwe_stream_add_value(current_ev
, p
,
4148 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
4155 buf
= kmalloc(30, GFP_ATOMIC
);
4157 memset(&iwe
, 0, sizeof(iwe
));
4158 iwe
.cmd
= IWEVCUSTOM
;
4159 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
4160 iwe
.u
.data
.length
= strlen(buf
);
4161 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4167 if (bss_mesh_cfg(bss
)) {
4169 u8
*cfg
= bss_mesh_cfg(bss
);
4170 buf
= kmalloc(50, GFP_ATOMIC
);
4172 memset(&iwe
, 0, sizeof(iwe
));
4173 iwe
.cmd
= IWEVCUSTOM
;
4174 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
4175 iwe
.u
.data
.length
= strlen(buf
);
4176 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4178 sprintf(buf
, "Path Selection Protocol ID: "
4179 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
4181 iwe
.u
.data
.length
= strlen(buf
);
4182 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4184 sprintf(buf
, "Path Selection Metric ID: "
4185 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
4187 iwe
.u
.data
.length
= strlen(buf
);
4188 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4190 sprintf(buf
, "Congestion Control Mode ID: "
4191 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
4193 iwe
.u
.data
.length
= strlen(buf
);
4194 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4196 sprintf(buf
, "Channel Precedence: "
4197 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
4199 iwe
.u
.data
.length
= strlen(buf
);
4200 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4210 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
4212 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4213 char *current_ev
= buf
;
4214 char *end_buf
= buf
+ len
;
4215 struct ieee80211_sta_bss
*bss
;
4217 spin_lock_bh(&local
->sta_bss_lock
);
4218 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
4219 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
4220 spin_unlock_bh(&local
->sta_bss_lock
);
4223 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
4226 spin_unlock_bh(&local
->sta_bss_lock
);
4227 return current_ev
- buf
;
4231 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
4233 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4234 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4236 kfree(ifsta
->extra_ie
);
4238 ifsta
->extra_ie
= NULL
;
4239 ifsta
->extra_ie_len
= 0;
4242 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
4243 if (!ifsta
->extra_ie
) {
4244 ifsta
->extra_ie_len
= 0;
4247 memcpy(ifsta
->extra_ie
, ie
, len
);
4248 ifsta
->extra_ie_len
= len
;
4253 struct sta_info
*ieee80211_ibss_add_sta(struct net_device
*dev
,
4254 struct sk_buff
*skb
, u8
*bssid
,
4257 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4258 struct sta_info
*sta
;
4259 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4260 DECLARE_MAC_BUF(mac
);
4262 /* TODO: Could consider removing the least recently used entry and
4263 * allow new one to be added. */
4264 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
4265 if (net_ratelimit()) {
4266 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
4267 "entry %s\n", dev
->name
, print_mac(mac
, addr
));
4272 printk(KERN_DEBUG
"%s: Adding new IBSS station %s (dev=%s)\n",
4273 wiphy_name(local
->hw
.wiphy
), print_mac(mac
, addr
), dev
->name
);
4275 sta
= sta_info_alloc(sdata
, addr
, GFP_ATOMIC
);
4279 set_sta_flags(sta
, WLAN_STA_AUTHORIZED
);
4281 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] =
4282 sdata
->u
.sta
.supp_rates_bits
[local
->hw
.conf
.channel
->band
];
4284 rate_control_rate_init(sta
, local
);
4286 if (sta_info_insert(sta
))
4293 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
4295 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4296 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4298 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
4301 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
4302 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
4305 ieee80211_send_deauth(dev
, ifsta
, reason
);
4306 ieee80211_set_disassoc(dev
, ifsta
, 1);
4311 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
4313 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4314 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4316 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
4319 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
4322 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
))
4325 ieee80211_send_disassoc(dev
, ifsta
, reason
);
4326 ieee80211_set_disassoc(dev
, ifsta
, 0);
4330 void ieee80211_notify_mac(struct ieee80211_hw
*hw
,
4331 enum ieee80211_notification_types notif_type
)
4333 struct ieee80211_local
*local
= hw_to_local(hw
);
4334 struct ieee80211_sub_if_data
*sdata
;
4336 switch (notif_type
) {
4337 case IEEE80211_NOTIFY_RE_ASSOC
:
4339 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4341 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
) {
4342 ieee80211_sta_req_auth(sdata
->dev
,
4351 EXPORT_SYMBOL(ieee80211_notify_mac
);