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"
33 #include "ieee80211_rate.h"
34 #include "ieee80211_led.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 IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
62 #define ERP_INFO_USE_PROTECTION BIT(1)
64 /* mgmt header + 1 byte action code */
65 #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
67 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
68 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
69 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
70 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
71 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
73 /* next values represent the buffer size for A-MPDU frame.
74 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
75 #define IEEE80211_MIN_AMPDU_BUF 0x8
76 #define IEEE80211_MAX_AMPDU_BUF 0x40
78 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
79 u8
*ssid
, size_t ssid_len
);
80 static struct ieee80211_sta_bss
*
81 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int freq
,
82 u8
*ssid
, u8 ssid_len
);
83 static void ieee80211_rx_bss_put(struct net_device
*dev
,
84 struct ieee80211_sta_bss
*bss
);
85 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
86 struct ieee80211_if_sta
*ifsta
);
87 static int ieee80211_sta_wep_configured(struct net_device
*dev
);
88 static int ieee80211_sta_start_scan(struct net_device
*dev
,
89 u8
*ssid
, size_t ssid_len
);
90 static int ieee80211_sta_config_auth(struct net_device
*dev
,
91 struct ieee80211_if_sta
*ifsta
);
94 void ieee802_11_parse_elems(u8
*start
, size_t len
,
95 struct ieee802_11_elems
*elems
)
100 memset(elems
, 0, sizeof(*elems
));
115 elems
->ssid_len
= elen
;
117 case WLAN_EID_SUPP_RATES
:
118 elems
->supp_rates
= pos
;
119 elems
->supp_rates_len
= elen
;
121 case WLAN_EID_FH_PARAMS
:
122 elems
->fh_params
= pos
;
123 elems
->fh_params_len
= elen
;
125 case WLAN_EID_DS_PARAMS
:
126 elems
->ds_params
= pos
;
127 elems
->ds_params_len
= elen
;
129 case WLAN_EID_CF_PARAMS
:
130 elems
->cf_params
= pos
;
131 elems
->cf_params_len
= elen
;
135 elems
->tim_len
= elen
;
137 case WLAN_EID_IBSS_PARAMS
:
138 elems
->ibss_params
= pos
;
139 elems
->ibss_params_len
= elen
;
141 case WLAN_EID_CHALLENGE
:
142 elems
->challenge
= pos
;
143 elems
->challenge_len
= elen
;
146 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
148 /* Microsoft OUI (00:50:F2) */
150 /* OUI Type 1 - WPA IE */
152 elems
->wpa_len
= elen
;
153 } else if (elen
>= 5 && pos
[3] == 2) {
155 elems
->wmm_info
= pos
;
156 elems
->wmm_info_len
= elen
;
157 } else if (pos
[4] == 1) {
158 elems
->wmm_param
= pos
;
159 elems
->wmm_param_len
= elen
;
166 elems
->rsn_len
= elen
;
168 case WLAN_EID_ERP_INFO
:
169 elems
->erp_info
= pos
;
170 elems
->erp_info_len
= elen
;
172 case WLAN_EID_EXT_SUPP_RATES
:
173 elems
->ext_supp_rates
= pos
;
174 elems
->ext_supp_rates_len
= elen
;
176 case WLAN_EID_HT_CAPABILITY
:
177 elems
->ht_cap_elem
= pos
;
178 elems
->ht_cap_elem_len
= elen
;
180 case WLAN_EID_HT_EXTRA_INFO
:
181 elems
->ht_info_elem
= pos
;
182 elems
->ht_info_elem_len
= elen
;
184 case WLAN_EID_MESH_ID
:
185 elems
->mesh_id
= pos
;
186 elems
->mesh_id_len
= elen
;
188 case WLAN_EID_MESH_CONFIG
:
189 elems
->mesh_config
= pos
;
190 elems
->mesh_config_len
= elen
;
192 case WLAN_EID_PEER_LINK
:
193 elems
->peer_link
= pos
;
194 elems
->peer_link_len
= elen
;
198 elems
->preq_len
= elen
;
202 elems
->prep_len
= elen
;
206 elems
->perr_len
= elen
;
218 static int ecw2cw(int ecw
)
220 return (1 << ecw
) - 1;
224 static void ieee80211_sta_def_wmm_params(struct net_device
*dev
,
225 struct ieee80211_sta_bss
*bss
,
228 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
229 struct ieee80211_local
*local
= sdata
->local
;
230 int i
, have_higher_than_11mbit
= 0;
233 /* cf. IEEE 802.11 9.2.12 */
234 for (i
= 0; i
< bss
->supp_rates_len
; i
++)
235 if ((bss
->supp_rates
[i
] & 0x7f) * 5 > 110)
236 have_higher_than_11mbit
= 1;
238 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
239 have_higher_than_11mbit
)
240 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
242 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
245 if (local
->ops
->conf_tx
) {
246 struct ieee80211_tx_queue_params qparam
;
248 memset(&qparam
, 0, sizeof(qparam
));
252 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
253 !(sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
))
258 qparam
.cw_max
= 1023;
261 for (i
= IEEE80211_TX_QUEUE_DATA0
; i
< NUM_TX_DATA_QUEUES
; i
++)
262 local
->ops
->conf_tx(local_to_hw(local
),
263 i
+ IEEE80211_TX_QUEUE_DATA0
,
267 /* IBSS uses different parameters for Beacon sending */
271 local
->ops
->conf_tx(local_to_hw(local
),
272 IEEE80211_TX_QUEUE_BEACON
, &qparam
);
277 static void ieee80211_sta_wmm_params(struct net_device
*dev
,
278 struct ieee80211_if_sta
*ifsta
,
279 u8
*wmm_param
, size_t wmm_param_len
)
281 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
282 struct ieee80211_tx_queue_params params
;
287 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
289 count
= wmm_param
[6] & 0x0f;
290 if (count
== ifsta
->wmm_last_param_set
)
292 ifsta
->wmm_last_param_set
= count
;
295 left
= wmm_param_len
- 8;
297 memset(¶ms
, 0, sizeof(params
));
299 if (!local
->ops
->conf_tx
)
303 for (; left
>= 4; left
-= 4, pos
+= 4) {
304 int aci
= (pos
[0] >> 5) & 0x03;
305 int acm
= (pos
[0] >> 4) & 0x01;
310 queue
= IEEE80211_TX_QUEUE_DATA3
;
312 local
->wmm_acm
|= BIT(0) | BIT(3);
316 queue
= IEEE80211_TX_QUEUE_DATA1
;
318 local
->wmm_acm
|= BIT(4) | BIT(5);
322 queue
= IEEE80211_TX_QUEUE_DATA0
;
324 local
->wmm_acm
|= BIT(6) | BIT(7);
329 queue
= IEEE80211_TX_QUEUE_DATA2
;
331 local
->wmm_acm
|= BIT(1) | BIT(2);
336 params
.aifs
= pos
[0] & 0x0f;
337 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
338 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
339 params
.txop
= pos
[2] | (pos
[3] << 8);
340 #ifdef CONFIG_MAC80211_DEBUG
341 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
342 "cWmin=%d cWmax=%d txop=%d\n",
343 dev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
344 params
.cw_max
, params
.txop
);
346 /* TODO: handle ACM (block TX, fallback to next lowest allowed
348 if (local
->ops
->conf_tx(local_to_hw(local
), queue
, ¶ms
)) {
349 printk(KERN_DEBUG
"%s: failed to set TX queue "
350 "parameters for queue %d\n", dev
->name
, queue
);
356 static u32
ieee80211_handle_erp_ie(struct ieee80211_sub_if_data
*sdata
,
359 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
360 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
361 bool use_protection
= (erp_value
& WLAN_ERP_USE_PROTECTION
) != 0;
362 bool use_short_preamble
= (erp_value
& WLAN_ERP_BARKER_PREAMBLE
) == 0;
363 DECLARE_MAC_BUF(mac
);
366 if (use_protection
!= bss_conf
->use_cts_prot
) {
367 if (net_ratelimit()) {
368 printk(KERN_DEBUG
"%s: CTS protection %s (BSSID="
371 use_protection
? "enabled" : "disabled",
372 print_mac(mac
, ifsta
->bssid
));
374 bss_conf
->use_cts_prot
= use_protection
;
375 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
378 if (use_short_preamble
!= bss_conf
->use_short_preamble
) {
379 if (net_ratelimit()) {
380 printk(KERN_DEBUG
"%s: switched to %s barker preamble"
383 use_short_preamble
? "short" : "long",
384 print_mac(mac
, ifsta
->bssid
));
386 bss_conf
->use_short_preamble
= use_short_preamble
;
387 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
393 int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap
*ht_cap_ie
,
394 struct ieee80211_ht_info
*ht_info
)
400 memset(ht_info
, 0, sizeof(*ht_info
));
403 u8 ampdu_info
= ht_cap_ie
->ampdu_params_info
;
405 ht_info
->ht_supported
= 1;
406 ht_info
->cap
= le16_to_cpu(ht_cap_ie
->cap_info
);
407 ht_info
->ampdu_factor
=
408 ampdu_info
& IEEE80211_HT_CAP_AMPDU_FACTOR
;
409 ht_info
->ampdu_density
=
410 (ampdu_info
& IEEE80211_HT_CAP_AMPDU_DENSITY
) >> 2;
411 memcpy(ht_info
->supp_mcs_set
, ht_cap_ie
->supp_mcs_set
, 16);
413 ht_info
->ht_supported
= 0;
418 int ieee80211_ht_addt_info_ie_to_ht_bss_info(
419 struct ieee80211_ht_addt_info
*ht_add_info_ie
,
420 struct ieee80211_ht_bss_info
*bss_info
)
422 if (bss_info
== NULL
)
425 memset(bss_info
, 0, sizeof(*bss_info
));
427 if (ht_add_info_ie
) {
429 op_mode
= le16_to_cpu(ht_add_info_ie
->operation_mode
);
431 bss_info
->primary_channel
= ht_add_info_ie
->control_chan
;
432 bss_info
->bss_cap
= ht_add_info_ie
->ht_param
;
433 bss_info
->bss_op_mode
= (u8
)(op_mode
& 0xff);
439 static void ieee80211_sta_send_associnfo(struct net_device
*dev
,
440 struct ieee80211_if_sta
*ifsta
)
445 union iwreq_data wrqu
;
447 if (!ifsta
->assocreq_ies
&& !ifsta
->assocresp_ies
)
450 buf
= kmalloc(50 + 2 * (ifsta
->assocreq_ies_len
+
451 ifsta
->assocresp_ies_len
), GFP_KERNEL
);
455 len
= sprintf(buf
, "ASSOCINFO(");
456 if (ifsta
->assocreq_ies
) {
457 len
+= sprintf(buf
+ len
, "ReqIEs=");
458 for (i
= 0; i
< ifsta
->assocreq_ies_len
; i
++) {
459 len
+= sprintf(buf
+ len
, "%02x",
460 ifsta
->assocreq_ies
[i
]);
463 if (ifsta
->assocresp_ies
) {
464 if (ifsta
->assocreq_ies
)
465 len
+= sprintf(buf
+ len
, " ");
466 len
+= sprintf(buf
+ len
, "RespIEs=");
467 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
468 len
+= sprintf(buf
+ len
, "%02x",
469 ifsta
->assocresp_ies
[i
]);
472 len
+= sprintf(buf
+ len
, ")");
474 if (len
> IW_CUSTOM_MAX
) {
475 len
= sprintf(buf
, "ASSOCRESPIE=");
476 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
477 len
+= sprintf(buf
+ len
, "%02x",
478 ifsta
->assocresp_ies
[i
]);
482 memset(&wrqu
, 0, sizeof(wrqu
));
483 wrqu
.data
.length
= len
;
484 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
490 static void ieee80211_set_associated(struct net_device
*dev
,
491 struct ieee80211_if_sta
*ifsta
,
494 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
495 struct ieee80211_local
*local
= sdata
->local
;
496 union iwreq_data wrqu
;
497 u32 changed
= BSS_CHANGED_ASSOC
;
500 struct ieee80211_sta_bss
*bss
;
502 ifsta
->flags
|= IEEE80211_STA_ASSOCIATED
;
504 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
507 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
508 local
->hw
.conf
.channel
->center_freq
,
509 ifsta
->ssid
, ifsta
->ssid_len
);
511 if (bss
->has_erp_value
)
512 changed
|= ieee80211_handle_erp_ie(
513 sdata
, bss
->erp_value
);
514 ieee80211_rx_bss_put(dev
, bss
);
517 netif_carrier_on(dev
);
518 ifsta
->flags
|= IEEE80211_STA_PREV_BSSID_SET
;
519 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
520 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
521 ieee80211_sta_send_associnfo(dev
, ifsta
);
523 ieee80211_sta_tear_down_BA_sessions(dev
, ifsta
->bssid
);
524 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
525 netif_carrier_off(dev
);
526 ieee80211_reset_erp_info(dev
);
527 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
529 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
530 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
531 ifsta
->last_probe
= jiffies
;
532 ieee80211_led_assoc(local
, assoc
);
534 sdata
->bss_conf
.assoc
= assoc
;
535 ieee80211_bss_info_change_notify(sdata
, changed
);
538 static void ieee80211_set_disassoc(struct net_device
*dev
,
539 struct ieee80211_if_sta
*ifsta
, int deauth
)
542 ifsta
->auth_tries
= 0;
543 ifsta
->assoc_tries
= 0;
544 ieee80211_set_associated(dev
, ifsta
, 0);
547 void ieee80211_sta_tx(struct net_device
*dev
, struct sk_buff
*skb
,
550 struct ieee80211_sub_if_data
*sdata
;
551 struct ieee80211_tx_packet_data
*pkt_data
;
553 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
554 skb
->dev
= sdata
->local
->mdev
;
555 skb_set_mac_header(skb
, 0);
556 skb_set_network_header(skb
, 0);
557 skb_set_transport_header(skb
, 0);
559 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
560 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
561 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
563 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
569 static void ieee80211_send_auth(struct net_device
*dev
,
570 struct ieee80211_if_sta
*ifsta
,
571 int transaction
, u8
*extra
, size_t extra_len
,
574 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
576 struct ieee80211_mgmt
*mgmt
;
578 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
579 sizeof(*mgmt
) + 6 + extra_len
);
581 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
582 "frame\n", dev
->name
);
585 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
587 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
588 memset(mgmt
, 0, 24 + 6);
589 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
590 IEEE80211_STYPE_AUTH
);
592 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
593 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
594 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
595 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
596 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
597 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
598 ifsta
->auth_transaction
= transaction
+ 1;
599 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
601 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
603 ieee80211_sta_tx(dev
, skb
, encrypt
);
607 static void ieee80211_authenticate(struct net_device
*dev
,
608 struct ieee80211_if_sta
*ifsta
)
610 DECLARE_MAC_BUF(mac
);
613 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
614 printk(KERN_DEBUG
"%s: authentication with AP %s"
616 dev
->name
, print_mac(mac
, ifsta
->bssid
));
617 ifsta
->state
= IEEE80211_DISABLED
;
621 ifsta
->state
= IEEE80211_AUTHENTICATE
;
622 printk(KERN_DEBUG
"%s: authenticate with AP %s\n",
623 dev
->name
, print_mac(mac
, ifsta
->bssid
));
625 ieee80211_send_auth(dev
, ifsta
, 1, NULL
, 0, 0);
627 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_AUTH_TIMEOUT
);
631 static void ieee80211_send_assoc(struct net_device
*dev
,
632 struct ieee80211_if_sta
*ifsta
)
634 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
636 struct ieee80211_mgmt
*mgmt
;
640 struct ieee80211_sta_bss
*bss
;
642 struct ieee80211_supported_band
*sband
;
644 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
645 sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
648 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
649 "frame\n", dev
->name
);
652 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
654 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
656 capab
= ifsta
->capab
;
658 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
) {
659 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
660 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
661 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
662 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
665 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
666 local
->hw
.conf
.channel
->center_freq
,
667 ifsta
->ssid
, ifsta
->ssid_len
);
669 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
670 capab
|= WLAN_CAPABILITY_PRIVACY
;
674 ieee80211_rx_bss_put(dev
, bss
);
677 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
679 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
680 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
681 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
683 if (ifsta
->flags
& IEEE80211_STA_PREV_BSSID_SET
) {
685 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
686 IEEE80211_STYPE_REASSOC_REQ
);
687 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
688 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
689 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
693 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
694 IEEE80211_STYPE_ASSOC_REQ
);
695 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
696 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
700 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
701 *pos
++ = WLAN_EID_SSID
;
702 *pos
++ = ifsta
->ssid_len
;
703 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
705 len
= sband
->n_bitrates
;
708 pos
= skb_put(skb
, len
+ 2);
709 *pos
++ = WLAN_EID_SUPP_RATES
;
711 for (i
= 0; i
< len
; i
++) {
712 int rate
= sband
->bitrates
[i
].bitrate
;
713 *pos
++ = (u8
) (rate
/ 5);
716 if (sband
->n_bitrates
> len
) {
717 pos
= skb_put(skb
, sband
->n_bitrates
- len
+ 2);
718 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
719 *pos
++ = sband
->n_bitrates
- len
;
720 for (i
= len
; i
< sband
->n_bitrates
; i
++) {
721 int rate
= sband
->bitrates
[i
].bitrate
;
722 *pos
++ = (u8
) (rate
/ 5);
726 if (ifsta
->extra_ie
) {
727 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
728 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
731 if (wmm
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
732 pos
= skb_put(skb
, 9);
733 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
734 *pos
++ = 7; /* len */
735 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
738 *pos
++ = 2; /* WME */
739 *pos
++ = 0; /* WME info */
740 *pos
++ = 1; /* WME ver */
743 /* wmm support is a must to HT */
744 if (wmm
&& sband
->ht_info
.ht_supported
) {
745 __le16 tmp
= cpu_to_le16(sband
->ht_info
.cap
);
746 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
)+2);
747 *pos
++ = WLAN_EID_HT_CAPABILITY
;
748 *pos
++ = sizeof(struct ieee80211_ht_cap
);
749 memset(pos
, 0, sizeof(struct ieee80211_ht_cap
));
750 memcpy(pos
, &tmp
, sizeof(u16
));
752 /* TODO: needs a define here for << 2 */
753 *pos
++ = sband
->ht_info
.ampdu_factor
|
754 (sband
->ht_info
.ampdu_density
<< 2);
755 memcpy(pos
, sband
->ht_info
.supp_mcs_set
, 16);
758 kfree(ifsta
->assocreq_ies
);
759 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
760 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_KERNEL
);
761 if (ifsta
->assocreq_ies
)
762 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
764 ieee80211_sta_tx(dev
, skb
, 0);
768 static void ieee80211_send_deauth(struct net_device
*dev
,
769 struct ieee80211_if_sta
*ifsta
, u16 reason
)
771 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
773 struct ieee80211_mgmt
*mgmt
;
775 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
777 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
778 "frame\n", dev
->name
);
781 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
783 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
785 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
786 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
787 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
788 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
789 IEEE80211_STYPE_DEAUTH
);
791 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
793 ieee80211_sta_tx(dev
, skb
, 0);
797 static void ieee80211_send_disassoc(struct net_device
*dev
,
798 struct ieee80211_if_sta
*ifsta
, u16 reason
)
800 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
802 struct ieee80211_mgmt
*mgmt
;
804 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
806 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
807 "frame\n", dev
->name
);
810 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
812 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
814 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
815 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
816 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
817 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
818 IEEE80211_STYPE_DISASSOC
);
820 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
822 ieee80211_sta_tx(dev
, skb
, 0);
826 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
827 struct ieee80211_if_sta
*ifsta
)
829 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
830 struct ieee80211_sta_bss
*bss
;
835 if (!ifsta
|| (ifsta
->flags
& IEEE80211_STA_MIXED_CELL
))
838 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
839 local
->hw
.conf
.channel
->center_freq
,
840 ifsta
->ssid
, ifsta
->ssid_len
);
844 bss_privacy
= !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
);
845 wep_privacy
= !!ieee80211_sta_wep_configured(dev
);
846 privacy_invoked
= !!(ifsta
->flags
& IEEE80211_STA_PRIVACY_INVOKED
);
848 ieee80211_rx_bss_put(dev
, bss
);
850 if ((bss_privacy
== wep_privacy
) || (bss_privacy
== privacy_invoked
))
857 static void ieee80211_associate(struct net_device
*dev
,
858 struct ieee80211_if_sta
*ifsta
)
860 DECLARE_MAC_BUF(mac
);
862 ifsta
->assoc_tries
++;
863 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
864 printk(KERN_DEBUG
"%s: association with AP %s"
866 dev
->name
, print_mac(mac
, ifsta
->bssid
));
867 ifsta
->state
= IEEE80211_DISABLED
;
871 ifsta
->state
= IEEE80211_ASSOCIATE
;
872 printk(KERN_DEBUG
"%s: associate with AP %s\n",
873 dev
->name
, print_mac(mac
, ifsta
->bssid
));
874 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
875 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
876 "mixed-cell disabled - abort association\n", dev
->name
);
877 ifsta
->state
= IEEE80211_DISABLED
;
881 ieee80211_send_assoc(dev
, ifsta
);
883 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_ASSOC_TIMEOUT
);
887 static void ieee80211_associated(struct net_device
*dev
,
888 struct ieee80211_if_sta
*ifsta
)
890 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
891 struct sta_info
*sta
;
893 DECLARE_MAC_BUF(mac
);
895 /* TODO: start monitoring current AP signal quality and number of
896 * missed beacons. Scan other channels every now and then and search
898 /* TODO: remove expired BSSes */
900 ifsta
->state
= IEEE80211_ASSOCIATED
;
904 sta
= sta_info_get(local
, ifsta
->bssid
);
906 printk(KERN_DEBUG
"%s: No STA entry for own AP %s\n",
907 dev
->name
, print_mac(mac
, ifsta
->bssid
));
911 if (time_after(jiffies
,
912 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
913 if (ifsta
->flags
& IEEE80211_STA_PROBEREQ_POLL
) {
914 printk(KERN_DEBUG
"%s: No ProbeResp from "
915 "current AP %s - assume out of "
917 dev
->name
, print_mac(mac
, ifsta
->bssid
));
919 sta_info_unlink(&sta
);
921 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
923 local
->scan_ssid_len
);
924 ifsta
->flags
^= IEEE80211_STA_PROBEREQ_POLL
;
926 ifsta
->flags
&= ~IEEE80211_STA_PROBEREQ_POLL
;
927 if (time_after(jiffies
, ifsta
->last_probe
+
928 IEEE80211_PROBE_INTERVAL
)) {
929 ifsta
->last_probe
= jiffies
;
930 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
939 if (disassoc
&& sta
) {
941 sta_info_destroy(sta
);
946 ifsta
->state
= IEEE80211_DISABLED
;
947 ieee80211_set_associated(dev
, ifsta
, 0);
949 mod_timer(&ifsta
->timer
, jiffies
+
950 IEEE80211_MONITORING_INTERVAL
);
955 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
956 u8
*ssid
, size_t ssid_len
)
958 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
959 struct ieee80211_supported_band
*sband
;
961 struct ieee80211_mgmt
*mgmt
;
962 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
965 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200);
967 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
968 "request\n", dev
->name
);
971 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
973 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
975 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
976 IEEE80211_STYPE_PROBE_REQ
);
977 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
979 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
980 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
982 memset(mgmt
->da
, 0xff, ETH_ALEN
);
983 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
985 pos
= skb_put(skb
, 2 + ssid_len
);
986 *pos
++ = WLAN_EID_SSID
;
988 memcpy(pos
, ssid
, ssid_len
);
990 supp_rates
= skb_put(skb
, 2);
991 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
993 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
995 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
996 struct ieee80211_rate
*rate
= &sband
->bitrates
[i
];
998 pos
= skb_put(skb
, 1);
1000 } else if (supp_rates
[1] == 8) {
1001 esupp_rates
= skb_put(skb
, 3);
1002 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
1004 pos
= &esupp_rates
[2];
1006 pos
= skb_put(skb
, 1);
1009 *pos
= rate
->bitrate
/ 5;
1012 ieee80211_sta_tx(dev
, skb
, 0);
1016 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
1018 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1019 if (!sdata
|| !sdata
->default_key
||
1020 sdata
->default_key
->conf
.alg
!= ALG_WEP
)
1026 static void ieee80211_auth_completed(struct net_device
*dev
,
1027 struct ieee80211_if_sta
*ifsta
)
1029 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
1030 ifsta
->flags
|= IEEE80211_STA_AUTHENTICATED
;
1031 ieee80211_associate(dev
, ifsta
);
1035 static void ieee80211_auth_challenge(struct net_device
*dev
,
1036 struct ieee80211_if_sta
*ifsta
,
1037 struct ieee80211_mgmt
*mgmt
,
1041 struct ieee802_11_elems elems
;
1043 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
1044 pos
= mgmt
->u
.auth
.variable
;
1045 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1046 if (!elems
.challenge
) {
1047 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
1048 "frame\n", dev
->name
);
1051 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
1052 elems
.challenge_len
+ 2, 1);
1055 static void ieee80211_send_addba_resp(struct net_device
*dev
, u8
*da
, u16 tid
,
1056 u8 dialog_token
, u16 status
, u16 policy
,
1057 u16 buf_size
, u16 timeout
)
1059 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1060 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1061 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1062 struct sk_buff
*skb
;
1063 struct ieee80211_mgmt
*mgmt
;
1066 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1067 sizeof(mgmt
->u
.action
.u
.addba_resp
));
1069 printk(KERN_DEBUG
"%s: failed to allocate buffer "
1070 "for addba resp frame\n", dev
->name
);
1074 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1075 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1076 memset(mgmt
, 0, 24);
1077 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1078 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1079 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1080 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1082 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1083 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1084 IEEE80211_STYPE_ACTION
);
1086 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_resp
));
1087 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1088 mgmt
->u
.action
.u
.addba_resp
.action_code
= WLAN_ACTION_ADDBA_RESP
;
1089 mgmt
->u
.action
.u
.addba_resp
.dialog_token
= dialog_token
;
1091 capab
= (u16
)(policy
<< 1); /* bit 1 aggregation policy */
1092 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1093 capab
|= (u16
)(buf_size
<< 6); /* bit 15:6 max size of aggregation */
1095 mgmt
->u
.action
.u
.addba_resp
.capab
= cpu_to_le16(capab
);
1096 mgmt
->u
.action
.u
.addba_resp
.timeout
= cpu_to_le16(timeout
);
1097 mgmt
->u
.action
.u
.addba_resp
.status
= cpu_to_le16(status
);
1099 ieee80211_sta_tx(dev
, skb
, 0);
1104 void ieee80211_send_addba_request(struct net_device
*dev
, const u8
*da
,
1105 u16 tid
, u8 dialog_token
, u16 start_seq_num
,
1106 u16 agg_size
, u16 timeout
)
1108 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1109 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1110 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1111 struct sk_buff
*skb
;
1112 struct ieee80211_mgmt
*mgmt
;
1115 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1116 sizeof(mgmt
->u
.action
.u
.addba_req
));
1120 printk(KERN_ERR
"%s: failed to allocate buffer "
1121 "for addba request frame\n", dev
->name
);
1124 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1125 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1126 memset(mgmt
, 0, 24);
1127 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1128 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1129 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1130 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1132 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1134 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1135 IEEE80211_STYPE_ACTION
);
1137 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.addba_req
));
1139 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1140 mgmt
->u
.action
.u
.addba_req
.action_code
= WLAN_ACTION_ADDBA_REQ
;
1142 mgmt
->u
.action
.u
.addba_req
.dialog_token
= dialog_token
;
1143 capab
= (u16
)(1 << 1); /* bit 1 aggregation policy */
1144 capab
|= (u16
)(tid
<< 2); /* bit 5:2 TID number */
1145 capab
|= (u16
)(agg_size
<< 6); /* bit 15:6 max size of aggergation */
1147 mgmt
->u
.action
.u
.addba_req
.capab
= cpu_to_le16(capab
);
1149 mgmt
->u
.action
.u
.addba_req
.timeout
= cpu_to_le16(timeout
);
1150 mgmt
->u
.action
.u
.addba_req
.start_seq_num
=
1151 cpu_to_le16(start_seq_num
<< 4);
1153 ieee80211_sta_tx(dev
, skb
, 0);
1156 static void ieee80211_sta_process_addba_request(struct net_device
*dev
,
1157 struct ieee80211_mgmt
*mgmt
,
1160 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1161 struct ieee80211_hw
*hw
= &local
->hw
;
1162 struct ieee80211_conf
*conf
= &hw
->conf
;
1163 struct sta_info
*sta
;
1164 struct tid_ampdu_rx
*tid_agg_rx
;
1165 u16 capab
, tid
, timeout
, ba_policy
, buf_size
, start_seq_num
, status
;
1167 int ret
= -EOPNOTSUPP
;
1168 DECLARE_MAC_BUF(mac
);
1172 sta
= sta_info_get(local
, mgmt
->sa
);
1178 /* extract session parameters from addba request frame */
1179 dialog_token
= mgmt
->u
.action
.u
.addba_req
.dialog_token
;
1180 timeout
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.timeout
);
1182 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.start_seq_num
) >> 4;
1184 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1185 ba_policy
= (capab
& IEEE80211_ADDBA_PARAM_POLICY_MASK
) >> 1;
1186 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1187 buf_size
= (capab
& IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
) >> 6;
1189 status
= WLAN_STATUS_REQUEST_DECLINED
;
1191 /* sanity check for incoming parameters:
1192 * check if configuration can support the BA policy
1193 * and if buffer size does not exceeds max value */
1194 if (((ba_policy
!= 1)
1195 && (!(conf
->ht_conf
.cap
& IEEE80211_HT_CAP_DELAY_BA
)))
1196 || (buf_size
> IEEE80211_MAX_AMPDU_BUF
)) {
1197 status
= WLAN_STATUS_INVALID_QOS_PARAM
;
1198 #ifdef CONFIG_MAC80211_HT_DEBUG
1199 if (net_ratelimit())
1200 printk(KERN_DEBUG
"AddBA Req with bad params from "
1201 "%s on tid %u. policy %d, buffer size %d\n",
1202 print_mac(mac
, mgmt
->sa
), tid
, ba_policy
,
1204 #endif /* CONFIG_MAC80211_HT_DEBUG */
1207 /* determine default buffer size */
1208 if (buf_size
== 0) {
1209 struct ieee80211_supported_band
*sband
;
1211 sband
= local
->hw
.wiphy
->bands
[conf
->channel
->band
];
1212 buf_size
= IEEE80211_MIN_AMPDU_BUF
;
1213 buf_size
= buf_size
<< sband
->ht_info
.ampdu_factor
;
1217 /* examine state machine */
1218 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1220 if (sta
->ampdu_mlme
.tid_state_rx
[tid
] != HT_AGG_STATE_IDLE
) {
1221 #ifdef CONFIG_MAC80211_HT_DEBUG
1222 if (net_ratelimit())
1223 printk(KERN_DEBUG
"unexpected AddBA Req from "
1225 print_mac(mac
, mgmt
->sa
), tid
);
1226 #endif /* CONFIG_MAC80211_HT_DEBUG */
1230 /* prepare A-MPDU MLME for Rx aggregation */
1231 sta
->ampdu_mlme
.tid_rx
[tid
] =
1232 kmalloc(sizeof(struct tid_ampdu_rx
), GFP_ATOMIC
);
1233 if (!sta
->ampdu_mlme
.tid_rx
[tid
]) {
1234 if (net_ratelimit())
1235 printk(KERN_ERR
"allocate rx mlme to tid %d failed\n",
1240 sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
.function
=
1241 sta_rx_agg_session_timer_expired
;
1242 sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
.data
=
1243 (unsigned long)&sta
->timer_to_tid
[tid
];
1244 init_timer(&sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
);
1246 tid_agg_rx
= sta
->ampdu_mlme
.tid_rx
[tid
];
1248 /* prepare reordering buffer */
1249 tid_agg_rx
->reorder_buf
=
1250 kmalloc(buf_size
* sizeof(struct sk_buf
*), GFP_ATOMIC
);
1251 if (!tid_agg_rx
->reorder_buf
) {
1252 if (net_ratelimit())
1253 printk(KERN_ERR
"can not allocate reordering buffer "
1254 "to tid %d\n", tid
);
1255 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]);
1258 memset(tid_agg_rx
->reorder_buf
, 0,
1259 buf_size
* sizeof(struct sk_buf
*));
1261 if (local
->ops
->ampdu_action
)
1262 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_START
,
1263 sta
->addr
, tid
, &start_seq_num
);
1264 #ifdef CONFIG_MAC80211_HT_DEBUG
1265 printk(KERN_DEBUG
"Rx A-MPDU on tid %d result %d", tid
, ret
);
1266 #endif /* CONFIG_MAC80211_HT_DEBUG */
1269 kfree(tid_agg_rx
->reorder_buf
);
1271 sta
->ampdu_mlme
.tid_rx
[tid
] = NULL
;
1275 /* change state and send addba resp */
1276 sta
->ampdu_mlme
.tid_state_rx
[tid
] = HT_AGG_STATE_OPERATIONAL
;
1277 tid_agg_rx
->dialog_token
= dialog_token
;
1278 tid_agg_rx
->ssn
= start_seq_num
;
1279 tid_agg_rx
->head_seq_num
= start_seq_num
;
1280 tid_agg_rx
->buf_size
= buf_size
;
1281 tid_agg_rx
->timeout
= timeout
;
1282 tid_agg_rx
->stored_mpdu_num
= 0;
1283 status
= WLAN_STATUS_SUCCESS
;
1285 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1288 ieee80211_send_addba_resp(sta
->sdata
->dev
, sta
->addr
, tid
,
1289 dialog_token
, status
, 1, buf_size
, timeout
);
1293 static void ieee80211_sta_process_addba_resp(struct net_device
*dev
,
1294 struct ieee80211_mgmt
*mgmt
,
1297 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1298 struct ieee80211_hw
*hw
= &local
->hw
;
1299 struct sta_info
*sta
;
1306 sta
= sta_info_get(local
, mgmt
->sa
);
1312 capab
= le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.capab
);
1313 tid
= (capab
& IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1315 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
1317 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1319 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1320 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1321 printk(KERN_DEBUG
"state not HT_ADDBA_REQUESTED_MSK:"
1323 goto addba_resp_exit
;
1326 if (mgmt
->u
.action
.u
.addba_resp
.dialog_token
!=
1327 sta
->ampdu_mlme
.tid_tx
[tid
]->dialog_token
) {
1328 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1329 #ifdef CONFIG_MAC80211_HT_DEBUG
1330 printk(KERN_DEBUG
"wrong addBA response token, tid %d\n", tid
);
1331 #endif /* CONFIG_MAC80211_HT_DEBUG */
1332 goto addba_resp_exit
;
1335 del_timer_sync(&sta
->ampdu_mlme
.tid_tx
[tid
]->addba_resp_timer
);
1336 #ifdef CONFIG_MAC80211_HT_DEBUG
1337 printk(KERN_DEBUG
"switched off addBA timer for tid %d \n", tid
);
1338 #endif /* CONFIG_MAC80211_HT_DEBUG */
1339 if (le16_to_cpu(mgmt
->u
.action
.u
.addba_resp
.status
)
1340 == WLAN_STATUS_SUCCESS
) {
1341 if (*state
& HT_ADDBA_RECEIVED_MSK
)
1342 printk(KERN_DEBUG
"double addBA response\n");
1344 *state
|= HT_ADDBA_RECEIVED_MSK
;
1345 sta
->ampdu_mlme
.addba_req_num
[tid
] = 0;
1347 if (*state
== HT_AGG_STATE_OPERATIONAL
) {
1348 printk(KERN_DEBUG
"Aggregation on for tid %d \n", tid
);
1349 ieee80211_wake_queue(hw
, sta
->tid_to_tx_q
[tid
]);
1352 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1353 printk(KERN_DEBUG
"recipient accepted agg: tid %d \n", tid
);
1355 printk(KERN_DEBUG
"recipient rejected agg: tid %d \n", tid
);
1357 sta
->ampdu_mlme
.addba_req_num
[tid
]++;
1358 /* this will allow the state check in stop_BA_session */
1359 *state
= HT_AGG_STATE_OPERATIONAL
;
1360 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1361 ieee80211_stop_tx_ba_session(hw
, sta
->addr
, tid
,
1362 WLAN_BACK_INITIATOR
);
1369 void ieee80211_send_delba(struct net_device
*dev
, const u8
*da
, u16 tid
,
1370 u16 initiator
, u16 reason_code
)
1372 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1373 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1374 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1375 struct sk_buff
*skb
;
1376 struct ieee80211_mgmt
*mgmt
;
1379 skb
= dev_alloc_skb(sizeof(*mgmt
) + local
->hw
.extra_tx_headroom
+ 1 +
1380 sizeof(mgmt
->u
.action
.u
.delba
));
1383 printk(KERN_ERR
"%s: failed to allocate buffer "
1384 "for delba frame\n", dev
->name
);
1388 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1389 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
1390 memset(mgmt
, 0, 24);
1391 memcpy(mgmt
->da
, da
, ETH_ALEN
);
1392 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1393 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
)
1394 memcpy(mgmt
->bssid
, dev
->dev_addr
, ETH_ALEN
);
1396 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
1397 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
1398 IEEE80211_STYPE_ACTION
);
1400 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.delba
));
1402 mgmt
->u
.action
.category
= WLAN_CATEGORY_BACK
;
1403 mgmt
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
1404 params
= (u16
)(initiator
<< 11); /* bit 11 initiator */
1405 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
1407 mgmt
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
1408 mgmt
->u
.action
.u
.delba
.reason_code
= cpu_to_le16(reason_code
);
1410 ieee80211_sta_tx(dev
, skb
, 0);
1413 void ieee80211_sta_stop_rx_ba_session(struct net_device
*dev
, u8
*ra
, u16 tid
,
1414 u16 initiator
, u16 reason
)
1416 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1417 struct ieee80211_hw
*hw
= &local
->hw
;
1418 struct sta_info
*sta
;
1423 sta
= sta_info_get(local
, ra
);
1429 /* check if TID is in operational state */
1430 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1431 if (sta
->ampdu_mlme
.tid_state_rx
[tid
]
1432 != HT_AGG_STATE_OPERATIONAL
) {
1433 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1437 sta
->ampdu_mlme
.tid_state_rx
[tid
] =
1438 HT_AGG_STATE_REQ_STOP_BA_MSK
|
1439 (initiator
<< HT_AGG_STATE_INITIATOR_SHIFT
);
1440 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_rx
);
1442 /* stop HW Rx aggregation. ampdu_action existence
1443 * already verified in session init so we add the BUG_ON */
1444 BUG_ON(!local
->ops
->ampdu_action
);
1446 ret
= local
->ops
->ampdu_action(hw
, IEEE80211_AMPDU_RX_STOP
,
1449 printk(KERN_DEBUG
"HW problem - can not stop rx "
1450 "aggergation for tid %d\n", tid
);
1452 /* shutdown timer has not expired */
1453 if (initiator
!= WLAN_BACK_TIMER
)
1454 del_timer_sync(&sta
->ampdu_mlme
.tid_rx
[tid
]->session_timer
);
1456 /* check if this is a self generated aggregation halt */
1457 if (initiator
== WLAN_BACK_RECIPIENT
|| initiator
== WLAN_BACK_TIMER
)
1458 ieee80211_send_delba(dev
, ra
, tid
, 0, reason
);
1460 /* free the reordering buffer */
1461 for (i
= 0; i
< sta
->ampdu_mlme
.tid_rx
[tid
]->buf_size
; i
++) {
1462 if (sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
]) {
1463 /* release the reordered frames */
1464 dev_kfree_skb(sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
]);
1465 sta
->ampdu_mlme
.tid_rx
[tid
]->stored_mpdu_num
--;
1466 sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
[i
] = NULL
;
1469 /* free resources */
1470 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]->reorder_buf
);
1471 kfree(sta
->ampdu_mlme
.tid_rx
[tid
]);
1472 sta
->ampdu_mlme
.tid_rx
[tid
] = NULL
;
1473 sta
->ampdu_mlme
.tid_state_rx
[tid
] = HT_AGG_STATE_IDLE
;
1479 static void ieee80211_sta_process_delba(struct net_device
*dev
,
1480 struct ieee80211_mgmt
*mgmt
, size_t len
)
1482 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1483 struct sta_info
*sta
;
1486 DECLARE_MAC_BUF(mac
);
1490 sta
= sta_info_get(local
, mgmt
->sa
);
1496 params
= le16_to_cpu(mgmt
->u
.action
.u
.delba
.params
);
1497 tid
= (params
& IEEE80211_DELBA_PARAM_TID_MASK
) >> 12;
1498 initiator
= (params
& IEEE80211_DELBA_PARAM_INITIATOR_MASK
) >> 11;
1500 #ifdef CONFIG_MAC80211_HT_DEBUG
1501 if (net_ratelimit())
1502 printk(KERN_DEBUG
"delba from %s (%s) tid %d reason code %d\n",
1503 print_mac(mac
, mgmt
->sa
),
1504 initiator
? "initiator" : "recipient", tid
,
1505 mgmt
->u
.action
.u
.delba
.reason_code
);
1506 #endif /* CONFIG_MAC80211_HT_DEBUG */
1508 if (initiator
== WLAN_BACK_INITIATOR
)
1509 ieee80211_sta_stop_rx_ba_session(dev
, sta
->addr
, tid
,
1510 WLAN_BACK_INITIATOR
, 0);
1511 else { /* WLAN_BACK_RECIPIENT */
1512 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1513 sta
->ampdu_mlme
.tid_state_tx
[tid
] =
1514 HT_AGG_STATE_OPERATIONAL
;
1515 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1516 ieee80211_stop_tx_ba_session(&local
->hw
, sta
->addr
, tid
,
1517 WLAN_BACK_RECIPIENT
);
1523 * After sending add Block Ack request we activated a timer until
1524 * add Block Ack response will arrive from the recipient.
1525 * If this timer expires sta_addba_resp_timer_expired will be executed.
1527 void sta_addba_resp_timer_expired(unsigned long data
)
1529 /* not an elegant detour, but there is no choice as the timer passes
1530 * only one argument, and both sta_info and TID are needed, so init
1531 * flow in sta_info_create gives the TID as data, while the timer_to_id
1532 * array gives the sta through container_of */
1533 u16 tid
= *(int *)data
;
1534 struct sta_info
*temp_sta
= container_of((void *)data
,
1535 struct sta_info
, timer_to_tid
[tid
]);
1537 struct ieee80211_local
*local
= temp_sta
->local
;
1538 struct ieee80211_hw
*hw
= &local
->hw
;
1539 struct sta_info
*sta
;
1544 sta
= sta_info_get(local
, temp_sta
->addr
);
1550 state
= &sta
->ampdu_mlme
.tid_state_tx
[tid
];
1551 /* check if the TID waits for addBA response */
1552 spin_lock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1553 if (!(*state
& HT_ADDBA_REQUESTED_MSK
)) {
1554 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1555 *state
= HT_AGG_STATE_IDLE
;
1556 printk(KERN_DEBUG
"timer expired on tid %d but we are not "
1557 "expecting addBA response there", tid
);
1558 goto timer_expired_exit
;
1561 printk(KERN_DEBUG
"addBA response timer expired on tid %d\n", tid
);
1563 /* go through the state check in stop_BA_session */
1564 *state
= HT_AGG_STATE_OPERATIONAL
;
1565 spin_unlock_bh(&sta
->ampdu_mlme
.ampdu_tx
);
1566 ieee80211_stop_tx_ba_session(hw
, temp_sta
->addr
, tid
,
1567 WLAN_BACK_INITIATOR
);
1574 * After accepting the AddBA Request we activated a timer,
1575 * resetting it after each frame that arrives from the originator.
1576 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
1578 void sta_rx_agg_session_timer_expired(unsigned long data
)
1580 /* not an elegant detour, but there is no choice as the timer passes
1581 * only one argument, and verious sta_info are needed here, so init
1582 * flow in sta_info_create gives the TID as data, while the timer_to_id
1583 * array gives the sta through container_of */
1584 u8
*ptid
= (u8
*)data
;
1585 u8
*timer_to_id
= ptid
- *ptid
;
1586 struct sta_info
*sta
= container_of(timer_to_id
, struct sta_info
,
1589 printk(KERN_DEBUG
"rx session timer expired on tid %d\n", (u16
)*ptid
);
1590 ieee80211_sta_stop_rx_ba_session(sta
->sdata
->dev
, sta
->addr
,
1591 (u16
)*ptid
, WLAN_BACK_TIMER
,
1592 WLAN_REASON_QSTA_TIMEOUT
);
1595 void ieee80211_sta_tear_down_BA_sessions(struct net_device
*dev
, u8
*addr
)
1597 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1600 for (i
= 0; i
< STA_TID_NUM
; i
++) {
1601 ieee80211_stop_tx_ba_session(&local
->hw
, addr
, i
,
1602 WLAN_BACK_INITIATOR
);
1603 ieee80211_sta_stop_rx_ba_session(dev
, addr
, i
,
1604 WLAN_BACK_RECIPIENT
,
1605 WLAN_REASON_QSTA_LEAVE_QBSS
);
1609 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
1610 struct ieee80211_if_sta
*ifsta
,
1611 struct ieee80211_mgmt
*mgmt
,
1614 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1615 u16 auth_alg
, auth_transaction
, status_code
;
1616 DECLARE_MAC_BUF(mac
);
1618 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
1619 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
) {
1620 printk(KERN_DEBUG
"%s: authentication frame received from "
1621 "%s, but not in authenticate state - ignored\n",
1622 dev
->name
, print_mac(mac
, mgmt
->sa
));
1627 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
1628 "received from %s - ignored\n",
1629 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1633 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1634 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1635 printk(KERN_DEBUG
"%s: authentication frame received from "
1636 "unknown AP (SA=%s BSSID=%s) - "
1637 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1638 print_mac(mac
, mgmt
->bssid
));
1642 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
1643 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
1644 printk(KERN_DEBUG
"%s: authentication frame received from "
1645 "unknown BSSID (SA=%s BSSID=%s) - "
1646 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1647 print_mac(mac
, mgmt
->bssid
));
1651 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
1652 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
1653 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
1655 printk(KERN_DEBUG
"%s: RX authentication from %s (alg=%d "
1656 "transaction=%d status=%d)\n",
1657 dev
->name
, print_mac(mac
, mgmt
->sa
), auth_alg
,
1658 auth_transaction
, status_code
);
1660 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
1661 /* IEEE 802.11 standard does not require authentication in IBSS
1662 * networks and most implementations do not seem to use it.
1663 * However, try to reply to authentication attempts if someone
1664 * has actually implemented this.
1665 * TODO: Could implement shared key authentication. */
1666 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
1667 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
1668 "frame (alg=%d transaction=%d)\n",
1669 dev
->name
, auth_alg
, auth_transaction
);
1672 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
1675 if (auth_alg
!= ifsta
->auth_alg
||
1676 auth_transaction
!= ifsta
->auth_transaction
) {
1677 printk(KERN_DEBUG
"%s: unexpected authentication frame "
1678 "(alg=%d transaction=%d)\n",
1679 dev
->name
, auth_alg
, auth_transaction
);
1683 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1684 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
1685 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
1686 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
1688 const int num_algs
= ARRAY_SIZE(algs
);
1690 algs
[0] = algs
[1] = algs
[2] = 0xff;
1691 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1692 algs
[0] = WLAN_AUTH_OPEN
;
1693 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1694 algs
[1] = WLAN_AUTH_SHARED_KEY
;
1695 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1696 algs
[2] = WLAN_AUTH_LEAP
;
1697 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
1699 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
1703 for (i
= 0; i
< num_algs
; i
++) {
1705 if (pos
>= num_algs
)
1707 if (algs
[pos
] == ifsta
->auth_alg
||
1710 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
1711 !ieee80211_sta_wep_configured(dev
))
1713 ifsta
->auth_alg
= algs
[pos
];
1714 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
1716 dev
->name
, ifsta
->auth_alg
);
1723 switch (ifsta
->auth_alg
) {
1724 case WLAN_AUTH_OPEN
:
1725 case WLAN_AUTH_LEAP
:
1726 ieee80211_auth_completed(dev
, ifsta
);
1728 case WLAN_AUTH_SHARED_KEY
:
1729 if (ifsta
->auth_transaction
== 4)
1730 ieee80211_auth_completed(dev
, ifsta
);
1732 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
);
1738 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
1739 struct ieee80211_if_sta
*ifsta
,
1740 struct ieee80211_mgmt
*mgmt
,
1744 DECLARE_MAC_BUF(mac
);
1747 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
1748 "received from %s - ignored\n",
1749 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1753 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1754 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1755 "unknown AP (SA=%s BSSID=%s) - "
1756 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1757 print_mac(mac
, mgmt
->bssid
));
1761 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1763 printk(KERN_DEBUG
"%s: RX deauthentication from %s"
1765 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1767 if (ifsta
->flags
& IEEE80211_STA_AUTHENTICATED
) {
1768 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1771 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1772 ifsta
->state
== IEEE80211_ASSOCIATE
||
1773 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1774 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1775 mod_timer(&ifsta
->timer
, jiffies
+
1776 IEEE80211_RETRY_AUTH_INTERVAL
);
1779 ieee80211_set_disassoc(dev
, ifsta
, 1);
1780 ifsta
->flags
&= ~IEEE80211_STA_AUTHENTICATED
;
1784 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1785 struct ieee80211_if_sta
*ifsta
,
1786 struct ieee80211_mgmt
*mgmt
,
1790 DECLARE_MAC_BUF(mac
);
1793 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1794 "received from %s - ignored\n",
1795 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1799 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1800 printk(KERN_DEBUG
"%s: disassociation frame received from "
1801 "unknown AP (SA=%s BSSID=%s) - "
1802 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1803 print_mac(mac
, mgmt
->bssid
));
1807 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1809 printk(KERN_DEBUG
"%s: RX disassociation from %s"
1811 dev
->name
, print_mac(mac
, mgmt
->sa
), reason_code
);
1813 if (ifsta
->flags
& IEEE80211_STA_ASSOCIATED
)
1814 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1816 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1817 ifsta
->state
= IEEE80211_ASSOCIATE
;
1818 mod_timer(&ifsta
->timer
, jiffies
+
1819 IEEE80211_RETRY_AUTH_INTERVAL
);
1822 ieee80211_set_disassoc(dev
, ifsta
, 0);
1826 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
1827 struct ieee80211_if_sta
*ifsta
,
1828 struct ieee80211_mgmt
*mgmt
,
1832 struct ieee80211_local
*local
= sdata
->local
;
1833 struct net_device
*dev
= sdata
->dev
;
1834 struct ieee80211_supported_band
*sband
;
1835 struct sta_info
*sta
;
1836 u64 rates
, basic_rates
;
1837 u16 capab_info
, status_code
, aid
;
1838 struct ieee802_11_elems elems
;
1839 struct ieee80211_bss_conf
*bss_conf
= &sdata
->bss_conf
;
1842 DECLARE_MAC_BUF(mac
);
1843 bool have_higher_than_11mbit
= false;
1845 /* AssocResp and ReassocResp have identical structure, so process both
1846 * of them in this function. */
1848 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1849 printk(KERN_DEBUG
"%s: association frame received from "
1850 "%s, but not in associate state - ignored\n",
1851 dev
->name
, print_mac(mac
, mgmt
->sa
));
1856 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1857 "received from %s - ignored\n",
1858 dev
->name
, len
, print_mac(mac
, mgmt
->sa
));
1862 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1863 printk(KERN_DEBUG
"%s: association frame received from "
1864 "unknown AP (SA=%s BSSID=%s) - "
1865 "ignored\n", dev
->name
, print_mac(mac
, mgmt
->sa
),
1866 print_mac(mac
, mgmt
->bssid
));
1870 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1871 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1872 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1874 printk(KERN_DEBUG
"%s: RX %sssocResp from %s (capab=0x%x "
1875 "status=%d aid=%d)\n",
1876 dev
->name
, reassoc
? "Rea" : "A", print_mac(mac
, mgmt
->sa
),
1877 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
1879 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1880 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1881 dev
->name
, status_code
);
1882 /* if this was a reassociation, ensure we try a "full"
1883 * association next time. This works around some broken APs
1884 * which do not correctly reject reassociation requests. */
1885 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
1889 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1890 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1891 "set\n", dev
->name
, aid
);
1892 aid
&= ~(BIT(15) | BIT(14));
1894 pos
= mgmt
->u
.assoc_resp
.variable
;
1895 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1897 if (!elems
.supp_rates
) {
1898 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1903 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1905 ifsta
->ap_capab
= capab_info
;
1907 kfree(ifsta
->assocresp_ies
);
1908 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1909 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_KERNEL
);
1910 if (ifsta
->assocresp_ies
)
1911 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1915 /* Add STA entry for the AP */
1916 sta
= sta_info_get(local
, ifsta
->bssid
);
1918 struct ieee80211_sta_bss
*bss
;
1921 sta
= sta_info_alloc(sdata
, ifsta
->bssid
, GFP_ATOMIC
);
1923 printk(KERN_DEBUG
"%s: failed to alloc STA entry for"
1924 " the AP\n", dev
->name
);
1928 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
,
1929 local
->hw
.conf
.channel
->center_freq
,
1930 ifsta
->ssid
, ifsta
->ssid_len
);
1932 sta
->last_rssi
= bss
->rssi
;
1933 sta
->last_signal
= bss
->signal
;
1934 sta
->last_noise
= bss
->noise
;
1935 ieee80211_rx_bss_put(dev
, bss
);
1938 err
= sta_info_insert(sta
);
1940 printk(KERN_DEBUG
"%s: failed to insert STA entry for"
1941 " the AP (error %d)\n", dev
->name
, err
);
1948 * FIXME: Do we really need to update the sta_info's information here?
1949 * We already know about the AP (we found it in our list) so it
1950 * should already be filled with the right info, no?
1951 * As is stands, all this is racy because typically we assume
1952 * the information that is filled in here (except flags) doesn't
1953 * change while a STA structure is alive. As such, it should move
1954 * to between the sta_info_alloc() and sta_info_insert() above.
1957 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
| WLAN_STA_ASSOC_AP
|
1958 WLAN_STA_AUTHORIZED
;
1962 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
1964 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
1965 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
1968 have_higher_than_11mbit
= true;
1970 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1971 if (sband
->bitrates
[j
].bitrate
== rate
)
1973 if (elems
.supp_rates
[i
] & 0x80)
1974 basic_rates
|= BIT(j
);
1978 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
1979 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
1982 have_higher_than_11mbit
= true;
1984 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1985 if (sband
->bitrates
[j
].bitrate
== rate
)
1987 if (elems
.ext_supp_rates
[i
] & 0x80)
1988 basic_rates
|= BIT(j
);
1992 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] = rates
;
1993 sdata
->basic_rates
= basic_rates
;
1995 /* cf. IEEE 802.11 9.2.12 */
1996 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
1997 have_higher_than_11mbit
)
1998 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
2000 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
2002 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&& elems
.wmm_param
&&
2003 local
->ops
->conf_ht
) {
2004 struct ieee80211_ht_bss_info bss_info
;
2006 ieee80211_ht_cap_ie_to_ht_info(
2007 (struct ieee80211_ht_cap
*)
2008 elems
.ht_cap_elem
, &sta
->ht_info
);
2009 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2010 (struct ieee80211_ht_addt_info
*)
2011 elems
.ht_info_elem
, &bss_info
);
2012 ieee80211_hw_config_ht(local
, 1, &sta
->ht_info
, &bss_info
);
2015 rate_control_rate_init(sta
, local
);
2017 if (elems
.wmm_param
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
2018 sta
->flags
|= WLAN_STA_WME
;
2020 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2021 elems
.wmm_param_len
);
2025 /* set AID, ieee80211_set_associated() will tell the driver */
2026 bss_conf
->aid
= aid
;
2027 ieee80211_set_associated(dev
, ifsta
, 1);
2029 ieee80211_associated(dev
, ifsta
);
2033 /* Caller must hold local->sta_bss_lock */
2034 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
2035 struct ieee80211_sta_bss
*bss
)
2037 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2040 if (bss_mesh_cfg(bss
))
2041 hash_idx
= mesh_id_hash(bss_mesh_id(bss
),
2042 bss_mesh_id_len(bss
));
2044 hash_idx
= STA_HASH(bss
->bssid
);
2046 bss
->hnext
= local
->sta_bss_hash
[hash_idx
];
2047 local
->sta_bss_hash
[hash_idx
] = bss
;
2051 /* Caller must hold local->sta_bss_lock */
2052 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
2053 struct ieee80211_sta_bss
*bss
)
2055 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2056 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
2057 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
2061 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
2064 prev
->hnext
= bss
->hnext
;
2073 static struct ieee80211_sta_bss
*
2074 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
, int freq
,
2075 u8
*ssid
, u8 ssid_len
)
2077 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2078 struct ieee80211_sta_bss
*bss
;
2080 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2083 atomic_inc(&bss
->users
);
2084 atomic_inc(&bss
->users
);
2085 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
2087 if (ssid
&& ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
2088 memcpy(bss
->ssid
, ssid
, ssid_len
);
2089 bss
->ssid_len
= ssid_len
;
2092 spin_lock_bh(&local
->sta_bss_lock
);
2093 /* TODO: order by RSSI? */
2094 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2095 __ieee80211_rx_bss_hash_add(dev
, bss
);
2096 spin_unlock_bh(&local
->sta_bss_lock
);
2100 static struct ieee80211_sta_bss
*
2101 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
, int freq
,
2102 u8
*ssid
, u8 ssid_len
)
2104 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2105 struct ieee80211_sta_bss
*bss
;
2107 spin_lock_bh(&local
->sta_bss_lock
);
2108 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
2110 if (!bss_mesh_cfg(bss
) &&
2111 !memcmp(bss
->bssid
, bssid
, ETH_ALEN
) &&
2112 bss
->freq
== freq
&&
2113 bss
->ssid_len
== ssid_len
&&
2114 (ssid_len
== 0 || !memcmp(bss
->ssid
, ssid
, ssid_len
))) {
2115 atomic_inc(&bss
->users
);
2120 spin_unlock_bh(&local
->sta_bss_lock
);
2124 #ifdef CONFIG_MAC80211_MESH
2125 static struct ieee80211_sta_bss
*
2126 ieee80211_rx_mesh_bss_get(struct net_device
*dev
, u8
*mesh_id
, int mesh_id_len
,
2127 u8
*mesh_cfg
, int freq
)
2129 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2130 struct ieee80211_sta_bss
*bss
;
2132 spin_lock_bh(&local
->sta_bss_lock
);
2133 bss
= local
->sta_bss_hash
[mesh_id_hash(mesh_id
, mesh_id_len
)];
2135 if (bss_mesh_cfg(bss
) &&
2136 !memcmp(bss_mesh_cfg(bss
), mesh_cfg
, MESH_CFG_CMP_LEN
) &&
2137 bss
->freq
== freq
&&
2138 mesh_id_len
== bss
->mesh_id_len
&&
2139 (mesh_id_len
== 0 || !memcmp(bss
->mesh_id
, mesh_id
,
2141 atomic_inc(&bss
->users
);
2146 spin_unlock_bh(&local
->sta_bss_lock
);
2150 static struct ieee80211_sta_bss
*
2151 ieee80211_rx_mesh_bss_add(struct net_device
*dev
, u8
*mesh_id
, int mesh_id_len
,
2152 u8
*mesh_cfg
, int mesh_config_len
, int freq
)
2154 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2155 struct ieee80211_sta_bss
*bss
;
2157 if (mesh_config_len
!= MESH_CFG_LEN
)
2160 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
2164 bss
->mesh_cfg
= kmalloc(MESH_CFG_CMP_LEN
, GFP_ATOMIC
);
2165 if (!bss
->mesh_cfg
) {
2170 if (mesh_id_len
&& mesh_id_len
<= IEEE80211_MAX_MESH_ID_LEN
) {
2171 bss
->mesh_id
= kmalloc(mesh_id_len
, GFP_ATOMIC
);
2172 if (!bss
->mesh_id
) {
2173 kfree(bss
->mesh_cfg
);
2177 memcpy(bss
->mesh_id
, mesh_id
, mesh_id_len
);
2180 atomic_inc(&bss
->users
);
2181 atomic_inc(&bss
->users
);
2182 memcpy(bss
->mesh_cfg
, mesh_cfg
, MESH_CFG_CMP_LEN
);
2183 bss
->mesh_id_len
= mesh_id_len
;
2185 spin_lock_bh(&local
->sta_bss_lock
);
2186 /* TODO: order by RSSI? */
2187 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
2188 __ieee80211_rx_bss_hash_add(dev
, bss
);
2189 spin_unlock_bh(&local
->sta_bss_lock
);
2194 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
2200 kfree(bss_mesh_id(bss
));
2201 kfree(bss_mesh_cfg(bss
));
2206 static void ieee80211_rx_bss_put(struct net_device
*dev
,
2207 struct ieee80211_sta_bss
*bss
)
2209 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2210 if (!atomic_dec_and_test(&bss
->users
))
2213 spin_lock_bh(&local
->sta_bss_lock
);
2214 __ieee80211_rx_bss_hash_del(dev
, bss
);
2215 list_del(&bss
->list
);
2216 spin_unlock_bh(&local
->sta_bss_lock
);
2217 ieee80211_rx_bss_free(bss
);
2221 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
2223 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2224 spin_lock_init(&local
->sta_bss_lock
);
2225 INIT_LIST_HEAD(&local
->sta_bss_list
);
2229 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
2231 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2232 struct ieee80211_sta_bss
*bss
, *tmp
;
2234 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
2235 ieee80211_rx_bss_put(dev
, bss
);
2239 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
2240 struct ieee80211_if_sta
*ifsta
,
2241 struct ieee80211_sta_bss
*bss
)
2243 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2244 int res
, rates
, i
, j
;
2245 struct sk_buff
*skb
;
2246 struct ieee80211_mgmt
*mgmt
;
2247 struct ieee80211_tx_control control
;
2248 struct rate_selection ratesel
;
2250 struct ieee80211_sub_if_data
*sdata
;
2251 struct ieee80211_supported_band
*sband
;
2253 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2255 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2257 /* Remove possible STA entries from other IBSS networks. */
2258 sta_info_flush_delayed(sdata
);
2260 if (local
->ops
->reset_tsf
) {
2261 /* Reset own TSF to allow time synchronization work. */
2262 local
->ops
->reset_tsf(local_to_hw(local
));
2264 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
2265 res
= ieee80211_if_config(dev
);
2269 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2271 sdata
->drop_unencrypted
= bss
->capability
&
2272 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
2274 res
= ieee80211_set_freq(local
, bss
->freq
);
2276 if (local
->oper_channel
->flags
& IEEE80211_CHAN_NO_IBSS
) {
2277 printk(KERN_DEBUG
"%s: IBSS not allowed on frequency "
2278 "%d MHz\n", dev
->name
, local
->oper_channel
->center_freq
);
2282 /* Set beacon template */
2283 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 400);
2288 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2290 mgmt
= (struct ieee80211_mgmt
*)
2291 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2292 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2293 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2294 IEEE80211_STYPE_BEACON
);
2295 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2296 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2297 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2298 mgmt
->u
.beacon
.beacon_int
=
2299 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2300 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2302 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2303 *pos
++ = WLAN_EID_SSID
;
2304 *pos
++ = ifsta
->ssid_len
;
2305 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2307 rates
= bss
->supp_rates_len
;
2310 pos
= skb_put(skb
, 2 + rates
);
2311 *pos
++ = WLAN_EID_SUPP_RATES
;
2313 memcpy(pos
, bss
->supp_rates
, rates
);
2315 if (bss
->band
== IEEE80211_BAND_2GHZ
) {
2316 pos
= skb_put(skb
, 2 + 1);
2317 *pos
++ = WLAN_EID_DS_PARAMS
;
2319 *pos
++ = ieee80211_frequency_to_channel(bss
->freq
);
2322 pos
= skb_put(skb
, 2 + 2);
2323 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2325 /* FIX: set ATIM window based on scan results */
2329 if (bss
->supp_rates_len
> 8) {
2330 rates
= bss
->supp_rates_len
- 8;
2331 pos
= skb_put(skb
, 2 + rates
);
2332 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2334 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2337 memset(&control
, 0, sizeof(control
));
2338 rate_control_get_rate(dev
, sband
, skb
, &ratesel
);
2339 if (!ratesel
.rate
) {
2340 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2341 "for IBSS beacon\n", dev
->name
);
2344 control
.vif
= &sdata
->vif
;
2345 control
.tx_rate
= ratesel
.rate
;
2346 if (sdata
->bss_conf
.use_short_preamble
&&
2347 ratesel
.rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
2348 control
.flags
|= IEEE80211_TXCTL_SHORT_PREAMBLE
;
2349 control
.antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
2350 control
.flags
|= IEEE80211_TXCTL_NO_ACK
;
2351 control
.retry_limit
= 1;
2353 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2354 if (ifsta
->probe_resp
) {
2355 mgmt
= (struct ieee80211_mgmt
*)
2356 ifsta
->probe_resp
->data
;
2357 mgmt
->frame_control
=
2358 IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2359 IEEE80211_STYPE_PROBE_RESP
);
2361 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2362 "template for IBSS\n", dev
->name
);
2365 if (local
->ops
->beacon_update
&&
2366 local
->ops
->beacon_update(local_to_hw(local
),
2367 skb
, &control
) == 0) {
2368 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2369 "template\n", dev
->name
);
2374 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2375 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2376 int bitrate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2377 for (j
= 0; j
< sband
->n_bitrates
; j
++)
2378 if (sband
->bitrates
[j
].bitrate
== bitrate
)
2381 ifsta
->supp_rates_bits
[local
->hw
.conf
.channel
->band
] = rates
;
2383 ieee80211_sta_def_wmm_params(dev
, bss
, 1);
2387 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2388 "template\n", dev
->name
);
2392 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2393 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2395 ieee80211_rx_bss_put(dev
, bss
);
2400 u64
ieee80211_sta_get_rates(struct ieee80211_local
*local
,
2401 struct ieee802_11_elems
*elems
,
2402 enum ieee80211_band band
)
2404 struct ieee80211_supported_band
*sband
;
2405 struct ieee80211_rate
*bitrates
;
2409 sband
= local
->hw
.wiphy
->bands
[band
];
2413 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
2416 bitrates
= sband
->bitrates
;
2417 num_rates
= sband
->n_bitrates
;
2419 for (i
= 0; i
< elems
->supp_rates_len
+
2420 elems
->ext_supp_rates_len
; i
++) {
2423 if (i
< elems
->supp_rates_len
)
2424 rate
= elems
->supp_rates
[i
];
2425 else if (elems
->ext_supp_rates
)
2426 rate
= elems
->ext_supp_rates
2427 [i
- elems
->supp_rates_len
];
2428 own_rate
= 5 * (rate
& 0x7f);
2429 for (j
= 0; j
< num_rates
; j
++)
2430 if (bitrates
[j
].bitrate
== own_rate
)
2431 supp_rates
|= BIT(j
);
2437 static void ieee80211_rx_bss_info(struct net_device
*dev
,
2438 struct ieee80211_mgmt
*mgmt
,
2440 struct ieee80211_rx_status
*rx_status
,
2443 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2444 struct ieee802_11_elems elems
;
2447 struct ieee80211_sta_bss
*bss
;
2448 struct sta_info
*sta
;
2449 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2450 u64 beacon_timestamp
, rx_timestamp
;
2451 struct ieee80211_channel
*channel
;
2452 DECLARE_MAC_BUF(mac
);
2453 DECLARE_MAC_BUF(mac2
);
2455 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
2456 return; /* ignore ProbeResp to foreign address */
2459 printk(KERN_DEBUG
"%s: RX %s from %s to %s\n",
2460 dev
->name
, beacon
? "Beacon" : "Probe Response",
2461 print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
));
2464 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2468 beacon_timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
2469 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2471 if (ieee80211_vif_is_mesh(&sdata
->vif
) && elems
.mesh_id
&&
2472 elems
.mesh_config
&& mesh_matches_local(&elems
, dev
)) {
2473 u64 rates
= ieee80211_sta_get_rates(local
, &elems
,
2476 mesh_neighbour_update(mgmt
->sa
, rates
, dev
,
2477 mesh_peer_accepts_plinks(&elems
, dev
));
2482 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& elems
.supp_rates
&&
2483 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0 &&
2484 (sta
= sta_info_get(local
, mgmt
->sa
))) {
2486 u64 supp_rates
= ieee80211_sta_get_rates(local
, &elems
,
2489 prev_rates
= sta
->supp_rates
[rx_status
->band
];
2490 sta
->supp_rates
[rx_status
->band
] &= supp_rates
;
2491 if (sta
->supp_rates
[rx_status
->band
] == 0) {
2492 /* No matching rates - this should not really happen.
2493 * Make sure that at least one rate is marked
2494 * supported to avoid issues with TX rate ctrl. */
2495 sta
->supp_rates
[rx_status
->band
] =
2496 sdata
->u
.sta
.supp_rates_bits
[rx_status
->band
];
2498 if (sta
->supp_rates
[rx_status
->band
] != prev_rates
) {
2499 printk(KERN_DEBUG
"%s: updated supp_rates set for "
2500 "%s based on beacon info (0x%llx & 0x%llx -> "
2502 dev
->name
, print_mac(mac
, sta
->addr
),
2503 (unsigned long long) prev_rates
,
2504 (unsigned long long) supp_rates
,
2505 (unsigned long long) sta
->supp_rates
[rx_status
->band
]);
2511 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
2512 freq
= ieee80211_channel_to_frequency(elems
.ds_params
[0]);
2514 freq
= rx_status
->freq
;
2516 channel
= ieee80211_get_channel(local
->hw
.wiphy
, freq
);
2518 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
2521 #ifdef CONFIG_MAC80211_MESH
2522 if (elems
.mesh_config
)
2523 bss
= ieee80211_rx_mesh_bss_get(dev
, elems
.mesh_id
,
2524 elems
.mesh_id_len
, elems
.mesh_config
, freq
);
2527 bss
= ieee80211_rx_bss_get(dev
, mgmt
->bssid
, freq
,
2528 elems
.ssid
, elems
.ssid_len
);
2530 #ifdef CONFIG_MAC80211_MESH
2531 if (elems
.mesh_config
)
2532 bss
= ieee80211_rx_mesh_bss_add(dev
, elems
.mesh_id
,
2533 elems
.mesh_id_len
, elems
.mesh_config
,
2534 elems
.mesh_config_len
, freq
);
2537 bss
= ieee80211_rx_bss_add(dev
, mgmt
->bssid
, freq
,
2538 elems
.ssid
, elems
.ssid_len
);
2543 /* TODO: order by RSSI? */
2544 spin_lock_bh(&local
->sta_bss_lock
);
2545 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
2546 spin_unlock_bh(&local
->sta_bss_lock
);
2550 bss
->band
= rx_status
->band
;
2552 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
2553 bss
->probe_resp
&& beacon
) {
2555 * Do not allow beacon to override data from Probe Response. */
2556 ieee80211_rx_bss_put(dev
, bss
);
2560 /* save the ERP value so that it is available at association time */
2561 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
2562 bss
->erp_value
= elems
.erp_info
[0];
2563 bss
->has_erp_value
= 1;
2566 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
2567 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
2569 bss
->supp_rates_len
= 0;
2570 if (elems
.supp_rates
) {
2571 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2572 if (clen
> elems
.supp_rates_len
)
2573 clen
= elems
.supp_rates_len
;
2574 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
.supp_rates
,
2576 bss
->supp_rates_len
+= clen
;
2578 if (elems
.ext_supp_rates
) {
2579 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
2580 if (clen
> elems
.ext_supp_rates_len
)
2581 clen
= elems
.ext_supp_rates_len
;
2582 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
2583 elems
.ext_supp_rates
, clen
);
2584 bss
->supp_rates_len
+= clen
;
2588 (!bss
->wpa_ie
|| bss
->wpa_ie_len
!= elems
.wpa_len
||
2589 memcmp(bss
->wpa_ie
, elems
.wpa
, elems
.wpa_len
))) {
2591 bss
->wpa_ie
= kmalloc(elems
.wpa_len
+ 2, GFP_ATOMIC
);
2593 memcpy(bss
->wpa_ie
, elems
.wpa
- 2, elems
.wpa_len
+ 2);
2594 bss
->wpa_ie_len
= elems
.wpa_len
+ 2;
2596 bss
->wpa_ie_len
= 0;
2597 } else if (!elems
.wpa
&& bss
->wpa_ie
) {
2600 bss
->wpa_ie_len
= 0;
2604 (!bss
->rsn_ie
|| bss
->rsn_ie_len
!= elems
.rsn_len
||
2605 memcmp(bss
->rsn_ie
, elems
.rsn
, elems
.rsn_len
))) {
2607 bss
->rsn_ie
= kmalloc(elems
.rsn_len
+ 2, GFP_ATOMIC
);
2609 memcpy(bss
->rsn_ie
, elems
.rsn
- 2, elems
.rsn_len
+ 2);
2610 bss
->rsn_ie_len
= elems
.rsn_len
+ 2;
2612 bss
->rsn_ie_len
= 0;
2613 } else if (!elems
.rsn
&& bss
->rsn_ie
) {
2616 bss
->rsn_ie_len
= 0;
2619 if (elems
.wmm_param
&&
2620 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_param_len
||
2621 memcmp(bss
->wmm_ie
, elems
.wmm_param
, elems
.wmm_param_len
))) {
2623 bss
->wmm_ie
= kmalloc(elems
.wmm_param_len
+ 2, GFP_ATOMIC
);
2625 memcpy(bss
->wmm_ie
, elems
.wmm_param
- 2,
2626 elems
.wmm_param_len
+ 2);
2627 bss
->wmm_ie_len
= elems
.wmm_param_len
+ 2;
2629 bss
->wmm_ie_len
= 0;
2630 } else if (!elems
.wmm_param
&& bss
->wmm_ie
) {
2633 bss
->wmm_ie_len
= 0;
2635 if (elems
.ht_cap_elem
&&
2636 (!bss
->ht_ie
|| bss
->ht_ie_len
!= elems
.ht_cap_elem_len
||
2637 memcmp(bss
->ht_ie
, elems
.ht_cap_elem
, elems
.ht_cap_elem_len
))) {
2639 bss
->ht_ie
= kmalloc(elems
.ht_cap_elem_len
+ 2, GFP_ATOMIC
);
2641 memcpy(bss
->ht_ie
, elems
.ht_cap_elem
- 2,
2642 elems
.ht_cap_elem_len
+ 2);
2643 bss
->ht_ie_len
= elems
.ht_cap_elem_len
+ 2;
2646 } else if (!elems
.ht_cap_elem
&& bss
->ht_ie
) {
2652 bss
->timestamp
= beacon_timestamp
;
2653 bss
->last_update
= jiffies
;
2654 bss
->rssi
= rx_status
->ssi
;
2655 bss
->signal
= rx_status
->signal
;
2656 bss
->noise
= rx_status
->noise
;
2660 /* check if we need to merge IBSS */
2661 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
2662 !local
->sta_sw_scanning
&& !local
->sta_hw_scanning
&&
2663 bss
->capability
& WLAN_CAPABILITY_IBSS
&&
2664 bss
->freq
== local
->oper_channel
->center_freq
&&
2665 elems
.ssid_len
== sdata
->u
.sta
.ssid_len
&&
2666 memcmp(elems
.ssid
, sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
) == 0) {
2667 if (rx_status
->flag
& RX_FLAG_TSFT
) {
2668 /* in order for correct IBSS merging we need mactime
2670 * since mactime is defined as the time the first data
2671 * symbol of the frame hits the PHY, and the timestamp
2672 * of the beacon is defined as "the time that the data
2673 * symbol containing the first bit of the timestamp is
2674 * transmitted to the PHY plus the transmitting STA’s
2675 * delays through its local PHY from the MAC-PHY
2676 * interface to its interface with the WM"
2677 * (802.11 11.1.2) - equals the time this bit arrives at
2678 * the receiver - we have to take into account the
2679 * offset between the two.
2680 * e.g: at 1 MBit that means mactime is 192 usec earlier
2681 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2683 int rate
= local
->hw
.wiphy
->bands
[rx_status
->band
]->
2684 bitrates
[rx_status
->rate_idx
].bitrate
;
2685 rx_timestamp
= rx_status
->mactime
+ (24 * 8 * 10 / rate
);
2686 } else if (local
&& local
->ops
&& local
->ops
->get_tsf
)
2687 /* second best option: get current TSF */
2688 rx_timestamp
= local
->ops
->get_tsf(local_to_hw(local
));
2690 /* can't merge without knowing the TSF */
2691 rx_timestamp
= -1LLU;
2692 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2693 printk(KERN_DEBUG
"RX beacon SA=%s BSSID="
2694 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2695 print_mac(mac
, mgmt
->sa
),
2696 print_mac(mac2
, mgmt
->bssid
),
2697 (unsigned long long)rx_timestamp
,
2698 (unsigned long long)beacon_timestamp
,
2699 (unsigned long long)(rx_timestamp
- beacon_timestamp
),
2701 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2702 if (beacon_timestamp
> rx_timestamp
) {
2703 #ifndef CONFIG_MAC80211_IBSS_DEBUG
2704 if (net_ratelimit())
2706 printk(KERN_DEBUG
"%s: beacon TSF higher than "
2707 "local TSF - IBSS merge with BSSID %s\n",
2708 dev
->name
, print_mac(mac
, mgmt
->bssid
));
2709 ieee80211_sta_join_ibss(dev
, &sdata
->u
.sta
, bss
);
2710 ieee80211_ibss_add_sta(dev
, NULL
,
2711 mgmt
->bssid
, mgmt
->sa
);
2715 ieee80211_rx_bss_put(dev
, bss
);
2719 static void ieee80211_rx_mgmt_probe_resp(struct net_device
*dev
,
2720 struct ieee80211_mgmt
*mgmt
,
2722 struct ieee80211_rx_status
*rx_status
)
2724 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 0);
2728 static void ieee80211_rx_mgmt_beacon(struct net_device
*dev
,
2729 struct ieee80211_mgmt
*mgmt
,
2731 struct ieee80211_rx_status
*rx_status
)
2733 struct ieee80211_sub_if_data
*sdata
;
2734 struct ieee80211_if_sta
*ifsta
;
2736 struct ieee802_11_elems elems
;
2737 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2738 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
2741 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 1);
2743 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2744 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
2746 ifsta
= &sdata
->u
.sta
;
2748 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
) ||
2749 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
2752 /* Process beacon from the current BSS */
2753 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2757 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
2759 if (elems
.erp_info
&& elems
.erp_info_len
>= 1)
2760 changed
|= ieee80211_handle_erp_ie(sdata
, elems
.erp_info
[0]);
2762 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&&
2763 elems
.wmm_param
&& local
->ops
->conf_ht
&&
2764 conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) {
2765 struct ieee80211_ht_bss_info bss_info
;
2767 ieee80211_ht_addt_info_ie_to_ht_bss_info(
2768 (struct ieee80211_ht_addt_info
*)
2769 elems
.ht_info_elem
, &bss_info
);
2770 /* check if AP changed bss inforamation */
2771 if ((conf
->ht_bss_conf
.primary_channel
!=
2772 bss_info
.primary_channel
) ||
2773 (conf
->ht_bss_conf
.bss_cap
!= bss_info
.bss_cap
) ||
2774 (conf
->ht_bss_conf
.bss_op_mode
!= bss_info
.bss_op_mode
))
2775 ieee80211_hw_config_ht(local
, 1, &conf
->ht_conf
,
2779 if (elems
.wmm_param
&& (ifsta
->flags
& IEEE80211_STA_WMM_ENABLED
)) {
2780 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
2781 elems
.wmm_param_len
);
2784 ieee80211_bss_info_change_notify(sdata
, changed
);
2788 static void ieee80211_rx_mgmt_probe_req(struct net_device
*dev
,
2789 struct ieee80211_if_sta
*ifsta
,
2790 struct ieee80211_mgmt
*mgmt
,
2792 struct ieee80211_rx_status
*rx_status
)
2794 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2795 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2797 struct sk_buff
*skb
;
2798 struct ieee80211_mgmt
*resp
;
2800 DECLARE_MAC_BUF(mac
);
2801 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2802 DECLARE_MAC_BUF(mac2
);
2803 DECLARE_MAC_BUF(mac3
);
2806 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
||
2807 ifsta
->state
!= IEEE80211_IBSS_JOINED
||
2808 len
< 24 + 2 || !ifsta
->probe_resp
)
2811 if (local
->ops
->tx_last_beacon
)
2812 tx_last_beacon
= local
->ops
->tx_last_beacon(local_to_hw(local
));
2816 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2817 printk(KERN_DEBUG
"%s: RX ProbeReq SA=%s DA=%s BSSID="
2818 "%s (tx_last_beacon=%d)\n",
2819 dev
->name
, print_mac(mac
, mgmt
->sa
), print_mac(mac2
, mgmt
->da
),
2820 print_mac(mac3
, mgmt
->bssid
), tx_last_beacon
);
2821 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2823 if (!tx_last_beacon
)
2826 if (memcmp(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
) != 0 &&
2827 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
2830 end
= ((u8
*) mgmt
) + len
;
2831 pos
= mgmt
->u
.probe_req
.variable
;
2832 if (pos
[0] != WLAN_EID_SSID
||
2833 pos
+ 2 + pos
[1] > end
) {
2834 if (net_ratelimit()) {
2835 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
2837 dev
->name
, print_mac(mac
, mgmt
->sa
));
2842 (pos
[1] != ifsta
->ssid_len
||
2843 memcmp(pos
+ 2, ifsta
->ssid
, ifsta
->ssid_len
) != 0)) {
2844 /* Ignore ProbeReq for foreign SSID */
2848 /* Reply with ProbeResp */
2849 skb
= skb_copy(ifsta
->probe_resp
, GFP_KERNEL
);
2853 resp
= (struct ieee80211_mgmt
*) skb
->data
;
2854 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
2855 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2856 printk(KERN_DEBUG
"%s: Sending ProbeResp to %s\n",
2857 dev
->name
, print_mac(mac
, resp
->da
));
2858 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2859 ieee80211_sta_tx(dev
, skb
, 0);
2862 static void ieee80211_rx_mgmt_action(struct net_device
*dev
,
2863 struct ieee80211_if_sta
*ifsta
,
2864 struct ieee80211_mgmt
*mgmt
,
2866 struct ieee80211_rx_status
*rx_status
)
2868 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2870 if (len
< IEEE80211_MIN_ACTION_SIZE
)
2873 switch (mgmt
->u
.action
.category
) {
2874 case WLAN_CATEGORY_BACK
:
2875 switch (mgmt
->u
.action
.u
.addba_req
.action_code
) {
2876 case WLAN_ACTION_ADDBA_REQ
:
2877 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2878 sizeof(mgmt
->u
.action
.u
.addba_req
)))
2880 ieee80211_sta_process_addba_request(dev
, mgmt
, len
);
2882 case WLAN_ACTION_ADDBA_RESP
:
2883 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2884 sizeof(mgmt
->u
.action
.u
.addba_resp
)))
2886 ieee80211_sta_process_addba_resp(dev
, mgmt
, len
);
2888 case WLAN_ACTION_DELBA
:
2889 if (len
< (IEEE80211_MIN_ACTION_SIZE
+
2890 sizeof(mgmt
->u
.action
.u
.delba
)))
2892 ieee80211_sta_process_delba(dev
, mgmt
, len
);
2895 if (net_ratelimit())
2896 printk(KERN_DEBUG
"%s: Rx unknown A-MPDU action\n",
2901 case PLINK_CATEGORY
:
2902 if (ieee80211_vif_is_mesh(&sdata
->vif
))
2903 mesh_rx_plink_frame(dev
, mgmt
, len
, rx_status
);
2905 case MESH_PATH_SEL_CATEGORY
:
2906 if (ieee80211_vif_is_mesh(&sdata
->vif
))
2907 mesh_rx_path_sel_frame(dev
, mgmt
, len
);
2910 if (net_ratelimit())
2911 printk(KERN_DEBUG
"%s: Rx unknown action frame - "
2912 "category=%d\n", dev
->name
, mgmt
->u
.action
.category
);
2917 void ieee80211_sta_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
2918 struct ieee80211_rx_status
*rx_status
)
2920 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2921 struct ieee80211_sub_if_data
*sdata
;
2922 struct ieee80211_if_sta
*ifsta
;
2923 struct ieee80211_mgmt
*mgmt
;
2929 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2930 ifsta
= &sdata
->u
.sta
;
2932 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2933 fc
= le16_to_cpu(mgmt
->frame_control
);
2935 switch (fc
& IEEE80211_FCTL_STYPE
) {
2936 case IEEE80211_STYPE_PROBE_REQ
:
2937 case IEEE80211_STYPE_PROBE_RESP
:
2938 case IEEE80211_STYPE_BEACON
:
2939 case IEEE80211_STYPE_ACTION
:
2940 memcpy(skb
->cb
, rx_status
, sizeof(*rx_status
));
2941 case IEEE80211_STYPE_AUTH
:
2942 case IEEE80211_STYPE_ASSOC_RESP
:
2943 case IEEE80211_STYPE_REASSOC_RESP
:
2944 case IEEE80211_STYPE_DEAUTH
:
2945 case IEEE80211_STYPE_DISASSOC
:
2946 skb_queue_tail(&ifsta
->skb_queue
, skb
);
2947 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2950 printk(KERN_DEBUG
"%s: received unknown management frame - "
2951 "stype=%d\n", dev
->name
,
2952 (fc
& IEEE80211_FCTL_STYPE
) >> 4);
2961 static void ieee80211_sta_rx_queued_mgmt(struct net_device
*dev
,
2962 struct sk_buff
*skb
)
2964 struct ieee80211_rx_status
*rx_status
;
2965 struct ieee80211_sub_if_data
*sdata
;
2966 struct ieee80211_if_sta
*ifsta
;
2967 struct ieee80211_mgmt
*mgmt
;
2970 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2971 ifsta
= &sdata
->u
.sta
;
2973 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
2974 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
2975 fc
= le16_to_cpu(mgmt
->frame_control
);
2977 switch (fc
& IEEE80211_FCTL_STYPE
) {
2978 case IEEE80211_STYPE_PROBE_REQ
:
2979 ieee80211_rx_mgmt_probe_req(dev
, ifsta
, mgmt
, skb
->len
,
2982 case IEEE80211_STYPE_PROBE_RESP
:
2983 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
, skb
->len
, rx_status
);
2985 case IEEE80211_STYPE_BEACON
:
2986 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
, rx_status
);
2988 case IEEE80211_STYPE_AUTH
:
2989 ieee80211_rx_mgmt_auth(dev
, ifsta
, mgmt
, skb
->len
);
2991 case IEEE80211_STYPE_ASSOC_RESP
:
2992 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 0);
2994 case IEEE80211_STYPE_REASSOC_RESP
:
2995 ieee80211_rx_mgmt_assoc_resp(sdata
, ifsta
, mgmt
, skb
->len
, 1);
2997 case IEEE80211_STYPE_DEAUTH
:
2998 ieee80211_rx_mgmt_deauth(dev
, ifsta
, mgmt
, skb
->len
);
3000 case IEEE80211_STYPE_DISASSOC
:
3001 ieee80211_rx_mgmt_disassoc(dev
, ifsta
, mgmt
, skb
->len
);
3003 case IEEE80211_STYPE_ACTION
:
3004 ieee80211_rx_mgmt_action(dev
, ifsta
, mgmt
, skb
->len
, rx_status
);
3013 ieee80211_sta_rx_scan(struct net_device
*dev
, struct sk_buff
*skb
,
3014 struct ieee80211_rx_status
*rx_status
)
3016 struct ieee80211_mgmt
*mgmt
;
3020 return RX_DROP_UNUSABLE
;
3022 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3023 fc
= le16_to_cpu(mgmt
->frame_control
);
3025 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_CTL
)
3029 return RX_DROP_MONITOR
;
3031 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
3032 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
) {
3033 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
,
3034 skb
->len
, rx_status
);
3037 } else if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
) {
3038 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
,
3048 static int ieee80211_sta_active_ibss(struct net_device
*dev
)
3050 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3052 struct sta_info
*sta
;
3053 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3057 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
3058 if (sta
->sdata
== sdata
&&
3059 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
3072 static void ieee80211_sta_expire(struct net_device
*dev
, unsigned long exp_time
)
3074 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3075 struct sta_info
*sta
, *tmp
;
3076 LIST_HEAD(tmp_list
);
3077 DECLARE_MAC_BUF(mac
);
3078 unsigned long flags
;
3080 spin_lock_irqsave(&local
->sta_lock
, flags
);
3081 list_for_each_entry_safe(sta
, tmp
, &local
->sta_list
, list
)
3082 if (time_after(jiffies
, sta
->last_rx
+ exp_time
)) {
3083 printk(KERN_DEBUG
"%s: expiring inactive STA %s\n",
3084 dev
->name
, print_mac(mac
, sta
->addr
));
3085 __sta_info_unlink(&sta
);
3087 list_add(&sta
->list
, &tmp_list
);
3089 spin_unlock_irqrestore(&local
->sta_lock
, flags
);
3094 list_for_each_entry_safe(sta
, tmp
, &tmp_list
, list
)
3095 sta_info_destroy(sta
);
3100 static void ieee80211_sta_merge_ibss(struct net_device
*dev
,
3101 struct ieee80211_if_sta
*ifsta
)
3103 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
3105 ieee80211_sta_expire(dev
, IEEE80211_IBSS_INACTIVITY_LIMIT
);
3106 if (ieee80211_sta_active_ibss(dev
))
3109 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
3110 "IBSS networks with same SSID (merge)\n", dev
->name
);
3111 ieee80211_sta_req_scan(dev
, ifsta
->ssid
, ifsta
->ssid_len
);
3115 #ifdef CONFIG_MAC80211_MESH
3116 static void ieee80211_mesh_housekeeping(struct net_device
*dev
,
3117 struct ieee80211_if_sta
*ifsta
)
3119 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3122 ieee80211_sta_expire(dev
, IEEE80211_MESH_PEER_INACTIVITY_LIMIT
);
3123 mesh_path_expire(dev
);
3125 free_plinks
= mesh_plink_availables(sdata
);
3126 if (free_plinks
!= sdata
->u
.sta
.accepting_plinks
)
3127 ieee80211_if_config_beacon(dev
);
3129 mod_timer(&ifsta
->timer
, jiffies
+
3130 IEEE80211_MESH_HOUSEKEEPING_INTERVAL
);
3134 void ieee80211_start_mesh(struct net_device
*dev
)
3136 struct ieee80211_if_sta
*ifsta
;
3137 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3138 ifsta
= &sdata
->u
.sta
;
3139 ifsta
->state
= IEEE80211_MESH_UP
;
3140 ieee80211_sta_timer((unsigned long)sdata
);
3145 void ieee80211_sta_timer(unsigned long data
)
3147 struct ieee80211_sub_if_data
*sdata
=
3148 (struct ieee80211_sub_if_data
*) data
;
3149 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3150 struct ieee80211_local
*local
= wdev_priv(&sdata
->wdev
);
3152 set_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3153 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3156 void ieee80211_sta_work(struct work_struct
*work
)
3158 struct ieee80211_sub_if_data
*sdata
=
3159 container_of(work
, struct ieee80211_sub_if_data
, u
.sta
.work
);
3160 struct net_device
*dev
= sdata
->dev
;
3161 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3162 struct ieee80211_if_sta
*ifsta
;
3163 struct sk_buff
*skb
;
3165 if (!netif_running(dev
))
3168 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
3171 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
3172 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
3173 sdata
->vif
.type
!= IEEE80211_IF_TYPE_MESH_POINT
) {
3174 printk(KERN_DEBUG
"%s: ieee80211_sta_work: non-STA interface "
3175 "(type=%d)\n", dev
->name
, sdata
->vif
.type
);
3178 ifsta
= &sdata
->u
.sta
;
3180 while ((skb
= skb_dequeue(&ifsta
->skb_queue
)))
3181 ieee80211_sta_rx_queued_mgmt(dev
, skb
);
3183 #ifdef CONFIG_MAC80211_MESH
3184 if (ifsta
->preq_queue_len
&&
3186 ifsta
->last_preq
+ msecs_to_jiffies(ifsta
->mshcfg
.dot11MeshHWMPpreqMinInterval
)))
3187 mesh_path_start_discovery(dev
);
3190 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
3191 ifsta
->state
!= IEEE80211_ASSOCIATE
&&
3192 test_and_clear_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
)) {
3193 if (ifsta
->scan_ssid_len
)
3194 ieee80211_sta_start_scan(dev
, ifsta
->scan_ssid
, ifsta
->scan_ssid_len
);
3196 ieee80211_sta_start_scan(dev
, NULL
, 0);
3200 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
)) {
3201 if (ieee80211_sta_config_auth(dev
, ifsta
))
3203 clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
3204 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
))
3207 switch (ifsta
->state
) {
3208 case IEEE80211_DISABLED
:
3210 case IEEE80211_AUTHENTICATE
:
3211 ieee80211_authenticate(dev
, ifsta
);
3213 case IEEE80211_ASSOCIATE
:
3214 ieee80211_associate(dev
, ifsta
);
3216 case IEEE80211_ASSOCIATED
:
3217 ieee80211_associated(dev
, ifsta
);
3219 case IEEE80211_IBSS_SEARCH
:
3220 ieee80211_sta_find_ibss(dev
, ifsta
);
3222 case IEEE80211_IBSS_JOINED
:
3223 ieee80211_sta_merge_ibss(dev
, ifsta
);
3225 #ifdef CONFIG_MAC80211_MESH
3226 case IEEE80211_MESH_UP
:
3227 ieee80211_mesh_housekeeping(dev
, ifsta
);
3231 printk(KERN_DEBUG
"ieee80211_sta_work: Unknown state %d\n",
3236 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
3237 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
3238 "mixed-cell disabled - disassociate\n", dev
->name
);
3240 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
3241 ieee80211_set_disassoc(dev
, ifsta
, 0);
3246 static void ieee80211_sta_reset_auth(struct net_device
*dev
,
3247 struct ieee80211_if_sta
*ifsta
)
3249 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3251 if (local
->ops
->reset_tsf
) {
3252 /* Reset own TSF to allow time synchronization work. */
3253 local
->ops
->reset_tsf(local_to_hw(local
));
3256 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
3259 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
3260 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3261 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
3262 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
3263 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
3264 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
3266 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
3267 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
3269 ifsta
->auth_transaction
= -1;
3270 ifsta
->flags
&= ~IEEE80211_STA_ASSOCIATED
;
3271 ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
3272 netif_carrier_off(dev
);
3276 void ieee80211_sta_req_auth(struct net_device
*dev
,
3277 struct ieee80211_if_sta
*ifsta
)
3279 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3280 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3282 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3285 if ((ifsta
->flags
& (IEEE80211_STA_BSSID_SET
|
3286 IEEE80211_STA_AUTO_BSSID_SEL
)) &&
3287 (ifsta
->flags
& (IEEE80211_STA_SSID_SET
|
3288 IEEE80211_STA_AUTO_SSID_SEL
))) {
3289 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3290 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3294 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta
*ifsta
,
3295 const char *ssid
, int ssid_len
)
3297 int tmp
, hidden_ssid
;
3299 if (ssid_len
== ifsta
->ssid_len
&&
3300 !memcmp(ifsta
->ssid
, ssid
, ssid_len
))
3303 if (ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
)
3309 if (ssid
[tmp
] != '\0') {
3315 if (hidden_ssid
&& ifsta
->ssid_len
== ssid_len
)
3318 if (ssid_len
== 1 && ssid
[0] == ' ')
3324 static int ieee80211_sta_config_auth(struct net_device
*dev
,
3325 struct ieee80211_if_sta
*ifsta
)
3327 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3328 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3329 struct ieee80211_sta_bss
*bss
, *selected
= NULL
;
3330 int top_rssi
= 0, freq
;
3332 if (!(ifsta
->flags
& (IEEE80211_STA_AUTO_SSID_SEL
|
3333 IEEE80211_STA_AUTO_BSSID_SEL
| IEEE80211_STA_AUTO_CHANNEL_SEL
))) {
3334 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3335 ieee80211_sta_reset_auth(dev
, ifsta
);
3339 spin_lock_bh(&local
->sta_bss_lock
);
3340 freq
= local
->oper_channel
->center_freq
;
3341 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3342 if (!(bss
->capability
& WLAN_CAPABILITY_ESS
))
3345 if (!!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
) ^
3346 !!sdata
->default_key
)
3349 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_CHANNEL_SEL
) &&
3353 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_BSSID_SEL
) &&
3354 memcmp(bss
->bssid
, ifsta
->bssid
, ETH_ALEN
))
3357 if (!(ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
) &&
3358 !ieee80211_sta_match_ssid(ifsta
, bss
->ssid
, bss
->ssid_len
))
3361 if (!selected
|| top_rssi
< bss
->rssi
) {
3363 top_rssi
= bss
->rssi
;
3367 atomic_inc(&selected
->users
);
3368 spin_unlock_bh(&local
->sta_bss_lock
);
3371 ieee80211_set_freq(local
, selected
->freq
);
3372 if (!(ifsta
->flags
& IEEE80211_STA_SSID_SET
))
3373 ieee80211_sta_set_ssid(dev
, selected
->ssid
,
3374 selected
->ssid_len
);
3375 ieee80211_sta_set_bssid(dev
, selected
->bssid
);
3376 ieee80211_sta_def_wmm_params(dev
, selected
, 0);
3377 ieee80211_rx_bss_put(dev
, selected
);
3378 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3379 ieee80211_sta_reset_auth(dev
, ifsta
);
3382 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
) {
3383 if (ifsta
->flags
& IEEE80211_STA_AUTO_SSID_SEL
)
3384 ieee80211_sta_start_scan(dev
, NULL
, 0);
3386 ieee80211_sta_start_scan(dev
, ifsta
->ssid
,
3388 ifsta
->state
= IEEE80211_AUTHENTICATE
;
3389 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
3391 ifsta
->state
= IEEE80211_DISABLED
;
3397 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
3398 struct ieee80211_if_sta
*ifsta
)
3400 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3401 struct ieee80211_sta_bss
*bss
;
3402 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3403 struct ieee80211_supported_band
*sband
;
3404 u8 bssid
[ETH_ALEN
], *pos
;
3406 DECLARE_MAC_BUF(mac
);
3409 /* Easier testing, use fixed BSSID. */
3410 memset(bssid
, 0xfe, ETH_ALEN
);
3412 /* Generate random, not broadcast, locally administered BSSID. Mix in
3413 * own MAC address to make sure that devices that do not have proper
3414 * random number generator get different BSSID. */
3415 get_random_bytes(bssid
, ETH_ALEN
);
3416 for (i
= 0; i
< ETH_ALEN
; i
++)
3417 bssid
[i
] ^= dev
->dev_addr
[i
];
3422 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID %s\n",
3423 dev
->name
, print_mac(mac
, bssid
));
3425 bss
= ieee80211_rx_bss_add(dev
, bssid
,
3426 local
->hw
.conf
.channel
->center_freq
,
3427 sdata
->u
.sta
.ssid
, sdata
->u
.sta
.ssid_len
);
3431 bss
->band
= local
->hw
.conf
.channel
->band
;
3432 sband
= local
->hw
.wiphy
->bands
[bss
->band
];
3434 if (local
->hw
.conf
.beacon_int
== 0)
3435 local
->hw
.conf
.beacon_int
= 10000;
3436 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
3437 bss
->last_update
= jiffies
;
3438 bss
->capability
= WLAN_CAPABILITY_IBSS
;
3439 if (sdata
->default_key
) {
3440 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
3442 sdata
->drop_unencrypted
= 0;
3443 bss
->supp_rates_len
= sband
->n_bitrates
;
3444 pos
= bss
->supp_rates
;
3445 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
3446 int rate
= sband
->bitrates
[i
].bitrate
;
3447 *pos
++ = (u8
) (rate
/ 5);
3450 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3454 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
3455 struct ieee80211_if_sta
*ifsta
)
3457 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3458 struct ieee80211_sta_bss
*bss
;
3462 DECLARE_MAC_BUF(mac
);
3463 DECLARE_MAC_BUF(mac2
);
3465 if (ifsta
->ssid_len
== 0)
3468 active_ibss
= ieee80211_sta_active_ibss(dev
);
3469 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3470 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
3471 dev
->name
, active_ibss
);
3472 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3473 spin_lock_bh(&local
->sta_bss_lock
);
3474 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3475 if (ifsta
->ssid_len
!= bss
->ssid_len
||
3476 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
3477 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
3479 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3480 printk(KERN_DEBUG
" bssid=%s found\n",
3481 print_mac(mac
, bss
->bssid
));
3482 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3483 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
3485 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
3488 spin_unlock_bh(&local
->sta_bss_lock
);
3490 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3491 printk(KERN_DEBUG
" sta_find_ibss: selected %s current "
3492 "%s\n", print_mac(mac
, bssid
), print_mac(mac2
, ifsta
->bssid
));
3493 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3494 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
3495 (bss
= ieee80211_rx_bss_get(dev
, bssid
,
3496 local
->hw
.conf
.channel
->center_freq
,
3497 ifsta
->ssid
, ifsta
->ssid_len
))) {
3498 printk(KERN_DEBUG
"%s: Selected IBSS BSSID %s"
3499 " based on configured SSID\n",
3500 dev
->name
, print_mac(mac
, bssid
));
3501 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
3503 #ifdef CONFIG_MAC80211_IBSS_DEBUG
3504 printk(KERN_DEBUG
" did not try to join ibss\n");
3505 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
3507 /* Selected IBSS not found in current scan results - try to scan */
3508 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3509 !ieee80211_sta_active_ibss(dev
)) {
3510 mod_timer(&ifsta
->timer
, jiffies
+
3511 IEEE80211_IBSS_MERGE_INTERVAL
);
3512 } else if (time_after(jiffies
, local
->last_scan_completed
+
3513 IEEE80211_SCAN_INTERVAL
)) {
3514 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
3515 "join\n", dev
->name
);
3516 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
3518 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
3519 int interval
= IEEE80211_SCAN_INTERVAL
;
3521 if (time_after(jiffies
, ifsta
->ibss_join_req
+
3522 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
3523 if ((ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) &&
3524 (!(local
->oper_channel
->flags
&
3525 IEEE80211_CHAN_NO_IBSS
)))
3526 return ieee80211_sta_create_ibss(dev
, ifsta
);
3527 if (ifsta
->flags
& IEEE80211_STA_CREATE_IBSS
) {
3528 printk(KERN_DEBUG
"%s: IBSS not allowed on"
3529 " %d MHz\n", dev
->name
,
3530 local
->hw
.conf
.channel
->center_freq
);
3533 /* No IBSS found - decrease scan interval and continue
3535 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
3538 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3539 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
3547 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
3549 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3550 struct ieee80211_if_sta
*ifsta
;
3552 if (len
> IEEE80211_MAX_SSID_LEN
)
3555 ifsta
= &sdata
->u
.sta
;
3557 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
3558 ifsta
->flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
3559 memcpy(ifsta
->ssid
, ssid
, len
);
3560 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
3561 ifsta
->ssid_len
= len
;
3564 ifsta
->flags
|= IEEE80211_STA_SSID_SET
;
3566 ifsta
->flags
&= ~IEEE80211_STA_SSID_SET
;
3567 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3568 !(ifsta
->flags
& IEEE80211_STA_BSSID_SET
)) {
3569 ifsta
->ibss_join_req
= jiffies
;
3570 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
3571 return ieee80211_sta_find_ibss(dev
, ifsta
);
3577 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
3579 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3580 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3581 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
3582 *len
= ifsta
->ssid_len
;
3587 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
3589 struct ieee80211_sub_if_data
*sdata
;
3590 struct ieee80211_if_sta
*ifsta
;
3593 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3594 ifsta
= &sdata
->u
.sta
;
3596 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
3597 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
3598 res
= ieee80211_if_config(dev
);
3600 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
3601 "the low-level driver\n", dev
->name
);
3606 if (is_valid_ether_addr(bssid
))
3607 ifsta
->flags
|= IEEE80211_STA_BSSID_SET
;
3609 ifsta
->flags
&= ~IEEE80211_STA_BSSID_SET
;
3615 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
3616 struct ieee80211_sub_if_data
*sdata
,
3619 struct sk_buff
*skb
;
3620 struct ieee80211_hdr
*nullfunc
;
3623 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
3625 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
3626 "frame\n", sdata
->dev
->name
);
3629 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3631 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
3632 memset(nullfunc
, 0, 24);
3633 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
3634 IEEE80211_FCTL_TODS
;
3636 fc
|= IEEE80211_FCTL_PM
;
3637 nullfunc
->frame_control
= cpu_to_le16(fc
);
3638 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3639 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
3640 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
3642 ieee80211_sta_tx(sdata
->dev
, skb
, 0);
3646 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
3648 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
3649 ieee80211_vif_is_mesh(&sdata
->vif
))
3650 ieee80211_sta_timer((unsigned long)sdata
);
3653 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
3655 struct ieee80211_local
*local
= hw_to_local(hw
);
3656 struct net_device
*dev
= local
->scan_dev
;
3657 struct ieee80211_sub_if_data
*sdata
;
3658 union iwreq_data wrqu
;
3660 local
->last_scan_completed
= jiffies
;
3661 memset(&wrqu
, 0, sizeof(wrqu
));
3662 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
3664 if (local
->sta_hw_scanning
) {
3665 local
->sta_hw_scanning
= 0;
3666 if (ieee80211_hw_config(local
))
3667 printk(KERN_DEBUG
"%s: failed to restore operational "
3668 "channel after scan\n", dev
->name
);
3669 /* Restart STA timer for HW scan case */
3671 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
)
3672 ieee80211_restart_sta_timer(sdata
);
3678 local
->sta_sw_scanning
= 0;
3679 if (ieee80211_hw_config(local
))
3680 printk(KERN_DEBUG
"%s: failed to restore operational "
3681 "channel after scan\n", dev
->name
);
3684 netif_tx_lock_bh(local
->mdev
);
3685 local
->filter_flags
&= ~FIF_BCN_PRBRESP_PROMISC
;
3686 local
->ops
->configure_filter(local_to_hw(local
),
3687 FIF_BCN_PRBRESP_PROMISC
,
3688 &local
->filter_flags
,
3689 local
->mdev
->mc_count
,
3690 local
->mdev
->mc_list
);
3692 netif_tx_unlock_bh(local
->mdev
);
3695 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3697 /* No need to wake the master device. */
3698 if (sdata
->dev
== local
->mdev
)
3701 /* Tell AP we're back */
3702 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3703 sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
)
3704 ieee80211_send_nullfunc(local
, sdata
, 0);
3706 ieee80211_restart_sta_timer(sdata
);
3708 netif_wake_queue(sdata
->dev
);
3713 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3714 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
3715 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3716 if (!(ifsta
->flags
& IEEE80211_STA_BSSID_SET
) ||
3717 (!ifsta
->state
== IEEE80211_IBSS_JOINED
&&
3718 !ieee80211_sta_active_ibss(dev
)))
3719 ieee80211_sta_find_ibss(dev
, ifsta
);
3722 EXPORT_SYMBOL(ieee80211_scan_completed
);
3724 void ieee80211_sta_scan_work(struct work_struct
*work
)
3726 struct ieee80211_local
*local
=
3727 container_of(work
, struct ieee80211_local
, scan_work
.work
);
3728 struct net_device
*dev
= local
->scan_dev
;
3729 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3730 struct ieee80211_supported_band
*sband
;
3731 struct ieee80211_channel
*chan
;
3733 unsigned long next_delay
= 0;
3735 if (!local
->sta_sw_scanning
)
3738 switch (local
->scan_state
) {
3739 case SCAN_SET_CHANNEL
:
3741 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3742 * after we successfully scanned the last channel of the last
3743 * band (and the last band is supported by the hw)
3745 if (local
->scan_band
< IEEE80211_NUM_BANDS
)
3746 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3751 * If we are at an unsupported band and have more bands
3752 * left to scan, advance to the next supported one.
3754 while (!sband
&& local
->scan_band
< IEEE80211_NUM_BANDS
- 1) {
3756 sband
= local
->hw
.wiphy
->bands
[local
->scan_band
];
3757 local
->scan_channel_idx
= 0;
3760 /* if no more bands/channels left, complete scan */
3761 if (!sband
|| local
->scan_channel_idx
>= sband
->n_channels
) {
3762 ieee80211_scan_completed(local_to_hw(local
));
3766 chan
= &sband
->channels
[local
->scan_channel_idx
];
3768 if (chan
->flags
& IEEE80211_CHAN_DISABLED
||
3769 (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
3770 chan
->flags
& IEEE80211_CHAN_NO_IBSS
))
3774 local
->scan_channel
= chan
;
3775 if (ieee80211_hw_config(local
)) {
3776 printk(KERN_DEBUG
"%s: failed to set freq to "
3777 "%d MHz for scan\n", dev
->name
,
3783 /* advance state machine to next channel/band */
3784 local
->scan_channel_idx
++;
3785 if (local
->scan_channel_idx
>= sband
->n_channels
) {
3787 * scan_band may end up == IEEE80211_NUM_BANDS, but
3788 * we'll catch that case above and complete the scan
3789 * if that is the case.
3792 local
->scan_channel_idx
= 0;
3798 next_delay
= IEEE80211_PROBE_DELAY
+
3799 usecs_to_jiffies(local
->hw
.channel_change_time
);
3800 local
->scan_state
= SCAN_SEND_PROBE
;
3802 case SCAN_SEND_PROBE
:
3803 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
3804 local
->scan_state
= SCAN_SET_CHANNEL
;
3806 if (local
->scan_channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
3808 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
3809 local
->scan_ssid_len
);
3810 next_delay
= IEEE80211_CHANNEL_TIME
;
3814 if (local
->sta_sw_scanning
)
3815 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3820 static int ieee80211_sta_start_scan(struct net_device
*dev
,
3821 u8
*ssid
, size_t ssid_len
)
3823 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3824 struct ieee80211_sub_if_data
*sdata
;
3826 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
3829 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
3830 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
3833 * ScanType: ACTIVE, PASSIVE
3834 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
3835 * a Probe frame during active scanning
3837 * MinChannelTime (>= ProbeDelay), in TU
3838 * MaxChannelTime: (>= MinChannelTime), in TU
3841 /* MLME-SCAN.confirm
3843 * ResultCode: SUCCESS, INVALID_PARAMETERS
3846 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3847 if (local
->scan_dev
== dev
)
3852 if (local
->ops
->hw_scan
) {
3853 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
3856 local
->sta_hw_scanning
= 1;
3857 local
->scan_dev
= dev
;
3862 local
->sta_sw_scanning
= 1;
3865 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3867 /* Don't stop the master interface, otherwise we can't transmit
3869 if (sdata
->dev
== local
->mdev
)
3872 netif_stop_queue(sdata
->dev
);
3873 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
&&
3874 (sdata
->u
.sta
.flags
& IEEE80211_STA_ASSOCIATED
))
3875 ieee80211_send_nullfunc(local
, sdata
, 1);
3880 local
->scan_ssid_len
= ssid_len
;
3881 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
3883 local
->scan_ssid_len
= 0;
3884 local
->scan_state
= SCAN_SET_CHANNEL
;
3885 local
->scan_channel_idx
= 0;
3886 local
->scan_band
= IEEE80211_BAND_2GHZ
;
3887 local
->scan_dev
= dev
;
3889 netif_tx_lock_bh(local
->mdev
);
3890 local
->filter_flags
|= FIF_BCN_PRBRESP_PROMISC
;
3891 local
->ops
->configure_filter(local_to_hw(local
),
3892 FIF_BCN_PRBRESP_PROMISC
,
3893 &local
->filter_flags
,
3894 local
->mdev
->mc_count
,
3895 local
->mdev
->mc_list
);
3896 netif_tx_unlock_bh(local
->mdev
);
3898 /* TODO: start scan as soon as all nullfunc frames are ACKed */
3899 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
3900 IEEE80211_CHANNEL_TIME
);
3906 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
3908 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3909 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3910 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3912 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
3913 return ieee80211_sta_start_scan(dev
, ssid
, ssid_len
);
3915 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
) {
3916 if (local
->scan_dev
== dev
)
3921 ifsta
->scan_ssid_len
= ssid_len
;
3923 memcpy(ifsta
->scan_ssid
, ssid
, ssid_len
);
3924 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
3925 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
3930 ieee80211_sta_scan_result(struct net_device
*dev
,
3931 struct ieee80211_sta_bss
*bss
,
3932 char *current_ev
, char *end_buf
)
3934 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3935 struct iw_event iwe
;
3937 if (time_after(jiffies
,
3938 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
3941 memset(&iwe
, 0, sizeof(iwe
));
3942 iwe
.cmd
= SIOCGIWAP
;
3943 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3944 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
3945 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3948 memset(&iwe
, 0, sizeof(iwe
));
3949 iwe
.cmd
= SIOCGIWESSID
;
3950 if (bss_mesh_cfg(bss
)) {
3951 iwe
.u
.data
.length
= bss_mesh_id_len(bss
);
3952 iwe
.u
.data
.flags
= 1;
3953 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3956 iwe
.u
.data
.length
= bss
->ssid_len
;
3957 iwe
.u
.data
.flags
= 1;
3958 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
3962 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)
3963 || bss_mesh_cfg(bss
)) {
3964 memset(&iwe
, 0, sizeof(iwe
));
3965 iwe
.cmd
= SIOCGIWMODE
;
3966 if (bss_mesh_cfg(bss
))
3967 iwe
.u
.mode
= IW_MODE_MESH
;
3968 else if (bss
->capability
& WLAN_CAPABILITY_ESS
)
3969 iwe
.u
.mode
= IW_MODE_MASTER
;
3971 iwe
.u
.mode
= IW_MODE_ADHOC
;
3972 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3976 memset(&iwe
, 0, sizeof(iwe
));
3977 iwe
.cmd
= SIOCGIWFREQ
;
3978 iwe
.u
.freq
.m
= bss
->freq
;
3980 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3983 memset(&iwe
, 0, sizeof(iwe
));
3984 iwe
.cmd
= SIOCGIWFREQ
;
3985 iwe
.u
.freq
.m
= ieee80211_frequency_to_channel(bss
->freq
);
3987 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3990 memset(&iwe
, 0, sizeof(iwe
));
3992 iwe
.u
.qual
.qual
= bss
->signal
;
3993 iwe
.u
.qual
.level
= bss
->rssi
;
3994 iwe
.u
.qual
.noise
= bss
->noise
;
3995 iwe
.u
.qual
.updated
= local
->wstats_flags
;
3996 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
3999 memset(&iwe
, 0, sizeof(iwe
));
4000 iwe
.cmd
= SIOCGIWENCODE
;
4001 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
4002 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
4004 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
4005 iwe
.u
.data
.length
= 0;
4006 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
4008 if (bss
&& bss
->wpa_ie
) {
4009 memset(&iwe
, 0, sizeof(iwe
));
4010 iwe
.cmd
= IWEVGENIE
;
4011 iwe
.u
.data
.length
= bss
->wpa_ie_len
;
4012 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4016 if (bss
&& bss
->rsn_ie
) {
4017 memset(&iwe
, 0, sizeof(iwe
));
4018 iwe
.cmd
= IWEVGENIE
;
4019 iwe
.u
.data
.length
= bss
->rsn_ie_len
;
4020 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
4024 if (bss
&& bss
->supp_rates_len
> 0) {
4025 /* display all supported rates in readable format */
4026 char *p
= current_ev
+ IW_EV_LCP_LEN
;
4029 memset(&iwe
, 0, sizeof(iwe
));
4030 iwe
.cmd
= SIOCGIWRATE
;
4031 /* Those two flags are ignored... */
4032 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
4034 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
4035 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
4037 p
= iwe_stream_add_value(current_ev
, p
,
4038 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
4045 buf
= kmalloc(30, GFP_ATOMIC
);
4047 memset(&iwe
, 0, sizeof(iwe
));
4048 iwe
.cmd
= IWEVCUSTOM
;
4049 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
4050 iwe
.u
.data
.length
= strlen(buf
);
4051 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4057 if (bss_mesh_cfg(bss
)) {
4059 u8
*cfg
= bss_mesh_cfg(bss
);
4060 buf
= kmalloc(50, GFP_ATOMIC
);
4062 memset(&iwe
, 0, sizeof(iwe
));
4063 iwe
.cmd
= IWEVCUSTOM
;
4064 sprintf(buf
, "Mesh network (version %d)", cfg
[0]);
4065 iwe
.u
.data
.length
= strlen(buf
);
4066 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4068 sprintf(buf
, "Path Selection Protocol ID: "
4069 "0x%02X%02X%02X%02X", cfg
[1], cfg
[2], cfg
[3],
4071 iwe
.u
.data
.length
= strlen(buf
);
4072 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4074 sprintf(buf
, "Path Selection Metric ID: "
4075 "0x%02X%02X%02X%02X", cfg
[5], cfg
[6], cfg
[7],
4077 iwe
.u
.data
.length
= strlen(buf
);
4078 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4080 sprintf(buf
, "Congestion Control Mode ID: "
4081 "0x%02X%02X%02X%02X", cfg
[9], cfg
[10],
4083 iwe
.u
.data
.length
= strlen(buf
);
4084 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4086 sprintf(buf
, "Channel Precedence: "
4087 "0x%02X%02X%02X%02X", cfg
[13], cfg
[14],
4089 iwe
.u
.data
.length
= strlen(buf
);
4090 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
4100 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
4102 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4103 char *current_ev
= buf
;
4104 char *end_buf
= buf
+ len
;
4105 struct ieee80211_sta_bss
*bss
;
4107 spin_lock_bh(&local
->sta_bss_lock
);
4108 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
4109 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
4110 spin_unlock_bh(&local
->sta_bss_lock
);
4113 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
4116 spin_unlock_bh(&local
->sta_bss_lock
);
4117 return current_ev
- buf
;
4121 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
4123 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4124 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4125 kfree(ifsta
->extra_ie
);
4127 ifsta
->extra_ie
= NULL
;
4128 ifsta
->extra_ie_len
= 0;
4131 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
4132 if (!ifsta
->extra_ie
) {
4133 ifsta
->extra_ie_len
= 0;
4136 memcpy(ifsta
->extra_ie
, ie
, len
);
4137 ifsta
->extra_ie_len
= len
;
4142 struct sta_info
* ieee80211_ibss_add_sta(struct net_device
*dev
,
4143 struct sk_buff
*skb
, u8
*bssid
,
4146 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
4147 struct sta_info
*sta
;
4148 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4149 DECLARE_MAC_BUF(mac
);
4151 /* TODO: Could consider removing the least recently used entry and
4152 * allow new one to be added. */
4153 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
4154 if (net_ratelimit()) {
4155 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
4156 "entry %s\n", dev
->name
, print_mac(mac
, addr
));
4161 printk(KERN_DEBUG
"%s: Adding new IBSS station %s (dev=%s)\n",
4162 wiphy_name(local
->hw
.wiphy
), print_mac(mac
, addr
), dev
->name
);
4164 sta
= sta_info_alloc(sdata
, addr
, GFP_ATOMIC
);
4168 sta
->flags
|= WLAN_STA_AUTHORIZED
;
4170 sta
->supp_rates
[local
->hw
.conf
.channel
->band
] =
4171 sdata
->u
.sta
.supp_rates_bits
[local
->hw
.conf
.channel
->band
];
4173 rate_control_rate_init(sta
, local
);
4175 if (sta_info_insert(sta
))
4182 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
4184 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4185 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4187 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
4190 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
4191 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
4194 ieee80211_send_deauth(dev
, ifsta
, reason
);
4195 ieee80211_set_disassoc(dev
, ifsta
, 1);
4200 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
4202 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
4203 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
4205 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
4208 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
4211 if (!(ifsta
->flags
& IEEE80211_STA_ASSOCIATED
))
4214 ieee80211_send_disassoc(dev
, ifsta
, reason
);
4215 ieee80211_set_disassoc(dev
, ifsta
, 0);