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 ieee80211_sta_start_scan(dev
, NULL
, 0);
2158 ifsta
->state
= IEEE80211_AUTHENTICATE
;
2159 set_bit(IEEE80211_STA_REQ_AUTH
, &ifsta
->request
);
2161 ifsta
->state
= IEEE80211_DISABLED
;
2166 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
2167 struct ieee80211_if_sta
*ifsta
,
2168 struct ieee80211_sta_bss
*bss
)
2170 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2171 int res
, rates
, i
, j
;
2172 struct sk_buff
*skb
;
2173 struct ieee80211_mgmt
*mgmt
;
2174 struct ieee80211_tx_control control
;
2175 struct ieee80211_rate
*rate
;
2176 struct ieee80211_hw_mode
*mode
;
2177 struct rate_control_extra extra
;
2179 struct ieee80211_sub_if_data
*sdata
;
2181 /* Remove possible STA entries from other IBSS networks. */
2182 sta_info_flush(local
, NULL
);
2184 if (local
->ops
->reset_tsf
) {
2185 /* Reset own TSF to allow time synchronization work. */
2186 local
->ops
->reset_tsf(local_to_hw(local
));
2188 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
2189 res
= ieee80211_if_config(dev
);
2193 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2195 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2196 sdata
->drop_unencrypted
= bss
->capability
&
2197 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
2199 res
= ieee80211_set_channel(local
, -1, bss
->freq
);
2201 if (!(local
->oper_channel
->flag
& IEEE80211_CHAN_W_IBSS
)) {
2202 printk(KERN_DEBUG
"%s: IBSS not allowed on channel %d "
2203 "(%d MHz)\n", dev
->name
, local
->hw
.conf
.channel
,
2204 local
->hw
.conf
.freq
);
2208 /* Set beacon template based on scan results */
2209 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 400);
2214 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2216 mgmt
= (struct ieee80211_mgmt
*)
2217 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2218 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2219 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2220 IEEE80211_STYPE_BEACON
);
2221 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2222 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2223 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2224 mgmt
->u
.beacon
.beacon_int
=
2225 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2226 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2228 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2229 *pos
++ = WLAN_EID_SSID
;
2230 *pos
++ = ifsta
->ssid_len
;
2231 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2233 rates
= bss
->supp_rates_len
;
2236 pos
= skb_put(skb
, 2 + rates
);
2237 *pos
++ = WLAN_EID_SUPP_RATES
;
2239 memcpy(pos
, bss
->supp_rates
, rates
);
2241 pos
= skb_put(skb
, 2 + 1);
2242 *pos
++ = WLAN_EID_DS_PARAMS
;
2244 *pos
++ = bss
->channel
;
2246 pos
= skb_put(skb
, 2 + 2);
2247 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2249 /* FIX: set ATIM window based on scan results */
2253 if (bss
->supp_rates_len
> 8) {
2254 rates
= bss
->supp_rates_len
- 8;
2255 pos
= skb_put(skb
, 2 + rates
);
2256 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2258 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2261 memset(&control
, 0, sizeof(control
));
2262 memset(&extra
, 0, sizeof(extra
));
2263 extra
.mode
= local
->oper_hw_mode
;
2264 rate
= rate_control_get_rate(local
, dev
, skb
, &extra
);
2266 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2267 "for IBSS beacon\n", dev
->name
);
2270 control
.tx_rate
= (local
->short_preamble
&&
2271 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
)) ?
2272 rate
->val2
: rate
->val
;
2273 control
.antenna_sel_tx
= local
->hw
.conf
.antenna_sel_tx
;
2274 control
.power_level
= local
->hw
.conf
.power_level
;
2275 control
.flags
|= IEEE80211_TXCTL_NO_ACK
;
2276 control
.retry_limit
= 1;
2278 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2279 if (ifsta
->probe_resp
) {
2280 mgmt
= (struct ieee80211_mgmt
*)
2281 ifsta
->probe_resp
->data
;
2282 mgmt
->frame_control
=
2283 IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2284 IEEE80211_STYPE_PROBE_RESP
);
2286 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2287 "template for IBSS\n", dev
->name
);
2290 if (local
->ops
->beacon_update
&&
2291 local
->ops
->beacon_update(local_to_hw(local
),
2292 skb
, &control
) == 0) {
2293 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2294 "template based on scan results\n", dev
->name
);
2299 mode
= local
->oper_hw_mode
;
2300 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2301 int bitrate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2302 if (mode
->mode
== MODE_ATHEROS_TURBO
)
2304 for (j
= 0; j
< mode
->num_rates
; j
++)
2305 if (mode
->rates
[j
].rate
== bitrate
)
2308 ifsta
->supp_rates_bits
= rates
;
2312 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2313 "template\n", dev
->name
);
2317 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2318 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2320 ieee80211_rx_bss_put(dev
, bss
);
2326 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
2327 struct ieee80211_if_sta
*ifsta
)
2329 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2330 struct ieee80211_sta_bss
*bss
;
2331 struct ieee80211_sub_if_data
*sdata
;
2332 struct ieee80211_hw_mode
*mode
;
2333 u8 bssid
[ETH_ALEN
], *pos
;
2337 /* Easier testing, use fixed BSSID. */
2338 memset(bssid
, 0xfe, ETH_ALEN
);
2340 /* Generate random, not broadcast, locally administered BSSID. Mix in
2341 * own MAC address to make sure that devices that do not have proper
2342 * random number generator get different BSSID. */
2343 get_random_bytes(bssid
, ETH_ALEN
);
2344 for (i
= 0; i
< ETH_ALEN
; i
++)
2345 bssid
[i
] ^= dev
->dev_addr
[i
];
2350 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID " MAC_FMT
"\n",
2351 dev
->name
, MAC_ARG(bssid
));
2353 bss
= ieee80211_rx_bss_add(dev
, bssid
);
2357 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2358 mode
= local
->oper_hw_mode
;
2360 if (local
->hw
.conf
.beacon_int
== 0)
2361 local
->hw
.conf
.beacon_int
= 100;
2362 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
2363 bss
->hw_mode
= local
->hw
.conf
.phymode
;
2364 bss
->channel
= local
->hw
.conf
.channel
;
2365 bss
->freq
= local
->hw
.conf
.freq
;
2366 bss
->last_update
= jiffies
;
2367 bss
->capability
= WLAN_CAPABILITY_IBSS
;
2368 if (sdata
->default_key
) {
2369 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
2371 sdata
->drop_unencrypted
= 0;
2372 bss
->supp_rates_len
= mode
->num_rates
;
2373 pos
= bss
->supp_rates
;
2374 for (i
= 0; i
< mode
->num_rates
; i
++) {
2375 int rate
= mode
->rates
[i
].rate
;
2376 if (mode
->mode
== MODE_ATHEROS_TURBO
)
2378 *pos
++ = (u8
) (rate
/ 5);
2381 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
2385 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
2386 struct ieee80211_if_sta
*ifsta
)
2388 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2389 struct ieee80211_sta_bss
*bss
;
2394 if (ifsta
->ssid_len
== 0)
2397 active_ibss
= ieee80211_sta_active_ibss(dev
);
2398 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2399 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
2400 dev
->name
, active_ibss
);
2401 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2402 spin_lock_bh(&local
->sta_bss_lock
);
2403 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
2404 if (ifsta
->ssid_len
!= bss
->ssid_len
||
2405 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
2406 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
2408 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2409 printk(KERN_DEBUG
" bssid=" MAC_FMT
" found\n",
2410 MAC_ARG(bss
->bssid
));
2411 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2412 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
2414 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
2417 spin_unlock_bh(&local
->sta_bss_lock
);
2419 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2420 printk(KERN_DEBUG
" sta_find_ibss: selected " MAC_FMT
" current "
2421 MAC_FMT
"\n", MAC_ARG(bssid
), MAC_ARG(ifsta
->bssid
));
2422 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2423 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
2424 (bss
= ieee80211_rx_bss_get(dev
, bssid
))) {
2425 printk(KERN_DEBUG
"%s: Selected IBSS BSSID " MAC_FMT
2426 " based on configured SSID\n",
2427 dev
->name
, MAC_ARG(bssid
));
2428 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
2430 #ifdef CONFIG_MAC80211_IBSS_DEBUG
2431 printk(KERN_DEBUG
" did not try to join ibss\n");
2432 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
2434 /* Selected IBSS not found in current scan results - try to scan */
2435 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
2436 !ieee80211_sta_active_ibss(dev
)) {
2437 mod_timer(&ifsta
->timer
, jiffies
+
2438 IEEE80211_IBSS_MERGE_INTERVAL
);
2439 } else if (time_after(jiffies
, local
->last_scan_completed
+
2440 IEEE80211_SCAN_INTERVAL
)) {
2441 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
2442 "join\n", dev
->name
);
2443 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
2445 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
2446 int interval
= IEEE80211_SCAN_INTERVAL
;
2448 if (time_after(jiffies
, ifsta
->ibss_join_req
+
2449 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
2450 if (ifsta
->create_ibss
&&
2451 local
->oper_channel
->flag
& IEEE80211_CHAN_W_IBSS
)
2452 return ieee80211_sta_create_ibss(dev
, ifsta
);
2453 if (ifsta
->create_ibss
) {
2454 printk(KERN_DEBUG
"%s: IBSS not allowed on the"
2455 " configured channel %d (%d MHz)\n",
2456 dev
->name
, local
->hw
.conf
.channel
,
2457 local
->hw
.conf
.freq
);
2460 /* No IBSS found - decrease scan interval and continue
2462 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
2465 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
2466 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
2474 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
2476 struct ieee80211_sub_if_data
*sdata
;
2477 struct ieee80211_if_sta
*ifsta
;
2478 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2480 if (len
> IEEE80211_MAX_SSID_LEN
)
2483 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
2485 if (local
->ops
->conf_tx
) {
2486 struct ieee80211_tx_queue_params qparam
;
2489 memset(&qparam
, 0, sizeof(qparam
));
2490 /* TODO: are these ok defaults for all hw_modes? */
2493 local
->hw
.conf
.phymode
== MODE_IEEE80211B
? 31 : 15;
2494 qparam
.cw_max
= 1023;
2495 qparam
.burst_time
= 0;
2496 for (i
= IEEE80211_TX_QUEUE_DATA0
; i
< NUM_TX_DATA_QUEUES
; i
++)
2498 local
->ops
->conf_tx(local_to_hw(local
),
2499 i
+ IEEE80211_TX_QUEUE_DATA0
,
2502 /* IBSS uses different parameters for Beacon sending */
2506 local
->ops
->conf_tx(local_to_hw(local
),
2507 IEEE80211_TX_QUEUE_BEACON
, &qparam
);
2510 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2511 ifsta
= &sdata
->u
.sta
;
2513 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
2514 ifsta
->prev_bssid_set
= 0;
2515 memcpy(ifsta
->ssid
, ssid
, len
);
2516 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
2517 ifsta
->ssid_len
= len
;
2519 ifsta
->ssid_set
= len
? 1 : 0;
2520 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&& !ifsta
->bssid_set
) {
2521 ifsta
->ibss_join_req
= jiffies
;
2522 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
2523 return ieee80211_sta_find_ibss(dev
, ifsta
);
2529 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
2531 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2532 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2533 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
2534 *len
= ifsta
->ssid_len
;
2539 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
2541 struct ieee80211_sub_if_data
*sdata
;
2542 struct ieee80211_if_sta
*ifsta
;
2545 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2546 ifsta
= &sdata
->u
.sta
;
2548 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
2549 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
2550 res
= ieee80211_if_config(dev
);
2552 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
2553 "the low-level driver\n", dev
->name
);
2558 if (!is_valid_ether_addr(bssid
))
2559 ifsta
->bssid_set
= 0;
2561 ifsta
->bssid_set
= 1;
2566 static void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
2567 struct ieee80211_sub_if_data
*sdata
,
2570 struct sk_buff
*skb
;
2571 struct ieee80211_hdr
*nullfunc
;
2574 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 24);
2576 printk(KERN_DEBUG
"%s: failed to allocate buffer for nullfunc "
2577 "frame\n", sdata
->dev
->name
);
2580 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2582 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 24);
2583 memset(nullfunc
, 0, 24);
2584 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
2585 IEEE80211_FCTL_TODS
;
2587 fc
|= IEEE80211_FCTL_PM
;
2588 nullfunc
->frame_control
= cpu_to_le16(fc
);
2589 memcpy(nullfunc
->addr1
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
2590 memcpy(nullfunc
->addr2
, sdata
->dev
->dev_addr
, ETH_ALEN
);
2591 memcpy(nullfunc
->addr3
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
2593 ieee80211_sta_tx(sdata
->dev
, skb
, 0);
2597 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
2599 struct ieee80211_local
*local
= hw_to_local(hw
);
2600 struct net_device
*dev
= local
->scan_dev
;
2601 struct ieee80211_sub_if_data
*sdata
;
2602 union iwreq_data wrqu
;
2604 local
->last_scan_completed
= jiffies
;
2606 local
->sta_scanning
= 0;
2608 if (ieee80211_hw_config(local
))
2609 printk(KERN_DEBUG
"%s: failed to restore operational"
2610 "channel after scan\n", dev
->name
);
2612 if (!(local
->hw
.flags
& IEEE80211_HW_NO_PROBE_FILTERING
) &&
2613 ieee80211_if_config(dev
))
2614 printk(KERN_DEBUG
"%s: failed to restore operational"
2615 "BSSID after scan\n", dev
->name
);
2617 memset(&wrqu
, 0, sizeof(wrqu
));
2618 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2620 read_lock(&local
->sub_if_lock
);
2621 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2623 /* No need to wake the master device. */
2624 if (sdata
->dev
== local
->mdev
)
2627 if (sdata
->type
== IEEE80211_IF_TYPE_STA
) {
2628 if (sdata
->u
.sta
.associated
)
2629 ieee80211_send_nullfunc(local
, sdata
, 0);
2630 ieee80211_sta_timer((unsigned long)sdata
);
2633 netif_wake_queue(sdata
->dev
);
2635 read_unlock(&local
->sub_if_lock
);
2637 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2638 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2639 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2640 if (!ifsta
->bssid_set
||
2641 (!ifsta
->state
== IEEE80211_IBSS_JOINED
&&
2642 !ieee80211_sta_active_ibss(dev
)))
2643 ieee80211_sta_find_ibss(dev
, ifsta
);
2646 EXPORT_SYMBOL(ieee80211_scan_completed
);
2648 void ieee80211_sta_scan_work(struct work_struct
*work
)
2650 struct ieee80211_local
*local
=
2651 container_of(work
, struct ieee80211_local
, scan_work
.work
);
2652 struct net_device
*dev
= local
->scan_dev
;
2653 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2654 struct ieee80211_hw_mode
*mode
;
2655 struct ieee80211_channel
*chan
;
2657 unsigned long next_delay
= 0;
2659 if (!local
->sta_scanning
)
2662 switch (local
->scan_state
) {
2663 case SCAN_SET_CHANNEL
:
2664 mode
= local
->scan_hw_mode
;
2665 if (local
->scan_hw_mode
->list
.next
== &local
->modes_list
&&
2666 local
->scan_channel_idx
>= mode
->num_channels
) {
2667 ieee80211_scan_completed(local_to_hw(local
));
2670 skip
= !(local
->enabled_modes
& (1 << mode
->mode
));
2671 chan
= &mode
->channels
[local
->scan_channel_idx
];
2672 if (!(chan
->flag
& IEEE80211_CHAN_W_SCAN
) ||
2673 (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&&
2674 !(chan
->flag
& IEEE80211_CHAN_W_IBSS
)) ||
2675 (local
->hw_modes
& local
->enabled_modes
&
2676 (1 << MODE_IEEE80211G
) && mode
->mode
== MODE_IEEE80211B
))
2681 printk(KERN_DEBUG
"%s: scan channel %d (%d MHz)\n",
2682 dev
->name
, chan
->chan
, chan
->freq
);
2685 local
->scan_channel
= chan
;
2686 if (ieee80211_hw_config(local
)) {
2687 printk(KERN_DEBUG
"%s: failed to set channel "
2688 "%d (%d MHz) for scan\n", dev
->name
,
2689 chan
->chan
, chan
->freq
);
2694 local
->scan_channel_idx
++;
2695 if (local
->scan_channel_idx
>= local
->scan_hw_mode
->num_channels
) {
2696 if (local
->scan_hw_mode
->list
.next
!= &local
->modes_list
) {
2697 local
->scan_hw_mode
= list_entry(local
->scan_hw_mode
->list
.next
,
2698 struct ieee80211_hw_mode
,
2700 local
->scan_channel_idx
= 0;
2707 next_delay
= IEEE80211_PROBE_DELAY
+
2708 usecs_to_jiffies(local
->hw
.channel_change_time
);
2709 local
->scan_state
= SCAN_SEND_PROBE
;
2711 case SCAN_SEND_PROBE
:
2712 if (local
->scan_channel
->flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
) {
2713 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
2714 local
->scan_ssid_len
);
2715 next_delay
= IEEE80211_CHANNEL_TIME
;
2717 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
2718 local
->scan_state
= SCAN_SET_CHANNEL
;
2722 if (local
->sta_scanning
)
2723 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
2728 static int ieee80211_sta_start_scan(struct net_device
*dev
,
2729 u8
*ssid
, size_t ssid_len
)
2731 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2732 struct ieee80211_sub_if_data
*sdata
;
2734 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
2737 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
2738 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
2741 * ScanType: ACTIVE, PASSIVE
2742 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
2743 * a Probe frame during active scanning
2745 * MinChannelTime (>= ProbeDelay), in TU
2746 * MaxChannelTime: (>= MinChannelTime), in TU
2749 /* MLME-SCAN.confirm
2751 * ResultCode: SUCCESS, INVALID_PARAMETERS
2754 if (local
->sta_scanning
) {
2755 if (local
->scan_dev
== dev
)
2760 if (local
->ops
->hw_scan
) {
2761 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
2764 local
->sta_scanning
= 1;
2765 local
->scan_dev
= dev
;
2770 local
->sta_scanning
= 1;
2772 read_lock(&local
->sub_if_lock
);
2773 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2775 /* Don't stop the master interface, otherwise we can't transmit
2777 if (sdata
->dev
== local
->mdev
)
2780 netif_stop_queue(sdata
->dev
);
2781 if (sdata
->type
== IEEE80211_IF_TYPE_STA
&&
2782 sdata
->u
.sta
.associated
)
2783 ieee80211_send_nullfunc(local
, sdata
, 1);
2785 read_unlock(&local
->sub_if_lock
);
2788 local
->scan_ssid_len
= ssid_len
;
2789 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
2791 local
->scan_ssid_len
= 0;
2792 local
->scan_state
= SCAN_SET_CHANNEL
;
2793 local
->scan_hw_mode
= list_entry(local
->modes_list
.next
,
2794 struct ieee80211_hw_mode
,
2796 local
->scan_channel_idx
= 0;
2797 local
->scan_dev
= dev
;
2799 if (!(local
->hw
.flags
& IEEE80211_HW_NO_PROBE_FILTERING
) &&
2800 ieee80211_if_config(dev
))
2801 printk(KERN_DEBUG
"%s: failed to set BSSID for scan\n",
2804 /* TODO: start scan as soon as all nullfunc frames are ACKed */
2805 queue_delayed_work(local
->hw
.workqueue
, &local
->scan_work
,
2806 IEEE80211_CHANNEL_TIME
);
2812 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
2814 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2815 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2816 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2818 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2819 return ieee80211_sta_start_scan(dev
, ssid
, ssid_len
);
2821 if (local
->sta_scanning
) {
2822 if (local
->scan_dev
== dev
)
2827 set_bit(IEEE80211_STA_REQ_SCAN
, &ifsta
->request
);
2828 queue_work(local
->hw
.workqueue
, &ifsta
->work
);
2833 ieee80211_sta_scan_result(struct net_device
*dev
,
2834 struct ieee80211_sta_bss
*bss
,
2835 char *current_ev
, char *end_buf
)
2837 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2838 struct iw_event iwe
;
2840 if (time_after(jiffies
,
2841 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
2844 if (!(local
->enabled_modes
& (1 << bss
->hw_mode
)))
2847 if (local
->scan_flags
& IEEE80211_SCAN_WPA_ONLY
&&
2848 !bss
->wpa_ie
&& !bss
->rsn_ie
)
2851 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
&&
2852 (local
->scan_ssid_len
!= bss
->ssid_len
||
2853 memcmp(local
->scan_ssid
, bss
->ssid
, bss
->ssid_len
) != 0))
2856 memset(&iwe
, 0, sizeof(iwe
));
2857 iwe
.cmd
= SIOCGIWAP
;
2858 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
2859 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
2860 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2863 memset(&iwe
, 0, sizeof(iwe
));
2864 iwe
.cmd
= SIOCGIWESSID
;
2865 iwe
.u
.data
.length
= bss
->ssid_len
;
2866 iwe
.u
.data
.flags
= 1;
2867 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2870 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
2871 memset(&iwe
, 0, sizeof(iwe
));
2872 iwe
.cmd
= SIOCGIWMODE
;
2873 if (bss
->capability
& WLAN_CAPABILITY_ESS
)
2874 iwe
.u
.mode
= IW_MODE_MASTER
;
2876 iwe
.u
.mode
= IW_MODE_ADHOC
;
2877 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2881 memset(&iwe
, 0, sizeof(iwe
));
2882 iwe
.cmd
= SIOCGIWFREQ
;
2883 iwe
.u
.freq
.m
= bss
->channel
;
2885 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2887 iwe
.u
.freq
.m
= bss
->freq
* 100000;
2889 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2892 memset(&iwe
, 0, sizeof(iwe
));
2894 iwe
.u
.qual
.qual
= bss
->signal
;
2895 iwe
.u
.qual
.level
= bss
->rssi
;
2896 iwe
.u
.qual
.noise
= bss
->noise
;
2897 iwe
.u
.qual
.updated
= local
->wstats_flags
;
2898 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2901 memset(&iwe
, 0, sizeof(iwe
));
2902 iwe
.cmd
= SIOCGIWENCODE
;
2903 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
2904 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
2906 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
2907 iwe
.u
.data
.length
= 0;
2908 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
2910 if (bss
&& bss
->wpa_ie
) {
2911 memset(&iwe
, 0, sizeof(iwe
));
2912 iwe
.cmd
= IWEVGENIE
;
2913 iwe
.u
.data
.length
= bss
->wpa_ie_len
;
2914 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2918 if (bss
&& bss
->rsn_ie
) {
2919 memset(&iwe
, 0, sizeof(iwe
));
2920 iwe
.cmd
= IWEVGENIE
;
2921 iwe
.u
.data
.length
= bss
->rsn_ie_len
;
2922 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2926 if (bss
&& bss
->supp_rates_len
> 0) {
2927 /* display all supported rates in readable format */
2928 char *p
= current_ev
+ IW_EV_LCP_LEN
;
2931 memset(&iwe
, 0, sizeof(iwe
));
2932 iwe
.cmd
= SIOCGIWRATE
;
2933 /* Those two flags are ignored... */
2934 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
2936 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2937 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
2939 p
= iwe_stream_add_value(current_ev
, p
,
2940 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
2947 buf
= kmalloc(30, GFP_ATOMIC
);
2949 memset(&iwe
, 0, sizeof(iwe
));
2950 iwe
.cmd
= IWEVCUSTOM
;
2951 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
2952 iwe
.u
.data
.length
= strlen(buf
);
2953 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2962 if (!(local
->scan_flags
& IEEE80211_SCAN_EXTRA_INFO
))
2965 buf
= kmalloc(100, GFP_ATOMIC
);
2969 memset(&iwe
, 0, sizeof(iwe
));
2970 iwe
.cmd
= IWEVCUSTOM
;
2971 sprintf(buf
, "bcn_int=%d", bss
->beacon_int
);
2972 iwe
.u
.data
.length
= strlen(buf
);
2973 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2976 memset(&iwe
, 0, sizeof(iwe
));
2977 iwe
.cmd
= IWEVCUSTOM
;
2978 sprintf(buf
, "capab=0x%04x", bss
->capability
);
2979 iwe
.u
.data
.length
= strlen(buf
);
2980 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2991 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
2993 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2994 char *current_ev
= buf
;
2995 char *end_buf
= buf
+ len
;
2996 struct ieee80211_sta_bss
*bss
;
2998 spin_lock_bh(&local
->sta_bss_lock
);
2999 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
3000 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
3001 spin_unlock_bh(&local
->sta_bss_lock
);
3004 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
3007 spin_unlock_bh(&local
->sta_bss_lock
);
3008 return current_ev
- buf
;
3012 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
3014 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3015 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3016 kfree(ifsta
->extra_ie
);
3018 ifsta
->extra_ie
= NULL
;
3019 ifsta
->extra_ie_len
= 0;
3022 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
3023 if (!ifsta
->extra_ie
) {
3024 ifsta
->extra_ie_len
= 0;
3027 memcpy(ifsta
->extra_ie
, ie
, len
);
3028 ifsta
->extra_ie_len
= len
;
3033 struct sta_info
* ieee80211_ibss_add_sta(struct net_device
*dev
,
3034 struct sk_buff
*skb
, u8
*bssid
,
3037 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
3038 struct sta_info
*sta
;
3039 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3041 /* TODO: Could consider removing the least recently used entry and
3042 * allow new one to be added. */
3043 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
3044 if (net_ratelimit()) {
3045 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
3046 "entry " MAC_FMT
"\n", dev
->name
, MAC_ARG(addr
));
3051 printk(KERN_DEBUG
"%s: Adding new IBSS station " MAC_FMT
" (dev=%s)\n",
3052 local
->mdev
->name
, MAC_ARG(addr
), dev
->name
);
3054 sta
= sta_info_add(local
, dev
, addr
, GFP_ATOMIC
);
3058 sta
->supp_rates
= sdata
->u
.sta
.supp_rates_bits
;
3060 rate_control_rate_init(sta
, local
);
3062 return sta
; /* caller will call sta_info_put() */
3066 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
3068 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3069 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3071 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
3074 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
3075 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
3078 ieee80211_send_deauth(dev
, ifsta
, reason
);
3079 ieee80211_set_disassoc(dev
, ifsta
, 1);
3084 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
3086 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3087 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
3089 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
3092 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
3095 if (!ifsta
->associated
)
3098 ieee80211_send_disassoc(dev
, ifsta
, reason
);
3099 ieee80211_set_disassoc(dev
, ifsta
, 0);