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
);
661 static void ieee80211_send_assoc(struct net_device
*dev
,
662 struct ieee80211_if_sta
*ifsta
)
664 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
666 struct ieee80211_mgmt
*mgmt
;
670 struct ieee80211_sta_bss
*bss
;
672 struct ieee80211_supported_band
*sband
;
674 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
675 sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
678 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
679 "frame\n", dev
->name
);
682 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
684 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
686 capab
= ifsta
->capab
;
688 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
) {
689 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
690 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
691 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
692 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
695 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
696 local
->hw
.conf
.channel
->center_freq
,
697 ifsta
->ssid
, ifsta
->ssid_len
);
699 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
700 capab
|= WLAN_CAPABILITY_PRIVACY
;
703 ieee80211_rx_bss_put(dev
, bss
);
706 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
708 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
709 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
710 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
712 if (ifsta
->flags
& IEEE80211_STA_PREV_BSSID_SET
) {
714 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
715 IEEE80211_STYPE_REASSOC_REQ
);
716 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
717 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
718 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
722 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
723 IEEE80211_STYPE_ASSOC_REQ
);
724 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
725 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
729 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
730 *pos
++ = WLAN_EID_SSID
;
731 *pos
++ = ifsta
->ssid_len
;
732 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
734 len
= sband
->n_bitrates
;
737 pos
= skb_put(skb
, len
+ 2);
738 *pos
++ = WLAN_EID_SUPP_RATES
;
740 for (i
= 0; i
< len
; i
++) {
741 int rate
= sband
->bitrates
[i
].bitrate
;
742 *pos
++ = (u8
) (rate
/ 5);
745 if (sband
->n_bitrates
> len
) {
746 pos
= skb_put(skb
, sband
->n_bitrates
- len
+ 2);
747 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
748 *pos
++ = sband
->n_bitrates
- len
;
749 for (i
= len
; i
< sband
->n_bitrates
; i
++) {
750 int rate
= sband
->bitrates
[i
].bitrate
;
751 *pos
++ = (u8
) (rate
/ 5);
755 if (ifsta
->extra_ie
) {
756 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
757 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
760 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
761 pos
= skb_put(skb
, 9);
762 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
763 *pos
++ = 7; /* len */
764 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
767 *pos
++ = 2; /* WME */
768 *pos
++ = 0; /* WME info */
769 *pos
++ = 1; /* WME ver */
773 /* wmm support is a must to HT */
774 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
) &&
775 sband
->ht_info
.ht_supported
) {
776 __le16 tmp
= cpu_to_le16(sband
->ht_info
.cap
);
777 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
)+2);
778 *pos
++ = WLAN_EID_HT_CAPABILITY
;
779 *pos
++ = sizeof(struct ieee80211_ht_cap
);
780 memset(pos
, 0, sizeof(struct ieee80211_ht_cap
));
781 memcpy(pos
, &tmp
, sizeof(u16
));
783 /* TODO: needs a define here for << 2 */
784 *pos
++ = sband
->ht_info
.ampdu_factor
|
785 (sband
->ht_info
.ampdu_density
<< 2);
786 memcpy(pos
, sband
->ht_info
.supp_mcs_set
, 16);
789 kfree(ifsta
->assocreq_ies
);
790 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
791 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_KERNEL
);
792 if (ifsta
->assocreq_ies
)
793 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
795 ieee80211_sta_tx(dev
, skb
, 0);
799 static void ieee80211_send_deauth(struct net_device
*dev
,
800 struct ieee80211_if_sta
*ifsta
, u16 reason
)
802 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
804 struct ieee80211_mgmt
*mgmt
;
806 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
808 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
809 "frame\n", dev
->name
);
812 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
814 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
816 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
817 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
818 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
819 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
820 IEEE80211_STYPE_DEAUTH
);
822 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
824 ieee80211_sta_tx(dev
, skb
, 0);
828 static void ieee80211_send_disassoc(struct net_device
*dev
,
829 struct ieee80211_if_sta
*ifsta
, u16 reason
)
831 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
833 struct ieee80211_mgmt
*mgmt
;
835 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
837 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
838 "frame\n", dev
->name
);
841 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
843 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
845 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
846 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
847 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
848 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
849 IEEE80211_STYPE_DISASSOC
);
851 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
853 ieee80211_sta_tx(dev
, skb
, 0);
857 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
858 struct ieee80211_if_sta
*ifsta
)
860 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
861 struct ieee80211_sta_bss
*bss
;
866 if (!ifsta
|| (ifsta
->flags
& IEEE80211_STA_MIXED_CELL
))
869 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
870 local
->hw
.conf
.channel
->center_freq
,
871 ifsta
->ssid
, ifsta
->ssid_len
);
875 bss_privacy
= !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
876 wep_privacy
= !!ieee80211_sta_wep_configured(dev
);
877 privacy_invoked
= !!(ifsta
->flags
& IEEE80211_STA_PRIVACY_INVOKED
);
879 ieee80211_rx_bss_put(dev
, bss
);
881 if ((bss_privacy
== wep_privacy
) || (bss_privacy
== privacy_invoked
))
888 static void ieee80211_associate(struct net_device
*dev
,
889 struct ieee80211_if_sta
*ifsta
)
891 DECLARE_MAC_BUF(mac
);
893 ifsta
->assoc_tries
++;
894 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
895 printk(KERN_DEBUG
"%s: association with AP %s"
897 dev
->name
, print_mac(mac
, ifsta
->bssid
));
898 ifsta
->state
= IEEE80211_DISABLED
;
902 ifsta
->state
= IEEE80211_ASSOCIATE
;
903 printk(KERN_DEBUG
"%s: associate with AP %s\n",
904 dev
->name
, print_mac(mac
, ifsta
->bssid
));
905 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
906 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
907 "mixed-cell disabled - abort association\n", dev
->name
);
908 ifsta
->state
= IEEE80211_DISABLED
;
912 ieee80211_send_assoc(dev
, ifsta
);
914 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_ASSOC_TIMEOUT
);
918 static void ieee80211_associated(struct net_device
*dev
,
919 struct ieee80211_if_sta
*ifsta
)
921 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
922 struct sta_info
*sta
;
924 DECLARE_MAC_BUF(mac
);
926 /* TODO: start monitoring current AP signal quality and number of
927 * missed beacons. Scan other channels every now and then and search
929 /* TODO: remove expired BSSes */
931 ifsta
->state
= IEEE80211_ASSOCIATED
;
935 sta
= sta_info_get(local
, ifsta
->bssid
);
937 printk(KERN_DEBUG
"%s: No STA entry for own AP %s\n",
938 dev
->name
, print_mac(mac
, ifsta
->bssid
));
942 if (time_after(jiffies
,
943 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
944 if (ifsta
->flags
& IEEE80211_STA_PROBEREQ_POLL
) {
945 printk(KERN_DEBUG
"%s: No ProbeResp from "
946 "current AP %s - assume out of "
948 dev
->name
, print_mac(mac
, ifsta
->bssid
));
950 sta_info_unlink(&sta
);
952 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
954 local
->scan_ssid_len
);
955 ifsta
->flags
^= IEEE80211_STA_PROBEREQ_POLL
;
957 ifsta
->flags
&= ~IEEE80211_STA_PROBEREQ_POLL
;
958 if (time_after(jiffies
, ifsta
->last_probe
+
959 IEEE80211_PROBE_INTERVAL
)) {
960 ifsta
->last_probe
= jiffies
;
961 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
971 sta_info_destroy(sta
);
974 ifsta
->state
= IEEE80211_DISABLED
;
975 ieee80211_set_associated(dev
, ifsta
, 0);
977 mod_timer(&ifsta
->timer
, jiffies
+
978 IEEE80211_MONITORING_INTERVAL
);
983 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
984 u8
*ssid
, size_t ssid_len
)
986 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
987 struct ieee80211_supported_band
*sband
;
989 struct ieee80211_mgmt
*mgmt
;
990 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
993 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200);
995 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
996 "request\n", dev
->name
);
999 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1001 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1002 memset(mgmt
, 0, 24);
1003 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1004 IEEE80211_STYPE_PROBE_REQ
);
1005 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1007 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
1008 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
1010 memset(mgmt
->da
, 0xff, ETH_ALEN
);
1011 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
1013 pos
= skb_put(skb
, 2 + ssid_len
);
1014 *pos
++ = WLAN_EID_SSID
;
1016 memcpy(pos
, ssid
, ssid_len
);
1018 supp_rates
= skb_put(skb
, 2);
1019 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
1021 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
1023 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1024 struct ieee80211_rate
*rate
= &sband
->bitrates
[i
];
1026 pos
= skb_put(skb
, 1);
1028 } else if (supp_rates
[1] == 8) {
1029 esupp_rates
= skb_put(skb
, 3);
1030 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
1032 pos
= &esupp_rates
[2];
1034 pos
= skb_put(skb
, 1);
1037 *pos
= rate
->bitrate
/ 5;
1040 ieee80211_sta_tx(dev
, skb
, 0);
1044 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
1046 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1047 if (!sdata
|| !sdata
->default_key
||
1048 sdata
->default_key
->conf
.alg
!= ALG_WEP
)
1054 static void ieee80211_auth_completed(struct net_device
*dev
,
1055 struct ieee80211_if_sta
*ifsta
)
1057 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
1058 ifsta
->flags
|= IEEE80211_STA_AUTHENTICATED
;
1059 ieee80211_associate(dev
, ifsta
);
1063 static void ieee80211_auth_challenge(struct net_device
*dev
,
1064 struct ieee80211_if_sta
*ifsta
,
1065 struct ieee80211_mgmt
*mgmt
,
1069 struct ieee802_11_elems elems
;
1071 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
1072 pos
= mgmt
->u
.auth
.variable
;
1073 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1074 if (!elems
.challenge
) {
1075 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
1076 "frame\n", dev
->name
);
1079 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
1080 elems
.challenge_len
+ 2, 1);
1083 static void ieee80211_send_addba_resp(struct net_device
*dev
, u8
*da
, u16 tid
,
1084 u8 dialog_token
, u16 status
, u16 policy
,
1085 u16 buf_size
, u16 timeout
)
1087 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1088 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1089 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1090 struct sk_buff
*skb
;
1091 struct ieee80211_mgmt
*mgmt
;
1094 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
);
1097 printk(KERN_DEBUG
"%s: failed to allocate buffer "
1098 "for addba resp frame\n", dev
->name
);
1102 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1103 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1104 memset(mgmt
, 0, 24);
1105 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1106 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1107 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1108 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1110 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1111 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1112 IEEE80211_STYPE_ACTION
);
1114 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_resp
));
1115 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1116 mgmt
->u
.action
.u
.addba_resp
.action_code
= WLAN_ACTION_ADDBA_RESP
;
1117 mgmt
->u
.action
.u
.addba_resp
.dialog_token
= dialog_token
;
1119 capab
= (u16
)(policy
<< 1); /* bit 1 aggregation policy */
1120 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1121 capab
|= (u16
)(buf_size
<< 6); /* bit 15:6 max size of aggregation */
1123 mgmt
->u
.action
.u
.addba_resp
.capab
= cpu_to_le16(capab
);
1124 mgmt
->u
.action
.u
.addba_resp
.timeout
= cpu_to_le16(timeout
);
1125 mgmt
->u
.action
.u
.addba_resp
.status
= cpu_to_le16(status
);
1127 ieee80211_sta_tx(dev
, skb
, 0);
1132 void ieee80211_send_addba_request(struct net_device
*dev
, const u8
*da
,
1133 u16 tid
, u8 dialog_token
, u16 start_seq_num
,
1134 u16 agg_size
, u16 timeout
)
1136 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1137 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1138 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1139 struct sk_buff
*skb
;
1140 struct ieee80211_mgmt
*mgmt
;
1143 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
);
1146 printk(KERN_ERR
"%s: failed to allocate buffer "
1147 "for addba request frame\n", dev
->name
);
1150 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1151 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1152 memset(mgmt
, 0, 24);
1153 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1154 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1155 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1156 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1158 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1160 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1161 IEEE80211_STYPE_ACTION
);
1163 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_req
));
1165 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1166 mgmt
->u
.action
.u
.addba_req
.action_code
= WLAN_ACTION_ADDBA_REQ
;
1168 mgmt
->u
.action
.u
.addba_req
.dialog_token
= dialog_token
;
1169 capab
= (u16
)(1 << 1); /* bit 1 aggregation policy */
1170 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1171 capab
|= (u16
)(agg_size
<< 6); /* bit 15:6 max size of aggergation */
1173 mgmt
->u
.action
.u
.addba_req
.capab
= cpu_to_le16(capab
);
1175 mgmt
->u
.action
.u
.addba_req
.timeout
= cpu_to_le16(timeout
);
1176 mgmt
->u
.action
.u
.addba_req
.start_seq_num
=
1177 cpu_to_le16(start_seq_num
<< 4);
1179 ieee80211_sta_tx(dev
, skb
, 0);
1182 static void ieee80211_sta_process_addba_request(struct net_device
*dev
,
1183 struct ieee80211_mgmt
*mgmt
,
1186 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1187 struct ieee80211_hw
*hw
= &local
->hw
;
1188 struct ieee80211_conf
*conf
= &hw
->conf
;
1189 struct sta_info
*sta
;
1190 struct tid_ampdu_rx
*tid_agg_rx
;
1191 u16 capab
, tid
, timeout
, ba_policy
, buf_size
, start_seq_num
, status
;
1193 int ret
= -EOPNOTSUPP
;
1194 DECLARE_MAC_BUF(mac
);
1198 sta
= sta_info_get(local
, mgmt
->sa
);
1204 /* extract session parameters from addba request frame */
1205 dialog_token
= mgmt
->u
.action
.u
.addba_req
.dialog_token
;
1206 timeout
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.timeout
);
1208 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.start_seq_num
) >> 4;
1210 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1211 ba_policy
= (capab
& IEEE80211_ADDBA_PARAM_POLICY_MASK
) >> 1;
1212 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1213 buf_size
= (capab
& IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
) >> 6;
1215 status
= WLAN_STATUS_REQUEST_DECLINED
;
1217 /* sanity check for incoming parameters:
1218 * check if configuration can support the BA policy
1219 * and if buffer size does not exceeds max value */
1220 if (((ba_policy
!= 1)
1221 && (!(conf
->ht_conf
.cap
& IEEE80211_HT_CAP_DELAY_BA
)))
1222 || (buf_size
> IEEE80211_MAX_AMPDU_BUF
)) {
1223 status
= WLAN_STATUS_INVALID_QOS_PARAM
;
1224 #ifdef CONFIG_MAC80211_HT_DEBUG
1225 if (net_ratelimit())
1226 printk(KERN_DEBUG
"AddBA Req with bad params from "
1227 "%s on tid %u. policy %d, buffer size %d\n",
1228 print_mac(mac
, mgmt
->sa
), tid
, ba_policy
,
1230 #endif /* CONFIG_MAC80211_HT_DEBUG */
1233 /* determine default buffer size */
1234 if (buf_size
== 0) {
1235 struct ieee80211_supported_band
*sband
;
1237 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
1238 buf_size
= IEEE80211_MIN_AMPDU_BUF
;
1239 buf_size
= buf_size
<< sband
->ht_info
.ampdu_factor
;
1243 /* examine state machine */
1244 spin_lock_bh(&sta
->lock
);
1246 if (sta
->ampdu_mlme
.tid_state_rx
[tid
] != HT_AGG_STATE_IDLE
) {
1247 #ifdef CONFIG_MAC80211_HT_DEBUG
1248 if (net_ratelimit())
1249 printk(KERN_DEBUG
"unexpected AddBA Req from "
1251 print_mac(mac
, mgmt
->sa
), tid
);
1252 #endif /* CONFIG_MAC80211_HT_DEBUG */
1256 /* prepare A-MPDU MLME for Rx aggregation */
1257 sta
->ampdu_mlme
.tid_rx
[tid
] =
1258 kmalloc(sizeof(struct tid_ampdu_rx
), GFP_ATOMIC
);
1259 if (!sta
->ampdu_mlme
.tid_rx
[tid
]) {
1260 if (net_ratelimit())
1261 printk(KERN_ERR
"allocate rx mlme to tid %d failed\n",
1266 sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
.function
=
1267 sta_rx_agg_session_timer_expired
;
1268 sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
.data
=
1269 (unsigned long)&sta
->timer_to_tid
[tid
];
1270 init_timer(&sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
);
1272 tid_agg_rx
= sta
->ampdu_mlme
.tid_rx
[tid
];
1274 /* prepare reordering buffer */
1275 tid_agg_rx
->reorder_buf
=
1276 kmalloc(buf_size
* sizeof(struct sk_buf
*), GFP_ATOMIC
);
1277 if (!tid_agg_rx
->reorder_buf
) {
1278 if (net_ratelimit())
1279 printk(KERN_ERR
"can not allocate reordering buffer "
1280 "to tid %d\n", tid
);
1281 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]);
1284 memset(tid_agg_rx
->reorder_buf
, 0,
1285 buf_size
* sizeof(struct sk_buf
*));
1287 if (local
->ops
->ampdu_action
)
1288 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_START
,
1289 sta
->addr
, tid
, &start_seq_num
);
1290 #ifdef CONFIG_MAC80211_HT_DEBUG
1291 printk(KERN_DEBUG
"Rx A-MPDU request on tid %d result %d\n", tid
, ret
);
1292 #endif /* CONFIG_MAC80211_HT_DEBUG */
1295 kfree(tid_agg_rx
->reorder_buf
);
1297 sta
->ampdu_mlme
.tid_rx
[tid
] = NULL
;
1301 /* change state and send addba resp */
1302 sta
->ampdu_mlme
.tid_state_rx
[tid
] = HT_AGG_STATE_OPERATIONAL
;
1303 tid_agg_rx
->dialog_token
= dialog_token
;
1304 tid_agg_rx
->ssn
= start_seq_num
;
1305 tid_agg_rx
->head_seq_num
= start_seq_num
;
1306 tid_agg_rx
->buf_size
= buf_size
;
1307 tid_agg_rx
->timeout
= timeout
;
1308 tid_agg_rx
->stored_mpdu_num
= 0;
1309 status
= WLAN_STATUS_SUCCESS
;
1311 spin_unlock_bh(&sta
->lock
);
1314 ieee80211_send_addba_resp(sta
->sdata
->dev
, sta
->addr
, tid
,
1315 dialog_token
, status
, 1, buf_size
, timeout
);
1319 static void ieee80211_sta_process_addba_resp(struct net_device
*dev
,
1320 struct ieee80211_mgmt
*mgmt
,
1323 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1324 struct ieee80211_hw
*hw
= &local
->hw
;
1325 struct sta_info
*sta
;
1332 sta
= sta_info_get(local
, mgmt
->sa
);
1338 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.capab
);
1339 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1341 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
1343 spin_lock_bh(&sta
->lock
);
1345 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1346 spin_unlock_bh(&sta
->lock
);
1347 printk(KERN_DEBUG
"state not HT_ADDBA_REQUESTED_MSK:"
1349 goto addba_resp_exit
;
1352 if (mgmt
->u
.action
.u
.addba_resp
.dialog_token
!=
1353 sta
->ampdu_mlme
.tid_tx
[tid
]->dialog_token
) {
1354 spin_unlock_bh(&sta
->lock
);
1355 #ifdef CONFIG_MAC80211_HT_DEBUG
1356 printk(KERN_DEBUG
"wrong addBA response token, tid %d\n", tid
);
1357 #endif /* CONFIG_MAC80211_HT_DEBUG */
1358 goto addba_resp_exit
;
1361 del_timer_sync(&sta
->ampdu_mlme
.tid_tx
[tid
]->addba_resp_timer
);
1362 #ifdef CONFIG_MAC80211_HT_DEBUG
1363 printk(KERN_DEBUG
"switched off addBA timer for tid %d \n", tid
);
1364 #endif /* CONFIG_MAC80211_HT_DEBUG */
1365 if (le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.status
)
1366 == WLAN_STATUS_SUCCESS
) {
1367 if (*state
& HT_ADDBA_RECEIVED_MSK
)
1368 printk(KERN_DEBUG
"double addBA response\n");
1370 *state
|= HT_ADDBA_RECEIVED_MSK
;
1371 sta
->ampdu_mlme
.addba_req_num
[tid
] = 0;
1373 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
1374 printk(KERN_DEBUG
"Aggregation on for tid %d \n", tid
);
1375 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
1378 spin_unlock_bh(&sta
->lock
);
1379 printk(KERN_DEBUG
"recipient accepted agg: tid %d \n", tid
);
1381 printk(KERN_DEBUG
"recipient rejected agg: tid %d \n", tid
);
1383 sta
->ampdu_mlme
.addba_req_num
[tid
]++;
1384 /* this will allow the state check in stop_BA_session */
1385 *state
= HT_AGG_STATE_OPERATIONAL
;
1386 spin_unlock_bh(&sta
->lock
);
1387 ieee80211_stop_tx_ba_session(hw
, sta
->addr
, tid
,
1388 WLAN_BACK_INITIATOR
);
1395 void ieee80211_send_delba(struct net_device
*dev
, const u8
*da
, u16 tid
,
1396 u16 initiator
, u16 reason_code
)
1398 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1399 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1400 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1401 struct sk_buff
*skb
;
1402 struct ieee80211_mgmt
*mgmt
;
1405 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
);
1408 printk(KERN_ERR
"%s: failed to allocate buffer "
1409 "for delba frame\n", dev
->name
);
1413 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1414 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1415 memset(mgmt
, 0, 24);
1416 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1417 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1418 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1419 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1421 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1422 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1423 IEEE80211_STYPE_ACTION
);
1425 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.delba
));
1427 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1428 mgmt
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
1429 params
= (u16
)(initiator
<< 11); /* bit 11 initiator */
1430 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
1432 mgmt
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
1433 mgmt
->u
.action
.u
.delba
.reason_code
= cpu_to_le16(reason_code
);
1435 ieee80211_sta_tx(dev
, skb
, 0);
1438 void ieee80211_sta_stop_rx_ba_session(struct net_device
*dev
, u8
*ra
, u16 tid
,
1439 u16 initiator
, u16 reason
)
1441 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1442 struct ieee80211_hw
*hw
= &local
->hw
;
1443 struct sta_info
*sta
;
1445 DECLARE_MAC_BUF(mac
);
1449 sta
= sta_info_get(local
, ra
);
1455 /* check if TID is in operational state */
1456 spin_lock_bh(&sta
->lock
);
1457 if (sta
->ampdu_mlme
.tid_state_rx
[tid
]
1458 != HT_AGG_STATE_OPERATIONAL
) {
1459 spin_unlock_bh(&sta
->lock
);
1463 sta
->ampdu_mlme
.tid_state_rx
[tid
] =
1464 HT_AGG_STATE_REQ_STOP_BA_MSK
|
1465 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
1466 spin_unlock_bh(&sta
->lock
);
1468 /* stop HW Rx aggregation. ampdu_action existence
1469 * already verified in session init so we add the BUG_ON */
1470 BUG_ON(!local
->ops
->ampdu_action
);
1472 #ifdef CONFIG_MAC80211_HT_DEBUG
1473 printk(KERN_DEBUG
"Rx BA session stop requested for %s tid %u\n",
1474 print_mac(mac
, ra
), tid
);
1475 #endif /* CONFIG_MAC80211_HT_DEBUG */
1477 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_STOP
,
1480 printk(KERN_DEBUG
"HW problem - can not stop rx "
1481 "aggergation for tid %d\n", tid
);
1483 /* shutdown timer has not expired */
1484 if (initiator
!= WLAN_BACK_TIMER
)
1485 del_timer_sync(&sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
);
1487 /* check if this is a self generated aggregation halt */
1488 if (initiator
== WLAN_BACK_RECIPIENT
|| initiator
== WLAN_BACK_TIMER
)
1489 ieee80211_send_delba(dev
, ra
, tid
, 0, reason
);
1491 /* free the reordering buffer */
1492 for (i
= 0; i
< sta
->ampdu_mlme
.tid_rx
[tid
]->buf_size
; i
++) {
1493 if (sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
]) {
1494 /* release the reordered frames */
1495 dev_kfree_skb(sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
]);
1496 sta
->ampdu_mlme
.tid_rx
[tid
]->stored_mpdu_num
--;
1497 sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
] = NULL
;
1500 /* free resources */
1501 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
);
1502 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]);
1503 sta
->ampdu_mlme
.tid_rx
[tid
] = NULL
;
1504 sta
->ampdu_mlme
.tid_state_rx
[tid
] = HT_AGG_STATE_IDLE
;
1510 static void ieee80211_sta_process_delba(struct net_device
*dev
,
1511 struct ieee80211_mgmt
*mgmt
, size_t len
)
1513 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1514 struct sta_info
*sta
;
1517 DECLARE_MAC_BUF(mac
);
1521 sta
= sta_info_get(local
, mgmt
->sa
);
1527 params
= le16_to_cpu(mgmt
->u
.action
.u
.delba
.params
);
1528 tid
= (params
& IEEE80211_DELBA_PARAM_TID_MASK
) >> 12;
1529 initiator
= (params
& IEEE80211_DELBA_PARAM_INITIATOR_MASK
) >> 11;
1531 #ifdef CONFIG_MAC80211_HT_DEBUG
1532 if (net_ratelimit())
1533 printk(KERN_DEBUG
"delba from %s (%s) tid %d reason code %d\n",
1534 print_mac(mac
, mgmt
->sa
),
1535 initiator
? "initiator" : "recipient", tid
,
1536 mgmt
->u
.action
.u
.delba
.reason_code
);
1537 #endif /* CONFIG_MAC80211_HT_DEBUG */
1539 if (initiator
== WLAN_BACK_INITIATOR
)
1540 ieee80211_sta_stop_rx_ba_session(dev
, sta
->addr
, tid
,
1541 WLAN_BACK_INITIATOR
, 0);
1542 else { /* WLAN_BACK_RECIPIENT */
1543 spin_lock_bh(&sta
->lock
);
1544 sta
->ampdu_mlme
.tid_state_tx
[tid
] =
1545 HT_AGG_STATE_OPERATIONAL
;
1546 spin_unlock_bh(&sta
->lock
);
1547 ieee80211_stop_tx_ba_session(&local
->hw
, sta
->addr
, tid
,
1548 WLAN_BACK_RECIPIENT
);
1554 * After sending add Block Ack request we activated a timer until
1555 * add Block Ack response will arrive from the recipient.
1556 * If this timer expires sta_addba_resp_timer_expired will be executed.
1558 void sta_addba_resp_timer_expired(unsigned long data
)
1560 /* not an elegant detour, but there is no choice as the timer passes
1561 * only one argument, and both sta_info and TID are needed, so init
1562 * flow in sta_info_create gives the TID as data, while the timer_to_id
1563 * array gives the sta through container_of */
1564 u16 tid
= *(int *)data
;
1565 struct sta_info
*temp_sta
= container_of((void *)data
,
1566 struct sta_info
, timer_to_tid
[tid
]);
1568 struct ieee80211_local
*local
= temp_sta
->local
;
1569 struct ieee80211_hw
*hw
= &local
->hw
;
1570 struct sta_info
*sta
;
1575 sta
= sta_info_get(local
, temp_sta
->addr
);
1581 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
1582 /* check if the TID waits for addBA response */
1583 spin_lock_bh(&sta
->lock
);
1584 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1585 spin_unlock_bh(&sta
->lock
);
1586 *state
= HT_AGG_STATE_IDLE
;
1587 printk(KERN_DEBUG
"timer expired on tid %d but we are not "
1588 "expecting addBA response there", tid
);
1589 goto timer_expired_exit
;
1592 printk(KERN_DEBUG
"addBA response timer expired on tid %d\n", tid
);
1594 /* go through the state check in stop_BA_session */
1595 *state
= HT_AGG_STATE_OPERATIONAL
;
1596 spin_unlock_bh(&sta
->lock
);
1597 ieee80211_stop_tx_ba_session(hw
, temp_sta
->addr
, tid
,
1598 WLAN_BACK_INITIATOR
);
1605 * After accepting the AddBA Request we activated a timer,
1606 * resetting it after each frame that arrives from the originator.
1607 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1609 static void sta_rx_agg_session_timer_expired(unsigned long data
)
1611 /* not an elegant detour, but there is no choice as the timer passes
1612 * only one argument, and verious sta_info are needed here, so init
1613 * flow in sta_info_create gives the TID as data, while the timer_to_id
1614 * array gives the sta through container_of */
1615 u8
*ptid
= (u8
*)data
;
1616 u8
*timer_to_id
= ptid
- *ptid
;
1617 struct sta_info
*sta
= container_of(timer_to_id
, struct sta_info
,
1620 printk(KERN_DEBUG
"rx session timer expired on tid %d\n", (u16
)*ptid
);
1621 ieee80211_sta_stop_rx_ba_session(sta
->sdata
->dev
, sta
->addr
,
1622 (u16
)*ptid
, WLAN_BACK_TIMER
,
1623 WLAN_REASON_QSTA_TIMEOUT
);
1626 void ieee80211_sta_tear_down_BA_sessions(struct net_device
*dev
, u8
*addr
)
1628 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1631 for (i
= 0; i
< STA_TID_NUM
; i
++) {
1632 ieee80211_stop_tx_ba_session(&local
->hw
, addr
, i
,
1633 WLAN_BACK_INITIATOR
);
1634 ieee80211_sta_stop_rx_ba_session(dev
, addr
, i
,
1635 WLAN_BACK_RECIPIENT
,
1636 WLAN_REASON_QSTA_LEAVE_QBSS
);
1640 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
1641 struct ieee80211_if_sta
*ifsta
,
1642 struct ieee80211_mgmt
*mgmt
,
1645 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1646 u16 auth_alg
, auth_transaction
, status_code
;
1647 DECLARE_MAC_BUF(mac
);
1649 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
1650 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
) {
1651 printk(KERN_DEBUG
"%s: authentication frame received from "
1652 "%s, but not in authenticate state - ignored\n",
1653 dev
->name
, print_mac(mac
, mgmt
->sa
));
1658 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
1659 "received from %s - ignored\n",
1660 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1664 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1665 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1666 printk(KERN_DEBUG
"%s: authentication frame received from "
1667 "unknown AP (SA=%s BSSID=%s) - "
1668 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1669 print_mac(mac
, mgmt
->bssid
));
1673 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1674 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
1675 printk(KERN_DEBUG
"%s: authentication frame received from "
1676 "unknown BSSID (SA=%s BSSID=%s) - "
1677 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1678 print_mac(mac
, mgmt
->bssid
));
1682 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
1683 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
1684 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
1686 printk(KERN_DEBUG
"%s: RX authentication from %s (alg=%d "
1687 "transaction=%d status=%d)\n",
1688 dev
->name
, print_mac(mac
, mgmt
->sa
), auth_alg
,
1689 auth_transaction
, status_code
);
1691 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
1692 /* IEEE 802.11 standard does not require authentication in IBSS
1693 * networks and most implementations do not seem to use it.
1694 * However, try to reply to authentication attempts if someone
1695 * has actually implemented this.
1696 * TODO: Could implement shared key authentication. */
1697 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
1698 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
1699 "frame (alg=%d transaction=%d)\n",
1700 dev
->name
, auth_alg
, auth_transaction
);
1703 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
1706 if (auth_alg
!= ifsta
->auth_alg
||
1707 auth_transaction
!= ifsta
->auth_transaction
) {
1708 printk(KERN_DEBUG
"%s: unexpected authentication frame "
1709 "(alg=%d transaction=%d)\n",
1710 dev
->name
, auth_alg
, auth_transaction
);
1714 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1715 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
1716 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
1717 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
1719 const int num_algs
= ARRAY_SIZE(algs
);
1721 algs
[0] = algs
[1] = algs
[2] = 0xff;
1722 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1723 algs
[0] = WLAN_AUTH_OPEN
;
1724 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1725 algs
[1] = WLAN_AUTH_SHARED_KEY
;
1726 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1727 algs
[2] = WLAN_AUTH_LEAP
;
1728 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
1730 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
1734 for (i
= 0; i
< num_algs
; i
++) {
1736 if (pos
>= num_algs
)
1738 if (algs
[pos
] == ifsta
->auth_alg
||
1741 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
1742 !ieee80211_sta_wep_configured(dev
))
1744 ifsta
->auth_alg
= algs
[pos
];
1745 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
1747 dev
->name
, ifsta
->auth_alg
);
1754 switch (ifsta
->auth_alg
) {
1755 case WLAN_AUTH_OPEN
:
1756 case WLAN_AUTH_LEAP
:
1757 ieee80211_auth_completed(dev
, ifsta
);
1759 case WLAN_AUTH_SHARED_KEY
:
1760 if (ifsta
->auth_transaction
== 4)
1761 ieee80211_auth_completed(dev
, ifsta
);
1763 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
);
1769 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
1770 struct ieee80211_if_sta
*ifsta
,
1771 struct ieee80211_mgmt
*mgmt
,
1775 DECLARE_MAC_BUF(mac
);
1778 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
1779 "received from %s - ignored\n",
1780 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1784 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1785 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1786 "unknown AP (SA=%s BSSID=%s) - "
1787 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1788 print_mac(mac
, mgmt
->bssid
));
1792 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1794 printk(KERN_DEBUG
"%s: RX deauthentication from %s"
1796 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1798 if (ifsta
->flags
& IEEE80211_STA_AUTHENTICATED
)
1799 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1801 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1802 ifsta
->state
== IEEE80211_ASSOCIATE
||
1803 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1804 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1805 mod_timer(&ifsta
->timer
, jiffies
+
1806 IEEE80211_RETRY_AUTH_INTERVAL
);
1809 ieee80211_set_disassoc(dev
, ifsta
, 1);
1810 ifsta
->flags
&= ~IEEE80211_STA_AUTHENTICATED
;
1814 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1815 struct ieee80211_if_sta
*ifsta
,
1816 struct ieee80211_mgmt
*mgmt
,
1820 DECLARE_MAC_BUF(mac
);
1823 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1824 "received from %s - ignored\n",
1825 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1829 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1830 printk(KERN_DEBUG
"%s: disassociation frame received from "
1831 "unknown AP (SA=%s BSSID=%s) - "
1832 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1833 print_mac(mac
, mgmt
->bssid
));
1837 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1839 printk(KERN_DEBUG
"%s: RX disassociation from %s"
1841 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1843 if (ifsta
->flags
& IEEE80211_STA_ASSOCIATED
)
1844 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1846 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1847 ifsta
->state
= IEEE80211_ASSOCIATE
;
1848 mod_timer(&ifsta
->timer
, jiffies
+
1849 IEEE80211_RETRY_AUTH_INTERVAL
);
1852 ieee80211_set_disassoc(dev
, ifsta
, 0);
1856 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
1857 struct ieee80211_if_sta
*ifsta
,
1858 struct ieee80211_mgmt
*mgmt
,
1862 struct ieee80211_local
*local
= sdata
->local
;
1863 struct net_device
*dev
= sdata
->dev
;
1864 struct ieee80211_supported_band
*sband
;
1865 struct sta_info
*sta
;
1866 u64 rates
, basic_rates
;
1867 u16 capab_info
, status_code
, aid
;
1868 struct ieee802_11_elems elems
;
1869 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
1872 DECLARE_MAC_BUF(mac
);
1873 bool have_higher_than_11mbit
= false;
1875 /* AssocResp and ReassocResp have identical structure, so process both
1876 * of them in this function. */
1878 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1879 printk(KERN_DEBUG
"%s: association frame received from "
1880 "%s, but not in associate state - ignored\n",
1881 dev
->name
, print_mac(mac
, mgmt
->sa
));
1886 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1887 "received from %s - ignored\n",
1888 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1892 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1893 printk(KERN_DEBUG
"%s: association frame received from "
1894 "unknown AP (SA=%s BSSID=%s) - "
1895 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1896 print_mac(mac
, mgmt
->bssid
));
1900 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1901 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1902 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1904 printk(KERN_DEBUG
"%s: RX %sssocResp from %s (capab=0x%x "
1905 "status=%d aid=%d)\n",
1906 dev
->name
, reassoc
? "Rea" : "A", print_mac(mac
, mgmt
->sa
),
1907 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
1909 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1910 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1911 dev
->name
, status_code
);
1912 /* if this was a reassociation, ensure we try a "full"
1913 * association next time. This works around some broken APs
1914 * which do not correctly reject reassociation requests. */
1915 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
1919 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1920 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1921 "set\n", dev
->name
, aid
);
1922 aid
&= ~(BIT(15) | BIT(14));
1924 pos
= mgmt
->u
.assoc_resp
.variable
;
1925 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1927 if (!elems
.supp_rates
) {
1928 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1933 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1935 ifsta
->ap_capab
= capab_info
;
1937 kfree(ifsta
->assocresp_ies
);
1938 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1939 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_KERNEL
);
1940 if (ifsta
->assocresp_ies
)
1941 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1945 /* Add STA entry for the AP */
1946 sta
= sta_info_get(local
, ifsta
->bssid
);
1948 struct ieee80211_sta_bss
*bss
;
1951 sta
= sta_info_alloc(sdata
, ifsta
->bssid
, GFP_ATOMIC
);
1953 printk(KERN_DEBUG
"%s: failed to alloc STA entry for"
1954 " the AP\n", dev
->name
);
1958 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
1959 local
->hw
.conf
.channel
->center_freq
,
1960 ifsta
->ssid
, ifsta
->ssid_len
);
1962 sta
->last_signal
= bss
->signal
;
1963 sta
->last_qual
= bss
->qual
;
1964 sta
->last_noise
= bss
->noise
;
1965 ieee80211_rx_bss_put(dev
, bss
);
1968 err
= sta_info_insert(sta
);
1970 printk(KERN_DEBUG
"%s: failed to insert STA entry for"
1971 " the AP (error %d)\n", dev
->name
, err
);
1978 * FIXME: Do we really need to update the sta_info's information here?
1979 * We already know about the AP (we found it in our list) so it
1980 * should already be filled with the right info, no?
1981 * As is stands, all this is racy because typically we assume
1982 * the information that is filled in here (except flags) doesn't
1983 * change while a STA structure is alive. As such, it should move
1984 * to between the sta_info_alloc() and sta_info_insert() above.
1987 set_sta_flags(sta
, WLAN_STA_AUTH
| WLAN_STA_ASSOC
| WLAN_STA_ASSOC_AP
|
1988 WLAN_STA_AUTHORIZED
);
1992 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
1994 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
1995 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
1998 have_higher_than_11mbit
= true;
2000 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2001 if (sband
->bitrates
[j
].bitrate
== rate
)
2003 if (elems
.supp_rates
[i
] & 0x80)
2004 basic_rates
|= BIT(j
);
2008 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
2009 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
2012 have_higher_than_11mbit
= true;
2014 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2015 if (sband
->bitrates
[j
].bitrate
== rate
)
2017 if (elems
.ext_supp_rates
[i
] & 0x80)
2018 basic_rates
|= BIT(j
);
2022 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] = rates
;
2023 sdata
->basic_rates
= basic_rates
;
2025 /* cf. IEEE 802.11 9.2.12 */
2026 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
2027 have_higher_than_11mbit
)
2028 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
2030 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
2032 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&& elems
.wmm_param
&&
2033 (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
2034 struct ieee80211_ht_bss_info bss_info
;
2035 ieee80211_ht_cap_ie_to_ht_info(
2036 (struct ieee80211_ht_cap
*)
2037 elems
.ht_cap_elem
, &sta
->ht_info
);
2038 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2039 (struct ieee80211_ht_addt_info
*)
2040 elems
.ht_info_elem
, &bss_info
);
2041 ieee80211_handle_ht(local
, 1, &sta
->ht_info
, &bss_info
);
2044 rate_control_rate_init(sta
, local
);
2046 if (elems
.wmm_param
) {
2047 set_sta_flags(sta
, WLAN_STA_WME
);
2049 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2050 elems
.wmm_param_len
);
2054 /* set AID and assoc capability,
2055 * ieee80211_set_associated() will tell the driver */
2056 bss_conf
->aid
= aid
;
2057 bss_conf
->assoc_capability
= capab_info
;
2058 ieee80211_set_associated(dev
, ifsta
, 1);
2060 ieee80211_associated(dev
, ifsta
);
2064 /* Caller must hold local->sta_bss_lock */
2065 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
2066 struct ieee80211_sta_bss
*bss
)
2068 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2071 if (bss_mesh_cfg(bss
))
2072 hash_idx
= mesh_id_hash(bss_mesh_id(bss
),
2073 bss_mesh_id_len(bss
));
2075 hash_idx
= STA_HASH(bss
->bssid
);
2077 bss
->hnext
= local
->sta_bss_hash
[hash_idx
];
2078 local
->sta_bss_hash
[hash_idx
] = bss
;
2082 /* Caller must hold local->sta_bss_lock */
2083 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
2084 struct ieee80211_sta_bss
*bss
)
2086 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2087 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
2088 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
2092 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
2095 prev
->hnext
= bss
->hnext
;
2104 static struct ieee80211_sta_bss
*
2105 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
, int freq
,
2106 u8
*ssid
, u8 ssid_len
)
2108 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2109 struct ieee80211_sta_bss
*bss
;
2111 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2114 atomic_inc(&bss
->users
);
2115 atomic_inc(&bss
->users
);
2116 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
2118 if (ssid
&& ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
2119 memcpy(bss
->ssid
, ssid
, ssid_len
);
2120 bss
->ssid_len
= ssid_len
;
2123 spin_lock_bh(&local
->sta_bss_lock
);
2124 /* TODO: order by RSSI? */
2125 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2126 __ieee80211_rx_bss_hash_add(dev
, bss
);
2127 spin_unlock_bh(&local
->sta_bss_lock
);
2131 static struct ieee80211_sta_bss
*
2132 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int freq
,
2133 u8
*ssid
, u8 ssid_len
)
2135 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2136 struct ieee80211_sta_bss
*bss
;
2138 spin_lock_bh(&local
->sta_bss_lock
);
2139 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
2141 if (!bss_mesh_cfg(bss
) &&
2142 !memcmp(bss
->bssid
, bssid
, ETH_ALEN
) &&
2143 bss
->freq
== freq
&&
2144 bss
->ssid_len
== ssid_len
&&
2145 (ssid_len
== 0 || !memcmp(bss
->ssid
, ssid
, ssid_len
))) {
2146 atomic_inc(&bss
->users
);
2151 spin_unlock_bh(&local
->sta_bss_lock
);
2155 #ifdef CONFIG_MAC80211_MESH
2156 static struct ieee80211_sta_bss
*
2157 ieee80211_rx_mesh_bss_get(struct net_device
*dev
, u8
*mesh_id
, int mesh_id_len
,
2158 u8
*mesh_cfg
, int freq
)
2160 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2161 struct ieee80211_sta_bss
*bss
;
2163 spin_lock_bh(&local
->sta_bss_lock
);
2164 bss
= local
->sta_bss_hash
[mesh_id_hash(mesh_id
, mesh_id_len
)];
2166 if (bss_mesh_cfg(bss
) &&
2167 !memcmp(bss_mesh_cfg(bss
), mesh_cfg
, MESH_CFG_CMP_LEN
) &&
2168 bss
->freq
== freq
&&
2169 mesh_id_len
== bss
->mesh_id_len
&&
2170 (mesh_id_len
== 0 || !memcmp(bss
->mesh_id
, mesh_id
,
2172 atomic_inc(&bss
->users
);
2177 spin_unlock_bh(&local
->sta_bss_lock
);
2181 static struct ieee80211_sta_bss
*
2182 ieee80211_rx_mesh_bss_add(struct net_device
*dev
, u8
*mesh_id
, int mesh_id_len
,
2183 u8
*mesh_cfg
, int mesh_config_len
, int freq
)
2185 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2186 struct ieee80211_sta_bss
*bss
;
2188 if (mesh_config_len
!= MESH_CFG_LEN
)
2191 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2195 bss
->mesh_cfg
= kmalloc(MESH_CFG_CMP_LEN
, GFP_ATOMIC
);
2196 if (!bss
->mesh_cfg
) {
2201 if (mesh_id_len
&& mesh_id_len
<= IEEE80211_MAX_MESH_ID_LEN
) {
2202 bss
->mesh_id
= kmalloc(mesh_id_len
, GFP_ATOMIC
);
2203 if (!bss
->mesh_id
) {
2204 kfree(bss
->mesh_cfg
);
2208 memcpy(bss
->mesh_id
, mesh_id
, mesh_id_len
);
2211 atomic_inc(&bss
->users
);
2212 atomic_inc(&bss
->users
);
2213 memcpy(bss
->mesh_cfg
, mesh_cfg
, MESH_CFG_CMP_LEN
);
2214 bss
->mesh_id_len
= mesh_id_len
;
2216 spin_lock_bh(&local
->sta_bss_lock
);
2217 /* TODO: order by RSSI? */
2218 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2219 __ieee80211_rx_bss_hash_add(dev
, bss
);
2220 spin_unlock_bh(&local
->sta_bss_lock
);
2225 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
2231 kfree(bss_mesh_id(bss
));
2232 kfree(bss_mesh_cfg(bss
));
2237 static void ieee80211_rx_bss_put(struct net_device
*dev
,
2238 struct ieee80211_sta_bss
*bss
)
2240 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2243 if (!atomic_dec_and_lock(&bss
->users
, &local
->sta_bss_lock
)) {
2248 __ieee80211_rx_bss_hash_del(dev
, bss
);
2249 list_del(&bss
->list
);
2250 spin_unlock_bh(&local
->sta_bss_lock
);
2251 ieee80211_rx_bss_free(bss
);
2255 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
2257 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2258 spin_lock_init(&local
->sta_bss_lock
);
2259 INIT_LIST_HEAD(&local
->sta_bss_list
);
2263 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
2265 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2266 struct ieee80211_sta_bss
*bss
, *tmp
;
2268 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
2269 ieee80211_rx_bss_put(dev
, bss
);
2273 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
2274 struct ieee80211_if_sta
*ifsta
,
2275 struct ieee80211_sta_bss
*bss
)
2277 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2278 int res
, rates
, i
, j
;
2279 struct sk_buff
*skb
;
2280 struct ieee80211_mgmt
*mgmt
;
2281 struct ieee80211_tx_control control
;
2282 struct rate_selection ratesel
;
2284 struct ieee80211_sub_if_data
*sdata
;
2285 struct ieee80211_supported_band
*sband
;
2287 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2289 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2291 /* Remove possible STA entries from other IBSS networks. */
2292 sta_info_flush_delayed(sdata
);
2294 if (local
->ops
->reset_tsf
) {
2295 /* Reset own TSF to allow time synchronization work. */
2296 local
->ops
->reset_tsf(local_to_hw(local
));
2298 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
2299 res
= ieee80211_if_config(dev
);
2303 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2305 sdata
->drop_unencrypted
= bss
->capability
&
2306 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
2308 res
= ieee80211_set_freq(local
, bss
->freq
);
2310 if (local
->oper_channel
->flags
& IEEE80211_CHAN_NO_IBSS
) {
2311 printk(KERN_DEBUG
"%s: IBSS not allowed on frequency "
2312 "%d MHz\n", dev
->name
, local
->oper_channel
->center_freq
);
2316 /* Set beacon template */
2317 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 400);
2322 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2324 mgmt
= (struct ieee80211_mgmt
*)
2325 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2326 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2327 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2328 IEEE80211_STYPE_BEACON
);
2329 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2330 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2331 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2332 mgmt
->u
.beacon
.beacon_int
=
2333 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2334 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2336 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2337 *pos
++ = WLAN_EID_SSID
;
2338 *pos
++ = ifsta
->ssid_len
;
2339 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2341 rates
= bss
->supp_rates_len
;
2344 pos
= skb_put(skb
, 2 + rates
);
2345 *pos
++ = WLAN_EID_SUPP_RATES
;
2347 memcpy(pos
, bss
->supp_rates
, rates
);
2349 if (bss
->band
== IEEE80211_BAND_2GHZ
) {
2350 pos
= skb_put(skb
, 2 + 1);
2351 *pos
++ = WLAN_EID_DS_PARAMS
;
2353 *pos
++ = ieee80211_frequency_to_channel(bss
->freq
);
2356 pos
= skb_put(skb
, 2 + 2);
2357 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2359 /* FIX: set ATIM window based on scan results */
2363 if (bss
->supp_rates_len
> 8) {
2364 rates
= bss
->supp_rates_len
- 8;
2365 pos
= skb_put(skb
, 2 + rates
);
2366 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2368 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2371 memset(&control
, 0, sizeof(control
));
2372 rate_control_get_rate(dev
, sband
, skb
, &ratesel
);
2373 if (!ratesel
.rate
) {
2374 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2375 "for IBSS beacon\n", dev
->name
);
2378 control
.vif
= &sdata
->vif
;
2379 control
.tx_rate
= ratesel
.rate
;
2380 if (sdata
->bss_conf
.use_short_preamble
&&
2381 ratesel
.rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
2382 control
.flags
|= IEEE80211_TXCTL_SHORT_PREAMBLE
;
2383 control
.antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
2384 control
.flags
|= IEEE80211_TXCTL_NO_ACK
;
2385 control
.retry_limit
= 1;
2387 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2388 if (ifsta
->probe_resp
) {
2389 mgmt
= (struct ieee80211_mgmt
*)
2390 ifsta
->probe_resp
->data
;
2391 mgmt
->frame_control
=
2392 IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2393 IEEE80211_STYPE_PROBE_RESP
);
2395 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2396 "template for IBSS\n", dev
->name
);
2399 if (local
->ops
->beacon_update
&&
2400 local
->ops
->beacon_update(local_to_hw(local
),
2401 skb
, &control
) == 0) {
2402 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2403 "template\n", dev
->name
);
2408 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2409 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2410 int bitrate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2411 for (j
= 0; j
< sband
->n_bitrates
; j
++)
2412 if (sband
->bitrates
[j
].bitrate
== bitrate
)
2415 ifsta
->supp_rates_bits
[local
->hw
.conf
.channel
->band
] = rates
;
2417 ieee80211_sta_def_wmm_params(dev
, bss
, 1);
2421 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2422 "template\n", dev
->name
);
2426 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2427 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2429 ieee80211_rx_bss_put(dev
, bss
);
2434 u64
ieee80211_sta_get_rates(struct ieee80211_local
*local
,
2435 struct ieee802_11_elems
*elems
,
2436 enum ieee80211_band band
)
2438 struct ieee80211_supported_band
*sband
;
2439 struct ieee80211_rate
*bitrates
;
2443 sband
= local
->hw
.wiphy
->bands
[band
];
2447 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2450 bitrates
= sband
->bitrates
;
2451 num_rates
= sband
->n_bitrates
;
2453 for (i
= 0; i
< elems
->supp_rates_len
+
2454 elems
->ext_supp_rates_len
; i
++) {
2457 if (i
< elems
->supp_rates_len
)
2458 rate
= elems
->supp_rates
[i
];
2459 else if (elems
->ext_supp_rates
)
2460 rate
= elems
->ext_supp_rates
2461 [i
- elems
->supp_rates_len
];
2462 own_rate
= 5 * (rate
& 0x7f);
2463 for (j
= 0; j
< num_rates
; j
++)
2464 if (bitrates
[j
].bitrate
== own_rate
)
2465 supp_rates
|= BIT(j
);
2471 static void ieee80211_rx_bss_info(struct net_device
*dev
,
2472 struct ieee80211_mgmt
*mgmt
,
2474 struct ieee80211_rx_status
*rx_status
,
2477 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2478 struct ieee802_11_elems elems
;
2481 struct ieee80211_sta_bss
*bss
;
2482 struct sta_info
*sta
;
2483 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2484 u64 beacon_timestamp
, rx_timestamp
;
2485 struct ieee80211_channel
*channel
;
2486 DECLARE_MAC_BUF(mac
);
2487 DECLARE_MAC_BUF(mac2
);
2489 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
2490 return; /* ignore ProbeResp to foreign address */
2493 printk(KERN_DEBUG
"%s: RX %s from %s to %s\n",
2494 dev
->name
, beacon
? "Beacon" : "Probe Response",
2495 print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
));
2498 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2502 beacon_timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
2503 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2505 if (ieee80211_vif_is_mesh(&sdata
->vif
) && elems
.mesh_id
&&
2506 elems
.mesh_config
&& mesh_matches_local(&elems
, dev
)) {
2507 u64 rates
= ieee80211_sta_get_rates(local
, &elems
,
2510 mesh_neighbour_update(mgmt
->sa
, rates
, dev
,
2511 mesh_peer_accepts_plinks(&elems
, dev
));
2516 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& elems
.supp_rates
&&
2517 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0 &&
2518 (sta
= sta_info_get(local
, mgmt
->sa
))) {
2520 u64 supp_rates
= ieee80211_sta_get_rates(local
, &elems
,
2523 prev_rates
= sta
->supp_rates
[rx_status
->band
];
2524 sta
->supp_rates
[rx_status
->band
] &= supp_rates
;
2525 if (sta
->supp_rates
[rx_status
->band
] == 0) {
2526 /* No matching rates - this should not really happen.
2527 * Make sure that at least one rate is marked
2528 * supported to avoid issues with TX rate ctrl. */
2529 sta
->supp_rates
[rx_status
->band
] =
2530 sdata
->u
.sta
.supp_rates_bits
[rx_status
->band
];
2532 if (sta
->supp_rates
[rx_status
->band
] != prev_rates
) {
2533 printk(KERN_DEBUG
"%s: updated supp_rates set for "
2534 "%s based on beacon info (0x%llx & 0x%llx -> "
2536 dev
->name
, print_mac(mac
, sta
->addr
),
2537 (unsigned long long) prev_rates
,
2538 (unsigned long long) supp_rates
,
2539 (unsigned long long) sta
->supp_rates
[rx_status
->band
]);
2545 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
2546 freq
= ieee80211_channel_to_frequency(elems
.ds_params
[0]);
2548 freq
= rx_status
->freq
;
2550 channel
= ieee80211_get_channel(local
->hw
.wiphy
, freq
);
2552 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
2555 #ifdef CONFIG_MAC80211_MESH
2556 if (elems
.mesh_config
)
2557 bss
= ieee80211_rx_mesh_bss_get(dev
, elems
.mesh_id
,
2558 elems
.mesh_id_len
, elems
.mesh_config
, freq
);
2561 bss
= ieee80211_rx_bss_get(dev
, mgmt
->bssid
, freq
,
2562 elems
.ssid
, elems
.ssid_len
);
2564 #ifdef CONFIG_MAC80211_MESH
2565 if (elems
.mesh_config
)
2566 bss
= ieee80211_rx_mesh_bss_add(dev
, elems
.mesh_id
,
2567 elems
.mesh_id_len
, elems
.mesh_config
,
2568 elems
.mesh_config_len
, freq
);
2571 bss
= ieee80211_rx_bss_add(dev
, mgmt
->bssid
, freq
,
2572 elems
.ssid
, elems
.ssid_len
);
2577 /* TODO: order by RSSI? */
2578 spin_lock_bh(&local
->sta_bss_lock
);
2579 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
2580 spin_unlock_bh(&local
->sta_bss_lock
);
2584 /* save the ERP value so that it is available at association time */
2585 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
2586 bss
->erp_value
= elems
.erp_info
[0];
2587 bss
->has_erp_value
= 1;
2590 if (elems
.ht_cap_elem
&&
2591 (!bss
->ht_ie
|| bss
->ht_ie_len
!= elems
.ht_cap_elem_len
||
2592 memcmp(bss
->ht_ie
, elems
.ht_cap_elem
, elems
.ht_cap_elem_len
))) {
2594 bss
->ht_ie
= kmalloc(elems
.ht_cap_elem_len
+ 2, GFP_ATOMIC
);
2596 memcpy(bss
->ht_ie
, elems
.ht_cap_elem
- 2,
2597 elems
.ht_cap_elem_len
+ 2);
2598 bss
->ht_ie_len
= elems
.ht_cap_elem_len
+ 2;
2601 } else if (!elems
.ht_cap_elem
&& bss
->ht_ie
) {
2607 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
2608 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2610 bss
->supp_rates_len
= 0;
2611 if (elems
.supp_rates
) {
2612 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2613 if (clen
> elems
.supp_rates_len
)
2614 clen
= elems
.supp_rates_len
;
2615 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
.supp_rates
,
2617 bss
->supp_rates_len
+= clen
;
2619 if (elems
.ext_supp_rates
) {
2620 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2621 if (clen
> elems
.ext_supp_rates_len
)
2622 clen
= elems
.ext_supp_rates_len
;
2623 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
2624 elems
.ext_supp_rates
, clen
);
2625 bss
->supp_rates_len
+= clen
;
2628 bss
->band
= rx_status
->band
;
2630 bss
->timestamp
= beacon_timestamp
;
2631 bss
->last_update
= jiffies
;
2632 bss
->signal
= rx_status
->signal
;
2633 bss
->noise
= rx_status
->noise
;
2634 bss
->qual
= rx_status
->qual
;
2635 if (!beacon
&& !bss
->probe_resp
)
2636 bss
->probe_resp
= true;
2639 * In STA mode, the remaining parameters should not be overridden
2640 * by beacons because they're not necessarily accurate there.
2642 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
2643 bss
->probe_resp
&& beacon
) {
2644 ieee80211_rx_bss_put(dev
, bss
);
2649 (!bss
->wpa_ie
|| bss
->wpa_ie_len
!= elems
.wpa_len
||
2650 memcmp(bss
->wpa_ie
, elems
.wpa
, elems
.wpa_len
))) {
2652 bss
->wpa_ie
= kmalloc(elems
.wpa_len
+ 2, GFP_ATOMIC
);
2654 memcpy(bss
->wpa_ie
, elems
.wpa
- 2, elems
.wpa_len
+ 2);
2655 bss
->wpa_ie_len
= elems
.wpa_len
+ 2;
2657 bss
->wpa_ie_len
= 0;
2658 } else if (!elems
.wpa
&& bss
->wpa_ie
) {
2661 bss
->wpa_ie_len
= 0;
2665 (!bss
->rsn_ie
|| bss
->rsn_ie_len
!= elems
.rsn_len
||
2666 memcmp(bss
->rsn_ie
, elems
.rsn
, elems
.rsn_len
))) {
2668 bss
->rsn_ie
= kmalloc(elems
.rsn_len
+ 2, GFP_ATOMIC
);
2670 memcpy(bss
->rsn_ie
, elems
.rsn
- 2, elems
.rsn_len
+ 2);
2671 bss
->rsn_ie_len
= elems
.rsn_len
+ 2;
2673 bss
->rsn_ie_len
= 0;
2674 } else if (!elems
.rsn
&& bss
->rsn_ie
) {
2677 bss
->rsn_ie_len
= 0;
2682 * http://www.wipo.int/pctdb/en/wo.jsp?wo=2007047181&IA=WO2007047181&DISPLAY=DESC
2686 * In particular, "Wi-Fi CERTIFIED for WMM - Support for Multimedia
2687 * Applications with Quality of Service in Wi-Fi Networks," Wi- Fi
2688 * Alliance (September 1, 2004) is incorporated by reference herein.
2689 * The inclusion of the WMM Parameters in probe responses and
2690 * association responses is mandatory for WMM enabled networks. The
2691 * inclusion of the WMM Parameters in beacons, however, is optional.
2694 if (elems
.wmm_param
&&
2695 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_param_len
||
2696 memcmp(bss
->wmm_ie
, elems
.wmm_param
, elems
.wmm_param_len
))) {
2698 bss
->wmm_ie
= kmalloc(elems
.wmm_param_len
+ 2, GFP_ATOMIC
);
2700 memcpy(bss
->wmm_ie
, elems
.wmm_param
- 2,
2701 elems
.wmm_param_len
+ 2);
2702 bss
->wmm_ie_len
= elems
.wmm_param_len
+ 2;
2704 bss
->wmm_ie_len
= 0;
2705 } else if (elems
.wmm_info
&&
2706 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_info_len
||
2707 memcmp(bss
->wmm_ie
, elems
.wmm_info
, elems
.wmm_info_len
))) {
2708 /* As for certain AP's Fifth bit is not set in WMM IE in
2709 * beacon frames.So while parsing the beacon frame the
2710 * wmm_info structure is used instead of wmm_param.
2711 * wmm_info structure was never used to set bss->wmm_ie.
2712 * This code fixes this problem by copying the WME
2713 * information from wmm_info to bss->wmm_ie and enabling
2714 * n-band association.
2717 bss
->wmm_ie
= kmalloc(elems
.wmm_info_len
+ 2, GFP_ATOMIC
);
2719 memcpy(bss
->wmm_ie
, elems
.wmm_info
- 2,
2720 elems
.wmm_info_len
+ 2);
2721 bss
->wmm_ie_len
= elems
.wmm_info_len
+ 2;
2723 bss
->wmm_ie_len
= 0;
2724 } else if (!elems
.wmm_param
&& !elems
.wmm_info
&& bss
->wmm_ie
) {
2727 bss
->wmm_ie_len
= 0;
2730 /* check if we need to merge IBSS */
2731 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
2732 !local
->sta_sw_scanning
&& !local
->sta_hw_scanning
&&
2733 bss
->capability
& WLAN_CAPABILITY_IBSS
&&
2734 bss
->freq
== local
->oper_channel
->center_freq
&&
2735 elems
.ssid_len
== sdata
->u
.sta
.ssid_len
&&
2736 memcmp(elems
.ssid
, sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
) == 0) {
2737 if (rx_status
->flag
& RX_FLAG_TSFT
) {
2738 /* in order for correct IBSS merging we need mactime
2740 * since mactime is defined as the time the first data
2741 * symbol of the frame hits the PHY, and the timestamp
2742 * of the beacon is defined as "the time that the data
2743 * symbol containing the first bit of the timestamp is
2744 * transmitted to the PHY plus the transmitting STA’s
2745 * delays through its local PHY from the MAC-PHY
2746 * interface to its interface with the WM"
2747 * (802.11 11.1.2) - equals the time this bit arrives at
2748 * the receiver - we have to take into account the
2749 * offset between the two.
2750 * e.g: at 1 MBit that means mactime is 192 usec earlier
2751 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2753 int rate
= local
->hw
.wiphy
->bands
[rx_status
->band
]->
2754 bitrates
[rx_status
->rate_idx
].bitrate
;
2755 rx_timestamp
= rx_status
->mactime
+ (24 * 8 * 10 / rate
);
2756 } else if (local
&& local
->ops
&& local
->ops
->get_tsf
)
2757 /* second best option: get current TSF */
2758 rx_timestamp
= local
->ops
->get_tsf(local_to_hw(local
));
2760 /* can't merge without knowing the TSF */
2761 rx_timestamp
= -1LLU;
2762 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2763 printk(KERN_DEBUG
"RX beacon SA=%s BSSID="
2764 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2765 print_mac(mac
, mgmt
->sa
),
2766 print_mac(mac2
, mgmt
->bssid
),
2767 (unsigned long long)rx_timestamp
,
2768 (unsigned long long)beacon_timestamp
,
2769 (unsigned long long)(rx_timestamp
- beacon_timestamp
),
2771 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2772 if (beacon_timestamp
> rx_timestamp
) {
2773 #ifndef CONFIG_MAC80211_IBSS_DEBUG
2774 if (net_ratelimit())
2776 printk(KERN_DEBUG
"%s: beacon TSF higher than "
2777 "local TSF - IBSS merge with BSSID %s\n",
2778 dev
->name
, print_mac(mac
, mgmt
->bssid
));
2779 ieee80211_sta_join_ibss(dev
, &sdata
->u
.sta
, bss
);
2780 ieee80211_ibss_add_sta(dev
, NULL
,
2781 mgmt
->bssid
, mgmt
->sa
);
2785 ieee80211_rx_bss_put(dev
, bss
);
2789 static void ieee80211_rx_mgmt_probe_resp(struct net_device
*dev
,
2790 struct ieee80211_mgmt
*mgmt
,
2792 struct ieee80211_rx_status
*rx_status
)
2794 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 0);
2798 static void ieee80211_rx_mgmt_beacon(struct net_device
*dev
,
2799 struct ieee80211_mgmt
*mgmt
,
2801 struct ieee80211_rx_status
*rx_status
)
2803 struct ieee80211_sub_if_data
*sdata
;
2804 struct ieee80211_if_sta
*ifsta
;
2806 struct ieee802_11_elems elems
;
2807 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2808 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
2811 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 1);
2813 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2814 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
2816 ifsta
= &sdata
->u
.sta
;
2818 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
) ||
2819 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
2822 /* Process beacon from the current BSS */
2823 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2827 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2829 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2830 elems
.wmm_param_len
);
2832 /* Do not send changes to driver if we are scanning. This removes
2833 * requirement that driver's bss_info_changed function needs to be
2835 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
2838 if (elems
.erp_info
&& elems
.erp_info_len
>= 1)
2839 changed
|= ieee80211_handle_erp_ie(sdata
, elems
.erp_info
[0]);
2841 u16 capab
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2842 changed
|= ieee80211_handle_protect_preamb(sdata
, false,
2843 (capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
) != 0);
2846 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&&
2847 elems
.wmm_param
&& conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
2848 struct ieee80211_ht_bss_info bss_info
;
2850 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2851 (struct ieee80211_ht_addt_info
*)
2852 elems
.ht_info_elem
, &bss_info
);
2853 changed
|= ieee80211_handle_ht(local
, 1, &conf
->ht_conf
,
2857 ieee80211_bss_info_change_notify(sdata
, changed
);
2861 static void ieee80211_rx_mgmt_probe_req(struct net_device
*dev
,
2862 struct ieee80211_if_sta
*ifsta
,
2863 struct ieee80211_mgmt
*mgmt
,
2865 struct ieee80211_rx_status
*rx_status
)
2867 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2868 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2870 struct sk_buff
*skb
;
2871 struct ieee80211_mgmt
*resp
;
2873 DECLARE_MAC_BUF(mac
);
2874 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2875 DECLARE_MAC_BUF(mac2
);
2876 DECLARE_MAC_BUF(mac3
);
2879 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
||
2880 ifsta
->state
!= IEEE80211_IBSS_JOINED
||
2881 len
< 24 + 2 || !ifsta
->probe_resp
)
2884 if (local
->ops
->tx_last_beacon
)
2885 tx_last_beacon
= local
->ops
->tx_last_beacon(local_to_hw(local
));
2889 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2890 printk(KERN_DEBUG
"%s: RX ProbeReq SA=%s DA=%s BSSID="
2891 "%s (tx_last_beacon=%d)\n",
2892 dev
->name
, print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
),
2893 print_mac(mac3
, mgmt
->bssid
), tx_last_beacon
);
2894 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2896 if (!tx_last_beacon
)
2899 if (memcmp(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
) != 0 &&
2900 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
2903 end
= ((u8
*) mgmt
) + len
;
2904 pos
= mgmt
->u
.probe_req
.variable
;
2905 if (pos
[0] != WLAN_EID_SSID
||
2906 pos
+ 2 + pos
[1] > end
) {
2907 if (net_ratelimit()) {
2908 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
2910 dev
->name
, print_mac(mac
, mgmt
->sa
));
2915 (pos
[1] != ifsta
->ssid_len
||
2916 memcmp(pos
+ 2, ifsta
->ssid
, ifsta
->ssid_len
) != 0)) {
2917 /* Ignore ProbeReq for foreign SSID */
2921 /* Reply with ProbeResp */
2922 skb
= skb_copy(ifsta
->probe_resp
, GFP_KERNEL
);
2926 resp
= (struct ieee80211_mgmt
*) skb
->data
;
2927 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
2928 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2929 printk(KERN_DEBUG
"%s: Sending ProbeResp to %s\n",
2930 dev
->name
, print_mac(mac
, resp
->da
));
2931 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2932 ieee80211_sta_tx(dev
, skb
, 0);
2935 static void ieee80211_rx_mgmt_action(struct net_device
*dev
,
2936 struct ieee80211_if_sta
*ifsta
,
2937 struct ieee80211_mgmt
*mgmt
,
2939 struct ieee80211_rx_status
*rx_status
)
2941 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2943 if (len
< IEEE80211_MIN_ACTION_SIZE
)
2946 switch (mgmt
->u
.action
.category
) {
2947 case WLAN_CATEGORY_BACK
:
2948 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
2949 case WLAN_ACTION_ADDBA_REQ
:
2950 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2951 sizeof(mgmt
->u
.action
.u
.addba_req
)))
2953 ieee80211_sta_process_addba_request(dev
, mgmt
, len
);
2955 case WLAN_ACTION_ADDBA_RESP
:
2956 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2957 sizeof(mgmt
->u
.action
.u
.addba_resp
)))
2959 ieee80211_sta_process_addba_resp(dev
, mgmt
, len
);
2961 case WLAN_ACTION_DELBA
:
2962 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2963 sizeof(mgmt
->u
.action
.u
.delba
)))
2965 ieee80211_sta_process_delba(dev
, mgmt
, len
);
2968 if (net_ratelimit())
2969 printk(KERN_DEBUG
"%s: Rx unknown A-MPDU action\n",
2974 case PLINK_CATEGORY
:
2975 if (ieee80211_vif_is_mesh(&sdata
->vif
))
2976 mesh_rx_plink_frame(dev
, mgmt
, len
, rx_status
);
2978 case MESH_PATH_SEL_CATEGORY
:
2979 if (ieee80211_vif_is_mesh(&sdata
->vif
))
2980 mesh_rx_path_sel_frame(dev
, mgmt
, len
);
2983 if (net_ratelimit())
2984 printk(KERN_DEBUG
"%s: Rx unknown action frame - "
2985 "category=%d\n", dev
->name
, mgmt
->u
.action
.category
);
2990 void ieee80211_sta_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
2991 struct ieee80211_rx_status
*rx_status
)
2993 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2994 struct ieee80211_sub_if_data
*sdata
;
2995 struct ieee80211_if_sta
*ifsta
;
2996 struct ieee80211_mgmt
*mgmt
;
3002 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3003 ifsta
= &sdata
->u
.sta
;
3005 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3006 fc
= le16_to_cpu(mgmt
->frame_control
);
3008 switch (fc
& IEEE80211_FCTL_STYPE
) {
3009 case IEEE80211_STYPE_PROBE_REQ
:
3010 case IEEE80211_STYPE_PROBE_RESP
:
3011 case IEEE80211_STYPE_BEACON
:
3012 case IEEE80211_STYPE_ACTION
:
3013 memcpy(skb
->cb
, rx_status
, sizeof(*rx_status
));
3014 case IEEE80211_STYPE_AUTH
:
3015 case IEEE80211_STYPE_ASSOC_RESP
:
3016 case IEEE80211_STYPE_REASSOC_RESP
:
3017 case IEEE80211_STYPE_DEAUTH
:
3018 case IEEE80211_STYPE_DISASSOC
:
3019 skb_queue_tail(&ifsta
->skb_queue
, skb
);
3020 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3023 printk(KERN_DEBUG
"%s: received unknown management frame - "
3024 "stype=%d\n", dev
->name
,
3025 (fc
& IEEE80211_FCTL_STYPE
) >> 4);
3034 static void ieee80211_sta_rx_queued_mgmt(struct net_device
*dev
,
3035 struct sk_buff
*skb
)
3037 struct ieee80211_rx_status
*rx_status
;
3038 struct ieee80211_sub_if_data
*sdata
;
3039 struct ieee80211_if_sta
*ifsta
;
3040 struct ieee80211_mgmt
*mgmt
;
3043 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3044 ifsta
= &sdata
->u
.sta
;
3046 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
3047 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3048 fc
= le16_to_cpu(mgmt
->frame_control
);
3050 switch (fc
& IEEE80211_FCTL_STYPE
) {
3051 case IEEE80211_STYPE_PROBE_REQ
:
3052 ieee80211_rx_mgmt_probe_req(dev
, ifsta
, mgmt
, skb
->len
,
3055 case IEEE80211_STYPE_PROBE_RESP
:
3056 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
, skb
->len
, rx_status
);
3058 case IEEE80211_STYPE_BEACON
:
3059 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
, rx_status
);
3061 case IEEE80211_STYPE_AUTH
:
3062 ieee80211_rx_mgmt_auth(dev
, ifsta
, mgmt
, skb
->len
);
3064 case IEEE80211_STYPE_ASSOC_RESP
:
3065 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 0);
3067 case IEEE80211_STYPE_REASSOC_RESP
:
3068 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 1);
3070 case IEEE80211_STYPE_DEAUTH
:
3071 ieee80211_rx_mgmt_deauth(dev
, ifsta
, mgmt
, skb
->len
);
3073 case IEEE80211_STYPE_DISASSOC
:
3074 ieee80211_rx_mgmt_disassoc(dev
, ifsta
, mgmt
, skb
->len
);
3076 case IEEE80211_STYPE_ACTION
:
3077 ieee80211_rx_mgmt_action(dev
, ifsta
, mgmt
, skb
->len
, rx_status
);
3086 ieee80211_sta_rx_scan(struct net_device
*dev
, struct sk_buff
*skb
,
3087 struct ieee80211_rx_status
*rx_status
)
3089 struct ieee80211_mgmt
*mgmt
;
3093 return RX_DROP_UNUSABLE
;
3095 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3096 fc
= le16_to_cpu(mgmt
->frame_control
);
3098 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
)
3102 return RX_DROP_MONITOR
;
3104 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
3105 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
) {
3106 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
,
3107 skb
->len
, rx_status
);
3110 } else if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
) {
3111 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
,
3121 static int ieee80211_sta_active_ibss(struct net_device
*dev
)
3123 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3125 struct sta_info
*sta
;
3126 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3130 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
3131 if (sta
->sdata
== sdata
&&
3132 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
3145 static void ieee80211_sta_expire(struct net_device
*dev
, unsigned long exp_time
)
3147 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3148 struct sta_info
*sta
, *tmp
;
3149 LIST_HEAD(tmp_list
);
3150 DECLARE_MAC_BUF(mac
);
3151 unsigned long flags
;
3153 spin_lock_irqsave(&local
->sta_lock
, flags
);
3154 list_for_each_entry_safe(sta
, tmp
, &local
->sta_list
, list
)
3155 if (time_after(jiffies
, sta
->last_rx
+ exp_time
)) {
3156 printk(KERN_DEBUG
"%s: expiring inactive STA %s\n",
3157 dev
->name
, print_mac(mac
, sta
->addr
));
3158 __sta_info_unlink(&sta
);
3160 list_add(&sta
->list
, &tmp_list
);
3162 spin_unlock_irqrestore(&local
->sta_lock
, flags
);
3164 list_for_each_entry_safe(sta
, tmp
, &tmp_list
, list
)
3165 sta_info_destroy(sta
);
3169 static void ieee80211_sta_merge_ibss(struct net_device
*dev
,
3170 struct ieee80211_if_sta
*ifsta
)
3172 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
3174 ieee80211_sta_expire(dev
, IEEE80211_IBSS_INACTIVITY_LIMIT
);
3175 if (ieee80211_sta_active_ibss(dev
))
3178 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
3179 "IBSS networks with same SSID (merge)\n", dev
->name
);
3180 ieee80211_sta_req_scan(dev
, ifsta
->ssid
, ifsta
->ssid_len
);
3184 #ifdef CONFIG_MAC80211_MESH
3185 static void ieee80211_mesh_housekeeping(struct net_device
*dev
,
3186 struct ieee80211_if_sta
*ifsta
)
3188 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3191 ieee80211_sta_expire(dev
, IEEE80211_MESH_PEER_INACTIVITY_LIMIT
);
3192 mesh_path_expire(dev
);
3194 free_plinks
= mesh_plink_availables(sdata
);
3195 if (free_plinks
!= sdata
->u
.sta
.accepting_plinks
)
3196 ieee80211_if_config_beacon(dev
);
3198 mod_timer(&ifsta
->timer
, jiffies
+
3199 IEEE80211_MESH_HOUSEKEEPING_INTERVAL
);
3203 void ieee80211_start_mesh(struct net_device
*dev
)
3205 struct ieee80211_if_sta
*ifsta
;
3206 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3207 ifsta
= &sdata
->u
.sta
;
3208 ifsta
->state
= IEEE80211_MESH_UP
;
3209 ieee80211_sta_timer((unsigned long)sdata
);
3214 void ieee80211_sta_timer(unsigned long data
)
3216 struct ieee80211_sub_if_data
*sdata
=
3217 (struct ieee80211_sub_if_data
*) data
;
3218 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3219 struct ieee80211_local
*local
= wdev_priv(&sdata
->wdev
);
3221 set_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3222 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3225 void ieee80211_sta_work(struct work_struct
*work
)
3227 struct ieee80211_sub_if_data
*sdata
=
3228 container_of(work
, struct ieee80211_sub_if_data
, u
.sta
.work
);
3229 struct net_device
*dev
= sdata
->dev
;
3230 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3231 struct ieee80211_if_sta
*ifsta
;
3232 struct sk_buff
*skb
;
3234 if (!netif_running(dev
))
3237 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
3240 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
3241 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
3242 sdata
->vif
.type
!= IEEE80211_IF_TYPE_MESH_POINT
) {
3243 printk(KERN_DEBUG
"%s: ieee80211_sta_work: non-STA interface "
3244 "(type=%d)\n", dev
->name
, sdata
->vif
.type
);
3247 ifsta
= &sdata
->u
.sta
;
3249 while ((skb
= skb_dequeue(&ifsta
->skb_queue
)))
3250 ieee80211_sta_rx_queued_mgmt(dev
, skb
);
3252 #ifdef CONFIG_MAC80211_MESH
3253 if (ifsta
->preq_queue_len
&&
3255 ifsta
->last_preq
+ msecs_to_jiffies(ifsta
->mshcfg
.dot11MeshHWMPpreqMinInterval
)))
3256 mesh_path_start_discovery(dev
);
3259 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
3260 ifsta
->state
!= IEEE80211_ASSOCIATE
&&
3261 test_and_clear_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
)) {
3262 if (ifsta
->scan_ssid_len
)
3263 ieee80211_sta_start_scan(dev
, ifsta
->scan_ssid
, ifsta
->scan_ssid_len
);
3265 ieee80211_sta_start_scan(dev
, NULL
, 0);
3269 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
)) {
3270 if (ieee80211_sta_config_auth(dev
, ifsta
))
3272 clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3273 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
))
3276 switch (ifsta
->state
) {
3277 case IEEE80211_DISABLED
:
3279 case IEEE80211_AUTHENTICATE
:
3280 ieee80211_authenticate(dev
, ifsta
);
3282 case IEEE80211_ASSOCIATE
:
3283 ieee80211_associate(dev
, ifsta
);
3285 case IEEE80211_ASSOCIATED
:
3286 ieee80211_associated(dev
, ifsta
);
3288 case IEEE80211_IBSS_SEARCH
:
3289 ieee80211_sta_find_ibss(dev
, ifsta
);
3291 case IEEE80211_IBSS_JOINED
:
3292 ieee80211_sta_merge_ibss(dev
, ifsta
);
3294 #ifdef CONFIG_MAC80211_MESH
3295 case IEEE80211_MESH_UP
:
3296 ieee80211_mesh_housekeeping(dev
, ifsta
);
3300 printk(KERN_DEBUG
"ieee80211_sta_work: Unknown state %d\n",
3305 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
3306 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
3307 "mixed-cell disabled - disassociate\n", dev
->name
);
3309 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
3310 ieee80211_set_disassoc(dev
, ifsta
, 0);
3315 static void ieee80211_sta_reset_auth(struct net_device
*dev
,
3316 struct ieee80211_if_sta
*ifsta
)
3318 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3320 if (local
->ops
->reset_tsf
) {
3321 /* Reset own TSF to allow time synchronization work. */
3322 local
->ops
->reset_tsf(local_to_hw(local
));
3325 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
3328 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
3329 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3330 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
3331 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
3332 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
3333 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
3335 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3336 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
3338 ifsta
->auth_transaction
= -1;
3339 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
3340 ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
3341 netif_carrier_off(dev
);
3345 void ieee80211_sta_req_auth(struct net_device
*dev
,
3346 struct ieee80211_if_sta
*ifsta
)
3348 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3349 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3351 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3354 if ((ifsta
->flags
& (IEEE80211_STA_BSSID_SET
|
3355 IEEE80211_STA_AUTO_BSSID_SEL
)) &&
3356 (ifsta
->flags
& (IEEE80211_STA_SSID_SET
|
3357 IEEE80211_STA_AUTO_SSID_SEL
))) {
3358 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3359 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3363 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta
*ifsta
,
3364 const char *ssid
, int ssid_len
)
3366 int tmp
, hidden_ssid
;
3368 if (ssid_len
== ifsta
->ssid_len
&&
3369 !memcmp(ifsta
->ssid
, ssid
, ssid_len
))
3372 if (ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
)
3378 if (ssid
[tmp
] != '\0') {
3384 if (hidden_ssid
&& ifsta
->ssid_len
== ssid_len
)
3387 if (ssid_len
== 1 && ssid
[0] == ' ')
3393 static int ieee80211_sta_config_auth(struct net_device
*dev
,
3394 struct ieee80211_if_sta
*ifsta
)
3396 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3397 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3398 struct ieee80211_sta_bss
*bss
, *selected
= NULL
;
3399 int top_rssi
= 0, freq
;
3401 if (!(ifsta
->flags
& (IEEE80211_STA_AUTO_SSID_SEL
|
3402 IEEE80211_STA_AUTO_BSSID_SEL
| IEEE80211_STA_AUTO_CHANNEL_SEL
))) {
3403 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3404 ieee80211_sta_reset_auth(dev
, ifsta
);
3408 spin_lock_bh(&local
->sta_bss_lock
);
3409 freq
= local
->oper_channel
->center_freq
;
3410 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3411 if (!(bss
->capability
& WLAN_CAPABILITY_ESS
))
3414 if (!!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
) ^
3415 !!sdata
->default_key
)
3418 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_CHANNEL_SEL
) &&
3422 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
) &&
3423 memcmp(bss
->bssid
, ifsta
->bssid
, ETH_ALEN
))
3426 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
) &&
3427 !ieee80211_sta_match_ssid(ifsta
, bss
->ssid
, bss
->ssid_len
))
3430 if (!selected
|| top_rssi
< bss
->signal
) {
3432 top_rssi
= bss
->signal
;
3436 atomic_inc(&selected
->users
);
3437 spin_unlock_bh(&local
->sta_bss_lock
);
3440 ieee80211_set_freq(local
, selected
->freq
);
3441 if (!(ifsta
->flags
& IEEE80211_STA_SSID_SET
))
3442 ieee80211_sta_set_ssid(dev
, selected
->ssid
,
3443 selected
->ssid_len
);
3444 ieee80211_sta_set_bssid(dev
, selected
->bssid
);
3445 ieee80211_sta_def_wmm_params(dev
, selected
, 0);
3446 ieee80211_rx_bss_put(dev
, selected
);
3447 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3448 ieee80211_sta_reset_auth(dev
, ifsta
);
3451 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
) {
3452 if (ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
)
3453 ieee80211_sta_start_scan(dev
, NULL
, 0);
3455 ieee80211_sta_start_scan(dev
, ifsta
->ssid
,
3457 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3458 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3460 ifsta
->state
= IEEE80211_DISABLED
;
3466 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
3467 struct ieee80211_if_sta
*ifsta
)
3469 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3470 struct ieee80211_sta_bss
*bss
;
3471 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3472 struct ieee80211_supported_band
*sband
;
3473 u8 bssid
[ETH_ALEN
], *pos
;
3475 DECLARE_MAC_BUF(mac
);
3478 /* Easier testing, use fixed BSSID. */
3479 memset(bssid
, 0xfe, ETH_ALEN
);
3481 /* Generate random, not broadcast, locally administered BSSID. Mix in
3482 * own MAC address to make sure that devices that do not have proper
3483 * random number generator get different BSSID. */
3484 get_random_bytes(bssid
, ETH_ALEN
);
3485 for (i
= 0; i
< ETH_ALEN
; i
++)
3486 bssid
[i
] ^= dev
->dev_addr
[i
];
3491 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID %s\n",
3492 dev
->name
, print_mac(mac
, bssid
));
3494 bss
= ieee80211_rx_bss_add(dev
, bssid
,
3495 local
->hw
.conf
.channel
->center_freq
,
3496 sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
);
3500 bss
->band
= local
->hw
.conf
.channel
->band
;
3501 sband
= local
->hw
.wiphy
->bands
[bss
->band
];
3503 if (local
->hw
.conf
.beacon_int
== 0)
3504 local
->hw
.conf
.beacon_int
= 10000;
3505 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
3506 bss
->last_update
= jiffies
;
3507 bss
->capability
= WLAN_CAPABILITY_IBSS
;
3509 if (sdata
->default_key
)
3510 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
3512 sdata
->drop_unencrypted
= 0;
3514 bss
->supp_rates_len
= sband
->n_bitrates
;
3515 pos
= bss
->supp_rates
;
3516 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
3517 int rate
= sband
->bitrates
[i
].bitrate
;
3518 *pos
++ = (u8
) (rate
/ 5);
3521 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3525 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
3526 struct ieee80211_if_sta
*ifsta
)
3528 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3529 struct ieee80211_sta_bss
*bss
;
3533 DECLARE_MAC_BUF(mac
);
3534 DECLARE_MAC_BUF(mac2
);
3536 if (ifsta
->ssid_len
== 0)
3539 active_ibss
= ieee80211_sta_active_ibss(dev
);
3540 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3541 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
3542 dev
->name
, active_ibss
);
3543 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3544 spin_lock_bh(&local
->sta_bss_lock
);
3545 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3546 if (ifsta
->ssid_len
!= bss
->ssid_len
||
3547 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
3548 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
3550 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3551 printk(KERN_DEBUG
" bssid=%s found\n",
3552 print_mac(mac
, bss
->bssid
));
3553 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3554 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
3556 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
3559 spin_unlock_bh(&local
->sta_bss_lock
);
3561 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3562 printk(KERN_DEBUG
" sta_find_ibss: selected %s current "
3563 "%s\n", print_mac(mac
, bssid
), print_mac(mac2
, ifsta
->bssid
));
3564 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3565 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
3566 (bss
= ieee80211_rx_bss_get(dev
, bssid
,
3567 local
->hw
.conf
.channel
->center_freq
,
3568 ifsta
->ssid
, ifsta
->ssid_len
))) {
3569 printk(KERN_DEBUG
"%s: Selected IBSS BSSID %s"
3570 " based on configured SSID\n",
3571 dev
->name
, print_mac(mac
, bssid
));
3572 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3574 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3575 printk(KERN_DEBUG
" did not try to join ibss\n");
3576 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3578 /* Selected IBSS not found in current scan results - try to scan */
3579 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3580 !ieee80211_sta_active_ibss(dev
)) {
3581 mod_timer(&ifsta
->timer
, jiffies
+
3582 IEEE80211_IBSS_MERGE_INTERVAL
);
3583 } else if (time_after(jiffies
, local
->last_scan_completed
+
3584 IEEE80211_SCAN_INTERVAL
)) {
3585 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
3586 "join\n", dev
->name
);
3587 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
3589 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
3590 int interval
= IEEE80211_SCAN_INTERVAL
;
3592 if (time_after(jiffies
, ifsta
->ibss_join_req
+
3593 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
3594 if ((ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) &&
3595 (!(local
->oper_channel
->flags
&
3596 IEEE80211_CHAN_NO_IBSS
)))
3597 return ieee80211_sta_create_ibss(dev
, ifsta
);
3598 if (ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) {
3599 printk(KERN_DEBUG
"%s: IBSS not allowed on"
3600 " %d MHz\n", dev
->name
,
3601 local
->hw
.conf
.channel
->center_freq
);
3604 /* No IBSS found - decrease scan interval and continue
3606 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
3609 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3610 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
3618 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
3620 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3621 struct ieee80211_if_sta
*ifsta
;
3623 if (len
> IEEE80211_MAX_SSID_LEN
)
3626 ifsta
= &sdata
->u
.sta
;
3628 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
3629 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
3630 memcpy(ifsta
->ssid
, ssid
, len
);
3631 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
3632 ifsta
->ssid_len
= len
;
3635 ifsta
->flags
|= IEEE80211_STA_SSID_SET
;
3637 ifsta
->flags
&= ~IEEE80211_STA_SSID_SET
;
3638 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3639 !(ifsta
->flags
& IEEE80211_STA_BSSID_SET
)) {
3640 ifsta
->ibss_join_req
= jiffies
;
3641 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3642 return ieee80211_sta_find_ibss(dev
, ifsta
);
3648 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
3650 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3651 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3652 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
3653 *len
= ifsta
->ssid_len
;
3658 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
3660 struct ieee80211_sub_if_data
*sdata
;
3661 struct ieee80211_if_sta
*ifsta
;
3664 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3665 ifsta
= &sdata
->u
.sta
;
3667 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
3668 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
3669 res
= ieee80211_if_config(dev
);
3671 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
3672 "the low-level driver\n", dev
->name
);
3677 if (is_valid_ether_addr(bssid
))
3678 ifsta
->flags
|= IEEE80211_STA_BSSID_SET
;
3680 ifsta
->flags
&= ~IEEE80211_STA_BSSID_SET
;
3686 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
3687 struct ieee80211_sub_if_data
*sdata
,
3690 struct sk_buff
*skb
;
3691 struct ieee80211_hdr
*nullfunc
;
3694 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
3696 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
3697 "frame\n", sdata
->dev
->name
);
3700 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3702 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
3703 memset(nullfunc
, 0, 24);
3704 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
3705 IEEE80211_FCTL_TODS
;
3707 fc
|= IEEE80211_FCTL_PM
;
3708 nullfunc
->frame_control
= cpu_to_le16(fc
);
3709 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3710 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
3711 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3713 ieee80211_sta_tx(sdata
->dev
, skb
, 0);
3717 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
3719 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
3720 ieee80211_vif_is_mesh(&sdata
->vif
))
3721 ieee80211_sta_timer((unsigned long)sdata
);
3724 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
3726 struct ieee80211_local
*local
= hw_to_local(hw
);
3727 struct net_device
*dev
= local
->scan_dev
;
3728 struct ieee80211_sub_if_data
*sdata
;
3729 union iwreq_data wrqu
;
3731 local
->last_scan_completed
= jiffies
;
3732 memset(&wrqu
, 0, sizeof(wrqu
));
3733 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
3735 if (local
->sta_hw_scanning
) {
3736 local
->sta_hw_scanning
= 0;
3737 if (ieee80211_hw_config(local
))
3738 printk(KERN_DEBUG
"%s: failed to restore operational "
3739 "channel after scan\n", dev
->name
);
3740 /* Restart STA timer for HW scan case */
3742 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
)
3743 ieee80211_restart_sta_timer(sdata
);
3749 local
->sta_sw_scanning
= 0;
3750 if (ieee80211_hw_config(local
))
3751 printk(KERN_DEBUG
"%s: failed to restore operational "
3752 "channel after scan\n", dev
->name
);
3755 netif_tx_lock_bh(local
->mdev
);
3756 local
->filter_flags
&= ~FIF_BCN_PRBRESP_PROMISC
;
3757 local
->ops
->configure_filter(local_to_hw(local
),
3758 FIF_BCN_PRBRESP_PROMISC
,
3759 &local
->filter_flags
,
3760 local
->mdev
->mc_count
,
3761 local
->mdev
->mc_list
);
3763 netif_tx_unlock_bh(local
->mdev
);
3766 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3768 /* No need to wake the master device. */
3769 if (sdata
->dev
== local
->mdev
)
3772 /* Tell AP we're back */
3773 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3774 sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
)
3775 ieee80211_send_nullfunc(local
, sdata
, 0);
3777 ieee80211_restart_sta_timer(sdata
);
3779 netif_wake_queue(sdata
->dev
);
3784 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3785 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
3786 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3787 if (!(ifsta
->flags
& IEEE80211_STA_BSSID_SET
) ||
3788 (!ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3789 !ieee80211_sta_active_ibss(dev
)))
3790 ieee80211_sta_find_ibss(dev
, ifsta
);
3793 EXPORT_SYMBOL(ieee80211_scan_completed
);
3795 void ieee80211_sta_scan_work(struct work_struct
*work
)
3797 struct ieee80211_local
*local
=
3798 container_of(work
, struct ieee80211_local
, scan_work
.work
);
3799 struct net_device
*dev
= local
->scan_dev
;
3800 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3801 struct ieee80211_supported_band
*sband
;
3802 struct ieee80211_channel
*chan
;
3804 unsigned long next_delay
= 0;
3806 if (!local
->sta_sw_scanning
)
3809 switch (local
->scan_state
) {
3810 case SCAN_SET_CHANNEL
:
3812 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3813 * after we successfully scanned the last channel of the last
3814 * band (and the last band is supported by the hw)
3816 if (local
->scan_band
< IEEE80211_NUM_BANDS
)
3817 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3822 * If we are at an unsupported band and have more bands
3823 * left to scan, advance to the next supported one.
3825 while (!sband
&& local
->scan_band
< IEEE80211_NUM_BANDS
- 1) {
3827 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3828 local
->scan_channel_idx
= 0;
3831 /* if no more bands/channels left, complete scan */
3832 if (!sband
|| local
->scan_channel_idx
>= sband
->n_channels
) {
3833 ieee80211_scan_completed(local_to_hw(local
));
3837 chan
= &sband
->channels
[local
->scan_channel_idx
];
3839 if (chan
->flags
& IEEE80211_CHAN_DISABLED
||
3840 (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3841 chan
->flags
& IEEE80211_CHAN_NO_IBSS
))
3845 local
->scan_channel
= chan
;
3846 if (ieee80211_hw_config(local
)) {
3847 printk(KERN_DEBUG
"%s: failed to set freq to "
3848 "%d MHz for scan\n", dev
->name
,
3854 /* advance state machine to next channel/band */
3855 local
->scan_channel_idx
++;
3856 if (local
->scan_channel_idx
>= sband
->n_channels
) {
3858 * scan_band may end up == IEEE80211_NUM_BANDS, but
3859 * we'll catch that case above and complete the scan
3860 * if that is the case.
3863 local
->scan_channel_idx
= 0;
3869 next_delay
= IEEE80211_PROBE_DELAY
+
3870 usecs_to_jiffies(local
->hw
.channel_change_time
);
3871 local
->scan_state
= SCAN_SEND_PROBE
;
3873 case SCAN_SEND_PROBE
:
3874 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
3875 local
->scan_state
= SCAN_SET_CHANNEL
;
3877 if (local
->scan_channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
3879 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
3880 local
->scan_ssid_len
);
3881 next_delay
= IEEE80211_CHANNEL_TIME
;
3885 if (local
->sta_sw_scanning
)
3886 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3891 static int ieee80211_sta_start_scan(struct net_device
*dev
,
3892 u8
*ssid
, size_t ssid_len
)
3894 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3895 struct ieee80211_sub_if_data
*sdata
;
3897 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
3900 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3901 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3904 * ScanType: ACTIVE, PASSIVE
3905 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3906 * a Probe frame during active scanning
3908 * MinChannelTime (>= ProbeDelay), in TU
3909 * MaxChannelTime: (>= MinChannelTime), in TU
3912 /* MLME-SCAN.confirm
3914 * ResultCode: SUCCESS, INVALID_PARAMETERS
3917 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3918 if (local
->scan_dev
== dev
)
3923 if (local
->ops
->hw_scan
) {
3924 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
3927 local
->sta_hw_scanning
= 1;
3928 local
->scan_dev
= dev
;
3933 local
->sta_sw_scanning
= 1;
3936 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3938 /* Don't stop the master interface, otherwise we can't transmit
3940 if (sdata
->dev
== local
->mdev
)
3943 netif_stop_queue(sdata
->dev
);
3944 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3945 (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
))
3946 ieee80211_send_nullfunc(local
, sdata
, 1);
3951 local
->scan_ssid_len
= ssid_len
;
3952 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
3954 local
->scan_ssid_len
= 0;
3955 local
->scan_state
= SCAN_SET_CHANNEL
;
3956 local
->scan_channel_idx
= 0;
3957 local
->scan_band
= IEEE80211_BAND_2GHZ
;
3958 local
->scan_dev
= dev
;
3960 netif_tx_lock_bh(local
->mdev
);
3961 local
->filter_flags
|= FIF_BCN_PRBRESP_PROMISC
;
3962 local
->ops
->configure_filter(local_to_hw(local
),
3963 FIF_BCN_PRBRESP_PROMISC
,
3964 &local
->filter_flags
,
3965 local
->mdev
->mc_count
,
3966 local
->mdev
->mc_list
);
3967 netif_tx_unlock_bh(local
->mdev
);
3969 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3970 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3971 IEEE80211_CHANNEL_TIME
);
3977 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
3979 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3980 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3981 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3983 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3984 return ieee80211_sta_start_scan(dev
, ssid
, ssid_len
);
3986 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3987 if (local
->scan_dev
== dev
)
3992 ifsta
->scan_ssid_len
= ssid_len
;
3994 memcpy(ifsta
->scan_ssid
, ssid
, ssid_len
);
3995 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
3996 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
4001 ieee80211_sta_scan_result(struct net_device
*dev
,
4002 struct ieee80211_sta_bss
*bss
,
4003 char *current_ev
, char *end_buf
)
4005 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4006 struct iw_event iwe
;
4008 if (time_after(jiffies
,
4009 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
4012 memset(&iwe
, 0, sizeof(iwe
));
4013 iwe
.cmd
= SIOCGIWAP
;
4014 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
4015 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
4016 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4019 memset(&iwe
, 0, sizeof(iwe
));
4020 iwe
.cmd
= SIOCGIWESSID
;
4021 if (bss_mesh_cfg(bss
)) {
4022 iwe
.u
.data
.length
= bss_mesh_id_len(bss
);
4023 iwe
.u
.data
.flags
= 1;
4024 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4027 iwe
.u
.data
.length
= bss
->ssid_len
;
4028 iwe
.u
.data
.flags
= 1;
4029 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4033 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
4034 || bss_mesh_cfg(bss
)) {
4035 memset(&iwe
, 0, sizeof(iwe
));
4036 iwe
.cmd
= SIOCGIWMODE
;
4037 if (bss_mesh_cfg(bss
))
4038 iwe
.u
.mode
= IW_MODE_MESH
;
4039 else if (bss
->capability
& WLAN_CAPABILITY_ESS
)
4040 iwe
.u
.mode
= IW_MODE_MASTER
;
4042 iwe
.u
.mode
= IW_MODE_ADHOC
;
4043 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4047 memset(&iwe
, 0, sizeof(iwe
));
4048 iwe
.cmd
= SIOCGIWFREQ
;
4049 iwe
.u
.freq
.m
= bss
->freq
;
4051 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4054 memset(&iwe
, 0, sizeof(iwe
));
4055 iwe
.cmd
= SIOCGIWFREQ
;
4056 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->freq
);
4058 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4061 memset(&iwe
, 0, sizeof(iwe
));
4063 iwe
.u
.qual
.qual
= bss
->qual
;
4064 iwe
.u
.qual
.level
= bss
->signal
;
4065 iwe
.u
.qual
.noise
= bss
->noise
;
4066 iwe
.u
.qual
.updated
= local
->wstats_flags
;
4067 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
4070 memset(&iwe
, 0, sizeof(iwe
));
4071 iwe
.cmd
= SIOCGIWENCODE
;
4072 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
4073 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
4075 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
4076 iwe
.u
.data
.length
= 0;
4077 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
4079 if (bss
&& bss
->wpa_ie
) {
4080 memset(&iwe
, 0, sizeof(iwe
));
4081 iwe
.cmd
= IWEVGENIE
;
4082 iwe
.u
.data
.length
= bss
->wpa_ie_len
;
4083 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4087 if (bss
&& bss
->rsn_ie
) {
4088 memset(&iwe
, 0, sizeof(iwe
));
4089 iwe
.cmd
= IWEVGENIE
;
4090 iwe
.u
.data
.length
= bss
->rsn_ie_len
;
4091 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4095 if (bss
&& bss
->supp_rates_len
> 0) {
4096 /* display all supported rates in readable format */
4097 char *p
= current_ev
+ IW_EV_LCP_LEN
;
4100 memset(&iwe
, 0, sizeof(iwe
));
4101 iwe
.cmd
= SIOCGIWRATE
;
4102 /* Those two flags are ignored... */
4103 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
4105 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
4106 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
4108 p
= iwe_stream_add_value(current_ev
, p
,
4109 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
4116 buf
= kmalloc(30, GFP_ATOMIC
);
4118 memset(&iwe
, 0, sizeof(iwe
));
4119 iwe
.cmd
= IWEVCUSTOM
;
4120 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
4121 iwe
.u
.data
.length
= strlen(buf
);
4122 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4128 if (bss_mesh_cfg(bss
)) {
4130 u8
*cfg
= bss_mesh_cfg(bss
);
4131 buf
= kmalloc(50, GFP_ATOMIC
);
4133 memset(&iwe
, 0, sizeof(iwe
));
4134 iwe
.cmd
= IWEVCUSTOM
;
4135 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
4136 iwe
.u
.data
.length
= strlen(buf
);
4137 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4139 sprintf(buf
, "Path Selection Protocol ID: "
4140 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
4142 iwe
.u
.data
.length
= strlen(buf
);
4143 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4145 sprintf(buf
, "Path Selection Metric ID: "
4146 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
4148 iwe
.u
.data
.length
= strlen(buf
);
4149 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4151 sprintf(buf
, "Congestion Control Mode ID: "
4152 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
4154 iwe
.u
.data
.length
= strlen(buf
);
4155 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4157 sprintf(buf
, "Channel Precedence: "
4158 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
4160 iwe
.u
.data
.length
= strlen(buf
);
4161 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4171 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
4173 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4174 char *current_ev
= buf
;
4175 char *end_buf
= buf
+ len
;
4176 struct ieee80211_sta_bss
*bss
;
4178 spin_lock_bh(&local
->sta_bss_lock
);
4179 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
4180 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
4181 spin_unlock_bh(&local
->sta_bss_lock
);
4184 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
4187 spin_unlock_bh(&local
->sta_bss_lock
);
4188 return current_ev
- buf
;
4192 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
4194 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4195 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4197 kfree(ifsta
->extra_ie
);
4199 ifsta
->extra_ie
= NULL
;
4200 ifsta
->extra_ie_len
= 0;
4203 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
4204 if (!ifsta
->extra_ie
) {
4205 ifsta
->extra_ie_len
= 0;
4208 memcpy(ifsta
->extra_ie
, ie
, len
);
4209 ifsta
->extra_ie_len
= len
;
4214 struct sta_info
*ieee80211_ibss_add_sta(struct net_device
*dev
,
4215 struct sk_buff
*skb
, u8
*bssid
,
4218 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4219 struct sta_info
*sta
;
4220 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4221 DECLARE_MAC_BUF(mac
);
4223 /* TODO: Could consider removing the least recently used entry and
4224 * allow new one to be added. */
4225 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
4226 if (net_ratelimit()) {
4227 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
4228 "entry %s\n", dev
->name
, print_mac(mac
, addr
));
4233 printk(KERN_DEBUG
"%s: Adding new IBSS station %s (dev=%s)\n",
4234 wiphy_name(local
->hw
.wiphy
), print_mac(mac
, addr
), dev
->name
);
4236 sta
= sta_info_alloc(sdata
, addr
, GFP_ATOMIC
);
4240 set_sta_flags(sta
, WLAN_STA_AUTHORIZED
);
4242 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] =
4243 sdata
->u
.sta
.supp_rates_bits
[local
->hw
.conf
.channel
->band
];
4245 rate_control_rate_init(sta
, local
);
4247 if (sta_info_insert(sta
))
4254 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
4256 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4257 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4259 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
4262 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
4263 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
4266 ieee80211_send_deauth(dev
, ifsta
, reason
);
4267 ieee80211_set_disassoc(dev
, ifsta
, 1);
4272 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
4274 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4275 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4277 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
4280 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
4283 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
))
4286 ieee80211_send_disassoc(dev
, ifsta
, reason
);
4287 ieee80211_set_disassoc(dev
, ifsta
, 0);
4291 void ieee80211_notify_mac(struct ieee80211_hw
*hw
,
4292 enum ieee80211_notification_types notif_type
)
4294 struct ieee80211_local
*local
= hw_to_local(hw
);
4295 struct ieee80211_sub_if_data
*sdata
;
4297 switch (notif_type
) {
4298 case IEEE80211_NOTIFY_RE_ASSOC
:
4300 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4302 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
) {
4303 ieee80211_sta_req_auth(sdata
->dev
,
4312 EXPORT_SYMBOL(ieee80211_notify_mac
);