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.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 * BSS table: use <BSSID,SSID> as the key to support multi-SSID APs
14 * order BSS list by RSSI(?) ("quality of AP")
15 * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
18 #include <linux/config.h>
19 #include <linux/version.h>
20 #include <linux/if_ether.h>
21 #include <linux/skbuff.h>
22 #include <linux/netdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/wireless.h>
25 #include <linux/random.h>
26 #include <net/iw_handler.h>
27 #include <asm/types.h>
28 #include <asm/delay.h>
30 #include <net/ieee80211.h>
31 #include <net/ieee80211_mgmt.h>
32 #include "ieee80211_i.h"
33 #include "rate_control.h"
34 #include "hostapd_ioctl.h"
36 /* #define IEEE80211_IBSS_DEBUG */
38 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
39 #define IEEE80211_AUTH_MAX_TRIES 3
40 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
41 #define IEEE80211_ASSOC_MAX_TRIES 3
42 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
43 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
44 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
45 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
46 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
47 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
49 #define IEEE80211_PROBE_DELAY (HZ / 33)
50 #define IEEE80211_CHANNEL_TIME (HZ / 33)
51 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
52 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
53 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
54 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
56 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
59 #define IEEE80211_FC(type, stype) cpu_to_le16((type << 2) | (stype << 4))
61 #define ERP_INFO_USE_PROTECTION BIT(1)
63 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
64 u8
*ssid
, size_t ssid_len
);
65 static struct ieee80211_sta_bss
*
66 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
);
67 static void ieee80211_rx_bss_put(struct net_device
*dev
,
68 struct ieee80211_sta_bss
*bss
);
69 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
70 struct ieee80211_if_sta
*ifsta
);
71 static int ieee80211_sta_wep_configured(struct net_device
*dev
);
74 /* Parsed Information Elements */
75 struct ieee802_11_elems
{
99 u8 ext_supp_rates_len
;
106 typedef enum { ParseOK
= 0, ParseUnknown
= 1, ParseFailed
= -1 } ParseRes
;
109 static ParseRes
ieee802_11_parse_elems(u8
*start
, size_t len
,
110 struct ieee802_11_elems
*elems
)
116 memset(elems
, 0, sizeof(*elems
));
128 printk(KERN_DEBUG
"IEEE 802.11 element parse "
129 "failed (id=%d elen=%d left=%d)\n",
138 elems
->ssid_len
= elen
;
140 case WLAN_EID_SUPP_RATES
:
141 elems
->supp_rates
= pos
;
142 elems
->supp_rates_len
= elen
;
144 case WLAN_EID_FH_PARAMS
:
145 elems
->fh_params
= pos
;
146 elems
->fh_params_len
= elen
;
148 case WLAN_EID_DS_PARAMS
:
149 elems
->ds_params
= pos
;
150 elems
->ds_params_len
= elen
;
152 case WLAN_EID_CF_PARAMS
:
153 elems
->cf_params
= pos
;
154 elems
->cf_params_len
= elen
;
158 elems
->tim_len
= elen
;
160 case WLAN_EID_IBSS_PARAMS
:
161 elems
->ibss_params
= pos
;
162 elems
->ibss_params_len
= elen
;
164 case WLAN_EID_CHALLENGE
:
165 elems
->challenge
= pos
;
166 elems
->challenge_len
= elen
;
169 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
171 /* Microsoft OUI (00:50:F2) */
173 /* OUI Type 1 - WPA IE */
175 elems
->wpa_len
= elen
;
176 } else if (elen
>= 5 && pos
[3] == 2) {
178 elems
->wmm_info
= pos
;
179 elems
->wmm_info_len
= elen
;
180 } else if (pos
[4] == 1) {
181 elems
->wmm_param
= pos
;
182 elems
->wmm_param_len
= elen
;
189 elems
->rsn_len
= elen
;
191 case WLAN_EID_ERP_INFO
:
192 elems
->erp_info
= pos
;
193 elems
->erp_info_len
= elen
;
195 case WLAN_EID_EXT_SUPP_RATES
:
196 elems
->ext_supp_rates
= pos
;
197 elems
->ext_supp_rates_len
= elen
;
201 printk(KERN_DEBUG
"IEEE 802.11 element parse ignored "
202 "unknown element (id=%d elen=%d)\n",
216 return unknown
? ParseUnknown
: ParseOK
;
222 static int ecw2cw(int ecw
)
233 static void ieee80211_sta_wmm_params(struct net_device
*dev
,
234 struct ieee80211_if_sta
*ifsta
,
235 u8
*wmm_param
, size_t wmm_param_len
)
237 struct ieee80211_local
*local
= dev
->priv
;
238 struct ieee80211_tx_queue_params params
;
243 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
245 count
= wmm_param
[6] & 0x0f;
246 if (count
== ifsta
->wmm_last_param_set
)
248 ifsta
->wmm_last_param_set
= count
;
251 left
= wmm_param_len
- 8;
253 memset(¶ms
, 0, sizeof(params
));
255 if (local
->hw
->conf_tx
== NULL
)
259 for (; left
>= 4; left
-= 4, pos
+= 4) {
260 int aci
= (pos
[0] >> 5) & 0x03;
261 int acm
= (pos
[0] >> 4) & 0x01;
266 queue
= IEEE80211_TX_QUEUE_DATA3
;
268 local
->wmm_acm
|= BIT(1) | BIT(2);
272 queue
= IEEE80211_TX_QUEUE_DATA1
;
274 local
->wmm_acm
|= BIT(4) | BIT(5);
278 queue
= IEEE80211_TX_QUEUE_DATA0
;
280 local
->wmm_acm
|= BIT(6) | BIT(7);
285 queue
= IEEE80211_TX_QUEUE_DATA2
;
287 local
->wmm_acm
|= BIT(0) | BIT(3);
292 params
.aifs
= pos
[0] & 0x0f;
293 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
294 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
295 /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
296 params
.burst_time
= (pos
[2] | (pos
[3] << 8)) * 32 / 100;
297 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
298 "cWmin=%d cWmax=%d burst=%d\n",
299 dev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
300 params
.cw_max
, params
.burst_time
);
301 /* TODO: handle ACM (block TX, fallback to next lowest allowed
303 if (local
->hw
->conf_tx(local
->mdev
, queue
, ¶ms
)) {
304 printk(KERN_DEBUG
"%s: failed to set TX queue "
305 "parameters for queue %d\n", dev
->name
, queue
);
311 static void ieee80211_sta_send_associnfo(struct net_device
*dev
,
312 struct ieee80211_if_sta
*ifsta
)
317 union iwreq_data wrqu
;
319 if (ifsta
->assocreq_ies
== NULL
&& ifsta
->assocresp_ies
== NULL
)
322 buf
= kmalloc(50 + 2 * (ifsta
->assocreq_ies_len
+
323 ifsta
->assocresp_ies_len
), GFP_ATOMIC
);
327 len
= sprintf(buf
, "ASSOCINFO(");
328 if (ifsta
->assocreq_ies
) {
329 len
+= sprintf(buf
+ len
, "ReqIEs=");
330 for (i
= 0; i
< ifsta
->assocreq_ies_len
; i
++) {
331 len
+= sprintf(buf
+ len
, "%02x",
332 ifsta
->assocreq_ies
[i
]);
335 if (ifsta
->assocresp_ies
) {
336 if (ifsta
->assocreq_ies
)
337 len
+= sprintf(buf
+ len
, " ");
338 len
+= sprintf(buf
+ len
, "RespIEs=");
339 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
340 len
+= sprintf(buf
+ len
, "%02x",
341 ifsta
->assocresp_ies
[i
]);
344 len
+= sprintf(buf
+ len
, ")");
346 if (len
> IW_CUSTOM_MAX
) {
347 len
= sprintf(buf
, "ASSOCRESPIE=");
348 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
349 len
+= sprintf(buf
+ len
, "%02x",
350 ifsta
->assocresp_ies
[i
]);
354 memset(&wrqu
, 0, sizeof(wrqu
));
355 wrqu
.data
.length
= len
;
356 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
362 static void ieee80211_set_associated(struct net_device
*dev
,
363 struct ieee80211_if_sta
*ifsta
, int assoc
)
365 union iwreq_data wrqu
;
367 if (ifsta
->associated
== assoc
)
370 ifsta
->associated
= assoc
;
373 struct ieee80211_sub_if_data
*sdata
;
374 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
375 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
377 ifsta
->prev_bssid_set
= 1;
378 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
379 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
380 ieee80211_sta_send_associnfo(dev
, ifsta
);
382 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
384 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
385 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
386 ifsta
->last_probe
= jiffies
;
390 static void ieee80211_sta_tx(struct net_device
*dev
, struct sk_buff
*skb
,
391 int encrypt
, int probe_resp
)
393 struct ieee80211_sub_if_data
*sdata
;
394 struct ieee80211_tx_packet_data
*pkt_data
;
396 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
397 skb
->dev
= sdata
->master
;
398 skb
->mac
.raw
= skb
->nh
.raw
= skb
->h
.raw
= skb
->data
;
400 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
401 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
402 pkt_data
->magic
= IEEE80211_CB_MAGIC
;
403 pkt_data
->sdata
= sdata
;
404 pkt_data
->control
.do_not_encrypt
= !encrypt
;
406 pkt_data
->control
.pkt_type
= PKT_PROBE_RESP
;
412 static void ieee80211_send_auth(struct net_device
*dev
,
413 struct ieee80211_if_sta
*ifsta
,
414 int transaction
, u8
*extra
, size_t extra_len
,
418 struct ieee80211_mgmt
*mgmt
;
420 skb
= dev_alloc_skb(sizeof(*mgmt
) + 6 + extra_len
);
422 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
423 "frame\n", dev
->name
);
427 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
428 memset(mgmt
, 0, 24 + 6);
429 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
432 mgmt
->frame_control
|= cpu_to_le16(WLAN_FC_ISWEP
);
433 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
434 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
435 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
436 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
437 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
438 ifsta
->auth_transaction
= transaction
+ 1;
439 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
441 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
443 ieee80211_sta_tx(dev
, skb
, encrypt
, 0);
447 static void ieee80211_authenticate(struct net_device
*dev
,
448 struct ieee80211_if_sta
*ifsta
)
451 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
452 printk(KERN_DEBUG
"%s: authentication with AP " MACSTR
454 dev
->name
, MAC2STR(ifsta
->bssid
));
458 ifsta
->state
= IEEE80211_AUTHENTICATE
;
459 printk(KERN_DEBUG
"%s: authenticate with AP " MACSTR
"\n",
460 dev
->name
, MAC2STR(ifsta
->bssid
));
462 ieee80211_send_auth(dev
, ifsta
, 1, NULL
, 0, 0);
464 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_AUTH_TIMEOUT
);
468 static void ieee80211_send_assoc(struct net_device
*dev
,
469 struct ieee80211_if_sta
*ifsta
)
471 struct ieee80211_local
*local
= dev
->priv
;
473 struct ieee80211_mgmt
*mgmt
;
477 struct ieee80211_sta_bss
*bss
;
480 skb
= dev_alloc_skb(sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
483 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
484 "frame\n", dev
->name
);
488 capab
= ifsta
->capab
;
489 if (local
->conf
.phymode
== MODE_IEEE80211G
) {
490 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
|
491 WLAN_CAPABILITY_SHORT_PREAMBLE
;
493 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
495 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
496 capab
|= WLAN_CAPABILITY_PRIVACY
;
500 ieee80211_rx_bss_put(dev
, bss
);
503 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
505 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
506 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
507 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
509 if (ifsta
->prev_bssid_set
) {
511 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
512 WLAN_FC_STYPE_REASSOC_REQ
);
513 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
514 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
515 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
519 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
520 WLAN_FC_STYPE_ASSOC_REQ
);
521 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
522 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
526 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
527 *pos
++ = WLAN_EID_SSID
;
528 *pos
++ = ifsta
->ssid_len
;
529 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
531 len
= local
->num_curr_rates
;
534 pos
= skb_put(skb
, len
+ 2);
535 *pos
++ = WLAN_EID_SUPP_RATES
;
537 for (i
= 0; i
< len
; i
++) {
538 int rate
= local
->curr_rates
[i
].rate
;
539 if (local
->conf
.phymode
== MODE_ATHEROS_TURBO
)
541 *pos
++ = (u8
) (rate
/ 5);
544 if (local
->num_curr_rates
> len
) {
545 pos
= skb_put(skb
, local
->num_curr_rates
- len
+ 2);
546 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
547 *pos
++ = local
->num_curr_rates
- len
;
548 for (i
= len
; i
< local
->num_curr_rates
; i
++) {
549 int rate
= local
->curr_rates
[i
].rate
;
550 if (local
->conf
.phymode
== MODE_ATHEROS_TURBO
)
552 *pos
++ = (u8
) (rate
/ 5);
556 if (ifsta
->extra_ie
) {
557 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
558 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
561 if (wmm
&& ifsta
->wmm_enabled
) {
562 pos
= skb_put(skb
, 9);
563 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
564 *pos
++ = 7; /* len */
565 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
568 *pos
++ = 2; /* WME */
569 *pos
++ = 0; /* WME info */
570 *pos
++ = 1; /* WME ver */
574 kfree(ifsta
->assocreq_ies
);
575 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
576 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_ATOMIC
);
577 if (ifsta
->assocreq_ies
)
578 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
580 ieee80211_sta_tx(dev
, skb
, 0, 0);
584 static void ieee80211_send_deauth(struct net_device
*dev
,
585 struct ieee80211_if_sta
*ifsta
, u16 reason
)
588 struct ieee80211_mgmt
*mgmt
;
590 skb
= dev_alloc_skb(sizeof(*mgmt
));
592 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
593 "frame\n", dev
->name
);
597 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
599 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
600 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
601 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
602 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
603 WLAN_FC_STYPE_DEAUTH
);
605 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
607 ieee80211_sta_tx(dev
, skb
, 0, 0);
611 static void ieee80211_send_disassoc(struct net_device
*dev
,
612 struct ieee80211_if_sta
*ifsta
, u16 reason
)
615 struct ieee80211_mgmt
*mgmt
;
617 skb
= dev_alloc_skb(sizeof(*mgmt
));
619 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
620 "frame\n", dev
->name
);
624 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
626 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
627 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
628 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
629 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
630 WLAN_FC_STYPE_DISASSOC
);
632 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
634 ieee80211_sta_tx(dev
, skb
, 0, 0);
638 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
639 struct ieee80211_if_sta
*ifsta
)
641 struct ieee80211_sta_bss
*bss
;
644 if (ifsta
== NULL
|| ifsta
->mixed_cell
||
645 ifsta
->key_mgmt
!= IEEE80211_KEY_MGMT_NONE
)
648 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
652 if (ieee80211_sta_wep_configured(dev
) !=
653 !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
))
656 ieee80211_rx_bss_put(dev
, bss
);
662 static void ieee80211_associate(struct net_device
*dev
,
663 struct ieee80211_if_sta
*ifsta
)
665 ifsta
->assoc_tries
++;
666 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
667 printk(KERN_DEBUG
"%s: association with AP " MACSTR
669 dev
->name
, MAC2STR(ifsta
->bssid
));
673 ifsta
->state
= IEEE80211_ASSOCIATE
;
674 printk(KERN_DEBUG
"%s: associate with AP " MACSTR
"\n",
675 dev
->name
, MAC2STR(ifsta
->bssid
));
676 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
677 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
678 "mixed-cell disabled - abort association\n", dev
->name
);
682 ieee80211_send_assoc(dev
, ifsta
);
684 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_ASSOC_TIMEOUT
);
688 static void ieee80211_associated(struct net_device
*dev
,
689 struct ieee80211_if_sta
*ifsta
)
691 struct ieee80211_local
*local
= dev
->priv
;
692 struct sta_info
*sta
;
695 /* TODO: start monitoring current AP signal quality and number of
696 * missed beacons. Scan other channels every now and then and search
698 /* TODO: remove expired BSSes */
700 ifsta
->state
= IEEE80211_ASSOCIATED
;
702 sta
= sta_info_get(local
, ifsta
->bssid
);
704 printk(KERN_DEBUG
"%s: No STA entry for own AP " MACSTR
"\n",
705 dev
->name
, MAC2STR(ifsta
->bssid
));
709 if (time_after(jiffies
,
710 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
711 if (ifsta
->probereq_poll
) {
712 printk(KERN_DEBUG
"%s: No ProbeResp from "
713 "current AP " MACSTR
" - assume out of "
715 dev
->name
, MAC2STR(ifsta
->bssid
));
718 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
720 local
->scan_ssid_len
);
721 ifsta
->probereq_poll
= 1;
724 ifsta
->probereq_poll
= 0;
725 if (time_after(jiffies
, ifsta
->last_probe
+
726 IEEE80211_PROBE_INTERVAL
)) {
727 ifsta
->last_probe
= jiffies
;
728 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
733 sta_info_release(local
, sta
);
736 union iwreq_data wrqu
;
737 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
738 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
739 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
740 mod_timer(&ifsta
->timer
,
741 jiffies
+ IEEE80211_MONITORING_INTERVAL
+ 30 * HZ
);
743 mod_timer(&ifsta
->timer
,
744 jiffies
+ IEEE80211_MONITORING_INTERVAL
);
749 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
750 u8
*ssid
, size_t ssid_len
)
752 struct ieee80211_local
*local
= dev
->priv
;
754 struct ieee80211_mgmt
*mgmt
;
755 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
758 skb
= dev_alloc_skb(sizeof(*mgmt
) + 200);
760 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
761 "request\n", dev
->name
);
765 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
767 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
768 WLAN_FC_STYPE_PROBE_REQ
);
769 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
771 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
772 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
774 memset(mgmt
->da
, 0xff, ETH_ALEN
);
775 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
777 pos
= skb_put(skb
, 2 + ssid_len
);
778 *pos
++ = WLAN_EID_SSID
;
780 memcpy(pos
, ssid
, ssid_len
);
782 supp_rates
= skb_put(skb
, 2);
783 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
785 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
786 struct ieee80211_rate
*rate
= &local
->curr_rates
[i
];
787 if (!(rate
->flags
& IEEE80211_RATE_SUPPORTED
))
790 pos
= skb_put(skb
, 1);
792 } else if (supp_rates
[1] == 8) {
793 esupp_rates
= skb_put(skb
, 3);
794 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
796 pos
= &esupp_rates
[2];
798 pos
= skb_put(skb
, 1);
801 if (local
->conf
.phymode
== MODE_ATHEROS_TURBO
)
802 *pos
= rate
->rate
/ 10;
804 *pos
= rate
->rate
/ 5;
807 ieee80211_sta_tx(dev
, skb
, 0, 0);
811 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
813 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
814 if (sdata
== NULL
|| sdata
->default_key
== NULL
||
815 sdata
->default_key
->alg
!= ALG_WEP
)
821 static void ieee80211_auth_completed(struct net_device
*dev
,
822 struct ieee80211_if_sta
*ifsta
)
824 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
825 ifsta
->authenticated
= 1;
826 ieee80211_associate(dev
, ifsta
);
830 static void ieee80211_auth_challenge(struct net_device
*dev
,
831 struct ieee80211_if_sta
*ifsta
,
832 struct ieee80211_mgmt
*mgmt
,
834 struct ieee80211_rx_status
*rx_status
)
837 struct ieee802_11_elems elems
;
839 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
840 pos
= mgmt
->u
.auth
.variable
;
841 if (ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
)
843 printk(KERN_DEBUG
"%s: failed to parse Auth(challenge)\n",
847 if (elems
.challenge
== NULL
) {
848 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
849 "frame\n", dev
->name
);
852 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
853 elems
.challenge_len
+ 2, 1);
857 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
858 struct ieee80211_if_sta
*ifsta
,
859 struct ieee80211_mgmt
*mgmt
,
861 struct ieee80211_rx_status
*rx_status
)
863 struct ieee80211_local
*local
= dev
->priv
;
864 u16 auth_alg
, auth_transaction
, status_code
;
866 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
867 local
->conf
.mode
!= IW_MODE_ADHOC
) {
868 printk(KERN_DEBUG
"%s: authentication frame received from "
869 MACSTR
", but not in authenticate state - ignored\n",
870 dev
->name
, MAC2STR(mgmt
->sa
));
875 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
876 "received from " MACSTR
" - ignored\n",
877 dev
->name
, len
, MAC2STR(mgmt
->sa
));
881 if (local
->conf
.mode
!= IW_MODE_ADHOC
&&
882 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
883 printk(KERN_DEBUG
"%s: authentication frame received from "
884 "unknown AP (SA=" MACSTR
" BSSID=" MACSTR
") - "
885 "ignored\n", dev
->name
, MAC2STR(mgmt
->sa
),
886 MAC2STR(mgmt
->bssid
));
890 if (local
->conf
.mode
== IW_MODE_ADHOC
&&
891 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
892 printk(KERN_DEBUG
"%s: authentication frame received from "
893 "unknown BSSID (SA=" MACSTR
" BSSID=" MACSTR
") - "
894 "ignored\n", dev
->name
, MAC2STR(mgmt
->sa
),
895 MAC2STR(mgmt
->bssid
));
899 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
900 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
901 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
903 printk(KERN_DEBUG
"%s: RX authentication from " MACSTR
" (alg=%d "
904 "transaction=%d status=%d)\n",
905 dev
->name
, MAC2STR(mgmt
->sa
), auth_alg
,
906 auth_transaction
, status_code
);
908 if (local
->conf
.mode
== IW_MODE_ADHOC
) {
909 /* IEEE 802.11 standard does not require authentication in IBSS
910 * networks and most implementations do not seem to use it.
911 * However, try to reply to authentication attempts if someone
912 * has actually implemented this.
913 * TODO: Could implement shared key authentication. */
914 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
915 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
916 "frame (alg=%d transaction=%d)\n",
917 dev
->name
, auth_alg
, auth_transaction
);
920 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
923 if (auth_alg
!= ifsta
->auth_alg
||
924 auth_transaction
!= ifsta
->auth_transaction
) {
925 printk(KERN_DEBUG
"%s: unexpected authentication frame "
926 "(alg=%d transaction=%d)\n",
927 dev
->name
, auth_alg
, auth_transaction
);
931 if (status_code
!= WLAN_STATUS_SUCCESS
) {
932 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
933 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
934 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
935 const int num_algs
= 3;
938 algs
[0] = algs
[1] = algs
[2] = 0xff;
939 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
940 algs
[0] = WLAN_AUTH_OPEN
;
941 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
942 algs
[1] = WLAN_AUTH_SHARED_KEY
;
943 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
944 algs
[2] = WLAN_AUTH_LEAP
;
945 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
947 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
951 for (i
= 0; i
< num_algs
; i
++) {
955 if (algs
[pos
] == ifsta
->auth_alg
||
958 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
959 !ieee80211_sta_wep_configured(dev
))
961 ifsta
->auth_alg
= algs
[pos
];
962 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
964 dev
->name
, ifsta
->auth_alg
);
971 switch (ifsta
->auth_alg
) {
974 ieee80211_auth_completed(dev
, ifsta
);
976 case WLAN_AUTH_SHARED_KEY
:
977 if (ifsta
->auth_transaction
== 4)
978 ieee80211_auth_completed(dev
, ifsta
);
980 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
,
987 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
988 struct ieee80211_if_sta
*ifsta
,
989 struct ieee80211_mgmt
*mgmt
,
991 struct ieee80211_rx_status
*rx_status
)
996 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
997 "received from " MACSTR
" - ignored\n",
998 dev
->name
, len
, MAC2STR(mgmt
->sa
));
1002 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1003 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1004 "unknown AP (SA=" MACSTR
" BSSID=" MACSTR
") - "
1005 "ignored\n", dev
->name
, MAC2STR(mgmt
->sa
),
1006 MAC2STR(mgmt
->bssid
));
1010 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1012 printk(KERN_DEBUG
"%s: RX deauthentication from " MACSTR
1014 dev
->name
, MAC2STR(mgmt
->sa
), reason_code
);
1016 if (ifsta
->authenticated
) {
1017 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1020 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1021 ifsta
->state
== IEEE80211_ASSOCIATE
||
1022 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1023 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1024 mod_timer(&ifsta
->timer
,
1025 jiffies
+ IEEE80211_RETRY_AUTH_INTERVAL
);
1028 ieee80211_set_associated(dev
, ifsta
, 0);
1029 ifsta
->authenticated
= 0;
1033 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1034 struct ieee80211_if_sta
*ifsta
,
1035 struct ieee80211_mgmt
*mgmt
,
1037 struct ieee80211_rx_status
*rx_status
)
1042 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1043 "received from " MACSTR
" - ignored\n",
1044 dev
->name
, len
, MAC2STR(mgmt
->sa
));
1048 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1049 printk(KERN_DEBUG
"%s: disassociation frame received from "
1050 "unknown AP (SA=" MACSTR
" BSSID=" MACSTR
") - "
1051 "ignored\n", dev
->name
, MAC2STR(mgmt
->sa
),
1052 MAC2STR(mgmt
->bssid
));
1056 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1058 printk(KERN_DEBUG
"%s: RX disassociation from " MACSTR
1060 dev
->name
, MAC2STR(mgmt
->sa
), reason_code
);
1062 if (ifsta
->associated
)
1063 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1065 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1066 ifsta
->state
= IEEE80211_ASSOCIATE
;
1067 mod_timer(&ifsta
->timer
,
1068 jiffies
+ IEEE80211_RETRY_AUTH_INTERVAL
);
1071 ieee80211_set_associated(dev
, ifsta
, 0);
1075 static void ieee80211_rx_mgmt_assoc_resp(struct net_device
*dev
,
1076 struct ieee80211_if_sta
*ifsta
,
1077 struct ieee80211_mgmt
*mgmt
,
1079 struct ieee80211_rx_status
*rx_status
,
1082 struct ieee80211_local
*local
= dev
->priv
;
1083 struct sta_info
*sta
;
1085 u16 capab_info
, status_code
, aid
;
1086 struct ieee802_11_elems elems
;
1090 /* AssocResp and ReassocResp have identical structure, so process both
1091 * of them in this function. */
1093 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1094 printk(KERN_DEBUG
"%s: association frame received from "
1095 MACSTR
", but not in associate state - ignored\n",
1096 dev
->name
, MAC2STR(mgmt
->sa
));
1101 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1102 "received from " MACSTR
" - ignored\n",
1103 dev
->name
, len
, MAC2STR(mgmt
->sa
));
1107 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1108 printk(KERN_DEBUG
"%s: association frame received from "
1109 "unknown AP (SA=" MACSTR
" BSSID=" MACSTR
") - "
1110 "ignored\n", dev
->name
, MAC2STR(mgmt
->sa
),
1111 MAC2STR(mgmt
->bssid
));
1115 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1116 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1117 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1118 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1119 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1120 "set\n", dev
->name
, aid
);
1121 aid
&= ~(BIT(15) | BIT(14));
1123 printk(KERN_DEBUG
"%s: RX %sssocResp from " MACSTR
" (capab=0x%x "
1124 "status=%d aid=%d)\n",
1125 dev
->name
, reassoc
? "Rea" : "A", MAC2STR(mgmt
->sa
),
1126 capab_info
, status_code
, aid
);
1128 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1129 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1130 dev
->name
, status_code
);
1134 pos
= mgmt
->u
.assoc_resp
.variable
;
1135 if (ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
)
1137 printk(KERN_DEBUG
"%s: failed to parse AssocResp\n",
1142 if (elems
.supp_rates
== NULL
) {
1143 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1148 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1150 ifsta
->ap_capab
= capab_info
;
1152 kfree(ifsta
->assocresp_ies
);
1153 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1154 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_ATOMIC
);
1155 if (ifsta
->assocresp_ies
)
1156 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1158 ieee80211_set_associated(dev
, ifsta
, 1);
1160 /* Add STA entry for the AP */
1161 sta
= sta_info_get(local
, ifsta
->bssid
);
1163 sta
= sta_info_add(local
, dev
, ifsta
->bssid
);
1165 printk(KERN_DEBUG
"%s: failed to add STA entry for the"
1166 " AP\n", dev
->name
);
1172 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
1176 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
1177 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
1178 if (local
->conf
.phymode
== MODE_ATHEROS_TURBO
)
1180 for (j
= 0; j
< local
->num_curr_rates
; j
++)
1181 if (local
->curr_rates
[j
].rate
== rate
)
1184 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
1185 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
1186 if (local
->conf
.phymode
== MODE_ATHEROS_TURBO
)
1188 for (j
= 0; j
< local
->num_curr_rates
; j
++)
1189 if (local
->curr_rates
[j
].rate
== rate
)
1192 sta
->supp_rates
= rates
;
1194 rate_control_rate_init(local
, sta
);
1196 if (elems
.wmm_param
&& ifsta
->wmm_enabled
) {
1197 sta
->flags
|= WLAN_STA_WME
;
1198 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
1199 elems
.wmm_param_len
);
1203 sta_info_release(local
, sta
);
1205 ieee80211_associated(dev
, ifsta
);
1209 /* Caller must hold local->sta_bss_lock */
1210 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
1211 struct ieee80211_sta_bss
*bss
)
1213 struct ieee80211_local
*local
= dev
->priv
;
1214 bss
->hnext
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1215 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] = bss
;
1219 /* Caller must hold local->sta_bss_lock */
1220 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
1221 struct ieee80211_sta_bss
*bss
)
1223 struct ieee80211_local
*local
= dev
->priv
;
1224 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
1225 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1229 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
1232 prev
->hnext
= bss
->hnext
;
1242 static struct ieee80211_sta_bss
*
1243 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
)
1245 struct ieee80211_local
*local
= dev
->priv
;
1246 struct ieee80211_sta_bss
*bss
;
1248 bss
= kmalloc(sizeof(*bss
), GFP_ATOMIC
);
1251 memset(bss
, 0, sizeof(*bss
));
1252 atomic_inc(&bss
->users
);
1253 atomic_inc(&bss
->users
);
1254 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
1256 spin_lock_bh(&local
->sta_bss_lock
);
1257 /* TODO: order by RSSI? */
1258 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
1259 __ieee80211_rx_bss_hash_add(dev
, bss
);
1260 spin_unlock_bh(&local
->sta_bss_lock
);
1265 static struct ieee80211_sta_bss
*
1266 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
)
1268 struct ieee80211_local
*local
= dev
->priv
;
1269 struct ieee80211_sta_bss
*bss
;
1271 spin_lock_bh(&local
->sta_bss_lock
);
1272 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
1274 if (memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0) {
1275 atomic_inc(&bss
->users
);
1280 spin_unlock_bh(&local
->sta_bss_lock
);
1285 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
1294 static void ieee80211_rx_bss_put(struct net_device
*dev
,
1295 struct ieee80211_sta_bss
*bss
)
1297 struct ieee80211_local
*local
= dev
->priv
;
1298 if (!atomic_dec_and_test(&bss
->users
))
1301 spin_lock_bh(&local
->sta_bss_lock
);
1302 __ieee80211_rx_bss_hash_del(dev
, bss
);
1303 list_del(&bss
->list
);
1304 spin_unlock_bh(&local
->sta_bss_lock
);
1305 ieee80211_rx_bss_free(bss
);
1309 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
1311 struct ieee80211_local
*local
= dev
->priv
;
1312 spin_lock_init(&local
->sta_bss_lock
);
1313 INIT_LIST_HEAD(&local
->sta_bss_list
);
1317 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
1319 struct ieee80211_local
*local
= dev
->priv
;
1320 struct ieee80211_sta_bss
*bss
;
1321 struct list_head
*ptr
;
1324 ptr
= local
->sta_bss_list
.next
;
1325 if (!ptr
|| ptr
== &local
->sta_bss_list
)
1327 bss
= list_entry(ptr
, struct ieee80211_sta_bss
, list
);
1328 ieee80211_rx_bss_put(dev
, bss
);
1333 static void ieee80211_rx_bss_info(struct net_device
*dev
,
1334 struct ieee80211_mgmt
*mgmt
,
1336 struct ieee80211_rx_status
*rx_status
,
1339 struct ieee80211_local
*local
= dev
->priv
;
1340 struct ieee802_11_elems elems
;
1342 int channel
, invalid
= 0, clen
;
1343 struct ieee80211_sta_bss
*bss
;
1344 struct sta_info
*sta
;
1345 struct ieee80211_sub_if_data
*sdata
;
1349 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
1350 return; /* ignore ProbeResp to foreign address */
1353 printk(KERN_DEBUG
"%s: RX %s from " MACSTR
" to " MACSTR
"\n",
1354 dev
->name
, beacon
? "Beacon" : "Probe Response",
1355 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
));
1358 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1362 pos
= mgmt
->u
.beacon
.timestamp
;
1363 timestamp
= ((u64
) pos
[7] << 56) | ((u64
) pos
[6] << 48) |
1364 ((u64
) pos
[5] << 40) | ((u64
) pos
[4] << 32) |
1365 ((u64
) pos
[3] << 24) | ((u64
) pos
[2] << 16) |
1366 ((u64
) pos
[1] << 8) | ((u64
) pos
[0]);
1368 if (local
->conf
.mode
== IW_MODE_ADHOC
&& beacon
&&
1369 memcmp(mgmt
->bssid
, local
->bssid
, ETH_ALEN
) == 0) {
1370 #ifdef IEEE80211_IBSS_DEBUG
1371 static unsigned long last_tsf_debug
= 0;
1373 if (local
->hw
->get_tsf
)
1374 tsf
= local
->hw
->get_tsf(local
->mdev
);
1377 if (time_after(jiffies
, last_tsf_debug
+ 5 * HZ
)) {
1378 printk(KERN_DEBUG
"RX beacon SA=" MACSTR
" BSSID="
1379 MACSTR
" TSF=0x%llx BCN=0x%llx diff=%lld "
1381 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->bssid
),
1382 tsf
, timestamp
, tsf
- timestamp
, jiffies
);
1383 last_tsf_debug
= jiffies
;
1385 #endif /* IEEE80211_IBSS_DEBUG */
1388 if (ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
,
1389 &elems
) == ParseFailed
)
1392 if (local
->conf
.mode
== IW_MODE_ADHOC
&& elems
.supp_rates
&&
1393 memcmp(mgmt
->bssid
, local
->bssid
, ETH_ALEN
) == 0 &&
1394 (sta
= sta_info_get(local
, mgmt
->sa
)) &&
1395 (sdata
= IEEE80211_DEV_TO_SUB_IF(dev
)) &&
1396 sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
1397 struct ieee80211_rate
*rates
;
1399 u32 supp_rates
, prev_rates
;
1400 int i
, j
, oper_mode
;
1402 rates
= local
->curr_rates
;
1403 num_rates
= local
->num_curr_rates
;
1404 oper_mode
= local
->sta_scanning
? local
->scan_oper_phymode
:
1405 local
->conf
.phymode
;
1406 for (i
= 0; i
< local
->hw
->num_modes
; i
++) {
1407 struct ieee80211_hw_modes
*mode
= &local
->hw
->modes
[i
];
1408 if (oper_mode
== mode
->mode
) {
1409 rates
= mode
->rates
;
1410 num_rates
= mode
->num_rates
;
1416 for (i
= 0; i
< elems
.supp_rates_len
+
1417 elems
.ext_supp_rates_len
; i
++) {
1420 if (i
< elems
.supp_rates_len
)
1421 rate
= elems
.supp_rates
[i
];
1422 else if (elems
.ext_supp_rates
)
1423 rate
= elems
.ext_supp_rates
1424 [i
- elems
.supp_rates_len
];
1425 own_rate
= 5 * (rate
& 0x7f);
1426 if (oper_mode
== MODE_ATHEROS_TURBO
)
1428 for (j
= 0; j
< num_rates
; j
++)
1429 if (rates
[j
].rate
== own_rate
)
1430 supp_rates
|= BIT(j
);
1433 prev_rates
= sta
->supp_rates
;
1434 sta
->supp_rates
&= supp_rates
;
1435 if (sta
->supp_rates
== 0) {
1436 /* No matching rates - this should not really happen.
1437 * Make sure that at least one rate is marked
1438 * supported to avoid issues with TX rate ctrl. */
1440 sta
->supp_rates
= sdata
->u
.sta
.supp_rates_bits
;
1442 if (sta
->supp_rates
!= prev_rates
) {
1443 printk(KERN_DEBUG
"%s: updated supp_rates set for "
1444 MACSTR
" based on beacon info (0x%x & 0x%x -> "
1446 dev
->name
, MAC2STR(sta
->addr
), prev_rates
,
1447 supp_rates
, sta
->supp_rates
);
1449 sta_info_release(local
, sta
);
1452 if (elems
.ssid
== NULL
)
1455 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
1456 channel
= elems
.ds_params
[0];
1458 channel
= rx_status
->channel
;
1460 bss
= ieee80211_rx_bss_get(dev
, mgmt
->bssid
);
1462 bss
= ieee80211_rx_bss_add(dev
, mgmt
->bssid
);
1467 /* TODO: order by RSSI? */
1468 spin_lock_bh(&local
->sta_bss_lock
);
1469 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
1470 spin_unlock_bh(&local
->sta_bss_lock
);
1474 if (bss
->probe_resp
&& beacon
) {
1475 /* Do not allow beacon to override data from Probe Response. */
1476 ieee80211_rx_bss_put(dev
, bss
);
1480 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
1481 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
1482 if (elems
.ssid
&& elems
.ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
1483 memcpy(bss
->ssid
, elems
.ssid
, elems
.ssid_len
);
1484 bss
->ssid_len
= elems
.ssid_len
;
1487 bss
->supp_rates_len
= 0;
1488 if (elems
.supp_rates
) {
1489 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
1490 if (clen
> elems
.supp_rates_len
)
1491 clen
= elems
.supp_rates_len
;
1492 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
.supp_rates
,
1494 bss
->supp_rates_len
+= clen
;
1496 if (elems
.ext_supp_rates
) {
1497 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
1498 if (clen
> elems
.ext_supp_rates_len
)
1499 clen
= elems
.ext_supp_rates_len
;
1500 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
1501 elems
.ext_supp_rates
, clen
);
1502 bss
->supp_rates_len
+= clen
;
1506 (bss
->wpa_ie
== NULL
|| bss
->wpa_ie_len
!= elems
.wpa_len
||
1507 memcmp(bss
->wpa_ie
, elems
.wpa
, elems
.wpa_len
))) {
1509 bss
->wpa_ie
= kmalloc(elems
.wpa_len
+ 2, GFP_ATOMIC
);
1511 memcpy(bss
->wpa_ie
, elems
.wpa
- 2, elems
.wpa_len
+ 2);
1512 bss
->wpa_ie_len
= elems
.wpa_len
+ 2;
1514 bss
->wpa_ie_len
= 0;
1515 } else if (!elems
.wpa
&& bss
->wpa_ie
) {
1518 bss
->wpa_ie_len
= 0;
1522 (bss
->rsn_ie
== NULL
|| bss
->rsn_ie_len
!= elems
.rsn_len
||
1523 memcmp(bss
->rsn_ie
, elems
.rsn
, elems
.rsn_len
))) {
1525 bss
->rsn_ie
= kmalloc(elems
.rsn_len
+ 2, GFP_ATOMIC
);
1527 memcpy(bss
->rsn_ie
, elems
.rsn
- 2, elems
.rsn_len
+ 2);
1528 bss
->rsn_ie_len
= elems
.rsn_len
+ 2;
1530 bss
->rsn_ie_len
= 0;
1531 } else if (!elems
.rsn
&& bss
->rsn_ie
) {
1534 bss
->rsn_ie_len
= 0;
1537 if (elems
.wmm_param
&&
1538 (bss
->wmm_ie
== NULL
|| bss
->wmm_ie_len
!= elems
.wmm_param_len
||
1539 memcmp(bss
->wmm_ie
, elems
.wmm_param
, elems
.wmm_param_len
))) {
1541 bss
->wmm_ie
= kmalloc(elems
.wmm_param_len
+ 2, GFP_ATOMIC
);
1543 memcpy(bss
->wmm_ie
, elems
.wmm_param
- 2,
1544 elems
.wmm_param_len
+ 2);
1545 bss
->wmm_ie_len
= elems
.wmm_param_len
+ 2;
1547 bss
->wmm_ie_len
= 0;
1548 } else if (!elems
.wmm_param
&& bss
->wmm_ie
) {
1551 bss
->wmm_ie_len
= 0;
1555 bss
->hw_mode
= local
->conf
.phymode
;
1556 bss
->channel
= channel
;
1557 bss
->freq
= local
->conf
.freq
;
1558 if (channel
!= local
->conf
.channel
&&
1559 (local
->conf
.phymode
== MODE_IEEE80211G
||
1560 local
->conf
.phymode
== MODE_IEEE80211B
) &&
1561 channel
>= 1 && channel
<= 14) {
1562 static const int freq_list
[] = {
1563 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1564 2447, 2452, 2457, 2462, 2467, 2472, 2484
1566 /* IEEE 802.11g/b mode can receive packets from neighboring
1567 * channels, so map the channel into frequency. */
1568 bss
->freq
= freq_list
[channel
- 1];
1570 bss
->timestamp
= timestamp
;
1571 bss
->last_update
= jiffies
;
1572 bss
->rssi
= rx_status
->ssi
;
1575 ieee80211_rx_bss_put(dev
, bss
);
1579 static void ieee80211_rx_mgmt_probe_resp(struct net_device
*dev
,
1580 struct ieee80211_mgmt
*mgmt
,
1582 struct ieee80211_rx_status
*rx_status
)
1584 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 0);
1588 static void ieee80211_rx_mgmt_beacon(struct net_device
*dev
,
1589 struct ieee80211_mgmt
*mgmt
,
1591 struct ieee80211_rx_status
*rx_status
)
1593 struct ieee80211_local
*local
= dev
->priv
;
1594 struct ieee80211_sub_if_data
*sdata
;
1595 struct ieee80211_if_sta
*ifsta
;
1598 struct ieee802_11_elems elems
;
1600 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 1);
1602 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1603 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
1605 ifsta
= &sdata
->u
.sta
;
1607 if (!ifsta
->associated
||
1608 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
1611 /* Process beacon from the current BSS */
1612 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1616 if (ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
,
1617 &elems
) == ParseFailed
)
1621 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
1623 (elems
.erp_info
[0] & ERP_INFO_USE_PROTECTION
) != 0;
1626 if (use_protection
!= !!ifsta
->use_protection
) {
1627 if (net_ratelimit()) {
1628 printk(KERN_DEBUG
"%s: CTS protection %s (BSSID="
1631 use_protection
? "enabled" : "disabled",
1632 MAC2STR(ifsta
->bssid
));
1634 ifsta
->use_protection
= use_protection
? 1 : 0;
1635 local
->cts_protect_erp_frames
= use_protection
;
1638 if (elems
.wmm_param
&& ifsta
->wmm_enabled
) {
1639 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
1640 elems
.wmm_param_len
);
1645 static void ieee80211_rx_mgmt_probe_req(struct net_device
*dev
,
1646 struct ieee80211_if_sta
*ifsta
,
1647 struct ieee80211_mgmt
*mgmt
,
1649 struct ieee80211_rx_status
*rx_status
)
1651 struct ieee80211_local
*local
= dev
->priv
;
1653 struct sk_buff
*skb
;
1654 struct ieee80211_mgmt
*resp
;
1657 if (local
->conf
.mode
!= IW_MODE_ADHOC
||
1658 ifsta
->state
!= IEEE80211_IBSS_JOINED
||
1659 len
< 24 + 2 || ifsta
->probe_resp
== NULL
)
1662 if (local
->hw
->tx_last_beacon
)
1663 tx_last_beacon
= local
->hw
->tx_last_beacon(local
->mdev
);
1667 #ifdef IEEE80211_IBSS_DEBUG
1668 printk(KERN_DEBUG
"%s: RX ProbeReq SA=" MACSTR
" DA=" MACSTR
" BSSID="
1669 MACSTR
" (tx_last_beacon=%d)\n",
1670 dev
->name
, MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
),
1671 MAC2STR(mgmt
->bssid
), tx_last_beacon
);
1672 #endif /* IEEE80211_IBSS_DEBUG */
1674 if (!tx_last_beacon
)
1677 if (memcmp(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
) != 0 &&
1678 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
1681 end
= ((u8
*) mgmt
) + len
;
1682 pos
= mgmt
->u
.probe_req
.variable
;
1683 if (pos
[0] != WLAN_EID_SSID
||
1684 pos
+ 2 + pos
[1] > end
) {
1685 if (net_ratelimit()) {
1686 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
1687 "from " MACSTR
"\n",
1688 dev
->name
, MAC2STR(mgmt
->sa
));
1693 (pos
[1] != ifsta
->ssid_len
||
1694 memcmp(pos
+ 2, ifsta
->ssid
, ifsta
->ssid_len
) != 0)) {
1695 /* Ignore ProbeReq for foreign SSID */
1699 /* Reply with ProbeResp */
1700 skb
= skb_copy(ifsta
->probe_resp
, GFP_ATOMIC
);
1704 resp
= (struct ieee80211_mgmt
*) skb
->data
;
1705 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
1706 #ifdef IEEE80211_IBSS_DEBUG
1707 printk(KERN_DEBUG
"%s: Sending ProbeResp to " MACSTR
"\n",
1708 dev
->name
, MAC2STR(resp
->da
));
1709 #endif /* IEEE80211_IBSS_DEBUG */
1710 ieee80211_sta_tx(dev
, skb
, 0, 1);
1714 void ieee80211_sta_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
1715 struct ieee80211_rx_status
*rx_status
)
1717 struct ieee80211_sub_if_data
*sdata
;
1718 struct ieee80211_if_sta
*ifsta
;
1719 struct ieee80211_mgmt
*mgmt
;
1725 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1726 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
) {
1727 printk(KERN_DEBUG
"%s: ieee80211_sta_rx_mgmt: non-STA "
1728 "interface (type=%d)\n", dev
->name
, sdata
->type
);
1731 ifsta
= &sdata
->u
.sta
;
1733 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
1734 fc
= le16_to_cpu(mgmt
->frame_control
);
1736 switch (WLAN_FC_GET_STYPE(fc
)) {
1737 case WLAN_FC_STYPE_PROBE_REQ
:
1738 ieee80211_rx_mgmt_probe_req(dev
, ifsta
, mgmt
, skb
->len
,
1741 case WLAN_FC_STYPE_PROBE_RESP
:
1742 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
, skb
->len
, rx_status
);
1744 case WLAN_FC_STYPE_BEACON
:
1745 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
, rx_status
);
1747 case WLAN_FC_STYPE_AUTH
:
1748 ieee80211_rx_mgmt_auth(dev
, ifsta
, mgmt
, skb
->len
, rx_status
);
1750 case WLAN_FC_STYPE_ASSOC_RESP
:
1751 ieee80211_rx_mgmt_assoc_resp(dev
, ifsta
, mgmt
, skb
->len
,
1754 case WLAN_FC_STYPE_REASSOC_RESP
:
1755 ieee80211_rx_mgmt_assoc_resp(dev
, ifsta
, mgmt
, skb
->len
,
1758 case WLAN_FC_STYPE_DEAUTH
:
1759 ieee80211_rx_mgmt_deauth(dev
, ifsta
, mgmt
, skb
->len
,
1762 case WLAN_FC_STYPE_DISASSOC
:
1763 ieee80211_rx_mgmt_disassoc(dev
, ifsta
, mgmt
, skb
->len
,
1767 printk(KERN_DEBUG
"%s: received unknown management frame - "
1768 "stype=%d\n", dev
->name
, WLAN_FC_GET_STYPE(fc
));
1777 void ieee80211_sta_rx_scan(struct net_device
*dev
, struct sk_buff
*skb
,
1778 struct ieee80211_rx_status
*rx_status
)
1780 struct ieee80211_mgmt
*mgmt
;
1783 if (skb
->len
< 24) {
1788 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
1789 fc
= le16_to_cpu(mgmt
->frame_control
);
1791 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
) {
1792 if (WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
1793 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
,
1794 skb
->len
, rx_status
);
1795 } else if (WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
) {
1796 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
,
1805 static int ieee80211_sta_active_ibss(struct net_device
*dev
)
1807 struct ieee80211_local
*local
= dev
->priv
;
1808 struct list_head
*ptr
;
1810 struct sta_info
*sta
;
1812 spin_lock_bh(&local
->sta_lock
);
1813 list_for_each(ptr
, &local
->sta_list
) {
1814 sta
= list_entry(ptr
, struct sta_info
, list
);
1815 if (sta
->dev
== dev
&&
1816 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
1822 spin_unlock_bh(&local
->sta_lock
);
1828 static void ieee80211_sta_expire(struct net_device
*dev
)
1830 struct ieee80211_local
*local
= dev
->priv
;
1831 struct list_head
*ptr
, *n
;
1832 struct sta_info
*sta
;
1834 spin_lock_bh(&local
->sta_lock
);
1835 list_for_each_safe(ptr
, n
, &local
->sta_list
) {
1836 sta
= list_entry(ptr
, struct sta_info
, list
);
1837 if (time_after(jiffies
, sta
->last_rx
+
1838 IEEE80211_IBSS_INACTIVITY_LIMIT
)) {
1839 printk(KERN_DEBUG
"%s: expiring inactive STA " MACSTR
1840 "\n", dev
->name
, MAC2STR(sta
->addr
));
1841 sta_info_free(local
, sta
, 1);
1844 spin_unlock_bh(&local
->sta_lock
);
1848 static void ieee80211_sta_merge_ibss(struct net_device
*dev
,
1849 struct ieee80211_if_sta
*ifsta
)
1851 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
1853 ieee80211_sta_expire(dev
);
1854 if (ieee80211_sta_active_ibss(dev
))
1857 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
1858 "IBSS networks with same SSID (merge)\n", dev
->name
);
1859 ieee80211_sta_req_scan(dev
, ifsta
->ssid
, ifsta
->ssid_len
);
1863 void ieee80211_sta_timer(unsigned long ptr
)
1865 struct net_device
*dev
;
1866 struct ieee80211_sub_if_data
*sdata
;
1867 struct ieee80211_if_sta
*ifsta
;
1869 dev
= (struct net_device
*) ptr
;
1870 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1871 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
) {
1872 printk(KERN_DEBUG
"%s: ieee80211_sta_timer: non-STA interface "
1873 "(type=%d)\n", dev
->name
, sdata
->type
);
1876 ifsta
= &sdata
->u
.sta
;
1878 switch (ifsta
->state
) {
1879 case IEEE80211_DISABLED
:
1881 case IEEE80211_AUTHENTICATE
:
1882 ieee80211_authenticate(dev
, ifsta
);
1884 case IEEE80211_ASSOCIATE
:
1885 ieee80211_associate(dev
, ifsta
);
1887 case IEEE80211_ASSOCIATED
:
1888 ieee80211_associated(dev
, ifsta
);
1890 case IEEE80211_IBSS_SEARCH
:
1891 ieee80211_sta_find_ibss(dev
, ifsta
);
1893 case IEEE80211_IBSS_JOINED
:
1894 ieee80211_sta_merge_ibss(dev
, ifsta
);
1897 printk(KERN_DEBUG
"ieee80211_sta_timer: Unknown state %d\n",
1902 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
1903 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
1904 "mixed-cell disabled - disassociate\n", dev
->name
);
1906 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
1907 ieee80211_set_associated(dev
, ifsta
, 0);
1912 static void ieee80211_sta_new_auth(struct net_device
*dev
,
1913 struct ieee80211_if_sta
*ifsta
)
1915 struct ieee80211_local
*local
= dev
->priv
;
1917 if (local
->conf
.mode
!= IW_MODE_INFRA
)
1920 if (local
->hw
->reset_tsf
) {
1921 /* Reset own TSF to allow time synchronization work. */
1922 local
->hw
->reset_tsf(local
->mdev
);
1925 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
1928 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1929 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
1930 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1931 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
1932 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1933 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
1935 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
1936 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
1938 ifsta
->auth_transaction
= -1;
1939 ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
1940 ieee80211_authenticate(dev
, ifsta
);
1944 static int ieee80211_ibss_allowed(struct ieee80211_local
*local
)
1948 for (m
= 0; m
< local
->hw
->num_modes
; m
++) {
1949 struct ieee80211_hw_modes
*mode
= &local
->hw
->modes
[m
];
1950 if (mode
->mode
!= local
->conf
.phymode
)
1952 for (c
= 0; c
< mode
->num_channels
; c
++) {
1953 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
1954 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
1955 chan
->chan
== local
->conf
.channel
) {
1956 if (chan
->flag
& IEEE80211_CHAN_W_IBSS
)
1967 extern int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
1968 struct iw_request_info
*info
,
1969 struct iw_freq
*freq
, char *extra
);
1971 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
1972 struct ieee80211_if_sta
*ifsta
,
1973 struct ieee80211_sta_bss
*bss
)
1975 struct ieee80211_local
*local
= dev
->priv
;
1977 int res
, rates
, i
, j
;
1978 struct sk_buff
*skb
;
1979 struct ieee80211_mgmt
*mgmt
;
1980 struct ieee80211_tx_control control
;
1981 struct ieee80211_rate
*rate
;
1982 struct rate_control_extra extra
;
1984 struct ieee80211_sub_if_data
*sdata
;
1986 /* Remove possible STA entries from other IBSS networks. */
1987 sta_info_flush(local
, NULL
);
1989 if (local
->hw
->reset_tsf
) {
1990 /* Reset own TSF to allow time synchronization work. */
1991 local
->hw
->reset_tsf(local
->mdev
);
1993 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
1994 memcpy(local
->bssid
, bss
->bssid
, ETH_ALEN
);
1995 memcpy(local
->conf
.client_bssid
, bss
->bssid
, ETH_ALEN
);
1997 local
->conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
1999 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2000 sdata
->drop_unencrypted
= bss
->capability
&
2001 cpu_to_le16(WLAN_CAPABILITY_PRIVACY
) ? 1 : 0;
2003 memset(&rq
, 0, sizeof(rq
));
2004 rq
.m
= bss
->freq
* 100000;
2006 res
= ieee80211_ioctl_siwfreq(dev
, NULL
, &rq
, NULL
);
2008 if (!ieee80211_ibss_allowed(local
)) {
2009 printk(KERN_DEBUG
"%s: IBSS not allowed on channel %d "
2010 "(%d MHz)\n", dev
->name
, local
->conf
.channel
,
2015 /* Set beacon template based on scan results */
2016 skb
= dev_alloc_skb(400);
2021 mgmt
= (struct ieee80211_mgmt
*)
2022 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2023 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2024 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
2025 WLAN_FC_STYPE_BEACON
);
2026 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2027 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2028 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2029 mgmt
->u
.beacon
.beacon_int
=
2030 cpu_to_le16(local
->conf
.beacon_int
);
2031 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2033 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2034 *pos
++ = WLAN_EID_SSID
;
2035 *pos
++ = ifsta
->ssid_len
;
2036 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2038 rates
= bss
->supp_rates_len
;
2041 pos
= skb_put(skb
, 2 + rates
);
2042 *pos
++ = WLAN_EID_SUPP_RATES
;
2044 memcpy(pos
, bss
->supp_rates
, rates
);
2046 pos
= skb_put(skb
, 2 + 1);
2047 *pos
++ = WLAN_EID_DS_PARAMS
;
2049 *pos
++ = bss
->channel
;
2051 pos
= skb_put(skb
, 2 + 2);
2052 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2054 /* FIX: set ATIM window based on scan results */
2058 if (bss
->supp_rates_len
> 8) {
2059 rates
= bss
->supp_rates_len
- 8;
2060 pos
= skb_put(skb
, 2 + rates
);
2061 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2063 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2066 memset(&control
, 0, sizeof(control
));
2067 control
.pkt_type
= PKT_PROBE_RESP
;
2068 memset(&extra
, 0, sizeof(extra
));
2069 extra
.endidx
= local
->num_curr_rates
;
2070 rate
= rate_control_get_rate(dev
, skb
, &extra
);
2072 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2073 "for IBSS beacon\n", dev
->name
);
2076 control
.tx_rate
= (local
->short_preamble
&&
2077 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
)) ?
2078 rate
->val2
: rate
->val
;
2079 control
.antenna_sel
= local
->conf
.antenna_sel
;
2080 control
.power_level
= local
->conf
.power_level
;
2082 control
.retry_limit
= 1;
2083 control
.rts_cts_duration
= 0;
2085 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2086 if (ifsta
->probe_resp
) {
2087 mgmt
= (struct ieee80211_mgmt
*)
2088 ifsta
->probe_resp
->data
;
2089 mgmt
->frame_control
=
2090 IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
2091 WLAN_FC_STYPE_PROBE_RESP
);
2093 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2094 "template for IBSS\n", dev
->name
);
2097 if (local
->hw
->beacon_update
&&
2098 local
->hw
->beacon_update(dev
, skb
, &control
) == 0) {
2099 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2100 "template based on scan results\n", dev
->name
);
2105 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2106 int rate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2107 if (local
->conf
.phymode
== MODE_ATHEROS_TURBO
)
2109 for (j
= 0; j
< local
->num_curr_rates
; j
++)
2110 if (local
->curr_rates
[j
].rate
== rate
)
2113 ifsta
->supp_rates_bits
= rates
;
2117 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2118 "template\n", dev
->name
);
2122 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2123 mod_timer(&ifsta
->timer
, jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2125 ieee80211_rx_bss_put(dev
, bss
);
2131 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
2132 struct ieee80211_if_sta
*ifsta
)
2134 struct ieee80211_local
*local
= dev
->priv
;
2135 struct ieee80211_sta_bss
*bss
;
2136 struct ieee80211_sub_if_data
*sdata
;
2137 u8 bssid
[ETH_ALEN
], *pos
;
2141 /* Easier testing, use fixed BSSID. */
2142 memset(bssid
, 0xfe, ETH_ALEN
);
2144 /* Generate random, not broadcast, locally administered BSSID. Mix in
2145 * own MAC address to make sure that devices that do not have proper
2146 * random number generator get different BSSID. */
2147 get_random_bytes(bssid
, ETH_ALEN
);
2148 for (i
= 0; i
< ETH_ALEN
; i
++)
2149 bssid
[i
] ^= dev
->dev_addr
[i
];
2154 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID " MACSTR
"\n",
2155 dev
->name
, MAC2STR(bssid
));
2157 bss
= ieee80211_rx_bss_add(dev
, bssid
);
2161 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2163 if (local
->conf
.beacon_int
== 0)
2164 local
->conf
.beacon_int
= 100;
2165 bss
->beacon_int
= local
->conf
.beacon_int
;
2166 bss
->hw_mode
= local
->conf
.phymode
;
2167 bss
->channel
= local
->conf
.channel
;
2168 bss
->freq
= local
->conf
.freq
;
2169 bss
->last_update
= jiffies
;
2170 bss
->capability
= cpu_to_le16(WLAN_CAPABILITY_IBSS
);
2171 if (sdata
->default_key
) {
2172 bss
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
2174 sdata
->drop_unencrypted
= 0;
2175 bss
->supp_rates_len
= local
->num_curr_rates
;
2176 pos
= bss
->supp_rates
;
2177 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
2178 int rate
= local
->curr_rates
[i
].rate
;
2179 if (local
->conf
.phymode
== MODE_ATHEROS_TURBO
)
2181 *pos
++ = (u8
) (rate
/ 5);
2184 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
2188 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
2189 struct ieee80211_if_sta
*ifsta
)
2191 struct ieee80211_local
*local
= dev
->priv
;
2192 struct ieee80211_sta_bss
*bss
;
2195 struct list_head
*ptr
;
2198 if (ifsta
->ssid_len
== 0)
2201 active_ibss
= ieee80211_sta_active_ibss(dev
);
2202 #ifdef IEEE80211_IBSS_DEBUG
2203 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
2204 dev
->name
, active_ibss
);
2205 #endif /* IEEE80211_IBSS_DEBUG */
2206 spin_lock_bh(&local
->sta_bss_lock
);
2207 list_for_each(ptr
, &local
->sta_bss_list
) {
2208 bss
= list_entry(ptr
, struct ieee80211_sta_bss
, list
);
2209 if (ifsta
->ssid_len
!= bss
->ssid_len
||
2210 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
2211 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
2213 #ifdef IEEE80211_IBSS_DEBUG
2214 printk(KERN_DEBUG
" bssid=" MACSTR
" found\n",
2215 MAC2STR(bss
->bssid
));
2216 #endif /* IEEE80211_IBSS_DEBUG */
2217 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
2219 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
2222 spin_unlock_bh(&local
->sta_bss_lock
);
2224 #ifdef IEEE80211_IBSS_DEBUG
2225 printk(KERN_DEBUG
" sta_find_ibss: selected " MACSTR
" current "
2226 MACSTR
"\n", MAC2STR(bssid
), MAC2STR(ifsta
->bssid
));
2227 #endif /* IEEE80211_IBSS_DEBUG */
2228 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
2229 (bss
= ieee80211_rx_bss_get(dev
, bssid
))) {
2230 printk(KERN_DEBUG
"%s: Selected IBSS BSSID " MACSTR
2231 " based on configured SSID\n",
2232 dev
->name
, MAC2STR(bssid
));
2233 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
2235 #ifdef IEEE80211_IBSS_DEBUG
2236 printk(KERN_DEBUG
" did not try to join ibss\n");
2237 #endif /* IEEE80211_IBSS_DEBUG */
2239 /* Selected IBSS not found in current scan results - try to scan */
2240 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
2241 !ieee80211_sta_active_ibss(dev
)) {
2242 mod_timer(&ifsta
->timer
,
2243 jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
);
2244 } else if (time_after(jiffies
, local
->last_scan_completed
+
2245 IEEE80211_SCAN_INTERVAL
)) {
2246 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
2247 "join\n", dev
->name
);
2248 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
2250 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
2251 int interval
= IEEE80211_SCAN_INTERVAL
;
2253 if (time_after(jiffies
, ifsta
->ibss_join_req
+
2254 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
2255 if (ifsta
->create_ibss
&&
2256 ieee80211_ibss_allowed(local
))
2257 return ieee80211_sta_create_ibss(dev
, ifsta
);
2258 if (ifsta
->create_ibss
) {
2259 printk(KERN_DEBUG
"%s: IBSS not allowed on the"
2260 " configured channel %d (%d MHz)\n",
2261 dev
->name
, local
->conf
.channel
,
2265 /* No IBSS found - decrease scan interval and continue
2267 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
2270 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
2271 mod_timer(&ifsta
->timer
, jiffies
+ interval
);
2279 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
2281 struct ieee80211_sub_if_data
*sdata
;
2282 struct ieee80211_if_sta
*ifsta
;
2283 struct ieee80211_local
*local
= dev
->priv
;
2285 if (len
> IEEE80211_MAX_SSID_LEN
)
2288 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
2290 if (local
->hw
->conf_tx
) {
2291 struct ieee80211_tx_queue_params qparam
;
2294 memset(&qparam
, 0, sizeof(qparam
));
2295 /* TODO: are these ok defaults for all hw_modes? */
2298 local
->conf
.phymode
== MODE_IEEE80211B
? 31 : 15;
2299 qparam
.cw_max
= 1023;
2300 qparam
.burst_time
= 0;
2301 for (i
= IEEE80211_TX_QUEUE_DATA0
; i
< NUM_TX_DATA_QUEUES
; i
++)
2303 local
->hw
->conf_tx(dev
, i
+ IEEE80211_TX_QUEUE_DATA0
,
2306 /* IBSS uses different parameters for Beacon sending */
2310 local
->hw
->conf_tx(dev
, IEEE80211_TX_QUEUE_BEACON
, &qparam
);
2313 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2314 ifsta
= &sdata
->u
.sta
;
2316 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
2317 ifsta
->prev_bssid_set
= 0;
2318 memcpy(ifsta
->ssid
, ssid
, len
);
2319 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
2320 ifsta
->ssid_len
= len
;
2322 ifsta
->ssid_set
= 1;
2323 if (local
->conf
.mode
== IW_MODE_ADHOC
&& !ifsta
->bssid_set
) {
2324 ifsta
->ibss_join_req
= jiffies
;
2325 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
2326 return ieee80211_sta_find_ibss(dev
, ifsta
);
2329 if (ifsta
->bssid_set
&& ifsta
->state
!= IEEE80211_AUTHENTICATE
)
2330 ieee80211_sta_new_auth(dev
, ifsta
);
2336 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
2338 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2339 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2340 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
2341 *len
= ifsta
->ssid_len
;
2346 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
2348 struct ieee80211_local
*local
= dev
->priv
;
2349 struct ieee80211_sub_if_data
*sdata
;
2350 struct ieee80211_if_sta
*ifsta
;
2352 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2353 ifsta
= &sdata
->u
.sta
;
2355 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
2356 if (local
->conf
.mode
== IW_MODE_ADHOC
)
2357 memcpy(local
->bssid
, bssid
, ETH_ALEN
);
2359 if (memcmp(bssid
, "\x00\x00\x00\x00\x00\x00", ETH_ALEN
) == 0)
2360 ifsta
->bssid_set
= 0;
2362 ifsta
->bssid_set
= 1;
2363 if (ifsta
->ssid_set
)
2364 ieee80211_sta_new_auth(dev
, ifsta
);
2370 static void ieee80211_sta_save_oper_chan(struct net_device
*dev
)
2372 struct ieee80211_local
*local
= dev
->priv
;
2373 local
->scan_oper_channel
= local
->conf
.channel
;
2374 local
->scan_oper_channel_val
= local
->conf
.channel_val
;
2375 local
->scan_oper_power_level
= local
->conf
.power_level
;
2376 local
->scan_oper_freq
= local
->conf
.freq
;
2377 local
->scan_oper_phymode
= local
->conf
.phymode
;
2378 local
->scan_oper_antenna_max
= local
->conf
.antenna_max
;
2382 static int ieee80211_sta_restore_oper_chan(struct net_device
*dev
)
2384 struct ieee80211_local
*local
= dev
->priv
;
2385 local
->conf
.channel
= local
->scan_oper_channel
;
2386 local
->conf
.channel_val
= local
->scan_oper_channel_val
;
2387 local
->conf
.power_level
= local
->scan_oper_power_level
;
2388 local
->conf
.freq
= local
->scan_oper_freq
;
2389 local
->conf
.phymode
= local
->scan_oper_phymode
;
2390 local
->conf
.antenna_max
= local
->scan_oper_antenna_max
;
2391 return ieee80211_hw_config(dev
);
2395 static int ieee80211_active_scan(struct ieee80211_local
*local
)
2399 for (m
= 0; m
< local
->hw
->num_modes
; m
++) {
2400 struct ieee80211_hw_modes
*mode
= &local
->hw
->modes
[m
];
2401 if (mode
->mode
!= local
->conf
.phymode
)
2403 for (c
= 0; c
< mode
->num_channels
; c
++) {
2404 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
2405 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
2406 chan
->chan
== local
->conf
.channel
) {
2407 if (chan
->flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
)
2418 static void ieee80211_sta_scan_timer(unsigned long ptr
)
2420 struct net_device
*dev
= (struct net_device
*) ptr
;
2421 struct ieee80211_local
*local
= dev
->priv
;
2422 struct ieee80211_hw_modes
*mode
;
2423 struct ieee80211_channel
*chan
;
2425 union iwreq_data wrqu
;
2427 if (!local
->sta_scanning
)
2430 switch (local
->scan_state
) {
2431 case SCAN_SET_CHANNEL
:
2432 mode
= &local
->hw
->modes
[local
->scan_hw_mode_idx
];
2433 if (local
->scan_hw_mode_idx
>= local
->hw
->num_modes
||
2434 (local
->scan_hw_mode_idx
+ 1 == local
->hw
->num_modes
&&
2435 local
->scan_channel_idx
>= mode
->num_channels
)) {
2436 if (ieee80211_sta_restore_oper_chan(dev
)) {
2437 printk(KERN_DEBUG
"%s: failed to restore "
2438 "operational channel after scan\n",
2441 printk(KERN_DEBUG
"%s: scan completed\n", dev
->name
);
2442 local
->sta_scanning
= 0;
2443 local
->last_scan_completed
= jiffies
;
2444 memset(&wrqu
, 0, sizeof(wrqu
));
2445 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2446 if (local
->conf
.mode
== IW_MODE_ADHOC
) {
2447 struct ieee80211_sub_if_data
*sdata
=
2448 IEEE80211_DEV_TO_SUB_IF(dev
);
2449 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2450 if (!ifsta
->bssid_set
||
2451 (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
2452 !ieee80211_sta_active_ibss(dev
)))
2453 ieee80211_sta_find_ibss(dev
, ifsta
);
2457 skip
= !(local
->hw_modes
& (1 << mode
->mode
));
2458 chan
= &mode
->channels
[local
->scan_channel_idx
];
2459 if (!(chan
->flag
& IEEE80211_CHAN_W_SCAN
) ||
2460 (local
->conf
.mode
== IW_MODE_ADHOC
&&
2461 !(chan
->flag
& IEEE80211_CHAN_W_IBSS
)) ||
2462 (local
->hw_modes
& (1 << MODE_IEEE80211G
) &&
2463 mode
->mode
== MODE_IEEE80211B
&& local
->scan_skip_11b
))
2468 printk(KERN_DEBUG
"%s: scan channel %d (%d MHz)\n",
2469 dev
->name
, chan
->chan
, chan
->freq
);
2472 local
->conf
.channel
= chan
->chan
;
2473 local
->conf
.channel_val
= chan
->val
;
2474 local
->conf
.power_level
= chan
->power_level
;
2475 local
->conf
.freq
= chan
->freq
;
2476 local
->conf
.phymode
= mode
->mode
;
2477 local
->conf
.antenna_max
= chan
->antenna_max
;
2478 if (ieee80211_hw_config(dev
)) {
2479 printk(KERN_DEBUG
"%s: failed to set channel "
2480 "%d (%d MHz) for scan\n", dev
->name
,
2481 chan
->chan
, chan
->freq
);
2486 local
->scan_channel_idx
++;
2487 if (local
->scan_channel_idx
>=
2488 local
->hw
->modes
[local
->scan_hw_mode_idx
].num_channels
) {
2489 local
->scan_hw_mode_idx
++;
2490 local
->scan_channel_idx
= 0;
2494 local
->scan_timer
.expires
= jiffies
;
2498 local
->scan_timer
.expires
= jiffies
+ IEEE80211_PROBE_DELAY
;
2499 local
->scan_state
= SCAN_SEND_PROBE
;
2501 case SCAN_SEND_PROBE
:
2502 if (ieee80211_active_scan(local
)) {
2503 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
2504 local
->scan_ssid_len
);
2505 local
->scan_timer
.expires
=
2506 jiffies
+ IEEE80211_CHANNEL_TIME
;
2508 local
->scan_timer
.expires
=
2509 jiffies
+ IEEE80211_PASSIVE_CHANNEL_TIME
;
2511 local
->scan_state
= SCAN_SET_CHANNEL
;
2515 add_timer(&local
->scan_timer
);
2519 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
2521 struct ieee80211_local
*local
= dev
->priv
;
2523 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
2526 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
2527 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
2530 * ScanType: ACTIVE, PASSIVE
2531 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
2532 * a Probe frame during active scanning
2534 * MinChannelTime (>= ProbeDelay), in TU
2535 * MaxChannelTime: (>= MinChannelTime), in TU
2538 /* MLME-SCAN.confirm
2540 * ResultCode: SUCCESS, INVALID_PARAMETERS
2543 /* TODO: if assoc, move to power save mode for the duration of the
2546 if (local
->sta_scanning
)
2549 printk(KERN_DEBUG
"%s: starting scan\n", dev
->name
);
2551 ieee80211_sta_save_oper_chan(dev
);
2553 local
->sta_scanning
= 1;
2554 /* TODO: stop TX queue? */
2557 local
->scan_ssid_len
= ssid_len
;
2558 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
2560 local
->scan_ssid_len
= 0;
2561 local
->scan_skip_11b
= 1; /* FIX: clear this is 11g is not supported */
2562 local
->scan_state
= SCAN_SET_CHANNEL
;
2563 local
->scan_hw_mode_idx
= 0;
2564 local
->scan_channel_idx
= 0;
2565 init_timer(&local
->scan_timer
);
2566 local
->scan_timer
.data
= (unsigned long) dev
;
2567 local
->scan_timer
.function
= ieee80211_sta_scan_timer
;
2568 local
->scan_timer
.expires
= jiffies
+ 1;
2569 add_timer(&local
->scan_timer
);
2576 ieee80211_sta_scan_result(struct net_device
*dev
,
2577 struct ieee80211_sta_bss
*bss
,
2578 char *current_ev
, char *end_buf
)
2580 struct ieee80211_local
*local
= dev
->priv
;
2581 struct iw_event iwe
;
2583 if (time_after(jiffies
,
2584 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
2587 if (!(local
->hw_modes
& (1 << bss
->hw_mode
)))
2590 if (local
->scan_flags
& IEEE80211_SCAN_WPA_ONLY
&&
2591 bss
->wpa_ie
== NULL
&& bss
->rsn_ie
== NULL
)
2594 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
&&
2595 (local
->scan_ssid_len
!= bss
->ssid_len
||
2596 memcmp(local
->scan_ssid
, bss
->ssid
, bss
->ssid_len
) != 0))
2599 memset(&iwe
, 0, sizeof(iwe
));
2600 iwe
.cmd
= SIOCGIWAP
;
2601 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
2602 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
2603 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2606 memset(&iwe
, 0, sizeof(iwe
));
2607 iwe
.cmd
= SIOCGIWESSID
;
2608 iwe
.u
.data
.length
= bss
->ssid_len
;
2609 iwe
.u
.data
.flags
= 1;
2610 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2613 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
2614 memset(&iwe
, 0, sizeof(iwe
));
2615 iwe
.cmd
= SIOCGIWMODE
;
2616 if (bss
->capability
& WLAN_CAPABILITY_ESS
)
2617 iwe
.u
.mode
= IW_MODE_MASTER
;
2619 iwe
.u
.mode
= IW_MODE_ADHOC
;
2620 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2624 memset(&iwe
, 0, sizeof(iwe
));
2625 iwe
.cmd
= SIOCGIWFREQ
;
2626 iwe
.u
.freq
.m
= bss
->freq
* 100000;
2628 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2631 memset(&iwe
, 0, sizeof(iwe
));
2632 iwe
.cmd
= SIOCGIWENCODE
;
2633 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
2634 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
2636 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
2637 iwe
.u
.data
.length
= 0;
2638 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
2640 if (bss
&& bss
->wpa_ie
) {
2643 buf
= kmalloc(30 + bss
->wpa_ie_len
* 2, GFP_ATOMIC
);
2646 p
+= sprintf(p
, "wpa_ie=");
2647 for (i
= 0; i
< bss
->wpa_ie_len
; i
++)
2648 p
+= sprintf(p
, "%02x", bss
->wpa_ie
[i
]);
2649 memset(&iwe
, 0, sizeof(iwe
));
2650 iwe
.cmd
= IWEVCUSTOM
;
2651 iwe
.u
.data
.length
= strlen(buf
);
2652 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2658 if (bss
&& bss
->rsn_ie
) {
2661 buf
= kmalloc(30 + bss
->rsn_ie_len
* 2, GFP_ATOMIC
);
2664 p
+= sprintf(p
, "rsn_ie=");
2665 for (i
= 0; i
< bss
->rsn_ie_len
; i
++)
2666 p
+= sprintf(p
, "%02x", bss
->rsn_ie
[i
]);
2667 memset(&iwe
, 0, sizeof(iwe
));
2668 iwe
.cmd
= IWEVCUSTOM
;
2669 iwe
.u
.data
.length
= strlen(buf
);
2670 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2678 buf
= kmalloc(30, GFP_ATOMIC
);
2680 memset(&iwe
, 0, sizeof(iwe
));
2681 iwe
.cmd
= IWEVCUSTOM
;
2682 sprintf(buf
, "tsf=%016llx", bss
->timestamp
);
2683 iwe
.u
.data
.length
= strlen(buf
);
2684 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2694 if (!(local
->scan_flags
& IEEE80211_SCAN_EXTRA_INFO
))
2697 buf
= kmalloc(100, GFP_ATOMIC
);
2701 memset(&iwe
, 0, sizeof(iwe
));
2702 iwe
.cmd
= IWEVCUSTOM
;
2703 sprintf(buf
, "bcn_int=%d", bss
->beacon_int
);
2704 iwe
.u
.data
.length
= strlen(buf
);
2705 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2708 memset(&iwe
, 0, sizeof(iwe
));
2709 iwe
.cmd
= IWEVCUSTOM
;
2710 sprintf(buf
, "rssi=%d", bss
->rssi
);
2711 iwe
.u
.data
.length
= strlen(buf
);
2712 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2715 memset(&iwe
, 0, sizeof(iwe
));
2716 iwe
.cmd
= IWEVCUSTOM
;
2717 sprintf(buf
, "capab=0x%04x", bss
->capability
);
2718 iwe
.u
.data
.length
= strlen(buf
);
2719 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2723 p
+= sprintf(p
, "supp_rates=");
2724 for (i
= 0; i
< bss
->supp_rates_len
; i
++)
2725 p
+= sprintf(p
, "%02x", bss
->supp_rates
[i
]);
2726 memset(&iwe
, 0, sizeof(iwe
));
2727 iwe
.cmd
= IWEVCUSTOM
;
2728 iwe
.u
.data
.length
= strlen(buf
);
2729 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2740 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
2742 struct ieee80211_local
*local
= dev
->priv
;
2743 struct list_head
*ptr
;
2744 char *current_ev
= buf
;
2745 char *end_buf
= buf
+ len
;
2746 struct ieee80211_sta_bss
*bss
;
2748 spin_lock_bh(&local
->sta_bss_lock
);
2749 list_for_each(ptr
, &local
->sta_bss_list
) {
2750 bss
= list_entry(ptr
, struct ieee80211_sta_bss
, list
);
2751 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
2754 spin_unlock_bh(&local
->sta_bss_lock
);
2755 return current_ev
- buf
;
2759 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
2761 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2762 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2763 kfree(ifsta
->extra_ie
);
2765 ifsta
->extra_ie
= NULL
;
2766 ifsta
->extra_ie_len
= 0;
2769 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
2770 if (ifsta
->extra_ie
== NULL
) {
2771 ifsta
->extra_ie_len
= 0;
2774 memcpy(ifsta
->extra_ie
, ie
, len
);
2775 ifsta
->extra_ie_len
= len
;
2776 if (ifsta
->bssid_set
&& ifsta
->ssid_set
&&
2777 ifsta
->state
!= IEEE80211_AUTHENTICATE
)
2778 ieee80211_sta_new_auth(dev
, ifsta
);
2783 struct sta_info
* ieee80211_ibss_add_sta(struct net_device
*dev
,
2784 struct sk_buff
*skb
, u8
*bssid
,
2787 struct ieee80211_local
*local
= dev
->priv
;
2788 struct list_head
*ptr
;
2789 struct sta_info
*sta
;
2790 struct ieee80211_sub_if_data
*sdata
= NULL
;
2791 struct net_device
*sta_dev
= NULL
;
2793 /* TODO: Could consider removing the least recently used entry and
2794 * allow new one to be added. */
2795 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
2796 if (net_ratelimit()) {
2797 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
2798 "entry " MACSTR
"\n", dev
->name
, MAC2STR(addr
));
2803 spin_lock_bh(&local
->sub_if_lock
);
2804 list_for_each(ptr
, &local
->sub_if_list
) {
2805 sdata
= list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
2806 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
&&
2807 memcmp(bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0) {
2808 sta_dev
= sdata
->dev
;
2812 spin_unlock_bh(&local
->sub_if_lock
);
2814 if (sta_dev
== NULL
)
2817 printk(KERN_DEBUG
"%s: Adding new IBSS station " MACSTR
" (dev=%s)\n",
2818 dev
->name
, MAC2STR(addr
), sta_dev
->name
);
2820 sta
= sta_info_add(local
, dev
, addr
);
2826 sta
->supp_rates
= sdata
->u
.sta
.supp_rates_bits
;
2828 rate_control_rate_init(local
, sta
);
2830 return sta
; /* caller will call sta_info_release() */
2834 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
2836 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2837 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2839 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
2842 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
2845 ieee80211_send_deauth(dev
, ifsta
, reason
);
2846 ieee80211_set_associated(dev
, ifsta
, 0);
2851 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
2853 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2854 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2856 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
2859 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
2862 if (!ifsta
->associated
)
2865 ieee80211_send_disassoc(dev
, ifsta
, reason
);
2866 ieee80211_set_associated(dev
, ifsta
, 0);