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 * BSS table: use <BSSID,SSID> as the key to support multi-SSID APs
16 * order BSS list by RSSI(?) ("quality of AP")
17 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
20 #include <linux/delay.h>
21 #include <linux/if_ether.h>
22 #include <linux/skbuff.h>
23 #include <linux/netdevice.h>
24 #include <linux/if_arp.h>
25 #include <linux/wireless.h>
26 #include <linux/random.h>
27 #include <linux/etherdevice.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 "hostapd_ioctl.h"
36 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
37 #define IEEE80211_AUTH_MAX_TRIES 3
38 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
39 #define IEEE80211_ASSOC_MAX_TRIES 3
40 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
41 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
42 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
43 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
44 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
45 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
47 #define IEEE80211_PROBE_DELAY (HZ / 33)
48 #define IEEE80211_CHANNEL_TIME (HZ / 33)
49 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
50 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
51 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
52 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
54 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
57 #define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
59 #define ERP_INFO_USE_PROTECTION BIT(1)
61 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
62 u8
*ssid
, size_t ssid_len
);
63 static struct ieee80211_sta_bss
*
64 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
);
65 static void ieee80211_rx_bss_put(struct net_device
*dev
,
66 struct ieee80211_sta_bss
*bss
);
67 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
68 struct ieee80211_if_sta
*ifsta
);
69 static int ieee80211_sta_wep_configured(struct net_device
*dev
);
70 static int ieee80211_sta_start_scan(struct net_device
*dev
,
71 u8
*ssid
, size_t ssid_len
);
72 static int ieee80211_sta_config_auth(struct net_device
*dev
,
73 struct ieee80211_if_sta
*ifsta
);
76 /* Parsed Information Elements */
77 struct ieee802_11_elems
{
94 /* length of them, respectively */
106 u8 ext_supp_rates_len
;
111 typedef enum { ParseOK
= 0, ParseUnknown
= 1, ParseFailed
= -1 } ParseRes
;
114 static ParseRes
ieee802_11_parse_elems(u8
*start
, size_t len
,
115 struct ieee802_11_elems
*elems
)
121 memset(elems
, 0, sizeof(*elems
));
133 printk(KERN_DEBUG
"IEEE 802.11 element parse "
134 "failed (id=%d elen=%d left=%d)\n",
143 elems
->ssid_len
= elen
;
145 case WLAN_EID_SUPP_RATES
:
146 elems
->supp_rates
= pos
;
147 elems
->supp_rates_len
= elen
;
149 case WLAN_EID_FH_PARAMS
:
150 elems
->fh_params
= pos
;
151 elems
->fh_params_len
= elen
;
153 case WLAN_EID_DS_PARAMS
:
154 elems
->ds_params
= pos
;
155 elems
->ds_params_len
= elen
;
157 case WLAN_EID_CF_PARAMS
:
158 elems
->cf_params
= pos
;
159 elems
->cf_params_len
= elen
;
163 elems
->tim_len
= elen
;
165 case WLAN_EID_IBSS_PARAMS
:
166 elems
->ibss_params
= pos
;
167 elems
->ibss_params_len
= elen
;
169 case WLAN_EID_CHALLENGE
:
170 elems
->challenge
= pos
;
171 elems
->challenge_len
= elen
;
174 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
176 /* Microsoft OUI (00:50:F2) */
178 /* OUI Type 1 - WPA IE */
180 elems
->wpa_len
= elen
;
181 } else if (elen
>= 5 && pos
[3] == 2) {
183 elems
->wmm_info
= pos
;
184 elems
->wmm_info_len
= elen
;
185 } else if (pos
[4] == 1) {
186 elems
->wmm_param
= pos
;
187 elems
->wmm_param_len
= elen
;
194 elems
->rsn_len
= elen
;
196 case WLAN_EID_ERP_INFO
:
197 elems
->erp_info
= pos
;
198 elems
->erp_info_len
= elen
;
200 case WLAN_EID_EXT_SUPP_RATES
:
201 elems
->ext_supp_rates
= pos
;
202 elems
->ext_supp_rates_len
= elen
;
206 printk(KERN_DEBUG
"IEEE 802.11 element parse ignored "
207 "unknown element (id=%d elen=%d)\n",
218 /* Do not trigger error if left == 1 as Apple Airport base stations
219 * send AssocResps that are one spurious byte too long. */
221 return unknown
? ParseUnknown
: ParseOK
;
227 static int ecw2cw(int ecw
)
238 static void ieee80211_sta_wmm_params(struct net_device
*dev
,
239 struct ieee80211_if_sta
*ifsta
,
240 u8
*wmm_param
, size_t wmm_param_len
)
242 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
243 struct ieee80211_tx_queue_params params
;
248 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
250 count
= wmm_param
[6] & 0x0f;
251 if (count
== ifsta
->wmm_last_param_set
)
253 ifsta
->wmm_last_param_set
= count
;
256 left
= wmm_param_len
- 8;
258 memset(¶ms
, 0, sizeof(params
));
260 if (!local
->ops
->conf_tx
)
264 for (; left
>= 4; left
-= 4, pos
+= 4) {
265 int aci
= (pos
[0] >> 5) & 0x03;
266 int acm
= (pos
[0] >> 4) & 0x01;
271 queue
= IEEE80211_TX_QUEUE_DATA3
;
273 local
->wmm_acm
|= BIT(0) | BIT(3);
277 queue
= IEEE80211_TX_QUEUE_DATA1
;
279 local
->wmm_acm
|= BIT(4) | BIT(5);
283 queue
= IEEE80211_TX_QUEUE_DATA0
;
285 local
->wmm_acm
|= BIT(6) | BIT(7);
290 queue
= IEEE80211_TX_QUEUE_DATA2
;
292 local
->wmm_acm
|= BIT(1) | BIT(2);
297 params
.aifs
= pos
[0] & 0x0f;
298 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
299 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
300 /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
301 params
.burst_time
= (pos
[2] | (pos
[3] << 8)) * 32 / 100;
302 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
303 "cWmin=%d cWmax=%d burst=%d\n",
304 dev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
305 params
.cw_max
, params
.burst_time
);
306 /* TODO: handle ACM (block TX, fallback to next lowest allowed
308 if (local
->ops
->conf_tx(local_to_hw(local
), queue
, ¶ms
)) {
309 printk(KERN_DEBUG
"%s: failed to set TX queue "
310 "parameters for queue %d\n", dev
->name
, queue
);
316 static void ieee80211_handle_erp_ie(struct net_device
*dev
, u8 erp_value
)
318 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
319 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
320 int use_protection
= (erp_value
& WLAN_ERP_USE_PROTECTION
) != 0;
322 if (use_protection
!= sdata
->use_protection
) {
323 if (net_ratelimit()) {
324 printk(KERN_DEBUG
"%s: CTS protection %s (BSSID="
327 use_protection
? "enabled" : "disabled",
328 MAC_ARG(ifsta
->bssid
));
330 sdata
->use_protection
= use_protection
;
335 static void ieee80211_sta_send_associnfo(struct net_device
*dev
,
336 struct ieee80211_if_sta
*ifsta
)
341 union iwreq_data wrqu
;
343 if (!ifsta
->assocreq_ies
&& !ifsta
->assocresp_ies
)
346 buf
= kmalloc(50 + 2 * (ifsta
->assocreq_ies_len
+
347 ifsta
->assocresp_ies_len
), GFP_ATOMIC
);
351 len
= sprintf(buf
, "ASSOCINFO(");
352 if (ifsta
->assocreq_ies
) {
353 len
+= sprintf(buf
+ len
, "ReqIEs=");
354 for (i
= 0; i
< ifsta
->assocreq_ies_len
; i
++) {
355 len
+= sprintf(buf
+ len
, "%02x",
356 ifsta
->assocreq_ies
[i
]);
359 if (ifsta
->assocresp_ies
) {
360 if (ifsta
->assocreq_ies
)
361 len
+= sprintf(buf
+ len
, " ");
362 len
+= sprintf(buf
+ len
, "RespIEs=");
363 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
364 len
+= sprintf(buf
+ len
, "%02x",
365 ifsta
->assocresp_ies
[i
]);
368 len
+= sprintf(buf
+ len
, ")");
370 if (len
> IW_CUSTOM_MAX
) {
371 len
= sprintf(buf
, "ASSOCRESPIE=");
372 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
373 len
+= sprintf(buf
+ len
, "%02x",
374 ifsta
->assocresp_ies
[i
]);
378 memset(&wrqu
, 0, sizeof(wrqu
));
379 wrqu
.data
.length
= len
;
380 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
386 static void ieee80211_set_associated(struct net_device
*dev
,
387 struct ieee80211_if_sta
*ifsta
, int assoc
)
389 union iwreq_data wrqu
;
390 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
392 if (ifsta
->associated
== assoc
)
395 ifsta
->associated
= assoc
;
398 struct ieee80211_sub_if_data
*sdata
;
399 struct ieee80211_sta_bss
*bss
;
400 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
401 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
404 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
406 if (bss
->has_erp_value
)
407 ieee80211_handle_erp_ie(dev
, bss
->erp_value
);
408 ieee80211_rx_bss_put(dev
, bss
);
411 netif_carrier_on(dev
);
412 ifsta
->prev_bssid_set
= 1;
413 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
414 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
415 ieee80211_sta_send_associnfo(dev
, ifsta
);
417 netif_carrier_off(dev
);
418 sdata
->use_protection
= 0;
419 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
421 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
422 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
423 ifsta
->last_probe
= jiffies
;
426 static void ieee80211_set_disassoc(struct net_device
*dev
,
427 struct ieee80211_if_sta
*ifsta
, int deauth
)
430 ifsta
->auth_tries
= 0;
431 ifsta
->assoc_tries
= 0;
432 ieee80211_set_associated(dev
, ifsta
, 0);
435 static void ieee80211_sta_tx(struct net_device
*dev
, struct sk_buff
*skb
,
438 struct ieee80211_sub_if_data
*sdata
;
439 struct ieee80211_tx_packet_data
*pkt_data
;
441 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
442 skb
->dev
= sdata
->local
->mdev
;
443 skb_set_mac_header(skb
, 0);
444 skb_set_network_header(skb
, 0);
445 skb_set_transport_header(skb
, 0);
447 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
448 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
449 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
450 pkt_data
->mgmt_iface
= (sdata
->type
== IEEE80211_IF_TYPE_MGMT
);
451 pkt_data
->do_not_encrypt
= !encrypt
;
457 static void ieee80211_send_auth(struct net_device
*dev
,
458 struct ieee80211_if_sta
*ifsta
,
459 int transaction
, u8
*extra
, size_t extra_len
,
462 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
464 struct ieee80211_mgmt
*mgmt
;
466 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
467 sizeof(*mgmt
) + 6 + extra_len
);
469 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
470 "frame\n", dev
->name
);
473 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
475 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
476 memset(mgmt
, 0, 24 + 6);
477 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
478 IEEE80211_STYPE_AUTH
);
480 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
481 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
482 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
483 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
484 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
485 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
486 ifsta
->auth_transaction
= transaction
+ 1;
487 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
489 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
491 ieee80211_sta_tx(dev
, skb
, encrypt
);
495 static void ieee80211_authenticate(struct net_device
*dev
,
496 struct ieee80211_if_sta
*ifsta
)
499 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
500 printk(KERN_DEBUG
"%s: authentication with AP " MAC_FMT
502 dev
->name
, MAC_ARG(ifsta
->bssid
));
503 ifsta
->state
= IEEE80211_DISABLED
;
507 ifsta
->state
= IEEE80211_AUTHENTICATE
;
508 printk(KERN_DEBUG
"%s: authenticate with AP " MAC_FMT
"\n",
509 dev
->name
, MAC_ARG(ifsta
->bssid
));
511 ieee80211_send_auth(dev
, ifsta
, 1, NULL
, 0, 0);
513 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_AUTH_TIMEOUT
);
517 static void ieee80211_send_assoc(struct net_device
*dev
,
518 struct ieee80211_if_sta
*ifsta
)
520 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
521 struct ieee80211_hw_mode
*mode
;
523 struct ieee80211_mgmt
*mgmt
;
527 struct ieee80211_sta_bss
*bss
;
530 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
531 sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
534 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
535 "frame\n", dev
->name
);
538 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
540 mode
= local
->oper_hw_mode
;
541 capab
= ifsta
->capab
;
542 if (mode
->mode
== MODE_IEEE80211G
) {
543 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
|
544 WLAN_CAPABILITY_SHORT_PREAMBLE
;
546 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
548 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
549 capab
|= WLAN_CAPABILITY_PRIVACY
;
553 ieee80211_rx_bss_put(dev
, bss
);
556 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
558 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
559 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
560 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
562 if (ifsta
->prev_bssid_set
) {
564 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
565 IEEE80211_STYPE_REASSOC_REQ
);
566 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
567 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
568 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
572 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
573 IEEE80211_STYPE_ASSOC_REQ
);
574 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
575 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
579 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
580 *pos
++ = WLAN_EID_SSID
;
581 *pos
++ = ifsta
->ssid_len
;
582 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
584 len
= mode
->num_rates
;
587 pos
= skb_put(skb
, len
+ 2);
588 *pos
++ = WLAN_EID_SUPP_RATES
;
590 for (i
= 0; i
< len
; i
++) {
591 int rate
= mode
->rates
[i
].rate
;
592 if (mode
->mode
== MODE_ATHEROS_TURBO
)
594 *pos
++ = (u8
) (rate
/ 5);
597 if (mode
->num_rates
> len
) {
598 pos
= skb_put(skb
, mode
->num_rates
- len
+ 2);
599 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
600 *pos
++ = mode
->num_rates
- len
;
601 for (i
= len
; i
< mode
->num_rates
; i
++) {
602 int rate
= mode
->rates
[i
].rate
;
603 if (mode
->mode
== MODE_ATHEROS_TURBO
)
605 *pos
++ = (u8
) (rate
/ 5);
609 if (ifsta
->extra_ie
) {
610 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
611 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
614 if (wmm
&& ifsta
->wmm_enabled
) {
615 pos
= skb_put(skb
, 9);
616 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
617 *pos
++ = 7; /* len */
618 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
621 *pos
++ = 2; /* WME */
622 *pos
++ = 0; /* WME info */
623 *pos
++ = 1; /* WME ver */
627 kfree(ifsta
->assocreq_ies
);
628 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
629 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_ATOMIC
);
630 if (ifsta
->assocreq_ies
)
631 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
633 ieee80211_sta_tx(dev
, skb
, 0);
637 static void ieee80211_send_deauth(struct net_device
*dev
,
638 struct ieee80211_if_sta
*ifsta
, u16 reason
)
640 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
642 struct ieee80211_mgmt
*mgmt
;
644 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
646 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
647 "frame\n", dev
->name
);
650 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
652 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
654 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
655 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
656 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
657 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
658 IEEE80211_STYPE_DEAUTH
);
660 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
662 ieee80211_sta_tx(dev
, skb
, 0);
666 static void ieee80211_send_disassoc(struct net_device
*dev
,
667 struct ieee80211_if_sta
*ifsta
, u16 reason
)
669 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
671 struct ieee80211_mgmt
*mgmt
;
673 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
675 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
676 "frame\n", dev
->name
);
679 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
681 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
683 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
684 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
685 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
686 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
687 IEEE80211_STYPE_DISASSOC
);
689 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
691 ieee80211_sta_tx(dev
, skb
, 0);
695 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
696 struct ieee80211_if_sta
*ifsta
)
698 struct ieee80211_sta_bss
*bss
;
701 if (!ifsta
|| ifsta
->mixed_cell
||
702 ifsta
->key_mgmt
!= IEEE80211_KEY_MGMT_NONE
)
705 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
709 if (ieee80211_sta_wep_configured(dev
) !=
710 !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
))
713 ieee80211_rx_bss_put(dev
, bss
);
719 static void ieee80211_associate(struct net_device
*dev
,
720 struct ieee80211_if_sta
*ifsta
)
722 ifsta
->assoc_tries
++;
723 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
724 printk(KERN_DEBUG
"%s: association with AP " MAC_FMT
726 dev
->name
, MAC_ARG(ifsta
->bssid
));
727 ifsta
->state
= IEEE80211_DISABLED
;
731 ifsta
->state
= IEEE80211_ASSOCIATE
;
732 printk(KERN_DEBUG
"%s: associate with AP " MAC_FMT
"\n",
733 dev
->name
, MAC_ARG(ifsta
->bssid
));
734 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
735 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
736 "mixed-cell disabled - abort association\n", dev
->name
);
737 ifsta
->state
= IEEE80211_DISABLED
;
741 ieee80211_send_assoc(dev
, ifsta
);
743 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_ASSOC_TIMEOUT
);
747 static void ieee80211_associated(struct net_device
*dev
,
748 struct ieee80211_if_sta
*ifsta
)
750 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
751 struct sta_info
*sta
;
754 /* TODO: start monitoring current AP signal quality and number of
755 * missed beacons. Scan other channels every now and then and search
757 /* TODO: remove expired BSSes */
759 ifsta
->state
= IEEE80211_ASSOCIATED
;
761 sta
= sta_info_get(local
, ifsta
->bssid
);
763 printk(KERN_DEBUG
"%s: No STA entry for own AP " MAC_FMT
"\n",
764 dev
->name
, MAC_ARG(ifsta
->bssid
));
768 if (time_after(jiffies
,
769 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
770 if (ifsta
->probereq_poll
) {
771 printk(KERN_DEBUG
"%s: No ProbeResp from "
772 "current AP " MAC_FMT
" - assume out of "
774 dev
->name
, MAC_ARG(ifsta
->bssid
));
776 sta_info_free(sta
, 0);
777 ifsta
->probereq_poll
= 0;
779 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
781 local
->scan_ssid_len
);
782 ifsta
->probereq_poll
= 1;
785 ifsta
->probereq_poll
= 0;
786 if (time_after(jiffies
, ifsta
->last_probe
+
787 IEEE80211_PROBE_INTERVAL
)) {
788 ifsta
->last_probe
= jiffies
;
789 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
797 union iwreq_data wrqu
;
798 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
799 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
800 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
801 mod_timer(&ifsta
->timer
, jiffies
+
802 IEEE80211_MONITORING_INTERVAL
+ 30 * HZ
);
804 mod_timer(&ifsta
->timer
, jiffies
+
805 IEEE80211_MONITORING_INTERVAL
);
810 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
811 u8
*ssid
, size_t ssid_len
)
813 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
814 struct ieee80211_hw_mode
*mode
;
816 struct ieee80211_mgmt
*mgmt
;
817 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
820 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200);
822 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
823 "request\n", dev
->name
);
826 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
828 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
830 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
831 IEEE80211_STYPE_PROBE_REQ
);
832 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
834 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
835 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
837 memset(mgmt
->da
, 0xff, ETH_ALEN
);
838 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
840 pos
= skb_put(skb
, 2 + ssid_len
);
841 *pos
++ = WLAN_EID_SSID
;
843 memcpy(pos
, ssid
, ssid_len
);
845 supp_rates
= skb_put(skb
, 2);
846 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
848 mode
= local
->oper_hw_mode
;
849 for (i
= 0; i
< mode
->num_rates
; i
++) {
850 struct ieee80211_rate
*rate
= &mode
->rates
[i
];
851 if (!(rate
->flags
& IEEE80211_RATE_SUPPORTED
))
854 pos
= skb_put(skb
, 1);
856 } else if (supp_rates
[1] == 8) {
857 esupp_rates
= skb_put(skb
, 3);
858 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
860 pos
= &esupp_rates
[2];
862 pos
= skb_put(skb
, 1);
865 if (mode
->mode
== MODE_ATHEROS_TURBO
)
866 *pos
= rate
->rate
/ 10;
868 *pos
= rate
->rate
/ 5;
871 ieee80211_sta_tx(dev
, skb
, 0);
875 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
877 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
878 if (!sdata
|| !sdata
->default_key
||
879 sdata
->default_key
->alg
!= ALG_WEP
)
885 static void ieee80211_auth_completed(struct net_device
*dev
,
886 struct ieee80211_if_sta
*ifsta
)
888 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
889 ifsta
->authenticated
= 1;
890 ieee80211_associate(dev
, ifsta
);
894 static void ieee80211_auth_challenge(struct net_device
*dev
,
895 struct ieee80211_if_sta
*ifsta
,
896 struct ieee80211_mgmt
*mgmt
,
900 struct ieee802_11_elems elems
;
902 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
903 pos
= mgmt
->u
.auth
.variable
;
904 if (ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
)
906 printk(KERN_DEBUG
"%s: failed to parse Auth(challenge)\n",
910 if (!elems
.challenge
) {
911 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
912 "frame\n", dev
->name
);
915 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
916 elems
.challenge_len
+ 2, 1);
920 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
921 struct ieee80211_if_sta
*ifsta
,
922 struct ieee80211_mgmt
*mgmt
,
925 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
926 u16 auth_alg
, auth_transaction
, status_code
;
928 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
929 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
930 printk(KERN_DEBUG
"%s: authentication frame received from "
931 MAC_FMT
", but not in authenticate state - ignored\n",
932 dev
->name
, MAC_ARG(mgmt
->sa
));
937 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
938 "received from " MAC_FMT
" - ignored\n",
939 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
943 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
944 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
945 printk(KERN_DEBUG
"%s: authentication frame received from "
946 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
947 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
948 MAC_ARG(mgmt
->bssid
));
952 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
953 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
954 printk(KERN_DEBUG
"%s: authentication frame received from "
955 "unknown BSSID (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
956 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
957 MAC_ARG(mgmt
->bssid
));
961 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
962 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
963 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
965 printk(KERN_DEBUG
"%s: RX authentication from " MAC_FMT
" (alg=%d "
966 "transaction=%d status=%d)\n",
967 dev
->name
, MAC_ARG(mgmt
->sa
), auth_alg
,
968 auth_transaction
, status_code
);
970 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
971 /* IEEE 802.11 standard does not require authentication in IBSS
972 * networks and most implementations do not seem to use it.
973 * However, try to reply to authentication attempts if someone
974 * has actually implemented this.
975 * TODO: Could implement shared key authentication. */
976 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
977 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
978 "frame (alg=%d transaction=%d)\n",
979 dev
->name
, auth_alg
, auth_transaction
);
982 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
985 if (auth_alg
!= ifsta
->auth_alg
||
986 auth_transaction
!= ifsta
->auth_transaction
) {
987 printk(KERN_DEBUG
"%s: unexpected authentication frame "
988 "(alg=%d transaction=%d)\n",
989 dev
->name
, auth_alg
, auth_transaction
);
993 if (status_code
!= WLAN_STATUS_SUCCESS
) {
994 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
995 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
996 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
998 const int num_algs
= ARRAY_SIZE(algs
);
1000 algs
[0] = algs
[1] = algs
[2] = 0xff;
1001 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1002 algs
[0] = WLAN_AUTH_OPEN
;
1003 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1004 algs
[1] = WLAN_AUTH_SHARED_KEY
;
1005 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1006 algs
[2] = WLAN_AUTH_LEAP
;
1007 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
1009 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
1013 for (i
= 0; i
< num_algs
; i
++) {
1015 if (pos
>= num_algs
)
1017 if (algs
[pos
] == ifsta
->auth_alg
||
1020 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
1021 !ieee80211_sta_wep_configured(dev
))
1023 ifsta
->auth_alg
= algs
[pos
];
1024 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
1026 dev
->name
, ifsta
->auth_alg
);
1033 switch (ifsta
->auth_alg
) {
1034 case WLAN_AUTH_OPEN
:
1035 case WLAN_AUTH_LEAP
:
1036 ieee80211_auth_completed(dev
, ifsta
);
1038 case WLAN_AUTH_SHARED_KEY
:
1039 if (ifsta
->auth_transaction
== 4)
1040 ieee80211_auth_completed(dev
, ifsta
);
1042 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
);
1048 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
1049 struct ieee80211_if_sta
*ifsta
,
1050 struct ieee80211_mgmt
*mgmt
,
1056 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
1057 "received from " MAC_FMT
" - ignored\n",
1058 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
1062 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1063 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1064 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
1065 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
1066 MAC_ARG(mgmt
->bssid
));
1070 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1072 printk(KERN_DEBUG
"%s: RX deauthentication from " MAC_FMT
1074 dev
->name
, MAC_ARG(mgmt
->sa
), reason_code
);
1076 if (ifsta
->authenticated
) {
1077 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1080 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1081 ifsta
->state
== IEEE80211_ASSOCIATE
||
1082 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1083 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1084 mod_timer(&ifsta
->timer
, jiffies
+
1085 IEEE80211_RETRY_AUTH_INTERVAL
);
1088 ieee80211_set_disassoc(dev
, ifsta
, 1);
1089 ifsta
->authenticated
= 0;
1093 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1094 struct ieee80211_if_sta
*ifsta
,
1095 struct ieee80211_mgmt
*mgmt
,
1101 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1102 "received from " MAC_FMT
" - ignored\n",
1103 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
1107 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1108 printk(KERN_DEBUG
"%s: disassociation frame received from "
1109 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
1110 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
1111 MAC_ARG(mgmt
->bssid
));
1115 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1117 printk(KERN_DEBUG
"%s: RX disassociation from " MAC_FMT
1119 dev
->name
, MAC_ARG(mgmt
->sa
), reason_code
);
1121 if (ifsta
->associated
)
1122 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1124 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1125 ifsta
->state
= IEEE80211_ASSOCIATE
;
1126 mod_timer(&ifsta
->timer
, jiffies
+
1127 IEEE80211_RETRY_AUTH_INTERVAL
);
1130 ieee80211_set_disassoc(dev
, ifsta
, 0);
1134 static void ieee80211_rx_mgmt_assoc_resp(struct net_device
*dev
,
1135 struct ieee80211_if_sta
*ifsta
,
1136 struct ieee80211_mgmt
*mgmt
,
1140 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1141 struct ieee80211_hw_mode
*mode
;
1142 struct sta_info
*sta
;
1144 u16 capab_info
, status_code
, aid
;
1145 struct ieee802_11_elems elems
;
1149 /* AssocResp and ReassocResp have identical structure, so process both
1150 * of them in this function. */
1152 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1153 printk(KERN_DEBUG
"%s: association frame received from "
1154 MAC_FMT
", but not in associate state - ignored\n",
1155 dev
->name
, MAC_ARG(mgmt
->sa
));
1160 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1161 "received from " MAC_FMT
" - ignored\n",
1162 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
1166 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1167 printk(KERN_DEBUG
"%s: association frame received from "
1168 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
1169 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
1170 MAC_ARG(mgmt
->bssid
));
1174 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1175 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1176 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1177 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1178 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1179 "set\n", dev
->name
, aid
);
1180 aid
&= ~(BIT(15) | BIT(14));
1182 printk(KERN_DEBUG
"%s: RX %sssocResp from " MAC_FMT
" (capab=0x%x "
1183 "status=%d aid=%d)\n",
1184 dev
->name
, reassoc
? "Rea" : "A", MAC_ARG(mgmt
->sa
),
1185 capab_info
, status_code
, aid
);
1187 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1188 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1189 dev
->name
, status_code
);
1190 if (status_code
== WLAN_STATUS_REASSOC_NO_ASSOC
)
1191 ifsta
->prev_bssid_set
= 0;
1195 pos
= mgmt
->u
.assoc_resp
.variable
;
1196 if (ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
)
1198 printk(KERN_DEBUG
"%s: failed to parse AssocResp\n",
1203 if (!elems
.supp_rates
) {
1204 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1209 /* it probably doesn't, but if the frame includes an ERP value then
1210 * update our stored copy */
1211 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
1212 struct ieee80211_sta_bss
*bss
1213 = ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
1215 bss
->erp_value
= elems
.erp_info
[0];
1216 bss
->has_erp_value
= 1;
1217 ieee80211_rx_bss_put(dev
, bss
);
1221 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1223 ifsta
->ap_capab
= capab_info
;
1225 kfree(ifsta
->assocresp_ies
);
1226 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1227 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_ATOMIC
);
1228 if (ifsta
->assocresp_ies
)
1229 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1231 ieee80211_set_associated(dev
, ifsta
, 1);
1233 /* Add STA entry for the AP */
1234 sta
= sta_info_get(local
, ifsta
->bssid
);
1236 struct ieee80211_sta_bss
*bss
;
1237 sta
= sta_info_add(local
, dev
, ifsta
->bssid
, GFP_ATOMIC
);
1239 printk(KERN_DEBUG
"%s: failed to add STA entry for the"
1240 " AP\n", dev
->name
);
1243 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
1245 sta
->last_rssi
= bss
->rssi
;
1246 sta
->last_signal
= bss
->signal
;
1247 sta
->last_noise
= bss
->noise
;
1248 ieee80211_rx_bss_put(dev
, bss
);
1253 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
1257 mode
= local
->oper_hw_mode
;
1258 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
1259 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
1260 if (mode
->mode
== MODE_ATHEROS_TURBO
)
1262 for (j
= 0; j
< mode
->num_rates
; j
++)
1263 if (mode
->rates
[j
].rate
== rate
)
1266 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
1267 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
1268 if (mode
->mode
== MODE_ATHEROS_TURBO
)
1270 for (j
= 0; j
< mode
->num_rates
; j
++)
1271 if (mode
->rates
[j
].rate
== rate
)
1274 sta
->supp_rates
= rates
;
1276 rate_control_rate_init(sta
, local
);
1278 if (elems
.wmm_param
&& ifsta
->wmm_enabled
) {
1279 sta
->flags
|= WLAN_STA_WME
;
1280 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
1281 elems
.wmm_param_len
);
1287 ieee80211_associated(dev
, ifsta
);
1291 /* Caller must hold local->sta_bss_lock */
1292 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
1293 struct ieee80211_sta_bss
*bss
)
1295 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1296 bss
->hnext
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1297 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] = bss
;
1301 /* Caller must hold local->sta_bss_lock */
1302 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
1303 struct ieee80211_sta_bss
*bss
)
1305 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1306 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
1307 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1311 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
1314 prev
->hnext
= bss
->hnext
;
1323 static struct ieee80211_sta_bss
*
1324 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
)
1326 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1327 struct ieee80211_sta_bss
*bss
;
1329 bss
= kzalloc(sizeof(*bss
), GFP_ATOMIC
);
1332 atomic_inc(&bss
->users
);
1333 atomic_inc(&bss
->users
);
1334 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
1336 spin_lock_bh(&local
->sta_bss_lock
);
1337 /* TODO: order by RSSI? */
1338 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
1339 __ieee80211_rx_bss_hash_add(dev
, bss
);
1340 spin_unlock_bh(&local
->sta_bss_lock
);
1345 static struct ieee80211_sta_bss
*
1346 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
)
1348 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1349 struct ieee80211_sta_bss
*bss
;
1351 spin_lock_bh(&local
->sta_bss_lock
);
1352 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
1354 if (memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0) {
1355 atomic_inc(&bss
->users
);
1360 spin_unlock_bh(&local
->sta_bss_lock
);
1365 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
1374 static void ieee80211_rx_bss_put(struct net_device
*dev
,
1375 struct ieee80211_sta_bss
*bss
)
1377 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1378 if (!atomic_dec_and_test(&bss
->users
))
1381 spin_lock_bh(&local
->sta_bss_lock
);
1382 __ieee80211_rx_bss_hash_del(dev
, bss
);
1383 list_del(&bss
->list
);
1384 spin_unlock_bh(&local
->sta_bss_lock
);
1385 ieee80211_rx_bss_free(bss
);
1389 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
1391 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1392 spin_lock_init(&local
->sta_bss_lock
);
1393 INIT_LIST_HEAD(&local
->sta_bss_list
);
1397 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
1399 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1400 struct ieee80211_sta_bss
*bss
, *tmp
;
1402 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
1403 ieee80211_rx_bss_put(dev
, bss
);
1407 static void ieee80211_rx_bss_info(struct net_device
*dev
,
1408 struct ieee80211_mgmt
*mgmt
,
1410 struct ieee80211_rx_status
*rx_status
,
1413 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1414 struct ieee802_11_elems elems
;
1416 int channel
, invalid
= 0, clen
;
1417 struct ieee80211_sta_bss
*bss
;
1418 struct sta_info
*sta
;
1419 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1422 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
1423 return; /* ignore ProbeResp to foreign address */
1426 printk(KERN_DEBUG
"%s: RX %s from " MAC_FMT
" to " MAC_FMT
"\n",
1427 dev
->name
, beacon
? "Beacon" : "Probe Response",
1428 MAC_ARG(mgmt
->sa
), MAC_ARG(mgmt
->da
));
1431 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1435 timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
1437 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
1438 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0) {
1439 #ifdef CONFIG_MAC80211_IBSS_DEBUG
1440 static unsigned long last_tsf_debug
= 0;
1442 if (local
->ops
->get_tsf
)
1443 tsf
= local
->ops
->get_tsf(local_to_hw(local
));
1446 if (time_after(jiffies
, last_tsf_debug
+ 5 * HZ
)) {
1447 printk(KERN_DEBUG
"RX beacon SA=" MAC_FMT
" BSSID="
1448 MAC_FMT
" TSF=0x%llx BCN=0x%llx diff=%lld "
1450 MAC_ARG(mgmt
->sa
), MAC_ARG(mgmt
->bssid
),
1451 (unsigned long long)tsf
,
1452 (unsigned long long)timestamp
,
1453 (unsigned long long)(tsf
- timestamp
),
1455 last_tsf_debug
= jiffies
;
1457 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
1460 if (ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
,
1461 &elems
) == ParseFailed
)
1464 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&& elems
.supp_rates
&&
1465 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0 &&
1466 (sta
= sta_info_get(local
, mgmt
->sa
))) {
1467 struct ieee80211_hw_mode
*mode
;
1468 struct ieee80211_rate
*rates
;
1470 u32 supp_rates
, prev_rates
;
1473 mode
= local
->sta_scanning
?
1474 local
->scan_hw_mode
: local
->oper_hw_mode
;
1475 rates
= mode
->rates
;
1476 num_rates
= mode
->num_rates
;
1479 for (i
= 0; i
< elems
.supp_rates_len
+
1480 elems
.ext_supp_rates_len
; i
++) {
1483 if (i
< elems
.supp_rates_len
)
1484 rate
= elems
.supp_rates
[i
];
1485 else if (elems
.ext_supp_rates
)
1486 rate
= elems
.ext_supp_rates
1487 [i
- elems
.supp_rates_len
];
1488 own_rate
= 5 * (rate
& 0x7f);
1489 if (mode
->mode
== MODE_ATHEROS_TURBO
)
1491 for (j
= 0; j
< num_rates
; j
++)
1492 if (rates
[j
].rate
== own_rate
)
1493 supp_rates
|= BIT(j
);
1496 prev_rates
= sta
->supp_rates
;
1497 sta
->supp_rates
&= supp_rates
;
1498 if (sta
->supp_rates
== 0) {
1499 /* No matching rates - this should not really happen.
1500 * Make sure that at least one rate is marked
1501 * supported to avoid issues with TX rate ctrl. */
1502 sta
->supp_rates
= sdata
->u
.sta
.supp_rates_bits
;
1504 if (sta
->supp_rates
!= prev_rates
) {
1505 printk(KERN_DEBUG
"%s: updated supp_rates set for "
1506 MAC_FMT
" based on beacon info (0x%x & 0x%x -> "
1508 dev
->name
, MAC_ARG(sta
->addr
), prev_rates
,
1509 supp_rates
, sta
->supp_rates
);
1517 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
1518 channel
= elems
.ds_params
[0];
1520 channel
= rx_status
->channel
;
1522 bss
= ieee80211_rx_bss_get(dev
, mgmt
->bssid
);
1524 bss
= ieee80211_rx_bss_add(dev
, mgmt
->bssid
);
1529 /* TODO: order by RSSI? */
1530 spin_lock_bh(&local
->sta_bss_lock
);
1531 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
1532 spin_unlock_bh(&local
->sta_bss_lock
);
1536 if (bss
->probe_resp
&& beacon
) {
1537 /* Do not allow beacon to override data from Probe Response. */
1538 ieee80211_rx_bss_put(dev
, bss
);
1542 /* save the ERP value so that it is available at association time */
1543 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
1544 bss
->erp_value
= elems
.erp_info
[0];
1545 bss
->has_erp_value
= 1;
1548 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
1549 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
1550 if (elems
.ssid
&& elems
.ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
1551 memcpy(bss
->ssid
, elems
.ssid
, elems
.ssid_len
);
1552 bss
->ssid_len
= elems
.ssid_len
;
1555 bss
->supp_rates_len
= 0;
1556 if (elems
.supp_rates
) {
1557 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
1558 if (clen
> elems
.supp_rates_len
)
1559 clen
= elems
.supp_rates_len
;
1560 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
.supp_rates
,
1562 bss
->supp_rates_len
+= clen
;
1564 if (elems
.ext_supp_rates
) {
1565 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
1566 if (clen
> elems
.ext_supp_rates_len
)
1567 clen
= elems
.ext_supp_rates_len
;
1568 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
1569 elems
.ext_supp_rates
, clen
);
1570 bss
->supp_rates_len
+= clen
;
1574 (!bss
->wpa_ie
|| bss
->wpa_ie_len
!= elems
.wpa_len
||
1575 memcmp(bss
->wpa_ie
, elems
.wpa
, elems
.wpa_len
))) {
1577 bss
->wpa_ie
= kmalloc(elems
.wpa_len
+ 2, GFP_ATOMIC
);
1579 memcpy(bss
->wpa_ie
, elems
.wpa
- 2, elems
.wpa_len
+ 2);
1580 bss
->wpa_ie_len
= elems
.wpa_len
+ 2;
1582 bss
->wpa_ie_len
= 0;
1583 } else if (!elems
.wpa
&& bss
->wpa_ie
) {
1586 bss
->wpa_ie_len
= 0;
1590 (!bss
->rsn_ie
|| bss
->rsn_ie_len
!= elems
.rsn_len
||
1591 memcmp(bss
->rsn_ie
, elems
.rsn
, elems
.rsn_len
))) {
1593 bss
->rsn_ie
= kmalloc(elems
.rsn_len
+ 2, GFP_ATOMIC
);
1595 memcpy(bss
->rsn_ie
, elems
.rsn
- 2, elems
.rsn_len
+ 2);
1596 bss
->rsn_ie_len
= elems
.rsn_len
+ 2;
1598 bss
->rsn_ie_len
= 0;
1599 } else if (!elems
.rsn
&& bss
->rsn_ie
) {
1602 bss
->rsn_ie_len
= 0;
1605 if (elems
.wmm_param
&&
1606 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_param_len
||
1607 memcmp(bss
->wmm_ie
, elems
.wmm_param
, elems
.wmm_param_len
))) {
1609 bss
->wmm_ie
= kmalloc(elems
.wmm_param_len
+ 2, GFP_ATOMIC
);
1611 memcpy(bss
->wmm_ie
, elems
.wmm_param
- 2,
1612 elems
.wmm_param_len
+ 2);
1613 bss
->wmm_ie_len
= elems
.wmm_param_len
+ 2;
1615 bss
->wmm_ie_len
= 0;
1616 } else if (!elems
.wmm_param
&& bss
->wmm_ie
) {
1619 bss
->wmm_ie_len
= 0;
1623 bss
->hw_mode
= rx_status
->phymode
;
1624 bss
->channel
= channel
;
1625 bss
->freq
= rx_status
->freq
;
1626 if (channel
!= rx_status
->channel
&&
1627 (bss
->hw_mode
== MODE_IEEE80211G
||
1628 bss
->hw_mode
== MODE_IEEE80211B
) &&
1629 channel
>= 1 && channel
<= 14) {
1630 static const int freq_list
[] = {
1631 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1632 2447, 2452, 2457, 2462, 2467, 2472, 2484
1634 /* IEEE 802.11g/b mode can receive packets from neighboring
1635 * channels, so map the channel into frequency. */
1636 bss
->freq
= freq_list
[channel
- 1];
1638 bss
->timestamp
= timestamp
;
1639 bss
->last_update
= jiffies
;
1640 bss
->rssi
= rx_status
->ssi
;
1641 bss
->signal
= rx_status
->signal
;
1642 bss
->noise
= rx_status
->noise
;
1645 ieee80211_rx_bss_put(dev
, bss
);
1649 static void ieee80211_rx_mgmt_probe_resp(struct net_device
*dev
,
1650 struct ieee80211_mgmt
*mgmt
,
1652 struct ieee80211_rx_status
*rx_status
)
1654 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 0);
1658 static void ieee80211_rx_mgmt_beacon(struct net_device
*dev
,
1659 struct ieee80211_mgmt
*mgmt
,
1661 struct ieee80211_rx_status
*rx_status
)
1663 struct ieee80211_sub_if_data
*sdata
;
1664 struct ieee80211_if_sta
*ifsta
;
1666 struct ieee802_11_elems elems
;
1668 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 1);
1670 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1671 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
1673 ifsta
= &sdata
->u
.sta
;
1675 if (!ifsta
->associated
||
1676 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
1679 /* Process beacon from the current BSS */
1680 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1684 if (ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
,
1685 &elems
) == ParseFailed
)
1688 if (elems
.erp_info
&& elems
.erp_info_len
>= 1)
1689 ieee80211_handle_erp_ie(dev
, elems
.erp_info
[0]);
1691 if (elems
.wmm_param
&& ifsta
->wmm_enabled
) {
1692 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
1693 elems
.wmm_param_len
);
1698 static void ieee80211_rx_mgmt_probe_req(struct net_device
*dev
,
1699 struct ieee80211_if_sta
*ifsta
,
1700 struct ieee80211_mgmt
*mgmt
,
1702 struct ieee80211_rx_status
*rx_status
)
1704 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1705 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1707 struct sk_buff
*skb
;
1708 struct ieee80211_mgmt
*resp
;
1711 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
||
1712 ifsta
->state
!= IEEE80211_IBSS_JOINED
||
1713 len
< 24 + 2 || !ifsta
->probe_resp
)
1716 if (local
->ops
->tx_last_beacon
)
1717 tx_last_beacon
= local
->ops
->tx_last_beacon(local_to_hw(local
));
1721 #ifdef CONFIG_MAC80211_IBSS_DEBUG
1722 printk(KERN_DEBUG
"%s: RX ProbeReq SA=" MAC_FMT
" DA=" MAC_FMT
" BSSID="
1723 MAC_FMT
" (tx_last_beacon=%d)\n",
1724 dev
->name
, MAC_ARG(mgmt
->sa
), MAC_ARG(mgmt
->da
),
1725 MAC_ARG(mgmt
->bssid
), tx_last_beacon
);
1726 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
1728 if (!tx_last_beacon
)
1731 if (memcmp(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
) != 0 &&
1732 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
1735 end
= ((u8
*) mgmt
) + len
;
1736 pos
= mgmt
->u
.probe_req
.variable
;
1737 if (pos
[0] != WLAN_EID_SSID
||
1738 pos
+ 2 + pos
[1] > end
) {
1739 if (net_ratelimit()) {
1740 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
1741 "from " MAC_FMT
"\n",
1742 dev
->name
, MAC_ARG(mgmt
->sa
));
1747 (pos
[1] != ifsta
->ssid_len
||
1748 memcmp(pos
+ 2, ifsta
->ssid
, ifsta
->ssid_len
) != 0)) {
1749 /* Ignore ProbeReq for foreign SSID */
1753 /* Reply with ProbeResp */
1754 skb
= skb_copy(ifsta
->probe_resp
, GFP_ATOMIC
);
1758 resp
= (struct ieee80211_mgmt
*) skb
->data
;
1759 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
1760 #ifdef CONFIG_MAC80211_IBSS_DEBUG
1761 printk(KERN_DEBUG
"%s: Sending ProbeResp to " MAC_FMT
"\n",
1762 dev
->name
, MAC_ARG(resp
->da
));
1763 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
1764 ieee80211_sta_tx(dev
, skb
, 0);
1768 void ieee80211_sta_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
1769 struct ieee80211_rx_status
*rx_status
)
1771 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1772 struct ieee80211_sub_if_data
*sdata
;
1773 struct ieee80211_if_sta
*ifsta
;
1774 struct ieee80211_mgmt
*mgmt
;
1780 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1781 ifsta
= &sdata
->u
.sta
;
1783 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
1784 fc
= le16_to_cpu(mgmt
->frame_control
);
1786 switch (fc
& IEEE80211_FCTL_STYPE
) {
1787 case IEEE80211_STYPE_PROBE_REQ
:
1788 case IEEE80211_STYPE_PROBE_RESP
:
1789 case IEEE80211_STYPE_BEACON
:
1790 memcpy(skb
->cb
, rx_status
, sizeof(*rx_status
));
1791 case IEEE80211_STYPE_AUTH
:
1792 case IEEE80211_STYPE_ASSOC_RESP
:
1793 case IEEE80211_STYPE_REASSOC_RESP
:
1794 case IEEE80211_STYPE_DEAUTH
:
1795 case IEEE80211_STYPE_DISASSOC
:
1796 skb_queue_tail(&ifsta
->skb_queue
, skb
);
1797 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
1800 printk(KERN_DEBUG
"%s: received unknown management frame - "
1801 "stype=%d\n", dev
->name
,
1802 (fc
& IEEE80211_FCTL_STYPE
) >> 4);
1811 static void ieee80211_sta_rx_queued_mgmt(struct net_device
*dev
,
1812 struct sk_buff
*skb
)
1814 struct ieee80211_rx_status
*rx_status
;
1815 struct ieee80211_sub_if_data
*sdata
;
1816 struct ieee80211_if_sta
*ifsta
;
1817 struct ieee80211_mgmt
*mgmt
;
1820 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1821 ifsta
= &sdata
->u
.sta
;
1823 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
1824 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
1825 fc
= le16_to_cpu(mgmt
->frame_control
);
1827 switch (fc
& IEEE80211_FCTL_STYPE
) {
1828 case IEEE80211_STYPE_PROBE_REQ
:
1829 ieee80211_rx_mgmt_probe_req(dev
, ifsta
, mgmt
, skb
->len
,
1832 case IEEE80211_STYPE_PROBE_RESP
:
1833 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
, skb
->len
, rx_status
);
1835 case IEEE80211_STYPE_BEACON
:
1836 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
, rx_status
);
1838 case IEEE80211_STYPE_AUTH
:
1839 ieee80211_rx_mgmt_auth(dev
, ifsta
, mgmt
, skb
->len
);
1841 case IEEE80211_STYPE_ASSOC_RESP
:
1842 ieee80211_rx_mgmt_assoc_resp(dev
, ifsta
, mgmt
, skb
->len
, 0);
1844 case IEEE80211_STYPE_REASSOC_RESP
:
1845 ieee80211_rx_mgmt_assoc_resp(dev
, ifsta
, mgmt
, skb
->len
, 1);
1847 case IEEE80211_STYPE_DEAUTH
:
1848 ieee80211_rx_mgmt_deauth(dev
, ifsta
, mgmt
, skb
->len
);
1850 case IEEE80211_STYPE_DISASSOC
:
1851 ieee80211_rx_mgmt_disassoc(dev
, ifsta
, mgmt
, skb
->len
);
1859 void ieee80211_sta_rx_scan(struct net_device
*dev
, struct sk_buff
*skb
,
1860 struct ieee80211_rx_status
*rx_status
)
1862 struct ieee80211_mgmt
*mgmt
;
1865 if (skb
->len
< 24) {
1870 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
1871 fc
= le16_to_cpu(mgmt
->frame_control
);
1873 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
1874 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
) {
1875 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
,
1876 skb
->len
, rx_status
);
1877 } else if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
) {
1878 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
,
1887 static int ieee80211_sta_active_ibss(struct net_device
*dev
)
1889 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1891 struct sta_info
*sta
;
1893 spin_lock_bh(&local
->sta_lock
);
1894 list_for_each_entry(sta
, &local
->sta_list
, list
) {
1895 if (sta
->dev
== dev
&&
1896 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
1902 spin_unlock_bh(&local
->sta_lock
);
1908 static void ieee80211_sta_expire(struct net_device
*dev
)
1910 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1911 struct sta_info
*sta
, *tmp
;
1913 spin_lock_bh(&local
->sta_lock
);
1914 list_for_each_entry_safe(sta
, tmp
, &local
->sta_list
, list
)
1915 if (time_after(jiffies
, sta
->last_rx
+
1916 IEEE80211_IBSS_INACTIVITY_LIMIT
)) {
1917 printk(KERN_DEBUG
"%s: expiring inactive STA " MAC_FMT
1918 "\n", dev
->name
, MAC_ARG(sta
->addr
));
1919 sta_info_free(sta
, 1);
1921 spin_unlock_bh(&local
->sta_lock
);
1925 static void ieee80211_sta_merge_ibss(struct net_device
*dev
,
1926 struct ieee80211_if_sta
*ifsta
)
1928 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
1930 ieee80211_sta_expire(dev
);
1931 if (ieee80211_sta_active_ibss(dev
))
1934 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
1935 "IBSS networks with same SSID (merge)\n", dev
->name
);
1936 ieee80211_sta_req_scan(dev
, ifsta
->ssid
, ifsta
->ssid_len
);
1940 void ieee80211_sta_timer(unsigned long data
)
1942 struct ieee80211_sub_if_data
*sdata
=
1943 (struct ieee80211_sub_if_data
*) data
;
1944 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
1945 struct ieee80211_local
*local
= wdev_priv(&sdata
->wdev
);
1947 set_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
1948 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
1952 void ieee80211_sta_work(struct work_struct
*work
)
1954 struct ieee80211_sub_if_data
*sdata
=
1955 container_of(work
, struct ieee80211_sub_if_data
, u
.sta
.work
);
1956 struct net_device
*dev
= sdata
->dev
;
1957 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1958 struct ieee80211_if_sta
*ifsta
;
1959 struct sk_buff
*skb
;
1961 if (!netif_running(dev
))
1964 if (local
->sta_scanning
)
1967 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1968 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
1969 printk(KERN_DEBUG
"%s: ieee80211_sta_work: non-STA interface "
1970 "(type=%d)\n", dev
->name
, sdata
->type
);
1973 ifsta
= &sdata
->u
.sta
;
1975 while ((skb
= skb_dequeue(&ifsta
->skb_queue
)))
1976 ieee80211_sta_rx_queued_mgmt(dev
, skb
);
1978 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
1979 ifsta
->state
!= IEEE80211_ASSOCIATE
&&
1980 test_and_clear_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
)) {
1981 ieee80211_sta_start_scan(dev
, NULL
, 0);
1985 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
)) {
1986 if (ieee80211_sta_config_auth(dev
, ifsta
))
1988 clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
);
1989 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN
, &ifsta
->request
))
1992 switch (ifsta
->state
) {
1993 case IEEE80211_DISABLED
:
1995 case IEEE80211_AUTHENTICATE
:
1996 ieee80211_authenticate(dev
, ifsta
);
1998 case IEEE80211_ASSOCIATE
:
1999 ieee80211_associate(dev
, ifsta
);
2001 case IEEE80211_ASSOCIATED
:
2002 ieee80211_associated(dev
, ifsta
);
2004 case IEEE80211_IBSS_SEARCH
:
2005 ieee80211_sta_find_ibss(dev
, ifsta
);
2007 case IEEE80211_IBSS_JOINED
:
2008 ieee80211_sta_merge_ibss(dev
, ifsta
);
2011 printk(KERN_DEBUG
"ieee80211_sta_work: Unknown state %d\n",
2016 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
2017 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
2018 "mixed-cell disabled - disassociate\n", dev
->name
);
2020 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
2021 ieee80211_set_disassoc(dev
, ifsta
, 0);
2026 static void ieee80211_sta_reset_auth(struct net_device
*dev
,
2027 struct ieee80211_if_sta
*ifsta
)
2029 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2031 if (local
->ops
->reset_tsf
) {
2032 /* Reset own TSF to allow time synchronization work. */
2033 local
->ops
->reset_tsf(local_to_hw(local
));
2036 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
2039 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
2040 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
2041 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
2042 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
2043 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
2044 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
2046 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
2047 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
2049 ifsta
->auth_transaction
= -1;
2050 ifsta
->associated
= ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
2051 netif_carrier_off(dev
);
2055 void ieee80211_sta_req_auth(struct net_device
*dev
,
2056 struct ieee80211_if_sta
*ifsta
)
2058 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2059 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2061 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2064 if ((ifsta
->bssid_set
|| ifsta
->auto_bssid_sel
) &&
2065 (ifsta
->ssid_set
|| ifsta
->auto_ssid_sel
)) {
2066 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
2067 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2071 static int ieee80211_sta_match_ssid(struct ieee80211_if_sta
*ifsta
,
2072 const char *ssid
, int ssid_len
)
2074 int tmp
, hidden_ssid
;
2076 if (!memcmp(ifsta
->ssid
, ssid
, ssid_len
))
2079 if (ifsta
->auto_bssid_sel
)
2085 if (ssid
[tmp
] != '\0') {
2091 if (hidden_ssid
&& ifsta
->ssid_len
== ssid_len
)
2094 if (ssid_len
== 1 && ssid
[0] == ' ')
2100 static int ieee80211_sta_config_auth(struct net_device
*dev
,
2101 struct ieee80211_if_sta
*ifsta
)
2103 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2104 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2105 struct ieee80211_sta_bss
*bss
, *selected
= NULL
;
2106 int top_rssi
= 0, freq
;
2108 if (!ifsta
->auto_channel_sel
&& !ifsta
->auto_bssid_sel
&&
2109 !ifsta
->auto_ssid_sel
) {
2110 ifsta
->state
= IEEE80211_AUTHENTICATE
;
2111 ieee80211_sta_reset_auth(dev
, ifsta
);
2115 spin_lock_bh(&local
->sta_bss_lock
);
2116 freq
= local
->oper_channel
->freq
;
2117 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
2118 if (!(bss
->capability
& WLAN_CAPABILITY_ESS
))
2121 if (!!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
) ^
2122 !!sdata
->default_key
)
2125 if (!ifsta
->auto_channel_sel
&& bss
->freq
!= freq
)
2128 if (!ifsta
->auto_bssid_sel
&&
2129 memcmp(bss
->bssid
, ifsta
->bssid
, ETH_ALEN
))
2132 if (!ifsta
->auto_ssid_sel
&&
2133 !ieee80211_sta_match_ssid(ifsta
, bss
->ssid
, bss
->ssid_len
))
2136 if (!selected
|| top_rssi
< bss
->rssi
) {
2138 top_rssi
= bss
->rssi
;
2142 atomic_inc(&selected
->users
);
2143 spin_unlock_bh(&local
->sta_bss_lock
);
2146 ieee80211_set_channel(local
, -1, selected
->freq
);
2147 if (!ifsta
->ssid_set
)
2148 ieee80211_sta_set_ssid(dev
, selected
->ssid
,
2149 selected
->ssid_len
);
2150 ieee80211_sta_set_bssid(dev
, selected
->bssid
);
2151 ieee80211_rx_bss_put(dev
, selected
);
2152 ifsta
->state
= IEEE80211_AUTHENTICATE
;
2153 ieee80211_sta_reset_auth(dev
, ifsta
);
2156 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
) {
2157 if (ifsta
->auto_ssid_sel
)
2158 ieee80211_sta_start_scan(dev
, NULL
, 0);
2160 ieee80211_sta_start_scan(dev
, ifsta
->ssid
,
2162 ifsta
->state
= IEEE80211_AUTHENTICATE
;
2163 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
2165 ifsta
->state
= IEEE80211_DISABLED
;
2170 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
2171 struct ieee80211_if_sta
*ifsta
,
2172 struct ieee80211_sta_bss
*bss
)
2174 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2175 int res
, rates
, i
, j
;
2176 struct sk_buff
*skb
;
2177 struct ieee80211_mgmt
*mgmt
;
2178 struct ieee80211_tx_control control
;
2179 struct ieee80211_rate
*rate
;
2180 struct ieee80211_hw_mode
*mode
;
2181 struct rate_control_extra extra
;
2183 struct ieee80211_sub_if_data
*sdata
;
2185 /* Remove possible STA entries from other IBSS networks. */
2186 sta_info_flush(local
, NULL
);
2188 if (local
->ops
->reset_tsf
) {
2189 /* Reset own TSF to allow time synchronization work. */
2190 local
->ops
->reset_tsf(local_to_hw(local
));
2192 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
2193 res
= ieee80211_if_config(dev
);
2197 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2199 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2200 sdata
->drop_unencrypted
= bss
->capability
&
2201 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
2203 res
= ieee80211_set_channel(local
, -1, bss
->freq
);
2205 if (!(local
->oper_channel
->flag
& IEEE80211_CHAN_W_IBSS
)) {
2206 printk(KERN_DEBUG
"%s: IBSS not allowed on channel %d "
2207 "(%d MHz)\n", dev
->name
, local
->hw
.conf
.channel
,
2208 local
->hw
.conf
.freq
);
2212 /* Set beacon template based on scan results */
2213 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 400);
2218 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2220 mgmt
= (struct ieee80211_mgmt
*)
2221 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2222 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2223 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2224 IEEE80211_STYPE_BEACON
);
2225 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2226 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2227 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2228 mgmt
->u
.beacon
.beacon_int
=
2229 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2230 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2232 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2233 *pos
++ = WLAN_EID_SSID
;
2234 *pos
++ = ifsta
->ssid_len
;
2235 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2237 rates
= bss
->supp_rates_len
;
2240 pos
= skb_put(skb
, 2 + rates
);
2241 *pos
++ = WLAN_EID_SUPP_RATES
;
2243 memcpy(pos
, bss
->supp_rates
, rates
);
2245 pos
= skb_put(skb
, 2 + 1);
2246 *pos
++ = WLAN_EID_DS_PARAMS
;
2248 *pos
++ = bss
->channel
;
2250 pos
= skb_put(skb
, 2 + 2);
2251 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2253 /* FIX: set ATIM window based on scan results */
2257 if (bss
->supp_rates_len
> 8) {
2258 rates
= bss
->supp_rates_len
- 8;
2259 pos
= skb_put(skb
, 2 + rates
);
2260 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2262 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2265 memset(&control
, 0, sizeof(control
));
2266 memset(&extra
, 0, sizeof(extra
));
2267 extra
.mode
= local
->oper_hw_mode
;
2268 rate
= rate_control_get_rate(local
, dev
, skb
, &extra
);
2270 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2271 "for IBSS beacon\n", dev
->name
);
2274 control
.tx_rate
= (local
->short_preamble
&&
2275 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
)) ?
2276 rate
->val2
: rate
->val
;
2277 control
.antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
2278 control
.power_level
= local
->hw
.conf
.power_level
;
2279 control
.flags
|= IEEE80211_TXCTL_NO_ACK
;
2280 control
.retry_limit
= 1;
2282 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2283 if (ifsta
->probe_resp
) {
2284 mgmt
= (struct ieee80211_mgmt
*)
2285 ifsta
->probe_resp
->data
;
2286 mgmt
->frame_control
=
2287 IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2288 IEEE80211_STYPE_PROBE_RESP
);
2290 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2291 "template for IBSS\n", dev
->name
);
2294 if (local
->ops
->beacon_update
&&
2295 local
->ops
->beacon_update(local_to_hw(local
),
2296 skb
, &control
) == 0) {
2297 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2298 "template based on scan results\n", dev
->name
);
2303 mode
= local
->oper_hw_mode
;
2304 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2305 int bitrate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2306 if (mode
->mode
== MODE_ATHEROS_TURBO
)
2308 for (j
= 0; j
< mode
->num_rates
; j
++)
2309 if (mode
->rates
[j
].rate
== bitrate
)
2312 ifsta
->supp_rates_bits
= rates
;
2316 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2317 "template\n", dev
->name
);
2321 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2322 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2324 ieee80211_rx_bss_put(dev
, bss
);
2330 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
2331 struct ieee80211_if_sta
*ifsta
)
2333 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2334 struct ieee80211_sta_bss
*bss
;
2335 struct ieee80211_sub_if_data
*sdata
;
2336 struct ieee80211_hw_mode
*mode
;
2337 u8 bssid
[ETH_ALEN
], *pos
;
2341 /* Easier testing, use fixed BSSID. */
2342 memset(bssid
, 0xfe, ETH_ALEN
);
2344 /* Generate random, not broadcast, locally administered BSSID. Mix in
2345 * own MAC address to make sure that devices that do not have proper
2346 * random number generator get different BSSID. */
2347 get_random_bytes(bssid
, ETH_ALEN
);
2348 for (i
= 0; i
< ETH_ALEN
; i
++)
2349 bssid
[i
] ^= dev
->dev_addr
[i
];
2354 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID " MAC_FMT
"\n",
2355 dev
->name
, MAC_ARG(bssid
));
2357 bss
= ieee80211_rx_bss_add(dev
, bssid
);
2361 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2362 mode
= local
->oper_hw_mode
;
2364 if (local
->hw
.conf
.beacon_int
== 0)
2365 local
->hw
.conf
.beacon_int
= 100;
2366 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
2367 bss
->hw_mode
= local
->hw
.conf
.phymode
;
2368 bss
->channel
= local
->hw
.conf
.channel
;
2369 bss
->freq
= local
->hw
.conf
.freq
;
2370 bss
->last_update
= jiffies
;
2371 bss
->capability
= WLAN_CAPABILITY_IBSS
;
2372 if (sdata
->default_key
) {
2373 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
2375 sdata
->drop_unencrypted
= 0;
2376 bss
->supp_rates_len
= mode
->num_rates
;
2377 pos
= bss
->supp_rates
;
2378 for (i
= 0; i
< mode
->num_rates
; i
++) {
2379 int rate
= mode
->rates
[i
].rate
;
2380 if (mode
->mode
== MODE_ATHEROS_TURBO
)
2382 *pos
++ = (u8
) (rate
/ 5);
2385 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
2389 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
2390 struct ieee80211_if_sta
*ifsta
)
2392 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2393 struct ieee80211_sta_bss
*bss
;
2398 if (ifsta
->ssid_len
== 0)
2401 active_ibss
= ieee80211_sta_active_ibss(dev
);
2402 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2403 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
2404 dev
->name
, active_ibss
);
2405 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2406 spin_lock_bh(&local
->sta_bss_lock
);
2407 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
2408 if (ifsta
->ssid_len
!= bss
->ssid_len
||
2409 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
2410 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
2412 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2413 printk(KERN_DEBUG
" bssid=" MAC_FMT
" found\n",
2414 MAC_ARG(bss
->bssid
));
2415 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2416 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
2418 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
2421 spin_unlock_bh(&local
->sta_bss_lock
);
2423 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2424 printk(KERN_DEBUG
" sta_find_ibss: selected " MAC_FMT
" current "
2425 MAC_FMT
"\n", MAC_ARG(bssid
), MAC_ARG(ifsta
->bssid
));
2426 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2427 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
2428 (bss
= ieee80211_rx_bss_get(dev
, bssid
))) {
2429 printk(KERN_DEBUG
"%s: Selected IBSS BSSID " MAC_FMT
2430 " based on configured SSID\n",
2431 dev
->name
, MAC_ARG(bssid
));
2432 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
2434 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2435 printk(KERN_DEBUG
" did not try to join ibss\n");
2436 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2438 /* Selected IBSS not found in current scan results - try to scan */
2439 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
2440 !ieee80211_sta_active_ibss(dev
)) {
2441 mod_timer(&ifsta
->timer
, jiffies
+
2442 IEEE80211_IBSS_MERGE_INTERVAL
);
2443 } else if (time_after(jiffies
, local
->last_scan_completed
+
2444 IEEE80211_SCAN_INTERVAL
)) {
2445 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
2446 "join\n", dev
->name
);
2447 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
2449 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
2450 int interval
= IEEE80211_SCAN_INTERVAL
;
2452 if (time_after(jiffies
, ifsta
->ibss_join_req
+
2453 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
2454 if (ifsta
->create_ibss
&&
2455 local
->oper_channel
->flag
& IEEE80211_CHAN_W_IBSS
)
2456 return ieee80211_sta_create_ibss(dev
, ifsta
);
2457 if (ifsta
->create_ibss
) {
2458 printk(KERN_DEBUG
"%s: IBSS not allowed on the"
2459 " configured channel %d (%d MHz)\n",
2460 dev
->name
, local
->hw
.conf
.channel
,
2461 local
->hw
.conf
.freq
);
2464 /* No IBSS found - decrease scan interval and continue
2466 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
2469 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
2470 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
2478 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
2480 struct ieee80211_sub_if_data
*sdata
;
2481 struct ieee80211_if_sta
*ifsta
;
2482 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2484 if (len
> IEEE80211_MAX_SSID_LEN
)
2487 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
2489 if (local
->ops
->conf_tx
) {
2490 struct ieee80211_tx_queue_params qparam
;
2493 memset(&qparam
, 0, sizeof(qparam
));
2494 /* TODO: are these ok defaults for all hw_modes? */
2497 local
->hw
.conf
.phymode
== MODE_IEEE80211B
? 31 : 15;
2498 qparam
.cw_max
= 1023;
2499 qparam
.burst_time
= 0;
2500 for (i
= IEEE80211_TX_QUEUE_DATA0
; i
< NUM_TX_DATA_QUEUES
; i
++)
2502 local
->ops
->conf_tx(local_to_hw(local
),
2503 i
+ IEEE80211_TX_QUEUE_DATA0
,
2506 /* IBSS uses different parameters for Beacon sending */
2510 local
->ops
->conf_tx(local_to_hw(local
),
2511 IEEE80211_TX_QUEUE_BEACON
, &qparam
);
2514 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2515 ifsta
= &sdata
->u
.sta
;
2517 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
2518 ifsta
->prev_bssid_set
= 0;
2519 memcpy(ifsta
->ssid
, ssid
, len
);
2520 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
2521 ifsta
->ssid_len
= len
;
2523 ifsta
->ssid_set
= len
? 1 : 0;
2524 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&& !ifsta
->bssid_set
) {
2525 ifsta
->ibss_join_req
= jiffies
;
2526 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
2527 return ieee80211_sta_find_ibss(dev
, ifsta
);
2533 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
2535 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2536 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2537 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
2538 *len
= ifsta
->ssid_len
;
2543 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
2545 struct ieee80211_sub_if_data
*sdata
;
2546 struct ieee80211_if_sta
*ifsta
;
2549 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2550 ifsta
= &sdata
->u
.sta
;
2552 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
2553 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
2554 res
= ieee80211_if_config(dev
);
2556 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
2557 "the low-level driver\n", dev
->name
);
2562 if (!is_valid_ether_addr(bssid
))
2563 ifsta
->bssid_set
= 0;
2565 ifsta
->bssid_set
= 1;
2570 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
2571 struct ieee80211_sub_if_data
*sdata
,
2574 struct sk_buff
*skb
;
2575 struct ieee80211_hdr
*nullfunc
;
2578 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
2580 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
2581 "frame\n", sdata
->dev
->name
);
2584 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2586 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
2587 memset(nullfunc
, 0, 24);
2588 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
2589 IEEE80211_FCTL_TODS
;
2591 fc
|= IEEE80211_FCTL_PM
;
2592 nullfunc
->frame_control
= cpu_to_le16(fc
);
2593 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
2594 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
2595 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
2597 ieee80211_sta_tx(sdata
->dev
, skb
, 0);
2601 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
2603 struct ieee80211_local
*local
= hw_to_local(hw
);
2604 struct net_device
*dev
= local
->scan_dev
;
2605 struct ieee80211_sub_if_data
*sdata
;
2606 union iwreq_data wrqu
;
2608 local
->last_scan_completed
= jiffies
;
2610 local
->sta_scanning
= 0;
2612 if (ieee80211_hw_config(local
))
2613 printk(KERN_DEBUG
"%s: failed to restore operational"
2614 "channel after scan\n", dev
->name
);
2616 if (!(local
->hw
.flags
& IEEE80211_HW_NO_PROBE_FILTERING
) &&
2617 ieee80211_if_config(dev
))
2618 printk(KERN_DEBUG
"%s: failed to restore operational"
2619 "BSSID after scan\n", dev
->name
);
2621 memset(&wrqu
, 0, sizeof(wrqu
));
2622 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2624 read_lock(&local
->sub_if_lock
);
2625 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2627 /* No need to wake the master device. */
2628 if (sdata
->dev
== local
->mdev
)
2631 if (sdata
->type
== IEEE80211_IF_TYPE_STA
) {
2632 if (sdata
->u
.sta
.associated
)
2633 ieee80211_send_nullfunc(local
, sdata
, 0);
2634 ieee80211_sta_timer((unsigned long)sdata
);
2637 netif_wake_queue(sdata
->dev
);
2639 read_unlock(&local
->sub_if_lock
);
2641 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2642 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2643 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2644 if (!ifsta
->bssid_set
||
2645 (!ifsta
->state
== IEEE80211_IBSS_JOINED
&&
2646 !ieee80211_sta_active_ibss(dev
)))
2647 ieee80211_sta_find_ibss(dev
, ifsta
);
2650 EXPORT_SYMBOL(ieee80211_scan_completed
);
2652 void ieee80211_sta_scan_work(struct work_struct
*work
)
2654 struct ieee80211_local
*local
=
2655 container_of(work
, struct ieee80211_local
, scan_work
.work
);
2656 struct net_device
*dev
= local
->scan_dev
;
2657 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2658 struct ieee80211_hw_mode
*mode
;
2659 struct ieee80211_channel
*chan
;
2661 unsigned long next_delay
= 0;
2663 if (!local
->sta_scanning
)
2666 switch (local
->scan_state
) {
2667 case SCAN_SET_CHANNEL
:
2668 mode
= local
->scan_hw_mode
;
2669 if (local
->scan_hw_mode
->list
.next
== &local
->modes_list
&&
2670 local
->scan_channel_idx
>= mode
->num_channels
) {
2671 ieee80211_scan_completed(local_to_hw(local
));
2674 skip
= !(local
->enabled_modes
& (1 << mode
->mode
));
2675 chan
= &mode
->channels
[local
->scan_channel_idx
];
2676 if (!(chan
->flag
& IEEE80211_CHAN_W_SCAN
) ||
2677 (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&&
2678 !(chan
->flag
& IEEE80211_CHAN_W_IBSS
)) ||
2679 (local
->hw_modes
& local
->enabled_modes
&
2680 (1 << MODE_IEEE80211G
) && mode
->mode
== MODE_IEEE80211B
))
2685 printk(KERN_DEBUG
"%s: scan channel %d (%d MHz)\n",
2686 dev
->name
, chan
->chan
, chan
->freq
);
2689 local
->scan_channel
= chan
;
2690 if (ieee80211_hw_config(local
)) {
2691 printk(KERN_DEBUG
"%s: failed to set channel "
2692 "%d (%d MHz) for scan\n", dev
->name
,
2693 chan
->chan
, chan
->freq
);
2698 local
->scan_channel_idx
++;
2699 if (local
->scan_channel_idx
>= local
->scan_hw_mode
->num_channels
) {
2700 if (local
->scan_hw_mode
->list
.next
!= &local
->modes_list
) {
2701 local
->scan_hw_mode
= list_entry(local
->scan_hw_mode
->list
.next
,
2702 struct ieee80211_hw_mode
,
2704 local
->scan_channel_idx
= 0;
2711 next_delay
= IEEE80211_PROBE_DELAY
+
2712 usecs_to_jiffies(local
->hw
.channel_change_time
);
2713 local
->scan_state
= SCAN_SEND_PROBE
;
2715 case SCAN_SEND_PROBE
:
2716 if (local
->scan_channel
->flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
) {
2717 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
2718 local
->scan_ssid_len
);
2719 next_delay
= IEEE80211_CHANNEL_TIME
;
2721 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
2722 local
->scan_state
= SCAN_SET_CHANNEL
;
2726 if (local
->sta_scanning
)
2727 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
2732 static int ieee80211_sta_start_scan(struct net_device
*dev
,
2733 u8
*ssid
, size_t ssid_len
)
2735 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2736 struct ieee80211_sub_if_data
*sdata
;
2738 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
2741 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
2742 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
2745 * ScanType: ACTIVE, PASSIVE
2746 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
2747 * a Probe frame during active scanning
2749 * MinChannelTime (>= ProbeDelay), in TU
2750 * MaxChannelTime: (>= MinChannelTime), in TU
2753 /* MLME-SCAN.confirm
2755 * ResultCode: SUCCESS, INVALID_PARAMETERS
2758 if (local
->sta_scanning
) {
2759 if (local
->scan_dev
== dev
)
2764 if (local
->ops
->hw_scan
) {
2765 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
2768 local
->sta_scanning
= 1;
2769 local
->scan_dev
= dev
;
2774 local
->sta_scanning
= 1;
2776 read_lock(&local
->sub_if_lock
);
2777 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2779 /* Don't stop the master interface, otherwise we can't transmit
2781 if (sdata
->dev
== local
->mdev
)
2784 netif_stop_queue(sdata
->dev
);
2785 if (sdata
->type
== IEEE80211_IF_TYPE_STA
&&
2786 sdata
->u
.sta
.associated
)
2787 ieee80211_send_nullfunc(local
, sdata
, 1);
2789 read_unlock(&local
->sub_if_lock
);
2792 local
->scan_ssid_len
= ssid_len
;
2793 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
2795 local
->scan_ssid_len
= 0;
2796 local
->scan_state
= SCAN_SET_CHANNEL
;
2797 local
->scan_hw_mode
= list_entry(local
->modes_list
.next
,
2798 struct ieee80211_hw_mode
,
2800 local
->scan_channel_idx
= 0;
2801 local
->scan_dev
= dev
;
2803 if (!(local
->hw
.flags
& IEEE80211_HW_NO_PROBE_FILTERING
) &&
2804 ieee80211_if_config(dev
))
2805 printk(KERN_DEBUG
"%s: failed to set BSSID for scan\n",
2808 /* TODO: start scan as soon as all nullfunc frames are ACKed */
2809 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
2810 IEEE80211_CHANNEL_TIME
);
2816 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
2818 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2819 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2820 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2822 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2823 return ieee80211_sta_start_scan(dev
, ssid
, ssid_len
);
2825 if (local
->sta_scanning
) {
2826 if (local
->scan_dev
== dev
)
2831 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
2832 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2837 ieee80211_sta_scan_result(struct net_device
*dev
,
2838 struct ieee80211_sta_bss
*bss
,
2839 char *current_ev
, char *end_buf
)
2841 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2842 struct iw_event iwe
;
2844 if (time_after(jiffies
,
2845 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
2848 if (!(local
->enabled_modes
& (1 << bss
->hw_mode
)))
2851 if (local
->scan_flags
& IEEE80211_SCAN_WPA_ONLY
&&
2852 !bss
->wpa_ie
&& !bss
->rsn_ie
)
2855 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
&&
2856 (local
->scan_ssid_len
!= bss
->ssid_len
||
2857 memcmp(local
->scan_ssid
, bss
->ssid
, bss
->ssid_len
) != 0))
2860 memset(&iwe
, 0, sizeof(iwe
));
2861 iwe
.cmd
= SIOCGIWAP
;
2862 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
2863 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
2864 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2867 memset(&iwe
, 0, sizeof(iwe
));
2868 iwe
.cmd
= SIOCGIWESSID
;
2869 iwe
.u
.data
.length
= bss
->ssid_len
;
2870 iwe
.u
.data
.flags
= 1;
2871 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2874 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
2875 memset(&iwe
, 0, sizeof(iwe
));
2876 iwe
.cmd
= SIOCGIWMODE
;
2877 if (bss
->capability
& WLAN_CAPABILITY_ESS
)
2878 iwe
.u
.mode
= IW_MODE_MASTER
;
2880 iwe
.u
.mode
= IW_MODE_ADHOC
;
2881 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2885 memset(&iwe
, 0, sizeof(iwe
));
2886 iwe
.cmd
= SIOCGIWFREQ
;
2887 iwe
.u
.freq
.m
= bss
->channel
;
2889 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2891 iwe
.u
.freq
.m
= bss
->freq
* 100000;
2893 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2896 memset(&iwe
, 0, sizeof(iwe
));
2898 iwe
.u
.qual
.qual
= bss
->signal
;
2899 iwe
.u
.qual
.level
= bss
->rssi
;
2900 iwe
.u
.qual
.noise
= bss
->noise
;
2901 iwe
.u
.qual
.updated
= local
->wstats_flags
;
2902 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2905 memset(&iwe
, 0, sizeof(iwe
));
2906 iwe
.cmd
= SIOCGIWENCODE
;
2907 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
2908 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
2910 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
2911 iwe
.u
.data
.length
= 0;
2912 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
2914 if (bss
&& bss
->wpa_ie
) {
2915 memset(&iwe
, 0, sizeof(iwe
));
2916 iwe
.cmd
= IWEVGENIE
;
2917 iwe
.u
.data
.length
= bss
->wpa_ie_len
;
2918 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2922 if (bss
&& bss
->rsn_ie
) {
2923 memset(&iwe
, 0, sizeof(iwe
));
2924 iwe
.cmd
= IWEVGENIE
;
2925 iwe
.u
.data
.length
= bss
->rsn_ie_len
;
2926 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2930 if (bss
&& bss
->supp_rates_len
> 0) {
2931 /* display all supported rates in readable format */
2932 char *p
= current_ev
+ IW_EV_LCP_LEN
;
2935 memset(&iwe
, 0, sizeof(iwe
));
2936 iwe
.cmd
= SIOCGIWRATE
;
2937 /* Those two flags are ignored... */
2938 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
2940 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2941 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
2943 p
= iwe_stream_add_value(current_ev
, p
,
2944 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
2951 buf
= kmalloc(30, GFP_ATOMIC
);
2953 memset(&iwe
, 0, sizeof(iwe
));
2954 iwe
.cmd
= IWEVCUSTOM
;
2955 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
2956 iwe
.u
.data
.length
= strlen(buf
);
2957 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2966 if (!(local
->scan_flags
& IEEE80211_SCAN_EXTRA_INFO
))
2969 buf
= kmalloc(100, GFP_ATOMIC
);
2973 memset(&iwe
, 0, sizeof(iwe
));
2974 iwe
.cmd
= IWEVCUSTOM
;
2975 sprintf(buf
, "bcn_int=%d", bss
->beacon_int
);
2976 iwe
.u
.data
.length
= strlen(buf
);
2977 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2980 memset(&iwe
, 0, sizeof(iwe
));
2981 iwe
.cmd
= IWEVCUSTOM
;
2982 sprintf(buf
, "capab=0x%04x", bss
->capability
);
2983 iwe
.u
.data
.length
= strlen(buf
);
2984 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2995 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
2997 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2998 char *current_ev
= buf
;
2999 char *end_buf
= buf
+ len
;
3000 struct ieee80211_sta_bss
*bss
;
3002 spin_lock_bh(&local
->sta_bss_lock
);
3003 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3004 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
3005 spin_unlock_bh(&local
->sta_bss_lock
);
3008 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
3011 spin_unlock_bh(&local
->sta_bss_lock
);
3012 return current_ev
- buf
;
3016 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
3018 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3019 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3020 kfree(ifsta
->extra_ie
);
3022 ifsta
->extra_ie
= NULL
;
3023 ifsta
->extra_ie_len
= 0;
3026 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
3027 if (!ifsta
->extra_ie
) {
3028 ifsta
->extra_ie_len
= 0;
3031 memcpy(ifsta
->extra_ie
, ie
, len
);
3032 ifsta
->extra_ie_len
= len
;
3037 struct sta_info
* ieee80211_ibss_add_sta(struct net_device
*dev
,
3038 struct sk_buff
*skb
, u8
*bssid
,
3041 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3042 struct sta_info
*sta
;
3043 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3045 /* TODO: Could consider removing the least recently used entry and
3046 * allow new one to be added. */
3047 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
3048 if (net_ratelimit()) {
3049 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
3050 "entry " MAC_FMT
"\n", dev
->name
, MAC_ARG(addr
));
3055 printk(KERN_DEBUG
"%s: Adding new IBSS station " MAC_FMT
" (dev=%s)\n",
3056 local
->mdev
->name
, MAC_ARG(addr
), dev
->name
);
3058 sta
= sta_info_add(local
, dev
, addr
, GFP_ATOMIC
);
3062 sta
->supp_rates
= sdata
->u
.sta
.supp_rates_bits
;
3064 rate_control_rate_init(sta
, local
);
3066 return sta
; /* caller will call sta_info_put() */
3070 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
3072 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3073 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3075 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
3078 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
3079 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
3082 ieee80211_send_deauth(dev
, ifsta
, reason
);
3083 ieee80211_set_disassoc(dev
, ifsta
, 1);
3088 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
3090 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3091 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3093 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
3096 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
3099 if (!ifsta
->associated
)
3102 ieee80211_send_disassoc(dev
, ifsta
, reason
);
3103 ieee80211_set_disassoc(dev
, ifsta
, 0);